RadioLib
Universal wireless communication library for Arduino
Loading...
Searching...
No Matches
PhysicalLayer Class Referenceabstract

Provides common interface for protocols that run on LoRa/FSK modules, such as RTTY or LoRaWAN. Also extracts some common module-independent methods. Using this interface class allows to use the protocols on various modules without much code duplicity. Because this class is used mainly as interface, all of its virtual members must be implemented in the module class. More...

#include <PhysicalLayer.h>

Inheritance diagram for PhysicalLayer:
CC1101 ExternalRadio LRxxxx RF69 SX126x SX127x SX128x Si443x nRF24

Public Member Functions

 PhysicalLayer ()
 Default constructor.
virtual ~PhysicalLayer ()=default
 Default destructor.
int16_t transmit (const char *str, uint8_t addr=0)
 C-string transmit method.
virtual int16_t transmit (const uint8_t *data, size_t len, uint8_t addr=0)
 Binary transmit method. Must be implemented in module class.
virtual int16_t sleep ()
 Sets module to sleep.
virtual int16_t standby ()
 Sets module to standby.
virtual int16_t standby (uint8_t mode)
 Sets module to a specific standby mode.
virtual int16_t startReceive ()
 Sets module to received mode using its default configuration.
virtual int16_t startReceive (uint32_t timeout, RadioLibIrqFlags_t irqFlags=RADIOLIB_IRQ_RX_DEFAULT_FLAGS, RadioLibIrqFlags_t irqMask=RADIOLIB_IRQ_RX_DEFAULT_MASK, size_t len=0)
 Interrupt-driven receive method. A DIO pin will be activated when full packet is received. Must be implemented in module class.
virtual int16_t receive (uint8_t *data, size_t len, RadioLibTime_t timeout=0)
 Binary receive method. Must be implemented in module class.
int16_t startTransmit (const char *str, uint8_t addr=0)
 Interrupt-driven Arduino String transmit method. Unlike the standard transmit method, this one is non-blocking. Interrupt pin will be activated when transmission finishes.
virtual int16_t startTransmit (const uint8_t *data, size_t len, uint8_t addr=0)
 Interrupt-driven binary transmit method.
virtual int16_t finishTransmit ()
 Clean up after transmission is done.
virtual int16_t finishReceive ()
 Clean up after reception is done.
virtual int16_t readData (uint8_t *data, size_t len)
 Reads data that was received after calling startReceive method.
virtual int16_t transmitDirect (uint32_t frf=0)
 Enables direct transmission mode on pins DIO1 (clock) and DIO2 (data). Must be implemented in module class. While in direct mode, the module will not be able to transmit or receive packets. Can only be activated in FSK mode.
virtual int16_t receiveDirect ()
 Enables direct reception mode on pins DIO1 (clock) and DIO2 (data). Must be implemented in module class. While in direct mode, the module will not be able to transmit or receive packets. Can only be activated in FSK mode.
virtual int16_t setFrequency (uint32_t freq)
 Sets carrier frequency. Must be implemented in module class.
virtual int16_t setBitRate (uint32_t br)
 Sets FSK bit rate. Only available in FSK mode. Must be implemented in module class.
virtual int16_t setFrequencyDeviation (uint32_t freqDev)
 Sets FSK frequency deviation from carrier frequency. Only available in FSK mode. Must be implemented in module class.
virtual int16_t setSpreadingFactor (uint8_t sf)
 Sets LoRa spreading factor. Must be implemented in module class.
virtual int16_t setBandwidth (uint32_t bw)
 Sets LoRa bandwidth. Must be implemented in module class.
virtual int16_t setCodingRate (uint8_t cr, bool longInterleave=false)
 Sets LoRa coding rate denominator. Must be implemented in module class.
virtual int16_t setLrFhssConfig (uint8_t bw, uint8_t cr, bool narrowGrid, uint8_t hdrCount=3, uint16_t hopSeed=0x13A)
 Sets LR-FHSS configuration. Must be implemented in module class.
virtual int16_t setDataShaping (uint8_t sh)
 Sets GFSK data shaping. Only available in FSK mode. Must be implemented in module class.
virtual int16_t setEncoding (uint8_t encoding)
 Sets FSK data encoding. Only available in FSK mode. Must be implemented in module class.
virtual int16_t invertIQ (bool enable)
 Set IQ inversion. Must be implemented in module class if the module supports it.
virtual int16_t setOutputPower (int8_t power)
 Set output power. Must be implemented in module class if the module supports it.
int16_t setOutputPowerOffset (int8_t offset)
 Sets offset of the output power. Useful for devices where the radio has an external power amplifier, or of the RF system has a known loss between the radio and the antenna. NOTE: This method must be called BEFORE any calls to radio.begin() or radio.setOutputPower() for the offset to be applied!
int16_t setOutputPowerOffset (const int8_t *lut, size_t steps)
 Sets offset of the output power. Useful for devices where the radio has an external power amplifier, or of the RF system has a known loss between the radio and the antenna. This overload allows to compensate a non-linear PA gain, dependant on the radio power output via a lookup table. NOTE: This method must be called BEFORE any calls to radio.begin() or radio.setOutputPower() for the offset to be applied!
virtual int16_t setSyncWord (uint8_t *sync, size_t len)
 Set sync word. Must be implemented in module class if the module supports it.
virtual int16_t setPreambleLength (size_t len, size_t detLen=0xFFFFFFFF)
 Set preamble length. Must be implemented in module class if the module supports it.
