Semi debugged sms.

This commit is contained in:
Andrey Egorov
2024-07-29 18:53:55 +03:00
parent 1b741c7dab
commit d05e2205d6
4 changed files with 19 additions and 15 deletions

View File

@ -33,6 +33,7 @@ type Port interface {
Disconnect() error
IsConnected() bool
RawSend(msg string) (string, error)
Send(cmd string) (Resp, error)
io.Closer
@ -89,7 +90,7 @@ func (p *atPort) IsConnected() bool {
}
// Low level write/read function
func (p *atPort) makeReq(msg string) (string, error) {
func (p *atPort) RawSend(msg string) (string, error) {
// Write
if _, err := p.port.Write([]byte(msg)); err != nil {
return "", fmt.Errorf("serial port write: %w", err)
@ -107,12 +108,12 @@ func (p *atPort) makeReq(msg string) (string, error) {
func (p *atPort) Send(cmd string) (Resp, error) {
cmd += "\r\n"
rawResp, err := p.makeReq(cmd)
rawResp, err := p.RawSend(cmd)
if err != nil {
return RespNil, fmt.Errorf("make request: %w", err)
}
if len(rawResp) <= 4 {
return RespNil, fmt.Errorf("read too small msg: %d byte", len(rawResp))
return RespNil, fmt.Errorf("read too small msg: %d byte - %s", len(rawResp), string(rawResp))
}
resp := rawResp[2 : len(rawResp)-2] // Cut \r\n