From 8068bcc3567350a736af32a5efddd86c69d5e99f Mon Sep 17 00:00:00 2001 From: Egor Shitikov <egorshitikov@gmail.com> Date: Thu, 19 Sep 2024 13:02:07 -0700 Subject: [PATCH] [SX128x] getRssi(false) without packet (#1222) * Update SX128x.h * Update SX128x.cpp --- src/modules/SX128x/SX128x.cpp | 11 +++++++++++ src/modules/SX128x/SX128x.h | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/src/modules/SX128x/SX128x.cpp b/src/modules/SX128x/SX128x.cpp index 8fc395bf..d8488f1c 100644 --- a/src/modules/SX128x/SX128x.cpp +++ b/src/modules/SX128x/SX128x.cpp @@ -1253,6 +1253,17 @@ float SX128x::getRSSI() { } } +float SX128x::getRSSI(bool packet) { + if (!packet) { + // get instantaneous RSSI value + uint8_t data[3] = {0, 0, 0}; // RssiInst, Status, RFU + this->mod->SPIreadStream(RADIOLIB_SX128X_CMD_GET_RSSI_INST, data, 3); + return ((float)data[0] / (-2.0)); + } else { + return this->getRSSI(); + } +} + float SX128x::getSNR() { // check active modem uint8_t modem = getPacketType(); diff --git a/src/modules/SX128x/SX128x.h b/src/modules/SX128x/SX128x.h index eab6eafc..cea6b7ad 100644 --- a/src/modules/SX128x/SX128x.h +++ b/src/modules/SX128x/SX128x.h @@ -761,6 +761,13 @@ class SX128x: public PhysicalLayer { */ float getRSSI() override; + /*! + \brief Gets RSSI (Recorded Signal Strength Indicator). + \param packet Whether to read last packet RSSI, or the current value. + \returns RSSI value in dBm. + */ + float getRSSI(bool packet); + /*! \brief Gets SNR (Signal to Noise Ratio) of the last received packet. Only available for LoRa or ranging modem. \returns SNR of the last received packet in dB.