From 72845e4c1f2ef002e9450f1081804a300b3373fb Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Tue, 12 Aug 2025 20:53:20 +0200 Subject: [PATCH] core: gps: use new gps device API --- openrtx/include/core/gps.h | 2 +- openrtx/src/core/gps.c | 35 +++++++++-------------------------- openrtx/src/core/openrtx.c | 7 ------- openrtx/src/core/threads.c | 19 +++++++++---------- 4 files changed, 19 insertions(+), 44 deletions(-) diff --git a/openrtx/include/core/gps.h b/openrtx/include/core/gps.h index a1e0b33d..dc9d2f98 100644 --- a/openrtx/include/core/gps.h +++ b/openrtx/include/core/gps.h @@ -107,7 +107,7 @@ static inline int gps_getSentence(const struct gpsDevice *dev, char *buf, const * if available, enabled and ready, decode NMEA sentences and update * the radio state with the retrieved data. */ -void gps_task(); +void gps_task(const struct gpsDevice *dev); #endif /* GPS_H */ diff --git a/openrtx/src/core/gps.c b/openrtx/src/core/gps.c index 98cec649..cd822045 100644 --- a/openrtx/src/core/gps.c +++ b/openrtx/src/core/gps.c @@ -18,7 +18,6 @@ ***************************************************************************/ #include -#include #include #include #include @@ -28,17 +27,18 @@ #define KNOTS2KMH(x) ((((int) x) * 1852) / 1000) -static char sentence[2*MINMEA_MAX_LENGTH]; static bool gpsEnabled = false; -static bool readNewSentence = true; #ifdef CONFIG_RTC static bool isRtcSyncronised = false; #endif -void gps_task() +void gps_task(const struct gpsDevice *dev) { + char sentence[2*MINMEA_MAX_LENGTH]; + int ret; + // No GPS, return - if(state.gpsDetected == false) + if(dev == NULL) return; // Handle GPS turn on/off @@ -47,9 +47,9 @@ void gps_task() gpsEnabled = state.settings.gps_enabled; if(gpsEnabled) - gps_enable(); + gps_enable(dev); else - gps_disable(); + gps_disable(dev); } // GPS disabled, nothing to do @@ -57,24 +57,10 @@ void gps_task() return; // Acquire a new NMEA sentence from GPS - if(readNewSentence) - { - int status = gps_getNmeaSentence(sentence, 2*MINMEA_MAX_LENGTH); - if(status != 0) return; - readNewSentence = false; - } - - // Waiting for a sentence... - if(gps_nmeaSentenceReady() == false) + ret = gps_getSentence(dev, sentence, sizeof(sentence)); + if(ret <= 0) return; - // Discard all non-GPS sentences - if((sentence[0] != '$') || (sentence[1] != 'G')) - { - readNewSentence = true; - return; - } - // Parse the sentence. Work on a local state copy to minimize the time // spent with the state mutex locked gps_t gps_data; @@ -207,7 +193,4 @@ void gps_task() isRtcSyncronised = false; } #endif - - // Finally, trigger the acquisition of a new NMEA sentence - readNewSentence = true; } diff --git a/openrtx/src/core/openrtx.c b/openrtx/src/core/openrtx.c index c7f2ad38..05878757 100644 --- a/openrtx/src/core/openrtx.c +++ b/openrtx/src/core/openrtx.c @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -73,12 +72,6 @@ void openrtx_init() gfx_render(); sleepFor(0u, 30u); display_setBacklightLevel(state.settings.brightness); - - #if defined(CONFIG_GPS) - // Detect and initialise GPS - state.gpsDetected = gps_detect(1000); - if(state.gpsDetected) gps_init(9600); - #endif } void *openrtx_run(void *arg) diff --git a/openrtx/src/core/threads.c b/openrtx/src/core/threads.c index 38687b3f..da998fed 100644 --- a/openrtx/src/core/threads.c +++ b/openrtx/src/core/threads.c @@ -33,10 +33,7 @@ #include #include #include -#ifdef CONFIG_GPS -#include #include -#endif #include #if defined(PLATFORM_TTWRPLUS) @@ -137,7 +134,13 @@ void *main_thread(void *arg) { (void) arg; - long long time = 0; + long long time = 0; + + #if defined(CONFIG_GPS) + const struct gpsDevice *gps = platform_initGps(); + if(gps != NULL) + state.gpsDetected = true; + #endif while(state.devStatus != SHUTDOWN) { @@ -154,8 +157,8 @@ void *main_thread(void *arg) pthread_mutex_unlock(&state_mutex); // Run GPS task - #if defined(CONFIG_GPS) && !defined(MD3x0_ENABLE_DBG) - gps_task(); + #if defined(CONFIG_GPS) + gps_task(gps); #endif // Run state update task @@ -166,10 +169,6 @@ void *main_thread(void *arg) sleepUntil(time); } - #if defined(CONFIG_GPS) - gps_terminate(); - #endif - return NULL; }