diff --git a/Config.h b/Config.h index 13b0b91..3d76536 100644 --- a/Config.h +++ b/Config.h @@ -4,7 +4,7 @@ #define CONFIG_H #define MAJ_VERS 0x01 - #define MIN_VERS 0x0C + #define MIN_VERS 0x0D #define MCU_328P 0x90 #define MCU_1284P 0x91 @@ -88,7 +88,7 @@ int last_rssi = -292; uint8_t last_rssi_raw = 0x00; - int8_t last_snr = 0; + uint8_t last_snr_raw = 0x00; size_t read_len = 0; uint8_t seq = 0xFF; uint8_t pbuf[MTU]; diff --git a/LoRa.cpp b/LoRa.cpp index 37d63f8..8243ecb 100644 --- a/LoRa.cpp +++ b/LoRa.cpp @@ -235,8 +235,11 @@ int LoRaClass::packetRssi() { return pkt_rssi; } -float LoRaClass::packetSnr() -{ +uint8_t LoRaClass::packetSnrRaw() { + return readRegister(REG_PKT_SNR_VALUE); +} + +float LoRaClass::packetSnr() { return ((int8_t)readRegister(REG_PKT_SNR_VALUE)) * 0.25; } diff --git a/LoRa.h b/LoRa.h index 4027bdf..09bdc54 100644 --- a/LoRa.h +++ b/LoRa.h @@ -1,5 +1,8 @@ // Copyright (c) Sandeep Mistry. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// Licensed under the MIT license. + +// Modifications and additions copyright 2018 by Mark Qvist +// Obviously still under the MIT license. #ifndef LORA_H #define LORA_H @@ -29,6 +32,7 @@ public: int parsePacket(int size = 0); int packetRssi(); uint8_t packetRssiRaw(); + uint8_t packetSnrRaw(); float packetSnr(); long packetFrequencyError(); diff --git a/RNode_Firmware.ino b/RNode_Firmware.ino index f1d5280..b961f11 100644 --- a/RNode_Firmware.ino +++ b/RNode_Firmware.ino @@ -104,14 +104,14 @@ void receiveCallback(int packet_size) { read_len = 0; seq = sequence; last_rssi = LoRa.packetRssi(); - last_snr = LoRa.packetSnr(); + last_snr_raw = LoRa.packetSnrRaw(); getPacketData(packet_size); } else if (isSplitPacket(header) && seq == sequence) { // This is the second part of a split // packet, so we add it to the buffer // and set the ready flag. last_rssi = (last_rssi+LoRa.packetRssi())/2; - last_snr = (last_snr+LoRa.packetSnr())/2; + last_snr_raw = (last_snr_raw+LoRa.packetSnrRaw())/2; getPacketData(packet_size); seq = SEQ_UNSET; ready = true; @@ -123,7 +123,7 @@ void receiveCallback(int packet_size) { read_len = 0; seq = sequence; last_rssi = LoRa.packetRssi(); - last_snr = LoRa.packetSnr(); + last_snr_raw = LoRa.packetSnrRaw(); getPacketData(packet_size); } else if (!isSplitPacket(header)) { // This is not a split packet, so we @@ -138,7 +138,7 @@ void receiveCallback(int packet_size) { } last_rssi = LoRa.packetRssi(); - last_snr = LoRa.packetSnr(); + last_snr_raw = LoRa.packetSnrRaw(); getPacketData(packet_size); ready = true; } @@ -166,6 +166,7 @@ void receiveCallback(int packet_size) { // output directly over to the host read_len = 0; last_rssi = LoRa.packetRssi(); + last_snr_raw = LoRa.packetSnrRaw(); getPacketData(packet_size); // We first signal the RSSI of the diff --git a/Utilities.h b/Utilities.h index 26c2255..2753fad 100644 --- a/Utilities.h +++ b/Utilities.h @@ -138,10 +138,9 @@ void kiss_indicate_stat_rssi() { } void kiss_indicate_stat_snr() { - uint8_t packet_snr_val = (uint8_t)(last_snr+snr_offset); Serial.write(FEND); Serial.write(CMD_STAT_SNR); - escapedSerialWrite(packet_snr_val); + escapedSerialWrite(last_snr_raw); Serial.write(FEND); }