Fixed RmFront panic.

This commit is contained in:
Andrey Egorov
2024-08-09 11:21:02 +03:00
parent 6c110b9a8b
commit dde1411b18
3 changed files with 12 additions and 5 deletions

View File

@ -49,9 +49,10 @@ func (g *gps) Update() error {
if err != nil {
return fmt.Errorf("receive GPS data: %w", err)
}
if !resp.Check() {
if !resp.Check() || !resp.CheckFront("+CGPSINFO:") {
return fmt.Errorf("get GPS info: error response: %s", resp)
}
if err := g.data.decode(strings.Split(strings.Replace(resp.RmFront("+CGPSINFO:").String(), "\r", "", -1), "\n")[0]); err != nil {
g.logger.Printf("error decode: %s\n", err.Error())
}
@ -86,7 +87,7 @@ func (g *gps) switchGpsMode(on bool) error {
if err != nil {
return fmt.Errorf("make at ask: %w", err)
}
if !resp.Check() {
if !resp.Check() || !resp.CheckFront("+CGPS:") {
return fmt.Errorf("get GPS mode: error response: %s", resp)
}
ans := strings.Replace(strings.Split(strings.Split(resp.RmFront("+CGPS:").String(), "\n")[0], ",")[0], " ", "", -1)