summaryrefslogtreecommitdiff
path: root/digital/zigbit/bitcloud/stack/Components/ZCL/include/zclZllOnOffCluster.h
blob: f16eaf1e615aed2612a61f9cc1d33b5ec4cd9fb4 (plain)
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
/***************************************************************************//**
  \file zclZllOnOffCluster.h

  \brief
    The header file describes the ZLL On/Off Cluster and its interface

  \author
    Atmel Corporation: http://www.atmel.com \n
    Support email: avr@atmel.com

  Copyright (c) 2008-2011, Atmel Corporation. All rights reserved.
  Licensed under Atmel's Limited License Agreement (BitCloudTM).

  \internal
    History:
    21.03.11 A. Taradov - Created.
*******************************************************************************/

#ifndef _ZCLZLLONOFFCLUSTER_H
#define	_ZCLZLLONOFFCLUSTER_H

/*!
Attributes and commands for determining basic information about a device,
setting user device information such as location, enabling a device and resetting it
to factory defaults.
*/

/*******************************************************************************
                   Includes section
*******************************************************************************/

#include <zcl.h>
#include <clusters.h>

/*******************************************************************************
                   Define(s) section
*******************************************************************************/

#define ZCL_ON_OFF_CLUSTER_ACCEPT_ONLY_WHEN_ON 0x01

/**
 * \brief On/Off Cluster server attributes amount
*/

#define ZCL_ONOFF_CLUSTER_SERVER_ATTRIBUTES_AMOUNT 4

/**
 * \brief On/Off Cluster client attributes amount. Clinet doesn't have attributes.
*/

#define ZCL_ONOFF_CLUSTER_CLIENT_ATTRIBTUES_AMOUNT 0

/**
 * \brief On/Off Cluster commands amount
*/

#define ZCL_ONOFF_CLUSTER_COMMANDS_AMOUNT 6

/**
 * \brief On/Off Cluster server's attributes identifiers
*/

#define ZCL_ONOFF_CLUSTER_ONOFF_SERVER_ATTRIBUTE_ID  CCPU_TO_LE16(0x0000)
#define ZCL_ONOFF_CLUSTER_GLOBAL_SCENE_CONTROL_SERVER_ATTRIBUTE_ID  CCPU_TO_LE16(0x4000)
#define ZCL_ONOFF_CLUSTER_ON_TIME_SERVER_ATTRIBUTE_ID  CCPU_TO_LE16(0x4001)
#define ZCL_ONOFF_CLUSTER_OFF_WAIT_TIME_SERVER_ATTRIBUTE_ID  CCPU_TO_LE16(0x4002)

/**
 * \brief On/Off Cluster client's command identifiers
*/

#define ZCL_ONOFF_CLUSTER_OFF_COMMAND_ID 0x00
#define ZCL_ONOFF_CLUSTER_ON_COMMAND_ID 0x01
#define ZCL_ONOFF_CLUSTER_TOGGLE_COMMAND_ID 0x02
#define ZCL_ONOFF_CLUSTER_OFF_WITH_EFFECT_COMMAND_ID 0x40
#define ZCL_ONOFF_CLUSTER_ON_WITH_RECALL_GLOBAL_SCENE_COMMAND_ID 0x41
#define ZCL_ONOFF_CLUSTER_ON_WITH_TIMED_OFF_COMMAND_ID 0x42

/**
 * \brief On/Off Cluster server define attributes macros
*/

#define ZCL_DEFINE_ONOFF_CLUSTER_SERVER_ATTRIBUTES(min, max) \
    DEFINE_REPORTABLE_ATTRIBUTE(onOff, ZCL_READONLY_ATTRIBUTE, ZCL_ONOFF_CLUSTER_ONOFF_SERVER_ATTRIBUTE_ID, ZCL_BOOLEAN_DATA_TYPE_ID, min, max), \
    DEFINE_ATTRIBUTE(globalSceneControl, ZCL_READONLY_ATTRIBUTE, ZCL_ONOFF_CLUSTER_GLOBAL_SCENE_CONTROL_SERVER_ATTRIBUTE_ID, ZCL_BOOLEAN_DATA_TYPE_ID), \
    DEFINE_ATTRIBUTE(onTime, ZCL_READONLY_ATTRIBUTE, ZCL_ONOFF_CLUSTER_ON_TIME_SERVER_ATTRIBUTE_ID, ZCL_U16BIT_DATA_TYPE_ID), \
    DEFINE_ATTRIBUTE(offWaitTime, ZCL_READONLY_ATTRIBUTE, ZCL_ONOFF_CLUSTER_OFF_WAIT_TIME_SERVER_ATTRIBUTE_ID, ZCL_U16BIT_DATA_TYPE_ID)

