From beb17d0922dcc0285c51dc4a032d7e393d496ed6 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Wed, 27 Jun 2018 14:08:16 +0200 Subject: [PATCH] Fixed RSSI indication --- Config.h | 7 ++++--- Libraries/RNode.py | 4 +++- LoRa.cpp | 15 ++++++++++++--- LoRa.h | 1 + Utilities.cpp | 3 ++- 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/Config.h b/Config.h index fdc8905..1bec50a 100644 --- a/Config.h +++ b/Config.h @@ -4,7 +4,7 @@ #define CONFIG_H #define MAJ_VERS 0x01 - #define MIN_VERS 0x05 + #define MIN_VERS 0x06 #define MCU_328P 0x90 #define MCU_1284P 0x91 @@ -62,7 +62,7 @@ // MCU independent configuration parameters const long serial_baudrate = 115200; - const int rssi_offset = 164; + const int rssi_offset = 292; const int lora_rx_turnaround_ms = 50; @@ -83,7 +83,8 @@ uint8_t model = 0x00; uint8_t hwrev = 0x00; - int last_rssi = -164; + int last_rssi = -292; + uint8_t last_rssi_raw = 0x00; size_t read_len = 0; uint8_t seq = 0xFF; uint8_t pbuf[MTU]; diff --git a/Libraries/RNode.py b/Libraries/RNode.py index 7a53da0..01129ad 100644 --- a/Libraries/RNode.py +++ b/Libraries/RNode.py @@ -66,6 +66,8 @@ class RNodeInterface(): LOG_DEBUG = 6 LOG_EXTREME = 7 + RSSI_OFFSET = 292 + def __init__(self, callback, name, port, frequency = None, bandwidth = None, txpower = None, sf = None, cr = None, loglevel = -1, flow_control = True): self.serial = None self.loglevel = loglevel @@ -410,7 +412,7 @@ class RNodeInterface(): self.r_stat_tx = ord(command_buffer[0]) << 24 | ord(command_buffer[1]) << 16 | ord(command_buffer[2]) << 8 | ord(command_buffer[3]) elif (command == KISS.CMD_STAT_RSSI): - self.r_stat_rssi = ord(byte) + self.r_stat_rssi = ord(byte)-RSSI_OFFSET elif (command == KISS.CMD_RANDOM): self.r_random = ord(byte) elif (command == KISS.CMD_ERROR): diff --git a/LoRa.cpp b/LoRa.cpp index 1db2e9b..23c9aec 100644 --- a/LoRa.cpp +++ b/LoRa.cpp @@ -212,9 +212,18 @@ uint8_t LoRaClass::modemStatus() { return readRegister(REG_MODEM_STAT); } -int LoRaClass::packetRssi() -{ - return (readRegister(REG_PKT_RSSI_VALUE) - (_frequency < 868E6 ? 164 : 157)); +uint8_t LoRaClass::packetRssiRaw() { + uint8_t pkt_rssi_value = readRegister(REG_PKT_RSSI_VALUE); + return pkt_rssi_value; +} + +int LoRaClass::packetRssi() { + int pkt_rssi = (int)readRegister(REG_PKT_RSSI_VALUE); + // TODO: change this to look at the actual model code + if (_frequency < 820E6) pkt_rssi -= 7; + pkt_rssi -= 157; + + return pkt_rssi; } float LoRaClass::packetSnr() diff --git a/LoRa.h b/LoRa.h index 25b24f2..c65ce64 100644 --- a/LoRa.h +++ b/LoRa.h @@ -26,6 +26,7 @@ public: int parsePacket(int size = 0); int packetRssi(); + uint8_t packetRssiRaw(); float packetSnr(); long packetFrequencyError(); diff --git a/Utilities.cpp b/Utilities.cpp index 2722827..9d58b57 100644 --- a/Utilities.cpp +++ b/Utilities.cpp @@ -131,9 +131,10 @@ void kiss_indicate_stat_tx() { } void kiss_indicate_stat_rssi() { + uint8_t packet_rssi_val = (uint8_t)(last_rssi+rssi_offset); Serial.write(FEND); Serial.write(CMD_STAT_RSSI); - Serial.write((uint8_t)last_rssi+rssi_offset); + Serial.write(packet_rssi_val); Serial.write(FEND); }