fix module frequency overriding

The `RadioInterface::freq` member was encapsulated with the `RadioInterface::getFreq()` function,
which could be overridden in child classes for some LoRa-modules.
This commit is contained in:
Vladislav Osmanov 2021-09-13 22:13:51 +03:00
parent da61090dc5
commit cb42440963
5 changed files with 9 additions and 11 deletions

View File

@ -67,7 +67,7 @@ bool RF95Interface::init()
#endif #endif
setTransmitEnable(false); setTransmitEnable(false);
int res = lora->begin(freq, bw, sf, cr, syncWord, power, currentLimit, preambleLength); int res = lora->begin(getFreq(), bw, sf, cr, syncWord, power, currentLimit, preambleLength);
DEBUG_MSG("RF95 init result %d\n", res); DEBUG_MSG("RF95 init result %d\n", res);
// current limit was removed from module' ctor // current limit was removed from module' ctor
@ -119,7 +119,7 @@ bool RF95Interface::reconfigure()
err = lora->setPreambleLength(preambleLength); err = lora->setPreambleLength(preambleLength);
assert(err == ERR_NONE); assert(err == ERR_NONE);
err = lora->setFrequency(freq); err = lora->setFrequency(getFreq());
if (err != ERR_NONE) if (err != ERR_NONE)
RECORD_CRITICALERROR(CriticalErrorCode_InvalidRadioSetting); RECORD_CRITICALERROR(CriticalErrorCode_InvalidRadioSetting);

View File

@ -318,14 +318,14 @@ void RadioInterface::applyModemConfig()
// If user has manually specified a channel num, then use that, otherwise generate one by hashing the name // If user has manually specified a channel num, then use that, otherwise generate one by hashing the name
const char *channelName = channels.getName(channels.getPrimaryIndex()); const char *channelName = channels.getName(channels.getPrimaryIndex());
int channel_num = channelSettings.channel_num ? channelSettings.channel_num - 1 : hash(channelName) % myRegion->numChannels; int channel_num = channelSettings.channel_num ? channelSettings.channel_num - 1 : hash(channelName) % myRegion->numChannels;
freq = myRegion->freq + radioConfig.preferences.frequency_offset + myRegion->spacing * channel_num; float freq = myRegion->freq + radioConfig.preferences.frequency_offset + myRegion->spacing * channel_num;
DEBUG_MSG("Set radio: name=%s, config=%u, ch=%d, power=%d\n", channelName, channelSettings.modem_config, channel_num, power); DEBUG_MSG("Set radio: name=%s, config=%u, ch=%d, power=%d\n", channelName, channelSettings.modem_config, channel_num, power);
DEBUG_MSG("Radio myRegion->freq: %f\n", myRegion->freq); DEBUG_MSG("Radio myRegion->freq: %f\n", myRegion->freq);
DEBUG_MSG("Radio myRegion->spacing: %f\n", myRegion->spacing); DEBUG_MSG("Radio myRegion->spacing: %f\n", myRegion->spacing);
DEBUG_MSG("Radio myRegion->numChannels: %d\n", myRegion->numChannels); DEBUG_MSG("Radio myRegion->numChannels: %d\n", myRegion->numChannels);
DEBUG_MSG("Radio channel_num: %d\n", channel_num); DEBUG_MSG("Radio channel_num: %d\n", channel_num);
DEBUG_MSG("Radio frequency: %f\n", freq); DEBUG_MSG("Radio frequency: %f\n", getFreq()); // the frequency could be overridden in RadioInterface::getFreq() for some modules
DEBUG_MSG("Short packet time: %u msec\n", shortPacketMsec); DEBUG_MSG("Short packet time: %u msec\n", shortPacketMsec);
saveChannelNum(channel_num); saveChannelNum(channel_num);

View File

@ -78,8 +78,6 @@ class RadioInterface
void deliverToReceiver(MeshPacket *p); void deliverToReceiver(MeshPacket *p);
public: public:
float freq = 915.0;
/** pool is the pool we will alloc our rx packets from /** pool is the pool we will alloc our rx packets from
*/ */
RadioInterface(); RadioInterface();
@ -149,7 +147,7 @@ class RadioInterface
/** /**
* Get the frequency we saved. * Get the frequency we saved.
*/ */
float getFreq(); virtual float getFreq();
/// Some boards (1st gen Pinetab Lora module) have broken IRQ wires, so we need to poll via i2c registers /// Some boards (1st gen Pinetab Lora module) have broken IRQ wires, so we need to poll via i2c registers
virtual bool isIRQPending() { return false; } virtual bool isIRQPending() { return false; }

View File

@ -8,8 +8,8 @@
class SX1268Interface : public SX126xInterface<SX1268> class SX1268Interface : public SX126xInterface<SX1268>
{ {
public: public:
/// Initializing the frequency of the SX1268 module regardless of the region /// override frequency of the SX1268 module regardless of the region
float freq = 433.0; virtual float getFreq() { return 433.0; }
SX1268Interface(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE busy, SPIClass &spi); SX1268Interface(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE busy, SPIClass &spi);
}; };

View File

@ -52,7 +52,7 @@ bool SX126xInterface<T>::init()
limitPower(); limitPower();
int res = lora.begin(freq, bw, sf, cr, syncWord, power, preambleLength, tcxoVoltage, useRegulatorLDO); int res = lora.begin(getFreq(), bw, sf, cr, syncWord, power, preambleLength, tcxoVoltage, useRegulatorLDO);
// \todo Display actual typename of the adapter, not just `SX126x` // \todo Display actual typename of the adapter, not just `SX126x`
DEBUG_MSG("SX126x init result %d\n", res); DEBUG_MSG("SX126x init result %d\n", res);
@ -135,7 +135,7 @@ bool SX126xInterface<T>::reconfigure()
err = lora.setPreambleLength(preambleLength); err = lora.setPreambleLength(preambleLength);
assert(err == ERR_NONE); assert(err == ERR_NONE);
err = lora.setFrequency(freq); err = lora.setFrequency(getFreq());
if (err != ERR_NONE) if (err != ERR_NONE)
RECORD_CRITICALERROR(CriticalErrorCode_InvalidRadioSetting); RECORD_CRITICALERROR(CriticalErrorCode_InvalidRadioSetting);