📄 alarm_test.c
字号:
/*
V0.1 Initial Release 10/July/2006 RBR
*/
/*
This just tests an RFD sending an alarm to the Coordinator
Topology is:
Coordinator-> RFD1
-
Start the coordinator first, then the RFD.
Also, if using Win32, you need to be running the virtual board
interface for the RFD so that you can push a button to send
the alarm.
Each time you press/release SW1, the RFD will toggle
the alarm on the coordinator (an alarm on the coordinator
causes its LED1 to flash).
*/
#include "msstate_lrwpan.h"
typedef enum _RFD_STATE_ENUM {
RFD_STATE_JOIN_NETWORK,
RFD_STATE_JOIN_WAIT,
RFD_STATE_RUN1,
RFD_STATE_RUN2,
RFD_STATE_RUN3
}RFD_STATE_ENUM;
RFD_STATE_ENUM rfdState;
void printJoinInfo(void);
void printJoinInfo(void){
conPrintROMString("My ShortAddress is: ");
conPrintUINT16(aplGetMyShortAddress());
conPCRLF();
conPrintROMString("Parent LADDR: ");
conPrintLADDR(aplGetParentLongAddress());
conPrintROMString(", Parent SADDR: ");
conPrintUINT16(aplGetParentShortAddress());
conPCRLF();
}
UINT16 ping_cnt;
void main (void){
UINT32 my_timer;
BYTE alarm_mode;
//HalInit, evbInit will have to be called by the user
halInit();
evbInit();
aplInit(); //init the stack
conPrintConfig();
ENABLE_GLOBAL_INTERRUPT(); //enable interrupts
EVB_LED1_OFF();
EVB_LED2_OFF();
alarm_mode = 1;
//debug_level = 10;
#ifndef LRWPAN_COORDINATOR
rfdState = RFD_STATE_JOIN_NETWORK;
while(1) {
apsFSM();
switch(rfdState) {
case RFD_STATE_JOIN_NETWORK:
EVB_LED1_OFF(); //not connected to a network
aplJoinNetwork();
rfdState = RFD_STATE_JOIN_WAIT;
break;
case RFD_STATE_JOIN_WAIT:
if (apsBusy()) break;
if (aplGetStatus() == LRWPAN_STATUS_SUCCESS) {
conPrintROMString("Network Join succeeded!\n");
printJoinInfo();
rfdState = RFD_STATE_RUN1;
EVB_LED1_ON();
} else
{
conPrintROMString("Network Join FAILED! Waiting, then trying again\n");
my_timer= halGetMACTimer();
//wait for 2 seconds
while ((halMACTimerNowDelta(my_timer))< MSECS_TO_MACTICKS(2*1000));
rfdState = RFD_STATE_JOIN_NETWORK;
}
break;
case RFD_STATE_RUN1:
if (EVB_SW1_PRESSED()) rfdState = RFD_STATE_RUN2;
break;
case RFD_STATE_RUN2:
if (EVB_SW1_RELEASED()) {
//send the alarm
aplSendAlarm(0,alarm_mode);
rfdState = RFD_STATE_RUN3;
}
break;
case RFD_STATE_RUN3:
if (apsBusy()) break;
if (aplGetStatus() == LRWPAN_STATUS_SUCCESS) {
conPrintROMString("Alarm successfully sent!\n");
alarm_mode = !alarm_mode;
}else {
conPrintROMString("Alarm send failed, try again!\n");
}
rfdState = RFD_STATE_RUN1;
break;
default:
rfdState = RFD_STATE_JOIN_NETWORK;
}
}
#else
aplFormNetwork();
while(apsBusy()) {apsFSM();} //wait for finish
conPrintROMString("Network formed, waiting for RX\n");
EVB_LED1_ON();
while(1) {apsFSM();} //coordinator or router just runs the stack
#endif
}
///////User Callbacks///////////////
//just print out packets
LRWPAN_STATUS_ENUM usrRxPacketCallback(void) {
BYTE len, *ptr;
//just print out this data
conPrintROMString("User Data Packet Received: \n");
conPrintROMString("SrcSADDR: ");
conPrintUINT16(aplGetRxSrcSADDR());
conPrintROMString(", DstEp: ");
conPrintUINT8(aplGetRxDstEp());
conPrintROMString(", Cluster: ");
conPrintUINT8(aplGetRxCluster());
conPrintROMString(", MsgLen: ");
len = aplGetRxMsgLen();
conPrintUINT8(len);
conPrintROMString(",RSSI: ");
conPrintUINT8(aplGetRxRSSI());
conPCRLF();
conPrintROMString("PingCnt: ");
ptr = aplGetRxMsgData();
ping_cnt = *ptr;
ptr++;
ping_cnt += ((UINT16)*ptr)<<8;
conPrintUINT16(ping_cnt);
conPCRLF();
return(LRWPAN_STATUS_SUCCESS);
}
LRWPAN_STATUS_ENUM usrZepRxCallback(void){return(LRWPAN_STATUS_SUCCESS);}
#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){\
return TRUE;
}
BOOL usrJoinNotifyCallback(LADDR *ptr){
//allow anybody to join
conPrintROMString("Node joined: ");
conPrintLADDR(ptr);
conPCRLF();
DEBUG_PRINTNEIGHBORS(DBG_INFO);
return TRUE;
}
#endif
//called when the slow timer interrupt occurs
#ifdef LRWPAN_ENABLE_SLOW_TIMER
void usrSlowTimerInt(void ) {}
#endif
//general interrupt callback , when this is called depends on the HAL layer.
void usrIntCallback(void){}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -