Added read.
This commit is contained in:
@ -44,8 +44,8 @@ func (d *dialer) Init() error {
|
||||
}
|
||||
|
||||
func (d *dialer) Send(number, msg string) error {
|
||||
d.port.Send(fmt.Sprintf("AT+CMGS=\"%s\"", number)) // Because it will throw error
|
||||
resp, err := d.port.RawSend(fmt.Sprintf("%s\x1A", msg)); // Add additional \r\n because there is not supposed to be
|
||||
d.port.Send(fmt.Sprintf("AT+CMGS=\"%s\"", number)) // Because it will throw error
|
||||
resp, err := d.port.RawSend(fmt.Sprintf("%s\x1A", msg)) // Add additional \r\n because there is not supposed to be
|
||||
if err != nil {
|
||||
return fmt.Errorf("message request: %w", err)
|
||||
}
|
||||
@ -66,7 +66,18 @@ func (d *dialer) ReadNew() ([]string, error) {
|
||||
return nil, fmt.Errorf("AT+CMGL request: %w", err)
|
||||
}
|
||||
msgs := strings.Split(strings.Replace(string(resp), "\r", "", -1), "\n")
|
||||
return msgs, nil // TODO
|
||||
|
||||
outMsgs := make([]string, 0)
|
||||
for _, s := range msgs {
|
||||
if len(s) >= len("+CMGL:") && s[:len("+CMGL:")] == "+CMGL:" {
|
||||
params := strings.Split(s[len("+CMGL:"):], ",")
|
||||
d.logger.Println("GET MSG:", params)
|
||||
} else {
|
||||
outMsgs = append(outMsgs, s)
|
||||
}
|
||||
}
|
||||
|
||||
return outMsgs, nil // TODO
|
||||
}
|
||||
|
||||
func (d *dialer) Close() error {
|
||||
|
Reference in New Issue
Block a user