virtual int16_t setDataRate (DataRate_t dr, ModemType_t modem=RADIOLIB_MODEM_NONE)
 Set data rate. Must be implemented in module class if the module supports it.
virtual int16_t checkDataRate (DataRate_t dr, ModemType_t modem=RADIOLIB_MODEM_NONE)
 Check the data rate can be configured by this module. Must be implemented in module class if the module supports it.
virtual size_t getPacketLength (bool update=true)
 Query modem for the packet length of received payload. Must be implemented in module class.
virtual float getRSSI ()
 Gets RSSI (Received Signal Strength Indicator) of the last received packet.
virtual float getSNR ()
 Gets SNR (Signal to Noise Ratio) of the last received packet. Only available for LoRa modem.
virtual RadioLibTime_t calculateTimeOnAir (ModemType_t modem, DataRate_t dr, PacketConfig_t pc, size_t len)
 Calculate the expected time-on-air for a given modem, data rate, packet configuration and payload size.
virtual RadioLibTime_t getTimeOnAir (size_t len)
 Get expected time-on-air for a given size of payload.
virtual RadioLibTime_t calculateRxTimeout (RadioLibTime_t timeoutUs)
 Calculate the timeout value for this specific module / series (in number of symbols or units of time).
uint32_t getIrqMapped (RadioLibIrqFlags_t irq)
 Convert from radio-agnostic IRQ flags to radio-specific flags.
int16_t checkIrq (RadioLibIrqType_t irq)
 Check whether a specific IRQ bit is set (e.g. RxTimeout, CadDone).
int16_t setIrq (RadioLibIrqFlags_t irq)
 Set interrupt on specific IRQ bit(s) (e.g. RxTimeout, CadDone). Keep in mind that not all radio modules support all RADIOLIB_IRQ_ flags!
int16_t clearIrq (RadioLibIrqFlags_t irq)
 Clear interrupt on a specific IRQ bit (e.g. RxTimeout, CadDone). Keep in mind that not all radio modules support all RADIOLIB_IRQ_ flags!
virtual uint32_t getIrqFlags ()
 Read currently active IRQ flags. Must be implemented in module class.
virtual int16_t setIrqFlags (uint32_t irq)
 Set interrupt on DIO1 to be sent on a specific IRQ bit (e.g. RxTimeout, CadDone). Must be implemented in module class.
virtual int16_t clearIrqFlags (uint32_t irq)
 Clear interrupt on a specific IRQ bit (e.g. RxTimeout, CadDone). Must be implemented in module class.
virtual int16_t startChannelScan ()
 Interrupt-driven channel activity detection method. Interrupt will be activated when packet is detected. Must be implemented in module class.
virtual int16_t startChannelScan (const ChannelScanConfig_t &config)
 Interrupt-driven channel activity detection method. interrupt will be activated when packet is detected. Must be implemented in module class.
virtual int16_t getChannelScanResult ()
 Read the channel scan result.
virtual int16_t scanChannel ()
 Check whether the current communication channel is free or occupied. Performs CAD for LoRa modules, or RSSI measurement for FSK modules.
virtual int16_t scanChannel (const ChannelScanConfig_t &config)
 Check whether the current communication channel is free or occupied. Performs CAD for LoRa modules, or RSSI measurement for FSK modules.
int32_t random (int32_t max)
 Get truly random number in range 0 - max.
int32_t random (int32_t min, int32_t max)
 Get truly random number in range min - max.
virtual uint8_t randomByte ()
 Get one truly random byte from RSSI noise. Must be implemented in module class.
int16_t startDirect ()
 Configure module parameters for direct modes. Must be called prior to "ham" modes like RTTY or AX.25. Only available in FSK mode.
int16_t setDirectSyncWord (uint32_t syncWord, uint8_t len)
 Set sync word to be used to determine start of packet in direct reception mode.
virtual void setDirectAction (void(*func)(void))
 Set interrupt service routine function to call when data bit is received in direct mode. Must be implemented in module class.
virtual void readBit (uint32_t pin)
 Function to read and process data bit in direct reception mode. Must be implemented in module class.
int16_t available ()
 Get the number of direct mode bytes currently available in buffer.
void dropSync ()
 Forcefully drop synchronization.
uint8_t read (bool drop=true)
 Get data from direct mode buffer.
virtual void setIrqAction (void(*func)(void), bool rising=true)
 Sets interrupt service routine to call when IRQ is activated.
virtual void clearIrqAction ()
 Clears interrupt service routine to call when IRQ is activated.
virtual int16_t setModem (ModemType_t modem)
 Set modem for the radio to use. Will perform full reset and reconfigure the radio using its default parameters.
virtual int16_t getModem (ModemType_t *modem)
 Get modem currently in use by the radio.
virtual int16_t getMode (RadioModeType_t *mode)
 Read the operating mode the radio is in, as the chip reports it. Unlike PhysicalLayer::stagedMode, which is what was last asked of the radio, this reads the hardware, so a caller can tell a radio that has left a mode on its own - a receive that did not survive a frame, or a chip that lost its state - from one that is still in it.
virtual int16_t stageMode (RadioModeType_t mode, RadioModeConfig_t *cfg)
 Stage mode of the radio to be launched later using launchMode.
virtual int16_t launchMode ()
 Launch previously staged mode.
virtual int16_t writeTxBuffer (const uint8_t *data, size_t len)
 Write a payload into the transmit buffer without staging or starting a transmission. This allows the payload write, which is the slowest part of starting a transmission, to be done while the radio is busy with something else - during a channel scan, for example. The transmission is staged afterwards by calling stageMode with RADIOLIB_RADIO_MODE_TX and RadioModeConfig_t::transmit.data set to NULL, which sets the packet parameters and the IRQ mapping for the payload already in the buffer; transmit.len must still be set to its length. The buffer holds exactly this payload after the call, whether or not one was written before.
