Digi XBee(R) ANSI C Host Library
Files | Macros | Functions | Variables

Files

file  zcl_time.h
 Header for implementation of ZigBee Time Cluster (ZCL Spec section 3.12).
 
file  zcl_time.c
 Client and server code to implement the ZigBee Time Cluster.
 

Macros

#define zcl_gmtime(tm, timestamp)   xbee_gmtime( tm, timestamp)
 
#define zcl_mktime(tm)   xbee_mktime( tm)
 
#define ZCL_CLUST_ENTRY_TIME_BOTH
 Macro for inserting a standard Time Server (and Client) into an endpoint's cluster list. More...
 
#define ZCL_CLUST_ENTRY_TIME_SERVER
 Macro for inserting a standard Time Server (no Client) into an endpoint's cluster list. More...
 
#define ZCL_CLUST_ENTRY_TIME_CLIENT
 Macro for inserting a standard Time Client (no Server) into an endpoint's cluster list. More...
 
#define _zcl_time_debug
 

Functions

zcl_utctime_t zcl_time_now (void)
 Returns the current date/time, using the ZCL epoch of January 1, 2000. More...
 
int zcl_time_client (const wpan_envelope_t FAR *envelope, void FAR *context)
 Handle Read Attribute Responses to requests sent as part of the zcl_time_find_servers() process. More...
 
int zcl_time_find_servers (wpan_dev_t *dev, uint16_t profile_id)
 Find Time Servers on the network, query them for the current time and then synchronize this device's clock to that time. More...
 
int _zcl_time_time_set (const zcl_attribute_full_t FAR *attribute, zcl_attribute_write_rec_t *rec)
 Function registered to ZCL_TIME_ATTR_TIME attribute of Time Cluster and called to modify the attribute. Also called internally to update the zcl_time_skew global. More...
 
uint_fast8_t _zcl_time_time_get (const zcl_attribute_full_t FAR *attribute)
 Function registered to ZCL_TIME_ATTR_TIME attribute of Time Cluster and called to refresh the Time attribute (global zcl_time_time). More...
 
int _zcl_time_timestatus_set (const zcl_attribute_full_t FAR *attribute, zcl_attribute_write_rec_t *rec)
 Special code for setting bitfield of TimeStatus attribute. More...
 

Variables

const zcl_attribute_tree_t zcl_time_attribute_tree []
 
zcl_utctime_t zcl_time_time
 Current value of Time Attribute (ZCL_TIME_ATTR_TIME), start value doesn't matter since it is set by _zcl_time_time_get(). More...
 
uint8_t zcl_time_timestatus = 0
 Current value of TimeStatus Attribute (ZCL_TIME_ATTR_TIME_STATUS)
 
int32_t zcl_time_skew = 0
 difference between xbee_seconds_timer() and actual calendar time
 
struct {
   zcl_attribute_full_t   time
 
   zcl_attribute_full_t   time_status
 
   uint16_t   end_of_list
 
zcl_time_attr
 Global attribute list used in ZCL_CLUST_ENTRY_TIME_SERVER and for adding a Time Cluster Server to an endpoint. More...
 
const zcl_attribute_tree_t zcl_time_attribute_tree []
 

Attributes of ZCL Time Cluster

#define ZCL_TIME_ATTR_TIME   0x0000
 3.12.2.2.1 Time Attribute
 
#define ZCL_TIME_ATTR_TIME_STATUS   0x0001
 3.12.2.2.2 TimeStatus Attribute
 
#define ZCL_TIME_ATTR_TIME_ZONE   0x0002
 3.12.2.2.3 TimeZone Attribute
 
#define ZCL_TIME_ATTR_DST_START   0x0003
 3.12.2.2.4 DstStart Attribute
 
#define ZCL_TIME_ATTR_DST_END   0x0004
 3.12.2.2.5 DstEnd Attribute
 
#define ZCL_TIME_ATTR_DST_SHIFT   0x0005
 3.12.2.2.6 DstShift Attribute
 
#define ZCL_TIME_ATTR_STANDARD_TIME   0x0006
 3.12.2.2.7 StandardTime Attribute
 
#define ZCL_TIME_ATTR_LOCAL_TIME   0x0007
 3.12.2.2.8 LocalTime Attribute
 

Bitfields for attribute ZCL_TIME_ATTR_TIME, TimeStatus.

Bits 3-7 are reserved.

Per Section 3.12.2.2.2 of the ZCL spec:

