关于读取属性的方法
最近在做温度数据的采集的实验,用ZCL库开发,根据VV给我的提示,只要通过zcl_SendRead发送读属性的命令就可以啦,我实验了下也是可以的,但是读到的数据感觉不对,我分两步做:
1.用z-stack2.5.1的例程,light和Switch配合,Switch里面通过zcl_SendRead读取light的属性,设置读取两个属性,如下:
readCmd.attrID[0] = ATTRID_BASIC_HW_VERSION;
readCmd.attrID[1] = ATTRID_BASIC_ZCL_VERSION;
发送命令后,在Switch里面也能收到数据,在zclSampleSw_ProcessInReadRspCmd里面处理接收到的数据,但是发现每次都是第一个属性的相关数据不对,而且每次读到的还不一样,但是第二个属性的数据是对的,每次都对,不知道什么原因。
如果把readCmd调整如下:
readCmd.attrID[1] = ATTRID_BASIC_HW_VERSION;
readCmd.attrID[0] = ATTRID_BASIC_ZCL_VERSION;
还是第一个属性的数据不对,每次读到的还不一样,第二个都对。
不知道什么原因
2.然后我把温度的相关属性列表加入了属性记录表,包括下面三个:
// *** Temperature Measurement Attriubtes ***
{
ZCL_CLUSTER_ID_MS_TEMPERATURE_MEASUREMENT,
{ // Attribute record
ATTRID_MS_TEMPERATURE_MEASURED_VALUE,
ZCL_DATATYPE_INT16,
ACCESS_CONTROL_READ,
(void *)&zclSampleTemperatureSensor_MeasuredValue
}
},
{
ZCL_CLUSTER_ID_MS_TEMPERATURE_MEASUREMENT,
{ // Attribute record
ATTRID_MS_TEMPERATURE_MIN_MEASURED_VALUE,
ZCL_DATATYPE_INT16,
ACCESS_CONTROL_READ,
(void *)&zclSampleTemperatureSensor_MinMeasuredValue
}
},
{
ZCL_CLUSTER_ID_MS_TEMPERATURE_MEASUREMENT,
{ // Attribute record
ATTRID_MS_TEMPERATURE_MAX_MEASURED_VALUE,
ZCL_DATATYPE_UINT16,
ACCESS_CONTROL_READ,
(void *)&zclSampleTemperatureSensor_MaxMeasuredValue
}
},
然后在Switch端读属性,如下:
readCmd.attrID[1] = ATTRID_BASIC_HW_VERSION;
readCmd.attrID[0] = ATTRID_BASIC_ZCL_VERSION;
readCmd.attrID[2] = ATTRID_MS_TEMPERATURE_MEASURED_VALUE;
但是发现第三个属性的相关记录也是不对,比如数据类型应该是0x29,读到的是0x20,
-----------------------------------------------------------------------
以上问题感觉很奇怪,不知道什么原因
第二步实验有些问题,但是第一步的感觉没问题啊,但是读到的数据还是不对。
我加了温度相关的属性,然后又实验了,
设置如下:
zclReadCmd_t readCmd;
readCmd.numAttr = 2;
readCmd.attrID[0] = ATTRID_MS_TEMPERATURE_MEASURED_VALUE;
readCmd.attrID[1] = ZCL_CLUSTER_ID_MS_TEMPERATURE_MEASUREMENT;
发送读属性的函数:
zcl_SendRead( ZCLHOMEAPPSW0_ENDPOINT, &zclHomeAppSW0_DstAddr,
ZCL_CLUSTER_ID_MS_ILLUMINANCE_MEASUREMENT, &readCmd,
ZCL_FRAME_CLIENT_SERVER_DIR, false, 0);
接收到响应后的处理:
每次读到的数据都不一样,就是attrID dataType每次读到的不一样,和真实值也不一样
/*********************************************************************
* @fn zclSampleSw_ProcessInReadRspCmd
*
* @brief Process the "Profile" Read Response Command
*
* @param pInMsg - incoming message to process
*
* @return none
*/
static uint8 zclHomeAppSw0_ProcessInReadRspCmd( zclIncomingMsg_t *pInMsg )
{
zclReadRspCmd_t *readRspCmd;
uint8 i;
uint16 attrID;
uint8 dataType;
readRspCmd = (zclReadRspCmd_t *)pInMsg->attrCmd;
for (i = 0; i < readRspCmd->numAttr; i++)
{
// Notify the originator of the results of the original read attributes
// attempt and, for each successfull request, the value of the requested
// attribute
attrID = readRspCmd->attrList[i].attrID;
dataType = readRspCmd->attrList[i].dataType;
//a = *(readRspCmd->attrList[i].data);
}
return TRUE;
}
zclReadCmd_t readCmd;
typedef struct
{
uint8 numAttr; // number of attributes in the list
uint16 attrID[]; // supported attributes list - this structure should
// be allocated with the appropriate number of attributes.
} zclReadCmd_t;
需要动态分配内存吧
