forked from meshtastic/firmware
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Calculate TX air time duty cycles meshtastic#588 -- UNTESTED
- Loading branch information
1 parent
34e6dbe
commit ded2b86
Showing
4 changed files
with
84 additions
and
18 deletions.
There are no files selected for viewing
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,31 +1,80 @@ | ||
/* | ||
We will keep hourly stats for 48 hours and daily stats for 7 days | ||
#include "airtime.h" | ||
#include <Arduino.h> | ||
|
||
3600 seconds in an hour, uint16_t per hour | ||
86400 seconds in a day, uint32_t per day | ||
#define hoursToLog 48 | ||
|
||
Memory to store 48 hours = 96 bytes | ||
Memory to store 7 days = 28 bytes | ||
// Here for convience and to avoid magic numbers. | ||
uint16_t secondsPerHour = 3600; | ||
|
||
// 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; | ||
} airtimes; | ||
|
||
*/ | ||
|
||
void logTXairtime(uint32_t airtime_ms) | ||
void logAirtime(reportTypes reportType, uint32_t airtime_ms) | ||
{ | ||
/* | ||
currentHourIndexReset(); | ||
|
||
How many hours since power up? | ||
if (reportType == TX_LOG) { | ||
airtimes.hourTX[currentHourIndex()] = airtimes.hourTX[currentHourIndex()] + round(airtime_ms / 1000); | ||
} else if (reportType == RX_LOG) { | ||
airtimes.hourRX[currentHourIndex()] = airtimes.hourRX[currentHourIndex()] + round(airtime_ms / 1000); | ||
} else if (reportType == RX_ALL_LOG) { | ||
airtimes.hourRX_ALL[currentHourIndex()] = airtimes.hourRX_ALL[currentHourIndex()] + round(airtime_ms / 1000); | ||
} else { | ||
// Unknown report type | ||
|
||
} | ||
} | ||
|
||
Millis / 1000 / 3600 | ||
// This will let us easily switch away from using millis at some point. | ||
// todo: Don't use millis, instead maintain our own count of time since | ||
// boot in seconds. | ||
uint32_t secondsSinceBoot() | ||
{ | ||
return millis() / 1000; | ||
} | ||
|
||
uint8_t currentHourIndex() | ||
{ | ||
// return ((secondsSinceBoot() - (secondsSinceBoot() / (hoursToLog * secondsPerHour))) / secondsPerHour); | ||
return ((secondsSinceBoot() / secondsPerHour) % hoursToLog); | ||
} | ||
|
||
// currentHourIndexReset() should be called every time we receive a packet to log (either RX or TX) | ||
// and every time we are asked to report on airtime usage. | ||
void currentHourIndexReset() | ||
{ | ||
if (airtimes.lastHourIndex != currentHourIndex()) { | ||
airtimes.hourTX[currentHourIndex()] = 0; | ||
airtimes.hourRX[currentHourIndex()] = 0; | ||
airtimes.hourRX_ALL[currentHourIndex()] = 0; | ||
|
||
*/ | ||
airtimes.lastHourIndex = currentHourIndex(); | ||
} | ||
} | ||
|
||
void logRXairtime() | ||
uint16_t *airtimeReport(reportTypes reportType) | ||
{ | ||
/* | ||
static uint16_t array[hoursToLog]; | ||
|
||
*/ | ||
} | ||
currentHourIndexReset(); | ||
|
||
for (int i = 0; i < hoursToLog; i++) { | ||
if (reportType == TX_LOG) { | ||
array[i] = airtimes.hourTX[(airtimes.lastHourIndex + i) % hoursToLog]; | ||
} else if (reportType == RX_LOG) { | ||
array[i] = airtimes.hourRX[(airtimes.lastHourIndex + i) % hoursToLog]; | ||
} else if (reportType == RX_ALL_LOG) { | ||
array[i] = airtimes.hourRX_ALL[(airtimes.lastHourIndex + i) % hoursToLog]; | ||
} else { | ||
// Unknown report type | ||
return array; | ||
} | ||
} | ||
|
||
return array; | ||
} |
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