zigbee 模块回调函数与 ZCL 规范不兼容

zigbee module callback function incompatible to ZCL spec

我已经按照ZCL的报告实现了能够接收传感器发送的数据的功能。

在SDK中是这样定义的:

void ZbZclReportFunc{
  struct ZbZclClusterT * clusterPtr,
  zbApsdeDataInt * dataIndPtr,
  uint16_t attributeId,
  const uint8_t * data
}

通过实现如上所示的回调函数,我可以接收除数据以外的所有信息。

在 ZCL 规范中,温度测量集群定义了它的 "MeasuredValue" 有符号 16 位整数。

我使用以下格式打印数据:

printf("Degree: 0x%04x", *data);

不出所料,显示的数据是“0x002b”为例

将其强制转换为带符号的 16 位整数并没有帮助。

printf("Degree: 0x%04x", (int16_t)*data);

有什么想法吗?

谢谢

Zigbee 封包数据为小端。此外,MeasuredValue 的单位是 "hundredths of degrees Celsius"。因此,如果您测量的温度值为 26 摄氏度,则您的数据缓冲区将如下所示:28 0A。要转换为摄氏度,您可以使用:

double temperature = (double)((int16_t)(data[1] << 8) | (int16_t)data[0]) / 100.0;