Fixed NMEA report parsing.
This commit is contained in:
parent
9bc94bfe7c
commit
e2e02ebbfe
@ -22,9 +22,14 @@ func (g *gps) CheckStatus() error {
|
||||
// asc := 0 // Active satelites' counter
|
||||
checkLoop:
|
||||
for _, s := range reports {
|
||||
// Check for NMEA format
|
||||
if len(s) < 1 || s[0] != '$' {
|
||||
continue checkLoop
|
||||
}
|
||||
|
||||
g.logger.Println("NMEA check:", s)
|
||||
values := strings.Split(s, ",")
|
||||
if len(values) < 1 || len(values[0]) != 6 || values[0][0] != '$' {
|
||||
if len(values[0]) != 6 {
|
||||
return fmt.Errorf("nmea invalid sentence: %s", s)
|
||||
}
|
||||
switch values[0][3:] { // Switch by content
|
||||
|
@ -146,11 +146,15 @@ func (g *gps) collectNmeaReports(flags nmeaFlags) ([]string, error) {
|
||||
// OK
|
||||
// (NMEA sentence)...
|
||||
// OK
|
||||
if len(strs) < 2 {
|
||||
return nil, fmt.Errorf("responce too few rows: %d", len(strs))
|
||||
}
|
||||
if !(strs[0] == "OK" && strs[len(strs)-1] == "OK") {
|
||||
return nil, fmt.Errorf("not OK responce: [% s]", strs)
|
||||
}
|
||||
return strs[1 : len(strs)-1], nil
|
||||
// if len(strs) < 2 {
|
||||
// return nil, fmt.Errorf("responce too few rows: %d", len(strs))
|
||||
// }
|
||||
// if !(strs[0] == "OK" && strs[len(strs)-1] == "OK") {
|
||||
// return nil, fmt.Errorf("not OK responce: [% s]", strs)
|
||||
// }
|
||||
|
||||
// This... response is not stable
|
||||
// Every time it gives one or two OK and in ramdom order
|
||||
// So I will not check gor it
|
||||
return strs, nil
|
||||
}
|
||||
|
@ -230,8 +230,7 @@ func (c *conn) Ping() bool {
|
||||
}
|
||||
c.logger.Println("Ping 2 resp:", string(resp))
|
||||
|
||||
|
||||
return !strings.Contains(string(resp), "Destination Host Unreachable") // tmp solution
|
||||
return !(strings.Contains(string(resp), "Destination Host Unreachable") || strings.Contains(string(resp), "Destination Net Unreachable")) // tmp solution
|
||||
}
|
||||
|
||||
func (c *conn) Close() error {
|
||||
|
Loading…
Reference in New Issue
Block a user