1
0
Files
BasaltMeter/BasaltPresenter/Presenter/cmd_client.hpp
2026-01-10 20:02:50 +08:00

65 lines
2.1 KiB
C++

#pragma once
#include <basalt/char_types.hpp>
#include <basalt/pipe_operator.hpp>
#include <cstdint>
namespace basalt::presenter::cmd_client {
// Protocol codes
enum class ProtocolCode : std::uint8_t {
HANDSHAKE_REQUEST = 0x61, ///< Trainer -> Presenter
HANDSHAKE_RESPONSE = 0x62, ///< Presenter -> Trainer
DATA_READY = 0x01, ///< Presenter -> Trainer
DATA_RECEIVED = 0x02, ///< Trainer -> Presenter
ACTIVELY_STOP = 0x21, ///< Presenter-->Trainer
STOP_REQUEST = 0x71, ///< Presenter<--Trainer
STOP_RESPONSE = 0x72, ///< Presenter-->Trainer
};
// Pixel kind values
enum class PixelKind : std::uint8_t {
GRAY_FLOAT32 = 0x01, ///< Grayscale represented by one float32
GRAY_U8 = 0x02, ///< Grayscale represented by one u8
RGB_FLOAT32 = 0x03, ///< RGB represented by three float32
RGB_U8 = 0x04 ///< RGB represented by three u8
};
struct HandshakePayload {
bool headless;
PixelKind pixel_kind;
std::uint32_t width;
std::uint32_t height;
shared::char_types::BSString engine_name;
std::uint32_t engine_device;
shared::char_types::BSString deliver_name;
std::uint32_t deliver_device;
shared::char_types::BSString object_loader_name;
shared::char_types::BSString object_loader_file;
shared::char_types::BSString anime_loader_name;
shared::char_types::BSString anime_loader_file;
};
// Status
enum class CmdClientStatus {
Ready,
Running,
Stop,
};
class CmdClient {
public:
CmdClient();
~CmdClient();
public:
// Wait for handshake from Trainer, send response with data properties
HandshakePayload wait_handshake();
// Tick function called every frame to send data ready and wait for response
bool tick(bool actively_stop = false);
private:
shared::pipe_operator::PipeOperator m_PipeOperator;
CmdClientStatus m_Status;
};
} // namespace basalt::presenter::cmd_client