Fix return function.
[bertos.git] / bertos / net / nmea.c
index 00c6d076e71a9d6fbc3f72b308a2e6c3dba83119..29f99ee19396b1f5646ed291d87cbda5f95935be 100644 (file)
@@ -76,23 +76,35 @@ static uint32_t tokenToInt(const char *s)
        return num;
 }
 
-
-static udegree_t nmea_latitude(const char *plat, const char *phem)
+static udegree_t convertToDegree(const char *str)
 {
-       int ns;
-       uint32_t lat;
+       uint32_t dec;
        uint32_t deg;
        uint32_t min;
 
-       if (*plat == 0)
+       if (*str == 0)
        {
         return 0;
     }
+
+       dec = tokenToInt(str);
+       deg = dec / 1000000;
+       min = dec - deg * 1000000;
+       dec = deg * 1000000 + ((min * 5) + 1) / 3;
+
+       return dec;
+}
+
+static udegree_t nmea_latitude(const char *plat, const char *phem)
+{
+       int ns;
+
     if (*phem == 0)
        {
         return 0;
     }
 
+
     /* north lat is +, south lat is - */
     if (*phem == 'N')
        {
@@ -103,29 +115,13 @@ static udegree_t nmea_latitude(const char *plat, const char *phem)
         ns = -1;
     }
 
-       lat = tokenToInt(plat);
-       deg = lat / 1000000;
-       min = lat - deg * 1000000;
-       lat = deg * 1000000 + ((min * 5) + 1) / 3;
 
-       return ns * lat;
+       return ns * convertToDegree(plat);
 }
 
 static udegree_t nmea_longitude(const char *plot, const char *phem)
 {
        int ew;
-       uint32_t lot;
-       uint32_t deg;
-       uint32_t min;
-
-       if (*plot == 0)
-       {
-        return 0;
-    }
-    if (*phem == 0)
-       {
-        return 0;
-    }
 
     /* west long is negative, east long is positive */
     if (*phem == 'E')
@@ -136,12 +132,12 @@ static udegree_t nmea_longitude(const char *plot, const char *phem)
         ew = -1;
     }
 
-       lot = tokenToInt(plot);
-       deg = lot / 1000000;
-       min = lot - deg * 1000000;
-       lot = deg * 1000000 + ((min * 5) + 1) / 3;
+    if (*phem == 0)
+       {
+        return 0;
+    }
 
-       return ew  * lot;
+       return ew * convertToDegree(plot);
 }
 
 static uint16_t nmea_altitude(const char *palt, const char *punits)
@@ -196,6 +192,7 @@ static time_t timestampToSec(uint32_t time_stamp, uint32_t date_stamp)
        t.tm_sec = tmr[0] + (ROUND_UP(msec, 1000) / 1000);
        t.tm_min = tmr[1];
        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_year = 70;
@@ -374,7 +371,7 @@ int nmea_gpgsv(nmeap_context_t *context, nmeap_sentence_t *sentence)
         * if the sentence has a callout, call it
         */
     if (sentence->callout != 0)
-        (*sentence->callout)(context,gsv,context->user_data);
+        (*sentence->callout)(context, gsv, context->user_data);
 
     return NMEA_GPGSV;
 }
@@ -384,8 +381,7 @@ void nmea_poll(nmeap_context_t *context, KFile *channel)
        int c;
        while ((c = kfile_getc(channel)) != EOF)
        {
-               if (nmeap_parse(context, c) == -1)
-                       break;
+               nmeap_parse(context, c);
        }
 }