@@ -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}
@@ -268,12 +272,12 @@ int MyMesh::calcRxDelay(float score, uint32_t air_time) const {
268272}
269273
270274uint32_t MyMesh::getRetransmitDelay (const mesh::Packet *packet) {
271- uint32_t t = (_radio-> getEstAirtimeFor (packet->getPathByteLen () + packet->payload_len + 2 ) * 0 .5f );
272- return getRNG ()->nextInt (0 , 5 *t + 1 );
275+ uint32_t tx_airtime_ms = (estimateTxAirtimeFor (packet->getPathByteLen () + packet->payload_len + 2 , packet-> _tx_cr ) * 0 .5f );
276+ return getRNG ()->nextInt (0 , 5 * tx_airtime_ms + 1 );
273277}
274278uint32_t MyMesh::getDirectRetransmitDelay (const mesh::Packet *packet) {
275- uint32_t t = (_radio-> getEstAirtimeFor (packet->getPathByteLen () + packet->payload_len + 2 ) * 0 .2f );
276- return getRNG ()->nextInt (0 , 5 *t + 1 );
279+ uint32_t tx_airtime_ms = (estimateTxAirtimeFor (packet->getPathByteLen () + packet->payload_len + 2 , packet-> _tx_cr ) * 0 .2f );
280+ return getRNG ()->nextInt (0 , 5 * tx_airtime_ms + 1 );
277281}
278282
279283uint8_t MyMesh::getExtraAckTransmitCount () const {
@@ -962,6 +966,7 @@ void MyMesh::begin(bool has_display) {
962966 _store->loadChannels (this );
963967
964968 radio_driver.setParams (_prefs.freq , _prefs.bw , _prefs.sf , _prefs.cr );
969+ setDefaultCR (_prefs.cr );
965970 radio_driver.setTxPower (_prefs.tx_power_dbm );
966971 radio_driver.setRxBoostedGainMode (_prefs.rx_boosted_gain );
967972 MESH_DEBUG_PRINTLN (" RX Boosted Gain Mode: %s" ,
@@ -1389,6 +1394,7 @@ void MyMesh::handleCmdFrame(size_t len) {
13891394 savePrefs ();
13901395
13911396 radio_driver.setParams (_prefs.freq , _prefs.bw , _prefs.sf , _prefs.cr );
1397+ setDefaultCR (_prefs.cr );
13921398 MESH_DEBUG_PRINTLN (" OK: CMD_SET_RADIO_PARAMS: f=%d, bw=%d, sf=%d, cr=%d" , freq, bw, (uint32_t )sf,
13931399 (uint32_t )cr);
13941400
@@ -1754,10 +1760,13 @@ void MyMesh::handleCmdFrame(size_t len) {
17541760 memcpy (&auth, &cmd_frame[5 ], 4 );
17551761 auto pkt = createTrace (tag, auth, flags);
17561762 if (pkt) {
1763+ if ((path_len >> path_sz) > 0 ) {
1764+ pkt->_tx_cr = selectCodingRateForPeer (&cmd_frame[10 ], 1 << path_sz);
1765+ }
17571766 sendDirect (pkt, &cmd_frame[10 ], path_len);
17581767
1759- uint32_t t = _radio-> getEstAirtimeFor (pkt->payload_len + pkt->path_len + 2 );
1760- uint32_t est_timeout = calcDirectTimeoutMillisFor (t , path_len >> path_sz);
1768+ uint32_t tx_airtime_ms = estimateTxAirtimeFor (pkt->payload_len + pkt->path_len + 2 , pkt-> _tx_cr );
1769+ uint32_t est_timeout = calcDirectTimeoutMillisFor (tx_airtime_ms , path_len >> path_sz);
17611770
17621771 out_frame[0 ] = RESP_CODE_SENT ;
17631772 out_frame[1 ] = 0 ;
0 commit comments