minmea: add minmea_talker_id()

This commit is contained in:
Kosma Moczek 2014-03-24 23:13:05 +01:00
parent 5bc6fddb55
commit ea1bbcbfa5
3 changed files with 24 additions and 1 deletions

View File

@ -259,6 +259,19 @@ end:
return result; 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) enum minmea_sentence_id minmea_sentence_id(const char *sentence)
{ {
if (!minmea_check(sentence)) if (!minmea_check(sentence))

View File

@ -92,6 +92,11 @@ struct minmea_sentence_gsa {
*/ */
bool minmea_check(const char *sentence); bool minmea_check(const char *sentence);
/**
* Determine talker identifier.
*/
bool minmea_talker_id(char talker[3], const char *sentence);
/** /**
* Determine sentence identifier. * Determine sentence identifier.
*/ */

View File

@ -382,7 +382,7 @@ START_TEST(test_minmea_usage1)
const char *sentences[] = { const char *sentences[] = {
"$GPRMC,081836,A,3751.65,S,14507.36,E,000.0,360.0,130998,011.3,E*62", "$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", "$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, NULL,
}; };
@ -407,6 +407,11 @@ START_TEST(test_minmea_usage1)
default: { default: {
} break; } 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 END_TEST