Skip to content
Closed
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 43 additions & 10 deletions src/airtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,20 +161,22 @@ AirTime::AirTime() : concurrency::OSThread("AirTime"), airtimes({}) {}

int32_t AirTime::runOnce()
{
secSinceBoot++;
// set internal counter once per thread call
// to ensure period won't change during its execution
this->secSinceBoot = millis() / 1000;
Comment thread
m1nl marked this conversation as resolved.
Resolved

uint8_t utilPeriod = this->getPeriodUtilMinute();
uint8_t utilPeriodTX = this->getPeriodUtilHour();

if (firstTime) {

// Init utilizationTX window to all 0
for (uint32_t i = 0; i < MINUTES_IN_HOUR; i++) {
for (int i = 0; i < MINUTES_IN_HOUR; i++) {
this->utilizationTX[i] = 0;
}

// Init channelUtilization window to all 0
for (uint32_t i = 0; i < CHANNEL_UTILIZATION_PERIODS; i++) {
for (int i = 0; i < CHANNEL_UTILIZATION_PERIODS; i++) {
this->channelUtilization[i] = 0;
}

Expand All @@ -193,18 +195,49 @@ int32_t AirTime::runOnce()
} else {
this->airtimeRotatePeriod();

Comment thread
m1nl marked this conversation as resolved.
Resolved
// Reset the channelUtilization window when we roll over
// reset windows when channel utilization period increased
if (lastUtilPeriod != utilPeriod) {
Comment thread
m1nl marked this conversation as resolved.
Resolved
lastUtilPeriod = utilPeriod;
// initially assume period got increased by 1
lastUtilPeriod = (lastUtilPeriod + 1) % CHANNEL_UTILIZATION_PERIODS;

// detect wrap-around and clear all periods up to CHANNEL_UTILIZATION_PERIODS
if (lastUtilPeriod > utilPeriod) {
for (uint8_t i = lastUtilPeriod; i < CHANNEL_UTILIZATION_PERIODS; i++)
this->channelUtilization[i] = 0;

// then continue from 0
lastUtilPeriod = 0;
}

this->channelUtilization[utilPeriod] = 0;
// clear all periods between (but not including) previous one and (including) new one
// not including previous one as it got increased by 1
for (uint8_t i = lastUtilPeriod; i <= utilPeriod; i++)
this->channelUtilization[i] = 0;

lastUtilPeriod = utilPeriod;
Comment thread
m1nl marked this conversation as resolved.
Resolved
}

// reset windows when TX utilization period increased
if (lastUtilPeriodTX != utilPeriodTX) {
Comment thread
thebentern marked this conversation as resolved.
Resolved
lastUtilPeriodTX = utilPeriodTX;
// initially assume period got increased by 1
lastUtilPeriodTX = (lastUtilPeriodTX + 1) % MINUTES_IN_HOUR;

this->utilizationTX[utilPeriodTX] = 0;
// detect wrap-around and clear all periods up to MINUTES_IN_HOUR
if (lastUtilPeriodTX > utilPeriodTX) {
for (int i = lastUtilPeriodTX; i < MINUTES_IN_HOUR; i++)
this->utilizationTX[i] = 0;

// then continue from 0
lastUtilPeriodTX = 0;
}

// clear all periods between (but not including) previous one and (including) a new one
// not including previous one as it got increased by 1
for (int i = lastUtilPeriodTX; i <= utilPeriodTX; i++)
this->utilizationTX[i] = 0;

lastUtilPeriodTX = utilPeriodTX;
Comment thread
m1nl marked this conversation as resolved.
Resolved
}
Comment thread
thebentern marked this conversation as resolved.
Resolved
}
return (1000 * 1);
}
return 1000;
Comment thread
m1nl marked this conversation as resolved.
Resolved
}
Loading