From 3cfbb0cf58c3e85ad3299f3f3a837c85eb70fb0e Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Fri, 12 Mar 2021 18:48:50 +0100 Subject: [PATCH] Added implicit header mode --- Config.h | 12 +++++++----- Framing.h | 1 + RNode_Firmware.ino | 26 ++++++++++++++++++++++---- Utilities.h | 17 ++++++++++++++++- 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/Config.h b/Config.h index 7ae3d00..179ead6 100644 --- a/Config.h +++ b/Config.h @@ -4,7 +4,7 @@ #define CONFIG_H #define MAJ_VERS 0x01 - #define MIN_VERS 0x10 + #define MIN_VERS 0x11 #define MCU_1284P 0x91 @@ -61,10 +61,12 @@ uint32_t lora_freq = 0; // Operational variables - bool radio_locked = true; - bool radio_online = false; - bool hw_ready = false; - bool promisc = false; + bool radio_locked = true; + bool radio_online = false; + bool hw_ready = false; + bool promisc = false; + bool implicit = false; + uint8_t implicit_l = 0; uint8_t op_mode = MODE_HOST; uint8_t model = 0x00; diff --git a/Framing.h b/Framing.h index 80ec1cd..7290167 100644 --- a/Framing.h +++ b/Framing.h @@ -16,6 +16,7 @@ #define CMD_RADIO_STATE 0x06 #define CMD_RADIO_LOCK 0x07 #define CMD_DETECT 0x08 + #define CMD_IMPLICIT 0x09 #define CMD_PROMISC 0x0E #define CMD_READY 0x0F diff --git a/RNode_Firmware.ino b/RNode_Firmware.ino index bca73d7..d7a562e 100644 --- a/RNode_Firmware.ino +++ b/RNode_Firmware.ino @@ -58,6 +58,14 @@ void setup() { validateStatus(); } +void lora_receive() { + if (!implicit) { + LoRa.receive(); + } else { + LoRa.receive(implicit_l); + } +} + bool startRadio() { update_radio_lock(); if (!radio_online) { @@ -80,7 +88,7 @@ bool startRadio() { LoRa.enableCrc(); LoRa.onReceive(receiveCallback); - LoRa.receive(); + lora_receive(); // Flash an info pattern to indicate // that the radio is now on @@ -275,7 +283,7 @@ void transmit(size_t size) { LoRa.endPacket(); led_tx_off(); - LoRa.receive(); + lora_receive(); } else { // In promiscuous mode, we only send out // plain raw LoRa packets with a maximum @@ -288,7 +296,14 @@ void transmit(size_t size) { size = SINGLE_MTU; } - LoRa.beginPacket(); + // If implicit header mode has been set, + // set packet length to payload data length + if (!implicit) { + LoRa.beginPacket(); + } else { + LoRa.beginPacket(size); + } + for (size_t i; i < size; i++) { LoRa.write(tbuf[i]); @@ -297,7 +312,7 @@ void transmit(size_t size) { LoRa.endPacket(); led_tx_off(); - LoRa.receive(); + lora_receive(); } } else { kiss_indicate_error(ERROR_TXFAILED); @@ -435,6 +450,9 @@ void serialCallback(uint8_t sbyte) { if (op_mode == MODE_HOST) setCodingRate(); kiss_indicate_codingrate(); } + } else if (command == CMD_IMPLICIT) { + set_implicit_length(sbyte); + kiss_indicate_implicit_length(); } else if (command == CMD_RADIO_STATE) { if (sbyte == 0xFF) { kiss_indicate_radiostate(); diff --git a/Utilities.h b/Utilities.h index 73edc79..5c52b53 100644 --- a/Utilities.h +++ b/Utilities.h @@ -167,6 +167,13 @@ void kiss_indicate_codingrate() { Serial.write(FEND); } +void kiss_indicate_implicit_length() { + Serial.write(FEND); + Serial.write(CMD_IMPLICIT); + Serial.write(implicit_l); + Serial.write(FEND); +} + void kiss_indicate_txpower() { Serial.write(FEND); Serial.write(CMD_TXPOWER); @@ -263,6 +270,15 @@ void setCodingRate() { if (radio_online) LoRa.setCodingRate4(lora_cr); } +void set_implicit_length(uint8_t len) { + implicit_l = len; + if (implicit_l != 0) { + implicit = true; + } else { + implicit = false; + } +} + void setTXPower() { if (radio_online) { if (model == MODEL_A4) LoRa.setTxPower(lora_txp, PA_OUTPUT_RFO_PIN); @@ -626,4 +642,3 @@ inline void fifo16_init(FIFOBuffer16 *f, size_t *buffer, size_t size) { inline size_t fifo16_len(FIFOBuffer16 *f) { return (f->end - f->begin); } -