Partial work to migrate to OSThread model

1.2-legacy
Jm 2021-01-01 12:31:46 -08:00
rodzic 9587729bb0
commit 925829dc58
6 zmienionych plików z 91 dodań i 30 usunięć

Wyświetl plik

@ -3,6 +3,8 @@
#define periodsToLog 48
AirTime airTime;
// 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.
@ -11,6 +13,8 @@ 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 {
uint16_t periodTX[periodsToLog];
@ -19,14 +23,18 @@ struct airtimeStruct {
uint8_t lastPeriodIndex;
} airtimes;
void logAirtime(reportTypes reportType, uint32_t airtime_ms)
void AirTime::logAirtime(reportTypes reportType, uint32_t airtime_ms)
{
DEBUG_MSG("Packet - logAirtime()\n");
if (reportType == TX_LOG) {
DEBUG_MSG("Packet transmitted = %u\n", (uint32_t)round(airtime_ms / 1000));
airtimes.periodTX[0] = airtimes.periodTX[0] + round(airtime_ms / 1000);
} else if (reportType == RX_LOG) {
DEBUG_MSG("Packet received = %u\n", (uint32_t)round(airtime_ms / 1000));
airtimes.periodRX[0] = airtimes.periodRX[0] + round(airtime_ms / 1000);
} else if (reportType == RX_ALL_LOG) {
DEBUG_MSG("Packet received (noise?) = %u\n", (uint32_t)round(airtime_ms / 1000));
airtimes.periodRX_ALL[0] = airtimes.periodRX_ALL[0] + round(airtime_ms / 1000);
} else {
// Unknown report type
@ -38,23 +46,22 @@ uint8_t currentPeriodIndex()
return ((getSecondsSinceBoot() / secondsPerPeriod) % periodsToLog);
}
void airtimeCalculator()
void airtimeRotatePeriod()
{
if (millis() - lastMillis > 1000) {
lastMillis = millis();
secSinceBoot++;
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.periodTX[0] = 0;
airtimes.periodRX[0] = 0;
airtimes.periodRX_ALL[0] = 0;
airtimes.lastPeriodIndex = currentPeriodIndex();
if (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];
}
airtimes.periodTX[0] = 0;
airtimes.periodRX[0] = 0;
airtimes.periodRX_ALL[0] = 0;
airtimes.lastPeriodIndex = currentPeriodIndex();
}
}
@ -86,3 +93,15 @@ uint32_t getSecondsSinceBoot()
{
return secSinceBoot;
}
AirTime::AirTime() : concurrency::OSThread("AirTime") {}
int32_t AirTime::runOnce()
{
DEBUG_MSG("AirTime::runOnce()\n");
airtimeRotatePeriod();
secSinceBoot++;
return 1000;
}

Wyświetl plik

@ -1,5 +1,6 @@
#pragma once
#include "concurrency/OSThread.h"
#include "configuration.h"
#include <Arduino.h>
#include <functional>
@ -18,7 +19,7 @@
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
other lora radios.
other lora radios.
RX_ALL_LOG - RX_LOG = Other lora radios on our frequency channel.
*/
@ -26,7 +27,7 @@ enum reportTypes { TX_LOG, RX_LOG, RX_ALL_LOG };
void logAirtime(reportTypes reportType, uint32_t airtime_ms);
void airtimeCalculator();
void airtimeRotatePeriod();
uint8_t currentPeriodIndex();
uint8_t getPeriodsToLog();
@ -35,4 +36,19 @@ uint32_t getSecondsSinceBoot();
uint16_t *airtimeReport(reportTypes reportType);
uint32_t getSecondsPerPeriod();
uint32_t getSecondsPerPeriod();
class AirTime : private concurrency::OSThread
{
public:
AirTime();
void logAirtime(reportTypes reportType, uint32_t airtime_ms);
protected:
virtual int32_t runOnce();
};
extern AirTime airTime;

Wyświetl plik

@ -584,6 +584,4 @@ void loop()
mainDelay.delay(delayMsec);
// if (didWake) DEBUG_MSG("wake!\n");
// Handles cleanup for the airtime calculator.
airtimeCalculator();
}

