国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

12 關于端點(Endpoint)、簇(clusterId)以及規范(ProfileID)

2019-11-08 03:09:10
字體:
來源:轉載
供稿:網友

Endpoint

1、他是一個字節編號的,數據收和發送的基本單元,在模塊通信的時候,發送模塊必須指定收發雙方模塊的網絡地址和端點。

2、端點要使用必須要和模塊里的某個任務掛鉤定義;

首先每一個端點可以看成是一個1個字節數字編號的開有一扇門的房間,數據最終的目標是進入到無線數據包指定的目標端點房間,而取無線數據這個相關的代碼在任務事件處理函數里,TI協議棧有那么多的任務事件處理函數,所以必須要指定在哪個任務事件處理函數 來取這個無線數據包里面的有用數據。

3、一個端點只能掛鉤在一個任務上,而一個任務可以掛鉤多個端點,且端點對所有的任務是公用的,定義一個少一個。 一個端點假如可以掛鉤在多個任務上,那么接收模塊接到無線數據時候,這個時候同一個端點有多個任務事件處理函數去處理,不合理;一個任務上掛多個端點(6 7 掛應用層任務),發送給協調器模塊的6 7端點的數據都會進入到應用層任務事件處理函數里來,僅僅做個判斷到底是投遞到6房間還是7號房間就可以了。

結合代碼,定義端點和任務掛鉤在基礎實驗的代碼里是那些代碼

SimonApp.c

void SimonApp_Init( byte task_id ) //定義了10號端點并且和這個模塊的應用層任務掛鉤

