Worked on logging + some cleanup
This commit is contained in:
54
firmware/src/LoggingAPI.h
Normal file
54
firmware/src/LoggingAPI.h
Normal file
@@ -0,0 +1,54 @@
|
||||
#include "Dtypes.h"
|
||||
#include "MessageCodes.h"
|
||||
#include "Logger.h"
|
||||
#include "SwimTrackerConfig.h"
|
||||
|
||||
#include <ArduinoWebsockets.h>
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
|
||||
class LoggingAPI
|
||||
{
|
||||
public:
|
||||
void onClientConnect(websockets::WebsocketsClient &client) {}
|
||||
|
||||
bool handleMessage(websockets::WebsocketsClient &client, MessageCode code, const char *payload, size_t size) {
|
||||
switch(code) {
|
||||
case MessageCode::LOG_STREAMING_START:
|
||||
running_ = true;
|
||||
return true;
|
||||
case MessageCode::LOG_STREAMING_STOP:
|
||||
running_ = false;
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename TServer>
|
||||
void iteration(TServer &server)
|
||||
{
|
||||
const Logger * logger = Logger::getInstance();
|
||||
|
||||
if(running_)
|
||||
{
|
||||
StaticJsonDocument<1024> data;
|
||||
for (int i = 0; i < MAX_WEBSOCKET_CONNECTIONS; ++i)
|
||||
{
|
||||
auto &c = server.client(i);
|
||||
if (c.available())
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
lastOffset_ = logger->currentSize();
|
||||
}
|
||||
|
||||
private:
|
||||
bool running_ = false;
|
||||
size_t lastOffset_ = 0;
|
||||
};
|
||||
|
||||
@@ -15,6 +15,7 @@ enum class MessageCode : uint8_t
|
||||
WIFI_STATE_RESPONSE = 8,
|
||||
WIFI_SCAN_RESPONSE = 9,
|
||||
APP_LAYER_PING = 10,
|
||||
LOG_UPDATE = 11,
|
||||
|
||||
// from frontend to device
|
||||
START_SESSION = 128,
|
||||
@@ -25,4 +26,6 @@ enum class MessageCode : uint8_t
|
||||
WIFI_STATE_SET = 133,
|
||||
WIFI_STATE_GET = 134,
|
||||
WIFI_TRIGGER_SCAN = 135,
|
||||
LOG_STREAMING_START = 136,
|
||||
LOG_STREAMING_STOP = 137
|
||||
};
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
#include "Dtypes.h"
|
||||
#include "UserDB.h"
|
||||
#include "MessageCodes.h"
|
||||
#include "SwimTrackerConfig.h"
|
||||
|
||||
#include <ArduinoWebsockets.h>
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
|
||||
@@ -460,7 +460,6 @@ void setup()
|
||||
mdnsSetup(configuredHostname);
|
||||
|
||||
sessionManagerSetup();
|
||||
Logger::setNtpTime(sessionManager.getNtpTime());
|
||||
sessionManager.tare();
|
||||
|
||||
// HTTP & Websocket server
|
||||
|
||||
Reference in New Issue
Block a user