Skip to content
Permalink
Browse files

GPS code now returns processed data

  • Loading branch information...
cbrake committed Apr 6, 2019
1 parent 910090c commit 8df0c4586739d1876fad09b61fe5e2f3e0640227
Showing with 36 additions and 4 deletions.
  1. +21 −0 data/gps.go
  2. +15 −4 gps/gps.go
@@ -0,0 +1,21 @@
package data

import (
nmea "github.com/adrianmo/go-nmea"
)

// GpsPos describes location and fix information from a GPS
type GpsPos struct {
Lat float64 `json:"lat"`
Long float64 `json:"long"`
Fix string `json:"fix"`
NumSat int64 `json:"numSat"`
}

// FromGPGGA converts a GPGGA string to a position/fix
func (p *GpsPos) FromGPGGA(gpgga nmea.GPGGA) {
p.Lat = float64(gpgga.Latitude)
p.Long = float64(gpgga.Longitude)
p.Fix = gpgga.FixQuality
p.NumSat = gpgga.NumSatellites
}
@@ -9,20 +9,21 @@ import (

nmea "github.com/adrianmo/go-nmea"
"github.com/cbrake/go-serial/serial"
"github.com/simpleiot/simpleiot/data"
)

// Gps represent a GPS receiver
type Gps struct {
portName string
baud uint
c chan nmea.Sentence
c chan data.GpsPos
debug bool
stop bool
port io.ReadWriteCloser
}

// NewGps is used to create a new Gps type
func NewGps(portName string, baud uint, c chan nmea.Sentence) *Gps {
func NewGps(portName string, baud uint, c chan data.GpsPos) *Gps {
return &Gps{
portName: portName,
baud: baud,
@@ -87,9 +88,19 @@ func (gps *Gps) Start() {
break
}

m, err := nmea.Parse(strings.TrimSpace(line))
s, err := nmea.Parse(strings.TrimSpace(line))
if err == nil {
gps.c <- m
if s.DataType() == nmea.TypeGGA {
m := s.(nmea.GGA)
ret := data.GpsPos{
Lat: m.Latitude,
Long: m.Longitude,
Fix: m.FixQuality,
NumSat: m.NumSatellites,
}

gps.c <- ret
}
} else {
if gps.debug {
fmt.Println("Error parsing GPS data: ", err)

0 comments on commit 8df0c45

Please sign in to comment.
You can’t perform that action at this time.