lm3s1968: add keypad driver implementation to the example.
[bertos.git] / bertos / net / nmea.c
index fdf6b174bbdaf09bb45b550481a6a206ee66bb1b..8403973c28ad88671c88e2d82f2ca57d7400ad4c 100644 (file)
 #include <string.h>
 #include <stdlib.h>
 
-
+/*
+ * Make conversion from one string to int.
+ *
+ * You can specify the precision if the string is a float
+ * number. The result is an int multiplied to 10^precision.
+ */
 static uint32_t tokenToInt(const char *s, int precision)
 {
        uint32_t num = 0;
@@ -103,6 +108,9 @@ static uint32_t tokenToInt(const char *s, int precision)
        return num;
 }
 
+/*
+ * Convert a string to micro degree.
+ */
 static udegree_t convertToDegree(const char *str)
 {
        uint32_t dec;
@@ -122,6 +130,9 @@ static udegree_t convertToDegree(const char *str)
        return dec;
 }
 
+/*
+ * Retun latitude in micro degree from a string.
+ */
 static udegree_t nmea_latitude(const char *plat, const char *phem)
 {
        int ns;
@@ -130,15 +141,15 @@ static udegree_t nmea_latitude(const char *plat, const char *phem)
         return 0;
 
     /* north lat is +, south lat is - */
-    if (*phem == 'N')
-        ns = 1;
-    else
-        ns = -1;
+       ns = (*phem == 'N') ? 1 : -1;
 
 
        return ns * convertToDegree(plat);
 }
 
+/*
+ * Retun longitude in micro degree from a string.
+ */
 static udegree_t nmea_longitude(const char *plot, const char *phem)
 {
        int ew;
@@ -147,14 +158,15 @@ static udegree_t nmea_longitude(const char *plot, const char *phem)
         return 0;
 
     /* west long is negative, east long is positive */
-    if (*phem == 'E')
-        ew = 1;
-    else
-        ew = -1;
+   ew = (*phem == 'E') ? 1 : -1;
 
        return ew * convertToDegree(plot);
 }
 
+/*
+ * Return altitude in meter from a string.
+ *
+ */
 static uint16_t nmea_altitude(const char *palt, const char *punits)
 {
        uint32_t alt;
@@ -179,6 +191,9 @@ static uint16_t nmea_altitude(const char *palt, const char *punits)
        return alt;
 }
 
+/*
+ * Convert time and date stamp string to unix time.
+ */
 static time_t timestampToSec(uint32_t time_stamp, uint32_t date_stamp)
 {
        struct tm t;
@@ -239,17 +254,19 @@ 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);
+       (void)data;
+       LOG_INFOB(
+               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);
+       );
 }
 
 /**
@@ -259,16 +276,19 @@ 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);
+       (void)data;
+    LOG_INFOB(
+               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);
+       );
 }
 
 /**
@@ -278,12 +298,15 @@ void gpgsv_callout(nmeap_context_t *context, void *data, void *user_data)
 {
        (void)context;
        (void)user_data;
-       NmeaGsv *gsv = (NmeaGsv *)data;
+       (void)data;
+       LOG_INFOB(
+               NmeaGsv *gsv = (NmeaGsv *)data;
 
-    LOG_INFO("Found GPGSV message %d %d %d\n", gsv->tot_message, gsv->message_num, gsv->tot_svv);
+           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);
+               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);
+       );
 }
 
 /**
@@ -293,9 +316,11 @@ 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);
+       (void)data;
+       LOG_INFOB(
+               NmeaVtg *vtg = (NmeaVtg *)data;
+           LOG_INFO("Found GPVTG message %d %d %d\n", vtg->track_good, vtg->knot_speed, vtg->km_speed);
+       );
 }
 
 
@@ -433,6 +458,10 @@ int nmea_gpgsv(nmeap_context_t *context, nmeap_sentence_t *sentence)
     return NMEA_GPGSV;
 }
 
+
+/*
+ * Parse NMEA sentence from a channel.
+ */
 void nmea_poll(nmeap_context_t *context, KFile *channel)
 {
        int c;