31#ifndef SENSOR_COMMON_IMPL_HPP_
32#define SENSOR_COMMON_IMPL_HPP_
34#include <dw/core/base/Types.h>
36#include <dw/rig/Rig.h>
37#include <dw/core/logger/Logger.hpp>
47 using FixedString1024 = dw::core::FixedString<1024>;
50 static FixedString1024
adjustPath(
const char* paramString, uint64_t sensorId,
const char* toFind, dwConstRigHandle_t& rig)
52 constexpr char LOG_TAG[] =
"SensorCommonImpl";
53 FixedString1024 parameters(paramString);
54 const char* path =
nullptr;
58 throw Exception(DW_INVALID_ARGUMENT,
"Driveworks sensor adjustPath: no sensor data found for sensorId ", sensorId,
59 " with param: \"", paramString,
"\", please check whether the data path in param is accessible");
62 FixedString1024 p(path);
63 FixedString1024 param(paramString);
64 auto start = param.find(toFind);
65 if (start == FixedString1024::NPOS)
70 FixedString1024 find(toFind);
72 auto first = param.substr(0, start + find.size());
74 auto second = param.substr(start + find.size(), param.size());
77 start = second.find(
",");
78 if (start == FixedString1024::NPOS)
80 start = second.size();
84 auto origVideoPath = second.substr(0, start);
87 parameters = first.c_str();
89 second = second.substr(start, second.size());
92 parameters += second.c_str();
96 start = parameters.find(
"timestamp=");
97 if (start != FixedString1024::NPOS)
100 auto commonPrefix = p.rfind(origVideoPath);
101 if (commonPrefix == FixedString1024::NPOS)
105 DW_LOGW <<
"adjustPath: [sensorId: " << sensorId <<
" with param:" << paramString <<
"] Failed to extract rig directory path, so that cannot adjust timestamp path" << Logger::State::endl;
108 p = p.substr(0, commonPrefix);
110 auto patternSize = FixedString1024(
"timestamp=").size();
111 first = parameters.substr(0, start + patternSize);
112 second = parameters.substr(start + patternSize, parameters.size());
115 parameters += second;
121 static dwSensorHandle_t
createSensor(std::string sensorName, dwConstRigHandle_t rig, dwSALHandle_t sal)
123 using FixedString1024 = dw::core::FixedString<1024>;
125 dwSensorParams sensorParams{};
126 uint32_t sensorId = 0;
127 dwSensorHandle_t sensorHandle = DW_NULL_HANDLE;
134 FixedString1024 parameters(
"");
135 if (FixedString1024(sensorParams.protocol).find(
".virtual") != FixedString1024::NPOS)
140 sensorParams.parameters = parameters.c_str();
144 "Cannot create sensor");
#define FRWK_CHECK_DW_ERROR_MSG(x, description)
#define FRWK_CHECK_DW_ERROR(x)
static FixedString1024 adjustPath(const char *paramString, uint64_t sensorId, const char *toFind, dwConstRigHandle_t &rig)
static dwSensorHandle_t createSensor(std::string sensorName, dwConstRigHandle_t rig, dwSALHandle_t sal)