{..// Fill out the endpoint description. SimonApp_epDesc.endPoint = 10;//SimonApp_ENDPOINT; 此端點編號為10 SimonApp_epDesc.task_id = &SimonApp_TaskID; 和我們應用層任務掛鉤 SimonApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&SimonApp_SimpleDesc;//更加詳細的描述這個端點一些情況就像我們定義一個編號房間,描述房間里大概有多少人之類的信息。 SimonApp_epDesc.latencyReq = noLatencyReqs;//差不多 // Register the endpoint description with the AF afRegister( &SimonApp_epDesc );//這個函數必須要調用才能完成整個掛鉤操作..}

端點描述符,代碼里一個結構體SimonApp_epDesc

所以,基本實驗是0xA406 10 <—–>0x0000 10 無線數據包發出去以后,首先目標協調器模塊的網絡地址0x0000對上了,協調器可以拿到這個無線數據包。在底層任務,判斷10號端點房間已經定義且和應用層任務掛鉤,那么這個無線數據包發送一個消息到們應用層任務 。

case AF_INCOMING_MSG_CMD: SimonApp_MessageMSGCB( MSGpkt ); break;

在消息處理里,把hello Simon 通過串口送出去 Uart_Send_String(pkt->cmd.Data,pkt->cmd.DataLength);

端點就相當于一個房間的門牌號!!!

簇 ClusterID

簇就是相當于端點房間里面的人,是接收最終的目標。這東西是2個字節編號,在射頻發送的時候,必須要指定接收模塊的鏃,發送模塊不需要指定。

結合代碼發送模塊: 在發送模塊里,我們用的數據發送源端點,也是10,所以我們也定義這個10端點也掛鉤應用層任務,原則上,外部給我們終端模塊10號端點來數據,也會進入終端應用層任務事件處理 函數里。而我們這個端點僅僅這里作為發送模塊,但是我們要實用10端點,必須要掛鉤定義。

發送幀里面的東西在代碼里體現:

byte SimonApp_TransID; // This is the unique message ID (counter) SimonApp.c全局變量,記錄我們應用層任務發送的數據包的個數

void SimonApp_Init( byte task_id ){.. SimonApp_TransID = 0;..} if(0==P1_1) {//按鈕3按下 char theMessageData[] ="Hello lao da"; SimonApp_DstAddr.addrMode = (afAddrMode_t)Addr16Bit; SimonApp_DstAddr.addr.shortAddr = 0x0000;//接收模塊的網絡地址 // Take the first endpoint, Can be changed to search through endpoints SimonApp_DstAddr.endPoint =SimonApp_ENDPOINT ;//接收模塊的端點房間號 //SimonApp_epDesc 結構體 端點描述符有源端點的信息,也是10 AF_DataRequest( &SimonApp_DstAddr, &SimonApp_epDesc, SimonApp_CLUSTERID,//目標端點鏃,房間里的接收人數據宏是1,2個字節,所以在射頻幀里面是0x0001 (byte)osal_strlen( theMessageData ) + 1,//發送字符串的長度 (byte *)&theMessageData,//字符串內容數組的首地址 &SimonApp_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ); P1SEL &=0Xfe;// 1111 1110 P1DIR |=0X01; P1_0 ^=1;

再發送方總體框架:

if ( events & SimonApp_MY_EVT ) { if(0==P1_1) {//按鈕3按下 char theMessageData[] ={3}; SimonApp_DstAddr.addrMode = (afAddrMode_t)Addr16Bit; SimonApp_DstAddr.addr.shortAddr = 0x0000; // Take the first endpoint, Can be changed to search through endpoints SimonApp_DstAddr.endPoint = 7; AF_DataRequest( &SimonApp_DstAddr, &SimonApp_epDesc, 0x0001, 1,//(byte)osal_strlen( theMessageData ) + 1, (byte *)&theMessageData, &SimonApp_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ); } if(0==P2_0) {//按鈕4按下 char theMessageData[] ={4}; SimonApp_DstAddr.addrMode = (afAddrMode_t)Addr16Bit; SimonApp_DstAddr.addr.shortAddr = 0x0000; // Take the first endpoint, Can be changed to search through endpoints SimonApp_DstAddr.endPoint = 7; AF_DataRequest( &SimonApp_DstAddr, &SimonApp_epDesc, 0x0002, 1,//(byte)osal_strlen( theMessageData ) + 1, (byte *)&theMessageData, &SimonApp_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ); } if(0==P0_5) {//按鈕5按下 char theMessageData[] ={5}; SimonApp_DstAddr.addrMode = (afAddrMode_t)Addr16Bit; SimonApp_DstAddr.addr.shortAddr = 0x0000; // Take the first endpoint, Can be changed to search through endpoints SimonApp_DstAddr.endPoint = 6; AF_DataRequest( &SimonApp_DstAddr, &SimonApp_epDesc, 0x0001, 1,//(byte)osal_strlen( theMessageData ) + 1, (byte *)&theMessageData, &SimonApp_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ); } return (events ^ SimonApp_MY_EVT); }

在接收方可使用如下代碼識別具體端點、具體簇:

void SimonApp_MessageMSGCB( afIncomingMSGPacket_t *pkt ){ if ( 7 == pkt->endPoint ) { switch ( pkt->clusterId ) { case 0x0001: // "the" message #if defined( LCD_SUPPORTED ) HalLcdWriteScreen( (char*)pkt->cmd.Data, "rcvd" ); #elif defined( WIN32 ) WPRINTSTR( pkt->cmd.Data ); #endif Uart_Send_String(pkt->cmd.Data,pkt->cmd.DataLength); LS164_BYTE(pkt->cmd.Data[0]); MYLED1 ^= 1; break; case 0x0002: Uart_Send_String(pkt->cmd.Data,pkt->cmd.DataLength); LS164_BYTE(pkt->cmd.Data[0]); MYLED2 ^= 1; break; } } if ( 6 == pkt->endPoint ) { switch ( pkt->clusterId ) { case 0x0001: // "the" message #if defined( LCD_SUPPORTED ) HalLcdWriteScreen( (char*)pkt->cmd.Data, "rcvd" ); #elif defined( WIN32 ) WPRINTSTR( pkt->cmd.Data ); #endif Uart_Send_String(pkt->cmd.Data,pkt->cmd.DataLength); LS164_BYTE(pkt->cmd.Data[0]); MYLED3 ^= 1; break; } }}

初始化函數里面有如下語句用來填充端點描述符和簇信息:

>// Fill out the endpoint description. SimonApp_epDesc.endPoint = 11;//SimonApp_ENDPOINT; SimonApp_epDesc.task_id = &SimonApp_TaskID; SimonApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&SimonApp_SimpleDesc; SimonApp_epDesc.latencyReq = noLatencyReqs; // Register the endpoint description with the AF afRegister( &SimonApp_epDesc );

其中的

SimonApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&SimonApp_SimpleDesc;

完成了簇信息表的構建,因為簇信息封裝在SimonApp_SimpleDesc里面,這里面卻只是起到一個信息表的作用!方便數據到來的時候查詢相關信息表!但真正的一個房間(端點)有多少人(簇),卻是在SimonApp_MessageMSGCB函數中判斷數據包攜帶的clusterId成員時決定的!!!

具體的SimonApp_SimpleDesc相關定義如下:

// This list should be filled with application specific Cluster IDs.const cId_t SimonApp_ClusterList[SimonApp_MAX_CLUSTERS] ={ SimonApp_CLUSTERID};const SimpleDescriptionFormat_t SimonApp_SimpleDesc ={ SimonApp_ENDPOINT, // int Endpoint; SimonApp_PROFID, // uint16 AppProfId[2]; SimonApp_DEVICEID, // uint16 AppDeviceId[2]; SimonApp_DEVICE_VERSION, // int AppDevVer:4; SimonApp_FLAGS, // int AppFlags:4; SimonApp_MAX_CLUSTERS, // byte AppNumInClusters; (cId_t *)SimonApp_ClusterList, // byte *pAppInClusterList; SimonApp_MAX_CLUSTERS, // byte AppNumInClusters; (cId_t *)SimonApp_ClusterList // byte *pAppInClusterList;};

規范

也叫作屬性(ProfileID),實際上他就是代表不同類型的應用具有不同的ProfileID,這些表現在有效載荷里面!所以不同協議棧版本主要區別就是這個屬性不同而已!!!

屬性就是在應用層有用的數據載荷,做專門規定應用類型的最小單元

#define SimonApp_PROFID 0x0F04 在端點描述符里有提到,所以在無線數據包(抓包)里有看到相關的信息!!

綜合實例

終端節點–發送

Enddevice.c

填充端點,和應用掛鉤void SimonApp_Init( byte task_id ){ SimonApp_TaskID = task_id; SimonApp_NwkState = DEV_INIT; SimonApp_TransID = 0; ... ... // Fill out the endpoint description. SimonApp_epDesc.endPoint = 11;//SimonApp_ENDPOINT; SimonApp_epDesc.task_id = &SimonApp_TaskID; SimonApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&SimonApp_SimpleDesc; SimonApp_epDesc.latencyReq = noLatencyReqs; // Register the endpoint description with the AF afRegister( &SimonApp_epDesc ); ... ...}處理按鍵事件 按鍵通過自定義的中斷函數設置SimonApp_MY_EVT 事件,導致調用以下代碼:if ( events & SimonApp_MY_EVT ) { if(0==P1_1) {//按鈕3按下 char theMessageData[] ={3}; SimonApp_DstAddr.addrMode = (afAddrMode_t)Addr16Bit; SimonApp_DstAddr.addr.shortAddr = 0x0000; // Take the first endpoint, Can be changed to search through endpoints SimonApp_DstAddr.endPoint = 7; AF_DataRequest( &SimonApp_DstAddr, &SimonApp_epDesc, 0x0001, 1,//(byte)osal_strlen( theMessageData ) + 1, (byte *)&theMessageData, &SimonApp_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ); } if(0==P2_0) {//按鈕4按下 char theMessageData[] ={4}; SimonApp_DstAddr.addrMode = (afAddrMode_t)Addr16Bit; SimonApp_DstAddr.addr.shortAddr = 0x0000; // Take the first endpoint, Can be changed to search through endpoints SimonApp_DstAddr.endPoint = 7; AF_DataRequest( &SimonApp_DstAddr, &SimonApp_epDesc, 0x0002, 1,//(byte)osal_strlen( theMessageData ) + 1, (byte *)&theMessageData, &SimonApp_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ); } if(0==P0_5) {//按鈕5按下 char theMessageData[] ={5}; SimonApp_DstAddr.addrMode = (afAddrMode_t)Addr16Bit; SimonApp_DstAddr.addr.shortAddr = 0x0000; // Take the first endpoint, Can be changed to search through endpoints SimonApp_DstAddr.endPoint = 6; AF_DataRequest( &SimonApp_DstAddr, &SimonApp_epDesc, 0x0001, 1,//(byte)osal_strlen( theMessageData ) + 1, (byte *)&theMessageData, &SimonApp_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ); } return (events ^ SimonApp_MY_EVT); }

協調器–接收

填充端點、綁定應用層任務 SimonAPP.cvoid SimonApp_Init( byte task_id ){... ...// Fill out the endpoint description. SimonApp_epDesc.endPoint = 7;//SimonApp_ENDPOINT; SimonApp_epDesc.task_id = &SimonApp_TaskID; SimonApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&SimonApp_SimpleDesc; SimonApp_epDesc.latencyReq = noLatencyReqs; // Register the endpoint description with the AF afRegister( &SimonApp_epDesc ); /*=========================================================================*/ // Fill out the endpoint description. SimonApp_epDesc1.endPoint = 6;//SimonApp_ENDPOINT; SimonApp_epDesc1.task_id = &SimonApp_TaskID; SimonApp_epDesc1.simpleDesc = (SimpleDescriptionFormat_t *)&SimonApp_SimpleDesc; SimonApp_epDesc1.latencyReq = noLatencyReqs; // Register the endpoint description with the AF afRegister( &SimonApp_epDesc1 );... ... }接收到數據以后,判斷是屬于哪一個端點、屬于哪一個簇void SimonApp_MessageMSGCB( afIncomingMSGPacket_t *pkt ){ if ( 7 == pkt->endPoint ) { switch ( pkt->clusterId ) { case 0x0001: Uart_Send_String(pkt->cmd.Data,pkt->cmd.DataLength); LS164_BYTE(pkt->cmd.Data[0]); MYLED1 ^= 1; break; case 0x0002: Uart_Send_String(pkt->cmd.Data,pkt->cmd.DataLength); LS164_BYTE(pkt->cmd.Data[0]); MYLED2 ^= 1; break; } } if ( 6 == pkt->endPoint ) { switch ( pkt->clusterId ) { case 0x0001: // "the" message #if defined( LCD_SUPPORTED ) HalLcdWriteScreen( (char*)pkt->cmd.Data, "rcvd" ); #elif defined( WIN32 ) WPRINTSTR( pkt->cmd.Data ); #endif Uart_Send_String(pkt->cmd.Data,pkt->cmd.DataLength); LS164_BYTE(pkt->cmd.Data[0]); MYLED3 ^= 1; break; } }}

這里才是真正的判斷一個房間有哪些人,具體數據又屬于誰!!實際上與初始化的時候指定的簇數組無關!!!


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 白水县| 尚志市| 房产| 北票市| 新巴尔虎右旗| 项城市| 福泉市| 龙游县| 四会市| 白水县| 安徽省| 盐亭县| 岚皋县| 长阳| 图们市| 南岸区| 广元市| 宁化县| 义乌市| 镇宁| 永丰县| 南康市| 富宁县| 大悟县| 北川| 澳门| 海南省| 日喀则市| 会东县| 同德县| 武冈市| 深圳市| 玉山县| 阿巴嘎旗| 乐清市| 克拉玛依市| 竹山县| 琼结县| 博客| 图们市| 诸城市|