Pārlūkot izejas kodu

Share auto-pause detection between the firmware and gps-test-tool

Extracted auto_pause_process()/auto_unpause()/auto_pause_activate() out of
soft/main.c into their own module (soft/autopause.c/.h), matching the
existing gpx.c/nmea.c/syslog.c wrapper convention, so gps-test-tool compiles
and runs the exact same logic instead of never calling it at all.

This matters because auto-pause directly gates System.distance/
elevation_gain/elevation_loss (excluded while paused), so it's a major part
of what the tool's GPX/summary output actually looks like: running the full
2026-09-26 hike log through it now shows 44 PAUSE/RESUME events and
moving=8h01m/stopped=1h18m in the final summary, instead of the previous
(wrong) moving=9h20m/stopped=0h00m with auto-pause silently never engaging.
Distance/gain/loss also drop slightly now that paused-time drift is
correctly excluded, and the GPX gets 22 separate <trkseg> blocks instead of
one continuous segment.

Wired up in gps-test-tool/main.c: CONFFLAG_AUTO_PAUSE enabled and
auto_pause_time/dist/speed defaulted to soft/settings.c's own defaults_u8
(30s/10m/3km/h), auto_pause_process() called alongside gpx_process_point()
per accepted point, matching soft/main.c's pairing. beep() is stubbed out
(meaningless on PC) via a static inline in gps-test-tool/main.h.
k4be 1 nedēļu atpakaļ
vecāks
revīzija
760f59354c

+ 1 - 1
gps-test-tool/Makefile

@@ -5,7 +5,7 @@ CFLAGS = -Wall -Wextra -g -O2 -I. -I../soft -DPC_BUILD
 LDFLAGS = -lm
 
 TARGET = gps-test-tool
-SOURCES = main.c gpx_wrapper.c nmea_actual_wrapper.c syslog_wrapper.c
+SOURCES = main.c gpx_wrapper.c nmea_actual_wrapper.c syslog_wrapper.c autopause_wrapper.c
 OBJECTS = $(SOURCES:.c=.o)
 
 TEST_MALFORMED = test-malformed

+ 10 - 0
gps-test-tool/autopause_wrapper.c

@@ -0,0 +1,10 @@
+/*
+ * Autopause Wrapper for PC Compilation
+ * Simply includes actual autopause.c - main.h handles all PC/embedded switches
+ */
+
+#define PC_BUILD
+#include "main.h"
+
+/* Include the actual autopause.c source */
+#include "../soft/autopause.c"

+ 7 - 2
gps-test-tool/main.c

@@ -68,7 +68,11 @@ 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 */
-    System.conf.auto_pause_dist = 100;
+    /* 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.tracking_paused = 0;
     System.tracking_auto_paused = 0;
@@ -101,7 +105,7 @@ int process_nmea_file(const char *input_file, const char *output_gpx,
     }
 
     /* Configure filters */
-    config_flags = filters_enabled ? 0 : CONFFLAG_DISABLE_FILTERS;
+    config_flags = (filters_enabled ? 0 : CONFFLAG_DISABLE_FILTERS) | CONFFLAG_AUTO_PAUSE;
 
     /* Reset system state */
     reset_system();
@@ -159,6 +163,7 @@ int process_nmea_file(const char *input_file, const char *output_gpx,
             /* Only process if we have valid coordinates from GGA */
             if (System.location_valid == LOC_VALID_NEW || System.location_valid == LOC_VALID) {
                 gpx_process_point(&location, &gpx_file);
+                auto_pause_process();
                 point_count++;
             }
         }

+ 17 - 0
gps-test-tool/main.h

@@ -250,6 +250,15 @@ struct location_s {
     time_t time;
 };
 
+/* Must match soft/autopause.h exactly: soft/autopause.c is compiled into
+ * this tool too (see autopause_wrapper.c). */
+struct auto_pause_s {
+    unsigned char point_counter;
+    unsigned long int prev_distance;
+    unsigned char speed_counter;
+};
+extern struct auto_pause_s auto_pause;
+
 /* Global variables */
 extern volatile struct system_s System;
 extern struct location_s location;