Wyświetl plik

@ -97,7 +97,7 @@ ErrorCode RadioLibInterface::send(MeshPacket *p)
// Count the packet toward our TX airtime utilization.
// We only count it if it can be added to the TX queue.
logAirtime(TX_LOG, xmitMsec);
airTime.logAirtime(TX_LOG, xmitMsec);
// We want all sending/receiving to be done by our daemon thread, We use a delay here because this packet might have been sent
// in response to a packet we just received. So we want to make sure the other side has had a chance to reconfigure its radio
@ -216,7 +216,7 @@ void RadioLibInterface::handleReceiveInterrupt()
size_t length = iface->getPacketLength();
xmitMsec = getPacketTime(length);
logAirtime(RX_ALL_LOG, xmitMsec);
airTime.logAirtime(RX_ALL_LOG, xmitMsec);
int state = iface->readData(radiobuf, length);
if (state != ERR_NONE) {
@ -258,7 +258,7 @@ void RadioLibInterface::handleReceiveInterrupt()
printPacket("Lora RX", mp);
xmitMsec = getPacketTime(mp);
logAirtime(RX_LOG, xmitMsec);
airTime.logAirtime(RX_LOG, xmitMsec);
deliverToReceiver(mp);
}

Wyświetl plik

@ -808,10 +808,10 @@ void handleFormUpload(HTTPRequest *req, HTTPResponse *res)
return;
}
//if (readLength) {
file.write(buf, readLength);
fileLength += readLength;
DEBUG_MSG("File Length %i\n", fileLength);
// if (readLength) {
file.write(buf, readLength);
fileLength += readLength;
DEBUG_MSG("File Length %i\n", fileLength);
//}
}
// enableLoopWDT();
@ -988,7 +988,8 @@ void handleRoot(HTTPRequest *req, HTTPResponse *res)
res->printf("<p></p>\n");
res->printf("<p>You have gotten this error because the filesystem for the web server has not been loaded.</p>\n");
res->printf("<p>Please review the 'Common Problems' section of the <a "
"href=https://github.com/meshtastic/Meshtastic-device/wiki/How-to-use-the-Meshtastic-Web-Interface-over-WiFi>web interface</a> documentation.</p>\n");
"href=https://github.com/meshtastic/Meshtastic-device/wiki/"
"How-to-use-the-Meshtastic-Web-Interface-over-WiFi>web interface</a> documentation.</p>\n");
return;
}
@ -1212,3 +1213,13 @@ void replaceAll(std::string &str, const std::string &from, const std::string &to
start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx'
}
}
HttpServer::HttpServer() : concurrency::OSThread("HttpServer") {
DEBUG_MSG("22**********************************\n");
}
int32_t HttpServer::runOnce()
{
DEBUG_MSG("11**********************************\n");
return 200; // Poll our GPIOs every 200ms (FIXME, make adjustable via protobuf arg)
}

Wyświetl plik

@ -1,6 +1,7 @@
#pragma once
#include "PhoneAPI.h"
#include "concurrency/OSThread.h"
#include <Arduino.h>
#include <functional>
@ -22,7 +23,7 @@ void handleRoot();
void handleScriptsScriptJS();
void handleJSONChatHistoryDummy();
void replaceAll(std::string& str, const std::string& from, const std::string& to);
void replaceAll(std::string &str, const std::string &from, const std::string &to);
class HttpAPI : public PhoneAPI
{
@ -35,4 +36,20 @@ class HttpAPI : public PhoneAPI
protected:
// Nothing here yet
};
};
/**
* A plugin that provides easy low-level remote access to device hardware.
*/
class HttpServer : public concurrency::OSThread
{
public:
// Nothing here
// RemoteHardwarePlugin();
HttpServer();
protected:
virtual int32_t runOnce();
};
// extern HttpServer httpServer;