mirror of
https://github.com/BotChain-Robots/firmware.git
synced 2026-07-08 17:47:21 +02:00
Communication router fixes
This commit is contained in:
@@ -24,17 +24,8 @@ CommunicationRouter::~CommunicationRouter() {
|
|||||||
const auto that = static_cast<CommunicationRouter *>(args);
|
const auto that = static_cast<CommunicationRouter *>(args);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
// todo: strange to have this here, but i dont want 4 threads calling it or a thread just for it.
|
|
||||||
if (std::chrono::system_clock::now() - that->m_last_leader_updated > std::chrono::seconds(15)) {
|
|
||||||
that->update_leader();
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto buffer = that->m_tcp_rx_queue->dequeue();
|
const auto buffer = that->m_tcp_rx_queue->dequeue();
|
||||||
|
that->route(buffer->data(), buffer->size());
|
||||||
std::cout << "dequeued buffer" << std::endl;
|
|
||||||
|
|
||||||
that->m_rx_callback(reinterpret_cast<char *>(buffer->data()), buffer->size());
|
|
||||||
std::cout << "WiFi callback" << std::endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,13 +43,18 @@ CommunicationRouter::~CommunicationRouter() {
|
|||||||
const auto err = that->m_data_link_manager->receive(reinterpret_cast<uint8_t *>(buffer), 512, &bytes_received, channel);
|
const auto err = that->m_data_link_manager->receive(reinterpret_cast<uint8_t *>(buffer), 512, &bytes_received, channel);
|
||||||
that->m_data_link_manager->start_receive_frames(channel);
|
that->m_data_link_manager->start_receive_frames(channel);
|
||||||
|
|
||||||
if (ESP_OK != err) {
|
// todo: do we only want one thread ever doing this?
|
||||||
|
if (std::chrono::system_clock::now() - that->m_last_leader_updated > std::chrono::seconds(15)) {
|
||||||
|
that->m_last_leader_updated = std::chrono::system_clock::now();
|
||||||
|
std::cout << "Updating leader" << std::endl;
|
||||||
|
that->update_leader();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ESP_OK != err || bytes_received < 1) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
that->route(reinterpret_cast<uint8_t *>(buffer), bytes_received);
|
that->route(reinterpret_cast<uint8_t *>(buffer), bytes_received);
|
||||||
|
|
||||||
std::cout << "RMT callback" << std::endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +75,7 @@ void CommunicationRouter::update_leader() {
|
|||||||
for (int i = 0; i < table_size; i++) {
|
for (int i = 0; i < table_size; i++) {
|
||||||
const auto id = table[i].info.board_id;
|
const auto id = table[i].info.board_id;
|
||||||
connected_module_ids.emplace_back(id);
|
connected_module_ids.emplace_back(id);
|
||||||
if (max > id) {
|
if (id > max) { // todo: change this to be correct
|
||||||
max = id;
|
max = id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,18 +94,22 @@ void CommunicationRouter::update_leader() {
|
|||||||
if (this->m_leader == m_module_id) {
|
if (this->m_leader == m_module_id) {
|
||||||
mDNSDiscoveryService::set_connected_boards(connected_module_ids);
|
mDNSDiscoveryService::set_connected_boards(connected_module_ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->m_last_leader_updated = std::chrono::system_clock::now();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommunicationRouter::route(uint8_t* buffer, const size_t length) const {
|
void CommunicationRouter::route(uint8_t* buffer, const size_t length) const {
|
||||||
const auto& mpi_message = Flatbuffers::MPIMessageBuilder::parse_mpi_message(buffer);
|
const auto& mpi_message = Flatbuffers::MPIMessageBuilder::parse_mpi_message(buffer);
|
||||||
|
|
||||||
if (mpi_message->destination() == m_module_id) {
|
if (mpi_message->destination() == m_module_id) {
|
||||||
|
std::cout << "Routing to this module [dest:" << static_cast<int>(mpi_message->destination()) << ", length: " << length << "]" << std::endl;
|
||||||
this->m_rx_callback(reinterpret_cast<char *>(buffer), 512);
|
this->m_rx_callback(reinterpret_cast<char *>(buffer), 512);
|
||||||
} else if (mpi_message->destination() == PC_ADDR && this->m_leader == m_module_id) {
|
} else if (mpi_message->destination() == PC_ADDR && this->m_leader == m_module_id) {
|
||||||
|
std::cout << "Routing to wifi [dest:" << static_cast<int>(mpi_message->destination()) << ", length: " << length << "]" << std::endl;
|
||||||
this->m_tcp_server->send_msg(reinterpret_cast<char *>(buffer), 512);
|
this->m_tcp_server->send_msg(reinterpret_cast<char *>(buffer), 512);
|
||||||
|
} else if (mpi_message->destination() == PC_ADDR) {
|
||||||
|
std::cout << "Routing to wireline for wifi [dest:" << static_cast<int>(mpi_message->destination()) << ", length: " << length << "]" << std::endl;
|
||||||
|
this->m_data_link_manager->send(this->m_leader, buffer, length, FrameType::MOTOR_TYPE, 0);
|
||||||
}else {
|
}else {
|
||||||
|
std::cout << "Routing to wireline [dest:" << static_cast<int>(mpi_message->destination()) << ", length: " << length << "]" << std::endl;
|
||||||
this->m_data_link_manager->send(mpi_message->destination(), buffer, length, FrameType::MOTOR_TYPE, 0);
|
this->m_data_link_manager->send(mpi_message->destination(), buffer, length, FrameType::MOTOR_TYPE, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,13 +40,13 @@ public:
|
|||||||
m_last_leader_updated(std::chrono::system_clock::now()){
|
m_last_leader_updated(std::chrono::system_clock::now()){
|
||||||
update_leader();
|
update_leader();
|
||||||
|
|
||||||
xTaskCreate(router_thread, "communication_router", 2048, this, 3, &this->m_router_thread);
|
xTaskCreate(router_thread, "communication_router", 4096, this, 3, &this->m_router_thread);
|
||||||
|
|
||||||
const auto num_channels = MODULE_TO_NUM_CHANNELS_MAP[ConfigManager::get_module_type()];
|
const auto num_channels = MODULE_TO_NUM_CHANNELS_MAP[ConfigManager::get_module_type()];
|
||||||
this->m_link_layer_threads.resize(num_channels);
|
this->m_link_layer_threads.resize(num_channels);
|
||||||
for (uint8_t i = 0; i < num_channels; i++) {
|
for (uint8_t i = 0; i < num_channels; i++) {
|
||||||
auto *params = new link_layer_thread_params(this, i);
|
auto *params = new link_layer_thread_params(this, i);
|
||||||
xTaskCreate(link_layer_thread, "communication_router_rmt", 3096, params, 3, &this->m_link_layer_threads[i]);
|
xTaskCreate(link_layer_thread, "communication_router_rmt", 4096, params, 3, &this->m_link_layer_threads[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <format>
|
#include <format>
|
||||||
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
// todo: clean this up (strange to be a constructor) also need to add more details, need to add to routing table
|
// todo: clean this up (strange to be a constructor) also need to add more details, need to add to routing table
|
||||||
@@ -36,7 +37,7 @@ void mDNSDiscoveryService::set_connected_boards(const std::vector<int>& boards)
|
|||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
|
||||||
for (int i = 0; i < boards.size(); i++) {
|
for (int i = 0; i < boards.size(); i++) {
|
||||||
ss << boards[i];
|
ss << std::to_string(boards[i]);
|
||||||
if (i < boards.size() - 1) {
|
if (i < boards.size() - 1) {
|
||||||
ss << ',';
|
ss << ',';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,11 +16,10 @@
|
|||||||
char buffer[512];
|
char buffer[512];
|
||||||
while (true) {
|
while (true) {
|
||||||
messaging_interface->recv(buffer, 512, 0, 1);
|
messaging_interface->recv(buffer, 512, 0, 1);
|
||||||
std::cout << buffer << std::endl;
|
//std::cout << buffer << std::endl;
|
||||||
|
|
||||||
|
std::string s = std::format("num {} bo", ConfigManager::get_module_id());
|
||||||
char s[21] = {'H', 'e', 'l', 'l', 'o', ' ', 'f', 'r', 'o', 'm', ' ', 't', 'h', 'e', ' ', 'B', 'O', 'A', 'R', 'D', '!' };
|
messaging_interface->send(s.data(), s.size(), 0, 2, true);
|
||||||
messaging_interface->send(s, 21, 5, 2, true);
|
|
||||||
|
|
||||||
ESP_LOGI("MEM", "Free internal RAM: %d", heap_caps_get_free_size(MALLOC_CAP_8BIT));
|
ESP_LOGI("MEM", "Free internal RAM: %d", heap_caps_get_free_size(MALLOC_CAP_8BIT));
|
||||||
ESP_LOGI("MEM", "Free PSRAM: %d", heap_caps_get_free_size(MALLOC_CAP_SPIRAM));
|
ESP_LOGI("MEM", "Free PSRAM: %d", heap_caps_get_free_size(MALLOC_CAP_SPIRAM));
|
||||||
|
|||||||
Reference in New Issue
Block a user