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

📄 max_msg_test.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 a router test, using direct messages from
RFD to coordinator. Used to test maximum sized payload.

Coordinator ->  RFD1

Start the coordinator first, then
RFD1. If a RFD1 fails to join the network, try
again.

This does not require any Virtual Boards to be running,
everything done through the console.

Max Message size up the tree:
 The Zigbee AF frame format takes 3 bytes (1 trans.header, 1 trans seq number, 1 payload len.)

The Zigbee APS frame format takes 6 bytes (1 frame control,1  dest ep, cluster, 2 bytes profile, 1 endpoint).

The Zibbee NWK frame takes 8 bytes.

The maximum MAC header is 23 bytes (2 frame control, 1 seq, 2 DST PANID, 8 dst address, 8 src address, 2 SRC PANID)

Two bytes of the 127 byte packet also get taken up by the two FCS bytes at the end of packet.

Worst case maximum payload of  (127 - (3+6+8+23+2) ) = 85 bytes

This is worst case, if all of the MAC header fields were used.
For data frames up the tree, the MAC header uses short addressing for destination,
and drops the SRC panID so it takes
15 bytes (2 frame control, 1 seq, 2 PANID, 8 dst address, 2 src address),
giving you a 93 byte max payload.
Down the tree is a little less as short addressing is use for the destination.


In WIN32, start the coord first, then the router so that it
joins the coord, then RFDs so that they join the router.

*/

#include "msstate_lrwpan.h"

BYTE payload[96];  //buffer for payload
BYTE test_number;
LADDR_UNION dstADDR;
UINT32 my_timer;

void getpayload(void);

void print_test(void){
    conPrintROMString("Test ");
    conPrintUINT8((UINT8) test_number);
     conPrintROMString(", Sending msg: ");
     conPrintString((char *)&payload[0]);
	conPCRLF();
}


//this is assumed to be the long address of our coordinator, in little endian order
//used to test LONG ADDRESSING back to coordinator
UINT8 coord[8] = {0x06f,0x21,0x01,0x00,0x00,0x4B,0x12,0x00};


#define NUM_MESSAGES 1
//convoluted mess because of different ways compilers treat const char strings
void getpayload(void) {
   BYTE *dst;
   ROMCHAR *src;
   BYTE msgnum;

   //maximum size message that can be sent up the tree.
   //92 character string + null byte = 93 byte payload.
   static ROMCHAR _x0_[] = "0_________1_________2_________3_________4_________5_________6_________7_________8________9__";
 
 
   msgnum = halGetRandomByte();
   msgnum = msgnum % NUM_MESSAGES;
	
   switch (msgnum) {
     default :  src = &_x0_[0]; break;
    }
    dst = &payload[0];
    while (*src) {
        *dst = *src;
         dst++;src++;
    }
   *dst = *src;
}




void packet_test(void) {

	switch(test_number) {
	  case 0:
          getpayload();
		  print_test();
		  conPrintROMString("Direct MSG to Coord, SHORT addr, dstEP: 1, no ack requested\n");
		  conPrintROMString("hit a key to send packet\n");
		  halGetch();
		  dstADDR.saddr = 0; //Coordinator has address 0
		  aplSendMSG (APS_DSTMODE_SHORT,
			  &dstADDR,
			  2, //dst EP
			  0, //cluster is ignored for direct message
			  1, //src EP
			  payload,
			  strlen((char *)payload)+1,
			  apsGenTSN(),
			  FALSE);  //No APS ack requested
		  test_number++;
		  break;
	  case 1:
		  getpayload();
		  print_test();
		  conPrintROMString("Direct MSG to Coord, SHORT addr,  dstEP: 1, APS ack requested\n");
		  conPrintROMString("hit a key to send packet\n");
		  halGetch();
		  dstADDR.saddr = 0; //Coordinator has address 0
		  aplSendMSG (APS_DSTMODE_SHORT,
			  &dstADDR,
			  2, //dst EP
			  0, //cluster is ignored direct message
			  1, //src EP
			  payload,
			  strlen((char *)payload)+1,
			  apsGenTSN(),
			  TRUE);    //request an ACK
		  test_number++;
		  break;
	  default:
		  test_number = 0;

		  break;
	}


	//block, and see if message sent successfully
	while(apsBusy()) {apsFSM();}
	if (aplGetStatus() == LRWPAN_STATUS_SUCCESS) {
		conPrintROMString("MSG send succeeded!\n");
	}else {
		conPrintROMString("MSG send FAILED!\n");
	}


}

void main (void){


	//this initialization set our SADDR to 0xFFFF,
	//PANID to the default PANID

	//HalInit, evbInit will have to be called by the user
	halInit();
	evbInit();

	aplInit();  //init the stack
	conPrintConfig();
	ENABLE_GLOBAL_INTERRUPT();  //enable interrupts
	test_number = 0;

	//debug_level = 10;


#ifdef LRWPAN_COORDINATOR

	aplFormNetwork();
	while(apsBusy()) {apsFSM();} //wait for finish

	conPrintROMString("Nwk formed, waiting for join and reception\n");
	while(1) {apsFSM();}

#else
	do {
		aplJoinNetwork();
		while(apsBusy()) {apsFSM();} //wait for finish
		if (aplGetStatus() == LRWPAN_STATUS_SUCCESS) {
			conPrintROMString("Network Join succeeded!\n");
			conPrintROMString("My ShortAddress is: ");
			conPrintUINT16(aplGetMyShortAddress());
			conPCRLF();
			conPrintROMString("Parent LADDR: ")
			conPrintLADDR(aplGetParentLongAddress());
			conPrintROMString(", Parent SADDR: ");
			conPrintUINT16(aplGetParentShortAddress());
			conPCRLF();
			break;
		}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));
		       }
	} while(1);


#ifdef LRWPAN_RFD
	//now send packets
	while (1) {
		packet_test();
		while(apsBusy()) {apsFSM();} //wait for finish
	}
#endif
#ifdef LRWPAN_ROUTER
	//router does nothing, just routes
	DEBUG_PRINTNEIGHBORS(DBG_INFO);
	conPrintROMString("Router, doing its thing.!\n");
	while(1) {apsFSM();}
#endif

#endif


}

//########## 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){

#ifdef LRWPAN_COORDINATOR
	if (aplGetRxCluster() == ZEP_END_DEVICE_ANNOUNCE) {
		//a new end device has announced itself, print out the
		//the neightbor table and address map
		dbgPrintNeighborTable();
	}
#endif
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) {

	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(", Msg Length: ");
	len = aplGetRxMsgLen();
	conPrintUINT8(len);
	conPCRLF();
	conPrintROMString("Msg: ");
	ptr = aplGetRxMsgData();
	while(len){
		halPutch(*ptr);
		ptr++; len--;
	}
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


void usrIntCallback(void){}

//called when the slow timer interrupt occurs
#ifdef LRWPAN_ENABLE_SLOW_TIMER
void usrSlowTimerInt(void ) {}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -