RadioLib
Universal wireless communication library for Arduino
Loading...
Searching...
No Matches
PhysicalLayer.h
1#if !defined(_RADIOLIB_PHYSICAL_LAYER_H)
2#define _RADIOLIB_PHYSICAL_LAYER_H
3
4#include "../../TypeDef.h"
5#include "../../Module.h"
6
7// common IRQ values - the IRQ flags in RadioLibIrqFlags_t arguments are offset by this value
8enum RadioLibIrqType_t {
9 RADIOLIB_IRQ_TX_DONE = 0x00,
10 RADIOLIB_IRQ_RX_DONE = 0x01,
11 RADIOLIB_IRQ_PREAMBLE_DETECTED = 0x02,
12 RADIOLIB_IRQ_SYNC_WORD_VALID = 0x03,
13 RADIOLIB_IRQ_HEADER_VALID = 0x04,
14 RADIOLIB_IRQ_HEADER_ERR = 0x05,
15 RADIOLIB_IRQ_CRC_ERR = 0x06,
16 RADIOLIB_IRQ_CAD_DONE = 0x07,
17 RADIOLIB_IRQ_CAD_DETECTED = 0x08,
18 RADIOLIB_IRQ_TIMEOUT = 0x09,
19 RADIOLIB_IRQ_NOT_SUPPORTED = 0x1F, // this must be the last value, intentionally set to 31
20};
21
22// some commonly used default values - defined here to ensure all modules have the same default behavior
23#define RADIOLIB_IRQ_RX_DEFAULT_FLAGS ((1UL << RADIOLIB_IRQ_RX_DONE) | (1UL << RADIOLIB_IRQ_TIMEOUT) | (1UL << RADIOLIB_IRQ_CRC_ERR) | (1UL << RADIOLIB_IRQ_HEADER_VALID) | (1UL << RADIOLIB_IRQ_HEADER_ERR))
24#define RADIOLIB_IRQ_RX_DEFAULT_MASK ((1UL << RADIOLIB_IRQ_RX_DONE))
25#define RADIOLIB_IRQ_CAD_DEFAULT_FLAGS ((1UL << RADIOLIB_IRQ_CAD_DETECTED) | (1UL << RADIOLIB_IRQ_CAD_DONE))
26#define RADIOLIB_IRQ_CAD_DEFAULT_MASK ((1UL << RADIOLIB_IRQ_CAD_DETECTED) | (1UL << RADIOLIB_IRQ_CAD_DONE))
27
32struct LoRaRate_t {
35
37 uint32_t bandwidth;
38
40 uint8_t codingRate;
41};
42
47struct FSKRate_t {
49 uint32_t bitRate;
50
52 uint32_t freqDev;
53};
54
61 uint8_t bw;
62
64 uint8_t cr;
65
68};
69
84
88
91
94
97};
98
102
105
107 uint8_t crcLength;
108};
109
112 uint8_t hdrCount;
113};
114
123};
124
154
161 float limit;
162};
163
175
178 uint8_t mode;
179};
180
197
200 const uint8_t* data;
201
203 size_t len;
204
206 uint8_t addr;
207};
208
211 uint8_t mode;
212};
213
230
235enum ModemType_t {
236 RADIOLIB_MODEM_FSK = 0,
237 RADIOLIB_MODEM_LORA,
238 RADIOLIB_MODEM_LRFHSS,
239 RADIOLIB_MODEM_NONE, // last entry
240};
241
246enum RadioModeType_t {
247 RADIOLIB_RADIO_MODE_NONE = 0,
248 RADIOLIB_RADIO_MODE_STANDBY,
249 RADIOLIB_RADIO_MODE_RX,
250 RADIOLIB_RADIO_MODE_TX,
251 RADIOLIB_RADIO_MODE_SCAN,
252 RADIOLIB_RADIO_MODE_SLEEP,
253};
254
255#define RADIOLIB_LORA_SYNC_WORD_PRIVATE (0x12UL << 0) // 7 0 LoRa sync word: private network
256#define RADIOLIB_LORA_SYNC_WORD_PUBLIC (0x34UL << 0) // 7 0 public network (LoRaWAN)
257
258#define RADIOLIB_LR_FHSS_CR_5_6 (0x00UL << 0) // 7 0 LR-FHSS coding rate: 5/6
259#define RADIOLIB_LR_FHSS_CR_2_3 (0x01UL << 0) // 7 0 2/3
260#define RADIOLIB_LR_FHSS_CR_1_2 (0x02UL << 0) // 7 0 1/2
261#define RADIOLIB_LR_FHSS_CR_1_3 (0x03UL << 0) // 7 0 1/3
262#define RADIOLIB_LR_FHSS_BW_39_06 (0x00UL << 0) // 7 0 LR-FHSS bandwidth: 39.06 kHz
263#define RADIOLIB_LR_FHSS_BW_85_94 (0x01UL << 0) // 7 0 85.94 kHz
264#define RADIOLIB_LR_FHSS_BW_136_72 (0x02UL << 0) // 7 0 136.72 kHz
265#define RADIOLIB_LR_FHSS_BW_183_59 (0x03UL << 0) // 7 0 183.59 kHz
266#define RADIOLIB_LR_FHSS_BW_335_94 (0x04UL << 0) // 7 0 335.94 kHz
267#define RADIOLIB_LR_FHSS_BW_386_72 (0x05UL << 0) // 7 0 386.72 kHz
268#define RADIOLIB_LR_FHSS_BW_722_66 (0x06UL << 0) // 7 0 722.66 kHz
269#define RADIOLIB_LR_FHSS_BW_773_44 (0x07UL << 0) // 7 0 773.44 kHz
270#define RADIOLIB_LR_FHSS_BW_1523_4 (0x08UL << 0) // 7 0 1523.4 kHz
271#define RADIOLIB_LR_FHSS_BW_1574_2 (0x09UL << 0) // 7 0 1574.2 kHz
272
273#define RADIOLIB_FLRC_BR_2600 (0x00UL << 0) // 7 0 bitrate/bandwidth: 2600 kbps, 2666 kHz
274#define RADIOLIB_FLRC_BR_2080 (0x01UL << 0) // 7 0 2080 kbps, 2222 kHz
275#define RADIOLIB_FLRC_BR_1300 (0x02UL << 0) // 7 0 1300 kbps, 1333 kHz
276#define RADIOLIB_FLRC_BR_1040 (0x03UL << 0) // 7 0 1040 kbps, 1333 kHz
277#define RADIOLIB_FLRC_BR_650 (0x04UL << 0) // 7 0 650 kbps, 888 kHz
278#define RADIOLIB_FLRC_BR_520 (0x05UL << 0) // 7 0 520 kbps, 769 kHz
279#define RADIOLIB_FLRC_BR_325 (0x06UL << 0) // 7 0 325 kbps, 444 kHz
280#define RADIOLIB_FLRC_BR_260 (0x07UL << 0) // 7 0 260 kbps, 444 kHz
281#define RADIOLIB_FLRC_CR_1_2 (0x00UL << 0) // 7 0 coding rate: 1/2
282#define RADIOLIB_FLRC_CR_3_4 (0x01UL << 0) // 7 0 3/4
283#define RADIOLIB_FLRC_CR_1_0 (0x02UL << 0) // 7 0 1 (un-coded)
284#define RADIOLIB_FLRC_CR_2_3 (0x03UL << 0) // 7 0 2/3
285
286#define RADIOLIB_LR_FHSS_BIT_RATE (488.28215f) // 31 0 LR FHSS bit rate: 488.28215 bps
287#define RADIOLIB_LR_FHSS_HEADER_BITS (114) // 7 0 LR FHSS packet bit widths: header
288#define RADIOLIB_LR_FHSS_FRAG_BITS (48) // 7 0 payload fragment
289#define RADIOLIB_LR_FHSS_BLOCK_PREAMBLE_BITS (2) // 7 0 block preamble
290#define RADIOLIB_LR_FHSS_BLOCK_BITS (RADIOLIB_LR_FHSS_FRAG_BITS + RADIOLIB_LR_FHSS_BLOCK_PREAMBLE_BITS)
291
294 uint32_t frequency = RADIOLIB_UNIT_MEGA(434);
296 uint32_t bandwidth = RADIOLIB_UNIT_KILO(125);
298 uint8_t spreadingFactor = 9;
301 uint8_t codingRate = 7;
303 uint8_t syncWord = RADIOLIB_LORA_SYNC_WORD_PRIVATE;
305 int8_t power = 10;
307 uint16_t preambleLength = 8;
308};
309
312 uint32_t frequency = RADIOLIB_UNIT_MEGA(434);
314 uint32_t bitRate = 4800;
316 uint32_t frequencyDeviation = RADIOLIB_UNIT_KILO(5);
318 uint32_t receiverBandwidth = RADIOLIB_UNIT_KILO(125);
320 int8_t power = 10;
322 uint16_t preambleLength = 16;
323};
324
327 uint32_t frequency = RADIOLIB_UNIT_MEGA(434);
329 uint32_t bitRate = 4800;
331 int8_t power = 10;
332};
333
336 uint32_t frequency = RADIOLIB_UNIT_MEGA(434);
338 uint32_t bitRate = 4800;
340 uint32_t receiverBandwidth = RADIOLIB_UNIT_KILO(125);
342 int8_t power = 10;
344 uint16_t preambleLength = 16;
345};
346
349 uint32_t frequency = RADIOLIB_UNIT_MEGA(434);
351 uint8_t bandwidth = RADIOLIB_LR_FHSS_BW_722_66;
353 uint8_t codingRate = RADIOLIB_LR_FHSS_CR_2_3;
355 bool narrowGrid = true;
357 int8_t power = 10;
358};
359
362 uint32_t frequency = RADIOLIB_UNIT_MEGA(434);
364 uint32_t bitRate = RADIOLIB_UNIT_KILO(650);
366 uint8_t codingRate = RADIOLIB_FLRC_CR_2_3;
368 int8_t power = 10;
370 uint16_t preambleLength = 16;
373};
374
377 uint32_t frequency = RADIOLIB_UNIT_MEGA(2400);
379 uint16_t bitRate = 800;
381 uint32_t frequencyDeviation = RADIOLIB_UNIT_KILO(400);
383 int8_t power = 10;
386};
387
393
403 public:
404
406 float freqStep;
407
410
416 bool resetOnStartup = true;
417
418 // constructor
419
424
428 virtual ~PhysicalLayer() = default;
429
430 // basic methods
431
432 #if defined(RADIOLIB_BUILD_ARDUINO)
439 int16_t transmit(__FlashStringHelper* fstr, uint8_t addr = 0);
440
447 int16_t transmit(String& str, uint8_t addr = 0);
448 #endif
449
456 int16_t transmit(const char* str, uint8_t addr = 0);
457
465 virtual int16_t transmit(const uint8_t* data, size_t len, uint8_t addr = 0);
466
467 #if defined(RADIOLIB_BUILD_ARDUINO)
476 int16_t receive(String& str, size_t len = 0, RadioLibTime_t timeout = 0);
477 #endif
478
483 virtual int16_t sleep();
484
489 virtual int16_t standby();
490
495 virtual int16_t standby(uint8_t mode);
496
501 virtual int16_t startReceive();
502
513 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);
514
523 virtual int16_t receive(uint8_t* data, size_t len, RadioLibTime_t timeout = 0);
524
525 #if defined(RADIOLIB_BUILD_ARDUINO)
533 int16_t startTransmit(String& str, uint8_t addr = 0);
534 #endif
535
543 int16_t startTransmit(const char* str, uint8_t addr = 0);
544
552 virtual int16_t startTransmit(const uint8_t* data, size_t len, uint8_t addr = 0);
553
558 virtual int16_t finishTransmit();
559
564 virtual int16_t finishReceive();
565
566 #if defined(RADIOLIB_BUILD_ARDUINO)
574 int16_t readData(String& str, size_t len = 0);
575 #endif
576
584 virtual int16_t readData(uint8_t* data, size_t len);
585
592 virtual int16_t transmitDirect(uint32_t frf = 0);
593
599 virtual int16_t receiveDirect();
600
601 // configuration methods
602
608 virtual int16_t setFrequency(uint32_t freq);
609
615 virtual int16_t setBitRate(uint32_t br);
616
623 virtual int16_t setFrequencyDeviation(uint32_t freqDev);
624
630 virtual int16_t setSpreadingFactor(uint8_t sf);
631
637 virtual int16_t setBandwidth(uint32_t bw);
638
649 virtual int16_t setCodingRate(uint8_t cr, bool longInterleave = false);
650
660 virtual int16_t setLrFhssConfig(uint8_t bw, uint8_t cr, bool narrowGrid, uint8_t hdrCount = 3, uint16_t hopSeed = 0x13A);
661
667 virtual int16_t setDataShaping(uint8_t sh);
668
674 virtual int16_t setEncoding(uint8_t encoding);
675
681 virtual int16_t invertIQ(bool enable);
682
688 virtual int16_t setOutputPower(int8_t power);
689
699 int16_t setOutputPowerOffset(int8_t offset);
700
715 int16_t setOutputPowerOffset(const int8_t* lut, size_t steps);
716
723 virtual int16_t setSyncWord(uint8_t* sync, size_t len);
724
731 virtual int16_t setPreambleLength(size_t len, size_t detLen = 0xFFFFFFFF);
732
740 virtual int16_t setDataRate(DataRate_t dr, ModemType_t modem = RADIOLIB_MODEM_NONE);
741
749 virtual int16_t checkDataRate(DataRate_t dr, ModemType_t modem = RADIOLIB_MODEM_NONE);
750
756 virtual size_t getPacketLength(bool update = true);
757
762 virtual float getRSSI();
763
768 virtual float getSNR();
769
777 static float getNumSymbols(DataRate_t dr, PacketConfig_t pc, size_t len);
778
787 virtual RadioLibTime_t calculateTimeOnAir(ModemType_t modem, DataRate_t dr, PacketConfig_t pc, size_t len);
788
794 virtual RadioLibTime_t getTimeOnAir(size_t len);
795
803
809 uint32_t getIrqMapped(RadioLibIrqFlags_t irq);
810
816 int16_t checkIrq(RadioLibIrqType_t irq);
817
825 int16_t setIrq(RadioLibIrqFlags_t irq);
826
834 int16_t clearIrq(RadioLibIrqFlags_t irq);
835
841 virtual uint32_t getIrqFlags();
842
849 virtual int16_t setIrqFlags(uint32_t irq);
850
857 virtual int16_t clearIrqFlags(uint32_t irq);
858
864 virtual int16_t startChannelScan();
865
872 virtual int16_t startChannelScan(const ChannelScanConfig_t &config);
873
878 virtual int16_t getChannelScanResult();
879
886 virtual int16_t scanChannel();
887
895 virtual int16_t scanChannel(const ChannelScanConfig_t &config);
896
902 int32_t random(int32_t max);
903
910 int32_t random(int32_t min, int32_t max);
911
916 virtual uint8_t randomByte();
917
923 int16_t startDirect();
924
925 #if !RADIOLIB_EXCLUDE_DIRECT_RECEIVE
932 int16_t setDirectSyncWord(uint32_t syncWord, uint8_t len);
933
939 virtual void setDirectAction(void (*func)(void));
940
945 virtual void readBit(uint32_t pin);
946
951 int16_t available();
952
956 void dropSync();
957
964 uint8_t read(bool drop = true);
965 #endif
966
972 virtual void setIrqAction(void (*func)(void), bool rising = true);
973
977 virtual void clearIrqAction();
978
985 virtual int16_t setModem(ModemType_t modem);
986
992 virtual int16_t getModem(ModemType_t* modem);
993
1004 virtual int16_t getMode(RadioModeType_t* mode);
1005
1012 virtual int16_t stageMode(RadioModeType_t mode, RadioModeConfig_t* cfg);
1013
1018 virtual int16_t launchMode();
1019
1032 virtual int16_t writeTxBuffer(const uint8_t* data, size_t len);
1033
1040 virtual int16_t clearTxBuffer();
1041
1042 #if RADIOLIB_INTERRUPT_TIMING
1043
1049 void setInterruptSetup(void (*func)(uint32_t));
1050
1055 void setTimerFlag();
1056
1057 #endif
1058
1076 int16_t calculateRxDutyCycle(size_t txPreLen, size_t rxPreLen, uint16_t minSymbols, DataRate_t* dr, uint32_t* wakePeriod, uint32_t* sleepPeriod);
1077
1083 int8_t getOutputPowerMin() const { return(powerMin); }
1084
1090 int8_t getOutputPowerMax() const { return(powerMax); }
1091
1092#if !RADIOLIB_GODMODE
1093 protected:
1094#endif
1095 int8_t powerMin = 0, powerMax = 0;
1096 uint8_t paSteps = 0;
1097
1098 uint32_t irqMap[10] = { 0 };
1099 RadioModeType_t stagedMode = RADIOLIB_RADIO_MODE_NONE;
1100
1110 int16_t applyOutputPowerOffset(int8_t base, const int8_t* pwrReq, int8_t* pwrRadio);
1111 int16_t findRxBw(uint32_t rxBw, const uint32_t* rxBwAvg, const uint8_t* lut, size_t lutSize, uint32_t rxBwMax, uint8_t* val);
1112
1113#if !RADIOLIB_EXCLUDE_DIRECT_RECEIVE
1114 void updateDirectBuffer(uint8_t bit);
1115#endif
1116
1117#if !RADIOLIB_GODMODE
1118 private:
1119#endif
1120
1121 #if !RADIOLIB_EXCLUDE_DIRECT_RECEIVE
1122 uint8_t bufferBitPos = 0;
1123 uint8_t bufferWritePos = 0;
1124 uint8_t bufferReadPos = 0;
1125 uint8_t buffer[RADIOLIB_STATIC_ARRAY_SIZE] = { 0 };
1126 uint32_t syncBuffer = 0;
1127 uint32_t directSyncWord = 0;
1128 uint8_t directSyncWordLen = 0;
1129 uint32_t directSyncWordMask = 0;
1130 bool gotSync = false;
1131 #endif
1132
1133 virtual Module* getMod() = 0;
1134
1135 // allow specific classes access the private getMod method
1136 friend class AFSKClient;
1137 friend class RTTYClient;
1138 friend class MorseClient;
1139 friend class HellClient;
1140 friend class SSTVClient;
1141 friend class AX25Client;
1142 friend class FSK4Client;
1143 friend class PagerClient;
1144 friend class BellClient;
1145 friend class FT8Client;
1146 friend class LoRaWANNode;
1147 friend class M17Client;
1148
1149 int8_t paOffsetLut[48] = { 0 };
1150};
1151
1152#endif
virtual int16_t stageMode(RadioModeType_t mode, RadioModeConfig_t *cfg)
Stage mode of the radio to be launched later using launchMode.
Definition PhysicalLayer.cpp:697
virtual void clearIrqAction()
Clears interrupt service routine to call when IRQ is activated.
Definition PhysicalLayer.cpp:677
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 mi...
Definition PhysicalLayer.cpp:729
virtual int16_t invertIQ(bool enable)
Set IQ inversion. Must be implemented in module class if the module supports it.
Definition PhysicalLayer.cpp:300
virtual int16_t startReceive()
Sets module to received mode using its default configuration.
Definition PhysicalLayer.cpp:131
virtual uint8_t randomByte()
Get one truly random byte from RSSI noise. Must be implemented in module class.
Definition PhysicalLayer.cpp:572
size_t maxPacketLength
Maximum length of packet that can be received by the module.
Definition PhysicalLayer.h:409
virtual int16_t finishTransmit()
Clean up after transmission is done.
Definition PhysicalLayer.cpp:175
int16_t checkIrq(RadioLibIrqType_t irq)
Check whether a specific IRQ bit is set (e.g. RxTimeout, CadDone).
Definition PhysicalLayer.cpp:493
virtual int16_t getMode(RadioModeType_t *mode)
Read the operating mode the radio is in, as the chip reports it. Unlike PhysicalLayer::stagedMode,...
Definition PhysicalLayer.cpp:692
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:375
virtual void setIrqAction(void(*func)(void), bool rising=true)
Sets interrupt service routine to call when IRQ is activated.
Definition PhysicalLayer.cpp:671
int8_t getOutputPowerMax() const
Get the maximum output power supported by the radio. This includes any previously configured PA offse...
Definition PhysicalLayer.h:1090
virtual int16_t readData(uint8_t *data, size_t len)
Reads data that was received after calling startReceive method.
Definition PhysicalLayer.cpp:235
void dropSync()
Forcefully drop synchronization.
Definition PhysicalLayer.cpp:595
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.
Definition PhysicalLayer.cpp:281
int16_t transmit(const char *str, uint8_t addr=0)
C-string transmit method.
Definition PhysicalLayer.cpp:53
uint8_t read(bool drop=true)
Get data from direct mode buffer.
Definition PhysicalLayer.cpp:602
virtual RadioLibTime_t getTimeOnAir(size_t len)
Get expected time-on-air for a given size of payload.
Definition PhysicalLayer.cpp:471
virtual int16_t clearTxBuffer()
Discard a payload previously written by writeTxBuffer. On radios whose transmit buffer is simply over...
Definition PhysicalLayer.cpp:713
virtual int16_t writeTxBuffer(const uint8_t *data, size_t len)
Write a payload into the transmit buffer without staging or starting a transmission....
Definition PhysicalLayer.cpp:707
virtual int16_t launchMode()
Launch previously staged mode.
Definition PhysicalLayer.cpp:703
static float getNumSymbols(DataRate_t dr, PacketConfig_t pc, size_t len)
Convert from bytes to LoRa symbols.
Definition PhysicalLayer.cpp:392
virtual int16_t getChannelScanResult()
Read the channel scan result.
Definition PhysicalLayer.cpp:532
virtual int16_t setFrequencyDeviation(uint32_t freqDev)
Sets FSK frequency deviation from carrier frequency. Only available in FSK mode. Must be implemented ...
Definition PhysicalLayer.cpp:260
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:310
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 p...
Definition PhysicalLayer.cpp:682
virtual ~PhysicalLayer()=default
Default destructor.
virtual RadioLibTime_t calculateRxTimeout(RadioLibTime_t timeoutUs)
Calculate the timeout value for this specific module / series (in number of symbols or units of time)...
Definition PhysicalLayer.cpp:476
virtual int16_t setBitRate(uint32_t br)
Sets FSK bit rate. Only available in FSK mode. Must be implemented in module class.
Definition PhysicalLayer.cpp:255
int16_t setIrq(RadioLibIrqFlags_t irq)
Set interrupt on specific IRQ bit(s) (e.g. RxTimeout, CadDone). Keep in mind that not all radio modul...
Definition PhysicalLayer.cpp:501
int16_t startDirect()
Configure module parameters for direct modes. Must be called prior to "ham" modes like RTTY or AX....
Definition PhysicalLayer.cpp:576
virtual int16_t finishReceive()
Clean up after reception is done.
Definition PhysicalLayer.cpp:188
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:610
virtual int16_t setSpreadingFactor(uint8_t sf)
Sets LoRa spreading factor. Must be implemented in module class.
Definition PhysicalLayer.cpp:265
int16_t startTransmit(const char *str, uint8_t addr=0)
Interrupt-driven Arduino String transmit method. Unlike the standard transmit method,...
Definition PhysicalLayer.cpp:157
int16_t setOutputPowerOffset(int8_t offset)
Sets offset of the output power. Useful for devices where the radio has an external power amplifier,...
Definition PhysicalLayer.cpp:779
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 modu...
Definition PhysicalLayer.cpp:369
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:241
float freqStep
Frequency step of the synthesizer in Hz.
Definition PhysicalLayer.h:406
virtual float getRSSI()
Gets RSSI (Received Signal Strength Indicator) of the last received packet.
Definition PhysicalLayer.cpp:384
int16_t available()
Get the number of direct mode bytes currently available in buffer.
Definition PhysicalLayer.cpp:591
virtual int16_t scanChannel()
Check whether the current communication channel is free or occupied. Performs CAD for LoRa modules,...
Definition PhysicalLayer.cpp:536
virtual void setDirectAction(void(*func)(void))
Set interrupt service routine function to call when data bit is received in direct mode....
Definition PhysicalLayer.cpp:661
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.
Definition PhysicalLayer.cpp:316
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 siz...
Definition PhysicalLayer.cpp:420
virtual int16_t clearIrqFlags(uint32_t irq)
Clear interrupt on a specific IRQ bit (e.g. RxTimeout, CadDone). Must be implemented in module class.
Definition PhysicalLayer.cpp:518
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.
Definition PhysicalLayer.cpp:322
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:295
virtual int16_t standby()
Sets module to standby.
Definition PhysicalLayer.cpp:122
virtual int16_t setFrequency(uint32_t freq)
Sets carrier frequency. Must be implemented in module class.
Definition PhysicalLayer.cpp:250
int32_t random(int32_t max)
Get truly random number in range 0 - max.
Definition PhysicalLayer.cpp:545
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:665
virtual int16_t setOutputPower(int8_t power)
Set output power. Must be implemented in module class if the module supports it.
Definition PhysicalLayer.cpp:305
virtual int16_t receiveDirect()
Enables direct reception mode on pins DIO1 (clock) and DIO2 (data). Must be implemented in module cla...
Definition PhysicalLayer.cpp:246
virtual int16_t startChannelScan()
Interrupt-driven channel activity detection method. Interrupt will be activated when packet is detect...
Definition PhysicalLayer.cpp:523
virtual int16_t setBandwidth(uint32_t bw)
Sets LoRa bandwidth. Must be implemented in module class.
Definition PhysicalLayer.cpp:270
uint32_t getIrqMapped(RadioLibIrqFlags_t irq)
Convert from radio-agnostic IRQ flags to radio-specific flags.
Definition PhysicalLayer.cpp:481
virtual int16_t receive(uint8_t *data, size_t len, RadioLibTime_t timeout=0)
Binary receive method. Must be implemented in module class.
Definition PhysicalLayer.cpp:111
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:290
virtual float getSNR()
Gets SNR (Signal to Noise Ratio) of the last received packet. Only available for LoRa modem.
Definition PhysicalLayer.cpp:388
virtual int16_t getModem(ModemType_t *modem)
Get modem currently in use by the radio.
Definition PhysicalLayer.cpp:687
int8_t getOutputPowerMin() const
Get the minimum output power supported by the radio. This includes any previously configured PA offse...
Definition PhysicalLayer.h:1083
virtual int16_t sleep()
Sets module to sleep.
Definition PhysicalLayer.cpp:118
virtual uint32_t getIrqFlags()
Read currently active IRQ flags. Must be implemented in module class.
Definition PhysicalLayer.cpp:509
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...
Definition PhysicalLayer.cpp:513
virtual int16_t setCodingRate(uint8_t cr, bool longInterleave=false)
Sets LoRa coding rate denominator. Must be implemented in module class.
Definition PhysicalLayer.cpp:275
int16_t clearIrq(RadioLibIrqFlags_t irq)
Clear interrupt on a specific IRQ bit (e.g. RxTimeout, CadDone). Keep in mind that not all radio modu...
Definition PhysicalLayer.cpp:505
PhysicalLayer()
Default constructor.
Definition PhysicalLayer.cpp:5
#define RADIOLIB_SHAPING_0_5
Gaussian shaping filter, BT = 0.5.
Definition TypeDef.h:27
bool resetOnStartup
Whether to reset the module on startup. Setting to false allows to restore radio operation by calling...
Definition PhysicalLayer.h:416
unsigned long RadioLibTime_t
Type used for durations in RadioLib.
Definition TypeDef.h:783
uint32_t RadioLibIrqFlags_t
Type used for radio-agnostic IRQ flags. IRQ to enable corresponds to the bit index (RadioLibIrq_t)....
Definition TypeDef.h:789
Channel scan configuration interpretation in case LoRa CAD is used.
Definition PhysicalLayer.h:129
RadioLibTime_t rxSymbols
Rx sync timeout in symbols.
Definition PhysicalLayer.h:146
uint8_t detPeak
Number of peak detection symbols.
Definition PhysicalLayer.h:134
uint8_t symNum
Number of symbols to consider signal present.
Definition PhysicalLayer.h:131
uint8_t exitMode
Exit mode after signal detection is complete - module-specific value.
Definition PhysicalLayer.h:140
RadioLibTime_t rxTimeout
Rx packet timeout in microseconds.
Definition PhysicalLayer.h:143
RadioLibIrqFlags_t irqFlags
Optional IRQ flags to set, bits offset by the value of RADIOLIB_IRQ_.
Definition PhysicalLayer.h:149
RadioLibIrqFlags_t irqMask
Optional IRQ mask to set, bits offset by the value of RADIOLIB_IRQ_.
Definition PhysicalLayer.h:152
uint8_t detMin
Number of minimum detection symbols.
Definition PhysicalLayer.h:137
Definition PhysicalLayer.h:375
uint8_t dataShaping
Time-bandwidth product of the Gaussian filter to be used for shaping. Defaults to 0....
Definition PhysicalLayer.h:385
uint32_t frequency
Carrier frequency in MHz. Defaults to 2400.0 MHz.
Definition PhysicalLayer.h:377
uint16_t bitRate
BLE bit rate in kbps. Defaults to 800 kbps.
Definition PhysicalLayer.h:379
uint32_t frequencyDeviation
BLE frequency deviation in kHz. Defaults to 400.0 kHz.
Definition PhysicalLayer.h:381
int8_t power
Output power in dBm. Defaults to 10 dBm.
Definition PhysicalLayer.h:383
Definition PhysicalLayer.h:325
int8_t power
Output power in dBm. Defaults to 10 dBm.
Definition PhysicalLayer.h:331
uint32_t bitRate
FSK bit rate in kbps. Defaults to 4.8 kbps.
Definition PhysicalLayer.h:329
uint32_t frequency
Carrier frequency in MHz. Defaults to 434.0 MHz.
Definition PhysicalLayer.h:327
Definition PhysicalLayer.h:360
uint8_t codingRate
FLRC coding rate. Defaults to RADIOLIB_FLRC_CR_2_3 (coding rate 2/3).
Definition PhysicalLayer.h:366
uint16_t preambleLength
FLRC preamble length in bits. Defaults to 16 bits.
Definition PhysicalLayer.h:370
int8_t power
Output power in dBm. Defaults to 10 dBm.
Definition PhysicalLayer.h:368
uint32_t bitRate
FLRC bit rate in kbps. Defaults to 650 kbps.
Definition PhysicalLayer.h:364
uint8_t dataShaping
Time-bandwidth product of the Gaussian filter to be used for shaping. Defaults to 0....
Definition PhysicalLayer.h:372
uint32_t frequency
Carrier frequency in MHz. Defaults to 434.0 MHz.
Definition PhysicalLayer.h:362
Definition PhysicalLayer.h:310
uint32_t frequencyDeviation
FSK frequency deviation in kHz. Defaults to 5.0 kHz.
Definition PhysicalLayer.h:316
uint32_t frequency
Carrier frequency in MHz. Defaults to 434.0 MHz.
Definition PhysicalLayer.h:312
uint16_t preambleLength
FSK preamble length in bits. Defaults to 16 bits.
Definition PhysicalLayer.h:322
int8_t power
Output power in dBm. Defaults to 10 dBm.
Definition PhysicalLayer.h:320
uint32_t receiverBandwidth
FSK receiver bandwidth in kHz. Defaults to 125.0 kHz.
Definition PhysicalLayer.h:318
uint32_t bitRate
FSK bit rate in kbps. Defaults to 4.8 kbps.
Definition PhysicalLayer.h:314
Definition PhysicalLayer.h:347
uint8_t bandwidth
LR-FHSS bandwidth, one of RADIOLIB_LR_FHSS_BW_* values. Defaults to 722.66 kHz.
Definition PhysicalLayer.h:351
bool narrowGrid
Whether to use narrow (3.9 kHz) or wide (25.39 kHz) grid spacing. Defaults to true (narrow/non-FCC) g...
Definition PhysicalLayer.h:355
int8_t power
Output power in dBm. Defaults to 10 dBm.
Definition PhysicalLayer.h:357
uint8_t codingRate
LR-FHSS coding rate, one of RADIOLIB_LR_FHSS_CR_* values. Defaults to 2/3 coding rate.
Definition PhysicalLayer.h:353
uint32_t frequency
Carrier frequency in MHz. Defaults to 434.0 MHz.
Definition PhysicalLayer.h:349
Definition PhysicalLayer.h:292
uint16_t preambleLength
LoRa preamble length in symbols. Defaults to 8 symbols.
Definition PhysicalLayer.h:307
uint8_t codingRate
LoRa coding rate. Defaults to 7 (coding rate 4/7). Allowed values range from 4 to 8....
Definition PhysicalLayer.h:301
int8_t power
Output power in dBm. Defaults to 10 dBm.
Definition PhysicalLayer.h:305
uint32_t frequency
Carrier frequency in MHz. Defaults to 434.0 MHz.
Definition PhysicalLayer.h:294
uint8_t syncWord
1-byte LoRa sync word. Defaults to RADIOLIB_LORA_SYNC_WORD_PRIVATE (0x12).
Definition PhysicalLayer.h:303
uint8_t spreadingFactor
LoRa spreading factor. Defaults to 9.
Definition PhysicalLayer.h:298
uint32_t bandwidth
LoRa bandwidth in kHz. Defaults to 125.0 kHz.
Definition PhysicalLayer.h:296
Definition PhysicalLayer.h:334
uint32_t receiverBandwidth
FSK receiver bandwidth in kHz. Defaults to 125.0 kHz.
Definition PhysicalLayer.h:340
int8_t power
Output power in dBm. Defaults to 10 dBm.
Definition PhysicalLayer.h:342
uint32_t frequency
Carrier frequency in MHz. Defaults to 434.0 MHz.
Definition PhysicalLayer.h:336
uint16_t preambleLength
FSK preamble length in bits. Defaults to 16 bits.
Definition PhysicalLayer.h:344
uint32_t bitRate
FSK bit rate in kbps. Defaults to 4.8 kbps.
Definition PhysicalLayer.h:338
Definition PhysicalLayer.h:99
uint8_t crcLength
FSK CRC length in bytes.
Definition PhysicalLayer.h:107
uint8_t syncWordLength
Length of the sync word in bits.
Definition PhysicalLayer.h:104
uint16_t preambleLength
FSK preamble length in bits.
Definition PhysicalLayer.h:101
Data rate structure interpretation in case FSK is used.
Definition PhysicalLayer.h:47
uint32_t bitRate
FSK bit rate in bps.
Definition PhysicalLayer.h:49
uint32_t freqDev
FSK frequency deviation in Hz.
Definition PhysicalLayer.h:52
Definition PhysicalLayer.h:85
bool implicitHeader
LoRa implicit header mode.
Definition PhysicalLayer.h:90
bool crcEnabled
LoRa CRC mode.
Definition PhysicalLayer.h:93
bool ldrOptimize
LoRa low data rate optimization.
Definition PhysicalLayer.h:96
uint16_t preambleLength
LoRa preamble length.
Definition PhysicalLayer.h:87
Data rate structure interpretation in case LoRa is used.
Definition PhysicalLayer.h:32
uint32_t bandwidth
LoRa bandwidth in Hz.
Definition PhysicalLayer.h:37
uint8_t spreadingFactor
LoRa spreading factor.
Definition PhysicalLayer.h:34
uint8_t codingRate
LoRa coding rate denominator.
Definition PhysicalLayer.h:40
Definition PhysicalLayer.h:110
uint8_t hdrCount
LR-FHSS header count (1 - 4).
Definition PhysicalLayer.h:112
Data rate structure interpretation in case LR-FHSS is used.
Definition PhysicalLayer.h:59
bool narrowGrid
Grid spacing.
Definition PhysicalLayer.h:67
uint8_t cr
Coding rate.
Definition PhysicalLayer.h:64
uint8_t bw
Bandwidth.
Definition PhysicalLayer.h:61
Channel scan configuration interpretation in case RSSI threshold is used.
Definition PhysicalLayer.h:159
float limit
RSSI limit in dBm.
Definition PhysicalLayer.h:161
Definition PhysicalLayer.h:181
RadioLibIrqFlags_t irqFlags
Sets the IRQ flags.
Definition PhysicalLayer.h:189
size_t len
Packet length, needed for some modules under special circumstances (e.g. LoRa implicit header mode).
Definition PhysicalLayer.h:195
uint32_t timeout
Raw timeout value. Some modules use this argument to specify operation mode (single vs....
Definition PhysicalLayer.h:183
uint16_t syncSymbols
LoRa sync timeout, given as the number of LoRa symbols.
Definition PhysicalLayer.h:186
RadioLibIrqFlags_t irqMask
Sets the mask of IRQ flags that will trigger the radio interrupt pin.
Definition PhysicalLayer.h:192
Definition PhysicalLayer.h:209
uint8_t mode
Module-specific sleep mode configuration.
Definition PhysicalLayer.h:211
Definition PhysicalLayer.h:176
uint8_t mode
Module-specific standby mode configuration.
Definition PhysicalLayer.h:178
Definition PhysicalLayer.h:198
const uint8_t * data
Binary data that will be transmitted.
Definition PhysicalLayer.h:200
uint8_t addr
Node address to transmit the packet to. Only used in FSK mode.
Definition PhysicalLayer.h:206
size_t len
Length of binary data to transmit (in bytes).
Definition PhysicalLayer.h:203
Common channel scan configuration structure.
Definition PhysicalLayer.h:168
RSSIScanConfig_t rssi
Interpretation for modems that use RSSI threshold.
Definition PhysicalLayer.h:173
CADScanConfig_t cad
Interpretation for modems that use CAD (usually LoRa modems).
Definition PhysicalLayer.h:170
Common data rate structure.
Definition PhysicalLayer.h:74
LrFhssRate_t lrFhss
Interpretation for LR-FHSS modems.
Definition PhysicalLayer.h:82
LoRaRate_t lora
Interpretation for LoRa modems.
Definition PhysicalLayer.h:76
FSKRate_t fsk
Interpretation for FSK modems.
Definition PhysicalLayer.h:79
Common packet configuration structure.
Definition PhysicalLayer.h:119
Definition PhysicalLayer.h:214
SleepConfig_t sleep
Interpretation for sleep mode.
Definition PhysicalLayer.h:228
StandbyConfig_t standby
Interpretation for standby mode.
Definition PhysicalLayer.h:216
ChannelScanConfig_t scan
Interpretation for scanning.
Definition PhysicalLayer.h:225
TransmitConfig_t transmit
Interpretation for Tx mode.
Definition PhysicalLayer.h:222
ReceiveConfig_t receive
Interpretation for Rx mode.
Definition PhysicalLayer.h:219