010ba9c7bd
We implemented the feature to fill unassembled slots w/dummy header values for the livox pcloud header. We also fixed a bug where io uring was writing into the last slot only because we were using the same iovec for every SQE.
104 lines
2.9 KiB
C++
104 lines
2.9 KiB
C++
#ifndef _LIVOX_GEN1_IOURING_ASSEMBLY_ENGINE_H
|
|
#define _LIVOX_GEN1_IOURING_ASSEMBLY_ENGINE_H
|
|
|
|
#include <boostAsioLinkageFix.h>
|
|
#include <cstdint>
|
|
#include <cstddef>
|
|
#include <memory>
|
|
#include <functional>
|
|
#include <vector>
|
|
#include <chrono>
|
|
#include <atomic>
|
|
#include <liburing.h>
|
|
#include <boost/asio/io_service.hpp>
|
|
#include <boost/asio/deadline_timer.hpp>
|
|
#include <boost/asio/posix/stream_descriptor.hpp>
|
|
#include <livoxProto1/device.h>
|
|
#include <asynchronousContinuation.h>
|
|
#include <asynchronousLoop.h>
|
|
#include <callback.h>
|
|
#include <spinLock.h>
|
|
#include "frameAssemblyDesc.h"
|
|
|
|
namespace smo {
|
|
namespace stim_buff {
|
|
|
|
class PcloudStimulusBuffer;
|
|
|
|
class IoUringAssemblyEngine
|
|
{
|
|
public:
|
|
explicit IoUringAssemblyEngine(
|
|
PcloudStimulusBuffer& parent, size_t nDgramsPerStagingBufferFrame);
|
|
~IoUringAssemblyEngine() = default;
|
|
|
|
bool setup();
|
|
void finalize();
|
|
|
|
typedef std::function<void(void*, int)> resetAndAssembleFrameCbFn;
|
|
void resetAndAssembleFrame(resetAndAssembleFrameCbFn onCqeReady);
|
|
void stop(bool doAcquireLock = true);
|
|
|
|
typedef std::function<void(bool, AsynchronousLoop)> assembleFrameReqCbFn;
|
|
void assembleFrameReq(Callback<assembleFrameReqCbFn> cb);
|
|
|
|
// Telemetry helpers
|
|
static size_t computePointsPerDgram(int returnMode);
|
|
static size_t computePointsPerFrame(int returnMode, size_t nDgramsPerFrame)
|
|
{ return computePointsPerDgram(returnMode) * nDgramsPerFrame; }
|
|
|
|
private:
|
|
PcloudStimulusBuffer& parent;
|
|
|
|
// Cached descriptor for reuse across iterations
|
|
std::shared_ptr<FrameAssemblyDesc> frameAssemblyDesc;
|
|
|
|
// io_uring infrastructure
|
|
struct io_uring ring;
|
|
bool isSetup;
|
|
|
|
// Eventfd for CQE notifications (used with boost's unified loop)
|
|
int eventfdFd;
|
|
std::unique_ptr<boost::asio::posix::stream_descriptor> eventfdDesc;
|
|
uint64_t eventfd_value; // Buffer for async_read_some
|
|
// Point cloud data socket descriptor
|
|
std::shared_ptr<boost::asio::posix::stream_descriptor> pcloudDataFdDesc;
|
|
|
|
// Stall detection timer
|
|
boost::asio::deadline_timer stallTimer;
|
|
// Callback for CQE ntfns (called with user_data+result from each CQE)
|
|
resetAndAssembleFrameCbFn onCqeReadyCallback;
|
|
// Flag to indicate assembly is in progress (cleared by stop())
|
|
// Protected by isAssemblingLock
|
|
SpinLock isAssemblingLock;
|
|
bool isAssembling;
|
|
|
|
// Number of datagrams per staging buffer frame
|
|
size_t nDgramsPerStagingBufferFrame;
|
|
|
|
struct SlotAssemblyDesc
|
|
{
|
|
bool assembled;
|
|
struct msghdr msgHdr;
|
|
struct iovec ioVec;
|
|
};
|
|
|
|
// Track which slots have been successfully assembled and maintain persistent iovecs
|
|
std::vector<SlotAssemblyDesc> assembledSlotsTracker;
|
|
|
|
void fillUnAssembledSlotsWithDummyDgrams();
|
|
void printSlotBytes(size_t slotIndex, size_t nBytes);
|
|
void onEventfdRead(
|
|
const boost::system::error_code& error, std::size_t bytes_transferred);
|
|
|
|
class AssembleFrameReq;
|
|
friend class AssembleFrameReq;
|
|
};
|
|
|
|
} // namespace stim_buff
|
|
} // namespace smo
|
|
|
|
#endif // _LIVOX_GEN1_IOURING_ASSEMBLY_ENGINE_H
|
|
|
|
|