2025-11-03 22:18:45 -04:00
|
|
|
#include <boostAsioLinkageFix.h>
|
2025-09-06 20:06:38 -04:00
|
|
|
#include <stdexcept>
|
2025-11-01 22:41:58 -04:00
|
|
|
#include <boost/asio/posix/stream_descriptor.hpp>
|
2025-09-05 00:08:25 -04:00
|
|
|
#include "livoxProto1.h"
|
2025-09-06 20:06:38 -04:00
|
|
|
#include "device.h"
|
|
|
|
|
#include "core.h"
|
2025-11-01 22:41:58 -04:00
|
|
|
#include "udpCommandDemuxer.h"
|
2025-09-06 20:06:38 -04:00
|
|
|
|
2025-09-05 00:08:25 -04:00
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
|
2026-05-28 20:13:12 -04:00
|
|
|
sscl::co::ViralNonPostingInvoker<LivoxProto1GetOrCreateDeviceResult>
|
|
|
|
|
livoxProto1_getOrCreateDeviceCReq(
|
2025-09-06 20:06:38 -04:00
|
|
|
const std::string& deviceIdentifier,
|
2025-12-27 16:21:22 -04:00
|
|
|
const std::shared_ptr<sscl::ComponentThread>& componentThread,
|
2025-11-01 02:45:24 -04:00
|
|
|
int commandTimeoutMs, int retryDelayMs,
|
2025-09-06 20:06:38 -04:00
|
|
|
const std::string& smoIp, uint8_t smoSubnetNbits,
|
2026-05-28 20:13:12 -04:00
|
|
|
uint16_t dataPort, uint16_t cmdPort, uint16_t imuPort)
|
2025-09-06 20:06:38 -04:00
|
|
|
{
|
|
|
|
|
// Get the global DeviceManager instance
|
|
|
|
|
auto& protoState = livoxProto1::getProtoState();
|
|
|
|
|
if (!protoState.deviceManager)
|
|
|
|
|
{
|
|
|
|
|
throw std::runtime_error(
|
|
|
|
|
std::string(__func__) + ": LivoxProto1 not initialized - call "
|
|
|
|
|
"livoxProto1_main first");
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-28 20:13:12 -04:00
|
|
|
// Delegate to the DeviceManager to create the device
|
|
|
|
|
co_return co_await protoState.deviceManager->getOrCreateDeviceCReq(
|
2025-09-06 20:06:38 -04:00
|
|
|
deviceIdentifier, componentThread,
|
2025-11-01 02:45:24 -04:00
|
|
|
commandTimeoutMs, retryDelayMs,
|
2025-09-06 20:06:38 -04:00
|
|
|
smoIp, smoSubnetNbits,
|
2026-05-28 20:13:12 -04:00
|
|
|
dataPort, cmdPort, imuPort);
|
2025-09-06 20:06:38 -04:00
|
|
|
}
|
2025-09-05 00:08:25 -04:00
|
|
|
|
2026-05-28 20:13:12 -04:00
|
|
|
sscl::co::ViralNonPostingInvoker<bool> livoxProto1_destroyDeviceCReq(
|
|
|
|
|
std::shared_ptr<livoxProto1::Device> device)
|
2025-09-09 12:07:49 -04:00
|
|
|
{
|
|
|
|
|
auto& protoState = livoxProto1::getProtoState();
|
|
|
|
|
if (!protoState.deviceManager)
|
|
|
|
|
{
|
|
|
|
|
throw std::runtime_error(std::string(__func__)
|
|
|
|
|
+ ": DeviceManager not initialized");
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-28 20:13:12 -04:00
|
|
|
co_return co_await protoState.deviceManager->destroyDeviceCReq(device);
|
2025-09-09 12:07:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void livoxProto1_main(
|
2025-12-27 16:21:22 -04:00
|
|
|
const std::shared_ptr<sscl::ComponentThread>& componentThread,
|
2025-10-01 18:47:42 -04:00
|
|
|
const smo::stim_buff::SmoCallbacks& smoCallbacks)
|
2025-09-05 00:08:25 -04:00
|
|
|
{
|
2025-09-09 12:07:49 -04:00
|
|
|
livoxProto1::main(componentThread, smoCallbacks);
|
2025-09-05 00:08:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void livoxProto1_exit(void)
|
|
|
|
|
{
|
|
|
|
|
livoxProto1::exit();
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-28 20:13:12 -04:00
|
|
|
sscl::co::ViralNonPostingInvoker<bool> livoxProto1_device_enablePcloudDataCReq(
|
|
|
|
|
std::shared_ptr<livoxProto1::Device> device)
|
2025-10-25 12:53:07 -04:00
|
|
|
{
|
|
|
|
|
if (!device)
|
|
|
|
|
{
|
|
|
|
|
throw std::runtime_error(std::string(__func__)
|
|
|
|
|
+ ": Device pointer is null");
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-28 20:13:12 -04:00
|
|
|
co_return co_await device->enablePcloudDataCReq();
|
2025-10-25 12:53:07 -04:00
|
|
|
}
|
|
|
|
|
|
2026-05-28 20:13:12 -04:00
|
|
|
sscl::co::ViralNonPostingInvoker<bool> livoxProto1_device_disablePcloudDataCReq(
|
|
|
|
|
std::shared_ptr<livoxProto1::Device> device)
|
2025-10-25 12:53:07 -04:00
|
|
|
{
|
|
|
|
|
if (!device)
|
|
|
|
|
{
|
|
|
|
|
throw std::runtime_error(std::string(__func__)
|
|
|
|
|
+ ": Device pointer is null");
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-28 20:13:12 -04:00
|
|
|
co_return co_await device->disablePcloudDataCReq();
|
2025-10-25 12:53:07 -04:00
|
|
|
}
|
|
|
|
|
|
2026-05-28 20:13:12 -04:00
|
|
|
sscl::co::ViralNonPostingInvoker<LivoxProto1GetReturnModeResult>
|
|
|
|
|
livoxProto1_device_getReturnModeCReq(
|
|
|
|
|
std::shared_ptr<livoxProto1::Device> device)
|
2025-10-30 11:49:54 -04:00
|
|
|
{
|
|
|
|
|
if (!device)
|
|
|
|
|
{
|
|
|
|
|
throw std::runtime_error(std::string(__func__)
|
|
|
|
|
+ ": Device pointer is null");
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-28 20:13:12 -04:00
|
|
|
livoxProto1::Device::GetReturnModeResult deviceResult =
|
|
|
|
|
co_await device->getReturnModeCReq();
|
|
|
|
|
LivoxProto1GetReturnModeResult result;
|
|
|
|
|
result.success = deviceResult.success;
|
|
|
|
|
result.returnMode = deviceResult.returnMode;
|
|
|
|
|
co_return result;
|
2025-10-30 11:49:54 -04:00
|
|
|
}
|
|
|
|
|
|
2025-11-01 22:41:58 -04:00
|
|
|
std::shared_ptr<boost::asio::posix::stream_descriptor>
|
|
|
|
|
livoxProto1_getPcloudDataFdDesc(void)
|
|
|
|
|
{
|
|
|
|
|
auto& protoState = livoxProto1::getProtoState();
|
|
|
|
|
if (!protoState.deviceManager)
|
|
|
|
|
{
|
|
|
|
|
throw std::runtime_error(std::string(__func__)
|
|
|
|
|
+ ": DeviceManager not initialized");
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-02 19:16:22 -04:00
|
|
|
return protoState.deviceManager->udpCommandDemuxer.getPcloudDataFdDesc();
|
2025-11-01 22:41:58 -04:00
|
|
|
}
|
|
|
|
|
|
2025-09-05 00:08:25 -04:00
|
|
|
} // extern "C"
|