Skip to content

Latest commit

 

History

History
 
 

gsm

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

gsm

A high level Go driver for GSM modems.

Build Status go.dev reference Coverage Status Go Report Card License: MIT

The gsm package provides a wrapper around at that supports sending and receiving SMS messages, including long multi-part messages.

Features

Supports the following functionality:

  • Simple synchronous interface for sending messages
  • Both text and PDU mode interface to GSM modem
  • Asynchronous handling of received messages

Usage

Construction

The GSM modem is constructed with New:

modem := gsm.New(atmodem)

Some modem behaviour can be controlled using optional parameters. This example sets the puts the modem into PDU mode:

modem := gsm.New(atmodem, gsm.WithPDUMode)

Modem Init

The modem is reset into a known state and checked that is supports GSM functionality using the Init method:

err := modem.Init()

The Init method is a wrapper around the at Init method, and accepts the same options:

err := modem.Init(at.WithCmds("Z","^CURC=0"))

Sending Short Messages

Send a simple short message that will fit within a single SMS TPDU using SendShortMessage:

mr, err := modem.SendShortMessage("+12345","hello")

The modem may be in either text or PDU mode.

Sending Long Messages

This example sends an SMS with the modem in text mode:

mrs, err := modem.SendLongMessage("+12345", apotentiallylongmessage)

Sending PDUs

Arbitrary SMS TPDUs can be sent using the SendPDU method:

mr, err := modem.SendPDU(tpdu)

Receiving Messages

A handler can be provided for received SMS messages using StartMessageRx:

handler := func(msg gsm.Message) {
    // handle message here
}
err := modem.StartMessageRx(handler)

The handler can be removed using StopMessageRx:

modem.StopMessageRx()

Options

A number of the modem methods accept optional parameters. The following table comprises a list of the available options:

Option Method Description
WithCollector(Collector) StartMessageRx Provide a custom collector to reassemble multi-part SMSs.
WithEncoderOption(sms.EncoderOption) New Specify options for encoding outgoing messages.
WithPDUMode New Configure the modem into PDU mode (default).
WithReassemblyTimeout(time.Duration) StartMessageRx Overrides the time allowed to wait for all the parts of a multi-part message to be received and reassembled. The default is 24 hours. This option is ignored if WithCollector is also applied.
WithSCA(pdumode.SMSCAddress) New Override the SCA when sending messages.
WithTextMode New Configure the modem into text mode. This is only required to send short messages in text mode, and conflicts with sending long messages or PDUs, as well as receiving messages.