19uint8_t checksum(
const uint8_t *from_len, uint16_t n)
22 for (uint16_t i = 0; i < n; i++)
23 c = (uint8_t)(c ^ from_len[i]);
28uint16_t zwave_build_frame(zwave_type type, uint8_t cmd,
const uint8_t *data, uint8_t data_len, uint8_t *out,
33 uint8_t frame_len = (uint8_t)(data_len + 3);
34 uint16_t total = (uint16_t)(2 + frame_len);
37 out[0] = Zwave::ZWAVE_SOF;
39 out[2] = (uint8_t)type;
41 for (uint8_t i = 0; i < data_len; i++)
44 out[1 + frame_len] = checksum(&out[1], frame_len);
48int zwave_parse_frame(
const uint8_t *raw, uint16_t len, uint8_t *type, uint8_t *cmd,
const uint8_t **pdata,
53 if (raw[0] != Zwave::ZWAVE_SOF)
57 uint8_t frame_len = raw[1];
60 uint16_t total = (uint16_t)(2 + frame_len);
63 if (checksum(&raw[1], frame_len) != raw[1 + frame_len])
72 *pdata_len = (uint8_t)(frame_len - 3);
76bool zwave_is_ack(uint8_t b)
78 return b == Zwave::ZWAVE_ACK;
80bool zwave_is_nak(uint8_t b)
82 return b == Zwave::ZWAVE_NAK;
84bool zwave_is_can(uint8_t b)
86 return b == Zwave::ZWAVE_CAN;
89uint16_t zwave_build_ack(uint8_t *out, uint16_t cap)
93 out[0] = Zwave::ZWAVE_ACK;
#define DETWS_ZWAVE_MAX_DATA
Reject a Z-Wave frame whose declared length exceeds this data cap (sanity).
Z-Wave Serial API frame codec (DETWS_ENABLE_ZWAVE) - Silicon Labs controller.