[OpenWrt-Devel] [PATCH] ugps: Only convert lat and lon to negative after parsing

Giovani Espindola GEspindola at advantech-bb.com
Fri Oct 20 08:19:02 EDT 2017


This is a bugfix for package ugps.

Current code parses following GPRMC

$GPRMC,185834.0,A,2335.766399,S,04635.923564,W,0.0,,191017,0.0,E,A*20

as

position: -22.929440 -45.932056

with this fix it's being parsed correctly as

position: -23.596106 -46.598721


Signed-off-by: Giovani Milanez Espindola <gespindola at advantech-bb.com>

-------------- next part --------------
From 092b311a3c8911ce9da3f913787b77397e88b4a8 Mon Sep 17 00:00:00 2001
From: Giovani Espindola <gespindola at advantech-bb.com>
Date: Thu, 19 Oct 2017 15:54:05 -0200
Subject: [PATCH] Only convert lat and lon to negative after parsing

---
 nmea.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/nmea.c b/nmea.c
index 275f39f..1a3f94f 100644
--- a/nmea.c
+++ b/nmea.c
@@ -123,11 +123,6 @@ nmea_rmc_cb(void)
 		float lat = strtof(nmea_params[3].str, NULL);
 		float lon = strtof(nmea_params[5].str, NULL);
 
-		if (*nmea_params[4].str == 'S')
-			lat *= -1.0;
-		if (*nmea_params[6].str == 'W')
-			lon *= -1.0;
-
 		degrees = floor(lat / 100.0);
 		minutes = lat - (degrees * 100.0);
 	        lat = degrees + minutes / 60.0;
@@ -136,6 +131,11 @@ nmea_rmc_cb(void)
 		minutes = lon - (degrees * 100.0);
 		lon = degrees + minutes / 60.0;
 
+		if (*nmea_params[4].str == 'S')
+			lat *= -1.0;
+		if (*nmea_params[6].str == 'W')
+			lon *= -1.0;		
+
 		snprintf(latitude, sizeof(latitude), "%f", lat);
 		snprintf(longitude, sizeof(longitude), "%f", lon);
 
-- 
2.11.0

-------------- next part --------------
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list