From 2234df1de26a7f9914802e9eca266d5b5a7c254c Mon Sep 17 00:00:00 2001 From: Hayodea Hekol Date: Thu, 30 Oct 2025 13:50:46 -0400 Subject: [PATCH] livoxGen1:attach: alloc PcloudStimBuff after getting return mode --- stimBuffApis/livoxGen1/livoxGen1.cpp | 34 ++++++++++++++++------------ 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/stimBuffApis/livoxGen1/livoxGen1.cpp b/stimBuffApis/livoxGen1/livoxGen1.cpp index 13f8f76..43203a8 100644 --- a/stimBuffApis/livoxGen1/livoxGen1.cpp +++ b/stimBuffApis/livoxGen1/livoxGen1.cpp @@ -96,6 +96,7 @@ public: public: const std::shared_ptr spec; std::shared_ptr stimBuff; + std::shared_ptr deviceTmp; private: std::unique_ptr delayTimer; @@ -113,15 +114,8 @@ public: return; } - // Create and add PcloudStimulusBuffer to collection - StimulusBuffer::PcloudFormatDesc formatDesc; - formatDesc.format = StimulusBuffer::PcloudFormatDesc::Format::XYZI; - auto pcloudStimBuff = std::make_shared( - *context->spec, dev, formatDesc); - - context->stimBuff = pcloudStimBuff; - dev->nAttachedStimBuffs++; - attachedStimBuffs.push_back(pcloudStimBuff); + // Stash device pointer until after getReturnMode succeeds + context->deviceTmp = dev; if (1 || OptionParser::getOptions().verbose) { @@ -141,7 +135,7 @@ public: { // Initialize timer with device's component thread delayTimer = std::make_unique( - context->stimBuff->device->componentThread->getIoService()); + context->deviceTmp->componentThread->getIoService()); delayTimer->expires_from_now(boost::posix_time::milliseconds(5)); delayTimer->async_wait( @@ -164,7 +158,7 @@ public: } (*livoxProto1.livoxProto1_device_getReturnModeReq)( - context->stimBuff->device, + context->deviceTmp, {context, std::bind( &AttachDeviceReq::attachDeviceReq3, context.get(), context, @@ -184,6 +178,16 @@ public: return; } + // Create and add PcloudStimulusBuffer to collection now that device is ready + StimulusBuffer::PcloudFormatDesc formatDesc; + formatDesc.format = StimulusBuffer::PcloudFormatDesc::Format::XYZI; + auto pcloudStimBuff = std::make_shared( + *context->spec, context->deviceTmp, formatDesc); + + context->stimBuff = pcloudStimBuff; + context->deviceTmp->nAttachedStimBuffs++; + attachedStimBuffs.push_back(pcloudStimBuff); + if (1 || OptionParser::getOptions().verbose) { std::cout << __func__ << ": Got return mode (" << (int)mode @@ -509,15 +513,15 @@ extern "C" void livoxGen1_attachDeviceReq( return; } - /* Get return mode first. Don't need delay since this no commands were + /* Enable pcloud data first. Don't need delay since no commands were * sent to device prior to us reaching here. */ - (*livoxProto1.livoxProto1_device_getReturnModeReq)( + (*livoxProto1.livoxProto1_device_enablePcloudDataReq)( pcloudStimBuff->device, {request, std::bind( - &AttachDeviceReq::attachDeviceReq3, + &AttachDeviceReq::attachDeviceReq5, request.get(), request, - std::placeholders::_1, std::placeholders::_2)}); + std::placeholders::_1)}); return; }