Revision 1437
| trunk/code/projects/test/test_xbee.c (revision 1437) | ||
|---|---|---|
| 7 | 7 |
|
| 8 | 8 |
extern int xbee_send_read_at_command(char* command); |
| 9 | 9 |
extern int xbee_get_packet(unsigned char* dest); |
| 10 |
extern void xbee_terminate(void); |
|
| 10 | 11 |
|
| 11 | 12 |
/* |
| 12 | 13 |
* This function tests the xbee, returning the results to teraterm |
| ... | ... | |
| 14 | 15 |
* |
| 15 | 16 |
*/ |
| 16 | 17 |
|
| 17 |
static init = 0; |
|
| 18 |
|
|
| 19 | 18 |
int testxbee(void) {
|
| 20 | 19 |
|
| 21 | 20 |
unsigned char buf[100]; |
| ... | ... | |
| 24 | 23 |
usb_init(); |
| 25 | 24 |
usb_puts("usb turned on, test starting:\r\n");
|
| 26 | 25 |
|
| 27 |
if(!init) {
|
|
| 28 |
// initialize xbee only once |
|
| 29 |
if (xbee_lib_init() != 0) {
|
|
| 30 |
usb_puts("xbee_lib_init() failed\r\n");
|
|
| 31 |
return -1; |
|
| 32 |
} else {
|
|
| 33 |
usb_puts("xbee_lib__init successful\r\n");
|
|
| 34 |
init = 1; |
|
| 35 |
} |
|
| 26 |
if (xbee_lib_init() != 0) {
|
|
| 27 |
usb_puts("xbee_lib_init() failed\r\n");
|
|
| 28 |
return -1; |
|
| 29 |
} else {
|
|
| 30 |
usb_puts("xbee_lib__init successful\r\n");
|
|
| 36 | 31 |
} |
| 37 |
|
|
| 32 |
|
|
| 38 | 33 |
usb_puts("\r\n\n");
|
| 39 | 34 |
delay_ms(1000); |
| 40 | 35 |
|
| ... | ... | |
| 49 | 44 |
break; // got a response |
| 50 | 45 |
} |
| 51 | 46 |
} |
| 52 |
usb_puts("testxbee done\r\n\r\n");
|
|
| 53 | 47 |
|
| 48 |
xbee_terminate(); |
|
| 49 |
usb_puts("testxbee done\r\n\r\n");
|
|
| 50 |
|
|
| 54 | 51 |
return 0; |
| 55 | 52 |
} |
| trunk/code/projects/test/xbee.c (revision 1437) | ||
|---|---|---|
| 88 | 88 |
static int xbee_enter_command_mode(void); |
| 89 | 89 |
static int xbee_exit_command_mode(void); |
| 90 | 90 |
static int xbee_enter_api_mode(void); |
| 91 |
static int xbee_exit_api_mode(void); |
|
| 91 | 92 |
static int xbee_wait_for_string(char* s, int len); |
| 92 | 93 |
static int xbee_wait_for_ok(void); |
| 93 | 94 |
|
| ... | ... | |
| 349 | 350 |
free(xbee_listen_thread); |
| 350 | 351 |
lockf(xbee_stream, F_ULOCK, 0); |
| 351 | 352 |
close(xbee_stream); |
| 353 |
#else |
|
| 354 |
xbee_exit_api_mode(); |
|
| 352 | 355 |
#endif |
| 353 | 356 |
} |
| 354 | 357 |
|
| ... | ... | |
| 456 | 459 |
} |
| 457 | 460 |
|
| 458 | 461 |
/** |
| 462 |
* Exit API mode. |
|
| 463 |
**/ |
|
| 464 |
static int xbee_exit_api_mode() |
|
| 465 |
{
|
|
| 466 |
if (xbee_send_modify_at_command("AP","0") != 0) {
|
|
| 467 |
return -1; |
|
| 468 |
} |
|
| 469 |
|
|
| 470 |
return 0; |
|
| 471 |
} |
|
| 472 |
|
|
| 473 |
/** |
|
| 459 | 474 |
* Wait until the string "OK\r" is received from the XBee. |
| 460 | 475 |
**/ |
| 461 | 476 |
static int xbee_wait_for_ok() |
| trunk/code/projects/test/main.c (revision 1437) | ||
|---|---|---|
| 17 | 17 |
// RUN_TEST(testtokenring); |
| 18 | 18 |
// RUN_TEST(testwireless); |
| 19 | 19 |
RUN_TEST(testxbee); |
| 20 |
delay_ms(1000); |
|
| 20 | 21 |
} |
| 21 | 22 |
|
| 22 | 23 |
return 0; |
Also available in: Unified diff