Improved SMS.
This commit is contained in:
@ -116,23 +116,33 @@ func (p *atPort) RawSend(msg string) (string, error) {
|
||||
}
|
||||
// time.Sleep(time.Millisecond)
|
||||
// Read
|
||||
readLen, err := p.port.Read(p.inputBuf)
|
||||
// p.logger.Println(msg, "\x1b[38;2;150;150;150mRAWREAD:", string(p.inputBuf[:readLen]), "\x1b[38;2;255;255;255m")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("port read: %w", err)
|
||||
outBuf := make([]byte, 0)
|
||||
readLoop:
|
||||
for {
|
||||
readLen, err := p.port.Read(p.inputBuf)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("port read: %w", err)
|
||||
}
|
||||
if readLen == 0 {
|
||||
break readLoop
|
||||
}
|
||||
outBuf = append(outBuf, p.inputBuf[:readLen]...)
|
||||
if readLen < len(p.inputBuf) {
|
||||
break readLoop
|
||||
}
|
||||
}
|
||||
// p.logger.Println(msg, "\x1b[38;2;150;150;150mRAWREAD:", string(p.inputBuf[:readLen]), "\x1b[38;2;255;255;255m")
|
||||
|
||||
return string(p.inputBuf[:readLen]), nil
|
||||
return string(outBuf), nil
|
||||
}
|
||||
|
||||
func (p *atPort) Send(cmd string) (Resp, error) {
|
||||
cmd += "\r\n"
|
||||
rawResp, err := p.RawSend(cmd)
|
||||
rawResp, err := p.RawSend(cmd + "\r\n")
|
||||
if err != nil {
|
||||
return RespNil, fmt.Errorf("make request: %w", err)
|
||||
return RespNil, fmt.Errorf("%s request: %w", cmd, err)
|
||||
}
|
||||
if len(rawResp) <= 4 {
|
||||
return RespNil, fmt.Errorf("read too small msg: %d byte - %s", len(rawResp), string(rawResp))
|
||||
return RespNil, fmt.Errorf("%s request: read too small msg: %d byte - %s", cmd, len(rawResp), string(rawResp))
|
||||
}
|
||||
resp := rawResp[2 : len(rawResp)-2] // Cut \r\n
|
||||
|
||||
|
Reference in New Issue
Block a user