-
Notifications
You must be signed in to change notification settings - Fork 37
/
ZclApplianceControlServer.java
423 lines (385 loc) · 16.9 KB
/
ZclApplianceControlServer.java
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
/**
* This file is part of JEMMA - http://jemma.energy-home.org
* (C) Copyright 2013 Telecom Italia (http://www.telecomitalia.it)
*
* JEMMA is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License (LGPL) version 3
* or later as published by the Free Software Foundation, which accompanies
* this distribution and is available at http://www.gnu.org/licenses/lgpl.html
*
* JEMMA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License (LGPL) for more details.
*
*/
package org.energy_home.jemma.ah.zigbee.zcl.cluster.eh;
import java.util.HashMap;
import java.util.Iterator;
import org.energy_home.jemma.ah.cluster.zigbee.eh.ApplianceControlClient;
import org.energy_home.jemma.ah.cluster.zigbee.eh.ApplianceControlServer;
import org.energy_home.jemma.ah.cluster.zigbee.eh.SignalStateResponse;
import org.energy_home.jemma.ah.cluster.zigbee.eh.WriteAttributeRecord;
import org.energy_home.jemma.ah.hac.ApplianceException;
import org.energy_home.jemma.ah.hac.IEndPointRequestContext;
import org.energy_home.jemma.ah.hac.ServiceClusterException;
import org.energy_home.jemma.ah.internal.zigbee.ZclAttributeDescriptor;
import org.energy_home.jemma.ah.zigbee.IZclFrame;
import org.energy_home.jemma.ah.zigbee.ZCL;
import org.energy_home.jemma.ah.zigbee.ZclFrame;
import org.energy_home.jemma.ah.zigbee.ZigBeeDevice;
import org.energy_home.jemma.ah.zigbee.ZigBeeDeviceListener;
import org.energy_home.jemma.ah.zigbee.zcl.IZclAttributeDescriptor;
import org.energy_home.jemma.ah.zigbee.zcl.ZclException;
import org.energy_home.jemma.ah.zigbee.zcl.ZclValidationException;
import org.energy_home.jemma.ah.zigbee.zcl.lib.ZclServiceCluster;
import org.energy_home.jemma.ah.zigbee.zcl.lib.types.ZclAbstractDataType;
import org.energy_home.jemma.ah.zigbee.zcl.lib.types.ZclDataTypeBoolean;
import org.energy_home.jemma.ah.zigbee.zcl.lib.types.ZclDataTypeEnum8;
import org.energy_home.jemma.ah.zigbee.zcl.lib.types.ZclDataTypeI16;
import org.energy_home.jemma.ah.zigbee.zcl.lib.types.ZclDataTypeUI16;
import org.energy_home.jemma.ah.zigbee.zcl.lib.types.ZclDataTypeUI24;
import org.energy_home.jemma.ah.zigbee.zcl.lib.types.ZclDataTypeUI8;
public class ZclApplianceControlServer extends ZclServiceCluster implements ApplianceControlServer, ZigBeeDeviceListener {
public final static short CLUSTER_ID = 27;
final static HashMap attributesMapByName = new HashMap();
final static HashMap attributesMapById = new HashMap();
static {
attributesMapByName.put(ZclApplianceControlServer.ATTR_StartTime_NAME, new ZclAttributeDescriptor(0,
ZclApplianceControlServer.ATTR_StartTime_NAME, new ZclDataTypeUI16(), null, true, 1));
attributesMapByName.put(ZclApplianceControlServer.ATTR_FinishTime_NAME, new ZclAttributeDescriptor(1,
ZclApplianceControlServer.ATTR_FinishTime_NAME, new ZclDataTypeUI16(), null, true, 1));
attributesMapByName.put(ZclApplianceControlServer.ATTR_RemainingTime_NAME, new ZclAttributeDescriptor(2,
ZclApplianceControlServer.ATTR_RemainingTime_NAME, new ZclDataTypeUI16(), null, true, 1));
attributesMapByName.put(ATTR_CycleTarget0_NAME, new ZclAttributeDescriptor(4,
ATTR_CycleTarget0_NAME, new ZclDataTypeUI8(), null, true, 1));
attributesMapByName.put(ATTR_CycleTarget1_NAME, new ZclAttributeDescriptor(5,
ATTR_CycleTarget1_NAME, new ZclDataTypeUI8(), null, true, 1));
attributesMapByName.put(ATTR_TemperatureTarget0_NAME, new ZclAttributeDescriptor(6,
ATTR_TemperatureTarget0_NAME, new ZclDataTypeI16(), null, true, 1));
attributesMapByName.put(ATTR_TemperatureTarget1_NAME, new ZclAttributeDescriptor(7,
ATTR_TemperatureTarget1_NAME, new ZclDataTypeI16(), null, true, 1));
attributesMapByName.put(ATTR_Spin_NAME, new ZclAttributeDescriptor(10, //spin attribute id: 0x000a
ATTR_Spin_NAME, new ZclDataTypeI16(), null, true, 1));
attributesMapByName.put(ATTR_SuperCoolMode_NAME, new ZclAttributeDescriptor(11, //SuperCoolMode attribute id: 0x000b
ATTR_SuperCoolMode_NAME, new ZclDataTypeBoolean(), null, true, 1));
attributesMapByName.put(ATTR_SuperFreezeMode_NAME, new ZclAttributeDescriptor(12, //SuperFreezeMode attribute id: 0x000c
ATTR_SuperFreezeMode_NAME, new ZclDataTypeBoolean(), null, true, 1));
attributesMapByName.put(ATTR_NormalMode_NAME, new ZclAttributeDescriptor(13, //NormalMode attribute id: 0x000d
ATTR_NormalMode_NAME, new ZclDataTypeBoolean(), null, true, 1));
attributesMapByName.put(ATTR_EcoMode_NAME, new ZclAttributeDescriptor(14, //EcoMode attribute id: 0x000e
ATTR_EcoMode_NAME, new ZclDataTypeBoolean(), null, true, 1));
attributesMapByName.put(ATTR_HolidayMode_NAME, new ZclAttributeDescriptor(15, //EcoMode attribute id: 0x000f
ATTR_HolidayMode_NAME, new ZclDataTypeBoolean(), null, true, 1));
attributesMapByName.put(ATTR_IceParty_NAME, new ZclAttributeDescriptor(20, //IceParty attribute id: 0x0014
ATTR_IceParty_NAME, new ZclDataTypeBoolean(), null, true, 1));
}
public ZclApplianceControlServer() throws ApplianceException {
super();
}
public boolean notifyZclFrame(short clusterId, IZclFrame zclFrame) throws Exception {
boolean handled;
handled = super.notifyZclFrame(clusterId, zclFrame);
if (handled) {
return handled;
}
int commandId = zclFrame.getCommandId();
if (zclFrame.isClientToServer()) {
throw new ZclValidationException("invalid direction field");
}
IZclFrame responseZclFrame = null;
ZigBeeDevice device = getZigBeeDevice();
int statusCode = ZCL.SUCCESS;
ApplianceControlClient c = ((ApplianceControlClient) getSinglePeerCluster((ApplianceControlClient.class.getName())));
switch (commandId) {
case 1:
responseZclFrame = parseSignalStateNotification(c, zclFrame);
break;
default:
throw new ZclException(ZCL.UNSUP_CLUSTER_COMMAND);
}
if (responseZclFrame == null) {
if (!zclFrame.isDefaultResponseDisabled()) {
responseZclFrame = getDefaultResponse(zclFrame, statusCode);
}
else {
return true;
}
}
if (!(responseZclFrame == null)) {
device.post(ZclApplianceControlServer.CLUSTER_ID, responseZclFrame);
return true;
}
return false;
}
protected int getClusterId() {
return CLUSTER_ID;
}
protected IZclAttributeDescriptor getAttributeDescriptor(String name) {
return ((IZclAttributeDescriptor) attributesMapByName.get(name));
}
protected IZclAttributeDescriptor getAttributeDescriptor(int id) {
Iterator iterator = attributesMapByName.values().iterator();
// FIXME: generate it and optimize!!!!
for (; iterator.hasNext();) {
IZclAttributeDescriptor attributeDescriptor = (IZclAttributeDescriptor) iterator.next();
if (attributeDescriptor.zclGetId() == id)
return attributeDescriptor;
}
return null;
}
public void execCommandExecution(short CommandId, IEndPointRequestContext context) throws ApplianceException,
ServiceClusterException {
int size = 0;
size += ZclDataTypeEnum8.zclSize(CommandId);
ZclFrame zclFrame = new ZclFrame(1, size);
zclFrame.setCommandId(0);
ZclDataTypeEnum8.zclSerialize(zclFrame, CommandId);
issueExec(zclFrame, 11, context);
}
public SignalStateResponse execSignalState(IEndPointRequestContext context) throws ApplianceException, ServiceClusterException {
ZclFrame zclFrame = new ZclFrame(1);
zclFrame.setCommandId(1);
IZclFrame zclResponseFrame = issueExec(zclFrame, 0, context);
return (ZclSignalStateResponse.zclParse(zclResponseFrame));
}
public void execWriteFunctions(WriteAttributeRecord[] WriteAttributeRecords, IEndPointRequestContext context)
throws ApplianceException, ServiceClusterException {
int size = 255;
ZclFrame zclFrame = new ZclFrame(1, size);
zclFrame.setCommandId(2);
for (int i = 0; i < WriteAttributeRecords.length; i++) {
IZclAttributeDescriptor attributeDescriptor = getAttributeDescriptor(WriteAttributeRecords[i].name);
zclFrame.appendUInt16(attributeDescriptor.zclGetId());
ZclAbstractDataType zclDataType = attributeDescriptor.zclGetDataType();
zclFrame.appendUInt8(zclDataType.zclGetDataType());
zclDataType.zclObjectSerialize(zclFrame, WriteAttributeRecords[i].value);
}
zclFrame.shrink();
issueExec(zclFrame, 11, context);
}
public void execOverloadPauseResume(IEndPointRequestContext context) throws ApplianceException, ServiceClusterException {
ZclFrame zclFrame = new ZclFrame(1);
zclFrame.setCommandId(3);
issueExec(zclFrame, 11, context);
}
public void execOverloadPause(IEndPointRequestContext context) throws ApplianceException, ServiceClusterException {
ZclFrame zclFrame = new ZclFrame(1);
zclFrame.setCommandId(4);
issueExec(zclFrame, 11, context);
}
public void execOverloadWarning(short WarningEvent, IEndPointRequestContext context) throws ApplianceException,
ServiceClusterException {
int size = 0;
size += ZclDataTypeEnum8.zclSize(WarningEvent);
ZclFrame zclFrame = new ZclFrame(1, size);
zclFrame.setCommandId(5);
ZclDataTypeEnum8.zclSerialize(zclFrame, WarningEvent);
issueExec(zclFrame, 11, context);
}
protected IZclFrame parseSignalStateNotification(ApplianceControlClient o, IZclFrame zclFrame) throws ApplianceException,
ServiceClusterException {
short ApplianceStatus = ZclDataTypeEnum8.zclParse(zclFrame);
short RemoteEnableFlags = ZclDataTypeUI8.zclParse(zclFrame);
int ApplianceStatus2 = ZclDataTypeUI24.zclParse(zclFrame);
o.execSignalStateNotification(ApplianceStatus, RemoteEnableFlags, ApplianceStatus2, endPoint.getDefaultRequestContext());
return null;
}
public int getStartTime(IEndPointRequestContext context) throws ApplianceException, ServiceClusterException {
if (context != null) {
Integer objectResult = null;
objectResult = ((Integer) getValidCachedAttributeObject(0, context.getMaxAgeForAttributeValues()));
if (objectResult != null) {
return objectResult.intValue();
}
}
IZclFrame zclFrame = readAttribute(0, context);
int v = ZclDataTypeUI16.zclParse(zclFrame);
setCachedAttributeObject(0, new Integer(v));
return v;
}
public int getFinishTime(IEndPointRequestContext context) throws ApplianceException, ServiceClusterException {
if (context != null) {
Integer objectResult = null;
objectResult = ((Integer) getValidCachedAttributeObject(1, context.getMaxAgeForAttributeValues()));
if (objectResult != null) {
return objectResult.intValue();
}
}
IZclFrame zclFrame = readAttribute(1, context);
int v = ZclDataTypeUI16.zclParse(zclFrame);
setCachedAttributeObject(1, new Integer(v));
return v;
}
public int getRemainingTime(IEndPointRequestContext context) throws ApplianceException, ServiceClusterException {
if (context != null) {
Integer objectResult = null;
objectResult = ((Integer) getValidCachedAttributeObject(2, context.getMaxAgeForAttributeValues()));
if (objectResult != null) {
return objectResult.intValue();
}
}
IZclFrame zclFrame = readAttribute(2, context);
int v = ZclDataTypeUI16.zclParse(zclFrame);
setCachedAttributeObject(2, new Integer(v));
return v;
}
public short getCycleTarget0(IEndPointRequestContext context) throws ApplianceException, ServiceClusterException {
if (context != null) {
Short objectResult = null;
objectResult = ((Short) getValidCachedAttributeObject(4, context.getMaxAgeForAttributeValues()));
if (objectResult != null) {
return objectResult.shortValue();
}
}
IZclFrame zclFrame = readAttribute(4, context);
short v = ZclDataTypeUI8.zclParse(zclFrame);
setCachedAttributeObject(4, new Short(v));
return v;
}
public short getCycleTarget1(IEndPointRequestContext context) throws ApplianceException, ServiceClusterException {
if (context != null) {
Short objectResult = null;
objectResult = ((Short) getValidCachedAttributeObject(5, context.getMaxAgeForAttributeValues()));
if (objectResult != null) {
return objectResult.shortValue();
}
}
IZclFrame zclFrame = readAttribute(5, context);
short v = ZclDataTypeUI8.zclParse(zclFrame);
setCachedAttributeObject(5, new Short(v));
return v;
}
public int getTemperatureTarget0(IEndPointRequestContext context) throws ApplianceException, ServiceClusterException {
if (context != null) {
Integer objectResult = null;
objectResult = ((Integer) getValidCachedAttributeObject(6, context.getMaxAgeForAttributeValues()));
if (objectResult != null) {
return objectResult.intValue();
}
}
IZclFrame zclFrame = readAttribute(6, context);
int v = ZclDataTypeI16.zclParse(zclFrame);
setCachedAttributeObject(6, new Integer(v));
return v;
}
public int getTemperatureTarget1(IEndPointRequestContext context) throws ApplianceException, ServiceClusterException {
if (context != null) {
Integer objectResult = null;
objectResult = ((Integer) getValidCachedAttributeObject(7, context.getMaxAgeForAttributeValues()));
if (objectResult != null) {
return objectResult.intValue();
}
}
IZclFrame zclFrame = readAttribute(7, context);
int v = ZclDataTypeI16.zclParse(zclFrame);
setCachedAttributeObject(7, new Integer(v));
return v;
}
@Override
public short getSpin(IEndPointRequestContext context) throws ApplianceException, ServiceClusterException {
if (context != null) {
Short objectResult = null;
objectResult = ((Short) getValidCachedAttributeObject(10 //spin attribute ID: 0x000a
, context.getMaxAgeForAttributeValues()));
if (objectResult != null) {
return objectResult.shortValue();
}
}
IZclFrame zclFrame = readAttribute(10, context);//spin attribute ID: 0x000a
Integer v = ZclDataTypeUI16.zclParse(zclFrame);
setCachedAttributeObject(10, v.shortValue());
return v.shortValue();
}
@Override
public boolean getEcoMode(IEndPointRequestContext context) throws ApplianceException, ServiceClusterException {
if (context != null) {
Boolean objectResult = null;
objectResult = ((Boolean) getValidCachedAttributeObject(14 //EcoMode attribute ID: 0x000e
, context.getMaxAgeForAttributeValues()));
if (objectResult != null) {
return objectResult;
}
}
IZclFrame zclFrame = readAttribute(14, context);//EcoMode attribute ID: 0x000e
Boolean v = ZclDataTypeBoolean.zclParse(zclFrame);
setCachedAttributeObject(14, v);
return v;
}
@Override
public boolean getNormalMode(IEndPointRequestContext context) throws ApplianceException, ServiceClusterException {
if (context != null) {
Boolean objectResult = null;
objectResult = ((Boolean) getValidCachedAttributeObject(13 //NormalMode attribute ID: 0x000d
, context.getMaxAgeForAttributeValues()));
if (objectResult != null) {
return objectResult;
}
}
IZclFrame zclFrame = readAttribute(13, context);//NormalMode attribute ID: 0x000d
Boolean v = ZclDataTypeBoolean.zclParse(zclFrame);
setCachedAttributeObject(13, v);
return v;
}
@Override
public boolean getHolidayMode(IEndPointRequestContext context) throws ApplianceException, ServiceClusterException {
if (context != null) {
Boolean objectResult = null;
objectResult = ((Boolean) getValidCachedAttributeObject(15 //HolidayMode attribute ID: 0x000f
, context.getMaxAgeForAttributeValues()));
if (objectResult != null) {
return objectResult;
}
}
IZclFrame zclFrame = readAttribute(15, context);//HolidayMode attribute ID: 0x000f
Boolean v = ZclDataTypeBoolean.zclParse(zclFrame);
setCachedAttributeObject(15, v);
return v;
}
@Override
public boolean getIceParty(IEndPointRequestContext context) throws ApplianceException, ServiceClusterException {
if (context != null) {
Boolean objectResult = null;
objectResult = ((Boolean) getValidCachedAttributeObject(20 //IceParty attribute ID: 0x0014
, context.getMaxAgeForAttributeValues()));
if (objectResult != null) {
return objectResult;
}
}
IZclFrame zclFrame = readAttribute(20, context);//IceParty attribute ID: 0x0014
Boolean v = ZclDataTypeBoolean.zclParse(zclFrame);
setCachedAttributeObject(20, v);
return v;
}
@Override
public boolean getSuperCoolMode(IEndPointRequestContext context) throws ApplianceException, ServiceClusterException {
if (context != null) {
Boolean objectResult = null;
objectResult = ((Boolean) getValidCachedAttributeObject(11 //SuperCool attribute ID: 0x000b
, context.getMaxAgeForAttributeValues()));
if (objectResult != null) {
return objectResult;
}
}
IZclFrame zclFrame = readAttribute(11, context); //SuperCool attribute ID: 0x000b
Boolean v = ZclDataTypeBoolean.zclParse(zclFrame);
setCachedAttributeObject(11, v);
return v;
}
@Override
public boolean getSuperFreezeMode(IEndPointRequestContext context) throws ApplianceException,
ServiceClusterException {
if (context != null) {
Boolean objectResult = null;
objectResult = ((Boolean) getValidCachedAttributeObject(12 //SuperFreeze attribute ID: 0x000c
, context.getMaxAgeForAttributeValues()));
if (objectResult != null) {
return objectResult;
}
}
IZclFrame zclFrame = readAttribute(12, context); //SuperFreeze attribute ID: 0x000c
Boolean v = ZclDataTypeBoolean.zclParse(zclFrame);
setCachedAttributeObject(12,v);
return v;
}
}