示例#1
0
/*
	main

	Initiate communication with the XBee module, then accept AT commands from
	STDIO, pass them to the XBee module and print the result.
*/
int main( int argc, char *argv[])
{
   char cmdstr[80];
	int status;
	xbee_serial_t XBEE_SERPORT;

	parse_serial_arguments( argc, argv, &XBEE_SERPORT);

	// initialize the serial and device layer for this XBee device
	if (xbee_dev_init( &my_xbee, &XBEE_SERPORT, NULL, NULL))
	{
		printf( "Failed to initialize device.\n");
		return 0;
	}

	// Initialize the AT Command layer for this XBee device and have the
	// driver query it for basic information (hardware version, firmware version,
	// serial number, IEEE address, etc.)
	xbee_cmd_init_device( &my_xbee);
	printf( "Waiting for driver to query the XBee device...\n");
	do {
		xbee_dev_tick( &my_xbee);
		status = xbee_cmd_query_status( &my_xbee);
	} while (status == -EBUSY);
	if (status)
	{
		printf( "Error %d waiting for query to complete.\n", status);
	}

	// report on the settings
	xbee_dev_dump_settings( &my_xbee, XBEE_DEV_DUMP_FLAG_DEFAULT);

   printATCmds( &my_xbee);

   while (1)
   {
      while (xbee_readline( cmdstr, sizeof cmdstr) == -EAGAIN)
      {
      	xbee_dev_tick( &my_xbee);
      }

		if (! strncmpi( cmdstr, "menu", 4))
      {
      	printATCmds( &my_xbee);
      }
      else if (! strcmpi( cmdstr, "quit"))
      {
			return 0;
		}
      else
      {
			process_command( &my_xbee, cmdstr);
	   }
   }
}
示例#2
0
void help(void)
{
   printATCmds( &my_xbee);
   printf("Commands and data:\n");
   printf("  [AT]xx [parm] (Issue AT command - local or remote)\n");
   printf("  $             (Issue canned list of commands and show result)\n");
   sxa_select_help();
   printf("Other:\n");
   printf("  menu     (print this command list)\n");
   printf("  quit     (quit this demo)\n");
}
/*
	main

	Initiate communication with the XBee module, then accept AT commands from
	STDIO, pass them to the XBee module and print the result.
*/
int main( void)
{
    char cmdstr[80];
    int status;
    uint16_t t;


    if (xbee_dev_init( &my_xbee, &XBEE_SERPORT, xbee_awake_pin, xbee_reset_pin))
    {
        printf( "Failed to initialize device.\n");
        return 0;
    }

    //xbee_dev_reset( &my_xbee);
    // give the XBee 500ms to wake up after resetting it (or exit if it
    // receives a packet)
    t = XBEE_SET_TIMEOUT_MS(500);
    while (! XBEE_CHECK_TIMEOUT_MS(t) && xbee_dev_tick( &my_xbee) <= 0);

    // Initialize the AT Command layer for this XBee device and have the
    // driver query it for basic information (hardware version, firmware version,
    // serial number, IEEE address, etc.)
    xbee_cmd_init_device( &my_xbee);
    printf( "Waiting for driver to query the XBee device...\n");
    do {
        xbee_dev_tick( &my_xbee);
        status = xbee_cmd_query_status( &my_xbee);
    } while (status == -EBUSY);
    if (status)
    {
        printf( "Error %d waiting for query to complete.\n", status);
    }

    // report on the settings
    xbee_dev_dump_settings( &my_xbee, XBEE_DEV_DUMP_FLAG_DEFAULT);

    printATCmds( &my_xbee);
    printf("Target setting for remote commands:\n");
    printf(" > addr   (addr is hex ieee addr, high bytes assumed 0013a200)\n");
    printf(" >        (reset to local device)\n");
    printf(" <        (reinstate previous remote target)\n");

    while (1)
    {
        while (xbee_readline( cmdstr, sizeof cmdstr) == -EAGAIN)
        {
            xbee_dev_tick( &my_xbee);
        }

        if (! strncmpi( cmdstr, "menu", 4))
        {
            printATCmds( &my_xbee);
        }
        else if (! strcmpi( cmdstr, "quit"))
        {
            return 0;
        }
        else if ( cmdstr[0] == '>')
        {
            have_target = set_target( cmdstr+1, &target_ieee);
        }
        else if ( cmdstr[0] == '<')
        {
            if (ever_had_target)
            {
                have_target = 1;
                printf("Reinstating %" PRIsFAR "\n",
                       addr64_format(cmdstr, &target_ieee));
            }
            else
            {
                printf("Nothing to reinstate\n");
            }
        }
        else
        {
            have_target ?
            process_command_remote( &my_xbee, cmdstr, &target_ieee) :
            process_command( &my_xbee, cmdstr);
        }
    }
}