DriveWorks SDK Reference
3.5.78 Release
For Test and Development only

/dvs/git/dirty/gitlab-master_av/dw/sdk/samples/sensors/canbus/interpreter/README.md
Go to the documentation of this file.
1 # Copyright (c) 2019-2020 NVIDIA CORPORATION. All rights reserved.
2 
3 @page dwx_canbus_message_sample CAN Message Interpreter Sample
4 @tableofcontents
5 
6 @note SW Release Applicability: This sample is available in both **NVIDIA DriveWorks** and **NVIDIA DRIVE Software** releases.
7 
8 @section dwx_canbus_message_sample_description Description
9 
10 The CAN Message Interpreter sample is a simple CAN bus interpreter sample.
11 An interpreter is built based either on the definition in a DBC file or
12 a set of user-provided callbacks and input CAN messages are then decoded
13 by the interpreter. In this sample, information about car steering and
14 speed is transmitted in CAN messages, and the sample decodes and displays
15 all received CAN messages. By default, the sample demonstrates the usage
16 with virtual CAN, using an offline message file.
17 
18 You may also set the input arguments for real CAN message input (e.g., can0 or
19 vcan0) on Linux desktop or can.aurix on NVIDIA DRIVE<sup>&trade;</sup> platforms.
20 
21 Use this sample application with:
22 
23 - Virtual CAN bus defined in NVIDIA<sup>&reg;</sup> DriveWorks with offline binary CAN message files
24 - Virtual CAN bus defined by SocketCAN on Linux
25 - Aurix CAN bus on NVIDIA DRIVE<sup>&trade;</sup> platforms (see @ref dwx_canbus_logger_sample for Aurix based parameters)
26 - Real CAN device, on Linux or QNX
27 
28 @section dwx_canbus_message_sample_running Running the Sample
29 
30 The CAN Message Interpreter sample, sample_canbus_interpreter, accepts the following parameters:
31 
32  ./sample_canbus_interpreter --driver=[can.virtual|can.socket|can.aurix]
33  --dbc=[path/to/dbc/file]
34  --params=[comma/separated/key/value/pairs]
35 
36 Where:
37 
38  --driver=[can.virtual|can.socket|can.aurix]
39  Allows to specify which CAN interface to use.
40  Devault value: can.virtual
41 
42  --dbc=[path/to/dbc/file]
43  Location of DBC file.
44  Default value: /path/to/data/samples/sensors/can/sample.dbc
45 
46  --params=[comma/separated/key/value/pairs]
47  Different parameters are available for each CAN driver.
48  Default value: file=path/to/data/samples/sensors/can/canbus_dbc.can
49 
50 @note For a full list of key/value pairs that can be passed to --params see @ref dwx_sensor_enum_sample .
51 
52 @subsection dwx_canbus_message_sample_examples Examples
53 
54 #### Offline CAN Messages
55 
56  ./sample_canbus_interpreter
57 
58 By default, the sample reads `data/samples/sensors/can/sample.dbc` to build the
59 interpreter, and opens a virtual CAN bus with messages defined in
60 `data/samples/sensors/can/canbus_dbc.can`.
61 
62 The output on the console is the car steering and speed. For example:
63 
64  5662312708 [0x100] -> 0x9d 0xfe Car steering -0.0221875 rad at [5662312708]
65  5662312708 [0x200] -> 0x1f 0x21 Car speed 8.479 m/s at [5662312708]
66 
67 #### DBC interpreter
68 
69 The sample can be used with a DBC file provided by the user. In order to start
70 interpreter sample using user provided DBC file, pass `--dbc` parameter to the
71 application:
72 
73  ./sample_canbus_interpreter --dbc=user_path_to/file.dbc
74 
75 #### Callback-based "plugin" interpreter
76 
77 The sample can be used with an interpreter using user-provided callbacks. In order
78 to start the callback-based interpreter, pass `--dbc=plugin` as parameter to the
79 application
80 
81  ./sample_canbus_interpreter --dbc=plugin
82 
83 #### Virtual CAN Bus on Linux
84 
85  ./sample_canbus_interpreter --driver=can.socket --params=device=vcan0
86 
87 Run it with a virtual CAN device created with:
88 
89  $ sudo modprobe vcan
90  $ sudo ip link add dev vcan0 type vcan
91  $ sudo ip link set up vcan0
92 
93 To send data from the console to the virtual CAN bus, run `cansend` (from the
94 `can-utils` package):
95 
96  $ cansend vcan0 100#fa490200
97  $ cansend vcan0 200#2e920300
98 
99 This sends a CAN message with the CAN ID and 2 bytes of data, containing: 0x11,
100 0x22
101 
102 The output is similar to:
103 
104  44798857 [0x100] -> 0xfa 0x49 0x2 0x0 Car steering 0.0937563 rad at [44798857]
105  64318678 [0x200] -> 0x2e 0x92 0x3 0x0 Car speed 2.3403 m/s at [64318678]
106 
107 @note the virtual CAN interface is not available on QNX
108 
109 #### Real CAN Device on Linux
110 
111  $ ./sample_canbus_interpreter --driver=can.socket --params=device=can0
112 
113 A valid SocketCAN device must be present in the system as canX. For example, a
114 PCAN USB. The bitrate is set to 500 KB. Set the bitrate on the CAN device:
115 
116  $ sudo ip link set can0 type can bitrate 500000
117  $ sudo ip link set can0 up
118 
119 @note the steps above are not needed on QNX
120 
121 The CAN interface used to listen on a real CAN bus must have SocketCAN driver
122 implementation in the system. A SocketCAN based driver can be identified easily
123 if `:> sudo ifconfig -a` returns the default network interfaces **and** a CAN
124 based interface (i.e., canX, slcanX, etc).
125 
126 ##### AurixCAN
127 
128 On NVIDIA DRIVE<sup>&trade;</sup> platforms, CAN messages can be sent and received by the Xaviers through Aurix.
129 For further information how to setup the sample to run with AurixCAN see @ref dwx_canbus_logger_sample_description
130 
131 
132 @section dwx_canbus_message_sample_output Output
133 
134 The sample prints on console the interpreted CAN messages
135 
136  5652171936 [0x100] -> 0x7e 0xbb 0x2 0x0 Car steering 0.111919 rad at [5652171936]
137  5652171936 [0x200] -> 0x80 0x57 0x2 0x0 Car speed 1.53472 m/s at [5652171936]
138  5652174567 [0x100] -> 0xa0 0xc1 0x2 0x0 Car steering 0.1129 rad at [5652174567]
139  5652174567 [0x200] -> 0x80 0x57 0x2 0x0 Car speed 1.53472 m/s at [5652174567]
140  5652177205 [0x100] -> 0xa0 0xc1 0x2 0x0 Car steering 0.1129 rad at [5652177205]
141  5652177205 [0x200] -> 0x80 0x57 0x2 0x0 Car speed 1.53472 m/s at [5652177205]
142  5652179850 [0x100] -> 0xa0 0xc1 0x2 0x0 Car steering 0.1129 rad at [5652179850]
143  5652179850 [0x200] -> 0x80 0x57 0x2 0x0 Car speed 1.53472 m/s at [5652179850]
144  5652182733 [0x100] -> 0xa0 0xc1 0x2 0x0 Car steering 0.1129 rad at [5652182733]
145  5652182733 [0x200] -> 0x80 0x57 0x2 0x0 Car speed 1.53472 m/s at [5652182733]
146  5652185391 [0x100] -> 0x2 0xc9 0x2 0x0 Car steering 0.114081 rad at [5652185391]
147  5652185391 [0x200] -> 0x10 0x65 0x2 0x0 Car speed 1.56944 m/s at [5652185391]
148  5652187984 [0x100] -> 0x2 0xc9 0x2 0x0 Car steering 0.114081 rad at [5652187984]
149  5652187984 [0x200] -> 0x10 0x65 0x2 0x0 Car speed 1.56944 m/s at [5652187984]
150  5652190645 [0x100] -> 0x2 0xc9 0x2 0x0 Car steering 0.114081 rad at [5652190645]
151  5652190645 [0x200] -> 0x10 0x65 0x2 0x0 Car speed 1.56944 m/s at [5652190645]
152  5652193322 [0x100] -> 0x2 0xc9 0x2 0x0 Car steering 0.114081 rad at [5652193322]
153 
154 @section dwx_canbus_message_sample_more Additional Information
155 
156 For more details see @ref canbus_mainsection.