virtual int16_t clearTxBuffer ()
 Discard a payload previously written by writeTxBuffer. On radios whose transmit buffer is simply overwritten by the next write there is nothing to discard, and this reports success without touching the radio.
int16_t calculateRxDutyCycle (size_t txPreLen, size_t rxPreLen, uint16_t minSymbols, DataRate_t *dr, uint32_t *wakePeriod, uint32_t *sleepPeriod)
 Calculates sleep and wake cycles for startReceiveDutyCycle methods so that the receiver should not miss any messages. Useful only for LoRa modems.
int8_t getOutputPowerMin () const
 Get the minimum output power supported by the radio. This includes any previously configured PA offset.
int8_t getOutputPowerMax () const
 Get the maximum output power supported by the radio. This includes any previously configured PA offset.

Static Public Member Functions

static float getNumSymbols (DataRate_t dr, PacketConfig_t pc, size_t len)
 Convert from bytes to LoRa symbols.

Public Attributes

float freqStep
 Frequency step of the synthesizer in Hz.
size_t maxPacketLength
 Maximum length of packet that can be received by the module.
bool resetOnStartup = true
 Whether to reset the module on startup. Setting to false allows to restore radio operation by calling begin after deep sleep mode on some platforms (like ESP32).

Friends

class AFSKClient
class RTTYClient
class MorseClient
class HellClient
class SSTVClient
class AX25Client
class FSK4Client
class PagerClient
class BellClient
class FT8Client
class LoRaWANNode
class M17Client

Detailed Description

Provides common interface for protocols that run on LoRa/FSK modules, such as RTTY or LoRaWAN. Also extracts some common module-independent methods. Using this interface class allows to use the protocols on various modules without much code duplicity. Because this class is used mainly as interface, all of its virtual members must be implemented in the module class.

Member Function Documentation

◆ available()

int16_t PhysicalLayer::available ( )

Get the number of direct mode bytes currently available in buffer.

Returns
Number of available bytes.

◆ calculateRxDutyCycle()

int16_t PhysicalLayer::calculateRxDutyCycle ( size_t txPreLen,
size_t rxPreLen,
uint16_t minSymbols,
DataRate_t * dr,
uint32_t * wakePeriod,
uint32_t * sleepPeriod )

Calculates sleep and wake cycles for startReceiveDutyCycle methods so that the receiver should not miss any messages. Useful only for LoRa modems.

Parameters
txPreLenExpected preamble length of the messages to receive. If set to zero, the receiver preamble length will be used. This value cannot exceed the configured preamble length. If the sender preamble length is variable, set the maximum expected length by calling setPreambleLength(maximumExpectedLength) prior to this method, and use the minimum expected length here.
rxPreLenCurrently configured preamble length of the receiver (this radio).
minSymbolsEnsure that the unit will catch at least this many symbols of any preamble of the specified senderPreambleLength. To reliably latch a preamble, the receiver requires 8 symbols for SF7-12 and 12 symbols for SF5-6. If set to zero, the minimum required symbols will be used.
drPointer to structure holding LoRa data rate information (only spreading factor and bandwidth are used).
wakePeriodPointer to variable where the calculated wake period in microseconds will be stored.
sleePeriodPointer to variable where the calculated sleep period in microseconds will be stored.
Returns
Status Codes

◆ calculateRxTimeout()

RadioLibTime_t PhysicalLayer::calculateRxTimeout ( RadioLibTime_t timeoutUs)
virtual

Calculate the timeout value for this specific module / series (in number of symbols or units of time).

Parameters
timeoutUsTimeout in microseconds to listen for.
Returns
Timeout value in a unit that is specific for the used module.

Reimplemented in LRxxxx, SX126x, SX127x, and SX128x.

◆ calculateTimeOnAir()

RadioLibTime_t PhysicalLayer::calculateTimeOnAir ( ModemType_t modem,
DataRate_t dr,
PacketConfig_t pc,
size_t len )
virtual

Calculate the expected time-on-air for a given modem, data rate, packet configuration and payload size.

Parameters
modemModem type.
drData rate.
pcPacket config.
lenPayload length in bytes.
Returns
Expected time-on-air in microseconds.

Reimplemented in SX127x, and SX128x.

◆ checkDataRate()

int16_t PhysicalLayer::checkDataRate ( DataRate_t dr,
ModemType_t modem = RADIOLIB_MODEM_NONE )
virtual

Check the data rate can be configured by this module. Must be implemented in module class if the module supports it.

Parameters
drData rate struct.
modemThe modem corresponding to the requested datarate (FSK, LoRa or LR-FHSS). Defaults to currently active modem if not supplied.
Returns
Status Codes

Reimplemented in LLCC68, LR11x0, LR2021, SX126x, SX1272, SX1273, SX1277, SX1278, and SX128x.

◆ checkIrq()

int16_t PhysicalLayer::checkIrq ( RadioLibIrqType_t irq)

Check whether a specific IRQ bit is set (e.g. RxTimeout, CadDone).

Parameters
irqIRQ type to check, one of RADIOLIB_IRQ_*.
Returns
1 when requested IRQ is set, 0 when it is not or RADIOLIB_ERR_UNSUPPORTED if the IRQ is not supported.

◆ clearIrq()

