]> git.tnoah.ca Git - lora-radio.git/commitdiff
Added interference avoidance option
authorMark Qvist <mark@unsigned.io>
Thu, 9 Jan 2025 16:58:46 +0000 (17:58 +0100)
committerMark Qvist <mark@unsigned.io>
Thu, 9 Jan 2025 16:58:46 +0000 (17:58 +0100)
Config.h
Framing.h
Makefile
RNode_Firmware.ino
ROM.h
Utilities.h

index 01332132a83ad2caeae0666364c13c758a6a9e66..1152fda80e040698ae32f0c7555eeba18bed49da 100644 (file)
--- a/Config.h
+++ b/Config.h
@@ -96,6 +96,8 @@
        #define CSMA_BAND_1_MAX_AIRTIME    7
        #define CSMA_BAND_N_MIN_AIRTIME    85
        #define CSMA_INFR_THRESHOLD_DB     12
+       bool interference_detected      =  false;
+       bool avoid_interference         =  true;
        int csma_slot_ms                =  CSMA_SLOT_MIN_MS;
        unsigned long difs_ms           =  CSMA_SIFS_MS + 2*csma_slot_ms;
        unsigned long difs_wait_start   = -1;
index a8dc4f722fe04ef09f682903fde11556a69f2589..89e103971b7624506863ca1512eaeb3c365d6ed3 100644 (file)
--- a/Framing.h
+++ b/Framing.h
@@ -62,6 +62,7 @@
   #define CMD_NP_INT      0x65
   #define CMD_BT_CTRL     0x46
   #define CMD_BT_PIN      0x62
+  #define CMD_DIS_IA      0x69
 
   #define CMD_BOARD       0x47
   #define CMD_PLATFORM    0x48
index 9e340af7fe1fbd1243881bfc4775e378915348cf..53f32bd72d8c5cbe80a0d66ced2dd23118d8bea9 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -226,8 +226,8 @@ upload-t3s3:
        arduino-cli upload -p /dev/ttyACM0 --fqbn esp32:esp32:esp32s3
        @sleep 1
        rnodeconf /dev/ttyACM0 --firmware-hash $$(./partition_hashes ./build/esp32.esp32.esp32s3/RNode_Firmware.ino.bin)
-       #@sleep 3
-       #python ./Release/esptool/esptool.py --chip esp32s3 --port /dev/ttyACM0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin
+       @sleep 3
+       python ./Release/esptool/esptool.py --chip esp32s3 --port /dev/ttyACM0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin
 
 upload-featheresp32:
        arduino-cli upload -p /dev/ttyUSB0 --fqbn esp32:esp32:featheresp32
index 12f6df0b6c68e7d376b75a4fdee56fd948aa27ee..98a327db28eff7a34168320742f3cec1801f0855 100644 (file)
@@ -237,6 +237,15 @@ void setup() {
     }
   #endif
 
+  #if MCU_VARIANT == MCU_ESP32 || MCU_VARIANT == MCU_NRF52
+    #if MODEM == SX1280
+      avoid_interference = false;
+    #else
+      if (EEPROM.read(eeprom_addr(ADDR_CONF_DIA)) == 0x01) { avoid_interference = false; }
+      else                                                 { avoid_interference = true; }
+    #endif
+  #endif
+
   // Validate board health, EEPROM and config
   validate_status();
 
@@ -1152,6 +1161,17 @@ void serial_callback(uint8_t sbyte) {
             display_unblank();
         }
       #endif
