Skip to content

Commit

Permalink
prepare GPS data
Browse files Browse the repository at this point in the history
  • Loading branch information
talkkonnect committed Jan 2, 2022
1 parent b3c3a2e commit e610080
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 57 deletions.
1 change: 0 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ var (
maxchannelid uint32
tmessage string
isrepeattx bool = true
m string
)

type Talkkonnect struct {
Expand Down
8 changes: 4 additions & 4 deletions commandkeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,15 +446,15 @@ func (b *Talkkonnect) cmdSendEmail() {
emailMessage = emailMessage + fmt.Sprintf("Mumble Username: %s \n", b.Username)

if Config.Global.Software.SMTP.GpsDateTime {
emailMessage = emailMessage + fmt.Sprintf("Date "+GPSDate+" UTC Time "+GPSTime+"\n")
emailMessage = emailMessage + fmt.Sprintf("Date "+GNSSData.Date+" UTC Time "+GNSSData.Time+"\n")
}

if Config.Global.Software.SMTP.GpsLatLong {
emailMessage = emailMessage + fmt.Sprintf("Latitude "+strconv.FormatFloat(GPSLatitude, 'f', 6, 64)+" Longitude "+strconv.FormatFloat(GPSLongitude, 'f', 6, 64)+"\n")
emailMessage = emailMessage + fmt.Sprintf("Latitude "+strconv.FormatFloat(GNSSData.Lattitude, 'f', 6, 64)+" Longitude "+strconv.FormatFloat(GNSSData.Longitude, 'f', 6, 64)+"\n")
}

if Config.Global.Software.SMTP.GoogleMapsURL {
emailMessage = emailMessage + "http://www.google.com/maps/place/" + strconv.FormatFloat(GPSLatitude, 'f', 6, 64) + "," + strconv.FormatFloat(GPSLongitude, 'f', 6, 64)
emailMessage = emailMessage + "http://www.google.com/maps/place/" + strconv.FormatFloat(GNSSData.Lattitude, 'f', 6, 64) + "," + strconv.FormatFloat(GNSSData.Longitude, 'f', 6, 64)
}

err := sendviagmail(Config.Global.Software.SMTP.Username, Config.Global.Software.SMTP.Password, Config.Global.Software.SMTP.Receiver, Config.Global.Software.SMTP.Subject, emailMessage)
Expand Down Expand Up @@ -667,7 +667,7 @@ func (b *Talkkonnect) cmdPanicSimulation() {

if goodGPSRead && i != tries {
log.Println("info: Sending GPS Info My Message")
gpsMessage := "My GPS Coordinates are " + fmt.Sprintf(" Latitude "+strconv.FormatFloat(GPSLatitude, 'f', 6, 64)) + fmt.Sprintf(" Longitude "+strconv.FormatFloat(GPSLongitude, 'f', 6, 64))
gpsMessage := "My GPS Coordinates are " + fmt.Sprintf(" Latitude "+strconv.FormatFloat(GNSSData.Lattitude, 'f', 6, 64)) + fmt.Sprintf(" Longitude "+strconv.FormatFloat(GNSSData.Longitude, 'f', 6, 64))
b.SendMessage(gpsMessage, Config.Global.Hardware.PanicFunction.RecursiveSendMessage)
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/talkkonnect/talkkonnect
go 1.17

require (
github.com/adrianmo/go-nmea v1.5.0
github.com/allan-simon/go-singleinstance v0.0.0-20210120080615-d0997106ab37
github.com/comail/colog v0.0.0-20160416085026-fba8e7b1f46c
github.com/eclipse/paho.mqtt.golang v1.3.5
Expand All @@ -13,7 +14,6 @@ require (
github.com/stianeikeland/go-rpio v4.2.0+incompatible
github.com/talkkonnect/go-hd44780 v0.0.0-20210824123606-f3398c777f39
github.com/talkkonnect/go-mcp23017 v0.0.0-20210831103122-1c46ab6c8c82
github.com/talkkonnect/go-nmea v0.0.0-20210719131409-1f6a4b9c6894
github.com/talkkonnect/go-oled-i2c v0.0.0-20190324002809-c9178f9ccd23
github.com/talkkonnect/go-openal v0.0.0-20181013102444-59f5b1d30aff
github.com/talkkonnect/gpio v0.0.0-20181225144829-9b8a2de8e6fe
Expand Down
13 changes: 9 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
github.com/adrianmo/go-nmea v1.5.0 h1:tTEmL+NYPFDB6eiqhBoiVFrIn9tQX5jSzZ+VfnWeInM=
github.com/adrianmo/go-nmea v1.5.0/go.mod h1:u8bPnpKt/D/5rll/5l9f6iDfeq5WZW0+/SXdkwix6Tg=
github.com/allan-simon/go-singleinstance v0.0.0-20210120080615-d0997106ab37 h1:28uU3TtuvQ6KRndxg9TrC868jBWmSKgh0GTXkACCXmA=
github.com/allan-simon/go-singleinstance v0.0.0-20210120080615-d0997106ab37/go.mod h1:6AXRstqK+32jeFmw89QGL2748+dj34Av4xc/I9oo9BY=
github.com/comail/colog v0.0.0-20160416085026-fba8e7b1f46c h1:bzYQ6WpR+t35/y19HUkolcg7SYeWZ15IclC9Z4naGHI=
github.com/comail/colog v0.0.0-20160416085026-fba8e7b1f46c/go.mod h1:1WwgAwMKQLYG5I2FBhpVx94YTOAuB2W59IZ7REjSE6Y=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/eclipse/paho.mqtt.golang v1.3.5 h1:sWtmgNxYM9P2sP+xEItMozsR3w0cqZFlqnNN1bdl41Y=
Expand Down Expand Up @@ -38,8 +41,9 @@ github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/stianeikeland/go-rpio v4.2.0+incompatible h1:CUOlIxdJdT+H1obJPsmg8byu7jMSECLfAN9zynm5QGo=
github.com/stianeikeland/go-rpio v4.2.0+incompatible/go.mod h1:Sh81rdJwD96E2wja2Gd7rrKM+XZ9LrwvN2w4IXrqLR8=
github.com/stretchr/testify v1.2.1 h1:52QO5WkIUcHGIR7EnGagH88x1bUzqGXTC5/1bDTUQ7U=
github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/talkkonnect/embd v0.0.0-20210824124053-e127c37e1577 h1:bihz9UL2bBgp4WQpbXjFtcQj5q7iOtmRELXcxM4bPlQ=
github.com/talkkonnect/embd v0.0.0-20210824124053-e127c37e1577/go.mod h1:yEIQ+VcMM5dw+3yR4/bGAh81Dre39uSQvvN62qm/VLA=
github.com/talkkonnect/go-hd44780 v0.0.0-20210824123606-f3398c777f39 h1:8BrBXtXo8Dt5ogGG/VvCrA32X92CVuT8l4/jNF3JYjE=
Expand All @@ -50,8 +54,6 @@ github.com/talkkonnect/go-logger v0.0.0-20190316101244-635f8e12dd6c h1:kbjUEvovC
github.com/talkkonnect/go-logger v0.0.0-20190316101244-635f8e12dd6c/go.mod h1:RgJ9bxHte2cnbimoMDr7NNLOxYWiBgYAnf67OzucsMw=
github.com/talkkonnect/go-mcp23017 v0.0.0-20210831103122-1c46ab6c8c82 h1:VgA8XaXnDBytA2zVv94AXp3WAyQOBW/SNaTXjZco1Qc=
github.com/talkkonnect/go-mcp23017 v0.0.0-20210831103122-1c46ab6c8c82/go.mod h1:9+q2vdqRNwz4tVg3K77nwUT2ePfkrrRWX+xy8u7lE6A=
github.com/talkkonnect/go-nmea v0.0.0-20210719131409-1f6a4b9c6894 h1:G1nlV2WxU5Q1tkqIRpAM7QdGCxdnbgD8HH+zCBZbEU4=
github.com/talkkonnect/go-nmea v0.0.0-20210719131409-1f6a4b9c6894/go.mod h1:d/3MpsW0wdx2ZXQVxj92RRr1YnuJ9bVPengVHw2QKEw=
github.com/talkkonnect/go-oled-i2c v0.0.0-20190324002809-c9178f9ccd23 h1:zlIQLLPf2w5EOMm2hO9i7z+QZ6paAKCfW8C/7IqHti0=
github.com/talkkonnect/go-oled-i2c v0.0.0-20190324002809-c9178f9ccd23/go.mod h1:zdbvJKE9p2OJ3XMlb0X7YYD8GNPMILwDebKZH9OvMi8=
github.com/talkkonnect/go-openal v0.0.0-20181013102444-59f5b1d30aff h1:Cdwko65/+E0ABkBIlkk8VPIKdH4gaOauhm56vMmdjwU=
Expand Down Expand Up @@ -83,5 +85,8 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
periph.io/x/periph v3.6.8+incompatible h1:lki0ie6wHtvlilXhIkabdCUQMpb5QN4Fx33yNQdqnaA=
periph.io/x/periph v3.6.8+incompatible/go.mod h1:EWr+FCIU2dBWz5/wSWeiIUJTriYv9v2j2ENBmgYyy7Y=
149 changes: 104 additions & 45 deletions gps.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,49 @@ import (
"log"

"github.com/jacobsa/go-serial/serial"
"github.com/talkkonnect/go-nmea"
"github.com/adrianmo/go-nmea"
)

//GPS Related Global Variables
type GSVDataStruct struct {
PRNNumber int64
SNR int64
Azimuth int64
Elevation int64
}

type GNSSDataStruct struct {
Time string
Validity string
Lattitude float64
Longitude float64
Speed float64
Course float64
Date string
Variation float64
FixQuality string
SatsInUse int64
SatsInView int64
GSVData [4]GSVDataStruct
}

var (
GPSTime string
GPSDate string
GPSLatitude float64
GPSLongitude float64
GPSSpeed float64
GPSCourse float64
GPSVariation float64
RMCSentenceValid bool
GGASentenceValid bool
GSVSentenceValid bool
goodGPSRead bool
GNSSData GNSSDataStruct
)

var goodGPSRead bool = false

func getGpsPosition(verbose bool) (bool, error) {
RMCSentenceValid = false
GGASentenceValid = false
GSVSentenceValid = false
goodGPSRead = false

if Config.Global.Hardware.GPS.Enabled {

if Config.Global.Hardware.GPS.Port == "" {
return false, errors.New("You Must Specify Port")
return false, errors.New("gnss port not specified")
}

if Config.Global.Hardware.GPS.Even && Config.Global.Hardware.GPS.Odd {
Expand Down Expand Up @@ -89,7 +111,7 @@ func getGpsPosition(verbose bool) (bool, error) {

if err != nil {
Config.Global.Hardware.GPS.Enabled = false
return false, errors.New("Cannot Open Serial Port")
return false, errors.New("cannot open serial port")
} else {
defer f.Close()
}
Expand All @@ -99,17 +121,17 @@ func getGpsPosition(verbose bool) (bool, error) {

if err != nil {
Config.Global.Hardware.GPS.Enabled = false
return false, errors.New("Cannot Decode Hex Data")
return false, errors.New("cannot decode hex data")
}

log.Println("Sending: ", hex.EncodeToString(txData_))

count, err := f.Write(txData_)

if err != nil {
return false, errors.New("Error writing to serial port")
return false, errors.New("error writing to serial port")
} else {
log.Println("Wrote %v bytes\n", count)
log.Printf("Wrote %v bytes\n", count)
}

}
Expand All @@ -125,46 +147,83 @@ func getGpsPosition(verbose bool) (bool, error) {
reader := bufio.NewReader(serialPort)
scanner := bufio.NewScanner(reader)

goodGPSRead = false
for scanner.Scan() {
s, err := nmea.Parse(scanner.Text())

if err == nil {
if s.DataType() == nmea.TypeRMC {
m := s.(nmea.RMC)
if m.Latitude != 0 && m.Longitude != 0 {
goodGPSRead = true
GPSTime = fmt.Sprintf("%v", m.Time)
GPSDate = fmt.Sprintf("%v", m.Date)
GPSLatitude = m.Latitude
GPSLongitude = m.Longitude
if verbose {
log.Println("info: Raw Sentence ", m)
log.Println("info: Time: ", m.Time)
log.Println("info: Validity: ", m.Validity)
log.Println("info: Latitude GPS: ", nmea.FormatGPS(m.Latitude))
log.Println("info: Latitude DMS: ", nmea.FormatDMS(m.Latitude))
log.Println("info: Longitude GPS: ", nmea.FormatGPS(m.Longitude))
log.Println("info: Longitude DMS: ", nmea.FormatDMS(m.Longitude))
log.Println("info: Speed: ", m.Speed)
log.Println("info: Course: ", m.Course)
log.Println("info: Date: ", m.Date)
log.Println("info: Variation: ", m.Variation)

switch s.DataType() {

case nmea.TypeRMC:
{
m := s.(nmea.RMC)
if m.Latitude != 0 && m.Longitude != 0 && !RMCSentenceValid {
RMCSentenceValid = true
GNSSData.Date = fmt.Sprintf("%v", m.Date)
GNSSData.Time = fmt.Sprintf("%v", m.Time)
GNSSData.Validity = fmt.Sprintf("%v", m.Validity)
GNSSData.Lattitude = m.Latitude
GNSSData.Longitude = m.Longitude
GNSSData.Speed = m.Speed
GNSSData.Course = m.Course
GNSSData.Variation = m.Variation

}
}
case nmea.TypeGGA:
{
m := s.(nmea.GGA)
if m.Latitude != 0 && m.Longitude != 0 && !GGASentenceValid {
GGASentenceValid = true
GNSSData.FixQuality = m.FixQuality
GNSSData.SatsInUse = m.NumSatellites
}
}

case nmea.TypeGSV:
{
m := s.(nmea.GSV)

for i := range m.Info {
if m.Info[i].SNR > 0 && !GSVSentenceValid {
GNSSData.GSVData[i].PRNNumber = s.(nmea.GSV).Info[i].SVPRNNumber
GNSSData.GSVData[i].SNR = s.(nmea.GSV).Info[i].SNR
GNSSData.GSVData[i].Azimuth = s.(nmea.GSV).Info[i].Azimuth
GNSSData.GSVData[i].Elevation = s.(nmea.GSV).Info[i].Elevation
if i >= 3 {
GSVSentenceValid = true
GNSSData.SatsInView = m.NumberSVsInView
}
}
}
break
} else {
log.Println("warn: Got Latitude 0 and Longtitude 0 from GPS")
}
} else {
log.Println("warn: GPS Sentence Format Was not nmea.RMC")
}
}
}
if RMCSentenceValid && GGASentenceValid && GSVSentenceValid {
goodGPSRead = true
log.Println("info: RMC Date ", GNSSData.Date)
log.Println("info: RMC Time ", GNSSData.Time)
log.Println("info: RMC Validity ", GNSSData.Validity)
log.Println("info: RMC Latitude DMS ", GNSSData.Longitude)
log.Println("info: RMC Longitude DMS ", GNSSData.Lattitude)
log.Println("info: RMC Speed ", GNSSData.Speed)
log.Println("info: RMC Course ", GNSSData.Course)
log.Println("info: RMC Variation ", GNSSData.Variation)
log.Println("info: GGA GPS Quality Indicator ", GNSSData.FixQuality)
log.Println("info: GGA No of Satellites in Use ", GNSSData.SatsInUse)
log.Println("info: GSV No of Satellites View ", GNSSData.SatsInView)
for i := range GNSSData.GSVData {
log.Println("info: GSV SVPRNNumber Satellite ", i, " ", GNSSData.GSVData[i].PRNNumber)
log.Println("info: GSV SNR Satellite ", i, " ", GNSSData.GSVData[i].SNR)
log.Println("info: GSV Azimuth Satellite ", i, " ", GNSSData.GSVData[i].Azimuth)
log.Println("info: GSV Elevation Satellite ", i, " ", GNSSData.GSVData[i].Elevation)
}
}
} else {
return false, errors.New("Rx Not Set")
return false, errors.New("error parsing gnss module")
}

return goodGPSRead, nil
}
return false, errors.New("GPS Not Enabled")
return false, errors.New("gnss not enabled")
}
4 changes: 2 additions & 2 deletions xmlparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ import (
)

const (
talkkonnectVersion string = "2.07.01"
talkkonnectReleased string = "Dec 31 2021"
talkkonnectVersion string = "2.07.02"
talkkonnectReleased string = "Jan 02 2022"
)

type ConfigStruct struct {
Expand Down

0 comments on commit e610080

Please sign in to comment.