Add brief. Add example callout functions. Use tokenToInt to compute date time stamp...
authorasterix <asterix@38d2e660-2303-0410-9eaa-f027e97ec537>
Tue, 13 Oct 2009 09:19:57 +0000 (09:19 +0000)
committerasterix <asterix@38d2e660-2303-0410-9eaa-f027e97ec537>
Tue, 13 Oct 2009 09:19:57 +0000 (09:19 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3075 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/net/nmea.c
bertos/net/nmea.h

index 23e6dbcdc8bcbf305d82d4212a2ecd48a7b117dd..fdf6b174bbdaf09bb45b550481a6a206ee66bb1b 100644 (file)
  * 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 <asterix@develer.com>
  *
@@ -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]);
index 84dfcc18c64bdc4bf06fcdac53caeb5deca7f611..f735f6bfbaf18fb20e36ee52bd3a985beae52955 100644 (file)
@@ -29,7 +29,7 @@
  * Copyright 2009 Develer S.r.l. (http://www.develer.com/)
  *
  * -->
- * \brief NMEA Parser
+ * \brief NMEA Parser.
  *
  * \author Daniele Basile <asterix@develer.com>
  *
@@ -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);