Added RMS.

This commit is contained in:
2024-08-07 17:34:56 +03:00
parent 59bd2c5db3
commit 0b76884112
5 changed files with 65 additions and 20 deletions

View File

@ -30,7 +30,7 @@ const (
nmeaFlagsMask = (1 << 18) - 1
collectTimeout = 2 * time.Second
collectTimeout = 1 * time.Second
)
func secondCountDownTimer(title string, logger *log.Logger, t time.Duration) {

View File

@ -7,10 +7,11 @@ import (
)
type Status struct {
GotResponses bool `json:"gotResponses"`
IsValidData bool `json:"isValidData"`
FoundSatelitesCount int `json:"foundSatelitesCount"`
ActiveSatelitesCount int `json:"activeSatelitesCount"`
GotResponses bool `json:"gotResponses"`
IsValidData bool `json:"isValidData"`
FoundSatelitesCount int `json:"foundSatelitesCount"`
ActiveSatelitesCount int `json:"activeSatelitesCount"`
Rms float32 `json:"rms"` // Root mean square
}
var StatusNil = Status{
@ -18,6 +19,7 @@ var StatusNil = Status{
IsValidData: false,
FoundSatelitesCount: 0,
ActiveSatelitesCount: 0,
Rms: 0,
}
func (g *gps) GetStatus() (Status, error) {
@ -46,7 +48,7 @@ checkLoop:
return StatusNil, fmt.Errorf("nmea invalid sentence: %s", s)
}
switch values[0][3:] { // Switch by content
case "GSV":
case "GSV": // Any satelites
g.logger.Println("check GSV")
// Check len
if len(values) < 17 {
@ -80,7 +82,7 @@ checkLoop:
continue checkLoop
}
st.FoundSatelitesCount = satCount
case "GSA":
case "GSA": // Active satelites
g.logger.Println("check GSA")
// Check len
@ -104,7 +106,7 @@ checkLoop:
}
}
st.ActiveSatelitesCount = max(st.ActiveSatelitesCount, count)
case "RMC":
case "RMC": // Minimum GPS data
g.logger.Println("check RMC")
// Check len
if len(values) < 12 {
@ -118,10 +120,30 @@ checkLoop:
// 2 - is data valid or not
// 3: - other data
// Msg index
// Is valid value
if values[2] == "A" {
st.IsValidData = true
}
case "GST":
g.logger.Println("check GST")
// Check len
if len(values) < 8 {
g.logger.Println("GST too small values")
continue checkLoop
}
// Decode
// 0 - msg type
// 1 - time
// 2 - Root Mean Square
// 3: - other data
rms, err := strconv.ParseFloat(values[2], 32)
if err != nil {
g.logger.Println("RMS decode:", err.Error())
continue checkLoop
}
st.Rms = float32(rms)
}
}