26using namespace rusefi::stringutil;
28static long hex2int(
const char * a,
const int len) {
32 for (i = 0; i < len; i++)
34 val += (a[i] - 48) * (1 << (4 * (len - 1 - i)));
36 val += (a[i] - 87) * (1 << (4 * (len - 1 - i)));
42 float sec = modff(deg_point, &ddeg) * 60;
43 int deg = (int) (ddeg / 100);
44 int min = (int) (deg_point - (deg * 100));
46 float absdlat = round(deg * 1000000.);
47 float absmlat = round(min * 1000000.);
48 float absslat = round(sec * 1000000.);
50 return round(absdlat + (absmlat / 60) + (absslat / 3600)) / 1000000;
55 float lat = (ns ==
'N') ? *latitude : -1 * (*latitude);
56 float lon = (we ==
'E') ? *longitude : -1 * (*longitude);
65 int i = 0, sLen = strlen(a);
66 if (sLen > GPS_MAX_STRING)
67 sLen = GPS_MAX_STRING;
69 while (i < sLen && a[i] != 44) {
96 char const * p = (
char *)nmea;
97 char dStr[GPS_MAX_STRING];
99 p = strchr(p,
',') + 1;
101 p = strchr(p,
',') + 1;
103 if (strlen(p) == 0) {
109 p = strchr(p,
',') + 1;
122 p = strchr(p,
',') + 1;
126 p = strchr(p,
',') + 1;
139 p = strchr(p,
',') + 1;
143 p = strchr(p,
',') + 1;
147 p = strchr(p,
',') + 1;
149 p = strchr(p,
',') + 1;
173 char const * p = (
char *)nmea;
174 char dStr[GPS_MAX_STRING];
177 p = strchr(p,
',') + 1;
179 if (strlen(dStr) > 5) {
185 p = strchr(p,
',') + 1;
188 if (dStr[0] ==
'V') {
195 p = strchr(p,
',') + 1;
199 p = strchr(p,
',') + 1;
212 p = strchr(p,
',') + 1;
216 p = strchr(p,
',') + 1;
229 p = strchr(p,
',') + 1;
231 loc->
speed = atoff(dStr);
233 p = strchr(p,
',') + 1;
235 loc->
course = atoff(dStr);
237 p = strchr(p,
',') + 1;
239 if (strlen(dStr) > 5) {
247 memcpy(&loc->
time, &dt,
sizeof(dt));
261 if (checksum != _EMPTY) {
265 if (strstr(message, NMEA_GPGGA_STR) != NULL) {
269 if (strstr(message, NMEA_GPRMC_STR) != NULL) {
279 const char* starPtr = strrchr(message,
'*');
281 return NMEA_CHECKSUM_ERR;
283 const char* int_message = starPtr + 1;
284 long checksum =
hex2int(int_message, 2);
287 while ((p = *message++) !=
'*') {
291 if (sum != checksum) {
292 return NMEA_CHECKSUM_ERR;
301 switch (coord->
type) {
static int str_till_comma(const char *const a, char *const dStr)
static void nmea_parse_gprmc(char const *const nmea, loc_t *loc)
static void nmea_parse_gpgga(char const *const nmea, loc_t *loc)
void gps_location(loc_t *coord, char const *const buffer)
static float gps_deg_dec(float deg_point)
static long hex2int(const char *a, const int len)
int nmea_valid_checksum(char const *message)
nmea_message_type nmea_get_message_type(const char *message)
static void gps_convert_deg_to_dec(float *latitude, char ns, float *longitude, char we)
static int str2int(const char *a, const int len)
static BigBufferHandle buffer