pull/182/head^2
Christopher Young 2015-12-29 17:00:59 -05:00
rodzic 052b4e2855
commit 60e143bd36
1 zmienionych plików z 153 dodań i 165 usunięć

Wyświetl plik

@ -169,7 +169,6 @@ func initGPSSerial() bool {
// Set 10Hz update. Little endian order.
p.Write(makeUBXCFG(0x06, 0x08, 6, []byte{0x64, 0x00, 0x01, 0x00, 0x01, 0x00}))
// Set navigation settings.
nav := make([]byte, 36)
nav[0] = 0x05 // Set dyn and fixMode only.
@ -180,7 +179,6 @@ func initGPSSerial() bool {
p.Write(makeUBXCFG(0x06, 0x24, 36, nav))
// GNSS configuration CFG-GNSS for ublox 7 higher, p. 125 (v8)
//
// NOTE: Max position rate = 5 Hz if GPS+GLONASS used.
@ -295,7 +293,7 @@ func validateNMEAChecksum(s string) (string, bool) {
s_out := s_split[0]
s_cs := s_split[1]
if (len(s_cs) < 2) {
if len(s_cs) < 2 {
return "Missing checksum. Fewer than two bytes after asterisk", false
}
@ -309,26 +307,24 @@ func validateNMEAChecksum(s string) (string, bool) {
cs_calc = cs_calc ^ byte(s_out[i])
}
if (cs_calc != byte(cs)) {
if cs_calc != byte(cs) {
return fmt.Sprintf("Checksum failed. Calculated %#X; expected %#X", cs_calc, cs), false
}
return s_out, true
}
func processNMEALine(l string) bool {
replayLog(l, MSGCLASS_GPS)
l_valid, validNMEAcs := validateNMEAChecksum(l)
if (!validNMEAcs) {
if !validNMEAcs {
log.Printf("GPS error. Invalid NMEA string: %s\n", l_valid) // remove log message once validation complete
return false
}
x := strings.Split(l_valid, ",")
if (x[0] == "PUBX") { // UBX proprietary message
if (x[1] == "00") { // position message
if x[0] == "PUBX" { // UBX proprietary message
if x[1] == "00" { // position message
if len(x) < 20 {
return false
}
@ -393,13 +389,13 @@ func processNMEALine(l string) bool {
// field 8 = nav status
// DR = dead reckoning, G2= 2D GPS, G3 = 3D GPS, D2= 2D diff, D3 = 3D diff, RK = GPS+DR, TT = time only
if (x[8] == "D2" || x[8] == "D3") {
if x[8] == "D2" || x[8] == "D3" {
mySituation.quality = 2
} else if (x[8] == "G2" || x[8] == "G3") {
} else if x[8] == "G2" || x[8] == "G3" {
mySituation.quality = 1
} else if (x[8] == "DR" || x[8] == "RK") {
} else if x[8] == "DR" || x[8] == "RK" {
mySituation.quality = 6
} else if (x[8] == "NF") {
} else if x[8] == "NF" {
mySituation.quality = 0
return false // return false if no valid fix.
} else {
@ -430,7 +426,6 @@ func processNMEALine(l string) bool {
mySituation.NACp = 0
}
// field 10 = vertical accuracy, m
vAcc, err := strconv.ParseFloat(x[10], 32)
if err != nil {
@ -438,7 +433,6 @@ func processNMEALine(l string) bool {
}
mySituation.AccuracyVert = float32(vAcc * 2) // UBX reports 1-sigma variation; we want 95% confidence
// field 11 = groundspeed, km/h
groundspeed, err := strconv.ParseFloat(x[11], 32)
if err != nil {
@ -469,8 +463,6 @@ func processNMEALine(l string) bool {
mySituation.GroundSpeed = uint16(groundspeed)
mySituation.LastGroundTrackTime = time.Now()
// field 13 = vertical velocity, m/s
vv, err := strconv.ParseFloat(x[13], 32)
if err != nil {
@ -478,11 +470,8 @@ func processNMEALine(l string) bool {
}
mySituation.GPSVertVel = float32(vv * -3.28084) // convert to ft/sec and positive = up
// field 14 = age of diff corrections
// field 18 = number of satellites
sat, err1 := strconv.Atoi(x[18])
if err1 != nil {
@ -492,7 +481,7 @@ func processNMEALine(l string) bool {
mySituation.LastFixLocalTime = time.Now()
} else if (x[1] == "03") { // satellite status message
} else if x[1] == "03" { // satellite status message
// field 2 = number of satellites tracked
satSeen := 0 // satellites seen (signal present)
@ -504,7 +493,7 @@ func processNMEALine(l string) bool {
// fields 3-8 are repeated block
for i := 0; i < satTracked; i++ {
if (x[7+6*i] != "") {
if x[7+6*i] != "" {
satSeen++
}
}
@ -512,7 +501,6 @@ func processNMEALine(l string) bool {
mySituation.SatellitesSeen = uint16(satSeen)
// log.Printf("Satellites with signal: %v\n",mySituation.SatellitesSeen)
/* Reference for future constellation tracking
for i:= 0; i < satTracked; i++ {
x[3+6*i] // sv number
@ -523,7 +511,7 @@ func processNMEALine(l string) bool {
x[8+6*i] // lock time, sec, 0-64
*/
} else if (x[1] == "04") { // clock message
} else if x[1] == "04" { // clock message
// field 2 is UTC time
if len(x[2]) < 9 {