@@ -319,8 +328,16 @@ void log_fix_event(void);
 void log_fix_lost(void);
 void log_sbas_transition(void);
 void log_session_summary(unsigned char final);
+void log_pause_event(unsigned char started);
 void gps_powered_on(void);
 
+/* Auto-pause is real logic (soft/autopause.c), not stubbed - it directly
+ * gates System.distance/elevation_gain/elevation_loss, which is a major part
+ * of what this tool's output looks like. It calls beep(), which is
+ * meaningless on PC and stubbed out here. */
+void auto_pause_process(void);
+static inline void beep(unsigned int len, unsigned char cnt) { (void)len; (void)cnt; }
+
 extern volatile unsigned char reset_cause;
 extern __flash const char *gnss_names[];
 extern __flash const char *uart_log_mode_names[];

+ 1 - 1
soft/Makefile

@@ -6,7 +6,7 @@ FW_VERSION_NUM = 1.0.0
 GIT_HASH := $(shell git describe --always --dirty --abbrev=8 2>/dev/null || echo unknown)
 
 ### Source files and search directory
-CSRC    = main.c uart0.c uart1.c ff.c mmc.c 1wire.c ds18b20.c expander.c I2C.c xprintf.c gpx.c ffunicode.c display.c working_modes.o timec.o nmea.o settings.o menu.o syslog.o
+CSRC    = main.c uart0.c uart1.c ff.c mmc.c 1wire.c ds18b20.c expander.c I2C.c xprintf.c gpx.c ffunicode.c display.c working_modes.o timec.o nmea.o settings.o menu.o syslog.o autopause.o
 ASRC    = stime.S
 VPATH   =
 

+ 58 - 0
soft/autopause.c

@@ -0,0 +1,58 @@
+/*
+ * Auto-pause detection: shared between the firmware and gps-test-tool (see
+ * autopause_wrapper.c), since it directly gates what ends up in
+ * System.distance/elevation_gain/elevation_loss (excluded while paused) and
+ * is a major part of what those tools' output actually looks like.
+ */
+#ifdef PC_BUILD
+#include "../gps-test-tool/main.h"
+#else
+#include "main.h"
+#endif
+
+struct auto_pause_s auto_pause;
+
+static void auto_unpause(void) {
+	if (!System.tracking_auto_paused)
+		return;
+	System.tracking_auto_paused = 0;
+	log_pause_event(0);
+	beep(50, 4);
+}
+
+static void auto_pause_activate(void) {
+	System.tracking_auto_paused = 1;
+	log_pause_event(1);
+	beep(50, 3);
+}
+
+void auto_pause_process(void) {
+	if (System.tracking_paused || !get_flag(CONFFLAG_AUTO_PAUSE)) { /* remove auto-pause */
+		System.tracking_auto_paused = 0;
+		auto_pause.prev_distance = System.distance;
+		auto_pause.point_counter = 0;
+		auto_pause.speed_counter = 0;
+		return;
+	}
+	if (System.speed >= System.conf.auto_pause_speed) { /* unpause when set speed is exceeded for 3 consecutive measurements */
+		if (++auto_pause.speed_counter >= 3) {
+			auto_pause.point_counter = 0;
+			auto_pause.speed_counter = 0;
+			auto_unpause();
+			return;
+		}
+	} else {
+		auto_pause.speed_counter = 0;
+	}
+	if (++auto_pause.point_counter < System.conf.auto_pause_time)
+		return;
+	auto_pause.point_counter = 0;
+	if ((System.distance - auto_pause.prev_distance)/100 > System.conf.auto_pause_dist) {
+		if (System.tracking_auto_paused)
+			auto_unpause(); /* unpause when distance exceeded */
+	} else {
+		if (!System.tracking_auto_paused)
+			auto_pause_activate(); /* pause otherwise */
+	}
+	auto_pause.prev_distance = System.distance;
+}

