From cb07b6ac62e241791aac1c561edb579f36a8cee6 Mon Sep 17 00:00:00 2001 From: Andrey Egorov Date: Thu, 8 Aug 2024 15:52:52 +0300 Subject: [PATCH] Fixed GPS info parsing. --- api/modem/gps/data.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/api/modem/gps/data.go b/api/modem/gps/data.go index 15df608..a5c90ab 100644 --- a/api/modem/gps/data.go +++ b/api/modem/gps/data.go @@ -2,6 +2,8 @@ package gps import ( "fmt" + "io" + "log" "math" "strconv" "strings" @@ -44,14 +46,18 @@ func (gps *Data) decode(str string) error { var err error newGpsInfo := Data{} strs := strings.Split(strings.Split(strings.Replace(str, " ", "", -1), "\n")[0], ",") + logger := log.New(io.Discard, "modem-gps", log.LstdFlags) + if len(strs) < 7 { + return fmt.Errorf("ERROR: too small msg: %s", strs) + } newGpsInfo.Latitude, err = strconv.ParseFloat(strs[0], 64) if err != nil { - return fmt.Errorf("parse latitude: %w", err) + logger.Println("ERROR parse latitude:", err.Error()) } newGpsInfo.Longitude, err = strconv.ParseFloat(strs[2], 64) if err != nil { - return fmt.Errorf("parse longitude: %w", err) + logger.Println("ERROR parse longitude:", err.Error()) } newGpsInfo.Latitude /= 100 newGpsInfo.Longitude /= 100 @@ -61,17 +67,17 @@ func (gps *Data) decode(str string) error { newGpsInfo.Time = strs[5] newGpsInfo.Altitude, err = strconv.ParseFloat(strs[6], 64) if err != nil { - return fmt.Errorf("parse altitude: %w", err) + logger.Println("ERROR parse altitude:", err.Error()) } newGpsInfo.Speed, err = strconv.ParseFloat(strs[7], 64) if err != nil { - return fmt.Errorf("parse speed: %w", err) + logger.Println("ERROR parse speed:", err.Error()) } // Course sometimes may be null if len(strs[8]) > 0 { newGpsInfo.Course, err = strconv.ParseFloat(strs[8], 64) if err != nil { - return fmt.Errorf("parse course: %w", err) + logger.Println("ERROR parse course:", err.Error()) } } *gps = newGpsInfo