From 04e24ab9d14c23ac94fbe501b70122732e021569 Mon Sep 17 00:00:00 2001 From: G4lile0 Date: Fri, 24 Mar 2023 20:30:06 +0100 Subject: [PATCH] [SX1278] New getInstRSSI to get current RSSI --- src/modules/SX127x/SX1278.cpp | 33 +++++++++++++++++++++++++++++++++ src/modules/SX127x/SX1278.h | 9 +++++++++ 2 files changed, 42 insertions(+) diff --git a/src/modules/SX127x/SX1278.cpp b/src/modules/SX127x/SX1278.cpp index fda1b3c2..4bcd3ee7 100644 --- a/src/modules/SX127x/SX1278.cpp +++ b/src/modules/SX127x/SX1278.cpp @@ -421,6 +421,39 @@ float SX1278::getRSSI(bool skipReceive) { } } +float SX1278::getInstRSSI(bool skipReceive) { + if(getActiveModem() == RADIOLIB_SX127X_LORA) { + // for LoRa, get current RSSI + float currentRSSI; + + // RSSI calculation uses different constant for low-frequency and high-frequency ports + if(_freq < 868.0) { + currentRSSI = -164 + _mod->SPIgetRegValue(RADIOLIB_SX127X_REG_RSSI_VALUE); + } else { + currentRSSI = -157 + _mod->SPIgetRegValue(RADIOLIB_SX127X_REG_RSSI_VALUE); + } + + return(currentRSSI); + + } else { + // enable listen mode + if(!skipReceive) { + startReceive(); + } + + // read the value for FSK + float rssi = (float)_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_RSSI_VALUE_FSK) / -2.0; + + // set mode back to standby + if(!skipReceive) { + standby(); + } + + // return the value + return(rssi); + } +} + int16_t SX1278::setCRC(bool enable, bool mode) { if(getActiveModem() == RADIOLIB_SX127X_LORA) { // set LoRa CRC diff --git a/src/modules/SX127x/SX1278.h b/src/modules/SX127x/SX1278.h index fd274572..51096cd5 100644 --- a/src/modules/SX127x/SX1278.h +++ b/src/modules/SX127x/SX1278.h @@ -257,6 +257,15 @@ class SX1278: public SX127x { */ float getRSSI(bool skipReceive = false); + /*! + \brief Gets current signal strength indicator of for LoRa modem, or current RSSI level for FSK modem. + + \param skipReceive Set to true to skip putting radio in receive mode for the RSSI measurement in FKS/OOK mode. + + \returns Current packet RSSI for LoRa modem, or FSK modem. + */ + float getInstRSSI(bool skipReceive = false); + /*! \brief Enables/disables CRC check of received packets.