1、关于zigbee协议栈SerialApp工程里ZDPMatchDescReq发起的简单描述符绑定机制#if defined ( ZDO_MATCH_REQUEST )/该函数进行简单描述符匹配/* * fn ZDP_MatchDescReq * * brief This builds and send a Match_Desc_req message. This * function sends a broadcast or unicast message * requesting the list of endpoint/interfaces that * match profile ID
2、and cluster IDs. * * param dstAddr - destination address * param ProfileID - Profile ID * param NumInClusters - number of input clusters * param InClusterList - input cluster ID list * param NumOutClusters - number of output clusters * param OutClusterList - output cluster ID list * param SecurityEn
3、able - Security Options * * return afStatus_t */afStatus_t ZDP_MatchDescReq( zAddrType_t *dstAddr, uint16 nwkAddr, uint16 ProfileID, byte NumInClusters, cId_t *InClusterList, byte NumOutClusters, cId_t *OutClusterList, byte SecurityEnable ) byte *pBuf = ZDP_TmpBuf; / nwkAddr+ProfileID+NumInClusters+
4、NumOutClusters. byte i, len = 2 + 2 + 1 + 1; / nwkAddr+ProfileID+NumInClusters+NumOutClusters.(网络地址,PROfileID,输入输出簇 数量) len += (NumInClusters + NumOutClusters) * sizeof(uint16); if ( len = ZDP_BUF_SZ-1 ) return afStatus_MEM_FAIL; *pBuf+ = LO_UINT16( nwkAddr ); / NWKAddrOfInterest *pBuf+ = HI_UINT16(
5、 nwkAddr ); *pBuf+ = LO_UINT16( ProfileID ); / Profile ID *pBuf+ = HI_UINT16( ProfileID ); *pBuf+ = NumInClusters; / Input cluster list if ( NumInClusters ) for (i=0; iNumInClusters; +i) *pBuf+ = LO_UINT16( InClusterListi ); *pBuf+ = HI_UINT16( InClusterListi ); *pBuf+ = NumOutClusters; / Output clu
6、ster list if ( NumOutClusters ) for (i=0; iasdu; aoi = BUILD_UINT16( msg0, msg1 );/保存网络地址 profileID = BUILD_UINT16( msg2, msg3 );/保存空中接收过来的Profile ID msg += 4; if ( ADDR_BCAST_NOT_ME = NLME_IsAddressBroadcast(aoi) ) ZDP_MatchDescRsp( inMsg-TransSeq, &(inMsg-srcAddr), ZDP_INVALID_REQTYPE, ZDAppNwkAdd
7、r.addr.shortAddr, 0, NULL, inMsg-SecurityUse ); return; else if ( (ADDR_NOT_BCAST = NLME_IsAddressBroadcast(aoi) & (aoi != ZDAppNwkAddr.addr.shortAddr) ) ZDP_MatchDescRsp( inMsg-TransSeq, &(inMsg-srcAddr), ZDP_INVALID_REQTYPE, ZDAppNwkAddr.addr.shortAddr, 0, NULL, inMsg-SecurityUse ); return; numInC
8、lusters = *msg+; if ( numInClusters ) inClusters = (uint16*)osal_mem_alloc( numInClusters * sizeof( uint16 ) ); msg = ZDO_ConvertOTAClusters( numInClusters, msg, inClusters );/将空中传过来的输入簇列表进行整理保存 numOutClusters = *msg+; if ( numOutClusters ) outClusters = (uint16 *)osal_mem_alloc( numOutClusters * si
9、zeof( uint16 ) ); msg = ZDO_ConvertOTAClusters( numOutClusters, msg, outClusters );/将空中传过来的输出簇列表进行整理保存 / First count the number of endpoints that match./数出跟空中传过来消息匹配的端口数量 epDesc = epList;/保存本设备的注册端点列表 while ( epDesc ) / Dont search endpoint 0 and check if response is allowed if ( epDesc-epDesc-endPo
10、int != ZDO_EP & (epDesc-flags&eEP_AllowMatch) )/本设备满条件:端点号不为0并且允许匹配 if ( epDesc-pfnDescCB )/?什么意思处理的回调函数,该选项默认为NULL sDesc = (SimpleDescriptionFormat_t *)epDesc-pfnDescCB( AF_DESCRIPTOR_SIMPLE, epDesc-epDesc-endPoint ); allocated = TRUE; else sDesc = epDesc-epDesc-simpleDesc;/保存本设备简单描述符在sDesc! alloca
11、ted = FALSE; if ( sDesc & sDesc-AppProfId = profileID )/本设备的简单描述符不为空并且ProfileID等于空中传过来要匹配的ProfileID uint8 *uint8Buf = (uint8 *)ZDOBuildBuf; / If there are no search input/ouput clusters - respond if ( (numInClusters = 0) & (numOutClusters = 0)/或者输入簇数量跟输出簇数量为零 / Are there matching input clusters? | (
12、ZDO_AnyClusterMatches( numInClusters, inClusters, sDesc-AppNumInClusters, sDesc-pAppInClusterList )/或者空中输入簇和本设备的输入簇匹配 / Are there matching output clusters? | (ZDO_AnyClusterMatches( numOutClusters, outClusters, sDesc-AppNumOutClusters, sDesc-pAppOutClusterList ) /或者空中输出簇和本设备的输出簇匹配 ) / Notify the end
13、point of the match. 公告匹配的设备 uint8 bufLen = sizeof( ZDO_MatchDescRspSent_t ) + (numOutClusters + numInClusters) * sizeof(uint16); ZDO_MatchDescRspSent_t *pRspSent = (ZDO_MatchDescRspSent_t *) osal_msg_allocate( bufLen ); if (pRspSent) pRspSent-hdr.event = ZDO_MATCH_DESC_RSP_SENT; pRspSent-nwkAddr = i
14、nMsg-srcAddr.addr.shortAddr;/保存空中源地址 pRspSent-numInClusters = numInClusters; pRspSent-numOutClusters = numOutClusters; if (numInClusters) pRspSent-pInClusters = (uint16*) (pRspSent + 1); osal_memcpy(pRspSent-pInClusters, inClusters, numInClusters * sizeof(uint16);/将空中的输入簇列表进行了保存 else pRspSent-pInClu
15、sters = NULL; if (numOutClusters) pRspSent-pOutClusters = (uint16*)(pRspSent + 1) + numInClusters; osal_memcpy(pRspSent-pOutClusters, outClusters, numOutClusters * sizeof(uint16);/将空中的输出簇列表进行了保存 else pRspSent-pOutClusters = NULL; osal_msg_send( *epDesc-epDesc-task_id, (uint8 *)pRspSent );/ uint8Bufe
16、pCnt+ = sDesc-EndPoint; if ( allocated ) osal_mem_free( sDesc ); epDesc = epDesc-nextDesc; /找下一个端点 / Send the message only if at least one match found. if ( epCnt ) if ( ZSuccess = ZDP_MatchDescRsp( inMsg-TransSeq, &(inMsg-srcAddr), ZDP_SUCCESS, ZDAppNwkAddr.addr.shortAddr, epCnt, (uint8 *)ZDOBuildB
17、uf, inMsg-SecurityUse ) )/见下 #if defined( LCD_SUPPORTED ) HalLcdWriteScreen( Match Desc Req, Rsp Sent );#endif else #if defined( LCD_SUPPORTED ) HalLcdWriteScreen( Match Desc Req, Non Matched );#endif if ( inClusters ) osal_mem_free( inClusters ); if ( outClusters ) osal_mem_free( outClusters );/* *
18、 ZDP_MatchDescRsp - Send an list of endpoint that match */#define ZDP_MatchDescRsp( TransSeq, dstAddr, Status, nwkAddr, Count, pEPList, SecurityEnable ) ZDP_EPRsp( Match_Desc_rsp, TransSeq, dstAddr, Status, nwkAddr, Count, pEPList, SecurityEnable ) /注意簇ID为Match_Desc_rsp* * fn ZDP_EPRsp * * brief Thi
19、s builds and send an endpoint list. Used in * Active_EP_rsp and Match_Desc_Rsp * message. This function sends unicast message to the * requesting device. * * param MsgType - either Active_EP_rsp or Match_Desc_Rsp * param dstAddr - destination address * param Status - message status (ZDP_SUCCESS or o
20、ther) * param nwkAddr - Devices short address that this response describes * param Count - number of endpoint/interfaces in list * param pEPIntfList - Array of Endpoint/Interfaces * param SecurityEnable - Security Options * * return afStatus_t */afStatus_t ZDP_EPRsp( uint16 MsgType, byte TransSeq, z
21、AddrType_t *dstAddr, byte Status, uint16 nwkAddr, byte Count, byte *pEPList, byte SecurityEnable ) byte *pBuf = ZDP_TmpBuf; byte len = 1 + 2 + 1; / Status + nwkAddr + endpoint/interface count. byte txOptions; if ( MsgType = Match_Desc_rsp ) txOptions = AF_MSG_ACK_REQUEST; else txOptions = 0; *pBuf+
22、= Status; *pBuf+ = LO_UINT16( nwkAddr ); *pBuf+ = HI_UINT16( nwkAddr ); /分装本设备的网络地址 *pBuf+ = Count; / Endpoint/Interface count /簇匹配的数量 if ( Count ) len += Count; osal_memcpy( pBuf, pEPList, Count ); FillAndSendTxOptions( &TransSeq, dstAddr, MsgType, len, txOptions );#define FillAndSendTxOptions( TRA
23、NSSEQ, ADDR, ID, LEN, TxO ) afStatus_t stat; ZDP_TxOptions = (TxO); stat = fillAndSend( (TRANSSEQ), (ADDR), (ID), (LEN) ); ZDP_TxOptions = AF_TX_OPTIONS_NONE; return stat; static afStatus_t fillAndSend( uint8 *transSeq, zAddrType_t *addr, cId_t clusterID, byte len ) afAddrType_t afAddr; ZADDR_TO_AFA
24、DDR( addr, afAddr ); *(ZDP_TmpBuf-1) = *transSeq; return AF_DataRequest( &afAddr, &ZDApp_epDesc, clusterID, (uint16)(len+1), (uint8*)(ZDP_TmpBuf-1), transSeq, ZDP_TxOptions, AF_DEFAULT_RADIUS );void ZDApp_ProcessOSALMsg( osal_event_hdr_t *msgPtr ) / Data Confirmation message fields byte sentEP; / This should always be 0 byte sentStatus; afDataConfirm_t *afDataConfirm; switch ( msgPtr-event ) / Incoming ZDO Message case AF_INCOMING_MSG_CMD: ZDP_IncomingData( (afIncomingMSGPacket_t *)msgPtr ); break; case ZDO_CB_MSG: Z
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1