From 963840915bff15963466aa928e7f7a2da443ff78 Mon Sep 17 00:00:00 2001 From: evilsocket Date: Thu, 7 Mar 2019 10:29:17 +0100 Subject: [PATCH] new: parsing gps GPGGA messages other than just GNGGA (fixes #473) --- modules/gps/gps.go | 25 ++++++++++++++++++------- session/session.go | 7 ++++++- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/modules/gps/gps.go b/modules/gps/gps.go index 35a8eff6..2734a3b4 100644 --- a/modules/gps/gps.go +++ b/modules/gps/gps.go @@ -106,12 +106,21 @@ func (mod *GPS) readLine() (line string, err error) { } func (mod *GPS) Show() error { - fmt.Printf("latitude:%f longitude:%f quality:%s satellites:%d altitude:%f\n", - mod.Session.GPS.Latitude, - mod.Session.GPS.Longitude, - mod.Session.GPS.FixQuality, - mod.Session.GPS.NumSatellites, - mod.Session.GPS.Altitude) + if mod.Session.GPS.GNGGA.Time.Valid { + fmt.Printf("latitude:%f longitude:%f quality:%s satellites:%d altitude:%f\n", + mod.Session.GPS.GNGGA.Latitude, + mod.Session.GPS.GNGGA.Longitude, + mod.Session.GPS.GNGGA.FixQuality, + mod.Session.GPS.GNGGA.NumSatellites, + mod.Session.GPS.GNGGA.Altitude) + } else { + fmt.Printf("latitude:%f longitude:%f quality:%s satellites:%d altitude:%f\n", + mod.Session.GPS.GPGGA.Latitude, + mod.Session.GPS.GPGGA.Longitude, + mod.Session.GPS.GPGGA.FixQuality, + mod.Session.GPS.GPGGA.NumSatellites, + mod.Session.GPS.GPGGA.Altitude) + } mod.Session.Refresh() @@ -132,7 +141,9 @@ func (mod *GPS) Start() error { if s, err := nmea.Parse(line); err == nil { // http://aprs.gids.nl/nmea/#gga if m, ok := s.(nmea.GNGGA); ok { - mod.Session.GPS = m + mod.Session.GPS.GNGGA = m + } else if m, ok := s.(nmea.GPGGA); ok { + mod.Session.GPS.GPGGA = m } } else { mod.Debug("error parsing line '%s': %s", line, err) diff --git a/session/session.go b/session/session.go index 65da22be..b2befd2f 100644 --- a/session/session.go +++ b/session/session.go @@ -73,6 +73,11 @@ func (mm ModuleList) MarshalJSON() ([]byte, error) { return json.Marshal(mods) } +type GPS struct { + GNGGA nmea.GNGGA + GPGGA nmea.GPGGA +} + type Session struct { Options core.Options `json:"options"` Interface *network.Endpoint `json:"interface"` @@ -85,7 +90,7 @@ type Session struct { Queue *packets.Queue `json:"packets"` StartedAt time.Time `json:"started_at"` Active bool `json:"active"` - GPS nmea.GNGGA `json:"gps"` + GPS GPS `json:"gps"` Modules ModuleList `json:"modules"` Input *readline.Instance `json:"-"`