Skip to content

Commit

Permalink
Merge pull request jacketizer#58 from igrr/support_gnss
Browse files Browse the repository at this point in the history
parsers: check only sentence ID, not talker ID
  • Loading branch information
igrr authored Dec 3, 2022
2 parents e10384e + 1b12415 commit 91fd433
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/nmea/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ nmea_get_parser_by_sentence(const char *sentence)

for (i = 0; i < n_parsers; i++) {
parser = parsers[i];
if (0 == strncmp(sentence + 1, parser->parser.type_word, NMEA_PREFIX_LENGTH)) {
/* compare only the sentence ID, ignore the talker ID */
if (0 == strncmp(sentence + 3, parser->parser.type_word + 2, NMEA_PREFIX_LENGTH - 2)) {
return parser;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/nmea/parser_static.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ nmea_get_parser_by_sentence(const char *sentence)
int i;

for (i = 0; i < PARSER_COUNT; i++) {
if (0 == strncmp(sentence + 1, parsers[i].parser.type_word, NMEA_PREFIX_LENGTH)) {
/* compare only the sentence ID, ignore the talker ID */
if (0 == strncmp(sentence + 3, parsers[i].parser.type_word + 2, NMEA_PREFIX_LENGTH - 2)) {
return &(parsers[i]);
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/nmea/parser_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

typedef struct {
nmea_t type;
/* For compatibility with older versions, type_word also contains the talker ID (e.g. "GP".)
* However the talker ID is not taken account when looking for a parser. For example, the parser
* with type_word="GPRMC" will also be used for a "GNRMC" sentence.
*/
char type_word[NMEA_PREFIX_LENGTH];
nmea_s *data;
} nmea_parser_s;
Expand Down
5 changes: 5 additions & 0 deletions tests/unit-tests/test_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ test_get_type_ok()
mu_assert("should return correct type (GPGGA)", NMEA_GPGGA == res);
free(sentence);

sentence = strdup("$GNGGA,4916.45,N,12311.12,W,225444,A\r\n");
res = nmea_get_type(sentence);
mu_assert("should return correct type (GPGGA) even if talker is GN", NMEA_GPGGA == res);
free(sentence);

return 0;
}

Expand Down

0 comments on commit 91fd433

Please sign in to comment.