Added service checks. Some refactoring.

This commit is contained in:
Andrey Egorov
2024-08-12 13:40:26 +03:00
parent d21ad0ce00
commit 5059814d39
9 changed files with 258 additions and 187 deletions

View File

@ -6,23 +6,6 @@ import (
"strings"
)
func (d *dialer) checkPIN() error {
// Get code
resp, err := d.port.Send("AT+CPIN?")
if err != nil {
return fmt.Errorf("AT+CPIN? request: %w", err)
}
if !resp.Check() || !resp.CheckFront("+CPIN:") {
return fmt.Errorf("AT+CPIN? error response: %s", resp)
}
code := strings.ReplaceAll(strings.ReplaceAll(strings.Split(resp.RmFront("+CPIN:").String(), "\n")[0], "\r", ""), " ", "")
if code != "READY" {
return fmt.Errorf("not READY code: %s", code)
}
d.logger.Println("PIN is ready")
return nil
}
func (d *dialer) setupMsgSt() error {
// Check for free space for messages
// !!! I use one! memory for all three bindings

View File

@ -8,6 +8,7 @@ import (
"time"
"gitea.unprism.ru/KRBL/sim-modem/api/modem/at"
"gitea.unprism.ru/KRBL/sim-modem/api/modem/utils"
)
type dialer struct {
@ -36,7 +37,7 @@ func (d *dialer) Init() error {
return fmt.Errorf("serial port is not connected")
}
// Check ping
if err := d.checkPIN(); err != nil {
if err := utils.CheckPIN(d.port, d.logger); err != nil {
return fmt.Errorf("check PIN: %w", err)
}
// Setup prefered message storage