feat: integrate tactile stream decoding
This commit is contained in:
77
components/ffmsep/cpstream_core.hh
Normal file
77
components/ffmsep/cpstream_core.hh
Normal file
@@ -0,0 +1,77 @@
|
||||
#pragma once
|
||||
|
||||
#include "components/ffmsep/cpdecoder.hh"
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <serial/serial.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace ffmsep {
|
||||
|
||||
struct DecodedFrame {
|
||||
CPFrame frame;
|
||||
std::chrono::steady_clock::time_point received_at{};
|
||||
std::int64_t pts = 0;
|
||||
};
|
||||
|
||||
struct CPStreamConfig {
|
||||
std::string port;
|
||||
std::uint32_t baudrate = 115200;
|
||||
serial::Timeout timeout = serial::Timeout::simpleTimeout(50);
|
||||
serial::bytesize_t bytesize = serial::eightbits;
|
||||
serial::parity_t parity = serial::parity_none;
|
||||
serial::stopbits_t stopbits = serial::stopbits_one;
|
||||
serial::flowcontrol_t flowcontrol = serial::flowcontrol_none;
|
||||
std::size_t read_chunk_size = 256;
|
||||
std::size_t packet_queue_capacity = 128;
|
||||
std::size_t frame_queue_capacity = 16;
|
||||
CPCodecID codec_id = CPCodecID::Unknow;
|
||||
std::string codec_name;
|
||||
};
|
||||
|
||||
class CPStreamCore {
|
||||
public:
|
||||
using FrameCallback = std::function<void(const DecodedFrame&)>;
|
||||
|
||||
explicit CPStreamCore(CPStreamConfig config = {});
|
||||
~CPStreamCore();
|
||||
|
||||
CPStreamCore(const CPStreamCore&) = delete;
|
||||
CPStreamCore& operator=(const CPStreamCore&) = delete;
|
||||
|
||||
bool open(const CPStreamConfig& config);
|
||||
bool open();
|
||||
bool reopen(const CPStreamConfig& config);
|
||||
void close();
|
||||
|
||||
bool start();
|
||||
void stop();
|
||||
|
||||
[[nodiscard]] bool is_open() const noexcept;
|
||||
[[nodiscard]] bool is_running() const noexcept;
|
||||
|
||||
bool send(const std::vector<std::uint8_t>& data);
|
||||
bool send(const std::uint8_t* data, std::size_t size);
|
||||
|
||||
std::optional<DecodedFrame> try_pop_frame();
|
||||
bool wait_for_frame(DecodedFrame& frame, std::chrono::milliseconds timeout);
|
||||
void clear_frames();
|
||||
void set_frame_queue_capacity(std::size_t capacity);
|
||||
|
||||
void set_frame_callback(FrameCallback callback);
|
||||
|
||||
[[nodiscard]] CPStreamConfig config() const;
|
||||
[[nodiscard]] std::string last_error() const;
|
||||
|
||||
static std::vector<serial::PortInfo> list_available_ports();
|
||||
|
||||
private:
|
||||
struct Impl;
|
||||
std::unique_ptr<Impl> impl_;
|
||||
};
|
||||
|
||||
} // namespace ffmsep
|
||||
Reference in New Issue
Block a user