/* * main.h - PC Compatible Version * Central header for GPS Test Tool - handles PC/embedded switches */ #pragma once #ifdef PC_BUILD /* ========== PC BUILD CONFIGURATION ========== */ /* Standard C headers - all includes centralized here */ #include #include #include #include #include #include #include #include #include /* Prevent AVR headers from being included */ #define _AVR_PGMSPACE_H_ 1 #define _AVR_IO_H_ 1 #define _AVR_WDT_H_ 1 #define _AVR_SLEEP_H_ 1 #define _AVR_INTERRUPT_H_ 1 #define _AVR_EEPROM_H_ 1 /* PROGMEM/Flash support - no-op on PC */ #define PROGMEM #define __flash #define PSTR(s) (s) #define strcpy_P strcpy #define strcat_P strcat #define strcmp_P strcmp #define pgm_read_byte(addr) (*(addr)) /* Stub LCD type to bypass error */ #define LCD_ALNUM /* Interrupt stubs */ #define cli() #define sei() /* FatFS types */ typedef struct { FILE *fp; char filename[256]; } FIL; typedef uint32_t DWORD; typedef unsigned int UINT; typedef unsigned char BYTE; typedef char TCHAR; typedef unsigned char FRESULT; /* FatFS functions */ #define FA_WRITE 0x02 #define FA_OPEN_ALWAYS 0x10 static inline FRESULT f_open(FIL *file, const TCHAR *path, BYTE mode) { (void)mode; file->fp = fopen(path, "w"); return file->fp ? 0 : 1; } static inline FRESULT f_write(FIL *file, const void *buf, UINT len, UINT *written) { if (!file->fp) return 1; *written = fwrite(buf, 1, len, file->fp); return (*written == len) ? 0 : 1; } static inline FRESULT f_close(FIL *file) { if (file->fp) { fclose(file->fp); file->fp = NULL; return 0; } return 1; } /* xprintf functions */ extern FILE *debug_output; static inline void xputs(const char* str) { FILE *out = debug_output ? debug_output : stdout; fputs(str, out); } static inline void xputs_P(const char* str) { FILE *out = debug_output ? debug_output : stdout; fputs(str, out); } static inline void xprintf(const char* fmt, ...) { FILE *out = debug_output ? debug_output : stdout; va_list ap; va_start(ap, fmt); vfprintf(out, fmt, ap); va_end(ap); } static inline void xsprintf(char* buff, const char* fmt, ...) { va_list ap; va_start(ap, fmt); vsprintf(buff, fmt, ap); va_end(ap); } static inline void xfprintf(void (*put)(int), const char* fmt, ...) { /* Stub for PC - just ignore output to UART */ (void)put; (void)fmt; } /* xatof - Parse float from string (used by NMEA parser) */ static inline void xatof(const char **str, double *result) { char *end; *result = strtod(*str, &end); *str = end; } /* Math constants */ #ifndef M_PI #define M_PI 3.14159265358979323846 #endif #else /* ========== EMBEDDED BUILD CONFIGURATION ========== */ #define __PROG_TYPES_COMPAT__ #include #include #include #include "stime.h" #include "expander.h" #include "settings.h" #if defined(LCD_GRAPHIC) #include "UC1601S-I2C.h" #elif defined(LCD_ALNUM) #include "HD44780-I2C.h" #else #error No LCD type defined #endif #endif /* PC_BUILD */ /* ========== COMMON DEFINITIONS (both PC and embedded) ========== */ #define IVT_SYNC 180 #define POWER_SW_TIME 300 #define BACKLIGHT_TIME 10000 #define VI_LVL 3.1 #define VI_LVH 3.4 #define VI_MULT (3.3 / 6.6 / 2.495 * 1024) /* Configuration flags */ #define CONFFLAG_DISABLE_FILTERS 0x01 #define CONFFLAG_ENABLE_SBAS 0x02 #define CONFFLAG_AUTO_PAUSE 0x04 /* GNSS modes */ #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 /* GPS initialization states */ #define GPS_INIT_NOT_INITIALIZED 0 #define GPS_INIT_QUERY_SENT 1 /* Location validity states */ #define LOC_INVALID 0 #define LOC_VALID_NEW 1 #define LOC_VALID 2 /* Configuration structure */ struct config_s { unsigned char skip_points; unsigned char auto_pause_dist; unsigned char gnss_mode; unsigned char min_sat; unsigned char min_sats; /* Alias for compatibility */ }; /* System structure */ struct system_s { struct config_s conf; unsigned long int distance; /* cm */ unsigned long int elevation_gain; /* dm (decimeters, 0.1m resolution) */ unsigned long int elevation_loss; /* dm (decimeters, 0.1m resolution) */ unsigned char speed; /* km/h */ time_t time_start; time_t current_pause_start; time_t pause_time; unsigned tracking_paused:1; unsigned tracking_auto_paused:1; unsigned gps_initialized:2; unsigned gps_only:1; unsigned keypress:1; unsigned location_valid:2; unsigned sat_count_low:1; unsigned sbas:1; unsigned satellites_used:5; }; /* Location structure */ struct location_s { float lon; float lat; float alt; time_t time; }; /* Global variables */ extern volatile struct system_s System; extern struct location_s location; extern time_t utc; /* Configuration flags */ extern unsigned char config_flags; static inline unsigned char get_flag(unsigned char flag) { return (config_flags & flag) ? 1 : 0; } /* Time functions */ char *get_iso_time(time_t time, unsigned char local); void iso_time_to_filename(char *time); /* GPS and distance functions */ void gps_initialize(void); void add_distance(float dist); void add_elevation(float ele_change); /* Stub functions for PC build */ #ifdef PC_BUILD static inline void set_timer(int timer, int val) { (void)timer; (void)val; } static inline int timer_expired(int timer) { (void)timer; return 0; } static inline void wdt_reset(void) {} static inline void sleep(void) {} static inline int uart0_test(void) { return 0; } static inline unsigned char uart0_get(void) { return 0; } static inline void uart0_put(char c) { (void)c; } static inline void uart1_put(char c) { (void)c; } static unsigned char FLAGS = 0; #define F_LVD 0x01 #define F_POWEROFF 0x02 #define F_GPSOK 0x04 #define recv_timeout 0 #endif /* PC_BUILD stubs */