From a0f2aaf1131be6adc3145c9f4475259776eab31f Mon Sep 17 00:00:00 2001 From: Felix Rusu Date: Wed, 6 Nov 2013 23:15:51 -0500 Subject: [PATCH] Add reception RSSI (more accurate) --- Examples/Gateway/Gateway.ino | 2 +- Examples/Node/Node.ino | 2 +- RFM69.cpp | 3 +++ RFM69.h | 3 ++- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Examples/Gateway/Gateway.ino b/Examples/Gateway/Gateway.ino index 4913c55..df70e7b 100644 --- a/Examples/Gateway/Gateway.ino +++ b/Examples/Gateway/Gateway.ino @@ -107,7 +107,7 @@ void loop() { } for (byte i = 0; i < radio.DATALEN; i++) Serial.print((char)radio.DATA[i]); - Serial.print(" [RX_RSSI:");Serial.print(radio.readRSSI());Serial.print("]"); + Serial.print(" [RX_RSSI:");Serial.print(radio.RSSI);Serial.print("]"); if (radio.ACK_REQUESTED) { diff --git a/Examples/Node/Node.ino b/Examples/Node/Node.ino index 39d9903..4d22798 100644 --- a/Examples/Node/Node.ino +++ b/Examples/Node/Node.ino @@ -101,7 +101,7 @@ void loop() { Serial.print('[');Serial.print(radio.SENDERID, DEC);Serial.print("] "); for (byte i = 0; i < radio.DATALEN; i++) Serial.print((char)radio.DATA[i]); - Serial.print(" [RX_RSSI:");Serial.print(radio.readRSSI());Serial.print("]"); + Serial.print(" [RX_RSSI:");Serial.print(radio.RSSI);Serial.print("]"); if (radio.ACK_REQUESTED) { diff --git a/RFM69.cpp b/RFM69.cpp index 8710923..c5ca36c 100644 --- a/RFM69.cpp +++ b/RFM69.cpp @@ -18,6 +18,7 @@ volatile byte RFM69::TARGETID; //should match _address volatile byte RFM69::PAYLOADLEN; volatile byte RFM69::ACK_REQUESTED; volatile byte RFM69::ACK_RECEIVED; /// Should be polled immediately after sending a packet with ACK request +volatile int RFM69::RSSI; //most accurate RSSI during reception (closest to the reception) RFM69* RFM69::selfPointer; bool RFM69::initialize(byte freqBand, byte nodeID, byte networkID) @@ -259,6 +260,7 @@ void RFM69::interruptHandler() { unselect(); setMode(RF69_MODE_RX); } + RSSI = readRSSI(); //digitalWrite(4, 0); } @@ -271,6 +273,7 @@ void RFM69::receiveBegin() { PAYLOADLEN = 0; ACK_REQUESTED = 0; ACK_RECEIVED = 0; + RSSI = 0; if (readReg(REG_IRQFLAGS2) & RF_IRQFLAGS2_PAYLOADREADY) writeReg(REG_PACKETCONFIG2, (readReg(REG_PACKETCONFIG2) & 0xFB) | RF_PACKET2_RXRESTART); // avoid RX deadlocks writeReg(REG_DIOMAPPING1, RF_DIOMAPPING1_DIO0_01); //set DIO0 to "PAYLOADREADY" in receive mode diff --git a/RFM69.h b/RFM69.h index d1d643e..10fea00 100644 --- a/RFM69.h +++ b/RFM69.h @@ -2,7 +2,7 @@ // Driver definition for HopeRF RFM69W/RFM69HW, Semtech SX1231/1231H // ********************************************************************************** // Creative Commons Attrib Share-Alike License -// You are free to use/extend this library but please abide with the CCSA license: +// You are free to use/extend this library but please abide with the CC-BY-SA license: // http://creativecommons.org/licenses/by-sa/3.0/ // 2013-06-14 (C) felix@lowpowerlab.com // ********************************************************************************** @@ -39,6 +39,7 @@ class RFM69 { static volatile byte PAYLOADLEN; static volatile byte ACK_REQUESTED; static volatile byte ACK_RECEIVED; /// Should be polled immediately after sending a packet with ACK request + static volatile int RSSI; //most accurate RSSI during reception (closest to the reception) static volatile byte _mode; //should be protected? RFM69(byte slaveSelectPin=SPI_CS, byte interruptPin=RF69_IRQ_PIN, bool isRFM69HW=false) {