Skip to content

Commit

Permalink
Merge pull request #1 from meshtastic/master
Browse files Browse the repository at this point in the history
Pull master
  • Loading branch information
linagee authored Dec 30, 2021
2 parents a534eae + 41dcfdd commit 0a4659b
Show file tree
Hide file tree
Showing 14 changed files with 146 additions and 159 deletions.
38 changes: 0 additions & 38 deletions bin/build-nightly.sh

This file was deleted.

6 changes: 3 additions & 3 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
; https://docs.platformio.org/page/projectconf.html

[platformio]
;default_envs = tbeam
default_envs = tbeam
;default_envs = tbeam0.7
;default_envs = heltec-v2.0
;default_envs = tlora-v1
Expand All @@ -21,7 +21,7 @@
;default_envs = native # lora-relay-v1 # nrf52840dk-geeksville # linux # or if you'd like to change the default to something like lora-relay-v1 put that here
;default_envs = rak4631
;default_envs = rak4630
default_envs = meshtastic-diy-v1
;default_envs = meshtastic-diy-v1

[common]
; common is not currently used
Expand Down Expand Up @@ -124,7 +124,7 @@ platform_packages =
framework-arduinoespressif32@https://github.com/meshtastic/arduino-esp32.git#4cde0f5d412d2695184f32e8a47e9bea57b45276

; leave this commented out to avoid breaking Windows
upload_port = /dev/ttyUSB0
;upload_port = /dev/ttyUSB0
;monitor_port = /dev/ttyUSB0

;upload_port = /dev/cu.SLAB_USBtoUART
Expand Down
2 changes: 1 addition & 1 deletion proto
Submodule proto updated from c52c8e to 1d3b48
120 changes: 69 additions & 51 deletions src/airtime.cpp
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);
}
34 changes: 26 additions & 8 deletions src/airtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,46 @@
RX_ALL_LOG - RX_LOG = Other lora radios on our frequency channel.
*/
enum reportTypes { TX_LOG, RX_LOG, RX_ALL_LOG };

void logAirtime(reportTypes reportType, uint32_t airtime_ms);
#define CHANNEL_UTILIZATION_PERIODS 6
#define SECONDS_PER_PERIOD 3600
#define PERIODS_TO_LOG 24

void airtimeRotatePeriod();

uint8_t currentPeriodIndex();
uint8_t getPeriodsToLog();
enum reportTypes { TX_LOG, RX_LOG, RX_ALL_LOG };

uint32_t getSecondsSinceBoot();
void logAirtime(reportTypes reportType, uint32_t airtime_ms);

uint32_t *airtimeReport(reportTypes reportType);

uint32_t getSecondsPerPeriod();

class AirTime : private concurrency::OSThread
{

public:
AirTime();

void logAirtime(reportTypes reportType, uint32_t airtime_ms);
float channelUtilizationPercent();
uint32_t channelUtilization[CHANNEL_UTILIZATION_PERIODS];

uint8_t currentPeriodIndex();
void airtimeRotatePeriod();
uint8_t getPeriodsToLog();
uint32_t getSecondsPerPeriod();
uint32_t getSecondsSinceBoot();
uint32_t *airtimeReport(reportTypes reportType);

private:
bool firstTime = true;
uint8_t lastUtilPeriod = 0;
uint32_t secSinceBoot = 0;

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;

protected:
virtual int32_t runOnce() override;
Expand Down
15 changes: 5 additions & 10 deletions src/graphics/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,11 +619,6 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_
n = nodeDB.getNodeByIndex(nodeIndex);
}
displayedNodeNum = n->num;

// We just changed to a new node screen, ask that node for updated state if it's older than 2 minutes
if (sinceLastSeen(n) > 120) {
service.sendNetworkPing(displayedNodeNum, true);
}
}

NodeInfo *node = nodeDB.getNodeByIndex(nodeIndex);
Expand Down Expand Up @@ -1403,11 +1398,11 @@ void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *stat

display->drawString(x, y + FONT_HEIGHT_SMALL * 1, uptime);

#ifndef NO_ESP32
// Show CPU Frequency.
display->drawString(x + SCREEN_WIDTH - display->getStringWidth("CPU " + String(getCpuFrequencyMhz()) + "MHz"),
y + FONT_HEIGHT_SMALL * 1, "CPU " + String(getCpuFrequencyMhz()) + "MHz");
#endif
// Display Channel Utilization
char chUtil[13];
sprintf(chUtil, "ChUtil %2.0f%%", airTime->channelUtilizationPercent());
display->drawString(x + SCREEN_WIDTH - display->getStringWidth(chUtil),
y + FONT_HEIGHT_SMALL * 1, chUtil);

// Line 3
if (radioConfig.preferences.gps_format != GpsCoordinateFormat_GpsFormatDMS) // if DMS then don't draw altitude
Expand Down
2 changes: 1 addition & 1 deletion src/mesh/generated/admin.pb.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ extern const pb_msgdesc_t AdminMessage_msg;
#define AdminMessage_fields &AdminMessage_msg

/* Maximum encoded size of messages (where known) */
#define AdminMessage_size 461
#define AdminMessage_size 529

#ifdef __cplusplus
} /* extern "C" */
Expand Down
2 changes: 1 addition & 1 deletion src/mesh/generated/deviceonly.pb.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ extern const pb_msgdesc_t ChannelFile_msg;
/* Maximum encoded size of messages (where known) */
#define LegacyRadioConfig_size 4
#define LegacyRadioConfig_LegacyPreferences_size 2
#define DeviceState_size 9943
#define DeviceState_size 9967
#define ChannelFile_size 832

#ifdef __cplusplus
Expand Down
Loading

0 comments on commit 0a4659b

Please sign in to comment.