sforkowany z mirror/meshtastic-firmware
Partial work to migrate to OSThread model
rodzic
9587729bb0
commit
925829dc58
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
#define periodsToLog 48
|
#define periodsToLog 48
|
||||||
|
|
||||||
|
AirTime airTime;
|
||||||
|
|
||||||
// A reminder that there are 3600 seconds in an hour so I don't have
|
// A reminder that there are 3600 seconds in an hour so I don't have
|
||||||
// to keep googling it.
|
// to keep googling it.
|
||||||
// This can be changed to a smaller number to speed up testing.
|
// 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 lastMillis = 0;
|
||||||
uint32_t secSinceBoot = 0;
|
uint32_t secSinceBoot = 0;
|
||||||
|
|
||||||
|
// AirTime at;
|
||||||
|
|
||||||
// Don't read out of this directly. Use the helper functions.
|
// Don't read out of this directly. Use the helper functions.
|
||||||
struct airtimeStruct {
|
struct airtimeStruct {
|
||||||
uint16_t periodTX[periodsToLog];
|
uint16_t periodTX[periodsToLog];
|
||||||
|
@ -19,14 +23,18 @@ struct airtimeStruct {
|
||||||
uint8_t lastPeriodIndex;
|
uint8_t lastPeriodIndex;
|
||||||
} airtimes;
|
} 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) {
|
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);
|
airtimes.periodTX[0] = airtimes.periodTX[0] + round(airtime_ms / 1000);
|
||||||
} else if (reportType == RX_LOG) {
|
} 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);
|
airtimes.periodRX[0] = airtimes.periodRX[0] + round(airtime_ms / 1000);
|
||||||
} else if (reportType == RX_ALL_LOG) {
|
} 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);
|
airtimes.periodRX_ALL[0] = airtimes.periodRX_ALL[0] + round(airtime_ms / 1000);
|
||||||
} else {
|
} else {
|
||||||
// Unknown report type
|
// Unknown report type
|
||||||
|
@ -38,23 +46,22 @@ uint8_t currentPeriodIndex()
|
||||||
return ((getSecondsSinceBoot() / secondsPerPeriod) % periodsToLog);
|
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;
|
return secSinceBoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AirTime::AirTime() : concurrency::OSThread("AirTime") {}
|
||||||
|
|
||||||
|
int32_t AirTime::runOnce()
|
||||||
|
{
|
||||||
|
DEBUG_MSG("AirTime::runOnce()\n");
|
||||||
|
|
||||||
|
airtimeRotatePeriod();
|
||||||
|
secSinceBoot++;
|
||||||
|
|
||||||
|
return 1000;
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "concurrency/OSThread.h"
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
@ -26,7 +27,7 @@ enum reportTypes { TX_LOG, RX_LOG, RX_ALL_LOG };
|
||||||
|
|
||||||
void logAirtime(reportTypes reportType, uint32_t airtime_ms);
|
void logAirtime(reportTypes reportType, uint32_t airtime_ms);
|
||||||
|
|
||||||
void airtimeCalculator();
|
void airtimeRotatePeriod();
|
||||||
|
|
||||||
uint8_t currentPeriodIndex();
|
uint8_t currentPeriodIndex();
|
||||||
uint8_t getPeriodsToLog();
|
uint8_t getPeriodsToLog();
|
||||||
|
@ -36,3 +37,18 @@ uint32_t getSecondsSinceBoot();
|
||||||
uint16_t *airtimeReport(reportTypes reportType);
|
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;
|
|
@ -584,6 +584,4 @@ void loop()
|
||||||
mainDelay.delay(delayMsec);
|
mainDelay.delay(delayMsec);
|
||||||
// if (didWake) DEBUG_MSG("wake!\n");
|
// if (didWake) DEBUG_MSG("wake!\n");
|
||||||
|
|
||||||
// Handles cleanup for the airtime calculator.
|
|
||||||
airtimeCalculator();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,7 @@ ErrorCode RadioLibInterface::send(MeshPacket *p)
|
||||||
|
|
||||||
// Count the packet toward our TX airtime utilization.
|
// Count the packet toward our TX airtime utilization.
|
||||||
// We only count it if it can be added to the TX queue.
|
// 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
|
// 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
|
// 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();
|
size_t length = iface->getPacketLength();
|
||||||
|
|
||||||
xmitMsec = getPacketTime(length);
|
xmitMsec = getPacketTime(length);
|
||||||
logAirtime(RX_ALL_LOG, xmitMsec);
|
airTime.logAirtime(RX_ALL_LOG, xmitMsec);
|
||||||
|
|
||||||
int state = iface->readData(radiobuf, length);
|
int state = iface->readData(radiobuf, length);
|
||||||
if (state != ERR_NONE) {
|
if (state != ERR_NONE) {
|
||||||
|
@ -258,7 +258,7 @@ void RadioLibInterface::handleReceiveInterrupt()
|
||||||
printPacket("Lora RX", mp);
|
printPacket("Lora RX", mp);
|
||||||
|
|
||||||
xmitMsec = getPacketTime(mp);
|
xmitMsec = getPacketTime(mp);
|
||||||
logAirtime(RX_LOG, xmitMsec);
|
airTime.logAirtime(RX_LOG, xmitMsec);
|
||||||
|
|
||||||
deliverToReceiver(mp);
|
deliverToReceiver(mp);
|
||||||
}
|
}
|
||||||
|
|
|
@ -808,10 +808,10 @@ void handleFormUpload(HTTPRequest *req, HTTPResponse *res)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (readLength) {
|
// if (readLength) {
|
||||||
file.write(buf, readLength);
|
file.write(buf, readLength);
|
||||||
fileLength += readLength;
|
fileLength += readLength;
|
||||||
DEBUG_MSG("File Length %i\n", fileLength);
|
DEBUG_MSG("File Length %i\n", fileLength);
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
// enableLoopWDT();
|
// enableLoopWDT();
|
||||||
|
@ -988,7 +988,8 @@ void handleRoot(HTTPRequest *req, HTTPResponse *res)
|
||||||
res->printf("<p></p>\n");
|
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>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 "
|
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;
|
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'
|
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)
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "PhoneAPI.h"
|
#include "PhoneAPI.h"
|
||||||
|
#include "concurrency/OSThread.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
@ -22,7 +23,7 @@ void handleRoot();
|
||||||
void handleScriptsScriptJS();
|
void handleScriptsScriptJS();
|
||||||
void handleJSONChatHistoryDummy();
|
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
|
class HttpAPI : public PhoneAPI
|
||||||
{
|
{
|
||||||
|
@ -36,3 +37,19 @@ class HttpAPI : public PhoneAPI
|
||||||
protected:
|
protected:
|
||||||
// Nothing here yet
|
// 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;
|
||||||
|
|
Ładowanie…
Reference in New Issue