int16_t PhysicalLayer::clearIrq ( RadioLibIrqFlags_t irq)

Clear interrupt on a specific IRQ bit (e.g. RxTimeout, CadDone). Keep in mind that not all radio modules support all RADIOLIB_IRQ_ flags!

Parameters
irqFlags to set, multiple bits may be enabled. IRQ to enable corresponds to the bit index (RadioLibIrq_t). For example, if bit 0 is enabled, the module will enable its RADIOLIB_IRQ_TX_DONE (if it is supported).
Returns
Status Codes

◆ clearIrqFlags()

int16_t PhysicalLayer::clearIrqFlags ( uint32_t irq)
virtual

Clear interrupt on a specific IRQ bit (e.g. RxTimeout, CadDone). Must be implemented in module class.

Parameters
irqModule-specific IRQ flags.
Returns
Status Codes

Reimplemented in LR11x0, LR2021, Si443x, SX126x, SX127x, and SX128x.

◆ clearTxBuffer()

int16_t PhysicalLayer::clearTxBuffer ( )
virtual

Discard a payload previously written by writeTxBuffer. On radios whose transmit buffer is simply overwritten by the next write there is nothing to discard, and this reports success without touching the radio.

Returns
Status Codes

Reimplemented in LR11x0, LR2021, SX126x, SX127x, and SX128x.

◆ finishReceive()

int16_t PhysicalLayer::finishReceive ( )
virtual

Clean up after reception is done.

Returns
Status Codes

Reimplemented in CC1101, LR11x0, LR2021, nRF24, RF69, Si443x, SX126x, SX127x, and SX128x.

◆ finishTransmit()

int16_t PhysicalLayer::finishTransmit ( )
virtual

Clean up after transmission is done.

Returns
Status Codes

Reimplemented in CC1101, and SX127x.

◆ getChannelScanResult()

int16_t PhysicalLayer::getChannelScanResult ( )
virtual

Read the channel scan result.

Returns
Status Codes

Reimplemented in LR11x0, LR2021, SX126x, SX127x, and SX128x.

◆ getIrqFlags()

uint32_t PhysicalLayer::getIrqFlags ( )
virtual

Read currently active IRQ flags. Must be implemented in module class.

Returns
IRQ flags.

Reimplemented in LR11x0, LR2021, Si443x, SX126x, SX127x, and SX128x.

◆ getIrqMapped()

uint32_t PhysicalLayer::getIrqMapped ( RadioLibIrqFlags_t irq)

Convert from radio-agnostic IRQ flags to radio-specific flags.

Parameters
irqRadio-agnostic IRQ flags.
Returns
Flags for a specific radio module.

◆ getMode()

int16_t PhysicalLayer::getMode ( RadioModeType_t * mode)
virtual

Read the operating mode the radio is in, as the chip reports it. Unlike PhysicalLayer::stagedMode, which is what was last asked of the radio, this reads the hardware, so a caller can tell a radio that has left a mode on its own - a receive that did not survive a frame, or a chip that lost its state - from one that is still in it.

Parameters
modePointer to the variable to save the mode into. A mode the chip reports that has no RadioModeType_t equivalent, frequency synthesis for example, is reported as RADIOLIB_RADIO_MODE_NONE.
Returns
Status Codes

Reimplemented in LR11x0, LR2021, SX126x, SX127x, and SX128x.

◆ getModem()

int16_t PhysicalLayer::getModem ( ModemType_t * modem)
virtual

Get modem currently in use by the radio.

Parameters
modemPointer to a variable to save the retrieved configuration into.
Returns
Status Codes

Reimplemented in LR11x0, LR2021, SX126x, SX127x, and SX128x.

◆ getNumSymbols()

float PhysicalLayer::getNumSymbols ( DataRate_t dr,
PacketConfig_t pc,
size_t len )
static

Convert from bytes to LoRa symbols.

Parameters
drData rate.
pcPacket configuration.
lenPayload length in bytes.
Returns
The total number of LoRa symbols, including preamble, sync and possible header.

◆ getOutputPowerMax()

int8_t PhysicalLayer::getOutputPowerMax ( ) const
inline

Get the maximum output power supported by the radio. This includes any previously configured PA offset.

Returns
The maximum supported output power in dBm.

◆ getOutputPowerMin()

int8_t PhysicalLayer::getOutputPowerMin ( ) const
inline

Get the minimum output power supported by the radio. This includes any previously configured PA offset.

Returns
The minimum supported output power in dBm.

◆ getPacketLength()

size_t PhysicalLayer::getPacketLength ( bool update = true)
virtual

Query modem for the packet length of received payload. Must be implemented in module class.

Parameters
updateUpdate received packet length. Will return cached value when set to false.
Returns
Length of last received packet in bytes.

Reimplemented in CC1101, LR11x0, LR2021, nRF24, RF69, Si443x, SX126x, SX127x, and SX128x.

◆ getRSSI()

float PhysicalLayer::getRSSI ( )
virtual

Gets RSSI (Received Signal Strength Indicator) of the last received packet.

Returns
RSSI of the last received packet in dBm.

Reimplemented in CC1101, LR11x0, LR2021, RF69, SX126x, SX1272, SX1278, and SX128x.

◆ getSNR()

float PhysicalLayer::getSNR ( )
virtual

Gets SNR (Signal to Noise Ratio) of the last received packet. Only available for LoRa modem.

Returns
SNR of the last received packet in dB.

Reimplemented in LR11x0, LR2021, SX126x, SX127x, and SX128x.

◆ getTimeOnAir()

