-
Notifications
You must be signed in to change notification settings - Fork 964
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from meshtastic/master
Pull master
- Loading branch information
Showing
14 changed files
with
146 additions
and
159 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule proto
updated
from c52c8e to 1d3b48
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,117 +1,135 @@ | ||
#include "configuration.h" | ||
#include "airtime.h" | ||
#include "NodeDB.h" | ||
#include "configuration.h" | ||
|
||
#define periodsToLog 24 | ||
|
||
AirTime *airTime; | ||
|
||
uint32_t secondsPerPeriod = 3600; | ||
uint32_t lastMillis = 0; | ||
uint32_t secSinceBoot = 0; | ||
|
||
// AirTime at; | ||
|
||
// Don't read out of this directly. Use the helper functions. | ||
struct airtimeStruct { | ||
uint32_t periodTX[periodsToLog]; // AirTime transmitted | ||
uint32_t periodRX[periodsToLog]; // AirTime received and repeated (Only valid mesh packets) | ||
uint32_t periodRX_ALL[periodsToLog]; // AirTime received regardless of valid mesh packet. Could include noise. | ||
uint8_t lastPeriodIndex; | ||
} airtimes; | ||
|
||
|
||
void AirTime::logAirtime(reportTypes reportType, uint32_t airtime_ms) | ||
{ | ||
|
||
// TODO: Is the airtimes array still necessary? It's now in myNodeInfo anyway | ||
|
||
if (reportType == TX_LOG) { | ||
DEBUG_MSG("AirTime - Packet transmitted : %ums\n", airtime_ms); | ||
airtimes.periodTX[0] = 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; | ||
} else if (reportType == RX_LOG) { | ||
DEBUG_MSG("AirTime - Packet received : %ums\n", airtime_ms); | ||
airtimes.periodRX[0] = airtimes.periodRX[0] + airtime_ms; | ||
this->airtimes.periodRX[0] = this->airtimes.periodRX[0] + airtime_ms; | ||
myNodeInfo.air_period_rx[0] = myNodeInfo.air_period_rx[0] + airtime_ms; | ||
} else if (reportType == RX_ALL_LOG) { | ||
DEBUG_MSG("AirTime - Packet received (noise?) : %ums\n", airtime_ms); | ||
airtimes.periodRX_ALL[0] = airtimes.periodRX_ALL[0] + airtime_ms; | ||
} else { | ||
DEBUG_MSG("AirTime - Unknown report time. This should never happen!!\n"); | ||
this->airtimes.periodRX_ALL[0] = this->airtimes.periodRX_ALL[0] + airtime_ms; | ||
} | ||
|
||
uint8_t channelUtilPeriod = (getSecondsSinceBoot() / 10) % CHANNEL_UTILIZATION_PERIODS; | ||
this->channelUtilization[channelUtilPeriod] = channelUtilization[channelUtilPeriod] + airtime_ms; | ||
} | ||
|
||
uint8_t currentPeriodIndex() | ||
uint8_t AirTime::currentPeriodIndex() | ||
{ | ||
return ((getSecondsSinceBoot() / secondsPerPeriod) % periodsToLog); | ||
return ((getSecondsSinceBoot() / SECONDS_PER_PERIOD) % PERIODS_TO_LOG); | ||
} | ||
|
||
void airtimeRotatePeriod() | ||
void AirTime::airtimeRotatePeriod() | ||
{ | ||
|
||
if (airtimes.lastPeriodIndex != currentPeriodIndex()) { | ||
if (this->airtimes.lastPeriodIndex != currentPeriodIndex()) { | ||
DEBUG_MSG("Rotating airtimes to a new period = %u\n", currentPeriodIndex()); | ||
|
||
for (int i = periodsToLog - 2; i >= 0; --i) { | ||
airtimes.periodTX[i + 1] = airtimes.periodTX[i]; | ||
airtimes.periodRX[i + 1] = airtimes.periodRX[i]; | ||
airtimes.periodRX_ALL[i + 1] = airtimes.periodRX_ALL[i]; | ||
for (int i = PERIODS_TO_LOG - 2; i >= 0; --i) { | ||
this->airtimes.periodTX[i + 1] = this->airtimes.periodTX[i]; | ||
this->airtimes.periodRX[i + 1] = this->airtimes.periodRX[i]; | ||
this->airtimes.periodRX_ALL[i + 1] = this->airtimes.periodRX_ALL[i]; | ||
|
||
myNodeInfo.air_period_tx[i + 1] = myNodeInfo.air_period_tx[i]; | ||
myNodeInfo.air_period_rx[i + 1] = myNodeInfo.air_period_rx[i]; | ||
} | ||
airtimes.periodTX[0] = 0; | ||
airtimes.periodRX[0] = 0; | ||
airtimes.periodRX_ALL[0] = 0; | ||
|
||
this->airtimes.periodTX[0] = 0; | ||
this->airtimes.periodRX[0] = 0; | ||
this->airtimes.periodRX_ALL[0] = 0; | ||
|
||
myNodeInfo.air_period_tx[0] = 0; | ||
myNodeInfo.air_period_rx[0] = 0; | ||
|
||
|
||
airtimes.lastPeriodIndex = currentPeriodIndex(); | ||
this->airtimes.lastPeriodIndex = currentPeriodIndex(); | ||
} | ||
} | ||
|
||
uint32_t *airtimeReport(reportTypes reportType) | ||
uint32_t *AirTime::airtimeReport(reportTypes reportType) | ||
{ | ||
|
||
if (reportType == TX_LOG) { | ||
return airtimes.periodTX; | ||
return this->airtimes.periodTX; | ||
} else if (reportType == RX_LOG) { | ||
return airtimes.periodRX; | ||
return this->airtimes.periodRX; | ||
} else if (reportType == RX_ALL_LOG) { | ||
return airtimes.periodRX_ALL; | ||
return this->airtimes.periodRX_ALL; | ||
} | ||
return 0; | ||
} | ||
|
||
uint8_t getPeriodsToLog() | ||
uint8_t AirTime::getPeriodsToLog() | ||
{ | ||
return periodsToLog; | ||
return PERIODS_TO_LOG; | ||
} | ||
|
||
uint32_t getSecondsPerPeriod() | ||
uint32_t AirTime::getSecondsPerPeriod() | ||
{ | ||
return secondsPerPeriod; | ||
return SECONDS_PER_PERIOD; | ||
} | ||
|
||
uint32_t getSecondsSinceBoot() | ||
uint32_t AirTime::getSecondsSinceBoot() | ||
{ | ||
return secSinceBoot; | ||
return this->secSinceBoot; | ||
} | ||
|
||
float AirTime::channelUtilizationPercent() | ||
{ | ||
uint32_t sum = 0; | ||
for (uint32_t i = 0; i < CHANNEL_UTILIZATION_PERIODS; i++) { | ||
sum += this->channelUtilization[i]; | ||
// DEBUG_MSG("ChanUtilArray %u %u\n", i, this->channelUtilization[i]); | ||
} | ||
|
||
return (float(sum) / float(CHANNEL_UTILIZATION_PERIODS * 10 * 1000)) * 100; | ||
} | ||
|
||
AirTime::AirTime() : concurrency::OSThread("AirTime") {} | ||
|
||
int32_t AirTime::runOnce() | ||
{ | ||
//DEBUG_MSG("AirTime::runOnce()\n"); | ||
|
||
airtimeRotatePeriod(); | ||
secSinceBoot++; | ||
|
||
/* | ||
This actually doesn't need to be run once per second but we currently use it for the | ||
secSinceBoot counter. | ||
uint8_t utilPeriod = (getSecondsSinceBoot() / 10) % CHANNEL_UTILIZATION_PERIODS; | ||
|
||
if (firstTime) { | ||
airtimeRotatePeriod(); | ||
|
||
for (uint32_t i = 0; i < CHANNEL_UTILIZATION_PERIODS; i++) { | ||
this->channelUtilization[i] = 0; | ||
} | ||
|
||
firstTime = false; | ||
lastUtilPeriod = utilPeriod; | ||
|
||
} else { | ||
|
||
// Reset the channelUtilization window when we roll over | ||
if (lastUtilPeriod != utilPeriod) { | ||
lastUtilPeriod = utilPeriod; | ||
|
||
this->channelUtilization[utilPeriod] = 0; | ||
} | ||
|
||
// Update channel_utilization every second. | ||
myNodeInfo.channel_utilization = airTime->channelUtilizationPercent(); | ||
} | ||
|
||
If we have a better counter of how long the device has been online (and not millis()) | ||
then we can change this to something less frequent. Maybe once ever 5 seconds? | ||
*/ | ||
return (1000 * 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.