From a5d216ffc96279b4513425f61338ebc91d7ad336 Mon Sep 17 00:00:00 2001 From: Andrey Egorov Date: Tue, 23 Jul 2024 17:26:24 +0300 Subject: [PATCH] Debugged connection. --- .gitignore | 1 + Makefile | 8 ++++---- api/modem/at/at.go | 2 +- api/modem/at/response.go | 2 +- api/modem/modem.go | 21 +++++++++++++++------ 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 74750ad..9f8ced0 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ out/ Makefile go.sum .git/ +*.swp diff --git a/Makefile b/Makefile index 5ae9fa7..eb3e247 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ build: - @go build -o ./out/annalist.exe main.go -#run: build -# @./out/annalist.exe + docker compose build +run: build + docker compose up #linux: # @$Env:GOOS="linux"; $Env:GOARCH="arm"; $Env:GOARM=5 @@ -14,4 +14,4 @@ push: git status git add -A git commit -m "Transfer." - git push origin master \ No newline at end of file + git push origin master diff --git a/api/modem/at/at.go b/api/modem/at/at.go index 630f5a1..9e89d1b 100644 --- a/api/modem/at/at.go +++ b/api/modem/at/at.go @@ -86,7 +86,7 @@ func (p *atPort) makeReq(msg string) (string, error) { } // Read readLen, err := p.port.Read(p.inputBuf) - log.Println("RAWREAD:", string(p.inputBuf[:readLen])) + log.Println(msg, "RAWREAD:", string(p.inputBuf[:readLen])) if err != nil { return "", fmt.Errorf("port read: %w", err) } diff --git a/api/modem/at/response.go b/api/modem/at/response.go index d92a8b5..c09199c 100644 --- a/api/modem/at/response.go +++ b/api/modem/at/response.go @@ -12,6 +12,6 @@ func (resp Resp) RmFront(str string) Resp { return Resp(string(resp)[len(str):]) } -func (resp Resp) Str() string { +func (resp Resp) String() string { return string(resp) } diff --git a/api/modem/modem.go b/api/modem/modem.go index 9d102e9..8a23b41 100644 --- a/api/modem/modem.go +++ b/api/modem/modem.go @@ -69,8 +69,9 @@ func (m *modem) Init() error { if err := m.onOffPin.Init(); err != nil { return fmt.Errorf("gpio pin init: %w", err) } - m.onOffPin.PowerOn() + // onOffPin.PowerOn() + log.Println("===============================") // Soft search if err := m.SearchPort(true); err != nil { return fmt.Errorf("soft port search: %w", err) @@ -86,10 +87,14 @@ func (m *modem) Init() error { return errors.New("no port is detected") } + log.Println("===============================") + // Connect if err := m.Connect(); err != nil { return fmt.Errorf("connect: %w", err) } + + log.Println("===============================") // Tests if err := m.TestGPS(); err != nil { return fmt.Errorf("testGPS: %w", err) @@ -128,13 +133,16 @@ func (m *modem) checkPort(portName string) error { if !resp.Check() { return fmt.Errorf("error response: %s", resp) } - model := resp.RmFront("+CGMM:").String() + model := strings.Split(resp.String(), "\n")[0] if err != nil { return fmt.Errorf("get model: %w", err) } - if model != "SIMCOM_SIM7600E-H" { + rightModel := "SIMCOM_SIM7600E-H" + // log.Printf("[% x]\n [% x]", []byte("SIMCOM_SIM7600E-H"), []byte(model)) + if model[:len(rightModel)] != rightModel { return fmt.Errorf("invalid modem model: %s", model) } + log.Println("Model right") return nil } @@ -179,7 +187,7 @@ func (m *modem) Ping() error { if err != nil { return err } - if resp.Check() { + if !resp.Check() { return fmt.Errorf("connection lost") } return nil @@ -200,11 +208,12 @@ func (m *modem) SwitchToGpsMode() error { if !resp.Check() { return fmt.Errorf("error response") } - ans := strings.Split(resp.RmFront("+CGPS:").String(), "\n")[0] + ans := strings.Replace(strings.Split(strings.Split(resp.RmFront("+CGPS:").String(), "\n")[0], ",")[0], " ", "", -1) if ans == "1" { log.Println("GPS already enabled") return nil } + log.Println(ans) // Modem is not in GPS mode resp, err = m.port.Send("AT+CGPS=1") @@ -257,7 +266,7 @@ func (m *modem) Update() error { // Update log.Println("Receiving GPS data...") - resp, err := m.port.Send("AT+GPSINFO") + resp, err := m.port.Send("AT+CGPSINFO") if err != nil { return fmt.Errorf("receive GPS data: %w", err) }