forked from dresden-elektronik/deconz-rest-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ias_ace.cpp
159 lines (137 loc) · 4.08 KB
/
ias_ace.cpp
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
#include <QString>
#include <QVariantMap>
#include "de_web_plugin.h"
#include "de_web_plugin_private.h"
#include "json.h"
// server send
#define CMD_ARM_RESPONSE 0x00
#define CMD_GET_ZONE_ID_MAP_RESPONSE 0x01
#define CMD_GET_ZONE_INFORMATION_RESPONSE 0x02
#define CMD_ZONE_STATUS_CHANGED 0x03
#define CMD_PANEL_STATUS_CHANGED 0x04
#define CMD_GET_PANEL_STATUS_RESPONSE 0x05
#define CMD_SET_BYPASSED_ZONE_LIST 0x06
#define CMD_BYPASS_RESPONSE 0x07
#define CMD_GET_ZONE_STATUS_RESPONSE 0x08
// server receive
#define CMD_ARM 0x00
#define CMD_BYPASS 0x01
#define CMD_EMERGENCY 0x02
#define CMD_FIRE 0x03
#define CMD_PANIC 0x04
#define CMD_GET_ZONE_ID_MAP 0x05
#define CMD_GET_ZONE_INFORMATION 0x06
#define CMD_GET_PANEL_STATUS 0x07
#define CMD_GET_BYPASSED_ZONE_LIST 0x08
#define CMD_GET_ZONE_STATUS 0x09
void DeRestPluginPrivate::handleIasAceClusterIndication(const deCONZ::ApsDataIndication &ind, deCONZ::ZclFrame &zclFrame)
{
if (zclFrame.isDefaultResponse())
{
return;
}
QDataStream stream(zclFrame.payload());
stream.setByteOrder(QDataStream::LittleEndian);
if ((zclFrame.frameControl() & deCONZ::ZclFCDirectionServerToClient))
{
return;
}
if (zclFrame.commandId() == CMD_ARM)
{
quint8 armMode;
QString code;
quint8 zoneId;
stream >> armMode;
if (zclFrame.payload().length() == 6)
{
quint8 codeTemp;
stream >> codeTemp; // 0 for keyfobs or other devices not supporting any codes
code = codeTemp;
}
else
{
// Not yet supported
return;
}
stream >> zoneId;
if (armMode <= 3)
{
sendArmResponse(ind, zclFrame, armMode);
}
return;
}
else if (zclFrame.commandId() == CMD_EMERGENCY)
{
}
else if (zclFrame.commandId() == CMD_FIRE)
{
}
else if (zclFrame.commandId() == CMD_PANIC)
{
}
else if (zclFrame.commandId() == CMD_GET_ZONE_ID_MAP)
{
}
else if (zclFrame.commandId() == CMD_GET_ZONE_INFORMATION)
{
}
else if (zclFrame.commandId() == CMD_GET_PANEL_STATUS)
{
}
else if (zclFrame.commandId() == CMD_GET_BYPASSED_ZONE_LIST)
{
}
else if (zclFrame.commandId() == CMD_GET_ZONE_STATUS)
{
}
if (!(zclFrame.frameControl() & deCONZ::ZclFCDisableDefaultResponse))
{
sendZclDefaultResponse(ind, zclFrame, deCONZ::ZclSuccessStatus);
}
}
void DeRestPluginPrivate::sendArmResponse(const deCONZ::ApsDataIndication &ind, deCONZ::ZclFrame &zclFrame, quint8 armMode)
{
quint8 armNotification = 0xFF;
if (armMode <= 3)
{
// 0: All zones disarmed, 1: Only day/home zones armed, 2: Only night/sleep zones armed, 3: All zones armed
armNotification = armMode;
}
else if (armMode > 3 && armMode <= 6)
{
// 4 - 6 not supported
return;
}
else
{
// invalid
return;
}
deCONZ::ApsDataRequest req;
deCONZ::ZclFrame outZclFrame;
req.setProfileId(ind.profileId());
req.setClusterId(ind.clusterId());
req.setDstAddressMode(ind.srcAddressMode());
req.dstAddress() = ind.srcAddress();
req.setDstEndpoint(ind.srcEndpoint());
req.setSrcEndpoint(endpoint());
outZclFrame.setSequenceNumber(zclFrame.sequenceNumber());
outZclFrame.setCommandId(CMD_ARM_RESPONSE);
outZclFrame.setFrameControl(deCONZ::ZclFCClusterCommand |
deCONZ::ZclFCDirectionServerToClient |
deCONZ::ZclFCDisableDefaultResponse);
{ // payload
QDataStream stream(&outZclFrame.payload(), QIODevice::WriteOnly);
stream.setByteOrder(QDataStream::LittleEndian);
stream << armNotification;
}
{ // ZCL frame
QDataStream stream(&req.asdu(), QIODevice::WriteOnly);
stream.setByteOrder(QDataStream::LittleEndian);
outZclFrame.writeToStream(stream);
}
if (apsCtrl && apsCtrl->apsdeDataRequest(req) != deCONZ::Success)
{
DBG_Printf(DBG_INFO_L2, "[IAS ACE] - Failed to send IAS ACE arm reponse.\n");
}
}