CMUX: Experimental implementation

This commit is contained in:
David Cermak
2021-03-04 20:19:18 +01:00
parent 25f5541199
commit fbb4791af1
19 changed files with 631 additions and 170 deletions

View File

@ -2,11 +2,18 @@
#include <string.h>
#include "esp_log.h"
DTE::DTE(std::unique_ptr<terminal> terminal):
DTE::DTE(std::unique_ptr<Terminal> terminal):
buffer_size(DTE_BUFFER_SIZE), consumed(0),
// buffer(std::make_shared<std::vector<uint8_t>>(buffer_size)),
// buffer(new uint8_t[buffer_size], std::default_delete<uint8_t[]>()),
// buffer(new uint8_t[buffer_size], std::default_delete<uint8_t[]>()),
// buffer(nullptr),
buffer(std::make_unique<uint8_t[]>(buffer_size)),
term(std::move(terminal)), mode(dte_mode::UNDEF) {}
term(std::move(terminal)), mode(dte_mode::UNDEF)
{
// buffer = new std::shared_ptr<uint8_t[]>(buffer_size, [](uint8_t p[]){ delete[] p;});
}
command_result DTE::command(const std::string& command, got_line_cb got_line, uint32_t time_ms)
{
@ -18,11 +25,14 @@ command_result DTE::command(const std::string& command, got_line_cb got_line, ui
auto actual_len = term->read(data, data_to_read);
consumed += actual_len;
if (memchr(data, '\n', actual_len)) {
// ESP_LOGE("GOT", "LINE");
res = got_line(buffer.get(), consumed);
if (res == command_result::OK || res == command_result::FAIL) {
signal.set(GOT_LINE);
return true;
}
}
return false;
});
auto got_lf = signal.wait(GOT_LINE, time_ms);
if (got_lf && res == command_result::TIMEOUT) {