From 35b16835c29e0f857cc926fdbe085947d9c8d10a Mon Sep 17 00:00:00 2001 From: Adriano Caloiaro Date: Sun, 9 Aug 2020 19:28:22 -0600 Subject: [PATCH] Only return valid locations --- service/current_location.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/service/current_location.go b/service/current_location.go index 7daa9d3..1bd0980 100644 --- a/service/current_location.go +++ b/service/current_location.go @@ -57,7 +57,13 @@ func currentLocation(dbPath string) (location Location) { fileHandle.ReadAt(char, cursor) if cursor != -1 && (char[0] == '\n') { // stop if we find a line - break + parseNmeaSentence(line, &location) + + // break when a 'good' location has been found. This will usually be myst last known location. + // when the router is reporting 0 coordinates, it doesn't have a signal + if location.Lat != 0 || location.Lon != 0 { + break + } } line = fmt.Sprintf("%s%s", string(char), line) // there is more efficient way @@ -67,7 +73,11 @@ func currentLocation(dbPath string) (location Location) { } } - fields := strings.Split(line, ",") + return +} + +func parseNmeaSentence(sentence string, location *Location) { + fields := strings.Split(sentence, ",") if f, err := strconv.ParseFloat(fields[0], 64); err == nil { location.Lat = f @@ -76,9 +86,4 @@ func currentLocation(dbPath string) (location Location) { if f, err := strconv.ParseFloat(fields[1], 64); err == nil { location.Lon = f } - - return -} - -func main() { }