示例#1
0
/*
	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);
	   }
   }
}
示例#2
0
void issue_commands(sxa_node_t FAR *sxa)
{
	int i;
	xbee_command_list_context_t	my_clc;			// Context structure

   // Set up parameter data for any SET commands
   my_struct.new_dd = 0x0F111111;
   strcpy(my_struct.ni, "MyNodeID");

   // Start issuing commands in list
	xbee_cmd_list_execute( sxa_xbee( sxa),			// Get the XBee device from sxa
   								&my_clc,					// The command list context
									my_command_list,		// The command list itself
                           &my_struct,				// The struct to fill in
                           sxa_wpan_address( sxa));	// Target Xbee address

   // For this sample, block until complete.  Real application would be
   // doing something else in the meantime, inside the loop.
	while (xbee_cmd_list_status(&my_clc) == -EBUSY)
   {
   	sxa_tick();
   }

   // Now look at the final status
   switch (xbee_cmd_list_status(&my_clc))
   {
   	case XBEE_COMMAND_LIST_DONE:
      	printf("Completed successfully:\n");
         printf(" CH = %d\n", my_struct.ch);
         printf(" OP =\n");
			hex_dump( my_struct.op, sizeof(my_struct.op), HEX_DUMP_FLAG_TAB);
         printf(" OI = 0x%04X\n", my_struct.oi);
         printf(" MY = 0x%04X\n", my_struct.my);
         printf(" SC =");
         for (i = 0; i < 16; ++i)
         {
         	printf("%d", my_struct.sc[i]);
         }
         printf(" (ch 11..26)\n");
         printf(" DD (old) = 0x%08lX\n", my_struct.old_dd);
         printf(" DD (new) = 0x%08lX\n", my_struct.verify_dd);
         break;
      case XBEE_COMMAND_LIST_TIMEOUT:
      	printf("Timed out\n");
         break;
      case XBEE_COMMAND_LIST_ERROR:
      default:
      	printf("Completed partially or with errors\n");
         break;
   }
}
示例#3
0
/*
	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");
      }
   }
}