1、剛開始,我們確實需要借助官方模板,添加簡單的代碼,做出通信基本收發實驗,建立感性的認識。
2、然后,在官方代碼基本實驗基礎上,了解相關的概念,掌握通信過程中原理,結合自己的理解,自己動手做一個個性化實驗,驗證我們的理解。
在Zigbee網絡里,模塊之間要進行通信,發射模塊非常明確知道接收模塊的網絡地址,以這個地址發送數據給接收模塊,叫單播。
模塊在入網的時候,父節點隨機分配網絡地址給子節點。但是協調器模塊在網絡里的地址永遠是0x0000.
在同一個工程里面通過選項卡控制不同的文件的編譯細節!復制SimonAPP.c文件作為Enddevice.c文件,然后選擇不同選項卡,通過文件的option設置,利用Exclude from build選項設置某個文件在某個選項卡下是否參與編譯!??!
在Enddevice.c文件里的SimonApp_MY_EVT事件處理中按鈕1 按下的相關處理代碼:
if ( events & SimonApp_MY_EVT ) { if(0==P1_1) {//按鈕3按下 LS164_BYTE(3); char theMessageData[] ={8}; 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 ; AF_DataRequest( &SimonApp_DstAddr, &SimonApp_epDesc, SimonApp_CLUSTERID, 1,//(byte)osal_strlen( theMessageData ) + 1, (byte *)&theMessageData, &SimonApp_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ); P1SEL &=0Xfe;// 翻轉LED P1DIR |=0X01; P1_0 ^=1; } if(0==P2_0) {//按鈕4按下 LS164_BYTE(4); } if(0==P0_5) {//按鈕5按下 LS164_BYTE(5); } return (events ^ SimonApp_MY_EVT); }接收的大概過程是,當終端模塊發送數據時候,協調器模塊底層任務拿到這個無線數據,給我們應用層任務發送一個AF_INCOMING_MSG_CMD在消息處理里,我們把有用數據拿出來在數碼管上顯示。
SimonAPP.c里面:
void SimonApp_MessageMSGCB( afIncomingMSGPacket_t *pkt ){ switch ( pkt->clusterId ) { case SimonApp_CLUSTERID: // "the" message#if defined( LCD_SUPPORTED ) HalLcdWriteScreen( (char*)pkt->cmd.Data, "rcvd" );#elif defined( WIN32 ) WPRINTSTR( pkt->cmd.Data );#endif LS164_BYTE(pkt->cmd.Data[0]); break; }}在Enddevice.c文件里的SimonApp_MY_EVT事件處理中按鈕1 按下的相關處理代碼:
if ( events & SimonApp_MY_EVT ) { if(0==P1_1) {//按鈕3按下 LS164_BYTE(3); char theMessageData[] ="Hello Simon"; 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 ; AF_DataRequest( &SimonApp_DstAddr, &SimonApp_epDesc, SimonApp_CLUSTERID, (byte)osal_strlen( theMessageData ) + 1, (byte *)&theMessageData, &SimonApp_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ); P1SEL &=0Xfe;// 翻轉LED P1DIR |=0X01; P1_0 ^=1; } if(0==P2_0) {//按鈕4按下 LS164_BYTE(4); } if(0==P0_5) {//按鈕5按下 LS164_BYTE(5); } return (events ^ SimonApp_MY_EVT); }1.因為要接收字符串,移植串口模塊化文件,添加UART.C UART.h頭文件到 工程源文件目錄?。?!
2.在ZMain.c文件的main 靠近模塊void InitUart();初始化串口!??!
3.取消TI默認對串口的配置,在main函數找到 HalDriverInit函數,通過該函數修該宏定義: 把宏#define HAL_UART FALSE
4.在ZMain,c添加UART.h頭文件初始化算完成了
5.在SimonApp_MessageMSGCB函數中添加: Uart_Send_String(pkt->cmd.Data,pkt->cmd.DataLength); 記得在SDApp.c文件添加UART.h頭文件

新聞熱點
疑難解答