LivoxGen1: Add StagingBuffer class.

This commit is contained in:
2025-10-25 14:44:43 -04:00
parent 6650664529
commit 862acf0fe3
3 changed files with 53 additions and 0 deletions
+1
View File
@@ -8,6 +8,7 @@ if(ENABLE_STIMBUFFAPI_livoxGen1)
add_library(livoxGen1 SHARED
livoxGen1.cpp
stagingBuffer.cpp
)
target_include_directories(livoxGen1 PUBLIC
+1
View File
@@ -0,0 +1 @@
+51
View File
@@ -0,0 +1,51 @@
#ifndef STAGINGBUFFER_H
#define STAGINGBUFFER_H
#include <memory>
#include <cstdint>
#include <functional>
#include <atomic>
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<uint8_t[]> buffer_;
size_t bufferSize_;
// Current state
std::atomic<size_t> currentSize_;
std::atomic<bool> isAssembling_;
};
} // namespace stim_buff
} // namespace smo
#endif // STAGINGBUFFER_H