待解决问题
但看源码应该是可以的,先记下有时间再看
zcl_samplesw.c
uint8 pValue[8]={0x21,0x12,0,0,0xfa,0xa3,0,0x80}; // uint8 pValue[8]={0x80,0,0xa3,0xfa,0,0,0x12,0x21}; zclSampleSw_DstAddr.addrMode = (afAddrMode_t)Addr64Bit; zclSampleSw_DstAddr.endPoint = 13; //zclSampleSw_DstAddr.addr.shortAddr=0xffff; osal_memcpy(zclSampleSw_DstAddr.addr.extAddr,pValue,8); readcmd.numAttr=2; readcmd.attrID[0]=ATTRID_BASIC_ZCL_VERSION; readcmd.attrID[1]=ATTRID_BASIC_MANUFACTURER_NAME; st= zcl_SendRead( SAMPLESW_ENDPOINT, &zclSampleSw_DstAddr, /*ZCL_CLUSTER_ID_GEN_ON_OFF*/ZCL_CLUSTER_ID_GEN_BASIC, &readcmd, ZCL_FRAME_CLIENT_SERVER_DIR, false, 0 );
2.homeautomation中,zcl_samplesw.c
绑定之后,使用如下可以成功读取到zcl_samplelight.c的属性值
/* zclSampleSw_DstAddr.addrMode = (afAddrMode_t)AddrBroadcast; zclSampleSw_DstAddr.endPoint = 13; zclSampleSw_DstAddr.addr.shortAddr=0xffff; */ readcmd.numAttr=2; readcmd.attrID[0]=ATTRID_BASIC_ZCL_VERSION; readcmd.attrID[1]=ATTRID_BASIC_MANUFACTURER_NAME; st= zcl_SendRead( SAMPLESW_ENDPOINT, &zclSampleSw_DstAddr, /*ZCL_CLUSTER_ID_GEN_ON_OFF*/ZCL_CLUSTER_ID_GEN_BASIC, &readcmd, ZCL_FRAME_CLIENT_SERVER_DIR, false, 0 );
但是如果把注释取消,就不能成功读取,具体是
对方可以收到消息,可以进入到zafIncomingData函数,但是
void afIncomingData( aps_FrameFormat_t *aff, zAddrType_t *SrcAddress, uint16 SrcPanId, NLDE_Signal_t *sig, byte SecurityUse, uint32 timestamp ) { endPointDesc_t *epDesc = NULL; uint16 epProfileID = 0xFFFF; // Invalid Profile ID epList_t *pList = epList; #if !defined ( APS_NO_GROUPS ) uint8 grpEp = APS_GROUPS_EP_NOT_FOUND; #endif if ( ((aff->FrmCtrl & APS_DELIVERYMODE_MASK) == APS_FC_DM_GROUP) ) { #if !defined ( APS_NO_GROUPS ) // Find the first endpoint for this group grpEp = aps_FindGroupForEndpoint( aff->GroupID, APS_GROUPS_FIND_FIRST ); if ( grpEp == APS_GROUPS_EP_NOT_FOUND ) return; // No endpoint found epDesc = afFindEndPointDesc( grpEp ); if ( epDesc == NULL ) return; // Endpoint descriptor not found pList = afFindEndPointDescList( epDesc->endPoint ); #else return; // Not supported #endif } else if ( aff->DstEndPoint == AF_BROADCAST_ENDPOINT ) { // Set the list if ( pList != NULL ) { epDesc = pList->epDesc; } } else if ( (epDesc = afFindEndPointDesc( aff->DstEndPoint )) ) { pList = afFindEndPointDescList( epDesc->endPoint ); } while ( epDesc )//进入不了这个循环中,貌似epDesc有问题 { } }
原因找到:
双方的端点的简单描述符里的clustlist里需要都定义需要通信的clusterid才行,并且双方方向要互补。
sw定义的outclustlist:
const cId_t zclSampleSw_OutClusterList[ZCLSAMPLESW_MAX_OUTCLUSTERS] =
{
ZCL_CLUSTER_ID_GEN_ON_OFF,
ZCL_CLUSTER_ID_GEN_BASIC
};
light定义的inclusterlist:
const cId_t zclSampleLight_InClusterList[ZCLSAMPLELIGHT_MAX_INCLUSTERS] =
{
ZCL_CLUSTER_ID_GEN_BASIC,
ZCL_CLUSTER_ID_GEN_SCENES,
ZCL_CLUSTER_ID_GEN_GROUPS,
ZCL_CLUSTER_ID_GEN_ON_OFF,
ZCL_CLUSTER_ID_GEN_LEVEL_CONTROL
};
双方简单描述符里都有ZCL_CLUSTER_ID_GEN_BASIC,则可以通过指定地址方式进行clusterid是ZCL_CLUSTER_ID_GEN_BASIC的数据通信。
在绑定的时候使用的是
ZDP_EndDeviceBindReq( &dstAddr, NLME_GetShortAddr(),
SAMPLELIGHT_ENDPOINT,
ZCL_HA_PROFILE_ID,
ZCLSAMPLELIGHT_BINDINGLIST,
bindingInClusters,
/*0, NULL, // No Outgoing clusters to bind*/
ZCLSAMPLELIGHT_BINDINGLIST, bindingInClusters,
TRUE );
双方的bindingInClusters定义都如下:
static cId_t bindingInClusters[ZCLSAMPLELIGHT_BINDINGLIST] =
{
ZCL_CLUSTER_ID_GEN_ON_OFF,
ZCL_CLUSTER_ID_GEN_BASIC
};
则双方可以通过绑定方式进行clusterid是ZCL_CLUSTER_ID_GEN_BASIC或者ZCL_CLUSTER_ID_GEN_ON_OFF的数据通信
中断函数中最好不要循环,也不要调用汗循环语句的函数,否则程序莫名其妙的出现问题,比如数组数据均变成0
void test(void); void test(void) { int i=1; while(i--); } #pragma vector = T4_VECTOR __interrupt void as_ir_rec_T4_ISR(void) { if(TIMIF &= 0x18) //Timer4溢出? { irtime++; if(irtime>18000) { T4CTL &= ~0x10; // 停止定时器T4 ifg=0; irok=1; //中断中不要调用这些函数 // osal_start_timerEx(8,SAMPLESW_IRSOURCECODE_OK,100); //test中有循环,cpu执行起来会出问题 test();// } TIMIF &= ~0x18; //清除Timer4溢出中断标记 IRCON &= ~0x10; //清除Timer4中断标记 } }