LivoxProto1: port to sscl::co framework

Code now actually looks a lot cleaner, tbh.
This commit is contained in:
2026-05-28 20:13:12 -04:00
parent bbc16dc4c4
commit 25efccf6c5
20 changed files with 1275 additions and 2145 deletions
-1
View File
@@ -14,7 +14,6 @@ if(ENABLE_STIMBUFFAPI_livoxGen1)
add_library(livoxGen1 SHARED
livoxGen1.cpp
livoxGen1Proto1CpsBridge.cpp
pcloudStimulusProducer.cpp
livoxPcloudFrameDumper.cpp
ioUringAssemblyEngine.cpp
+44 -42
View File
@@ -11,7 +11,6 @@
#include <user/senseApiDesc.h>
#include "livoxGen1Internal.h"
#include "livoxGen1Proto1CpsBridge.h"
namespace smo::stim_buff {
@@ -28,11 +27,11 @@ LivoxProto1DllState::LivoxProto1DllState()
: dlopenHandle(nullptr, DlCloser),
livoxProto1_main(nullptr),
livoxProto1_exit(nullptr),
livoxProto1_getOrCreateDeviceReq(nullptr),
livoxProto1_destroyDeviceReq(nullptr),
livoxProto1_device_enablePcloudDataReq(nullptr),
livoxProto1_device_disablePcloudDataReq(nullptr),
livoxProto1_device_getReturnModeReq(nullptr),
livoxProto1_getOrCreateDeviceCReq(nullptr),
livoxProto1_destroyDeviceCReq(nullptr),
livoxProto1_device_enablePcloudDataCReq(nullptr),
livoxProto1_device_disablePcloudDataCReq(nullptr),
livoxProto1_device_getReturnModeCReq(nullptr),
livoxProto1_getPcloudDataFdDesc(nullptr)
{}
@@ -221,14 +220,14 @@ bool validateAttachRequest(
sscl::co::ViralNonPostingInvoker<StimBuffDeviceOpResult>
enablePcloudDataForAttach(
const std::shared_ptr<device::DeviceAttachmentSpec> &desc,
const std::shared_ptr<sscl::ComponentThread> &componentThread,
const std::shared_ptr<sscl::ComponentThread> &/*componentThread*/,
const std::shared_ptr<livoxProto1::Device> &device)
{
/* Enable pcloud data. Don't need delay since no commands were
* sent to device prior to us reaching here (or delay already handled).
*/
const bool enabled = co_await coAwaitEnablePcloudData(
componentThread, device);
const bool enabled = co_await (*livoxProto1.livoxProto1_device_enablePcloudDataCReq)(
device);
if (!enabled)
{
@@ -329,10 +328,13 @@ attachByCreatingProducer(
* Generally, it will resume sending them within 1-2 seconds.
*/
const LivoxProviderParams params = parseLivoxProviderParams(desc);
adapters::smo::GetOrCreateDeviceResult deviceResult =
co_await coAwaitGetOrCreateDevice(
componentThread, desc->deviceSelector,
params);
LivoxProto1GetOrCreateDeviceResult deviceResult =
co_await (*livoxProto1.livoxProto1_getOrCreateDeviceCReq)(
desc->deviceSelector,
componentThread,
params.commandTimeoutMs, params.retryDelayMs,
params.smoIp, params.smoSubnetNbits,
params.dataPort, params.cmdPort, params.imuPort);
if (!deviceResult.success || !deviceResult.device)
{
@@ -354,7 +356,7 @@ attachByCreatingProducer(
* may not yet be ready for another command.
*/
// Initialize timer with LivoxGen1 metadata io_service
const bool delayOk = co_await adapters::boostAsio::deadlineTimerWaitAReq(
const bool delayOk = co_await adapters::boostAsio::getDeadlineTimerAReqAwaiter(
componentThread->getIoService(),
boost::posix_time::milliseconds(LIVOX_GEN1_DEVICE_COMMAND_DELAY_MS));
@@ -364,8 +366,9 @@ attachByCreatingProducer(
co_return StimBuffDeviceOpResult{false, desc};
}
auto returnModeResult = co_await coAwaitGetReturnMode(
componentThread, deviceResult.device);
LivoxProto1GetReturnModeResult returnModeResult =
co_await (*livoxProto1.livoxProto1_device_getReturnModeCReq)(
deviceResult.device);
if (!returnModeResult.success)
{
@@ -455,7 +458,7 @@ livoxGen1_attachDeviceCReq(
const std::shared_ptr<device::DeviceAttachmentSpec> &desc,
const std::shared_ptr<sscl::ComponentThread> &componentThread)
{
if (!livoxProto1.livoxProto1_getOrCreateDeviceReq)
if (!livoxProto1.livoxProto1_getOrCreateDeviceCReq)
{
throw std::runtime_error(
std::string(__func__) + ": LivoxProto1 getOrCreateDevice function "
@@ -522,8 +525,8 @@ livoxGen1_detachDeviceCReq(
// Last buffer on producer: disable pcloud before tearing down device
// Disable point cloud data first
const bool disabled = co_await coAwaitDisablePcloudData(
requestComponentThread, stimProducer->device);
const bool disabled = co_await (*livoxProto1.livoxProto1_device_disablePcloudDataCReq)(
stimProducer->device);
if (!disabled)
{
@@ -536,7 +539,7 @@ livoxGen1_detachDeviceCReq(
// Helper method to delay and then call destroyDeviceReq
// Initialize timer with LivoxGen1 metadata io_service
co_await adapters::boostAsio::deadlineTimerWaitAReq(
co_await adapters::boostAsio::getDeadlineTimerAReqAwaiter(
requestComponentThread->getIoService(),
boost::posix_time::milliseconds(LIVOX_GEN1_DEVICE_COMMAND_DELAY_MS));
@@ -563,8 +566,7 @@ livoxGen1_detachDeviceCReq(
attachedStimulusProducers.erase(it);
}
const bool destroyed = co_await coAwaitDestroyDevice(
requestComponentThread,
const bool destroyed = co_await (*livoxProto1.livoxProto1_destroyDeviceCReq)(
stimProducer->device);
if (!destroyed) {
std::cerr << __func__ << ": Failed to destroy dev "
@@ -611,31 +613,31 @@ sscl::co::ViralNonPostingInvoker<int> livoxGen1_initializeCInd()
dlsym(livoxProto1.dlopenHandle.get(), "livoxProto1_main"));
livoxProto1.livoxProto1_exit = reinterpret_cast<livoxProto1_exitFn *>(
dlsym(livoxProto1.dlopenHandle.get(), "livoxProto1_exit"));
livoxProto1.livoxProto1_getOrCreateDeviceReq = reinterpret_cast<
livoxProto1_getOrCreateDeviceReqFn *>(
livoxProto1.livoxProto1_getOrCreateDeviceCReq = reinterpret_cast<
livoxProto1_getOrCreateDeviceCReqFn *>(
dlsym(
livoxProto1.dlopenHandle.get(),
"livoxProto1_getOrCreateDeviceReq"));
livoxProto1.livoxProto1_destroyDeviceReq = reinterpret_cast<
livoxProto1_destroyDeviceReqFn *>(
"livoxProto1_getOrCreateDeviceCReq"));
livoxProto1.livoxProto1_destroyDeviceCReq = reinterpret_cast<
livoxProto1_destroyDeviceCReqFn *>(
dlsym(
livoxProto1.dlopenHandle.get(),
"livoxProto1_destroyDeviceReq"));
livoxProto1.livoxProto1_device_enablePcloudDataReq = reinterpret_cast<
livoxProto1_device_enablePcloudDataReqFn *>(
"livoxProto1_destroyDeviceCReq"));
livoxProto1.livoxProto1_device_enablePcloudDataCReq = reinterpret_cast<
livoxProto1_device_enablePcloudDataCReqFn *>(
dlsym(
livoxProto1.dlopenHandle.get(),
"livoxProto1_device_enablePcloudDataReq"));
livoxProto1.livoxProto1_device_disablePcloudDataReq = reinterpret_cast<
livoxProto1_device_disablePcloudDataReqFn *>(
"livoxProto1_device_enablePcloudDataCReq"));
livoxProto1.livoxProto1_device_disablePcloudDataCReq = reinterpret_cast<
livoxProto1_device_disablePcloudDataCReqFn *>(
dlsym(
livoxProto1.dlopenHandle.get(),
"livoxProto1_device_disablePcloudDataReq"));
livoxProto1.livoxProto1_device_getReturnModeReq = reinterpret_cast<
livoxProto1_device_getReturnModeReqFn *>(
"livoxProto1_device_disablePcloudDataCReq"));
livoxProto1.livoxProto1_device_getReturnModeCReq = reinterpret_cast<
livoxProto1_device_getReturnModeCReqFn *>(
dlsym(
livoxProto1.dlopenHandle.get(),
"livoxProto1_device_getReturnModeReq"));
"livoxProto1_device_getReturnModeCReq"));
livoxProto1.livoxProto1_getPcloudDataFdDesc = reinterpret_cast<
livoxProto1_getPcloudDataFdDescFn *>(
dlsym(
@@ -644,11 +646,11 @@ sscl::co::ViralNonPostingInvoker<int> livoxGen1_initializeCInd()
if (!livoxProto1.livoxProto1_main
|| !livoxProto1.livoxProto1_exit
|| !livoxProto1.livoxProto1_getOrCreateDeviceReq
|| !livoxProto1.livoxProto1_destroyDeviceReq
|| !livoxProto1.livoxProto1_device_enablePcloudDataReq
|| !livoxProto1.livoxProto1_device_disablePcloudDataReq
|| !livoxProto1.livoxProto1_device_getReturnModeReq
|| !livoxProto1.livoxProto1_getOrCreateDeviceCReq
|| !livoxProto1.livoxProto1_destroyDeviceCReq
|| !livoxProto1.livoxProto1_device_enablePcloudDataCReq
|| !livoxProto1.livoxProto1_device_disablePcloudDataCReq
|| !livoxProto1.livoxProto1_device_getReturnModeCReq
|| !livoxProto1.livoxProto1_getPcloudDataFdDesc)
{
throw std::runtime_error(
+7 -7
View File
@@ -18,13 +18,13 @@ struct LivoxProto1DllState
std::unique_ptr<void, void(*)(void*)> dlopenHandle;
livoxProto1_mainFn *livoxProto1_main;
livoxProto1_exitFn *livoxProto1_exit;
livoxProto1_getOrCreateDeviceReqFn *livoxProto1_getOrCreateDeviceReq;
livoxProto1_destroyDeviceReqFn *livoxProto1_destroyDeviceReq;
livoxProto1_device_enablePcloudDataReqFn
*livoxProto1_device_enablePcloudDataReq;
livoxProto1_device_disablePcloudDataReqFn
*livoxProto1_device_disablePcloudDataReq;
livoxProto1_device_getReturnModeReqFn *livoxProto1_device_getReturnModeReq;
livoxProto1_getOrCreateDeviceCReqFn *livoxProto1_getOrCreateDeviceCReq;
livoxProto1_destroyDeviceCReqFn *livoxProto1_destroyDeviceCReq;
livoxProto1_device_enablePcloudDataCReqFn
*livoxProto1_device_enablePcloudDataCReq;
livoxProto1_device_disablePcloudDataCReqFn
*livoxProto1_device_disablePcloudDataCReq;
livoxProto1_device_getReturnModeCReqFn *livoxProto1_device_getReturnModeCReq;
livoxProto1_getPcloudDataFdDescFn *livoxProto1_getPcloudDataFdDesc;
};
@@ -1,89 +0,0 @@
#include "livoxGen1Proto1CpsBridge.h"
#include <stdexcept>
namespace smo::stim_buff {
sscl::co::ViralNonPostingInvoker<adapters::smo::GetOrCreateDeviceResult>
coAwaitGetOrCreateDevice(
const std::shared_ptr<sscl::ComponentThread> &componentThread,
const std::string &deviceIdentifier,
const LivoxProviderParams &params)
{
if (!livoxProto1.livoxProto1_getOrCreateDeviceReq) {
throw std::runtime_error("coAwaitGetOrCreateDevice: proto1 function missing");
}
auto result = co_await adapters::smo::getGetOrCreateDeviceReqAReqAwaiter(
componentThread->getIoService(),
livoxProto1.livoxProto1_getOrCreateDeviceReq,
deviceIdentifier,
componentThread,
params.commandTimeoutMs,
params.retryDelayMs,
params.smoIp,
params.smoSubnetNbits,
params.dataPort,
params.cmdPort,
params.imuPort);
co_return result;
}
sscl::co::ViralNonPostingInvoker<adapters::smo::GetReturnModeResult>
coAwaitGetReturnMode(
const std::shared_ptr<sscl::ComponentThread> &componentThread,
const std::shared_ptr<livoxProto1::Device> &device)
{
if (!livoxProto1.livoxProto1_device_getReturnModeReq) {
throw std::runtime_error("coAwaitGetReturnMode: proto1 function missing");
}
co_return co_await adapters::smo::getDeviceGetReturnModeReqAReqAwaiter(
componentThread->getIoService(),
livoxProto1.livoxProto1_device_getReturnModeReq,
device);
}
sscl::co::ViralNonPostingInvoker<bool> coAwaitEnablePcloudData(
const std::shared_ptr<sscl::ComponentThread> &componentThread,
const std::shared_ptr<livoxProto1::Device> &device)
{
if (!livoxProto1.livoxProto1_device_enablePcloudDataReq) {
throw std::runtime_error("coAwaitEnablePcloudData: proto1 function missing");
}
co_return co_await adapters::smo::getDeviceEnablePcloudDataReqAReqAwaiter(
componentThread->getIoService(),
livoxProto1.livoxProto1_device_enablePcloudDataReq,
device);
}
sscl::co::ViralNonPostingInvoker<bool> coAwaitDisablePcloudData(
const std::shared_ptr<sscl::ComponentThread> &componentThread,
const std::shared_ptr<livoxProto1::Device> &device)
{
if (!livoxProto1.livoxProto1_device_disablePcloudDataReq) {
throw std::runtime_error("coAwaitDisablePcloudData: proto1 function missing");
}
co_return co_await adapters::smo::getDeviceDisablePcloudDataReqAReqAwaiter(
componentThread->getIoService(),
livoxProto1.livoxProto1_device_disablePcloudDataReq,
device);
}
sscl::co::ViralNonPostingInvoker<bool> coAwaitDestroyDevice(
const std::shared_ptr<sscl::ComponentThread> &componentThread,
const std::shared_ptr<livoxProto1::Device> &device)
{
if (!livoxProto1.livoxProto1_destroyDeviceReq) {
throw std::runtime_error("coAwaitDestroyDevice: proto1 function missing");
}
co_return co_await adapters::smo::getDestroyDeviceReqAReqAwaiter(
componentThread->getIoService(),
livoxProto1.livoxProto1_destroyDeviceReq,
device);
}
} // namespace smo::stim_buff
@@ -1,39 +0,0 @@
#ifndef LIVOX_GEN1_PROTO1_CPS_BRIDGE_H
#define LIVOX_GEN1_PROTO1_CPS_BRIDGE_H
#include <memory>
#include <adapters/smo/livoxProto1CpsAwaiters.h>
#include <spinscale/co/invokers.h>
#include <spinscale/componentThread.h>
#include "livoxGen1Internal.h"
namespace smo::stim_buff {
sscl::co::ViralNonPostingInvoker<adapters::smo::GetOrCreateDeviceResult>
coAwaitGetOrCreateDevice(
const std::shared_ptr<sscl::ComponentThread> &componentThread,
const std::string &deviceIdentifier,
const LivoxProviderParams &params);
sscl::co::ViralNonPostingInvoker<adapters::smo::GetReturnModeResult>
coAwaitGetReturnMode(
const std::shared_ptr<sscl::ComponentThread> &componentThread,
const std::shared_ptr<livoxProto1::Device> &device);
sscl::co::ViralNonPostingInvoker<bool> coAwaitEnablePcloudData(
const std::shared_ptr<sscl::ComponentThread> &componentThread,
const std::shared_ptr<livoxProto1::Device> &device);
sscl::co::ViralNonPostingInvoker<bool> coAwaitDisablePcloudData(
const std::shared_ptr<sscl::ComponentThread> &componentThread,
const std::shared_ptr<livoxProto1::Device> &device);
sscl::co::ViralNonPostingInvoker<bool> coAwaitDestroyDevice(
const std::shared_ptr<sscl::ComponentThread> &componentThread,
const std::shared_ptr<livoxProto1::Device> &device);
} // namespace smo::stim_buff
#endif // LIVOX_GEN1_PROTO1_CPS_BRIDGE_H