RadioLibTime_t PhysicalLayer::getTimeOnAir ( size_t len)
virtual

Get expected time-on-air for a given size of payload.

Parameters
lenPayload length in bytes.
Returns
Expected time-on-air in microseconds.

Reimplemented in LR11x0, LR2021, SX126x, SX127x, and SX128x.

◆ invertIQ()

int16_t PhysicalLayer::invertIQ ( bool enable)
virtual

Set IQ inversion. Must be implemented in module class if the module supports it.

Parameters
enableTrue to use inverted IQ, false for non-inverted.
Returns
Status Codes

Reimplemented in LR11x0, LR2021, SX126x, SX127x, and SX128x.

◆ launchMode()

int16_t PhysicalLayer::launchMode ( )
virtual

Launch previously staged mode.

Returns
Status Codes

Reimplemented in LR11x0, LR2021, SX126x, SX127x, and SX128x.

◆ random() [1/2]

int32_t PhysicalLayer::random ( int32_t max)

Get truly random number in range 0 - max.

Parameters
maxThe maximum value of the random number (non-inclusive).
Returns
Random number.

◆ random() [2/2]

int32_t PhysicalLayer::random ( int32_t min,
int32_t max )

Get truly random number in range min - max.

Parameters
minThe minimum value of the random number (inclusive).
maxThe maximum value of the random number (non-inclusive).
Returns
Random number.

◆ randomByte()

uint8_t PhysicalLayer::randomByte ( )
virtual

Get one truly random byte from RSSI noise. Must be implemented in module class.

Returns
TRNG byte.

Reimplemented in CC1101, LR11x0, LR2021, RF69, Si443x, SX126x, SX127x, and SX128x.

◆ read()

uint8_t PhysicalLayer::read ( bool drop = true)

Get data from direct mode buffer.

Parameters
dropDrop synchronization on read - next reading will require waiting for the sync word again. Defaults to true.
Returns
Byte from direct mode buffer.

◆ readBit()

void PhysicalLayer::readBit ( uint32_t pin)
virtual

Function to read and process data bit in direct reception mode. Must be implemented in module class.

Parameters
pinPin on which to read.

Reimplemented in CC1101, RF69, Si443x, SX126x, SX127x, and SX128x.

◆ readData()

int16_t PhysicalLayer::readData ( uint8_t * data,
size_t len )
virtual

Reads data that was received after calling startReceive method.

Parameters
dataPointer to array to save the received binary data.
lenNumber of bytes that will be read. When set to 0, the packet length will be retrieved automatically. When more bytes than received are requested, only the number of bytes requested will be returned.
Returns
Status Codes

Reimplemented in CC1101, LR11x0, LR2021, nRF24, RF69, Si443x, SX126x, SX127x, and SX128x.

◆ receive()

int16_t PhysicalLayer::receive ( uint8_t * data,
size_t len,
RadioLibTime_t timeout = 0 )
virtual

Binary receive method. Must be implemented in module class.

Parameters
dataPointer to array to save the received binary data.
lenPacket length, needed for some modules under special circumstances (e.g. LoRa implicit header mode).
timeoutReception timeout in milliseconds. If set to 0, timeout period will be calculated automatically based on the radio configuration.
Returns
Status Codes

Reimplemented in CC1101, LR11x0, LR2021, nRF24, RF69, Si443x, SX126x, SX127x, and SX128x.

◆ receiveDirect()

int16_t PhysicalLayer::receiveDirect ( )
virtual

Enables direct reception mode on pins DIO1 (clock) and DIO2 (data). Must be implemented in module class. While in direct mode, the module will not be able to transmit or receive packets. Can only be activated in FSK mode.

Returns
Status Codes

Reimplemented in CC1101, LR11x0, LR2021, nRF24, RF69, Si443x, SX126x, SX127x, and SX128x.

◆ scanChannel() [1/2]

int16_t PhysicalLayer::scanChannel ( )
virtual

Check whether the current communication channel is free or occupied. Performs CAD for LoRa modules, or RSSI measurement for FSK modules.

Returns
RADIOLIB_CHANNEL_FREE when channel is free, RADIOLIB_LORA_DETECTED when occupied or other Status Codes.

Reimplemented in LR11x0, LR2021, SX126x, SX127x, and SX128x.

◆ scanChannel() [2/2]

int16_t PhysicalLayer::scanChannel ( const ChannelScanConfig_t & config)
virtual

Check whether the current communication channel is free or occupied. Performs CAD for LoRa modules, or RSSI measurement for FSK modules.

Parameters
configScan configuration structure. Interpretation depends on currently active modem.
Returns
RADIOLIB_CHANNEL_FREE when channel is free, RADIOLIB_LORA_DETECTED when occupied or other Status Codes.

Reimplemented in LR11x0, LR2021, SX126x, SX127x, and SX128x.

◆ setBandwidth()

int16_t PhysicalLayer::setBandwidth ( uint32_t bw)
virtual

Sets LoRa bandwidth. Must be implemented in module class.

Parameters
bwLoRa bandwidth to be set in Hz.
Returns
Status Codes

Reimplemented in LLCC68, LR11x0, LR2021, SX126x, SX1272, SX1278, and SX128x.

◆ setBitRate()

int16_t PhysicalLayer::setBitRate ( uint32_t br)
virtual

Sets FSK bit rate. Only available in FSK mode. Must be implemented in module class.

Parameters
brBit rate to be set (in bps).
Returns
Status Codes

Reimplemented in CC1101, LR11x0, LR2021, nRF24, RF69, Si443x, SX1233, SX126x, SX1272, SX1278, and SX128x.

