日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

zigbee 空中消息溯源

發布時間:2024/4/14 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 zigbee 空中消息溯源 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

消息發送到空中:

/********************************************************************** @fn AF_DataRequest** @brief Common functionality for invoking APSDE_DataReq() for both* SendMulti and MSG-Send.** input parameters** @param *dstAddr - Full ZB destination address: Nwk Addr + End Point.* @param *srcEP - Origination (i.e. respond to or ack to) End Point Descr.* @param cID - A valid cluster ID as specified by the Profile.* @param len - Number of bytes of data pointed to by next param.* @param *buf - A pointer to the data bytes to send.* @param *transID - A pointer to a byte which can be modified and which will* be used as the transaction sequence number of the msg.* @param options - Valid bit mask of Tx options.* @param radius - Normally set to AF_DEFAULT_RADIUS.** output parameters** @param *transID - Incremented by one if the return value is success.** @return afStatus_t - See previous definition of afStatus_... types.*/ uint8 AF_DataRequestDiscoverRoute = TRUE; afStatus_t AF_DataRequest( afAddrType_t *dstAddr, endPointDesc_t *srcEP,uint16 cID, uint16 len, uint8 *buf, uint8 *transID,uint8 options, uint8 radius ) {pDescCB pfnDescCB;ZStatus_t stat;APSDE_DataReq_t req;afDataReqMTU_t mtu;// Verify source end pointif ( srcEP == NULL ){return afStatus_INVALID_PARAMETER;}#if !defined( REFLECTOR )if ( dstAddr->addrMode == afAddrNotPresent ){return afStatus_INVALID_PARAMETER;} #endif// Validate broadcastingif ( ( dstAddr->addrMode == afAddr16Bit ) ||( dstAddr->addrMode == afAddrBroadcast ) ){// Check for valid broadcast valuesif( ADDR_NOT_BCAST != NLME_IsAddressBroadcast( dstAddr->addr.shortAddr ) ){// Force mode to broadcastdstAddr->addrMode = afAddrBroadcast;}else{// Address is not a valid broadcast typeif ( dstAddr->addrMode == afAddrBroadcast ){return afStatus_INVALID_PARAMETER;}}}else if ( dstAddr->addrMode != afAddr64Bit &&dstAddr->addrMode != afAddrGroup &&dstAddr->addrMode != afAddrNotPresent ){return afStatus_INVALID_PARAMETER;}// Set destination addressreq.dstAddr.addrMode = dstAddr->addrMode;if ( dstAddr->addrMode == afAddr64Bit )osal_cpyExtAddr( req.dstAddr.addr.extAddr, dstAddr->addr.extAddr );//數組 所以拷貝elsereq.dstAddr.addr.shortAddr = dstAddr->addr.shortAddr;//數字,直接賦值req.profileID = ZDO_PROFILE_ID;if ( (pfnDescCB = afGetDescCB( srcEP )) ){uint16 *pID = (uint16 *)(pfnDescCB(AF_DESCRIPTOR_PROFILE_ID, srcEP->endPoint ));if ( pID ){req.profileID = *pID;osal_mem_free( pID );}}else if ( srcEP->simpleDesc ){req.profileID = srcEP->simpleDesc->AppProfId;}req.txOptions = 0;if ( ( options & AF_ACK_REQUEST ) &&( req.dstAddr.addrMode != AddrBroadcast ) &&( req.dstAddr.addrMode != AddrGroup ) ){req.txOptions |= APS_TX_OPTIONS_ACK;}if ( options & AF_SKIP_ROUTING ){req.txOptions |= APS_TX_OPTIONS_SKIP_ROUTING;}if ( options & AF_EN_SECURITY ){req.txOptions |= APS_TX_OPTIONS_SECURITY_ENABLE;mtu.aps.secure = TRUE;}else{mtu.aps.secure = FALSE;}mtu.kvp = FALSE;req.transID = *transID;req.srcEP = srcEP->endPoint;req.dstEP = dstAddr->endPoint;req.clusterID = cID;req.asduLen = len;req.asdu = buf;req.discoverRoute = AF_DataRequestDiscoverRoute;//(uint8)((options & AF_DISCV_ROUTE) ? 1 : 0);req.radiusCounter = radius; #if defined ( INTER_PAN )req.dstPanId = dstAddr->panId;if ( StubAPS_InterPan( dstAddr->panId, dstAddr->endPoint ) ){if ( len > INTERP_DataReqMTU() ){stat = afStatus_INVALID_PARAMETER;}else{stat = INTERP_DataReq( &req );}}else #endif // INTER_PAN{if (len > afDataReqMTU( &mtu ) ){if (apsfSendFragmented){stat = (*apsfSendFragmented)( &req );}else{stat = afStatus_INVALID_PARAMETER;}}else{stat = APSDE_DataReq( &req );}}/** If this is an EndPoint-to-EndPoint message on the same device, it will not* get added to the NWK databufs. So it will not go OTA and it will not get* a MACCB_DATA_CONFIRM_CMD callback. Thus it is necessary to generate the* AF_DATA_CONFIRM_CMD here. Note that APSDE_DataConfirm() only generates one* message with the first in line TransSeqNumber, even on a multi message.* Also note that a reflected msg will not have its confirmation generated* here.*/if ( (req.dstAddr.addrMode == Addr16Bit) &&(req.dstAddr.addr.shortAddr == NLME_GetShortAddr()) ){afDataConfirm( srcEP->endPoint, *transID, stat );}if ( stat == afStatus_SUCCESS ){(*transID)++;}return (afStatus_t)stat; }
指定要發送到的目標地址dstAddr,包括目的網絡號,目的短地址或長地址,目的端點
typedef struct {union{uint16 shortAddr;ZLongAddr_t extAddr;} addr;afAddrMode_t addrMode;byte endPoint;uint16 panId; // used for the INTER_PAN feature } afAddrType_t; 指定發送的clustid,cID
指定要發送的數據長度,len
指定要發送的數據,buf,即asdu,應用層負載
指定發送選項options,比如是否加密?AF_SKIP_ROUTING

要向對方說明本地端點描述符:srcEP
typedef struct {byte endPoint;byte *task_id; // Pointer to location of the Application task ID.SimpleDescriptionFormat_t *simpleDesc;afNetworkLatencyReq_t latencyReq; } endPointDesc_t;其實只用到了結構體里的兩個東東
? 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;}}
空中到來的消息經過協議棧的秘密傳輸,終于在af中被暴露出來,
aff,接收到的aps層幀結構,包括如下信息
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,源網絡號
sig,信號強度
SecurityUse,是否加密
timestamp,時間戳

可見,除了SrcPanId,sig,timestamp這幾個元素是下層自動添加的,其他參數和使用afIncomingData發送過來的參數對應。



以下待續:
綁定是 ?
源端點《--》目的地址+目的端點
每次建立一個綁定,都會在自身設備中創建一條這樣的記錄,
這樣以后在發送數據的時候,只要指定源端點,而不必指定目的地址和目的端點,協議棧會從綁定表中直接讀取出來目的地址和目的端點,將數據發給他們

而設備接收時,就跟平常一樣接收就行。
但是還有一個clusterlist,似乎有點疑惑?答案:
1.綁定時使用的如果是clusterlist,雙方可以通過綁定方式進行clusterid屬于clusterlist的數據通信
2.雙方簡單描述符里的對應clusterlist都有同一個clusterid,則可以通過指定地址方式進行此clusterid的數據通信。
3.一般發命令的是outclusterlist,接收命令并回應的是inclusterlist,但是實驗中發現沒有這個規定。只要雙方通信端點的clusterlist的方向相反,內容一樣就可以對clusterlist的clusterid通信。
http://blog.csdn.net/songqqnew/article/details/8684315

轉載于:https://www.cnblogs.com/-song/archive/2013/02/24/3331825.html

總結

以上是生活随笔為你收集整理的zigbee 空中消息溯源的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。