mirror of
https://github.com/BotChain-Robots/firmware.git
synced 2026-07-08 09:37:21 +02:00
OTA + remote logging + profiling
This commit is contained in:
51
main/RemoteDebugging.cpp
Normal file
51
main/RemoteDebugging.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include "RemoteDebugging.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
|
||||
std::string RemoteDebugging::get_task_manager() {
|
||||
std::string out;
|
||||
out.resize(1024);
|
||||
vTaskGetRunTimeStats(out.data());
|
||||
out.resize(425);
|
||||
return out;
|
||||
}
|
||||
|
||||
std::string RemoteDebugging::get_logs() {
|
||||
std::string out;
|
||||
for (const auto& log : log_buffer->peek_drain()) {
|
||||
out.append(log);
|
||||
}
|
||||
out.resize(800);
|
||||
return out;
|
||||
}
|
||||
|
||||
void RemoteDebugging::register_calls(MessagingInterface &messaging_interface) {
|
||||
messaging_interface.register_function(2, [](const uint8_t *parameters, size_t parameter_size, Writer& writer) {
|
||||
auto out = get_task_manager();
|
||||
std::vector<uint8_t> vec(out.begin(), out.end());
|
||||
writer.write(vec);
|
||||
});
|
||||
messaging_interface.register_function(3, [](const uint8_t *parameters, size_t parameter_size, Writer& writer) {
|
||||
auto out = get_logs();
|
||||
std::vector<uint8_t> vec(out.begin(), out.end());
|
||||
writer.write(vec);
|
||||
});
|
||||
}
|
||||
|
||||
int RemoteDebugging::custom_log_write(const char *data, va_list args) {
|
||||
char tmp[512];
|
||||
|
||||
va_list copy;
|
||||
va_copy(copy, args);
|
||||
int len = vsnprintf(tmp, sizeof(tmp), data, copy);
|
||||
va_end(copy);
|
||||
|
||||
std::string str;
|
||||
str.assign(tmp, len);
|
||||
std::cout << str;
|
||||
log_buffer->push(std::move(str));
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user