Skip to content

Commit

Permalink
fix: Return err when desired reponse not exist in response
Browse files Browse the repository at this point in the history
  • Loading branch information
selengalp committed Mar 20, 2024
1 parent f1b48a8 commit e477beb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
6 changes: 6 additions & 0 deletions atcom.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,10 @@ func (t *Atcom) SendAT(command string, args map[string]interface{}) ([]string, e

// check desired and fault existed in response
if desired != nil || fault != nil {
ok := false
for _, desiredStr := range desired {
if strings.Contains(response, desiredStr) {
ok = true
found <- nil
return
}
Expand All @@ -208,6 +210,10 @@ func (t *Atcom) SendAT(command string, args map[string]interface{}) ([]string, e
}
}

if !ok {
found <- errors.New("desired response not found")
return
}
} else {
found <- nil
return
Expand Down
19 changes: 3 additions & 16 deletions examples/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,10 @@ func main() {
response, err := at.SendAT("ATE1", args)
fmt.Println(response, err)

response1, err := at.SendAT("AT+CGDCONT?", args)
fmt.Println(response1, err)

response2, err := at.SendAT("AT+COPS?", args)
fmt.Println(response2, err)

// response3, err := at.SendAT("AT#ECMD=0", args)
// fmt.Println(response3, err)

// response4, err := at.SendAT("AT#ECM=1,0", args)
// fmt.Println(response4, err)

// response5, err := at.SendAT("AT#ECM?", args)
// fmt.Println(response5, err)

// command that takes very long time to respond
// response6, err := at.SendAT("AT+COPS=?", args)
// fmt.Println(response6, err)

args["desired"] = []string{"internet"}
response1, err := at.SendAT("AT+CGDCONT?", args)
fmt.Println(response1, err)
}
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package atcom

const Version = "0.1.0"
const Version = "0.1.1"

0 comments on commit e477beb

Please sign in to comment.