-
Notifications
You must be signed in to change notification settings - Fork 42
/
modeminfo.go
96 lines (91 loc) · 1.79 KB
/
modeminfo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// SPDX-License-Identifier: MIT
//
// Copyright © 2018 Kent Gibson <[email protected]>.
// modeminfo collects and displays information related to the modem and its
// current configuration.
//
// This serves as an example of how interact with a modem, as well as
// providing information which may be useful for debugging.
package main
import (
"flag"
"fmt"
"io"
"log"
"os"
"time"
"github.com/warthog618/modem/at"
"github.com/warthog618/modem/serial"
"github.com/warthog618/modem/trace"
)
var version = "undefined"
func main() {
dev := flag.String("d", "/dev/ttyUSB0", "path to modem device")
baud := flag.Int("b", 115200, "baud rate")
timeout := flag.Duration("t", 400*time.Millisecond, "command timeout period")
verbose := flag.Bool("v", false, "log modem interactions")
vsn := flag.Bool("version", false, "report version and exit")
flag.Parse()
if *vsn {
fmt.Printf("%s %s\n", os.Args[0], version)
os.Exit(0)
}
m, err := serial.New(serial.WithPort(*dev), serial.WithBaud(*baud))
if err != nil {
log.Println(err)
return
}
defer m.Close()
var mio io.ReadWriter = m
if *verbose {
mio = trace.New(m)
}
a := at.New(mio, at.WithTimeout(*timeout))
err = a.Init()
if err != nil {
log.Println(err)
return
}
cmds := []string{
"I",
"+GCAP",
"+CMEE=2",
"+CGMI",
"+CGMM",
"+CGMR",
"+CGSN",
"+CSQ",
"+CIMI",
"+CREG?",
"+CNUM",
"+CPIN?",
"+CEER",
"+CSCA?",
"+CSMS?",
"+CSMS=?",
"+CPMS=?",
"+CCID?",
"+CCID=?",
"^ICCID?",
"+CNMI?",
"+CNMI=?",
"+CNMA=?",
"+CMGF?",
"+CMGF=?",
"+CUSD?",
"+CUSD=?",
"^USSDMODE?",
"^USSDMODE=?",
}
for _, cmd := range cmds {
info, err := a.Command(cmd)
fmt.Println("AT" + cmd)
if err != nil {
fmt.Printf(" %s\n", err)
continue
}
for _, l := range info {
fmt.Printf(" %s\n", l)
}
}
}