Fixed NMEA report parsing.

This commit is contained in:
yotia 2024-08-02 19:16:39 +03:00
parent 9bc94bfe7c
commit e2e02ebbfe
3 changed files with 20 additions and 12 deletions

View File

@ -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

View File

@ -51,7 +51,7 @@ var nmeaFlagsAll = gga | rmc | gpgsv | gpgsa | vtg | xfi | glgsa | gns | gagsv |
func (g *gps) rawCollect(flags nmeaFlags) (string, error) { func (g *gps) rawCollect(flags nmeaFlags) (string, error) {
// Need to omplement low level write/read here because collect must be atomic operation // Need to omplement low level write/read here because collect must be atomic operation
// If other command is executed(write/read) it will read a part of nmea report and cause an error // If other command is executed(write/read) it will read a part of nmea report and cause an error
// Setup gps // Setup gps
// Receive data from all contries' satelites, enable DPO(Dynamic Power Optimization) mode // Receive data from all contries' satelites, enable DPO(Dynamic Power Optimization) mode
@ -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
} }

View File

@ -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 {