Skip to content

Commit

Permalink
Re-compute correct timeslot on applyModemConfig (#4469)
Browse files Browse the repository at this point in the history
* Re-compute correct timeslot on applyModemConfig

* Cap contention window max at 7
  • Loading branch information
thebentern authored Aug 15, 2024
1 parent ef56fae commit 6f1dae1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/mesh/RadioInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
6 changes: 4 additions & 2 deletions src/mesh/RadioInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
* */
Expand Down

0 comments on commit 6f1dae1

Please sign in to comment.