• <xmp id="om0om">
  • <table id="om0om"><noscript id="om0om"></noscript></table>
  • Compute Graph Framework SDK Reference  5.8
    All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
    SensorCommonImpl.hpp
    Go to the documentation of this file.
    1
    2//
    3// Notice
    4// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES
    5// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
    6// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT,
    7// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
    8//
    9// NVIDIA CORPORATION & AFFILIATES assumes no responsibility for the consequences of use of such
    10// information or for any infringement of patents or other rights of third parties that may
    11// result from its use. No license is granted by implication or otherwise under any patent
    12// or patent rights of NVIDIA CORPORATION & AFFILIATES. No third party distribution is allowed unless
    13// expressly authorized by NVIDIA. Details are subject to change without notice.
    14// This code supersedes and replaces all information previously supplied.
    15// NVIDIA CORPORATION & AFFILIATES products are not authorized for use as critical
    16// components in life support devices or systems without express written approval of
    17// NVIDIA CORPORATION & AFFILIATES.
    18//
    19// SPDX-FileCopyrightText: Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
    20// SPDX-License-Identifier: LicenseRef-NvidiaProprietary
    21//
    22// NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
    23// property and proprietary rights in and to this material, related
    24// documentation and any modifications thereto. Any use, reproduction,
    25// disclosure or distribution of this material and related documentation
    26// without an express license agreement from NVIDIA CORPORATION or
    27// its affiliates is strictly prohibited.
    28//
    30
    31#ifndef SENSOR_COMMON_IMPL_HPP_
    32#define SENSOR_COMMON_IMPL_HPP_
    33
    34#include <dw/core/base/Types.h>
    35#include <dwcgf/Exception.hpp>
    36#include <dw/rig/Rig.h>
    38
    39namespace dw
    40{
    41namespace framework
    42{
    43
    45{
    46
    47 using FixedString1024 = dw::core::FixedString<1024>;
    48
    49public:
    50 static FixedString1024 adjustPath(const char* paramString, uint64_t sensorId, const char* toFind, dwConstRigHandle_t& rig)
    51 {
    52 constexpr char LOG_TAG[] = "SensorCommonImpl";
    53 FixedString1024 parameters(paramString);
    54 const char* path = nullptr;
    55 FRWK_CHECK_DW_ERROR(dwRig_getSensorDataPath(&path, static_cast<uint32_t>(sensorId), rig));
    56 if (path == nullptr)
    57 {
    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");
    60 }
    61
    62 FixedString1024 p(path);
    63 FixedString1024 param(paramString);
    64 auto start = param.find(toFind);
    65 if (start == FixedString1024::NPOS)
    66 {
    67 return parameters;
    68 }
    69
    70 FixedString1024 find(toFind);
    71 // String from start to end of pattern
    72 auto first = param.substr(0, start + find.size());
    73 // String from end of pattern to end of string
    74 auto second = param.substr(start + find.size(), param.size());
    75
    76 // Extract file name from rest of arguments
    77 start = second.find(",");
    78 if (start == FixedString1024::NPOS)
    79 {
    80 start = second.size();
    81 }
    82
    83 // Save original video path for later use
    84 auto origVideoPath = second.substr(0, start);
    85
    86 // Append absolute path (actually 'p' might be not absolute, just completed with relative rig path dir)
    87 parameters = first.c_str();
    88 parameters += p;
    89 second = second.substr(start, second.size());
    90
    91 // Append the rest of the param, if there's any
    92 parameters += second.c_str();
    93
    94 if (find == "video=")
    95 {
    96 start = parameters.find("timestamp=");
    97 if (start != FixedString1024::NPOS)
    98 {
    99 // Extract the common prefix (i.e. rig dir) from video absolute path 'p'
    100 auto commonPrefix = p.rfind(origVideoPath);
    101 if (commonPrefix == FixedString1024::NPOS)
    102 {
    103 // Absolute path returned from dwRig is supposed to have "original path" as suffix
    104 // If that's not true, we cannot adjust timestamp path, just keep it unchanged
    105 FRWK_LOGW << "adjustPath: [sensorId: " << sensorId << " with param:" << paramString << "] Failed to extract rig directory path, so that cannot adjust timestamp path" << Logger::State::endl;
    106 commonPrefix = 0;
    107 }
    108 p = p.substr(0, commonPrefix);
    109 // Add common prefix to timestamp path
    110 auto patternSize = FixedString1024("timestamp=").size();
    111 first = parameters.substr(0, start + patternSize);
    112 second = parameters.substr(start + patternSize, parameters.size());
    113 parameters = first;
    114 parameters += p;
    115 parameters += second;
    116 }
    117 }
    118 return parameters;
    119 }
    120
    121 static dwSensorHandle_t createSensor(std::string sensorName, dwConstRigHandle_t rig, dwSALHandle_t sal)
    122 {
    123 using FixedString1024 = dw::core::FixedString<1024>;
    124
    125 dwSensorParams sensorParams{};
    126 uint32_t sensorId = 0;
    127 dwSensorHandle_t sensorHandle = DW_NULL_HANDLE;
    128 FRWK_CHECK_DW_ERROR(dwRig_findSensorByName(&sensorId, sensorName.c_str(), rig));
    129 FRWK_CHECK_DW_ERROR(dwRig_getSensorParameter(&sensorParams.parameters, sensorId, rig));
    130 FRWK_CHECK_DW_ERROR(dwRig_getSensorProtocol(&sensorParams.protocol, sensorId, rig));
    131
    132 // Fix virtual sensor paths to be absolute rather than relative so sensor
    133 // initialize gets the right file path.
    134 FixedString1024 parameters("");
    135 if (FixedString1024(sensorParams.protocol).find(".virtual") != FixedString1024::NPOS)
    136 {
    137 parameters = dw::framework::SensorCommonImpl::adjustPath(sensorParams.parameters, sensorId, "video=", rig);
    138 parameters = dw::framework::SensorCommonImpl::adjustPath(parameters.c_str(), sensorId, "file=", rig);
    139
    140 sensorParams.parameters = parameters.c_str();
    141 }
    142
    143 FRWK_CHECK_DW_ERROR_MSG(dwSAL_createSensor(&sensorHandle, sensorParams, sal),
    144 "Cannot create sensor");
    145 return sensorHandle;
    146 }
    147};
    148} // namespace framework
    149} // namespace dw
    150
    151#endif // SENSOR_COMMON_IMPL_HPP_
    #define FRWK_CHECK_DW_ERROR_MSG(x, description)
    Definition: Exception.hpp:329
    #define FRWK_CHECK_DW_ERROR(x)
    Definition: Exception.hpp:263
    #define FRWK_LOGW
    Definition: Logger.hpp:40
    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)
    Definition: Exception.hpp:47
    人人超碰97caoporen国产