mirror of
https://github.com/BotChain-Robots/firmware.git
synced 2026-07-08 09:37:21 +02:00
Send more metadata
This commit is contained in:
@@ -10,7 +10,9 @@ namespace Flatbuffers {
|
||||
const uint8_t module_id,
|
||||
const ModuleType module_type,
|
||||
const std::vector<uint8_t>& channel_to_module,
|
||||
const std::vector<int8_t>& orientation_to_module) {
|
||||
const std::vector<int8_t>& 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);
|
||||
|
||||
@@ -20,7 +20,9 @@ namespace Flatbuffers {
|
||||
uint8_t module_id,
|
||||
ModuleType module_type,
|
||||
const std::vector<uint8_t>& channel_to_module,
|
||||
const std::vector<int8_t>& orientation_to_module);
|
||||
const std::vector<int8_t>& orientation_to_module,
|
||||
Messaging::ConnectionType connection_type,
|
||||
uint8_t leader);
|
||||
|
||||
private:
|
||||
flatbuffers::FlatBufferBuilder builder_;
|
||||
|
||||
@@ -153,3 +153,7 @@ std::pair<std::vector<uint8_t>, std::vector<Orientation>> CommunicationRouter::g
|
||||
|
||||
return { connected_module_ids, connected_module_orientations };
|
||||
}
|
||||
|
||||
[[nodiscard]] uint8_t CommunicationRouter::get_leader() const {
|
||||
return this->m_leader;
|
||||
}
|
||||
|
||||
@@ -66,3 +66,14 @@ void MessagingInterface::checkOrInsertTag(const uint8_t tag) {
|
||||
std::pair<std::vector<uint8_t>, std::vector<Orientation>> 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();
|
||||
}
|
||||
|
||||
@@ -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 <module, mount orientation>
|
||||
std::pair<std::vector<uint8_t>, std::vector<Orientation>> get_physically_connected_modules() const;
|
||||
[[nodiscard]] std::pair<std::vector<uint8_t>, std::vector<Orientation>> 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<PtrQueue<std::vector<uint8_t>>> m_tcp_rx_queue;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <flatbuffers_generated/TopologyMessage_generated.h>
|
||||
|
||||
#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<uint8_t>, std::vector<Orientation>> 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);
|
||||
|
||||
@@ -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<char *>(data), size, PC_ADDR, TOPOLOGY_CMD_TAG, true);
|
||||
vTaskDelay(METADATA_PERIOD_MS / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user