




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
1、 實驗題目:實驗12無線傳感網(wǎng)絡(luò)演示實驗 實驗時間:2015.12.31一、 實驗?zāi)康模赫莆語igBee(cc2530)與傳感器節(jié)點的串口通信協(xié)議。掌握傳感器數(shù)據(jù)的采集與傳輸過程。學(xué)習(xí)無線傳感網(wǎng)絡(luò)的搭建。二、 實驗原理及程序分析:傳感器說明串口設(shè)置波特率115200,數(shù)據(jù)位8,停止位1,無校驗位傳感器底層協(xié)議協(xié)調(diào)器程序#include "OSAL.h"#include "AF.h"#include "ZDApp.h"#include "ZDObject.h"#include "ZDProfile.h&qu
2、ot;#include <string.h>#include "Coordinator.h"#include "DebugTrace.h"#if !defined(WIN32)#include "OnBoard.h"#endif#include "hal_led.h"#include "hal_lcd.h"#include "hal_key.h"#include "hal_uart.h"const cId_t GenericApp_Cluste
3、rListGENERICAPP_MAX_CLUSTERS=GENERICAPP_CLUSTERID ;const SimpleDescriptionFormat_t GenericApp_SimpleDesc=GENERICAPP_ENDPOINT,GENERICAPP_PROFID, GENERICAPP_DEVICEID,GENERICAPP_DEVICE_VERSION,GENERICAPP_FLAGS,GENERICAPP_MAX_CLUSTERS,(cId_t *)GenericApp_ClusterList,0,(cId_t *)NULL;endPointDesc_t Generi
4、cApp_epDesc;byte GenericApp_TaskID;byte GenericApp_TransID;unsigned char uartbuf128;devStates_t GenericApp_NwkState;void GenericApp_MessageMSGCB(afIncomingMSGPacket_t *pckt);void GenericApp_SendTheMessage(void);void GenericApp_Init(byte task_id)halUARTCfg_t uartConfig;GenericApp_TaskID =task_id;Gene
5、ricApp_TransID =0;GenericApp_epDesc.endPoint=GENERICAPP_ENDPOINT;GenericApp_epDesc.task_id=&GenericApp_TaskID;GenericApp_epDesc.simpleDesc=(SimpleDescriptionFormat_t *)&GenericApp_SimpleDesc;GenericApp_epDesc.latencyReq=noLatencyReqs;afRegister(&GenericApp_epDesc);uartConfig.configured =
6、TRUE;uartConfig.baudRate =HAL_UART_BR_115200;uartConfig.flowControl =FALSE;uartConfig.callBackFunc =NULL;HalUARTOpen(0,&uartConfig);UINT16 GenericApp_ProcessEvent(byte tadk_id,UINT16 events)afIncomingMSGPacket_t *MSGpkt;if(events&SYS_EVENT_MSG)MSGpkt=(afIncomingMSGPacket_t *)osal_msg_receive
7、(GenericApp_TaskID);while(MSGpkt)switch(MSGpkt->hdr.event)case ZDO_STATE_CHANGE:GenericApp_NwkState=(devStates_t)(MSGpkt->hdr.status);if(GenericApp_NwkState=DEV_ZB_COORD)HalLedSet(HAL_LED_1, HAL_LED_MODE_ON);case AF_INCOMING_MSG_CMD:GenericApp_MessageMSGCB(MSGpkt);break;default:break;osal_msg_
8、deallocate(uint8 *) MSGpkt);MSGpkt=(afIncomingMSGPacket_t *)osal_msg_receive(GenericApp_TaskID);return (events SYS_EVENT_MSG);return 0;void GenericApp_MessageMSGCB(afIncomingMSGPacket_t * pkt)unsigned char buffer14;int i=0;switch(pkt->clusterId)case GENERICAPP_CLUSTERID:osal_memcpy(buffer, pkt-&g
9、t;cmd.Data, 14);uartbuf0=0xee;uartbuf1=0xcc;uartbuf2=0x00;uartbuf3=0x00;uartbuf4=0x00;uartbuf5=HI_UINT16(pkt->srcAddr.addr.shortAddr);uartbuf6=LO_UINT16(pkt->srcAddr.addr.shortAddr);uartbuf7=0x00;uartbuf8=0x00;uartbuf9=HI_UINT16(NLME_GetCoordShortAddr();uartbuf10=LO_UINT16(NLME_GetCoordShortAd
10、dr();uartbuf11=0x01;/stateuartbuf12=0x0B;/chaneluartbuf13=pkt->endPoint;for(i=14;i<=26;i+)uartbufi=bufferi-12;HalUARTWrite(0,uartbuf,26);HalLedBlink(HAL_LED_2,0,50,500);break;端點端程序#include "OSAL.h"#include "AF.h"#include "ZDApp.h"#include "ZDObject.h"#in
11、clude "ZDProfile.h"#include <string.h>#include "Coordinator.h"#include "DebugTrace.h"#if !defined(WIN32)#include "OnBoard.h"#endif#include "hal_led.h"#include "hal_lcd.h"#include "hal_key.h"#include "hal_uart.h"#de
12、fine SEND_DATA_EVENT 0x01const cId_t GenericApp_ClusterListGENERICAPP_MAX_CLUSTERS=GENERICAPP_CLUSTERID ;const SimpleDescriptionFormat_t GenericApp_SimpleDesc=GENERICAPP_ENDPOINT,GENERICAPP_PROFID,GENERICAPP_DEVICEID,GENERICAPP_DEVICE_VERSION,GENERICAPP_FLAGS,0,(cId_t *)NULL,GENERICAPP_MAX_CLUSTERS,
13、(cId_t *)GenericApp_ClusterList,;endPointDesc_t GenericApp_epDesc;byte GenericApp_TaskID;byte GenericApp_TransID;devStates_t GenericApp_NwkState;unsigned char uartbuf14;void GenericApp_MessageMSGCB(afIncomingMSGPacket_t *pckt);void GenericApp_SendTheMessage(void);static void rxCB(uint8 port, uint8 e
14、vent);static void rxCB(uint8 port, uint8 event)HalUARTRead(0, uartbuf, 14);osal_set_event(GenericApp_TaskID,SEND_DATA_EVENT);void GenericApp_Init(byte task_id)GenericApp_TaskID =task_id;GenericApp_NwkState =DEV_INIT;GenericApp_TransID =0;GenericApp_epDesc.endPoint=GENERICAPP_ENDPOINT;GenericApp_epDe
15、sc.task_id=&GenericApp_TaskID;GenericApp_epDesc.simpleDesc=(SimpleDescriptionFormat_t *)&GenericApp_SimpleDesc;GenericApp_epDesc.latencyReq=noLatencyReqs;afRegister(&GenericApp_epDesc);halUARTCfg_t uartConfig;uartConfig.configured =TRUE;uartConfig.baudRate =HAL_UART_BR_115200;uartConfig.
16、flowControl =FALSE;uartConfig.callBackFunc =rxCB;HalUARTOpen(0,&uartConfig);UINT16 GenericApp_ProcessEvent(byte tadk_id,UINT16 events)afIncomingMSGPacket_t *MSGpkt;if(events&SYS_EVENT_MSG)MSGpkt=(afIncomingMSGPacket_t *)osal_msg_receive(GenericApp_TaskID);while(MSGpkt)switch(MSGpkt->hdr.e
17、vent)case ZDO_STATE_CHANGE:GenericApp_NwkState=(devStates_t)(MSGpkt->hdr.status);if(GenericApp_NwkState=DEV_END_DEVICE)|(GenericApp_NwkState=DEV_ROUTER)HalLedSet(HAL_LED_1, HAL_LED_MODE_ON);osal_set_event(GenericApp_TaskID,SEND_DATA_EVENT);default:break;osal_msg_deallocate(uint8 *) MSGpkt);MSGpkt
18、=(afIncomingMSGPacket_t *)osal_msg_receive(GenericApp_TaskID);return (events SYS_EVENT_MSG);if(events&SEND_DATA_EVENT)GenericApp_SendTheMessage();osal_start_timerEx(GenericApp_TaskID,SEND_DATA_EVENT,1000);return (eventsSEND_DATA_EVENT);return 0;void GenericApp_SendTheMessage(void)afAddrType_t my_DstAddr;my_DstAddr.addrMode=(afAddrMode_t)Addr16Bit;my_DstAddr.endPoint=GENERICAPP_ENDPOINT;my_DstAddr.addr.shortAddr=0x0000;if(afStatus_SUCCESS!=AF_DataRequest(&my_DstAddr,&GenericApp_epDesc, GENERICAPP_CLUSTERID,14,uartbuf,&Generi
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 班主任班級安全防范與應(yīng)急處理協(xié)議
- 舊村改造項目拆遷補償與二手房購買合同
- 財務(wù)軟件研發(fā)保密協(xié)議及勞動合同模板
- 電玩城免責(zé)協(xié)議書范本
- 部門副總經(jīng)理員工晉升與發(fā)展規(guī)劃勞動合同范本
- 殘疾人勞動合同簽訂與勞動爭議預(yù)防與處理
- 樁基成孔智能監(jiān)測儀
- 學(xué)校繳費流程規(guī)范說明
- 快遞店店員培訓(xùn)
- 2025消防知識培訓(xùn)
- 2024年遼寧省普通高等學(xué)校招生錄取普通類本科批(物理學(xué)科類)投檔最低分
- 保安培訓(xùn)考試內(nèi)容解析及試題及答案
- 電梯維護保養(yǎng)服務(wù)投標(biāo)文件(技術(shù)方案)
- 2025年中國PCR儀市場全面調(diào)研及行業(yè)投資潛力預(yù)測報告
- 2025年醫(yī)院信息科數(shù)據(jù)安全管理計劃
- 智能工廠整體解決方案
- 2025年四川大學(xué)自主招生個人陳述的自我定位
- 2025年福建省建工集團及下屬集團招聘235人高頻重點提升(共500題)附帶答案詳解
- 緊急情況的處理措施、預(yù)案以及抵抗風(fēng)險的措施
- 2025中智集團招聘重要崗位高頻重點提升(共500題)附帶答案詳解
- 水暖維修培訓(xùn)課件
評論
0/150
提交評論