]> git.tnoah.ca Git - lora-radio.git/commitdiff
Added KISS flow control
authorMark Qvist <mark@adepta.io>
Thu, 26 Apr 2018 08:34:39 +0000 (10:34 +0200)
committerMark Qvist <mark@adepta.io>
Thu, 26 Apr 2018 08:34:39 +0000 (10:34 +0200)
Config.h
Framing.h
RNode_Firmware.ino
Utilities.cpp

index a7e02e000a9519805ca1498bc6be22a441168090..812a319b0b5fa877f5dbe502b263e802f8a2ca2e 100644 (file)
--- a/Config.h
+++ b/Config.h
@@ -26,6 +26,9 @@
                const int pin_dio = 2;
                const int pin_led_rx = 5;
                const int pin_led_tx = 4;
+
+               #define FLOW_CONTROL_ENABLED true
+               #define QUEUE_SIZE 0
        #endif
 
        #if MCU_VARIANT == MCU_1284P
@@ -34,6 +37,9 @@
                const int pin_dio = 2;
                const int pin_led_rx = 12;
                const int pin_led_tx = 13;
+
+               #define FLOW_CONTROL_ENABLED true
+               #define QUEUE_SIZE 24
        #endif
 
        // MCU independent configuration parameters
@@ -42,6 +48,7 @@
 
        // Default LoRa settings
        int  lora_sf   = 0;
+       int  lora_cr   = 5;
        int  lora_txp  = 0xFF;
        uint32_t lora_bw   = 0;
        uint32_t lora_freq = 0;
index 4c0efe422aeabc3d74df7f84e3f6db88d0daadc7..6b00cc42ee3894fd063b04c6df3b91f64cb78914 100644 (file)
--- a/Framing.h
+++ b/Framing.h
@@ -14,6 +14,7 @@
        #define CMD_SF                  0x04
        #define CMD_RADIO_STATE 0x05
        #define CMD_RADIO_LOCK  0x06
+       #define CMD_READY               0x0F
 
        #define CMD_STAT_RX             0x21
        #define CMD_STAT_TX             0x22
index e00c160ea664a7c2f5d9e885a5c31228f55e57e5..65eb3b0af2e1165c18e2ef0f3e6251be59409024 100644 (file)
@@ -42,6 +42,7 @@ bool startRadio() {
         setTXPower();
         setBandwidth();
         setSpreadingFactor();
+        setCodingRate();
         getFrequency();
 
         LoRa.enableCrc();
@@ -178,6 +179,10 @@ void transmit(size_t size) {
     LoRa.endPacket();
     led_tx_off();
     LoRa.receive();
+
+    if (FLOW_CONTROL_ENABLED)
+      kiss_indicate_ready();
+
   } else {
     kiss_indicate_error(ERROR_TXFAILED);
     led_indicate_error(5);
index ec09a845a5d9e200944604843d52af965cfb7813..533445c8d1d035f39f1b1bfac100a6d78fa0e5d0 100644 (file)
@@ -146,6 +146,13 @@ void kiss_indicate_random(uint8_t byte) {
        Serial.write(FEND);
 }
 
+void kiss_indicate_ready() {
+       Serial.write(FEND);
+       Serial.write(CMD_READY);
+       Serial.write(0x01);
+       Serial.write(FEND);
+}
+
 bool isSplitPacket(uint8_t header) {
        return (header & FLAG_SPLIT);
 }
@@ -165,6 +172,10 @@ void setSpreadingFactor() {
        if (radio_online) LoRa.setSpreadingFactor(lora_sf);
 }
 
+void setCodingRate() {
+       if (radio_online) LoRa.setCodingRate4(lora_cr);
+}
+
 void setTXPower() {
        if (radio_online) LoRa.setTxPower(lora_txp);
 }