Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ systems.
* ``GSA`` (DOP and active satellites)
* ``GST`` (Pseudorange Noise Statistics)
* ``GSV`` (Satellites in view)
* ``HDT`` (Heading, True)
* ``RMC`` (Recommended Minimum: position, velocity, time)
* ``VTG`` (Track made good and Ground speed)
* ``ZDA`` (Time & Date - UTC, day, month, year and local time zone)
Expand Down
16 changes: 16 additions & 0 deletions minmea.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ struct sentence_id_map_entry sentence_id_map[] = {
{ "RMC", MINMEA_SENTENCE_RMC },
{ "VTG", MINMEA_SENTENCE_VTG },
{ "ZDA", MINMEA_SENTENCE_ZDA },
{ "HDT", MINMEA_SENTENCE_HDT },
};

const char* minmea_sentence(enum minmea_sentence_id id) {
Expand Down Expand Up @@ -640,6 +641,21 @@ bool minmea_parse_zda(struct minmea_sentence_zda *frame, const char *sentence)
return true;
}

bool minmea_parse_hdt(struct minmea_sentence_hdt *frame, const char *sentence)
{ /* Scan using 't' for the union type payload pointer, 'f' for float, 'c' for char */
if (!minmea_scan(sentence, "tfc",
&frame->type,
&frame->heading,
&frame->true_heading)
) return false;

/* Verify if the extracted token matches the specific HDT layout code */
if (memcmp(frame->type.sentence_id, "HDT", sizeof(frame->type.sentence_id)))
return false;
return true;

}

int minmea_getdatetime(struct tm *tm, const struct minmea_date *date, const struct minmea_time *time_)
{
if (date->year == -1 || time_->hours == -1)
Expand Down
12 changes: 8 additions & 4 deletions minmea.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ enum minmea_sentence_id {
MINMEA_SENTENCE_RMC,
MINMEA_SENTENCE_VTG,
MINMEA_SENTENCE_ZDA,
MINMEA_SENTENCE_HDT,
};

struct minmea_float {
Expand Down Expand Up @@ -196,6 +197,12 @@ struct minmea_sentence_zda {
int minute_offset;
};

struct minmea_sentence_hdt {
union minmea_type type;
struct minmea_float heading;
char true_heading;
};

/**
* Calculate raw sentence checksum. Does not check sentence integrity.
*/
Expand Down Expand Up @@ -249,6 +256,7 @@ bool minmea_parse_gst(struct minmea_sentence_gst *frame, const char *sentence);
bool minmea_parse_gsv(struct minmea_sentence_gsv *frame, const char *sentence);
bool minmea_parse_vtg(struct minmea_sentence_vtg *frame, const char *sentence);
bool minmea_parse_zda(struct minmea_sentence_zda *frame, const char *sentence);
bool minmea_parse_hdt(struct minmea_sentence_hdt *frame, const char *sentence);

/**
* Convert GPS UTC date/time representation to a UNIX calendar time.
Expand Down Expand Up @@ -311,10 +319,6 @@ static inline bool minmea_isfield(char c) {
return isprint((unsigned char) c) && c != ',' && c != '*';
}

#ifdef __cplusplus
}
#endif

#endif /* MINMEA_H */

/* vim: set ts=4 sw=4 et: */
24 changes: 23 additions & 1 deletion tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ static const char *valid_sentences_checksum[] = {
"$GPGST,024603.00,3.2,6.6,4.7,47.3,5.8,5.6,22.0*58",
"$GPZDA,160012.71,11,03,2004,-1,00*7D",
"$GNGBS,170556.00,3.0,2.9,8.3,,,,*5C",
"$HEHDT,234.56,T*19",
NULL,
};

Expand All @@ -64,6 +65,7 @@ static const char *invalid_sentences[] = {
"$GPTXT,hello\n ",
"$GPTXT,hello\r*24",
"$GPTXT,hello\r\n$",
"$HEHDT,234.56,T*1E",
NULL,
};

Expand Down Expand Up @@ -902,7 +904,7 @@ START_TEST(test_minmea_parse_gsv6)
const char *sentence = "$GPGSV,3,1,11,09,57,333,29.0,07,54,227,,04,49,043,24.5,03,43,129,,1*67";
struct minmea_sentence_gsv frame = {};
static const struct minmea_sentence_gsv expected = {
.type = {"GP", "GSV"},
.type = { .talker_id = "GP", .sentence_id = "GSV", .null_terminator = '\0' },
.total_msgs = 3,
.msg_nr = 1,
.total_sats = 11,
Expand Down Expand Up @@ -1029,6 +1031,25 @@ START_TEST(test_minmea_parse_zda1)
}
END_TEST

START_TEST(test_minmea_parse_hdt)
{
/* Standard gyrocompass heading sentence for validation */
const char *hdt_sentence = "$HEHDT,234.56,T*19\r\n";
struct minmea_sentence_hdt frame;

/* Verify sentence ID mapping */
ck_assert_int_eq(minmea_sentence_id(hdt_sentence, false), MINMEA_SENTENCE_HDT);

/* Verify parser execution state */
ck_assert(minmea_parse_hdt(&frame, hdt_sentence) == true);

/* Verify mapped data indicators and structures */
ck_assert_int_eq(frame.true_heading, 'T');
ck_assert_int_eq(frame.heading.value, 23456);
ck_assert_int_eq(frame.heading.scale, 100);
}
END_TEST

START_TEST(test_minmea_usage1)
{
const char *sentences[] = {
Expand Down Expand Up @@ -1252,6 +1273,7 @@ static Suite *minmea_suite(void)
tcase_add_test(tc_parse, test_minmea_parse_vtg2);
tcase_add_test(tc_parse, test_minmea_parse_vtg3);
tcase_add_test(tc_parse, test_minmea_parse_zda1);
tcase_add_test(tc_parse, test_minmea_parse_hdt);
suite_add_tcase(s, tc_parse);

TCase *tc_usage = tcase_create("minmea_usage");
Expand Down