◆ setCodingRate()

int16_t PhysicalLayer::setCodingRate ( uint8_t cr,
bool longInterleave = false )
virtual

Sets LoRa coding rate denominator. Must be implemented in module class.

Parameters
crLoRa coding rate denominator to be set. Allowed values range from 4 to 8. Note that a value of 4 means no coding, is undocumented and not recommended without your own FEC.
longInterleaveEnable long interleaver when set to true. Note that with long interleaver enabled, CR 4/7 is not possible, there are packet length restrictions, and it is not compatible with SX127x radios!
Returns
Status Codes

Reimplemented in LR11x0, LR2021, SX126x, SX1272, SX1278, and SX128x.

◆ setDataRate()

int16_t PhysicalLayer::setDataRate ( DataRate_t dr,
ModemType_t modem = RADIOLIB_MODEM_NONE )
virtual

Set data rate. Must be implemented in module class if the module supports it.

Parameters
drData rate struct.
modemThe modem corresponding to the requested datarate (FSK, LoRa or LR-FHSS). Defaults to currently active modem if not supplied.
Returns
Status Codes

◆ setDataShaping()

int16_t PhysicalLayer::setDataShaping ( uint8_t sh)
virtual

Sets GFSK data shaping. Only available in FSK mode. Must be implemented in module class.

Parameters
shShaping to be set. See Data shaping filter values aliases. for possible values.
Returns
Status Codes

Reimplemented in CC1101, ExternalRadio, LR11x0, LR2021, nRF24, RF69, Si443x, SX126x, SX1272, SX1278, and SX128x.

◆ setDirectAction()

void PhysicalLayer::setDirectAction ( void(* func )(void))
virtual

Set interrupt service routine function to call when data bit is received in direct mode. Must be implemented in module class.

Parameters
funcPointer to interrupt service routine.

Reimplemented in CC1101, RF69, Si443x, SX126x, SX127x, and SX128x.

◆ setDirectSyncWord()

int16_t PhysicalLayer::setDirectSyncWord ( uint32_t syncWord,
uint8_t len )

Set sync word to be used to determine start of packet in direct reception mode.

Parameters
syncWordSync word bits.
lenSync word length in bits. Set to zero to disable sync word matching.
Returns
Status Codes

◆ setEncoding()

int16_t PhysicalLayer::setEncoding ( uint8_t encoding)
virtual

Sets FSK data encoding. Only available in FSK mode. Must be implemented in module class.

Parameters
encodingEncoding to be used. See Encoding type aliases. for possible values.
Returns
Status Codes

Reimplemented in CC1101, ExternalRadio, LR11x0, LR2021, nRF24, RF69, Si443x, SX126x, SX127x, and SX128x.

◆ setFrequency()

int16_t PhysicalLayer::setFrequency ( uint32_t freq)
virtual

Sets carrier frequency. Must be implemented in module class.

Parameters
freqCarrier frequency to be set in Hz.
Returns
Status Codes

Reimplemented in CC1101, LR1110, LR1120, LR2021, nRF24, RF69, Si4430, Si4432, SX1262, SX1268, SX1272, SX1276, SX1277, SX1278, SX1279, and SX128x.

◆ setFrequencyDeviation()

int16_t PhysicalLayer::setFrequencyDeviation ( uint32_t freqDev)
virtual

Sets FSK frequency deviation from carrier frequency. Only available in FSK mode. Must be implemented in module class.

Parameters
freqDevFrequency deviation to be set in Hz.
Returns
Status Codes

Reimplemented in CC1101, ExternalRadio, LR11x0, LR2021, nRF24, RF69, Si443x, SX126x, SX127x, and SX128x.

◆ setIrq()

int16_t PhysicalLayer::setIrq ( RadioLibIrqFlags_t irq)

Set interrupt on specific IRQ bit(s) (e.g. RxTimeout, CadDone). Keep in mind that not all radio modules support all RADIOLIB_IRQ_ flags!

Parameters
irqFlags to set, multiple bits may be enabled. IRQ to enable corresponds to the bit index (RadioLibIrq_t). For example, if bit 0 is enabled, the module will enable its RADIOLIB_IRQ_TX_DONE (if it is supported).
Returns
Status Codes

◆ setIrqAction()

void PhysicalLayer::setIrqAction ( void(* func )(void),
bool rising = true )
virtual

Sets interrupt service routine to call when IRQ is activated.

Parameters
funcISR to call.
risingWhether to activate on rising (true) or falling (false) edge, defaults to rising.

◆ setIrqFlags()

int16_t PhysicalLayer::setIrqFlags ( uint32_t irq)
virtual

Set interrupt on DIO1 to be sent on a specific IRQ bit (e.g. RxTimeout, CadDone). Must be implemented in module class.

Parameters
irqModule-specific IRQ flags.
Returns
Status Codes

Reimplemented in LR11x0, LR2021, SX126x, SX127x, and SX128x.

◆ setLrFhssConfig()

int16_t PhysicalLayer::setLrFhssConfig ( uint8_t bw,
uint8_t cr,
bool narrowGrid,
uint8_t hdrCount = 3,
uint16_t hopSeed = 0x13A )
virtual

Sets LR-FHSS configuration. Must be implemented in module class.

