⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bluegps.c

📁 GPS接收软件
💻 C
📖 第 1 页 / 共 2 页
字号:
          print_message (MSG_VERBOSE,                         "Entries in Datalog: %ld (%.2f%% free)\n",                         state->entries, 100 * state->space);          if (context->filename)            {              context->expected_entries = state->entries;              if (strcmp (context->filename, "-") == 0)                context->outfile = stdout;              else                context->outfile = fopen (context->filename, "w");              if (!context->outfile)                {                  perror ("Unable to open output file");                  context->req_quit = 1;                }            }        }      else        {          rbt3000_abort ("Wrong logstate reply size.");        }      break;    case CMD_GETLOG:      entrycount = 0;      break;    case CMD_DATALGENTRY:      if (len - 1 == sizeof (datalog_entry_t))        {          datalog_entry_t *entry = (datalog_entry_t *) (buffer + 1);          if (entrycount == entry->block &&              entrycount < context->expected_entries)            {              entrycount++;              print_progress_bar (MSG_NORMAL, entrycount,                                  context->expected_entries);              fprint_datalog_entry_nmea (context->outfile, entry);            }          else            {              rbt3000_abort ("\nWrong sequence number in Logentry.");            }        }      else if (len - 1 == sizeof (datalog_end_entry_t))        {          if (context->outfile != stdout)            fclose (context->outfile);          print_message (MSG_NORMAL, "\n");          if (entrycount != context->expected_entries)            rbt3000_abort ("\nUnexpected end of Logentries.");          context->expected_entries = 0;        }      else        {          rbt3000_abort ("\nWrong datalgentry reply size.");        }      break;    case CMD_SETLOGCONF:      if (len - 1 == 24)        {          datalog_config_t *status = (datalog_config_t *) (buffer + 1);          print_message (MSG_NORMAL, "New Datalog configuration:\n");          print_datalog_config (MSG_NORMAL, status);          print_message (MSG_NORMAL, "\n");        }      else        {          rbt3000_abort ("Wrong setlogconf reply size.");        }      break;    case CMD_PASSWORD_SET:      if (len - 1 == 1)        print_message (MSG_NORMAL, "Password set to new value\n");      else        rbt3000_abort ("Wrong password_set reply size.");      break;    case CMD_PASSWORD_ACT:      if (len - 1 == 1)        print_message (MSG_NORMAL, "Password protection %s.\n",                       buffer[1] ? "enabled" : "disabled");      else        rbt3000_abort ("Wrong password_act reply size.");      break;    case CMD_SETNAME:      if (len - 1 == 15)        {          buffer[15] = 0x0;          print_message (MSG_NORMAL, "Name set to \"%s\"\n\n", buffer + 1);        }      else        {          rbt3000_abort ("Wrong setname reply size.");        }      break;    case CMD_LOGERASE:      if (buffer[1])        print_message (MSG_NORMAL, "Erasing Log successful\n");      else        print_message (MSG_QUIET, "Erasing Log failed\n");      break;    default:      print_message (MSG_QUIET, "Unexpected reply in conf: %02x (len %d)\n",                     buffer[0] ,len);  }}voidrbt3000_handle_reply (int device_fd, unsigned char *buffer, int len){  static time_t alive_timer = 0;  static int connected = 0;  time_t now;  if (context->req_quit)    return;  else    rbt3000_handle_reply_action (device_fd, buffer, len);  switch (buffer[0])  {    case CMD_ECHO:      if (!connected)        {          connected = 1;          rbt3000_send_cmd (device_fd, CMD_STATUS);        }      break;    case CMD_STATUS:      if (context->need_password)        {          if (context->password[0])            rbt3000_send_cmd_seq (device_fd, CMD_PASSWORD,                                  context->password, 4);          else            rbt3000_abort ("Password required but not specified.");        }      else        {          rbt3000_send_cmd (device_fd, CMD_LOGSTATE);        }      break;    case CMD_PASSWORD:      if (!context->need_password)        rbt3000_send_cmd (device_fd, CMD_LOGSTATE);      else        rbt3000_abort ("Wrong password given.");      break;    case CMD_PASSWORD_SET:      rbt3000_send_cmd_seq (device_fd, CMD_PASSWORD_ACT, "\001", 1);      break;    case CMD_LOGSTATE:      if (context->expected_entries)        {          rbt3000_send_cmd_seq (device_fd, CMD_GETLOG,                                "\x00\x00\x00\x00\x01\x00\x00\x00"                                "\x00\x00\x00\x00\xDC\x05\x00\x00", 16);          return;        }      /* intentionally no break here */    case CMD_GETLOG:    case CMD_DATALGENTRY:      if (context->expected_entries)        {          if (!alive_timer)            alive_timer = time (NULL);          now = time (NULL);          if (now - alive_timer > 2)            {              rbt3000_send_cmd (device_fd, CMD_ALIVE);              alive_timer = now;            }          return;        }      if (context->have_old_config &&          context->commands & (SET_LOG_ENABLE |                     SET_LOG_OVERWRITE |                     SET_LOG_HEIGHT |                     SET_CONST_TIME |                     SET_CONST_DIST |                     SET_MAX_SPEED))        {          if (context->commands & SET_LOG_ENABLE)            context->old_config.enabled = context->new_config.enabled;          if (context->commands & SET_LOG_OVERWRITE)            context->old_config.overwrite = context->new_config.overwrite;          if (context->commands & SET_LOG_HEIGHT)            context->old_config.include_altitude = context->new_config.include_altitude;          if (context->commands & SET_CONST_TIME)            context->old_config.interval = context->new_config.interval;          if (context->commands & SET_CONST_DIST)            context->old_config.constant_distance = context->new_config.constant_distance;          if (context->commands & SET_MAX_SPEED)            context->old_config.speeding_limit = context->new_config.speeding_limit;          rbt3000_send_cmd_seq (device_fd, CMD_SETLOGCONF,                                (char *) &context->old_config,                                sizeof (context->old_config));          return;        }      /* intentionally no break here */    case CMD_SETLOGCONF:      if (context->commands & SET_NAME)        {          rbt3000_send_cmd_seq (device_fd, CMD_SETNAME,                                context->new_name, 15);          return;        }      /* intentionally no break here */    case CMD_SETNAME:      if (context->commands & SET_PASSWORD)        {          if (context->new_password[0])            rbt3000_send_cmd_seq (device_fd, CMD_PASSWORD_SET,                                  context->new_password, 4);          else            rbt3000_send_cmd_seq (device_fd, CMD_PASSWORD_ACT, "\0", 1);          return;        }      /* intentionally no break here */    case CMD_PASSWORD_ACT:      if (context->commands & ERASE_DATALOG)        {          rbt3000_send_cmd (device_fd, CMD_LOGERASE);          return;        }      /* intentionally no break here */    case CMD_LOGERASE:      context->req_quit = 1;      break;    default:      print_message (MSG_QUIET, "Unknown reply: 0x%02x (len %d)\n",                     buffer[0] ,len);  }}voidmainloop (int device_fd){  fd_set rfds, wfds;  struct timeval tv = { 1, 0 };  unsigned char buffer[1024];  int i, ret;  context->req_quit = 0;  while (!context->req_quit)    {      FD_ZERO (&rfds);      FD_ZERO (&wfds);      FD_SET (device_fd, &rfds);      tv.tv_sec = 1;      tv.tv_usec = 0;      ret = select (device_fd + 1, &rfds, &wfds, NULL, &tv);      if (ret < 0)        {          perror ("select");          break;        }      if (ret == 0)        rbt3000_send_cmd (device_fd, CMD_ECHO);      if (FD_ISSET (device_fd, &rfds))        {          ret = read (device_fd, &buffer, 1024);          if (ret < 0)            perror ("read");          for (i = 0; i < ret; i++)            rbt3000_parse_byte (device_fd, buffer[i]);        }    }}voidusage (char *message){  print_message (MSG_QUIET,                 "BlueGPS V"VERSION"\n"                 "       (c) 2006 by Till Harbaum <Till@Harbaum.org>\n"                 "                   and Simon Budig <simon@budig.de>\n"                 "\n"                 "Usage: bluegps [options] bdaddr\n"                 "\n"                 "Options:\n"                 "    -d <filename>  download nmea datalog to file\n"                 "    -d -           download nmea datalog to stdout\n"                 "    -e             erase datalog\n"                 "    -p <pass>      provide password (4 digits)\n"                 "\n"                 "    -h             show this help\n"                 "    -q             operate quietly\n"                 "    -v             operate verbously\n"                 "\n"                 "Device configuration:\n"                 "    -n             set name of RBT-3000\n"                 "    -w <pass>      set and enable new password (4 digits)\n"                 "    -W             disable password\n"                 "\n"                 "Logging configuration:\n"                 "    -l             enable logging\n"                 "    -L             disable logging\n"                 "    -i <interval>  log point every <interval> seconds\n"                 "    -I             no time-based logging\n"                 "    -c <dist>      log point every <dist> meters\n"                 "    -C             no distance-based logging\n"                 "    -s <speed>     log points when faster than <speed> km/h\n"                 "    -S             disable speed based logging\n"                 "    -a             include altitude information in log\n"                 "    -A             exclude altitude information in log\n"                 "    -o             overwrite when memory is full\n"                 "    -O             stop logging when memory is full\n"                 "\n");  if (message)    print_message (MSG_QUIET, "%s\n", message);  exit (1);}intmain (int   argc,      char *argv[]){  int i;  context = calloc (sizeof (BlueGPSContext), 1);  context->messages = MSG_NORMAL;  while ((i = getopt (argc, argv, "aAc:Cd:ehi:IlLn:oOp:qs:Svw:W")) != -1)    {      switch (i)        {          case 'a':            context->new_config.include_altitude = 1;            context->commands |= SET_LOG_HEIGHT;            break;          case 'A':            context->new_config.include_altitude = 0;            context->commands |= SET_LOG_HEIGHT;            break;          case 'c':            context->new_config.constant_distance = atol (optarg);            context->commands |= SET_CONST_DIST;            break;          case 'C':            context->new_config.constant_distance = 0;            context->commands |= SET_CONST_DIST;            break;          case 'd':            context->filename = strdup (optarg);            break;          case 'e':            context->commands |= ERASE_DATALOG;            break;          case 'h':            usage (NULL);            break;          case 'i':            context->new_config.interval = atol (optarg);            context->commands |= SET_CONST_TIME;            break;          case 'I':            context->new_config.interval = 0;            context->commands |= SET_CONST_TIME;            break;          case 'l':            context->new_config.enabled = 1;            context->commands |= SET_LOG_ENABLE;            break;          case 'L':            context->new_config.enabled = 0;            context->commands |= SET_LOG_ENABLE;            break;          case 'n':            strncpy (context->new_name, optarg, 14);            context->new_name[14] = 0;            context->commands |= SET_NAME;            break;          case 'o':            context->new_config.overwrite = 1;            context->commands |= SET_LOG_OVERWRITE;            break;          case 'O':            context->new_config.overwrite = 0;            context->commands |= SET_LOG_OVERWRITE;            break;          case 'p':            if (strlen (optarg) == 4 &&                isdigit (optarg[0]) && isdigit (optarg[1]) &&                isdigit (optarg[2]) && isdigit (optarg[3]))              {                strncpy (context->password, optarg, 4);              }            else              {                usage ("Password must consist exactly 4 digits.");              }            break;          case 'q':            context->messages = MSG_QUIET;            break;          case 's':            context->new_config.speeding_limit = atof (optarg);            context->commands |= SET_MAX_SPEED;            break;          case 'S':            context->new_config.speeding_limit = 0;            context->commands |= SET_MAX_SPEED;            break;          case 'v':            context->messages = MSG_VERBOSE;            break;          case 'w':            if (strlen (optarg) == 4 &&                isdigit (optarg[0]) && isdigit (optarg[1]) &&                isdigit (optarg[2]) && isdigit (optarg[3]))              {                strncpy (context->new_password, optarg, 4);                context->commands |= SET_PASSWORD;              }            else              {                usage ("Password must consist exactly 4 digits.");              }            break;          case 'W':            context->new_password[0] = 0;            context->commands |= SET_PASSWORD;            break;        }    }  if (context->filename == NULL &&      context->commands == 0 &&      context->messages == MSG_NORMAL)    context->messages = MSG_VERBOSE;  if (optind == argc)    {      usage ("Specify Device-Address");    }  if (optind > argc + 1)    {      usage ("too many Arguments given");    }  if (!rbt3000_connect (argv[optind]))    exit (1);  signal (SIGINT, sigproc);  rbt3000_init (context->device_fd);  mainloop (context->device_fd);  if (context->device_fd)    close (context->device_fd);  free (context);  return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -