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
|
// asc := 0 // Active satelites' counter
|
||||||
checkLoop:
|
checkLoop:
|
||||||
for _, s := range reports {
|
for _, s := range reports {
|
||||||
|
// Check for NMEA format
|
||||||
|
if len(s) < 1 || s[0] != '$' {
|
||||||
|
continue checkLoop
|
||||||
|
}
|
||||||
|
|
||||||
g.logger.Println("NMEA check:", s)
|
g.logger.Println("NMEA check:", s)
|
||||||
values := strings.Split(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)
|
return fmt.Errorf("nmea invalid sentence: %s", s)
|
||||||
}
|
}
|
||||||
switch values[0][3:] { // Switch by content
|
switch values[0][3:] { // Switch by content
|
||||||
|
@ -146,11 +146,15 @@ func (g *gps) collectNmeaReports(flags nmeaFlags) ([]string, error) {
|
|||||||
// OK
|
// OK
|
||||||
// (NMEA sentence)...
|
// (NMEA sentence)...
|
||||||
// OK
|
// OK
|
||||||
if len(strs) < 2 {
|
// if len(strs) < 2 {
|
||||||
return nil, fmt.Errorf("responce too few rows: %d", len(strs))
|
// return nil, fmt.Errorf("responce too few rows: %d", len(strs))
|
||||||
}
|
// }
|
||||||
if !(strs[0] == "OK" && strs[len(strs)-1] == "OK") {
|
// if !(strs[0] == "OK" && strs[len(strs)-1] == "OK") {
|
||||||
return nil, fmt.Errorf("not OK responce: [% s]", strs)
|
// return nil, fmt.Errorf("not OK responce: [% s]", strs)
|
||||||
}
|
// }
|
||||||
return strs[1 : len(strs)-1], nil
|
|
||||||
|
// 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
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ func (c *conn) ConfigurePPP() error {
|
|||||||
config := fmt.Sprintf(pppConfig, apn, c.port.GetName(), c.port.GetBaudrate())
|
config := fmt.Sprintf(pppConfig, apn, c.port.GetName(), c.port.GetBaudrate())
|
||||||
|
|
||||||
// Write to file
|
// Write to file
|
||||||
f, err := os.OpenFile("/etc/ppp/peers/"+pppConfigName, os.O_CREATE | os.O_WRONLY, 0666)
|
f, err := os.OpenFile("/etc/ppp/peers/"+pppConfigName, os.O_CREATE|os.O_WRONLY, 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("open ppp config file %w", err)
|
return fmt.Errorf("open ppp config file %w", err)
|
||||||
}
|
}
|
||||||
@ -230,8 +230,7 @@ func (c *conn) Ping() bool {
|
|||||||
}
|
}
|
||||||
c.logger.Println("Ping 2 resp:", string(resp))
|
c.logger.Println("Ping 2 resp:", string(resp))
|
||||||
|
|
||||||
|
return !(strings.Contains(string(resp), "Destination Host Unreachable") || strings.Contains(string(resp), "Destination Net Unreachable")) // tmp solution
|
||||||
return !strings.Contains(string(resp), "Destination Host Unreachable") // tmp solution
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *conn) Close() error {
|
func (c *conn) Close() error {
|
||||||
|
Loading…
Reference in New Issue
Block a user