-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests/pkg/minmea: adding GGA, GSA and RMC sentences to test application
- Loading branch information
Showing
1 changed file
with
110 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,30 +14,130 @@ | |
* @brief minmea GPS NMEA parser library package test application | ||
* | ||
* @author Kaspar Schleiser <[email protected]> | ||
* @author Jan Mohr <[email protected]> | ||
* | ||
* @} | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <inttypes.h> | ||
|
||
#include "fmt.h" | ||
#include "minmea.h" | ||
|
||
static const char *_gga = "$GNGGA,142142.227,5227.022,N,01317.919,E,1,12,1.0,0.0,M,0.0,M,,*70"; | ||
static const char *_gll = "$GNGLL,5229.0178,N,01326.7605,E,114350.000,A,A*45"; | ||
static const char *_gsa = "$GNGSA,A,3,01,02,03,04,05,06,07,08,09,10,11,12,1.0,1.0,1.0*2E"; | ||
static const char *_rmc = "$GPRMC,142142.227,A,5227.022,N,01317.919,E,,,201023,000.0,W*78"; | ||
|
||
int _parse_nmea_msg(const char* nmea_msg) | ||
{ | ||
/* get message type */ | ||
int msg_type = minmea_sentence_id(nmea_msg, false); | ||
switch (msg_type) { | ||
case MINMEA_SENTENCE_GGA: { | ||
struct minmea_sentence_gga frame; | ||
if (minmea_parse_gga(&frame, nmea_msg) && frame.fix_quality) { | ||
puts("check_nmea: GGA recorded"); | ||
|
||
/* print values */ | ||
print_str("\tlat: "); | ||
print_float(minmea_tocoord(&frame.latitude), 6); | ||
printf("\n"); | ||
print_str("\tlon: "); | ||
print_float(minmea_tocoord(&frame.longitude), 6); | ||
printf("\n"); | ||
printf("\talt: %"PRId32"\n", minmea_rescale(&frame.altitude, 1)); | ||
printf("\tn_sats: %d\n", frame.satellites_tracked); | ||
} | ||
else { | ||
puts("check_nmea: invalid GGA record"); | ||
} | ||
} break; | ||
case MINMEA_SENTENCE_GLL: { | ||
struct minmea_sentence_gll frame; | ||
if (minmea_parse_gll(&frame, nmea_msg)) { | ||
puts("check_nmea: GLL recorded"); | ||
|
||
/* print values */ | ||
print_str("\tlat: "); | ||
print_float(minmea_tocoord(&frame.latitude), 6); | ||
printf("\n"); | ||
print_str("\tlon: "); | ||
print_float(minmea_tocoord(&frame.longitude), 6); | ||
printf("\n"); | ||
} | ||
else { | ||
puts("check_nmea: invalid GLL record"); | ||
} | ||
} break; | ||
case MINMEA_SENTENCE_GSA: { | ||
struct minmea_sentence_gsa frame; | ||
if (minmea_parse_gsa(&frame, nmea_msg)) { | ||
puts("check_nmea: GSA recorded"); | ||
|
||
/* print values */ | ||
printf("\tmode: %c\n", frame.mode); /* (A)utomatic and (M)anuel mode */ | ||
printf("\tfix_type: %d\n", frame.fix_type); | ||
/* always a record of 12 satellites */ | ||
for (int i = 0; i < 12; i++) | ||
printf("\t%d. sat: %d\n", i, frame.sats[i]); | ||
} | ||
else { | ||
puts("check_nmea: invalid GSA record"); | ||
} | ||
} break; | ||
case MINMEA_SENTENCE_RMC: { | ||
struct minmea_sentence_rmc frame; | ||
if (minmea_parse_rmc(&frame, nmea_msg) && frame.valid) { | ||
puts("check_nmea: RMC recorded"); | ||
|
||
/* parse timestamp */ | ||
struct tm tm; | ||
time_t timestamp; | ||
minmea_getdatetime(&tm, &frame.date, &frame.time); | ||
timestamp = mktime(&tm); | ||
|
||
/* print values */ | ||
print_str("\tlat: "); | ||
print_float(minmea_tocoord(&frame.latitude), 6); | ||
printf("\n"); | ||
print_str("\tlon: "); | ||
print_float(minmea_tocoord(&frame.longitude), 6); | ||
printf("\n"); | ||
printf("\ttime: %"PRIu32"\n", (uint32_t)timestamp); | ||
} | ||
else { | ||
puts("check_nmea: invalid RMC record"); | ||
} | ||
} break; | ||
default: | ||
printf("check_nmea: unknown message type %d\n", msg_type); | ||
return -1; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
int main(void) | ||
{ | ||
print_str("START\n"); | ||
struct minmea_sentence_gll frame; | ||
|
||
int res = minmea_parse_gll(&frame, _gll); | ||
if (!res) { | ||
print_str("FAILURE: error parsing GPS sentence\n"); | ||
/* check GGA */ | ||
if (_parse_nmea_msg(_gga) != 0) { | ||
puts("Error parsing GGA"); | ||
} | ||
/* check GLL */ | ||
if (_parse_nmea_msg(_gll) != 0) { | ||
puts("Error parsing GLL"); | ||
} | ||
/* check GSA */ | ||
if (_parse_nmea_msg(_gsa) != 0) { | ||
puts("Error parsing GSA"); | ||
} | ||
else { | ||
print_str("parsed coordinates: lat="); | ||
print_float(minmea_tocoord(&frame.latitude), 6); | ||
print_str(" lon="); | ||
print_float(minmea_tocoord(&frame.longitude), 6); | ||
print_str("\nSUCCESS\n"); | ||
/* check RMC */ | ||
if (_parse_nmea_msg(_rmc) != 0) { | ||
puts("Error parsing RMC"); | ||
} | ||
|
||
return 0; | ||
|