刚刚测试了doorlock 与doorlockcontroller例程,控制作为终端,,接收端为协调器,终端能成功的控制协调器开关,命令能发送出去!那么问题也来了:之前做SampleApp实验时,,里面发送数据都是调用了AF_DataRequest()函数,但是在这个例程里面没找到?请问下大家,doorlockcontroller例程里面数据是通过什么函数发送出去的呢?
gaoyang9992006:
zcl_SendCommand( SAMPLEDOORLOCK_ENDPOINT, dstAddr, clusterID, hdr->commandID, TRUE, ZCL_FRAME_CLIENT_SERVER_DIR, hdr->fc.disableDefaultRsp, 0, hdr->transSeqNum, len, data );应该是这个吧,这个是发送指令。。。
gang ma2:
回复 gaoyang9992006:
我想发送长一点的数据,不是一个命令,而且,这个发送函数,触发的是接收方的哪个事件啊?
xiuqiang chen:
回复 gang ma2:
触发的是接收方ZCL_INCOMING_MSG。事件处理函数里面对各种命令进行解析处理。
Susan Yang:
回复 gang ma2:
您可以在协议栈内继续使用AF_DataRequest发送数据的
gang ma2:
回复 Susan Yang:
可是AF_DataRequest()函数里面的参数改怎么设置呢?前两个参数以及SAMPLEAPP_TransID这些在DoorLockComtrol的例程里面都没有啊?有HA的例程里有用AF_DataRequest()的示例吗?
Alvin Chen:
回复 gang ma2:
HA 引出了ZCL,您可以在zcl.c中看到。举例一下:
ZStatus_t zcl_SendCommand( uint8 srcEP, afAddrType_t *destAddr,uint16 clusterID, uint8 cmd, uint8 specific, uint8 direction,uint8 disableDefaultRsp, uint16 manuCode, uint8 seqNum,uint16 cmdFormatLen, uint8 *cmdFormat ) {endPointDesc_t *epDesc;zclFrameHdr_t hdr;uint8 *msgBuf;uint16 msgLen;uint8 *pBuf;uint8 options;ZStatus_t status;epDesc = afFindEndPointDesc( srcEP );if ( epDesc == NULL ){return ( ZInvalidParameter ); // EMBEDDED RETURN}#if defined ( INTER_PAN )if ( StubAPS_InterPan( destAddr->panId, destAddr->endPoint ) ){options = AF_TX_OPTIONS_NONE;}else #endif{options = zclGetClusterOption( srcEP, clusterID );// The cluster might not have been defined to use security but if this message// is in response to another message that was using APS security this message// will be sent with APS securityif ( !( options & AF_EN_SECURITY ) ){afIncomingMSGPacket_t *origPkt = zcl_getRawAFMsg();if ( ( origPkt != NULL ) && ( origPkt->SecurityUse == TRUE ) ){options |= AF_EN_SECURITY;}}}zcl_memset( &hdr, 0, sizeof( zclFrameHdr_t ) );// Not Profile wide command (like READ, WRITE)if ( specific ){hdr.fc.type = ZCL_FRAME_TYPE_SPECIFIC_CMD;}else{hdr.fc.type = ZCL_FRAME_TYPE_PROFILE_CMD;}if ( ( epDesc->simpleDesc == NULL ) ||( zcl_DeviceOperational( srcEP, clusterID, hdr.fc.type,cmd, epDesc->simpleDesc->AppProfId ) == FALSE ) ){return ( ZFailure ); // EMBEDDED RETURN}// Fill in the Maufacturer Codeif ( manuCode != 0 ){hdr.fc.manuSpecific = 1;hdr.manuCode = manuCode;}// Set the Command Directionif ( direction ){hdr.fc.direction = ZCL_FRAME_SERVER_CLIENT_DIR;}else{hdr.fc.direction = ZCL_FRAME_CLIENT_SERVER_DIR;}// Set the Disable Default Response fieldif ( disableDefaultRsp ){hdr.fc.disableDefaultRsp = 1;}else{hdr.fc.disableDefaultRsp = 0;}// Fill in the Transaction Sequence Numberhdr.transSeqNum = seqNum;// Fill in the commandhdr.commandID = cmd;// calculate the needed buffer sizemsgLen = zclCalcHdrSize( &hdr );msgLen += cmdFormatLen;// Allocate the buffer neededmsgBuf = zcl_mem_alloc( msgLen );if ( msgBuf != NULL ){// Fill in the ZCL HeaderpBuf = zclBuildHdr( &hdr, msgBuf );// Fill in the command framezcl_memcpy( pBuf, cmdFormat, cmdFormatLen );status = AF_DataRequest( destAddr, epDesc, clusterID, msgLen, msgBuf,&zcl_TransID, options, AF_DEFAULT_RADIUS );zcl_mem_free ( msgBuf );}else{status = ZMemError;}return ( status ); }