2024-07-31 19:18:44 +00:00
|
|
|
package gps
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (g *gps) CheckStatus() error {
|
|
|
|
// Provides more information about signal and possible problems using NMEA reports
|
|
|
|
|
|
|
|
// Collect reports
|
2024-08-01 16:34:58 +00:00
|
|
|
reports, err := g.collectNmeaReports(nmeaFlagsAll) // Now minimum
|
2024-07-31 19:18:44 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("collect nmea reports: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Annalise
|
|
|
|
// Now simpliest variant
|
|
|
|
// Checks if there is any satelites
|
|
|
|
sc := 0 // Satelites' counter
|
|
|
|
// asc := 0 // Active satelites' counter
|
|
|
|
checkLoop:
|
|
|
|
for _, s := range reports {
|
2024-08-02 16:16:39 +00:00
|
|
|
// Check for NMEA format
|
|
|
|
if len(s) < 1 || s[0] != '$' {
|
|
|
|
continue checkLoop
|
|
|
|
}
|
|
|
|
|
2024-07-31 19:18:44 +00:00
|
|
|
g.logger.Println("NMEA check:", s)
|
|
|
|
values := strings.Split(s, ",")
|
2024-08-02 16:16:39 +00:00
|
|
|
if len(values[0]) != 6 {
|
2024-07-31 19:18:44 +00:00
|
|
|
return fmt.Errorf("nmea invalid sentence: %s", s)
|
|
|
|
}
|
|
|
|
switch values[0][3:] { // Switch by content
|
|
|
|
case "gsv":
|
|
|
|
if len(values) < 17 {
|
|
|
|
g.logger.Println("GSV too small values")
|
|
|
|
continue checkLoop
|
|
|
|
}
|
|
|
|
c, err := strconv.Atoi(values[4])
|
|
|
|
if err != nil {
|
|
|
|
g.logger.Println("GSV too small values")
|
|
|
|
continue checkLoop
|
|
|
|
}
|
|
|
|
sc += c
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g.logger.Println("FOUND:", sc, "SATELITES")
|
|
|
|
if sc == 0 {
|
|
|
|
return fmt.Errorf("no satelites found")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|