-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_sapi_sreq.py
executable file
·129 lines (95 loc) · 3.31 KB
/
test_sapi_sreq.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#! /usr/bin/env python3
# test_sapi_sreq.py
#
# Unit tests for MT SAPI command parsing
#
# Author: Rhodri James ([email protected])
# Date: 15 July 2016
#
# Copyright 2016 Kynesim Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import base_test
import unittest
class BaseSapiSReq(base_test.BaseTest):
SUBSYSTEM = "SAPI"
TYPE = "SREQ"
class TestZbStartRequest(BaseSapiSReq):
COMMAND = 0x00
COMMAND_NAME = "ZB_START_REQUEST"
def test_start(self):
self.run_test()
class TestZbPermitJoiningRequest(BaseSapiSReq):
COMMAND = 0x08
COMMAND_NAME = "ZB_PERMIT_JOINING_REQUEST"
def test_permit_join(self):
self.add_hword("DstAddr", "1122", 0x1122)
self.add_byte("Timeout", "0x3c", 60)
self.run_test()
class TestZbBindDevice(BaseSapiSReq):
COMMAND = 0x01
COMMAND_NAME = "ZB_BIND_DEVICE"
def test_bind(self):
self.add_byte("Create", "0x01")
self.add_hword("CommandId", "248d", 0x248d)
self.add_ieee("DstExtAddr", (0x33, 0x44, 0x55, 0x66,
0x77, 0x88, 0x99, 0xaa))
self.run_test()
class TestZbAllowBind(BaseSapiSReq):
COMMAND = 0x02
COMMAND_NAME = "ZB_ALLOW_BIND"
def test_allow_bind(self):
self.add_byte("Timeout", "0x40")
self.run_test()
class TestZbSendDataRequest(BaseSapiSReq):
COMMAND = 0x03
COMMAND_NAME = "ZB_SEND_DATA_REQUEST"
def test_send_data(self):
self.add_hword("DstAddr", "892b", 0x892b)
self.add_hword("CommandId", "258d", 0x258d)
self.add_byte("Handle", "0xea")
self.add_byte("Ack", "0x01")
self.add_byte("Radius", "0x30")
self.add_byte("Length", "7")
self.add_bytes("Data", (0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x70))
self.run_test()
class TestZbReadConfiguration(BaseSapiSReq):
COMMAND = 0x04
COMMAND_NAME = "ZB_READ_CONFIGURATION"
def test_read_config(self):
self.add_byte("ConfigId", "0x01")
self.run_test()
class TestZbWriteConfiguration(BaseSapiSReq):
COMMAND = 0x05
COMMAND_NAME = "ZB_WRITE_CONFIGURATION"
def test_write_config(self):
self.add_byte("ConfigId", "0x38")
self.add_byte("Length", "3")
self.add_bytes("Data", (0x76, 0x2f, 0x01))
self.run_test()
class TestZbGetDeviceInfo(BaseSapiSReq):
COMMAND = 0x06
COMMAND_NAME = "ZB_GET_DEVICE_INFO"
def test_get_info(self):
self.add_byte("Param", "0x66")
self.run_test()
class TestZbFindDeviceRequest(BaseSapiSReq):
COMMAND = 0x07
COMMAND_NAME = "ZB_FIND_DEVICE_REQUEST"
def test_find_device(self):
self.add_bytes("SearchKey", (0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xaa, 0xbb),
leading_0x=True)
self.run_test()
if __name__ == "__main__":
unittest.main()