Compute Graph Framework SDK Reference  5.10
dwChannelDrainerTemplate.hpp
Go to the documentation of this file.
1
2// This code contains NVIDIA Confidential Information and is disclosed
3// under the Mutual Non-Disclosure Agreement.
4//
5// Notice
6// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES
7// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
8// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT,
9// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
10//
11// NVIDIA Corporation assumes no responsibility for the consequences of use of such
12// information or for any infringement of patents or other rights of third parties that may
13// result from its use. No license is granted by implication or otherwise under any patent
14// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless
15// expressly authorized by NVIDIA. Details are subject to change without notice.
16// This code supersedes and replaces all information previously supplied.
17// NVIDIA Corporation products are not authorized for use as critical
18// components in life support devices or systems without express written approval of
19// NVIDIA Corporation.
20//
21// Copyright (c) 2020-2022 NVIDIA Corporation. All rights reserved.
22//
23// NVIDIA Corporation and its licensors retain all intellectual property and proprietary
24// rights in and to this software and related documentation and any modifications thereto.
25// Any use, reproduction, disclosure or distribution of this software and related
26// documentation without an express license agreement from NVIDIA Corporation is
27// strictly prohibited.
28//
30#ifndef DWFRAMEWORK_DWNODES_SENSORS_DWSENSORNODE_DWCHANNELDRAINERTEMPLATE_HPP_
31#define DWFRAMEWORK_DWNODES_SENSORS_DWSENSORNODE_DWCHANNELDRAINERTEMPLATE_HPP_
32
44#include <dw/core/base/Types.h>
45#include <dw/sensors/Sensors.h>
46#include <dw/sensors/canbus/CAN.h>
47#include <dw/sensors/radar/Radar.h>
48#include <dwcgf/Exception.hpp>
49#include <dwcgf/node/Node.hpp>
50#include <dwcgf/port/Port.hpp>
51#include <memory>
52#include <unistd.h>
53
54namespace dw
55{
56namespace framework
57{
58
59template <typename OutputProcessedDataType, typename InputProcessedDataType = OutputProcessedDataType>
61{
63 std::shared_ptr<InputProcessedDataType> m_nextDataEvent = nullptr;
64
65 virtual dwStatus readNextData(dwTime_t inTimeout_us, InputDataPort inputPort)
66 {
67
68 if (!inputPort->isBound())
69 {
70 return DW_NOT_AVAILABLE;
71 }
72
73 if (inputPort->wait(inTimeout_us) == DW_SUCCESS)
74 {
75 m_nextDataEvent = inputPort->recv();
76 return DW_SUCCESS;
77 }
78
79 return DW_TIME_OUT;
80 }
81
82 virtual dwStatus getNextDataTimestamp(dwTime_t& outTimestamp) = 0;
83
84 virtual dwStatus getNextData(OutputProcessedDataType* outDataFrame, InputDataPort) = 0;
85
86 dwStatus reset()
87 {
88 m_nextDataEvent = nullptr;
89 return DW_SUCCESS;
90 }
91};
92
93template <typename OutputProcessedDataType, typename ReadProcessedDataFunc, typename InputProcessedDataType = OutputProcessedDataType>
94class dwChannelDrainerTemplate : public dwBaseDrainerTemplate<OutputProcessedDataType, ReadProcessedDataFunc, PortInput<InputProcessedDataType>*>
95{
97
98public:
99 static constexpr char LOG_TAG[] = "dwChannelDrainerTemplate";
100
101 explicit dwChannelDrainerTemplate(dwSensorDrainerParams params, std::unique_ptr<ReadProcessedDataFunc> readProcessedDataFunc, InputDataPort inputPort)
102 : dwBaseDrainerTemplate<OutputProcessedDataType, ReadProcessedDataFunc, InputDataPort>(params, std::move(readProcessedDataFunc), inputPort)
103 {
104 }
105
106 virtual ~dwChannelDrainerTemplate() = default;
107
108 virtual dwStatus reset() override
109 {
110 this->m_virtualSyncTime = 0;
111 this->m_nextDataReady = false;
112 return DW_SUCCESS;
113 }
114
115 // [out] outFrame output sensor frame
116 // [in/out] latestTimestamp timestamp associated with the sensor frame
117 // [in] timeout sensor reading timeout in microseconds
118 // [in] isDroppingData indicates if data is being dropped
119 dwStatus readProcessedData(OutputProcessedDataType* outFrame,
120 dwTime_t& latestTimestamp,
121 dwTime_t timeout,
122 bool isDroppingData = false) override
123 {
124 return dwBaseDrainerTemplate<OutputProcessedDataType, ReadProcessedDataFunc, InputDataPort>::tryRead(outFrame, latestTimestamp, timeout, isDroppingData);
125 }
126};
127
128template <typename OutputProcessedDataType, typename ReadProcessedDataFunc, typename InputProcessedDataType>
130} // namespace framework
131} // namespace dw
132
133#endif // DWFRAMEWORK_DWNODES_SENSORS_DWSENSORNODE_DWCHANNELDRAINERTEMPLATE_HPP_
virtual std::shared_ptr< T > recv()
Definition: Port.hpp:421
dwStatus wait(dwTime_t timeout)
Definition: Port.hpp:387
bool isBound() override
Definition: Port.hpp:372
virtual dwStatus tryRead(ProcessedDataType *outFrame, dwTime_t &latestTimestamp, dwTime_t timeout, bool isDroppingData=false)
dwStatus readProcessedData(OutputProcessedDataType *outFrame, dwTime_t &latestTimestamp, dwTime_t timeout, bool isDroppingData=false) override
dwChannelDrainerTemplate(dwSensorDrainerParams params, std::unique_ptr< ReadProcessedDataFunc > readProcessedDataFunc, InputDataPort inputPort)
Definition: Buffer.hpp:40
virtual dwStatus getNextDataTimestamp(dwTime_t &outTimestamp)=0
virtual dwStatus readNextData(dwTime_t inTimeout_us, InputDataPort inputPort)
std::shared_ptr< InputProcessedDataType > m_nextDataEvent
virtual dwStatus getNextData(OutputProcessedDataType *outDataFrame, InputDataPort)=0