forked from u236/homed-service-zigbee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzstack.h
310 lines (260 loc) · 8.59 KB
/
zstack.h
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#ifndef ZSTACK_H
#define ZSTACK_H
#define ZSTACK_CONFIGURATION_MARKER 0x42
#define ZSTACK_CLEAR_DELAY 4000
#define ZSTACK_REQUEST_TIMEOUT 10000
#define ZSTACK_SKIP_BOOTLOADER 0xEF
#define ZSTACK_PACKET_FLAG 0xFE
#define ZSTACK_COORDINATOR_STARTED 0x09
#define PERMIT_JOIN_MODE_ADDREESS 0x0F
#define PERMIT_JOIN_BROARCAST_ADDRESS 0xFFFC
#define AF_ACK_REQUEST 0x10
#define AF_DISCV_ROUTE 0x20
#define AF_EN_SECURITY 0x40
#define AF_SKIP_ROUTING 0x80
#define AF_DEFAULT_RADIUS 0x0F
#define SYS_VERSION 0x2102
#define SYS_OSAL_NV_ITEM_INIT 0x2107
#define SYS_OSAL_NV_READ 0x2108
#define SYS_OSAL_NV_WRITE 0x2109
#define SYS_SET_TX_POWER 0x2114
#define AF_REGISTER 0x2400
#define AF_DATA_REQUEST 0x2401
#define AF_DATA_REQUEST_EXT 0x2402
#define AF_INTER_PAN_CTL 0x2410
#define ZDO_NODE_DESC_REQ 0x2502
#define ZDO_SIMPLE_DESC_REQ 0x2504
#define ZDO_ACTIVE_EP_REQ 0x2505
#define ZDO_BIND_REQ 0x2521
#define ZDO_UNBIND_REQ 0x2522
#define ZDO_MGMT_LQI_REQ 0x2531
#define ZDO_MGMT_LEAVE_REQ 0x2534
#define ZDO_MGMT_PERMIT_JOIN_REQ 0x2536
#define ZDO_MSG_CB_REGISTER 0x253E
#define ZDO_STARTUP_FROM_APP 0x2540
#define ZDO_ADD_GROUP 0x254B
#define ZB_READ_CONFIGURATION 0x2604
#define ZB_WRITE_CONFIGURATION 0x2605
#define UTIL_GET_DEVICE_INFO 0x2700
#define APP_CNF_BDB_SET_CHANNEL 0x2F08
#define SYS_RESET_REQ 0x4100
#define SYS_RESET_IND 0x4180
#define AF_DATA_CONFIRM 0x4480
#define AF_INCOMING_MSG 0x4481
#define AF_INCOMING_MSG_EXT 0x4482
#define ZDO_NODE_DESC_RSP 0x4582
#define ZDO_SIMPLE_DESC_RSP 0x4584
#define ZDO_ACTIVE_EP_RSP 0x4585
#define ZDO_BIND_RSP 0x45A1
#define ZDO_UNBIND_RSP 0x45A2
#define ZDO_MGMT_LQI_RSP 0x45B1
#define ZDO_MGMT_LEAVE_RSP 0x45B4
#define ZDO_MGMT_PERMIT_JOIN_RSP 0x45B6
#define ZDO_MGMT_NWK_UPDATE_RSP 0x45B8
#define ZDO_STATE_CHANGE_IND 0x45C0
#define ZDO_END_DEVICE_ANNCE_IND 0x45C1
#define ZDO_SRC_RTG_IND 0x45C4
#define ZDO_CONCENTRATOR_IND 0x45C8
#define ZDO_LEAVE_IND 0x45C9
#define ZDO_TC_DEV_IND 0x45CA
#define ZDO_PERMIT_JOIN_IND 0x45CB
#define ZDO_MSG_CB_INCOMING 0x45FF
#define APP_CNF_BDB_COMMISSIONING_NOTIFICATION 0x4F80
#define ZCD_NV_STARTUP_OPTION 0x0003
#define ZCD_NV_MARKER 0x0060
#define ZCD_NV_PRECFGKEY 0x0062
#define ZCD_NV_PRECFGKEYS_ENABLE 0x0063
#define ZCD_NV_PANID 0x0083
#define ZCD_NV_CHANLIST 0x0084
#define ZCD_NV_LOGICAL_TYPE 0x0087
#define ZCD_NV_ZDO_DIRECT_CB 0x008F
#define ZCD_NV_TCLK_TABLE 0x0101
#include "adapter.h"
#pragma pack(push, 1)
struct versionResponseStruct
{
quint8 transport;
quint8 product;
quint8 major;
quint8 minor;
quint8 patch;
quint32 build;
};
struct addGroupRequestStruct
{
quint8 endpointId;
quint16 groupId;
quint8 nameLength;
};
struct registerEndpointRequestStruct
{
quint8 endpointId;
quint16 profileId;
quint16 deviceId;
quint8 version;
quint8 latency;
};
struct permitJoinRequestStruct
{
quint8 mode;
quint16 dstAddress;
quint8 duration;
quint8 significance;
};
struct dataRequestStruct
{
quint16 networkAddress;
quint8 dstEndpointId;
quint8 srcEndpointId;
quint16 clusterId;
quint8 transactionId;
quint8 options;
quint8 radius;
quint8 length;
};
struct extendedDataRequestStruct
{
quint8 dstAddressMode;
quint64 dstAddress;
quint8 dstEndpointId;
quint16 dstPanId;
quint8 srcEndpointId;
quint16 clusterId;
quint8 transactionId;
quint8 options;
quint8 radius;
quint16 length;
};
struct setChannelRequestStruct
{
quint8 isPrimary;
quint32 channel;
};
struct nvReadRequestStruct
{
quint16 id;
quint8 offset;
};
struct nvReadReplyStruct
{
quint8 status;
quint8 length;
};
struct nvInitRequestStruct
{
quint16 id;
quint16 itemLength;
quint8 dataLength;
};
struct nvWriteRequestStruct
{
quint16 id;
quint8 offset;
quint8 length;
};
struct readConfigurationReplyStruct
{
quint8 status;
quint8 id;
quint8 length;
};
struct writeConfigurationRequestStruct
{
quint8 id;
quint8 length;
};
struct dataConfirmStruct
{
quint8 status;
quint8 endpointId;
quint8 transactionId;
};
struct incomingMessageStruct
{
quint16 groupId;
quint16 clusterId;
quint16 srcAddress;
quint8 srcEndpointId;
quint8 dstEndpointId;
quint8 broadcast;
quint8 linkQuality;
quint8 security;
quint32 timestamp;
quint8 transactionId;
quint8 length;
};
struct extendedIncomingMessageStruct
{
quint16 groupId;
quint16 clusterId;
quint8 srcAddressMode;
quint64 srcAddress;
quint8 srcEndpointId;
quint16 srcPanId;
quint8 dstEndpointId;
quint8 broadcast;
quint8 linkQuality;
quint8 security;
quint32 timestamp;
quint8 transactionId;
quint16 length;
};
struct deviceLeaveStruct
{
quint16 networkAddress;
quint64 ieeeAddress;
quint8 request;
quint8 remove;
quint8 rejoin;
};
struct zdoMessageStruct
{
quint16 srcAddress;
quint8 broadcast;
quint16 clusterId;
quint8 security;
quint8 transactionId;
quint16 dstAddress;
};
#pragma pack(pop)
enum class ZStackVersion
{
ZStack3x0,
ZStack30x,
ZStack12x
};
class ZStack : public Adapter
{
Q_OBJECT
public:
ZStack(QSettings *config, QObject *parent);
bool unicastRequest(quint8 id, quint16 networkAddress, quint8 srcEndPointId, quint8 dstEndPointId, quint16 clusterId, const QByteArray &payload) override;
bool multicastRequest(quint8 id, quint16 groupId, quint8 srcEndPointId, quint8 dstEndPointId, quint16 clusterId, const QByteArray &payload) override;
bool unicastInterPanRequest(quint8 id, const QByteArray &ieeeAddress, quint16 clusterId, const QByteArray &payload) override;
bool broadcastInterPanRequest(quint8 id, quint16 clusterId, const QByteArray &payload) override;
bool setInterPanChannel(quint8 channel) override;
void resetInterPanChannel(void) override;
private:
ZStackVersion m_version;
quint8 m_status;
bool m_clear;
quint16 m_command;
QByteArray m_replyData;
QMap <quint16, QByteArray> m_nvItems;
QList <quint16> m_zdoClusters;
bool extendedRequest(quint8 id, const QByteArray &address, quint8 dstEndpointId, quint16 dstPanId, quint8 srcEndpointId, quint16 clusterId, const QByteArray &payload, bool group = false);
bool extendedRequest(quint8 id, quint16 address, quint8 dstEndpointId, quint16 dstPanId, quint8 srcEndpointId, quint16 clusterId, const QByteArray &paylaod, bool group = false);
bool sendRequest(quint16 command, const QByteArray &data = QByteArray());
void parsePacket(quint16 command, const QByteArray &data);
bool writeNvItem(quint16 id, const QByteArray &data);
bool writeConfiguration(quint16 id, const QByteArray &data);
bool startCoordinator(void);
void softReset(void) override;
void parseData(QByteArray &buffer) override;
bool permitJoin(bool enabled) override;
private slots:
void handleQueue(void) override;
signals:
void dataReceived(void);
};
#endif