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
7 // data rate structure interpretation in case LoRa is used
8 struct LoRaRate_t {
9 uint8_t spreadingFactor;
10 float bandwidth;
11 uint8_t codingRate;
12 };
13
14 // data rate structure interpretation in case FSK is used
15 struct FSKRate_t {
16 float bitRate;
17 float freqDev;
18 };
19
20 // common data rate
21 union DataRate_t {
22 LoRaRate_t lora;
23 FSKRate_t fsk;
24 };
25
34 class PhysicalLayer {
35 public:
36
37 // constructor
38
44 PhysicalLayer(float step, size_t maxLen);
45
46 // basic methods
47
48 #if defined(RADIOLIB_BUILD_ARDUINO)
55 int16_t transmit(__FlashStringHelper* fstr, uint8_t addr = 0);
56
63 int16_t transmit(String& str, uint8_t addr = 0);
64 #endif
65
72 int16_t transmit(const char* str, uint8_t addr = 0);
73
81 virtual int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0);
82
83 #if defined(RADIOLIB_BUILD_ARDUINO)
90 int16_t receive(String& str, size_t len = 0);
91 #endif
92
97 virtual int16_t sleep();
98
103 virtual int16_t standby();
104
109 virtual int16_t standby(uint8_t mode);
110
115 virtual int16_t startReceive();
116
127 virtual int16_t startReceive(uint32_t timeout, uint16_t irqFlags, uint16_t irqMask, size_t len);
128
135 virtual int16_t receive(uint8_t* data, size_t len);
136
137 #if defined(RADIOLIB_BUILD_ARDUINO)
145 int16_t startTransmit(String& str, uint8_t addr = 0);
146 #endif
147
155 int16_t startTransmit(const char* str, uint8_t addr = 0);
156
164 virtual int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr = 0);
165
170 virtual int16_t finishTransmit();
171
172 #if defined(RADIOLIB_BUILD_ARDUINO)
180 int16_t readData(String& str, size_t len = 0);
181 #endif
182
190 virtual int16_t readData(uint8_t* data, size_t len);
191
198 virtual int16_t transmitDirect(uint32_t frf = 0);
199
205 virtual int16_t receiveDirect();
206
207 // configuration methods
208
214 virtual int16_t setFrequency(float freq);
215
221 virtual int16_t setBitRate(float br);
222
229 virtual int16_t setFrequencyDeviation(float freqDev);
230
236 virtual int16_t setDataShaping(uint8_t sh);
237
243 virtual int16_t setEncoding(uint8_t encoding);
244
250 virtual int16_t invertIQ(bool enable);
251
257 virtual int16_t setOutputPower(int8_t power);
258
265 virtual int16_t setSyncWord(uint8_t* sync, size_t len);
266
272 virtual int16_t setPreambleLength(size_t len);
273
279 virtual int16_t setDataRate(DataRate_t dr);
280
285 float getFreqStep() const;
286
292 virtual size_t getPacketLength(bool update = true);
293
298 virtual float getRSSI();
299
304 virtual float getSNR();
305
311 virtual uint32_t getTimeOnAir(size_t len);
312
318 virtual int16_t startChannelScan();
319
324 virtual int16_t getChannelScanResult();
325
332 virtual int16_t scanChannel();
333
339 int32_t random(int32_t max);
340
347 int32_t random(int32_t min, int32_t max);
348
353 virtual uint8_t randomByte();
354
360 int16_t startDirect();
361
362 #if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
369 int16_t setDirectSyncWord(uint32_t syncWord, uint8_t len);
370
376 virtual void setDirectAction(void (*func)(void));
377
382 virtual void readBit(uint32_t pin);
383
388 int16_t available();
389
393 void dropSync();
394
401 uint8_t read(bool drop = true);
402 #endif
403
410 virtual int16_t setDIOMapping(uint32_t pin, uint32_t value);
411
416 virtual void setPacketReceivedAction(void (*func)(void));
417
421 virtual void clearPacketReceivedAction();
422
427 virtual void setPacketSentAction(void (*func)(void));
428
432 virtual void clearPacketSentAction();
433
438 virtual void setChannelScanAction(void (*func)(void));
439
443 virtual void clearChannelScanAction();
444
445 #if defined(RADIOLIB_INTERRUPT_TIMING)
446
452 void setInterruptSetup(void (*func)(uint32_t));
453
458 void setTimerFlag();
459
460 #endif
461
462 #if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
463 protected:
464 void updateDirectBuffer(uint8_t bit);
465 #endif
466
467 #if !defined(RADIOLIB_GODMODE)
468 private:
469 #endif
470 float freqStep;
471 size_t maxPacketLength;
472
473 #if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
474 uint8_t bufferBitPos;
475 uint8_t bufferWritePos;
476 uint8_t bufferReadPos;
477 uint8_t buffer[RADIOLIB_STATIC_ARRAY_SIZE];
478 uint32_t syncBuffer;
479 uint32_t directSyncWord;
480 uint8_t directSyncWordLen;
481 uint32_t directSyncWordMask;
482 bool gotSync;
483 #endif
484
485 virtual Module* getMod() = 0;
486
487 // allow specific classes access the private getMod method
488 friend class AFSKClient;
489 friend class RTTYClient;
490 friend class MorseClient;
491 friend class HellClient;
492 friend class SSTVClient;
493 friend class AX25Client;
494 friend class FSK4Client;
495 friend class PagerClient;
496 friend class BellClient;
497 friend class FT8Client;
498 friend class LoRaWANNode;
499 };
500
501 #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:282
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:34
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:461
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:336
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:449
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:435
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:359
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:366
PhysicalLayer::getTimeOnAir
virtual uint32_t getTimeOnAir(size_t len)
Get expected time-on-air for a given size of payload.
Definition: PhysicalLayer.cpp:292
PhysicalLayer::getChannelScanResult
virtual int16_t getChannelScanResult()
Read the channel scan result.
Definition: PhysicalLayer.cpp:301
PhysicalLayer::clearPacketSentAction
virtual void clearPacketSentAction()
Clears interrupt service routine to call when a packet is sent.
Definition: PhysicalLayer.cpp:453
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:445
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:340
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:374
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:355
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:305
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:425
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:309
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:429
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:457
PhysicalLayer::startChannelScan
virtual int16_t startChannelScan()
Interrupt-driven channel activity detection method. interrupt will be activated when packet is detect...
Definition: PhysicalLayer.cpp:297
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:441
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:15
LoRaRate_t
Definition: PhysicalLayer.h:8
DataRate_t
Definition: PhysicalLayer.h:21