DriveWorks SDK Reference
3.5.78 Release
For Test and Development only

sensors/canbus/docs/usecase2.md
Go to the documentation of this file.
1 # Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved.
2 
3 @page canbus_usecase2 Reading CAN Messages from Raw Data (Binary)
4 
5 @note SW Release Applicability: This tutorial is applicable to modules in both **NVIDIA DriveWorks** and **NVIDIA DRIVE Software** releases.
6 
7 The `dwSensorCAN_processRawData()` and `dwSensorCAN_popMessage()` functions
8 can be used to parse raw can bus data and read the messages in the
9 `dwCANMessage` format.
10 
11 For details on the CAN sensor module workflow, see @ref canbus_usecase1.
12 
13 #### Example
14 
15 The following code shows the general structure of a program reading raw
16 data from the can bus, serializing it and parsing it.
17 
18 ```{.cpp}
19 dwSensorHandle_t canSensor;
20 dwSAL_createSensor(&canSensor, ..., ...);
21 
22 dwSensor_start(canSensor);
23 
24 const uint8_t *data = nullptr;
25 size_t size = 0;
26 
27 while(loop)
28 {
29  dwStatus status = DW_NOT_READY;
30 
31  while (status == DW_NOT_READY)
32  {
33  dwSensor_readRawData(&data, &size, 1000000, canSensor);
34 
35  status = dwSensorCAN_processRawData(data, size, canSensor);
36 
37  dwSensorSerializer_serializeDataAsync(data, size, ...);
38 
39  dwSensor_returnRawData(data, canSensor);
40  }
41 
42  dwCANMessage message{};
43  dwSensorCAN_popMessage(&frame, canSensor);
44 
45  ...
46 }
47 
48 dwSensor_stop(canSensor);
49 dwSAL_releaseSensor(&canSensor);
50 ```
51 
52 For more details see @ref dwx_record_sample