summaryrefslogtreecommitdiffhomepage
path: root/digital/zigbit/bitcloud/stack/Components/ZCL/include/zclTimeCluster.h
blob: d2e30218529adc619d025b0ef1c3eda4e00369be (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
/***************************************************************************//**
  \file zclTimeCluster.h

  \brief
    The header file describes the ZCL Time Cluster and its interface

    The file describes the types and interface of the ZCL Time 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:
    02.01.09 A. Potashov - Created.
*******************************************************************************/
#ifndef _ZCLTIMECLUSTER_H
#define _ZCLTIMECLUSTER_H

/*!
This cluster provides a basic interface to a real-time clock. The clock time may be
read and also written, in order to synchronize the clock (as close as practical) to a
time standard. This time standard is the number of seconds since 0 hrs 0 mins 0
sec on 1st January 2000 UTC (Universal Coordinated Time).
*/

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

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


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

/***************************************************************************//**
  \brief ZCL Time Cluster server side commands amount
*******************************************************************************/
#define ZCL_TIME_CLUSTER_SERVER_ATTRIBUTES_AMOUNT      2
//The Time and TimeStatus attributes

/***************************************************************************//**
  \brief ZCL Time Cluster client side commands amount
*******************************************************************************/
#define ZCL_TIME_CLUSTER_CLIENT_ATTRIBUTES_AMOUNT      0
//There is no any attributes at client cluster side

/***************************************************************************//**
  \brief ZCL Time Cluster commands amount
*******************************************************************************/
#define ZCL_TIME_CLUSTER_COMMANDS_AMOUNT        0
//There is no any commands at client cluster side


//!ZCL Time Cluster server side Time attribute id
#define ZCL_TIME_CLUSTER_SERVER_TIME_ATTRIBUTE_ID             CCPU_TO_LE16(0x0000)
//!ZCL Time Cluster server side TimeStatus attribute id
#define ZCL_TIME_CLUSTER_SERVER_TIME_STATUS_ATTRIBUTE_ID      CCPU_TO_LE16(0x0001)
//!ZCL Time Cluster server side TimeZone attribute id
#define ZCL_TIME_CLUSTER_SERVER_TIME_ZONE_ATTRIBUTE_ID        CCPU_TO_LE16(0x0002)
//!ZCL Time Cluster server side DstStart attribute id
#define ZCL_TIME_CLUSTER_SERVER_DST_START_ATTRIBUTE_ID        CCPU_TO_LE16(0x0003)
//!ZCL Time Cluster server side DstEnd attribute id
#define ZCL_TIME_CLUSTER_SERVER_DST_END_ATRIBUTE_ID           CCPU_TO_LE16(0x0004)
//!ZCL Time Cluster server side DstShift attribute id
#define ZCL_TIME_CLUSTER_SERVER_DST_SHIFT_ATTRIBUTE_ID        CCPU_TO_LE16(0x0005)
//!ZCL Time Cluster server side StandardTime attribute id
#define ZCL_TIME_CLUSTER_SERVER_STANDARD_TIME_ATTRIBUTE_ID    CCPU_TO_LE16(0x0006)
//!ZCL Time Cluster server side LocalTime attribute id
#define ZCL__TIME_CLUSTER_SERVER_LOCAL_TIME_ATTRIBUTE_ID      CCPU_TO_LE16(0x0007)


/***************************************************************************//**
  \brief ZCL Time Cluster server side attributes defining macros

  This macros should be used for ZCL Time Cluster server side attributes defining.

  \return None

  \internal
  //The typical usage is:
  //Time Cluster server side related attributes
  ZCL_TimeClusterServerAttributes_t timeClusterAttributes = ZCL_DEFINE_TIME_CLUSTER_SERVER_ATTRIBUTES();
*******************************************************************************/
#define ZCL_DEFINE_TIME_CLUSTER_SERVER_ATTRIBUTES()                                                                 \
  DEFINE_ATTRIBUTE(time,       ZCL_READWRITE_ATTRIBUTE, ZCL_TIME_CLUSTER_SERVER_TIME_ATTRIBUTE_ID,         ZCL_UTC_TIME_DATA_TYPE_ID),      \
  DEFINE_ATTRIBUTE(timeStatus, ZCL_READWRITE_ATTRIBUTE, ZCL_TIME_CLUSTER_SERVER_TIME_STATUS_ATTRIBUTE_ID,  ZCL_8BIT_BITMAP_DATA_TYPE_ID)    \

/***************************************************************************//**
  \brief ZCL Time Cluster server side defining macros

  This macros should be used with #DEFINE_ZCL_TIME_CLUSTER_SERVER_ATTRIBUTES for
  ZCL Time Cluster server side defining in application.

  \param attributes - pointer to cluster server attributes (ZCL_TimeClusterServerAttributes_t)

  \return None

  \internal
  //The typical code is:
  //Time Cluster server side related attributes
  ZCL_TimeClusterServerAttributes_t timeClusterServerAttributes = DEFINE_ZCL_TIME_CLUSTER_SERVER_ATTRIBUTES();
  ZCL_Cluster_t myClusters[] =
  {
    ZCL_DEFINE_TIME_CLUSTER_SERVER(&timeClusterServerAttributes),
    //... Any other cluster defining ...
  }
*******************************************************************************/
#define TIME_CLUSTER_ZCL_SERVER_CLUSTER_TYPE(clattributes, clcommands)                                                    \
  {                                                                                                                       \
    .id = TIME_CLUSTER_ID,                                                                                                \
    .options = {.type = ZCL_SERVER_CLUSTER_TYPE, .security = ZCL_APPLICATION_LINK_KEY_CLUSTER_SECURITY},                  \
    .attributesAmount = ZCL_TIME_CLUSTER_SERVER_ATTRIBUTES_AMOUNT,                                                        \
    .attributes = (uint8_t *) clattributes,                                                                               \
    .commandsAmount = ZCL_TIME_CLUSTER_COMMANDS_AMOUNT,                                                                   \
    .commands = (uint8_t *) clcommands                                                                                    \
  }

/***************************************************************************//**
  \brief ZCL Time Cluster client side defining macros

  This macros should be used for ZCL Time Cluster client side defining in application.

  \return None

  \internal
  //The typical code is:
  ZCL_Cluster_t myClusters[] =
  {
    ZCL_DEFINE_TIME_CLUSTER_CLIENT(),
    //... Any other cluster defining ...
  }
*******************************************************************************/
#define TIME_CLUSTER_ZCL_CLIENT_CLUSTER_TYPE(clattributes, clcommands)                                                    \
  {                                                                                                                       \
    .id = TIME_CLUSTER_ID,                                                                                                \
    .options = {.type = ZCL_CLIENT_CLUSTER_TYPE, .security = ZCL_APPLICATION_LINK_KEY_CLUSTER_SECURITY },                 \
    .attributesAmount = ZCL_TIME_CLUSTER_CLIENT_ATTRIBUTES_AMOUNT,                                                        \
    .attributes = (uint8_t *) clattributes,                                                                               \
    .commandsAmount = ZCL_TIME_CLUSTER_COMMANDS_AMOUNT,                                                                   \
    .commands = (uint8_t *) clcommands                                                                                    \
  }

#define DEFINE_TIME_CLUSTER(cltype, clattributes, clcommands) TIME_CLUSTER_##cltype(clattributes, clcommands)

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

BEGIN_PACK
/***************************************************************************//**
  \brief
  ZCL Time Cluster attributes
*******************************************************************************/
typedef struct PACK
{
  /*!
  \brief Time attribute (R/W, M)

    The Time attribute is 32-bits in length and holds the time value of a real time
  clock. This attribute has data type UTCTime, but note that it may not actually be
  synchronised to UTC - see discussion of the TimeStatus attribute below.
    If the Master bit of the TimeStatus attribute has a value of 0, writing to this
  attribute shall set the real time clock to the written value, otherwise it cannot be
  written. The value 0xffffffff indicates an invalid time.
  */
  struct PACK
  {
    ZCL_AttributeId_t   id;           //!<Attribute Id (0x0000)
    uint8_t             type;         //!<Attribute type (UTCTime - 32-bit) (typeId = 0xe2, #ZCL_UTC_TIME_DATA_TYPE_ID)
    uint8_t             properties;   //!<Attribute properties bitmask
    ZCL_UTCTime_t       value;        //!<Attribute value (default none)
  } time;

  /*!
  \brief TimeStatus attribute (R/W, M)

    The Master and Synchronized bits together provide information on how closely
  the Time attribute conforms to the time standard.
    The Master bit specifies whether the real time clock corresponding to the Time
  attribute is internally set to the time standard. This bit is not writeable
  if a value is written to the TimeStatus attribute, this bit does not change.
    The Synchronized bit specifies whether Time has been set over the network to
  synchronize it (as close as may be practical) to the time standard. This
  bit must be explicitly written to indicate this i.e. it is not set automatically on
  writing to the Time attribute. If the Master bit is 1, the value of this bit is 0.
    If both the Master and Synchronized bits are 0, the real time clock has no defined
  relationship to the time standard (e.g. it may record the number of seconds since
  the device was initialized).
    The MasterZoneDst bit specifies whether the TimeZone, DstStart, DstEnd and
  DstShift attributes are set internally to correct values for the location of the clock.
  If not, these attributes need to be set over the network. This bit is not writeable if
  a value is written to the TimeStatus attribute, this bit does not change.
  */
  struct PACK
  {
    ZCL_AttributeId_t   id;               //!<Attribute Id (0x0001)
    uint8_t             type;             //!<Attribute type (8-bit bitmap, typeId = 0x18, #ZCL_8BIT_BITMAP_DATA_TYPE_ID)
    uint8_t             properties;       //!<Attribute properties bitmask
    struct PACK                           //!<Attribute value (default 0b00000000)
    {
      LITTLE_ENDIAN_OCTET(4,(
        uint8_t           master        :1, //!<Master bit (1 - master clock, 0 - not master clock)
        uint8_t           synchronized  :1, //!<Synchronized bit (1- synchronized, 0 - not synchronized)
        uint8_t           masterZoneDst :1, //!<MasterZoneDst bit (1 - master for Time Zone and DST, 0 - not master for Time Zone and DST)
        uint8_t           reserved      :5  //!<Reserved field
      ))
    } value;
  } timeStatus;
} ZCL_TimeClusterServerAttributes_t;
END_PACK
#endif // #ifndef _ZCLTIMECLUSTER_H

//eof zclTimeCluster.h