Developing with ZBOSS SDK for Zigbee
Read attributes request and response sending and parsing.

Data Structures

struct  zb_zcl_read_attr_req_s
 ZCL Read Attribute Command frame. More...
 
struct  zb_zcl_read_attr_res_s
 ZCL Read Attribute Response Command frame. More...
 

Macros

#define ZB_ZCL_GENERAL_GET_NEXT_READ_ATTR_RES(data_buf, read_attr_resp)
 Parses Read attribute response and returns next Read attribute status record or NULL if there is no more data. More...
 
#define ZB_ZCL_GENERAL_INIT_READ_ATTR_REQ(buffer, cmd_ptr, def_resp)
 Initialize Read attribute command. More...
 
#define ZB_ZCL_GENERAL_INIT_READ_ATTR_REQ_A(buffer, cmd_ptr, direction, def_resp)
 Initialize Read Attribute Request command. More...
 
#define ZB_ZCL_GENERAL_INIT_READ_ATTR_REQ_MANUF(buffer, cmd_ptr, direction, def_resp, manuf_code)
 Initialize Read Attribute Request command with manufacturer code. More...
 
#define ZB_ZCL_GENERAL_ADD_ID_READ_ATTR_REQ(cmd_ptr, attr_id)
 Add attribute id to command payload. More...
 
#define ZB_ZCL_GENERAL_SEND_READ_ATTR_REQ(buffer, cmd_ptr, addr, dst_addr_mode, dst_ep, ep, profile_id, cluster_id, cb)
 Sends Read attribute command. More...
 
#define ZB_ZCL_GENERAL_GET_READ_ATTR_REQ(_data_buf, _read_attr_req)
 Parses Read attribute request and returns next Read attribute record or NULL if there is no more data. More...
 
#define ZB_ZCL_GENERAL_INIT_READ_ATTR_RESP(_buffer, _cmd_ptr, _seq)
 Initialize Read Attribute Response command. More...
 
#define ZB_ZCL_GENERAL_INIT_READ_ATTR_RESP_EXT(_buffer, _cmd_ptr, _direction, _seq, _is_manuf, _manuf_id)
 Initialize Read Attribute Response command. More...
 
#define ZB_ZCL_GENERAL_ADD_READ_ATTR_RESP(_buf, _cmd_ptr, _attr_desc)
 Add attribute value to command payload. More...
 
#define ZB_ZCL_GENERAL_ADD_NO_SUPPORT_READ_ATTR_RESP(_buf, _cmd_ptr, _attr_id)
 Add attribute value to command payload. More...
 
#define ZB_ZCL_GENERAL_SEND_READ_ATTR_RESP( _buffer, _cmd_ptr, _addr, _dst_addr_mode, _dst_ep, _ep, _profile_id, _cluster_id, _cb)
 Send Read attribute response command. More...
 

Typedefs

typedef struct zb_zcl_read_attr_req_s zb_zcl_read_attr_req_t
 ZCL Read Attribute Command frame. More...
 
typedef struct zb_zcl_read_attr_res_s zb_zcl_read_attr_res_t
 ZCL Read Attribute Response Command frame. More...
 

Detailed Description

Read attributes command described in ZCL spec, subclauses 2.4.1 and 2.4.2.

Read attributes request command can be formed and sent as in following snippet:

Read attributes response can be parsed as:

until allocated buffer space exceeds.

Read attributes request parsing and response filling and sending is implemented in ZCL library internal functions.

For more information see any HA sample

Macro Definition Documentation

◆ ZB_ZCL_GENERAL_ADD_ID_READ_ATTR_REQ

#define ZB_ZCL_GENERAL_ADD_ID_READ_ATTR_REQ (   cmd_ptr,
  attr_id 
)
Value:
{ \
ZB_ZCL_PACKET_PUT_DATA16_VAL(cmd_ptr, (attr_id)); \
}

Add attribute id to command payload.

Parameters
cmd_ptr- command buffer pointer
attr_id- attribute ID

◆ ZB_ZCL_GENERAL_ADD_NO_SUPPORT_READ_ATTR_RESP

