mirror of
https://github.com/MrUnknownDE/OpenIris-ESPIDF.git
synced 2026-04-16 21:13:44 +02:00
Rewrite commands to nlohmann-json
This commit is contained in:
@@ -50,14 +50,24 @@ void SerialManager::try_receive()
|
||||
data[current_position] = '\0';
|
||||
current_position = 0;
|
||||
|
||||
const auto result = this->commandManager->executeFromJson(std::string_view(reinterpret_cast<const char *>(this->data)));
|
||||
const auto resultMessage = result.getResult();
|
||||
int written = usb_serial_jtag_write_bytes(resultMessage.c_str(), resultMessage.length(), 1000 / 20);
|
||||
(void)written; // ignore errors if driver already uninstalled
|
||||
const nlohmann::json result = this->commandManager->executeFromJson(std::string_view(reinterpret_cast<const char *>(this->data)));
|
||||
const auto resultMessage = result.dump();
|
||||
usb_serial_jtag_write_bytes_chunked(resultMessage.c_str(), resultMessage.length(), 1000 / 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SerialManager::usb_serial_jtag_write_bytes_chunked(const char *data, size_t len, size_t timeout)
|
||||
{
|
||||
while (len > 0)
|
||||
{
|
||||
auto to_write = len > BUF_SIZE ? BUF_SIZE : len;
|
||||
auto written = usb_serial_jtag_write_bytes(data, to_write, timeout);
|
||||
data += written;
|
||||
len -= written;
|
||||
}
|
||||
}
|
||||
|
||||
// Function to notify that a command was received during startup
|
||||
void SerialManager::notify_startup_command_received()
|
||||
{
|
||||
@@ -171,8 +181,8 @@ void HandleCDCSerialManagerTask(void *pvParameters)
|
||||
if (idx >= BUF_SIZE || buffer[idx - 1] == '\n' || buffer[idx - 1] == '\r')
|
||||
{
|
||||
buffer[idx - 1] = '\0';
|
||||
const auto result = commandManager->executeFromJson(std::string_view(reinterpret_cast<const char *>(buffer)));
|
||||
const auto resultMessage = result.getResult();
|
||||
const nlohmann::json result = commandManager->executeFromJson(std::string_view(reinterpret_cast<const char *>(buffer)));
|
||||
const auto resultMessage = result.dump();
|
||||
tud_cdc_write(resultMessage.c_str(), resultMessage.length());
|
||||
tud_cdc_write_flush();
|
||||
idx = 0;
|
||||
|
||||
@@ -41,6 +41,8 @@ public:
|
||||
void shutdown();
|
||||
|
||||
private:
|
||||
void usb_serial_jtag_write_bytes_chunked(const char *data, size_t len, size_t timeout);
|
||||
|
||||
std::shared_ptr<CommandManager> commandManager;
|
||||
esp_timer_handle_t *timerHandle;
|
||||
std::shared_ptr<ProjectConfig> deviceConfig;
|
||||
|
||||
Reference in New Issue
Block a user