From 6458edb901be6107455b9fecbdf0b7c82eae15ab Mon Sep 17 00:00:00 2001 From: José Bollo Date: Fri, 8 Jul 2016 09:32:20 +0200 Subject: fix angle measurement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I63ed2e6001f1cfedf82e527667d56a7787934315 Signed-off-by: José Bollo --- src/af-gps-binding.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/af-gps-binding.c b/src/af-gps-binding.c index 602ed91..cd9d021 100644 --- a/src/af-gps-binding.c +++ b/src/af-gps-binding.c @@ -125,6 +125,7 @@ static int nmea_time(const char *text, uint32_t *result) static int nmea_angle(const char *text, double *result) { uint32_t x = 0; + double v; int dotidx = (int)(strchrnul(text, '.') - text); switch(dotidx) { @@ -141,23 +142,19 @@ static int nmea_angle(const char *text, double *result) return 0; x = x * 10 + (uint32_t)(text[dotidx - 3] - '0'); case 2: - if (text[dotidx - 2] < '0' || text[dotidx - 2] > '9') - return 0; - x = x * 6 + (uint32_t)(text[dotidx - 3] - '0'); + v = atof(&text[dotidx - 2]); + break; case 1: if (text[dotidx - 1] < '0' || text[dotidx - 1] > '9') return 0; - x = x * 10 + (uint32_t)(text[dotidx - 3] - '0'); case 0: + v = atof(text); break; default: return 0; } - if (text[dotidx] == '.') - *result = atof(&text[dotidx]) + x; - else - *result = x; + *result = (double)x + v * 0.01666666666666666666666; return 1; } -- cgit 1.2.3-korg