From 2d8bda2f834c55651098281dd40157a9d63917ad Mon Sep 17 00:00:00 2001 From: Johnathon Slightham Date: Thu, 16 Oct 2025 21:24:41 -0400 Subject: [PATCH] Send more metadata --- components/flatbuffers/TopologyMessageBuilder.cpp | 8 ++++++-- .../flatbuffers/include/TopologyMessageBuilder.h | 4 +++- components/rpc/CommunicationRouter.cpp | 4 ++++ components/rpc/MessagingInterface.cpp | 11 +++++++++++ components/rpc/include/CommunicationRouter.h | 8 ++------ components/rpc/include/MessagingInterface.h | 3 +++ main/LoopManager.cpp | 8 +++++++- 7 files changed, 36 insertions(+), 10 deletions(-) diff --git a/components/flatbuffers/TopologyMessageBuilder.cpp b/components/flatbuffers/TopologyMessageBuilder.cpp index 51b59f1..7163f83 100644 --- a/components/flatbuffers/TopologyMessageBuilder.cpp +++ b/components/flatbuffers/TopologyMessageBuilder.cpp @@ -10,7 +10,9 @@ namespace Flatbuffers { const uint8_t module_id, const ModuleType module_type, const std::vector& channel_to_module, - const std::vector& orientation_to_module) { + const std::vector& orientation_to_module, + const Messaging::ConnectionType connection_type, + const uint8_t leader) { builder_.Clear(); const auto orientation_to_module_vector = builder_.CreateVector(orientation_to_module); @@ -22,7 +24,9 @@ namespace Flatbuffers { module_type, channel_to_module.size(), channel_to_module_vector, - orientation_to_module_vector + orientation_to_module_vector, + connection_type, + leader ); builder_.Finish(message); diff --git a/components/flatbuffers/include/TopologyMessageBuilder.h b/components/flatbuffers/include/TopologyMessageBuilder.h index e6ed55e..f46f980 100644 --- a/components/flatbuffers/include/TopologyMessageBuilder.h +++ b/components/flatbuffers/include/TopologyMessageBuilder.h @@ -20,7 +20,9 @@ namespace Flatbuffers { uint8_t module_id, ModuleType module_type, const std::vector& channel_to_module, - const std::vector& orientation_to_module); + const std::vector& orientation_to_module, + Messaging::ConnectionType connection_type, + uint8_t leader); private: flatbuffers::FlatBufferBuilder builder_; diff --git a/components/rpc/CommunicationRouter.cpp b/components/rpc/CommunicationRouter.cpp index 67fdca6..be5fc7f 100644 --- a/components/rpc/CommunicationRouter.cpp +++ b/components/rpc/CommunicationRouter.cpp @@ -153,3 +153,7 @@ std::pair, std::vector> CommunicationRouter::g return { connected_module_ids, connected_module_orientations }; } + +[[nodiscard]] uint8_t CommunicationRouter::get_leader() const { + return this->m_leader; +} diff --git a/components/rpc/MessagingInterface.cpp b/components/rpc/MessagingInterface.cpp index dcac8e2..e7ba831 100644 --- a/components/rpc/MessagingInterface.cpp +++ b/components/rpc/MessagingInterface.cpp @@ -66,3 +66,14 @@ void MessagingInterface::checkOrInsertTag(const uint8_t tag) { std::pair, std::vector> MessagingInterface::get_physically_connected_modules() const { return m_router->get_physically_connected_modules(); } + +Messaging::ConnectionType MessagingInterface::get_connection_type() const { + if (this->m_router->get_leader() == m_config_manager.get_module_id()) { + return Messaging::ConnectionType_DIRECT; + } + return Messaging::ConnectionType_HOP; +} + +uint8_t MessagingInterface::get_leader() const { + return this->m_router->get_leader(); +} diff --git a/components/rpc/include/CommunicationRouter.h b/components/rpc/include/CommunicationRouter.h index ce06633..ae1cab0 100644 --- a/components/rpc/include/CommunicationRouter.h +++ b/components/rpc/include/CommunicationRouter.h @@ -55,15 +55,11 @@ public: [[noreturn]] static void router_thread(void *args); [[noreturn]] static void link_layer_thread(void *args); - int send_msg(char* buffer, size_t length) const; - void update_leader(); - void route(uint8_t *buffer, size_t length) const; - - // pair of - std::pair, std::vector> get_physically_connected_modules() const; + [[nodiscard]] std::pair, std::vector> get_physically_connected_modules() const; + [[nodiscard]] uint8_t get_leader() const; // todo: does this really need to be here (so i can access from thread)? std::shared_ptr>> m_tcp_rx_queue; diff --git a/components/rpc/include/MessagingInterface.h b/components/rpc/include/MessagingInterface.h index 607f8e2..6b10f70 100644 --- a/components/rpc/include/MessagingInterface.h +++ b/components/rpc/include/MessagingInterface.h @@ -7,6 +7,7 @@ #include #include +#include #include "constants/app_comms.h" #include "CommunicationRouter.h" @@ -26,6 +27,8 @@ public: int recv(char* buffer, int size, int source, int tag); int sendrecv(char* send_buffer, int send_size, int dest, int send_tag, char* recv_buffer, int recv_size, int recv_tag); std::pair, std::vector> get_physically_connected_modules() const; + Messaging::ConnectionType get_connection_type() const; + uint8_t get_leader() const; private: void handleRecv(const char* recv_buffer, int recv_size); diff --git a/main/LoopManager.cpp b/main/LoopManager.cpp index 4474651..a06f299 100644 --- a/main/LoopManager.cpp +++ b/main/LoopManager.cpp @@ -39,7 +39,13 @@ casted_orientations.emplace_back(orientation); } - const auto [data, size] = topology_message_builder->build_topology_message(that->m_config_manager.get_module_id(), that->m_config_manager.get_module_type(), module_ids, casted_orientations); + const auto [data, size] = topology_message_builder->build_topology_message( + that->m_config_manager.get_module_id(), + that->m_config_manager.get_module_type(), + module_ids, + casted_orientations, + that->m_messaging_interface->get_connection_type(), + that->m_messaging_interface->get_leader()); that->m_messaging_interface->send(static_cast(data), size, PC_ADDR, TOPOLOGY_CMD_TAG, true); vTaskDelay(METADATA_PERIOD_MS / portTICK_PERIOD_MS); }