RadioLib
Universal wireless communication library for Arduino
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 RF69 SX126x SX127x SX128x Si443x nRF24 SX1231 SX1262 SX1268 SX1272 SX1278 SX1281 Si4432 LLCC68 SX1261 SX1273 RFM95 RFM96 SX1276 SX1277 SX1279 SX1280 Si4430 Si4431

Public Member Functions

 PhysicalLayer (float freqStep, size_t maxPacketLength)
 Default constructor. More...
 
int16_t transmit (__FlashStringHelper *fstr, uint8_t addr=0)
 Arduino Flash String transmit method. More...
 
int16_t transmit (String &str, uint8_t addr=0)
 Arduino String transmit method. More...
 
int16_t transmit (const char *str, uint8_t addr=0)
 C-string transmit method. More...
 
virtual int16_t transmit (uint8_t *data, size_t len, uint8_t addr=0)=0
 Binary transmit method. Must be implemented in module class. More...
 
int16_t receive (String &str, size_t len=0)
 Arduino String receive method. More...
 
virtual int16_t standby ()=0
 Sets module to standby. More...
 
virtual int16_t receive (uint8_t *data, size_t len)=0
 Binary receive method. Must be implemented in module class. More...
 
int16_t startTransmit (String &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. More...
 
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. More...
 
virtual int16_t startTransmit (uint8_t *data, size_t len, uint8_t addr=0)=0
 Interrupt-driven binary transmit method. More...
 
virtual int16_t finishTransmit ()=0
 Clean up after transmission is done. More...
 
int16_t readData (String &str, size_t len=0)
 Reads data that was received after calling startReceive method. More...
 
virtual int16_t readData (uint8_t *data, size_t len)=0
 Reads data that was received after calling startReceive method. More...
 
virtual int16_t transmitDirect (uint32_t frf=0)=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. More...
 
virtual int16_t receiveDirect ()=0
 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. More...
 
virtual int16_t setFrequency (float freq)=0
 Sets carrier frequency. Must be implemented in module class. More...
 
virtual int16_t setBitRate (float br)=0
 Sets FSK bit rate. Only available in FSK mode. Must be implemented in module class. More...
 
virtual int16_t setFrequencyDeviation (float freqDev)=0
 Sets FSK frequency deviation from carrier frequency. Only available in FSK mode. Must be implemented in module class. More...
 
virtual int16_t setDataShaping (uint8_t sh)=0
 Sets GFSK data shaping. Only available in FSK mode. Must be implemented in module class. More...
 
virtual int16_t setEncoding (uint8_t encoding)=0
 Sets FSK data encoding. Only available in FSK mode. Must be implemented in module class. More...
 
float getFreqStep () const
 Gets the module frequency step size that was set in constructor. More...
 
virtual size_t getPacketLength (bool update=true)=0
 Query modem for the packet length of received payload. Must be implemented in module class. More...
 
int32_t random (int32_t max)
 Get truly random number in range 0 - max. More...
 
int32_t random (int32_t min, int32_t max)
 Get truly random number in range min - max. More...
 
virtual uint8_t randomByte ()=0
 Get one truly random byte from RSSI noise. Must be implemented in module class. More...
 
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. More...
 
int16_t setDirectSyncWord (uint32_t syncWord, uint8_t len)
 Set sync word to be used to determine start of packet in direct reception mode. More...
 
virtual void setDirectAction (void(*func)(void))=0
 Set interrupt service routine function to call when data bit is receveid in direct mode. Must be implemented in module class. More...
 
virtual void readBit (RADIOLIB_PIN_TYPE pin)=0
 Function to read and process data bit in direct reception mode. Must be implemented in module class. More...
 
int16_t available ()
 Get the number of direct mode bytes currently available in buffer. More...
 
void dropSync ()
 Forcefully drop synchronization.
 
uint8_t read (bool drop=true)
 Get data from direct mode buffer. More...
 
virtual int16_t setDIOMapping (RADIOLIB_PIN_TYPE pin, uint8_t value)
 Configure DIO pin mapping to get a given signal on a DIO pin (if available). More...
 

Friends

class AFSKClient
 
class RTTYClient
 
class MorseClient
 
class HellClient
 
class SSTVClient
 
class AX25Client
 
class FSK4Client
 
class PagerClient
 

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.

Constructor & Destructor Documentation

◆ PhysicalLayer()

PhysicalLayer::PhysicalLayer ( float  freqStep,
size_t  maxPacketLength 
)

Default constructor.

Parameters
freqStepFrequency step of the synthesizer in Hz.
maxPacketLengthMaximum length of packet that can be received by the module.

Member Function Documentation

◆ available()

int16_t PhysicalLayer::available ( )

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

Returns
Number of available bytes.

◆ finishTransmit()

virtual int16_t PhysicalLayer::finishTransmit ( )
pure virtual

Clean up after transmission is done.

Returns
Status Codes

Implemented in SX128x, SX127x, SX126x, Si443x, RF69, nRF24, and CC1101.

◆ getFreqStep()

float PhysicalLayer::getFreqStep ( ) const

Gets the module frequency step size that was set in constructor.

Returns
Synthesizer frequency step size in Hz.

◆ getPacketLength()

virtual size_t PhysicalLayer::getPacketLength ( bool  update = true)
pure 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.

Implemented in SX128x, SX127x, SX126x, Si443x, RF69, nRF24, and CC1101.

◆ 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()

virtual uint8_t PhysicalLayer::randomByte ( )
pure virtual

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

Returns
TRNG byte.

Implemented in SX128x, SX127x, SX126x, Si443x, RF69, nRF24, and CC1101.

◆ 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. Defautls to true.
Returns
Byte from direct mode buffer.

◆ readBit()

virtual void PhysicalLayer::readBit ( RADIOLIB_PIN_TYPE  pin)
pure virtual

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

Parameters
pinPin on which to read.

Implemented in SX128x, SX127x, SX126x, Si443x, RF69, nRF24, and CC1101.

◆ readData() [1/2]

int16_t PhysicalLayer::readData ( String &  str,
size_t  len = 0 
)

Reads data that was received after calling startReceive method.

Parameters
strAddress of Arduino String to save the received data.
lenExpected number of characters in the message. When set to 0, the packet length will be retreived automatically. When more bytes than received are requested, only the number of bytes requested will be returned.
Returns
Status Codes

◆ readData() [2/2]

virtual int16_t PhysicalLayer::readData ( uint8_t *  data,
size_t  len 
)
pure 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 retreived automatically. When more bytes than received are requested, only the number of bytes requested will be returned.
Returns
Status Codes

Implemented in SX128x, SX127x, SX126x, Si443x, RF69, nRF24, and CC1101.

◆ receive() [1/2]

int16_t PhysicalLayer::receive ( String &  str,
size_t  len = 0 
)

Arduino String receive method.

Parameters
strAddress of Arduino String to save the received data.
lenExpected number of characters in the message. Leave as 0 if expecting a unknown size packet
Returns
Status Codes

◆ receive() [2/2]

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

Binary receive method. Must be implemented in module class.

Parameters
dataPointer to array to save the received binary data.
lenNumber of bytes that will be received. Must be known in advance for binary transmissions.
Returns
Status Codes

Implemented in SX128x, SX127x, SX126x, Si443x, RF69, nRF24, and CC1101.

◆ receiveDirect()

virtual int16_t PhysicalLayer::receiveDirect ( )
pure 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

Implemented in SX128x, SX127x, SX126x, Si443x, RF69, nRF24, and CC1101.

◆ setBitRate()

virtual int16_t PhysicalLayer::setBitRate ( float  br)
pure virtual

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

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

Implemented in SX128x, SX127x, SX126x, Si443x, RF69, nRF24, and CC1101.

◆ setDataShaping()

virtual int16_t PhysicalLayer::setDataShaping ( uint8_t  sh)
pure 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

Implemented in SX128x, SX1278, SX1272, SX126x, Si443x, RF69, nRF24, and CC1101.

◆ setDIOMapping()

int16_t PhysicalLayer::setDIOMapping ( RADIOLIB_PIN_TYPE  pin,
uint8_t  value 
)
virtual

Configure DIO pin mapping to get a given signal on a DIO pin (if available).

Parameters
pinPin number onto which a signal is to be placed.
valueThe value that indicates which function to place on that pin. See chip datasheet for details.
Returns
Status Codes

Reimplemented in SX127x, RF69, and CC1101.

◆ setDirectAction()

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

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

Parameters
funcPointer to interrupt service routine.

Implemented in SX128x, SX127x, SX126x, Si443x, RF69, nRF24, and CC1101.

◆ 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()

virtual int16_t PhysicalLayer::setEncoding ( uint8_t  encoding)
pure virtual

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

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

Implemented in SX128x, SX127x, SX126x, Si443x, RF69, nRF24, and CC1101.

◆ setFrequency()

virtual int16_t PhysicalLayer::setFrequency ( float  freq)
pure virtual

Sets carrier frequency. Must be implemented in module class.

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

Implemented in SX128x, SX1279, SX1278, SX1277, SX1276, SX1272, SX1268, SX1262, Si4432, Si4430, RFM96, RFM95, RF69, nRF24, and CC1101.

◆ setFrequencyDeviation()

virtual int16_t PhysicalLayer::setFrequencyDeviation ( float  freqDev)
pure 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 kHz).
Returns
Status Codes

