From ea1bbcbfa5f8dc3562c1d16a6755d5d87b0949f1 Mon Sep 17 00:00:00 2001 From: Kosma Moczek Date: Mon, 24 Mar 2014 23:13:05 +0100 Subject: [PATCH] minmea: add minmea_talker_id() --- minmea.c | 13 +++++++++++++ minmea.h | 5 +++++ tests.c | 7 ++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/minmea.c b/minmea.c index 1530be6..8bbbc59 100644 --- a/minmea.c +++ b/minmea.c @@ -259,6 +259,19 @@ end: return result; } +bool minmea_talker_id(char talker[3], const char *sentence) +{ + char type[6]; + if (!minmea_scan(sentence, "t", type)) + return false; + + talker[0] = type[0]; + talker[1] = type[1]; + talker[2] = '\0'; + + return true; +} + enum minmea_sentence_id minmea_sentence_id(const char *sentence) { if (!minmea_check(sentence)) diff --git a/minmea.h b/minmea.h index df3edf0..1caa0b3 100644 --- a/minmea.h +++ b/minmea.h @@ -92,6 +92,11 @@ struct minmea_sentence_gsa { */ bool minmea_check(const char *sentence); +/** + * Determine talker identifier. + */ +bool minmea_talker_id(char talker[3], const char *sentence); + /** * Determine sentence identifier. */ diff --git a/tests.c b/tests.c index 4d52ed4..c45bde3 100644 --- a/tests.c +++ b/tests.c @@ -382,7 +382,7 @@ START_TEST(test_minmea_usage1) const char *sentences[] = { "$GPRMC,081836,A,3751.65,S,14507.36,E,000.0,360.0,130998,011.3,E*62", "$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47", - "$GPGSA,A,3,04,05,,09,12,,,24,,,,,2.5,1.3,2.1*39", + "$GNGSA,A,3,04,05,,09,12,,,24,,,,,2.5,1.3,2.1", NULL, }; @@ -407,6 +407,11 @@ START_TEST(test_minmea_usage1) default: { } break; } + + char talker[3]; + char expected[3] = { (*sentence)[1], (*sentence)[2], '\0' }; + ck_assert(minmea_talker_id(talker, *sentence) == true); + ck_assert_str_eq(talker, expected); } } END_TEST