# RadioLib: src/protocols/PhysicalLayer/PhysicalLayer.h Source File

PhysicalLayer.h
#if !defined(_RADIOLIB_PHYSICAL_LAYER_H)
#define _RADIOLIB_PHYSICAL_LAYER_H
#include "../../TypeDef.h"
#include "../../Module.h"
// data rate structure interpretation in case LoRa is used
struct LoRaRate_t {
uint8_t spreadingFactor;
float bandwidth;
};
// data rate structure interpretation in case FSK is used
struct FSKRate_t {
float bitRate;
float freqDev;
};
// common data rate
union DataRate_t {
LoRaRate_t lora;
FSKRate_t fsk;
};
class PhysicalLayer {
public:
// constructor
PhysicalLayer(float step, size_t maxLen);
// basic methods
#if defined(RADIOLIB_BUILD_ARDUINO)
int16_t transmit(__FlashStringHelper* fstr, uint8_t addr = 0);
int16_t transmit(String& str, uint8_t addr = 0);
#endif
int16_t transmit(const char* str, uint8_t addr = 0);
virtual int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0);
#if defined(RADIOLIB_BUILD_ARDUINO)
int16_t receive(String& str, size_t len = 0);
#endif
virtual int16_t sleep();
virtual int16_t standby();
virtual int16_t standby(uint8_t mode);
virtual int16_t startReceive();
virtual int16_t startReceive(uint32_t timeout, uint16_t irqFlags, uint16_t irqMask, size_t len);
virtual int16_t receive(uint8_t* data, size_t len);
#if defined(RADIOLIB_BUILD_ARDUINO)
int16_t startTransmit(String& str, uint8_t addr = 0);
#endif
int16_t startTransmit(const char* str, uint8_t addr = 0);
virtual int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr = 0);
virtual int16_t finishTransmit();
#if defined(RADIOLIB_BUILD_ARDUINO)
int16_t readData(String& str, size_t len = 0);
#endif
virtual int16_t readData(uint8_t* data, size_t len);
virtual int16_t transmitDirect(uint32_t frf = 0);
virtual int16_t receiveDirect();
// configuration methods
virtual int16_t setFrequency(float freq);
virtual int16_t setBitRate(float br);
virtual int16_t setFrequencyDeviation(float freqDev);
virtual int16_t setDataShaping(uint8_t sh);
virtual int16_t setEncoding(uint8_t encoding);
virtual int16_t invertIQ(bool enable);
virtual int16_t setOutputPower(int8_t power);
virtual int16_t setSyncWord(uint8_t* sync, size_t len);
virtual int16_t setPreambleLength(size_t len);
virtual int16_t setDataRate(DataRate_t dr);
float getFreqStep() const;
virtual size_t getPacketLength(bool update = true);
virtual float getRSSI();
virtual float getSNR();
int32_t random(int32_t max);
int32_t random(int32_t min, int32_t max);
virtual uint8_t randomByte();
int16_t startDirect();
#if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
int16_t setDirectSyncWord(uint32_t syncWord, uint8_t len);
virtual void setDirectAction(void (*func)(void));
virtual void readBit(uint32_t pin);
int16_t available();
void dropSync();
uint8_t read(bool drop = true);
#endif
virtual int16_t setDIOMapping(uint32_t pin, uint32_t value);
virtual void setPacketReceivedAction(void (*func)(void));
virtual void clearPacketReceivedAction();
virtual void setPacketSentAction(void (*func)(void));
virtual void clearPacketSentAction();
#if defined(RADIOLIB_INTERRUPT_TIMING)
void setInterruptSetup(void (*func)(uint32_t));
void setTimerFlag();
#endif
#if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
protected:
void updateDirectBuffer(uint8_t bit);
#endif
#if !defined(RADIOLIB_GODMODE)
private:
#endif
float freqStep;
size_t maxPacketLength;
#if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
uint8_t bufferBitPos;
uint8_t bufferWritePos;
uint8_t bufferReadPos;
uint8_t buffer[RADIOLIB_STATIC_ARRAY_SIZE];
uint32_t syncBuffer;
uint32_t directSyncWord;
uint8_t directSyncWordLen;
uint32_t directSyncWordMask;
bool gotSync;
#endif
virtual Module* getMod() = 0;
// allow specific classes access the private getMod method
friend class AFSKClient;
friend class RTTYClient;
friend class MorseClient;
friend class HellClient;
friend class SSTVClient;
friend class AX25Client;
friend class FSK4Client;
friend class PagerClient;
friend class BellClient;
friend class FT8Client;
friend class LoRaWANNode;
};
#endif
AFSKClient
Client for audio-based transmissions. Requires Arduino tone() function, and a module capable of direc...
Definition: AFSK.h:16
AX25Client
Client for AX25 communication.
Definition: AX25.h:238
BellClient
Client for Bell modem communication. The public interface is the same as Arduino Serial.
Definition: BellModem.h:57
FSK4Client
Client for FSK-4 communication. The public interface is the same as Arduino Serial.
Definition: FSK4.h:15
HellClient
Client for Hellschreiber transmissions.
Definition: Hellschreiber.h:90
LoRaWANNode
LoRaWAN-compatible node (class A device).
Definition: LoRaWAN.h:211
Module
Implements all common low-level methods to control the wireless module. Every module class contains o...
Definition: Module.h:31
MorseClient
Client for Morse Code communication. The public interface is the same as Arduino Serial.
Definition: Morse.h:93
PagerClient
Client for Pager communication.
Definition: Pager.h:62
PhysicalLayer
Provides common interface for protocols that run on LoRa/FSK modules, such as RTTY or LoRaWAN....
Definition: PhysicalLayer.h:33
PhysicalLayer::invertIQ
virtual int16_t invertIQ(bool enable)
Set IQ inversion. Must be implemented in module class if the module supports it.
Definition: PhysicalLayer.cpp:249
PhysicalLayer::startReceive
virtual int16_t startReceive()
Sets module to received mode using its default configuration.
Definition: PhysicalLayer.cpp:131
PhysicalLayer::randomByte
virtual uint8_t randomByte()
Get one truly random byte from RSSI noise. Must be implemented in module class.
Definition: PhysicalLayer.cpp:319
PhysicalLayer::finishTransmit
virtual int16_t finishTransmit()
Clean up after transmission is done.
Definition: PhysicalLayer.cpp:160
PhysicalLayer::setFrequencyDeviation
virtual int16_t setFrequencyDeviation(float freqDev)
Sets FSK frequency deviation from carrier frequency. Only available in FSK mode. Must be implemented ...
Definition: PhysicalLayer.cpp:234
PhysicalLayer::getPacketLength
virtual size_t getPacketLength(bool update=true)
Query modem for the packet length of received payload. Must be implemented in module class.
Definition: PhysicalLayer.cpp:279
PhysicalLayer::setPacketSentAction
virtual void setPacketSentAction(void(*func)(void))
Sets interrupt service routine to call when a packet is sent.
Definition: PhysicalLayer.cpp:432
PhysicalLayer::setDIOMapping
virtual int16_t setDIOMapping(uint32_t pin, uint32_t value)
Configure DIO pin mapping to get a given signal on a DIO pin (if available).
Definition: PhysicalLayer.cpp:418
PhysicalLayer::readData
virtual int16_t readData(uint8_t *data, size_t len)
Reads data that was received after calling startReceive method.
Definition: PhysicalLayer.cpp:209
PhysicalLayer::dropSync
void dropSync()
Forcefully drop synchronization.
Definition: PhysicalLayer.cpp:342
PhysicalLayer::transmit
int16_t transmit(const char *str, uint8_t addr=0)
C-string transmit method.
Definition: PhysicalLayer.cpp:52
PhysicalLayer::read
uint8_t read(bool drop=true)
Get data from direct mode buffer.
Definition: PhysicalLayer.cpp:349
PhysicalLayer::clearPacketSentAction
virtual void clearPacketSentAction()
Clears interrupt service routine to call when a packet is sent.
Definition: PhysicalLayer.cpp:436
PhysicalLayer::setSyncWord
virtual int16_t setSyncWord(uint8_t *sync, size_t len)
Set sync word. Must be implemented in module class if the module supports it.
Definition: PhysicalLayer.cpp:259
PhysicalLayer::setDataRate
virtual int16_t setDataRate(DataRate_t dr)
Set data. Must be implemented in module class if the module supports it.
Definition: PhysicalLayer.cpp:270
PhysicalLayer::clearPacketReceivedAction
virtual void clearPacketReceivedAction()
Clears interrupt service routine to call when a packet is received.
Definition: PhysicalLayer.cpp:428
PhysicalLayer::setPreambleLength
virtual int16_t setPreambleLength(size_t len)
Set preamble length. Must be implemented in module class if the module supports it.
Definition: PhysicalLayer.cpp:265
PhysicalLayer::startDirect
int16_t startDirect()
Configure module parameters for direct modes. Must be called prior to "ham" modes like RTTY or AX....
Definition: PhysicalLayer.cpp:323
PhysicalLayer::setFrequency
virtual int16_t setFrequency(float freq)
Sets carrier frequency. Must be implemented in module class.
Definition: PhysicalLayer.cpp:224
PhysicalLayer::setDirectSyncWord
int16_t setDirectSyncWord(uint32_t syncWord, uint8_t len)
Set sync word to be used to determine start of packet in direct reception mode.
Definition: PhysicalLayer.cpp:357
PhysicalLayer::startTransmit
int16_t startTransmit(const char *str, uint8_t addr=0)
Interrupt-driven Arduino String transmit method. Unlike the standard transmit method,...
Definition: PhysicalLayer.cpp:149
PhysicalLayer::getFreqStep
float getFreqStep() const
Gets the module frequency step size that was set in constructor.
Definition: PhysicalLayer.cpp:275
PhysicalLayer::transmitDirect
virtual int16_t transmitDirect(uint32_t frf=0)
Enables direct transmission mode on pins DIO1 (clock) and DIO2 (data). Must be implemented in module ...
Definition: PhysicalLayer.cpp:215
PhysicalLayer::getRSSI
virtual float getRSSI()
Gets RSSI (Recorded Signal Strength Indicator) of the last received packet.
Definition: PhysicalLayer.cpp:284
PhysicalLayer::available
int16_t available()
Get the number of direct mode bytes currently available in buffer.
Definition: PhysicalLayer.cpp:338
PhysicalLayer::receive
virtual int16_t receive(uint8_t *data, size_t len)
Binary receive method. Must be implemented in module class.
Definition: PhysicalLayer.cpp:112
PhysicalLayer::setDirectAction
virtual void setDirectAction(void(*func)(void))
Set interrupt service routine function to call when data bit is received in direct mode....
Definition: PhysicalLayer.cpp:408
PhysicalLayer::setEncoding
virtual int16_t setEncoding(uint8_t encoding)
Sets FSK data encoding. Only available in FSK mode. Must be implemented in module class.
Definition: PhysicalLayer.cpp:244
PhysicalLayer::standby
virtual int16_t standby()
Sets module to standby.
Definition: PhysicalLayer.cpp:122
PhysicalLayer::random
int32_t random(int32_t max)
Get truly random number in range 0 - max.
Definition: PhysicalLayer.cpp:292
PhysicalLayer::readBit
virtual void readBit(uint32_t pin)
Function to read and process data bit in direct reception mode. Must be implemented in module class.
Definition: PhysicalLayer.cpp:412
PhysicalLayer::setOutputPower
virtual int16_t setOutputPower(int8_t power)
Set output power. Must be implemented in module class if the module supports it.
Definition: PhysicalLayer.cpp:254
PhysicalLayer::receiveDirect
virtual int16_t receiveDirect()
Enables direct reception mode on pins DIO1 (clock) and DIO2 (data). Must be implemented in module cla...
Definition: PhysicalLayer.cpp:220
PhysicalLayer::PhysicalLayer
PhysicalLayer(float step, size_t maxLen)
Default constructor.
Definition: PhysicalLayer.cpp:4
PhysicalLayer::setDataShaping
virtual int16_t setDataShaping(uint8_t sh)
Sets GFSK data shaping. Only available in FSK mode. Must be implemented in module class.
Definition: PhysicalLayer.cpp:239
PhysicalLayer::setPacketReceivedAction
virtual void setPacketReceivedAction(void(*func)(void))
Sets interrupt service routine to call when a packet is received.
Definition: PhysicalLayer.cpp:424
PhysicalLayer::setBitRate
virtual int16_t setBitRate(float br)
Sets FSK bit rate. Only available in FSK mode. Must be implemented in module class.
Definition: PhysicalLayer.cpp:229
PhysicalLayer::getSNR
virtual float getSNR()
Gets SNR (Signal to Noise Ratio) of the last received packet. Only available for LoRa modem.
Definition: PhysicalLayer.cpp:288
PhysicalLayer::sleep
virtual int16_t sleep()
Sets module to sleep.
Definition: PhysicalLayer.cpp:118
RTTYClient
Client for RTTY communication. The public interface is the same as Arduino Serial.
Definition: RTTY.h:17
SSTVClient
Client for SSTV transmissions.
Definition: SSTV.h:117
FSKRate_t
Definition: PhysicalLayer.h:14
LoRaRate_t
Definition: PhysicalLayer.h:8
DataRate_t
Definition: PhysicalLayer.h:20