From 318de480abd12642121137a44477b3c2cf4e876e Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 7 Feb 2020 18:31:51 +0100 Subject: [PATCH] Reworked PhysicalLayer to accept frequency step directly --- src/modules/CC1101/CC1101.cpp | 2 +- src/modules/CC1101/CC1101.h | 3 ++- src/modules/RF69/RF69.cpp | 2 +- src/modules/RF69/RF69.h | 3 ++- src/modules/SX126x/SX126x.cpp | 2 +- src/modules/SX126x/SX126x.h | 3 ++- src/modules/SX127x/SX127x.cpp | 2 +- src/modules/SX127x/SX127x.h | 5 +++-- src/modules/nRF24/nRF24.cpp | 2 +- src/modules/nRF24/nRF24.h | 5 ++--- src/protocols/Morse/Morse.cpp | 2 +- src/protocols/PhysicalLayer/PhysicalLayer.cpp | 13 ++++------- src/protocols/PhysicalLayer/PhysicalLayer.h | 22 +++++-------------- src/protocols/RTTY/RTTY.cpp | 4 ++-- 14 files changed, 29 insertions(+), 41 deletions(-) diff --git a/src/modules/CC1101/CC1101.cpp b/src/modules/CC1101/CC1101.cpp index 220957b9..a094c09e 100644 --- a/src/modules/CC1101/CC1101.cpp +++ b/src/modules/CC1101/CC1101.cpp @@ -1,6 +1,6 @@ #include "CC1101.h" -CC1101::CC1101(Module* module) : PhysicalLayer(CC1101_CRYSTAL_FREQ, CC1101_DIV_EXPONENT, CC1101_MAX_PACKET_LENGTH) { +CC1101::CC1101(Module* module) : PhysicalLayer(CC1101_FREQUENCY_STEP_SIZE, CC1101_MAX_PACKET_LENGTH) { _mod = module; _packetLengthQueried = false; _packetLengthConfig = CC1101_LENGTH_CONFIG_VARIABLE; diff --git a/src/modules/CC1101/CC1101.h b/src/modules/CC1101/CC1101.h index 0568de8f..3e8f3673 100644 --- a/src/modules/CC1101/CC1101.h +++ b/src/modules/CC1101/CC1101.h @@ -7,9 +7,10 @@ #include "../../protocols/PhysicalLayer/PhysicalLayer.h" // CC1101 physical layer properties +#define CC1101_FREQUENCY_STEP_SIZE 396.7285156 +#define CC1101_MAX_PACKET_LENGTH 63 #define CC1101_CRYSTAL_FREQ 26.0 #define CC1101_DIV_EXPONENT 16 -#define CC1101_MAX_PACKET_LENGTH 63 // CC1101 SPI commands #define CC1101_CMD_READ 0b10000000 diff --git a/src/modules/RF69/RF69.cpp b/src/modules/RF69/RF69.cpp index 48807f00..11c50c7f 100644 --- a/src/modules/RF69/RF69.cpp +++ b/src/modules/RF69/RF69.cpp @@ -1,6 +1,6 @@ #include "RF69.h" -RF69::RF69(Module* module) : PhysicalLayer(RF69_CRYSTAL_FREQ, RF69_DIV_EXPONENT, RF69_MAX_PACKET_LENGTH) { +RF69::RF69(Module* module) : PhysicalLayer(RF69_FREQUENCY_STEP_SIZE, RF69_MAX_PACKET_LENGTH) { _mod = module; _tempOffset = 0; diff --git a/src/modules/RF69/RF69.h b/src/modules/RF69/RF69.h index 4b35e817..44f5020a 100644 --- a/src/modules/RF69/RF69.h +++ b/src/modules/RF69/RF69.h @@ -7,9 +7,10 @@ #include "../../protocols/PhysicalLayer/PhysicalLayer.h" // RF69 physical layer properties +#define RF69_FREQUENCY_STEP_SIZE 61.03515625 +#define RF69_MAX_PACKET_LENGTH 64 #define RF69_CRYSTAL_FREQ 32.0 #define RF69_DIV_EXPONENT 19 -#define RF69_MAX_PACKET_LENGTH 64 // RF69 register map #define RF69_REG_FIFO 0x00 diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index 7cea5d77..2a9e4423 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -1,6 +1,6 @@ #include "SX126x.h" -SX126x::SX126x(Module* mod) : PhysicalLayer(SX126X_CRYSTAL_FREQ, SX126X_DIV_EXPONENT, SX126X_MAX_PACKET_LENGTH) { +SX126x::SX126x(Module* mod) : PhysicalLayer(SX126X_FREQUENCY_STEP_SIZE, SX126X_MAX_PACKET_LENGTH) { _mod = mod; } diff --git a/src/modules/SX126x/SX126x.h b/src/modules/SX126x/SX126x.h index 9c92a03e..f28e7d92 100644 --- a/src/modules/SX126x/SX126x.h +++ b/src/modules/SX126x/SX126x.h @@ -7,9 +7,10 @@ #include "../../protocols/PhysicalLayer/PhysicalLayer.h" // SX126X physical layer properties +#define SX126X_FREQUENCY_STEP_SIZE 0.9536743164 +#define SX126X_MAX_PACKET_LENGTH 255 #define SX126X_CRYSTAL_FREQ 32.0 #define SX126X_DIV_EXPONENT 25 -#define SX126X_MAX_PACKET_LENGTH 255 // SX126X SPI commands // operational modes commands diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index b645cbc3..36e4f857 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -1,6 +1,6 @@ #include "SX127x.h" -SX127x::SX127x(Module* mod) : PhysicalLayer(SX127X_CRYSTAL_FREQ, SX127X_DIV_EXPONENT, SX127X_MAX_PACKET_LENGTH) { +SX127x::SX127x(Module* mod) : PhysicalLayer(SX127X_FREQUENCY_STEP_SIZE, SX127X_MAX_PACKET_LENGTH) { _mod = mod; _packetLengthQueried = false; } diff --git a/src/modules/SX127x/SX127x.h b/src/modules/SX127x/SX127x.h index 26ea958c..d48e9e30 100644 --- a/src/modules/SX127x/SX127x.h +++ b/src/modules/SX127x/SX127x.h @@ -7,10 +7,11 @@ #include "../../protocols/PhysicalLayer/PhysicalLayer.h" // SX127x physical layer properties -#define SX127X_CRYSTAL_FREQ 32.0 -#define SX127X_DIV_EXPONENT 19 +#define SX127X_FREQUENCY_STEP_SIZE 61.03515625 #define SX127X_MAX_PACKET_LENGTH 255 #define SX127X_MAX_PACKET_LENGTH_FSK 64 +#define SX127X_CRYSTAL_FREQ 32.0 +#define SX127X_DIV_EXPONENT 19 // SX127x series common LoRa registers #define SX127X_REG_FIFO 0x00 diff --git a/src/modules/nRF24/nRF24.cpp b/src/modules/nRF24/nRF24.cpp index 67a9b0e3..725e9265 100644 --- a/src/modules/nRF24/nRF24.cpp +++ b/src/modules/nRF24/nRF24.cpp @@ -1,6 +1,6 @@ #include "nRF24.h" -nRF24::nRF24(Module* mod) : PhysicalLayer(NRF24_CRYSTAL_FREQ, NRF24_DIV_EXPONENT, NRF24_MAX_PACKET_LENGTH) { +nRF24::nRF24(Module* mod) : PhysicalLayer(NRF24_FREQUENCY_STEP_SIZE, NRF24_MAX_PACKET_LENGTH) { _mod = mod; } diff --git a/src/modules/nRF24/nRF24.h b/src/modules/nRF24/nRF24.h index 1e1b3823..e7e536b5 100644 --- a/src/modules/nRF24/nRF24.h +++ b/src/modules/nRF24/nRF24.h @@ -6,9 +6,8 @@ #include "../../protocols/PhysicalLayer/PhysicalLayer.h" -// nRF24 physical layer properties (dummy only) -#define NRF24_CRYSTAL_FREQ 1.0 -#define NRF24_DIV_EXPONENT 0 +// nRF24 physical layer properties +#define NRF24_FREQUENCY_STEP_SIZE 1000000.0 #define NRF24_MAX_PACKET_LENGTH 32 // nRF24 SPI commands diff --git a/src/protocols/Morse/Morse.cpp b/src/protocols/Morse/Morse.cpp index 0dbfd768..6b3e0c16 100644 --- a/src/protocols/Morse/Morse.cpp +++ b/src/protocols/Morse/Morse.cpp @@ -6,7 +6,7 @@ MorseClient::MorseClient(PhysicalLayer* phy) { int16_t MorseClient::begin(float base, uint8_t speed) { // calculate 24-bit frequency - _base = (base * (uint32_t(1) << _phy->getDivExponent())) / _phy->getCrystalFreq(); + _base = (base * 1000000.0) / _phy->getFreqStep(); // calculate dot length (assumes PARIS as typical word) _dotLength = 1200 / speed; diff --git a/src/protocols/PhysicalLayer/PhysicalLayer.cpp b/src/protocols/PhysicalLayer/PhysicalLayer.cpp index 75425fd8..0fc34b5b 100644 --- a/src/protocols/PhysicalLayer/PhysicalLayer.cpp +++ b/src/protocols/PhysicalLayer/PhysicalLayer.cpp @@ -1,8 +1,7 @@ #include "PhysicalLayer.h" -PhysicalLayer::PhysicalLayer(float crysFreq, uint8_t divExp, size_t maxPacketLength) { - _crystalFreq = crysFreq; - _divExponent = divExp; +PhysicalLayer::PhysicalLayer(float freqStep, size_t maxPacketLength) { + _freqStep = freqStep; _maxPacketLength = maxPacketLength; } @@ -141,10 +140,6 @@ int16_t PhysicalLayer::receive(String& str, size_t len) { return(state); } -float PhysicalLayer::getCrystalFreq() { - return(_crystalFreq); -} - -uint8_t PhysicalLayer::getDivExponent() { - return(_divExponent); +float PhysicalLayer::getFreqStep() { + return(_freqStep); } diff --git a/src/protocols/PhysicalLayer/PhysicalLayer.h b/src/protocols/PhysicalLayer/PhysicalLayer.h index 38f2974d..93872ebd 100644 --- a/src/protocols/PhysicalLayer/PhysicalLayer.h +++ b/src/protocols/PhysicalLayer/PhysicalLayer.h @@ -18,13 +18,11 @@ class PhysicalLayer { /*! \brief Default constructor. - \param crysFreq Frequency of crystal oscillator inside the module in MHz. - - \param divExp Exponent of module frequency divider. + \param freqStep Frequency step of the synthesizer in Hz. \param maxPacketLength Maximum length of packet that can be received by the module- */ - PhysicalLayer(float crysFreq, uint8_t divExp, size_t maxPacketLength); + PhysicalLayer(float freqStep, size_t maxPacketLength); // basic methods @@ -193,18 +191,11 @@ class PhysicalLayer { virtual int16_t setFrequencyDeviation(float freqDev) = 0; /*! - \brief Gets the module crystal oscillator frequency that was set in constructor. + \brief Gets the module frequency step size that was set in constructor. - \returns Crystal oscillator frequency in MHz. + \returns Synthesizer frequency step size in Hz. */ - float getCrystalFreq(); - - /*! - \brief Gets the module frequency divider exponent that was set in constructor. - - \returns Frequency divider exponent. - */ - uint8_t getDivExponent(); + float getFreqStep(); /*! \brief Query modem for the packet length of received payload. @@ -218,8 +209,7 @@ class PhysicalLayer { #ifndef RADIOLIB_GODMODE private: #endif - float _crystalFreq; - uint8_t _divExponent; + float _freqStep; size_t _maxPacketLength; }; diff --git a/src/protocols/RTTY/RTTY.cpp b/src/protocols/RTTY/RTTY.cpp index 0ea4e06f..c5eebe6c 100644 --- a/src/protocols/RTTY/RTTY.cpp +++ b/src/protocols/RTTY/RTTY.cpp @@ -131,7 +131,7 @@ int16_t RTTYClient::begin(float base, uint32_t shift, uint16_t rate, uint8_t enc _bitDuration = (uint32_t)1000000/rate; // calculate module carrier frequency resolution - uint32_t step = round((_phy->getCrystalFreq() * 1000000) / (uint32_t(1) << _phy->getDivExponent())); + uint32_t step = round(_phy->getFreqStep()); // check minimum shift value if(shift < step / 2) { @@ -146,7 +146,7 @@ int16_t RTTYClient::begin(float base, uint32_t shift, uint16_t rate, uint8_t enc } // calculate 24-bit frequency - _base = (base * (uint32_t(1) << _phy->getDivExponent())) / _phy->getCrystalFreq(); + _base = (base * 1000000.0) / _phy->getFreqStep(); // set module frequency deviation to 0 int16_t state = _phy->setFrequencyDeviation(0);