From f5920e6f58874bd250e8e5f0b1b812b85e4999d1 Mon Sep 17 00:00:00 2001 From: Johnathon Slightham Date: Tue, 30 Sep 2025 12:45:27 -0400 Subject: [PATCH] New flatbuffer code --- .../RobotConfiguration_generated.h | 206 ++++++++++++++++++ .../RobotModule_generated.h | 13 +- .../TopologyMessage_generated.h | 76 ++++++- main/LoopManager.cpp | 2 +- 4 files changed, 284 insertions(+), 13 deletions(-) create mode 100644 components/flatbuffers/include/flatbuffers_generated/RobotConfiguration_generated.h diff --git a/components/flatbuffers/include/flatbuffers_generated/RobotConfiguration_generated.h b/components/flatbuffers/include/flatbuffers_generated/RobotConfiguration_generated.h new file mode 100644 index 0000000..ac9397d --- /dev/null +++ b/components/flatbuffers/include/flatbuffers_generated/RobotConfiguration_generated.h @@ -0,0 +1,206 @@ +// automatically generated by the FlatBuffers compiler, do not modify + + +#ifndef FLATBUFFERS_GENERATED_ROBOTCONFIGURATION_FRONTEND_H_ +#define FLATBUFFERS_GENERATED_ROBOTCONFIGURATION_FRONTEND_H_ + +#include "flatbuffers/flatbuffers.h" + +// Ensure the included flatbuffers.h is the same version as when this file was +// generated, otherwise it may not be compatible. +// static_assert(FLATBUFFERS_VERSION_MAJOR == 25 && +// FLATBUFFERS_VERSION_MINOR == 2 && +// FLATBUFFERS_VERSION_REVISION == 10, +// "Non-compatible flatbuffers version included"); + +#include "RobotModule_generated.h" + +namespace Frontend { + +struct ModuleConnection; +struct ModuleConnectionBuilder; + +struct RobotConfiguration; +struct RobotConfigurationBuilder; + +struct ModuleConnection FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { + typedef ModuleConnectionBuilder Builder; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_FROM_MODULE_ID = 4, + VT_TO_MODULE_ID = 6, + VT_FROM_SOCKET = 8, + VT_TO_SOCKET = 10, + VT_ORIENTATION = 12 + }; + uint8_t from_module_id() const { + return GetField(VT_FROM_MODULE_ID, 0); + } + uint8_t to_module_id() const { + return GetField(VT_TO_MODULE_ID, 0); + } + uint8_t from_socket() const { + return GetField(VT_FROM_SOCKET, 0); + } + uint8_t to_socket() const { + return GetField(VT_TO_SOCKET, 0); + } + Orientation orientation() const { + return static_cast(GetField(VT_ORIENTATION, 0)); + } + bool Verify(::flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_FROM_MODULE_ID, 1) && + VerifyField(verifier, VT_TO_MODULE_ID, 1) && + VerifyField(verifier, VT_FROM_SOCKET, 1) && + VerifyField(verifier, VT_TO_SOCKET, 1) && + VerifyField(verifier, VT_ORIENTATION, 1) && + verifier.EndTable(); + } +}; + +struct ModuleConnectionBuilder { + typedef ModuleConnection Table; + ::flatbuffers::FlatBufferBuilder &fbb_; + ::flatbuffers::uoffset_t start_; + void add_from_module_id(uint8_t from_module_id) { + fbb_.AddElement(ModuleConnection::VT_FROM_MODULE_ID, from_module_id, 0); + } + void add_to_module_id(uint8_t to_module_id) { + fbb_.AddElement(ModuleConnection::VT_TO_MODULE_ID, to_module_id, 0); + } + void add_from_socket(uint8_t from_socket) { + fbb_.AddElement(ModuleConnection::VT_FROM_SOCKET, from_socket, 0); + } + void add_to_socket(uint8_t to_socket) { + fbb_.AddElement(ModuleConnection::VT_TO_SOCKET, to_socket, 0); + } + void add_orientation(Orientation orientation) { + fbb_.AddElement(ModuleConnection::VT_ORIENTATION, static_cast(orientation), 0); + } + explicit ModuleConnectionBuilder(::flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) { + start_ = fbb_.StartTable(); + } + ::flatbuffers::Offset Finish() { + const auto end = fbb_.EndTable(start_); + auto o = ::flatbuffers::Offset(end); + return o; + } +}; + +inline ::flatbuffers::Offset CreateModuleConnection( + ::flatbuffers::FlatBufferBuilder &_fbb, + uint8_t from_module_id = 0, + uint8_t to_module_id = 0, + uint8_t from_socket = 0, + uint8_t to_socket = 0, + Orientation orientation = Orientation_Deg0) { + ModuleConnectionBuilder builder_(_fbb); + builder_.add_orientation(orientation); + builder_.add_to_socket(to_socket); + builder_.add_from_socket(from_socket); + builder_.add_to_module_id(to_module_id); + builder_.add_from_module_id(from_module_id); + return builder_.Finish(); +} + +struct RobotConfiguration FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { + typedef RobotConfigurationBuilder Builder; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_MODULES = 4, + VT_CONNECTIONS = 6 + }; + const ::flatbuffers::Vector<::flatbuffers::Offset> *modules() const { + return GetPointer> *>(VT_MODULES); + } + const ::flatbuffers::Vector<::flatbuffers::Offset> *connections() const { + return GetPointer> *>(VT_CONNECTIONS); + } + bool Verify(::flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_MODULES) && + verifier.VerifyVector(modules()) && + verifier.VerifyVectorOfTables(modules()) && + VerifyOffset(verifier, VT_CONNECTIONS) && + verifier.VerifyVector(connections()) && + verifier.VerifyVectorOfTables(connections()) && + verifier.EndTable(); + } +}; + +struct RobotConfigurationBuilder { + typedef RobotConfiguration Table; + ::flatbuffers::FlatBufferBuilder &fbb_; + ::flatbuffers::uoffset_t start_; + void add_modules(::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset>> modules) { + fbb_.AddOffset(RobotConfiguration::VT_MODULES, modules); + } + void add_connections(::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset>> connections) { + fbb_.AddOffset(RobotConfiguration::VT_CONNECTIONS, connections); + } + explicit RobotConfigurationBuilder(::flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) { + start_ = fbb_.StartTable(); + } + ::flatbuffers::Offset Finish() { + const auto end = fbb_.EndTable(start_); + auto o = ::flatbuffers::Offset(end); + return o; + } +}; + +inline ::flatbuffers::Offset CreateRobotConfiguration( + ::flatbuffers::FlatBufferBuilder &_fbb, + ::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset>> modules = 0, + ::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset>> connections = 0) { + RobotConfigurationBuilder builder_(_fbb); + builder_.add_connections(connections); + builder_.add_modules(modules); + return builder_.Finish(); +} + +inline ::flatbuffers::Offset CreateRobotConfigurationDirect( + ::flatbuffers::FlatBufferBuilder &_fbb, + const std::vector<::flatbuffers::Offset> *modules = nullptr, + const std::vector<::flatbuffers::Offset> *connections = nullptr) { + auto modules__ = modules ? _fbb.CreateVector<::flatbuffers::Offset>(*modules) : 0; + auto connections__ = connections ? _fbb.CreateVector<::flatbuffers::Offset>(*connections) : 0; + return Frontend::CreateRobotConfiguration( + _fbb, + modules__, + connections__); +} + +inline const Frontend::RobotConfiguration *GetRobotConfiguration(const void *buf) { + return ::flatbuffers::GetRoot(buf); +} + +inline const Frontend::RobotConfiguration *GetSizePrefixedRobotConfiguration(const void *buf) { + return ::flatbuffers::GetSizePrefixedRoot(buf); +} + +inline bool VerifyRobotConfigurationBuffer( + ::flatbuffers::Verifier &verifier) { + return verifier.VerifyBuffer(nullptr); +} + +inline bool VerifySizePrefixedRobotConfigurationBuffer( + ::flatbuffers::Verifier &verifier) { + return verifier.VerifySizePrefixedBuffer(nullptr); +} + +inline void FinishRobotConfigurationBuffer( + ::flatbuffers::FlatBufferBuilder &fbb, + ::flatbuffers::Offset root) { + fbb.Finish(root); +} + +inline void FinishSizePrefixedRobotConfigurationBuffer( + ::flatbuffers::FlatBufferBuilder &fbb, + ::flatbuffers::Offset root) { + fbb.FinishSizePrefixed(root); +} + +} // namespace Frontend + +#endif // FLATBUFFERS_GENERATED_ROBOTCONFIGURATION_FRONTEND_H_ diff --git a/components/flatbuffers/include/flatbuffers_generated/RobotModule_generated.h b/components/flatbuffers/include/flatbuffers_generated/RobotModule_generated.h index 087e271..9c6ad67 100644 --- a/components/flatbuffers/include/flatbuffers_generated/RobotModule_generated.h +++ b/components/flatbuffers/include/flatbuffers_generated/RobotModule_generated.h @@ -24,36 +24,33 @@ enum ModuleType : int8_t { ModuleType_SERVO_1 = 1, ModuleType_DC_MOTOR = 2, ModuleType_BATTERY = 3, - ModuleType_SERVO_2 = 4, ModuleType_MIN = ModuleType_SPLITTER, - ModuleType_MAX = ModuleType_SERVO_2 + ModuleType_MAX = ModuleType_BATTERY }; -inline const ModuleType (&EnumValuesModuleType())[5] { +inline const ModuleType (&EnumValuesModuleType())[4] { static const ModuleType values[] = { ModuleType_SPLITTER, ModuleType_SERVO_1, ModuleType_DC_MOTOR, - ModuleType_BATTERY, - ModuleType_SERVO_2 + ModuleType_BATTERY }; return values; } inline const char * const *EnumNamesModuleType() { - static const char * const names[6] = { + static const char * const names[5] = { "SPLITTER", "SERVO_1", "DC_MOTOR", "BATTERY", - "SERVO_2", nullptr }; return names; } inline const char *EnumNameModuleType(ModuleType e) { - if (::flatbuffers::IsOutRange(e, ModuleType_SPLITTER, ModuleType_SERVO_2)) return ""; + if (::flatbuffers::IsOutRange(e, ModuleType_SPLITTER, ModuleType_BATTERY)) return ""; const size_t index = static_cast(e); return EnumNamesModuleType()[index]; } diff --git a/components/flatbuffers/include/flatbuffers_generated/TopologyMessage_generated.h b/components/flatbuffers/include/flatbuffers_generated/TopologyMessage_generated.h index 85870a7..ec2cab1 100644 --- a/components/flatbuffers/include/flatbuffers_generated/TopologyMessage_generated.h +++ b/components/flatbuffers/include/flatbuffers_generated/TopologyMessage_generated.h @@ -20,6 +20,36 @@ namespace Messaging { struct TopologyMessage; struct TopologyMessageBuilder; +enum ConnectionType : int8_t { + ConnectionType_DIRECT = 0, + ConnectionType_HOP = 1, + ConnectionType_MIN = ConnectionType_DIRECT, + ConnectionType_MAX = ConnectionType_HOP +}; + +inline const ConnectionType (&EnumValuesConnectionType())[2] { + static const ConnectionType values[] = { + ConnectionType_DIRECT, + ConnectionType_HOP + }; + return values; +} + +inline const char * const *EnumNamesConnectionType() { + static const char * const names[3] = { + "DIRECT", + "HOP", + nullptr + }; + return names; +} + +inline const char *EnumNameConnectionType(ConnectionType e) { + if (::flatbuffers::IsOutRange(e, ConnectionType_DIRECT, ConnectionType_HOP)) return ""; + const size_t index = static_cast(e); + return EnumNamesConnectionType()[index]; +} + struct TopologyMessage FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { typedef TopologyMessageBuilder Builder; enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { @@ -27,7 +57,10 @@ struct TopologyMessage FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { VT_MODULE_TYPE = 6, VT_NUM_CHANNELS = 8, VT_CHANNEL_TO_MODULE = 10, - VT_CHANNEL_TO_ORIENTATION = 12 + VT_CHANNEL_TO_ORIENTATION = 12, + VT_CONNECTION = 14, + VT_LEADER = 16, + VT_FIRMWARE = 18 }; uint8_t module_id() const { return GetField(VT_MODULE_ID, 0); @@ -44,6 +77,15 @@ struct TopologyMessage FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { const ::flatbuffers::Vector *channel_to_orientation() const { return GetPointer *>(VT_CHANNEL_TO_ORIENTATION); } + Messaging::ConnectionType connection() const { + return static_cast(GetField(VT_CONNECTION, 0)); + } + uint8_t leader() const { + return GetField(VT_LEADER, 0); + } + const ::flatbuffers::String *firmware() const { + return GetPointer(VT_FIRMWARE); + } bool Verify(::flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyField(verifier, VT_MODULE_ID, 1) && @@ -53,6 +95,10 @@ struct TopologyMessage FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { verifier.VerifyVector(channel_to_module()) && VerifyOffset(verifier, VT_CHANNEL_TO_ORIENTATION) && verifier.VerifyVector(channel_to_orientation()) && + VerifyField(verifier, VT_CONNECTION, 1) && + VerifyField(verifier, VT_LEADER, 1) && + VerifyOffset(verifier, VT_FIRMWARE) && + verifier.VerifyString(firmware()) && verifier.EndTable(); } }; @@ -76,6 +122,15 @@ struct TopologyMessageBuilder { void add_channel_to_orientation(::flatbuffers::Offset<::flatbuffers::Vector> channel_to_orientation) { fbb_.AddOffset(TopologyMessage::VT_CHANNEL_TO_ORIENTATION, channel_to_orientation); } + void add_connection(Messaging::ConnectionType connection) { + fbb_.AddElement(TopologyMessage::VT_CONNECTION, static_cast(connection), 0); + } + void add_leader(uint8_t leader) { + fbb_.AddElement(TopologyMessage::VT_LEADER, leader, 0); + } + void add_firmware(::flatbuffers::Offset<::flatbuffers::String> firmware) { + fbb_.AddOffset(TopologyMessage::VT_FIRMWARE, firmware); + } explicit TopologyMessageBuilder(::flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); @@ -93,10 +148,16 @@ inline ::flatbuffers::Offset CreateTopologyMessage( ModuleType module_type = ModuleType_SPLITTER, uint8_t num_channels = 0, ::flatbuffers::Offset<::flatbuffers::Vector> channel_to_module = 0, - ::flatbuffers::Offset<::flatbuffers::Vector> channel_to_orientation = 0) { + ::flatbuffers::Offset<::flatbuffers::Vector> channel_to_orientation = 0, + Messaging::ConnectionType connection = Messaging::ConnectionType_DIRECT, + uint8_t leader = 0, + ::flatbuffers::Offset<::flatbuffers::String> firmware = 0) { TopologyMessageBuilder builder_(_fbb); + builder_.add_firmware(firmware); builder_.add_channel_to_orientation(channel_to_orientation); builder_.add_channel_to_module(channel_to_module); + builder_.add_leader(leader); + builder_.add_connection(connection); builder_.add_num_channels(num_channels); builder_.add_module_type(module_type); builder_.add_module_id(module_id); @@ -109,16 +170,23 @@ inline ::flatbuffers::Offset CreateTopologyMessageDirect( ModuleType module_type = ModuleType_SPLITTER, uint8_t num_channels = 0, const std::vector *channel_to_module = nullptr, - const std::vector *channel_to_orientation = nullptr) { + const std::vector *channel_to_orientation = nullptr, + Messaging::ConnectionType connection = Messaging::ConnectionType_DIRECT, + uint8_t leader = 0, + const char *firmware = nullptr) { auto channel_to_module__ = channel_to_module ? _fbb.CreateVector(*channel_to_module) : 0; auto channel_to_orientation__ = channel_to_orientation ? _fbb.CreateVector(*channel_to_orientation) : 0; + auto firmware__ = firmware ? _fbb.CreateString(firmware) : 0; return Messaging::CreateTopologyMessage( _fbb, module_id, module_type, num_channels, channel_to_module__, - channel_to_orientation__); + channel_to_orientation__, + connection, + leader, + firmware__); } inline const Messaging::TopologyMessage *GetTopologyMessage(const void *buf) { diff --git a/main/LoopManager.cpp b/main/LoopManager.cpp index 9921c80..0d03f98 100644 --- a/main/LoopManager.cpp +++ b/main/LoopManager.cpp @@ -14,7 +14,7 @@ #define ACTUATOR_CMD_TAG 5 #define TOPOLOGY_CMD_TAG 6 -#define METADATA_PERIOD_MS 5000 +#define METADATA_PERIOD_MS 1000 [[noreturn]] void LoopManager::control_loop() const { const auto actuator = ActuatorFactory::create_actuator(ConfigManager::get_module_type());