From 2f0b7f8df73536a8dd2e4678fee61a73b8a1506d Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Thu, 21 Aug 2025 16:56:18 +0200 Subject: [PATCH] core: gps: added field for HDOP to GPS data HDOP is expressed in cm, meaning that an HDOP of 1.37m is stored as 137 in the GPS data structure. --- lib/minmea/include/minmea.h | 14 ++++++++++++++ openrtx/include/core/gps.h | 1 + openrtx/src/core/gps.c | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/minmea/include/minmea.h b/lib/minmea/include/minmea.h index da9aa54c..74f01b91 100644 --- a/lib/minmea/include/minmea.h +++ b/lib/minmea/include/minmea.h @@ -271,6 +271,20 @@ static inline int minmea_toint(struct minmea_float *f) return f->value / f->scale; } +/** + * Convert a fixed-point value to an integer value, applying an additional + * scaling factor. + * Returns zero for "unknown" values. + */ +static inline int minmea_toscaledint(struct minmea_float *f, const int scale) +{ + if(f->scale == 0) + return 0; + + int_least32_t tmp = f->value * scale; + return tmp / f->scale; +} + #ifdef __cplusplus } #endif diff --git a/openrtx/include/core/gps.h b/openrtx/include/core/gps.h index dc9d2f98..af028ad1 100644 --- a/openrtx/include/core/gps.h +++ b/openrtx/include/core/gps.h @@ -54,6 +54,7 @@ typedef struct uint16_t speed; // Ground speed in km/h int16_t tmg_mag; // Course over ground, degrees, magnetic int16_t tmg_true; // Course over ground, degrees, true + uint16_t hdop; // Horizontal dilution of precision, in cm } gps_t; diff --git a/openrtx/src/core/gps.c b/openrtx/src/core/gps.c index cd822045..8221049c 100644 --- a/openrtx/src/core/gps.c +++ b/openrtx/src/core/gps.c @@ -87,7 +87,6 @@ void gps_task(const struct gpsDevice *dev) gps_data.timestamp.year = frame.date.year; } - gps_data.tmg_true = minmea_tofloat(&frame.course); gps_data.speed = KNOTS2KMH(minmea_toint(&frame.speed)); } break; @@ -110,6 +109,7 @@ void gps_task(const struct gpsDevice *dev) struct minmea_sentence_gsa frame; if (minmea_parse_gsa(&frame, sentence)) { + gps_data.hdop = minmea_toscaledint(&frame.hdop, 100); gps_data.fix_type = frame.fix_type; for (int i = 0; i < 12; i++) {