From 15a0b3694dff71bbdc32edd46896ab1901403437 Mon Sep 17 00:00:00 2001 From: Jm Date: Sun, 27 Dec 2020 10:50:52 -0800 Subject: [PATCH] Update to #588 - Change "hour" to "period" --- src/airtime.cpp | 69 ++++++++++++++++++++------------------- src/airtime.h | 8 +++-- src/meshwifi/meshhttp.cpp | 15 +++++---- 3 files changed, 49 insertions(+), 43 deletions(-) diff --git a/src/airtime.cpp b/src/airtime.cpp index 82f0d3bff..ec0bf8c86 100644 --- a/src/airtime.cpp +++ b/src/airtime.cpp @@ -1,47 +1,41 @@ #include "airtime.h" #include -#define hoursToLog 48 +#define periodsToLog 48 // A reminder that there are 3600 seconds in an hour so I don't have // to keep googling it. // This can be changed to a smaller number to speed up testing. // -uint16_t secondsPerHour = 3600; +uint32_t secondsPerPeriod = 3600; uint32_t lastMillis = 0; uint32_t secSinceBoot = 0; // Don't read out of this directly. Use the helper functions. struct airtimeStruct { - uint16_t hourTX[hoursToLog]; - uint16_t hourRX[hoursToLog]; - uint16_t hourRX_ALL[hoursToLog]; - uint8_t lastHourIndex; + uint16_t periodTX[periodsToLog]; + uint16_t periodRX[periodsToLog]; + uint16_t periodRX_ALL[periodsToLog]; + uint8_t lastPeriodIndex; } airtimes; void logAirtime(reportTypes reportType, uint32_t airtime_ms) { if (reportType == TX_LOG) { - airtimes.hourTX[0] = airtimes.hourTX[0] + round(airtime_ms / 1000); + airtimes.periodTX[0] = airtimes.periodTX[0] + round(airtime_ms / 1000); } else if (reportType == RX_LOG) { - airtimes.hourRX[0] = airtimes.hourRX[0] + round(airtime_ms / 1000); + airtimes.periodRX[0] = airtimes.periodRX[0] + round(airtime_ms / 1000); } else if (reportType == RX_ALL_LOG) { - airtimes.hourRX_ALL[0] = airtimes.hourRX_ALL[0] + round(airtime_ms / 1000); + airtimes.periodRX_ALL[0] = airtimes.periodRX_ALL[0] + round(airtime_ms / 1000); } else { // Unknown report type } } -uint32_t getSecondsSinceBoot() +uint8_t currentPeriodIndex() { - return secSinceBoot; -} - -uint8_t currentHourIndex() -{ - // return ((secondsSinceBoot() - (secondsSinceBoot() / (hoursToLog * secondsPerHour))) / secondsPerHour); - return ((getSecondsSinceBoot() / secondsPerHour) % hoursToLog); + return ((getSecondsSinceBoot() / secondsPerPeriod) % periodsToLog); } void airtimeCalculator() @@ -49,18 +43,17 @@ void airtimeCalculator() if (millis() - lastMillis > 1000) { lastMillis = millis(); secSinceBoot++; - // DEBUG_MSG("------- lastHourIndex %i currentHourIndex %i\n", airtimes.lastHourIndex, currentHourIndex()); - if (airtimes.lastHourIndex != currentHourIndex()) { - for (int i = hoursToLog - 2; i >= 0; --i) { - airtimes.hourTX[i + 1] = airtimes.hourTX[i]; - airtimes.hourRX[i + 1] = airtimes.hourRX[i]; - airtimes.hourRX_ALL[i + 1] = airtimes.hourRX_ALL[i]; + if (airtimes.lastPeriodIndex != 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]; } - airtimes.hourTX[0] = 0; - airtimes.hourRX[0] = 0; - airtimes.hourRX_ALL[0] = 0; + airtimes.periodTX[0] = 0; + airtimes.periodRX[0] = 0; + airtimes.periodRX_ALL[0] = 0; - airtimes.lastHourIndex = currentHourIndex(); + airtimes.lastPeriodIndex = currentPeriodIndex(); } } } @@ -70,16 +63,26 @@ uint16_t *airtimeReport(reportTypes reportType) // currentHourIndexReset(); if (reportType == TX_LOG) { - return airtimes.hourTX; + return airtimes.periodTX; } else if (reportType == RX_LOG) { - return airtimes.hourRX; + return airtimes.periodRX; } else if (reportType == RX_ALL_LOG) { - return airtimes.hourRX_ALL; + return airtimes.periodRX_ALL; } return 0; } -uint8_t getHoursToLog() +uint8_t getPeriodsToLog() { - return hoursToLog; -} \ No newline at end of file + return periodsToLog; +} + +uint32_t getSecondsPerPeriod() +{ + return secondsPerPeriod; +} + +uint32_t getSecondsSinceBoot() +{ + return secSinceBoot; +} diff --git a/src/airtime.h b/src/airtime.h index 482ab394a..4cfbb82c2 100644 --- a/src/airtime.h +++ b/src/airtime.h @@ -28,9 +28,11 @@ void logAirtime(reportTypes reportType, uint32_t airtime_ms); void airtimeCalculator(); -uint8_t currentHourIndex(); -uint8_t getHoursToLog(); +uint8_t currentPeriodIndex(); +uint8_t getPeriodsToLog(); uint32_t getSecondsSinceBoot(); -uint16_t *airtimeReport(reportTypes reportType); \ No newline at end of file +uint16_t *airtimeReport(reportTypes reportType); + +uint32_t getSecondsPerPeriod(); \ No newline at end of file diff --git a/src/meshwifi/meshhttp.cpp b/src/meshwifi/meshhttp.cpp index e24f67173..851499a09 100644 --- a/src/meshwifi/meshhttp.cpp +++ b/src/meshwifi/meshhttp.cpp @@ -1075,11 +1075,11 @@ void handleReport(HTTPRequest *req, HTTPResponse *res) res->print("\"tx_log\": ["); logArray = airtimeReport(TX_LOG); - for (int i = 0; i < getHoursToLog(); i++) { + for (int i = 0; i < getPeriodsToLog(); i++) { uint16_t tmp; tmp = *(logArray + i); res->printf("%d", tmp); - if (i != getHoursToLog() - 1) { + if (i != getPeriodsToLog() - 1) { res->print(", "); } } @@ -1088,11 +1088,11 @@ void handleReport(HTTPRequest *req, HTTPResponse *res) res->print("\"rx_log\": ["); logArray = airtimeReport(RX_LOG); - for (int i = 0; i < getHoursToLog(); i++) { + for (int i = 0; i < getPeriodsToLog(); i++) { uint16_t tmp; tmp = *(logArray + i); res->printf("%d", tmp); - if (i != getHoursToLog() - 1) { + if (i != getPeriodsToLog() - 1) { res->print(", "); } } @@ -1101,18 +1101,19 @@ void handleReport(HTTPRequest *req, HTTPResponse *res) res->print("\"rx_all_log\": ["); logArray = airtimeReport(RX_ALL_LOG); - for (int i = 0; i < getHoursToLog(); i++) { + for (int i = 0; i < getPeriodsToLog(); i++) { uint16_t tmp; tmp = *(logArray + i); res->printf("%d", tmp); - if (i != getHoursToLog() - 1) { + if (i != getPeriodsToLog() - 1) { res->print(", "); } } res->println("],"); res->printf("\"seconds_since_boot\": %u,\n", getSecondsSinceBoot()); - res->printf("\"hours_to_log\": %u\n", getHoursToLog()); + res->printf("\"seconds_per_period\": %u,\n", getSecondsPerPeriod()); + res->printf("\"periods_to_log\": %u\n", getPeriodsToLog()); res->println("},");