-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
zstack.h
282 lines (233 loc) · 7.13 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
#ifndef ZSTACK_H
#define ZSTACK_H
#define ZSTACK_CLEAR_DELAY 4000
#define ZSTACK_REQUEST_TIMEOUT 10000
#define ZSTACK_SKIP_BOOTLOADER 0xEF
#define ZSTACK_PACKET_FLAG 0xFE
#define ZSTACK_NOT_STARTED_AUTOMATICALLY 0x00
#define ZSTACK_COORDINATOR_STARTED 0x09
#define ZSTACK_AF_DISCV_ROUTE 0x20
#define ZSTACK_AF_DEFAULT_RADIUS 0x0F
#define ZSTACK_SYS_VERSION 0x2102
#define ZSTACK_SYS_OSAL_NV_READ 0x2108
#define ZSTACK_SYS_OSAL_NV_WRITE 0x2109
#define ZSTACK_SYS_SET_TX_POWER 0x2114
#define ZSTACK_AF_REGISTER 0x2400
#define ZSTACK_AF_DATA_REQUEST 0x2401
#define ZSTACK_AF_DATA_REQUEST_EXT 0x2402
#define ZSTACK_AF_INTER_PAN_CTL 0x2410
#define ZSTACK_ZDO_MGMT_PERMIT_JOIN_REQ 0x2536
#define ZSTACK_ZDO_MSG_CB_REGISTER 0x253E
#define ZSTACK_ZDO_STARTUP_FROM_APP 0x2540
#define ZSTACK_ZDO_ADD_GROUP 0x254B
#define ZSTACK_ZB_READ_CONFIGURATION 0x2604
#define ZSTACK_ZB_WRITE_CONFIGURATION 0x2605
#define ZSTACK_UTIL_GET_DEVICE_INFO 0x2700
#define ZSTACK_APP_CNF_BDB_SET_CHANNEL 0x2F08
#define ZSTACK_SYS_RESET_REQ 0x4100
#define ZSTACK_SYS_RESET_IND 0x4180
#define ZSTACK_AF_DATA_CONFIRM 0x4480
#define ZSTACK_AF_INCOMING_MSG 0x4481
#define ZSTACK_AF_INCOMING_MSG_EXT 0x4482
#define ZSTACK_ZDO_MGMT_PERMIT_JOIN_RSP 0x45B6
#define ZSTACK_ZDO_MGMT_NWK_UPDATE_RSP 0x45B8
#define ZSTACK_ZDO_STATE_CHANGE_IND 0x45C0
#define ZSTACK_ZDO_END_DEVICE_ANNCE_IND 0x45C1
#define ZSTACK_ZDO_SRC_RTG_IND 0x45C4
#define ZSTACK_ZDO_CONCENTRATOR_IND 0x45C8
#define ZSTACK_ZDO_LEAVE_IND 0x45C9
#define ZSTACK_ZDO_TC_DEV_IND 0x45CA
#define ZSTACK_ZDO_PERMIT_JOIN_IND 0x45CB
#define ZSTACK_ZDO_MSG_CB_INCOMING 0x45FF
#define ZSTACK_APP_CNF_BDB_COMMISSIONING 0x4F80
#define ZCD_NV_STARTUP_OPTION 0x0003
#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 zstackVersionStruct
{
quint8 transport;
quint8 product;
quint8 major;
quint8 minor;
quint8 patch;
quint32 build;
};
struct zstackAddGroupStruct
{
quint8 endpointId;
quint16 groupId;
quint8 nameLength;
};
struct zstackRegisterEndpointStruct
{
quint8 endpointId;
quint16 profileId;
quint16 deviceId;
quint8 version;
quint8 latency;
};
struct zstackPermitJoinStruct
{
quint8 mode;
quint16 dstAddress;
quint8 duration;
quint8 significance;
};
struct zstackDataRequestStruct
{
quint16 networkAddress;
quint8 dstEndpointId;
quint8 srcEndpointId;
quint16 clusterId;
quint8 transactionId;
quint8 options;
quint8 radius;
quint8 length;
};
struct zstackExtendedRequestStruct
{
quint8 dstAddressMode;
quint64 dstAddress;
quint8 dstEndpointId;
quint16 dstPanId;
quint8 srcEndpointId;
quint16 clusterId;
quint8 transactionId;
quint8 options;
quint8 radius;
quint16 length;
};
struct zstackSetChannelStruct
{
quint8 isPrimary;
quint32 channel;
};
struct zstackNvReadStruct
{
quint16 id;
quint8 offset;
};
struct zstackNvReplyStruct
{
quint8 status;
quint8 length;
};
struct zstackNvWriteStruct
{
quint16 id;
quint8 offset;
quint8 length;
};
struct zstackReadConfigurationStruct
{
quint8 status;
quint8 id;
quint8 length;
};
struct zstackWriteConfigurationStruct
{
quint8 id;
quint8 length;
};
struct zstackDataConfirmStruct
{
quint8 status;
quint8 endpointId;
quint8 transactionId;
};
struct zstackIncomingMessageStruct
{
quint16 groupId;
quint16 clusterId;
quint16 srcAddress;
quint8 srcEndpointId;
quint8 dstEndpointId;
quint8 broadcast;
quint8 linkQuality;
quint8 security;
quint32 timestamp;
quint8 transactionId;
quint8 length;
};
struct zstackExtendedMessageStruct
{
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 zstackZdoMessageStruct
{
quint16 srcAddress;
quint8 broadcast;
quint16 clusterId;
quint8 security;
quint8 transactionId;
quint16 dstAddress;
};
struct zstackDeviceLeaveStruct
{
quint16 networkAddress;
quint64 ieeeAddress;
quint8 request;
quint8 remove;
quint8 rejoin;
};
#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