⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 node_sink.c

📁 //Basic packet sending test at the MAC level, used for internal testing only. //This packet test ha
💻 C
字号:
/*
  V0.1 Initial Release   10/July/2006  RBR

*/



/*
This is simply a sink, can be a coordinator,
router, or RFD. It just sits in the
network, does simple routing if it is a router,
and echos to the console any packets that it
receives. This does not check for
disassociation, is meant for simple testing.

Use this as a target of a node running the
rfd_sleep.c app to test sending  a direct
packet over a multi-hop link. Add this to
a network, record its short address, then
use this short address in the rfd_sleep.c
program.

This does not require any Virtual Boards to be running,
or interaction through the console.


*/

#include "msstate_lrwpan.h"


typedef enum _RFD_STATE_ENUM {
	RFD_STATE_JOIN_NETWORK,
	RFD_STATE_JOIN_WAIT,
	RFD_STATE_NORMAL
}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;

	//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();
	//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_NORMAL;
				  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_NORMAL:
			  //do nothing, never leave this state.
			  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 + -