From 968a2d7fbc906319111a4d5102e9f8b1f23edddb Mon Sep 17 00:00:00 2001 From: geeksville Date: Thu, 30 Apr 2020 19:58:10 -0700 Subject: [PATCH] store SNR in received packets --- src/rf95/RF95Interface.cpp | 8 ++++++++ src/rf95/RF95Interface.h | 4 ++++ src/rf95/RadioLibInterface.cpp | 3 ++- src/rf95/RadioLibInterface.h | 5 +++++ src/rf95/SX1262Interface.cpp | 7 +++++++ src/rf95/SX1262Interface.h | 5 ++++- 6 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/rf95/RF95Interface.cpp b/src/rf95/RF95Interface.cpp index fc0175af3..8076046ef 100644 --- a/src/rf95/RF95Interface.cpp +++ b/src/rf95/RF95Interface.cpp @@ -87,6 +87,14 @@ bool RF95Interface::reconfigure() return ERR_NONE; } +/** + * Add SNR data to received messages + */ +void RF95Interface::addReceiveMetadata(MeshPacket *mp) +{ + mp->rx_snr = lora->getSNR(); +} + void RF95Interface::setStandby() { int err = lora->standby(); diff --git a/src/rf95/RF95Interface.h b/src/rf95/RF95Interface.h index 01aae56af..187999f1c 100644 --- a/src/rf95/RF95Interface.h +++ b/src/rf95/RF95Interface.h @@ -45,6 +45,10 @@ class RF95Interface : public RadioLibInterface */ virtual void startReceive(); + /** + * Add SNR data to received messages + */ + virtual void addReceiveMetadata(MeshPacket *mp); private: void setStandby(); }; \ No newline at end of file diff --git a/src/rf95/RadioLibInterface.cpp b/src/rf95/RadioLibInterface.cpp index 655788a8b..6cfb54fee 100644 --- a/src/rf95/RadioLibInterface.cpp +++ b/src/rf95/RadioLibInterface.cpp @@ -185,6 +185,7 @@ void RadioLibInterface::handleReceiveInterrupt() mp->from = h->from; mp->to = h->to; mp->id = h->id; + addReceiveMetadata(mp); if (!pb_decode_from_bytes(payload, payloadLen, SubPacket_fields, p)) { DEBUG_MSG("Invalid protobufs in received mesh packet, discarding.\n"); @@ -193,7 +194,7 @@ void RadioLibInterface::handleReceiveInterrupt() } else { // parsing was successful, queue for our recipient mp->has_payload = true; - txGood++; + rxGood++; deliverToReceiver(mp); } diff --git a/src/rf95/RadioLibInterface.h b/src/rf95/RadioLibInterface.h index 653869e8c..a71a0a00e 100644 --- a/src/rf95/RadioLibInterface.h +++ b/src/rf95/RadioLibInterface.h @@ -116,4 +116,9 @@ class RadioLibInterface : public RadioInterface /** * If a send was in progress finish it and return the buffer to the pool */ void completeSending(); + + /** + * Add SNR data to received messages + */ + virtual void addReceiveMetadata(MeshPacket *mp) = 0; }; \ No newline at end of file diff --git a/src/rf95/SX1262Interface.cpp b/src/rf95/SX1262Interface.cpp index c4fa4d7bb..af3e4603b 100644 --- a/src/rf95/SX1262Interface.cpp +++ b/src/rf95/SX1262Interface.cpp @@ -79,6 +79,13 @@ void SX1262Interface::setStandby() disableInterrupt(); } +/** + * Add SNR data to received messages + */ +void SX1262Interface::addReceiveMetadata(MeshPacket *mp) { + mp->rx_snr = lora.getSNR(); +} + void SX1262Interface::startReceive() { setStandby(); diff --git a/src/rf95/SX1262Interface.h b/src/rf95/SX1262Interface.h index 88a251879..39c6e7c09 100644 --- a/src/rf95/SX1262Interface.h +++ b/src/rf95/SX1262Interface.h @@ -43,7 +43,10 @@ class SX1262Interface : public RadioLibInterface * Start waiting to receive a message */ virtual void startReceive(); - + /** + * Add SNR data to received messages + */ + virtual void addReceiveMetadata(MeshPacket *mp); private: void setStandby(); }; \ No newline at end of file