Parameters
bwLR-FHSS bandwidth, one of RADIOLIB_LR_FHSS_BW_* values.
crLR-FHSS coding rate, one of RADIOLIB_LR_FHSS_CR_* values.
narrowGridTrue for narrow (non-FCC) hopping grid; false for wide (FCC) grid.
hdrCountHeader packet count, 1 - 4. Defaults to 3.
hopSeed9-bit seed number for PRNG generation of the hopping sequence. Defaults to 0x13A.
Returns
Status Codes

Reimplemented in LR11x0, LR2021, and SX126x.

◆ setModem()

int16_t PhysicalLayer::setModem ( ModemType_t modem)
virtual

Set modem for the radio to use. Will perform full reset and reconfigure the radio using its default parameters.

Parameters
modemModem type to set. Not all modems are implemented by all radio modules!
Returns
Status Codes

Reimplemented in LLCC68, LR1110, LR1120, LR2021, SX1262, SX1268, SX1272, SX1273, SX1276, SX1277, SX1278, SX1279, and SX128x.

◆ setOutputPower()

int16_t PhysicalLayer::setOutputPower ( int8_t power)
virtual

Set output power. Must be implemented in module class if the module supports it.

Parameters
powerOutput power in dBm. The allowed range depends on the module used.
Returns
Status Codes

Reimplemented in CC1101, LR1110, LR1120, LR11x0, LR2021, nRF24, RF69, Si4430, Si4431, Si4432, STM32WLx, SX1261, SX1262, SX1268, SX126x, SX1272, SX1278, and SX128x.

◆ setOutputPowerOffset() [1/2]

int16_t PhysicalLayer::setOutputPowerOffset ( const int8_t * lut,
size_t steps )

Sets offset of the output power. Useful for devices where the radio has an external power amplifier, or of the RF system has a known loss between the radio and the antenna. This overload allows to compensate a non-linear PA gain, dependant on the radio power output via a lookup table. NOTE: This method must be called BEFORE any calls to radio.begin() or radio.setOutputPower() for the offset to be applied!

Parameters
lutPointer to a lookup table to use - for each output power configuration, value from the lookup table will be applied as offset. NOTE: The lookup table must be monotonically decreasing (values are always either lowering or remaining the same) and in 1 dB steps.
stepsNumber of steps/entries in the lookup table - this depends on the range of output power by the radio module. Different radio modules support different output power ranges!
Returns
Status Codes

◆ setOutputPowerOffset() [2/2]

int16_t PhysicalLayer::setOutputPowerOffset ( int8_t offset)

Sets offset of the output power. Useful for devices where the radio has an external power amplifier, or of the RF system has a known loss between the radio and the antenna. NOTE: This method must be called BEFORE any calls to radio.begin() or radio.setOutputPower() for the offset to be applied!

Parameters
offsetOffset to apply. If the PA has a linear gain of 12 dB, call radio.setOutputPowerOffset(12). If the setup has 1 dB of loss, call radio.setOutputPowerOffset(-1) to compensate.
Returns
Status Codes

◆ setPreambleLength()

int16_t PhysicalLayer::setPreambleLength ( size_t len,
size_t detLen = 0xFFFFFFFF )
virtual

Set preamble length. Must be implemented in module class if the module supports it.

Parameters
lenPreamble length in symbols (LoRa) or bits (FSK). Maximum length depends on the module used.
detLenMinimum detected preamble length during reception. Allowed values depend on the module used.
Returns
Status Codes

Reimplemented in CC1101, LR11x0, LR2021, RF69, Si443x, SX126x, SX127x, and SX128x.

◆ setSpreadingFactor()

int16_t PhysicalLayer::setSpreadingFactor ( uint8_t sf)
virtual

Sets LoRa spreading factor. Must be implemented in module class.

Parameters
sfLoRa spreading factor to be set.
Returns
Status Codes

Reimplemented in LLCC68, LR11x0, LR2021, SX126x, SX1272, SX1273, SX1277, SX1278, and SX128x.

◆ setSyncWord()

int16_t PhysicalLayer::setSyncWord ( uint8_t * sync,
size_t len )
virtual

Set sync word. Must be implemented in module class if the module supports it.

Parameters
syncPointer to the sync word.
lenSync word length in bytes. Maximum length depends on the module used.
Returns
Status Codes

Reimplemented in CC1101, LR11x0, LR2021, RF69, Si443x, SX126x, SX127x, and SX128x.

◆ sleep()

int16_t PhysicalLayer::sleep ( )
virtual

Sets module to sleep.

Returns
Status Codes

Reimplemented in CC1101, LR11x0, LR2021, nRF24, RF69, Si443x, SX126x, SX127x, and SX128x.

◆ stageMode()

int16_t PhysicalLayer::stageMode ( RadioModeType_t mode,
RadioModeConfig_t * cfg )
virtual

Stage mode of the radio to be launched later using launchMode.

Parameters
modeRadio mode to prepare.
cfgConfiguration of this mode (mode-dependent).
Returns
Status Codes

Reimplemented in LR11x0, LR2021, SX126x, SX127x, and SX128x.

◆ standby() [1/2]

int16_t PhysicalLayer::standby ( )
virtual

Sets module to standby.

Returns
Status Codes

Reimplemented in CC1101, LR11x0, LR2021, nRF24, RF69, Si443x, SX126x, SX127x, and SX128x.

◆ standby() [2/2]

int16_t PhysicalLayer::standby ( uint8_t mode)
virtual

Sets module to a specific standby mode.

Returns
Status Codes

Reimplemented in CC1101, LR11x0, LR2021, nRF24, RF69, Si443x, SX126x, SX127x, and SX128x.

◆ startChannelScan() [1/2]

int16_t PhysicalLayer::startChannelScan ( )
virtual

