1 # Copyright (c) 2019-2020 NVIDIA CORPORATION. All rights reserved.
3 @page dwx_canbus_message_sample CAN Message Interpreter Sample
6 @note SW Release Applicability: This sample is available in both **NVIDIA DriveWorks** and **NVIDIA DRIVE Software** releases.
8 @section dwx_canbus_message_sample_description Description
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.
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>™</sup> platforms.
21 Use this sample application with:
23 - Virtual CAN bus defined in NVIDIA<sup>®</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>™</sup> platforms (see @ref dwx_canbus_logger_sample for Aurix based parameters)
26 - Real CAN device, on Linux or QNX
28 @section dwx_canbus_message_sample_running Running the Sample
30 The CAN Message Interpreter sample, sample_canbus_interpreter, accepts the following parameters:
32 ./sample_canbus_interpreter --driver=[can.virtual|can.socket|can.aurix]
33 --dbc=[path/to/dbc/file]
34 --params=[comma/separated/key/value/pairs]
38 --driver=[can.virtual|can.socket|can.aurix]
39 Allows to specify which CAN interface to use.
40 Devault value: can.virtual
42 --dbc=[path/to/dbc/file]
44 Default value: /path/to/data/samples/sensors/can/sample.dbc
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
50 @note For a full list of key/value pairs that can be passed to --params see @ref dwx_sensor_enum_sample .
52 @subsection dwx_canbus_message_sample_examples Examples
54 #### Offline CAN Messages
56 ./sample_canbus_interpreter
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`.
62 The output on the console is the car steering and speed. For example:
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]
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
73 ./sample_canbus_interpreter --dbc=user_path_to/file.dbc
75 #### Callback-based "plugin" interpreter
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
81 ./sample_canbus_interpreter --dbc=plugin
83 #### Virtual CAN Bus on Linux
85 ./sample_canbus_interpreter --driver=can.socket --params=device=vcan0
87 Run it with a virtual CAN device created with:
90 $ sudo ip link add dev vcan0 type vcan
91 $ sudo ip link set up vcan0
93 To send data from the console to the virtual CAN bus, run `cansend` (from the
96 $ cansend vcan0 100#fa490200
97 $ cansend vcan0 200#2e920300
99 This sends a CAN message with the CAN ID and 2 bytes of data, containing: 0x11,
102 The output is similar to:
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]
107 @note the virtual CAN interface is not available on QNX
109 #### Real CAN Device on Linux
111 $ ./sample_canbus_interpreter --driver=can.socket --params=device=can0
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:
116 $ sudo ip link set can0 type can bitrate 500000
117 $ sudo ip link set can0 up
119 @note the steps above are not needed on QNX
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).
128 On NVIDIA DRIVE<sup>™</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
132 @section dwx_canbus_message_sample_output Output
134 The sample prints on console the interpreted CAN messages
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]
154 @section dwx_canbus_message_sample_more Additional Information
156 For more details see @ref canbus_mainsection.