Log streaming over websocket activated

This commit is contained in:
Martin Bauer 2023-09-08 10:26:49 +02:00
parent 149fb4fb03
commit 21ce6d5870
3 changed files with 22 additions and 17 deletions

View File

@ -64,6 +64,7 @@ public:
}
else
return false;
return true;
}
static Logger *getInstance();
@ -107,6 +108,6 @@ private:
Logger();
char *data_;
size_t totalSize_;
size_t currentSize_;
size_t totalSize_ = 0;
size_t currentSize_ = 0;
};

View File

@ -42,4 +42,5 @@ platform = native
test_ignore = test_embedded
build_flags = -g -DPLATFORM_NATIVE -std=c++17 -O0
build_src_filter = +<*> -<firmware_main.cpp> -<WifiManager.cpp> -<WifiAPI.cpp>
lib_compat_mode = off
lib_compat_mode = off

View File

@ -16,6 +16,11 @@ class LoggingAPI
switch(code) {
case MessageCode::LOG_STREAMING_START:
running_ = true;
if(firstCall_) {
const Logger * logger = Logger::getInstance();
lastEnd_ = logger->begin();
firstCall_ = false;
}
return true;
case MessageCode::LOG_STREAMING_STOP:
running_ = false;
@ -28,27 +33,25 @@ class LoggingAPI
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())
{
}
const Logger * logger = Logger::getInstance();
const auto beginIt = lastEnd_;
const auto endIt = logger->end();
StaticJsonDocument<512> data;
for(auto it = beginIt; it != endIt; ++beginIt) {
data["time"] = it.time_millis();
data["msg"] = it.message();
server.template sendToAll<512>(MessageCode::LOG_UPDATE, data);
}
lastEnd_ = endIt;
}
lastOffset_ = logger->currentSize();
}
private:
bool running_ = false;
size_t lastOffset_ = 0;
Logger::iterator lastEnd_;
bool firstCall_ = false;
};