/* main Initiate communication with the XBee module, then accept AT and other commands from STDIO, pass them to the XBee module via the SXA library, and print the results. */ int main( void) { char cmdstr[80]; int status; // Required local device initialization if (xbee_dev_init( &my_xbee, &XBEE_SERPORT, xbee_awake_pin, xbee_reset_pin)) { printf( "Failed to initialize device.\n"); exit(1); } // Initialize the Simple XBee API layer. SXA handles a lot of the // book-keeping for multiple remote nodes and XBee on-module I/Os. // It also helps to hide the difference between local and remote nodes. sxa = sxa_init_or_exit(&my_xbee, endpoints_table, 1); if (!sxa) { printf("Failed to initialize Simple XBee API!\n"); exit(2); } help(); while (1) { // Accumulate a command string, and call the tick function while waiting. while (xbee_readline( cmdstr, sizeof cmdstr) == -EAGAIN) { sxa_tick(); } // Have a command, process it. if (! strncmpi( cmdstr, "menu", 4)) { help(); } else if (! strcmpi( cmdstr, "quit")) { return 0; } else if ( sxa_select_command( cmdstr)) { // empty, command done } else if ( cmdstr[0] == '$') { issue_commands( sxa); } else { process_command_remote( sxa_xbee( sxa), cmdstr, have_target ? &target_ieee : NULL); } } }
/* main Initiate communication with the XBee module, then accept AT and other commands from STDIO, pass them to the XBee module via the SXA library, and print the results. */ int main( void) { char cmdstr[80]; char * slash; int ionum; int msglen; int msgsent; int status; int chunksize; // Required local device initialization if (xbee_dev_init( &my_xbee, &XBEE_SERPORT, xbee_awake_pin, xbee_reset_pin)) { printf( "Failed to initialize device.\n"); exit(1); } // Initialize the Simple XBee API layer. SXA handles a lot of the // book-keeping for multiple remote nodes and XBee on-module I/Os. // It also helps to hide the difference between local and remote nodes. sxa = sxa_init_or_exit(&my_xbee, endpoints_table, 1); if (!sxa) { printf("Failed to initialize Simple XBee API!\n"); exit(2); } help(); while (1) { // Accumulate a command string, and call the tick function while waiting. while (xbee_readline( cmdstr, sizeof cmdstr) == -EAGAIN) { sxa_tick(); } // Have a command, process it. if (! strncmpi( cmdstr, "menu", 4)) { help(); } else if (! strcmpi( cmdstr, "quit")) { return 0; } else if ( sxa_select_command( cmdstr)) { // empty, command done } else if ( cmdstr[0] == '$') { if (!have_target) { printf("Need a remote target to send data\n"); } else { msglen = atoi(cmdstr+1); slash = strchr(cmdstr, '/'); if (slash) { chunksize = atoi(slash + 1); if (chunksize > sizeof(qbf) || chunksize < 1) chunksize = sizeof(qbf); } else { chunksize = 64; } msgsent = 0; while (msglen >= chunksize) { status = send_data( sxa, qbf, chunksize); if (status) { printf("Error sending %d bytes: status=%d\n", chunksize, status); } else { msgsent += chunksize; } msglen -= chunksize; } if (msglen) { status = send_data( sxa, qbf, msglen); if (status) { printf("Error sending %d bytes: status=%d\n", msglen, status); } else { msgsent += msglen; } } printf("Total %d sent\n", msgsent); } } else if (!strncasecmp(cmdstr, "at", 2)) { process_command_remote( sxa_xbee( sxa), cmdstr, have_target ? &target_ieee : NULL); } else if (have_target) { msglen = strlen(cmdstr); printf( "sending %u bytes to '%ls'\n", msglen, sxa->id.node_info); status = send_data( sxa, cmdstr, msglen); if (status) { printf("Error sending %d bytes: status=%d\n", msglen, status); } } else { printf("Need a remote target to send data\n"); } } }