This commit is contained in:
Andrey Egorov 2024-07-22 20:57:36 +03:00
parent 620c98cbf1
commit dbb4fc5939

View File

@ -127,20 +127,20 @@ func (p *atPort) Request(cmdType CmdType, cmd string) (outStr string, outErr err
if len(rawResp) == 0 {
return "", fmt.Errorf("read nothing")
}
resp := strings.Split(rawResp, "\n")
resp := rawResp[2 : len(rawResp)-2] // Cut \r\n
switch cmdType {
case CmdTest, CmdCheck:
// Check and test cmds do not suppose anything but OK
if len(resp[1]) >= 2 && resp[1][:2] == "OK" {
if len(resp) >= 2 && resp[:2] == "OK" {
return "", nil
}
return "", fmt.Errorf("connection lost")
case CmdGet, CmdQuestion:
checkL := len(cmd) + 1
if len(resp[1]) >= checkL && resp[1][:checkL] != "+"+cmd {
if len(resp) >= checkL && resp[:checkL] != "+"+cmd {
return "", fmt.Errorf("connetion lost")
}
return strings.Split(resp[1], ":")[1], nil
return strings.Split(resp, ":")[1], nil
}
return "", fmt.Errorf("undefined command type")
}