sim-modem/api/modem/gps/check.go

52 lines
1.1 KiB
Go

package gps
import (
"fmt"
"strconv"
"strings"
)
func (g *gps) CheckStatus() error {
// Provides more information about signal and possible problems using NMEA reports
// Collect reports
reports, err := g.collectNmeaReports(gpgsv | gpgsa) // Now minimum
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 {
g.logger.Println("NMEA check:", s)
values := strings.Split(s, ",")
if len(values) < 1 || len(values[0]) != 6 || values[0][0] != '$' {
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
}