/**
 * \brief On/Off Cluster define commands macros
*/

#define ZCL_DEFINE_ONOFF_CLUSTER_COMMANDS(onCommandInd, offCommandInd, toggleCommandInd, offWithEffectInd, onWithRecallGlobalSceneInd, onWithTimedOffInd) \
    DEFINE_COMMAND(onCommand, ZCL_ONOFF_CLUSTER_ON_COMMAND_ID,  \
                     COMMAND_OPTIONS(CLIENT_TO_SERVER, ZCL_FRAME_CONTROL_DISABLE_DEFAULT_RESPONSE, ZCL_COMMAND_NO_ACK), \
                     onCommandInd), \
    DEFINE_COMMAND(offCommand, ZCL_ONOFF_CLUSTER_OFF_COMMAND_ID, \
                     COMMAND_OPTIONS(CLIENT_TO_SERVER, ZCL_FRAME_CONTROL_DISABLE_DEFAULT_RESPONSE, ZCL_COMMAND_NO_ACK), \
                     offCommandInd), \
    DEFINE_COMMAND(toggleCommand, ZCL_ONOFF_CLUSTER_TOGGLE_COMMAND_ID, \
                      COMMAND_OPTIONS(CLIENT_TO_SERVER, ZCL_FRAME_CONTROL_DISABLE_DEFAULT_RESPONSE, ZCL_COMMAND_NO_ACK), \
                     toggleCommandInd), \
    DEFINE_COMMAND(offWithEffectCommand, ZCL_ONOFF_CLUSTER_OFF_WITH_EFFECT_COMMAND_ID,  \
                     COMMAND_OPTIONS(CLIENT_TO_SERVER, ZCL_FRAME_CONTROL_DISABLE_DEFAULT_RESPONSE, ZCL_COMMAND_NO_ACK), \
                     offWithEffectInd), \
    DEFINE_COMMAND(onWithRecallGlobalSceneCommand, ZCL_ONOFF_CLUSTER_ON_WITH_RECALL_GLOBAL_SCENE_COMMAND_ID,  \
                     COMMAND_OPTIONS(CLIENT_TO_SERVER, ZCL_FRAME_CONTROL_DISABLE_DEFAULT_RESPONSE, ZCL_COMMAND_NO_ACK), \
                     onWithRecallGlobalSceneInd), \
    DEFINE_COMMAND(onWithTimedOffCommand, ZCL_ONOFF_CLUSTER_ON_WITH_TIMED_OFF_COMMAND_ID,  \
                     COMMAND_OPTIONS(CLIENT_TO_SERVER, ZCL_FRAME_CONTROL_DISABLE_DEFAULT_RESPONSE, ZCL_COMMAND_NO_ACK), \
                     onWithTimedOffInd)

/**
 * \brief On/Off Cluster definition macros
*/

#define ONOFF_CLUSTER_ZCL_CLIENT_CLUSTER_TYPE(clattributes, clcommands) \
{ \
   .id = ONOFF_CLUSTER_ID, \
   .options = \
   { \
     .type = ZCL_CLIENT_CLUSTER_TYPE, \
     .security = ZCL_NETWORK_KEY_CLUSTER_SECURITY, \
     .reserved = 0, \
   }, \
   .attributesAmount = ZCL_ONOFF_CLUSTER_CLIENT_ATTRIBTUES_AMOUNT, \
   .attributes = (uint8_t *)clattributes, \
   .commandsAmount = ZCL_ONOFF_CLUSTER_COMMANDS_AMOUNT, \
   .commands = (uint8_t *)clcommands \
}

#define ONOFF_CLUSTER_ZCL_SERVER_CLUSTER_TYPE(clattributes, clcommands) \
{ \
   .id = ONOFF_CLUSTER_ID, \
   .options = \
   { \
     .type = ZCL_SERVER_CLUSTER_TYPE, \
     .security = ZCL_NETWORK_KEY_CLUSTER_SECURITY, \
     .reserved = 0, \
   }, \
   .attributesAmount = ZCL_ONOFF_CLUSTER_SERVER_ATTRIBUTES_AMOUNT, \
   .attributes = (uint8_t *)clattributes, \
   .commandsAmount = ZCL_ONOFF_CLUSTER_COMMANDS_AMOUNT, \
   .commands = (uint8_t *)clcommands \
}

