From a370e981d8d367d3cefab088e1ad0afacbf2d6b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Marsza=C5=82kiewicz?= Date: Fri, 16 Jun 2017 12:54:17 +0200 Subject: [PATCH 1/2] Add $--ZDA sentences * Expand LDLIBS var in Makefile * Add parser zda * Extend sentence_id * Add example --- example.c | 18 ++++++++++++++++++ minmea.c | 28 ++++++++++++++++++++++++++++ minmea.h | 9 +++++++++ 3 files changed, 55 insertions(+) diff --git a/example.c b/example.c index 665b18f..e91451d 100644 --- a/example.c +++ b/example.c @@ -107,6 +107,24 @@ int main(void) } } break; + case MINMEA_SENTENCE_ZDA: { + struct minmea_sentence_zda frame; + if (minmea_parse_zda(&frame, line)) { + printf(INDENT_SPACES "$xxZDA: %d:%d:%d %02d.%02d.%d UTC%+03d:%02d\n", + frame.time.hours, + frame.time.minutes, + frame.time.seconds, + frame.date.day, + frame.date.month, + frame.date.year, + frame.hour_offset, + frame.minute_offset); + } + else { + printf(INDENT_SPACES "$xxZDA sentence is not parsed\n"); + } + } break; + case MINMEA_INVALID: { printf(INDENT_SPACES "$xxxxx sentence is not valid\n"); } break; diff --git a/minmea.c b/minmea.c index e5633c6..9e23933 100644 --- a/minmea.c +++ b/minmea.c @@ -372,6 +372,8 @@ enum minmea_sentence_id minmea_sentence_id(const char *sentence, bool strict) return MINMEA_SENTENCE_GSV; if (!strcmp(type+2, "VTG")) return MINMEA_SENTENCE_VTG; + if (!strcmp(type+2, "ZDA")) + return MINMEA_SENTENCE_ZDA; return MINMEA_UNKNOWN; } @@ -584,6 +586,32 @@ bool minmea_parse_vtg(struct minmea_sentence_vtg *frame, const char *sentence) return true; } +bool minmea_parse_zda(struct minmea_sentence_zda *frame, const char *sentence) +{ + // $GPZDA,201530.00,04,07,2002,00,00*60 + char type[6]; + + if(!minmea_scan(sentence, "tTiiiii", + type, + &frame->time, + &frame->date.day, + &frame->date.month, + &frame->date.year, + &frame->hour_offset, + &frame->minute_offset)) + return false; + if (strcmp(type+2, "ZDA")) + return false; + + // check offsets + if (abs(frame->hour_offset) > 13 || + frame->minute_offset > 59 || + frame->minute_offset < 0) + return false; + + return true; +} + int minmea_gettime(struct timespec *ts, const struct minmea_date *date, const struct minmea_time *time_) { if (date->year == -1 || time_->hours == -1) diff --git a/minmea.h b/minmea.h index acbf182..10351f6 100644 --- a/minmea.h +++ b/minmea.h @@ -32,6 +32,7 @@ enum minmea_sentence_id { MINMEA_SENTENCE_GST, MINMEA_SENTENCE_GSV, MINMEA_SENTENCE_VTG, + MINMEA_SENTENCE_ZDA, }; struct minmea_float { @@ -152,6 +153,13 @@ struct minmea_sentence_vtg { enum minmea_faa_mode faa_mode; }; +struct minmea_sentence_zda { + struct minmea_time time; + struct minmea_date date; + int hour_offset; + int minute_offset; +}; + /** * Calculate raw sentence checksum. Does not check sentence integrity. */ @@ -195,6 +203,7 @@ bool minmea_parse_gll(struct minmea_sentence_gll *frame, const char *sentence); bool minmea_parse_gst(struct minmea_sentence_gst *frame, const char *sentence); bool minmea_parse_gsv(struct minmea_sentence_gsv *frame, const char *sentence); bool minmea_parse_vtg(struct minmea_sentence_vtg *frame, const char *sentence); +bool minmea_parse_zda(struct minmea_sentence_zda *frame, const char *sentence); /** * Convert GPS UTC date/time representation to a UNIX timestamp. From f1871e40b9da1f9e2795dafb8fe893def454de1c Mon Sep 17 00:00:00 2001 From: Kosma Moczek Date: Tue, 15 Aug 2017 10:32:40 +0200 Subject: [PATCH 2/2] add unit tests for ZDA --- tests.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests.c b/tests.c index f42baa1..27e6e6e 100644 --- a/tests.c +++ b/tests.c @@ -39,6 +39,7 @@ static const char *valid_sentences_checksum[] = { "$GPRMC,123205.00,A,5106.94085,N,01701.51689,E,0.016,,280214,,,A*7B", "$GPVTG,,T,,M,0.016,N,0.030,K,A*27", "$GPGST,024603.00,3.2,6.6,4.7,47.3,5.8,5.6,22.0*58", + "$GPZDA,160012.71,11,03,2004,-1,00*7D", NULL, }; @@ -864,6 +865,26 @@ START_TEST(test_minmea_parse_vtg2) } END_TEST +START_TEST(test_minmea_parse_zda1) +{ + const char *sentence = "$GPZDA,160012.71,11,03,2004,-1,00*7D"; + struct minmea_sentence_zda frame = {}; + struct minmea_sentence_zda expected = {}; + + expected = (struct minmea_sentence_zda) { + .time = { 16, 0, 12, 710000 }, + .date = { 11, 3, 2004 }, + .hour_offset = -1, + .minute_offset = 0, + }; + + ck_assert(minmea_check(sentence, false) == true); + ck_assert(minmea_check(sentence, true) == true); + ck_assert(minmea_parse_zda(&frame, sentence) == true); + ck_assert(!memcmp(&frame, &expected, sizeof(frame))); +} +END_TEST + START_TEST(test_minmea_usage1) { const char *sentences[] = { @@ -1020,6 +1041,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_zda1); suite_add_tcase(s, tc_parse); TCase *tc_usage = tcase_create("minmea_usage");