mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
refactor: move tx duty cycle check to function
As a preparation to make the tx duty cycle check more precise, we move it into a function.
This commit is contained in:
parent
856df241ee
commit
7c1dfd9a95
2 changed files with 17 additions and 8 deletions
|
|
@ -271,19 +271,21 @@ void Dispatcher::processRecvPacket(Packet* pkt) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dispatcher::checkSend() {
|
void Dispatcher::ensureTxDutyCycle(int tx_len) {
|
||||||
if (_mgr->getOutboundCount(_ms->getMillis()) == 0) return;
|
uint32_t est_airtime = _radio->getEstAirtimeFor(tx_len);
|
||||||
|
|
||||||
updateTxBudget();
|
|
||||||
|
|
||||||
uint32_t est_airtime = _radio->getEstAirtimeFor(MAX_TRANS_UNIT);
|
|
||||||
if (tx_budget_ms < est_airtime / MIN_TX_BUDGET_AIRTIME_DIV) {
|
if (tx_budget_ms < est_airtime / MIN_TX_BUDGET_AIRTIME_DIV) {
|
||||||
float duty_cycle = 1.0f / (1.0f + getAirtimeBudgetFactor());
|
float duty_cycle = 1.0f / (1.0f + getAirtimeBudgetFactor());
|
||||||
unsigned long needed = est_airtime / MIN_TX_BUDGET_AIRTIME_DIV - tx_budget_ms;
|
unsigned long needed = est_airtime / MIN_TX_BUDGET_AIRTIME_DIV - tx_budget_ms;
|
||||||
next_tx_time = futureMillis((unsigned long)(needed / duty_cycle));
|
next_tx_time = futureMillis((unsigned long)(needed / duty_cycle));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Dispatcher::checkSend() {
|
||||||
|
if (_mgr->getOutboundCount(_ms->getMillis()) == 0) return;
|
||||||
|
|
||||||
|
updateTxBudget();
|
||||||
|
ensureTxDutyCycle(MAX_TRANS_UNIT);
|
||||||
|
|
||||||
if (!millisHasNowPassed(next_tx_time)) return;
|
if (!millisHasNowPassed(next_tx_time)) return;
|
||||||
if (_radio->isReceiving()) {
|
if (_radio->isReceiving()) {
|
||||||
if (cad_busy_start == 0) {
|
if (cad_busy_start == 0) {
|
||||||
|
|
|
||||||
|
|
@ -195,6 +195,13 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool tryParsePacket(Packet* pkt, const uint8_t* raw, int len);
|
bool tryParsePacket(Packet* pkt, const uint8_t* raw, int len);
|
||||||
|
/**
|
||||||
|
* \brief ensure the next tx time obeys the duty cycle
|
||||||
|
*
|
||||||
|
* Internally this updates the next_tx_time so that the Tx
|
||||||
|
* is executed by earliest the next allowed time slot.
|
||||||
|
*/
|
||||||
|
void ensureTxDutyCycle(int tx_len);
|
||||||
void checkRecv();
|
void checkRecv();
|
||||||
void checkSend();
|
void checkSend();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue