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 CONFIG_H
|
||||||
|
|
||||||
#define MAJ_VERS 0x01
|
#define MAJ_VERS 0x01
|
||||||
#define MIN_VERS 0x0A
|
#define MIN_VERS 0x0B
|
||||||
|
|
||||||
#define MCU_328P 0x90
|
#define MCU_328P 0x90
|
||||||
#define MCU_1284P 0x91
|
#define MCU_1284P 0x91
|
||||||
|
@ -62,10 +62,13 @@
|
||||||
|
|
||||||
// MCU independent configuration parameters
|
// MCU independent configuration parameters
|
||||||
const long serial_baudrate = 115200;
|
const long serial_baudrate = 115200;
|
||||||
const int rssi_offset = 292;
|
|
||||||
|
|
||||||
const int lora_rx_turnaround_ms = 50;
|
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
|
// Default LoRa settings
|
||||||
int lora_sf = 0;
|
int lora_sf = 0;
|
||||||
int lora_cr = 5;
|
int lora_cr = 5;
|
||||||
|
@ -85,6 +88,7 @@
|
||||||
|
|
||||||
int last_rssi = -292;
|
int last_rssi = -292;
|
||||||
uint8_t last_rssi_raw = 0x00;
|
uint8_t last_rssi_raw = 0x00;
|
||||||
|
int8_t last_snr = 0;
|
||||||
size_t read_len = 0;
|
size_t read_len = 0;
|
||||||
uint8_t seq = 0xFF;
|
uint8_t seq = 0xFF;
|
||||||
uint8_t pbuf[MTU];
|
uint8_t pbuf[MTU];
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#define CMD_STAT_RX 0x21
|
#define CMD_STAT_RX 0x21
|
||||||
#define CMD_STAT_TX 0x22
|
#define CMD_STAT_TX 0x22
|
||||||
#define CMD_STAT_RSSI 0x23
|
#define CMD_STAT_RSSI 0x23
|
||||||
|
#define CMD_STAT_SNR 0x24
|
||||||
#define CMD_BLINK 0x30
|
#define CMD_BLINK 0x30
|
||||||
#define CMD_RANDOM 0x40
|
#define CMD_RANDOM 0x40
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@ serialPort = "/dev/ttyUSB0"
|
||||||
# packet is received
|
# packet is received
|
||||||
def gotPacket(data, rnode):
|
def gotPacket(data, rnode):
|
||||||
print "Received a packet: "+data
|
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
|
# Create an RNode instance. This configures
|
||||||
# and powers up the radio.
|
# and powers up the radio.
|
||||||
|
|
|
@ -27,6 +27,7 @@ class KISS():
|
||||||
CMD_STAT_RX = chr(0x21)
|
CMD_STAT_RX = chr(0x21)
|
||||||
CMD_STAT_TX = chr(0x22)
|
CMD_STAT_TX = chr(0x22)
|
||||||
CMD_STAT_RSSI = chr(0x23)
|
CMD_STAT_RSSI = chr(0x23)
|
||||||
|
CMD_STAT_SNR = chr(0x24)
|
||||||
CMD_BLINK = chr(0x30)
|
CMD_BLINK = chr(0x30)
|
||||||
CMD_RANDOM = chr(0x40)
|
CMD_RANDOM = chr(0x40)
|
||||||
CMD_FW_VERSION = chr(0x50)
|
CMD_FW_VERSION = chr(0x50)
|
||||||
|
@ -66,7 +67,8 @@ class RNodeInterface():
|
||||||
LOG_DEBUG = 6
|
LOG_DEBUG = 6
|
||||||
LOG_EXTREME = 7
|
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):
|
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.serial = None
|
||||||
|
@ -99,6 +101,7 @@ class RNodeInterface():
|
||||||
self.r_stat_rx = None
|
self.r_stat_rx = None
|
||||||
self.r_stat_tx = None
|
self.r_stat_tx = None
|
||||||
self.r_stat_rssi = None
|
self.r_stat_rssi = None
|
||||||
|
self.r_stat_snr = None
|
||||||
self.r_random = None
|
self.r_random = None
|
||||||
|
|
||||||
self.packet_queue = []
|
self.packet_queue = []
|
||||||
|
@ -310,6 +313,7 @@ class RNodeInterface():
|
||||||
while self.serial.is_open:
|
while self.serial.is_open:
|
||||||
if self.serial.in_waiting:
|
if self.serial.in_waiting:
|
||||||
byte = self.serial.read(1)
|
byte = self.serial.read(1)
|
||||||
|
|
||||||
last_read_ms = int(time.time()*1000)
|
last_read_ms = int(time.time()*1000)
|
||||||
|
|
||||||
if (in_frame and byte == KISS.FEND and command == KISS.CMD_DATA):
|
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])
|
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):
|
elif (command == KISS.CMD_STAT_RSSI):
|
||||||
|
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
|
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):
|
elif (command == KISS.CMD_RANDOM):
|
||||||
self.r_random = ord(byte)
|
self.r_random = ord(byte)
|
||||||
elif (command == KISS.CMD_ERROR):
|
elif (command == KISS.CMD_ERROR):
|
||||||
|
|
15
LoRa.cpp
15
LoRa.cpp
|
@ -218,10 +218,19 @@ uint8_t LoRaClass::packetRssiRaw() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int LoRaClass::packetRssi() {
|
int LoRaClass::packetRssi() {
|
||||||
int pkt_rssi = (int)readRegister(REG_PKT_RSSI_VALUE);
|
int pkt_rssi = (int)readRegister(REG_PKT_RSSI_VALUE) - RSSI_OFFSET;
|
||||||
// TODO: change this to look at the actual model code
|
int pkt_snr = packetSnr();
|
||||||
|
|
||||||
if (_frequency < 820E6) pkt_rssi -= 7;
|
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;
|
return pkt_rssi;
|
||||||
}
|
}
|
||||||
|
|
2
LoRa.h
2
LoRa.h
|
@ -14,6 +14,8 @@
|
||||||
#define PA_OUTPUT_RFO_PIN 0
|
#define PA_OUTPUT_RFO_PIN 0
|
||||||
#define PA_OUTPUT_PA_BOOST_PIN 1
|
#define PA_OUTPUT_PA_BOOST_PIN 1
|
||||||
|
|
||||||
|
#define RSSI_OFFSET 157
|
||||||
|
|
||||||
class LoRaClass : public Stream {
|
class LoRaClass : public Stream {
|
||||||
public:
|
public:
|
||||||
LoRaClass();
|
LoRaClass();
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -104,12 +104,14 @@ void receiveCallback(int packet_size) {
|
||||||
read_len = 0;
|
read_len = 0;
|
||||||
seq = sequence;
|
seq = sequence;
|
||||||
last_rssi = LoRa.packetRssi();
|
last_rssi = LoRa.packetRssi();
|
||||||
|
last_snr = LoRa.packetSnr();
|
||||||
getPacketData(packet_size);
|
getPacketData(packet_size);
|
||||||
} else if (isSplitPacket(header) && seq == sequence) {
|
} else if (isSplitPacket(header) && seq == sequence) {
|
||||||
// This is the second part of a split
|
// This is the second part of a split
|
||||||
// packet, so we add it to the buffer
|
// packet, so we add it to the buffer
|
||||||
// and set the ready flag.
|
// and set the ready flag.
|
||||||
last_rssi = (last_rssi+LoRa.packetRssi())/2;
|
last_rssi = (last_rssi+LoRa.packetRssi())/2;
|
||||||
|
last_snr = (last_snr+LoRa.packetSnr())/2;
|
||||||
getPacketData(packet_size);
|
getPacketData(packet_size);
|
||||||
seq = SEQ_UNSET;
|
seq = SEQ_UNSET;
|
||||||
ready = true;
|
ready = true;
|
||||||
|
@ -121,6 +123,7 @@ void receiveCallback(int packet_size) {
|
||||||
read_len = 0;
|
read_len = 0;
|
||||||
seq = sequence;
|
seq = sequence;
|
||||||
last_rssi = LoRa.packetRssi();
|
last_rssi = LoRa.packetRssi();
|
||||||
|
last_snr = LoRa.packetSnr();
|
||||||
getPacketData(packet_size);
|
getPacketData(packet_size);
|
||||||
} else if (!isSplitPacket(header)) {
|
} else if (!isSplitPacket(header)) {
|
||||||
// This is not a split packet, so we
|
// This is not a split packet, so we
|
||||||
|
@ -135,6 +138,7 @@ void receiveCallback(int packet_size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
last_rssi = LoRa.packetRssi();
|
last_rssi = LoRa.packetRssi();
|
||||||
|
last_snr = LoRa.packetSnr();
|
||||||
getPacketData(packet_size);
|
getPacketData(packet_size);
|
||||||
ready = true;
|
ready = true;
|
||||||
}
|
}
|
||||||
|
@ -142,10 +146,8 @@ void receiveCallback(int packet_size) {
|
||||||
if (ready) {
|
if (ready) {
|
||||||
// We first signal the RSSI of the
|
// We first signal the RSSI of the
|
||||||
// recieved packet to the host.
|
// recieved packet to the host.
|
||||||
Serial.write(FEND);
|
kiss_indicate_stat_rssi();
|
||||||
Serial.write(CMD_STAT_RSSI);
|
kiss_indicate_stat_snr();
|
||||||
Serial.write((uint8_t)(last_rssi-rssi_offset));
|
|
||||||
Serial.write(FEND);
|
|
||||||
|
|
||||||
// And then write the entire packet
|
// And then write the entire packet
|
||||||
Serial.write(FEND);
|
Serial.write(FEND);
|
||||||
|
@ -168,10 +170,8 @@ void receiveCallback(int packet_size) {
|
||||||
|
|
||||||
// We first signal the RSSI of the
|
// We first signal the RSSI of the
|
||||||
// recieved packet to the host.
|
// recieved packet to the host.
|
||||||
Serial.write(FEND);
|
kiss_indicate_stat_rssi();
|
||||||
Serial.write(CMD_STAT_RSSI);
|
kiss_indicate_stat_snr();
|
||||||
Serial.write((uint8_t)(last_rssi-rssi_offset));
|
|
||||||
Serial.write(FEND);
|
|
||||||
|
|
||||||
// And then write the entire packet
|
// And then write the entire packet
|
||||||
Serial.write(FEND);
|
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);
|
uint8_t packet_rssi_val = (uint8_t)(last_rssi+rssi_offset);
|
||||||
Serial.write(FEND);
|
Serial.write(FEND);
|
||||||
Serial.write(CMD_STAT_RSSI);
|
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);
|
Serial.write(FEND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue