1 # Copyright (c) 2018-2020 NVIDIA CORPORATION. All rights reserved.
3 @page dwx_canbus_logger_sample CAN Message Logger Sample
6 @note SW Release Applicability: This sample is available in both **NVIDIA DriveWorks** and **NVIDIA DRIVE Software** releases.
8 @section dwx_canbus_logger_sample_description Description
10 The CAN Message Logger sample is a simple CAN bus listener sample. All
11 messages received over the CAN bus are printed on the console. A valid SocketCAN
12 or AurixCAN device must be present in the system. Please refer to your platform
13 datasheet for a description of the available CAN devices and the corresponding
16 @section dwx_canbus_logger_sample_running Running the sample
18 The CAN Message Logger sample, sample_canbus_logger, accepts the following parameters:
20 ./sample_canbus_logger --driver=[can.virtual|can.socket|can.aurix|can.custom]
21 --params=[comma/separated/key/value/pairs]
22 --filter=[id1:mask1+id2:mask2+..]
24 --send_i_understand_implications=[timeout]
25 --send_id=[message_ID]
30 --driver=[can.virtual|can.socket|can.aurix|can.custom]
31 Allows to specify which CAN interface to use.
32 Default value: can.virtual
34 --params=[comma/separated/key/value/pairs]
35 Different parameters are available for each CAN driver.
36 Default value: file=path/to/data/samples/sfm/triangulation/canbus.can
38 --filter=[id1:mask1+id2:mask2+..]
39 The sample provides support to filter (i.e., pass) messages of certain IDs. A
40 filter can be specified by adding `+` separated `id:mask` values to the
41 `--filter=` argument. A message is considered passing if `<received_can_id> &
43 Example 1 - pass all messages between 201-2FF: `--filter=200:F00`
44 Example 2 - pass only 100,110 and 301-31F: `--filter=100:FFF+110:FFF+300:FE0`
45 Example 3 - Empty filter. Pass all messages: `--filter=000:000`
46 Default value: "" : No filter is applied. Note that filters may still be applied during initilization by `params` messages.
49 DriveWorks supports hardware timestamps of the CAN messages. Xavier provides a hardware-based counter
50 timestamps all CAN messages on arrival directly on the SoC. For the case of AurixCAN,
51 the messages are timestamped by Aurix on arrival and passed together with the CAN messages over UDP
52 to DriveWorks. In order for hardware timestamps to work for SocketCAN, the application must run with
56 --send_i_understand_implications=[timeout]
57 Allows to generate a random CAN message each timeout ms
58 Note that sending might interfere with real hardware; therefore, only
59 use it if you know what you are doing.
62 --send_id=[message_ID]
63 Allows to send message with a custom ID.
64 This is only applicable if --send_i_understand_implications is not 0.
68 What size message should be sent.
69 This is only applicable if --send_i_understand_implications is not 0.
70 This results in sending non CAN FD messages if size is 0-8 and sending CAN FD messages if greater than 8.
74 @note For a full list of key/value pairs that can be passed to --params see @ref dwx_sensor_enum_sample .
76 @subsection dwx_canbus_logger_sample_examples Examples
78 #### Run with a Virtual CAN Device
80 Test the applications using either a real CAN device or a virtual one. Create a
81 virtual device using the following commands:
84 sudo ip link add dev vcan0 type vcan
85 sudo ip link set vcan0 mtu 72 # if want to use Can-FD mode
86 sudo ip link set up vcan0
88 In order to send data from the console to the virtual CAN bus, use the `cansend`
89 tool (from the `can-utils` package).
91 cansend vcan0 30B#1122334455667788
93 This example sends a CAN message with ID 0x30B and with 8-bytes containing:
96 If using the virtual CAN interface, the sample can be started with
97 `--driver=can.socket --params=device=vcan0` to listen on the virtual CAN
98 interface. Any message sent with `cansend vcan0` is displayed on the console.
100 @note the virtual CAN interface is not available on QNX
102 #### Run with Real Hardware
104 If using real-hardware connected to the CAN bus, set the bitrate to 500 KB in
105 order to test the sample. The sample does not support changing of the bitrate.
106 Set the bitrate on the CAN device by executing:
108 sudo ip link set can0 type can bitrate 500000
109 sudo ip link set can0 up
111 @note the steps above are not needed on QNX
113 The CAN interface used to listen on a real CAN bus must have SocketCAN driver
114 implementation in the system. A SocketCAN based driver can be identified easily
115 if `:> sudo ifconfig -a` returns the default network interfaces **and** a CAN
116 based interface (i.e., canX, slcanX, etc).
119 @note the virtual CAN interface is not available on QNX
124 To execute the sample to listen on the SocketCAN connectors, use:
126 --driver=can.socket --params=device=can0
130 On NVIDIA DRIVE<sup>™</sup> platforms, CAN messages can be sent and received by the Xaviers through Aurix.
131 For this to work, a proper setup of the Aurix needs to be made prior to running the application.
132 In order to connect to AurixCAN, use the following arguments:
134 ###### For driveworks 3.5 and above (Aurix version 4.0 and above)
135 --driver=can.aurix --params=ip=10.42.0.146,inIDMap=1:0x106+2:0x206,outIDMap=0x105:17+0x205:18
137 Where `ip` is the IP address from which the CAN messages are forwarded and `inIDMap/outIDMap` defines the mapping between PDU ID and CAN ID as defined by the security model of Aurix CAN. It has to match to the compiled into the Aurix security model. Please refer to the PDK documentation for more information about Aurix CAN security model.
139 ###### For driveworks 3.0 and below (Aurix version 3.X and below)
140 --driver=can.aurix --params=ip=10.42.0.146,bus=a,config-file=/path/to/EasyCanConfigFile.conf
142 Where `ip` is the IP address from which the CAN messages are forwarded, `bus`
143 points to the corresponding CAN bus connector, i.e., CAN-1->a, ..., CAN-4->d, and `config-file`
144 points to an EasyCAN configuration file. Please refer to the EasyCAN user guide provided as part of PDK documentation
145 to set up Aurix to filter and pass a selected subset of CAN messages.
146 An example file is provided in the DriveWorks data folder,
147 under /path/to/data/samples/sensors/can. Refer to the DriveWorks CAN bus documentation for more
148 details on this file.
150 The connection to AurixCAN happens using UDP sockets. Additional arguments for the remote (`aport`) and
151 local (`bport`) UDP port can be specified if AurixCAN is working in a non-default configuration. By
152 default, on DRIVE AGX, AurixCAN is reachable over `aport=50000` and communicates with the Xavier over `bport=60395`.
156 Additionally, the sample can be used as a CAN message generator:
158 ./sample_canbus_logger --send_i_understand_implications=100
160 in this case it generates a random CAN message each 100ms.
161 Note that sending might interfere with real hardware; therefore, only
162 use it if you know what you are doing.
164 @section dwx_canbus_logger_sample_output Output
166 The sample prints on console the received CAN messages:
168 5651471936 -> 100 [5] 7E BB 02 00 00
169 5651471936 (dt=0) -> 200 [5] 80 57 02 00 00
170 5651474567 (dt=2631) -> 100 [5] A0 C1 02 00 00
171 5651474567 (dt=0) -> 200 [5] 80 57 02 00 00
172 5651477205 (dt=2638) -> 100 [5] A0 C1 02 00 00
173 5651477205 (dt=0) -> 200 [5] 80 57 02 00 00
174 5651479850 (dt=2645) -> 100 [5] A0 C1 02 00 00
175 5651479850 (dt=0) -> 200 [5] 80 57 02 00 00
176 5651482733 (dt=2883) -> 100 [5] A0 C1 02 00 00
177 5651482733 (dt=0) -> 200 [5] 80 57 02 00 00
178 5651485391 (dt=2658) -> 100 [5] 02 C9 02 00 00
179 5651485391 (dt=0) -> 200 [5] 11 65 02 00 00
180 5651487984 (dt=2593) -> 100 [5] 02 C9 02 00 00
181 5651487984 (dt=0) -> 200 [5] 11 65 02 00 00
182 5651490645 (dt=2661) -> 100 [5] 02 C9 02 00 00
183 5651490645 (dt=0) -> 200 [5] 11 65 02 00 00
184 5651493322 (dt=2677) -> 100 [5] 02 C9 02 00 00
185 5651493322 (dt=0) -> 200 [5] 11 65 02 00 00
186 5651496024 (dt=2702) -> 100 [5] 5A D0 02 00 00
187 5651496024 (dt=0) -> 200 [5] 11 65 02 00 00
188 5651498602 (dt=2578) -> 100 [5] 5A D0 02 00 00
189 5651498602 (dt=0) -> 200 [5] 11 65 02 00 00
190 5651501306 (dt=2704) -> 100 [5] 5A D0 02 00 00
191 5651501306 (dt=0) -> 200 [5] 11 65 02 00 00
192 5651504039 (dt=2733) -> 100 [5] 5A D0 02 00 00
193 5651504039 (dt=0) -> 200 [5] 11 65 02 00 00
194 5651506639 (dt=2600) -> 100 [5] 7C D6 02 00 00
196 @section dwx_canbus_logger_sample_more Additional Information
198 For more details see @ref canbus_mainsection .