From 862acf0fe3253215baadcd7fc18c334f96fc1b1d Mon Sep 17 00:00:00 2001 From: Hayodea Hekol Date: Sat, 25 Oct 2025 14:44:43 -0400 Subject: [PATCH] LivoxGen1: Add StagingBuffer class. --- stimBuffApis/livoxGen1/CMakeLists.txt | 1 + stimBuffApis/livoxGen1/stagingBuffer.cpp | 1 + stimBuffApis/livoxGen1/stagingBuffer.h | 51 ++++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 stimBuffApis/livoxGen1/stagingBuffer.cpp create mode 100644 stimBuffApis/livoxGen1/stagingBuffer.h diff --git a/stimBuffApis/livoxGen1/CMakeLists.txt b/stimBuffApis/livoxGen1/CMakeLists.txt index ba4b8ad..babd7e7 100644 --- a/stimBuffApis/livoxGen1/CMakeLists.txt +++ b/stimBuffApis/livoxGen1/CMakeLists.txt @@ -8,6 +8,7 @@ if(ENABLE_STIMBUFFAPI_livoxGen1) add_library(livoxGen1 SHARED livoxGen1.cpp + stagingBuffer.cpp ) target_include_directories(livoxGen1 PUBLIC diff --git a/stimBuffApis/livoxGen1/stagingBuffer.cpp b/stimBuffApis/livoxGen1/stagingBuffer.cpp new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/stimBuffApis/livoxGen1/stagingBuffer.cpp @@ -0,0 +1 @@ + diff --git a/stimBuffApis/livoxGen1/stagingBuffer.h b/stimBuffApis/livoxGen1/stagingBuffer.h new file mode 100644 index 0000000..ed7e6da --- /dev/null +++ b/stimBuffApis/livoxGen1/stagingBuffer.h @@ -0,0 +1,51 @@ +#ifndef STAGINGBUFFER_H +#define STAGINGBUFFER_H + +#include +#include +#include +#include + +namespace smo { +namespace stim_buff { + +/** + * StagingBuffer manages a large buffer to guide io_uring in assembling some + * number of Livox Avia pcloud UDP dgrams into a single stim frame. + * + * The buffer operates in a cycle: + * 1. io_uring assembles UDP dgrams into the buffer until it's full + * 2. Buffer is handed off to the stimbuff layer to be appended to the stimbuff. + * 3. When the stimbuff layer has appended the current assembled frame, the + * assembly buffer is reset and cycle repeats. + */ +class StagingBuffer +{ +public: + explicit StagingBuffer(); + ~StagingBuffer(); + + // Non-copyable, movable + StagingBuffer(const StagingBuffer&) = delete; + StagingBuffer& operator=(const StagingBuffer&) = delete; + StagingBuffer(StagingBuffer&&) = default; + StagingBuffer& operator=(StagingBuffer&&) = default; + + bool isAssembling() const { return isAssembling_; } + void startAssembly(); + void stopAssembly(); + +private: + // Buffer data + std::unique_ptr buffer_; + size_t bufferSize_; + + // Current state + std::atomic currentSize_; + std::atomic isAssembling_; +}; + +} // namespace stim_buff +} // namespace smo + +#endif // STAGINGBUFFER_H