  • If the Master bit is 1, the value of [the Synchronized bit] is 0.
  • If both the Master and Synchronized bits are 0, the real time clock has no defined relationship to the time standard.
#define ZCL_TIME_STATUS_MASTER   0x01
 The RTC corresponding to the Time attribute is internally set to the time standard. More...
 
#define ZCL_TIME_STATUS_SYNCHRONIZED   0x02
 The Synchronized bit specifies whether Time has been set over the [ZigBee] network to synchronize it (as close as may be practical) to the time standard (see 3.12.1). More...
 
#define ZCL_TIME_STATUS_MASTERZONEDST   0x04
 The MasterZoneDst bit specifies whether the TimeZone, DstStart, DstEnd and DstShift attributes are set internally to correct values for the location of the clock. More...
 

Detailed Description

Macro Definition Documentation

#define ZCL_CLUST_ENTRY_TIME_BOTH
Value:
{ ZCL_CLUST_TIME, \
zcl_time_attribute_tree, \
int zcl_time_client(const wpan_envelope_t FAR *envelope, void FAR *context)
Handle Read Attribute Responses to requests sent as part of the zcl_time_find_servers() process...
Definition: zcl_time.c:291
#define WPAN_CLUST_FLAG_ENCRYPT
Data sent or received by this cluster must be encrypted.
Definition: aps.h:241
#define WPAN_CLUST_FLAG_INOUT
both client and server cluster
Definition: aps.h:232

Macro for inserting a standard Time Server (and Client) into an endpoint's cluster list.

#define ZCL_CLUST_ENTRY_TIME_CLIENT
Value:
{ ZCL_CLUST_TIME, \
int zcl_time_client(const wpan_envelope_t FAR *envelope, void FAR *context)
Handle Read Attribute Responses to requests sent as part of the zcl_time_find_servers() process...
Definition: zcl_time.c:291
#define WPAN_CLUST_FLAG_ENCRYPT
Data sent or received by this cluster must be encrypted.
Definition: aps.h:241
#define WPAN_CLUST_FLAG_CLIENT
alias name for output cluster (uses ZCL terminology)
Definition: aps.h:236
const zcl_attribute_tree_t FAR zcl_attributes_none[1]
If a cluster doesn't have attributes, use zcl_attributes_none (a single, empty attribute list) in the...
Definition: zigbee_zcl.c:49

Macro for inserting a standard Time Client (no Server) into an endpoint's cluster list.

#define ZCL_CLUST_ENTRY_TIME_SERVER
Value:
{ ZCL_CLUST_TIME, \
zcl_time_attribute_tree, \
int zcl_general_command(const wpan_envelope_t FAR *envelope, void FAR *context)
Handler for ZCL General Commands.
Definition: zigbee_zcl.c:1802
#define WPAN_CLUST_FLAG_ENCRYPT
Data sent or received by this cluster must be encrypted.
Definition: aps.h:241
#define WPAN_CLUST_FLAG_SERVER
alias name for input cluster (uses ZCL terminology)
Definition: aps.h:234

Macro for inserting a standard Time Server (no Client) into an endpoint's cluster list.

#define ZCL_TIME_STATUS_MASTER   0x01

The RTC corresponding to the Time attribute is internally set to the time standard.

This bit should only be set if the host has reliably set its RTC.

Referenced by _zcl_time_time_set(), _zcl_time_timestatus_set(), zcl_time_client(), and zcl_time_now().

#define ZCL_TIME_STATUS_MASTERZONEDST   0x04

The MasterZoneDst bit specifies whether the TimeZone, DstStart, DstEnd and DstShift attributes are set internally to correct values for the location of the clock.

#define ZCL_TIME_STATUS_SYNCHRONIZED   0x02

The Synchronized bit specifies whether Time has been set over the [ZigBee] network to synchronize it (as close as may be practical) to the time standard (see 3.12.1).

Referenced by _zcl_time_timestatus_set(), zcl_time_client(), and zcl_time_now().

Function Documentation

uint_fast8_t _zcl_time_time_get ( const zcl_attribute_full_t FAR attribute)

Function registered to ZCL_TIME_ATTR_TIME attribute of Time Cluster and called to refresh the Time attribute (global zcl_time_time).

See zcl_attribute_update_fn() for calling convention.

References PRIx32, XBEE_UNUSED_PARAMETER, zcl_time_skew, and zcl_time_time.

Referenced by _zcl_time_timestatus_set(), and zcl_time_now().

int _zcl_time_time_set ( const zcl_attribute_full_t FAR attribute,
zcl_attribute_write_rec_t rec 
)

Function registered to ZCL_TIME_ATTR_TIME attribute of Time Cluster and called to modify the attribute. Also called internally to update the zcl_time_skew global.

Parameters
[in]attributeignored; assumed to point to zcl_time_time
[in,out]recif NULL, function was called internally to update zcl_time_skew only

See zcl_attribute_write_fn() for calling convention.

References zcl_attribute_write_rec_t::buffer, zcl_attribute_write_rec_t::flags, PRId32, PRIx32, zcl_attribute_write_rec_t::status, ZCL_ATTR_WRITE_FLAG_ASSIGN, zcl_decode_attribute(), zcl_time_skew, ZCL_TIME_STATUS_MASTER, zcl_time_time, and zcl_time_timestatus.

Referenced by _zcl_time_timestatus_set(), and zcl_time_client().

int _zcl_time_timestatus_set ( const zcl_attribute_full_t FAR attribute,
zcl_attribute_write_rec_t rec 
)
int zcl_time_client ( const wpan_envelope_t FAR envelope,
void FAR context 
)

Handle Read Attribute Responses to requests sent as part of the zcl_time_find_servers() process.

This function expects to receive "read attribute response" packets ONLY for reads of Time and TimeStatus.

If responding device is a master or is synchronized with one, use it's Time value to update a "skew" global used to track the offset between system time (which may just be "seconds of uptime") and calendar time.

Parameters
[in]envelopeenvelope from received message
[in]contextpointer to attribute list for cluster (typically passed in via endpoint dispatcher)
Return values
0Command was processed and default response (with either success or error status) was sent.
!0Error sending default response; time may or may not have been set.

References _zcl_time_time_set(), zcl_command_t::command, FAR, zcl_command_t::frame_control, hex_dump(), HEX_DUMP_FLAG_TAB, le16toh, le32toh, PRIu32, ZCL_CMD_MATCH, ZCL_CMD_READ_ATTRIB_RESP, zcl_command_build(), zcl_default_response(), zcl_general_command(), ZCL_TIME_ATTR_TIME, ZCL_TIME_ATTR_TIME_STATUS, ZCL_TIME_STATUS_MASTER, ZCL_TIME_STATUS_SYNCHRONIZED, zcl_time_time, zcl_time_timestatus, and ZCL_TYPE_TIME_UTCTIME.

int zcl_time_find_servers ( wpan_dev_t dev,
uint16_t  profile_id 
)

Find Time Servers on the network, query them for the current time and then synchronize this device's clock to that time.

Note
This function uses a static buffer to hold context information for the ZDO responder that generates the ZCL Read Attributes request. Wait at least 60 seconds between calls to allow for earlier requests to time out.
This function will only work correctly if the Time Cluster Client in your endpoint table is using the zcl_time_client() function as its callback handler. If you use the ZCL_CLUST_ENTRY_TIME_CLIENT or ZCL_CLUST_ENTRY_TIME_BOTH macro, the client cluster is set up correctly.
Parameters
[in]devdevice to send query on
[in]profile_idprofile ID to match in endpoint table or #WPAN_APS_PROFILE_ANY to use the first endpoint with a Time Cluster Client
Return values
0Successfully issued ZDO Match Descriptor Request to find Time Cluster Servers on the network. No guarantee that we'll get a response.
!0Some sort of error occurred in generating or sending the ZDO Match Descriptor Request.
-EINVALCouldn't find a Time Cluster Client with profile_id in the endpoint table of dev.

References EINVAL, WPAN_CLUST_FLAG_CLIENT, WPAN_CLUSTER_END_OF_LIST, wpan_endpoint_of_cluster(), ZCL_ATTRIBUTE_END_OF_LIST, zcl_find_and_read_attributes(), ZCL_TIME_ATTR_TIME, and ZCL_TIME_ATTR_TIME_STATUS.

zcl_utctime_t zcl_time_now ( void  )

Returns the current date/time, using the ZCL epoch of January 1, 2000.

Assumes that device has connected to a time server and updated its clock accordingly. Returns ZCL_UTCTIME_INVALID if the device has not synchronized its clock.

Do not use this value for tracking elapsed time – use xbee_seconds_timer() or xbee_millisecond_timer() instead. The value may jump forward (or even backward) when the device decides to synchronize with a time server.

Return values
ZCL_UTCTIME_INVALIDClock not synchronized to a time source.
0-0xFFFFFFFENumber of elapsed seconds since midnight UTC on January 1, 2000.
See also
xbee_seconds_timer, xbee_millisecond_timer

References _zcl_time_time_get(), ZCL_TIME_STATUS_MASTER, ZCL_TIME_STATUS_SYNCHRONIZED, zcl_time_time, and zcl_time_timestatus.

Variable Documentation

const { ... } zcl_time_attr
Initial value:
=
{
{ 0 }, { 0 },
ZCL_TYPE_BITMAP_8BIT,
{ 0 }, { 0 },
}
#define ZCL_TYPE_TIME_UTCTIME
number of seconds (stored in uint32_t) since Midnight on 1/1/2000 UTC
Definition: zcl_types.h:268
#define ZCL_ATTRIB_FLAG_FULL
If set, this is part of a zcl_attribute_full_t structure.
Definition: zcl.h:759
#define ZCL_TIME_ATTR_TIME_STATUS
3.12.2.2.2 TimeStatus Attribute
Definition: zcl_time.h:46
uint8_t zcl_time_timestatus
Current value of TimeStatus Attribute (ZCL_TIME_ATTR_TIME_STATUS)
Definition: zcl_time.c:56
#define ZCL_TIME_ATTR_TIME
3.12.2.2.1 Time Attribute
Definition: zcl_time.h:44
int _zcl_time_timestatus_set(const zcl_attribute_full_t FAR *attribute, zcl_attribute_write_rec_t *rec)
Special code for setting bitfield of TimeStatus attribute.
Definition: zcl_time.c:163
int _zcl_time_time_set(const zcl_attribute_full_t FAR *attribute, zcl_attribute_write_rec_t *rec)
Function registered to ZCL_TIME_ATTR_TIME attribute of Time Cluster and called to modify the attribut...
Definition: zcl_time.c:81
uint_fast8_t _zcl_time_time_get(const zcl_attribute_full_t FAR *attribute)
Function registered to ZCL_TIME_ATTR_TIME attribute of Time Cluster and called to refresh the Time at...
Definition: zcl_time.c:124
#define ZCL_ATTRIBUTE_END_OF_LIST
Attribute ID for end of list marker.
Definition: zcl.h:851
zcl_utctime_t zcl_time_time
Current value of Time Attribute (ZCL_TIME_ATTR_TIME), start value doesn't matter since it is set by _...
Definition: zcl_time.c:50

Global attribute list used in ZCL_CLUST_ENTRY_TIME_SERVER and for adding a Time Cluster Server to an endpoint.

The Time Cluster Client does not have any attributes.

Referenced by _zcl_time_timestatus_set().

const zcl_attribute_tree_t zcl_time_attribute_tree[]
Initial value:
=
{ { ZCL_MFG_NONE, &zcl_time_attr.time.base, NULL } }
const struct @31 zcl_time_attr
Global attribute list used in ZCL_CLUST_ENTRY_TIME_SERVER and for adding a Time Cluster Server to an ...
zcl_utctime_t zcl_time_time

Current value of Time Attribute (ZCL_TIME_ATTR_TIME), start value doesn't matter since it is set by _zcl_time_time_get().

Referenced by _zcl_time_time_get(), _zcl_time_time_set(), _zcl_time_timestatus_set(), zcl_time_client(), and zcl_time_now().