From 6f1dae1b1b0eeda18217c13fd7ea06dd7b24e642 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Thu, 15 Aug 2024 15:05:38 -0500 Subject: [PATCH] Re-compute correct timeslot on applyModemConfig (#4469) * Re-compute correct timeslot on applyModemConfig * Cap contention window max at 7 --- src/mesh/RadioInterface.cpp | 1 + src/mesh/RadioInterface.h | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/mesh/RadioInterface.cpp b/src/mesh/RadioInterface.cpp index 7fe02f291..104ddbd1d 100644 --- a/src/mesh/RadioInterface.cpp +++ b/src/mesh/RadioInterface.cpp @@ -520,6 +520,7 @@ void RadioInterface::applyModemConfig() saveChannelNum(channel_num); saveFreq(freq + loraConfig.frequency_offset); + slotTimeMsec = computeSlotTimeMsec(bw, sf); preambleTimeMsec = getPacketTime((uint32_t)0); maxPacketTimeMsec = getPacketTime(meshtastic_Constants_DATA_PAYLOAD_LEN + sizeof(PacketHeader)); diff --git a/src/mesh/RadioInterface.h b/src/mesh/RadioInterface.h index b965328e4..1f2ec9bab 100644 --- a/src/mesh/RadioInterface.h +++ b/src/mesh/RadioInterface.h @@ -71,18 +71,20 @@ class RadioInterface - roundtrip air propagation time (assuming max. 30km between nodes); - Tx/Rx turnaround time (maximum of SX126x and SX127x); - MAC processing time (measured on T-beam) */ - uint32_t slotTimeMsec = 8.5 * pow(2, sf) / bw + 0.2 + 0.4 + 7; + uint32_t slotTimeMsec = computeSlotTimeMsec(bw, sf); uint16_t preambleLength = 16; // 8 is default, but we use longer to increase the amount of sleep time when receiving uint32_t preambleTimeMsec = 165; // calculated on startup, this is the default for LongFast uint32_t maxPacketTimeMsec = 3246; // calculated on startup, this is the default for LongFast const uint32_t PROCESSING_TIME_MSEC = 4500; // time to construct, process and construct a packet again (empirically determined) const uint8_t CWmin = 2; // minimum CWsize - const uint8_t CWmax = 8; // maximum CWsize + const uint8_t CWmax = 7; // maximum CWsize meshtastic_MeshPacket *sendingPacket = NULL; // The packet we are currently sending uint32_t lastTxStart = 0L; + uint32_t computeSlotTimeMsec(float bw, float sf) { return 8.5 * pow(2, sf) / bw + 0.2 + 0.4 + 7; } + /** * A temporary buffer used for sending/receiving packets, sized to hold the biggest buffer we might need * */