diff --git a/.gitignore b/.gitignore index 591da307..f1723db9 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,9 @@ *.tags *.tags1 +# Jetbrain IDEs +.idea + # Debug decoder extras/decoder/log.txt extras/decoder/out.txt diff --git a/keywords.txt b/keywords.txt index fd9d2268..34f66d67 100644 --- a/keywords.txt +++ b/keywords.txt @@ -132,6 +132,9 @@ forceLDRO KEYWORD2 autoLDRO KEYWORD2 getChipVersion KEYWORD2 invertIQ KEYWORD2 +setOokThresholdType KEYWORD2 +setOokPeakThresholdDecrement KEYWORD2 +setOokFixedOrFloorThreshold KEYWORD2 # RF69-specific setAESKey KEYWORD2 @@ -139,6 +142,7 @@ enableAES KEYWORD2 disableAES KEYWORD2 getTemperature KEYWORD2 setAmbientTemperature KEYWORD2 +setLnaTestBoost KEYWORD2 # CC1101-specific getLQI KEYWORD2 diff --git a/src/TypeDef.h b/src/TypeDef.h index 236c7ab4..2d22051d 100644 --- a/src/TypeDef.h +++ b/src/TypeDef.h @@ -325,6 +325,11 @@ */ #define ERR_INVALID_MODULATION -107 +/*! + \brief Supplied Peak type is invalid. +*/ +#define ERR_INVALID_OOK_RSSI_PEAK_TYPE -108 + // ESP8266 status codes /*! diff --git a/src/modules/RF69/RF69.cpp b/src/modules/RF69/RF69.cpp index 65aa67b1..4858380d 100644 --- a/src/modules/RF69/RF69.cpp +++ b/src/modules/RF69/RF69.cpp @@ -369,6 +369,31 @@ int16_t RF69::readData(uint8_t* data, size_t len) { return(ERR_NONE); } +int16_t RF69::setOOK(bool enableOOK) { + // set OOK and if successful, save the new setting + int16_t state = ERR_NONE; + if(enableOOK) { + state = _mod->SPIsetRegValue(RF69_REG_DATA_MODUL, RF69_OOK, 4, 3, 5); + } else { + state = _mod->SPIsetRegValue(RF69_REG_DATA_MODUL, RF69_FSK, 4, 3, 5); + } + if(state == ERR_NONE) { + _ook = enableOOK; + } + + return(state); +} + +int16_t RF69::setOokThresholdType(uint8_t type) { + if(type != RF69_OOK_THRESH_FIXED && type != RF69_OOK_THRESH_PEAK && type != RF69_OOK_THRESH_AVERAGE) + return ERR_INVALID_OOK_RSSI_PEAK_TYPE; + + int16_t state = ERR_NONE; + state = _mod->SPIsetRegValue(RF69_REG_OOK_PEAK, type, 7, 3, 5); + + return(state); +} + int16_t RF69::setFrequency(float freq) { // check allowed frequency range if(!(((freq > 290.0) && (freq < 340.0)) || @@ -762,6 +787,14 @@ int16_t RF69::setEncoding(uint8_t encoding) { } } +int16_t RF69::setLnaTestBoost(bool value) { + if(value) { + return (_mod->SPIsetRegValue(RF69_REG_TEST_LNA, RF69_TEST_LNA_BOOST_HIGH, 7, 0)); + } + + return(_mod->SPIsetRegValue(RF69_TEST_LNA_BOOST_NORMAL, RF69_TEST_LNA_BOOST_HIGH, 7, 0)); +} + float RF69::getRSSI() { return(-1.0 * (_mod->SPIgetRegValue(RF69_REG_RSSI_VALUE)/2.0)); } diff --git a/src/modules/RF69/RF69.h b/src/modules/RF69/RF69.h index 7bb87310..1474d31c 100644 --- a/src/modules/RF69/RF69.h +++ b/src/modules/RF69/RF69.h @@ -91,6 +91,7 @@ #define RF69_REG_AES_KEY_16 0x4D #define RF69_REG_TEMP_1 0x4E #define RF69_REG_TEMP_2 0x4F +#define RF69_REG_TEST_LNA 0x58 #define RF69_REG_TEST_PA1 0x5A #define RF69_REG_TEST_PA2 0x5C #define RF69_REG_TEST_DAGC 0x6F @@ -409,6 +410,10 @@ #define RF69_AES_OFF 0b00000000 // 0 0 AES encryption disabled (default) #define RF69_AES_ON 0b00000001 // 0 0 AES encryption enabled, payload size limited to 66 bytes +// RF69_REG_TEST_LNA +#define RF69_TEST_LNA_BOOST_NORMAL 0x1B // 7 0 +#define RF69_TEST_LNA_BOOST_HIGH 0x2D // 7 0 + // RF69_REG_TEMP_1 #define RF69_TEMP_MEAS_START 0b00001000 // 3 3 trigger temperature measurement #define RF69_TEMP_MEAS_RUNNING 0b00000100 // 2 2 temperature measurement status: on-going @@ -734,6 +739,23 @@ class RF69: public PhysicalLayer { */ size_t getPacketLength(bool update = true) override; + /*! + \brief Enables/disables OOK modulation instead of FSK. + + \param enableOOK Enable (true) or disable (false) OOK. + + \returns \ref status_codes + */ + int16_t setOOK(bool enableOOK); + + /*! + \brief Selects the type of threshold in the OOK data slicer + + \param type RF69_OOK_THRESH_FIXED RF69_OOK_THRESH_PEAK(default) RF69_OOK_THRESH_AVERAGE + \returns \ref status_codes + */ + int16_t setOokThresholdType(uint8_t type); + /*! \brief Set modem in fixed packet length mode. @@ -806,6 +828,15 @@ class RF69: public PhysicalLayer { */ int16_t setEncoding(uint8_t encoding) override; + /*! + \brief enable/disable LNA Boost mode (disabled by default + + \param value true to enable, false to disable + + \returns \ref status_codes + */ + int16_t setLnaTestBoost(bool value); + /*! \brief Gets RSSI (Recorded Signal Strength Indicator) of the last received packet. @@ -848,6 +879,7 @@ class RF69: public PhysicalLayer { float _br = 0; float _rxBw = 0; + bool _ook = false; int16_t _tempOffset = 0; int8_t _power = 0; diff --git a/src/modules/SX127x/SX1272.cpp b/src/modules/SX127x/SX1272.cpp index 183bbd85..755c39b4 100644 --- a/src/modules/SX127x/SX1272.cpp +++ b/src/modules/SX127x/SX1272.cpp @@ -330,7 +330,7 @@ int16_t SX1272::setDataShapingOOK(uint8_t sh) { return(state); } -float SX1272::getRSSI() { +float SX1272::getRSSI(bool skip_activation) { if(getActiveModem() == SX127X_LORA) { // RSSI calculation uses different constant for low-frequency and high-frequency ports float lastPacketRSSI = -139 + _mod->SPIgetRegValue(SX127X_REG_PKT_RSSI_VALUE); diff --git a/src/modules/SX127x/SX1272.h b/src/modules/SX127x/SX1272.h index 81b84cab..6ec58071 100644 --- a/src/modules/SX127x/SX1272.h +++ b/src/modules/SX127x/SX1272.h @@ -240,9 +240,11 @@ class SX1272: public SX127x { /*! \brief Gets recorded signal strength indicator of the latest received packet for LoRa modem, or current RSSI level for FSK modem. + \param skip_activation in OOK/FSK mode this function will put receiver in receive mode and then in standby. Make it TRUE if you don't want this behaviour. + \returns Last packet RSSI for LoRa modem, or current RSSI level for FSK modem. */ - float getRSSI(); + float getRSSI(bool skip_activation = false); /*! \brief Enables/disables CRC check of received packets. diff --git a/src/modules/SX127x/SX1278.cpp b/src/modules/SX127x/SX1278.cpp index f9bedb16..3e708bb3 100644 --- a/src/modules/SX127x/SX1278.cpp +++ b/src/modules/SX127x/SX1278.cpp @@ -315,10 +315,7 @@ int16_t SX1278::setOutputPower(int8_t power) { } int16_t SX1278::setGain(uint8_t gain) { - // check active modem - if(getActiveModem() != SX127X_LORA) { - return(ERR_WRONG_MODEM); - } + int16_t modem = getActiveModem(); // check allowed range if(gain > 6) { @@ -328,14 +325,27 @@ int16_t SX1278::setGain(uint8_t 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); + if(modem == SX127X_LORA){ + // 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); + } } + else if(modem == SX127X_FSK_OOK) { + // set gain + if(gain == 0) { + // gain set to 0, enable AGC loop + state |= _mod->SPIsetRegValue(SX127X_REG_RX_CONFIG, SX127X_AGC_AUTO_ON, 3, 3); + } else { + state |= _mod->SPIsetRegValue(SX127X_REG_RX_CONFIG, SX127X_AGC_AUTO_ON, 3, 3); + state |= _mod->SPIsetRegValue(SX127X_REG_LNA, (gain << 5) | SX127X_LNA_BOOST_ON); + } + } + return(state); } @@ -401,7 +411,7 @@ int16_t SX1278::setDataShapingOOK(uint8_t sh) { return(state); } -float SX1278::getRSSI() { +float SX1278::getRSSI(bool skip_activation) { if(getActiveModem() == SX127X_LORA) { // for LoRa, get RSSI of the last packet float lastPacketRSSI; @@ -424,13 +434,15 @@ float SX1278::getRSSI() { } else { // enable listen mode - startReceive(); + if(!skip_activation) + startReceive(); // read the value for FSK float rssi = (float)_mod->SPIgetRegValue(SX127X_REG_RSSI_VALUE_FSK) / -2.0; // set mode back to standby - standby(); + if(!skip_activation) + standby(); // return the value return(rssi); diff --git a/src/modules/SX127x/SX1278.h b/src/modules/SX127x/SX1278.h index 70f06092..40bcab66 100644 --- a/src/modules/SX127x/SX1278.h +++ b/src/modules/SX127x/SX1278.h @@ -248,9 +248,11 @@ class SX1278: public SX127x { /*! \brief Gets recorded signal strength indicator of the latest received packet for LoRa modem, or current RSSI level for FSK modem. + \param skip_activation in OOK/FSK mode this function will put receiver in receive mode and then in standby. Make it TRUE if you don't want this behaviour. + \returns Last packet RSSI for LoRa modem, or current RSSI level for FSK modem. */ - float getRSSI(); + float getRSSI(bool skip_activation=false); /*! \brief Enables/disables CRC check of received packets. diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index 2fac82e7..a9127da9 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -836,6 +836,44 @@ int16_t SX127x::disableAddressFiltering() { return(_mod->SPIsetRegValue(SX127X_REG_BROADCAST_ADRS, 0x00)); } +int16_t SX127x::setOokThresholdType(uint8_t type) { + // check active modem + if(getActiveModem() != SX127X_FSK_OOK) { + return(ERR_WRONG_MODEM); + } + + int16_t state = ERR_NONE; + state = _mod->SPIsetRegValue(SX127X_REG_OOK_PEAK, type, 4, 3, 5); + + return(state); +} + +int16_t SX127x::setOokFixedOrFloorThreshold(uint8_t value) { + // check active modem + if(getActiveModem() != SX127X_FSK_OOK) { + return(ERR_WRONG_MODEM); + } + + int16_t state = ERR_NONE; + state = _mod->SPIsetRegValue(SX127X_REG_OOK_FIX, value, 7, 0, 5); + + return(state); +} + +int16_t SX127x::setOokPeakThresholdDecrement(uint8_t value) { + // check active modem + if(getActiveModem() != SX127X_FSK_OOK) { + return(ERR_WRONG_MODEM); + } + + int16_t state = ERR_NONE; + state = _mod->SPIsetRegValue(SX127X_REG_OOK_AVG, value, 7, 5, 5); + + return(state); +} + + + int16_t SX127x::setOOK(bool enableOOK) { // check active modem if(getActiveModem() != SX127X_FSK_OOK) { diff --git a/src/modules/SX127x/SX127x.h b/src/modules/SX127x/SX127x.h index 90425b79..c1d53f0f 100644 --- a/src/modules/SX127x/SX127x.h +++ b/src/modules/SX127x/SX127x.h @@ -859,6 +859,34 @@ class SX127x: public PhysicalLayer { */ int16_t setOOK(bool enableOOK); + /*! + \brief Selects the type of threshold in the OOK data slicer + + \param type SX127X_OOK_THRESH_FIXED, SX127X_OOK_THRESH_PEAK(default), SX127X_OOK_THRESH_AVERAGE + + \returns \ref status_codes + */ + int16_t setOokThresholdType(uint8_t type); + + /*! + \brief Period of decrement of the RSSI threshold in the OOK demodulator + + \param value use defines SX127X_OOK_PEAK_THRESH_DEC_X_X_CHIP + + \returns \ref status_codes + */ + int16_t setOokPeakThresholdDecrement(uint8_t value); + + /*! + \brief Fixed threshold for the Data Slicer in OOK mode + Floor threshold for the Data Slicer in OOK when Peak mode is used + + \param value calculation is (128 - value/2) + + \returns \ref status_codes + */ + int16_t setOokFixedOrFloorThreshold(uint8_t value); + /*! \brief Query modem for the packet length of received payload.