X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fnet%2Fnmea.c;h=d3937282df9b83b01a26f6c8936c49cfb6b76c56;hb=aef5ae9c57a34a342c7a6c83ece45ee77483ef0d;hp=11dcf374b2fa108cb7d1cbdf620364d426897e91;hpb=47dfe44ebab1698c1dee6757b6ce0f19b5e030a3;p=bertos.git diff --git a/bertos/net/nmea.c b/bertos/net/nmea.c index 11dcf374..d3937282 100644 --- a/bertos/net/nmea.c +++ b/bertos/net/nmea.c @@ -33,6 +33,7 @@ * * \author Daniele Basile * + * notest:avr */ #include "nmea.h" @@ -76,23 +77,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 +116,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 +133,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) @@ -181,7 +178,7 @@ static time_t timestampToSec(uint32_t time_stamp, uint32_t date_stamp) memset(&tmr, 0, sizeof(tmr)); memset(&date, 0, sizeof(date)); - LOG_INFO("time_s[%u],date[%u]\n", time_stamp, date_stamp); + LOG_INFO("time_s[%lu],date[%lu]\n", (long)time_stamp, (long)date_stamp); uint32_t res = time_stamp / 1000; uint32_t all = time_stamp; msec = all - res * 1000;