ソースを参照

gps-test-tool: add settings options and single-run -o mode

k4be 1 日 前
親
コミット
0646c9ed35
2 ファイル変更、106 行追加、35 行削除
  1. 22 12
      gps-test-tool/README.md
  2. 84 23
      gps-test-tool/main.c

+ 22 - 12
gps-test-tool/README.md

@@ -56,20 +56,30 @@ the same input.
 
 ### Adjusting settings
 
-There's no command-line or interactive settings UI. To try different
-device settings against a log, edit the defaults in `reset_system()` in
-`main.c` (around line 67) and rebuild:
-
-```c
-System.conf.skip_points = 0;
-System.conf.auto_pause_time = 30;   // seconds
-System.conf.auto_pause_dist = 10;   // meters
-System.conf.auto_pause_speed = 3;   // km/h
-System.conf.min_sats = 4;           // minimum satellites for a valid fix
+Device settings can be given as options (defaults in brackets; the ranges
+the device accepts are in `soft/settings.c`'s `limits_min_u8`/`limits_max_u8`):
+
+```
+-A        disable auto-pause                 [enabled]
+-t SEC    auto-pause time                    [30]
+-d M      auto-pause distance                [10]
+-s KMH    auto-pause speed                   [3]
+-k N      points skipped after a fix         [0]
+-m N      minimum satellites                 [4]
+-v        verbose system log
 ```
 
-These match `soft/settings.c`'s out-of-the-box defaults, so start from a
-known-good baseline before changing them.
+The auto-pause defaults match `soft/settings.c`'s out-of-the-box defaults.
+
+### Single run
+
+`-o FILE` makes a single run with the given settings instead of the
+filtered/unfiltered pair, writing only that GPX file. `-l FILE` also writes
+its debug output, and `-n` disables filters:
+
+```
+./gps-test-tool -o out.gpx -l out.txt -n -t 60 input.nmea
+```
 
 ### Input format
 

+ 84 - 23
gps-test-tool/main.c

@@ -2,17 +2,21 @@
  * GPS Test Tool - PC Application
  *
  * Tests GPS filtering and GPX generation using actual embedded code
- * Usage: ./gps-test-tool <input.nmea>
+ * Usage: ./gps-test-tool [options] <input.nmea>
  *
- * Generates:
+ * Generates (default mode):
  *   - output_filtered.gpx
  *   - output_unfiltered.gpx
  *   - debug_filtered.txt
  *   - debug_unfiltered.txt
+ *
+ * With -o, does a single run with the given settings instead (used by
+ * gps-test-tool-gui).
  */
 
 #define PC_BUILD
 #include "main.h"
+#include <getopt.h>
 
 /* Global variables expected by project code */
 volatile struct system_s System;
@@ -63,17 +67,26 @@ void iso_time_to_filename(char *time) {
     }
 }
 
+/* Settings applied by reset_system(); command-line options override these. */
+static unsigned char opt_skip_points = 0;  /* Don't skip points for testing */
+/* Match soft/settings.c's defaults_u8, so this tool's auto-pause behavior
+ * matches an out-of-the-box device. */
+static unsigned char opt_auto_pause_time = 30;
+static unsigned char opt_auto_pause_dist = 10;
+static unsigned char opt_auto_pause_speed = 3;
+static unsigned char opt_min_sats = 4;  /* Require at least 4 satellites */
+static unsigned char opt_auto_pause = 1;
+static unsigned char opt_verbose_log = 0;
+
 /* Reset system state */
 void reset_system(void) {
     memset((void*)&System, 0, sizeof(System));
     memset(&location, 0, sizeof(location));
-    System.conf.skip_points = 0;  /* Don't skip points for testing */
-    /* Match soft/settings.c's defaults_u8, so this tool's auto-pause behavior
-     * (enabled below) matches an out-of-the-box device. */
-    System.conf.auto_pause_time = 30;
-    System.conf.auto_pause_dist = 10;
-    System.conf.auto_pause_speed = 3;
-    System.conf.min_sats = 4;  /* Require at least 4 satellites */
+    System.conf.skip_points = opt_skip_points;
+    System.conf.auto_pause_time = opt_auto_pause_time;
+    System.conf.auto_pause_dist = opt_auto_pause_dist;
+    System.conf.auto_pause_speed = opt_auto_pause_speed;
+    System.conf.min_sats = opt_min_sats;
     System.tracking_paused = 0;
     System.tracking_auto_paused = 0;
     System.bat_volt = 4.0f;   /* no real ADC here; keeps the status line's v=/bat%= fields sane */
@@ -109,7 +122,8 @@ int process_nmea_file(const char *input_file, const char *output_gpx,
 
     /* Configure filters */
     set_flag(CONFFLAG_DISABLE_FILTERS, !filters_enabled);
-    set_flag(CONFFLAG_AUTO_PAUSE, 1);
+    set_flag(CONFFLAG_AUTO_PAUSE, opt_auto_pause);
+    set_flag(CONFFLAG_VERBOSE_LOG, opt_verbose_log);
 
     gps_powered_on();
     log_boot_record();
@@ -260,25 +274,72 @@ int process_nmea_file(const char *input_file, const char *output_gpx,
     return 0;
 }
 
-int main(int argc, char *argv[]) {
-    int ret;
+static void usage(const char *name) {
+    fprintf(stderr, "Usage: %s [options] <input.nmea>\n", name);
+    fprintf(stderr, "\nWithout -o, generates:\n");
+    fprintf(stderr, "  - output_filtered.gpx\n");
+    fprintf(stderr, "  - output_unfiltered.gpx\n");
+    fprintf(stderr, "  - debug_filtered.txt\n");
+    fprintf(stderr, "  - debug_unfiltered.txt\n");
+    fprintf(stderr, "\nOptions:\n");
+    fprintf(stderr, "  -o FILE  single run: write GPX to FILE only\n");
+    fprintf(stderr, "  -l FILE  single run: write debug output to FILE (default: none)\n");
+    fprintf(stderr, "  -n       single run: disable filters\n");
+    fprintf(stderr, "  -A       disable auto-pause\n");
+    fprintf(stderr, "  -t SEC   auto-pause time (default %u)\n", opt_auto_pause_time);
+    fprintf(stderr, "  -d M     auto-pause distance (default %u)\n", opt_auto_pause_dist);
+    fprintf(stderr, "  -s KMH   auto-pause speed (default %u)\n", opt_auto_pause_speed);
+    fprintf(stderr, "  -k N     skip points after fix (default %u)\n", opt_skip_points);
+    fprintf(stderr, "  -m N     minimum satellites (default %u)\n", opt_min_sats);
+    fprintf(stderr, "  -v       verbose log\n");
+}
 
-    printf("GPS Test Tool v1.0\n");
-    printf("==================\n\n");
+/* Parse a 0..255 setting value; returns 0 on success. */
+static int parse_u8(const char *str, unsigned char *val) {
+    char *end;
+    long v = strtol(str, &end, 10);
+    if (!*str || *end || v < 0 || v > 255)
+        return 1;
+    *val = v;
+    return 0;
+}
 
-    if (argc != 2) {
-        fprintf(stderr, "Usage: %s <input.nmea>\n", argv[0]);
-        fprintf(stderr, "\nGenerates:\n");
-        fprintf(stderr, "  - output_filtered.gpx\n");
-        fprintf(stderr, "  - output_unfiltered.gpx\n");
-        fprintf(stderr, "  - debug_filtered.txt\n");
-        fprintf(stderr, "  - debug_unfiltered.txt\n");
+int main(int argc, char *argv[]) {
+    int ret, c, bad = 0;
+    const char *single_gpx = NULL;
+    const char *single_debug = "/dev/null";
+    int single_filters = 1;
+
+    while ((c = getopt(argc, argv, "o:l:nAt:d:s:k:m:v")) != -1) {
+        switch (c) {
+            case 'o': single_gpx = optarg; break;
+            case 'l': single_debug = optarg; break;
+            case 'n': single_filters = 0; break;
+            case 'A': opt_auto_pause = 0; break;
+            case 't': bad |= parse_u8(optarg, &opt_auto_pause_time); break;
+            case 'd': bad |= parse_u8(optarg, &opt_auto_pause_dist); break;
+            case 's': bad |= parse_u8(optarg, &opt_auto_pause_speed); break;
+            case 'k': bad |= parse_u8(optarg, &opt_skip_points); break;
+            case 'm': bad |= parse_u8(optarg, &opt_min_sats); break;
+            case 'v': opt_verbose_log = 1; break;
+            default: bad = 1; break;
+        }
+    }
+
+    if (bad || optind != argc - 1) {
+        usage(argv[0]);
         return 1;
     }
 
+    if (single_gpx)
+        return process_nmea_file(argv[optind], single_gpx, single_debug, single_filters);
+
+    printf("GPS Test Tool v1.0\n");
+    printf("==================\n\n");
+
     /* Process with filters enabled */
     printf("Processing with filters ENABLED...\n");
-    ret = process_nmea_file(argv[1], "output_filtered.gpx",
+    ret = process_nmea_file(argv[optind], "output_filtered.gpx",
                             "debug_filtered.txt", 1);
     if (ret != 0) {
         fprintf(stderr, "Failed to process with filters enabled\n");
@@ -287,7 +348,7 @@ int main(int argc, char *argv[]) {
 
     /* Process with filters disabled */
     printf("Processing with filters DISABLED...\n");
-    ret = process_nmea_file(argv[1], "output_unfiltered.gpx",
+    ret = process_nmea_file(argv[optind], "output_unfiltered.gpx",
                             "debug_unfiltered.txt", 0);
     if (ret != 0) {
         fprintf(stderr, "Failed to process with filters disabled\n");