LoRaLib
Arduino library for LoRa modules based on LoRa chips by Semtech (SX1272, SX1276, SX1278) and HopeRF (RFM95, RFM96, RFM98)
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:
SX127x SX1272 SX1278 SX1273 RFM95 RFM96 SX1276 SX1277 SX1279 RFM97

Public Member Functions

 PhysicalLayer (float crysFreq, uint8_t divExp, 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 receive (uint8_t *data, size_t len)=0
 Binary receive method. Must be implemented in module class. More...
 
virtual int16_t standby ()=0
 Sets module to standby. 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...
 
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 setFrequencyDeviation (float freqDev)=0
 Sets FSK frequency deviation from carrier frequency. Allowed values depend on bit rate setting and must be lower than 200 kHz. Only available in FSK mode. Must be implemented in module class. More...
 
float getCrystalFreq ()
 Gets the module crystal oscillator frequency that was set in constructor. More...
 
uint8_t getDivExponent ()
 Gets the module frequency divider exponent that was set in constructor. More...
 
virtual size_t getPacketLength (bool update=true)=0
 Query modem for the packet length of received payload. More...
 

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 ( float  crysFreq,
uint8_t  divExp,
size_t  maxPacketLength 
)

Default constructor.

Parameters
crysFreqFrequency of crystal oscillator inside the module in MHz.
divExpExponent of module frequency divider.
maxPacketLengthMaximum length of packet that can be received by the module-

Member Function Documentation

float PhysicalLayer::getCrystalFreq ( )

Gets the module crystal oscillator frequency that was set in constructor.

Returns
Crystal oscillator frequency in MHz.
uint8_t PhysicalLayer::getDivExponent ( )

Gets the module frequency divider exponent that was set in constructor.

Returns
Frequency divider exponent.
virtual size_t PhysicalLayer::getPacketLength ( bool  update = true)
pure virtual

Query modem for the packet length of received payload.

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

Implemented in SX127x.

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.
Returns
Status Codes
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 received. Must be known in advance for binary transmissions.
Returns
Status Codes

Implemented in SX127x.

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
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 SX127x.

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 SX127x.

virtual int16_t PhysicalLayer::setFrequencyDeviation ( float  freqDev)
pure virtual

Sets FSK frequency deviation from carrier frequency. Allowed values depend on bit rate setting and must be lower than 200 kHz. Only available in FSK mode. Must be implemented in module class.

Parameters
freqDevFrequency deviation to be set (in kHz).
Returns
Status Codes

Implemented in SX127x.

virtual int16_t PhysicalLayer::standby ( )
pure virtual

Sets module to standby.

Returns
Status Codes

Implemented in SX127x.

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
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
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 SX127x.

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
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
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
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 SX127x.

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 SX127x.


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