From 12b03ebc6171155e4c06e77ad902b5dcaebc3914 Mon Sep 17 00:00:00 2001 From: Eketh Date: Sun, 20 Apr 2014 10:27:22 +0200 Subject: [PATCH 1/7] Added support for GST frame --- minmea.c | 25 +++++++++++++++++++++++++ minmea.h | 13 +++++++++++++ 2 files changed, 38 insertions(+) diff --git a/minmea.c b/minmea.c index 8bbbc59..459c6ad 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,"GST")) + return MINMEA_SENTENCE_GST; return MINMEA_UNKNOWN; } @@ -385,6 +387,29 @@ bool minmea_parse_gsa(struct minmea_sentence_gsa *frame, const char *sentence) return true; } +bool minmea_parse_gst(struct minmea_sentence_gst *frame, const char *sentence) +{ + // $GPGST,024603.00,3.2,6.6,4.7,47.3,5.8,5.6,22.0*58 + char type[6]; + + if (!minmea_scan(sentence, "tTfffffff", + type, + &frame->time, + &frame->RMS_deviation,&frame->RMS_deviation_scale, + &frame->semi_major_sd,&frame->semi_major_sd_scale, + &frame->semi_minor_sd,&frame->semi_minor_sd_scale, + &frame->semi_major_orientation,&frame->semi_major_orientation_scale, + &frame->lattitude_error_deviation,&frame->lattitude_error_deviation_scale, + &frame->longitude_error_deviation,&frame->longitude_error_deviation_scale, + &frame->altitude_error_deviation,&frame->altitude_error_deviation_scale)) + return false; + if (strcmp(type+2, "GST")) + 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 1caa0b3..0e25ec6 100644 --- a/minmea.h +++ b/minmea.h @@ -29,6 +29,7 @@ enum minmea_sentence_id { MINMEA_SENTENCE_RMC, MINMEA_SENTENCE_GGA, MINMEA_SENTENCE_GSA, + MINMEA_SENTENCE_GST }; struct minmea_date { @@ -67,6 +68,17 @@ struct minmea_sentence_gga { int dgps_age; }; +struct minmea_sentence_gst { +struct minmea_time time; +int RMS_deviation, RMS_deviation_scale; +int semi_major_sd, semi_major_sd_scale; +int semi_minor_sd, semi_minor_sd_scale; +int semi_major_orientation, semi_major_orientation_scale; +int lattitude_error_deviation, lattitude_error_deviation_scale; +int longitude_error_deviation, longitude_error_deviation_scale; +int altitude_error_deviation, altitude_error_deviation_scale; +}; + enum minmea_gsa_mode { MINMEA_GPGSA_MODE_AUTO = 'A', MINMEA_GPGSA_MODE_FORCED = 'M', @@ -121,6 +133,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_gst(struct minmea_sentence_gst *frame, const char *sentence); /** * Convert GPS UTC date/time representation to a UNIX timestamp. From ae6195af1eeabd96d952284d9ab1de1b46aa72b6 Mon Sep 17 00:00:00 2001 From: Eketh Date: Sun, 20 Apr 2014 19:21:05 +0200 Subject: [PATCH 2/7] Removed tabulatures from minmea.c and minmea.h --- minmea.c | 6 +++--- minmea.h | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/minmea.c b/minmea.c index 459c6ad..9cb585f 100644 --- a/minmea.c +++ b/minmea.c @@ -287,8 +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,"GST")) - return MINMEA_SENTENCE_GST; + if (!strcmp(type+2,"GST")) + return MINMEA_SENTENCE_GST; return MINMEA_UNKNOWN; } @@ -396,7 +396,7 @@ bool minmea_parse_gst(struct minmea_sentence_gst *frame, const char *sentence) type, &frame->time, &frame->RMS_deviation,&frame->RMS_deviation_scale, - &frame->semi_major_sd,&frame->semi_major_sd_scale, + &frame->semi_major_sd,&frame->semi_major_sd_scale, &frame->semi_minor_sd,&frame->semi_minor_sd_scale, &frame->semi_major_orientation,&frame->semi_major_orientation_scale, &frame->lattitude_error_deviation,&frame->lattitude_error_deviation_scale, diff --git a/minmea.h b/minmea.h index 0e25ec6..65c6e9f 100644 --- a/minmea.h +++ b/minmea.h @@ -29,7 +29,7 @@ enum minmea_sentence_id { MINMEA_SENTENCE_RMC, MINMEA_SENTENCE_GGA, MINMEA_SENTENCE_GSA, - MINMEA_SENTENCE_GST + MINMEA_SENTENCE_GST }; struct minmea_date { @@ -69,14 +69,14 @@ struct minmea_sentence_gga { }; struct minmea_sentence_gst { -struct minmea_time time; -int RMS_deviation, RMS_deviation_scale; -int semi_major_sd, semi_major_sd_scale; -int semi_minor_sd, semi_minor_sd_scale; -int semi_major_orientation, semi_major_orientation_scale; -int lattitude_error_deviation, lattitude_error_deviation_scale; -int longitude_error_deviation, longitude_error_deviation_scale; -int altitude_error_deviation, altitude_error_deviation_scale; + struct minmea_time time; + int RMS_deviation, RMS_deviation_scale; + int semi_major_sd, semi_major_sd_scale; + int semi_minor_sd, semi_minor_sd_scale; + int semi_major_orientation, semi_major_orientation_scale; + int lattitude_error_deviation, lattitude_error_deviation_scale; + int longitude_error_deviation, longitude_error_deviation_scale; + int altitude_error_deviation, altitude_error_deviation_scale; }; enum minmea_gsa_mode { From 8a356438709fbc3b8d4609d9a26857bc1c636bab Mon Sep 17 00:00:00 2001 From: Eketh Date: Mon, 21 Apr 2014 10:35:22 +0200 Subject: [PATCH 3/7] Added support of GST frames in example.c --- example.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/example.c b/example.c index e973814..5ae6036 100644 --- a/example.c +++ b/example.c @@ -42,7 +42,24 @@ int main() printf("$GPGGA: fix quality: %d\n", frame.fix_quality); } } break; - + case MINMEA_SENTENCE_GST: { + struct minmea_sentence_gst frame; + if (minmea_parse_gst(&frame, line)) { + printf("+++ raw lattitude,longitude and altitude error deviation: (%d/%d,%d/%d,%d/d)\n", + frame.lattitude_error_deviation, frame.lattitude_error_deviation_scale, + frame.longitude_error_deviation, frame.longitude_error_deviation_scale, + frame.altitude_error_deviation, frame.altitude_error_deviation_scale); + printf("+++ fixed point lattitude,longitude and altitude error deviation \ + scaled to three decimal places: (%d,%d,%d)\n", + minmea_rescale(frame.lattitude_error_deviation, frame.lattitude_error_deviation_scale,1000), + minmea_rescale(frame.longitude_error_deviation, frame.longitude_error_deviation_scale,1000), + minmea_rescale(frame.altitude_error_deviation, frame.altitude_error_deviation_scale,1000)); + printf("+++ floating point degree lattitude,longitude and altitude error deviation: (%f,%f,%f)", + minmea_coord(frame.lattitude_error_deviation, frame.lattitude_error_deviation_scale), + minmea_coord(frame.longitude_error_deviation, frame.longitude_error_deviation_scale), + minmea_coord(frame.altitude_error_deviation, frame.altitude_error_deviation_scale)); + } + } break; default: { } break; } From d6a02269d41d525ef553bc6ced85cdae632615ca Mon Sep 17 00:00:00 2001 From: Eketh Date: Wed, 23 Apr 2014 13:23:24 +0200 Subject: [PATCH 4/7] Names unification for GPGST --- minmea.c | 6 +++--- minmea.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/minmea.c b/minmea.c index 9cb585f..5ec6452 100644 --- a/minmea.c +++ b/minmea.c @@ -395,9 +395,9 @@ bool minmea_parse_gst(struct minmea_sentence_gst *frame, const char *sentence) if (!minmea_scan(sentence, "tTfffffff", type, &frame->time, - &frame->RMS_deviation,&frame->RMS_deviation_scale, - &frame->semi_major_sd,&frame->semi_major_sd_scale, - &frame->semi_minor_sd,&frame->semi_minor_sd_scale, + &frame->rms_deviation,&frame->rms_deviation_scale, + &frame->semi_major_deviation,&frame->semi_major_deviation_scale, + &frame->semi_minor_deviation,&frame->semi_minor_deviation_scale, &frame->semi_major_orientation,&frame->semi_major_orientation_scale, &frame->lattitude_error_deviation,&frame->lattitude_error_deviation_scale, &frame->longitude_error_deviation,&frame->longitude_error_deviation_scale, diff --git a/minmea.h b/minmea.h index 65c6e9f..5f84857 100644 --- a/minmea.h +++ b/minmea.h @@ -70,9 +70,9 @@ struct minmea_sentence_gga { struct minmea_sentence_gst { struct minmea_time time; - int RMS_deviation, RMS_deviation_scale; - int semi_major_sd, semi_major_sd_scale; - int semi_minor_sd, semi_minor_sd_scale; + int rms_deviation, rms_deviation_scale; + int semi_major_deviation, semi_major_deviation_scale; + int semi_minor_deviation, semi_minor_deviation_scale; int semi_major_orientation, semi_major_orientation_scale; int lattitude_error_deviation, lattitude_error_deviation_scale; int longitude_error_deviation, longitude_error_deviation_scale; From 24968cb3bac466d2c9369aec566acc518427c160 Mon Sep 17 00:00:00 2001 From: Eketh Date: Wed, 23 Apr 2014 19:57:30 +0200 Subject: [PATCH 5/7] Fixed spelling/codestyle --- example.c | 18 ++++++------ minmea.c | 16 +++++------ minmea.h | 4 +-- tests.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 100 insertions(+), 23 deletions(-) diff --git a/example.c b/example.c index 5ae6036..8842328 100644 --- a/example.c +++ b/example.c @@ -45,17 +45,17 @@ int main() case MINMEA_SENTENCE_GST: { struct minmea_sentence_gst frame; if (minmea_parse_gst(&frame, line)) { - printf("+++ raw lattitude,longitude and altitude error deviation: (%d/%d,%d/%d,%d/d)\n", - frame.lattitude_error_deviation, frame.lattitude_error_deviation_scale, + printf("+++ raw latitude,longitude and altitude error deviation: (%d/%d,%d/%d,%d/d)\n", + frame.latitude_error_deviation, frame.latitude_error_deviation_scale, frame.longitude_error_deviation, frame.longitude_error_deviation_scale, frame.altitude_error_deviation, frame.altitude_error_deviation_scale); - printf("+++ fixed point lattitude,longitude and altitude error deviation \ - scaled to three decimal places: (%d,%d,%d)\n", - minmea_rescale(frame.lattitude_error_deviation, frame.lattitude_error_deviation_scale,1000), - minmea_rescale(frame.longitude_error_deviation, frame.longitude_error_deviation_scale,1000), - minmea_rescale(frame.altitude_error_deviation, frame.altitude_error_deviation_scale,1000)); - printf("+++ floating point degree lattitude,longitude and altitude error deviation: (%f,%f,%f)", - minmea_coord(frame.lattitude_error_deviation, frame.lattitude_error_deviation_scale), + printf("+++ fixed point latitude,longitude and altitude error deviation \ + scaled to one decimal place: (%d,%d,%d)\n", + minmea_rescale(frame.latitude_error_deviation, frame.latitude_error_deviation_scale,10), + minmea_rescale(frame.longitude_error_deviation, frame.longitude_error_deviation_scale,10), + minmea_rescale(frame.altitude_error_deviation, frame.altitude_error_deviation_scale,10)); + printf("+++ floating point degree latitude,longitude and altitude error deviation: (%f,%f,%f)", + minmea_coord(frame.latitude_error_deviation, frame.latitude_error_deviation_scale), minmea_coord(frame.longitude_error_deviation, frame.longitude_error_deviation_scale), minmea_coord(frame.altitude_error_deviation, frame.altitude_error_deviation_scale)); } diff --git a/minmea.c b/minmea.c index 5ec6452..84be55e 100644 --- a/minmea.c +++ b/minmea.c @@ -287,7 +287,7 @@ 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,"GST")) + if (!strcmp(type+2, "GST")) return MINMEA_SENTENCE_GST; return MINMEA_UNKNOWN; @@ -395,13 +395,13 @@ bool minmea_parse_gst(struct minmea_sentence_gst *frame, const char *sentence) if (!minmea_scan(sentence, "tTfffffff", type, &frame->time, - &frame->rms_deviation,&frame->rms_deviation_scale, - &frame->semi_major_deviation,&frame->semi_major_deviation_scale, - &frame->semi_minor_deviation,&frame->semi_minor_deviation_scale, - &frame->semi_major_orientation,&frame->semi_major_orientation_scale, - &frame->lattitude_error_deviation,&frame->lattitude_error_deviation_scale, - &frame->longitude_error_deviation,&frame->longitude_error_deviation_scale, - &frame->altitude_error_deviation,&frame->altitude_error_deviation_scale)) + &frame->rms_deviation, &frame->rms_deviation_scale, + &frame->semi_major_deviation, &frame->semi_major_deviation_scale, + &frame->semi_minor_deviation, &frame->semi_minor_deviation_scale, + &frame->semi_major_orientation, &frame->semi_major_orientation_scale, + &frame->latitude_error_deviation, &frame->latitude_error_deviation_scale, + &frame->longitude_error_deviation, &frame->longitude_error_deviation_scale, + &frame->altitude_error_deviation, &frame->altitude_error_deviation_scale)) return false; if (strcmp(type+2, "GST")) return false; diff --git a/minmea.h b/minmea.h index 5f84857..7f5a315 100644 --- a/minmea.h +++ b/minmea.h @@ -29,7 +29,7 @@ enum minmea_sentence_id { MINMEA_SENTENCE_RMC, MINMEA_SENTENCE_GGA, MINMEA_SENTENCE_GSA, - MINMEA_SENTENCE_GST + MINMEA_SENTENCE_GST, }; struct minmea_date { @@ -74,7 +74,7 @@ struct minmea_sentence_gst { int semi_major_deviation, semi_major_deviation_scale; int semi_minor_deviation, semi_minor_deviation_scale; int semi_major_orientation, semi_major_orientation_scale; - int lattitude_error_deviation, lattitude_error_deviation_scale; + int latitude_error_deviation, latitude_error_deviation_scale; int longitude_error_deviation, longitude_error_deviation_scale; int altitude_error_deviation, altitude_error_deviation_scale; }; diff --git a/tests.c b/tests.c index c45bde3..32ff6b2 100644 --- a/tests.c +++ b/tests.c @@ -32,6 +32,7 @@ static const char *valid_sequences[] = { "$GPGLL,5106.94086,N,01701.51680,E,123204.00,A,A*63", "$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". NULL, }; @@ -284,6 +285,50 @@ START_TEST(test_minmea_scan_complex2) } END_TEST +START_TEST(test_minmea_scan_complex3) +{ + const char *sentence = "$GPGST,024603.00,3.2,6.6,4.7,47.3,5.8,5.6,22.0*58"; + char type[6]; + struct minmea_time time; + int rms_deviation, rms_deviation_scale; + int semi_major_deviation, semi_major_deviation_scale; + int semi_minor_deviation, semi_minor_deviation_scale; + int semi_major_orientation, semi_major_orientation_scale; + int latitude_error_deviation, latitude_error_deviation_scale; + int longitude_error_deviation, longitude_error_deviation_scale; + int altitude_error_deviation, altitude_error_deviation_scale; + ck_assert(minmea_scan(sentence, "tTfffffff", + type, + &time, + &rms_deviation, &rms_deviation_scale, + &semi_major_deviation, &semi_major_deviation_scale, + &semi_minor_deviation, &semi_minor_deviation_scale, + &semi_major_orientation, &semi_major_orientation_scale, + &latitude_error_deviation, &latitude_error_deviation_scale, + &longitude_error_deviation, &longitude_error_deviation_scale, + &altitude_error_deviation, &altitude_error_deviation_scale) == true); + ck_assert_str_eq(type, "GPGST"); + ck_assert_int_eq(time.hours, 2); + ck_assert_int_eq(time.minutes, 46); + ck_assert_int_eq(time.seconds, 3); + ck_assert_int_eq(time.microseconds, 0); + ck_assert_int_eq(rms_deviation, 32); + ck_assert_int_eq(rms_deviation_scale, 10); + ck_assert_int_eq(semi_major_deviation, 66); + ck_assert_int_eq(semi_major_deviation_scale, 10); + ck_assert_int_eq(semi_minor_deviation, 47); + ck_assert_int_eq(semi_minor_deviation_scale, 10); + ck_assert_int_eq(semi_major_orientation, 473); + ck_assert_int_eq(semi_major_orientation_scale, 10); + ck_assert_int_eq(latitude_error_deviation, 58); + ck_assert_int_eq(latitude_error_deviation, 10); + ck_assert_int_eq(longitude_error_deviation, 56); + ck_assert_int_eq(longitude_error_deviation, 10); + ck_assert_int_eq(altitude_error_deviation, 220); + ck_assert_int_eq(altitude_error_deviation_scale,10); +} +END_TEST + START_TEST(test_minmea_parse_rmc1) { const char *sentence = "$GPRMC,081836.75,A,3751.65,S,14507.36,E,000.0,360.0,130998,011.3,E"; @@ -356,6 +401,33 @@ START_TEST(test_minmea_parse_gga1) } END_TEST +START_TEST(test_minmea_parse_gst1) +{ + const char *sentence = "$GPGST,024603.00,3.2,6.6,4.7,47.3,5.8,5.6,22.0*58"; + struct minmea_sentence_gst frame = {}; + struct minmea_sentence_gst expected = { + .time = { 2, 46, 3, 0 }, + .rms_deviation = 32, + .rms_deviation_scale = 10, + .semi_major_deviation = 66, + .semi_major_deviation_scale = 10, + .semi_minor_deviation = 47, + .semi_minor_deviation_scale = 10, + .semi_major_orientation = 473, + .semi_major_orientation_scale = 10, + .latitude_error_deviation = 58, + .latitude_error_deviation_scale = 10, + .longitude_error_deviation = 56, + .longitude_error_deviation_scale = 10, + .altitude_error_deviation = 220, + .altitude_error_deviation_scale = 10, + }; + ck_assert(minmea_check(sentence) == true); + ck_assert(minmea_parse_gst(&frame, sentence) == true); + ck_assert(!memcmp(&frame, &expected, sizeof(frame))); +} +END_TEST + START_TEST(test_minmea_parse_gsa1) { const char *sentence = "$GPGSA,A,3,04,05,,09,12,,,24,,,,,2.5,1.3,2.1*39"; @@ -383,6 +455,7 @@ START_TEST(test_minmea_usage1) "$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", "$GNGSA,A,3,04,05,,09,12,,,24,,,,,2.5,1.3,2.1", + "$GPGST,024603.00,3.2,6.6,4.7,47.3,5.8,5.6,22.0*58", NULL, }; @@ -392,17 +465,21 @@ START_TEST(test_minmea_usage1) struct minmea_sentence_rmc frame; ck_assert(minmea_parse_rmc(&frame, *sentence) == true); } break; - + case MINMEA_SENTENCE_GGA: { struct minmea_sentence_gga frame; ck_assert(minmea_parse_gga(&frame, *sentence) == true); } break; - + case MINMEA_SENTENCE_GSA: { struct minmea_sentence_gsa frame; ck_assert(minmea_parse_gsa(&frame, *sentence) == true); } break; + case MINMEA_SENTENCE_GST: { + struct minmea_sentence_gst frame; + ck_assert(minmea_parse_gst(&frame, *sentence) == true); + } break; default: { } break; @@ -473,7 +550,7 @@ END_TEST Suite *minmea_suite(void) { Suite *s = suite_create ("minmea"); - + TCase *tc_check = tcase_create("minmea_check"); tcase_add_test(tc_check, test_minmea_check); suite_add_tcase(s, tc_check); @@ -489,7 +566,7 @@ Suite *minmea_suite(void) tcase_add_test(tc_scan, test_minmea_scan_complex1); tcase_add_test(tc_scan, test_minmea_scan_complex2); suite_add_tcase(s, tc_scan); - + TCase *tc_parse = tcase_create("minmea_parse"); tcase_add_test(tc_parse, test_minmea_parse_rmc1); tcase_add_test(tc_parse, test_minmea_parse_rmc2); From b151ccae51466599cae9286ed667873cf971a377 Mon Sep 17 00:00:00 2001 From: Eketh Date: Wed, 23 Apr 2014 20:03:05 +0200 Subject: [PATCH 6/7] Fixed typo in example.c --- example.c | 1 + 1 file changed, 1 insertion(+) diff --git a/example.c b/example.c index 8842328..4d1f743 100644 --- a/example.c +++ b/example.c @@ -42,6 +42,7 @@ int main() printf("$GPGGA: fix quality: %d\n", frame.fix_quality); } } break; + case MINMEA_SENTENCE_GST: { struct minmea_sentence_gst frame; if (minmea_parse_gst(&frame, line)) { From cd0ee8f9e157c16f6518a77c5c44f83ba74eea46 Mon Sep 17 00:00:00 2001 From: Eketh Date: Wed, 23 Apr 2014 20:04:18 +0200 Subject: [PATCH 7/7] Fixed the last typo in example.c --- example.c | 1 + 1 file changed, 1 insertion(+) diff --git a/example.c b/example.c index 4d1f743..01152b0 100644 --- a/example.c +++ b/example.c @@ -61,6 +61,7 @@ int main() minmea_coord(frame.altitude_error_deviation, frame.altitude_error_deviation_scale)); } } break; + default: { } break; }