From 09f45bc3e21c45e9746bf832df6d802323cec486 Mon Sep 17 00:00:00 2001 From: cheetah Date: Sat, 10 Apr 2021 16:41:13 +0200 Subject: [PATCH] Delete pocsag-transmit-test/disabledsrc directory --- .../disabledsrc/SX1276Better.cpp | 128 ---- .../disabledsrc/SX1276Better.h | 91 --- .../disabledsrc/SX1278Better.cpp | 550 ------------------ .../disabledsrc/SX1278Better.h | 314 ---------- 4 files changed, 1083 deletions(-) delete mode 100644 pocsag-transmit-test/disabledsrc/SX1276Better.cpp delete mode 100644 pocsag-transmit-test/disabledsrc/SX1276Better.h delete mode 100644 pocsag-transmit-test/disabledsrc/SX1278Better.cpp delete mode 100644 pocsag-transmit-test/disabledsrc/SX1278Better.h diff --git a/pocsag-transmit-test/disabledsrc/SX1276Better.cpp b/pocsag-transmit-test/disabledsrc/SX1276Better.cpp deleted file mode 100644 index a738772..0000000 --- a/pocsag-transmit-test/disabledsrc/SX1276Better.cpp +++ /dev/null @@ -1,128 +0,0 @@ -#include "SX1276Better.h" - -SX1276Better::SX1276Better(Module* mod) : SX1278(mod) { - pubmod = mod; -} - -int16_t SX1276Better::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) { - // execute common part - int16_t state = SX127x::begin(SX1278_CHIP_VERSION, syncWord, preambleLength); - RADIOLIB_ASSERT(state); - - // configure publicly accessible settings - state = setBandwidth(bw); - RADIOLIB_ASSERT(state); - - state = setFrequency(freq); - RADIOLIB_ASSERT(state); - - state = setSpreadingFactor(sf); - RADIOLIB_ASSERT(state); - - state = setCodingRate(cr); - RADIOLIB_ASSERT(state); - - state = setOutputPower(power); - RADIOLIB_ASSERT(state); - - state = setGain(gain); - RADIOLIB_ASSERT(state); - - return(state); -} - -int16_t SX1276Better::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, bool enableOOK) { - // execute common part - int16_t state = SX127x::beginFSK(SX1278_CHIP_VERSION, br, freqDev, rxBw, preambleLength, enableOOK); - RADIOLIB_ASSERT(state); - - // configure publicly accessible settings - state = setFrequency(freq); - RADIOLIB_ASSERT(state); - - state = setOutputPower(power); - RADIOLIB_ASSERT(state); - - state = setDataShaping(RADIOLIB_SHAPING_NONE); - RADIOLIB_ASSERT(state); - - return(state); -} - -int16_t SX1276Better::setFrequency(float freq) { - RADIOLIB_CHECK_RANGE(freq, 137.0, 1020.0, ERR_INVALID_FREQUENCY); - - // SX1276/77/78 Errata fixes - if(getActiveModem() == SX127X_LORA) { - // sensitivity optimization for 500kHz bandwidth - // see SX1276/77/78 Errata, section 2.1 for details - if(abs(_bw - 500.0) <= 0.001) { - if((freq >= 862.0) && (freq <= 1020.0)) { - _mod->SPIwriteRegister(0x36, 0x02); - _mod->SPIwriteRegister(0x3a, 0x64); - } else if((freq >= 410.0) && (freq <= 525.0)) { - _mod->SPIwriteRegister(0x36, 0x02); - _mod->SPIwriteRegister(0x3a, 0x7F); - } - } - - // mitigation of receiver spurious response - // see SX1276/77/78 Errata, section 2.3 for details - if(abs(_bw - 7.8) <= 0.001) { - _mod->SPIsetRegValue(0x31, 0b0000000, 7, 7); - _mod->SPIsetRegValue(0x2F, 0x48); - _mod->SPIsetRegValue(0x30, 0x00); - freq += 7.8; - } else if(abs(_bw - 10.4) <= 0.001) { - _mod->SPIsetRegValue(0x31, 0b0000000, 7, 7); - _mod->SPIsetRegValue(0x2F, 0x44); - _mod->SPIsetRegValue(0x30, 0x00); - freq += 10.4; - } else if(abs(_bw - 15.6) <= 0.001) { - _mod->SPIsetRegValue(0x31, 0b0000000, 7, 7); - _mod->SPIsetRegValue(0x2F, 0x44); - _mod->SPIsetRegValue(0x30, 0x00); - freq += 15.6; - } else if(abs(_bw - 20.8) <= 0.001) { - _mod->SPIsetRegValue(0x31, 0b0000000, 7, 7); - _mod->SPIsetRegValue(0x2F, 0x44); - _mod->SPIsetRegValue(0x30, 0x00); - freq += 20.8; - } else if(abs(_bw - 31.25) <= 0.001) { - _mod->SPIsetRegValue(0x31, 0b0000000, 7, 7); - _mod->SPIsetRegValue(0x2F, 0x44); - _mod->SPIsetRegValue(0x30, 0x00); - freq += 31.25; - } else if(abs(_bw - 41.7) <= 0.001) { - _mod->SPIsetRegValue(0x31, 0b0000000, 7, 7); - _mod->SPIsetRegValue(0x2F, 0x44); - _mod->SPIsetRegValue(0x30, 0x00); - freq += 41.7; - } else if(abs(_bw - 62.5) <= 0.001) { - _mod->SPIsetRegValue(0x31, 0b0000000, 7, 7); - _mod->SPIsetRegValue(0x2F, 0x40); - _mod->SPIsetRegValue(0x30, 0x00); - } else if(abs(_bw - 125.0) <= 0.001) { - _mod->SPIsetRegValue(0x31, 0b0000000, 7, 7); - _mod->SPIsetRegValue(0x2F, 0x40); - _mod->SPIsetRegValue(0x30, 0x00); - } else if(abs(_bw - 250.0) <= 0.001) { - _mod->SPIsetRegValue(0x31, 0b0000000, 7, 7); - _mod->SPIsetRegValue(0x2F, 0x40); - _mod->SPIsetRegValue(0x30, 0x00); - } else if(abs(_bw - 500.0) <= 0.001) { - _mod->SPIsetRegValue(0x31, 0b1000000, 7, 7); - } - } - - // set frequency and if successful, save the new setting - int16_t state = SX127x::setFrequencyRaw(freq); - if(state == ERR_NONE) { - SX127x::_freq = freq; - } - return(state); -} - -int16_t SX1276Better::setModeP(uint8_t mode) { - return(_mod->SPIsetRegValue(SX127X_REG_OP_MODE, mode, 2, 0, 5)); -} \ No newline at end of file diff --git a/pocsag-transmit-test/disabledsrc/SX1276Better.h b/pocsag-transmit-test/disabledsrc/SX1276Better.h deleted file mode 100644 index 4e1aa24..0000000 --- a/pocsag-transmit-test/disabledsrc/SX1276Better.h +++ /dev/null @@ -1,91 +0,0 @@ -#if !defined(_RADIOLIB_SX1276Better_H) -#define _RADIOLIB_SX1276Better_H - -#include - -/*! - \class SX1276 - - \brief Derived class for %SX1276 modules. Overrides some methods from SX1278 due to different parameter ranges. -*/ -class SX1276Better: public SX1278 { - public: - - // constructor - - /*! - \brief Default constructor. Called from Arduino sketch when creating new LoRa instance. - - \param mod Instance of Module that will be used to communicate with the %LoRa chip. - */ - SX1276Better(Module* mod); - - // basic methods - - /*! - \brief %LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module. - - \param freq Carrier frequency in MHz. Allowed values range from 137.0 MHz to 1020.0 MHz. - - \param bw %LoRa link bandwidth in kHz. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz. - - \param sf %LoRa link spreading factor. Allowed values range from 6 to 12. - - \param cr %LoRa link coding rate denominator. Allowed values range from 5 to 8. - - \param syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks. - - \param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm. - - \param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number. - Allowed values range from 6 to 65535. - - \param gain Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain. - Set to 0 to enable automatic gain control (recommended). - - \returns \ref status_codes - */ - int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0); - - /*! - \brief FSK modem initialization method. Must be called at least once from Arduino sketch to initialize the module. - - \param freq Carrier frequency in MHz. Allowed values range from 137.0 MHz to 525.0 MHz. - - \param br Bit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 1.2 to 300.0 kbps. - - \param freqDev Frequency deviation of the FSK transmission in kHz. Allowed values range from 0.6 to 200.0 kHz. - Note that the allowed range changes based on bit rate setting, so that the condition FreqDev + BitRate/2 <= 250 kHz is always met. - - \param rxBw Receiver bandwidth in kHz. Allowed values are 2.6, 3.1, 3.9, 5.2, 6.3, 7.8, 10.4, 12.5, 15.6, 20.8, 25, 31.3, 41.7, 50, 62.5, 83.3, 100, 125, 166.7, 200 and 250 kHz. - - \param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm. - - \param preambleLength Length of FSK preamble in bits. - - \param enableOOK Use OOK modulation instead of FSK. - - \returns \ref status_codes - */ - int16_t beginFSK(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 125.0, int8_t power = 10, uint16_t preambleLength = 16, bool enableOOK = false); - - // configuration methods - - /*! - \brief Sets carrier frequency. Allowed values range from 137.0 MHz to 1020.0 MHz. - - \param freq Carrier frequency to be set in MHz. - - \returns \ref status_codes - */ - int16_t setFrequency(float freq); - Module* pubmod; - int16_t setModeP(uint8_t mode); -#if !defined(RADIOLIB_GODMODE) - private: -#endif - -}; - -#endif - diff --git a/pocsag-transmit-test/disabledsrc/SX1278Better.cpp b/pocsag-transmit-test/disabledsrc/SX1278Better.cpp deleted file mode 100644 index 76b437c..0000000 --- a/pocsag-transmit-test/disabledsrc/SX1278Better.cpp +++ /dev/null @@ -1,550 +0,0 @@ -#include "SX1278Better.h" - -SX1278Better::SX1278Better(Module* mod) : SX127x(mod) { - -} - -int16_t SX1278Better::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) { - // execute common part - int16_t state = SX127x::begin(SX1278_CHIP_VERSION, syncWord, preambleLength); - RADIOLIB_ASSERT(state); - - // configure publicly accessible settings - state = setBandwidth(bw); - RADIOLIB_ASSERT(state); - - state = setFrequency(freq); - RADIOLIB_ASSERT(state); - - state = setSpreadingFactor(sf); - RADIOLIB_ASSERT(state); - - state = setCodingRate(cr); - RADIOLIB_ASSERT(state); - - state = setOutputPower(power); - RADIOLIB_ASSERT(state); - - state = setGain(gain); - RADIOLIB_ASSERT(state); - - return(state); -} - -int16_t SX1278Better::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, bool enableOOK) { - // execute common part - int16_t state = SX127x::beginFSK(SX1278_CHIP_VERSION, br, freqDev, rxBw, preambleLength, enableOOK); - RADIOLIB_ASSERT(state); - - // configure settings not accessible by API - state = configFSK(); - RADIOLIB_ASSERT(state); - - // configure publicly accessible settings - state = setFrequency(freq); - RADIOLIB_ASSERT(state); - - state = setOutputPower(power); - RADIOLIB_ASSERT(state); - - state = setDataShaping(RADIOLIB_SHAPING_NONE); - RADIOLIB_ASSERT(state); - - return(state); -} - -void SX1278Better::reset() { - Module::pinMode(_mod->getRst(), OUTPUT); - Module::digitalWrite(_mod->getRst(), LOW); - Module::delay(1); - Module::digitalWrite(_mod->getRst(), HIGH); - Module::delay(5); -} - -int16_t SX1278Better::setFrequency(float freq) { - RADIOLIB_CHECK_RANGE(freq, 137.0, 525.0, ERR_INVALID_FREQUENCY); - - // SX1276/77/78 Errata fixes - if(getActiveModem() == SX127X_LORA) { - // sensitivity optimization for 500kHz bandwidth - // see SX1276/77/78 Errata, section 2.1 for details - if(abs(_bw - 500.0) <= 0.001) { - if((freq >= 862.0) && (freq <= 1020.0)) { - _mod->SPIwriteRegister(0x36, 0x02); - _mod->SPIwriteRegister(0x3a, 0x64); - } else if((freq >= 410.0) && (freq <= 525.0)) { - _mod->SPIwriteRegister(0x36, 0x02); - _mod->SPIwriteRegister(0x3a, 0x7F); - } - } - - // mitigation of receiver spurious response - // see SX1276/77/78 Errata, section 2.3 for details - if(abs(_bw - 7.8) <= 0.001) { - _mod->SPIsetRegValue(0x31, 0b0000000, 7, 7); - _mod->SPIsetRegValue(0x2F, 0x48); - _mod->SPIsetRegValue(0x30, 0x00); - freq += 7.8; - } else if(abs(_bw - 10.4) <= 0.001) { - _mod->SPIsetRegValue(0x31, 0b0000000, 7, 7); - _mod->SPIsetRegValue(0x2F, 0x44); - _mod->SPIsetRegValue(0x30, 0x00); - freq += 10.4; - } else if(abs(_bw - 15.6) <= 0.001) { - _mod->SPIsetRegValue(0x31, 0b0000000, 7, 7); - _mod->SPIsetRegValue(0x2F, 0x44); - _mod->SPIsetRegValue(0x30, 0x00); - freq += 15.6; - } else if(abs(_bw - 20.8) <= 0.001) { - _mod->SPIsetRegValue(0x31, 0b0000000, 7, 7); - _mod->SPIsetRegValue(0x2F, 0x44); - _mod->SPIsetRegValue(0x30, 0x00); - freq += 20.8; - } else if(abs(_bw - 31.25) <= 0.001) { - _mod->SPIsetRegValue(0x31, 0b0000000, 7, 7); - _mod->SPIsetRegValue(0x2F, 0x44); - _mod->SPIsetRegValue(0x30, 0x00); - freq += 31.25; - } else if(abs(_bw - 41.7) <= 0.001) { - _mod->SPIsetRegValue(0x31, 0b0000000, 7, 7); - _mod->SPIsetRegValue(0x2F, 0x44); - _mod->SPIsetRegValue(0x30, 0x00); - freq += 41.7; - } else if(abs(_bw - 62.5) <= 0.001) { - _mod->SPIsetRegValue(0x31, 0b0000000, 7, 7); - _mod->SPIsetRegValue(0x2F, 0x40); - _mod->SPIsetRegValue(0x30, 0x00); - } else if(abs(_bw - 125.0) <= 0.001) { - _mod->SPIsetRegValue(0x31, 0b0000000, 7, 7); - _mod->SPIsetRegValue(0x2F, 0x40); - _mod->SPIsetRegValue(0x30, 0x00); - } else if(abs(_bw - 250.0) <= 0.001) { - _mod->SPIsetRegValue(0x31, 0b0000000, 7, 7); - _mod->SPIsetRegValue(0x2F, 0x40); - _mod->SPIsetRegValue(0x30, 0x00); - } else if(abs(_bw - 500.0) <= 0.001) { - _mod->SPIsetRegValue(0x31, 0b1000000, 7, 7); - } - } - - // set frequency and if successful, save the new setting - int16_t state = SX127x::setFrequencyRaw(freq); - if(state == ERR_NONE) { - SX127x::_freq = freq; - } - return(state); -} - -int16_t SX1278Better::setBandwidth(float bw) { - // check active modem - if(getActiveModem() != SX127X_LORA) { - return(ERR_WRONG_MODEM); - } - - uint8_t newBandwidth; - - // check allowed bandwidth values - if(abs(bw - 7.8) <= 0.001) { - newBandwidth = SX1278_BW_7_80_KHZ; - } else if(abs(bw - 10.4) <= 0.001) { - newBandwidth = SX1278_BW_10_40_KHZ; - } else if(abs(bw - 15.6) <= 0.001) { - newBandwidth = SX1278_BW_15_60_KHZ; - } else if(abs(bw - 20.8) <= 0.001) { - newBandwidth = SX1278_BW_20_80_KHZ; - } else if(abs(bw - 31.25) <= 0.001) { - newBandwidth = SX1278_BW_31_25_KHZ; - } else if(abs(bw - 41.7) <= 0.001) { - newBandwidth = SX1278_BW_41_70_KHZ; - } else if(abs(bw - 62.5) <= 0.001) { - newBandwidth = SX1278_BW_62_50_KHZ; - } else if(abs(bw - 125.0) <= 0.001) { - newBandwidth = SX1278_BW_125_00_KHZ; - } else if(abs(bw - 250.0) <= 0.001) { - newBandwidth = SX1278_BW_250_00_KHZ; - } else if(abs(bw - 500.0) <= 0.001) { - newBandwidth = SX1278_BW_500_00_KHZ; - } else { - return(ERR_INVALID_BANDWIDTH); - } - - // set bandwidth and if successful, save the new setting - int16_t state = SX1278::setBandwidthRaw(newBandwidth); - if(state == ERR_NONE) { - SX127x::_bw = bw; - - // calculate symbol length and set low data rate optimization, if auto-configuration is enabled - if(_ldroAuto) { - float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw; - RADIOLIB_DEBUG_PRINT("Symbol length: "); - RADIOLIB_DEBUG_PRINT(symbolLength); - RADIOLIB_DEBUG_PRINTLN(" ms"); - if(symbolLength >= 16.0) { - state = _mod->SPIsetRegValue(SX1278_REG_MODEM_CONFIG_3, SX1278_LOW_DATA_RATE_OPT_ON, 3, 3); - } else { - state = _mod->SPIsetRegValue(SX1278_REG_MODEM_CONFIG_3, SX1278_LOW_DATA_RATE_OPT_OFF, 3, 3); - } - } - } - return(state); -} - -int16_t SX1278Better::setSpreadingFactor(uint8_t sf) { - // check active modem - if(getActiveModem() != SX127X_LORA) { - return(ERR_WRONG_MODEM); - } - - uint8_t newSpreadingFactor; - - // check allowed spreading factor values - switch(sf) { - case 6: - newSpreadingFactor = SX127X_SF_6; - break; - case 7: - newSpreadingFactor = SX127X_SF_7; - break; - case 8: - newSpreadingFactor = SX127X_SF_8; - break; - case 9: - newSpreadingFactor = SX127X_SF_9; - break; - case 10: - newSpreadingFactor = SX127X_SF_10; - break; - case 11: - newSpreadingFactor = SX127X_SF_11; - break; - case 12: - newSpreadingFactor = SX127X_SF_12; - break; - default: - return(ERR_INVALID_SPREADING_FACTOR); - } - - // set spreading factor and if successful, save the new setting - int16_t state = SX1278::setSpreadingFactorRaw(newSpreadingFactor); - if(state == ERR_NONE) { - SX127x::_sf = sf; - - // calculate symbol length and set low data rate optimization, if auto-configuration is enabled - if(_ldroAuto) { - float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw; - RADIOLIB_DEBUG_PRINT("Symbol length: "); - RADIOLIB_DEBUG_PRINT(symbolLength); - RADIOLIB_DEBUG_PRINTLN(" ms"); - if(symbolLength >= 16.0) { - state = _mod->SPIsetRegValue(SX1278_REG_MODEM_CONFIG_3, SX1278_LOW_DATA_RATE_OPT_ON, 3, 3); - } else { - state = _mod->SPIsetRegValue(SX1278_REG_MODEM_CONFIG_3, SX1278_LOW_DATA_RATE_OPT_OFF, 3, 3); - } - } - } - return(state); -} - -int16_t SX1278Better::setCodingRate(uint8_t cr) { - // check active modem - if(getActiveModem() != SX127X_LORA) { - return(ERR_WRONG_MODEM); - } - - uint8_t newCodingRate; - - // check allowed coding rate values - switch(cr) { - case 5: - newCodingRate = SX1278_CR_4_5; - break; - case 6: - newCodingRate = SX1278_CR_4_6; - break; - case 7: - newCodingRate = SX1278_CR_4_7; - break; - case 8: - newCodingRate = SX1278_CR_4_8; - break; - default: - return(ERR_INVALID_CODING_RATE); - } - - // set coding rate and if successful, save the new setting - int16_t state = SX1278::setCodingRateRaw(newCodingRate); - if(state == ERR_NONE) { - SX127x::_cr = cr; - } - return(state); -} - -int16_t SX1278Better::setOutputPower(int8_t power) { - // check allowed power range - if(!(((power >= -3) && (power <= 17)) || (power == 20))) { - return(ERR_INVALID_OUTPUT_POWER); - } - - // set mode to standby - int16_t state = SX127x::standby(); - - // set output power - if(power < 2) { - // power is less than 2 dBm, enable PA on RFO - state |= _mod->SPIsetRegValue(SX127X_REG_PA_CONFIG, SX127X_PA_SELECT_RFO, 7, 7); - state |= _mod->SPIsetRegValue(SX127X_REG_PA_CONFIG, SX1278_LOW_POWER | (power + 3), 6, 0); - state |= _mod->SPIsetRegValue(SX1278_REG_PA_DAC, SX127X_PA_BOOST_OFF, 2, 0); - } else if(power <= 17) { - // power is 2 - 17 dBm, enable PA1 + PA2 on PA_BOOST - state |= _mod->SPIsetRegValue(SX127X_REG_PA_CONFIG, SX127X_PA_SELECT_BOOST, 7, 7); - state |= _mod->SPIsetRegValue(SX127X_REG_PA_CONFIG, SX1278_MAX_POWER | (power - 2), 6, 0); - state |= _mod->SPIsetRegValue(SX1278_REG_PA_DAC, SX127X_PA_BOOST_OFF, 2, 0); - } else if(power == 20) { - // power is 20 dBm, enable PA1 + PA2 on PA_BOOST and enable high power mode - state |= _mod->SPIsetRegValue(SX127X_REG_PA_CONFIG, SX127X_PA_SELECT_BOOST, 7, 7); - state |= _mod->SPIsetRegValue(SX127X_REG_PA_CONFIG, SX1278_MAX_POWER | (power - 5), 6, 0); - state |= _mod->SPIsetRegValue(SX1278_REG_PA_DAC, SX127X_PA_BOOST_ON, 2, 0); - } - return(state); -} - -int16_t SX1278Better::setGain(uint8_t gain) { - // check active modem - if(getActiveModem() != SX127X_LORA) { - return(ERR_WRONG_MODEM); - } - - // check allowed range - if(gain > 6) { - return(ERR_INVALID_GAIN); - } - - // set mode to standby - int16_t state = SX127x::standby(); - - // set gain - if(gain == 0) { - // gain set to 0, enable AGC loop - state |= _mod->SPIsetRegValue(SX1278_REG_MODEM_CONFIG_3, SX1278_AGC_AUTO_ON, 2, 2); - } else { - state |= _mod->SPIsetRegValue(SX1278_REG_MODEM_CONFIG_3, SX1278_AGC_AUTO_OFF, 2, 2); - state |= _mod->SPIsetRegValue(SX127X_REG_LNA, (gain << 5) | SX127X_LNA_BOOST_ON); - } - return(state); -} - -int16_t SX1278Better::setDataShaping(uint8_t sh) { - // check active modem - if(getActiveModem() != SX127X_FSK_OOK) { - return(ERR_WRONG_MODEM); - } - - // check modulation - if(SX127x::_ook) { - return(ERR_INVALID_MODULATION); - } - - // set mode to standby - int16_t state = SX127x::standby(); - RADIOLIB_ASSERT(state); - - // set data shaping - switch(sh) { - case RADIOLIB_SHAPING_NONE: - return(_mod->SPIsetRegValue(SX127X_REG_PA_RAMP, SX1278_NO_SHAPING, 6, 5)); - case RADIOLIB_SHAPING_0_3: - return(_mod->SPIsetRegValue(SX127X_REG_PA_RAMP, SX1278_FSK_GAUSSIAN_0_3, 6, 5)); - case RADIOLIB_SHAPING_0_5: - return(_mod->SPIsetRegValue(SX127X_REG_PA_RAMP, SX1278_FSK_GAUSSIAN_0_5, 6, 5)); - case RADIOLIB_SHAPING_1_0: - return(_mod->SPIsetRegValue(SX127X_REG_PA_RAMP, SX1278_FSK_GAUSSIAN_1_0, 6, 5)); - default: - return(ERR_INVALID_DATA_SHAPING); - } -} - -int16_t SX1278Better::setDataShapingOOK(uint8_t sh) { - // check active modem - if(getActiveModem() != SX127X_FSK_OOK) { - return(ERR_WRONG_MODEM); - } - - // check modulation - if(!SX127x::_ook) { - return(ERR_INVALID_MODULATION); - } - - // set mode to standby - int16_t state = SX127x::standby(); - - // set data shaping - switch(sh) { - case 0: - state |= _mod->SPIsetRegValue(SX127X_REG_PA_RAMP, SX1278_NO_SHAPING, 6, 5); - break; - case 1: - state |= _mod->SPIsetRegValue(SX127X_REG_PA_RAMP, SX1278_OOK_FILTER_BR, 6, 5); - break; - case 2: - state |= _mod->SPIsetRegValue(SX127X_REG_PA_RAMP, SX1278_OOK_FILTER_2BR, 6, 5); - break; - default: - return(ERR_INVALID_DATA_SHAPING); - } - - return(state); -} - -float SX1278Better::getRSSI() { - if(getActiveModem() == SX127X_LORA) { - // for LoRa, get RSSI of the last packet - float lastPacketRSSI; - - // RSSI calculation uses different constant for low-frequency and high-frequency ports - if(_freq < 868.0) { - lastPacketRSSI = -164 + _mod->SPIgetRegValue(SX127X_REG_PKT_RSSI_VALUE); - } else { - lastPacketRSSI = -157 + _mod->SPIgetRegValue(SX127X_REG_PKT_RSSI_VALUE); - } - - // spread-spectrum modulation signal can be received below noise floor - // check last packet SNR and if it's less than 0, add it to reported RSSI to get the correct value - float lastPacketSNR = SX127x::getSNR(); - if(lastPacketSNR < 0.0) { - lastPacketRSSI += lastPacketSNR; - } - - return(lastPacketRSSI); - - } else { - // enable listen mode - startReceive(); - - // read the value for FSK - float rssi = (float)_mod->SPIgetRegValue(SX127X_REG_RSSI_VALUE_FSK) / -2.0; - - // set mode back to standby - standby(); - - // return the value - return(rssi); - } -} - -int16_t SX1278Better::setCRC(bool enableCRC) { - if(getActiveModem() == SX127X_LORA) { - // set LoRa CRC - SX127x::_crcEnabled = enableCRC; - if(enableCRC) { - return(_mod->SPIsetRegValue(SX127X_REG_MODEM_CONFIG_2, SX1278_RX_CRC_MODE_ON, 2, 2)); - } else { - return(_mod->SPIsetRegValue(SX127X_REG_MODEM_CONFIG_2, SX1278_RX_CRC_MODE_OFF, 2, 2)); - } - } else { - // set FSK CRC - if(enableCRC) { - return(_mod->SPIsetRegValue(SX127X_REG_PACKET_CONFIG_1, SX127X_CRC_ON, 4, 4)); - } else { - return(_mod->SPIsetRegValue(SX127X_REG_PACKET_CONFIG_1, SX127X_CRC_OFF, 4, 4)); - } - } -} - -int16_t SX1278Better::forceLDRO(bool enable) { - if(getActiveModem() != SX127X_LORA) { - return(ERR_WRONG_MODEM); - } - - _ldroAuto = false; - if(enable) { - return(_mod->SPIsetRegValue(SX1278_REG_MODEM_CONFIG_3, SX1278_LOW_DATA_RATE_OPT_ON, 3, 3)); - } else { - return(_mod->SPIsetRegValue(SX1278_REG_MODEM_CONFIG_3, SX1278_LOW_DATA_RATE_OPT_OFF, 3, 3)); - } -} - -int16_t SX1278Better::autoLDRO() { - if(getActiveModem() != SX127X_LORA) { - return(ERR_WRONG_MODEM); - } - - _ldroAuto = true; - return(ERR_NONE); -} - -int16_t SX1278Better::implicitHeader(size_t len) { - return(setHeaderType(SX1278_HEADER_IMPL_MODE, len)); -} - -int16_t SX1278Better::explicitHeader() { - return(setHeaderType(SX1278_HEADER_EXPL_MODE)); -} - -int16_t SX1278Better::setBandwidthRaw(uint8_t newBandwidth) { - // set mode to standby - int16_t state = SX127x::standby(); - - // write register - state |= _mod->SPIsetRegValue(SX127X_REG_MODEM_CONFIG_1, newBandwidth, 7, 4); - return(state); -} - -int16_t SX1278Better::setSpreadingFactorRaw(uint8_t newSpreadingFactor) { - // set mode to standby - int16_t state = SX127x::standby(); - - // write registers - if(newSpreadingFactor == SX127X_SF_6) { - state |= _mod->SPIsetRegValue(SX127X_REG_MODEM_CONFIG_1, SX1278_HEADER_IMPL_MODE, 0, 0); - state |= _mod->SPIsetRegValue(SX127X_REG_MODEM_CONFIG_2, SX127X_SF_6 | SX127X_TX_MODE_SINGLE | (SX127x::_crcEnabled ? SX1278_RX_CRC_MODE_ON : SX1278_RX_CRC_MODE_OFF), 7, 2); - state |= _mod->SPIsetRegValue(SX127X_REG_DETECT_OPTIMIZE, SX127X_DETECT_OPTIMIZE_SF_6, 2, 0); - state |= _mod->SPIsetRegValue(SX127X_REG_DETECTION_THRESHOLD, SX127X_DETECTION_THRESHOLD_SF_6); - } else { - state |= _mod->SPIsetRegValue(SX127X_REG_MODEM_CONFIG_1, SX1278_HEADER_EXPL_MODE, 0, 0); - state |= _mod->SPIsetRegValue(SX127X_REG_MODEM_CONFIG_2, newSpreadingFactor | SX127X_TX_MODE_SINGLE | (SX127x::_crcEnabled ? SX1278_RX_CRC_MODE_ON : SX1278_RX_CRC_MODE_OFF), 7, 2); - state |= _mod->SPIsetRegValue(SX127X_REG_DETECT_OPTIMIZE, SX127X_DETECT_OPTIMIZE_SF_7_12, 2, 0); - state |= _mod->SPIsetRegValue(SX127X_REG_DETECTION_THRESHOLD, SX127X_DETECTION_THRESHOLD_SF_7_12); - } - return(state); -} - -int16_t SX1278Better::setCodingRateRaw(uint8_t newCodingRate) { - // set mode to standby - int16_t state = SX127x::standby(); - - // write register - state |= _mod->SPIsetRegValue(SX127X_REG_MODEM_CONFIG_1, newCodingRate, 3, 1); - return(state); -} - -int16_t SX1278Better::setHeaderType(uint8_t headerType, size_t len) { - // check active modem - if(getActiveModem() != SX127X_LORA) { - return(ERR_WRONG_MODEM); - } - - // set requested packet mode - int16_t state = _mod->SPIsetRegValue(SX127X_REG_MODEM_CONFIG_1, headerType, 0, 0); - RADIOLIB_ASSERT(state); - - // set length to register - state = _mod->SPIsetRegValue(SX127X_REG_PAYLOAD_LENGTH, len); - RADIOLIB_ASSERT(state); - - // update cached value - _packetLength = len; - - return(state); -} - -int16_t SX1278Better::configFSK() { - // configure common registers - int16_t state = SX127x::configFSK(); - RADIOLIB_ASSERT(state); - - // set fast PLL hop - state = _mod->SPIsetRegValue(SX1278_REG_PLL_HOP, SX127X_FAST_HOP_ON, 7, 7); - return(state); -} - -#endif diff --git a/pocsag-transmit-test/disabledsrc/SX1278Better.h b/pocsag-transmit-test/disabledsrc/SX1278Better.h deleted file mode 100644 index d79937c..0000000 --- a/pocsag-transmit-test/disabledsrc/SX1278Better.h +++ /dev/null @@ -1,314 +0,0 @@ -#if !defined(_RADIOLIB_SX1278Better_H) -#define _RADIOLIB_SX1278Better_H - -#include - - -// SX1278 specific register map -#define SX1278_REG_MODEM_CONFIG_3 0x26 -#define SX1278_REG_PLL_HOP 0x44 -#define SX1278_REG_TCXO 0x4B -#define SX1278_REG_PA_DAC 0x4D -#define SX1278_REG_FORMER_TEMP 0x5B -#define SX1278_REG_REG_BIT_RATE_FRAC 0x5D -#define SX1278_REG_AGC_REF 0x61 -#define SX1278_REG_AGC_THRESH_1 0x62 -#define SX1278_REG_AGC_THRESH_2 0x63 -#define SX1278_REG_AGC_THRESH_3 0x64 -#define SX1278_REG_PLL 0x70 - -// SX1278 LoRa modem settings -// SX1278_REG_OP_MODE MSB LSB DESCRIPTION -#define SX1278_HIGH_FREQ 0b00000000 // 3 3 access HF test registers -#define SX1278_LOW_FREQ 0b00001000 // 3 3 access LF test registers - -// SX1278_REG_FRF_MSB + REG_FRF_MID + REG_FRF_LSB -#define SX1278_FRF_MSB 0x6C // 7 0 carrier frequency setting: f_RF = (F(XOSC) * FRF)/2^19 -#define SX1278_FRF_MID 0x80 // 7 0 where F(XOSC) = 32 MHz -#define SX1278_FRF_LSB 0x00 // 7 0 FRF = 3 byte value of FRF registers - -// SX1278_REG_PA_CONFIG -#define SX1278_MAX_POWER 0b01110000 // 6 4 max power: P_max = 10.8 + 0.6*MAX_POWER [dBm]; P_max(MAX_POWER = 0b111) = 15 dBm -#define SX1278_LOW_POWER 0b00100000 // 6 4 - -// SX1278_REG_LNA -#define SX1278_LNA_BOOST_LF_OFF 0b00000000 // 4 3 default LNA current - -// SX127X_REG_MODEM_CONFIG_1 -#define SX1278_BW_7_80_KHZ 0b00000000 // 7 4 bandwidth: 7.80 kHz -#define SX1278_BW_10_40_KHZ 0b00010000 // 7 4 10.40 kHz -#define SX1278_BW_15_60_KHZ 0b00100000 // 7 4 15.60 kHz -#define SX1278_BW_20_80_KHZ 0b00110000 // 7 4 20.80 kHz -#define SX1278_BW_31_25_KHZ 0b01000000 // 7 4 31.25 kHz -#define SX1278_BW_41_70_KHZ 0b01010000 // 7 4 41.70 kHz -#define SX1278_BW_62_50_KHZ 0b01100000 // 7 4 62.50 kHz -#define SX1278_BW_125_00_KHZ 0b01110000 // 7 4 125.00 kHz -#define SX1278_BW_250_00_KHZ 0b10000000 // 7 4 250.00 kHz -#define SX1278_BW_500_00_KHZ 0b10010000 // 7 4 500.00 kHz -#define SX1278_CR_4_5 0b00000010 // 3 1 error coding rate: 4/5 -#define SX1278_CR_4_6 0b00000100 // 3 1 4/6 -#define SX1278_CR_4_7 0b00000110 // 3 1 4/7 -#define SX1278_CR_4_8 0b00001000 // 3 1 4/8 -#define SX1278_HEADER_EXPL_MODE 0b00000000 // 0 0 explicit header mode -#define SX1278_HEADER_IMPL_MODE 0b00000001 // 0 0 implicit header mode - -// SX127X_REG_MODEM_CONFIG_2 -#define SX1278_RX_CRC_MODE_OFF 0b00000000 // 2 2 CRC disabled -#define SX1278_RX_CRC_MODE_ON 0b00000100 // 2 2 CRC enabled - -// SX1278_REG_MODEM_CONFIG_3 -#define SX1278_LOW_DATA_RATE_OPT_OFF 0b00000000 // 3 3 low data rate optimization disabled -#define SX1278_LOW_DATA_RATE_OPT_ON 0b00001000 // 3 3 low data rate optimization enabled -#define SX1278_AGC_AUTO_OFF 0b00000000 // 2 2 LNA gain set by REG_LNA -#define SX1278_AGC_AUTO_ON 0b00000100 // 2 2 LNA gain set by internal AGC loop - -// SX127X_REG_VERSION -#define SX1278_CHIP_VERSION 0x12 - -// SX1278 FSK modem settings -// SX127X_REG_PA_RAMP -#define SX1278_NO_SHAPING 0b00000000 // 6 5 data shaping: no shaping (default) -#define SX1278_FSK_GAUSSIAN_1_0 0b00100000 // 6 5 FSK modulation Gaussian filter, BT = 1.0 -#define SX1278_FSK_GAUSSIAN_0_5 0b01000000 // 6 5 FSK modulation Gaussian filter, BT = 0.5 -#define SX1278_FSK_GAUSSIAN_0_3 0b01100000 // 6 5 FSK modulation Gaussian filter, BT = 0.3 -#define SX1278_OOK_FILTER_BR 0b00100000 // 6 5 OOK modulation filter, f_cutoff = BR -#define SX1278_OOK_FILTER_2BR 0b01000000 // 6 5 OOK modulation filter, f_cutoff = 2*BR - -// SX1278_REG_AGC_REF -#define SX1278_AGC_REFERENCE_LEVEL_LF 0x19 // 5 0 floor reference for AGC thresholds: AgcRef = -174 + 10*log(2*RxBw) + 8 + AGC_REFERENCE_LEVEL [dBm]: below 525 MHz -#define SX1278_AGC_REFERENCE_LEVEL_HF 0x1C // 5 0 above 779 MHz - -// SX1278_REG_AGC_THRESH_1 -#define SX1278_AGC_STEP_1_LF 0x0C // 4 0 1st AGC threshold: below 525 MHz -#define SX1278_AGC_STEP_1_HF 0x0E // 4 0 above 779 MHz - -// SX1278_REG_AGC_THRESH_2 -#define SX1278_AGC_STEP_2_LF 0x40 // 7 4 2nd AGC threshold: below 525 MHz -#define SX1278_AGC_STEP_2_HF 0x50 // 7 4 above 779 MHz -#define SX1278_AGC_STEP_3 0x0B // 3 0 3rd AGC threshold - -// SX1278_REG_AGC_THRESH_3 -#define SX1278_AGC_STEP_4 0xC0 // 7 4 4th AGC threshold -#define SX1278_AGC_STEP_5 0x0C // 4 0 5th AGC threshold - -/*! - \class SX1278 - - \brief Derived class for %SX1278 modules. Also used as base class for SX1276, SX1277, SX1279, RFM95 and RFM96. - All of these modules use the same basic hardware and only differ in parameter ranges (and names). -*/ -class SX1278Better: public SX127x { - public: - - // constructor - - /*! - \brief Default constructor. Called from Arduino sketch when creating new LoRa instance. - - \param mod Instance of Module that will be used to communicate with the %LoRa chip. - */ - SX1278Better(Module* mod); - - // basic methods - - /*! - \brief %LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module. - - \param freq Carrier frequency in MHz. Allowed values range from 137.0 MHz to 525.0 MHz. - - \param bw %LoRa link bandwidth in kHz. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz. - - \param sf %LoRa link spreading factor. Allowed values range from 6 to 12. - - \param cr %LoRa link coding rate denominator. Allowed values range from 5 to 8. - - \param syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks. - - \param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm. - - \param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number. - Allowed values range from 6 to 65535. - - \param gain Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain. - Set to 0 to enable automatic gain control (recommended). - - \returns \ref status_codes - */ - int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0); - - /*! - \brief FSK modem initialization method. Must be called at least once from Arduino sketch to initialize the module. - - \param freq Carrier frequency in MHz. Allowed values range from 137.0 MHz to 525.0 MHz. - - \param br Bit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 1.2 to 300.0 kbps. - - \param freqDev Frequency deviation of the FSK transmission in kHz. Allowed values range from 0.6 to 200.0 kHz. - Note that the allowed range changes based on bit rate setting, so that the condition FreqDev + BitRate/2 <= 250 kHz is always met. - - \param rxBw Receiver bandwidth in kHz. Allowed values are 2.6, 3.1, 3.9, 5.2, 6.3, 7.8, 10.4, 12.5, 15.6, 20.8, 25, 31.3, 41.7, 50, 62.5, 83.3, 100, 125, 166.7, 200 and 250 kHz. - - \param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm. - - \param preambleLength Length of FSK preamble in bits. - - \param enableOOK Use OOK modulation instead of FSK. - - \returns \ref status_codes - */ - int16_t beginFSK(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 125.0, int8_t power = 10, uint16_t preambleLength = 16, bool enableOOK = false); - - /*! - \brief Reset method. Will reset the chip to the default state using RST pin. - */ - void reset() override; - - // configuration methods - - /*! - \brief Sets carrier frequency. Allowed values range from 137.0 MHz to 525.0 MHz. - - \param freq Carrier frequency to be set in MHz. - - \returns \ref status_codes - */ - int16_t setFrequency(float freq); - - /*! - \brief Sets %LoRa link bandwidth. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz. Only available in %LoRa mode. - - \param bw %LoRa link bandwidth to be set in kHz. - - \returns \ref status_codes - */ - int16_t setBandwidth(float bw); - - /*! - \brief Sets %LoRa link spreading factor. Allowed values range from 6 to 12. Only available in %LoRa mode. - - \param sf %LoRa link spreading factor to be set. - - \returns \ref status_codes - */ - int16_t setSpreadingFactor(uint8_t sf); - - /*! - \brief Sets %LoRa link coding rate denominator. Allowed values range from 5 to 8. Only available in %LoRa mode. - - \param cr %LoRa link coding rate denominator to be set. - - \returns \ref status_codes - */ - int16_t setCodingRate(uint8_t cr); - - /*! - \brief Sets transmission output power. Allowed values range from 2 to 17 dBm. - - \param power Transmission output power in dBm. - - \returns \ref status_codes - */ - int16_t setOutputPower(int8_t power); - - /*! - \brief Sets gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain. - Set to 0 to enable automatic gain control (recommended). Only available in %LoRa mode. - - \param gain Gain of receiver LNA (low-noise amplifier) to be set. - - \returns \ref status_codes - */ - int16_t setGain(uint8_t gain); - - /*! - \brief Sets Gaussian filter bandwidth-time product that will be used for data shaping. Only available in FSK mode with FSK modulation. - Allowed values are RADIOLIB_SHAPING_0_3, RADIOLIB_SHAPING_0_5 or RADIOLIB_SHAPING_1_0. Set to RADIOLIB_SHAPING_NONE to disable data shaping. - - \param sh Gaussian shaping bandwidth-time product that will be used for data shaping - - \returns \ref status_codes - */ - int16_t setDataShaping(uint8_t sh) override; - - /*! - \brief Sets filter cutoff frequency that will be used for data shaping. - Allowed values are 1 for frequency equal to bit rate and 2 for frequency equal to 2x bit rate. Set to 0 to disable data shaping. - Only available in FSK mode with OOK modulation. - - \param sh Cutoff frequency that will be used for data shaping - - \returns \ref status_codes - */ - int16_t setDataShapingOOK(uint8_t sh); - - /*! - \brief Gets recorded signal strength indicator of the latest received packet for LoRa modem, or current RSSI level for FSK modem. - - \returns Last packet RSSI for LoRa modem, or current RSSI level for FSK modem. - */ - float getRSSI(); - - /*! - \brief Enables/disables CRC check of received packets. - - \param enableCRC Enable (true) or disable (false) CRC. - - \returns \ref status_codes - */ - int16_t setCRC(bool enableCRC); - - /*! - \brief Forces LoRa low data rate optimization. Only available in LoRa mode. After calling this method, LDRO will always be set to - the provided value, regardless of symbol length. To re-enable automatic LDRO configuration, call SX1278::autoLDRO() - - \param enable Force LDRO to be always enabled (true) or disabled (false). - - \returns \ref status_codes - */ - int16_t forceLDRO(bool enable); - - /*! - \brief Re-enables automatic LDRO configuration. Only available in LoRa mode. After calling this method, LDRO will be enabled automatically - when symbol length exceeds 16 ms. - - \returns \ref status_codes - */ - int16_t autoLDRO(); - - /*! - \brief Set implicit header mode for future reception/transmission. - - \returns \ref status_codes - */ - int16_t implicitHeader(size_t len); - - /*! - \brief Set explicit header mode for future reception/transmission. - - \param len Payload length in bytes. - - \returns \ref status_codes - */ - int16_t explicitHeader(); - -#if !defined(RADIOLIB_GODMODE) - protected: -#endif - int16_t setBandwidthRaw(uint8_t newBandwidth); - int16_t setSpreadingFactorRaw(uint8_t newSpreadingFactor); - int16_t setCodingRateRaw(uint8_t newCodingRate); - int16_t setHeaderType(uint8_t headerType, size_t len = 0xFF); - - int16_t configFSK(); - -#if !defined(RADIOLIB_GODMODE) - private: -#endif - bool _ldroAuto = true; - bool _ldroEnabled = false; - -}; - -#endif - -#endif