mirror of
https://github.com/liberatedsystems/RNode_Firmware_CE.git
synced 2024-12-28 08:59:32 -05:00
Fixed RSSI indication confusion. Added SNR indication to received packets.
This commit is contained in:
parent
cd4587cca2
commit
bad6f4bf75
10
Config.h
10
Config.h
@ -4,7 +4,7 @@
|
||||
#define CONFIG_H
|
||||
|
||||
#define MAJ_VERS 0x01
|
||||
#define MIN_VERS 0x0A
|
||||
#define MIN_VERS 0x0B
|
||||
|
||||
#define MCU_328P 0x90
|
||||
#define MCU_1284P 0x91
|
||||
@ -62,10 +62,13 @@
|
||||
|
||||
// MCU independent configuration parameters
|
||||
const long serial_baudrate = 115200;
|
||||
const int rssi_offset = 292;
|
||||
|
||||
const int lora_rx_turnaround_ms = 50;
|
||||
|
||||
// SX1276 RSSI offset to get dBm value from
|
||||
// packet RSSI register
|
||||
const int rssi_offset = 157;
|
||||
const int snr_offset = 128;
|
||||
|
||||
// Default LoRa settings
|
||||
int lora_sf = 0;
|
||||
int lora_cr = 5;
|
||||
@ -85,6 +88,7 @@
|
||||
|
||||
int last_rssi = -292;
|
||||
uint8_t last_rssi_raw = 0x00;
|
||||
int8_t last_snr = 0;
|
||||
size_t read_len = 0;
|
||||
uint8_t seq = 0xFF;
|
||||
uint8_t pbuf[MTU];
|
||||
|
@ -22,6 +22,7 @@
|
||||
#define CMD_STAT_RX 0x21
|
||||
#define CMD_STAT_TX 0x22
|
||||
#define CMD_STAT_RSSI 0x23
|
||||
#define CMD_STAT_SNR 0x24
|
||||
#define CMD_BLINK 0x30
|
||||
#define CMD_RANDOM 0x40
|
||||
|
||||
|
@ -12,6 +12,8 @@ serialPort = "/dev/ttyUSB0"
|
||||
# packet is received
|
||||
def gotPacket(data, rnode):
|
||||
print "Received a packet: "+data
|
||||
print "RSSI: "+str(rnode.r_stat_rssi)+" dBm"
|
||||
print "SNR: "+str(rnode.r_stat_snr)+" dBm"
|
||||
|
||||
# Create an RNode instance. This configures
|
||||
# and powers up the radio.
|
||||
|
@ -27,6 +27,7 @@ class KISS():
|
||||
CMD_STAT_RX = chr(0x21)
|
||||
CMD_STAT_TX = chr(0x22)
|
||||
CMD_STAT_RSSI = chr(0x23)
|
||||
CMD_STAT_SNR = chr(0x24)
|
||||
CMD_BLINK = chr(0x30)
|
||||
CMD_RANDOM = chr(0x40)
|
||||
CMD_FW_VERSION = chr(0x50)
|
||||
@ -66,7 +67,8 @@ class RNodeInterface():
|
||||
LOG_DEBUG = 6
|
||||
LOG_EXTREME = 7
|
||||
|
||||
RSSI_OFFSET = 292
|
||||
RSSI_OFFSET = 157
|
||||
SNR_OFFSET = 128
|
||||
|
||||
def __init__(self, callback, name, port, frequency = None, bandwidth = None, txpower = None, sf = None, cr = None, loglevel = -1, flow_control = True):
|
||||
self.serial = None
|
||||
@ -99,6 +101,7 @@ class RNodeInterface():
|
||||
self.r_stat_rx = None
|
||||
self.r_stat_tx = None
|
||||
self.r_stat_rssi = None
|
||||
self.r_stat_snr = None
|
||||
self.r_random = None
|
||||
|
||||
self.packet_queue = []
|
||||
@ -310,6 +313,7 @@ class RNodeInterface():
|
||||
while self.serial.is_open:
|
||||
if self.serial.in_waiting:
|
||||
byte = self.serial.read(1)
|
||||
|
||||
last_read_ms = int(time.time()*1000)
|
||||
|
||||
if (in_frame and byte == KISS.FEND and command == KISS.CMD_DATA):
|
||||
@ -412,7 +416,29 @@ 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.RSSI_OFFSET
|
||||
if (byte == KISS.FESC):
|
||||
escape = True
|
||||
else:
|
||||
if (escape):
|
||||
if (byte == KISS.TFEND):
|
||||
byte = KISS.FEND
|
||||
if (byte == KISS.TFESC):
|
||||
byte = KISS.FESC
|
||||
escape = False
|
||||
self.r_stat_rssi = ord(byte)-self.RSSI_OFFSET
|
||||
|
||||
elif (command == KISS.CMD_STAT_SNR):
|
||||
if (byte == KISS.FESC):
|
||||
escape = True
|
||||
else:
|
||||
if (escape):
|
||||
if (byte == KISS.TFEND):
|
||||
byte = KISS.FEND
|
||||
if (byte == KISS.TFESC):
|
||||
byte = KISS.FESC
|
||||
escape = False
|
||||
self.r_stat_snr = ord(byte)-self.SNR_OFFSET
|
||||
|
||||
elif (command == KISS.CMD_RANDOM):
|
||||
self.r_random = ord(byte)
|
||||
elif (command == KISS.CMD_ERROR):
|
||||
|
15
LoRa.cpp
15
LoRa.cpp
@ -218,10 +218,19 @@ uint8_t LoRaClass::packetRssiRaw() {
|
||||
}
|
||||
|
||||
int LoRaClass::packetRssi() {
|
||||
int pkt_rssi = (int)readRegister(REG_PKT_RSSI_VALUE);
|
||||
// TODO: change this to look at the actual model code
|
||||
int pkt_rssi = (int)readRegister(REG_PKT_RSSI_VALUE) - RSSI_OFFSET;
|
||||
int pkt_snr = packetSnr();
|
||||
|
||||
if (_frequency < 820E6) pkt_rssi -= 7;
|
||||
pkt_rssi -= 157;
|
||||
|
||||
if (pkt_snr < 0) {
|
||||
pkt_rssi += pkt_snr;
|
||||
} else {
|
||||
// Slope correction is (16/15)*pkt_rssi,
|
||||
// this estimation looses one floating point
|
||||
// operation, and should be precise enough.
|
||||
pkt_rssi = (int)(1.066 * pkt_rssi);
|
||||
}
|
||||
|
||||
return pkt_rssi;
|
||||
}
|
||||
|
2
LoRa.h
2
LoRa.h
@ -14,6 +14,8 @@
|
||||
#define PA_OUTPUT_RFO_PIN 0
|
||||
#define PA_OUTPUT_PA_BOOST_PIN 1
|
||||
|
||||
#define RSSI_OFFSET 157
|
||||
|
||||
class LoRaClass : public Stream {
|
||||
public:
|
||||
LoRaClass();
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -104,12 +104,14 @@ void receiveCallback(int packet_size) {
|
||||
read_len = 0;
|
||||
seq = sequence;
|
||||
last_rssi = LoRa.packetRssi();
|
||||
last_snr = LoRa.packetSnr();
|
||||
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;
|
||||
getPacketData(packet_size);
|
||||
seq = SEQ_UNSET;
|
||||
ready = true;
|
||||
@ -121,6 +123,7 @@ void receiveCallback(int packet_size) {
|
||||
read_len = 0;
|
||||
seq = sequence;
|
||||
last_rssi = LoRa.packetRssi();
|
||||
last_snr = LoRa.packetSnr();
|
||||
getPacketData(packet_size);
|
||||
} else if (!isSplitPacket(header)) {
|
||||
// This is not a split packet, so we
|
||||
@ -135,6 +138,7 @@ void receiveCallback(int packet_size) {
|
||||
}
|
||||
|
||||
last_rssi = LoRa.packetRssi();
|
||||
last_snr = LoRa.packetSnr();
|
||||
getPacketData(packet_size);
|
||||
ready = true;
|
||||
}
|
||||
@ -142,10 +146,8 @@ void receiveCallback(int packet_size) {
|
||||
if (ready) {
|
||||
// We first signal the RSSI of the
|
||||
// recieved packet to the host.
|
||||
Serial.write(FEND);
|
||||
Serial.write(CMD_STAT_RSSI);
|
||||
Serial.write((uint8_t)(last_rssi-rssi_offset));
|
||||
Serial.write(FEND);
|
||||
kiss_indicate_stat_rssi();
|
||||
kiss_indicate_stat_snr();
|
||||
|
||||
// And then write the entire packet
|
||||
Serial.write(FEND);
|
||||
@ -168,10 +170,8 @@ void receiveCallback(int packet_size) {
|
||||
|
||||
// We first signal the RSSI of the
|
||||
// recieved packet to the host.
|
||||
Serial.write(FEND);
|
||||
Serial.write(CMD_STAT_RSSI);
|
||||
Serial.write((uint8_t)(last_rssi-rssi_offset));
|
||||
Serial.write(FEND);
|
||||
kiss_indicate_stat_rssi();
|
||||
kiss_indicate_stat_snr();
|
||||
|
||||
// And then write the entire packet
|
||||
Serial.write(FEND);
|
||||
|
10
Utilities.h
10
Utilities.h
@ -133,7 +133,15 @@ 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(packet_rssi_val);
|
||||
escapedSerialWrite(packet_rssi_val);
|
||||
Serial.write(FEND);
|
||||
}
|
||||
|
||||
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);
|
||||
Serial.write(FEND);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user