#define ZB_ZCL_GENERAL_ADD_NO_SUPPORT_READ_ATTR_RESP (   _buf,
  _cmd_ptr,
  _attr_id 
)
Value:
{ \
zb_uint16_t bytes_avail = ZB_ZCL_GET_BYTES_AVAILABLE((_buf), (_cmd_ptr)); \
if (bytes_avail >= (sizeof(zb_uint16_t) + sizeof(zb_uint8_t))) \
{ \
ZB_ZCL_PACKET_PUT_DATA16_VAL((_cmd_ptr), (_attr_id)); \
ZB_ZCL_PACKET_PUT_DATA8((_cmd_ptr), ZB_ZCL_STATUS_UNSUP_ATTRIB); \
} \
else \
{ \
TRACE_MSG(TRACE_ZCL1, "ERROR, buffer is full", (FMT__0)); \
} \
}

Add attribute value to command payload.

Parameters
_buf- buffer to store command data
_cmd_ptr- pointer to a command data memory
_attr_id- attribute identifier

◆ ZB_ZCL_GENERAL_ADD_READ_ATTR_RESP

#define ZB_ZCL_GENERAL_ADD_READ_ATTR_RESP (   _buf,
  _cmd_ptr,
  _attr_desc 
)
Value:
{ \
zb_uint16_t bytes_avail = ZB_ZCL_GET_BYTES_AVAILABLE((_buf), (_cmd_ptr)); \
zb_uint8_t attr_size = zb_zcl_get_attribute_size((_attr_desc)->type, (_attr_desc)->data_p); \
if (bytes_avail >= (sizeof(zb_zcl_read_attr_res_t) - sizeof(zb_uint8_t) + attr_size)) \
{ \
ZB_ZCL_PACKET_PUT_DATA16_VAL((_cmd_ptr), (_attr_desc)->id); \
ZB_ZCL_PACKET_PUT_DATA8((_cmd_ptr), ZB_ZCL_STATUS_SUCCESS); \
ZB_ZCL_PACKET_PUT_DATA8((_cmd_ptr), (_attr_desc)->type); \
(_cmd_ptr) = zb_zcl_put_value_to_packet((_cmd_ptr), (_attr_desc)->type, \
(zb_uint8_t *)(_attr_desc)->data_p); \
} \
else \
{ \
TRACE_MSG(TRACE_ZCL1, "ERROR, buffer is full", (FMT__0)); \
} \
}

Add attribute value to command payload.

Parameters
_buf- buffer to store command data
_cmd_ptr- pointer to a command data memory
_attr_desc- attribute descriptor

◆ ZB_ZCL_GENERAL_GET_NEXT_READ_ATTR_RES

#define ZB_ZCL_GENERAL_GET_NEXT_READ_ATTR_RES (   data_buf,
  read_attr_resp 
)
Value:
{ \
zb_uint8_t resp_size = 0xff; \
(read_attr_resp) = zb_buf_len(data_buf) >= ZB_ZCL_READ_ATTR_RESP_SIZE ? \
(zb_zcl_read_attr_res_t*)zb_buf_begin(data_buf) : NULL; \
\
if (read_attr_resp != NULL) \
{ \
resp_size = ZB_ZCL_READ_ATTR_RESP_SIZE; \
ZB_ZCL_HTOLE16_INPLACE(&(read_attr_resp)->attr_id); \
if ((read_attr_resp)->status == ZB_ZCL_STATUS_SUCCESS) \
{ \
resp_size += \
sizeof(zb_uint8_t) + \
zb_zcl_get_attribute_size((read_attr_resp)->attr_type, (read_attr_resp)->attr_value); \
if (resp_size <= zb_buf_len(data_buf)) \
{ \
ZB_ZCL_FIX_ENDIAN((read_attr_resp)->attr_value, (read_attr_resp)->attr_type); \
} \
} \
\
if (resp_size <= zb_buf_len(data_buf)) \
{ \
(void)zb_buf_cut_left((data_buf), resp_size); \
} \
else \
{ \
(read_attr_resp) = NULL; \
} \
} \
}

Parses Read attribute response and returns next Read attribute status record or NULL if there is no more data.

If response contains invalid data, NULL is returned.

Parameters
data_buf- ID zb_bufid_t of a buffer containing read attribute response data
read_attr_resp- out pointer to zb_zcl_read_attr_res_t, containing Read attribute status record
Note
data_buf buffer should contain Read attribute response payload, without ZCL header. Each parsed Read attribute status record is extracted from initial data_buf buffer

◆ ZB_ZCL_GENERAL_GET_READ_ATTR_REQ

