summaryrefslogtreecommitdiff
path: root/digital/zigbit/bitcloud/stack/Components/ZCL/include/zclPriceCluster.h
blob: 0769596b40e3c62beaf43dc3cd52e0303cb5914f (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
/************************************************************************//**
  \file zclPriceCluster.h

  \brief
    The header file describes the Price Cluster.

  \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:
    05.02.09 A. Mandychev - Changed.
******************************************************************************/

#ifndef _ZCLPRICECLUSTER_H
#define _ZCLPRICECLUSTER_H

/******************************************************************************
                        Includes section
******************************************************************************/
#include <zcl.h>
#include <clusters.h>

/******************************************************************************
                        Defines section
******************************************************************************/
/**
\brief Macros defines duration of Publish Price command,
 * which means 'until change'.
 * According to ZB AMI Spec r15, D.4.2.4.1.1, page 197.
*/
#define PUBLISH_PRICE_DURATION_UNTIL_CHANGED (0xFFFF)

/**
\brief Macros defines start time of Publish Price command,
 * which means 'now'.
 * According to ZB AMI Spec r15, D.4.2.4.1.1, page 197.
*/
#define PUBLISH_PRICE_START_TIME_NOW (0x0000)

/**
\brief Macros defines Price Ratio field special value,
 * which means 'not used'.
 * According to ZB AMI Spec r15, D.4.2.4.1.1, page 198.
*/
#define PUBLISH_PRICE_PRICE_RATIO_IS_NOT_USED (0xFF)

/**
\brief Macros defines Generation Price Ratio field special value,
 * which means 'not used'.
 * According to ZB AMI Spec r15, D.4.2.4.1.1, page 198.
*/
#define PUBLISH_PRICE_GENERATION_PRICE_RATIO_IS_NOT_USED (0xFF)

/**
\brief Macros defines Generation Price field special value,
 * which means 'not used'.
 * According to ZB AMI Spec r15, D.4.2.4.1.1, page 198.
*/
#define PUBLISH_PRICE_GENERATION_PRICE_IS_NOT_USED (0xFFFFFFFF)

/**
\brief Macros defines Number Of Block Thresholds field special value,
 * which means 'not used'.
 * According to ZigBee-095310r23ZB, page 65.
*/
#define PUBLISH_NUMBER_OF_BLOCK_THRESHOLDS_IS_NOT_USED (0xFF)

/**
\brief Macros defines Price Control field special value,
 * which means 'not used'.
 * According to ZigBee-095310r23ZB, page 65.
*/
#define PUBLISH_PRICE_CONTROL_IS_NOT_USED (0x00)

/**
\brief Macros defines Standing Charge field special value,
 * which means 'not used'.
 * According to ZigBee-095310r23ZB, page 65.
*/
#define PUBLISH_STANDING_CHARGE_IS_NOT_USED (0xFFFFFFFF)

/**
 * \brief Price Server Cluster attributes amount.
*/
#define PRICE_CLUSTER_SERVER_ATTRIBUTES_AMOUNT     0

/**
 * \brief Price Client Cluster attributes amount.
*/
#define PRICE_CLUSTER_CLIENT_ATTRIBUTES_AMOUNT     0

/**
 * \brief Price Client Cluster commands amount.
*/
#define PRICE_CLUSTER_COMMANDS_AMOUNT  3

/**
 * \brief Price Server Cluster commands identifiers.
*/
#define PUBLISH_PRICE_COMMAND_ID          0x00

/**
 * \brief Price Client Cluster commands identifiers.
*/
#define GET_CURRENT_PRICE_COMMAND_ID      0x00
#define GET_SCHEDULED_PRICES_COMMAND_ID   0x01

#define RATE_LABEL_MAX_LEN 12

/*
#define DEMAND_RESPONSE_CLUSTER_SERVER_COMMANDS(publishPriceInd) \
  DEFINE_COMMAND(publishPriceCommand, 0x00, COMMAND_OPTIONS(SERVER_TO_CLIENT), publishPriceInd)


#define DEMAND_RESPONSE_CLUSTER_CLIENT_COMMANDS(getCurrentPriceInd) \
  DEFINE_COMMAND(getCurrentPriceCommand, 0x00, COMMAND_OPTIONS(CLIENT_TO_SERVER), getCurrentPriceInd)
*/

#define PRICE_CLUSTER_COMMANDS(getCurrentPriceInd, publishPriceInd, getScheduledPricesInd) \
    DEFINE_COMMAND(getCurrentPriceCommand, 0x00, COMMAND_OPTIONS(CLIENT_TO_SERVER, ZCL_THERE_IS_RELEVANT_RESPONSE, ZCL_COMMAND_ACK), getCurrentPriceInd), \
    DEFINE_COMMAND(publishPriceCommand, 0x00, COMMAND_OPTIONS(SERVER_TO_CLIENT, ZCL_THERE_IS_NO_RELEVANT_RESPONSE, ZCL_COMMAND_ACK), publishPriceInd), \
    DEFINE_COMMAND(getScheduledPricesCommand, GET_SCHEDULED_PRICES_COMMAND_ID, COMMAND_OPTIONS(CLIENT_TO_SERVER, ZCL_THERE_IS_RELEVANT_RESPONSE, ZCL_COMMAND_ACK), getScheduledPricesInd)

#define PRICE_CLUSTER_ZCL_CLIENT_CLUSTER_TYPE(clattributes, clcommands) \
  { \
    .id = PRICE_CLUSTER_ID, \
    .options = {.type = ZCL_CLIENT_CLUSTER_TYPE, .security = ZCL_APPLICATION_LINK_KEY_CLUSTER_SECURITY}, \
    .attributesAmount = PRICE_CLUSTER_CLIENT_ATTRIBUTES_AMOUNT, \
    .attributes = (uint8_t *)clattributes, \
    .commandsAmount = PRICE_CLUSTER_COMMANDS_AMOUNT, \
    .commands = (uint8_t *)clcommands \
  }

#define PRICE_CLUSTER_ZCL_SERVER_CLUSTER_TYPE(clattributes, clcommands) \
  { \
    .id = PRICE_CLUSTER_ID, \
    .options = {.type = ZCL_SERVER_CLUSTER_TYPE, .security = ZCL_APPLICATION_LINK_KEY_CLUSTER_SECURITY}, \
    .attributesAmount = PRICE_CLUSTER_SERVER_ATTRIBUTES_AMOUNT, \
    .attributes = (uint8_t *)clattributes, \
    .commandsAmount = PRICE_CLUSTER_COMMANDS_AMOUNT, \
    .commands = (uint8_t *)clcommands \
  }
#define DEFINE_PRICE_CLUSTER(cltype, clattributes, clcommands) PRICE_CLUSTER_##cltype(clattributes, clcommands)

/******************************************************************************
                    Types section
******************************************************************************/
BEGIN_PACK
/**
 * \brief Publish Price Command Payload format.
*/
typedef struct PACK
{
  uint32_t        providerId;
  uint8_t         rateLabelLength;
  uint8_t         rateLabel[RATE_LABEL_MAX_LEN];
  uint32_t        issuerEventId;
  ZCL_UTCTime_t   currentTime;
  uint8_t         unitOfMeasure;
  uint16_t        currency;
  struct PACK
  {
    LITTLE_ENDIAN_OCTET(2,(
      uint8_t priceTrailDigit : 4,
      uint8_t priceTier : 4
    ))
  } priceTrailDigitPriceTier;
  struct PACK
  {
    LITTLE_ENDIAN_OCTET(2,(
      uint8_t numberOfPriceTiers : 4,
      uint8_t registerTier : 4
    ))
  } numberOfPriceTiersRegisterTier;
  ZCL_UTCTime_t   startTime;
  uint16_t        durationInMinutes;
  uint32_t        price;
  uint8_t         priceRatio;
  uint32_t        generationPrice;
  uint8_t         generationPriceRatio;
  uint32_t        alternateCostDelivered;
  uint8_t         alternateCostUnit;
  uint8_t         alternateCostTrailingDigit;
  uint8_t         numberOfBlockThresholds;
  uint8_t         priceControl;
  uint32_t        standingCharge;
} ZCL_PublishPrice_t;

/**
 * \brief Get Current Price Command Payload format.
*/
typedef struct PACK
{
  LITTLE_ENDIAN_OCTET(2,(
    uint8_t requestorRxOnWhenIdle :1, //!<The requestor Rx On When Idle sub-field
    uint8_t reserved              :7  //!<Reserved field
  ))
} ZCL_GetCurrentPrice_t;

/**
 * \brief Get Scheduled Prices Command Payload format.
*/
typedef struct PACK
{
  ZCL_UTCTime_t   startTime;
  uint8_t         numberOfEvents;
} ZCL_GetScheduledPrices_t;
END_PACK


/**
 * \brief ZCL Price Cluster Commands
 */
typedef struct
{
  //! Get Current Price Command descriptor
  struct
  {
    ZCL_CommandId_t       id;       //!<Command Id (0x00)
    ZclCommandOptions_t   options;  //!<Command options
    /**
      \brief Command indication handler
      \param payloadLength - length of payload in cotets
      \param payload - payload
      \return none
    */
    ZCL_Status_t (*getCurrentPrice)(ZCL_Addressing_t *addressing, uint8_t payloadLength, ZCL_GetCurrentPrice_t *payload);
  } getCurrentPriceCommand;

  //! Get Scheduled Prices Command descriptor
  struct
  {
    ZCL_CommandId_t       id;       //!<Command Id (0x01)
    ZclCommandOptions_t   options;  //!<Command options
    /**
      \brief Command indication handler
      \param payloadLength - length of payload in octets
      \param payload - payload
      \return none
    */
    ZCL_Status_t (*getScheduledPrices)(ZCL_Addressing_t *addressing, uint8_t payloadLength, ZCL_GetScheduledPrices_t *payload);
  } getScheduledPricesCommand;

  //! Publish Price Command descriptor
  struct
  {
    ZCL_CommandId_t       id;       //!<Command Id (0x00)
    ZclCommandOptions_t   options;  //!<Command options
    /**
      \brief Command indication handler
      \param payloadLength - length of payload in cotets
      \param payload - payload
      \return none
    */
    ZCL_Status_t (*publishPrice)(ZCL_Addressing_t *addressing, uint8_t payloadLength, ZCL_PublishPrice_t *payload);
  } publishPriceCommand;

} ZCL_PriceClusterCommands_t;



#endif // _ZCLPRICECLUSTER_H