当前位置:首页 > 低功耗的无线传感器网络节点设计
黑龙江工程学院本科生毕业设计
} }
//########## Callbacks ##########
//callback for anytime the Zero Endpoint RX handles a command //user can use the APS functions to access the arguments //and take additional action is desired.
//the callback occurs after the ZEP has already taken //its action.
LRWPAN_STATUS_ENUM usrZepRxCallback(void){
return LRWPAN_STATUS_SUCCESS; }
//callback from APS when packet is received //user must do something with data as it is freed //within the stack upon return.
LRWPAN_STATUS_ENUM usrRxPacketCallback(void) { //just print out this data conPrintROMString(\ //check the endpoint if (aplGetRxDstEp() == LIGHT_EP) { conPrintROMString(\ //our \ if (EVB_LED1_STATE()) { EVB_LED1_OFF(); } else { EVB_LED1_ON(); } } return (LRWPAN_STATUS_SUCCESS); }
31
黑龙江工程学院本科生毕业设计
#ifdef LRWPAN_FFD
//Callback to user level to see if OK for this node //to join - implement Access Control Lists here based //upon IEEE address if desired
BOOL usrJoinVerifyCallback(LADDR *ptr, BYTE capinfo){\\
#if 0 //set this to '1' if you want to test through a router //only accept routers.
//only let routers join us if we are coord #ifdef LRWPAN_COORDINATOR
if (LRWPAN_GET_CAPINFO_DEVTYPE(capinfo)) { //this is a router, let it join conPrintROMString(\ return TRUE; }else { conPrintROMString(\ return FALSE; } #else
return TRUE; #endif
#else
return TRUE;
#endif }
BOOL usrJoinNotifyCallback(LADDR *ptr){ //allow anybody to join conPrintROMString(\ conPrintLADDR(ptr); conPCRLF(); DEBUG_PRINTNEIGHBORS(DBG_INFO); return TRUE; }
#endif
//called when the slow timer interrupt occurs
32
黑龙江工程学院本科生毕业设计
#ifdef LRWPAN_ENABLE_SLOW_TIMER void usrSlowTimerInt(void ) {} #endif
//general interrupt callback , when this is called depends on the HAL layer. void usrIntCallback(void){}
#ifdef LRWPAN_COORDINATOR #ifdef LRWPAN_USE_PC_BIND
//This callback is a way for you to extend the PC client binding demo //with your own commands that you send to the coordinator via the serial //link from the PC. See the documentation for details. If you use this //callback, then you will be compatiable with future releases. //See the file pcbind.c for when this callback is invoked. void usrPbdCallback(UINT16 pktlen, BYTE crc){} #endif #endif
#include \
#ifndef LRWPAN_COORDINATOR
#define PING_DELAY 2 //wait before bouncing back #else
#define PING_DELAY 0 //coordinator does not wait #endif
#define RX_PING_TIMEOUT 5 //seconds
//this is assumed to be the long address of our coordinator, in little endian order //used to test LONG ADDRESSING back to coordinator
UINT16 ping_cnt; UINT32 my_timer; UINT32 last_tx_start;
LADDR_UNION dstADDR; /*
四种状态切换:开始接收、等待接收、发送、等待发送 */
33
黑龙江工程学院本科生毕业设计
typedef enum _PP_STATE_ENUM { PP_STATE_START_RX, PP_STATE_WAIT_FOR_RX, PP_STATE_SEND, PP_STATE_WAIT_FOR_TX }PP_STATE_ENUM;
PP_STATE_ENUM ppState;
BYTE rxFlag; //set from within usrRxPacketCallback 接收标志 BYTE payload[2]; //收发数据 UINT16 numTimeouts; //延时 BOOL first_packet; //第一包数据
void PingPong(void);
void PingPong (void ) { apsFSM();//应用层无线数据收发处理 switch (ppState) { case PP_STATE_START_RX: if (!first_packet) { my_timer= halGetMACTimer(); ppState = PP_STATE_WAIT_FOR_RX; }else if (rxFlag) { //on first packet, do not start timer, just wait for a packet. ppState = PP_STATE_WAIT_FOR_RX; first_packet = FALSE; } break; case PP_STATE_WAIT_FOR_RX: //rxFlag is set from within usrRxPacketCallback if (rxFlag || halMACTimerNowDelta(my_timer) > MSECS_TO_MACTICKS( RX_PING_TIMEOUT *1000 )) { if (!rxFlag) numTimeouts++; //got tired of waiting for a response, send again rxFlag = 0; //clear flag if (EVB_LED1_STATE()) EVB_LED1_OFF(); else EVB_LED1_ON(); //start timer my_timer= halGetMACTimer(); ppState = PP_STATE_SEND; } break; case PP_STATE_SEND: if ((halMACTimerNowDelta(my_timer))>
34
共分享92篇相关文档