#define ZB_ZCL_GENERAL_GET_READ_ATTR_REQ (   _data_buf,
  _read_attr_req 
)
Value:
{ \
(_read_attr_req) = zb_buf_len((_data_buf)) >= sizeof(zb_zcl_read_attr_req_t) ? \
(zb_zcl_read_attr_req_t*)zb_buf_begin((_data_buf)) : NULL; \
\
if ((_read_attr_req)) \
{ \
ZB_ZCL_HTOLE16_INPLACE(&(_read_attr_req)->attr_id); \
(void)zb_buf_cut_left((_data_buf), sizeof(zb_zcl_read_attr_req_t)); \
} \
}

Parses Read attribute request and returns next Read attribute record or NULL if there is no more data.

If request contains invalid data, NULL is returned.

Parameters
_data_buf- ID zb_bufid_t of a buffer containing write attribute request data
_read_attr_req- out pointer to zb_zcl_read_attr_req_t, containing Read attribute record out value direct into data_buf. Do not change data_buf before finish work with read_attr_req
Note
data_buf buffer should contain Read attribute request payload, without ZCL header. Each parsed Read attribute record is extracted from initial data_buf buffer

◆ ZB_ZCL_GENERAL_INIT_READ_ATTR_REQ

#define ZB_ZCL_GENERAL_INIT_READ_ATTR_REQ (   buffer,
  cmd_ptr,
  def_resp 
)
Value:
{ \
cmd_ptr = ZB_ZCL_START_PACKET(buffer); \
ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_REQ_FRAME_CONTROL(cmd_ptr, def_resp); \
ZB_ZCL_CONSTRUCT_COMMAND_HEADER(cmd_ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_READ_ATTRIB); \
}

Initialize Read attribute command.

Parameters
bufferto put packet to
cmd_ptr- command buffer pointer
def_resp- enable/disable default response

◆ ZB_ZCL_GENERAL_INIT_READ_ATTR_REQ_A

#define ZB_ZCL_GENERAL_INIT_READ_ATTR_REQ_A (   buffer,
  cmd_ptr,
  direction,
  def_resp 
)
Value:
{ \
cmd_ptr = ZB_ZCL_START_PACKET(buffer); \
ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_REQ_FRAME_CONTROL_A(cmd_ptr, direction, ZB_ZCL_NOT_MANUFACTURER_SPECIFIC, def_resp); \
ZB_ZCL_CONSTRUCT_COMMAND_HEADER(cmd_ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_READ_ATTRIB); \
}

Initialize Read Attribute Request command.

Parameters
buffer- buffer to store command data
cmd_ptr- pointer to a command data memory
direction- direction of command (see zb_zcl_frame_direction_t)
def_resp- enable/disable default response

◆ ZB_ZCL_GENERAL_INIT_READ_ATTR_REQ_MANUF

#define ZB_ZCL_GENERAL_INIT_READ_ATTR_REQ_MANUF (   buffer,
  cmd_ptr,
  direction,
  def_resp,
  manuf_code 
)
Value:
{ \
cmd_ptr = ZB_ZCL_START_PACKET(buffer); \
ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_REQ_FRAME_CONTROL_A(cmd_ptr, direction, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \
ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(cmd_ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_TRUE, manuf_code, ZB_ZCL_CMD_READ_ATTRIB); \
}

Initialize Read Attribute Request command with manufacturer code.

Parameters
buffer- buffer to store command data
cmd_ptr- pointer to a command data memory
direction- direction of command (see zb_zcl_frame_direction_t)
def_resp- enable/disable default response
manuf_code- manufacturer specific code

◆ ZB_ZCL_GENERAL_INIT_READ_ATTR_RESP

#define ZB_ZCL_GENERAL_INIT_READ_ATTR_RESP (   _buffer,
  _cmd_ptr,
  _seq 
)
Value:
{ \
cmd_ptr = ZB_ZCL_START_PACKET((_buffer)); \
ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_RESP_FRAME_CONTROL((_cmd_ptr)); \
ZB_ZCL_CONSTRUCT_COMMAND_HEADER((_cmd_ptr), (_seq), ZB_ZCL_CMD_READ_ATTRIB_RESP); \
}

Initialize Read Attribute Response command.

Parameters
_buffer- buffer to store command data
_cmd_ptr- pointer to a command data memory
_seq- command sequence

◆ ZB_ZCL_GENERAL_INIT_READ_ATTR_RESP_EXT

