]> git.tnoah.ca Git - lora-radio.git/commitdiff
Fixed RSSI indication
authorMark Qvist <mark@adepta.io>
Wed, 27 Jun 2018 12:08:16 +0000 (14:08 +0200)
committerMark Qvist <mark@adepta.io>
Wed, 27 Jun 2018 12:08:16 +0000 (14:08 +0200)
Config.h
Libraries/RNode.py
LoRa.cpp
LoRa.h
Utilities.cpp

index fdc89056d6f0d744ffa444d5790193de48c33aff..1bec50a0a9f5140782c568acc3ba1b908ff78b2e 100644 (file)
--- 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];
index 7a53da0acbfa60ed5bc05c92ab6027062c5c4dbb..01129adee923898ff053768161c7023a16063a11 100644 (file)
@@ -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):
index 1db2e9ba57ec2363aa54a9697ac98998a37f58f1..23c9aecd2bfba2705b93e83420c80579b1c9234b 100644 (file)
--- 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 25b24f2787904ba4e9ff0f0e1e98db779fb5244f..c65ce6411cb1d28cd0373ddbf590b5aebee5399a 100644 (file)
--- 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();
 
index 272282760ca2449084e9e6d729995f13e572ff89..9d58b5708271b50ea7514543c712b27c48a93bfa 100644 (file)
@@ -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);
 }