Project

General

Profile

Revision 931

Added by Tudor Achim over 15 years ago

changed xbee packet handling, added more info for unexpected packets

View differences:

trunk/code/projects/libwireless/lib/xbee.c
286 286
	WL_DEBUG_PRINT("Entered api mode.\n");
287 287

  
288 288
	if (xbee_exit_command_mode() != 0) {
289
		return -1;
289
	     return -1;
290 290
	}
291

  
291
	
292 292
	WL_DEBUG_PRINT("Left command mode.\n");
293 293

  
294 294
	if (xbee_send_read_at_command("MY")) {
......
302 302
	  ret = xbee_get_packet(NULL);
303 303

  
304 304
	  usleep(1000);
305

  
306
    /* xbee_get_packet returns -1 when passed NULL, so ret==-1 shouldn't be an error */
307
	  /*if (ret == -1) {
308
	    WL_DEBUG_PRINT("xbee_get_packet(NULL) failed.\n");
309
	    return -1;
310
	  }*/
305
	  
306
/* 	  if (ret == -1) { */
307
/* 	    WL_DEBUG_PRINT("xbee_get_packet(NULL) failed.\n"); */
308
/* 	    return -1; */
309
/* 	  } */
311 310
	}
312 311
#else
313 312
	//wait to return until the address is set
......
725 724
 **/
726 725
int xbee_get_packet(unsigned char* dest)
727 726
{
727
     int ret;
728 728
	//start reading a packet with XBEE_FRAME_START
729 729
	if (currentBufPos == 0)
730 730
	{
......
783 783
	}
784 784

  
785 785
	//we will take care of the packet
786
	if (xbee_handle_packet(xbee_buf + 3, len) != 1) {
787
		return -1;
786
	
787
	ret = xbee_handle_packet(xbee_buf+3, len);
788
	if (ret == 1) {
789
		return 3;
788 790
	}
789

  
791
	
790 792
	if (dest == NULL) {
791 793
		return -1;
792 794
	}
......
795 797
	for (i = 3; i < len + 3; i++) {
796 798
		dest[i - 3] = xbee_buf[i];
797 799
	}
798

  
799 800
	return len;
800 801
}
801 802

  
trunk/code/projects/libwireless/lib/wireless.c
461 461
	else
462 462
	{
463 463
		WL_DEBUG_PRINT("Unexpected packet received from XBee.\r\n");
464
		printf("0x%2X\n", wl_buf[0]);
465
		printf("%c%c%d\n", wl_buf[2], wl_buf[3], wl_buf[4]);
464 466
	}
465 467
}
466 468

  

Also available in: Unified diff