+ 11 - 0
soft/autopause.h

@@ -0,0 +1,11 @@
+#pragma once
+
+struct auto_pause_s {
+	unsigned char point_counter;
+	unsigned long int prev_distance;
+	unsigned char speed_counter;
+};
+
+extern struct auto_pause_s auto_pause;
+
+void auto_pause_process(void);

+ 0 - 46
soft/main.c

@@ -18,7 +18,6 @@ FIL system_log;				/* System log file */
 char Line[100];				/* Line buffer */
 time_t utc;					/* current time */
 struct location_s location;
-struct auto_pause_s auto_pause;
 volatile unsigned long int uptime_ms; /* milliseconds since MCU startup, for the system log */
 static unsigned int io_max_ms; /* longest single SD f_write()/f_sync() duration since the last status line, ms */
 
@@ -355,51 +354,6 @@ void close_files(unsigned char flush_logs) {
 	disk_ioctl(0, CTRL_POWER, 0);
 }
 
-static inline void auto_unpause(void) {
-	if (!System.tracking_auto_paused)
-		return;
-	System.tracking_auto_paused = 0;
-	log_pause_event(0);
-	beep(50, 4);
-}
-
-static inline void auto_pause_activate(void) {
-	System.tracking_auto_paused = 1;
-	log_pause_event(1);
-	beep(50, 3);
-}
-
-static inline void auto_pause_process(void) {
-	if (System.tracking_paused || !get_flag(CONFFLAG_AUTO_PAUSE)) { /* remove auto-pause */
-		System.tracking_auto_paused = 0;
-		auto_pause.prev_distance = System.distance;
-		auto_pause.point_counter = 0;
-		auto_pause.speed_counter = 0;
-		return;
-	}
-	if (System.speed >= System.conf.auto_pause_speed) { /* unpause when set speed is exceeded for 3 consecutive measurements */
-		if (++auto_pause.speed_counter >= 3) {
-			auto_pause.point_counter = 0;
-			auto_pause.speed_counter = 0;
-			auto_unpause();
-			return;
-		}
-	} else {
-		auto_pause.speed_counter = 0;
-	}
-	if (++auto_pause.point_counter < System.conf.auto_pause_time)
-		return;
-	auto_pause.point_counter = 0;
-	if ((System.distance - auto_pause.prev_distance)/100 > System.conf.auto_pause_dist) {
-		if (System.tracking_auto_paused)
-			auto_unpause(); /* unpause when distance exceeded */
-	} else {
-		if (!System.tracking_auto_paused)
-			auto_pause_activate(); /* pause otherwise */
-	}
-	auto_pause.prev_distance = System.distance;
-}
-
 void reset_counters(void) {
 	System.distance = 0;
 	System.elevation_gain = 0;

+ 3 - 6
soft/main.h

@@ -223,18 +223,14 @@ struct location_s {
 	time_t time;
 };
 
-struct auto_pause_s {
-	unsigned char point_counter;
-	unsigned long int prev_distance;
-	unsigned char speed_counter;
-};
-
 extern volatile struct system_s System;
 extern struct location_s location;
 extern time_t utc;
 extern volatile unsigned long int uptime_ms;
 extern volatile unsigned char reset_cause;
 
+void beep(unsigned int len, unsigned char cnt);
+
 /* Project includes - headers that depend on struct definitions above */
 #include "gpx.h"
 #include "display.h"
@@ -243,6 +239,7 @@ extern volatile unsigned char reset_cause;
 #include "nmea.h"
 #include "menu.h"
 #include "syslog.h"
+#include "autopause.h"
 
 static inline void atomic_set_uint(volatile unsigned int *volatile data, unsigned int value) __attribute__((always_inline));
 static inline void atomic_set_uint(volatile unsigned int *volatile data, unsigned int value){