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
565 virtual int16_t finishReceive();
566
567 #if defined(RADIOLIB_BUILD_ARDUINO)
575 int16_t readData(String& str, size_t len = 0);
576 #endif
577
585 virtual int16_t readData(uint8_t* data, size_t len);
586
593 virtual int16_t transmitDirect(uint32_t frf = 0);
594
600 virtual int16_t receiveDirect();
601
602 // configuration methods
603
609 virtual int16_t setFrequency(uint32_t freq);
610
616 virtual int16_t setBitRate(uint32_t br);
617
624 virtual int16_t setFrequencyDeviation(uint32_t freqDev);
625
631 virtual int16_t setSpreadingFactor(uint8_t sf);
632
638 virtual int16_t setBandwidth(uint32_t bw);
639
650 virtual int16_t setCodingRate(uint8_t cr, bool longInterleave = false);
651
661 virtual int16_t setLrFhssConfig(uint8_t bw, uint8_t cr, bool narrowGrid, uint8_t hdrCount = 3, uint16_t hopSeed = 0x13A);
662
668 virtual int16_t setDataShaping(uint8_t sh);
669
675 virtual int16_t setEncoding(uint8_t encoding);
676
682 virtual int16_t invertIQ(bool enable);
683
689 virtual int16_t setOutputPower(int8_t power);
690
700 int16_t setOutputPowerOffset(int8_t offset);
701
716 int16_t setOutputPowerOffset(const int8_t* lut, size_t steps);
717
724 virtual int16_t setSyncWord(uint8_t* sync, size_t len);
725
732 virtual int16_t setPreambleLength(size_t len, uint32_t detLen = 0xFFFFFFFFUL);
733
741 virtual int16_t setDataRate(DataRate_t dr, ModemType_t modem = RADIOLIB_MODEM_NONE);
742
750 virtual int16_t checkDataRate(DataRate_t dr, ModemType_t modem = RADIOLIB_MODEM_NONE);
751
757 virtual size_t getPacketLength(bool update = true);
758
763 virtual float getRSSI();
764
769 virtual float getSNR();
770
778 static float getNumSymbols(DataRate_t dr, PacketConfig_t pc, size_t len);
779
788 virtual RadioLibTime_t calculateTimeOnAir(ModemType_t modem, DataRate_t dr, PacketConfig_t pc, size_t len);
789
795 virtual RadioLibTime_t getTimeOnAir(size_t len);
796
804
810 uint32_t getIrqMapped(RadioLibIrqFlags_t irq);
811
817 int16_t checkIrq(RadioLibIrqType_t irq);
818
826 int16_t setIrq(RadioLibIrqFlags_t irq);
827
835 int16_t clearIrq(RadioLibIrqFlags_t irq);
836
842 virtual uint32_t getIrqFlags();
843
850 virtual int16_t setIrqFlags(uint32_t irq);
851
858 virtual int16_t clearIrqFlags(uint32_t irq);
859
865 virtual int16_t startChannelScan();
866
873 virtual int16_t startChannelScan(const ChannelScanConfig_t &config);
874
879 virtual int16_t getChannelScanResult();
880
887 virtual int16_t scanChannel();
888
896 virtual int16_t scanChannel(const ChannelScanConfig_t &config);
897
903 int32_t random(int32_t max);
904
911 int32_t random(int32_t min, int32_t max);
912
917 virtual uint8_t randomByte();
918
924 int16_t startDirect();
925
926 #if !RADIOLIB_EXCLUDE_DIRECT_RECEIVE
933 int16_t setDirectSyncWord(uint32_t syncWord, uint8_t len);
934
940 virtual void setDirectAction(void (*func)(void));
941
946 virtual void readBit(uint32_t pin);
947
952 int16_t available();
953
957 void dropSync();
958
965 uint8_t read(bool drop = true);
966 #endif
967
973 virtual void setIrqAction(void (*func)(void), bool rising = true);
974
978 virtual void clearIrqAction();
979
986 virtual int16_t setModem(ModemType_t modem);
987
993 virtual int16_t getModem(ModemType_t* modem);
994
1005 virtual int16_t getMode(RadioModeType_t* mode);
1006
1013 virtual int16_t stageMode(RadioModeType_t mode, RadioModeConfig_t* cfg);
1014
1019 virtual int16_t launchMode();
1020
1033 virtual int16_t writeTxBuffer(const uint8_t* data, size_t len);
1034
1041 virtual int16_t clearTxBuffer();
1042
1043 #if RADIOLIB_INTERRUPT_TIMING
1044
1050 void setInterruptSetup(void (*func)(uint32_t));
1051
1056 void setTimerFlag();
1057
1058 #endif
1059
1077 int16_t calculateRxDutyCycle(size_t txPreLen, size_t rxPreLen, uint16_t minSymbols, DataRate_t* dr, uint32_t* wakePeriod, uint32_t* sleepPeriod);
1078
1080 void setRfSwitchPins(uint32_t rxEn, uint32_t txEn);
1081
1083 void setRfSwitchTable(const uint32_t (&pins)[Module::RFSWITCH_MAX_PINS], const Module::RfSwitchMode_t table[]);
1084
1090 int8_t getOutputPowerMin() const { return(powerMin); }
1091
1097 int8_t getOutputPowerMax() const { return(powerMax); }
1098
1099#if !RADIOLIB_GODMODE
1100 protected:
1101#endif
1102 int8_t powerMin = 0, powerMax = 0;
1103 uint8_t paSteps = 0;
1104
1105 uint32_t irqMap[10] = { 0 };
1106 RadioModeType_t stagedMode = RADIOLIB_RADIO_MODE_NONE;
1107
1117 int16_t applyOutputPowerOffset(int8_t base, const int8_t* pwrReq, int8_t* pwrRadio);
1118 int16_t findRxBw(uint32_t rxBw, const uint32_t* rxBwAvg, const uint8_t* lut, size_t lutSize, uint32_t rxBwMax, uint8_t* val);
1119
1120#if !RADIOLIB_EXCLUDE_DIRECT_RECEIVE
1121 void updateDirectBuffer(uint8_t bit);
1122#endif
1123
1124#if !RADIOLIB_GODMODE
1125 private:
1126#endif
1127
1128 #if !RADIOLIB_EXCLUDE_DIRECT_RECEIVE
1129 uint8_t bufferBitPos = 0;
1130 size_t bufferWritePos = 0;
1131 size_t bufferReadPos = 0;
1132 uint8_t buffer[RADIOLIB_STATIC_ARRAY_SIZE] = { 0 };
1133 uint32_t syncBuffer = 0;
1134 uint32_t directSyncWord = 0;
1135 uint8_t directSyncWordLen = 0;
1136 uint32_t directSyncWordMask = 0;
1137 bool gotSync = false;
1138 #endif
1139
1140 virtual Module* getMod() = 0;
1141
1142 // allow specific classes access the private getMod method
1143 friend class AFSKClient;
1144 friend class RTTYClient;
1145 friend class MorseClient;
1146 friend class HellClient;
1147 friend class SSTVClient;
1148 friend class AX25Client;
1149 friend class FSK4Client;
1150 friend class PagerClient;
1151 friend class BellClient;
1152 friend class FT8Client;
1153 friend class LoRaWANNode;
1154 friend class M17Client;
1155
1156 int8_t paOffsetLut[48] = { 0 };
1157};
1158
1159#endif
static const size_t RFSWITCH_MAX_PINS
The maximum number of pins supported by the RF switch code. Note: It is not recommended to use this c...
Definition Module.h:83
virtual int16_t setPreambleLength(size_t len, uint32_t detLen=0xFFFFFFFFUL)
Set preamble length. Must be implemented in module class if the module supports it.
Definition PhysicalLayer.cpp:336
virtual int16_t stageMode(RadioModeType_t mode, RadioModeConfig_t *cfg)
Stage mode of the radio to be launched later using launchMode.
Definition PhysicalLayer.cpp:730
virtual void clearIrqAction()
Clears interrupt service routine to call when IRQ is activated.
Definition PhysicalLayer.cpp:710
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:762
virtual int16_t invertIQ(bool enable)
Set IQ inversion. Must be implemented in module class if the module supports it.
Definition PhysicalLayer.cpp:320
virtual int16_t startReceive()
Sets module to received mode using its default configuration.
Definition PhysicalLayer.cpp:141
virtual uint8_t randomByte()
Get one truly random byte from RSSI noise. Must be implemented in module class.
Definition PhysicalLayer.cpp:592
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:185
int16_t checkIrq(RadioLibIrqType_t irq)
Check whether a specific IRQ bit is set (e.g. RxTimeout, CadDone).
Definition PhysicalLayer.cpp:513
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:725
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:395
virtual void setIrqAction(void(*func)(void), bool rising=true)
Sets interrupt service routine to call when IRQ is activated.
Definition PhysicalLayer.cpp:704
int8_t getOutputPowerMax() const
Get the maximum output power supported by the radio. This includes any previously configured PA offse...
Definition PhysicalLayer.h:1097
virtual int16_t readData(uint8_t *data, size_t len)
Reads data that was received after calling startReceive method.
Definition PhysicalLayer.cpp:255
void setRfSwitchTable(const uint32_t(&pins)[Module::RFSWITCH_MAX_PINS], const Module::RfSwitchMode_t table[])
Some modules contain external RF switch controlled by pins. This function gives RadioLib control over...
Definition PhysicalLayer.cpp:817
void dropSync()
Forcefully drop synchronization.
Definition PhysicalLayer.cpp:615
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:301
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:622
virtual RadioLibTime_t getTimeOnAir(size_t len)
Get expected time-on-air for a given size of payload.
Definition PhysicalLayer.cpp:491
virtual int16_t clearTxBuffer()
Discard a payload previously written by writeTxBuffer. On radios whose transmit buffer is simply over...
Definition PhysicalLayer.cpp:746
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:740
virtual int16_t launchMode()
Launch previously staged mode.
Definition PhysicalLayer.cpp:736
static float getNumSymbols(DataRate_t dr, PacketConfig_t pc, size_t len)
Convert from bytes to LoRa symbols.
Definition PhysicalLayer.cpp:412
virtual int16_t getChannelScanResult()
Read the channel scan result.
Definition PhysicalLayer.cpp:552
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:280
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:330
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:715
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:496
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:275
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:521
int16_t startDirect()
Configure module parameters for direct modes. Must be called prior to "ham" modes like RTTY or AX....
Definition PhysicalLayer.cpp:596
void setRfSwitchPins(uint32_t rxEn, uint32_t txEn)
Some modules contain external RF switch controlled by pins. This function gives RadioLib control over...
Definition PhysicalLayer.cpp:812
virtual int16_t finishReceive()
Clean up after reception is done. Calling this method will clear all interrupts, dump any remaining p...
Definition PhysicalLayer.cpp:198
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:639
virtual int16_t setSpreadingFactor(uint8_t sf)
Sets LoRa spreading factor. Must be implemented in module class.
Definition PhysicalLayer.cpp:285
int16_t startTransmit(const char *str, uint8_t addr=0)
Interrupt-driven Arduino String transmit method. Unlike the standard transmit method,...
Definition PhysicalLayer.cpp:167
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:822
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:389
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:261
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:404
int16_t available()
Get the number of direct mode bytes currently available in buffer.
Definition PhysicalLayer.cpp:611
virtual int16_t scanChannel()
Check whether the current communication channel is free or occupied. Performs CAD for LoRa modules,...
Definition PhysicalLayer.cpp:556
virtual void setDirectAction(void(*func)(void))
Set interrupt service routine function to call when data bit is received in direct mode....
Definition PhysicalLayer.cpp:694
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:440
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:538
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:342
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:315
virtual int16_t standby()
Sets module to standby.
Definition PhysicalLayer.cpp:132
virtual int16_t setFrequency(uint32_t freq)
Sets carrier frequency. Must be implemented in module class.
Definition PhysicalLayer.cpp:270
int32_t random(int32_t max)
Get truly random number in range 0 - max.
Definition PhysicalLayer.cpp:565
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:698
virtual int16_t setOutputPower(int8_t power)
Set output power. Must be implemented in module class if the module supports it.
Definition PhysicalLayer.cpp:325
virtual int16_t receiveDirect()
Enables direct reception mode on pins DIO1 (clock) and DIO2 (data). Must be implemented in module cla...
Definition PhysicalLayer.cpp:266
virtual int16_t startChannelScan()
Interrupt-driven channel activity detection method. Interrupt will be activated when packet is detect...
Definition PhysicalLayer.cpp:543
virtual int16_t setBandwidth(uint32_t bw)
Sets LoRa bandwidth. Must be implemented in module class.
Definition PhysicalLayer.cpp:290
uint32_t getIrqMapped(RadioLibIrqFlags_t irq)
Convert from radio-agnostic IRQ flags to radio-specific flags.
Definition PhysicalLayer.cpp:501
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:121
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:310
virtual float getSNR()
Gets SNR (Signal to Noise Ratio) of the last received packet. Only available for LoRa modem.
Definition PhysicalLayer.cpp:408
virtual int16_t getModem(ModemType_t *modem)
Get modem currently in use by the radio.
Definition PhysicalLayer.cpp:720
int8_t getOutputPowerMin() const
Get the minimum output power supported by the radio. This includes any previously configured PA offse...
Definition PhysicalLayer.h:1090
virtual int16_t sleep()
Sets module to sleep.
Definition PhysicalLayer.cpp:128
virtual uint32_t getIrqFlags()
Read currently active IRQ flags. Must be implemented in module class.
Definition PhysicalLayer.cpp:529
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:533
virtual int16_t setCodingRate(uint8_t cr, bool longInterleave=false)
Sets LoRa coding rate denominator. Must be implemented in module class.
Definition PhysicalLayer.cpp:295
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:525
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
Description of RF switch pin states for a single mode. See setRfSwitchTable for details.
Definition Module.h:90
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