mirror of
https://github.com/acaloiaro/roam-location
synced 2026-07-21 10:12:21 +00:00
Don't log unknown locations
This commit is contained in:
parent
a601d21edc
commit
7a7acd4e29
2 changed files with 32 additions and 0 deletions
26
nmea/location.go
Normal file
26
nmea/location.go
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
package nmea
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Location struct {
|
||||
Lat float64 `json:"lat"`
|
||||
Lon float64 `json:"lon"`
|
||||
}
|
||||
|
||||
// ParseLocation parses nmea sentences into Location structures
|
||||
func ParseLocation(nmeaSentence string) (l Location) {
|
||||
fields := strings.Split(nmeaSentence, ",")
|
||||
|
||||
if f, err := strconv.ParseFloat(fields[0], 64); err == nil {
|
||||
l.Lat = f
|
||||
}
|
||||
|
||||
if f, err := strconv.ParseFloat(fields[1], 64); err == nil {
|
||||
l.Lon = f
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
|
@ -58,6 +58,12 @@ func handlePacket(buf []byte, rlen int) {
|
|||
|
||||
func appendLog(lat, lon float64, nmeaSentence string) {
|
||||
row := fmt.Sprintf("%f,%f,%s\n", lat, lon, nmeaSentence)
|
||||
|
||||
// don't log unknown locations
|
||||
if lat == 0 || lon == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
if _, err := dbFile.WriteString(row); err != nil {
|
||||
log.Println("unable to write to database:", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue