From 2721beeab87b2c99553f1ab2c3b4bc6dedb72cc1 Mon Sep 17 00:00:00 2001 From: Jason McNew Date: Thu, 1 Dec 2016 16:25:15 +0000 Subject: [PATCH 1/5] Reworks gpsd helper functions. SKY reports should already be using PRN so remove NMEA conversion. --- main/gpsd.go | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/main/gpsd.go b/main/gpsd.go index a57805b5..dc865ca5 100644 --- a/main/gpsd.go +++ b/main/gpsd.go @@ -8,18 +8,31 @@ import ( "sync" ) -func getNMEAName(sv int) string { - // GPS NMEA = PRN. GLONASS NMEA = PRN + 65. SBAS is PRN; needs to be converted to NMEA for compatiblity with GSV messages. - if sv < 33 { // indicates GPS - return fmt.Sprintf("G%d", sv) - } else if sv < 65 { // indicates SBAS: WAAS, EGNOS, MSAS, etc. - return fmt.Sprintf("S%d", sv+87) // add 87 to convert from NMEA to PRN. - } else if sv < 97 { // GLONASS - return fmt.Sprintf("R%d", sv-64) // subtract 64 to convert from NMEA to PRN. - } else if (sv >= 120) && (sv < 162) { // indicates SBAS: WAAS, EGNOS, MSAS, etc. - return fmt.Sprintf("S%d", sv) - } else { // TO-DO: Galileo - return fmt.Sprintf("U%d", sv) +// Determine type of satellite based on PRN number. +func satelliteType(prnId int) uint8 { + // TODO: Galileo + switch { + case 0 < prnId && prnId <= 32: + return SAT_TYPE_GPS + case 32 < prnId && prnId <= 64: + // This is actually the NMEA id range for SBAS: WAAS, EGNOS, MSAS, etc. + return SAT_TYPE_SBAS + case 64 < prnId && prnId <= 96: + return SAT_TYPE_GLONASS + case 120 <= prnId && prnId <= 138: + return SAT_TYPE_SBAS + default: + return SAT_TYPE_UNKNOWN + } +} + +func satelliteTypeCode(satType uint8) string { + switch satType { + case SAT_TYPE_GPS: return "G" + case SAT_TYPE_SBAS: return "S" + case SAT_TYPE_GLONASS: return "R" + case SAT_TYPE_UNKNOWN: return "U" + default: return "U" } } @@ -107,7 +120,8 @@ func processSKY(r interface{}) { for _, satellite := range sky.Satellites { var thisSatellite SatelliteInfo - thisSatellite.SatelliteID = getNMEAName(int(satellite.PRN)) // fmt.Sprintf("%v", satellite.PRN) + thisSatellite.Type = satelliteType(int(satellite.PRN)) + thisSatellite.SatelliteID = fmt.Sprint(satelliteTypeCode(thisSatellite.Type), int(satellite.PRN)) thisSatellite.Azimuth = int16(satellite.Az) thisSatellite.Elevation = int16(satellite.El) thisSatellite.Signal = int8(satellite.Ss) From b0050365af0a0ded862eea58af680b5152ab2672 Mon Sep 17 00:00:00 2001 From: Jason McNew Date: Fri, 2 Dec 2016 13:05:57 +0000 Subject: [PATCH 2/5] Rename SatelliteNMEA to Prn, reflecting actual usage. --- main/ry835ai.go | 8 ++++---- web/plates/gps.html | 6 +++--- web/plates/js/gps.js | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/main/ry835ai.go b/main/ry835ai.go index 715740bb..ba5a37c2 100644 --- a/main/ry835ai.go +++ b/main/ry835ai.go @@ -40,7 +40,7 @@ const ( ) type SatelliteInfo struct { - SatelliteNMEA uint8 // NMEA ID of the satellite. 1-32 is GPS, 33-54 is SBAS, 65-88 is Glonass. + Prn uint8 // PRN ID of the satellite. 1-32 is GPS, 65-88 is Glonass, 120-138 is SBAS SatelliteID string // Formatted code indicating source and PRN code. e.g. S138==WAAS satellite 138, G2==GPS satellites 2 Elevation int16 // Angle above local horizon, -xx to +90 Azimuth int16 // Bearing (degrees true), 0-359 @@ -716,7 +716,7 @@ func processNMEALine(l string) (sentenceUsed bool) { //log.Printf("UBX,03: Satellite %s already seen. Retrieving from 'Satellites'.\n", svStr) // DEBUG } else { // this satellite isn't in the Satellites data structure thisSatellite.SatelliteID = svStr - thisSatellite.SatelliteNMEA = uint8(sv) + thisSatellite.Prn = uint8(sv) thisSatellite.Type = uint8(svType) //log.Printf("UBX,03: Creating new satellite %s\n", svStr) // DEBUG } @@ -1125,7 +1125,7 @@ func processNMEALine(l string) (sentenceUsed bool) { //log.Printf("Satellite %s already seen. Retrieving from 'Satellites'.\n", svStr) } else { // this satellite isn't in the Satellites data structure, so create it thisSatellite.SatelliteID = svStr - thisSatellite.SatelliteNMEA = uint8(sv) + thisSatellite.Prn = uint8(sv) thisSatellite.Type = uint8(svType) //log.Printf("Creating new satellite %s from GSA message\n", svStr) // DEBUG } @@ -1250,7 +1250,7 @@ func processNMEALine(l string) (sentenceUsed bool) { //log.Printf("Satellite %s already seen. Retrieving from 'Satellites'.\n", svStr) // DEBUG } else { // this satellite isn't in the Satellites data structure, so create it new thisSatellite.SatelliteID = svStr - thisSatellite.SatelliteNMEA = uint8(sv) + thisSatellite.Prn = uint8(sv) thisSatellite.Type = uint8(svType) //log.Printf("Creating new satellite %s\n", svStr) // DEBUG } diff --git a/web/plates/gps.html b/web/plates/gps.html index d1408f7a..604e4ff1 100755 --- a/web/plates/gps.html +++ b/web/plates/gps.html @@ -63,16 +63,16 @@
Satellite - + Elevation Azimuth Signal
-
+
{{satellite.SatelliteID}} ✅ - + {{satellite.Elevation < -5 ? "---" : satellite.Elevation}}° {{satellite.Azimuth < 0 ? "---" : satellite.Azimuth}}° {{satellite.Signal < 1 ? "---" : satellite.Signal}} dB-Hz diff --git a/web/plates/js/gps.js b/web/plates/js/gps.js index 37e7dd73..57b5045b 100755 --- a/web/plates/js/gps.js +++ b/web/plates/js/gps.js @@ -129,7 +129,7 @@ function GPSCtrl($rootScope, $scope, $state, $http, $interval) { }; function setSatellite(obj, new_satellite) { - new_satellite.SatelliteNMEA = obj.SatelliteNMEA; + new_satellite.Prn = obj.Prn; new_satellite.SatelliteID = obj.SatelliteID; // Formatted code indicating source and PRN code. e.g. S138==WAAS satellite 138, G2==GPS satellites 2 new_satellite.Elevation = obj.Elevation; // Angle above local horizon, -xx to +90 new_satellite.Azimuth = obj.Azimuth; // Bearing (degrees true), 0-359 From 91377b1db8874c92845ba2021a3d6afeeb3cc343 Mon Sep 17 00:00:00 2001 From: Jason McNew Date: Fri, 2 Dec 2016 13:09:27 +0000 Subject: [PATCH 3/5] Populate Prn field from gpsd --- main/gpsd.go | 1 + 1 file changed, 1 insertion(+) diff --git a/main/gpsd.go b/main/gpsd.go index dc865ca5..aa6a8289 100644 --- a/main/gpsd.go +++ b/main/gpsd.go @@ -122,6 +122,7 @@ func processSKY(r interface{}) { var thisSatellite SatelliteInfo thisSatellite.Type = satelliteType(int(satellite.PRN)) thisSatellite.SatelliteID = fmt.Sprint(satelliteTypeCode(thisSatellite.Type), int(satellite.PRN)) + thisSatellite.Prn = uint8(satellite.PRN) thisSatellite.Azimuth = int16(satellite.Az) thisSatellite.Elevation = int16(satellite.El) thisSatellite.Signal = int8(satellite.Ss) From e28e7d3fa11ab65270d8946ce8a9e6e63e912f59 Mon Sep 17 00:00:00 2001 From: Jason McNew Date: Fri, 2 Dec 2016 17:28:30 +0000 Subject: [PATCH 4/5] Look for SBAS satellites in solution to set fix quality. --- main/gpsd.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/main/gpsd.go b/main/gpsd.go index aa6a8289..11fb68dc 100644 --- a/main/gpsd.go +++ b/main/gpsd.go @@ -36,6 +36,16 @@ func satelliteTypeCode(satType uint8) string { } } +// Caller must protect Satellites with satelliteMutex. +func isSbasInSolution() bool { + for _, satellite := range Satellites { + if(satellite.Type == SAT_TYPE_SBAS && satellite.InSolution) { + return true + } + } + return false +} + func processDEVICES(r interface{}) { devices := r.(*gpsd.DEVICESReport) log.Printf("DEVICES (%d)", len(devices.Devices)) @@ -66,12 +76,14 @@ func processTPV(r interface{}) { log.Printf("TPV", tpv.Device, tpv.Mode, tpv.Time, tpv.Tag) mySituation.mu_GPS.Lock() + satelliteMutex.Lock() defer func() { if globalSettings.DEBUG { logSituation() } mySituation.mu_GPS.Unlock() + satelliteMutex.Unlock() }() // 0 = No gps data, 1 = No fix, 2 = 2D fix, 3 = 3D fix @@ -88,7 +100,12 @@ func processTPV(r interface{}) { return } - mySituation.Quality = 1 + if(isSbasInSolution()) { + mySituation.Quality = 2 + } else { + mySituation.Quality = 1 + } + mySituation.Alt = float32(tpv.Alt) * 3.28084 // meters to feet mySituation.AccuracyVert = float32(tpv.Epv) mySituation.GPSVertVel = float32(tpv.Climb) From 257264bba81ebfe5d54afa16dbdd6d18a9fea065 Mon Sep 17 00:00:00 2001 From: Jason McNew Date: Fri, 2 Dec 2016 17:33:40 +0000 Subject: [PATCH 5/5] Fix go fmt format --- main/gpsd.go | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/main/gpsd.go b/main/gpsd.go index 11fb68dc..4176d129 100644 --- a/main/gpsd.go +++ b/main/gpsd.go @@ -28,22 +28,27 @@ func satelliteType(prnId int) uint8 { func satelliteTypeCode(satType uint8) string { switch satType { - case SAT_TYPE_GPS: return "G" - case SAT_TYPE_SBAS: return "S" - case SAT_TYPE_GLONASS: return "R" - case SAT_TYPE_UNKNOWN: return "U" - default: return "U" + case SAT_TYPE_GPS: + return "G" + case SAT_TYPE_SBAS: + return "S" + case SAT_TYPE_GLONASS: + return "R" + case SAT_TYPE_UNKNOWN: + return "U" + default: + return "U" } } // Caller must protect Satellites with satelliteMutex. func isSbasInSolution() bool { - for _, satellite := range Satellites { - if(satellite.Type == SAT_TYPE_SBAS && satellite.InSolution) { - return true - } - } - return false + for _, satellite := range Satellites { + if satellite.Type == SAT_TYPE_SBAS && satellite.InSolution { + return true + } + } + return false } func processDEVICES(r interface{}) { @@ -100,7 +105,7 @@ func processTPV(r interface{}) { return } - if(isSbasInSolution()) { + if isSbasInSolution() { mySituation.Quality = 2 } else { mySituation.Quality = 1