Zigbee Cluster Library (ZCL) frame codec: the application payload that rides inside an APS unicast on a Home Automation endpoint (profile 0x0104).
This is pure, transport-agnostic encoding/decoding: build the global commands
we need to interview and configure a sensor (Read Attributes, Configure
Reporting) and decode what it sends back (Read Attributes Response, Report
Attributes). It is deliberately independent of EZSP; Zigbee.EZSP.Adapter wraps
these bytes in an EmberApsFrame and hands them to the NCP.
ZCL frame layout
[frame control : 1]
[manufacturer code : 2 LE] # only if the MS bit is set
[transaction seq : 1]
[command id : 1]
[payload ...]Frame-control bits: type (0 = global/profile-wide, 1 = cluster-specific), bit2 manufacturer-specific, bit3 direction (0 = to-server, 1 = to-client), bit4 disable-default-response.
Summary
Functions
Build a Configure Reporting (global cmd 0x06) frame.
Decode a ZCL frame into a map: %{frame_type, direction, manufacturer, seq, command, command_name, payload} where payload is command-specific
(a list of attribute records for reads/reports).
Decode one attribute value of ZCL type from the front of bin.
Returns {value, rest}.
Encode a value given its ZCL data type id (little-endian).
Relative-humidity attribute (uint16, hundredths of a percent) → float %.
Build a Read Attributes (global cmd 0x00) frame for attr_ids.
Temperature attribute (int16, hundredths of a degree C) → float °C.
Functions
Build a Configure Reporting (global cmd 0x06) frame.
Each record is %{attr_id, type, min, max, change}. For analog attributes
change (the reportable delta, same data type as the attribute) is required;
for discrete attributes pass change: nil. min/max are the reporting
interval bounds in seconds.
Decode a ZCL frame into a map: %{frame_type, direction, manufacturer, seq, command, command_name, payload} where payload is command-specific
(a list of attribute records for reads/reports).
Decode one attribute value of ZCL type from the front of bin.
Returns {value, rest}.
Encode a value given its ZCL data type id (little-endian).
Relative-humidity attribute (uint16, hundredths of a percent) → float %.
Build a Read Attributes (global cmd 0x00) frame for attr_ids.
seq is the ZCL transaction sequence number (echoed in the response).
Temperature attribute (int16, hundredths of a degree C) → float °C.