Awesome
modem
A low level Go driver for AT modems.
modem is a Go library for interacting with AT based modems.
The initial impetus was to provide functionality to send and receive SMSs via a GSM modem, but the library may be generally useful for any device controlled by AT commands.
The at package provides a low level driver which sits between an io.ReadWriter, representing the physical modem, and a higher level driver or application.
The AT driver provides the ability to issue AT commands to the modem, and to receive the info and status returned by the modem, as synchronous function calls.
Handlers for asynchronous indications from the modem, such as received SMSs, can be registered with the driver.
The gsm package wraps the AT driver to add higher level functions to send and receive SMS messages, including long messages split into multiple parts, without any knowledge of the underlying AT commands.
The info package provides utility functions to manipulate the info returned in the responses from the modem.
The serial package provides a simple wrapper around a third party serial driver, so you don't have to find one yourself.
The trace package provides a driver, which may be inserted between the AT driver and the underlying modem, to log interactions with the modem for debugging purposes.
The cmd directory contains basic commands to exercise the library and a modem, including retrieving details from the modem, sending and receiving SMSs, and retrieving the SIM phonebook.
Features
Supports the following functionality:
- Simple synchronous interface for AT commands
- Serialises access to the modem from multiple goroutines
- Asynchronous indication handling
- Tracing of messages to and from the modem
- Pluggable serial driver - any io.ReadWriter will suffice
Usage
The at package allows you to issue commands to the modem and receive the response. e.g.:
modem := at.New(ioWR)
info, err := modem.Command("I")
produces the following interaction with the modem (exact results will differ for your modem):
2018/05/17 20:39:56 w: ATI
2018/05/17 20:39:56 r:
Manufacturer: huawei
Model: E173
Revision: 21.017.09.00.314
IMEI: 1234567
+GCAP: +CGSM,+DS,+ES
OK
and returns this info:
info = []string{
"Manufacturer: huawei",
"Model: E173",
"Revision: 21.017.09.00.314",
"IMEI: 1234567",
"+GCAP: +CGSM,+DS,+ES",
}
Refer to the modeminfo for an example of how to create a modem object such as the one used in this example.
For more information, refer to package documentation, tests and example commands.
Package | Documentation | Tests | Example code |
---|---|---|---|
at | at_test | modeminfo | |
gsm | gsm_test | sendsms, waitsms | |
info | info_test | phonebook | |
serial | serial_test | modeminfo, sendsms, waitsms | |
trace | trace_test | sendsms, waitsms |