@@ -258,6 +258,10 @@ float MyMesh::getAirtimeBudgetFactor() const {
258258 return _prefs.airtime_factor ;
259259}
260260
261+ uint32_t MyMesh::estimateTxAirtimeFor (int len_bytes, uint8_t tx_cr) const {
262+ return estimateLoRaAirtimeFor (len_bytes, _prefs.sf , _prefs.bw , tx_cr != 0 ? tx_cr : _prefs.cr );
263+ }
264+
261265int MyMesh::getInterferenceThreshold () const {
262266 return 0 ; // disabled for now, until currentRSSI() problem is resolved
263267}
@@ -271,12 +275,12 @@ int MyMesh::calcRxDelay(float score, uint32_t air_time) const {
271275}
272276
273277uint32_t MyMesh::getRetransmitDelay (const mesh::Packet *packet) {
274- uint32_t t = (_radio-> getEstAirtimeFor (packet->getPathByteLen () + packet->payload_len + 2 ) * 0 .5f );
275- return getRNG ()->nextInt (0 , 5 *t + 1 );
278+ uint32_t tx_airtime_ms = (estimateTxAirtimeFor (packet->getPathByteLen () + packet->payload_len + 2 , packet-> _tx_cr ) * 0 .5f );
279+ return getRNG ()->nextInt (0 , 5 * tx_airtime_ms + 1 );
276280}
277281uint32_t MyMesh::getDirectRetransmitDelay (const mesh::Packet *packet) {
278- uint32_t t = (_radio-> getEstAirtimeFor (packet->getPathByteLen () + packet->payload_len + 2 ) * 0 .2f );
279- return getRNG ()->nextInt (0 , 5 *t + 1 );
282+ uint32_t tx_airtime_ms = (estimateTxAirtimeFor (packet->getPathByteLen () + packet->payload_len + 2 , packet-> _tx_cr ) * 0 .2f );
283+ return getRNG ()->nextInt (0 , 5 * tx_airtime_ms + 1 );
280284}
281285
282286uint8_t MyMesh::getExtraAckTransmitCount () const {
@@ -965,6 +969,7 @@ void MyMesh::begin(bool has_display) {
965969 _store->loadChannels (this );
966970
967971 radio_driver.setParams (_prefs.freq , _prefs.bw , _prefs.sf , _prefs.cr );
972+ setDefaultCR (_prefs.cr );
968973 radio_driver.setTxPower (_prefs.tx_power_dbm );
969974 radio_driver.setRxBoostedGainMode (_prefs.rx_boosted_gain );
970975 MESH_DEBUG_PRINTLN (" RX Boosted Gain Mode: %s" ,
@@ -1392,6 +1397,7 @@ void MyMesh::handleCmdFrame(size_t len) {
13921397 savePrefs ();
13931398
13941399 radio_driver.setParams (_prefs.freq , _prefs.bw , _prefs.sf , _prefs.cr );
1400+ setDefaultCR (_prefs.cr );
13951401 MESH_DEBUG_PRINTLN (" OK: CMD_SET_RADIO_PARAMS: f=%d, bw=%d, sf=%d, cr=%d" , freq, bw, (uint32_t )sf,
13961402 (uint32_t )cr);
13971403
@@ -1757,10 +1763,13 @@ void MyMesh::handleCmdFrame(size_t len) {
17571763 memcpy (&auth, &cmd_frame[5 ], 4 );
17581764 auto pkt = createTrace (tag, auth, flags);
17591765 if (pkt) {
1766+ if ((path_len >> path_sz) > 0 ) {
1767+ pkt->_tx_cr = selectCodingRateForPeer (&cmd_frame[10 ], 1 << path_sz);
1768+ }
17601769 sendDirect (pkt, &cmd_frame[10 ], path_len);
17611770
1762- uint32_t t = _radio-> getEstAirtimeFor (pkt->payload_len + pkt->path_len + 2 );
1763- uint32_t est_timeout = calcDirectTimeoutMillisFor (t , path_len >> path_sz);
1771+ uint32_t tx_airtime_ms = estimateTxAirtimeFor (pkt->payload_len + pkt->path_len + 2 , pkt-> _tx_cr );
1772+ uint32_t est_timeout = calcDirectTimeoutMillisFor (tx_airtime_ms , path_len >> path_sz);
17641773
17651774 out_frame[0 ] = RESP_CODE_SENT ;
17661775 out_frame[1 ] = 0 ;
0 commit comments