Reworked PhysicalLayer to accept frequency step directly
This commit is contained in:
parent
b382a280a2
commit
318de480ab
14 changed files with 29 additions and 41 deletions
|
@ -1,6 +1,6 @@
|
||||||
#include "CC1101.h"
|
#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;
|
_mod = module;
|
||||||
_packetLengthQueried = false;
|
_packetLengthQueried = false;
|
||||||
_packetLengthConfig = CC1101_LENGTH_CONFIG_VARIABLE;
|
_packetLengthConfig = CC1101_LENGTH_CONFIG_VARIABLE;
|
||||||
|
|
|
@ -7,9 +7,10 @@
|
||||||
#include "../../protocols/PhysicalLayer/PhysicalLayer.h"
|
#include "../../protocols/PhysicalLayer/PhysicalLayer.h"
|
||||||
|
|
||||||
// CC1101 physical layer properties
|
// 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_CRYSTAL_FREQ 26.0
|
||||||
#define CC1101_DIV_EXPONENT 16
|
#define CC1101_DIV_EXPONENT 16
|
||||||
#define CC1101_MAX_PACKET_LENGTH 63
|
|
||||||
|
|
||||||
// CC1101 SPI commands
|
// CC1101 SPI commands
|
||||||
#define CC1101_CMD_READ 0b10000000
|
#define CC1101_CMD_READ 0b10000000
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "RF69.h"
|
#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;
|
_mod = module;
|
||||||
_tempOffset = 0;
|
_tempOffset = 0;
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,10 @@
|
||||||
#include "../../protocols/PhysicalLayer/PhysicalLayer.h"
|
#include "../../protocols/PhysicalLayer/PhysicalLayer.h"
|
||||||
|
|
||||||
// RF69 physical layer properties
|
// 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_CRYSTAL_FREQ 32.0
|
||||||
#define RF69_DIV_EXPONENT 19
|
#define RF69_DIV_EXPONENT 19
|
||||||
#define RF69_MAX_PACKET_LENGTH 64
|
|
||||||
|
|
||||||
// RF69 register map
|
// RF69 register map
|
||||||
#define RF69_REG_FIFO 0x00
|
#define RF69_REG_FIFO 0x00
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "SX126x.h"
|
#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;
|
_mod = mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,10 @@
|
||||||
#include "../../protocols/PhysicalLayer/PhysicalLayer.h"
|
#include "../../protocols/PhysicalLayer/PhysicalLayer.h"
|
||||||
|
|
||||||
// SX126X physical layer properties
|
// 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_CRYSTAL_FREQ 32.0
|
||||||
#define SX126X_DIV_EXPONENT 25
|
#define SX126X_DIV_EXPONENT 25
|
||||||
#define SX126X_MAX_PACKET_LENGTH 255
|
|
||||||
|
|
||||||
// SX126X SPI commands
|
// SX126X SPI commands
|
||||||
// operational modes commands
|
// operational modes commands
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "SX127x.h"
|
#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;
|
_mod = mod;
|
||||||
_packetLengthQueried = false;
|
_packetLengthQueried = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,11 @@
|
||||||
#include "../../protocols/PhysicalLayer/PhysicalLayer.h"
|
#include "../../protocols/PhysicalLayer/PhysicalLayer.h"
|
||||||
|
|
||||||
// SX127x physical layer properties
|
// SX127x physical layer properties
|
||||||
#define SX127X_CRYSTAL_FREQ 32.0
|
#define SX127X_FREQUENCY_STEP_SIZE 61.03515625
|
||||||
#define SX127X_DIV_EXPONENT 19
|
|
||||||
#define SX127X_MAX_PACKET_LENGTH 255
|
#define SX127X_MAX_PACKET_LENGTH 255
|
||||||
#define SX127X_MAX_PACKET_LENGTH_FSK 64
|
#define SX127X_MAX_PACKET_LENGTH_FSK 64
|
||||||
|
#define SX127X_CRYSTAL_FREQ 32.0
|
||||||
|
#define SX127X_DIV_EXPONENT 19
|
||||||
|
|
||||||
// SX127x series common LoRa registers
|
// SX127x series common LoRa registers
|
||||||
#define SX127X_REG_FIFO 0x00
|
#define SX127X_REG_FIFO 0x00
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "nRF24.h"
|
#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;
|
_mod = mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,8 @@
|
||||||
|
|
||||||
#include "../../protocols/PhysicalLayer/PhysicalLayer.h"
|
#include "../../protocols/PhysicalLayer/PhysicalLayer.h"
|
||||||
|
|
||||||
// nRF24 physical layer properties (dummy only)
|
// nRF24 physical layer properties
|
||||||
#define NRF24_CRYSTAL_FREQ 1.0
|
#define NRF24_FREQUENCY_STEP_SIZE 1000000.0
|
||||||
#define NRF24_DIV_EXPONENT 0
|
|
||||||
#define NRF24_MAX_PACKET_LENGTH 32
|
#define NRF24_MAX_PACKET_LENGTH 32
|
||||||
|
|
||||||
// nRF24 SPI commands
|
// nRF24 SPI commands
|
||||||
|
|
|
@ -6,7 +6,7 @@ MorseClient::MorseClient(PhysicalLayer* phy) {
|
||||||
|
|
||||||
int16_t MorseClient::begin(float base, uint8_t speed) {
|
int16_t MorseClient::begin(float base, uint8_t speed) {
|
||||||
// calculate 24-bit frequency
|
// 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)
|
// calculate dot length (assumes PARIS as typical word)
|
||||||
_dotLength = 1200 / speed;
|
_dotLength = 1200 / speed;
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
#include "PhysicalLayer.h"
|
#include "PhysicalLayer.h"
|
||||||
|
|
||||||
PhysicalLayer::PhysicalLayer(float crysFreq, uint8_t divExp, size_t maxPacketLength) {
|
PhysicalLayer::PhysicalLayer(float freqStep, size_t maxPacketLength) {
|
||||||
_crystalFreq = crysFreq;
|
_freqStep = freqStep;
|
||||||
_divExponent = divExp;
|
|
||||||
_maxPacketLength = maxPacketLength;
|
_maxPacketLength = maxPacketLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,10 +140,6 @@ int16_t PhysicalLayer::receive(String& str, size_t len) {
|
||||||
return(state);
|
return(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
float PhysicalLayer::getCrystalFreq() {
|
float PhysicalLayer::getFreqStep() {
|
||||||
return(_crystalFreq);
|
return(_freqStep);
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t PhysicalLayer::getDivExponent() {
|
|
||||||
return(_divExponent);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,13 +18,11 @@ class PhysicalLayer {
|
||||||
/*!
|
/*!
|
||||||
\brief Default constructor.
|
\brief Default constructor.
|
||||||
|
|
||||||
\param crysFreq Frequency of crystal oscillator inside the module in MHz.
|
\param freqStep Frequency step of the synthesizer in Hz.
|
||||||
|
|
||||||
\param divExp Exponent of module frequency divider.
|
|
||||||
|
|
||||||
\param maxPacketLength Maximum length of packet that can be received by the module-
|
\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
|
// basic methods
|
||||||
|
|
||||||
|
@ -193,18 +191,11 @@ class PhysicalLayer {
|
||||||
virtual int16_t setFrequencyDeviation(float freqDev) = 0;
|
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();
|
float getFreqStep();
|
||||||
|
|
||||||
/*!
|
|
||||||
\brief Gets the module frequency divider exponent that was set in constructor.
|
|
||||||
|
|
||||||
\returns Frequency divider exponent.
|
|
||||||
*/
|
|
||||||
uint8_t getDivExponent();
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Query modem for the packet length of received payload.
|
\brief Query modem for the packet length of received payload.
|
||||||
|
@ -218,8 +209,7 @@ class PhysicalLayer {
|
||||||
#ifndef RADIOLIB_GODMODE
|
#ifndef RADIOLIB_GODMODE
|
||||||
private:
|
private:
|
||||||
#endif
|
#endif
|
||||||
float _crystalFreq;
|
float _freqStep;
|
||||||
uint8_t _divExponent;
|
|
||||||
size_t _maxPacketLength;
|
size_t _maxPacketLength;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -131,7 +131,7 @@ int16_t RTTYClient::begin(float base, uint32_t shift, uint16_t rate, uint8_t enc
|
||||||
_bitDuration = (uint32_t)1000000/rate;
|
_bitDuration = (uint32_t)1000000/rate;
|
||||||
|
|
||||||
// calculate module carrier frequency resolution
|
// 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
|
// check minimum shift value
|
||||||
if(shift < step / 2) {
|
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
|
// 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
|
// set module frequency deviation to 0
|
||||||
int16_t state = _phy->setFrequencyDeviation(0);
|
int16_t state = _phy->setFrequencyDeviation(0);
|
||||||
|
|
Loading…
Add table
Reference in a new issue