Update to #588 - Change "hour" to "period"

pull/596/head
Jm 2020-12-27 10:50:52 -08:00
rodzic 6e4cf22cf0
commit 15a0b3694d
3 zmienionych plików z 49 dodań i 43 usunięć

Wyświetl plik

@ -1,47 +1,41 @@
#include "airtime.h"
#include <Arduino.h>
#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;
}
return periodsToLog;
}
uint32_t getSecondsPerPeriod()
{
return secondsPerPeriod;
}
uint32_t getSecondsSinceBoot()
{
return secSinceBoot;
}

Wyświetl plik

@ -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);
uint16_t *airtimeReport(reportTypes reportType);
uint32_t getSecondsPerPeriod();

Wyświetl plik

@ -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("},");