Implemented in SX128x, SX127x, SX126x, Si443x, RF69, nRF24, and CC1101.

◆ standby()

virtual int16_t PhysicalLayer::standby ( )
pure virtual

Sets module to standby.

Returns
Status Codes

Implemented in SX128x, SX127x, SX126x, Si443x, RF69, nRF24, and CC1101.

◆ 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

◆ startTransmit() [1/3]

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/3]

int16_t PhysicalLayer::startTransmit ( String &  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
strAddress of Arduino String that will be transmitted.
addrNode address to transmit the packet to. Only used in FSK mode.
Returns
Status Codes

◆ startTransmit() [3/3]

virtual int16_t PhysicalLayer::startTransmit ( uint8_t *  data,
size_t  len,
uint8_t  addr = 0 
)
pure 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

Implemented in SX128x, SX127x, SX126x, Si443x, RF69, CC1101, and nRF24.

◆ transmit() [1/4]

int16_t PhysicalLayer::transmit ( __FlashStringHelper *  fstr,
uint8_t  addr = 0 
)

Arduino Flash String transmit method.

Parameters
strPointer to Arduino Flash String that will be transmitted.
addrNode address to transmit the packet to. Only used in FSK mode.
Returns
Status Codes

◆ transmit() [2/4]

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() [3/4]

int16_t PhysicalLayer::transmit ( String &  str,
uint8_t  addr = 0 
)

Arduino String transmit method.

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

◆ transmit() [4/4]

virtual int16_t PhysicalLayer::transmit ( uint8_t *  data,
size_t  len,
uint8_t  addr = 0 
)
pure 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

Implemented in SX128x, SX127x, SX126x, Si443x, RF69, CC1101, and nRF24.

◆ transmitDirect()

virtual int16_t PhysicalLayer::transmitDirect ( uint32_t  frf = 0)
pure 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

Implemented in SX128x, SX127x, SX126x, Si443x, RF69, nRF24, and CC1101.


The documentation for this class was generated from the following files: