From 0056e7a9dee91ea58061e7f61a36b6a7a6d3ef26 Mon Sep 17 00:00:00 2001 From: Johnathon Slightham Date: Sat, 28 Mar 2026 23:10:58 -0400 Subject: [PATCH] Cleanup for release --- Frontend/RobotConfiguration.fbs | 18 +++++++++++++ Messaging/AngleControlMessage.fbs | 7 ++++++ Messaging/ConfigMessage.fbs | 35 ++++++++++++++++++++++++++ Messaging/MPIMessage.fbs | 19 ++++++++++++++ Messaging/OTAPacket.fbs | 9 +++++++ Messaging/RPCCall/ReturnCall.fbs | 9 +++++++ Messaging/RPCCall/SendCall.fbs | 10 ++++++++ Messaging/SensorMessage.fbs | 42 +++++++++++++++++++++++++++++++ Messaging/TextControlMessage.fbs | 7 ++++++ Messaging/TopologyMessage.fbs | 21 ++++++++++++++++ README.md | 26 +++++++++++++++++++ RobotModule.fbs | 42 +++++++++++++++++++++++++++++++ movement.fbs | 29 +++++++++++++++++++++ topology.fbs | 19 ++++++++++++++ 14 files changed, 293 insertions(+) create mode 100644 Frontend/RobotConfiguration.fbs create mode 100644 Messaging/AngleControlMessage.fbs create mode 100644 Messaging/ConfigMessage.fbs create mode 100644 Messaging/MPIMessage.fbs create mode 100644 Messaging/OTAPacket.fbs create mode 100644 Messaging/RPCCall/ReturnCall.fbs create mode 100644 Messaging/RPCCall/SendCall.fbs create mode 100644 Messaging/SensorMessage.fbs create mode 100644 Messaging/TextControlMessage.fbs create mode 100644 Messaging/TopologyMessage.fbs create mode 100644 README.md create mode 100644 RobotModule.fbs create mode 100644 movement.fbs create mode 100644 topology.fbs diff --git a/Frontend/RobotConfiguration.fbs b/Frontend/RobotConfiguration.fbs new file mode 100644 index 0000000..5713559 --- /dev/null +++ b/Frontend/RobotConfiguration.fbs @@ -0,0 +1,18 @@ +include "../RobotModule.fbs"; + +namespace Frontend; + +table ModuleConnection { + from_module_id: uint8; + to_module_id: uint8; + from_socket: uint8; + to_socket: uint8; + orientation: Orientation; +} + +table RobotConfiguration{ + modules: [RobotModule]; + connections: [ModuleConnection]; +} + +root_type RobotConfiguration; diff --git a/Messaging/AngleControlMessage.fbs b/Messaging/AngleControlMessage.fbs new file mode 100644 index 0000000..28782da --- /dev/null +++ b/Messaging/AngleControlMessage.fbs @@ -0,0 +1,7 @@ +namespace Messaging; + +table AngleControlMessage { + angle: int16; +} + +root_type AngleControlMessage; diff --git a/Messaging/ConfigMessage.fbs b/Messaging/ConfigMessage.fbs new file mode 100644 index 0000000..b877927 --- /dev/null +++ b/Messaging/ConfigMessage.fbs @@ -0,0 +1,35 @@ +namespace Messaging; + +enum EntryType : byte { + NONE = 0, + I32, + U32, + I64, + U64, + STRING, + BLOB +} + +table I32Value { value: int32; } +table U32Value { value: uint32; } +table I64Value { value: int64; } +table U64Value { value: uint64; } +table StringValue { value: string; } +table BlobValue { value: [ubyte]; } + +union NvsValue { + I32Value, + U32Value, + I64Value, + U64Value, + StringValue, + BlobValue +} + +table ConfigMessage { + key: string; + type: EntryType; + value: NvsValue; +} + +root_type ConfigMessage; diff --git a/Messaging/MPIMessage.fbs b/Messaging/MPIMessage.fbs new file mode 100644 index 0000000..da9ddf3 --- /dev/null +++ b/Messaging/MPIMessage.fbs @@ -0,0 +1,19 @@ +namespace Messaging; + +enum MessageType : byte { + BROADCAST = 0, + PTP = 1, +} + +table MPIMessage { + type: MessageType; + sender: uint8; + destination: uint8; + sequence_number: uint16; + is_durable: bool; + length: uint16; + tag: uint8; + payload: [ubyte]; +} + +root_type MPIMessage; diff --git a/Messaging/OTAPacket.fbs b/Messaging/OTAPacket.fbs new file mode 100644 index 0000000..207aab3 --- /dev/null +++ b/Messaging/OTAPacket.fbs @@ -0,0 +1,9 @@ +namespace Messaging; + +table OTAPacket { + sequence_number: uint16; + length: uint16; + payload: [ubyte]; +} + +root_type OTAPacket; diff --git a/Messaging/RPCCall/ReturnCall.fbs b/Messaging/RPCCall/ReturnCall.fbs new file mode 100644 index 0000000..f02e652 --- /dev/null +++ b/Messaging/RPCCall/ReturnCall.fbs @@ -0,0 +1,9 @@ +namespace Messaging; + +table ReturnCall { + unique_id: uint8; + length: uint16; + return_value: [ubyte]; +} + +root_type ReturnCall; diff --git a/Messaging/RPCCall/SendCall.fbs b/Messaging/RPCCall/SendCall.fbs new file mode 100644 index 0000000..821ce00 --- /dev/null +++ b/Messaging/RPCCall/SendCall.fbs @@ -0,0 +1,10 @@ +namespace Messaging; + +table SendCall { + tag: uint8; + unique_id: uint8; + length: uint16; + parameters: [ubyte]; +} + +root_type SendCall; diff --git a/Messaging/SensorMessage.fbs b/Messaging/SensorMessage.fbs new file mode 100644 index 0000000..9c23834 --- /dev/null +++ b/Messaging/SensorMessage.fbs @@ -0,0 +1,42 @@ +namespace Messaging; + +table TargetAngle { + value: int16; +} + +table CurrentText { + value: string; +} + +table CurrentAngle { + value: int16; +} + +table Distance { + value: float; +} + +table Temperature { + value: float; +} + +table Position { + heading: float; + pitch: float; + roll: float; +} + +union SensorValue { + TargetAngle, + CurrentAngle, + CurrentText, + Distance, + Temperature, + Position +} + +table SensorMessage { + values: [SensorValue]; +} + +root_type SensorMessage; diff --git a/Messaging/TextControlMessage.fbs b/Messaging/TextControlMessage.fbs new file mode 100644 index 0000000..018803f --- /dev/null +++ b/Messaging/TextControlMessage.fbs @@ -0,0 +1,7 @@ +namespace Messaging; + +table TextControlMessage { + message: string; +} + +root_type TextControlMessage; diff --git a/Messaging/TopologyMessage.fbs b/Messaging/TopologyMessage.fbs new file mode 100644 index 0000000..68b6abf --- /dev/null +++ b/Messaging/TopologyMessage.fbs @@ -0,0 +1,21 @@ +include "../RobotModule.fbs"; + +namespace Messaging; + +enum ConnectionType : byte { + DIRECT = 0, + HOP = 1, +} + +table TopologyMessage{ + module_id: uint8; + module_type: ModuleType; + num_channels: uint8; + channel_to_module: [uint8]; // index is channel, value is connected board; 0 represents no connection + channel_to_orientation: [Orientation]; // index is channel, value is orientation + connection: ConnectionType; + leader: uint8; + firmware: string; +} + +root_type TopologyMessage; diff --git a/README.md b/README.md new file mode 100644 index 0000000..8dd2916 --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +# Flatbuffers + +We use [Google's Flatbuffers](https://flatbuffers.dev) for serialization. The main benefit of Flatbuffers over other serialization libraries is that Flatbuffers is small and fast (it does not require an unpacking step). + +This repository contains all the Flatbuffer definition files (`.fbs`). It should only contain definition files. + +Unless there is a good reason to add fields to the middle of a schema, please only add new fields to the end of schema files (to help maintain backward compatibility). + +## Compiling +The schema definitions need to be compiled into code files for the languages we use. + +The documentation for Flatbuffer's `flatc` tool can be found [here](https://flatbuffers.dev/flatc). + +The generated files should then be copied into the respective repositories. Flatbuffers offers backward and forward compatibility. + +### Installation +#### MacOS +Install `flatc` with homebrew +``` +brew install flatbuffers +``` + +### Generating +``` +flatc --cpp +``` diff --git a/RobotModule.fbs b/RobotModule.fbs new file mode 100644 index 0000000..fb85c33 --- /dev/null +++ b/RobotModule.fbs @@ -0,0 +1,42 @@ +enum ModuleType: byte { + SPLITTER = 0, + SERVO_1 = 1, + DC_MOTOR = 2, + BATTERY = 3, + SERVO_2 = 4, + DISPLAY = 5, + GRIPPER = 6, + SPEAKER = 7, + IMU = 8, + DISTANCE_SENSOR = 9, + SPLITTER_2 = 10, + SPLITTER_3 = 11, + SPLITTER_4 = 12, + SPLITTER_5 = 13, + SPLITTER_6 = 14, + SPLITTER_7 = 15, + SPLITTER_8 = 16 +} + +enum Orientation : byte { + Deg0 = 0, + Deg90 = 1, + Deg180 = 2, + Deg270 = 3, +} + +table MotorState { + angle: int; +} + +union ModuleState { + MotorState +} + +table RobotModule { + id: uint8; + module_type: ModuleType; + configuration: ModuleState; +} + +root_type RobotModule; diff --git a/movement.fbs b/movement.fbs new file mode 100644 index 0000000..e7a5fa6 --- /dev/null +++ b/movement.fbs @@ -0,0 +1,29 @@ +namespace Movement; + +struct ConditionBlob { + value: ushort; + cond: ubyte; + module_type: ubyte; + in_use: ubyte; +} + +table MovementEntry { + board_id: ushort; + module_type: ubyte; + value_action: ushort; + condition: ConditionBlob; + ack: ubyte; + ack_ttl_ms: ushort; + post_delay_ms: ushort; +} + +table MovementVector { + key: ubyte (key); // map key + movements: [MovementEntry]; // vector value +} + +table MovementSet { + movement_map: [MovementVector]; +} + +root_type MovementSet; diff --git a/topology.fbs b/topology.fbs new file mode 100644 index 0000000..90438e9 --- /dev/null +++ b/topology.fbs @@ -0,0 +1,19 @@ +namespace Topology; + +struct ChannelBoardConn { + channel: ubyte; + board_id: ushort; +} + +table NeighbourBlob { + curr_board_id: ushort; + num_connections: ubyte; + neighbour_connections: [ChannelBoardConn]; +} + +table TopologyInfo { + num_boards: ushort; + boards: [NeighbourBlob]; +} + +root_type TopologyInfo; \ No newline at end of file