mirror of
https://github.com/BotChain-Robots/control.git
synced 2026-03-10 00:32:26 +01:00
Formatting, add remote calling to c library
This commit is contained in:
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
|
||||
Reference in New Issue
Block a user