Documentation
¶
Overview ¶
Package gsm provides a driver for GSM modems.
Index ¶
- Variables
- func UnmarshalTPDU(info []string) (tp tpdu.TPDU, err error)
- type Collector
- type ErrCollect
- type ErrDecode
- type ErrReassemblyTimeout
- type ErrUnmarshal
- type ErrorHandler
- type GSM
- func (g *GSM) Init(ctx context.Context, options ...at.InitOption) (err error)
- func (g *GSM) SendLongMessage(ctx context.Context, number string, message string, ...) (rsp []string, err error)
- func (g *GSM) SendPDU(ctx context.Context, tpdu []byte, options ...at.CommandOption) (rsp string, err error)
- func (g *GSM) SendShortMessage(ctx context.Context, number string, message string, ...) (rsp string, err error)
- func (g *GSM) StartMessageRx(ctx context.Context, mh MessageHandler, eh ErrorHandler, options ...RxOption) error
- func (g *GSM) StopMessageRx(ctx context.Context)
- type Message
- type MessageHandler
- type Option
- type RxOption
Constants ¶
This section is empty.
Variables ¶
var ( // ErrMalformedResponse indicates the modem returned a badly formed // response. ErrMalformedResponse = errors.New("modem returned malformed response") // ErrNotGSMCapable indicates that the modem does not support the GSM // command set, as determined from the GCAP response. ErrNotGSMCapable = errors.New("modem is not GSM capable") // ErrNotPINReady indicates the modem SIM card is not ready to perform // operations. ErrNotPINReady = errors.New("modem is not PIN Ready") // ErrOverlength indicates the message is too long for a single PDU and // must be split into multiple PDUs. ErrOverlength = errors.New("message too long for one SMS") // ErrUnderlength indicates that two few lines of info were provided to // decode a PDU. ErrUnderlength = errors.New("insufficient info") // ErrWrongMode indicates the GSM modem is operating in the wrong mode and // so cannot support the command. ErrWrongMode = errors.New("modem is in the wrong mode") )
var WithPDUMode = pduModeOption(true)
WithPDUMode specifies that the modem is to be used in PDU mode.
This is the default mode.
var WithTextMode = pduModeOption(false)
WithTextMode specifies that the modem is to be used in text mode.
This overrides is the default PDU mode.
Functions ¶
Types ¶
type Collector ¶ added in v0.4.0
Collector is the interface required to collect and reassemble TPDUs.
By default, this is implemented by an sms.Collector.
type ErrCollect ¶ added in v0.4.0
ErrCollect indicates that an error occured that prevented the TPDU from being collected.
func (ErrCollect) Error ¶ added in v0.4.0
func (e ErrCollect) Error() string
type ErrDecode ¶ added in v0.4.0
ErrDecode indicates that an error occured that prevented the TPDUs from being cdecoded.
type ErrReassemblyTimeout ¶ added in v0.4.0
ErrReassemblyTimeout indicates that one or more segments of a long message are missing, preventing the complete message being reassembled.
The missing segments are the nil entries in the array.
func (ErrReassemblyTimeout) Error ¶ added in v0.4.0
func (e ErrReassemblyTimeout) Error() string
type ErrUnmarshal ¶ added in v0.4.0
ErrUnmarshal indicates an error occured while trying to unmarshal the TPDU received from the modem.
func (ErrUnmarshal) Error ¶ added in v0.4.0
func (e ErrUnmarshal) Error() string
type ErrorHandler ¶ added in v0.4.0
type ErrorHandler func(error)
ErrorHandler receives asynchronous errors.
type GSM ¶
GSM modem decorates the AT modem with GSM specific functionality.
func (*GSM) SendLongMessage ¶ added in v0.4.0
func (g *GSM) SendLongMessage(ctx context.Context, number string, message string, options ...at.CommandOption) (rsp []string, err error)
SendLongMessage sends an SMS message to the number.
The modem must be in PDU mode. The message is split into concatenated SMS PDUs, if necessary.
The mr of send PDUs is returned on success, else an error.
func (*GSM) SendPDU ¶ added in v0.4.0
func (g *GSM) SendPDU(ctx context.Context, tpdu []byte, options ...at.CommandOption) (rsp string, err error)
SendPDU sends an SMS PDU.
tpdu is the binary TPDU to be sent. The mr is returned on success, else an error.
func (*GSM) SendShortMessage ¶ added in v0.4.0
func (g *GSM) SendShortMessage(ctx context.Context, number string, message string, options ...at.CommandOption) (rsp string, err error)
SendShortMessage sends an SMS message to the number.
If the modem is in PDU mode then the message is converted to a single SMS PDU.
The mr is returned on success, else an error.
func (*GSM) StartMessageRx ¶ added in v0.4.0
func (g *GSM) StartMessageRx(ctx context.Context, mh MessageHandler, eh ErrorHandler, options ...RxOption) error
StartMessageRx sets up the modem to receive SMS messages and pass them to the message handler.
The message may have been concatenated over several SMS PDUs, but if so is reassembled into a complete message before being passed to the message handler.
Errors detected while receiving messages are passed to the error handler.
Requires the modem to be in PDU mode.
func (*GSM) StopMessageRx ¶ added in v0.4.0
StopMessageRx ends the reception of messages started by StartMessageRx,
type Message ¶ added in v0.4.0
Message encapsulates the details of a received message.
The message is composed of one or more SMS-DELIVER TPDUs.
Commonly required fields are extracted for easy access.
type MessageHandler ¶ added in v0.4.0
type MessageHandler func(Message)
MessageHandler receives a decoded SMS message from the modem.
type Option ¶ added in v0.4.0
type Option interface {
// contains filtered or unexported methods
}
Option is a construction option for the GSM.
func WithEncoderOption ¶ added in v0.4.0
func WithEncoderOption(eo sms.EncoderOption) Option
WithEncoderOption applies the encoder option when converting from text messages to SMS TPDUs.
func WithSCA ¶ added in v0.4.0
func WithSCA(sca pdumode.SMSCAddress) Option
WithSCA sets the SCA used when transmitting SMSs in PDU mode.
This overrides the default set in the SIM.
The SCA is only relevant in PDU mode, so this option also enables PDU mode.
type RxOption ¶ added in v0.4.0
type RxOption interface {
// contains filtered or unexported methods
}
RxOption is a construction option for the GSM.
func WithCollector ¶ added in v0.4.0
WithCollector overrides the collector to be used to reassemble long messages.
The default is an sms.Collector.
func WithInitCmds ¶ added in v0.4.0
WithInitCmds overrides the commands required to setup the modem to notify when SMSs are received.
The default is {"+CSMS=1","+CNMI=1,2,0,0,0"}
func WithReassemblyTimeout ¶ added in v0.4.0
WithReassemblyTimeout specifies the maximum time allowed for all segments in a long message to be received.
The default is 24 hours.
This option is overridden by WithCollector.