Documentation ¶
Index ¶
- Constants
- Variables
- type Options
- type Packet
- type RFM9x
- func (rfm *RFM9x) ClearDIO0Interrupt() (err error)
- func (rfm *RFM9x) GetLoRaMode() (isLoRa bool, err error)
- func (rfm *RFM9x) GetOperatingMode() (mode byte, err error)
- func (rfm *RFM9x) GetVersion() (version byte, err error)
- func (rfm *RFM9x) Init(opts Options) (err error)
- func (rfm *RFM9x) ReadBits(address, bits, offset byte) (value byte, err error)
- func (rfm *RFM9x) ReadBuffer(address byte, length byte) (value []byte, err error)
- func (rfm *RFM9x) ReadByteFromAddress(address byte) (value byte, err error)
- func (rfm *RFM9x) Reset() (err error)
- func (rfm *RFM9x) Send(payload []byte) (err error)
- func (rfm *RFM9x) SetAGC(enableAGC bool) (err error)
- func (rfm *RFM9x) SetCodingRate(codingRate byte) (err error)
- func (rfm *RFM9x) SetDIO0Interrupt(interrupt func(machine.Pin)) (err error)
- func (rfm *RFM9x) SetFIFOBaseAddress(txBaseAddress byte, rxBaseAddress byte) (err error)
- func (rfm *RFM9x) SetFrequencyAndBandwidth(frequencyMHz int, bandwidthHz int) (err error)
- func (rfm *RFM9x) SetLoRaMode(isLoRa bool) (err error)
- func (rfm *RFM9x) SetLowFrequencyMode(isLowFrequency bool) (err error)
- func (rfm *RFM9x) SetOperatingMode(mode byte) (err error)
- func (rfm *RFM9x) SetPreambleLength(preambleLength uint16) (err error)
- func (rfm *RFM9x) SetRxCRC(enableCRC bool) (err error)
- func (rfm *RFM9x) SetSpreadingFactor(sf byte) (err error)
- func (rfm *RFM9x) SetTxPower(txPowerDb int) (err error)
- func (rfm *RFM9x) StartReceive() (err error)
- func (rfm *RFM9x) StopReceive() (err error)
- func (rfm *RFM9x) WriteBits(address, bits, offset, val byte) (err error)
- func (rfm *RFM9x) WriteBuffer(address byte, buffer []byte) (err error)
- func (rfm *RFM9x) WriteByteToAddress(address byte, val byte) (err error)
Constants ¶
const ( REGISTERS_FIFO = 0x00 REGISTERS_OP_MODE = 0x01 REGISTERS_FRF_MSB = 0x06 REGISTERS_FRF_MID = 0x07 REGISTERS_FRF_LSB = 0x08 REGISTERS_PA_CONFIG = 0x09 REGISTERS_FIFO_ADDR_PTR = 0x0D REGISTERS_FIFO_TX_BASE_ADDR = 0x0E REGISTERS_FIFO_RX_BASE_ADDR = 0x0F REGISTERS_IRQ_FLAGS = 0x12 REGISTERS_RX_NB_BYTES = 0x13 REGISTERS_PKT_SNR_VALUE = 0x19 REGISTERS_PKT_RSSI_VALUE = 0x1A REGISTERS_MODEM_CONFIG_1 = 0x1D REGISTERS_MODEM_CONFIG_2 = 0x1E REGISTERS_PREAMBLE_MSB = 0x20 REGISTERS_PREAMBLE_LSB = 0x21 REGISTERS_PAYLOAD_LENGTH = 0x22 REGISTERS_MODEM_CONFIG_3 = 0x26 REGISTERS_DIO_MAPPING_1 = 0x40 REGISTERS_DIO_MAPPING_2 = 0x41 REGISTERS_VERSION = 0x42 REGISTERS_PA_DAC = 0x4D OP_MODES_SLEEP = 0b000 OP_MODES_STANDBY = 0b001 OP_MODES_TRANSMIT = 0b011 OP_MODES_RXCONT = 0b101 OP_MODES_RXSINGLE = 0b110 OP_MODES_CAD = 0b111 DIO0_MAPPINGS_RX_DONE = 0b00 DIO0_MAPPINGS_TX_DONE = 0b01 DIO0_MAPPINGS_CAD_DONE = 0b10 RF95_FXOSC = 32000000 RF95_FSTEP = RF95_FXOSC / 524288 )
Define constants.
Variables ¶
var ( BANDWIDTHS = []int{7800, 10400, 15600, 20800, 31250, 41700, 62500, 125000, 250000} BW_REG_2F_OFFSETS = []byte{0x48, 0x44, 0x44, 0x44, 0x44, 0x44, 0x40, 0x40, 0x40} BITMASKS = []byte{0b00000001, 0b00000011, 0b00000111, 0b00001111, 0b00011111, 0b00111111, 0b01111111} )
Define lists and bitmasks.
var ( ErrRFM9xNotDetected = errors.New("RFM9x module not detected") ErrRFM9xNotSupported = errors.New("RFM9x version not supported") ErrRFM9xOPModeReadbackIncorrect = errors.New("communication error: Readback of operating mode configuration failed") ErrRFM9xLoRaModeReadbackIncorrect = errors.New("communication error: Readback of LoRa mode configuration failed") ErrSendPayloadEmpty = errors.New("empty payload supplied") ErrSendPayloadTooBig = errors.New("payload too long") ErrSendTimeOut = errors.New("timeout while sending") ErrInvalidSpreadingFactor = errors.New("invalid spreading factor") ErrInvalidCodingRate = errors.New("invalid coding rate") ErrInvalidTXPower = errors.New("invalid TX power") )
Define errors.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct { FrequencyMHz int PreambleLength uint16 BandwidthHz int CodingRate byte SpreadingFactor byte EnableCRCChecking bool TxPowerDb int EnableAGC bool ResetPin machine.Pin CSPin machine.Pin DIO0Pin machine.Pin DIO1Pin machine.Pin // Currently not used DIO2Pin machine.Pin // Currently not used SPISpeedHz uint32 TxTimeoutMs int }
Options are the options for the radio.
type Packet ¶
type Packet struct { // Payload is the bytes received by the radio Payload []byte // RSSIDb is the Received Signal Strength Indication of the Packet RSSIDb byte // SNRDb is the signal-to-noise ratio of the Packet SNRDb byte }
Packet is a packet received from the radio.
type RFM9x ¶
type RFM9x struct { // Options is an instance of the Options type Options Options // SPIDevice is the SPI device used to communicate with the RFM9X SPIDevice machine.SPI // OnReceivedPacket is a function set by the user that is executed when a packet is received OnReceivedPacket func(Packet) }
RFM9x is a driver for the RFM9x LoRa radio module.
func (*RFM9x) ClearDIO0Interrupt ¶
ClearDIO0Interrupt deletes the function set to be run when the DIO0 pin is changed.
func (*RFM9x) GetLoRaMode ¶
GetLoRaMode returns the current LoRa mode of the device.
func (*RFM9x) GetOperatingMode ¶
GetOperatingMode returns the current operating mode of the device.
func (*RFM9x) GetVersion ¶
GetVersion returns the version of the device. It should be 0x12.
func (*RFM9x) Init ¶
Init sets up the RFM9x with the options provided, and uses the defaultOptions for fields not specified by the options provided.
func (*RFM9x) ReadBuffer ¶
ReadBuffer uses SPI to read multiple bytes from the device using the address and length provided.
func (*RFM9x) ReadByteFromAddress ¶
ReadByteFromAddress reads a single byte from the device at the address provided.
func (*RFM9x) SetAGC ¶ added in v1.0.2
SetAGC enables or disables the Automatic Gain Control of the device.
func (*RFM9x) SetCodingRate ¶
SetCodingRate sets the coding rate of the device.
func (*RFM9x) SetDIO0Interrupt ¶
SetDIO0Interrupt sets the function to be run when the DIO0 pin is changed.
func (*RFM9x) SetFIFOBaseAddress ¶
SetFIFOBaseAddress sets the TX and RX base address of the device.
func (*RFM9x) SetFrequencyAndBandwidth ¶
SetFrequencyAndBandwidth sets the frequency (in MHz) and the bandwidth (in Hz) of the device.
func (*RFM9x) SetLoRaMode ¶
SetLoRaMode sets the current LoRa mode of the device.
func (*RFM9x) SetLowFrequencyMode ¶
SetLowFrequencyMode sets the low frequency mode of the device.
func (*RFM9x) SetOperatingMode ¶
SetOperatingMode sets the current operating mode of the device.
func (*RFM9x) SetPreambleLength ¶
SetPreambleLength sets the preamble length of the device.
func (*RFM9x) SetRxCRC ¶ added in v1.0.2
SetRxCRC enables or disables the CRC checking functionality of the device.
func (*RFM9x) SetSpreadingFactor ¶
SetSpreadingFactor sets the spreading factor of the device.
func (*RFM9x) SetTxPower ¶
SetTxPower sets the TX power of the device in db.
func (*RFM9x) StartReceive ¶ added in v1.0.2
StartReceive tells the RFM9X to start waiting for a packet. When it receives a packet, it will run OnReceivedPacket().
func (*RFM9x) StopReceive ¶
StopReceive puts the device into standby mode and stops waiting for packets.
func (*RFM9x) WriteBuffer ¶
WriteBuffer uses SPI to write multiple bytes to the device using the address and buffer provided.