mirror of
https://github.com/BotChain-Robots/control.git
synced 2026-03-10 00:32:26 +01:00
Formatting, add remote calling to c library
This commit is contained in:
@@ -14,15 +14,15 @@
|
||||
|
||||
namespace Flatbuffers {
|
||||
class AngleControlMessageBuilder {
|
||||
public:
|
||||
AngleControlMessageBuilder() : builder_(256) {}
|
||||
public:
|
||||
AngleControlMessageBuilder() : builder_(256) {
|
||||
}
|
||||
|
||||
SerializedMessage build_angle_control_message(int16_t angle);
|
||||
static const Messaging::AngleControlMessage *
|
||||
parse_angle_control_message(const uint8_t *buffer);
|
||||
SerializedMessage build_angle_control_message(int16_t angle);
|
||||
static const Messaging::AngleControlMessage *parse_angle_control_message(const uint8_t *buffer);
|
||||
|
||||
private:
|
||||
flatbuffers::FlatBufferBuilder builder_;
|
||||
private:
|
||||
flatbuffers::FlatBufferBuilder builder_;
|
||||
};
|
||||
} // namespace Flatbuffers
|
||||
|
||||
|
||||
@@ -12,32 +12,33 @@
|
||||
|
||||
namespace Flatbuffers {
|
||||
struct ModuleInstance {
|
||||
uint8_t id;
|
||||
ModuleType type;
|
||||
int angle;
|
||||
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;
|
||||
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) {}
|
||||
public:
|
||||
RobotConfigurationBuilder() : builder_(1024) {
|
||||
}
|
||||
|
||||
SerializedMessage build_robot_configuration(
|
||||
const std::vector<ModuleInstance> &modules,
|
||||
const std::vector<ModuleConnectionInstance> &connections);
|
||||
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);
|
||||
static const Frontend::RobotConfiguration *
|
||||
parse_robot_configuration(const std::uint8_t *buffer);
|
||||
|
||||
private:
|
||||
flatbuffers::FlatBufferBuilder builder_;
|
||||
private:
|
||||
flatbuffers::FlatBufferBuilder builder_;
|
||||
};
|
||||
} // namespace Flatbuffers
|
||||
|
||||
|
||||
@@ -13,52 +13,51 @@
|
||||
namespace Flatbuffers {
|
||||
|
||||
struct target_angle {
|
||||
int16_t angle;
|
||||
int16_t angle;
|
||||
};
|
||||
|
||||
struct current_angle {
|
||||
int16_t angle;
|
||||
int16_t angle;
|
||||
};
|
||||
|
||||
struct current_text {
|
||||
std::string text;
|
||||
std::string text;
|
||||
};
|
||||
|
||||
typedef std::variant<target_angle, current_angle, current_text> sensor_value;
|
||||
|
||||
class SensorMessageBuilder {
|
||||
public:
|
||||
SensorMessageBuilder() : builder_(1024) {}
|
||||
public:
|
||||
SensorMessageBuilder() : builder_(1024) {
|
||||
}
|
||||
|
||||
static const Messaging::SensorMessage *
|
||||
parse_sensor_message(const std::uint8_t *buffer);
|
||||
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()};
|
||||
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()};
|
||||
}
|
||||
case Messaging::SensorValue_CurrentText: {
|
||||
const Messaging::CurrentText *current =
|
||||
static_cast<const Messaging::CurrentText *>(value);
|
||||
return current_text{current->value()->str()};
|
||||
}
|
||||
default:
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
case Messaging::SensorValue_CurrentAngle: {
|
||||
const Messaging::CurrentAngle *current =
|
||||
static_cast<const Messaging::CurrentAngle *>(value);
|
||||
return current_angle{current->value()};
|
||||
}
|
||||
case Messaging::SensorValue_CurrentText: {
|
||||
const Messaging::CurrentText *current =
|
||||
static_cast<const Messaging::CurrentText *>(value);
|
||||
return current_text{current->value()->str()};
|
||||
}
|
||||
default:
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
flatbuffers::FlatBufferBuilder builder_;
|
||||
private:
|
||||
flatbuffers::FlatBufferBuilder builder_;
|
||||
};
|
||||
} // namespace Flatbuffers
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
namespace Flatbuffers {
|
||||
struct SerializedMessage {
|
||||
void *data;
|
||||
size_t size;
|
||||
void *data;
|
||||
size_t size;
|
||||
};
|
||||
} // namespace Flatbuffers
|
||||
|
||||
|
||||
@@ -14,13 +14,14 @@
|
||||
|
||||
namespace Flatbuffers {
|
||||
class TextControlMessageBuilder {
|
||||
public:
|
||||
TextControlMessageBuilder() : builder_(256) {}
|
||||
public:
|
||||
TextControlMessageBuilder() : builder_(256) {
|
||||
}
|
||||
|
||||
SerializedMessage build_text_control_message(std::string &t);
|
||||
SerializedMessage build_text_control_message(std::string &t);
|
||||
|
||||
private:
|
||||
flatbuffers::FlatBufferBuilder builder_;
|
||||
private:
|
||||
flatbuffers::FlatBufferBuilder builder_;
|
||||
};
|
||||
} // namespace Flatbuffers
|
||||
|
||||
|
||||
@@ -12,21 +12,20 @@
|
||||
|
||||
namespace Flatbuffers {
|
||||
class TopologyMessageBuilder {
|
||||
public:
|
||||
TopologyMessageBuilder() : builder_(1024) {}
|
||||
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);
|
||||
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 const Messaging::TopologyMessage *parse_topology_message(const uint8_t *buffer);
|
||||
|
||||
static bool is_valid_topology_message(const uint8_t *buffer, size_t size);
|
||||
static bool is_valid_topology_message(const uint8_t *buffer, size_t size);
|
||||
|
||||
private:
|
||||
flatbuffers::FlatBufferBuilder builder_;
|
||||
private:
|
||||
flatbuffers::FlatBufferBuilder builder_;
|
||||
};
|
||||
} // namespace Flatbuffers
|
||||
|
||||
|
||||
Reference in New Issue
Block a user