Documentation
¶
Overview ¶
Package at provides a low level driver for AT modems.
Index ¶
- Constants
- Variables
- type AT
- func (a *AT) AddIndication(prefix string, handler InfoHandler, options ...IndicationOption) (err error)
- func (a *AT) CancelIndication(prefix string)
- func (a *AT) Closed() <-chan struct{}
- func (a *AT) Command(ctx context.Context, cmd string, options ...CommandOption) ([]string, error)
- func (a *AT) Escape(b ...byte)
- func (a *AT) Init(ctx context.Context, options ...InitOption) error
- func (a *AT) SMSCommand(ctx context.Context, cmd string, sms string, options ...CommandOption) (info []string, err error)
- type CMEError
- type CMSError
- type CmdsOption
- type CommandOption
- type ConnectError
- type CustomParseRxLineOption
- type EscTimeOption
- type Indication
- type IndicationOption
- type InfoHandler
- type InitOption
- type NoModifyOption
- type Option
- type ParseRxLineFunc
- type Rxl
- type TimeoutOption
- type TrailingLinesOption
Constants ¶
const EscTimeout = 20 * time.Millisecond
Variables ¶
var ( // ErrClosed indicates an operation cannot be performed as the modem has // been closed. ErrClosed = errors.New("closed") // ErrDeadlineExceeded indicates the modem failed to complete an operation // within the required time. ErrDeadlineExceeded = errors.New("deadline exceeded") // ErrError indicates the modem returned a generic AT ERROR in response to // an operation. ErrError = errors.New("ERROR") // ErrIndicationExists indicates there is already a indication registered // for a prefix. ErrIndicationExists = errors.New("indication exists") )
var WithTrailingLine = TrailingLinesOption(1)
WithTrailingLine indicates the indication includes one line after the line containing the indication.
Functions ¶
This section is empty.
Types ¶
type AT ¶
type AT struct {
// contains filtered or unexported fields
}
AT represents a modem that can be managed using AT commands.
Commands can be issued to the modem using the Command and SMSCommand methods.
The AT closes the closed channel when the connection to the underlying modem is broken (Read returns EOF).
When closed, all outstanding commands return ErrClosed and the state of the underlying modem becomes unknown.
Once closed the AT cannot be re-opened - it must be recreated.
func (*AT) AddIndication ¶
func (a *AT) AddIndication(prefix string, handler InfoHandler, options ...IndicationOption) (err error)
AddIndication adds a handler for a set of lines beginning with the prefixed line and the following trailing lines.
func (*AT) CancelIndication ¶
CancelIndication removes any indication corresponding to the prefix.
If any such indication exists its return channel is closed and no further indications will be sent to it.
func (*AT) Closed ¶
func (a *AT) Closed() <-chan struct{}
Closed returns a channel which will block while the modem is not closed.
func (*AT) Command ¶
Command issues the command to the modem and returns the result.
The command should NOT include the AT prefix, nor <CR><LF> suffix which is automatically added.
The return value includes the info (the lines returned by the modem between the command and the status line), or an error if the command did not complete successfully.
func (*AT) Escape ¶ added in v0.4.0
Escape issues an escape sequence to the modem.
It does not wait for any response, but it does inhibit subsequent commands until the escTime has elapsed.
The escape sequence is "\x1b\r\n". Additional characters may be added to the sequence using the b parameter.
func (*AT) Init ¶
func (a *AT) Init(ctx context.Context, options ...InitOption) error
Init initialises the modem by escaping any outstanding SMS commands and resetting the modem to factory defaults.
The Init is intended to be called after creation and before any other commands are issued in order to get the modem into a known state. It can also be used subsequently to return the modem to a known state.
The default init commands can be overridden by the options parameter.
func (*AT) SMSCommand ¶
func (a *AT) SMSCommand(ctx context.Context, cmd string, sms string, options ...CommandOption) (info []string, err error)
SMSCommand issues an SMS command to the modem, and returns the result.
An SMS command is issued in two steps; first the command line:
AT<command><CR>
which the modem responds to with a ">" prompt, after which the SMS PDU is sent to the modem:
<sms><Ctrl-Z>
The modem then completes the command as per other commands, such as those issued by Command.
The format of the sms may be a text message or a hex coded SMS PDU, depending on the configuration of the modem (text or PDU mode).
type CMEError ¶
type CMEError string
CMEError indicates a CME Error was returned by the modem.
The value is the error value, in string form, which may be the numeric or textual, depending on the modem configuration.
type CMSError ¶
type CMSError string
CMSError indicates a CMS Error was returned by the modem.
The value is the error value, in string form, which may be the numeric or textual, depending on the modem configuration.
type CmdsOption ¶ added in v0.4.0
type CmdsOption []string
CmdsOption specifies the set of AT commands issued by Init.
func WithCmds ¶ added in v0.4.0
func WithCmds(cmds ...string) CmdsOption
WithCmds specifies the set of AT commands issued by Init.
The default commands are ATZ.
type CommandOption ¶ added in v0.4.0
type CommandOption interface {
// contains filtered or unexported methods
}
CommandOption defines a behaviouralk option for Command and SMSCommand.
type ConnectError ¶ added in v0.4.0
type ConnectError string
ConnectError indicates an attempt to dial failed.
The value of the error is the failure indication returned by the modem.
func (ConnectError) Error ¶ added in v0.4.0
func (e ConnectError) Error() string
type CustomParseRxLineOption ¶ added in v0.5.8
type CustomParseRxLineOption ParseRxLineFunc
type EscTimeOption ¶ added in v0.4.0
EscTimeOption defines the escape guard time for the modem.
func WithEscTime ¶ added in v0.4.0
func WithEscTime(d time.Duration) EscTimeOption
WithEscTime sets the guard time for the modem.
The escape time is the minimum time between an escape command being sent to the modem and any subsequent commands.
The default guard time is 20msec.
type Indication ¶ added in v0.4.0
type Indication struct {
// contains filtered or unexported fields
}
Indication represents an unsolicited result code (URC) from the modem, such as a received SMS message.
Indications are lines prefixed with a particular pattern, and may include a number of trailing lines. The matching lines are bundled into a slice and sent to the handler.
func WithIndication ¶ added in v0.4.0
func WithIndication(prefix string, handler InfoHandler, options ...IndicationOption) Indication
WithIndication adds an indication during construction.
type IndicationOption ¶ added in v0.4.0
type IndicationOption interface {
// contains filtered or unexported methods
}
IndicationOption alters the behavior of the indication.
type InfoHandler ¶ added in v0.4.0
type InfoHandler func([]string)
InfoHandler receives indication info.
type InitOption ¶ added in v0.4.0
type InitOption interface {
// contains filtered or unexported methods
}
InitOption defines a behaviouralk option for Init.
type NoModifyOption ¶ added in v0.5.8
type NoModifyOption bool
NoModifyOption specifies that the command should not be appended with "AT" prefix and "\r\n" suffix and must be issued as is.
type Option ¶ added in v0.4.0
type Option interface {
// contains filtered or unexported methods
}
Option is a construction option for an AT.
type ParseRxLineFunc ¶ added in v0.5.8
type TimeoutOption ¶ added in v0.4.0
TimeoutOption specifies the maximum time allowed for the modem to complete a command.
func WithTimeout ¶ added in v0.4.0
func WithTimeout(d time.Duration) TimeoutOption
WithTimeout specifies the maximum time allowed for the modem to complete a command.
type TrailingLinesOption ¶ added in v0.4.0
type TrailingLinesOption int
TrailingLinesOption specifies the number of trailing lines expected after an indication line.
func WithTrailingLines ¶ added in v0.4.0
func WithTrailingLines(l int) TrailingLinesOption
WithTrailingLines indicates the number of lines after the line containing the indication that arew to be collected as part of the indication.
The default is 0 - only the indication line itself is collected and returned.