Interrupt-driven channel activity detection method. Interrupt will be activated when packet is detected. Must be implemented in module class.

Returns
Status Codes

Reimplemented in LR11x0, LR2021, SX126x, SX127x, and SX128x.

◆ startChannelScan() [2/2]

int16_t PhysicalLayer::startChannelScan ( const ChannelScanConfig_t & config)
virtual

Interrupt-driven channel activity detection method. interrupt will be activated when packet is detected. Must be implemented in module class.

Parameters
configScan configuration structure. Interpretation depends on currently active modem.
Returns
Status Codes

Reimplemented in LR11x0, LR2021, SX126x, SX127x, and SX128x.

◆ startDirect()

int16_t PhysicalLayer::startDirect ( )

Configure module parameters for direct modes. Must be called prior to "ham" modes like RTTY or AX.25. Only available in FSK mode.

Returns
Status Codes

◆ startReceive() [1/2]

int16_t PhysicalLayer::startReceive ( )
virtual

Sets module to received mode using its default configuration.

Returns
Status Codes

Reimplemented in CC1101, LR11x0, LR2021, nRF24, RF69, Si443x, SX126x, SX127x, and SX128x.

◆ startReceive() [2/2]

int16_t PhysicalLayer::startReceive ( uint32_t timeout,
RadioLibIrqFlags_t irqFlags = RADIOLIB_IRQ_RX_DEFAULT_FLAGS,
RadioLibIrqFlags_t irqMask = RADIOLIB_IRQ_RX_DEFAULT_MASK,
size_t len = 0 )
virtual

Interrupt-driven receive method. A DIO pin will be activated when full packet is received. Must be implemented in module class.

Parameters
timeoutRaw timeout value. Some modules use this argument to specify operation mode (single vs. continuous receive).
irqFlagsSets the IRQ flags.
irqMaskSets the mask of IRQ flags that will trigger the radio interrupt pin.
lenPacket length, needed for some modules under special circumstances (e.g. LoRa implicit header mode).
Returns
Status Codes

Reimplemented in CC1101, LR11x0, LR2021, nRF24, RF69, Si443x, SX126x, SX127x, and SX128x.

◆ startTransmit() [1/2]

int16_t PhysicalLayer::startTransmit ( const char * str,
uint8_t addr = 0 )

Interrupt-driven Arduino String transmit method. Unlike the standard transmit method, this one is non-blocking. Interrupt pin will be activated when transmission finishes.

Parameters
strC-string that will be transmitted.
addrNode address to transmit the packet to. Only used in FSK mode.
Returns
Status Codes

◆ startTransmit() [2/2]

int16_t PhysicalLayer::startTransmit ( const uint8_t * data,
size_t len,
uint8_t addr = 0 )
virtual

Interrupt-driven binary transmit method.

Parameters
dataBinary data that will be transmitted.
lenLength of binary data to transmit (in bytes).
addrNode address to transmit the packet to. Only used in FSK mode.
Returns
Status Codes

Reimplemented in CC1101, LR11x0, LR2021, nRF24, RF69, Si443x, SX126x, SX127x, and SX128x.

◆ transmit() [1/2]

int16_t PhysicalLayer::transmit ( const char * str,
uint8_t addr = 0 )

C-string transmit method.

Parameters
strC-string that will be transmitted.
addrNode address to transmit the packet to. Only used in FSK mode.
Returns
Status Codes

◆ transmit() [2/2]

int16_t PhysicalLayer::transmit ( const uint8_t * data,
size_t len,
uint8_t addr = 0 )
virtual

Binary transmit method. Must be implemented in module class.

Parameters
dataBinary data that will be transmitted.
lenLength of binary data to transmit (in bytes).
addrNode address to transmit the packet to. Only used in FSK mode.
Returns
Status Codes

Reimplemented in CC1101, LR11x0, LR2021, nRF24, RF69, Si443x, SX126x, SX127x, and SX128x.

◆ transmitDirect()

int16_t PhysicalLayer::transmitDirect ( uint32_t frf = 0)
virtual

Enables direct transmission mode on pins DIO1 (clock) and DIO2 (data). Must be implemented in module class. While in direct mode, the module will not be able to transmit or receive packets. Can only be activated in FSK mode.

Parameters
frf24-bit raw frequency value to start transmitting at. Required for quick frequency shifts in RTTY.
Returns
Status Codes

Reimplemented in CC1101, ExternalRadio, LR11x0, LR2021, nRF24, RF69, Si443x, SX126x, SX127x, and SX128x.

◆ writeTxBuffer()

int16_t PhysicalLayer::writeTxBuffer ( const uint8_t * data,
size_t len )
virtual

Write a payload into the transmit buffer without staging or starting a transmission. This allows the payload write, which is the slowest part of starting a transmission, to be done while the radio is busy with something else - during a channel scan, for example. The transmission is staged afterwards by calling stageMode with RADIOLIB_RADIO_MODE_TX and RadioModeConfig_t::transmit.data set to NULL, which sets the packet parameters and the IRQ mapping for the payload already in the buffer; transmit.len must still be set to its length. The buffer holds exactly this payload after the call, whether or not one was written before.

Parameters
dataPayload to write into the transmit buffer.
lenPayload length in bytes.
Returns
Status Codes

Reimplemented in LR11x0, LR2021, SX126x, SX127x, and SX128x.


The documentation for this class was generated from the following files:
  • src/protocols/PhysicalLayer/PhysicalLayer.h
  • src/protocols/PhysicalLayer/PhysicalLayer.cpp