Пример #1
0
/*****************************************************************************
 Main program.
 *****************************************************************************/
int main (int argc, char* argv[]) {
  const char* usage0 =
   "usage: rtkgps [-h] [-v] [-d <dev> [-r <rate>] | -b <addr>]\n"
   "              ([-e] status | date | list | [-y] erase |\n"
   "              [-c <flg>] [-l <lgtp>] [-m <mfo>] [-s <int>] set |\n"
   "              [-n] [-p] [-o <dest> [-u]] [-f <nstr>] read)\n\n"
   "       -h        display usage\n"
   "       -v        verbose mode\n"
   "       -d <dev>  specify serial device\n"
   "       -r <rate> specify baud rate for serial device\n"
   "       -b <addr> specify bluetooth address\n"
   "       -e        display extended status information\n";
  const char* usage1 =
   "       -c <flg>  set real-time output (GPS mouse) mode "
                     "(0=disable, 1=enable)\n"
   "       -l <lgtp> set log record type (tl, tla, or tlav)\n"
   "       -m <mfo>  set memory overwrite behaviour (o=overwrite, s=stop)\n"
   "       -s <int>  set sampling interval in seconds\n"
   "       -n        output data in simple native text form\n"
   "       -p        display text progress bar\n"
   "       -o <dest> specify destination file or directory\n"
   "       -u        skip downloading date for existing files\n";
  const char* usage2 =
   "       -f <nstr> string specifying index number(s) of log file(s) \n"
   "                 to retrieve as a single file number, or range of \n"
   "                 file numbers in the format -n, n-, or n-m\n"
   "       -y        don't ask for confirmation\n";

  /* most Royalteks operate on 57600 baud, use that as the default */
  cmdlnopts_t cmdopt = {0,0,0,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
			NULL,NULL,-1,-1,-1,57600,""};

  /* Initialise usage string */
  strcpy(cmdopt.usgs, usage0);
  strcat(cmdopt.usgs, usage1);
  strcat(cmdopt.usgs, usage2);
  /* Scan command line options */
  scan_cmdline(argc, argv, &cmdopt);

  /* Set up warning callback function */
  gcwrnfp = warning;

  /* Perform requested task */
  if (strcmp(cmdopt.cmds,"status") == 0) {
    cmd_status(&cmdopt);
  } else if (strcmp(cmdopt.cmds,"date") == 0) {
    cmd_date(&cmdopt);
  } else if (strcmp(cmdopt.cmds,"list") == 0) {
    cmd_list(&cmdopt);
  } else if (strcmp(cmdopt.cmds,"set") == 0) {
    cmd_set(&cmdopt);
  } else if (strcmp(cmdopt.cmds,"read") == 0) {
    cmd_read(&cmdopt);
  } else if (strcmp(cmdopt.cmds,"erase") == 0) {
    cmd_erase(&cmdopt);
  }

  exit(0);
}
Пример #2
0
/*
 * process a single character of a multi-character command, such as
 * a number, or the pattern of a search command.
 */
int
cmd_char(int c)
{
	if (c == erase_char)
		return(cmd_erase());
	/* in this order, in case werase == erase_char */
	if (c == werase_char) {
		if (cp > cmdbuf) {
			while (isspace(cp[-1]) && !cmd_erase());
			while (!isspace(cp[-1]) && !cmd_erase());
			while (isspace(cp[-1]) && !cmd_erase());
		}
		return(cp == cmdbuf);
	}
	if (c == kill_char) {
		while (!cmd_erase());
		return(1);
	}
	/*
	 * No room in the command buffer, or no room on the screen;
	 * {{ Could get fancy here; maybe shift the displayed line
	 * and make room for more chars, like ksh. }}
	 */
	if (cp >= &cmdbuf[sizeof(cmdbuf)-1] || cmd_col >= sc_width-3)
		putchar('\7');
	else {
		*cp++ = c;
		if (CONTROL_CHAR(c)) {
			putchar('^');
			cmd_col++;
			c = CARAT_CHAR(c);
		}
		putchar(c);
		cmd_col++;
	}
	return(0);
}
Пример #3
0
void command_parse(const u08 *cmd, u08 len)
{
  u08 result = 0;
  switch(cmd[0]) {
    case 'c':
      result = cmd_color(cmd,len);
      break;
    case 'f':
      result = cmd_flags(cmd, len);
      break;
    case 'd':
      result = cmd_draw(cmd, len);
      break;
    case 'g':
      result = cmd_goto(cmd, len);
      break;
    case 'e':
      result = cmd_erase(cmd, len);
      break;
    case 's':
      /* do nothing - only return status */
      result = CMD_OK;
      break;
    case 'q':
      result = cmd_query(cmd, len);
      break;
    case 'i':
      result = cmd_input(cmd, len);
      break;
    case 'p':
      result = cmd_picture(cmd, len);
      break;
    case 'y':
      result = cmd_display(cmd, len);
      break;
    default:
      result = CMD_UNKNOWN_ERR;
      break;
  }
  // report status back
  if(result != CMD_NO_REPLY) {
    cmd_status(result);
  }
}