Corrections on fragmenting/buffering for vfs/cmux

This commit is contained in:
David Cermak
2021-05-13 07:28:05 +02:00
parent 927ad418b6
commit 0d9b5dd8b7
21 changed files with 578 additions and 335 deletions

View File

@ -56,7 +56,7 @@ class CMuxInstance;
class CMux {
public:
explicit CMux(std::unique_ptr<Terminal> t, std::unique_ptr<uint8_t[]> b, size_t buff_size):
term(std::move(t)), buffer_size(buff_size), buffer(std::move(b)) {}
term(std::move(t)), buffer_size(buff_size), buffer(std::move(b)), payload_start(nullptr), total_payload_size(0) {}
~CMux() = default;
[[nodiscard]] bool init();
void set_read_cb(int inst, std::function<bool(uint8_t *data, size_t len)> f);
@ -64,7 +64,7 @@ public:
int write(int i, uint8_t *data, size_t len);
private:
std::function<bool(uint8_t *data, size_t len)> read_cb[max_terms];
void data_available(uint8_t *data, size_t len);
void data_available(uint8_t *data, size_t len, size_t payload_offset);
void send_sabm(size_t i);
std::unique_ptr<Terminal> term;
cmux_state state;
@ -80,6 +80,8 @@ private:
Lock lock;
int instance;
int sabm_ack;
uint8_t *payload_start;
size_t total_payload_size;
};

View File

@ -96,7 +96,7 @@ public:
command_result command(const std::string &command, got_line_cb got_line, uint32_t time_ms, char separator) override;
private:
static const size_t GOT_LINE = signal_group::bit0; /*!< Bit indicating response available */
static const size_t GOT_LINE = SignalGroup::bit0; /*!< Bit indicating response available */
[[nodiscard]] bool setup_cmux(); /*!< Internal setup of CMUX mode */
@ -108,7 +108,7 @@ private:
Terminal *command_term; /*!< Reference to the terminal used for sending commands */
std::unique_ptr<Terminal> other_term; /*!< Secondary terminal for this DTE */
modem_mode mode; /*!< DTE operation mode */
signal_group signal; /*!< Event group used to signal request-response operations */
SignalGroup signal; /*!< Event group used to signal request-response operations */
std::function<bool(uint8_t *data, size_t len)> on_data; /*!< on data callback for current terminal */
};

View File

@ -75,9 +75,9 @@ private:
std::shared_ptr<DTE> ppp_dte;
esp_netif_t *netif;
struct ppp_netif_driver driver{};
signal_group signal;
static const size_t PPP_STARTED = signal_group::bit0;
static const size_t PPP_EXIT = signal_group::bit1;
SignalGroup signal;
static const size_t PPP_STARTED = SignalGroup::bit0;
static const size_t PPP_EXIT = SignalGroup::bit1;
};
/**

View File

@ -18,6 +18,8 @@
#if defined(CONFIG_IDF_TARGET_LINUX)
#include <mutex>
#include <thread>
#else
// forward declarations of FreeRTOS primitives
struct QueueDefinition;
@ -27,10 +29,12 @@ typedef void * EventGroupHandle_t;
namespace esp_modem {
// Forward declaration for both linux/FreeRTOS targets
//
using TaskFunction_t = void (*)(void*);
#if !defined(CONFIG_IDF_TARGET_LINUX)
struct Lock {
using MutexT = QueueDefinition*;
explicit Lock();
~Lock();
void lock();
@ -38,13 +42,14 @@ struct Lock {
private:
MutexT m{};
};
using Signal = void*;
using TaskT = void*;
using SignalT = void*;
#else
using Lock = std::mutex;
struct SignalGroup;
using Signal = std::unique_ptr<SignalGroup>;
struct SignalGroupInternal;
using SignalT = std::unique_ptr<SignalGroupInternal>;
using TaskT = std::thread;
static constexpr uint32_t portMAX_DELAY = UINT32_MAX;
#endif
template<class T>
@ -57,13 +62,26 @@ private:
T& lock;
};
struct signal_group {
class Task {
public:
explicit Task(size_t stack_size, size_t priority, void *task_param, TaskFunction_t task_function);
~Task();
static void Delete();
static void Relinquish();
private:
TaskT task_handle;
};
class SignalGroup {
public:
static constexpr size_t bit0 = 1 << 0;
static constexpr size_t bit1 = 1 << 1;
static constexpr size_t bit2 = 1 << 2;
static constexpr size_t bit3 = 1 << 3;
explicit signal_group();
explicit SignalGroup();
void set(uint32_t bits);
@ -77,10 +95,10 @@ struct signal_group {
// waiting for any bit, not clearing them
bool wait_any(uint32_t flags, uint32_t time_ms);
~signal_group();
~SignalGroup();
private:
Signal event_group;
SignalT event_group;
};
} // namespace esp_modem