+    } else if (command == CMD_DIS_IA) {
+      if (sbyte == FESC) {
+          ESCAPE = true;
+      } else {
+          if (ESCAPE) {
+              if (sbyte == TFEND) sbyte = FEND;
+              if (sbyte == TFESC) sbyte = FESC;
+              ESCAPE = false;
+          }
+          dia_conf_save(sbyte);
+      }
     } else if (command == CMD_DISP_RCND) {
       #if HAS_DISPLAY
         if (sbyte == FESC) {
@@ -1189,7 +1209,11 @@ void serial_callback(uint8_t sbyte) {
   portMUX_TYPE update_lock = portMUX_INITIALIZER_UNLOCKED;
 #endif
 
-bool medium_free() { update_modem_status(); return !dcd; }
+bool medium_free() {
+  update_modem_status();
+  if (avoid_interference && interference_detected) { return false; }
+  return !dcd;
+}
 
 bool noise_floor_sampled = false;
 int  noise_floor_sample  = 0;
@@ -1215,6 +1239,8 @@ void update_noise_floor() {
   #endif
 }
 
+#define LED_ID_TRIG 16
+uint8_t led_id_filter = 0;
 void update_modem_status() {
   #if MCU_VARIANT == MCU_ESP32
     portENTER_CRITICAL(&update_lock);
@@ -1232,13 +1258,22 @@ void update_modem_status() {
     portEXIT_CRITICAL();
   #endif
 
-  if (carrier_detected) { dcd = true; }
-  else { dcd = false; }
+  interference_detected = current_rssi > (noise_floor+CSMA_INFR_THRESHOLD_DB);
+  if (interference_detected) { if (led_id_filter < LED_ID_TRIG) { led_id_filter += 1; } }
+  else                       { if (led_id_filter > 0) {led_id_filter -= 1; } }
+
+  if (carrier_detected) { dcd = true; } else { dcd = false; }
 
   dcd_led = dcd;
   if (dcd_led) { led_rx_on(); }
-  else         { if (airtime_lock) { led_indicate_airtime_lock(); }
-                 else              { led_rx_off(); } }
+  else {
+    if (interference_detected) {
+      if (led_id_filter >= LED_ID_TRIG && noise_floor_sampled) { led_id_on(); }
+    } else {
+      if (airtime_lock) { led_indicate_airtime_lock(); }
+      else              { led_rx_off(); led_id_off(); }
+    }
+  }
 }
 
 void check_modem_status() {
diff --git a/ROM.h b/ROM.h
index 6f2ac2f54e8a2794ad5c5cae7b8b9e597ef35458..27c38bbb53c736b1c139c1982d0f1aba57025381 100644 (file)
--- a/ROM.h
+++ b/ROM.h
@@ -23,7 +23,7 @@
   #define ADDR_HW_REV    0x02
   #define ADDR_SERIAL    0x03
   #define ADDR_MADE      0x07
-  #define ADDR_CHKSUM     0x0B
+  #define ADDR_CHKSUM    0x0B
   #define ADDR_SIGNATURE 0x1B
   #define ADDR_INFO_LOCK 0x9B
 
@@ -43,6 +43,7 @@
   #define ADDR_CONF_PSET 0xB5
   #define ADDR_CONF_PINT 0xB6
   #define ADDR_CONF_BSET 0xB7
+  #define ADDR_CONF_DIA  0xB9
 
   #define INFO_LOCK_BYTE 0x73
   #define CONF_OK_BYTE   0x73
index 03e49854153f631e85a5c279b8094a8737aabc4a..000db683c4052c63abfeccf33fc822a1c8f5d104 100644 (file)
@@ -165,53 +165,73 @@ uint8_t boot_vector = 0x00;
        void led_rx_off() {     digitalWrite(pin_led_rx, LOW); }
        void led_tx_on()  { digitalWrite(pin_led_tx, HIGH); }
        void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
+       void led_id_on()  { }
+       void led_id_off() { }
 #elif MCU_VARIANT == MCU_ESP32
        #if HAS_NP == true
                void led_rx_on()  { npset(0, 0, 0xFF); }
                void led_rx_off() {     npset(0, 0, 0); }
                void led_tx_on()  { npset(0xFF, 0x50, 0x00); }
                void led_tx_off() { npset(0, 0, 0); }
+               void led_id_on()  { npset(0x90, 0, 0x70); }
+               void led_id_off() { npset(0, 0, 0); }
        #elif BOARD_MODEL == BOARD_RNODE_NG_20
                void led_rx_on()  { digitalWrite(pin_led_rx, HIGH); }
                void led_rx_off() {     digitalWrite(pin_led_rx, LOW); }
                void led_tx_on()  { digitalWrite(pin_led_tx, HIGH); }
                void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
+               void led_id_on()  { }
+               void led_id_off() { }
        #elif BOARD_MODEL == BOARD_RNODE_NG_21
                void led_rx_on()  { digitalWrite(pin_led_rx, HIGH); }
                void led_rx_off() {     digitalWrite(pin_led_rx, LOW); }
                void led_tx_on()  { digitalWrite(pin_led_tx, HIGH); }
                void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
+               void led_id_on()  { }
+               void led_id_off() { }
        #elif BOARD_MODEL == BOARD_RNODE_NG_22
                void led_rx_on()  { digitalWrite(pin_led_rx, HIGH); }
                void led_rx_off() {     digitalWrite(pin_led_rx, LOW); }
                void led_tx_on()  { digitalWrite(pin_led_tx, HIGH); }
                void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
+               void led_id_on()  { }
+               void led_id_off() { }
        #elif BOARD_MODEL == BOARD_TBEAM
                void led_rx_on()  { digitalWrite(pin_led_rx, HIGH); }
                void led_rx_off() {     digitalWrite(pin_led_rx, LOW); }
                void led_tx_on()  { digitalWrite(pin_led_tx, LOW); }
                void led_tx_off() { digitalWrite(pin_led_tx, HIGH); }
+               void led_id_on()  { }
+               void led_id_off() { }
        #elif BOARD_MODEL == BOARD_TDECK
                void led_rx_on()  { }
                void led_rx_off() {     }
                void led_tx_on()  { }
                void led_tx_off() { }
+               void led_id_on()  { }
+               void led_id_off() { }
        #elif BOARD_MODEL == BOARD_TBEAM_S_V1
                void led_rx_on()  { }
                void led_rx_off() {     }
                void led_tx_on()  { }
                void led_tx_off() { }
+               void led_id_on()  { }
+               void led_id_off() { }
        #elif BOARD_MODEL == BOARD_LORA32_V1_0
                #if defined(EXTERNAL_LEDS)
                        void led_rx_on()  { digitalWrite(pin_led_rx, HIGH); }
                        void led_rx_off() {     digitalWrite(pin_led_rx, LOW); }
                        void led_tx_on()  { digitalWrite(pin_led_tx, HIGH); }
                        void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
+                       void led_id_on()  { }
+                       void led_id_off() { }
                #else
                        void led_rx_on()  { digitalWrite(pin_led_rx, HIGH); }
                        void led_rx_off() {     digitalWrite(pin_led_rx, LOW); }
                        void led_tx_on()  { digitalWrite(pin_led_tx, HIGH); }
                        void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
+                       void led_id_on()  { }
+                       void led_id_off() { }
                #endif
        #elif BOARD_MODEL == BOARD_LORA32_V2_0
                #if defined(EXTERNAL_LEDS)
@@ -219,11 +239,15 @@ uint8_t boot_vector = 0x00;
                        void led_rx_off() {     digitalWrite(pin_led_rx, LOW); }
                        void led_tx_on()  { digitalWrite(pin_led_tx, HIGH); }
                        void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
+                       void led_id_on()  { }
+                       void led_id_off() { }
                #else
                        void led_rx_on()  { digitalWrite(pin_led_rx, LOW); }
                        void led_rx_off() {     digitalWrite(pin_led_rx, HIGH); }
                        void led_tx_on()  { digitalWrite(pin_led_tx, LOW); }
                        void led_tx_off() { digitalWrite(pin_led_tx, HIGH); }
+                       void led_id_on()  { }
+                       void led_id_off() { }
                #endif
        #elif BOARD_MODEL == BOARD_HELTEC32_V2
                #if defined(EXTERNAL_LEDS)
@@ -231,50 +255,68 @@ uint8_t boot_vector = 0x00;
                        void led_rx_off() {     digitalWrite(pin_led_rx, LOW); }
                        void led_tx_on()  { digitalWrite(pin_led_tx, HIGH); }
                        void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
+                       void led_id_on()  { }
+                       void led_id_off() { }
                #else
                        void led_rx_on()  { digitalWrite(pin_led_rx, HIGH); }
                        void led_rx_off() {     digitalWrite(pin_led_rx, LOW); }
                        void led_tx_on()  { digitalWrite(pin_led_tx, HIGH); }
                        void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
+                       void led_id_on()  { }
+                       void led_id_off() { }
                #endif
        #elif BOARD_MODEL == BOARD_HELTEC32_V3
                        void led_rx_on()  { digitalWrite(pin_led_rx, HIGH); }
                        void led_rx_off() {     digitalWrite(pin_led_rx, LOW); }
                        void led_tx_on()  { digitalWrite(pin_led_tx, HIGH); }
                        void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
+                       void led_id_on()  { }
+                       void led_id_off() { }
        #elif BOARD_MODEL == BOARD_LORA32_V2_1
                void led_rx_on()  { digitalWrite(pin_led_rx, HIGH); }
                void led_rx_off() {     digitalWrite(pin_led_rx, LOW); }
                void led_tx_on()  { digitalWrite(pin_led_tx, HIGH); }
                void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
+               void led_id_on()  { }
+               void led_id_off() { }
        #elif BOARD_MODEL == BOARD_HUZZAH32
                void led_rx_on()  { digitalWrite(pin_led_rx, HIGH); }
                void led_rx_off() {     digitalWrite(pin_led_rx, LOW); }
                void led_tx_on()  { digitalWrite(pin_led_tx, HIGH); }
                void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
+               void led_id_on()  { }
+               void led_id_off() { }
        #elif BOARD_MODEL == BOARD_GENERIC_ESP32
                void led_rx_on()  { digitalWrite(pin_led_rx, HIGH); }
                void led_rx_off() {     digitalWrite(pin_led_rx, LOW); }
                void led_tx_on()  { digitalWrite(pin_led_tx, HIGH); }
                void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
+               void led_id_on()  { }
+               void led_id_off() { }
        #endif
 #elif MCU_VARIANT == MCU_NRF52
     #if HAS_NP == true
-        void led_rx_on()  { npset(0, 0, 0xFF); }
-        void led_rx_off() {    npset(0, 0, 0); }
-        void led_tx_on()  { npset(0xFF, 0x50, 0x00); }
-        void led_tx_off() { npset(0, 0, 0); }
+      void led_rx_on()  { npset(0, 0, 0xFF); }
+      void led_rx_off() {      npset(0, 0, 0); }
+      void led_tx_on()  { npset(0xFF, 0x50, 0x00); }
+      void led_tx_off() { npset(0, 0, 0); }
+                       void led_id_on()  { npset(0x90, 0, 0x70); }
+                       void led_id_off() { npset(0, 0, 0); }
     #elif BOARD_MODEL == BOARD_RAK4631
                void led_rx_on()  { digitalWrite(pin_led_rx, HIGH); }
                void led_rx_off() {     digitalWrite(pin_led_rx, LOW); }
                void led_tx_on()  { digitalWrite(pin_led_tx, HIGH); }
                void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
+               void led_id_on()  { }
+               void led_id_off() { }
        #elif BOARD_MODEL == BOARD_HELTEC_T114
-        // Heltec T114 pulls pins LOW to turn on
-        void led_rx_on()  { digitalWrite(pin_led_rx, LOW); }
-        void led_rx_off() {    digitalWrite(pin_led_rx, HIGH); }
-        void led_tx_on()  { digitalWrite(pin_led_tx, LOW); }
-        void led_tx_off() { digitalWrite(pin_led_tx, HIGH); }
+    // Heltec T114 pulls pins LOW to turn on
+    void led_rx_on()  { digitalWrite(pin_led_rx, LOW); }
+    void led_rx_off() {        digitalWrite(pin_led_rx, HIGH); }
+    void led_tx_on()  { digitalWrite(pin_led_tx, LOW); }
+    void led_tx_off() { digitalWrite(pin_led_tx, HIGH); }
+               void led_id_on()  { }
+               void led_id_off() { }
     #endif
 #endif
 
@@ -1556,6 +1598,12 @@ void drot_conf_save(uint8_t val) {
        #endif
 }
 
+void dia_conf_save(uint8_t val) {
+       if (val > 0x00)  { eeprom_update(eeprom_addr(ADDR_CONF_DIA), 0x01); }
+       else             { eeprom_update(eeprom_addr(ADDR_CONF_DIA), 0x00); }
+       hard_reset();
+}
+
 void np_int_conf_save(uint8_t p_int) {
        eeprom_update(eeprom_addr(ADDR_CONF_PSET), CONF_OK_BYTE);
        eeprom_update(eeprom_addr(ADDR_CONF_PINT), p_int);