Merge pull request #1097 from mc-hamster/master

airtime - reuse some functions
This commit is contained in:
Jm Casler 2022-01-15 11:20:33 -08:00 committed by GitHub
commit 1c993c10a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 19 deletions

View File

@ -2,24 +2,19 @@
#include "NodeDB.h" #include "NodeDB.h"
#include "configuration.h" #include "configuration.h"
AirTime *airTime; AirTime *airTime;
// Don't read out of this directly. Use the helper functions. // Don't read out of this directly. Use the helper functions.
void AirTime::logAirtime(reportTypes reportType, uint32_t airtime_ms) void AirTime::logAirtime(reportTypes reportType, uint32_t airtime_ms)
{ {
uint8_t channelUtilPeriod = (getSecondsSinceBoot() / 10) % CHANNEL_UTILIZATION_PERIODS;
uint8_t channelUtilTXPeriod = (getSecondsSinceBoot() / 10) % CHANNEL_UTILIZATION_PERIODS;
if (reportType == TX_LOG) { if (reportType == TX_LOG) {
DEBUG_MSG("AirTime - Packet transmitted : %ums\n", airtime_ms); DEBUG_MSG("AirTime - Packet transmitted : %ums\n", airtime_ms);
this->airtimes.periodTX[0] = this->airtimes.periodTX[0] + airtime_ms; this->airtimes.periodTX[0] = this->airtimes.periodTX[0] + airtime_ms;
myNodeInfo.air_period_tx[0] = myNodeInfo.air_period_tx[0] + airtime_ms; myNodeInfo.air_period_tx[0] = myNodeInfo.air_period_tx[0] + airtime_ms;
this->utilizationTX[channelUtilTXPeriod] = channelUtilization[channelUtilTXPeriod] + airtime_ms; this->utilizationTX[this->getPeriodUtilHour()] = this->utilizationTX[this->getPeriodUtilHour()] + airtime_ms;
} else if (reportType == RX_LOG) { } else if (reportType == RX_LOG) {
DEBUG_MSG("AirTime - Packet received : %ums\n", airtime_ms); DEBUG_MSG("AirTime - Packet received : %ums\n", airtime_ms);
@ -31,8 +26,7 @@ void AirTime::logAirtime(reportTypes reportType, uint32_t airtime_ms)
} }
// Log all airtime type for channel utilization // Log all airtime type for channel utilization
this->channelUtilization[channelUtilPeriod] = channelUtilization[channelUtilPeriod] + airtime_ms; this->channelUtilization[this->getPeriodUtilMinute()] = channelUtilization[this->getPeriodUtilMinute()] + airtime_ms;
} }
uint8_t AirTime::currentPeriodIndex() uint8_t AirTime::currentPeriodIndex()
@ -40,6 +34,14 @@ uint8_t AirTime::currentPeriodIndex()
return ((getSecondsSinceBoot() / SECONDS_PER_PERIOD) % PERIODS_TO_LOG); return ((getSecondsSinceBoot() / SECONDS_PER_PERIOD) % PERIODS_TO_LOG);
} }
uint8_t AirTime::getPeriodUtilMinute() {
return (getSecondsSinceBoot() / 10) % CHANNEL_UTILIZATION_PERIODS;
}
uint8_t AirTime::getPeriodUtilHour() {
return (getSecondsSinceBoot() / 60) % MINUTES_IN_HOUR;
}
void AirTime::airtimeRotatePeriod() void AirTime::airtimeRotatePeriod()
{ {
@ -121,13 +123,12 @@ int32_t AirTime::runOnce()
{ {
secSinceBoot++; secSinceBoot++;
uint8_t utilPeriod = (getSecondsSinceBoot() / 10) % CHANNEL_UTILIZATION_PERIODS; uint8_t utilPeriod = this->getPeriodUtilMinute();
uint8_t utilPeriodTX = (getSecondsSinceBoot() / 60) % MINUTES_IN_HOUR; uint8_t utilPeriodTX = this->getPeriodUtilHour();
if (firstTime) { if (firstTime) {
airtimeRotatePeriod(); airtimeRotatePeriod();
// Init utilizationTX window to all 0 // Init utilizationTX window to all 0
for (uint32_t i = 0; i < MINUTES_IN_HOUR; i++) { for (uint32_t i = 0; i < MINUTES_IN_HOUR; i++) {
this->utilizationTX[i] = 0; this->utilizationTX[i] = 0;
@ -171,10 +172,15 @@ int32_t AirTime::runOnce()
// Update channel_utilization every second. // Update channel_utilization every second.
myNodeInfo.air_util_tx = airTime->utilizationTXPercent(); myNodeInfo.air_util_tx = airTime->utilizationTXPercent();
} }
/*
//DEBUG_MSG("Minutes %d TX Airtime %3.2f%\n", utilPeriodTX, airTime->utilizationTXPercent()); DEBUG_MSG("utilPeriodTX %d TX Airtime %3.2f%\n", utilPeriodTX, airTime->utilizationTXPercent());
for (uint32_t i = 0; i < MINUTES_IN_HOUR; i++) {
DEBUG_MSG(
"%d,", this->utilizationTX[i]
);
}
DEBUG_MSG("\n");
*/
return (1000 * 1); return (1000 * 1);
} }

View File

@ -69,6 +69,9 @@ class AirTime : private concurrency::OSThread
uint8_t lastPeriodIndex; uint8_t lastPeriodIndex;
} airtimes; } airtimes;
uint8_t getPeriodUtilMinute();
uint8_t getPeriodUtilHour();
protected: protected:
virtual int32_t runOnce() override; virtual int32_t runOnce() override;
}; };