diff --git a/stimBuffApis/livoxGen1/CMakeLists.txt b/stimBuffApis/livoxGen1/CMakeLists.txt index f8e9244..3a0969e 100644 --- a/stimBuffApis/livoxGen1/CMakeLists.txt +++ b/stimBuffApis/livoxGen1/CMakeLists.txt @@ -10,6 +10,7 @@ if(ENABLE_STIMBUFFAPI_livoxGen1) livoxGen1.cpp stagingBuffer.cpp pcloudStimulusBuffer.cpp + ioUringAssemblyEngine.cpp ) target_include_directories(livoxGen1 PUBLIC diff --git a/stimBuffApis/livoxGen1/ioUringAssemblyEngine.cpp b/stimBuffApis/livoxGen1/ioUringAssemblyEngine.cpp index c61f5ea..74557bb 100644 --- a/stimBuffApis/livoxGen1/ioUringAssemblyEngine.cpp +++ b/stimBuffApis/livoxGen1/ioUringAssemblyEngine.cpp @@ -1,7 +1,7 @@ #include #include #include -#include "IoUringAssemblyEngine.h" +#include "ioUringAssemblyEngine.h" namespace smo { namespace stim_buff { @@ -25,98 +25,117 @@ constexpr uint8_t kInvalidDataType = 0xFFu; } IoUringAssemblyEngine::IoUringAssemblyEngine() - : udpFd(-1), running(false), paused(false), frameCb(nullptr), - desc(nullptr), frameBase(nullptr), frameStrideBytes(0), - timeoutMs(15), frameIndex(0) - {} +: udpFd(-1), running(false), paused(false), frameCb(nullptr), +desc(nullptr), frameBase(nullptr), frameStrideBytes(0), +timeoutMs(15), frameIndex(0) +{} + +bool IoUringAssemblyEngine::setSocketFromDevice( + const std::shared_ptr& device + ) +{ + if (!device) { return false; } -bool IoUringAssemblyEngine::setSocketFromDevice(const std::shared_ptr& device) { - if (!device) return false; // Expect device to expose pcloudDataSocketDesc() - udpFd = device->pcloudDataSocketDesc(); - return udpFd >= 0; + udpFd = device->pcloudDataSocketDesc->native_handle(); + return (udpFd >= 0); } +bool IoUringAssemblyEngine::start( + FrameAssemblyDesc& descRef, uint8_t* frameBasePtr, + size_t frameStrideBytesArg, uint32_t timeoutMsArg + ) +{ + if (udpFd < 0 || !frameBasePtr || descRef.slots.empty()) + { return false; } -bool IoUringAssemblyEngine::start(FrameAssemblyDesc& descRef, - uint8_t* frameBasePtr, - size_t frameStrideBytesArg, - uint32_t timeoutMsArg) { - if (udpFd < 0 || !frameBasePtr || descRef.slots.empty()) return false; - desc = &descRef; - frameBase = frameBasePtr; - frameStrideBytes = frameStrideBytesArg; - timeoutMs = timeoutMsArg; - paused.store(false); - running.store(true); + desc = &descRef; + frameBase = frameBasePtr; + frameStrideBytes = frameStrideBytesArg; + timeoutMs = timeoutMsArg; + paused.store(false); + running.store(true); // Placeholder: actual io_uring submission/handling would run in a dedicated thread // For now, assume synchronous loop stub - postReceives(); - handleCqesAndTimeout(); + postReceives(); + handleCqesAndTimeout(); return true; } -void IoUringAssemblyEngine::pause() { - paused.store(true); +void IoUringAssemblyEngine::pause() +{ + paused.store(true); } -void IoUringAssemblyEngine::resume() { - if (!running.load()) return; - paused.store(false); +void IoUringAssemblyEngine::resume() +{ + if (!running.load()) + { return; } + + paused.store(false); postReceives(); } -void IoUringAssemblyEngine::stop() { - running.store(false); +void IoUringAssemblyEngine::stop() +{ + running.store(false); } -void IoUringAssemblyEngine::onFrameComplete(FrameCompleteCallback cb) { - frameCb = std::move(cb); +void IoUringAssemblyEngine::onFrameComplete(FrameCompleteCallback cb) +{ + frameCb = std::move(cb); } -void IoUringAssemblyEngine::postReceives() { +void IoUringAssemblyEngine::postReceives() +{ // Intentionally left minimal; real implementation will submit N RECVMSG SQEs } -void IoUringAssemblyEngine::handleCqesAndTimeout() { +void IoUringAssemblyEngine::handleCqesAndTimeout() +{ // Intentionally left minimal; real implementation will poll CQEs with timeout cancelIncompleteAndFillDummies(); - if (frameCb) frameCb(frameIndex++); + if (frameCb) + { frameCb(frameIndex++); } } -void IoUringAssemblyEngine::cancelIncompleteAndFillDummies() { - if (!desc) return; - for (size_t i = 0; i < desc->numSlots; ++i) { - // In the real path, decide from CQE accounting whether slot i completed. - // Here, demonstrate dummy header insertion API. - auto* hdr = reinterpret_cast(desc->slots[i].vaddr); - hdr->err_code = kInvalidErrCode; - hdr->timestamp_type = kInvalidTimestampType; - hdr->data_type = kInvalidDataType; - } +void IoUringAssemblyEngine::cancelIncompleteAndFillDummies() +{ + if (!desc) + { return; } + + for (size_t i = 0; i < desc->numSlots; ++i) + { + // In the real path, decide from CQE accounting whether slot i completed. + // Here, demonstrate dummy header insertion API. + auto* hdr = reinterpret_cast(desc->slots[i].vaddr); + hdr->err_code = kInvalidErrCode; + hdr->timestamp_type = kInvalidTimestampType; + hdr->data_type = kInvalidDataType; + } } size_t IoUringAssemblyEngine::computePointsPerDgram(int returnMode) { - /* Map modes to points per datagram based on Livox docs - * 1: first, 2: strongest -> 96 samples => 96 points - * 3: dual -> 48 samples * 2 points = 96 - * 4: triple -> 30 samples * 3 points = 90 - */ + /* + * Map modes to points per datagram based on Livox docs + * 1: first, 2: strongest -> 96 samples => 96 points + * 3: dual -> 48 samples * 2 points = 96 + * 4: triple -> 30 samples * 3 points = 90 + */ switch (returnMode) { - case livoxProto1::Device::ReturnMode::SingleFirst: - case livoxProto1::Device::ReturnMode::SingleStrongest: - case livoxProto1::Device::ReturnMode::Dual: - return 96u; - case livoxProto1::Device::ReturnMode::Triple: - return 90u; - default: - throw std::runtime_error(std::string(__func__) - + ": Unknown returnMode " + std::to_string(returnMode)); + case static_cast(livoxProto1::Device::ReturnMode::SingleFirst): + case static_cast(livoxProto1::Device::ReturnMode::SingleStrongest): + case static_cast(livoxProto1::Device::ReturnMode::Dual): + return 96u; + case static_cast(livoxProto1::Device::ReturnMode::Triple): + return 90u; + default: + throw std::runtime_error( + std::string(__func__) + ": Unknown returnMode " + + std::to_string(returnMode)); } } } // namespace stim_buff } // namespace smo - -