#define ZB_ZCL_GENERAL_INIT_READ_ATTR_RESP_EXT (   _buffer,
  _cmd_ptr,
  _direction,
  _seq,
  _is_manuf,
  _manuf_id 
)
Value:
{ \
cmd_ptr = ZB_ZCL_START_PACKET((_buffer)); \
ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_RESP_FRAME_CONTROL_A((_cmd_ptr), (_direction), (_is_manuf)); \
ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT((_cmd_ptr), (_seq), (_is_manuf), (_manuf_id), ZB_ZCL_CMD_READ_ATTRIB_RESP); \
}

Initialize Read Attribute Response command.

Parameters
_buffer- buffer to store command data
_cmd_ptr- pointer to a command data memory
_direction- direction of command (see zb_zcl_frame_direction_t)
_seq- command sequence
_is_manuf- whether command is manufacturer specific
_manuf_id- manufacturer ID (needed if _is_manuf is set)

◆ ZB_ZCL_GENERAL_SEND_READ_ATTR_REQ

#define ZB_ZCL_GENERAL_SEND_READ_ATTR_REQ (   buffer,
  cmd_ptr,
  addr,
  dst_addr_mode,
  dst_ep,
  ep,
  profile_id,
  cluster_id,
  cb 
)
Value:
ZB_ZCL_FINISH_PACKET(buffer, cmd_ptr) \
ZB_ZCL_SEND_COMMAND_SHORT(buffer, addr, dst_addr_mode, dst_ep, ep, profile_id, cluster_id, cb);

Sends Read attribute command.

Parameters
bufferto place data to
cmd_ptr- pointer to the memory area after the command data end
addr- address to send packet to
dst_addr_mode- addressing mode
dst_ep- destination endpoint
ep- sending endpoint
profile_id- profile identifier
cluster_id- cluster identifier
cb- callback for getting command send status

◆ ZB_ZCL_GENERAL_SEND_READ_ATTR_RESP

#define ZB_ZCL_GENERAL_SEND_READ_ATTR_RESP (   _buffer,
  _cmd_ptr,
  _addr,
  _dst_addr_mode,
  _dst_ep,
  _ep,
  _profile_id,
  _cluster_id,
  _cb 
)
Value:
{ \
ZB_ZCL_FINISH_PACKET((_buffer), (_cmd_ptr)) \
ZB_ZCL_SEND_COMMAND_SHORT((_buffer), (_addr), (_dst_addr_mode), (_dst_ep), (_ep), \
(_profile_id), (_cluster_id), (_cb)); \
}

Send Read attribute response command.

Parameters
_buffer- buffer to store command data
_cmd_ptr- pointer to a command data memory
_addr- address to send packet to
_dst_addr_mode- addressing mode
_dst_ep- destination endpoint
_ep- sending endpoint
_profile_id- profile identifier
_cluster_id- cluster identifier
_cb- callback for getting command send status

Typedef Documentation

◆ zb_zcl_read_attr_req_t

ZCL Read Attribute Command frame.

See also
ZCL spec, zb_zcl_read_attr 2.4.1 Read Attributes Command
Note
Command frame contains variable number of parameters

◆ zb_zcl_read_attr_res_t

ZCL Read Attribute Response Command frame.

