From ce455a07c3f2d0055f3b7971e91fe5a6e3903395 Mon Sep 17 00:00:00 2001 From: asterix Date: Tue, 13 Oct 2009 09:19:57 +0000 Subject: [PATCH] Add brief. Add example callout functions. Use tokenToInt to compute date time stamp. Fix default month date in timestampToSec. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3075 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/net/nmea.c | 88 +++++++++++++++++++++++++++++++++++++++++++++-- bertos/net/nmea.h | 8 ++++- 2 files changed, 92 insertions(+), 4 deletions(-) diff --git a/bertos/net/nmea.c b/bertos/net/nmea.c index 23e6dbcd..fdf6b174 100644 --- a/bertos/net/nmea.c +++ b/bertos/net/nmea.c @@ -29,7 +29,21 @@ * Copyright 2009 Develer S.r.l. (http://www.develer.com/) * * --> - * \brief NMEA implementation. + * + * \brief NMEA parser implementation. + * + * NMEA 0183 is acronym of National Marine Electronics Association that + * combined electrical and data specification for communication between marine + * electronic devices such as echo sounder, sonars, anemometer (wind speed and direction), + * gyrocompass, autopilot, GPS receivers and many other types of instruments. + * It has been defined by, and is controlled by, the U.S.-based National Marine + * Electronics Association. + * The NMEA 0183 standard uses a simple ASCII, serial communications protocol + * that defines how data is transmitted in a "sentence" from one "talker" + * to multiple "listeners" at a time. + * At the application layer, the standard also defines the contents of each sentence + * (message) type so that all listeners can parse messages accurately. + * * * \author Daniele Basile * @@ -180,6 +194,7 @@ static time_t timestampToSec(uint32_t time_stamp, uint32_t date_stamp) uint32_t res = time_stamp / 1000; uint32_t all = time_stamp; msec = all - res * 1000; + for (int i = 0; i < 3; i++) { all = res; @@ -193,7 +208,7 @@ static time_t timestampToSec(uint32_t time_stamp, uint32_t date_stamp) t.tm_hour = tmr[2]; //If we not have refence data, we set as default 1/1/1970. t.tm_mday = 1; - t.tm_mon = 1; + t.tm_mon = 0; t.tm_year = 70; if (date_stamp) @@ -217,6 +232,73 @@ static time_t timestampToSec(uint32_t time_stamp, uint32_t date_stamp) return mktime(&t); } +/** + * Callout example for GGA data + */ +void gpgga_callout(nmeap_context_t *context, void *data, void *user_data) +{ + (void)context; + (void)user_data; + NmeaGga *gga = (NmeaGga *)data; + + LOG_INFO("Found GPGGA message %ld %ld %d %lu %d %d %d %d\n", + (long)gga->latitude, + (long)gga->longitude, + gga->altitude, + gga->time, + gga->satellites, + gga->quality, + gga->hdop, + gga->geoid); +} + +/** + * Callout example for RMC + */ +void gprmc_callout(nmeap_context_t *context, void *data, void *user_data) +{ + (void)context; + (void)user_data; + NmeaRmc *rmc = (NmeaRmc *)data; + + LOG_INFO("Found GPRMC message %lu %c %ld %ld %d %d %d\n", + rmc->time, + rmc->warn, + (long)rmc->latitude, + (long)rmc->longitude, + rmc->speed, + rmc->course, + rmc->mag_var); +} + +/** + * Callout example for GSV data + */ +void gpgsv_callout(nmeap_context_t *context, void *data, void *user_data) +{ + (void)context; + (void)user_data; + NmeaGsv *gsv = (NmeaGsv *)data; + + LOG_INFO("Found GPGSV message %d %d %d\n", gsv->tot_message, gsv->message_num, gsv->tot_svv); + + for (int i = 0; i < 4; i++) + LOG_INFO("%d %d %d %d\n", gsv->info[i].sv_prn, gsv->info[i].elevation, gsv->info[i].azimut, gsv->info[i].snr); +} + +/** + * Callout example for VTG data + */ +void gpvtg_callout(nmeap_context_t *context, void *data, void *user_data) +{ + (void)context; + (void)user_data; + NmeaVtg *vtg = (NmeaVtg *)data; + + LOG_INFO("Found GPVTG message %d %d %d\n", vtg->track_good, vtg->knot_speed, vtg->km_speed); +} + + /** * standard GPGGA sentence parser @@ -267,7 +349,7 @@ int nmea_gprmc(nmeap_context_t *context, nmeap_sentence_t *sentence) /* * extract data from the tokens */ - rmc->time = timestampToSec(tokenToInt(context->token[1], 3), atoi(context->token[9])); + rmc->time = timestampToSec(tokenToInt(context->token[1], 3), tokenToInt(context->token[9], 0)); rmc->warn = *context->token[2]; rmc->latitude = nmea_latitude(context->token[3],context->token[4]); rmc->longitude = nmea_longitude(context->token[5],context->token[6]); diff --git a/bertos/net/nmea.h b/bertos/net/nmea.h index 84dfcc18..f735f6bf 100644 --- a/bertos/net/nmea.h +++ b/bertos/net/nmea.h @@ -29,7 +29,7 @@ * Copyright 2009 Develer S.r.l. (http://www.develer.com/) * * --> - * \brief NMEA Parser + * \brief NMEA Parser. * * \author Daniele Basile * @@ -138,6 +138,12 @@ int nmea_gpvtg(nmeap_context_t *context, nmeap_sentence_t *sentence); int nmea_gprmc(nmeap_context_t *context, nmeap_sentence_t *sentence); int nmea_gpgga(nmeap_context_t *context, nmeap_sentence_t *sentence); +// Example of callout +void gpgga_callout(nmeap_context_t *context, void *data, void *user_data); +void gprmc_callout(nmeap_context_t *context, void *data, void *user_data); +void gpgsv_callout(nmeap_context_t *context, void *data, void *user_data); +void gpvtg_callout(nmeap_context_t *context, void *data, void *user_data); + int nmea_testSetup(void); int nmea_testTearDown(void); int nmea_testRun(void); -- 2.25.1