Refactor LivoxGen1 provider param parsing to shared DAP helpers.
Replace local param parsing with DeviceAttachmentSpec primitives for consistency with lcameraBuff and intrin threshold modules. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -78,63 +78,112 @@ size_t parseNDgramsPerFrame(
|
|||||||
LivoxProviderParams parseLivoxProviderParams(
|
LivoxProviderParams parseLivoxProviderParams(
|
||||||
const std::shared_ptr<device::DeviceAttachmentSpec> &desc)
|
const std::shared_ptr<device::DeviceAttachmentSpec> &desc)
|
||||||
{
|
{
|
||||||
|
using device::DeviceAttachmentSpec;
|
||||||
|
|
||||||
|
const auto& providerParams = desc->providerParams;
|
||||||
|
|
||||||
|
static const std::vector<std::string> cmdTimeoutSynonyms = {
|
||||||
|
"cmd-timeout-ms",
|
||||||
|
"command-timeout-ms",
|
||||||
|
};
|
||||||
|
static const std::vector<std::string> retryDelaySynonyms = {
|
||||||
|
"retry-delay-ms",
|
||||||
|
};
|
||||||
|
static const std::vector<std::string> smoSubnetSynonyms = {
|
||||||
|
"smo-subnet-nbits",
|
||||||
|
};
|
||||||
|
static const std::vector<std::string> dataPortSynonyms = {
|
||||||
|
"data-port",
|
||||||
|
};
|
||||||
|
static const std::vector<std::string> cmdPortSynonyms = {
|
||||||
|
"cmd-port",
|
||||||
|
};
|
||||||
|
static const std::vector<std::string> imuPortSynonyms = {
|
||||||
|
"imu-port",
|
||||||
|
};
|
||||||
|
static const std::vector<std::string> smoIpSynonyms = {
|
||||||
|
"smo-ip",
|
||||||
|
};
|
||||||
|
|
||||||
|
DeviceAttachmentSpec::rejectUnknownParams(
|
||||||
|
providerParams,
|
||||||
|
std::string(__func__) + ": Unknown provider parameter: ",
|
||||||
|
cmdTimeoutSynonyms,
|
||||||
|
retryDelaySynonyms,
|
||||||
|
smoSubnetSynonyms,
|
||||||
|
dataPortSynonyms,
|
||||||
|
cmdPortSynonyms,
|
||||||
|
imuPortSynonyms,
|
||||||
|
smoIpSynonyms);
|
||||||
|
|
||||||
LivoxProviderParams params;
|
LivoxProviderParams params;
|
||||||
|
|
||||||
// Parse optional integer parameters from provider params
|
if (const auto matchedParam = DeviceAttachmentSpec::findOptionalParamWithSynonyms(
|
||||||
for (const auto &providerParam : desc->providerParams) {
|
providerParams, cmdTimeoutSynonyms))
|
||||||
if (providerParam.first == "cmd-timeout-ms"
|
{
|
||||||
|| providerParam.first == "command-timeout-ms")
|
params.commandTimeoutMs = DeviceAttachmentSpec::parseParamValueAsInt(
|
||||||
{
|
matchedParam->first, matchedParam->second);
|
||||||
params.commandTimeoutMs = device::DeviceAttachmentSpec
|
}
|
||||||
::parseRequiredParamAsInt(
|
|
||||||
desc->providerParams,
|
if (const auto matchedParam = DeviceAttachmentSpec::findOptionalParamWithSynonyms(
|
||||||
providerParam.first);
|
providerParams, retryDelaySynonyms))
|
||||||
} else if (providerParam.first == "retry-delay-ms") {
|
{
|
||||||
params.retryDelayMs = device::DeviceAttachmentSpec
|
params.retryDelayMs = DeviceAttachmentSpec::parseParamValueAsInt(
|
||||||
::parseRequiredParamAsInt(
|
matchedParam->first, matchedParam->second);
|
||||||
desc->providerParams,
|
}
|
||||||
"retry-delay-ms");
|
|
||||||
} else if (providerParam.first == "smo-subnet-nbits") {
|
if (const auto matchedParam = DeviceAttachmentSpec::findOptionalParamWithSynonyms(
|
||||||
params.smoSubnetNbits = static_cast<uint8_t>(
|
providerParams, smoSubnetSynonyms))
|
||||||
device::DeviceAttachmentSpec::parseRequiredParamAsInt(
|
{
|
||||||
desc->providerParams,
|
params.smoSubnetNbits = static_cast<uint8_t>(
|
||||||
"smo-subnet-nbits"));
|
DeviceAttachmentSpec::parseParamValueAsInt(
|
||||||
} else if (providerParam.first == "data-port") {
|
matchedParam->first, matchedParam->second));
|
||||||
params.dataPort = static_cast<uint16_t>(
|
}
|
||||||
device::DeviceAttachmentSpec::parseRequiredParamAsInt(
|
|
||||||
desc->providerParams,
|
if (const auto matchedParam = DeviceAttachmentSpec::findOptionalParamWithSynonyms(
|
||||||
"data-port"));
|
providerParams, dataPortSynonyms))
|
||||||
} else if (providerParam.first == "cmd-port") {
|
{
|
||||||
params.cmdPort = static_cast<uint16_t>(
|
params.dataPort = static_cast<uint16_t>(
|
||||||
device::DeviceAttachmentSpec::parseRequiredParamAsInt(
|
DeviceAttachmentSpec::parseParamValueAsInt(
|
||||||
desc->providerParams,
|
matchedParam->first, matchedParam->second));
|
||||||
"cmd-port"));
|
}
|
||||||
} else if (providerParam.first == "imu-port") {
|
|
||||||
params.imuPort = static_cast<uint16_t>(
|
if (const auto matchedParam = DeviceAttachmentSpec::findOptionalParamWithSynonyms(
|
||||||
device::DeviceAttachmentSpec::parseRequiredParamAsInt(
|
providerParams, cmdPortSynonyms))
|
||||||
desc->providerParams,
|
{
|
||||||
"imu-port"));
|
params.cmdPort = static_cast<uint16_t>(
|
||||||
} else if (providerParam.first == "smo-ip") {
|
DeviceAttachmentSpec::parseParamValueAsInt(
|
||||||
if (providerParam.second.empty()) {
|
matchedParam->first, matchedParam->second));
|
||||||
throw std::runtime_error(
|
}
|
||||||
std::string(__func__) + ": smo-ip parameter is empty");
|
|
||||||
}
|
if (const auto matchedParam = DeviceAttachmentSpec::findOptionalParamWithSynonyms(
|
||||||
if (providerParam.second.find('.') == std::string::npos
|
providerParams, imuPortSynonyms))
|
||||||
|| std::count(
|
{
|
||||||
providerParam.second.begin(),
|
params.imuPort = static_cast<uint16_t>(
|
||||||
providerParam.second.end(),
|
DeviceAttachmentSpec::parseParamValueAsInt(
|
||||||
'.') != 3)
|
matchedParam->first, matchedParam->second));
|
||||||
{
|
}
|
||||||
throw std::runtime_error(
|
|
||||||
std::string(__func__)
|
if (const auto matchedParam = DeviceAttachmentSpec::findOptionalParamWithSynonyms(
|
||||||
+ ": smo-ip parameter is not an IPv4 address");
|
providerParams, smoIpSynonyms))
|
||||||
}
|
{
|
||||||
params.smoIp = providerParam.second;
|
if (matchedParam->second.empty()) {
|
||||||
} else {
|
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
std::string(__func__) + ": Unknown provider parameter: "
|
std::string(__func__) + ": smo-ip parameter is empty");
|
||||||
+ providerParam.first);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (matchedParam->second.find('.') == std::string::npos
|
||||||
|
|| std::count(
|
||||||
|
matchedParam->second.begin(),
|
||||||
|
matchedParam->second.end(),
|
||||||
|
'.') != 3)
|
||||||
|
{
|
||||||
|
throw std::runtime_error(
|
||||||
|
std::string(__func__)
|
||||||
|
+ ": smo-ip parameter is not an IPv4 address");
|
||||||
|
}
|
||||||
|
|
||||||
|
params.smoIp = matchedParam->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
return params;
|
return params;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#ifndef _LIVOX_GEN1_PCLOUD_AMBIENCE_QUALE_IFACE_API_H
|
#ifndef _LIVOX_GEN1_PCLOUD_AMBIENCE_QUALE_IFACE_API_H
|
||||||
#define _LIVOX_GEN1_PCLOUD_AMBIENCE_QUALE_IFACE_API_H
|
#define _LIVOX_GEN1_PCLOUD_AMBIENCE_QUALE_IFACE_API_H
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
@@ -39,15 +38,6 @@ struct ParamComparator
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool paramsContain(
|
|
||||||
const std::vector<std::pair<std::string, std::string>>& params,
|
|
||||||
const std::string& name)
|
|
||||||
{
|
|
||||||
return std::any_of(
|
|
||||||
params.begin(), params.end(),
|
|
||||||
[&name](const auto& p) { return p.first == name; });
|
|
||||||
}
|
|
||||||
|
|
||||||
/* pcloudLightAmbience requires exactly one `passband-count-gt-val` on its
|
/* pcloudLightAmbience requires exactly one `passband-count-gt-val` on its
|
||||||
* qualeIfaceApi params; `passband-count-lt-val` is a hard error. Feeds a
|
* qualeIfaceApi params; `passband-count-lt-val` is a hard error. Feeds a
|
||||||
* negtrin(...) segment (scene is "unbearably much, get away").
|
* negtrin(...) segment (scene is "unbearably much, get away").
|
||||||
@@ -57,7 +47,8 @@ inline ParamComparator parsePcloudLightAmbienceGtComparator(
|
|||||||
{
|
{
|
||||||
const auto& params = deviceAttachmentSpec->qualeIfaceApiParams;
|
const auto& params = deviceAttachmentSpec->qualeIfaceApiParams;
|
||||||
|
|
||||||
if (paramsContain(params, "passband-count-lt-val"))
|
if (device::DeviceAttachmentSpec::paramsContain(
|
||||||
|
params, "passband-count-lt-val"))
|
||||||
{
|
{
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
"pcloudLightAmbience qualeIfaceApi does not accept "
|
"pcloudLightAmbience qualeIfaceApi does not accept "
|
||||||
@@ -91,7 +82,8 @@ inline ParamComparator parsePcloudDarkAmbienceLtComparator(
|
|||||||
{
|
{
|
||||||
const auto& params = deviceAttachmentSpec->qualeIfaceApiParams;
|
const auto& params = deviceAttachmentSpec->qualeIfaceApiParams;
|
||||||
|
|
||||||
if (paramsContain(params, "passband-count-gt-val"))
|
if (device::DeviceAttachmentSpec::paramsContain(
|
||||||
|
params, "passband-count-gt-val"))
|
||||||
{
|
{
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
"pcloudDarkAmbience qualeIfaceApi does not accept "
|
"pcloudDarkAmbience qualeIfaceApi does not accept "
|
||||||
|
|||||||
Reference in New Issue
Block a user