mirror of
https://github.com/BotChain-Robots/control.git
synced 2026-03-09 16:22:26 +01:00
Formatting, add remote calling to c library
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
#include "libcontrol.h"
|
||||
@@ -16,16 +16,16 @@ int main() {
|
||||
|
||||
std::cout << "Found " << controller->getModules().size() << " modules" << std::endl;
|
||||
|
||||
for (const auto& maybe_module : controller->getModules()) {
|
||||
if (const auto& module = maybe_module.lock()) {
|
||||
for (const auto &maybe_module : controller->getModules()) {
|
||||
if (const auto &module = maybe_module.lock()) {
|
||||
std::cout << "Found module " << (int)module->get_device_id();
|
||||
|
||||
if (module->get_type() == ModuleType_DISPLAY) {
|
||||
module->actuate(std::format("BotChain \n\n\nModule ID: {}", module->get_device_id()));
|
||||
module->actuate(
|
||||
std::format("BotChain \n\n\nModule ID: {}", module->get_device_id()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,9 @@ find_package(libcontrol REQUIRED)
|
||||
find_package(spdlog REQUIRED)
|
||||
find_package(librpc REQUIRED)
|
||||
|
||||
add_executable(RpcCallExample main.cpp)
|
||||
add_executable(RpcCallExample main.cpp flatbuffers/OTAPacketBuilder.cpp rpc/RemoteDebugging.cpp rpc/RemoteManagement.cpp)
|
||||
|
||||
target_include_directories(RpcCallExample PUBLIC include)
|
||||
|
||||
target_link_libraries(RpcCallExample
|
||||
PRIVATE
|
||||
|
||||
25
examples/rpc_call/flatbuffers/OTAPacketBuilder.cpp
Normal file
25
examples/rpc_call/flatbuffers/OTAPacketBuilder.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
#include "flatbuffers/OTAPacketBuilder.h"
|
||||
#include "flatbuffers/SerializedMessage.h"
|
||||
|
||||
namespace Flatbuffers {
|
||||
|
||||
SerializedMessage OTAPacketBuilder::build_ota_packet(uint16_t packet_num,
|
||||
const std::vector<uint8_t> &packet) {
|
||||
builder_.Clear();
|
||||
|
||||
const auto packet_vector = builder_.CreateVector(packet);
|
||||
|
||||
const auto message = Messaging::CreateOTAPacket(builder_, packet_num,
|
||||
static_cast<int>(packet.size()), packet_vector);
|
||||
|
||||
builder_.Finish(message);
|
||||
|
||||
return {builder_.GetBufferPointer(), builder_.GetSize()};
|
||||
}
|
||||
|
||||
const Messaging::OTAPacket *OTAPacketBuilder::parse_ota_packet(const uint8_t *buffer) {
|
||||
return flatbuffers::GetRoot<Messaging::OTAPacket>(buffer);
|
||||
}
|
||||
|
||||
} // namespace Flatbuffers
|
||||
28
examples/rpc_call/include/flatbuffers/OTAPacketBuilder.h
Normal file
28
examples/rpc_call/include/flatbuffers/OTAPacketBuilder.h
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
|
||||
#ifndef OTAPACKETBUILDER_H
|
||||
#define OTAPACKETBUILDER_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "flatbuffers/SerializedMessage.h"
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
#include "flatbuffers_generated/OTAPacket_generated.h"
|
||||
|
||||
namespace Flatbuffers {
|
||||
|
||||
class OTAPacketBuilder {
|
||||
public:
|
||||
OTAPacketBuilder() : builder_(1024) {
|
||||
}
|
||||
|
||||
SerializedMessage build_ota_packet(uint16_t packet_num, const std::vector<uint8_t> &packet);
|
||||
|
||||
static const Messaging::OTAPacket *parse_ota_packet(const uint8_t *buffer);
|
||||
|
||||
private:
|
||||
flatbuffers::FlatBufferBuilder builder_;
|
||||
};
|
||||
} // namespace Flatbuffers
|
||||
|
||||
#endif // OTAPACKETBUILDER_H
|
||||
15
examples/rpc_call/include/flatbuffers/SerializedMessage.h
Normal file
15
examples/rpc_call/include/flatbuffers/SerializedMessage.h
Normal file
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// Created by Johnathon Slightham on 2025-07-05.
|
||||
//
|
||||
|
||||
#ifndef SERIALIZEDMESSAGE_H
|
||||
#define SERIALIZEDMESSAGE_H
|
||||
|
||||
namespace Flatbuffers {
|
||||
struct SerializedMessage {
|
||||
void *data;
|
||||
size_t size;
|
||||
};
|
||||
} // namespace Flatbuffers
|
||||
|
||||
#endif // SERIALIZEDMESSAGE_H
|
||||
@@ -0,0 +1,115 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
|
||||
#ifndef FLATBUFFERS_GENERATED_OTAPACKET_MESSAGING_H_
|
||||
#define FLATBUFFERS_GENERATED_OTAPACKET_MESSAGING_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");
|
||||
|
||||
namespace Messaging {
|
||||
|
||||
struct OTAPacket;
|
||||
struct OTAPacketBuilder;
|
||||
|
||||
struct OTAPacket FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
typedef OTAPacketBuilder Builder;
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
VT_SEQUENCE_NUMBER = 4,
|
||||
VT_LENGTH = 6,
|
||||
VT_PAYLOAD = 8
|
||||
};
|
||||
uint16_t sequence_number() const {
|
||||
return GetField<uint16_t>(VT_SEQUENCE_NUMBER, 0);
|
||||
}
|
||||
uint16_t length() const {
|
||||
return GetField<uint16_t>(VT_LENGTH, 0);
|
||||
}
|
||||
const ::flatbuffers::Vector<uint8_t> *payload() const {
|
||||
return GetPointer<const ::flatbuffers::Vector<uint8_t> *>(VT_PAYLOAD);
|
||||
}
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<uint16_t>(verifier, VT_SEQUENCE_NUMBER, 2) &&
|
||||
VerifyField<uint16_t>(verifier, VT_LENGTH, 2) &&
|
||||
VerifyOffset(verifier, VT_PAYLOAD) && verifier.VerifyVector(payload()) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
};
|
||||
|
||||
struct OTAPacketBuilder {
|
||||
typedef OTAPacket Table;
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_sequence_number(uint16_t sequence_number) {
|
||||
fbb_.AddElement<uint16_t>(OTAPacket::VT_SEQUENCE_NUMBER, sequence_number, 0);
|
||||
}
|
||||
void add_length(uint16_t length) {
|
||||
fbb_.AddElement<uint16_t>(OTAPacket::VT_LENGTH, length, 0);
|
||||
}
|
||||
void add_payload(::flatbuffers::Offset<::flatbuffers::Vector<uint8_t>> payload) {
|
||||
fbb_.AddOffset(OTAPacket::VT_PAYLOAD, payload);
|
||||
}
|
||||
explicit OTAPacketBuilder(::flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
::flatbuffers::Offset<OTAPacket> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = ::flatbuffers::Offset<OTAPacket>(end);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline ::flatbuffers::Offset<OTAPacket>
|
||||
CreateOTAPacket(::flatbuffers::FlatBufferBuilder &_fbb, uint16_t sequence_number = 0,
|
||||
uint16_t length = 0,
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<uint8_t>> payload = 0) {
|
||||
OTAPacketBuilder builder_(_fbb);
|
||||
builder_.add_payload(payload);
|
||||
builder_.add_length(length);
|
||||
builder_.add_sequence_number(sequence_number);
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
inline ::flatbuffers::Offset<OTAPacket>
|
||||
CreateOTAPacketDirect(::flatbuffers::FlatBufferBuilder &_fbb, uint16_t sequence_number = 0,
|
||||
uint16_t length = 0, const std::vector<uint8_t> *payload = nullptr) {
|
||||
auto payload__ = payload ? _fbb.CreateVector<uint8_t>(*payload) : 0;
|
||||
return Messaging::CreateOTAPacket(_fbb, sequence_number, length, payload__);
|
||||
}
|
||||
|
||||
inline const Messaging::OTAPacket *GetOTAPacket(const void *buf) {
|
||||
return ::flatbuffers::GetRoot<Messaging::OTAPacket>(buf);
|
||||
}
|
||||
|
||||
inline const Messaging::OTAPacket *GetSizePrefixedOTAPacket(const void *buf) {
|
||||
return ::flatbuffers::GetSizePrefixedRoot<Messaging::OTAPacket>(buf);
|
||||
}
|
||||
|
||||
inline bool VerifyOTAPacketBuffer(::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifyBuffer<Messaging::OTAPacket>(nullptr);
|
||||
}
|
||||
|
||||
inline bool VerifySizePrefixedOTAPacketBuffer(::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifySizePrefixedBuffer<Messaging::OTAPacket>(nullptr);
|
||||
}
|
||||
|
||||
inline void FinishOTAPacketBuffer(::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<Messaging::OTAPacket> root) {
|
||||
fbb.Finish(root);
|
||||
}
|
||||
|
||||
inline void FinishSizePrefixedOTAPacketBuffer(::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<Messaging::OTAPacket> root) {
|
||||
fbb.FinishSizePrefixed(root);
|
||||
}
|
||||
|
||||
} // namespace Messaging
|
||||
|
||||
#endif // FLATBUFFERS_GENERATED_OTAPACKET_MESSAGING_H_
|
||||
24
examples/rpc_call/include/rpc/RemoteDebugging.h
Normal file
24
examples/rpc_call/include/rpc/RemoteDebugging.h
Normal file
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// Created by Johnathon Slightham on 2026-02-16.
|
||||
//
|
||||
|
||||
#ifndef NEW_DEV_TOOLS_REMOTEDEBUGGING_H
|
||||
#define NEW_DEV_TOOLS_REMOTEDEBUGGING_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include "libcontrol.h"
|
||||
|
||||
class RemoteDebugging {
|
||||
public:
|
||||
RemoteDebugging(std::shared_ptr<RobotController> controller) : m_robot_controller(controller) {
|
||||
}
|
||||
std::string get_task_manager(uint8_t module_id);
|
||||
std::string get_logs(uint8_t module_id);
|
||||
|
||||
private:
|
||||
std::shared_ptr<RobotController> m_robot_controller;
|
||||
};
|
||||
|
||||
#endif //NEW_DEV_TOOLS_REMOTEDEBUGGING_H
|
||||
38
examples/rpc_call/include/rpc/RemoteManagement.h
Normal file
38
examples/rpc_call/include/rpc/RemoteManagement.h
Normal file
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// Created by Johnathon Slightham on 2026-02-16.
|
||||
//
|
||||
|
||||
#ifndef REMOTEMANAGEMENT_H
|
||||
#define REMOTEMANAGEMENT_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
|
||||
#include "flatbuffers/OTAPacketBuilder.h"
|
||||
#include "libcontrol.h"
|
||||
|
||||
class RemoteManagement {
|
||||
public:
|
||||
RemoteManagement(uint8_t module_id, const std::string &path,
|
||||
std::shared_ptr<RobotController> controller)
|
||||
: m_module_id(module_id), m_file(path, std::ios::binary),
|
||||
m_builder(std::make_unique<Flatbuffers::OTAPacketBuilder>()),
|
||||
m_robot_controller(controller) {
|
||||
}
|
||||
bool perform_ota();
|
||||
void restart();
|
||||
|
||||
private:
|
||||
bool start_ota();
|
||||
bool write_ota(std::vector<uint8_t> &transmit_buffer);
|
||||
bool ota_end();
|
||||
|
||||
uint16_t m_sequence_num = 0;
|
||||
uint8_t m_module_id;
|
||||
std::ifstream m_file;
|
||||
std::unique_ptr<Flatbuffers::OTAPacketBuilder> m_builder;
|
||||
std::shared_ptr<RobotController> m_robot_controller;
|
||||
};
|
||||
|
||||
#endif // REMOTEMANAGEMENT_H
|
||||
@@ -7,34 +7,42 @@
|
||||
#include <vector>
|
||||
|
||||
#include "libcontrol.h"
|
||||
#include "rpc/RemoteManagement.h"
|
||||
|
||||
int main() {
|
||||
|
||||
const auto messaging_interface = std::make_unique<MessagingInterface>();
|
||||
// const auto messaging_interface = std::make_unique<MessagingInterface>();
|
||||
|
||||
const auto modules =
|
||||
messaging_interface->find_connected_modules(std::chrono::seconds(3));
|
||||
// const auto modules = messaging_interface->find_connected_modules(std::chrono::seconds(3));
|
||||
|
||||
std::cout << "Found " << modules.size() << " modules" << std::endl;
|
||||
// std::cout << "Found " << modules.size() << " modules" << std::endl;
|
||||
|
||||
for (const auto module : modules) {
|
||||
std::cout << "Found ID " << (int)module << std::endl;
|
||||
}
|
||||
// for (const auto module : modules) {
|
||||
// std::cout << "Found ID " << (int)module << std::endl;
|
||||
// }
|
||||
|
||||
const auto function_tag = 100;
|
||||
const auto module = 98;
|
||||
std::string msg = "Hello world!";
|
||||
std::vector<uint8_t> parameters(msg.begin(), msg.end());
|
||||
auto maybe_return_value =
|
||||
messaging_interface->remote_call(function_tag, module, parameters);
|
||||
const auto robot_controller = std::make_shared<RobotController>();
|
||||
robot_controller->fetchDirectlyConnectedModules(true);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||
|
||||
if (maybe_return_value) {
|
||||
auto return_value = std::move(*maybe_return_value);
|
||||
std::cout << "Got return value " << (char *)return_value->data()
|
||||
<< std::endl;
|
||||
} else {
|
||||
std::cout << "Function call time out" << std::endl;
|
||||
}
|
||||
// const auto function_tag = 3;
|
||||
// const auto module = 99;
|
||||
// std::string msg = "Hello world!";
|
||||
// std::vector<uint8_t> parameters(msg.begin(), msg.end());
|
||||
// auto maybe_return_value = messaging_interface->remote_call(function_tag, module, parameters);
|
||||
|
||||
return 0;
|
||||
// if (maybe_return_value) {
|
||||
// auto return_value = std::move(*maybe_return_value);
|
||||
// std::cout << "Got return value " << (char *)return_value->data() << std::endl;
|
||||
// } else {
|
||||
// std::cout << "Function call time out" << std::endl;
|
||||
// }
|
||||
//
|
||||
|
||||
std::string filename =
|
||||
"/Users/jslightham/Documents/Classes/capstone/firmware/build/firmware.bin";
|
||||
const auto rm = std::make_unique<RemoteManagement>(99, filename, robot_controller);
|
||||
rm->perform_ota();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
23
examples/rpc_call/rpc/RemoteDebugging.cpp
Normal file
23
examples/rpc_call/rpc/RemoteDebugging.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// Created by Johnathon Slightham on 2026-02-16.
|
||||
//
|
||||
|
||||
#include "rpc/RemoteDebugging.h"
|
||||
|
||||
std::string RemoteDebugging::get_task_manager(uint8_t module_id) {
|
||||
const auto maybe = m_robot_controller->remote_call(2, module_id, {});
|
||||
if (maybe) {
|
||||
std::string str((*maybe)->begin(), (*maybe)->end());
|
||||
return str;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string RemoteDebugging::get_logs(uint8_t module_id) {
|
||||
const auto maybe = m_robot_controller->remote_call(3, module_id, {});
|
||||
if (maybe) {
|
||||
std::string str((*maybe)->begin(), (*maybe)->end());
|
||||
return str;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
98
examples/rpc_call/rpc/RemoteManagement.cpp
Normal file
98
examples/rpc_call/rpc/RemoteManagement.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
//
|
||||
// Created by Johnathon Slightham on 2026-02-16.
|
||||
//
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "rpc/RemoteManagement.h"
|
||||
|
||||
#define MAX_PACKET_TX_ATTEMPTS 5
|
||||
#define OTA_CHUNK_SIZE 1024
|
||||
|
||||
bool RemoteManagement::perform_ota() {
|
||||
if (!m_file) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!start_ota()) {
|
||||
// std::cout << "Fail to start OTA update" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_file.seekg(0, std::ios::end);
|
||||
std::streamsize total_size = m_file.tellg();
|
||||
m_file.seekg(0, std::ios::beg);
|
||||
// std::cout << "Total number of chunks: " << total_size/OTA_CHUNK_SIZE << std::endl;
|
||||
|
||||
while (m_file) {
|
||||
// std::cout << "Top of transmit " << m_sequence_num << std::endl;
|
||||
|
||||
std::vector<uint8_t> buffer(OTA_CHUNK_SIZE);
|
||||
m_file.read(reinterpret_cast<char *>(buffer.data()), buffer.size());
|
||||
std::streamsize bytes_read = m_file.gcount();
|
||||
|
||||
if (bytes_read <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (m_sequence_num == 1 && buffer[0] != 0xE9) {
|
||||
// std::cout << "First byte of firmware must be 0xE9" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// buffer.resize(bytes_read);
|
||||
if (!write_ota(buffer)) {
|
||||
// std::cout << "Failed to write" << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
ota_end();
|
||||
restart();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RemoteManagement::restart() {
|
||||
// Will never return since the module will shutdown
|
||||
m_robot_controller->remote_call(7, m_module_id, {});
|
||||
}
|
||||
|
||||
bool RemoteManagement::start_ota() {
|
||||
// std::cout << "Starting OTA" << std::endl;
|
||||
const auto maybe = m_robot_controller->remote_call(4, m_module_id, {});
|
||||
if (maybe) {
|
||||
// std::cout << "Got valid response" << std::endl;
|
||||
m_sequence_num = 1;
|
||||
return (*maybe)->at(0) > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RemoteManagement::write_ota(std::vector<uint8_t> &transmit_buffer) {
|
||||
// std::cout << "Write OTA " << std::endl;
|
||||
const auto [ota_packet, packet_size] =
|
||||
m_builder->build_ota_packet(m_sequence_num, transmit_buffer);
|
||||
std::vector<uint8_t> vec((uint8_t *)ota_packet, (uint8_t *)ota_packet + packet_size);
|
||||
int attempts = 0;
|
||||
while (attempts < MAX_PACKET_TX_ATTEMPTS) {
|
||||
const auto maybe = m_robot_controller->remote_call(5, m_module_id, vec);
|
||||
if (maybe && (*maybe)->at(0) > 0) {
|
||||
// std::cout << "Success writing OTA" << std::endl;
|
||||
m_sequence_num++;
|
||||
return true;
|
||||
}
|
||||
attempts++;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RemoteManagement::ota_end() {
|
||||
const auto maybe = m_robot_controller->remote_call(6, m_module_id, {});
|
||||
if (maybe) {
|
||||
m_sequence_num = 0;
|
||||
return (*maybe)->at(0) > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -10,23 +10,22 @@
|
||||
|
||||
class Hub final : public Module {
|
||||
|
||||
public:
|
||||
explicit Hub(uint8_t device_id) : Module(device_id) {};
|
||||
public:
|
||||
explicit Hub(uint8_t device_id) : Module(device_id) {};
|
||||
|
||||
Hub(uint8_t device_id, ModuleType module_type)
|
||||
: Module(device_id, module_type) {};
|
||||
Hub(uint8_t device_id, ModuleType module_type) : Module(device_id, module_type) {};
|
||||
|
||||
Hub(uint8_t device_id, ModuleType module_type,
|
||||
Messaging::ConnectionType connection_type, uint8_t leader)
|
||||
: Module(device_id, module_type, connection_type, leader) {};
|
||||
Hub(uint8_t device_id, ModuleType module_type, Messaging::ConnectionType connection_type,
|
||||
uint8_t leader)
|
||||
: Module(device_id, module_type, connection_type, leader) {};
|
||||
|
||||
double get_position() override;
|
||||
std::string get_text() override;
|
||||
void actuate(double position) override;
|
||||
void actuate(double x, double y) override;
|
||||
void actuate(const std::string &t) override;
|
||||
std::vector<uint8_t> get_actuation_message() override;
|
||||
void update_sensor_data(const Flatbuffers::sensor_value &value) override;
|
||||
double get_position() override;
|
||||
std::string get_text() override;
|
||||
void actuate(double position) override;
|
||||
void actuate(double x, double y) override;
|
||||
void actuate(const std::string &t) override;
|
||||
std::vector<uint8_t> get_actuation_message() override;
|
||||
void update_sensor_data(const Flatbuffers::sensor_value &value) override;
|
||||
};
|
||||
|
||||
#endif // CONTROL_HUB_H
|
||||
|
||||
@@ -15,54 +15,54 @@
|
||||
#include "librpc.h"
|
||||
|
||||
struct neighbour {
|
||||
uint8_t device_id;
|
||||
Orientation orientation;
|
||||
uint8_t device_id;
|
||||
Orientation orientation;
|
||||
};
|
||||
|
||||
class Module {
|
||||
public:
|
||||
explicit Module(uint8_t device_id) : m_device_id(device_id) {};
|
||||
public:
|
||||
explicit Module(uint8_t device_id) : m_device_id(device_id) {};
|
||||
|
||||
Module(uint8_t device_id, ModuleType module_type)
|
||||
: m_device_id(device_id), m_module_type(module_type) {};
|
||||
Module(uint8_t device_id, ModuleType module_type)
|
||||
: m_device_id(device_id), m_module_type(module_type) {};
|
||||
|
||||
Module(uint8_t device_id, ModuleType module_type,
|
||||
Messaging::ConnectionType connection_type, uint8_t leader)
|
||||
: m_device_id(device_id), m_module_type(module_type),
|
||||
m_connection_type(connection_type), m_leader(leader) {};
|
||||
Module(uint8_t device_id, ModuleType module_type, Messaging::ConnectionType connection_type,
|
||||
uint8_t leader)
|
||||
: m_device_id(device_id), m_module_type(module_type), m_connection_type(connection_type),
|
||||
m_leader(leader) {};
|
||||
|
||||
std::vector<neighbour> get_neighbours();
|
||||
std::vector<neighbour> get_neighbours();
|
||||
|
||||
uint8_t get_device_id();
|
||||
uint8_t get_device_id();
|
||||
|
||||
ModuleType get_type();
|
||||
ModuleType get_type();
|
||||
|
||||
Messaging::ConnectionType get_connection_type();
|
||||
Messaging::ConnectionType get_connection_type();
|
||||
|
||||
uint8_t get_leader();
|
||||
uint8_t get_leader();
|
||||
|
||||
std::chrono::time_point<std::chrono::system_clock> get_last_updated_time();
|
||||
std::chrono::time_point<std::chrono::system_clock> get_last_updated_time();
|
||||
|
||||
// Not all modules implement all actuation/sensor values, some are no-ops
|
||||
virtual double get_position() = 0;
|
||||
virtual std::string get_text() = 0;
|
||||
virtual void actuate(double x) = 0;
|
||||
virtual void actuate(const std::string &text) = 0;
|
||||
virtual void actuate(double x, double y) = 0;
|
||||
// Not all modules implement all actuation/sensor values, some are no-ops
|
||||
virtual double get_position() = 0;
|
||||
virtual std::string get_text() = 0;
|
||||
virtual void actuate(double x) = 0;
|
||||
virtual void actuate(const std::string &text) = 0;
|
||||
virtual void actuate(double x, double y) = 0;
|
||||
|
||||
void update_module_metadata(const Messaging::TopologyMessage &message);
|
||||
void update_module_metadata(const Messaging::TopologyMessage &message);
|
||||
|
||||
virtual std::vector<uint8_t> get_actuation_message() = 0;
|
||||
virtual void update_sensor_data(const Flatbuffers::sensor_value &value) = 0;
|
||||
virtual std::vector<uint8_t> get_actuation_message() = 0;
|
||||
virtual void update_sensor_data(const Flatbuffers::sensor_value &value) = 0;
|
||||
|
||||
private:
|
||||
uint8_t m_device_id;
|
||||
ModuleType m_module_type;
|
||||
Messaging::ConnectionType m_connection_type;
|
||||
uint8_t m_leader;
|
||||
std::chrono::time_point<std::chrono::system_clock> m_last_updated;
|
||||
std::vector<neighbour> m_neighbours;
|
||||
std::shared_ptr<MessagingInterface> m_messaging_interface;
|
||||
private:
|
||||
uint8_t m_device_id;
|
||||
ModuleType m_module_type;
|
||||
Messaging::ConnectionType m_connection_type;
|
||||
uint8_t m_leader;
|
||||
std::chrono::time_point<std::chrono::system_clock> m_last_updated;
|
||||
std::vector<neighbour> m_neighbours;
|
||||
std::shared_ptr<MessagingInterface> m_messaging_interface;
|
||||
};
|
||||
|
||||
#endif // CONTROL_MODULE_H
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
#include "flatbuffers_generated/RobotModule_generated.h"
|
||||
|
||||
class ModuleFactory {
|
||||
public:
|
||||
static std::shared_ptr<Module>
|
||||
createModule(uint8_t device_id, ModuleType type,
|
||||
std::shared_ptr<MessagingInterface> &messaging_interface);
|
||||
public:
|
||||
static std::shared_ptr<Module>
|
||||
createModule(uint8_t device_id, ModuleType type,
|
||||
std::shared_ptr<MessagingInterface> &messaging_interface);
|
||||
};
|
||||
|
||||
#endif // CONTROL_MODULEFACTORY_H
|
||||
|
||||
@@ -9,21 +9,20 @@
|
||||
#include "flatbuffers_generated/TopologyMessage_generated.h"
|
||||
|
||||
class Actuator : public Module {
|
||||
public:
|
||||
explicit Actuator(uint8_t device_id) : Module(device_id) {};
|
||||
public:
|
||||
explicit Actuator(uint8_t device_id) : Module(device_id) {};
|
||||
|
||||
Actuator(uint8_t device_id, ModuleType module_type)
|
||||
: Module(device_id, module_type) {};
|
||||
Actuator(uint8_t device_id, ModuleType module_type) : Module(device_id, module_type) {};
|
||||
|
||||
Actuator(uint8_t device_id, ModuleType module_type,
|
||||
Messaging::ConnectionType connection_type, uint8_t leader)
|
||||
: Module(device_id, module_type, connection_type, leader) {};
|
||||
Actuator(uint8_t device_id, ModuleType module_type, Messaging::ConnectionType connection_type,
|
||||
uint8_t leader)
|
||||
: Module(device_id, module_type, connection_type, leader) {};
|
||||
|
||||
protected:
|
||||
virtual std::vector<uint8_t> get_actuation_message() = 0;
|
||||
protected:
|
||||
virtual std::vector<uint8_t> get_actuation_message() = 0;
|
||||
|
||||
private:
|
||||
[[noreturn]] void actuator_tx_loop();
|
||||
private:
|
||||
[[noreturn]] void actuator_tx_loop();
|
||||
};
|
||||
|
||||
#endif // CONTROL_MODULE_H
|
||||
|
||||
@@ -13,30 +13,29 @@
|
||||
|
||||
class BoundedPositionalActuator1D : public Actuator {
|
||||
|
||||
public:
|
||||
BoundedPositionalActuator1D(uint8_t device_id, ModuleType type,
|
||||
double max_value, double min_value,
|
||||
double initial_position)
|
||||
: Actuator(device_id, type), m_target_position(initial_position),
|
||||
m_max_value(max_value), m_min_value(min_value),
|
||||
acm_builder(
|
||||
std::make_unique<Flatbuffers::AngleControlMessageBuilder>()) {}
|
||||
public:
|
||||
BoundedPositionalActuator1D(uint8_t device_id, ModuleType type, double max_value,
|
||||
double min_value, double initial_position)
|
||||
: Actuator(device_id, type), m_target_position(initial_position), m_max_value(max_value),
|
||||
m_min_value(min_value),
|
||||
acm_builder(std::make_unique<Flatbuffers::AngleControlMessageBuilder>()) {
|
||||
}
|
||||
|
||||
double get_position() override;
|
||||
std::string get_text() override; // no-op
|
||||
void actuate(double position) override;
|
||||
void actuate(const std::string &text) override; // no-op
|
||||
void actuate(double x, double y) override; // no-op
|
||||
double get_position() override;
|
||||
std::string get_text() override; // no-op
|
||||
void actuate(double position) override;
|
||||
void actuate(const std::string &text) override; // no-op
|
||||
void actuate(double x, double y) override; // no-op
|
||||
|
||||
std::vector<uint8_t> get_actuation_message() override;
|
||||
void update_sensor_data(const Flatbuffers::sensor_value &value) override;
|
||||
std::vector<uint8_t> get_actuation_message() override;
|
||||
void update_sensor_data(const Flatbuffers::sensor_value &value) override;
|
||||
|
||||
private:
|
||||
double m_current_position = 0;
|
||||
double m_target_position;
|
||||
double m_max_value;
|
||||
double m_min_value;
|
||||
std::unique_ptr<Flatbuffers::AngleControlMessageBuilder> acm_builder;
|
||||
private:
|
||||
double m_current_position = 0;
|
||||
double m_target_position;
|
||||
double m_max_value;
|
||||
double m_min_value;
|
||||
std::unique_ptr<Flatbuffers::AngleControlMessageBuilder> acm_builder;
|
||||
};
|
||||
|
||||
#endif // CONTROL_1DPOSITIONALACTUATOR_H
|
||||
|
||||
@@ -13,26 +13,25 @@
|
||||
|
||||
class OledActuator : public Actuator {
|
||||
|
||||
public:
|
||||
OledActuator(uint8_t device_id, ModuleType type)
|
||||
: Actuator(device_id, type),
|
||||
m_text_message_builder(
|
||||
std::make_unique<Flatbuffers::TextControlMessageBuilder>()) {}
|
||||
public:
|
||||
OledActuator(uint8_t device_id, ModuleType type)
|
||||
: Actuator(device_id, type),
|
||||
m_text_message_builder(std::make_unique<Flatbuffers::TextControlMessageBuilder>()) {
|
||||
}
|
||||
|
||||
double get_position() override;
|
||||
std::string get_text() override;
|
||||
void actuate(double position) override;
|
||||
void actuate(double x, double y) override; // no-op
|
||||
void actuate(const std::string &text) override;
|
||||
double get_position() override;
|
||||
std::string get_text() override;
|
||||
void actuate(double position) override;
|
||||
void actuate(double x, double y) override; // no-op
|
||||
void actuate(const std::string &text) override;
|
||||
|
||||
std::vector<uint8_t> get_actuation_message() override;
|
||||
void update_sensor_data(const Flatbuffers::sensor_value &value) override;
|
||||
std::vector<uint8_t> get_actuation_message() override;
|
||||
void update_sensor_data(const Flatbuffers::sensor_value &value) override;
|
||||
|
||||
private:
|
||||
std::string m_current_text = "";
|
||||
std::string m_target_text = "";
|
||||
std::unique_ptr<Flatbuffers::TextControlMessageBuilder>
|
||||
m_text_message_builder;
|
||||
private:
|
||||
std::string m_current_text = "";
|
||||
std::string m_target_text = "";
|
||||
std::unique_ptr<Flatbuffers::TextControlMessageBuilder> m_text_message_builder;
|
||||
};
|
||||
|
||||
#endif // CONTROL_OLEDACTUATOR_H
|
||||
|
||||
@@ -13,27 +13,26 @@
|
||||
|
||||
class PositionalActuator1D final : public Actuator {
|
||||
|
||||
public:
|
||||
PositionalActuator1D(uint8_t device_id, ModuleType type)
|
||||
: Actuator(device_id, type),
|
||||
m_acm_builder(
|
||||
std::make_unique<Flatbuffers::AngleControlMessageBuilder>()) {};
|
||||
public:
|
||||
PositionalActuator1D(uint8_t device_id, ModuleType type)
|
||||
: Actuator(device_id, type),
|
||||
m_acm_builder(std::make_unique<Flatbuffers::AngleControlMessageBuilder>()) {};
|
||||
|
||||
double get_position() override;
|
||||
std::string get_text() override; // no-op
|
||||
void actuate(double position) override;
|
||||
void actuate(const std::string &text) override; // no-op
|
||||
void actuate(double x, double y) override; // no-op
|
||||
double get_position() override;
|
||||
std::string get_text() override; // no-op
|
||||
void actuate(double position) override;
|
||||
void actuate(const std::string &text) override; // no-op
|
||||
void actuate(double x, double y) override; // no-op
|
||||
|
||||
std::vector<uint8_t> get_actuation_message() override;
|
||||
void update_sensor_data(const Flatbuffers::sensor_value &value) override;
|
||||
std::vector<uint8_t> get_actuation_message() override;
|
||||
void update_sensor_data(const Flatbuffers::sensor_value &value) override;
|
||||
|
||||
private:
|
||||
void update_loop();
|
||||
double m_target_position = 0;
|
||||
double m_current_position = 0;
|
||||
double m_board_target_position = 0;
|
||||
std::unique_ptr<Flatbuffers::AngleControlMessageBuilder> m_acm_builder;
|
||||
private:
|
||||
void update_loop();
|
||||
double m_target_position = 0;
|
||||
double m_current_position = 0;
|
||||
double m_board_target_position = 0;
|
||||
std::unique_ptr<Flatbuffers::AngleControlMessageBuilder> m_acm_builder;
|
||||
};
|
||||
|
||||
#endif // CONTROL_1DPOSITIONALACTUATOR_H
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -17,76 +17,68 @@ namespace Messaging {
|
||||
struct AngleControlMessage;
|
||||
struct AngleControlMessageBuilder;
|
||||
|
||||
struct AngleControlMessage FLATBUFFERS_FINAL_CLASS
|
||||
: private ::flatbuffers::Table {
|
||||
typedef AngleControlMessageBuilder Builder;
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
VT_ANGLE = 4
|
||||
};
|
||||
int16_t angle() const { return GetField<int16_t>(VT_ANGLE, 0); }
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<int16_t>(verifier, VT_ANGLE, 2) && verifier.EndTable();
|
||||
}
|
||||
struct AngleControlMessage FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
typedef AngleControlMessageBuilder Builder;
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { VT_ANGLE = 4 };
|
||||
int16_t angle() const {
|
||||
return GetField<int16_t>(VT_ANGLE, 0);
|
||||
}
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) && VerifyField<int16_t>(verifier, VT_ANGLE, 2) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
};
|
||||
|
||||
struct AngleControlMessageBuilder {
|
||||
typedef AngleControlMessage Table;
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_angle(int16_t angle) {
|
||||
fbb_.AddElement<int16_t>(AngleControlMessage::VT_ANGLE, angle, 0);
|
||||
}
|
||||
explicit AngleControlMessageBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
::flatbuffers::Offset<AngleControlMessage> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = ::flatbuffers::Offset<AngleControlMessage>(end);
|
||||
return o;
|
||||
}
|
||||
typedef AngleControlMessage Table;
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_angle(int16_t angle) {
|
||||
fbb_.AddElement<int16_t>(AngleControlMessage::VT_ANGLE, angle, 0);
|
||||
}
|
||||
explicit AngleControlMessageBuilder(::flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
::flatbuffers::Offset<AngleControlMessage> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = ::flatbuffers::Offset<AngleControlMessage>(end);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline ::flatbuffers::Offset<AngleControlMessage>
|
||||
CreateAngleControlMessage(::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
int16_t angle = 0) {
|
||||
AngleControlMessageBuilder builder_(_fbb);
|
||||
builder_.add_angle(angle);
|
||||
return builder_.Finish();
|
||||
CreateAngleControlMessage(::flatbuffers::FlatBufferBuilder &_fbb, int16_t angle = 0) {
|
||||
AngleControlMessageBuilder builder_(_fbb);
|
||||
builder_.add_angle(angle);
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
inline const Messaging::AngleControlMessage *
|
||||
GetAngleControlMessage(const void *buf) {
|
||||
return ::flatbuffers::GetRoot<Messaging::AngleControlMessage>(buf);
|
||||
inline const Messaging::AngleControlMessage *GetAngleControlMessage(const void *buf) {
|
||||
return ::flatbuffers::GetRoot<Messaging::AngleControlMessage>(buf);
|
||||
}
|
||||
|
||||
inline const Messaging::AngleControlMessage *
|
||||
GetSizePrefixedAngleControlMessage(const void *buf) {
|
||||
return ::flatbuffers::GetSizePrefixedRoot<Messaging::AngleControlMessage>(
|
||||
buf);
|
||||
inline const Messaging::AngleControlMessage *GetSizePrefixedAngleControlMessage(const void *buf) {
|
||||
return ::flatbuffers::GetSizePrefixedRoot<Messaging::AngleControlMessage>(buf);
|
||||
}
|
||||
|
||||
inline bool VerifyAngleControlMessageBuffer(::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifyBuffer<Messaging::AngleControlMessage>(nullptr);
|
||||
return verifier.VerifyBuffer<Messaging::AngleControlMessage>(nullptr);
|
||||
}
|
||||
|
||||
inline bool
|
||||
VerifySizePrefixedAngleControlMessageBuffer(::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifySizePrefixedBuffer<Messaging::AngleControlMessage>(
|
||||
nullptr);
|
||||
inline bool VerifySizePrefixedAngleControlMessageBuffer(::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifySizePrefixedBuffer<Messaging::AngleControlMessage>(nullptr);
|
||||
}
|
||||
|
||||
inline void FinishAngleControlMessageBuffer(
|
||||
::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<Messaging::AngleControlMessage> root) {
|
||||
fbb.Finish(root);
|
||||
inline void
|
||||
FinishAngleControlMessageBuffer(::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<Messaging::AngleControlMessage> root) {
|
||||
fbb.Finish(root);
|
||||
}
|
||||
|
||||
inline void FinishSizePrefixedAngleControlMessageBuffer(
|
||||
::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<Messaging::AngleControlMessage> root) {
|
||||
fbb.FinishSizePrefixed(root);
|
||||
fbb.FinishSizePrefixed(root);
|
||||
}
|
||||
|
||||
} // namespace Messaging
|
||||
|
||||
@@ -23,195 +23,177 @@ 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<uint8_t>(VT_FROM_MODULE_ID, 0);
|
||||
}
|
||||
uint8_t to_module_id() const { return GetField<uint8_t>(VT_TO_MODULE_ID, 0); }
|
||||
uint8_t from_socket() const { return GetField<uint8_t>(VT_FROM_SOCKET, 0); }
|
||||
uint8_t to_socket() const { return GetField<uint8_t>(VT_TO_SOCKET, 0); }
|
||||
Orientation orientation() const {
|
||||
return static_cast<Orientation>(GetField<int8_t>(VT_ORIENTATION, 0));
|
||||
}
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<uint8_t>(verifier, VT_FROM_MODULE_ID, 1) &&
|
||||
VerifyField<uint8_t>(verifier, VT_TO_MODULE_ID, 1) &&
|
||||
VerifyField<uint8_t>(verifier, VT_FROM_SOCKET, 1) &&
|
||||
VerifyField<uint8_t>(verifier, VT_TO_SOCKET, 1) &&
|
||||
VerifyField<int8_t>(verifier, VT_ORIENTATION, 1) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
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<uint8_t>(VT_FROM_MODULE_ID, 0);
|
||||
}
|
||||
uint8_t to_module_id() const {
|
||||
return GetField<uint8_t>(VT_TO_MODULE_ID, 0);
|
||||
}
|
||||
uint8_t from_socket() const {
|
||||
return GetField<uint8_t>(VT_FROM_SOCKET, 0);
|
||||
}
|
||||
uint8_t to_socket() const {
|
||||
return GetField<uint8_t>(VT_TO_SOCKET, 0);
|
||||
}
|
||||
Orientation orientation() const {
|
||||
return static_cast<Orientation>(GetField<int8_t>(VT_ORIENTATION, 0));
|
||||
}
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) && VerifyField<uint8_t>(verifier, VT_FROM_MODULE_ID, 1) &&
|
||||
VerifyField<uint8_t>(verifier, VT_TO_MODULE_ID, 1) &&
|
||||
VerifyField<uint8_t>(verifier, VT_FROM_SOCKET, 1) &&
|
||||
VerifyField<uint8_t>(verifier, VT_TO_SOCKET, 1) &&
|
||||
VerifyField<int8_t>(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<uint8_t>(ModuleConnection::VT_FROM_MODULE_ID,
|
||||
from_module_id, 0);
|
||||
}
|
||||
void add_to_module_id(uint8_t to_module_id) {
|
||||
fbb_.AddElement<uint8_t>(ModuleConnection::VT_TO_MODULE_ID, to_module_id,
|
||||
0);
|
||||
}
|
||||
void add_from_socket(uint8_t from_socket) {
|
||||
fbb_.AddElement<uint8_t>(ModuleConnection::VT_FROM_SOCKET, from_socket, 0);
|
||||
}
|
||||
void add_to_socket(uint8_t to_socket) {
|
||||
fbb_.AddElement<uint8_t>(ModuleConnection::VT_TO_SOCKET, to_socket, 0);
|
||||
}
|
||||
void add_orientation(Orientation orientation) {
|
||||
fbb_.AddElement<int8_t>(ModuleConnection::VT_ORIENTATION,
|
||||
static_cast<int8_t>(orientation), 0);
|
||||
}
|
||||
explicit ModuleConnectionBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
::flatbuffers::Offset<ModuleConnection> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = ::flatbuffers::Offset<ModuleConnection>(end);
|
||||
return o;
|
||||
}
|
||||
typedef ModuleConnection Table;
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_from_module_id(uint8_t from_module_id) {
|
||||
fbb_.AddElement<uint8_t>(ModuleConnection::VT_FROM_MODULE_ID, from_module_id, 0);
|
||||
}
|
||||
void add_to_module_id(uint8_t to_module_id) {
|
||||
fbb_.AddElement<uint8_t>(ModuleConnection::VT_TO_MODULE_ID, to_module_id, 0);
|
||||
}
|
||||
void add_from_socket(uint8_t from_socket) {
|
||||
fbb_.AddElement<uint8_t>(ModuleConnection::VT_FROM_SOCKET, from_socket, 0);
|
||||
}
|
||||
void add_to_socket(uint8_t to_socket) {
|
||||
fbb_.AddElement<uint8_t>(ModuleConnection::VT_TO_SOCKET, to_socket, 0);
|
||||
}
|
||||
void add_orientation(Orientation orientation) {
|
||||
fbb_.AddElement<int8_t>(ModuleConnection::VT_ORIENTATION, static_cast<int8_t>(orientation),
|
||||
0);
|
||||
}
|
||||
explicit ModuleConnectionBuilder(::flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
::flatbuffers::Offset<ModuleConnection> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = ::flatbuffers::Offset<ModuleConnection>(end);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline ::flatbuffers::Offset<ModuleConnection>
|
||||
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,
|
||||
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();
|
||||
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<RobotModule>> *
|
||||
modules() const {
|
||||
return GetPointer<
|
||||
const ::flatbuffers::Vector<::flatbuffers::Offset<RobotModule>> *>(
|
||||
VT_MODULES);
|
||||
}
|
||||
const ::flatbuffers::Vector<
|
||||
::flatbuffers::Offset<Frontend::ModuleConnection>> *
|
||||
connections() const {
|
||||
return GetPointer<const ::flatbuffers::Vector<
|
||||
::flatbuffers::Offset<Frontend::ModuleConnection>> *>(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 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<RobotModule>> *modules() const {
|
||||
return GetPointer<const ::flatbuffers::Vector<::flatbuffers::Offset<RobotModule>> *>(
|
||||
VT_MODULES);
|
||||
}
|
||||
const ::flatbuffers::Vector<::flatbuffers::Offset<Frontend::ModuleConnection>> *
|
||||
connections() const {
|
||||
return GetPointer<
|
||||
const ::flatbuffers::Vector<::flatbuffers::Offset<Frontend::ModuleConnection>> *>(
|
||||
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<RobotModule>>>
|
||||
modules) {
|
||||
fbb_.AddOffset(RobotConfiguration::VT_MODULES, modules);
|
||||
}
|
||||
void add_connections(::flatbuffers::Offset<::flatbuffers::Vector<
|
||||
::flatbuffers::Offset<Frontend::ModuleConnection>>>
|
||||
connections) {
|
||||
fbb_.AddOffset(RobotConfiguration::VT_CONNECTIONS, connections);
|
||||
}
|
||||
explicit RobotConfigurationBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
::flatbuffers::Offset<RobotConfiguration> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = ::flatbuffers::Offset<RobotConfiguration>(end);
|
||||
return o;
|
||||
}
|
||||
typedef RobotConfiguration Table;
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_modules(
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<RobotModule>>> modules) {
|
||||
fbb_.AddOffset(RobotConfiguration::VT_MODULES, modules);
|
||||
}
|
||||
void add_connections(::flatbuffers::Offset<
|
||||
::flatbuffers::Vector<::flatbuffers::Offset<Frontend::ModuleConnection>>>
|
||||
connections) {
|
||||
fbb_.AddOffset(RobotConfiguration::VT_CONNECTIONS, connections);
|
||||
}
|
||||
explicit RobotConfigurationBuilder(::flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
::flatbuffers::Offset<RobotConfiguration> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = ::flatbuffers::Offset<RobotConfiguration>(end);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline ::flatbuffers::Offset<RobotConfiguration> CreateRobotConfiguration(
|
||||
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
::flatbuffers::Offset<
|
||||
::flatbuffers::Vector<::flatbuffers::Offset<RobotModule>>>
|
||||
modules = 0,
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<
|
||||
::flatbuffers::Offset<Frontend::ModuleConnection>>>
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<RobotModule>>> modules = 0,
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<Frontend::ModuleConnection>>>
|
||||
connections = 0) {
|
||||
RobotConfigurationBuilder builder_(_fbb);
|
||||
builder_.add_connections(connections);
|
||||
builder_.add_modules(modules);
|
||||
return builder_.Finish();
|
||||
RobotConfigurationBuilder builder_(_fbb);
|
||||
builder_.add_connections(connections);
|
||||
builder_.add_modules(modules);
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
inline ::flatbuffers::Offset<RobotConfiguration> CreateRobotConfigurationDirect(
|
||||
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
const std::vector<::flatbuffers::Offset<RobotModule>> *modules = nullptr,
|
||||
const std::vector<::flatbuffers::Offset<Frontend::ModuleConnection>>
|
||||
*connections = nullptr) {
|
||||
auto modules__ =
|
||||
modules ? _fbb.CreateVector<::flatbuffers::Offset<RobotModule>>(*modules)
|
||||
: 0;
|
||||
auto connections__ =
|
||||
connections
|
||||
? _fbb.CreateVector<
|
||||
::flatbuffers::Offset<Frontend::ModuleConnection>>(*connections)
|
||||
: 0;
|
||||
return Frontend::CreateRobotConfiguration(_fbb, modules__, connections__);
|
||||
const std::vector<::flatbuffers::Offset<Frontend::ModuleConnection>> *connections = nullptr) {
|
||||
auto modules__ = modules ? _fbb.CreateVector<::flatbuffers::Offset<RobotModule>>(*modules) : 0;
|
||||
auto connections__ =
|
||||
connections
|
||||
? _fbb.CreateVector<::flatbuffers::Offset<Frontend::ModuleConnection>>(*connections)
|
||||
: 0;
|
||||
return Frontend::CreateRobotConfiguration(_fbb, modules__, connections__);
|
||||
}
|
||||
|
||||
inline const Frontend::RobotConfiguration *
|
||||
GetRobotConfiguration(const void *buf) {
|
||||
return ::flatbuffers::GetRoot<Frontend::RobotConfiguration>(buf);
|
||||
inline const Frontend::RobotConfiguration *GetRobotConfiguration(const void *buf) {
|
||||
return ::flatbuffers::GetRoot<Frontend::RobotConfiguration>(buf);
|
||||
}
|
||||
|
||||
inline const Frontend::RobotConfiguration *
|
||||
GetSizePrefixedRobotConfiguration(const void *buf) {
|
||||
return ::flatbuffers::GetSizePrefixedRoot<Frontend::RobotConfiguration>(buf);
|
||||
inline const Frontend::RobotConfiguration *GetSizePrefixedRobotConfiguration(const void *buf) {
|
||||
return ::flatbuffers::GetSizePrefixedRoot<Frontend::RobotConfiguration>(buf);
|
||||
}
|
||||
|
||||
inline bool VerifyRobotConfigurationBuffer(::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifyBuffer<Frontend::RobotConfiguration>(nullptr);
|
||||
return verifier.VerifyBuffer<Frontend::RobotConfiguration>(nullptr);
|
||||
}
|
||||
|
||||
inline bool
|
||||
VerifySizePrefixedRobotConfigurationBuffer(::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifySizePrefixedBuffer<Frontend::RobotConfiguration>(
|
||||
nullptr);
|
||||
inline bool VerifySizePrefixedRobotConfigurationBuffer(::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifySizePrefixedBuffer<Frontend::RobotConfiguration>(nullptr);
|
||||
}
|
||||
|
||||
inline void FinishRobotConfigurationBuffer(
|
||||
::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<Frontend::RobotConfiguration> root) {
|
||||
fbb.Finish(root);
|
||||
inline void
|
||||
FinishRobotConfigurationBuffer(::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<Frontend::RobotConfiguration> root) {
|
||||
fbb.Finish(root);
|
||||
}
|
||||
|
||||
inline void FinishSizePrefixedRobotConfigurationBuffer(
|
||||
::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<Frontend::RobotConfiguration> root) {
|
||||
fbb.FinishSizePrefixed(root);
|
||||
fbb.FinishSizePrefixed(root);
|
||||
}
|
||||
|
||||
} // namespace Frontend
|
||||
|
||||
@@ -19,227 +19,218 @@ struct RobotModule;
|
||||
struct RobotModuleBuilder;
|
||||
|
||||
enum ModuleType : int8_t {
|
||||
ModuleType_SPLITTER = 0,
|
||||
ModuleType_SERVO_1 = 1,
|
||||
ModuleType_DC_MOTOR = 2,
|
||||
ModuleType_BATTERY = 3,
|
||||
ModuleType_SERVO_2 = 4,
|
||||
ModuleType_DISPLAY = 5,
|
||||
ModuleType_GRIPPER = 6,
|
||||
ModuleType_SPEAKER = 7,
|
||||
ModuleType_IMU = 8,
|
||||
ModuleType_DISTANCE_SENSOR = 9,
|
||||
ModuleType_SPLITTER_2 = 10,
|
||||
ModuleType_SPLITTER_3 = 11,
|
||||
ModuleType_SPLITTER_4 = 12,
|
||||
ModuleType_SPLITTER_5 = 13,
|
||||
ModuleType_SPLITTER_6 = 14,
|
||||
ModuleType_SPLITTER_7 = 15,
|
||||
ModuleType_SPLITTER_8 = 16,
|
||||
ModuleType_MIN = ModuleType_SPLITTER,
|
||||
ModuleType_MAX = ModuleType_SPLITTER_8
|
||||
ModuleType_SPLITTER = 0,
|
||||
ModuleType_SERVO_1 = 1,
|
||||
ModuleType_DC_MOTOR = 2,
|
||||
ModuleType_BATTERY = 3,
|
||||
ModuleType_SERVO_2 = 4,
|
||||
ModuleType_DISPLAY = 5,
|
||||
ModuleType_GRIPPER = 6,
|
||||
ModuleType_SPEAKER = 7,
|
||||
ModuleType_IMU = 8,
|
||||
ModuleType_DISTANCE_SENSOR = 9,
|
||||
ModuleType_SPLITTER_2 = 10,
|
||||
ModuleType_SPLITTER_3 = 11,
|
||||
ModuleType_SPLITTER_4 = 12,
|
||||
ModuleType_SPLITTER_5 = 13,
|
||||
ModuleType_SPLITTER_6 = 14,
|
||||
ModuleType_SPLITTER_7 = 15,
|
||||
ModuleType_SPLITTER_8 = 16,
|
||||
ModuleType_MIN = ModuleType_SPLITTER,
|
||||
ModuleType_MAX = ModuleType_SPLITTER_8
|
||||
};
|
||||
|
||||
inline const ModuleType (&EnumValuesModuleType())[17] {
|
||||
static const ModuleType values[] = {
|
||||
ModuleType_SPLITTER, ModuleType_SERVO_1, ModuleType_DC_MOTOR,
|
||||
ModuleType_BATTERY, ModuleType_SERVO_2, ModuleType_DISPLAY,
|
||||
ModuleType_GRIPPER, ModuleType_SPEAKER, ModuleType_IMU,
|
||||
ModuleType_DISTANCE_SENSOR, ModuleType_SPLITTER_2, ModuleType_SPLITTER_3,
|
||||
ModuleType_SPLITTER_4, ModuleType_SPLITTER_5, ModuleType_SPLITTER_6,
|
||||
ModuleType_SPLITTER_7, ModuleType_SPLITTER_8};
|
||||
return values;
|
||||
static const ModuleType values[] = {
|
||||
ModuleType_SPLITTER, ModuleType_SERVO_1, ModuleType_DC_MOTOR,
|
||||
ModuleType_BATTERY, ModuleType_SERVO_2, ModuleType_DISPLAY,
|
||||
ModuleType_GRIPPER, ModuleType_SPEAKER, ModuleType_IMU,
|
||||
ModuleType_DISTANCE_SENSOR, ModuleType_SPLITTER_2, ModuleType_SPLITTER_3,
|
||||
ModuleType_SPLITTER_4, ModuleType_SPLITTER_5, ModuleType_SPLITTER_6,
|
||||
ModuleType_SPLITTER_7, ModuleType_SPLITTER_8};
|
||||
return values;
|
||||
}
|
||||
|
||||
inline const char *const *EnumNamesModuleType() {
|
||||
static const char *const names[18] = {
|
||||
"SPLITTER", "SERVO_1", "DC_MOTOR", "BATTERY", "SERVO_2",
|
||||
"DISPLAY", "GRIPPER", "SPEAKER", "IMU", "DISTANCE_SENSOR",
|
||||
"SPLITTER_2", "SPLITTER_3", "SPLITTER_4", "SPLITTER_5", "SPLITTER_6",
|
||||
"SPLITTER_7", "SPLITTER_8", nullptr};
|
||||
return names;
|
||||
static const char *const names[18] = {
|
||||
"SPLITTER", "SERVO_1", "DC_MOTOR", "BATTERY", "SERVO_2", "DISPLAY",
|
||||
"GRIPPER", "SPEAKER", "IMU", "DISTANCE_SENSOR", "SPLITTER_2", "SPLITTER_3",
|
||||
"SPLITTER_4", "SPLITTER_5", "SPLITTER_6", "SPLITTER_7", "SPLITTER_8", nullptr};
|
||||
return names;
|
||||
}
|
||||
|
||||
inline const char *EnumNameModuleType(ModuleType e) {
|
||||
if (::flatbuffers::IsOutRange(e, ModuleType_SPLITTER, ModuleType_SPLITTER_8))
|
||||
return "";
|
||||
const size_t index = static_cast<size_t>(e);
|
||||
return EnumNamesModuleType()[index];
|
||||
if (::flatbuffers::IsOutRange(e, ModuleType_SPLITTER, ModuleType_SPLITTER_8))
|
||||
return "";
|
||||
const size_t index = static_cast<size_t>(e);
|
||||
return EnumNamesModuleType()[index];
|
||||
}
|
||||
|
||||
enum Orientation : int8_t {
|
||||
Orientation_Deg0 = 0,
|
||||
Orientation_Deg90 = 1,
|
||||
Orientation_Deg180 = 2,
|
||||
Orientation_Deg270 = 3,
|
||||
Orientation_MIN = Orientation_Deg0,
|
||||
Orientation_MAX = Orientation_Deg270
|
||||
Orientation_Deg0 = 0,
|
||||
Orientation_Deg90 = 1,
|
||||
Orientation_Deg180 = 2,
|
||||
Orientation_Deg270 = 3,
|
||||
Orientation_MIN = Orientation_Deg0,
|
||||
Orientation_MAX = Orientation_Deg270
|
||||
};
|
||||
|
||||
inline const Orientation (&EnumValuesOrientation())[4] {
|
||||
static const Orientation values[] = {Orientation_Deg0, Orientation_Deg90,
|
||||
Orientation_Deg180, Orientation_Deg270};
|
||||
return values;
|
||||
static const Orientation values[] = {Orientation_Deg0, Orientation_Deg90, Orientation_Deg180,
|
||||
Orientation_Deg270};
|
||||
return values;
|
||||
}
|
||||
|
||||
inline const char *const *EnumNamesOrientation() {
|
||||
static const char *const names[5] = {"Deg0", "Deg90", "Deg180", "Deg270",
|
||||
nullptr};
|
||||
return names;
|
||||
static const char *const names[5] = {"Deg0", "Deg90", "Deg180", "Deg270", nullptr};
|
||||
return names;
|
||||
}
|
||||
|
||||
inline const char *EnumNameOrientation(Orientation e) {
|
||||
if (::flatbuffers::IsOutRange(e, Orientation_Deg0, Orientation_Deg270))
|
||||
return "";
|
||||
const size_t index = static_cast<size_t>(e);
|
||||
return EnumNamesOrientation()[index];
|
||||
if (::flatbuffers::IsOutRange(e, Orientation_Deg0, Orientation_Deg270))
|
||||
return "";
|
||||
const size_t index = static_cast<size_t>(e);
|
||||
return EnumNamesOrientation()[index];
|
||||
}
|
||||
|
||||
enum ModuleState : uint8_t {
|
||||
ModuleState_NONE = 0,
|
||||
ModuleState_MotorState = 1,
|
||||
ModuleState_MIN = ModuleState_NONE,
|
||||
ModuleState_MAX = ModuleState_MotorState
|
||||
ModuleState_NONE = 0,
|
||||
ModuleState_MotorState = 1,
|
||||
ModuleState_MIN = ModuleState_NONE,
|
||||
ModuleState_MAX = ModuleState_MotorState
|
||||
};
|
||||
|
||||
inline const ModuleState (&EnumValuesModuleState())[2] {
|
||||
static const ModuleState values[] = {ModuleState_NONE,
|
||||
ModuleState_MotorState};
|
||||
return values;
|
||||
static const ModuleState values[] = {ModuleState_NONE, ModuleState_MotorState};
|
||||
return values;
|
||||
}
|
||||
|
||||
inline const char *const *EnumNamesModuleState() {
|
||||
static const char *const names[3] = {"NONE", "MotorState", nullptr};
|
||||
return names;
|
||||
static const char *const names[3] = {"NONE", "MotorState", nullptr};
|
||||
return names;
|
||||
}
|
||||
|
||||
inline const char *EnumNameModuleState(ModuleState e) {
|
||||
if (::flatbuffers::IsOutRange(e, ModuleState_NONE, ModuleState_MotorState))
|
||||
return "";
|
||||
const size_t index = static_cast<size_t>(e);
|
||||
return EnumNamesModuleState()[index];
|
||||
if (::flatbuffers::IsOutRange(e, ModuleState_NONE, ModuleState_MotorState))
|
||||
return "";
|
||||
const size_t index = static_cast<size_t>(e);
|
||||
return EnumNamesModuleState()[index];
|
||||
}
|
||||
|
||||
template <typename T> struct ModuleStateTraits {
|
||||
static const ModuleState enum_value = ModuleState_NONE;
|
||||
static const ModuleState enum_value = ModuleState_NONE;
|
||||
};
|
||||
|
||||
template <> struct ModuleStateTraits<MotorState> {
|
||||
static const ModuleState enum_value = ModuleState_MotorState;
|
||||
static const ModuleState enum_value = ModuleState_MotorState;
|
||||
};
|
||||
|
||||
bool VerifyModuleState(::flatbuffers::Verifier &verifier, const void *obj,
|
||||
ModuleState type);
|
||||
bool VerifyModuleStateVector(
|
||||
::flatbuffers::Verifier &verifier,
|
||||
const ::flatbuffers::Vector<::flatbuffers::Offset<void>> *values,
|
||||
const ::flatbuffers::Vector<uint8_t> *types);
|
||||
bool VerifyModuleState(::flatbuffers::Verifier &verifier, const void *obj, ModuleState type);
|
||||
bool VerifyModuleStateVector(::flatbuffers::Verifier &verifier,
|
||||
const ::flatbuffers::Vector<::flatbuffers::Offset<void>> *values,
|
||||
const ::flatbuffers::Vector<uint8_t> *types);
|
||||
|
||||
struct MotorState FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
typedef MotorStateBuilder Builder;
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
VT_ANGLE = 4
|
||||
};
|
||||
int32_t angle() const { return GetField<int32_t>(VT_ANGLE, 0); }
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<int32_t>(verifier, VT_ANGLE, 4) && verifier.EndTable();
|
||||
}
|
||||
typedef MotorStateBuilder Builder;
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { VT_ANGLE = 4 };
|
||||
int32_t angle() const {
|
||||
return GetField<int32_t>(VT_ANGLE, 0);
|
||||
}
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) && VerifyField<int32_t>(verifier, VT_ANGLE, 4) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
};
|
||||
|
||||
struct MotorStateBuilder {
|
||||
typedef MotorState Table;
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_angle(int32_t angle) {
|
||||
fbb_.AddElement<int32_t>(MotorState::VT_ANGLE, angle, 0);
|
||||
}
|
||||
explicit MotorStateBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
::flatbuffers::Offset<MotorState> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = ::flatbuffers::Offset<MotorState>(end);
|
||||
return o;
|
||||
}
|
||||
typedef MotorState Table;
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_angle(int32_t angle) {
|
||||
fbb_.AddElement<int32_t>(MotorState::VT_ANGLE, angle, 0);
|
||||
}
|
||||
explicit MotorStateBuilder(::flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
::flatbuffers::Offset<MotorState> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = ::flatbuffers::Offset<MotorState>(end);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline ::flatbuffers::Offset<MotorState>
|
||||
CreateMotorState(::flatbuffers::FlatBufferBuilder &_fbb, int32_t angle = 0) {
|
||||
MotorStateBuilder builder_(_fbb);
|
||||
builder_.add_angle(angle);
|
||||
return builder_.Finish();
|
||||
inline ::flatbuffers::Offset<MotorState> CreateMotorState(::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
int32_t angle = 0) {
|
||||
MotorStateBuilder builder_(_fbb);
|
||||
builder_.add_angle(angle);
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
struct RobotModule FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
typedef RobotModuleBuilder Builder;
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
VT_ID = 4,
|
||||
VT_MODULE_TYPE = 6,
|
||||
VT_CONFIGURATION_TYPE = 8,
|
||||
VT_CONFIGURATION = 10
|
||||
};
|
||||
uint8_t id() const { return GetField<uint8_t>(VT_ID, 0); }
|
||||
ModuleType module_type() const {
|
||||
return static_cast<ModuleType>(GetField<int8_t>(VT_MODULE_TYPE, 0));
|
||||
}
|
||||
ModuleState configuration_type() const {
|
||||
return static_cast<ModuleState>(
|
||||
GetField<uint8_t>(VT_CONFIGURATION_TYPE, 0));
|
||||
}
|
||||
const void *configuration() const {
|
||||
return GetPointer<const void *>(VT_CONFIGURATION);
|
||||
}
|
||||
template <typename T> const T *configuration_as() const;
|
||||
const MotorState *configuration_as_MotorState() const {
|
||||
return configuration_type() == ModuleState_MotorState
|
||||
? static_cast<const MotorState *>(configuration())
|
||||
: nullptr;
|
||||
}
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<uint8_t>(verifier, VT_ID, 1) &&
|
||||
VerifyField<int8_t>(verifier, VT_MODULE_TYPE, 1) &&
|
||||
VerifyField<uint8_t>(verifier, VT_CONFIGURATION_TYPE, 1) &&
|
||||
VerifyOffset(verifier, VT_CONFIGURATION) &&
|
||||
VerifyModuleState(verifier, configuration(), configuration_type()) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
typedef RobotModuleBuilder Builder;
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
VT_ID = 4,
|
||||
VT_MODULE_TYPE = 6,
|
||||
VT_CONFIGURATION_TYPE = 8,
|
||||
VT_CONFIGURATION = 10
|
||||
};
|
||||
uint8_t id() const {
|
||||
return GetField<uint8_t>(VT_ID, 0);
|
||||
}
|
||||
ModuleType module_type() const {
|
||||
return static_cast<ModuleType>(GetField<int8_t>(VT_MODULE_TYPE, 0));
|
||||
}
|
||||
ModuleState configuration_type() const {
|
||||
return static_cast<ModuleState>(GetField<uint8_t>(VT_CONFIGURATION_TYPE, 0));
|
||||
}
|
||||
const void *configuration() const {
|
||||
return GetPointer<const void *>(VT_CONFIGURATION);
|
||||
}
|
||||
template <typename T> const T *configuration_as() const;
|
||||
const MotorState *configuration_as_MotorState() const {
|
||||
return configuration_type() == ModuleState_MotorState
|
||||
? static_cast<const MotorState *>(configuration())
|
||||
: nullptr;
|
||||
}
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) && VerifyField<uint8_t>(verifier, VT_ID, 1) &&
|
||||
VerifyField<int8_t>(verifier, VT_MODULE_TYPE, 1) &&
|
||||
VerifyField<uint8_t>(verifier, VT_CONFIGURATION_TYPE, 1) &&
|
||||
VerifyOffset(verifier, VT_CONFIGURATION) &&
|
||||
VerifyModuleState(verifier, configuration(), configuration_type()) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
inline const MotorState *RobotModule::configuration_as<MotorState>() const {
|
||||
return configuration_as_MotorState();
|
||||
template <> inline const MotorState *RobotModule::configuration_as<MotorState>() const {
|
||||
return configuration_as_MotorState();
|
||||
}
|
||||
|
||||
struct RobotModuleBuilder {
|
||||
typedef RobotModule Table;
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_id(uint8_t id) {
|
||||
fbb_.AddElement<uint8_t>(RobotModule::VT_ID, id, 0);
|
||||
}
|
||||
void add_module_type(ModuleType module_type) {
|
||||
fbb_.AddElement<int8_t>(RobotModule::VT_MODULE_TYPE,
|
||||
static_cast<int8_t>(module_type), 0);
|
||||
}
|
||||
void add_configuration_type(ModuleState configuration_type) {
|
||||
fbb_.AddElement<uint8_t>(RobotModule::VT_CONFIGURATION_TYPE,
|
||||
static_cast<uint8_t>(configuration_type), 0);
|
||||
}
|
||||
void add_configuration(::flatbuffers::Offset<void> configuration) {
|
||||
fbb_.AddOffset(RobotModule::VT_CONFIGURATION, configuration);
|
||||
}
|
||||
explicit RobotModuleBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
::flatbuffers::Offset<RobotModule> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = ::flatbuffers::Offset<RobotModule>(end);
|
||||
return o;
|
||||
}
|
||||
typedef RobotModule Table;
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_id(uint8_t id) {
|
||||
fbb_.AddElement<uint8_t>(RobotModule::VT_ID, id, 0);
|
||||
}
|
||||
void add_module_type(ModuleType module_type) {
|
||||
fbb_.AddElement<int8_t>(RobotModule::VT_MODULE_TYPE, static_cast<int8_t>(module_type), 0);
|
||||
}
|
||||
void add_configuration_type(ModuleState configuration_type) {
|
||||
fbb_.AddElement<uint8_t>(RobotModule::VT_CONFIGURATION_TYPE,
|
||||
static_cast<uint8_t>(configuration_type), 0);
|
||||
}
|
||||
void add_configuration(::flatbuffers::Offset<void> configuration) {
|
||||
fbb_.AddOffset(RobotModule::VT_CONFIGURATION, configuration);
|
||||
}
|
||||
explicit RobotModuleBuilder(::flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
::flatbuffers::Offset<RobotModule> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = ::flatbuffers::Offset<RobotModule>(end);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline ::flatbuffers::Offset<RobotModule>
|
||||
@@ -247,72 +238,69 @@ CreateRobotModule(::flatbuffers::FlatBufferBuilder &_fbb, uint8_t id = 0,
|
||||
ModuleType module_type = ModuleType_SPLITTER,
|
||||
ModuleState configuration_type = ModuleState_NONE,
|
||||
::flatbuffers::Offset<void> configuration = 0) {
|
||||
RobotModuleBuilder builder_(_fbb);
|
||||
builder_.add_configuration(configuration);
|
||||
builder_.add_configuration_type(configuration_type);
|
||||
builder_.add_module_type(module_type);
|
||||
builder_.add_id(id);
|
||||
return builder_.Finish();
|
||||
RobotModuleBuilder builder_(_fbb);
|
||||
builder_.add_configuration(configuration);
|
||||
builder_.add_configuration_type(configuration_type);
|
||||
builder_.add_module_type(module_type);
|
||||
builder_.add_id(id);
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
inline bool VerifyModuleState(::flatbuffers::Verifier &verifier,
|
||||
const void *obj, ModuleState type) {
|
||||
switch (type) {
|
||||
case ModuleState_NONE: {
|
||||
return true;
|
||||
}
|
||||
case ModuleState_MotorState: {
|
||||
auto ptr = reinterpret_cast<const MotorState *>(obj);
|
||||
return verifier.VerifyTable(ptr);
|
||||
}
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool VerifyModuleStateVector(
|
||||
::flatbuffers::Verifier &verifier,
|
||||
const ::flatbuffers::Vector<::flatbuffers::Offset<void>> *values,
|
||||
const ::flatbuffers::Vector<uint8_t> *types) {
|
||||
if (!values || !types)
|
||||
return !values && !types;
|
||||
if (values->size() != types->size())
|
||||
return false;
|
||||
for (::flatbuffers::uoffset_t i = 0; i < values->size(); ++i) {
|
||||
if (!VerifyModuleState(verifier, values->Get(i),
|
||||
types->GetEnum<ModuleState>(i))) {
|
||||
return false;
|
||||
inline bool VerifyModuleState(::flatbuffers::Verifier &verifier, const void *obj,
|
||||
ModuleState type) {
|
||||
switch (type) {
|
||||
case ModuleState_NONE: {
|
||||
return true;
|
||||
}
|
||||
case ModuleState_MotorState: {
|
||||
auto ptr = reinterpret_cast<const MotorState *>(obj);
|
||||
return verifier.VerifyTable(ptr);
|
||||
}
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
inline const RobotModule *GetRobotModule(const void *buf) {
|
||||
return ::flatbuffers::GetRoot<RobotModule>(buf);
|
||||
}
|
||||
|
||||
inline const RobotModule *GetSizePrefixedRobotModule(const void *buf) {
|
||||
return ::flatbuffers::GetSizePrefixedRoot<RobotModule>(buf);
|
||||
}
|
||||
|
||||
inline bool VerifyRobotModuleBuffer(::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifyBuffer<RobotModule>(nullptr);
|
||||
}
|
||||
|
||||
inline bool
|
||||
VerifySizePrefixedRobotModuleBuffer(::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifySizePrefixedBuffer<RobotModule>(nullptr);
|
||||
VerifyModuleStateVector(::flatbuffers::Verifier &verifier,
|
||||
const ::flatbuffers::Vector<::flatbuffers::Offset<void>> *values,
|
||||
const ::flatbuffers::Vector<uint8_t> *types) {
|
||||
if (!values || !types)
|
||||
return !values && !types;
|
||||
if (values->size() != types->size())
|
||||
return false;
|
||||
for (::flatbuffers::uoffset_t i = 0; i < values->size(); ++i) {
|
||||
if (!VerifyModuleState(verifier, values->Get(i), types->GetEnum<ModuleState>(i))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
inline const RobotModule *GetRobotModule(const void *buf) {
|
||||
return ::flatbuffers::GetRoot<RobotModule>(buf);
|
||||
}
|
||||
|
||||
inline const RobotModule *GetSizePrefixedRobotModule(const void *buf) {
|
||||
return ::flatbuffers::GetSizePrefixedRoot<RobotModule>(buf);
|
||||
}
|
||||
|
||||
inline bool VerifyRobotModuleBuffer(::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifyBuffer<RobotModule>(nullptr);
|
||||
}
|
||||
|
||||
inline bool VerifySizePrefixedRobotModuleBuffer(::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifySizePrefixedBuffer<RobotModule>(nullptr);
|
||||
}
|
||||
|
||||
inline void FinishRobotModuleBuffer(::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<RobotModule> root) {
|
||||
fbb.Finish(root);
|
||||
fbb.Finish(root);
|
||||
}
|
||||
|
||||
inline void
|
||||
FinishSizePrefixedRobotModuleBuffer(::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<RobotModule> root) {
|
||||
fbb.FinishSizePrefixed(root);
|
||||
inline void FinishSizePrefixedRobotModuleBuffer(::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<RobotModule> root) {
|
||||
fbb.FinishSizePrefixed(root);
|
||||
}
|
||||
|
||||
#endif // FLATBUFFERS_GENERATED_ROBOTMODULE_H_
|
||||
|
||||
@@ -27,316 +27,293 @@ struct SensorMessage;
|
||||
struct SensorMessageBuilder;
|
||||
|
||||
enum SensorValue : uint8_t {
|
||||
SensorValue_NONE = 0,
|
||||
SensorValue_TargetAngle = 1,
|
||||
SensorValue_CurrentAngle = 2,
|
||||
SensorValue_CurrentText = 3,
|
||||
SensorValue_MIN = SensorValue_NONE,
|
||||
SensorValue_MAX = SensorValue_CurrentText
|
||||
SensorValue_NONE = 0,
|
||||
SensorValue_TargetAngle = 1,
|
||||
SensorValue_CurrentAngle = 2,
|
||||
SensorValue_CurrentText = 3,
|
||||
SensorValue_MIN = SensorValue_NONE,
|
||||
SensorValue_MAX = SensorValue_CurrentText
|
||||
};
|
||||
|
||||
inline const SensorValue (&EnumValuesSensorValue())[4] {
|
||||
static const SensorValue values[] = {
|
||||
SensorValue_NONE, SensorValue_TargetAngle, SensorValue_CurrentAngle,
|
||||
SensorValue_CurrentText};
|
||||
return values;
|
||||
static const SensorValue values[] = {SensorValue_NONE, SensorValue_TargetAngle,
|
||||
SensorValue_CurrentAngle, SensorValue_CurrentText};
|
||||
return values;
|
||||
}
|
||||
|
||||
inline const char *const *EnumNamesSensorValue() {
|
||||
static const char *const names[5] = {"NONE", "TargetAngle", "CurrentAngle",
|
||||
"CurrentText", nullptr};
|
||||
return names;
|
||||
static const char *const names[5] = {"NONE", "TargetAngle", "CurrentAngle", "CurrentText",
|
||||
nullptr};
|
||||
return names;
|
||||
}
|
||||
|
||||
inline const char *EnumNameSensorValue(SensorValue e) {
|
||||
if (::flatbuffers::IsOutRange(e, SensorValue_NONE, SensorValue_CurrentText))
|
||||
return "";
|
||||
const size_t index = static_cast<size_t>(e);
|
||||
return EnumNamesSensorValue()[index];
|
||||
if (::flatbuffers::IsOutRange(e, SensorValue_NONE, SensorValue_CurrentText))
|
||||
return "";
|
||||
const size_t index = static_cast<size_t>(e);
|
||||
return EnumNamesSensorValue()[index];
|
||||
}
|
||||
|
||||
template <typename T> struct SensorValueTraits {
|
||||
static const SensorValue enum_value = SensorValue_NONE;
|
||||
static const SensorValue enum_value = SensorValue_NONE;
|
||||
};
|
||||
|
||||
template <> struct SensorValueTraits<Messaging::TargetAngle> {
|
||||
static const SensorValue enum_value = SensorValue_TargetAngle;
|
||||
static const SensorValue enum_value = SensorValue_TargetAngle;
|
||||
};
|
||||
|
||||
template <> struct SensorValueTraits<Messaging::CurrentAngle> {
|
||||
static const SensorValue enum_value = SensorValue_CurrentAngle;
|
||||
static const SensorValue enum_value = SensorValue_CurrentAngle;
|
||||
};
|
||||
|
||||
template <> struct SensorValueTraits<Messaging::CurrentText> {
|
||||
static const SensorValue enum_value = SensorValue_CurrentText;
|
||||
static const SensorValue enum_value = SensorValue_CurrentText;
|
||||
};
|
||||
|
||||
bool VerifySensorValue(::flatbuffers::Verifier &verifier, const void *obj,
|
||||
SensorValue type);
|
||||
bool VerifySensorValueVector(
|
||||
::flatbuffers::Verifier &verifier,
|
||||
const ::flatbuffers::Vector<::flatbuffers::Offset<void>> *values,
|
||||
const ::flatbuffers::Vector<uint8_t> *types);
|
||||
bool VerifySensorValue(::flatbuffers::Verifier &verifier, const void *obj, SensorValue type);
|
||||
bool VerifySensorValueVector(::flatbuffers::Verifier &verifier,
|
||||
const ::flatbuffers::Vector<::flatbuffers::Offset<void>> *values,
|
||||
const ::flatbuffers::Vector<uint8_t> *types);
|
||||
|
||||
struct TargetAngle FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
typedef TargetAngleBuilder Builder;
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
VT_VALUE = 4
|
||||
};
|
||||
int16_t value() const { return GetField<int16_t>(VT_VALUE, 0); }
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<int16_t>(verifier, VT_VALUE, 2) && verifier.EndTable();
|
||||
}
|
||||
typedef TargetAngleBuilder Builder;
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { VT_VALUE = 4 };
|
||||
int16_t value() const {
|
||||
return GetField<int16_t>(VT_VALUE, 0);
|
||||
}
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) && VerifyField<int16_t>(verifier, VT_VALUE, 2) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
};
|
||||
|
||||
struct TargetAngleBuilder {
|
||||
typedef TargetAngle Table;
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_value(int16_t value) {
|
||||
fbb_.AddElement<int16_t>(TargetAngle::VT_VALUE, value, 0);
|
||||
}
|
||||
explicit TargetAngleBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
::flatbuffers::Offset<TargetAngle> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = ::flatbuffers::Offset<TargetAngle>(end);
|
||||
return o;
|
||||
}
|
||||
typedef TargetAngle Table;
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_value(int16_t value) {
|
||||
fbb_.AddElement<int16_t>(TargetAngle::VT_VALUE, value, 0);
|
||||
}
|
||||
explicit TargetAngleBuilder(::flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
::flatbuffers::Offset<TargetAngle> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = ::flatbuffers::Offset<TargetAngle>(end);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline ::flatbuffers::Offset<TargetAngle>
|
||||
CreateTargetAngle(::flatbuffers::FlatBufferBuilder &_fbb, int16_t value = 0) {
|
||||
TargetAngleBuilder builder_(_fbb);
|
||||
builder_.add_value(value);
|
||||
return builder_.Finish();
|
||||
inline ::flatbuffers::Offset<TargetAngle> CreateTargetAngle(::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
int16_t value = 0) {
|
||||
TargetAngleBuilder builder_(_fbb);
|
||||
builder_.add_value(value);
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
struct CurrentText FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
typedef CurrentTextBuilder Builder;
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
VT_VALUE = 4
|
||||
};
|
||||
const ::flatbuffers::String *value() const {
|
||||
return GetPointer<const ::flatbuffers::String *>(VT_VALUE);
|
||||
}
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_VALUE) &&
|
||||
verifier.VerifyString(value()) && verifier.EndTable();
|
||||
}
|
||||
typedef CurrentTextBuilder Builder;
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { VT_VALUE = 4 };
|
||||
const ::flatbuffers::String *value() const {
|
||||
return GetPointer<const ::flatbuffers::String *>(VT_VALUE);
|
||||
}
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_VALUE) &&
|
||||
verifier.VerifyString(value()) && verifier.EndTable();
|
||||
}
|
||||
};
|
||||
|
||||
struct CurrentTextBuilder {
|
||||
typedef CurrentText Table;
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_value(::flatbuffers::Offset<::flatbuffers::String> value) {
|
||||
fbb_.AddOffset(CurrentText::VT_VALUE, value);
|
||||
}
|
||||
explicit CurrentTextBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
::flatbuffers::Offset<CurrentText> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = ::flatbuffers::Offset<CurrentText>(end);
|
||||
return o;
|
||||
}
|
||||
typedef CurrentText Table;
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_value(::flatbuffers::Offset<::flatbuffers::String> value) {
|
||||
fbb_.AddOffset(CurrentText::VT_VALUE, value);
|
||||
}
|
||||
explicit CurrentTextBuilder(::flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
::flatbuffers::Offset<CurrentText> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = ::flatbuffers::Offset<CurrentText>(end);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline ::flatbuffers::Offset<CurrentText>
|
||||
CreateCurrentText(::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
::flatbuffers::Offset<::flatbuffers::String> value = 0) {
|
||||
CurrentTextBuilder builder_(_fbb);
|
||||
builder_.add_value(value);
|
||||
return builder_.Finish();
|
||||
CurrentTextBuilder builder_(_fbb);
|
||||
builder_.add_value(value);
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
inline ::flatbuffers::Offset<CurrentText>
|
||||
CreateCurrentTextDirect(::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
const char *value = nullptr) {
|
||||
auto value__ = value ? _fbb.CreateString(value) : 0;
|
||||
return Messaging::CreateCurrentText(_fbb, value__);
|
||||
CreateCurrentTextDirect(::flatbuffers::FlatBufferBuilder &_fbb, const char *value = nullptr) {
|
||||
auto value__ = value ? _fbb.CreateString(value) : 0;
|
||||
return Messaging::CreateCurrentText(_fbb, value__);
|
||||
}
|
||||
|
||||
struct CurrentAngle FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
typedef CurrentAngleBuilder Builder;
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
VT_VALUE = 4
|
||||
};
|
||||
int16_t value() const { return GetField<int16_t>(VT_VALUE, 0); }
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<int16_t>(verifier, VT_VALUE, 2) && verifier.EndTable();
|
||||
}
|
||||
typedef CurrentAngleBuilder Builder;
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { VT_VALUE = 4 };
|
||||
int16_t value() const {
|
||||
return GetField<int16_t>(VT_VALUE, 0);
|
||||
}
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) && VerifyField<int16_t>(verifier, VT_VALUE, 2) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
};
|
||||
|
||||
struct CurrentAngleBuilder {
|
||||
typedef CurrentAngle Table;
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_value(int16_t value) {
|
||||
fbb_.AddElement<int16_t>(CurrentAngle::VT_VALUE, value, 0);
|
||||
}
|
||||
explicit CurrentAngleBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
::flatbuffers::Offset<CurrentAngle> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = ::flatbuffers::Offset<CurrentAngle>(end);
|
||||
return o;
|
||||
}
|
||||
typedef CurrentAngle Table;
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_value(int16_t value) {
|
||||
fbb_.AddElement<int16_t>(CurrentAngle::VT_VALUE, value, 0);
|
||||
}
|
||||
explicit CurrentAngleBuilder(::flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
::flatbuffers::Offset<CurrentAngle> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = ::flatbuffers::Offset<CurrentAngle>(end);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline ::flatbuffers::Offset<CurrentAngle>
|
||||
CreateCurrentAngle(::flatbuffers::FlatBufferBuilder &_fbb, int16_t value = 0) {
|
||||
CurrentAngleBuilder builder_(_fbb);
|
||||
builder_.add_value(value);
|
||||
return builder_.Finish();
|
||||
CurrentAngleBuilder builder_(_fbb);
|
||||
builder_.add_value(value);
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
struct SensorMessage FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
typedef SensorMessageBuilder Builder;
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
VT_VALUES_TYPE = 4,
|
||||
VT_VALUES = 6
|
||||
};
|
||||
const ::flatbuffers::Vector<uint8_t> *values_type() const {
|
||||
return GetPointer<const ::flatbuffers::Vector<uint8_t> *>(VT_VALUES_TYPE);
|
||||
}
|
||||
const ::flatbuffers::Vector<::flatbuffers::Offset<void>> *values() const {
|
||||
return GetPointer<
|
||||
const ::flatbuffers::Vector<::flatbuffers::Offset<void>> *>(VT_VALUES);
|
||||
}
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyOffset(verifier, VT_VALUES_TYPE) &&
|
||||
verifier.VerifyVector(values_type()) &&
|
||||
VerifyOffset(verifier, VT_VALUES) &&
|
||||
verifier.VerifyVector(values()) &&
|
||||
VerifySensorValueVector(verifier, values(), values_type()) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
typedef SensorMessageBuilder Builder;
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
VT_VALUES_TYPE = 4,
|
||||
VT_VALUES = 6
|
||||
};
|
||||
const ::flatbuffers::Vector<uint8_t> *values_type() const {
|
||||
return GetPointer<const ::flatbuffers::Vector<uint8_t> *>(VT_VALUES_TYPE);
|
||||
}
|
||||
const ::flatbuffers::Vector<::flatbuffers::Offset<void>> *values() const {
|
||||
return GetPointer<const ::flatbuffers::Vector<::flatbuffers::Offset<void>> *>(VT_VALUES);
|
||||
}
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_VALUES_TYPE) &&
|
||||
verifier.VerifyVector(values_type()) && VerifyOffset(verifier, VT_VALUES) &&
|
||||
verifier.VerifyVector(values()) &&
|
||||
VerifySensorValueVector(verifier, values(), values_type()) && verifier.EndTable();
|
||||
}
|
||||
};
|
||||
|
||||
struct SensorMessageBuilder {
|
||||
typedef SensorMessage Table;
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_values_type(
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<uint8_t>> values_type) {
|
||||
fbb_.AddOffset(SensorMessage::VT_VALUES_TYPE, values_type);
|
||||
}
|
||||
void add_values(
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<void>>>
|
||||
values) {
|
||||
fbb_.AddOffset(SensorMessage::VT_VALUES, values);
|
||||
}
|
||||
explicit SensorMessageBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
::flatbuffers::Offset<SensorMessage> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = ::flatbuffers::Offset<SensorMessage>(end);
|
||||
return o;
|
||||
}
|
||||
typedef SensorMessage Table;
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_values_type(::flatbuffers::Offset<::flatbuffers::Vector<uint8_t>> values_type) {
|
||||
fbb_.AddOffset(SensorMessage::VT_VALUES_TYPE, values_type);
|
||||
}
|
||||
void
|
||||
add_values(::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<void>>> values) {
|
||||
fbb_.AddOffset(SensorMessage::VT_VALUES, values);
|
||||
}
|
||||
explicit SensorMessageBuilder(::flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
::flatbuffers::Offset<SensorMessage> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = ::flatbuffers::Offset<SensorMessage>(end);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline ::flatbuffers::Offset<SensorMessage> CreateSensorMessage(
|
||||
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<uint8_t>> values_type = 0,
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<void>>>
|
||||
values = 0) {
|
||||
SensorMessageBuilder builder_(_fbb);
|
||||
builder_.add_values(values);
|
||||
builder_.add_values_type(values_type);
|
||||
return builder_.Finish();
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<void>>> values = 0) {
|
||||
SensorMessageBuilder builder_(_fbb);
|
||||
builder_.add_values(values);
|
||||
builder_.add_values_type(values_type);
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
inline ::flatbuffers::Offset<SensorMessage> CreateSensorMessageDirect(
|
||||
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
const std::vector<uint8_t> *values_type = nullptr,
|
||||
const std::vector<::flatbuffers::Offset<void>> *values = nullptr) {
|
||||
auto values_type__ =
|
||||
values_type ? _fbb.CreateVector<uint8_t>(*values_type) : 0;
|
||||
auto values__ =
|
||||
values ? _fbb.CreateVector<::flatbuffers::Offset<void>>(*values) : 0;
|
||||
return Messaging::CreateSensorMessage(_fbb, values_type__, values__);
|
||||
inline ::flatbuffers::Offset<SensorMessage>
|
||||
CreateSensorMessageDirect(::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
const std::vector<uint8_t> *values_type = nullptr,
|
||||
const std::vector<::flatbuffers::Offset<void>> *values = nullptr) {
|
||||
auto values_type__ = values_type ? _fbb.CreateVector<uint8_t>(*values_type) : 0;
|
||||
auto values__ = values ? _fbb.CreateVector<::flatbuffers::Offset<void>>(*values) : 0;
|
||||
return Messaging::CreateSensorMessage(_fbb, values_type__, values__);
|
||||
}
|
||||
|
||||
inline bool VerifySensorValue(::flatbuffers::Verifier &verifier,
|
||||
const void *obj, SensorValue type) {
|
||||
switch (type) {
|
||||
case SensorValue_NONE: {
|
||||
return true;
|
||||
}
|
||||
case SensorValue_TargetAngle: {
|
||||
auto ptr = reinterpret_cast<const Messaging::TargetAngle *>(obj);
|
||||
return verifier.VerifyTable(ptr);
|
||||
}
|
||||
case SensorValue_CurrentAngle: {
|
||||
auto ptr = reinterpret_cast<const Messaging::CurrentAngle *>(obj);
|
||||
return verifier.VerifyTable(ptr);
|
||||
}
|
||||
case SensorValue_CurrentText: {
|
||||
auto ptr = reinterpret_cast<const Messaging::CurrentText *>(obj);
|
||||
return verifier.VerifyTable(ptr);
|
||||
}
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool VerifySensorValueVector(
|
||||
::flatbuffers::Verifier &verifier,
|
||||
const ::flatbuffers::Vector<::flatbuffers::Offset<void>> *values,
|
||||
const ::flatbuffers::Vector<uint8_t> *types) {
|
||||
if (!values || !types)
|
||||
return !values && !types;
|
||||
if (values->size() != types->size())
|
||||
return false;
|
||||
for (::flatbuffers::uoffset_t i = 0; i < values->size(); ++i) {
|
||||
if (!VerifySensorValue(verifier, values->Get(i),
|
||||
types->GetEnum<SensorValue>(i))) {
|
||||
return false;
|
||||
inline bool VerifySensorValue(::flatbuffers::Verifier &verifier, const void *obj,
|
||||
SensorValue type) {
|
||||
switch (type) {
|
||||
case SensorValue_NONE: {
|
||||
return true;
|
||||
}
|
||||
case SensorValue_TargetAngle: {
|
||||
auto ptr = reinterpret_cast<const Messaging::TargetAngle *>(obj);
|
||||
return verifier.VerifyTable(ptr);
|
||||
}
|
||||
case SensorValue_CurrentAngle: {
|
||||
auto ptr = reinterpret_cast<const Messaging::CurrentAngle *>(obj);
|
||||
return verifier.VerifyTable(ptr);
|
||||
}
|
||||
case SensorValue_CurrentText: {
|
||||
auto ptr = reinterpret_cast<const Messaging::CurrentText *>(obj);
|
||||
return verifier.VerifyTable(ptr);
|
||||
}
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
inline const Messaging::SensorMessage *GetSensorMessage(const void *buf) {
|
||||
return ::flatbuffers::GetRoot<Messaging::SensorMessage>(buf);
|
||||
}
|
||||
|
||||
inline const Messaging::SensorMessage *
|
||||
GetSizePrefixedSensorMessage(const void *buf) {
|
||||
return ::flatbuffers::GetSizePrefixedRoot<Messaging::SensorMessage>(buf);
|
||||
}
|
||||
|
||||
inline bool VerifySensorMessageBuffer(::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifyBuffer<Messaging::SensorMessage>(nullptr);
|
||||
}
|
||||
|
||||
inline bool
|
||||
VerifySizePrefixedSensorMessageBuffer(::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifySizePrefixedBuffer<Messaging::SensorMessage>(nullptr);
|
||||
VerifySensorValueVector(::flatbuffers::Verifier &verifier,
|
||||
const ::flatbuffers::Vector<::flatbuffers::Offset<void>> *values,
|
||||
const ::flatbuffers::Vector<uint8_t> *types) {
|
||||
if (!values || !types)
|
||||
return !values && !types;
|
||||
if (values->size() != types->size())
|
||||
return false;
|
||||
for (::flatbuffers::uoffset_t i = 0; i < values->size(); ++i) {
|
||||
if (!VerifySensorValue(verifier, values->Get(i), types->GetEnum<SensorValue>(i))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void FinishSensorMessageBuffer(
|
||||
::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<Messaging::SensorMessage> root) {
|
||||
fbb.Finish(root);
|
||||
inline const Messaging::SensorMessage *GetSensorMessage(const void *buf) {
|
||||
return ::flatbuffers::GetRoot<Messaging::SensorMessage>(buf);
|
||||
}
|
||||
|
||||
inline void FinishSizePrefixedSensorMessageBuffer(
|
||||
::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<Messaging::SensorMessage> root) {
|
||||
fbb.FinishSizePrefixed(root);
|
||||
inline const Messaging::SensorMessage *GetSizePrefixedSensorMessage(const void *buf) {
|
||||
return ::flatbuffers::GetSizePrefixedRoot<Messaging::SensorMessage>(buf);
|
||||
}
|
||||
|
||||
inline bool VerifySensorMessageBuffer(::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifyBuffer<Messaging::SensorMessage>(nullptr);
|
||||
}
|
||||
|
||||
inline bool VerifySizePrefixedSensorMessageBuffer(::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifySizePrefixedBuffer<Messaging::SensorMessage>(nullptr);
|
||||
}
|
||||
|
||||
inline void FinishSensorMessageBuffer(::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<Messaging::SensorMessage> root) {
|
||||
fbb.Finish(root);
|
||||
}
|
||||
|
||||
inline void
|
||||
FinishSizePrefixedSensorMessageBuffer(::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<Messaging::SensorMessage> root) {
|
||||
fbb.FinishSizePrefixed(root);
|
||||
}
|
||||
|
||||
} // namespace Messaging
|
||||
|
||||
@@ -17,84 +17,76 @@ namespace Messaging {
|
||||
struct TextControlMessage;
|
||||
struct TextControlMessageBuilder;
|
||||
|
||||
struct TextControlMessage FLATBUFFERS_FINAL_CLASS
|
||||
: private ::flatbuffers::Table {
|
||||
typedef TextControlMessageBuilder Builder;
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
VT_MESSAGE = 4
|
||||
};
|
||||
const ::flatbuffers::String *message() const {
|
||||
return GetPointer<const ::flatbuffers::String *>(VT_MESSAGE);
|
||||
}
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_MESSAGE) &&
|
||||
verifier.VerifyString(message()) && verifier.EndTable();
|
||||
}
|
||||
struct TextControlMessage FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
typedef TextControlMessageBuilder Builder;
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { VT_MESSAGE = 4 };
|
||||
const ::flatbuffers::String *message() const {
|
||||
return GetPointer<const ::flatbuffers::String *>(VT_MESSAGE);
|
||||
}
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_MESSAGE) &&
|
||||
verifier.VerifyString(message()) && verifier.EndTable();
|
||||
}
|
||||
};
|
||||
|
||||
struct TextControlMessageBuilder {
|
||||
typedef TextControlMessage Table;
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_message(::flatbuffers::Offset<::flatbuffers::String> message) {
|
||||
fbb_.AddOffset(TextControlMessage::VT_MESSAGE, message);
|
||||
}
|
||||
explicit TextControlMessageBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
::flatbuffers::Offset<TextControlMessage> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = ::flatbuffers::Offset<TextControlMessage>(end);
|
||||
return o;
|
||||
}
|
||||
typedef TextControlMessage Table;
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_message(::flatbuffers::Offset<::flatbuffers::String> message) {
|
||||
fbb_.AddOffset(TextControlMessage::VT_MESSAGE, message);
|
||||
}
|
||||
explicit TextControlMessageBuilder(::flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
::flatbuffers::Offset<TextControlMessage> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = ::flatbuffers::Offset<TextControlMessage>(end);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline ::flatbuffers::Offset<TextControlMessage> CreateTextControlMessage(
|
||||
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
::flatbuffers::Offset<::flatbuffers::String> message = 0) {
|
||||
TextControlMessageBuilder builder_(_fbb);
|
||||
builder_.add_message(message);
|
||||
return builder_.Finish();
|
||||
inline ::flatbuffers::Offset<TextControlMessage>
|
||||
CreateTextControlMessage(::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
::flatbuffers::Offset<::flatbuffers::String> message = 0) {
|
||||
TextControlMessageBuilder builder_(_fbb);
|
||||
builder_.add_message(message);
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
inline ::flatbuffers::Offset<TextControlMessage>
|
||||
CreateTextControlMessageDirect(::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
const char *message = nullptr) {
|
||||
auto message__ = message ? _fbb.CreateString(message) : 0;
|
||||
return Messaging::CreateTextControlMessage(_fbb, message__);
|
||||
auto message__ = message ? _fbb.CreateString(message) : 0;
|
||||
return Messaging::CreateTextControlMessage(_fbb, message__);
|
||||
}
|
||||
|
||||
inline const Messaging::TextControlMessage *
|
||||
GetTextControlMessage(const void *buf) {
|
||||
return ::flatbuffers::GetRoot<Messaging::TextControlMessage>(buf);
|
||||
inline const Messaging::TextControlMessage *GetTextControlMessage(const void *buf) {
|
||||
return ::flatbuffers::GetRoot<Messaging::TextControlMessage>(buf);
|
||||
}
|
||||
|
||||
inline const Messaging::TextControlMessage *
|
||||
GetSizePrefixedTextControlMessage(const void *buf) {
|
||||
return ::flatbuffers::GetSizePrefixedRoot<Messaging::TextControlMessage>(buf);
|
||||
inline const Messaging::TextControlMessage *GetSizePrefixedTextControlMessage(const void *buf) {
|
||||
return ::flatbuffers::GetSizePrefixedRoot<Messaging::TextControlMessage>(buf);
|
||||
}
|
||||
|
||||
inline bool VerifyTextControlMessageBuffer(::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifyBuffer<Messaging::TextControlMessage>(nullptr);
|
||||
return verifier.VerifyBuffer<Messaging::TextControlMessage>(nullptr);
|
||||
}
|
||||
|
||||
inline bool
|
||||
VerifySizePrefixedTextControlMessageBuffer(::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifySizePrefixedBuffer<Messaging::TextControlMessage>(
|
||||
nullptr);
|
||||
inline bool VerifySizePrefixedTextControlMessageBuffer(::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifySizePrefixedBuffer<Messaging::TextControlMessage>(nullptr);
|
||||
}
|
||||
|
||||
inline void FinishTextControlMessageBuffer(
|
||||
::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<Messaging::TextControlMessage> root) {
|
||||
fbb.Finish(root);
|
||||
inline void
|
||||
FinishTextControlMessageBuffer(::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<Messaging::TextControlMessage> root) {
|
||||
fbb.Finish(root);
|
||||
}
|
||||
|
||||
inline void FinishSizePrefixedTextControlMessageBuffer(
|
||||
::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<Messaging::TextControlMessage> root) {
|
||||
fbb.FinishSizePrefixed(root);
|
||||
fbb.FinishSizePrefixed(root);
|
||||
}
|
||||
|
||||
} // namespace Messaging
|
||||
|
||||
@@ -20,192 +20,182 @@ struct TopologyMessage;
|
||||
struct TopologyMessageBuilder;
|
||||
|
||||
enum ConnectionType : int8_t {
|
||||
ConnectionType_DIRECT = 0,
|
||||
ConnectionType_HOP = 1,
|
||||
ConnectionType_MIN = ConnectionType_DIRECT,
|
||||
ConnectionType_MAX = ConnectionType_HOP
|
||||
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;
|
||||
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;
|
||||
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<size_t>(e);
|
||||
return EnumNamesConnectionType()[index];
|
||||
if (::flatbuffers::IsOutRange(e, ConnectionType_DIRECT, ConnectionType_HOP))
|
||||
return "";
|
||||
const size_t index = static_cast<size_t>(e);
|
||||
return EnumNamesConnectionType()[index];
|
||||
}
|
||||
|
||||
struct TopologyMessage FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
typedef TopologyMessageBuilder Builder;
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
VT_MODULE_ID = 4,
|
||||
VT_MODULE_TYPE = 6,
|
||||
VT_NUM_CHANNELS = 8,
|
||||
VT_CHANNEL_TO_MODULE = 10,
|
||||
VT_CHANNEL_TO_ORIENTATION = 12,
|
||||
VT_CONNECTION = 14,
|
||||
VT_LEADER = 16,
|
||||
VT_FIRMWARE = 18
|
||||
};
|
||||
uint8_t module_id() const { return GetField<uint8_t>(VT_MODULE_ID, 0); }
|
||||
ModuleType module_type() const {
|
||||
return static_cast<ModuleType>(GetField<int8_t>(VT_MODULE_TYPE, 0));
|
||||
}
|
||||
uint8_t num_channels() const { return GetField<uint8_t>(VT_NUM_CHANNELS, 0); }
|
||||
const ::flatbuffers::Vector<uint8_t> *channel_to_module() const {
|
||||
return GetPointer<const ::flatbuffers::Vector<uint8_t> *>(
|
||||
VT_CHANNEL_TO_MODULE);
|
||||
}
|
||||
const ::flatbuffers::Vector<int8_t> *channel_to_orientation() const {
|
||||
return GetPointer<const ::flatbuffers::Vector<int8_t> *>(
|
||||
VT_CHANNEL_TO_ORIENTATION);
|
||||
}
|
||||
Messaging::ConnectionType connection() const {
|
||||
return static_cast<Messaging::ConnectionType>(
|
||||
GetField<int8_t>(VT_CONNECTION, 0));
|
||||
}
|
||||
uint8_t leader() const { return GetField<uint8_t>(VT_LEADER, 0); }
|
||||
const ::flatbuffers::String *firmware() const {
|
||||
return GetPointer<const ::flatbuffers::String *>(VT_FIRMWARE);
|
||||
}
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<uint8_t>(verifier, VT_MODULE_ID, 1) &&
|
||||
VerifyField<int8_t>(verifier, VT_MODULE_TYPE, 1) &&
|
||||
VerifyField<uint8_t>(verifier, VT_NUM_CHANNELS, 1) &&
|
||||
VerifyOffset(verifier, VT_CHANNEL_TO_MODULE) &&
|
||||
verifier.VerifyVector(channel_to_module()) &&
|
||||
VerifyOffset(verifier, VT_CHANNEL_TO_ORIENTATION) &&
|
||||
verifier.VerifyVector(channel_to_orientation()) &&
|
||||
VerifyField<int8_t>(verifier, VT_CONNECTION, 1) &&
|
||||
VerifyField<uint8_t>(verifier, VT_LEADER, 1) &&
|
||||
VerifyOffset(verifier, VT_FIRMWARE) &&
|
||||
verifier.VerifyString(firmware()) && verifier.EndTable();
|
||||
}
|
||||
typedef TopologyMessageBuilder Builder;
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
VT_MODULE_ID = 4,
|
||||
VT_MODULE_TYPE = 6,
|
||||
VT_NUM_CHANNELS = 8,
|
||||
VT_CHANNEL_TO_MODULE = 10,
|
||||
VT_CHANNEL_TO_ORIENTATION = 12,
|
||||
VT_CONNECTION = 14,
|
||||
VT_LEADER = 16,
|
||||
VT_FIRMWARE = 18
|
||||
};
|
||||
uint8_t module_id() const {
|
||||
return GetField<uint8_t>(VT_MODULE_ID, 0);
|
||||
}
|
||||
ModuleType module_type() const {
|
||||
return static_cast<ModuleType>(GetField<int8_t>(VT_MODULE_TYPE, 0));
|
||||
}
|
||||
uint8_t num_channels() const {
|
||||
return GetField<uint8_t>(VT_NUM_CHANNELS, 0);
|
||||
}
|
||||
const ::flatbuffers::Vector<uint8_t> *channel_to_module() const {
|
||||
return GetPointer<const ::flatbuffers::Vector<uint8_t> *>(VT_CHANNEL_TO_MODULE);
|
||||
}
|
||||
const ::flatbuffers::Vector<int8_t> *channel_to_orientation() const {
|
||||
return GetPointer<const ::flatbuffers::Vector<int8_t> *>(VT_CHANNEL_TO_ORIENTATION);
|
||||
}
|
||||
Messaging::ConnectionType connection() const {
|
||||
return static_cast<Messaging::ConnectionType>(GetField<int8_t>(VT_CONNECTION, 0));
|
||||
}
|
||||
uint8_t leader() const {
|
||||
return GetField<uint8_t>(VT_LEADER, 0);
|
||||
}
|
||||
const ::flatbuffers::String *firmware() const {
|
||||
return GetPointer<const ::flatbuffers::String *>(VT_FIRMWARE);
|
||||
}
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) && VerifyField<uint8_t>(verifier, VT_MODULE_ID, 1) &&
|
||||
VerifyField<int8_t>(verifier, VT_MODULE_TYPE, 1) &&
|
||||
VerifyField<uint8_t>(verifier, VT_NUM_CHANNELS, 1) &&
|
||||
VerifyOffset(verifier, VT_CHANNEL_TO_MODULE) &&
|
||||
verifier.VerifyVector(channel_to_module()) &&
|
||||
VerifyOffset(verifier, VT_CHANNEL_TO_ORIENTATION) &&
|
||||
verifier.VerifyVector(channel_to_orientation()) &&
|
||||
VerifyField<int8_t>(verifier, VT_CONNECTION, 1) &&
|
||||
VerifyField<uint8_t>(verifier, VT_LEADER, 1) &&
|
||||
VerifyOffset(verifier, VT_FIRMWARE) && verifier.VerifyString(firmware()) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
};
|
||||
|
||||
struct TopologyMessageBuilder {
|
||||
typedef TopologyMessage Table;
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_module_id(uint8_t module_id) {
|
||||
fbb_.AddElement<uint8_t>(TopologyMessage::VT_MODULE_ID, module_id, 0);
|
||||
}
|
||||
void add_module_type(ModuleType module_type) {
|
||||
fbb_.AddElement<int8_t>(TopologyMessage::VT_MODULE_TYPE,
|
||||
static_cast<int8_t>(module_type), 0);
|
||||
}
|
||||
void add_num_channels(uint8_t num_channels) {
|
||||
fbb_.AddElement<uint8_t>(TopologyMessage::VT_NUM_CHANNELS, num_channels, 0);
|
||||
}
|
||||
void add_channel_to_module(
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<uint8_t>> channel_to_module) {
|
||||
fbb_.AddOffset(TopologyMessage::VT_CHANNEL_TO_MODULE, channel_to_module);
|
||||
}
|
||||
void add_channel_to_orientation(
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<int8_t>>
|
||||
channel_to_orientation) {
|
||||
fbb_.AddOffset(TopologyMessage::VT_CHANNEL_TO_ORIENTATION,
|
||||
channel_to_orientation);
|
||||
}
|
||||
void add_connection(Messaging::ConnectionType connection) {
|
||||
fbb_.AddElement<int8_t>(TopologyMessage::VT_CONNECTION,
|
||||
static_cast<int8_t>(connection), 0);
|
||||
}
|
||||
void add_leader(uint8_t leader) {
|
||||
fbb_.AddElement<uint8_t>(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();
|
||||
}
|
||||
::flatbuffers::Offset<TopologyMessage> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = ::flatbuffers::Offset<TopologyMessage>(end);
|
||||
return o;
|
||||
}
|
||||
typedef TopologyMessage Table;
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_module_id(uint8_t module_id) {
|
||||
fbb_.AddElement<uint8_t>(TopologyMessage::VT_MODULE_ID, module_id, 0);
|
||||
}
|
||||
void add_module_type(ModuleType module_type) {
|
||||
fbb_.AddElement<int8_t>(TopologyMessage::VT_MODULE_TYPE, static_cast<int8_t>(module_type),
|
||||
0);
|
||||
}
|
||||
void add_num_channels(uint8_t num_channels) {
|
||||
fbb_.AddElement<uint8_t>(TopologyMessage::VT_NUM_CHANNELS, num_channels, 0);
|
||||
}
|
||||
void
|
||||
add_channel_to_module(::flatbuffers::Offset<::flatbuffers::Vector<uint8_t>> channel_to_module) {
|
||||
fbb_.AddOffset(TopologyMessage::VT_CHANNEL_TO_MODULE, channel_to_module);
|
||||
}
|
||||
void add_channel_to_orientation(
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<int8_t>> channel_to_orientation) {
|
||||
fbb_.AddOffset(TopologyMessage::VT_CHANNEL_TO_ORIENTATION, channel_to_orientation);
|
||||
}
|
||||
void add_connection(Messaging::ConnectionType connection) {
|
||||
fbb_.AddElement<int8_t>(TopologyMessage::VT_CONNECTION, static_cast<int8_t>(connection), 0);
|
||||
}
|
||||
void add_leader(uint8_t leader) {
|
||||
fbb_.AddElement<uint8_t>(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();
|
||||
}
|
||||
::flatbuffers::Offset<TopologyMessage> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = ::flatbuffers::Offset<TopologyMessage>(end);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline ::flatbuffers::Offset<TopologyMessage> CreateTopologyMessage(
|
||||
::flatbuffers::FlatBufferBuilder &_fbb, uint8_t module_id = 0,
|
||||
ModuleType module_type = ModuleType_SPLITTER, uint8_t num_channels = 0,
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<uint8_t>> channel_to_module = 0,
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<int8_t>>
|
||||
channel_to_orientation = 0,
|
||||
Messaging::ConnectionType connection = Messaging::ConnectionType_DIRECT,
|
||||
uint8_t leader = 0,
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<int8_t>> 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);
|
||||
return builder_.Finish();
|
||||
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);
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
inline ::flatbuffers::Offset<TopologyMessage> CreateTopologyMessageDirect(
|
||||
::flatbuffers::FlatBufferBuilder &_fbb, uint8_t module_id = 0,
|
||||
ModuleType module_type = ModuleType_SPLITTER, uint8_t num_channels = 0,
|
||||
const std::vector<uint8_t> *channel_to_module = nullptr,
|
||||
const std::vector<int8_t> *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<uint8_t>(*channel_to_module) : 0;
|
||||
auto channel_to_orientation__ =
|
||||
channel_to_orientation
|
||||
? _fbb.CreateVector<int8_t>(*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__, connection, leader, firmware__);
|
||||
inline ::flatbuffers::Offset<TopologyMessage>
|
||||
CreateTopologyMessageDirect(::flatbuffers::FlatBufferBuilder &_fbb, uint8_t module_id = 0,
|
||||
ModuleType module_type = ModuleType_SPLITTER, uint8_t num_channels = 0,
|
||||
const std::vector<uint8_t> *channel_to_module = nullptr,
|
||||
const std::vector<int8_t> *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<uint8_t>(*channel_to_module) : 0;
|
||||
auto channel_to_orientation__ =
|
||||
channel_to_orientation ? _fbb.CreateVector<int8_t>(*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__,
|
||||
connection, leader, firmware__);
|
||||
}
|
||||
|
||||
inline const Messaging::TopologyMessage *GetTopologyMessage(const void *buf) {
|
||||
return ::flatbuffers::GetRoot<Messaging::TopologyMessage>(buf);
|
||||
return ::flatbuffers::GetRoot<Messaging::TopologyMessage>(buf);
|
||||
}
|
||||
|
||||
inline const Messaging::TopologyMessage *
|
||||
GetSizePrefixedTopologyMessage(const void *buf) {
|
||||
return ::flatbuffers::GetSizePrefixedRoot<Messaging::TopologyMessage>(buf);
|
||||
inline const Messaging::TopologyMessage *GetSizePrefixedTopologyMessage(const void *buf) {
|
||||
return ::flatbuffers::GetSizePrefixedRoot<Messaging::TopologyMessage>(buf);
|
||||
}
|
||||
|
||||
inline bool VerifyTopologyMessageBuffer(::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifyBuffer<Messaging::TopologyMessage>(nullptr);
|
||||
return verifier.VerifyBuffer<Messaging::TopologyMessage>(nullptr);
|
||||
}
|
||||
|
||||
inline bool
|
||||
VerifySizePrefixedTopologyMessageBuffer(::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifySizePrefixedBuffer<Messaging::TopologyMessage>(nullptr);
|
||||
inline bool VerifySizePrefixedTopologyMessageBuffer(::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifySizePrefixedBuffer<Messaging::TopologyMessage>(nullptr);
|
||||
}
|
||||
|
||||
inline void FinishTopologyMessageBuffer(
|
||||
::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<Messaging::TopologyMessage> root) {
|
||||
fbb.Finish(root);
|
||||
inline void FinishTopologyMessageBuffer(::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<Messaging::TopologyMessage> root) {
|
||||
fbb.Finish(root);
|
||||
}
|
||||
|
||||
inline void FinishSizePrefixedTopologyMessageBuffer(
|
||||
::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<Messaging::TopologyMessage> root) {
|
||||
fbb.FinishSizePrefixed(root);
|
||||
inline void
|
||||
FinishSizePrefixedTopologyMessageBuffer(::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<Messaging::TopologyMessage> root) {
|
||||
fbb.FinishSizePrefixed(root);
|
||||
}
|
||||
|
||||
} // namespace Messaging
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef CONTROL_LIBRARY_H
|
||||
#define CONTROL_LIBRARY_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(_WIN32) || defined(__CYGWIN__)
|
||||
#ifdef CONTROL_EXPORTS
|
||||
#define LIB_API __declspec(dllexport)
|
||||
@@ -17,10 +19,12 @@ LIB_API void cleanup();
|
||||
LIB_API int send_angle_control(int module_id, int angle);
|
||||
LIB_API char *get_configuration(int *size_out);
|
||||
|
||||
LIB_API bool control_sentry_init(const char *dsn, const char *environment,
|
||||
const char *release);
|
||||
LIB_API void control_sentry_set_app_info(const char *app_name,
|
||||
const char *app_version,
|
||||
LIB_API bool remote_call_c(uint8_t function_tag, uint8_t module, const uint8_t *params,
|
||||
uint16_t params_len, uint8_t *out_buffer, uint16_t out_buffer_capacity,
|
||||
uint16_t *out_bytes_written);
|
||||
|
||||
LIB_API bool control_sentry_init(const char *dsn, const char *environment, const char *release);
|
||||
LIB_API void control_sentry_set_app_info(const char *app_name, const char *app_version,
|
||||
const char *build_number);
|
||||
LIB_API void control_sentry_shutdown(void);
|
||||
}
|
||||
|
||||
@@ -27,29 +27,28 @@
|
||||
*/
|
||||
class RobotController {
|
||||
|
||||
public:
|
||||
/**
|
||||
public:
|
||||
/**
|
||||
* \brief Creates a new RobotController.
|
||||
*
|
||||
* Each RobotController will establish unique connections to accessible
|
||||
* BotChain modules.
|
||||
*/
|
||||
RobotController()
|
||||
: m_messaging_interface(std::make_unique<MessagingInterface>()),
|
||||
m_metadata_loop(std::thread(&RobotController::metadata_loop, this)),
|
||||
m_transmit_loop(std::thread(&RobotController::transmit_loop, this)),
|
||||
m_configuration_loop(
|
||||
std::thread(&RobotController::configuration_loop, this)),
|
||||
m_sensor_loop(std::thread(&RobotController::sensor_loop, this)),
|
||||
m_expiry_looop(std::thread(&RobotController::expiry_loop, this)) {
|
||||
m_logger = spdlog::basic_logger_mt("default_logger", "libcontrol.log");
|
||||
spdlog::flush_on(spdlog::level::info);
|
||||
spdlog::set_default_logger(m_logger);
|
||||
}
|
||||
RobotController()
|
||||
: m_messaging_interface(std::make_unique<MessagingInterface>()),
|
||||
m_metadata_loop(std::thread(&RobotController::metadata_loop, this)),
|
||||
m_transmit_loop(std::thread(&RobotController::transmit_loop, this)),
|
||||
m_configuration_loop(std::thread(&RobotController::configuration_loop, this)),
|
||||
m_sensor_loop(std::thread(&RobotController::sensor_loop, this)),
|
||||
m_expiry_looop(std::thread(&RobotController::expiry_loop, this)) {
|
||||
m_logger = spdlog::basic_logger_mt("default_logger", "libcontrol.log");
|
||||
spdlog::flush_on(spdlog::level::info);
|
||||
spdlog::set_default_logger(m_logger);
|
||||
}
|
||||
|
||||
~RobotController();
|
||||
~RobotController();
|
||||
|
||||
/**
|
||||
/**
|
||||
* \brief Get a list of accessible modules
|
||||
*
|
||||
* Returns a std::vector containing robotic modules. This list includes
|
||||
@@ -58,9 +57,9 @@ public:
|
||||
* commands can be sent by calling the "as" function for the correct
|
||||
* type (can be identified through the ModuleType).
|
||||
*/
|
||||
std::vector<std::weak_ptr<Module>> getModules();
|
||||
std::vector<std::weak_ptr<Module>> getModules();
|
||||
|
||||
/**
|
||||
/**
|
||||
* \brief Get a module by ID
|
||||
*
|
||||
* Returns a std::vector containing robotic modules. This list includes
|
||||
@@ -69,60 +68,62 @@ public:
|
||||
* commands can be sent by calling the "as" function for the correct
|
||||
* type (can be identified through the ModuleType).
|
||||
*/
|
||||
std::optional<std::weak_ptr<Module>> getModule(uint8_t device_id);
|
||||
std::optional<std::weak_ptr<Module>> getModule(uint8_t device_id);
|
||||
|
||||
/**
|
||||
/**
|
||||
* \brief Get a list of all connections.
|
||||
*
|
||||
* Returns a list containing all connections between modules.
|
||||
*/
|
||||
std::vector<Flatbuffers::ModuleConnectionInstance> getConnections();
|
||||
std::vector<Flatbuffers::ModuleConnectionInstance> getConnections();
|
||||
|
||||
/**
|
||||
/**
|
||||
* \brief Get a list of accessible modules.
|
||||
*
|
||||
* Returns a list containing ID and types of each module.
|
||||
*/
|
||||
std::vector<Flatbuffers::ModuleInstance> getModuleList();
|
||||
std::vector<Flatbuffers::ModuleInstance> getModuleList();
|
||||
|
||||
/**
|
||||
/**
|
||||
* \brief Reset the list of modules.
|
||||
*
|
||||
* Reset the internal list containing known modules. Note: This list is
|
||||
* automatically updated, only call this function when you need to update the
|
||||
* list faster than the internal refresh logic.
|
||||
*/
|
||||
void resetModules();
|
||||
void resetModules();
|
||||
|
||||
/**
|
||||
/**
|
||||
* \brief Poll for devices accessible to the PC.
|
||||
*
|
||||
* Manually trigger a poll for devices accessible to the PC.
|
||||
*/
|
||||
void fetchDirectlyConnectedModules(bool block);
|
||||
void fetchDirectlyConnectedModules(bool block);
|
||||
|
||||
private:
|
||||
std::shared_ptr<spdlog::logger> m_logger;
|
||||
std::unordered_map<uint8_t, std::shared_ptr<Module>> m_id_to_module{};
|
||||
std::unordered_map<uint8_t,
|
||||
std::vector<Flatbuffers::ModuleConnectionInstance>>
|
||||
m_connection_map{};
|
||||
std::shared_mutex m_module_lock{};
|
||||
std::shared_mutex m_connection_lock{};
|
||||
std::shared_ptr<MessagingInterface> m_messaging_interface;
|
||||
std::atomic<bool> m_stop_thread{false}; // todo: make sure threads stop if we
|
||||
// dont get any messages (timeouts)
|
||||
std::thread m_metadata_loop;
|
||||
std::thread m_transmit_loop;
|
||||
std::thread m_configuration_loop;
|
||||
std::thread m_sensor_loop;
|
||||
std::thread m_expiry_looop;
|
||||
std::optional<std::unique_ptr<std::vector<uint8_t>>>
|
||||
remote_call(uint8_t function_tag, uint8_t module, const std::vector<uint8_t> ¶meters);
|
||||
|
||||
void metadata_loop();
|
||||
void transmit_loop();
|
||||
void configuration_loop();
|
||||
void sensor_loop();
|
||||
void expiry_loop();
|
||||
private:
|
||||
std::shared_ptr<spdlog::logger> m_logger;
|
||||
std::unordered_map<uint8_t, std::shared_ptr<Module>> m_id_to_module{};
|
||||
std::unordered_map<uint8_t, std::vector<Flatbuffers::ModuleConnectionInstance>>
|
||||
m_connection_map{};
|
||||
std::shared_mutex m_module_lock{};
|
||||
std::shared_mutex m_connection_lock{};
|
||||
std::shared_ptr<MessagingInterface> m_messaging_interface;
|
||||
std::atomic<bool> m_stop_thread{false}; // todo: make sure threads stop if we
|
||||
// dont get any messages (timeouts)
|
||||
std::thread m_metadata_loop;
|
||||
std::thread m_transmit_loop;
|
||||
std::thread m_configuration_loop;
|
||||
std::thread m_sensor_loop;
|
||||
std::thread m_expiry_looop;
|
||||
|
||||
void metadata_loop();
|
||||
void transmit_loop();
|
||||
void configuration_loop();
|
||||
void sensor_loop();
|
||||
void expiry_loop();
|
||||
};
|
||||
|
||||
#endif // CONTROL_LIBCONTROL_H
|
||||
|
||||
@@ -7,41 +7,44 @@
|
||||
class Event;
|
||||
|
||||
class CallbackHandle {
|
||||
public:
|
||||
CallbackHandle(Event *evt, int id) : evt(evt), id(id) {}
|
||||
~CallbackHandle();
|
||||
public:
|
||||
CallbackHandle(Event *evt, int id) : evt(evt), id(id) {
|
||||
}
|
||||
~CallbackHandle();
|
||||
|
||||
private:
|
||||
Event *evt;
|
||||
int id;
|
||||
private:
|
||||
Event *evt;
|
||||
int id;
|
||||
};
|
||||
|
||||
class Event {
|
||||
public:
|
||||
using Callback = std::function<void()>;
|
||||
public:
|
||||
using Callback = std::function<void()>;
|
||||
|
||||
CallbackHandle addListener(Callback cb) {
|
||||
int id = nextId++;
|
||||
callbacks[id] = std::move(cb);
|
||||
return CallbackHandle(this, id);
|
||||
}
|
||||
CallbackHandle addListener(Callback cb) {
|
||||
int id = nextId++;
|
||||
callbacks[id] = std::move(cb);
|
||||
return CallbackHandle(this, id);
|
||||
}
|
||||
|
||||
void remove(int id) { callbacks.erase(id); }
|
||||
void remove(int id) {
|
||||
callbacks.erase(id);
|
||||
}
|
||||
|
||||
void fire() {
|
||||
for (auto &kv : callbacks)
|
||||
kv.second();
|
||||
}
|
||||
void fire() {
|
||||
for (auto &kv : callbacks)
|
||||
kv.second();
|
||||
}
|
||||
|
||||
private:
|
||||
friend class CallbackHandle;
|
||||
std::unordered_map<int, Callback> callbacks;
|
||||
int nextId = 0;
|
||||
private:
|
||||
friend class CallbackHandle;
|
||||
std::unordered_map<int, Callback> callbacks;
|
||||
int nextId = 0;
|
||||
};
|
||||
|
||||
CallbackHandle::~CallbackHandle() {
|
||||
if (evt)
|
||||
evt->remove(id);
|
||||
if (evt)
|
||||
evt->remove(id);
|
||||
}
|
||||
|
||||
#endif // CONTROL_EVENT_H
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
|
||||
template <typename K, typename V, typename H>
|
||||
std::vector<V> map_to_values(const std::unordered_map<K, V, H> &map) {
|
||||
std::vector<V> out;
|
||||
out.reserve(map.size());
|
||||
for (auto const &[key, value] : map) {
|
||||
out.push_back(value);
|
||||
}
|
||||
return out;
|
||||
std::vector<V> out;
|
||||
out.reserve(map.size());
|
||||
for (auto const &[key, value] : map) {
|
||||
out.push_back(value);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
#endif // CONTROL_MAP_H
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
|
||||
// Custom hash function for std::pair
|
||||
template <typename T> struct pair_hash {
|
||||
std::size_t operator()(const std::pair<T, T> &p) const {
|
||||
return std::hash<T>()(p.first) ^ (std::hash<T>()(p.second) << 1);
|
||||
}
|
||||
std::size_t operator()(const std::pair<T, T> &p) const {
|
||||
return std::hash<T>()(p.first) ^ (std::hash<T>()(p.second) << 1);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // CONTROL_PAIRHASH_H
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <variant> // NOLINT
|
||||
|
||||
template <class... Ts> struct overloaded : Ts... {
|
||||
using Ts::operator()...;
|
||||
using Ts::operator()...;
|
||||
};
|
||||
|
||||
template <class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
|
||||
|
||||
20
src/Hub.cpp
20
src/Hub.cpp
@@ -2,32 +2,32 @@
|
||||
#include "flatbuffers/SensorMessageBuilder.h"
|
||||
|
||||
double Hub::get_position() {
|
||||
// no-op
|
||||
return 0;
|
||||
// no-op
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string Hub::get_text() {
|
||||
// no-op
|
||||
return "";
|
||||
// no-op
|
||||
return "";
|
||||
}
|
||||
|
||||
void Hub::actuate(double /* position */) {
|
||||
// no-op
|
||||
// no-op
|
||||
}
|
||||
|
||||
void Hub::actuate(double /* x */, double /* y */) {
|
||||
// no-op
|
||||
// no-op
|
||||
}
|
||||
|
||||
void Hub::actuate(const std::string &text) {
|
||||
// no-op
|
||||
// no-op
|
||||
}
|
||||
|
||||
std::vector<uint8_t> Hub::get_actuation_message() {
|
||||
// no-op
|
||||
return {};
|
||||
// no-op
|
||||
return {};
|
||||
}
|
||||
|
||||
void Hub::update_sensor_data(const Flatbuffers::sensor_value & /* value */) {
|
||||
// no-op
|
||||
// no-op
|
||||
}
|
||||
|
||||
@@ -4,33 +4,40 @@
|
||||
|
||||
#include "Module.h"
|
||||
|
||||
std::vector<neighbour> Module::get_neighbours() { return m_neighbours; }
|
||||
|
||||
uint8_t Module::get_device_id() { return m_device_id; }
|
||||
|
||||
ModuleType Module::get_type() { return m_module_type; }
|
||||
|
||||
Messaging::ConnectionType Module::get_connection_type() {
|
||||
return m_connection_type;
|
||||
std::vector<neighbour> Module::get_neighbours() {
|
||||
return m_neighbours;
|
||||
}
|
||||
|
||||
uint8_t Module::get_leader() { return m_leader; }
|
||||
uint8_t Module::get_device_id() {
|
||||
return m_device_id;
|
||||
}
|
||||
|
||||
std::chrono::time_point<std::chrono::system_clock>
|
||||
Module::get_last_updated_time() {
|
||||
return m_last_updated;
|
||||
ModuleType Module::get_type() {
|
||||
return m_module_type;
|
||||
}
|
||||
|
||||
Messaging::ConnectionType Module::get_connection_type() {
|
||||
return m_connection_type;
|
||||
}
|
||||
|
||||
uint8_t Module::get_leader() {
|
||||
return m_leader;
|
||||
}
|
||||
|
||||
std::chrono::time_point<std::chrono::system_clock> Module::get_last_updated_time() {
|
||||
return m_last_updated;
|
||||
}
|
||||
|
||||
void Module::update_module_metadata(const Messaging::TopologyMessage &message) {
|
||||
m_module_type = message.module_type();
|
||||
m_connection_type = message.connection();
|
||||
m_leader = message.leader();
|
||||
m_module_type = message.module_type();
|
||||
m_connection_type = message.connection();
|
||||
m_leader = message.leader();
|
||||
|
||||
m_last_updated = std::chrono::system_clock::now();
|
||||
m_last_updated = std::chrono::system_clock::now();
|
||||
|
||||
m_neighbours.clear();
|
||||
for (auto [id, ori] : std::views::zip(*message.channel_to_module(),
|
||||
*message.channel_to_orientation())) {
|
||||
m_neighbours.emplace_back(neighbour{id, static_cast<Orientation>(ori)});
|
||||
}
|
||||
m_neighbours.clear();
|
||||
for (auto [id, ori] :
|
||||
std::views::zip(*message.channel_to_module(), *message.channel_to_orientation())) {
|
||||
m_neighbours.emplace_back(neighbour{id, static_cast<Orientation>(ori)});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,26 +10,25 @@
|
||||
#define SERVO1_MIN_ANGLE 0
|
||||
#define SERVO1_DEFAULT_ANGLE 90
|
||||
|
||||
std::shared_ptr<Module> ModuleFactory::createModule(
|
||||
uint8_t device_id, ModuleType type,
|
||||
std::shared_ptr<MessagingInterface> &messaging_interface) {
|
||||
switch (type) {
|
||||
case ModuleType_SPLITTER:
|
||||
return std::make_shared<Hub>(device_id, type);
|
||||
case ModuleType_BATTERY:
|
||||
return std::make_shared<Hub>(device_id, type);
|
||||
case ModuleType_SERVO_1:
|
||||
case ModuleType_SERVO_2:
|
||||
case ModuleType_GRIPPER:
|
||||
return std::make_shared<BoundedPositionalActuator1D>(
|
||||
device_id, type, SERVO1_MAX_ANGLE, SERVO1_MIN_ANGLE,
|
||||
SERVO1_DEFAULT_ANGLE);
|
||||
case ModuleType_DC_MOTOR:
|
||||
return std::make_shared<PositionalActuator1D>(device_id, type);
|
||||
case ModuleType_DISPLAY:
|
||||
return std::make_shared<OledActuator>(device_id, type);
|
||||
default:
|
||||
std::shared_ptr<Module>
|
||||
ModuleFactory::createModule(uint8_t device_id, ModuleType type,
|
||||
std::shared_ptr<MessagingInterface> &messaging_interface) {
|
||||
switch (type) {
|
||||
case ModuleType_SPLITTER:
|
||||
return std::make_shared<Hub>(device_id, type);
|
||||
case ModuleType_BATTERY:
|
||||
return std::make_shared<Hub>(device_id, type);
|
||||
case ModuleType_SERVO_1:
|
||||
case ModuleType_SERVO_2:
|
||||
case ModuleType_GRIPPER:
|
||||
return std::make_shared<BoundedPositionalActuator1D>(
|
||||
device_id, type, SERVO1_MAX_ANGLE, SERVO1_MIN_ANGLE, SERVO1_DEFAULT_ANGLE);
|
||||
case ModuleType_DC_MOTOR:
|
||||
return std::make_shared<PositionalActuator1D>(device_id, type);
|
||||
case ModuleType_DISPLAY:
|
||||
return std::make_shared<OledActuator>(device_id, type);
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -7,46 +7,45 @@
|
||||
#include "util/Variant.h"
|
||||
|
||||
double BoundedPositionalActuator1D::get_position() {
|
||||
return m_current_position;
|
||||
return m_current_position;
|
||||
}
|
||||
|
||||
std::string BoundedPositionalActuator1D::get_text() { return ""; }
|
||||
std::string BoundedPositionalActuator1D::get_text() {
|
||||
return "";
|
||||
}
|
||||
|
||||
void BoundedPositionalActuator1D::actuate(double position) {
|
||||
if (position < m_min_value || position > m_max_value) {
|
||||
return;
|
||||
}
|
||||
if (position < m_min_value || position > m_max_value) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_target_position = position;
|
||||
m_target_position = position;
|
||||
}
|
||||
|
||||
void BoundedPositionalActuator1D::actuate(double x, double y) {}
|
||||
void BoundedPositionalActuator1D::actuate(double x, double y) {
|
||||
}
|
||||
|
||||
void BoundedPositionalActuator1D::actuate(const std::string &text) {}
|
||||
void BoundedPositionalActuator1D::actuate(const std::string &text) {
|
||||
}
|
||||
|
||||
std::vector<uint8_t> BoundedPositionalActuator1D::get_actuation_message() {
|
||||
std::vector<uint8_t> message{};
|
||||
std::vector<uint8_t> message{};
|
||||
|
||||
if (m_target_position == m_current_position) {
|
||||
if (m_target_position == m_current_position) {
|
||||
return message;
|
||||
}
|
||||
|
||||
auto [data, size] = acm_builder->build_angle_control_message(m_target_position);
|
||||
message.resize(size);
|
||||
memcpy(message.data(), data, size);
|
||||
return message;
|
||||
}
|
||||
|
||||
auto [data, size] =
|
||||
acm_builder->build_angle_control_message(m_target_position);
|
||||
message.resize(size);
|
||||
memcpy(message.data(), data, size);
|
||||
return message;
|
||||
}
|
||||
|
||||
void BoundedPositionalActuator1D::update_sensor_data(
|
||||
const Flatbuffers::sensor_value &value) {
|
||||
std::visit(
|
||||
overloaded{
|
||||
[this](Flatbuffers::target_angle a) { m_current_position = a.angle; },
|
||||
[this](Flatbuffers::current_angle a) {
|
||||
m_current_position = a.angle;
|
||||
},
|
||||
[this](Flatbuffers::current_text /*t*/) {},
|
||||
},
|
||||
value);
|
||||
void BoundedPositionalActuator1D::update_sensor_data(const Flatbuffers::sensor_value &value) {
|
||||
std::visit(overloaded{
|
||||
[this](Flatbuffers::target_angle a) { m_current_position = a.angle; },
|
||||
[this](Flatbuffers::current_angle a) { m_current_position = a.angle; },
|
||||
[this](Flatbuffers::current_text /*t*/) {},
|
||||
},
|
||||
value);
|
||||
}
|
||||
|
||||
@@ -3,36 +3,42 @@
|
||||
#include "util/Variant.h"
|
||||
#include <cstring>
|
||||
|
||||
double OledActuator::get_position() { return 0.0; }
|
||||
double OledActuator::get_position() {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
std::string OledActuator::get_text() { return m_current_text; }
|
||||
std::string OledActuator::get_text() {
|
||||
return m_current_text;
|
||||
}
|
||||
|
||||
void OledActuator::actuate(double /* position */) {}
|
||||
void OledActuator::actuate(double /* position */) {
|
||||
}
|
||||
|
||||
void OledActuator::actuate(double /* x */, double /* y */) {}
|
||||
void OledActuator::actuate(double /* x */, double /* y */) {
|
||||
}
|
||||
|
||||
void OledActuator::actuate(const std::string &text) { m_target_text = text; }
|
||||
void OledActuator::actuate(const std::string &text) {
|
||||
m_target_text = text;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> OledActuator::get_actuation_message() {
|
||||
std::vector<uint8_t> message{};
|
||||
std::vector<uint8_t> message{};
|
||||
|
||||
if (m_target_text == m_current_text) {
|
||||
if (m_target_text == m_current_text) {
|
||||
return message;
|
||||
}
|
||||
|
||||
auto [data, size] = m_text_message_builder->build_text_control_message(m_target_text);
|
||||
message.resize(size);
|
||||
memcpy(message.data(), data, size);
|
||||
return message;
|
||||
}
|
||||
|
||||
auto [data, size] =
|
||||
m_text_message_builder->build_text_control_message(m_target_text);
|
||||
message.resize(size);
|
||||
memcpy(message.data(), data, size);
|
||||
return message;
|
||||
}
|
||||
|
||||
void OledActuator::update_sensor_data(const Flatbuffers::sensor_value &value) {
|
||||
std::visit(
|
||||
overloaded{
|
||||
[this](Flatbuffers::target_angle /* a */) {},
|
||||
[this](Flatbuffers::current_angle /* a */) {},
|
||||
[this](Flatbuffers::current_text t) { m_current_text = t.text; },
|
||||
},
|
||||
value);
|
||||
std::visit(overloaded{
|
||||
[this](Flatbuffers::target_angle /* a */) {},
|
||||
[this](Flatbuffers::current_angle /* a */) {},
|
||||
[this](Flatbuffers::current_text t) { m_current_text = t.text; },
|
||||
},
|
||||
value);
|
||||
}
|
||||
|
||||
@@ -3,42 +3,42 @@
|
||||
#include "util/Variant.h"
|
||||
#include <cstring>
|
||||
|
||||
double PositionalActuator1D::get_position() { return m_current_position; }
|
||||
double PositionalActuator1D::get_position() {
|
||||
return m_current_position;
|
||||
}
|
||||
|
||||
std::string PositionalActuator1D::get_text() { return ""; }
|
||||
std::string PositionalActuator1D::get_text() {
|
||||
return "";
|
||||
}
|
||||
|
||||
void PositionalActuator1D::actuate(double position) {
|
||||
m_target_position = position;
|
||||
m_target_position = position;
|
||||
}
|
||||
|
||||
void PositionalActuator1D::actuate(double /* x */, double /* y */) {}
|
||||
void PositionalActuator1D::actuate(double /* x */, double /* y */) {
|
||||
}
|
||||
|
||||
void PositionalActuator1D::actuate(const std::string &text) {}
|
||||
void PositionalActuator1D::actuate(const std::string &text) {
|
||||
}
|
||||
|
||||
std::vector<uint8_t> PositionalActuator1D::get_actuation_message() {
|
||||
std::vector<uint8_t> message{};
|
||||
std::vector<uint8_t> message{};
|
||||
|
||||
if (m_target_position == m_board_target_position) {
|
||||
if (m_target_position == m_board_target_position) {
|
||||
return message;
|
||||
}
|
||||
|
||||
auto [data, size] = m_acm_builder->build_angle_control_message(m_target_position);
|
||||
message.resize(size);
|
||||
memcpy(message.data(), data, size);
|
||||
return message;
|
||||
}
|
||||
|
||||
auto [data, size] =
|
||||
m_acm_builder->build_angle_control_message(m_target_position);
|
||||
message.resize(size);
|
||||
memcpy(message.data(), data, size);
|
||||
return message;
|
||||
}
|
||||
|
||||
void PositionalActuator1D::update_sensor_data(
|
||||
const Flatbuffers::sensor_value &value) {
|
||||
std::visit(overloaded{
|
||||
[this](Flatbuffers::target_angle a) {
|
||||
m_board_target_position = a.angle;
|
||||
},
|
||||
[this](Flatbuffers::current_angle a) {
|
||||
m_current_position = a.angle;
|
||||
},
|
||||
[this](Flatbuffers::current_text /*t*/) {},
|
||||
},
|
||||
value);
|
||||
void PositionalActuator1D::update_sensor_data(const Flatbuffers::sensor_value &value) {
|
||||
std::visit(overloaded{
|
||||
[this](Flatbuffers::target_angle a) { m_board_target_position = a.angle; },
|
||||
[this](Flatbuffers::current_angle a) { m_current_position = a.angle; },
|
||||
[this](Flatbuffers::current_text /*t*/) {},
|
||||
},
|
||||
value);
|
||||
}
|
||||
|
||||
@@ -7,17 +7,16 @@
|
||||
namespace Flatbuffers {
|
||||
const Messaging::AngleControlMessage *
|
||||
AngleControlMessageBuilder::parse_angle_control_message(const uint8_t *buffer) {
|
||||
return flatbuffers::GetRoot<Messaging::AngleControlMessage>(buffer);
|
||||
return flatbuffers::GetRoot<Messaging::AngleControlMessage>(buffer);
|
||||
}
|
||||
|
||||
SerializedMessage
|
||||
AngleControlMessageBuilder::build_angle_control_message(const int16_t angle) {
|
||||
builder_.Clear();
|
||||
SerializedMessage AngleControlMessageBuilder::build_angle_control_message(const int16_t angle) {
|
||||
builder_.Clear();
|
||||
|
||||
const auto message = Messaging::CreateAngleControlMessage(builder_, angle);
|
||||
const auto message = Messaging::CreateAngleControlMessage(builder_, angle);
|
||||
|
||||
builder_.Finish(message);
|
||||
builder_.Finish(message);
|
||||
|
||||
return {builder_.GetBufferPointer(), builder_.GetSize()};
|
||||
return {builder_.GetBufferPointer(), builder_.GetSize()};
|
||||
}
|
||||
} // namespace Flatbuffers
|
||||
|
||||
@@ -12,41 +12,38 @@ namespace Flatbuffers {
|
||||
SerializedMessage RobotConfigurationBuilder::build_robot_configuration(
|
||||
const std::vector<ModuleInstance> &modules,
|
||||
const std::vector<ModuleConnectionInstance> &connections) {
|
||||
builder_.Clear();
|
||||
builder_.Clear();
|
||||
|
||||
std::vector<flatbuffers::Offset<RobotModule>> module_vector;
|
||||
std::vector<flatbuffers::Offset<Frontend::ModuleConnection>>
|
||||
connection_vector;
|
||||
std::vector<flatbuffers::Offset<RobotModule>> module_vector;
|
||||
std::vector<flatbuffers::Offset<Frontend::ModuleConnection>> connection_vector;
|
||||
|
||||
for (const auto &connection : connections) {
|
||||
connection_vector.push_back(Frontend::CreateModuleConnection(
|
||||
builder_, connection.from_module_id, connection.to_module_id,
|
||||
connection.from_socket, connection.to_socket, connection.orientation));
|
||||
}
|
||||
for (const auto &connection : connections) {
|
||||
connection_vector.push_back(Frontend::CreateModuleConnection(
|
||||
builder_, connection.from_module_id, connection.to_module_id, connection.from_socket,
|
||||
connection.to_socket, connection.orientation));
|
||||
}
|
||||
|
||||
for (const auto &module : modules) {
|
||||
// todo: this only works for motors right now
|
||||
auto motor_state = CreateMotorState(builder_, module.angle);
|
||||
const flatbuffers::Offset<void> config_union = motor_state.Union();
|
||||
module_vector.push_back(CreateRobotModule(builder_, module.id, module.type,
|
||||
ModuleState_MotorState,
|
||||
config_union));
|
||||
}
|
||||
for (const auto &module : modules) {
|
||||
// todo: this only works for motors right now
|
||||
auto motor_state = CreateMotorState(builder_, module.angle);
|
||||
const flatbuffers::Offset<void> config_union = motor_state.Union();
|
||||
module_vector.push_back(CreateRobotModule(builder_, module.id, module.type,
|
||||
ModuleState_MotorState, config_union));
|
||||
}
|
||||
|
||||
const auto connection_vector_fb = builder_.CreateVector(connection_vector);
|
||||
const auto module_vector_fb = builder_.CreateVector(module_vector);
|
||||
const auto connection_vector_fb = builder_.CreateVector(connection_vector);
|
||||
const auto module_vector_fb = builder_.CreateVector(module_vector);
|
||||
|
||||
const auto message = Frontend::CreateRobotConfiguration(
|
||||
builder_, module_vector_fb, connection_vector_fb);
|
||||
const auto message =
|
||||
Frontend::CreateRobotConfiguration(builder_, module_vector_fb, connection_vector_fb);
|
||||
|
||||
builder_.Finish(message);
|
||||
builder_.Finish(message);
|
||||
|
||||
return {builder_.GetBufferPointer(), builder_.GetSize()};
|
||||
return {builder_.GetBufferPointer(), builder_.GetSize()};
|
||||
}
|
||||
|
||||
const Frontend::RobotConfiguration *
|
||||
RobotConfigurationBuilder::parse_robot_configuration(
|
||||
const std::uint8_t *buffer) {
|
||||
return flatbuffers::GetRoot<Frontend::RobotConfiguration>(buffer);
|
||||
RobotConfigurationBuilder::parse_robot_configuration(const std::uint8_t *buffer) {
|
||||
return flatbuffers::GetRoot<Frontend::RobotConfiguration>(buffer);
|
||||
}
|
||||
} // namespace Flatbuffers
|
||||
|
||||
@@ -3,9 +3,8 @@
|
||||
|
||||
namespace Flatbuffers {
|
||||
|
||||
const Messaging::SensorMessage *
|
||||
SensorMessageBuilder::parse_sensor_message(const uint8_t *buffer) {
|
||||
return flatbuffers::GetRoot<Messaging::SensorMessage>(buffer);
|
||||
const Messaging::SensorMessage *SensorMessageBuilder::parse_sensor_message(const uint8_t *buffer) {
|
||||
return flatbuffers::GetRoot<Messaging::SensorMessage>(buffer);
|
||||
}
|
||||
|
||||
} // namespace Flatbuffers
|
||||
|
||||
@@ -6,16 +6,14 @@
|
||||
|
||||
namespace Flatbuffers {
|
||||
|
||||
SerializedMessage
|
||||
TextControlMessageBuilder::build_text_control_message(std::string &t) {
|
||||
builder_.Clear();
|
||||
SerializedMessage TextControlMessageBuilder::build_text_control_message(std::string &t) {
|
||||
builder_.Clear();
|
||||
|
||||
auto text_offset = builder_.CreateString(t);
|
||||
const auto message =
|
||||
Messaging::CreateTextControlMessage(builder_, text_offset);
|
||||
auto text_offset = builder_.CreateString(t);
|
||||
const auto message = Messaging::CreateTextControlMessage(builder_, text_offset);
|
||||
|
||||
builder_.Finish(message);
|
||||
builder_.Finish(message);
|
||||
|
||||
return {builder_.GetBufferPointer(), builder_.GetSize()};
|
||||
return {builder_.GetBufferPointer(), builder_.GetSize()};
|
||||
}
|
||||
} // namespace Flatbuffers
|
||||
|
||||
@@ -7,34 +7,32 @@
|
||||
#include "flatbuffers/SerializedMessage.h"
|
||||
|
||||
namespace Flatbuffers {
|
||||
SerializedMessage TopologyMessageBuilder::build_topology_message(
|
||||
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) {
|
||||
builder_.Clear();
|
||||
SerializedMessage
|
||||
TopologyMessageBuilder::build_topology_message(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) {
|
||||
builder_.Clear();
|
||||
|
||||
const auto orientation_to_module_vector =
|
||||
builder_.CreateVector(orientation_to_module);
|
||||
const auto channel_to_module_vector =
|
||||
builder_.CreateVector(channel_to_module);
|
||||
const auto orientation_to_module_vector = builder_.CreateVector(orientation_to_module);
|
||||
const auto channel_to_module_vector = builder_.CreateVector(channel_to_module);
|
||||
|
||||
const auto message = Messaging::CreateTopologyMessage(
|
||||
builder_, module_id, module_type, channel_to_module.size(),
|
||||
channel_to_module_vector, orientation_to_module_vector);
|
||||
const auto message =
|
||||
Messaging::CreateTopologyMessage(builder_, module_id, module_type, channel_to_module.size(),
|
||||
channel_to_module_vector, orientation_to_module_vector);
|
||||
|
||||
builder_.Finish(message);
|
||||
builder_.Finish(message);
|
||||
|
||||
return {builder_.GetBufferPointer(), builder_.GetSize()};
|
||||
return {builder_.GetBufferPointer(), builder_.GetSize()};
|
||||
}
|
||||
|
||||
const Messaging::TopologyMessage *
|
||||
TopologyMessageBuilder::parse_topology_message(const uint8_t *buffer) {
|
||||
return flatbuffers::GetRoot<Messaging::TopologyMessage>(buffer);
|
||||
return flatbuffers::GetRoot<Messaging::TopologyMessage>(buffer);
|
||||
}
|
||||
|
||||
bool TopologyMessageBuilder::is_valid_topology_message(const uint8_t *buffer,
|
||||
size_t size) {
|
||||
flatbuffers::Verifier verifier(buffer, size);
|
||||
return Messaging::VerifyTopologyMessageBuffer(verifier);
|
||||
bool TopologyMessageBuilder::is_valid_topology_message(const uint8_t *buffer, size_t size) {
|
||||
flatbuffers::Verifier verifier(buffer, size);
|
||||
return Messaging::VerifyTopologyMessageBuffer(verifier);
|
||||
}
|
||||
} // namespace Flatbuffers
|
||||
|
||||
@@ -14,93 +14,117 @@
|
||||
extern "C" {
|
||||
const auto robot_controller = std::make_unique<RobotController>();
|
||||
|
||||
const auto acm_builder =
|
||||
std::make_unique<Flatbuffers::AngleControlMessageBuilder>();
|
||||
const auto acm_builder = std::make_unique<Flatbuffers::AngleControlMessageBuilder>();
|
||||
|
||||
const auto robot_configuration_builder =
|
||||
std::make_unique<Flatbuffers::RobotConfigurationBuilder>();
|
||||
const auto robot_configuration_builder = std::make_unique<Flatbuffers::RobotConfigurationBuilder>();
|
||||
|
||||
LIB_API void init() {
|
||||
spdlog::info("[c_control] Initializing");
|
||||
robot_controller->fetchDirectlyConnectedModules(false);
|
||||
spdlog::info("[c_control] Initializing");
|
||||
robot_controller->fetchDirectlyConnectedModules(false);
|
||||
}
|
||||
|
||||
LIB_API void cleanup() { spdlog::info("[c_control] Cleanup"); }
|
||||
LIB_API void cleanup() {
|
||||
spdlog::info("[c_control] Cleanup");
|
||||
}
|
||||
|
||||
LIB_API int send_angle_control(int module_id, int angle) {
|
||||
if (const auto maybe_module = robot_controller->getModule(module_id)) {
|
||||
const auto module = (*maybe_module).lock();
|
||||
module->actuate(angle);
|
||||
}
|
||||
return 0;
|
||||
if (const auto maybe_module = robot_controller->getModule(module_id)) {
|
||||
const auto module = (*maybe_module).lock();
|
||||
module->actuate(angle);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
LIB_API char *get_configuration(int *size_out) {
|
||||
std::vector<Flatbuffers::ModuleInstance> modules_vec{};
|
||||
std::vector<Flatbuffers::ModuleConnectionInstance> connections_vec{};
|
||||
std::vector<Flatbuffers::ModuleInstance> modules_vec{};
|
||||
std::vector<Flatbuffers::ModuleConnectionInstance> connections_vec{};
|
||||
|
||||
for (const auto &module : robot_controller->getModuleList()) {
|
||||
modules_vec.emplace_back(module);
|
||||
}
|
||||
|
||||
for (const auto &connection : robot_controller->getConnections()) {
|
||||
connections_vec.emplace_back(connection);
|
||||
}
|
||||
|
||||
const auto [data, size] =
|
||||
robot_configuration_builder->build_robot_configuration(modules_vec,
|
||||
connections_vec);
|
||||
*size_out = size;
|
||||
return reinterpret_cast<char *>(data);
|
||||
}
|
||||
|
||||
LIB_API bool control_sentry_init(const char *dsn, const char *environment,
|
||||
const char *release) {
|
||||
sentry_options_t *options = sentry_options_new();
|
||||
sentry_options_set_dsn(options, dsn);
|
||||
sentry_options_set_environment(options, environment);
|
||||
sentry_options_set_release(options, release);
|
||||
sentry_options_set_auto_session_tracking(options, 1);
|
||||
|
||||
sentry_init(options);
|
||||
return true;
|
||||
}
|
||||
|
||||
LIB_API void control_sentry_shutdown(void) { sentry_close(); }
|
||||
|
||||
LIB_API void control_sentry_set_app_info(const char *app_name,
|
||||
const char *app_version,
|
||||
const char *build_number) {
|
||||
sentry_value_t app = sentry_value_new_object();
|
||||
|
||||
if (app_name && *app_name) {
|
||||
sentry_value_set_by_key(app, "name", sentry_value_new_string(app_name));
|
||||
}
|
||||
|
||||
if (app_version && *app_version) {
|
||||
sentry_value_set_by_key(app, "version",
|
||||
sentry_value_new_string(app_version));
|
||||
}
|
||||
|
||||
if (build_number && *build_number) {
|
||||
sentry_value_set_by_key(app, "build",
|
||||
sentry_value_new_string(build_number));
|
||||
}
|
||||
|
||||
sentry_set_context("app", app);
|
||||
|
||||
if (app_version && *app_version) {
|
||||
if (build_number && *build_number) {
|
||||
char release[256];
|
||||
snprintf(release, sizeof(release), "%s@%s+%s",
|
||||
app_name && *app_name ? app_name : "app", app_version,
|
||||
build_number);
|
||||
} else {
|
||||
// Example: mygame@1.2.3
|
||||
char release[256];
|
||||
snprintf(release, sizeof(release), "%s@%s",
|
||||
app_name && *app_name ? app_name : "app", app_version);
|
||||
for (const auto &module : robot_controller->getModuleList()) {
|
||||
modules_vec.emplace_back(module);
|
||||
}
|
||||
|
||||
for (const auto &connection : robot_controller->getConnections()) {
|
||||
connections_vec.emplace_back(connection);
|
||||
}
|
||||
|
||||
const auto [data, size] =
|
||||
robot_configuration_builder->build_robot_configuration(modules_vec, connections_vec);
|
||||
*size_out = size;
|
||||
return reinterpret_cast<char *>(data);
|
||||
}
|
||||
|
||||
LIB_API bool control_sentry_init(const char *dsn, const char *environment, const char *release) {
|
||||
sentry_options_t *options = sentry_options_new();
|
||||
sentry_options_set_dsn(options, dsn);
|
||||
sentry_options_set_environment(options, environment);
|
||||
sentry_options_set_release(options, release);
|
||||
sentry_options_set_auto_session_tracking(options, 1);
|
||||
|
||||
sentry_init(options);
|
||||
return true;
|
||||
}
|
||||
|
||||
LIB_API void control_sentry_shutdown(void) {
|
||||
sentry_close();
|
||||
}
|
||||
|
||||
LIB_API void control_sentry_set_app_info(const char *app_name, const char *app_version,
|
||||
const char *build_number) {
|
||||
sentry_value_t app = sentry_value_new_object();
|
||||
|
||||
if (app_name && *app_name) {
|
||||
sentry_value_set_by_key(app, "name", sentry_value_new_string(app_name));
|
||||
}
|
||||
|
||||
if (app_version && *app_version) {
|
||||
sentry_value_set_by_key(app, "version", sentry_value_new_string(app_version));
|
||||
}
|
||||
|
||||
if (build_number && *build_number) {
|
||||
sentry_value_set_by_key(app, "build", sentry_value_new_string(build_number));
|
||||
}
|
||||
|
||||
sentry_set_context("app", app);
|
||||
|
||||
if (app_version && *app_version) {
|
||||
if (build_number && *build_number) {
|
||||
char release[256];
|
||||
snprintf(release, sizeof(release), "%s@%s+%s", app_name && *app_name ? app_name : "app",
|
||||
app_version, build_number);
|
||||
} else {
|
||||
// Example: mygame@1.2.3
|
||||
char release[256];
|
||||
snprintf(release, sizeof(release), "%s@%s", app_name && *app_name ? app_name : "app",
|
||||
app_version);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LIB_API bool remote_call_c(uint8_t function_tag, uint8_t module, const uint8_t *params,
|
||||
uint16_t params_len, uint8_t *out_buffer, uint16_t out_buffer_capacity,
|
||||
uint16_t *out_bytes_written) {
|
||||
|
||||
if (!out_bytes_written)
|
||||
return false;
|
||||
|
||||
*out_bytes_written = 0;
|
||||
|
||||
std::vector<uint8_t> vec(params, params + params_len);
|
||||
|
||||
auto result = robot_controller->remote_call(function_tag, module, vec);
|
||||
|
||||
if (!result.has_value())
|
||||
return false;
|
||||
|
||||
const std::vector<uint8_t> &out = *result.value();
|
||||
|
||||
size_t needed = out.size();
|
||||
|
||||
if (!out_buffer || out_buffer_capacity < needed)
|
||||
return false;
|
||||
|
||||
memcpy(out_buffer, out.data(), needed);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -34,227 +34,223 @@
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
RobotController::~RobotController() {
|
||||
m_stop_thread = true;
|
||||
m_metadata_loop.join();
|
||||
m_transmit_loop.join();
|
||||
m_configuration_loop.join();
|
||||
m_sensor_loop.join();
|
||||
m_expiry_looop.join();
|
||||
m_stop_thread = true;
|
||||
m_metadata_loop.join();
|
||||
m_transmit_loop.join();
|
||||
m_configuration_loop.join();
|
||||
m_sensor_loop.join();
|
||||
m_expiry_looop.join();
|
||||
}
|
||||
|
||||
std::vector<std::weak_ptr<Module>> RobotController::getModules() {
|
||||
std::vector<std::weak_ptr<Module>> out;
|
||||
std::shared_lock lock(m_module_lock);
|
||||
out.reserve(m_id_to_module.size());
|
||||
for (const auto m : map_to_values(m_id_to_module)) {
|
||||
out.emplace_back(m);
|
||||
}
|
||||
return out;
|
||||
std::vector<std::weak_ptr<Module>> out;
|
||||
std::shared_lock lock(m_module_lock);
|
||||
out.reserve(m_id_to_module.size());
|
||||
for (const auto m : map_to_values(m_id_to_module)) {
|
||||
out.emplace_back(m);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::vector<Flatbuffers::ModuleConnectionInstance>
|
||||
RobotController::getConnections() {
|
||||
std::vector<Flatbuffers::ModuleConnectionInstance> out;
|
||||
std::shared_lock lock(m_connection_lock);
|
||||
std::vector<Flatbuffers::ModuleConnectionInstance> RobotController::getConnections() {
|
||||
std::vector<Flatbuffers::ModuleConnectionInstance> out;
|
||||
std::shared_lock lock(m_connection_lock);
|
||||
|
||||
for (auto const &[_, value] : m_connection_map) {
|
||||
for (const auto conn : value) {
|
||||
out.push_back(conn);
|
||||
for (auto const &[_, value] : m_connection_map) {
|
||||
for (const auto conn : value) {
|
||||
out.push_back(conn);
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
return out;
|
||||
}
|
||||
|
||||
std::vector<Flatbuffers::ModuleInstance> RobotController::getModuleList() {
|
||||
std::vector<Flatbuffers::ModuleInstance> out;
|
||||
std::shared_lock lock(m_module_lock);
|
||||
for (auto const &[key, value] : m_id_to_module) {
|
||||
out.push_back({key, value->get_type()});
|
||||
}
|
||||
return out;
|
||||
std::vector<Flatbuffers::ModuleInstance> out;
|
||||
std::shared_lock lock(m_module_lock);
|
||||
for (auto const &[key, value] : m_id_to_module) {
|
||||
out.push_back({key, value->get_type()});
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::optional<std::weak_ptr<Module>>
|
||||
RobotController::getModule(uint8_t device_id) {
|
||||
std::shared_lock lock(m_module_lock);
|
||||
if (m_id_to_module.contains(device_id)) {
|
||||
return m_id_to_module[device_id];
|
||||
} else {
|
||||
return std::nullopt;
|
||||
}
|
||||
std::optional<std::weak_ptr<Module>> RobotController::getModule(uint8_t device_id) {
|
||||
std::shared_lock lock(m_module_lock);
|
||||
if (m_id_to_module.contains(device_id)) {
|
||||
return m_id_to_module[device_id];
|
||||
} else {
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
void RobotController::resetModules() {
|
||||
std::unique_lock module_lock(m_module_lock);
|
||||
std::unique_lock conn_lock(m_connection_lock);
|
||||
m_id_to_module.erase(m_id_to_module.begin(), m_id_to_module.end());
|
||||
m_connection_map.erase(m_connection_map.begin(), m_connection_map.end());
|
||||
std::unique_lock module_lock(m_module_lock);
|
||||
std::unique_lock conn_lock(m_connection_lock);
|
||||
m_id_to_module.erase(m_id_to_module.begin(), m_id_to_module.end());
|
||||
m_connection_map.erase(m_connection_map.begin(), m_connection_map.end());
|
||||
}
|
||||
|
||||
void RobotController::fetchDirectlyConnectedModules(bool block) {
|
||||
spdlog::info("[Control] Fetching modules from network");
|
||||
auto t = std::thread([&] {
|
||||
auto out = m_messaging_interface->find_connected_modules(
|
||||
std::chrono::milliseconds(SCAN_DURATION_MS));
|
||||
spdlog::info("[Control] Found {} modules on the network", out.size());
|
||||
});
|
||||
spdlog::info("[Control] Fetching modules from network");
|
||||
auto t = std::thread([&] {
|
||||
auto out = m_messaging_interface->find_connected_modules(
|
||||
std::chrono::milliseconds(SCAN_DURATION_MS));
|
||||
spdlog::info("[Control] Found {} modules on the network", out.size());
|
||||
});
|
||||
|
||||
if (block) {
|
||||
t.join();
|
||||
} else {
|
||||
t.detach();
|
||||
}
|
||||
if (block) {
|
||||
t.join();
|
||||
} else {
|
||||
t.detach();
|
||||
}
|
||||
}
|
||||
|
||||
void RobotController::metadata_loop() {
|
||||
unsigned char buf[TOPOLOGY_BUFFER_SIZE];
|
||||
const auto builder = std::make_unique<Flatbuffers::TopologyMessageBuilder>();
|
||||
while (!m_stop_thread) {
|
||||
if (auto result = m_messaging_interface->recv(buf, TOPOLOGY_BUFFER_SIZE,
|
||||
TOPOLOGY_CMD_TAG)) {
|
||||
const auto &[rx_size, from] = *result;
|
||||
unsigned char buf[TOPOLOGY_BUFFER_SIZE];
|
||||
const auto builder = std::make_unique<Flatbuffers::TopologyMessageBuilder>();
|
||||
while (!m_stop_thread) {
|
||||
if (auto result =
|
||||
m_messaging_interface->recv(buf, TOPOLOGY_BUFFER_SIZE, TOPOLOGY_CMD_TAG)) {
|
||||
const auto &[rx_size, from] = *result;
|
||||
|
||||
flatbuffers::Verifier verifier(buf, rx_size);
|
||||
if (!Messaging::VerifyTopologyMessageBuffer(verifier)) {
|
||||
continue;
|
||||
}
|
||||
flatbuffers::Verifier verifier(buf, rx_size);
|
||||
if (!Messaging::VerifyTopologyMessageBuffer(verifier)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto metadata =
|
||||
builder->parse_topology_message(reinterpret_cast<uint8_t *>(buf));
|
||||
std::unique_lock lock(m_module_lock);
|
||||
if (!m_id_to_module.contains(metadata->module_id())) {
|
||||
spdlog::info("[Control] Creating module entry for {}",
|
||||
metadata->module_id());
|
||||
m_id_to_module.insert(
|
||||
{metadata->module_id(),
|
||||
ModuleFactory::createModule(metadata->module_id(),
|
||||
metadata->module_type(),
|
||||
m_messaging_interface)});
|
||||
}
|
||||
const auto metadata = builder->parse_topology_message(reinterpret_cast<uint8_t *>(buf));
|
||||
std::unique_lock lock(m_module_lock);
|
||||
if (!m_id_to_module.contains(metadata->module_id())) {
|
||||
spdlog::info("[Control] Creating module entry for {}", metadata->module_id());
|
||||
m_id_to_module.insert(
|
||||
{metadata->module_id(),
|
||||
ModuleFactory::createModule(metadata->module_id(), metadata->module_type(),
|
||||
m_messaging_interface)});
|
||||
}
|
||||
|
||||
m_id_to_module[metadata->module_id()]->update_module_metadata(*metadata);
|
||||
m_id_to_module[metadata->module_id()]->update_module_metadata(*metadata);
|
||||
|
||||
std::unique_lock conn_lock(m_connection_lock);
|
||||
std::vector<Flatbuffers::ModuleConnectionInstance> conns;
|
||||
for (uint8_t i = 1; i < NUM_CHANNELS; i++) {
|
||||
if (metadata->channel_to_module()->Get(i) > 0) {
|
||||
conns.push_back(Flatbuffers::ModuleConnectionInstance{
|
||||
.from_module_id = metadata->module_id(),
|
||||
.to_module_id = metadata->channel_to_module()->Get(i),
|
||||
.from_socket = i,
|
||||
.to_socket = 0,
|
||||
.orientation = static_cast<Orientation>(
|
||||
metadata->channel_to_orientation()->Get(i))});
|
||||
std::unique_lock conn_lock(m_connection_lock);
|
||||
std::vector<Flatbuffers::ModuleConnectionInstance> conns;
|
||||
for (uint8_t i = 1; i < NUM_CHANNELS; i++) {
|
||||
if (metadata->channel_to_module()->Get(i) > 0) {
|
||||
conns.push_back(Flatbuffers::ModuleConnectionInstance{
|
||||
.from_module_id = metadata->module_id(),
|
||||
.to_module_id = metadata->channel_to_module()->Get(i),
|
||||
.from_socket = i,
|
||||
.to_socket = 0,
|
||||
.orientation =
|
||||
static_cast<Orientation>(metadata->channel_to_orientation()->Get(i))});
|
||||
}
|
||||
}
|
||||
|
||||
m_connection_map[metadata->module_id()] = conns;
|
||||
}
|
||||
}
|
||||
|
||||
m_connection_map[metadata->module_id()] = conns;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RobotController::transmit_loop() {
|
||||
const auto builder = std::make_unique<Flatbuffers::TopologyMessageBuilder>();
|
||||
while (!m_stop_thread) {
|
||||
std::this_thread::sleep_for(CONTROL_MESSAGE_FREQUENCY);
|
||||
std::shared_lock lock(m_module_lock);
|
||||
for (const auto [id, module] : m_id_to_module) {
|
||||
auto out = module->get_actuation_message();
|
||||
const auto builder = std::make_unique<Flatbuffers::TopologyMessageBuilder>();
|
||||
while (!m_stop_thread) {
|
||||
std::this_thread::sleep_for(CONTROL_MESSAGE_FREQUENCY);
|
||||
std::shared_lock lock(m_module_lock);
|
||||
for (const auto [id, module] : m_id_to_module) {
|
||||
auto out = module->get_actuation_message();
|
||||
|
||||
if (out.size() > 0) {
|
||||
m_messaging_interface->send(out.data(), out.size(), id,
|
||||
ACTUATOR_CMD_TAG, false);
|
||||
}
|
||||
if (out.size() > 0) {
|
||||
m_messaging_interface->send(out.data(), out.size(), id, ACTUATOR_CMD_TAG, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RobotController::configuration_loop() {
|
||||
while (!m_stop_thread) {
|
||||
std::this_thread::sleep_for(NETWORK_CONFIG_FETCH_RATE);
|
||||
fetchDirectlyConnectedModules(true);
|
||||
}
|
||||
while (!m_stop_thread) {
|
||||
std::this_thread::sleep_for(NETWORK_CONFIG_FETCH_RATE);
|
||||
fetchDirectlyConnectedModules(true);
|
||||
}
|
||||
}
|
||||
|
||||
void RobotController::expiry_loop() {
|
||||
while (!m_stop_thread) {
|
||||
std::this_thread::sleep_for(MODULE_EXPIRE_TIME);
|
||||
while (!m_stop_thread) {
|
||||
std::this_thread::sleep_for(MODULE_EXPIRE_TIME);
|
||||
|
||||
std::unordered_set<uint8_t> delete_modules{};
|
||||
std::unordered_set<uint8_t> delete_modules{};
|
||||
|
||||
std::unique_lock module_lock(m_module_lock);
|
||||
std::unique_lock connection_lock(m_connection_lock);
|
||||
std::unique_lock module_lock(m_module_lock);
|
||||
std::unique_lock connection_lock(m_connection_lock);
|
||||
|
||||
for (auto it = m_id_to_module.begin(); it != m_id_to_module.end();) {
|
||||
if (it->second->get_last_updated_time() <
|
||||
std::chrono::system_clock::now() - MODULE_EXPIRE_TIME) {
|
||||
delete_modules.emplace(it->first);
|
||||
it = m_id_to_module.erase(it);
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
for (auto it = m_id_to_module.begin(); it != m_id_to_module.end();) {
|
||||
if (it->second->get_last_updated_time() <
|
||||
std::chrono::system_clock::now() - MODULE_EXPIRE_TIME) {
|
||||
delete_modules.emplace(it->first);
|
||||
it = m_id_to_module.erase(it);
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
// todo
|
||||
// Remove connections
|
||||
// for (auto it = m_connection_map.begin(); it != m_connection_map.end();) {
|
||||
// // Remove it->x connections
|
||||
// if (delete_modules.contains(it->first)) {
|
||||
// it = m_connection_map.erase(it);
|
||||
// } else {
|
||||
// ++it;
|
||||
// }
|
||||
|
||||
// // Remove x->it connections
|
||||
// for (auto it2 = it->second.begin(); it2 != it->second.end();) {
|
||||
// if (delete_modules.contains(it2->to_module_id)) {
|
||||
// it2 = it->second.erase(it2);
|
||||
// } else {
|
||||
// ++it2;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
// todo
|
||||
// Remove connections
|
||||
// for (auto it = m_connection_map.begin(); it != m_connection_map.end();) {
|
||||
// // Remove it->x connections
|
||||
// if (delete_modules.contains(it->first)) {
|
||||
// it = m_connection_map.erase(it);
|
||||
// } else {
|
||||
// ++it;
|
||||
// }
|
||||
|
||||
// // Remove x->it connections
|
||||
// for (auto it2 = it->second.begin(); it2 != it->second.end();) {
|
||||
// if (delete_modules.contains(it2->to_module_id)) {
|
||||
// it2 = it->second.erase(it2);
|
||||
// } else {
|
||||
// ++it2;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
void RobotController::sensor_loop() {
|
||||
unsigned char buf[SENSOR_BUFFER_SIZE];
|
||||
const auto builder = std::make_unique<Flatbuffers::SensorMessageBuilder>();
|
||||
while (!m_stop_thread) {
|
||||
if (auto result = m_messaging_interface->recv(buf, SENSOR_BUFFER_SIZE,
|
||||
SENSOR_CMD_TAG)) {
|
||||
const auto &[rx_size, from] = *result;
|
||||
unsigned char buf[SENSOR_BUFFER_SIZE];
|
||||
const auto builder = std::make_unique<Flatbuffers::SensorMessageBuilder>();
|
||||
while (!m_stop_thread) {
|
||||
if (auto result = m_messaging_interface->recv(buf, SENSOR_BUFFER_SIZE, SENSOR_CMD_TAG)) {
|
||||
const auto &[rx_size, from] = *result;
|
||||
|
||||
flatbuffers::Verifier verifier(buf, rx_size);
|
||||
if (!Messaging::VerifySensorMessageBuffer(verifier)) {
|
||||
continue;
|
||||
}
|
||||
flatbuffers::Verifier verifier(buf, rx_size);
|
||||
if (!Messaging::VerifySensorMessageBuffer(verifier)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto sensor_message =
|
||||
builder->parse_sensor_message(reinterpret_cast<uint8_t *>(buf));
|
||||
if (sensor_message->values()->size() !=
|
||||
sensor_message->values_type()->size()) {
|
||||
spdlog::error("[Control] Got a sensor message with different value "
|
||||
"({}) and type ({}) sizes",
|
||||
sensor_message->values()->size(),
|
||||
sensor_message->values_type()->size());
|
||||
continue;
|
||||
}
|
||||
const auto sensor_message =
|
||||
builder->parse_sensor_message(reinterpret_cast<uint8_t *>(buf));
|
||||
if (sensor_message->values()->size() != sensor_message->values_type()->size()) {
|
||||
spdlog::error("[Control] Got a sensor message with different value "
|
||||
"({}) and type ({}) sizes",
|
||||
sensor_message->values()->size(),
|
||||
sensor_message->values_type()->size());
|
||||
continue;
|
||||
}
|
||||
|
||||
std::shared_lock module_lock(m_module_lock);
|
||||
if (!m_id_to_module.contains(from)) {
|
||||
continue;
|
||||
}
|
||||
std::shared_lock module_lock(m_module_lock);
|
||||
if (!m_id_to_module.contains(from)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int i = 0; i < sensor_message->values()->size(); i++) {
|
||||
if (auto maybe_value =
|
||||
Flatbuffers::SensorMessageBuilder::build_sensor_value(
|
||||
static_cast<Messaging::SensorValue>(
|
||||
sensor_message->values_type()->Get(i)),
|
||||
sensor_message->values()->Get(i))) {
|
||||
m_id_to_module[from]->update_sensor_data(*maybe_value);
|
||||
for (int i = 0; i < sensor_message->values()->size(); i++) {
|
||||
if (auto maybe_value = Flatbuffers::SensorMessageBuilder::build_sensor_value(
|
||||
static_cast<Messaging::SensorValue>(sensor_message->values_type()->Get(i)),
|
||||
sensor_message->values()->Get(i))) {
|
||||
m_id_to_module[from]->update_sensor_data(*maybe_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<std::unique_ptr<std::vector<uint8_t>>>
|
||||
RobotController::remote_call(uint8_t function_tag, uint8_t module,
|
||||
const std::vector<uint8_t> ¶meters) {
|
||||
return m_messaging_interface->remote_call(function_tag, module, parameters);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user