From a0da280f6451c4ed20b711edb84dc3d258823e20 Mon Sep 17 00:00:00 2001 From: Kosma Moczek Date: Fri, 3 Jun 2022 01:40:30 +0200 Subject: [PATCH] add test_minmea_parse_vtg3 (fixes #57) --- minmea.c | 17 ++++++++++------- tests.c | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/minmea.c b/minmea.c index 89ef76b..e9361cc 100644 --- a/minmea.c +++ b/minmea.c @@ -594,7 +594,7 @@ bool minmea_parse_vtg(struct minmea_sentence_vtg *frame, const char *sentence) char type[6]; char c_true, c_magnetic, c_knots, c_kph, c_faa_mode; - if (!minmea_scan(sentence, "tfcfcfcfc;c", + if (!minmea_scan(sentence, "t;fcfcfcfcc", type, &frame->true_track_degrees, &c_true, @@ -608,12 +608,15 @@ bool minmea_parse_vtg(struct minmea_sentence_vtg *frame, const char *sentence) return false; if (strcmp(type+2, "VTG")) return false; - // check chars - if (c_true != 'T' || - c_magnetic != 'M' || - c_knots != 'N' || - c_kph != 'K') - return false; + // values are only valid with the accompanying characters + if (c_true != 'T') + frame->true_track_degrees.scale = 0; + if (c_magnetic != 'M') + frame->magnetic_track_degrees.scale = 0; + if (c_knots != 'N') + frame->speed_knots.scale = 0; + if (c_kph != 'K') + frame->speed_kph.scale = 0; frame->faa_mode = (enum minmea_faa_mode)c_faa_mode; return true; diff --git a/tests.c b/tests.c index 1a63380..90a935e 100644 --- a/tests.c +++ b/tests.c @@ -895,6 +895,27 @@ START_TEST(test_minmea_parse_vtg2) } END_TEST +START_TEST(test_minmea_parse_vtg3) +{ + // https://github.com/kosma/minmea/issues/57 + const char *sentence = "$GNVTG,,,,,,,,,N*2E"; + // clear structs before initialization to enable use of memcmp() + struct minmea_sentence_vtg frame = {}; + struct minmea_sentence_vtg expected = {}; + expected = (struct minmea_sentence_vtg){ + .true_track_degrees = { 0, 0 }, + .magnetic_track_degrees = { 0, 0 }, + .speed_knots = { 0, 0 }, + .speed_kph = { 0, 0 }, + .faa_mode = MINMEA_FAA_MODE_NOT_VALID, + }; + ck_assert(minmea_check(sentence, false) == true); + ck_assert(minmea_check(sentence, true) == true); + ck_assert(minmea_parse_vtg(&frame, sentence) == true); + ck_assert(!memcmp(&frame, &expected, sizeof(frame))); +} +END_TEST + START_TEST(test_minmea_parse_zda1) { const char *sentence = "$GPZDA,160012.71,11,03,2004,-1,00*7D"; @@ -1133,6 +1154,7 @@ static Suite *minmea_suite(void) tcase_add_test(tc_parse, test_minmea_parse_gsv5); tcase_add_test(tc_parse, test_minmea_parse_vtg1); tcase_add_test(tc_parse, test_minmea_parse_vtg2); + tcase_add_test(tc_parse, test_minmea_parse_vtg3); tcase_add_test(tc_parse, test_minmea_parse_zda1); suite_add_tcase(s, tc_parse);