From: batt Date: Mon, 7 Jun 2010 17:44:45 +0000 (+0000) Subject: Fix sign related issues. X-Git-Tag: 2.5.0~21 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=52d65db7c052108ba5d004dc4687f938d6f3dc90;p=bertos.git Fix sign related issues. Altitude and decimal degrees positions can be negative! Without this patch, dangerous overflows can happen. Also fix some minor documentation issues. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3896 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/net/nmea.c b/bertos/net/nmea.c index 8fe3ad7e..d232c73a 100644 --- a/bertos/net/nmea.c +++ b/bertos/net/nmea.c @@ -165,9 +165,9 @@ static udegree_t nmea_longitude(const char *plot, const char *phem) * Return altitude in meter from a string. * */ -static uint16_t nmea_altitude(const char *palt, const char *punits) +static int32_t nmea_altitude(const char *palt, const char *punits) { - uint32_t alt; + int32_t alt; if (*palt == 0) return 0; diff --git a/bertos/net/nmea.h b/bertos/net/nmea.h index f735f6bf..f0a8b3de 100644 --- a/bertos/net/nmea.h +++ b/bertos/net/nmea.h @@ -58,37 +58,37 @@ #define NMEA_GPGSV 4 // GSV MESSAGE ID // Standart type to rappresent fiels. -typedef uint32_t udegree_t; // Micro degrees -typedef uint32_t mdegree_t; // Milli degrees -typedef uint16_t degree_t; // Degrees +typedef int32_t udegree_t; // Micro degrees +typedef int32_t mdegree_t; // Milli degrees +typedef int16_t degree_t; // Degrees /** * Global Positioning System Fix Data. * Extracted data from a GGA message * - * Note: time membert containt the second elapsed from 00:00:00 1/1/1970, - * becouse from nmea sentence we read only the time of UTC position, we - * not have any reference of date (day, month and year) so time is refered to + * Note: time member contains the seconds elapsed from 00:00:00 1/1/1970, + * because from nmea sentence we read only the time of UTC position, we + * have not any reference of date (day, month and year) so time is referred to * the start of unix time. */ typedef struct NmeaGga { udegree_t latitude; /* Latitude (micro degree) */ udegree_t longitude; /* Longitude (micro degree) */ - uint16_t altitude; /* Altitude (Meter) */ + int32_t altitude; /* Altitude (Meter) */ time_t time; /* UTC of position (Unix time) */ uint16_t satellites; /* Satellites are in view */ uint16_t quality; /* Fix Quality: 0 = Invalid; 1 = GPS fix; 2 = DGPS fix; */ uint16_t hdop; /* Relative accuracy of horizontal position (hdop * 10) */ - uint16_t geoid; /* Height of geoid above WGS84 ellipsoid (Meter) */ + int16_t geoid; /* Height of geoid above WGS84 ellipsoid (Meter) */ } NmeaGga; /** * Recommended minimum specific GPS/Transit data. * Extracted data from an RMC message * - * Note: RMC sentece contain also date stamp so, time contain real second elapsed + * Note: RMC sentences contain also date stamp so, time contains real seconds elapsed * from 0:00:00 1/1/1970. */ typedef struct NmeaRmc