From 82b1c180f2eeb301c821cce774a22bead55fc353 Mon Sep 17 00:00:00 2001 From: Evgueni Souleimanov Date: Tue, 17 Jun 2014 20:32:18 -0400 Subject: [PATCH 01/12] remove example executable in make clean --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 075219a..5818208 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ scan-build: clean scan-build $(MAKE) tests clean: - $(RM) tests *.o + $(RM) tests example *.o tests: tests.o minmea.o example: example.o minmea.o From 1b3147c7e06f0ae19784187a6bc0b9f9d97e9d7e Mon Sep 17 00:00:00 2001 From: Evgueni Souleimanov Date: Mon, 16 Jun 2014 20:49:47 -0400 Subject: [PATCH 02/12] fix "warning: declaration of 'time' shadows a global declaration" (-Wshadow) This warning occurred when compiling using gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-3) on CentOS 6.5 x86_64 using the following CFLAGS (locally inserted into Makefile) CFLAGS = -g -Wall -Wextra -Wformat=2 -funsigned-char -fstrict-aliasing -Wstrict-aliasing -Wfloat-equal -Wundef -Wuninitialized -Wpointer-arith -Wbad-function-cast -Wcast-qual -Wcast-align -Wwrite-strings -Waddress -Waggregate-return -Wstrict-prototypes -Wold-style-declaration -Wold-style-definition -Wmissing-parameter-type -Wmissing-prototypes -Wmissing-declarations -Wmissing-field-initializers -Wmissing-noreturn -Wmissing-format-attribute -Wpacked -Wredundant-decls -Wnested-externs -Wshadow -Wsign-compare -Wlogical-op -std=c99 and this make command: make clean ; make example tests --- minmea.c | 22 ++++++++-------- minmea.h | 2 +- tests.c | 78 ++++++++++++++++++++++++++++---------------------------- 3 files changed, 51 insertions(+), 51 deletions(-) diff --git a/minmea.c b/minmea.c index f14290b..b5fdc47 100644 --- a/minmea.c +++ b/minmea.c @@ -252,7 +252,7 @@ bool minmea_scan(const char *sentence, const char *format, ...) } break; case 'T': { // Time (int, int, int, int), -1 if empty. - struct minmea_time *time = va_arg(ap, struct minmea_time *); + struct minmea_time *time_ = va_arg(ap, struct minmea_time *); int h = -1, i = -1, s = -1, u = -1; @@ -281,10 +281,10 @@ bool minmea_scan(const char *sentence, const char *format, ...) } } - time->hours = h; - time->minutes = i; - time->seconds = s; - time->microseconds = u; + time_->hours = h; + time_->minutes = i; + time_->seconds = s; + time_->microseconds = u; } break; case '_': { // Ignore the field. @@ -513,9 +513,9 @@ bool minmea_parse_gsv(struct minmea_sentence_gsv *frame, const char *sentence) return true; } -int minmea_gettimeofday(struct timeval *tv, const struct minmea_date *date, const struct minmea_time *time) +int minmea_gettimeofday(struct timeval *tv, const struct minmea_date *date, const struct minmea_time *time_) { - if (date->year == -1 || time->hours == -1) + if (date->year == -1 || time_->hours == -1) return -1; struct tm tm; @@ -523,14 +523,14 @@ int minmea_gettimeofday(struct timeval *tv, const struct minmea_date *date, cons tm.tm_year = 2000 + date->year - 1900; tm.tm_mon = date->month - 1; tm.tm_mday = date->day; - tm.tm_hour = time->hours; - tm.tm_min = time->minutes; - tm.tm_sec = time->seconds; + tm.tm_hour = time_->hours; + tm.tm_min = time_->minutes; + tm.tm_sec = time_->seconds; time_t timestamp = timegm(&tm); if (timestamp != -1) { tv->tv_sec = timestamp; - tv->tv_usec = time->microseconds; + tv->tv_usec = time_->microseconds; return 0; } else { return -1; diff --git a/minmea.h b/minmea.h index 30b0b86..23d615c 100644 --- a/minmea.h +++ b/minmea.h @@ -182,7 +182,7 @@ bool minmea_parse_gsv(struct minmea_sentence_gsv *frame, const char *sentence); /** * Convert GPS UTC date/time representation to a UNIX timestamp. */ -int minmea_gettimeofday(struct timeval *tv, const struct minmea_date *date, const struct minmea_time *time); +int minmea_gettimeofday(struct timeval *tv, const struct minmea_date *date, const struct minmea_time *time_); /** * Rescale a fixed-point value to a different scale. Rounds towards zero. diff --git a/tests.c b/tests.c index 5edc737..e5fd45b 100644 --- a/tests.c +++ b/tests.c @@ -268,28 +268,28 @@ END_TEST START_TEST(test_minmea_scan_T) { - struct minmea_time time; + struct minmea_time time_; - ck_assert(minmea_scan("$GPXXX,2359", "_T", &time) == false); - ck_assert(minmea_scan("$GPXXX,foobar", "_T", &time) == false); + ck_assert(minmea_scan("$GPXXX,2359", "_T", &time_) == false); + ck_assert(minmea_scan("$GPXXX,foobar", "_T", &time_) == false); - ck_assert(minmea_scan("$GPXXX,235960", "_T", &time) == true); - ck_assert_int_eq(time.hours, 23); - ck_assert_int_eq(time.minutes, 59); - ck_assert_int_eq(time.seconds, 60); - ck_assert_int_eq(time.microseconds, 0); + ck_assert(minmea_scan("$GPXXX,235960", "_T", &time_) == true); + ck_assert_int_eq(time_.hours, 23); + ck_assert_int_eq(time_.minutes, 59); + ck_assert_int_eq(time_.seconds, 60); + ck_assert_int_eq(time_.microseconds, 0); - ck_assert(minmea_scan("$GPXXX,213700.001", "_T", &time) == true); - ck_assert_int_eq(time.hours, 21); - ck_assert_int_eq(time.minutes, 37); - ck_assert_int_eq(time.seconds, 0); - ck_assert_int_eq(time.microseconds, 1000); + ck_assert(minmea_scan("$GPXXX,213700.001", "_T", &time_) == true); + ck_assert_int_eq(time_.hours, 21); + ck_assert_int_eq(time_.minutes, 37); + ck_assert_int_eq(time_.seconds, 0); + ck_assert_int_eq(time_.microseconds, 1000); - ck_assert(minmea_scan("$GPXXX,,,,,,,nope", "_T", &time) == true); - ck_assert_int_eq(time.hours, -1); - ck_assert_int_eq(time.minutes, -1); - ck_assert_int_eq(time.seconds, -1); - ck_assert_int_eq(time.microseconds, -1); + ck_assert(minmea_scan("$GPXXX,,,,,,,nope", "_T", &time_) == true); + ck_assert_int_eq(time_.hours, -1); + ck_assert_int_eq(time_.minutes, -1); + ck_assert_int_eq(time_.seconds, -1); + ck_assert_int_eq(time_.microseconds, -1); } END_TEST @@ -297,7 +297,7 @@ START_TEST(test_minmea_scan_complex1) { const char *sentence = "$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47\r\n"; char type[6]; - struct minmea_time time; + struct minmea_time time_; struct minmea_float latitude; int latitude_direction; struct minmea_float longitude; int longitude_direction; int fix_quality; @@ -307,7 +307,7 @@ START_TEST(test_minmea_scan_complex1) struct minmea_float height; char height_units; ck_assert(minmea_scan(sentence, "tTfdfdiiffcfc__", type, - &time, + &time_, &latitude, &latitude_direction, &longitude, &longitude_direction, &fix_quality, @@ -316,9 +316,9 @@ START_TEST(test_minmea_scan_complex1) &altitude, &altitude_units, &height, &height_units) == true); ck_assert_str_eq(type, "GPGGA"); - ck_assert_int_eq(time.hours, 12); - ck_assert_int_eq(time.minutes, 35); - ck_assert_int_eq(time.seconds, 19); + ck_assert_int_eq(time_.hours, 12); + ck_assert_int_eq(time_.minutes, 35); + ck_assert_int_eq(time_.seconds, 19); ck_assert_int_eq(latitude.value, 4807038); ck_assert_int_eq(latitude.scale, 1000); ck_assert_int_eq(latitude_direction, 1); @@ -343,7 +343,7 @@ START_TEST(test_minmea_scan_complex2) { const char *sentence = "$GPBWC,081837,,,,,,T,,M,,N,*13"; char type[6]; - struct minmea_time time; + struct minmea_time time_; struct minmea_float latitude; int latitude_direction; struct minmea_float longitude; int longitude_direction; struct minmea_float bearing_true; char bearing_true_mark; @@ -352,7 +352,7 @@ START_TEST(test_minmea_scan_complex2) char name[MINMEA_MAX_LENGTH]; ck_assert(minmea_scan(sentence, "tTfdfdfcfcfcs", type, - &time, + &time_, &latitude, &latitude_direction, &longitude, &longitude_direction, &bearing_true, &bearing_true_mark, @@ -360,9 +360,9 @@ START_TEST(test_minmea_scan_complex2) &distance, &distance_units, name) == true); ck_assert_str_eq(type, "GPBWC"); - ck_assert_int_eq(time.hours, 8); - ck_assert_int_eq(time.minutes, 18); - ck_assert_int_eq(time.seconds, 37); + ck_assert_int_eq(time_.hours, 8); + ck_assert_int_eq(time_.minutes, 18); + ck_assert_int_eq(time_.seconds, 37); ck_assert_int_eq(latitude.scale, 0); ck_assert_int_eq(latitude_direction, 0); ck_assert_int_eq(longitude.scale, 0); @@ -381,7 +381,7 @@ 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; + struct minmea_time time_; struct minmea_float rms_deviation; struct minmea_float semi_major_deviation; struct minmea_float semi_minor_deviation; @@ -391,7 +391,7 @@ START_TEST(test_minmea_scan_complex3) struct minmea_float altitude_error_deviation; ck_assert(minmea_scan(sentence, "tTfffffff", type, - &time, + &time_, &rms_deviation, &semi_major_deviation, &semi_minor_deviation, @@ -400,10 +400,10 @@ START_TEST(test_minmea_scan_complex3) &longitude_error_deviation, &altitude_error_deviation) == 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(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.value, 32); ck_assert_int_eq(rms_deviation.scale, 10); ck_assert_int_eq(semi_major_deviation.value, 66); @@ -649,18 +649,18 @@ END_TEST START_TEST(test_minmea_gettimeofday) { struct minmea_date date = { 14, 2, 14 }; - struct minmea_time time = { 13, 0, 9, 123456 }; + struct minmea_time time_ = { 13, 0, 9, 123456 }; struct timeval tv; - ck_assert(minmea_gettimeofday(&tv, &date, &time) == 0); + ck_assert(minmea_gettimeofday(&tv, &date, &time_) == 0); ck_assert_int_eq(tv.tv_sec, 1392382809); ck_assert_int_eq(tv.tv_usec, 123456); date.year = -1; - ck_assert(minmea_gettimeofday(&tv, &date, &time) != 0); + ck_assert(minmea_gettimeofday(&tv, &date, &time_) != 0); date.year = 2014; - time.hours = -1; - ck_assert(minmea_gettimeofday(&tv, &date, &time) != 0); + time_.hours = -1; + ck_assert(minmea_gettimeofday(&tv, &date, &time_) != 0); } END_TEST From 0fc9cea986134d5e8c50ae415d53ddd8e0cb91dc Mon Sep 17 00:00:00 2001 From: Evgueni Souleimanov Date: Mon, 16 Jun 2014 20:49:57 -0400 Subject: [PATCH 03/12] fix "warning: old-style function definition" This warning occurred when compiling using gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-3) on CentOS 6.5 x86_64 using the following CFLAGS (locally inserted into Makefile) CFLAGS = -g -Wall -Wextra -Wformat=2 -funsigned-char -fstrict-aliasing -Wstrict-aliasing -Wfloat-equal -Wundef -Wuninitialized -Wpointer-arith -Wbad-function-cast -Wcast-qual -Wcast-align -Wwrite-strings -Waddress -Waggregate-return -Wstrict-prototypes -Wold-style-declaration -Wold-style-definition -Wmissing-parameter-type -Wmissing-prototypes -Wmissing-declarations -Wmissing-field-initializers -Wmissing-noreturn -Wmissing-format-attribute -Wpacked -Wredundant-decls -Wnested-externs -Wshadow -Wsign-compare -Wlogical-op -std=c99 and this make command: make clean ; make example tests --- example.c | 2 +- tests.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/example.c b/example.c index 68fb873..0955be3 100644 --- a/example.c +++ b/example.c @@ -12,7 +12,7 @@ #include "minmea.h" -int main() +int main(void) { char line[MINMEA_MAX_LENGTH]; while (fgets(line, sizeof(line), stdin) != NULL) { diff --git a/tests.c b/tests.c index e5fd45b..a503c3c 100644 --- a/tests.c +++ b/tests.c @@ -754,7 +754,7 @@ Suite *minmea_suite(void) return s; } -int main() +int main(void) { int number_failed; Suite *s = minmea_suite(); From 2ae5c4a6455567be5e754db3fa5b34cba57ad7af Mon Sep 17 00:00:00 2001 From: Evgueni Souleimanov Date: Mon, 16 Jun 2014 20:50:08 -0400 Subject: [PATCH 04/12] fix "warning: no previous prototype for 'minmea_suite'" This warning occurred when compiling using gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-3) on CentOS 6.5 x86_64 using the following CFLAGS (locally inserted into Makefile) CFLAGS = -g -Wall -Wextra -Wformat=2 -funsigned-char -fstrict-aliasing -Wstrict-aliasing -Wfloat-equal -Wundef -Wuninitialized -Wpointer-arith -Wbad-function-cast -Wcast-qual -Wcast-align -Wwrite-strings -Waddress -Waggregate-return -Wstrict-prototypes -Wold-style-declaration -Wold-style-definition -Wmissing-parameter-type -Wmissing-prototypes -Wmissing-declarations -Wmissing-field-initializers -Wmissing-noreturn -Wmissing-format-attribute -Wpacked -Wredundant-decls -Wnested-externs -Wshadow -Wsign-compare -Wlogical-op -std=c99 and this make command: make clean ; make example tests --- tests.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests.c b/tests.c index a503c3c..794d330 100644 --- a/tests.c +++ b/tests.c @@ -707,7 +707,7 @@ END_TEST #pragma GCC diagnostic pop -Suite *minmea_suite(void) +static Suite *minmea_suite(void) { Suite *s = suite_create ("minmea"); From 52c077c5acfe04e3fbf509e9790392ecd4bf0700 Mon Sep 17 00:00:00 2001 From: Evgueni Souleimanov Date: Tue, 17 Jun 2014 20:23:22 -0400 Subject: [PATCH 05/12] undo commit "tests: prevent compiler warning when comparing floats" --- tests.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests.c b/tests.c index 794d330..3365edf 100644 --- a/tests.c +++ b/tests.c @@ -682,8 +682,6 @@ START_TEST(test_minmea_rescale) } END_TEST -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wfloat-equal" /* The float values used in tests should be exactly representable under IEEE754; * false negatives will occur otherwise. */ @@ -705,8 +703,6 @@ START_TEST(test_minmea_coord) } END_TEST -#pragma GCC diagnostic pop - static Suite *minmea_suite(void) { Suite *s = suite_create ("minmea"); From f68eb7c9fd968bea0811bdda521e29092bbbcc01 Mon Sep 17 00:00:00 2001 From: Evgueni Souleimanov Date: Tue, 17 Jun 2014 20:25:55 -0400 Subject: [PATCH 06/12] fix "warning: comparing floating point with == or != is unsafe" (epsilon comparison) Instead of comparing floats "x == y", perform comparison "fabs(x - y) <= epsilon", where epsilon is acceptable error that accumulates in computation of x and/or y. Because in this case all integers are small and all floats are exactly representable under IEEE754, epsilon may be zero in our tests. This warning occurred when compiling using gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-3) on CentOS 6.5 x86_64 using the following CFLAGS (locally inserted into Makefile) CFLAGS = -g -Wall -Wextra -Wformat=2 -funsigned-char -fstrict-aliasing -Wstrict-aliasing -Wfloat-equal -Wundef -Wuninitialized -Wpointer-arith -Wbad-function-cast -Wcast-qual -Wcast-align -Wwrite-strings -Waddress -Waggregate-return -Wstrict-prototypes -Wold-style-declaration -Wold-style-definition -Wmissing-parameter-type -Wmissing-prototypes -Wmissing-declarations -Wmissing-field-initializers -Wmissing-noreturn -Wmissing-format-attribute -Wpacked -Wredundant-decls -Wnested-externs -Wshadow -Wsign-compare -Wlogical-op -std=c99 and this make command: make clean ; make example tests --- tests.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests.c b/tests.c index 3365edf..46c3dda 100644 --- a/tests.c +++ b/tests.c @@ -688,18 +688,18 @@ END_TEST START_TEST(test_minmea_float) { ck_assert(isnan(minmea_tofloat(&(struct minmea_float) { 42, 0 }))); - ck_assert(minmea_tofloat(&(struct minmea_float) { 7, 1}) == 7.0); - ck_assert(minmea_tofloat(&(struct minmea_float) { -200, 100}) == -2.0); - ck_assert(minmea_tofloat(&(struct minmea_float) { 15, 10}) == 1.5); + ck_assert(fabs(minmea_tofloat(&(struct minmea_float) { 7, 1}) - 7.0) <= 0.0f); + ck_assert(fabs(minmea_tofloat(&(struct minmea_float) { -200, 100}) - (-2.0)) <= 0.0f); + ck_assert(fabs(minmea_tofloat(&(struct minmea_float) { 15, 10}) - 1.5) <= 0.0f); } END_TEST START_TEST(test_minmea_coord) { ck_assert(isnan(minmea_tocoord(&(struct minmea_float) { 42, 0 }))); - ck_assert(minmea_tocoord(&(struct minmea_float) { 4200, 1 }) == 42.0); - ck_assert(minmea_tocoord(&(struct minmea_float) { 420000, 100 }) == 42.0); - ck_assert(minmea_tocoord(&(struct minmea_float) { 423000, 100 }) == 42.5); + ck_assert(fabs(minmea_tocoord(&(struct minmea_float) { 4200, 1 }) - 42.0) <= 0.0f); + ck_assert(fabs(minmea_tocoord(&(struct minmea_float) { 420000, 100 }) - 42.0) <= 0.0f); + ck_assert(fabs(minmea_tocoord(&(struct minmea_float) { 423000, 100 }) - 42.5) <= 0.0f); } END_TEST From 74e2ce002e8b2ae75f024cf83061aea8796987bf Mon Sep 17 00:00:00 2001 From: Evgueni Souleimanov Date: Mon, 16 Jun 2014 20:50:18 -0400 Subject: [PATCH 07/12] add test for shorter GSV sentence, with 0 to 4 satellites --- tests.c | 169 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) diff --git a/tests.c b/tests.c index 46c3dda..b3eeace 100644 --- a/tests.c +++ b/tests.c @@ -596,6 +596,171 @@ START_TEST(test_minmea_parse_gsv1) } END_TEST +START_TEST(test_minmea_parse_gsv2) +{ + const char *sentence = "$GPGSV,4,2,11,08,51,203,30,09,45,215,28*75"; + struct minmea_sentence_gsv frame = {}; + static const struct minmea_sentence_gsv expected = { + .total_msgs = 4, + .msg_nr = 2, + .total_sats = 11, + .sats = { + { + .nr = 8, + .elevation = 51, + .azimuth = 203, + .snr = 30 + }, + { + .nr = 9, + .elevation = 45, + .azimuth = 215, + .snr = 28 + }, + { + .nr = 0, + .elevation = 0, + .azimuth = 0, + .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_parse_gsv3) +{ + const char *sentence = "$GPGSV,4,4,13,39,31,170,27*40"; + struct minmea_sentence_gsv frame = {}; + static const struct minmea_sentence_gsv expected = { + .total_msgs = 4, + .msg_nr = 4, + .total_sats = 13, + .sats = { + { + .nr = 39, + .elevation = 31, + .azimuth = 170, + .snr = 27 + }, + { + .nr = 0, + .elevation = 0, + .azimuth = 0, + .snr = 0 + }, + { + .nr = 0, + .elevation = 0, + .azimuth = 0, + .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_parse_gsv4) +{ + const char *sentence = "$GPGSV,4,4,13*7B"; + struct minmea_sentence_gsv frame = {}; + static const struct minmea_sentence_gsv expected = { + .total_msgs = 4, + .msg_nr = 4, + .total_sats = 13, + .sats = { + { + .nr = 0, + .elevation = 0, + .azimuth = 0, + .snr = 0 + }, + { + .nr = 0, + .elevation = 0, + .azimuth = 0, + .snr = 0 + }, + { + .nr = 0, + .elevation = 0, + .azimuth = 0, + .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_parse_gsv5) +{ + const char *sentence = "$GPGSV,4,1,13,02,28,259,33,04,12,212,27,05,34,305,30,07,79,138,*7F"; + struct minmea_sentence_gsv frame = {}; + static const struct minmea_sentence_gsv expected = { + .total_msgs = 4, + .msg_nr = 1, + .total_sats = 13, + .sats = { + { + .nr = 2, + .elevation = 28, + .azimuth = 259, + .snr = 33 + }, + { + .nr = 4, + .elevation = 12, + .azimuth = 212, + .snr = 27 + }, + { + .nr = 5, + .elevation = 34, + .azimuth = 305, + .snr = 30 + }, + { + .nr = 7, + .elevation = 79, + .azimuth = 138, + .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[] = { @@ -734,6 +899,10 @@ static Suite *minmea_suite(void) tcase_add_test(tc_parse, test_minmea_parse_gll2); tcase_add_test(tc_parse, test_minmea_parse_gst1); tcase_add_test(tc_parse, test_minmea_parse_gsv1); + tcase_add_test(tc_parse, test_minmea_parse_gsv2); + tcase_add_test(tc_parse, test_minmea_parse_gsv3); + tcase_add_test(tc_parse, test_minmea_parse_gsv4); + tcase_add_test(tc_parse, test_minmea_parse_gsv5); suite_add_tcase(s, tc_parse); TCase *tc_usage = tcase_create("minmea_usage"); From a52c1faa27750ecf5c9377c8b3c2194e640e14e7 Mon Sep 17 00:00:00 2001 From: Evgueni Souleimanov Date: Mon, 16 Jun 2014 20:50:27 -0400 Subject: [PATCH 08/12] GSV: parse sentences that list 0 to 4 satellites --- minmea.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/minmea.c b/minmea.c index b5fdc47..8ef653a 100644 --- a/minmea.c +++ b/minmea.c @@ -481,9 +481,13 @@ bool minmea_parse_gst(struct minmea_sentence_gst *frame, const char *sentence) 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 + // $GPGSV,3,3,11,22,42,067,42,24,14,311,43,27,05,244,00,,,,*4D + // $GPGSV,4,2,11,08,51,203,30,09,45,215,28*75 + // $GPGSV,4,4,13,39,31,170,27*40 + // $GPGSV,4,4,13*7B char type[6]; - if (!minmea_scan(sentence, "tiiiiiiiiiiiiiiiiiii", + if (!minmea_scan(sentence, "tiii;iiiiiiiiiiiiiiii", type, &frame->total_msgs, &frame->msg_nr, From 6f9ffab8837fbb1dc9877036c619c716395aba29 Mon Sep 17 00:00:00 2001 From: Evgueni Souleimanov Date: Tue, 17 Jun 2014 20:52:05 -0400 Subject: [PATCH 09/12] example: fix printf line --- example.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example.c b/example.c index 0955be3..9c01b7a 100644 --- a/example.c +++ b/example.c @@ -50,8 +50,8 @@ int main(void) frame.latitude_error_deviation.value, frame.latitude_error_deviation.scale, frame.longitude_error_deviation.value, frame.longitude_error_deviation.scale, frame.altitude_error_deviation.value, frame.altitude_error_deviation.scale); - printf("$xxGST fixed point latitude,longitude and altitude error deviation \ - scaled to one decimal place: (%d,%d,%d)\n", + printf("$xxGST fixed point latitude,longitude and altitude error deviation" + " scaled to one decimal place: (%d,%d,%d)\n", minmea_rescale(&frame.latitude_error_deviation, 10), minmea_rescale(&frame.longitude_error_deviation, 10), minmea_rescale(&frame.altitude_error_deviation, 10)); From eede684d27420cfa1230ed64fd038fef29366dbb Mon Sep 17 00:00:00 2001 From: Evgueni Souleimanov Date: Tue, 17 Jun 2014 20:56:29 -0400 Subject: [PATCH 10/12] example: indicate when a sentence is not parsed or is not valid Indicate when a sentence is not parsed or is not valid. Before this change, it was not clear from the example run whether each sentence is parsed properly or not. --- example.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/example.c b/example.c index 9c01b7a..efb5ea9 100644 --- a/example.c +++ b/example.c @@ -34,6 +34,9 @@ int main(void) minmea_tocoord(&frame.longitude), minmea_tofloat(&frame.speed)); } + else { + printf("$xxRMC sentence is not parsed\n"); + } } break; case MINMEA_SENTENCE_GGA: { @@ -41,6 +44,9 @@ int main(void) if (minmea_parse_gga(&frame, line)) { printf("$xxGGA: fix quality: %d\n", frame.fix_quality); } + else { + printf("$xxGGA sentence is not parsed\n"); + } } break; case MINMEA_SENTENCE_GST: { @@ -60,6 +66,9 @@ int main(void) minmea_tofloat(&frame.longitude_error_deviation), minmea_tofloat(&frame.altitude_error_deviation)); } + else { + printf("$xxGST sentence is not parsed\n"); + } } break; case MINMEA_SENTENCE_GSV: { @@ -74,9 +83,17 @@ int main(void) frame.sats[i].azimuth, frame.sats[i].snr); } + else { + printf("$xxGSV sentence is not parsed\n"); + } + } break; + + case MINMEA_INVALID: { + printf("$xxxxx sentence is not valid\n"); } break; default: { + printf("$xxxxx sentence is not parsed\n"); } break; } } From 4b060fe234e725d017e2e4071580681ae3c708cd Mon Sep 17 00:00:00 2001 From: Evgueni Souleimanov Date: Tue, 17 Jun 2014 20:58:16 -0400 Subject: [PATCH 11/12] example: indent parsing results with spaces --- example.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/example.c b/example.c index efb5ea9..26b74ce 100644 --- a/example.c +++ b/example.c @@ -12,6 +12,8 @@ #include "minmea.h" +#define INDENT_SPACES " " + int main(void) { char line[MINMEA_MAX_LENGTH]; @@ -21,79 +23,79 @@ int main(void) case MINMEA_SENTENCE_RMC: { struct minmea_sentence_rmc frame; if (minmea_parse_rmc(&frame, line)) { - printf("$xxRMC: raw coordinates and speed: (%d/%d,%d/%d) %d/%d\n", + printf(INDENT_SPACES "$xxRMC: raw coordinates and speed: (%d/%d,%d/%d) %d/%d\n", frame.latitude.value, frame.latitude.scale, frame.longitude.value, frame.longitude.scale, frame.speed.value, frame.speed.scale); - printf("$xxRMC fixed-point coordinates and speed scaled to three decimal places: (%d,%d) %d\n", + printf(INDENT_SPACES "$xxRMC fixed-point coordinates and speed scaled to three decimal places: (%d,%d) %d\n", minmea_rescale(&frame.latitude, 1000), minmea_rescale(&frame.longitude, 1000), minmea_rescale(&frame.speed, 1000)); - printf("$xxRMC floating point degree coordinates and speed: (%f,%f) %f\n", + printf(INDENT_SPACES "$xxRMC floating point degree coordinates and speed: (%f,%f) %f\n", minmea_tocoord(&frame.latitude), minmea_tocoord(&frame.longitude), minmea_tofloat(&frame.speed)); } else { - printf("$xxRMC sentence is not parsed\n"); + printf(INDENT_SPACES "$xxRMC sentence is not parsed\n"); } } break; case MINMEA_SENTENCE_GGA: { struct minmea_sentence_gga frame; if (minmea_parse_gga(&frame, line)) { - printf("$xxGGA: fix quality: %d\n", frame.fix_quality); + printf(INDENT_SPACES "$xxGGA: fix quality: %d\n", frame.fix_quality); } else { - printf("$xxGGA sentence is not parsed\n"); + printf(INDENT_SPACES "$xxGGA sentence is not parsed\n"); } } break; case MINMEA_SENTENCE_GST: { struct minmea_sentence_gst frame; if (minmea_parse_gst(&frame, line)) { - printf("$xxGST: raw latitude,longitude and altitude error deviation: (%d/%d,%d/%d,%d/%d)\n", + printf(INDENT_SPACES "$xxGST: raw latitude,longitude and altitude error deviation: (%d/%d,%d/%d,%d/%d)\n", frame.latitude_error_deviation.value, frame.latitude_error_deviation.scale, frame.longitude_error_deviation.value, frame.longitude_error_deviation.scale, frame.altitude_error_deviation.value, frame.altitude_error_deviation.scale); - printf("$xxGST fixed point latitude,longitude and altitude error deviation" + printf(INDENT_SPACES "$xxGST fixed point latitude,longitude and altitude error deviation" " scaled to one decimal place: (%d,%d,%d)\n", minmea_rescale(&frame.latitude_error_deviation, 10), minmea_rescale(&frame.longitude_error_deviation, 10), minmea_rescale(&frame.altitude_error_deviation, 10)); - printf("$xxGST floating point degree latitude, longitude and altitude error deviation: (%f,%f,%f)", + printf(INDENT_SPACES "$xxGST floating point degree latitude, longitude and altitude error deviation: (%f,%f,%f)", minmea_tofloat(&frame.latitude_error_deviation), minmea_tofloat(&frame.longitude_error_deviation), minmea_tofloat(&frame.altitude_error_deviation)); } else { - printf("$xxGST sentence is not parsed\n"); + printf(INDENT_SPACES "$xxGST sentence is not parsed\n"); } } break; case MINMEA_SENTENCE_GSV: { struct minmea_sentence_gsv frame; if (minmea_parse_gsv(&frame, line)) { - printf("$xxGSV: message %d of %d\n", frame.msg_nr, frame.total_msgs); - printf("$xxGSV: sattelites in view: %d\n", frame.total_sats); + printf(INDENT_SPACES "$xxGSV: message %d of %d\n", frame.msg_nr, frame.total_msgs); + printf(INDENT_SPACES "$xxGSV: sattelites in view: %d\n", frame.total_sats); for (int i = 0; i < 4; i++) - printf("$xxGSV: sat nr %d, elevation: %d, azimuth: %d, snr: %d dbm\n", + printf(INDENT_SPACES "$xxGSV: 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); } else { - printf("$xxGSV sentence is not parsed\n"); + printf(INDENT_SPACES "$xxGSV sentence is not parsed\n"); } } break; case MINMEA_INVALID: { - printf("$xxxxx sentence is not valid\n"); + printf(INDENT_SPACES "$xxxxx sentence is not valid\n"); } break; default: { - printf("$xxxxx sentence is not parsed\n"); + printf(INDENT_SPACES "$xxxxx sentence is not parsed\n"); } break; } } From 40b3fdd80d995915066b04c95023c9593524a997 Mon Sep 17 00:00:00 2001 From: Evgueni Souleimanov Date: Tue, 17 Jun 2014 21:22:27 -0400 Subject: [PATCH 12/12] tests: use fabsf (float), not fabs (double) in epsilon comparisons of floats Fixes a mistake in commit f68eb7c --- tests.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests.c b/tests.c index b3eeace..269a042 100644 --- a/tests.c +++ b/tests.c @@ -853,18 +853,18 @@ END_TEST START_TEST(test_minmea_float) { ck_assert(isnan(minmea_tofloat(&(struct minmea_float) { 42, 0 }))); - ck_assert(fabs(minmea_tofloat(&(struct minmea_float) { 7, 1}) - 7.0) <= 0.0f); - ck_assert(fabs(minmea_tofloat(&(struct minmea_float) { -200, 100}) - (-2.0)) <= 0.0f); - ck_assert(fabs(minmea_tofloat(&(struct minmea_float) { 15, 10}) - 1.5) <= 0.0f); + ck_assert(fabsf(minmea_tofloat(&(struct minmea_float) { 7, 1}) - 7.0f) <= 0.0f); + ck_assert(fabsf(minmea_tofloat(&(struct minmea_float) { -200, 100}) - (-2.0f)) <= 0.0f); + ck_assert(fabsf(minmea_tofloat(&(struct minmea_float) { 15, 10}) - 1.5f) <= 0.0f); } END_TEST START_TEST(test_minmea_coord) { ck_assert(isnan(minmea_tocoord(&(struct minmea_float) { 42, 0 }))); - ck_assert(fabs(minmea_tocoord(&(struct minmea_float) { 4200, 1 }) - 42.0) <= 0.0f); - ck_assert(fabs(minmea_tocoord(&(struct minmea_float) { 420000, 100 }) - 42.0) <= 0.0f); - ck_assert(fabs(minmea_tocoord(&(struct minmea_float) { 423000, 100 }) - 42.5) <= 0.0f); + ck_assert(fabsf(minmea_tocoord(&(struct minmea_float) { 4200, 1 }) - 42.0f) <= 0.0f); + ck_assert(fabsf(minmea_tocoord(&(struct minmea_float) { 420000, 100 }) - 42.0f) <= 0.0f); + ck_assert(fabsf(minmea_tocoord(&(struct minmea_float) { 423000, 100 }) - 42.5f) <= 0.0f); } END_TEST