From 81b272a394ac2c17fc80f9504f99386b2d46d9d2 Mon Sep 17 00:00:00 2001 From: bigmouseears Date: Mon, 25 May 2026 18:59:59 -0700 Subject: [PATCH 1/4] Added checks to discard gps data if RMC or GLL status is invalid --- gps/gps.c | 65 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 17 deletions(-) diff --git a/gps/gps.c b/gps/gps.c index db7427d..cf09f35 100644 --- a/gps/gps.c +++ b/gps/gps.c @@ -303,26 +303,57 @@ if (!strcmp(token, "$GPGGA")) } else if (!strcmp(token, "$GPRMC")) { - gps_ptr->utc_time = gps_string_to_float(GPSstrParse, &idx); - gps_ptr->rmc_status = gps_string_to_char(GPSstrParse, &idx); /* unused */ - gps_ptr->nmea_latitude = gps_string_to_float(GPSstrParse, &idx); - gps_ptr->ns = gps_string_to_char(GPSstrParse, &idx); - gps_ptr->nmea_longitude = gps_string_to_float(GPSstrParse, &idx); - gps_ptr->ew = gps_string_to_char(GPSstrParse, &idx); - gps_ptr->speed_k = gps_string_to_float(GPSstrParse, &idx); - gps_ptr->course_d = gps_string_to_float(GPSstrParse, &idx); - gps_ptr->date = (int)(0.5 + gps_string_to_float(GPSstrParse, &idx)); - gps_conv_latitude_longitude( gps_ptr ); + /* Parse data */ + float utc_time = gps_string_to_float(GPSstrParse, &idx); + char rmc_status = gps_string_to_char(GPSstrParse, &idx); + float nmea_latitude = gps_string_to_float(GPSstrParse, &idx); + char ns = gps_string_to_char(GPSstrParse, &idx); + float nmea_longitude = gps_string_to_float(GPSstrParse, &idx); + char ew = gps_string_to_char(GPSstrParse, &idx); + float speed_k = gps_string_to_float(GPSstrParse, &idx); + float course_d = gps_string_to_float(GPSstrParse, &idx); + int date = (int)(0.5 + gps_string_to_float(GPSstrParse, &idx)); + + /* Save status */ + gps_ptr->rmc_status = rmc_status; + + /* Save rest of data only if status is A: Active */ + if (rmc_status == 'A') + { + gps_ptr->utc_time = utc_time; + gps_ptr->nmea_latitude = nmea_latitude; + gps_ptr->ns = ns; + gps_ptr->nmea_longitude = nmea_longitude; + gps_ptr->ew = ew; + gps_ptr->speed_k = speed_k; + gps_ptr->course_d = course_d; + gps_ptr->date = date; + gps_conv_latitude_longitude( gps_ptr ); + } } else if (!strcmp(token, "$GPGLL")) { - gps_ptr->nmea_latitude = gps_string_to_float(GPSstrParse, &idx); - gps_ptr->ns = gps_string_to_char(GPSstrParse, &idx); - gps_ptr->nmea_longitude = gps_string_to_float(GPSstrParse, &idx); - gps_ptr->ew = gps_string_to_char(GPSstrParse, &idx); - gps_ptr->utc_time = gps_string_to_float(GPSstrParse, &idx); - gps_ptr->gll_status = gps_string_to_char(GPSstrParse, &idx); - gps_conv_latitude_longitude( gps_ptr ); + /* Parse data */ + float nmea_latitude = gps_string_to_float(GPSstrParse, &idx); + char ns = gps_string_to_char(GPSstrParse, &idx); + float nmea_longitude = gps_string_to_float(GPSstrParse, &idx); + char ew = gps_string_to_char(GPSstrParse, &idx); + float utc_time = gps_string_to_float(GPSstrParse, &idx); + char gll_status = gps_string_to_char(GPSstrParse, &idx); + + /* Store status */ + gps_ptr->gll_status = gll_status; + + /* Save rest of data only if status is A: Data Valid */ + if (gll_status == 'A') + { + gps_ptr->nmea_latitude = nmea_latitude; + gps_ptr->ns = ns; + gps_ptr->nmea_longitude = nmea_longitude; + gps_ptr->ew = ew; + gps_ptr->utc_time = utc_time; + gps_conv_latitude_longitude( gps_ptr ); + } } else if (!strcmp(token, "$GPVTG")) { From a787b67ab9f5f797e02e11a9448108ebde3f8aa5 Mon Sep 17 00:00:00 2001 From: bigmouseears Date: Tue, 2 Jun 2026 16:20:55 -0700 Subject: [PATCH 2/4] Attempt at updating unit tests --- _test/driver/gps/cases/NMEA_inputs.txt | 4 ++-- _test/driver/gps/cases/gps_parse_expected.txt | 4 +++- gps/gps.c | 21 +++++++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/_test/driver/gps/cases/NMEA_inputs.txt b/_test/driver/gps/cases/NMEA_inputs.txt index eddcf58..ea00284 100644 --- a/_test/driver/gps/cases/NMEA_inputs.txt +++ b/_test/driver/gps/cases/NMEA_inputs.txt @@ -13,5 +13,5 @@ "$GPGLL,3953.88008971,N,10506.75318910,W,034138.00,A,D*7A", "$GPGLL,5109.0262317,N,11401.8407304,W,202725.00,A,D*79", "$GPGLL,,,,,,,", - - +"$GPGLL,5109.0262317,N,11401.8407304,W,202725.00,V,D*79", +"$GPRMC,134734.000,A,5540.3233,N,01231.2941,E,1.23,107.22,041112,,,A*63", \ No newline at end of file diff --git a/_test/driver/gps/cases/gps_parse_expected.txt b/_test/driver/gps/cases/gps_parse_expected.txt index be0c2d3..b88f158 100644 --- a/_test/driver/gps/cases/gps_parse_expected.txt +++ b/_test/driver/gps/cases/gps_parse_expected.txt @@ -12,4 +12,6 @@ "0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0,0,0,0,0.000000,0.000000,0,0,0.000000,0.000000,0,0,0.000000,0,0.000000,0,0,0.000000,0", "39.898003,-105.112549,0.000000,10506.752930,3953.880127,34138.000000,N,W,0,0,0.000000,0.000000,0,0,0.000000,0.000000,0,A,0.000000,0,0.000000,0,0,0.000000,0", "51.150440,-114.030678,0.000000,11401.840820,5109.026367,202725.000000,N,W,0,0,0.000000,0.000000,0,0,0.000000,0.000000,0,A,0.000000,0,0.000000,0,0,0.000000,0", -"0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0,0,0,0,0.000000,0.000000,0,0,0.000000,0.000000,0,0,0.000000,0,0.000000,0,0,0.000000,0" \ No newline at end of file +"0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0,0,0,0,0.000000,0.000000,0,0,0.000000,0.000000,0,0,0.000000,0,0.000000,0,0,0.000000,0" +"0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0,0,0,0,0.000000,0.000000,0,0,0.000000,0.000000,0,V,0.000000,0,0.000000,0,0,0.000000,0" +"0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,N,E,0,0,0.000000,0.000000,0,V,0.000000,0.000000,0,0,0.000000,0,0.000000,0,0,0.000000,0", \ No newline at end of file diff --git a/gps/gps.c b/gps/gps.c index cf09f35..f34f091 100644 --- a/gps/gps.c +++ b/gps/gps.c @@ -330,6 +330,18 @@ else if (!strcmp(token, "$GPRMC")) gps_ptr->date = date; gps_conv_latitude_longitude( gps_ptr ); } + else + { + gps_ptr->utc_time = 0.0; + gps_ptr->nmea_latitude = 0.0; + gps_ptr->ns = 0; + gps_ptr->nmea_longitude = 0.0; + gps_ptr->ew = 0; + gps_ptr->speed_k = 0.0; + gps_ptr->course_d = 0.0; + gps_ptr->date = 0.0; + gps_conv_latitude_longitude( gps_ptr ); + } } else if (!strcmp(token, "$GPGLL")) { @@ -354,6 +366,15 @@ else if (!strcmp(token, "$GPGLL")) gps_ptr->utc_time = utc_time; gps_conv_latitude_longitude( gps_ptr ); } + else + { + gps_ptr->nmea_latitude = 0.0; + gps_ptr->ns = 0; + gps_ptr->nmea_longitude = 0.0; + gps_ptr->ew = 0; + gps_ptr->utc_time = 0.0; + gps_conv_latitude_longitude( gps_ptr ); + } } else if (!strcmp(token, "$GPVTG")) { From 42c0ea765686f73f5cfa17acc59d91937ddc103e Mon Sep 17 00:00:00 2001 From: bigmouseears Date: Tue, 2 Jun 2026 18:07:46 -0700 Subject: [PATCH 3/4] Forgot to change the num_cases initalization. Here is the commit where I do it. --- _test/driver/gps/test_gps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_test/driver/gps/test_gps.c b/_test/driver/gps/test_gps.c index 0a0f11d..eb44c3e 100644 --- a/_test/driver/gps/test_gps.c +++ b/_test/driver/gps/test_gps.c @@ -138,7 +138,7 @@ void test_GPS_parse /*------------------------------------------------------------------------------ Initializations ------------------------------------------------------------------------------*/ -int num_cases = 15; +int num_cases = 17; char buffer[200] = ""; // An NMEA message is 82 characters, but the way we parse may end up with more in order to represent the struct // Source: https://github.com/esutton/gps-nmea-log-files/blob/master/AMOD_AGL3080_20121104_134730.txt From 8f706fc3a95bc7fae0e7bde5d7b4bdb3fea653b0 Mon Sep 17 00:00:00 2001 From: bigmouseears Date: Tue, 9 Jun 2026 15:47:21 -0700 Subject: [PATCH 4/4] Attempt to fix test cases --- _test/driver/gps/cases/NMEA_inputs.txt | 6 +++--- _test/driver/gps/cases/gps_parse_expected.txt | 6 +++--- gps/gps.c | 21 ------------------- 3 files changed, 6 insertions(+), 27 deletions(-) diff --git a/_test/driver/gps/cases/NMEA_inputs.txt b/_test/driver/gps/cases/NMEA_inputs.txt index ea00284..1a80965 100644 --- a/_test/driver/gps/cases/NMEA_inputs.txt +++ b/_test/driver/gps/cases/NMEA_inputs.txt @@ -7,11 +7,11 @@ "$GPVTG,90.16,T,,M,1.75,N,3.2,K,A*31", "$GPGGA,134733.000,5540.3231,N,01231.2938,E,1,10,0.8,24.9,M,41.5,M,,0000*6D", "$GPRMC,134733.000,A,5540.3231,N,01231.2938,E,1.83,113.00,041112,,,A*67", +"$GPRMC,134733.000,V,0000.0000,N,00000.0000,E,1.83,000.00,041112,,,A*67", "$GPGGA,134734.000,5540.3233,S,01231.2941,W,1,10,0.8,23.7,M,41.5,M,,0000*6F", "$GPRMC,134734.000,A,5540.3233,N,01231.2941,E,1.23,107.22,041112,,,A*63", "$GPGSA,A,3,03,22,06,19,11,14,32,01,28,18,,,1.8,0.8,1.6*3F", "$GPGLL,3953.88008971,N,10506.75318910,W,034138.00,A,D*7A", "$GPGLL,5109.0262317,N,11401.8407304,W,202725.00,A,D*79", -"$GPGLL,,,,,,,", -"$GPGLL,5109.0262317,N,11401.8407304,W,202725.00,V,D*79", -"$GPRMC,134734.000,A,5540.3233,N,01231.2941,E,1.23,107.22,041112,,,A*63", \ No newline at end of file +"$GPGLL,0000.0000000,N,00000.0000000,W,000000.00,V,D*79", +"$GPGLL,,,,,,,", \ No newline at end of file diff --git a/_test/driver/gps/cases/gps_parse_expected.txt b/_test/driver/gps/cases/gps_parse_expected.txt index b88f158..361927c 100644 --- a/_test/driver/gps/cases/gps_parse_expected.txt +++ b/_test/driver/gps/cases/gps_parse_expected.txt @@ -7,11 +7,11 @@ "0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0,0,0,0,0.000000,0.000000,0,0,1.750000,0.000000,0,0,90.160004,T,0.000000,M,N,3.200000,K", "55.672054,12.521564,0.000000,1231.293823,5540.323242,134733.000000,N,E,1,10,0.800000,24.900000,M,0,0.000000,0.000000,0,0,0.000000,0,0.000000,0,0,0.000000,0", "55.672054,12.521564,0.000000,1231.293823,5540.323242,134733.000000,N,E,0,0,0.000000,0.000000,0,A,1.830000,113.000000,41112,0,0.000000,0,0.000000,0,0,0.000000,0", +"55.672054,12.521564,0.000000,1231.293823,5540.323242,134733.000000,N,E,0,0,0.000000,0.000000,0,V,1.830000,113.000000,41112,0,0.000000,0,0.000000,0,0,0.000000,0", "-55.672054,-12.521567,0.000000,1231.294067,5540.323242,134734.000000,S,W,1,10,0.800000,23.700001,M,0,0.000000,0.000000,0,0,0.000000,0,0.000000,0,0,0.000000,0", "55.672054,12.521567,0.000000,1231.294067,5540.323242,134734.000000,N,E,0,0,0.000000,0.000000,0,A,1.230000,107.220001,41112,0,0.000000,0,0.000000,0,0,0.000000,0", "0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0,0,0,0,0.000000,0.000000,0,0,0.000000,0.000000,0,0,0.000000,0,0.000000,0,0,0.000000,0", "39.898003,-105.112549,0.000000,10506.752930,3953.880127,34138.000000,N,W,0,0,0.000000,0.000000,0,0,0.000000,0.000000,0,A,0.000000,0,0.000000,0,0,0.000000,0", "51.150440,-114.030678,0.000000,11401.840820,5109.026367,202725.000000,N,W,0,0,0.000000,0.000000,0,0,0.000000,0.000000,0,A,0.000000,0,0.000000,0,0,0.000000,0", -"0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0,0,0,0,0.000000,0.000000,0,0,0.000000,0.000000,0,0,0.000000,0,0.000000,0,0,0.000000,0" -"0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0,0,0,0,0.000000,0.000000,0,0,0.000000,0.000000,0,V,0.000000,0,0.000000,0,0,0.000000,0" -"0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,N,E,0,0,0.000000,0.000000,0,V,0.000000,0.000000,0,0,0.000000,0,0.000000,0,0,0.000000,0", \ No newline at end of file +"51.150440,-114.030678,0.000000,11401.840820,5109.026367,202725.000000,N,W,0,0,0.000000,0.000000,0,0,0.000000,0.000000,0,V,0.000000,0,0.000000,0,0,0.000000,0", +"0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0,0,0,0,0.000000,0.000000,0,0,0.000000,0.000000,0,0,0.000000,0,0.000000,0,0,0.000000,0" \ No newline at end of file diff --git a/gps/gps.c b/gps/gps.c index f34f091..cf09f35 100644 --- a/gps/gps.c +++ b/gps/gps.c @@ -330,18 +330,6 @@ else if (!strcmp(token, "$GPRMC")) gps_ptr->date = date; gps_conv_latitude_longitude( gps_ptr ); } - else - { - gps_ptr->utc_time = 0.0; - gps_ptr->nmea_latitude = 0.0; - gps_ptr->ns = 0; - gps_ptr->nmea_longitude = 0.0; - gps_ptr->ew = 0; - gps_ptr->speed_k = 0.0; - gps_ptr->course_d = 0.0; - gps_ptr->date = 0.0; - gps_conv_latitude_longitude( gps_ptr ); - } } else if (!strcmp(token, "$GPGLL")) { @@ -366,15 +354,6 @@ else if (!strcmp(token, "$GPGLL")) gps_ptr->utc_time = utc_time; gps_conv_latitude_longitude( gps_ptr ); } - else - { - gps_ptr->nmea_latitude = 0.0; - gps_ptr->ns = 0; - gps_ptr->nmea_longitude = 0.0; - gps_ptr->ew = 0; - gps_ptr->utc_time = 0.0; - gps_conv_latitude_longitude( gps_ptr ); - } } else if (!strcmp(token, "$GPVTG")) {