From c273d92a3318c2043e4bfcef85900e15f0a65a1d Mon Sep 17 00:00:00 2001 From: mek_x Date: Wed, 23 Apr 2014 23:43:28 +0200 Subject: [PATCH 1/5] minmea: added minmea_parse_gsv --- minmea.c | 37 +++++++++++++++++++++++++++++++++++++ minmea.h | 16 ++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/minmea.c b/minmea.c index 8bbbc59..231062d 100644 --- a/minmea.c +++ b/minmea.c @@ -287,6 +287,8 @@ enum minmea_sentence_id minmea_sentence_id(const char *sentence) return MINMEA_SENTENCE_GGA; if (!strcmp(type+2, "GSA")) return MINMEA_SENTENCE_GSA; + if (!strcmp(type+2, "GSV")) + return MINMEA_SENTENCE_GSV; return MINMEA_UNKNOWN; } @@ -385,6 +387,41 @@ bool minmea_parse_gsa(struct minmea_sentence_gsa *frame, const char *sentence) return true; } +bool minmea_parse_gsv(struct minmea_sentence_gsv *frame, const char *sentence) +{ + // $GPGSV,3,1,11,03,03,111,00,04,15,270,00,06,01,010,00,13,06,292,00*74 + char type[6]; + + if (!minmea_scan(sentence, "tiiiiiiiiiiiiiiiiiii", + type, + &frame->total_msgs, + &frame->msg_nr, + &frame->total_sats, + &frame->sats[0].nr, + &frame->sats[0].elevation, + &frame->sats[0].azimuth, + &frame->sats[0].snr, + &frame->sats[1].nr, + &frame->sats[1].elevation, + &frame->sats[1].azimuth, + &frame->sats[1].snr, + &frame->sats[2].nr, + &frame->sats[2].elevation, + &frame->sats[2].azimuth, + &frame->sats[2].snr, + &frame->sats[3].nr, + &frame->sats[3].elevation, + &frame->sats[3].azimuth, + &frame->sats[3].snr + )) { + return false; + } + if (strcmp(type+2, "GSV")) + return false; + + return true; +} + int minmea_gettimeofday(struct timeval *tv, 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 8fab9c0..0ca4f40 100644 --- a/minmea.h +++ b/minmea.h @@ -31,6 +31,7 @@ enum minmea_sentence_id { MINMEA_SENTENCE_RMC, MINMEA_SENTENCE_GGA, MINMEA_SENTENCE_GSA, + MINMEA_SENTENCE_GSV }; struct minmea_date { @@ -89,6 +90,20 @@ struct minmea_sentence_gsa { int vdop, vdop_scale; }; +struct minmea_sat_info { + int nr; + int elevation; + int azimuth; + int snr; +}; + +struct minmea_sentence_gsv { + int total_msgs; + int msg_nr; + int total_sats; + struct minmea_sat_info sats[4]; +}; + /** * Check sentence validity and checksum. Returns true for valid sentences. */ @@ -123,6 +138,7 @@ bool minmea_scan(const char *sentence, const char *format, ...); bool minmea_parse_rmc(struct minmea_sentence_rmc *frame, const char *sentence); bool minmea_parse_gga(struct minmea_sentence_gga *frame, const char *sentence); bool minmea_parse_gsa(struct minmea_sentence_gsa *frame, const char *sentence); +bool minmea_parse_gsv(struct minmea_sentence_gsv *frame, const char *sentence); /** * Convert GPS UTC date/time representation to a UNIX timestamp. From 6aee1b8bb70049c6e25fe7745e83598e1a397dcd Mon Sep 17 00:00:00 2001 From: mek_x Date: Wed, 23 Apr 2014 23:43:58 +0200 Subject: [PATCH 2/5] example.c: added example for gsv parsing --- example.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/example.c b/example.c index e973814..5a6f48e 100644 --- a/example.c +++ b/example.c @@ -43,6 +43,20 @@ int main() } } break; + case MINMEA_SENTENCE_GSV: { + struct minmea_sentence_gsv frame; + if (minmea_parse_gsv(&frame, line)) { + printf("$GPGSV: message %d of %d\n", frame.msg_nr, frame.total_msgs); + printf("$GPGSV: sattelites in view: %d\n", frame.total_sats); + for (int i = 0; i < 4; i++) + printf("$GPGSV: sat nr %d, elevation: %d, azimuth: %d, snr: %d dbm\n", + frame.sats[i].nr, + frame.sats[i].elevation, + frame.sats[i].azimuth, + frame.sats[i].snr); + } + } break; + default: { } break; } From daed9fd7079ab4786c9730b62b92553e2c4f4abf Mon Sep 17 00:00:00 2001 From: mek_x Date: Wed, 23 Apr 2014 23:55:02 +0200 Subject: [PATCH 3/5] tests: added unit tests for gsv --- tests.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests.c b/tests.c index 0159fc1..4becf22 100644 --- a/tests.c +++ b/tests.c @@ -379,6 +379,47 @@ START_TEST(test_minmea_parse_gsa1) } END_TEST +START_TEST(test_minmea_parse_gsv1) +{ + const char *sentence = "$GPGSV,3,3,11,22,42,067,42,24,14,311,43,27,05,244,00,,,,*4D"; + struct minmea_sentence_gsv frame = {}; + static const struct minmea_sentence_gsv expected = { + .total_msgs = 3, + .msg_nr = 3, + .total_sats = 11, + .sats = { + { + .nr = 22, + .elevation = 42, + .azimuth = 67, + .snr = 42 + }, + { + .nr = 24, + .elevation = 14, + .azimuth = 311, + .snr = 43 + }, + { + .nr = 27, + .elevation = 5, + .azimuth = 244, + .snr = 0 + }, + { + .nr = 0, + .elevation = 0, + .azimuth = 0, + .snr = 0 + } + } + }; + ck_assert(minmea_check(sentence) == true); + ck_assert(minmea_parse_gsv(&frame, sentence) == true); + ck_assert(!memcmp(&frame, &expected, sizeof(frame))); +} +END_TEST + START_TEST(test_minmea_usage1) { const char *sentences[] = { @@ -497,6 +538,7 @@ Suite *minmea_suite(void) tcase_add_test(tc_parse, test_minmea_parse_rmc2); tcase_add_test(tc_parse, test_minmea_parse_gga1); tcase_add_test(tc_parse, test_minmea_parse_gsa1); + tcase_add_test(tc_parse, test_minmea_parse_gsv1); suite_add_tcase(s, tc_parse); TCase *tc_usage = tcase_create("minmea_usage"); From 32f6397c0592cb155e60c0d3b1e9d84c65b4eb6f Mon Sep 17 00:00:00 2001 From: mek_x Date: Thu, 24 Apr 2014 00:03:08 +0200 Subject: [PATCH 4/5] README.md: added info about GSV --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 8d788b0..c1d3271 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ systems. * ``RMC`` (Recommended Minimum: position, velocity, time) * ``GGA`` (Fix Data) * ``GSA`` (DOP and active satellites) +* ``GSV`` (Satellites in view) Adding support for more sentences is trivial; see ``minmea.c`` source. @@ -78,6 +79,20 @@ The library doesn't perform this conversion automatically for the following reas printf("$GPGGA: fix quality: %d\n", frame.fix_quality); } } break; + + case MINMEA_SENTENCE_GSV: { + struct minmea_sentence_gsv frame; + if (minmea_parse_gsv(&frame, line)) { + printf("$GPGSV: message %d of %d\n", frame.msg_nr, frame.total_msgs); + printf("$GPGSV: sattelites in view: %d\n", frame.total_sats); + for (int i = 0; i < 4; i++) + printf("$GPGSV: sat nr %d, elevation: %d, azimuth: %d, snr: %d dbm\n", + frame.sats[i].nr, + frame.sats[i].elevation, + frame.sats[i].azimuth, + frame.sats[i].snr); + } + } break; } } ``` From e4ce3245813aa73c0d47fa3f801f4b1018dabe95 Mon Sep 17 00:00:00 2001 From: mek-x Date: Thu, 24 Apr 2014 15:44:49 +0200 Subject: [PATCH 5/5] minmea.h: style fix --- minmea.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/minmea.h b/minmea.h index 0ca4f40..811a92c 100644 --- a/minmea.h +++ b/minmea.h @@ -31,7 +31,7 @@ enum minmea_sentence_id { MINMEA_SENTENCE_RMC, MINMEA_SENTENCE_GGA, MINMEA_SENTENCE_GSA, - MINMEA_SENTENCE_GSV + MINMEA_SENTENCE_GSV, }; struct minmea_date {