RMT running in integration

This commit is contained in:
2025-07-12 23:33:54 -04:00
parent a6b8b57a3b
commit 3d85ae97a6
6 changed files with 37 additions and 25 deletions

View File

@@ -9,6 +9,7 @@
#include <functional>
#include <memory>
#include <chrono>
#include <WifiManager.h>
#include "freertos/FreeRTOS.h"
@@ -29,21 +30,23 @@ class CommunicationRouter {
};
public:
explicit CommunicationRouter(const std::function<void(char*, int)> &rx_callback)
CommunicationRouter(const std::function<void(char*, int)> &rx_callback, std::unique_ptr<WifiManager>&& pc_connection)
: m_tcp_rx_queue(std::make_shared<PtrQueue<std::vector<uint8_t>>>(10)),
m_rx_callback(rx_callback),
m_tcp_server(std::make_unique<TCPServer>(TCP_PORT, m_tcp_rx_queue)),
m_data_link_manager(std::make_unique<DataLinkManager>(ConfigManager::get_module_id(), MODULE_TO_NUM_CHANNELS_MAP[ConfigManager::get_module_type()])),
m_pc_connection(std::move(pc_connection)),
m_module_id(ConfigManager::get_module_id()),
m_last_leader_updated(std::chrono::system_clock::now()){
update_leader();
xTaskCreate(router_thread, "communication_router", 2048, this, 3, &this->m_router_thread);
const auto num_channels = MODULE_TO_NUM_CHANNELS_MAP[ConfigManager::get_module_id()];
const auto num_channels = MODULE_TO_NUM_CHANNELS_MAP[ConfigManager::get_module_type()];
this->m_link_layer_threads.resize(num_channels);
for (uint8_t i = 0; i < num_channels; i++) {
auto *params = new link_layer_thread_params(this, i);
xTaskCreate(link_layer_thread, "communication_router_rmt", 2048, &params, 3, &this->m_link_layer_threads[i]);
xTaskCreate(link_layer_thread, "communication_router_rmt", 3096, params, 3, &this->m_link_layer_threads[i]);
}
}
@@ -66,7 +69,8 @@ private:
std::vector<TaskHandle_t> m_link_layer_threads;
std::unique_ptr<TCPServer> m_tcp_server;
std::unique_ptr<DataLinkManager> m_data_link_manager;
uint8_t m_leader;
std::unique_ptr<WifiManager> m_pc_connection; // todo: change to dependency inject
uint8_t m_leader = 0;
uint8_t m_module_id;
std::chrono::time_point<std::chrono::system_clock> m_last_leader_updated;
};

View File

@@ -13,9 +13,9 @@
class MessagingInterface {
public:
MessagingInterface()
explicit MessagingInterface(std::unique_ptr<WifiManager>&& pc_connection)
: m_mpi_rx_queue(xQueueCreate(MAX_RX_BUFFER_SIZE, RX_QUEUE_SIZE)),
m_router(std::make_unique<CommunicationRouter>([this](char* buffer, const int size) { handleRecv(buffer, size); })),
m_router(std::make_unique<CommunicationRouter>([this](char* buffer, const int size) { handleRecv(buffer, size); }, std::move(pc_connection))),
m_map_semaphore(xSemaphoreCreateMutex()) {};
~MessagingInterface();