#pragma once /* Needs time_t already defined (embedded: stime.h's typedef; PC: ) - * include this only after whichever of those this build already includes. */ /* * Definitions shared byte-for-byte between the embedded build (soft/) and * the PC test tool (gps-test-tool/): struct layouts that cross the boundary * between translation units compiled for each side (System/location/ * auto_pause, all real logic - gpx.c/nmea.c/syslog.c/autopause.c compile * unmodified into both), and the value constants those structs' fields hold. * * Kept deliberately minimal: this is not "the" shared header, just the part * that must never drift, because a mismatch here is a silent ABI mismatch * between translation units rather than a compile error. Includes, pin/ * hardware definitions, and anything embedded-only or PC-only stay in each * side's own main.h. */ /* System.location_valid values */ #define LOC_INVALID 0 #define LOC_VALID 1 #define LOC_VALID_NEW 2 /* System.fix_type values (from GSA) */ #define FIX_TYPE_UNKNOWN 0 #define FIX_TYPE_2D 2 #define FIX_TYPE_3D 3 /* GNSS modes (System.conf.gnss_mode) */ #define GNSS_MODE_GPS_GLONASS_GALILEO 0 #define GNSS_MODE_GPS 1 #define GNSS_MODE_GPS_GALILEO 2 #define GNSS_MODE_GALILEO 3 #define GNSS_MODE_GPS_BEIDOU 4 #define GNSS_MODE_BEIDOU 5 /* UART log mode values (System.conf.uart_log_mode) */ #define UART_LOG_MODE_MIXED 0 /* NMEA and system log interleaved (default) */ #define UART_LOG_MODE_NMEA 1 /* NMEA only */ #define UART_LOG_MODE_SYSTEM 2 /* system log only */ /* Reasons a candidate point can be rejected before being written (see * soft/syslog.h's reject_reason_names[], indexed by these) */ #define REJECT_REASON_KALMAN 0 /* Kalman-filtered position error too large */ #define REJECT_REASON_DISTDIFF 1 /* distance jump inconsistent with recent history */ #define REJECT_REASON_MINDIST 2 /* too small a position change since last saved point */ #define REJECT_REASON_ALTDIFF 3 /* altitude jump inconsistent with recent history */ /* System.conf.flags bit indices, read/set via get_flag(index)/set_flag(index, * val) - both sides index the same way (a bit position within a flags byte * array), not a pre-shifted bitmask, so these constants and the get_flag() * call sites are interchangeable between builds. */ #define CONFFLAG_DISABLE_FILTERS 0 #define CONFFLAG_ENABLE_SBAS 1 #define CONFFLAG_LOGGING_AFTER_BOOT 2 #define CONFFLAG_AUTO_PAUSE 3 #define CONFFLAG_RESET_ON_NEW_FILE 4 #define CONFFLAG_VERBOSE_LOG 5 #define CONFFLAG_LAST 5 struct config_s { union { unsigned char conf_u8[16]; struct { unsigned char gnss_mode; // 0 unsigned char skip_points; // 1 unsigned char auto_pause_time; // 2 unsigned char auto_pause_dist; // 3 unsigned char min_sats; // 4 unsigned char auto_pause_speed; // 5 unsigned char uart_log_mode; // 6 }; }; unsigned char flags[4]; }; struct location_s { float lon; float lat; float alt; time_t time; }; #ifndef PC_BUILD /* Real hardware-timer-backed countdowns (set_timer()/timer_expired() in * soft/main.h), driven by an ISR via atomic_set_uint()/atomic_get_uint(). * Embedded-only: the PC build's set_timer()/timer_expired() are plain no-op * functions that never reference System.timers, so struct system_s doesn't * carry it there - dead weight, and a stray cli()/sei() dependency, for a * build with no such ISR. */ struct timers { unsigned int owire; unsigned int beep; unsigned int recv_timeout; unsigned int status_log; unsigned int lcd; unsigned int backlight; }; #endif struct system_s { #ifndef PC_BUILD struct timers timers; #endif struct config_s conf; unsigned long int distance; // cm unsigned long int elevation_gain; // dm (decimeters, 0.1m resolution); filtered (dead-band+smoothed) unsigned long int elevation_loss; // dm; filtered (dead-band+smoothed) unsigned long int elevation_gain_raw; // dm; unfiltered, for log comparison only unsigned long int elevation_loss_raw; // dm; unfiltered, for log comparison only unsigned long int alt_max; // dm; highest smoothed altitude seen this session unsigned long int speed_accum_x100; // sum of instantaneous NMEA speed samples (km/h * 100) while not paused unsigned long int speed_sample_count; // number of samples in speed_accum_x100 unsigned long int points_written; // count of accepted/written track points this session unsigned long int rejected_count; // count of rejected candidate points this session (unsigned long: a poor-fix session can reject far more than 65535 times) unsigned long int points_paused; // count of candidate points seen while tracking_is_paused(), this session unsigned long int points_skipped; // count of candidate points dropped by the skip_points warm-up (after boot or a fix gap), this session unsigned long int points_accepted; // count of candidate points that passed every reject check, this session; with filters enabled, points_accepted - points_written*AVG_COUNT is "averaged out, not yet flushed". // points_paused + points_skipped + rejected_count + points_accepted may fall a couple short of the true candidate-point total: the sliding window used for the distance/altitude spike checks needs a couple of points to refill after each reset (boot, or a fix gap) before it can even decide reject-vs-accept, and those few points aren't tallied anywhere. unsigned int hdop_x100; // HDOP * 100, from GSA unsigned char fix_type; // FIX_TYPE_* from GSA unsigned char speed; // km/h time_t time_start; time_t current_pause_start; time_t pause_time; float bat_volt; float bat_volt_min; // lowest battery voltage seen this session float temperature; unsigned temperature_ok:1; unsigned satellites_used:5; unsigned location_valid:2; unsigned dgps:1; /* GGA reports a DGPS-quality fix - the receiver's own doing, not CONFFLAG_ENABLE_SBAS (our SBAS-search request) */ unsigned gps_initialized:2; unsigned gps_only:1; unsigned keypress:1; unsigned tracking_paused:1; unsigned tracking_auto_paused:1; unsigned open_new_file:1; unsigned sat_count_low:1; unsigned int global_error; unsigned char status; unsigned char display_state; unsigned char working_mode; }; /* Auto-pause state (soft/autopause.c, compiled unmodified into both builds - * see soft/autopause.h). */ struct auto_pause_s { unsigned char point_counter; unsigned long int prev_distance; unsigned char speed_counter; struct location_s pause_anchor; /* running average position while paused */ unsigned int anchor_sample_count; unsigned char resume_high_history; /* bit history: was the anchor-distance/speed resume condition met */ };