#define DEFINE_ONOFF_CLUSTER(cltype, clattributes, clcommands) \
    ONOFF_CLUSTER_##cltype(clattributes, clcommands)

/******************************************************************************
                    Types section
******************************************************************************/

BEGIN_PACK

/**
 * \brief On/Off Cluster server's attributes
*/

typedef struct PACK
{
  struct PACK
  {
    ZCL_AttributeId_t id;
    uint8_t type;
    uint8_t properties;
    bool value;
    ZCL_ReportTime_t  reportCounter;              //!<For internal use only
    ZCL_ReportTime_t  minReportInterval;          //!<Minimum reporting interval field value
    ZCL_ReportTime_t  maxReportInterval;          //!<Maximum reporting interval field value
    bool              reportableChange;        //!<Reporting change field value
    ZCL_ReportTime_t  timeoutPeriod;              //!<Timeout period field value
  } onOff;

  struct PACK
  {
    ZCL_AttributeId_t id;
    uint8_t type;
    uint8_t properties;
    bool value;
  } globalSceneControl;

  struct PACK
  {
    ZCL_AttributeId_t id;
    uint8_t type;
    uint8_t properties;
    uint16_t value;
  } onTime;

  struct PACK
  {
    ZCL_AttributeId_t id;
    uint8_t type;
    uint8_t properties;
    uint16_t value;
  } offWaitTime;
} ZCL_OnOffClusterServerAttributes_t;

/**
 *   \brief On/Off Cluster extension field set
 */
typedef struct PACK
{
    uint16_t clusterId;
    uint8_t length;
    bool onOffValue;
} ZCL_OnOffClusterExtensionFieldSet_t;

typedef struct PACK
{
  uint8_t effectIdentifier;
  uint8_t effectVariant;
} ZCL_OffWithEffect_t;

typedef struct PACK
{
  uint8_t onOffControl;
  uint16_t onTime;
  uint16_t offWaitTime;
} ZCL_OnWithTimedOff_t;

END_PACK

/**
 * \brief On/Off Cluster clients's commands.
*/

typedef struct
{
  struct
  {
    ZCL_CommandId_t id;
    ZclCommandOptions_t options;
    ZCL_Status_t(*onCommand)(ZCL_Addressing_t *addressing, uint8_t payloadLength, uint8_t * payload);
  } onCommand;

  struct
  {
    ZCL_CommandId_t id;
    ZclCommandOptions_t options;
    ZCL_Status_t(*offCommand)(ZCL_Addressing_t *addressing, uint8_t payloadLength, uint8_t * payload);
  } offCommand;

  struct
  {
    ZCL_CommandId_t id;
    ZclCommandOptions_t options;
    ZCL_Status_t(*toggleCommand)(ZCL_Addressing_t *addressing, uint8_t payloadLength, uint8_t * payload);
  } toggleCommand;

  struct
  {
    ZCL_CommandId_t id;
    ZclCommandOptions_t options;
    ZCL_Status_t(*offWithEffectCommand)(ZCL_Addressing_t *addressing, uint8_t payloadLength, ZCL_OffWithEffect_t * payload);
  } offWithEffectCommand;

  struct
  {
    ZCL_CommandId_t id;
    ZclCommandOptions_t options;
    ZCL_Status_t(*onWithRecallGlobalSceneCommand)(ZCL_Addressing_t *addressing, uint8_t payloadLength, uint8_t * payload);
  } onWithRecallGlobalSceneCommand;

  struct
  {
    ZCL_CommandId_t id;
    ZclCommandOptions_t options;
    ZCL_Status_t(*onWithTimedOffCommand)(ZCL_Addressing_t *addressing, uint8_t payloadLength, ZCL_OnWithTimedOff_t * payload);
  } onWithTimedOffCommand;

} ZCL_OnOffClusterCommands_t;

#define DEFINE_ONOFF_CLUSTER_EXTENSION_FIELD_SET(value) \
    .clusterId = ONOFF_CLUSTER_ID, \
    .length = sizeof(uint8_t), \
    .onOffValue = value

#endif	/* _ZCLZLLONOFFCLUSTER_H */