LivoxProto1: port to sscl::co framework
Code now actually looks a lot cleaner, tbh.
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user