zigbee 空中消息溯源
生活随笔
收集整理的這篇文章主要介紹了
zigbee 空中消息溯源
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
消息發(fā)送到空中:
指定要發(fā)送到的目標地址dstAddr,包括目的網(wǎng)絡(luò)號,目的短地址或長地址,目的端點
typedef struct {union{uint16 shortAddr;ZLongAddr_t extAddr;} addr;afAddrMode_t addrMode;byte endPoint;uint16 panId; // used for the INTER_PAN feature } afAddrType_t; 指定發(fā)送的clustid,cID
指定要發(fā)送的數(shù)據(jù)長度,len
指定要發(fā)送的數(shù)據(jù),buf,即asdu,應用層負載
指定發(fā)送選項options,比如是否加密?AF_SKIP_ROUTING
要向?qū)Ψ秸f明本地端點描述符:srcEP
typedef struct {byte endPoint;byte *task_id; // Pointer to location of the Application task ID.SimpleDescriptionFormat_t *simpleDesc;afNetworkLatencyReq_t latencyReq; } endPointDesc_t;其實只用到了結(jié)構(gòu)體里的兩個東東
? req.profileID = srcEP->simpleDesc->AppProfId;
? req.srcEP ? ? ? ? = srcEP->endPoint;
空中到來的消息:
/********************************************************************** @fn afIncomingData** @brief Transfer a data PDU (ASDU) from the APS sub-layer to the AF.** @param aff - pointer to APS frame format* @param SrcAddress - Source address* @param sig - incoming message's link quality* @param SecurityUse - Security enable/disable** @return none*/ 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 IDepList_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 groupgrpEp = aps_FindGroupForEndpoint( aff->GroupID, APS_GROUPS_FIND_FIRST );if ( grpEp == APS_GROUPS_EP_NOT_FOUND )return; // No endpoint foundepDesc = afFindEndPointDesc( grpEp );if ( epDesc == NULL )return; // Endpoint descriptor not foundpList = afFindEndPointDescList( epDesc->endPoint ); #elsereturn; // Not supported #endif }else if ( aff->DstEndPoint == AF_BROADCAST_ENDPOINT ){// Set the listif ( pList != NULL ){epDesc = pList->epDesc;}}else if ( (epDesc = afFindEndPointDesc( aff->DstEndPoint )) ){pList = afFindEndPointDescList( epDesc->endPoint );}while ( epDesc ){if ( pList->pfnDescCB ){uint16 *pID = (uint16 *)(pList->pfnDescCB(AF_DESCRIPTOR_PROFILE_ID, epDesc->endPoint ));if ( pID ){epProfileID = *pID;osal_mem_free( pID );}}else if ( epDesc->simpleDesc ){epProfileID = epDesc->simpleDesc->AppProfId;}if ( (aff->ProfileID == epProfileID) ||((epDesc->endPoint == ZDO_EP) && (aff->ProfileID == ZDO_PROFILE_ID)) ){{afBuildMSGIncoming( aff, epDesc, SrcAddress, SrcPanId, sig, SecurityUse, timestamp );}}if ( ((aff->FrmCtrl & APS_DELIVERYMODE_MASK) == APS_FC_DM_GROUP) ){ #if !defined ( APS_NO_GROUPS ) // Find the next endpoint for this groupgrpEp = aps_FindGroupForEndpoint( aff->GroupID, grpEp );if ( grpEp == APS_GROUPS_EP_NOT_FOUND )return; // No endpoint foundepDesc = afFindEndPointDesc( grpEp );if ( epDesc == NULL )return; // Endpoint descriptor not foundpList = afFindEndPointDescList( epDesc->endPoint ); #elsereturn; #endif }else if ( aff->DstEndPoint == AF_BROADCAST_ENDPOINT ){pList = pList->nextDesc;if ( pList )epDesc = pList->epDesc;elseepDesc = NULL;}elseepDesc = NULL;}}
空中到來的消息經(jīng)過協(xié)議棧的秘密傳輸,終于在af中被暴露出來,
aff,接收到的aps層幀結(jié)構(gòu),包括如下信息
typedef struct {byte FrmCtrl;byte XtndFrmCtrl;byte DstEndPoint;byte SrcEndPoint;uint16 GroupID;uint16 ClusterID;uint16 ProfileID;uint16 macDestAddr;byte wasBroadcast;byte apsHdrLen;byte *asdu;byte asduLength;byte ApsCounter;uint8 transID;uint8 BlkCount;uint8 AckBits; } aps_FrameFormat_t; 其中重要信息有:目的端點,源端點,組號,clustid,profileid,asdu(應用層負載),asdu len
SrcAddress,源地址,包括如下東東
typedef struct {union{uint16 shortAddr;ZLongAddr_t extAddr;} addr;byte addrMode; } zAddrType_t;
SrcPanId,源網(wǎng)絡(luò)號
sig,信號強度
SecurityUse,是否加密
timestamp,時間戳
可見,除了SrcPanId,sig,timestamp這幾個元素是下層自動添加的,其他參數(shù)和使用afIncomingData發(fā)送過來的參數(shù)對應。
以下待續(xù):
綁定是 ?
源端點《--》目的地址+目的端點
每次建立一個綁定,都會在自身設(shè)備中創(chuàng)建一條這樣的記錄,
這樣以后在發(fā)送數(shù)據(jù)的時候,只要指定源端點,而不必指定目的地址和目的端點,協(xié)議棧會從綁定表中直接讀取出來目的地址和目的端點,將數(shù)據(jù)發(fā)給他們
而設(shè)備接收時,就跟平常一樣接收就行。
但是還有一個clusterlist,似乎有點疑惑?答案:
1.綁定時使用的如果是clusterlist,雙方可以通過綁定方式進行clusterid屬于clusterlist的數(shù)據(jù)通信
2.雙方簡單描述符里的對應clusterlist都有同一個clusterid,則可以通過指定地址方式進行此clusterid的數(shù)據(jù)通信。
3.一般發(fā)命令的是outclusterlist,接收命令并回應的是inclusterlist,但是實驗中發(fā)現(xiàn)沒有這個規(guī)定。只要雙方通信端點的clusterlist的方向相反,內(nèi)容一樣就可以對clusterlist的clusterid通信。
http://blog.csdn.net/songqqnew/article/details/8684315
轉(zhuǎn)載于:https://www.cnblogs.com/-song/archive/2013/02/24/3331825.html
總結(jié)
以上是生活随笔為你收集整理的zigbee 空中消息溯源的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: zigbee bind, ZDO_Reg
- 下一篇: zigbee 协议栈原语及zstack