Debugged connection.

This commit is contained in:
Andrey Egorov 2024-07-23 17:26:24 +03:00
parent 6b8284ee47
commit a5d216ffc9
5 changed files with 22 additions and 12 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ out/
Makefile
go.sum
.git/
*.swp

View File

@ -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
git push origin master

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}