See also
ZCL spec, zb_zcl_read_attr 2.4.2 Read Attributes Response Command
Note
Command frame contains variable number of parameters. Also, based on status value attr_type and attr_value maybe absent.
ZB_ZCL_GENERAL_SEND_READ_ATTR_REQ
#define ZB_ZCL_GENERAL_SEND_READ_ATTR_REQ(buffer, cmd_ptr, addr, dst_addr_mode, dst_ep, ep, profile_id, cluster_id, cb)
Sends Read attribute command.
Definition: zb_zcl_commands.h:694
ZB_ZCL_START_PACKET
#define ZB_ZCL_START_PACKET(zbbuf)
Initializes zb_buf_t buffer and returns pointer to the beginning of array.
Definition: zb_zcl_common.h:1354
zb_uint8_t
unsigned char zb_uint8_t
Project-local 1-byte unsigned int type.
Definition: zb_types.h:158
ZB_ZCL_STATUS_SUCCESS
@ ZB_ZCL_STATUS_SUCCESS
Definition: zb_zcl_common.h:337
zb_zcl_get_attribute_size
zb_uint8_t zb_zcl_get_attribute_size(zb_uint8_t attr_type, zb_uint8_t *attr_value)
Get size of value of given attribute type.
ZB_AF_HA_PROFILE_ID
@ ZB_AF_HA_PROFILE_ID
Definition: zboss_api_af.h:315
ZB_ZCL_CMD_READ_ATTRIB_RESP
@ ZB_ZCL_CMD_READ_ATTRIB_RESP
Definition: zb_zcl_commands.h:62
ZB_ZCL_CLUSTER_ID_BINARY_INPUT
@ ZB_ZCL_CLUSTER_ID_BINARY_INPUT
Definition: zb_zcl_common.h:214
ZB_TRUE
@ ZB_TRUE
Definition: zb_types.h:130
ZB_ZCL_GET_SEQ_NUM
#define ZB_ZCL_GET_SEQ_NUM()
Return next sequence number for ZCL frame.
Definition: zb_zcl_common.h:1272
ZB_ZCL_CMD_READ_ATTRIB
@ ZB_ZCL_CMD_READ_ATTRIB
Definition: zb_zcl_commands.h:61
zb_buf_cut_left
#define zb_buf_cut_left(buf, size)
Definition: zboss_api_buf.h:485
zb_zcl_read_attr_res_s
ZCL Read Attribute Response Command frame.
Definition: zb_zcl_commands.h:581
ZB_ZCL_MANUFACTURER_SPECIFIC
@ ZB_ZCL_MANUFACTURER_SPECIFIC
Command refers to manufacturer-specific profile extension.
Definition: zb_zcl_common.h:872
ZB_ZCL_GET_BYTES_AVAILABLE
#define ZB_ZCL_GET_BYTES_AVAILABLE(zbbuf, ptr)
Return number of bytes available in a packet.
Definition: zb_zcl_common.h:1372
ZB_ZCL_GENERAL_GET_NEXT_READ_ATTR_RES
#define ZB_ZCL_GENERAL_GET_NEXT_READ_ATTR_RES(data_buf, read_attr_resp)
Parses Read attribute response and returns next Read attribute status record or NULL if there is no m...
Definition: zb_zcl_commands.h:599
zb_buf_begin
#define zb_buf_begin(buf)
Definition: zboss_api_buf.h:331
ZB_ZCL_GENERAL_ADD_ID_READ_ATTR_REQ
#define ZB_ZCL_GENERAL_ADD_ID_READ_ATTR_REQ(cmd_ptr, attr_id)
Add attribute id to command payload.
Definition: zb_zcl_commands.h:678
ZB_ZCL_NOT_MANUFACTURER_SPECIFIC
@ ZB_ZCL_NOT_MANUFACTURER_SPECIFIC
Standard profile command.
Definition: zb_zcl_common.h:867
zb_uint16_t
unsigned short zb_uint16_t
Project-local 2-byte unsigned int type.
Definition: zb_types.h:162
zb_zcl_put_value_to_packet
zb_uint8_t * zb_zcl_put_value_to_packet(zb_uint8_t *cmd_ptr, zb_uint8_t attr_type, zb_uint8_t *attr_value)
zb_zcl_read_attr_req_s
ZCL Read Attribute Command frame.
Definition: zb_zcl_commands.h:563
ZB_ZCL_ATTR_BINARY_INPUT_PRESENT_VALUE_ID
@ ZB_ZCL_ATTR_BINARY_INPUT_PRESENT_VALUE_ID
PresentValue attribute.
Definition: zb_zcl_binary_input.h:79
ZB_ZCL_STATUS_UNSUP_ATTRIB
@ ZB_ZCL_STATUS_UNSUP_ATTRIB
Definition: zb_zcl_common.h:346
zb_buf_len
#define zb_buf_len(buf)
Definition: zboss_api_buf.h:378
ZB_ZCL_GENERAL_INIT_READ_ATTR_REQ
#define ZB_ZCL_GENERAL_INIT_READ_ATTR_REQ(buffer, cmd_ptr, def_resp)
Initialize Read attribute command.
Definition: zb_zcl_commands.h:636
zb_zcl_read_attr_req_t
struct zb_zcl_read_attr_req_s zb_zcl_read_attr_req_t
ZCL Read Attribute Command frame.
ZB_ZCL_ENABLE_DEFAULT_RESPONSE
@ ZB_ZCL_ENABLE_DEFAULT_RESPONSE
Enable default response.
Definition: zb_zcl_common.h:883
ZB_ZCL_FINISH_PACKET
#define ZB_ZCL_FINISH_PACKET(zbbuf, ptr)
Definition: zb_zcl_common.h:1688