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(
|
||||
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;
|
||||
|
||||
// Parse optional integer parameters from provider params
|
||||
for (const auto &providerParam : desc->providerParams) {
|
||||
if (providerParam.first == "cmd-timeout-ms"
|
||||
|| providerParam.first == "command-timeout-ms")
|
||||
if (const auto matchedParam = DeviceAttachmentSpec::findOptionalParamWithSynonyms(
|
||||
providerParams, cmdTimeoutSynonyms))
|
||||
{
|
||||
params.commandTimeoutMs = DeviceAttachmentSpec::parseParamValueAsInt(
|
||||
matchedParam->first, matchedParam->second);
|
||||
}
|
||||
|
||||
if (const auto matchedParam = DeviceAttachmentSpec::findOptionalParamWithSynonyms(
|
||||
providerParams, retryDelaySynonyms))
|
||||
{
|
||||
params.retryDelayMs = DeviceAttachmentSpec::parseParamValueAsInt(
|
||||
matchedParam->first, matchedParam->second);
|
||||
}
|
||||
|
||||
if (const auto matchedParam = DeviceAttachmentSpec::findOptionalParamWithSynonyms(
|
||||
providerParams, smoSubnetSynonyms))
|
||||
{
|
||||
params.commandTimeoutMs = device::DeviceAttachmentSpec
|
||||
::parseRequiredParamAsInt(
|
||||
desc->providerParams,
|
||||
providerParam.first);
|
||||
} else if (providerParam.first == "retry-delay-ms") {
|
||||
params.retryDelayMs = device::DeviceAttachmentSpec
|
||||
::parseRequiredParamAsInt(
|
||||
desc->providerParams,
|
||||
"retry-delay-ms");
|
||||
} else if (providerParam.first == "smo-subnet-nbits") {
|
||||
params.smoSubnetNbits = static_cast<uint8_t>(
|
||||
device::DeviceAttachmentSpec::parseRequiredParamAsInt(
|
||||
desc->providerParams,
|
||||
"smo-subnet-nbits"));
|
||||
} else if (providerParam.first == "data-port") {
|
||||
DeviceAttachmentSpec::parseParamValueAsInt(
|
||||
matchedParam->first, matchedParam->second));
|
||||
}
|
||||
|
||||
if (const auto matchedParam = DeviceAttachmentSpec::findOptionalParamWithSynonyms(
|
||||
providerParams, dataPortSynonyms))
|
||||
{
|
||||
params.dataPort = static_cast<uint16_t>(
|
||||
device::DeviceAttachmentSpec::parseRequiredParamAsInt(
|
||||
desc->providerParams,
|
||||
"data-port"));
|
||||
} else if (providerParam.first == "cmd-port") {
|
||||
DeviceAttachmentSpec::parseParamValueAsInt(
|
||||
matchedParam->first, matchedParam->second));
|
||||
}
|
||||
|
||||
if (const auto matchedParam = DeviceAttachmentSpec::findOptionalParamWithSynonyms(
|
||||
providerParams, cmdPortSynonyms))
|
||||
{
|
||||
params.cmdPort = static_cast<uint16_t>(
|
||||
device::DeviceAttachmentSpec::parseRequiredParamAsInt(
|
||||
desc->providerParams,
|
||||
"cmd-port"));
|
||||
} else if (providerParam.first == "imu-port") {
|
||||
DeviceAttachmentSpec::parseParamValueAsInt(
|
||||
matchedParam->first, matchedParam->second));
|
||||
}
|
||||
|
||||
if (const auto matchedParam = DeviceAttachmentSpec::findOptionalParamWithSynonyms(
|
||||
providerParams, imuPortSynonyms))
|
||||
{
|
||||
params.imuPort = static_cast<uint16_t>(
|
||||
device::DeviceAttachmentSpec::parseRequiredParamAsInt(
|
||||
desc->providerParams,
|
||||
"imu-port"));
|
||||
} else if (providerParam.first == "smo-ip") {
|
||||
if (providerParam.second.empty()) {
|
||||
DeviceAttachmentSpec::parseParamValueAsInt(
|
||||
matchedParam->first, matchedParam->second));
|
||||
}
|
||||
|
||||
if (const auto matchedParam = DeviceAttachmentSpec::findOptionalParamWithSynonyms(
|
||||
providerParams, smoIpSynonyms))
|
||||
{
|
||||
if (matchedParam->second.empty()) {
|
||||
throw std::runtime_error(
|
||||
std::string(__func__) + ": smo-ip parameter is empty");
|
||||
}
|
||||
if (providerParam.second.find('.') == std::string::npos
|
||||
|
||||
if (matchedParam->second.find('.') == std::string::npos
|
||||
|| std::count(
|
||||
providerParam.second.begin(),
|
||||
providerParam.second.end(),
|
||||
matchedParam->second.begin(),
|
||||
matchedParam->second.end(),
|
||||
'.') != 3)
|
||||
{
|
||||
throw std::runtime_error(
|
||||
std::string(__func__)
|
||||
+ ": smo-ip parameter is not an IPv4 address");
|
||||
}
|
||||
params.smoIp = providerParam.second;
|
||||
} else {
|
||||
throw std::runtime_error(
|
||||
std::string(__func__) + ": Unknown provider parameter: "
|
||||
+ providerParam.first);
|
||||
}
|
||||
|
||||
params.smoIp = matchedParam->second;
|
||||
}
|
||||
|
||||
return params;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#ifndef _LIVOX_GEN1_PCLOUD_AMBIENCE_QUALE_IFACE_API_H
|
||||
#define _LIVOX_GEN1_PCLOUD_AMBIENCE_QUALE_IFACE_API_H
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#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
|
||||
* qualeIfaceApi params; `passband-count-lt-val` is a hard error. Feeds a
|
||||
* negtrin(...) segment (scene is "unbearably much, get away").
|
||||
@@ -57,7 +47,8 @@ inline ParamComparator parsePcloudLightAmbienceGtComparator(
|
||||
{
|
||||
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(
|
||||
"pcloudLightAmbience qualeIfaceApi does not accept "
|
||||
@@ -91,7 +82,8 @@ inline ParamComparator parsePcloudDarkAmbienceLtComparator(
|
||||
{
|
||||
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(
|
||||
"pcloudDarkAmbience qualeIfaceApi does not accept "
|
||||
|
||||
Reference in New Issue
Block a user