2020-12-25 06:12:59 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-01-01 20:31:46 +00:00
|
|
|
#include "concurrency/OSThread.h"
|
2020-12-25 06:12:59 +00:00
|
|
|
#include "configuration.h"
|
|
|
|
#include <Arduino.h>
|
|
|
|
#include <functional>
|
|
|
|
|
2020-12-27 17:29:48 +00:00
|
|
|
/*
|
|
|
|
TX_LOG - Time on air this device has transmitted
|
|
|
|
|
|
|
|
RX_LOG - Time on air used by valid and routable mesh packets, does not include
|
|
|
|
TX air time
|
|
|
|
|
|
|
|
RX_ALL_LOG - Time of all received lora packets. This includes packets that are not
|
|
|
|
for meshtastic devices. Does not include TX air time.
|
|
|
|
|
|
|
|
Example analytics:
|
|
|
|
|
|
|
|
TX_LOG + RX_LOG = Total air time for a perticular meshtastic channel.
|
|
|
|
|
|
|
|
TX_LOG + RX_LOG = Total air time for a perticular meshtastic channel, including
|
2021-01-01 20:31:46 +00:00
|
|
|
other lora radios.
|
2020-12-27 17:29:48 +00:00
|
|
|
|
|
|
|
RX_ALL_LOG - RX_LOG = Other lora radios on our frequency channel.
|
|
|
|
*/
|
2020-12-26 00:10:38 +00:00
|
|
|
|
2021-12-29 07:34:49 +00:00
|
|
|
#define CHANNEL_UTILIZATION_PERIODS 6
|
|
|
|
#define SECONDS_PER_PERIOD 3600
|
2022-03-03 04:38:14 +00:00
|
|
|
#define PERIODS_TO_LOG 8
|
2022-01-15 17:44:29 +00:00
|
|
|
#define MINUTES_IN_HOUR 60
|
2022-01-15 20:24:16 +00:00
|
|
|
#define SECONDS_IN_MINUTE 60
|
2022-11-26 19:50:00 +00:00
|
|
|
#define MS_IN_MINUTE (SECONDS_IN_MINUTE * 1000)
|
2022-01-15 20:24:16 +00:00
|
|
|
#define MS_IN_HOUR (MINUTES_IN_HOUR * SECONDS_IN_MINUTE * 1000)
|
|
|
|
|
2020-12-27 06:39:43 +00:00
|
|
|
|
2021-12-29 07:34:49 +00:00
|
|
|
enum reportTypes { TX_LOG, RX_LOG, RX_ALL_LOG };
|
2020-12-26 00:10:38 +00:00
|
|
|
|
2021-12-29 07:34:49 +00:00
|
|
|
void logAirtime(reportTypes reportType, uint32_t airtime_ms);
|
2020-12-26 00:10:38 +00:00
|
|
|
|
2021-01-15 02:40:18 +00:00
|
|
|
uint32_t *airtimeReport(reportTypes reportType);
|
2020-12-27 18:50:52 +00:00
|
|
|
|
2021-01-01 20:31:46 +00:00
|
|
|
class AirTime : private concurrency::OSThread
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
AirTime();
|
|
|
|
|
|
|
|
void logAirtime(reportTypes reportType, uint32_t airtime_ms);
|
2021-12-29 07:34:49 +00:00
|
|
|
float channelUtilizationPercent();
|
2022-01-15 17:44:29 +00:00
|
|
|
float utilizationTXPercent();
|
|
|
|
|
|
|
|
float UtilizationPercentTX();
|
2022-01-24 07:00:14 +00:00
|
|
|
uint32_t channelUtilization[CHANNEL_UTILIZATION_PERIODS] = {0};
|
|
|
|
uint32_t utilizationTX[MINUTES_IN_HOUR] = {0};
|
2021-12-29 07:34:49 +00:00
|
|
|
|
|
|
|
void airtimeRotatePeriod();
|
|
|
|
uint8_t getPeriodsToLog();
|
|
|
|
uint32_t getSecondsPerPeriod();
|
|
|
|
uint32_t getSecondsSinceBoot();
|
2021-12-29 08:45:36 +00:00
|
|
|
uint32_t *airtimeReport(reportTypes reportType);
|
2022-11-26 19:50:00 +00:00
|
|
|
uint8_t getSilentMinutes(float txPercent, float dutyCycle);
|
2021-12-29 07:34:49 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool firstTime = true;
|
|
|
|
uint8_t lastUtilPeriod = 0;
|
2022-01-15 17:44:29 +00:00
|
|
|
uint8_t lastUtilPeriodTX = 0;
|
2021-12-29 07:34:49 +00:00
|
|
|
uint32_t secSinceBoot = 0;
|
2021-01-01 20:31:46 +00:00
|
|
|
|
2021-12-29 08:45:36 +00:00
|
|
|
struct airtimeStruct {
|
|
|
|
uint32_t periodTX[PERIODS_TO_LOG]; // AirTime transmitted
|
|
|
|
uint32_t periodRX[PERIODS_TO_LOG]; // AirTime received and repeated (Only valid mesh packets)
|
|
|
|
uint32_t periodRX_ALL[PERIODS_TO_LOG]; // AirTime received regardless of valid mesh packet. Could include noise.
|
|
|
|
uint8_t lastPeriodIndex;
|
|
|
|
} airtimes;
|
|
|
|
|
2022-01-15 19:19:50 +00:00
|
|
|
uint8_t getPeriodUtilMinute();
|
|
|
|
uint8_t getPeriodUtilHour();
|
2022-01-15 23:27:25 +00:00
|
|
|
uint8_t currentPeriodIndex();
|
2022-01-15 19:19:50 +00:00
|
|
|
|
2021-01-01 20:31:46 +00:00
|
|
|
protected:
|
2021-03-21 14:44:08 +00:00
|
|
|
virtual int32_t runOnce() override;
|
2021-01-01 20:31:46 +00:00
|
|
|
};
|
|
|
|
|
2022-01-24 07:00:14 +00:00
|
|
|
extern AirTime *airTime;
|