DriveWorks SDK Reference
3.5.78 Release
For Test and Development only

sensors/plugins/canbus/docs/canbus_fullsensor.md
Go to the documentation of this file.
1 # Copyright (c) 2019-2020 NVIDIA CORPORATION. All rights reserved.
2 
3 @page sensorplugins_canbussensor Custom CANs (Comprehensive)
4 @tableofcontents
5 
6 @note SW Release Applicability: This tutorial is applicable to modules in both **NVIDIA DriveWorks** and **NVIDIA DRIVE Software** releases.
7 
8 @section sensorplugins_canbussensor_comm Introduction
9 
10 The Comprehensive Plugin Framework for CAN sensors allows third parties to interface with
11 custom sensor using a shared object (.so) containing their sensor driver implementation.
12 
13 The CAN may use any available interface to communicate with NVIDIA DRIVE™ AGX as the plugin
14 fully implements the communication channel.
15 
16 @section sensorplugins_canbussensor_impl Plugin Implementation
17 
18 The plugin framework defines a set of function pointer definitions which must be
19 implemented and exported to the SAL. For CAN sensors, the plugin must have implementation
20 for the function pointers defined in:
21 
22 * @ref sensor_plugins_ext_common_group.
23 * @ref sensor_plugins_ext_canbus_group.
24 
25 In addition, the plugin must implement & export the function, `dwSensorCANPlugin_getFunctionTable()`,
26 which is the only C function that needs to be exposed from the shared object.
27 This allows the developer flexibility to implement internals of their plugin in C++, if necessary.
28 
29 @section sensorplugins_canbussensor_interface Plugin Interfaces
30 
31 This section does not substitute the API specification, but attempts to give a high-level overview
32 of how implemented plugin functions will be exercised by SAL.
33 
34 @subsection sensorplugins_canbussensor_interface_init Initialization
35 
36 For the purpose of creation, DriveWorks sensors are specified by `dwSensorParams`,
37 which contains a protocol and parameter string for the sensor to be created.
38 
39 For custom CANs, the protocol and parameter string will be as follows:
40 
41  params: decoder-path=<path_to_so>[,<custom params>]
42 
43 At initialization, a user's call to `dwSensor_create()` will lead to SAL
44 dynamically loading the plugin library via `dlopen()`.
45 SAL will then make the following call to your plugin:
46 
47 | # | Function Call | Purpose |
48 | - | ------------- | ------- |
49 | 1 | `dwSensorPlugin_createHandle()` | Initialize a context for this sensor (allocate resources, etc.) |
50 
51 After the call to `dwSensorPlugin_createHandle` the plugin should be ready.
52 
53 @subsection sensorplugins_canbussensor_interface_constants Sensor Creation
54 
55 The plugin framework provides a specific entrypoint to initialize the control-plane /
56 transport layer with the sensor. For this, SAL will make the following calls to your plugin:
57 
58 | # | Function Call | Purpose |
59 | - | ------------- | ------- |
60 | 1 | `dwSensorPlugin_createSensor()` | Initialization of communication & transport plane with the sensor |
61 
62 It is up to the developer to decide what actions need to be taken during this call.
63 The sensor plugin is not expected to serve data until the sensor is started.
64 
65 @note This section only applies for live sensors, and is skipped for virtual sensors
66 
67 @subsection sensorplugins_canbussensor_interface_lifecycle Sensor Lifecycle
68 
69 After sensor creation and initialization, DriveWorks provides a set of
70 @ref sensors_usecase1 user APIs.
71 
72 These have a 1:1 mapping to plugin entrypoints, and their purpose is
73 self-explanatory:
74 
75 | DriveWorks User API | Plugin API |
76 | ------------------- | ---------- |
77 | `dwSensor_start()` | `dwSensorPlugin_start()` |
78 | `dwSensor_stop()` | `dwSensorPlugin_stop()` |
79 | `dwSAL_releaseSensor()` | `dwSensorPlugin_reset()` |
80 
81 Before querying the plugin for raw data, SAL will make a call
82 to start the sensor.
83 
84 @subsection sensorplugins_canbussensor_interface_rawdata Raw Data Gathering
85 
86 From its communication plane, the sensor plugin is responsible for gathering
87 raw data from the device. Once the sensor has been started via a
88 `dwSensorPlugin_start()` call, SAL will make the following calls to your plugin:
89 
90 | # | Function Call | Purpose |
91 | - | ------------- | ------- |
92 | 1 | `dwSensorPlugin_readRawData()` | Provide raw data for a single sensor message as a byte array |
93 | 2 | `dwSensorPlugin_returnRawData()` | Returns raw data previously acquired |
94 
95 We recommend the following format for the data that is returned:
96 
97  ------------------------- Header -----------------------
98  [Payload Size (uint32_t)][Timestamp (dwTime_t)][Payload]
99 
100 @note There may be multiple calls to `dwSensorPlugin_readRawData()` before a call to
101 `dwSensorPlugin_returnRawData()`. The plugin is responsible for memory management of this
102 raw buffer; an example of a refcounted buffer pool is provided as sample code.
103 
104 @note This section only applies for live sensors, and is skipped for virtual sensors
105 
106 @subsection sensorplugins_canbussensor_interface_filter Filter
107 
108 Specifes a set of CAN IDs to be filtered.
109 
110 In order to set filtering on CAN IDs to be processed, SAL will
111 make the following calls to your plugin:
112 
113 | # | Function Call | Purpose |
114 | - | ------------- | ------- |
115 | ? | `dwSensorCANPlugin_clearFilter()` | Clear previously set filters |
116 | ? | `dwSensorCANPlugin_setFilter()` | Set filters |
117 
118 @subsection sensorplugins_canbussensor_interface_send Send
119 
120 Sends a message over the CAN bus within a specified timeout.
121 
122 In order to send message over the CAN bus, SAL will make the
123 following calls to your plugin:
124 
125 | # | Function Call | Purpose |
126 | - | ------------- | ------- |
127 | ? | `dwSensorCANPlugin_send()` | Send message over CAN |
128 
129 @subsection sensorplugins_canbussensor_interface_setUseHwTimestamps TimeStamps
130 
131 Enables or disables hardware timestamp of the CAN messages.
132 
133 In order to enable or disable hardware timestamp, SAL will make the
134 following calls to your plugin:
135 
136 | # | Function Call | Purpose |
137 | - | ------------- | ------- |
138 | ? | `dwSensorCANPlugin_setUseHwTimestamps()` | Enables or disables hardware timestamp |
139 
140 @section sensorplugins_canbussensor_example Example
141 
142 See @ref dwx_canbus_plugin_sample.