From 2ede362cb3ab05fd064bd2cb275c020e2a5c233b Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Thu, 10 Oct 2024 23:26:12 +0200 Subject: [PATCH] Adjusted CSMA parameters and P-curve. Added dynamic CSMA slot time. --- Config.h | 8 +++++--- RNode_Firmware.ino | 4 ++-- Utilities.h | 4 +++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Config.h b/Config.h index d10cc60..b7871d8 100644 --- a/Config.h +++ b/Config.h @@ -20,7 +20,7 @@ #define CONFIG_H #define MAJ_VERS 0x01 - #define MIN_VERS 0x4d + #define MIN_VERS 0x4e #define MODE_HOST 0x11 #define MODE_TNC 0x12 @@ -74,9 +74,11 @@ #define LORA_PREAMBLE_SYMBOLS_MIN 18 #define LORA_PREAMBLE_TARGET_MS 15 #define LORA_CAD_SYMBOLS 3 + #define CSMA_SLOT_MAX_MS 100 + #define CSMA_SLOT_MIN_MS 24 int csma_slot_ms = 50; - float csma_p_min = 0.08; - float csma_p_max = 0.75; + float csma_p_min = 0.15; + float csma_p_max = 0.333; float csma_b_speed = 0.15; uint8_t csma_p = 85; diff --git a/RNode_Firmware.ino b/RNode_Firmware.ino index 3e6b09f..089e82f 100644 --- a/RNode_Firmware.ino +++ b/RNode_Firmware.ino @@ -1298,10 +1298,10 @@ void validate_status() { #if MCU_VARIANT == MCU_ESP32 || MCU_VARIANT == MCU_NRF52 #define _e 2.71828183 - #define _S 10.0 + #define _S 12.5 float csma_slope(float u) { return (pow(_e,_S*u-_S/2.0))/(pow(_e,_S*u-_S/2.0)+1.0); } void update_csma_p() { - csma_p = (uint8_t)((1.0-(csma_p_min+(csma_p_max-csma_p_min)*csma_slope(airtime)))*255.0); + csma_p = (uint8_t)((1.0-(csma_p_min+(csma_p_max-csma_p_min)*csma_slope(airtime+csma_b_speed)))*255.0); } #endif diff --git a/Utilities.h b/Utilities.h index 0a3fffb..f0fccd0 100644 --- a/Utilities.h +++ b/Utilities.h @@ -1047,7 +1047,9 @@ void updateBitrate() { lora_symbol_time_ms = (1.0/lora_symbol_rate)*1000.0; lora_bitrate = (uint32_t)(lora_sf * ( (4.0/(float)lora_cr) / ((float)(pow(2, lora_sf))/((float)lora_bw/1000.0)) ) * 1000.0); lora_us_per_byte = 1000000.0/((float)lora_bitrate/8.0); - // csma_slot_ms = lora_symbol_time_ms*10; + csma_slot_ms = lora_symbol_time_ms*12; + if (csma_slot_ms > CSMA_SLOT_MAX_MS) { csma_slot_ms = CSMA_SLOT_MAX_MS; } + if (csma_slot_ms < CSMA_SLOT_MIN_MS) { csma_slot_ms = CSMA_SLOT_MIN_MS; } float target_preamble_symbols = (LORA_PREAMBLE_TARGET_MS/lora_symbol_time_ms)-LORA_PREAMBLE_SYMBOLS_HW; if (target_preamble_symbols < LORA_PREAMBLE_SYMBOLS_MIN) { target_preamble_symbols = LORA_PREAMBLE_SYMBOLS_MIN;