diff --git a/src/airtime.cpp b/src/airtime.cpp index 9632181b..a8399fbc 100644 --- a/src/airtime.cpp +++ b/src/airtime.cpp @@ -17,27 +17,27 @@ uint32_t secSinceBoot = 0; // Don't read out of this directly. Use the helper functions. struct airtimeStruct { - uint16_t periodTX[periodsToLog]; - uint16_t periodRX[periodsToLog]; - uint16_t periodRX_ALL[periodsToLog]; + uint16_t periodTX[periodsToLog]; // AirTime transmitted + uint16_t periodRX[periodsToLog]; // AirTime received and repeated (Only valid mesh packets) + uint16_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) { - DEBUG_MSG("Packet - logAirtime()\n"); + // DEBUG_MSG("Packet - logAirtime()\n"); if (reportType == TX_LOG) { - DEBUG_MSG("Packet transmitted = %u\n", (uint32_t)round(airtime_ms / 1000)); + DEBUG_MSG("AirTime - Packet transmitted : %us %ums\n", (uint32_t)round((float)airtime_ms / (float)1000), airtime_ms); 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)); + DEBUG_MSG("AirTime - Packet received : %us %ums\n", (uint32_t)round((float)airtime_ms / (float)1000), airtime_ms); 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)); + DEBUG_MSG("AirTime - Packet received (noise?) : %us %ums\n", (uint32_t)round((float)airtime_ms / (float)1000), airtime_ms); airtimes.periodRX_ALL[0] = airtimes.periodRX_ALL[0] + round(airtime_ms / 1000); } else { - // Unknown report type + DEBUG_MSG("AirTime - Unknown report time. This should never happen!!\n"); } } @@ -67,7 +67,6 @@ void airtimeRotatePeriod() uint16_t *airtimeReport(reportTypes reportType) { - // currentHourIndexReset(); if (reportType == TX_LOG) { return airtimes.periodTX; @@ -98,10 +97,17 @@ AirTime::AirTime() : concurrency::OSThread("AirTime") {} int32_t AirTime::runOnce() { - DEBUG_MSG("AirTime::runOnce()\n"); + // DEBUG_MSG("AirTime::runOnce()\n"); airtimeRotatePeriod(); secSinceBoot++; - return 1000; + /* + This actually doesn't need to be run once per second but we currently use it for the + secSinceBoot counter. + + 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); } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index bf62e585..32704093 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,6 +21,7 @@ #include "main.h" #include "meshwifi/meshhttp.h" #include "meshwifi/meshwifi.h" +#include "meshwifi/WebServerThread.h" #include "sleep.h" #include "target_specific.h" #include diff --git a/src/meshwifi/WebServerThread.cpp b/src/meshwifi/WebServerThread.cpp new file mode 100644 index 00000000..dbb4a82f --- /dev/null +++ b/src/meshwifi/WebServerThread.cpp @@ -0,0 +1,14 @@ +#include "meshwifi/WebServerThread.h" +#include + +// Thread for the HTTP Server +WebServerThread webServerThread; + +WebServerThread::WebServerThread() : concurrency::OSThread("WebServerThread") {} + +int32_t WebServerThread::runOnce() +{ + DEBUG_MSG("WebServerThread::runOnce()\n"); + + return (1000 * 1); +} diff --git a/src/meshwifi/WebServerThread.h b/src/meshwifi/WebServerThread.h new file mode 100644 index 00000000..2f3b5510 --- /dev/null +++ b/src/meshwifi/WebServerThread.h @@ -0,0 +1,22 @@ +#pragma once + +#include "concurrency/OSThread.h" +#include "concurrency/Periodic.h" +#include +#include +#include "configuration.h" + + +class WebServerThread : private concurrency::OSThread +{ + + public: + WebServerThread(); + + + protected: + + virtual int32_t runOnce(); +}; + +extern WebServerThread webServerThread; \ No newline at end of file diff --git a/src/meshwifi/meshhttp.cpp b/src/meshwifi/meshhttp.cpp index 46fb1809..8814dc9d 100644 --- a/src/meshwifi/meshhttp.cpp +++ b/src/meshwifi/meshhttp.cpp @@ -49,6 +49,7 @@ HTTPServer *insecureServer; // Our API to handle messages to and from the radio. HttpAPI webAPI; + // Declare some handler functions for the various URLs on the server void handleAPIv1FromRadio(HTTPRequest *req, HTTPResponse *res); void handleAPIv1ToRadio(HTTPRequest *req, HTTPResponse *res); @@ -1213,13 +1214,3 @@ 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) -} diff --git a/src/meshwifi/meshhttp.h b/src/meshwifi/meshhttp.h index 3bcf2511..fc3e89f0 100644 --- a/src/meshwifi/meshhttp.h +++ b/src/meshwifi/meshhttp.h @@ -25,6 +25,8 @@ void handleJSONChatHistoryDummy(); void replaceAll(std::string &str, const std::string &from, const std::string &to); + +// Interface to the PhoneAPI to access the protobufs with messages class HttpAPI : public PhoneAPI { @@ -37,19 +39,3 @@ 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;