mirror of
https://github.com/BotChain-Robots/control.git
synced 2026-03-10 00:32:26 +01:00
Prepare files for public release
This commit is contained in:
29
include/flatbuffers/AngleControlMessageBuilder.h
Normal file
29
include/flatbuffers/AngleControlMessageBuilder.h
Normal file
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// Created by Johnathon Slightham on 2025-06-30.
|
||||
//
|
||||
|
||||
#ifndef ANGLECONTROLMESSAGEBUILDER_H_
|
||||
#define ANGLECONTROLMESSAGEBUILDER_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "SerializedMessage.h"
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
#include "flatbuffers_generated/AngleControlMessage_generated.h"
|
||||
|
||||
namespace Flatbuffers {
|
||||
class AngleControlMessageBuilder {
|
||||
public:
|
||||
AngleControlMessageBuilder() : builder_(256) {
|
||||
}
|
||||
|
||||
SerializedMessage build_angle_control_message(int16_t angle);
|
||||
static const Messaging::AngleControlMessage *parse_angle_control_message(const uint8_t *buffer);
|
||||
|
||||
private:
|
||||
flatbuffers::FlatBufferBuilder builder_;
|
||||
};
|
||||
} // namespace Flatbuffers
|
||||
|
||||
#endif
|
||||
45
include/flatbuffers/RobotConfigurationBuilder.h
Normal file
45
include/flatbuffers/RobotConfigurationBuilder.h
Normal file
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// Created by Johnathon Slightham on 2025-07-25.
|
||||
//
|
||||
|
||||
#ifndef ROBOTCONFIGURATIONBUILDER_H
|
||||
#define ROBOTCONFIGURATIONBUILDER_H
|
||||
#include "SerializedMessage.h"
|
||||
#include <cstdint>
|
||||
#include <flatbuffers_generated/RobotConfiguration_generated.h>
|
||||
#include <flatbuffers_generated/RobotModule_generated.h>
|
||||
#include <vector>
|
||||
|
||||
namespace Flatbuffers {
|
||||
struct ModuleInstance {
|
||||
uint8_t id;
|
||||
ModuleType type;
|
||||
int angle;
|
||||
};
|
||||
|
||||
struct ModuleConnectionInstance {
|
||||
uint8_t from_module_id;
|
||||
uint8_t to_module_id;
|
||||
uint8_t from_socket;
|
||||
uint8_t to_socket;
|
||||
Orientation orientation;
|
||||
};
|
||||
|
||||
class RobotConfigurationBuilder {
|
||||
public:
|
||||
RobotConfigurationBuilder() : builder_(1024) {
|
||||
}
|
||||
|
||||
SerializedMessage
|
||||
build_robot_configuration(const std::vector<ModuleInstance> &modules,
|
||||
const std::vector<ModuleConnectionInstance> &connections);
|
||||
|
||||
static const Frontend::RobotConfiguration *
|
||||
parse_robot_configuration(const std::uint8_t *buffer);
|
||||
|
||||
private:
|
||||
flatbuffers::FlatBufferBuilder builder_;
|
||||
};
|
||||
} // namespace Flatbuffers
|
||||
|
||||
#endif // ROBOTCONFIGURATIONBUILDER_H
|
||||
54
include/flatbuffers/SensorMessageBuilder.h
Normal file
54
include/flatbuffers/SensorMessageBuilder.h
Normal file
@@ -0,0 +1,54 @@
|
||||
//
|
||||
// Created by Johnathon Slightham on 2025-06-30.
|
||||
//
|
||||
|
||||
#ifndef SENSORMESSAGEBUILDER_H
|
||||
#define SENSORMESSAGEBUILDER_H
|
||||
|
||||
#include <variant>
|
||||
|
||||
#include "flatbuffers_generated/SensorMessage_generated.h"
|
||||
|
||||
namespace Flatbuffers {
|
||||
|
||||
struct target_angle {
|
||||
int16_t angle;
|
||||
};
|
||||
|
||||
struct current_angle {
|
||||
int16_t angle;
|
||||
};
|
||||
|
||||
typedef std::variant<target_angle, current_angle> sensor_value;
|
||||
|
||||
class SensorMessageBuilder {
|
||||
public:
|
||||
SensorMessageBuilder() : builder_(1024) {
|
||||
}
|
||||
|
||||
static const Messaging::SensorMessage *parse_sensor_message(const std::uint8_t *buffer);
|
||||
|
||||
template <typename T>
|
||||
static std::optional<sensor_value> build_sensor_value(Messaging::SensorValue type, T value) {
|
||||
switch (type) {
|
||||
case Messaging::SensorValue_TargetAngle: {
|
||||
const Messaging::TargetAngle *target =
|
||||
static_cast<const Messaging::TargetAngle *>(value);
|
||||
return target_angle{target->value()};
|
||||
}
|
||||
case Messaging::SensorValue_CurrentAngle: {
|
||||
const Messaging::CurrentAngle *current =
|
||||
static_cast<const Messaging::CurrentAngle *>(value);
|
||||
return current_angle{current->value()};
|
||||
}
|
||||
default:
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
flatbuffers::FlatBufferBuilder builder_;
|
||||
};
|
||||
} // namespace Flatbuffers
|
||||
|
||||
#endif // TOPOLOGYMESSAGEBUILDER_H
|
||||
17
include/flatbuffers/SerializedMessage.h
Normal file
17
include/flatbuffers/SerializedMessage.h
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// Created by Johnathon Slightham on 2025-07-05.
|
||||
//
|
||||
|
||||
#ifndef SERIALIZEDMESSAGE_H
|
||||
#define SERIALIZEDMESSAGE_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
namespace Flatbuffers {
|
||||
struct SerializedMessage {
|
||||
void *data;
|
||||
size_t size;
|
||||
};
|
||||
} // namespace Flatbuffers
|
||||
|
||||
#endif // SERIALIZEDMESSAGE_H
|
||||
32
include/flatbuffers/TopologyMessageBuilder.h
Normal file
32
include/flatbuffers/TopologyMessageBuilder.h
Normal file
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// Created by Johnathon Slightham on 2025-06-30.
|
||||
//
|
||||
|
||||
#ifndef TOPOLOGYMESSAGEBUILDER_H
|
||||
#define TOPOLOGYMESSAGEBUILDER_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "SerializedMessage.h"
|
||||
#include "flatbuffers_generated/TopologyMessage_generated.h"
|
||||
|
||||
namespace Flatbuffers {
|
||||
class TopologyMessageBuilder {
|
||||
public:
|
||||
TopologyMessageBuilder() : builder_(1024) {
|
||||
}
|
||||
|
||||
SerializedMessage build_topology_message(uint8_t module_id, ModuleType module_type,
|
||||
const std::vector<uint8_t> &channel_to_module,
|
||||
const std::vector<int8_t> &orientation_to_module);
|
||||
|
||||
static const Messaging::TopologyMessage *parse_topology_message(const uint8_t *buffer);
|
||||
|
||||
static bool is_valid_topology_message(const uint8_t *buffer, size_t size);
|
||||
|
||||
private:
|
||||
flatbuffers::FlatBufferBuilder builder_;
|
||||
};
|
||||
} // namespace Flatbuffers
|
||||
|
||||
#endif // TOPOLOGYMESSAGEBUILDER_H
|
||||
Reference in New Issue
Block a user