mirror of
https://github.com/meshtastic/firmware.git
synced 2025-08-04 04:40:50 +00:00
Merge pull request #1097 from mc-hamster/master
airtime - reuse some functions
This commit is contained in:
commit
1c993c10a1
@ -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,11 +34,19 @@ 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()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (this->airtimes.lastPeriodIndex != currentPeriodIndex()) {
|
if (this->airtimes.lastPeriodIndex != currentPeriodIndex()) {
|
||||||
//DEBUG_MSG("Rotating airtimes to a new period = %u\n", currentPeriodIndex());
|
// DEBUG_MSG("Rotating airtimes to a new period = %u\n", currentPeriodIndex());
|
||||||
|
|
||||||
for (int i = PERIODS_TO_LOG - 2; i >= 0; --i) {
|
for (int i = PERIODS_TO_LOG - 2; i >= 0; --i) {
|
||||||
this->airtimes.periodTX[i + 1] = this->airtimes.periodTX[i];
|
this->airtimes.periodTX[i + 1] = this->airtimes.periodTX[i];
|
||||||
@ -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;
|
||||||
@ -144,8 +145,8 @@ int32_t AirTime::runOnce()
|
|||||||
this->airtimes.periodRX[i] = 0;
|
this->airtimes.periodRX[i] = 0;
|
||||||
this->airtimes.periodRX_ALL[i] = 0;
|
this->airtimes.periodRX_ALL[i] = 0;
|
||||||
|
|
||||||
//myNodeInfo.air_period_tx[i] = 0;
|
// myNodeInfo.air_period_tx[i] = 0;
|
||||||
//myNodeInfo.air_period_rx[i] = 0;
|
// myNodeInfo.air_period_rx[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
firstTime = false;
|
firstTime = false;
|
||||||
@ -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);
|
||||||
}
|
}
|
@ -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;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user