RadioLib Universal wireless communication library for Arduino

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
11 struct LoRaRate_t {
13 uint8_t spreadingFactor;
14
16 float bandwidth;
17
19 uint8_t codingRate;
20 };
21
26 struct FSKRate_t {
28 float bitRate;
29
31 float freqDev;
32 };
33
38 union DataRate_t {
40 LoRaRate_t lora;
41
43 FSKRate_t fsk;
44 };
45
54 class PhysicalLayer {
55 public:
56
57 // constructor
58
64 PhysicalLayer(float step, size_t maxLen);
65
66 // basic methods
67
68 #if defined(RADIOLIB_BUILD_ARDUINO)
75 int16_t transmit(__FlashStringHelper* fstr, uint8_t addr = 0);
76
83 int16_t transmit(String& str, uint8_t addr = 0);
84 #endif
85
92 int16_t transmit(const char* str, uint8_t addr = 0);
93
101 virtual int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0);
102
103 #if defined(RADIOLIB_BUILD_ARDUINO)
110 int16_t receive(String& str, size_t len = 0);
111 #endif
112
117 virtual int16_t sleep();
118
123 virtual int16_t standby();
124
129 virtual int16_t standby(uint8_t mode);
130
135 virtual int16_t startReceive();
136
147 virtual int16_t startReceive(uint32_t timeout, uint16_t irqFlags, uint16_t irqMask, size_t len);
148
155 virtual int16_t receive(uint8_t* data, size_t len);
156
157 #if defined(RADIOLIB_BUILD_ARDUINO)
165 int16_t startTransmit(String& str, uint8_t addr = 0);
166 #endif
167
175 int16_t startTransmit(const char* str, uint8_t addr = 0);
176
184 virtual int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr = 0);
185
190 virtual int16_t finishTransmit();
191
192 #if defined(RADIOLIB_BUILD_ARDUINO)
200 int16_t readData(String& str, size_t len = 0);
201 #endif
202
210 virtual int16_t readData(uint8_t* data, size_t len);
211
218 virtual int16_t transmitDirect(uint32_t frf = 0);
219
225 virtual int16_t receiveDirect();
226
227 // configuration methods
228
234 virtual int16_t setFrequency(float freq);
235
241 virtual int16_t setBitRate(float br);
242
249 virtual int16_t setFrequencyDeviation(float freqDev);
250
256 virtual int16_t setDataShaping(uint8_t sh);
257
263 virtual int16_t setEncoding(uint8_t encoding);
264
270 virtual int16_t invertIQ(bool enable);
271
277 virtual int16_t setOutputPower(int8_t power);
278
285 virtual int16_t setSyncWord(uint8_t* sync, size_t len);
286
292 virtual int16_t setPreambleLength(size_t len);
293
299 virtual int16_t setDataRate(DataRate_t dr);
300
306 virtual int16_t checkDataRate(DataRate_t dr);
307
312 float getFreqStep() const;
313
319 virtual size_t getPacketLength(bool update = true);
320
325 virtual float getRSSI();
326
331 virtual float getSNR();
332
338 virtual uint32_t getTimeOnAir(size_t len);
339
345 virtual uint32_t calculateRxTimeout(uint32_t timeoutUs);
346
353 virtual int16_t irqRxDoneRxTimeout(uint16_t &irqFlags, uint16_t &irqMask);
354
359 virtual bool isRxTimeout();
360
366 virtual int16_t startChannelScan();
367
372 virtual int16_t getChannelScanResult();
373
380 virtual int16_t scanChannel();
381
387 int32_t random(int32_t max);
388
395 int32_t random(int32_t min, int32_t max);
396
401 virtual uint8_t randomByte();
402
408 int16_t startDirect();
409
410 #if !RADIOLIB_EXCLUDE_DIRECT_RECEIVE
417 int16_t setDirectSyncWord(uint32_t syncWord, uint8_t len);
418
424 virtual void setDirectAction(void (*func)(void));
425
430 virtual void readBit(uint32_t pin);
431
436 int16_t available();
437
441 void dropSync();
442
449 uint8_t read(bool drop = true);
450 #endif
451
458 virtual int16_t setDIOMapping(uint32_t pin, uint32_t value);
459
464 virtual void setPacketReceivedAction(void (*func)(void));
465
469 virtual void clearPacketReceivedAction();
470
475 virtual void setPacketSentAction(void (*func)(void));
476
480 virtual void clearPacketSentAction();
481
486 virtual void setChannelScanAction(void (*func)(void));
487
491 virtual void clearChannelScanAction();
492
493 #if RADIOLIB_INTERRUPT_TIMING
494
500 void setInterruptSetup(void (*func)(uint32_t));
501
506 void setTimerFlag();
507
508 #endif
509
510 #if !RADIOLIB_GODMODE
511 protected:
512 #endif
513 #if !RADIOLIB_EXCLUDE_DIRECT_RECEIVE
514 void updateDirectBuffer(uint8_t bit);
515 #endif
516
517 #if !RADIOLIB_GODMODE
518 private:
519 #endif
520 float freqStep;
521 size_t maxPacketLength;
522
523 #if !RADIOLIB_EXCLUDE_DIRECT_RECEIVE
524 uint8_t bufferBitPos;
525 uint8_t bufferWritePos;
526 uint8_t bufferReadPos;
527 uint8_t buffer[RADIOLIB_STATIC_ARRAY_SIZE];
528 uint32_t syncBuffer;
529 uint32_t directSyncWord;
530 uint8_t directSyncWordLen;
531 uint32_t directSyncWordMask;
532 bool gotSync;
533 #endif
534
535 virtual Module* getMod() = 0;
536
537 // allow specific classes access the private getMod method
538 friend class AFSKClient;
539 friend class RTTYClient;
540 friend class MorseClient;
541 friend class HellClient;
542 friend class SSTVClient;
543 friend class AX25Client;
544 friend class FSK4Client;
545 friend class PagerClient;
546 friend class BellClient;
547 friend class FT8Client;
548 friend class LoRaWANNode;
549 };
550
551 #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:498
Module
Implements all common low-level methods to control the wireless module. Every module class contains o...
Definition: Module.h:68
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:54
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::clearChannelScanAction
virtual void clearChannelScanAction()
Clears interrupt service routine to call when a channel scan is finished.
Definition: PhysicalLayer.cpp:481
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:356
PhysicalLayer::irqRxDoneRxTimeout
virtual int16_t irqRxDoneRxTimeout(uint16_t &irqFlags, uint16_t &irqMask)
Create the flags that make up RxDone and RxTimeout used for receiving downlinks.
Definition: PhysicalLayer.cpp:307
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:284
PhysicalLayer::setPacketSentAction
virtual void setPacketSentAction(void(*func)(void))
Sets interrupt service routine to call when a packet is sent.
Definition: PhysicalLayer.cpp:469
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:455
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:379
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:386
PhysicalLayer::calculateRxTimeout
virtual uint32_t calculateRxTimeout(uint32_t timeoutUs)
Calculate the timeout value for this specific module / series (in number of symbols or units of time)
Definition: PhysicalLayer.cpp:302
PhysicalLayer::getTimeOnAir
virtual uint32_t getTimeOnAir(size_t len)
Get expected time-on-air for a given size of payload.
Definition: PhysicalLayer.cpp:297
PhysicalLayer::checkDataRate
virtual int16_t checkDataRate(DataRate_t dr)
Check the data rate can be configured by this module. Must be implemented in module class if the modu...
Definition: PhysicalLayer.cpp:275
PhysicalLayer::getChannelScanResult
virtual int16_t getChannelScanResult()
Read the channel scan result.
Definition: PhysicalLayer.cpp:321
PhysicalLayer::clearPacketSentAction
virtual void clearPacketSentAction()
Clears interrupt service routine to call when a packet is sent.
Definition: PhysicalLayer.cpp:473
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:465
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:360
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:394
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:280
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:289
PhysicalLayer::available
int16_t available()
Get the number of direct mode bytes currently available in buffer.
Definition: PhysicalLayer.cpp:375
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::scanChannel
virtual int16_t scanChannel()
Check whether the current communication channel is free or occupied. Performs CAD for LoRa modules,...
Definition: PhysicalLayer.cpp:325
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:445
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::isRxTimeout
virtual bool isRxTimeout()
Check whether the IRQ bit for RxTimeout is set.
Definition: PhysicalLayer.cpp:313
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:329
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:449
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::setChannelScanAction
virtual void setChannelScanAction(void(*func)(void))
Sets interrupt service routine to call when a channel scan is finished.
Definition: PhysicalLayer.cpp:477
PhysicalLayer::startChannelScan
virtual int16_t startChannelScan()
Interrupt-driven channel activity detection method. interrupt will be activated when packet is detect...
Definition: PhysicalLayer.cpp:317
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:461
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:293
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
Data rate structure interpretation in case FSK is used.
Definition: PhysicalLayer.h:26
FSKRate_t::bitRate
float bitRate
FSK bit rate in kbps.
Definition: PhysicalLayer.h:28
FSKRate_t::freqDev
float freqDev
FS frequency deviation in kHz.
Definition: PhysicalLayer.h:31
LoRaRate_t
Data rate structure interpretation in case LoRa is used.
Definition: PhysicalLayer.h:11
LoRaRate_t::spreadingFactor
uint8_t spreadingFactor
LoRa spreading factor.
Definition: PhysicalLayer.h:13
LoRaRate_t::bandwidth
float bandwidth
LoRa bandwidth in kHz.
Definition: PhysicalLayer.h:16
LoRaRate_t::codingRate
uint8_t codingRate
LoRa coding rate.
Definition: PhysicalLayer.h:19
DataRate_t
Common data rate structure.
Definition: PhysicalLayer.h:38
DataRate_t::lora
LoRaRate_t lora
Interpretation for LoRa modems.
Definition: PhysicalLayer.h:40
DataRate_t::fsk
FSKRate_t fsk
Interpretation for FSK modems.
Definition: PhysicalLayer.h:43