You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+64-19Lines changed: 64 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,21 @@ This project provides a C++ library that reads and parses [CAN](https://en.wikip
4
4
5
5
Currently the library only understand a subset of the DBC file format.
6
6
7
+
**How robust and efficient is this library ?**
8
+
9
+
C++ CAN Parser is an open-source project based on my work. The library is currently used in a robust
10
+
industrial-grade pipeline. The few test files that I gathered in the tests/dbc-files/ directory are
11
+
inspired by in-use CAN databases of several automotive industrial companies. So you can safely include
12
+
this library into your own pipeline or CAN-based software.
13
+
14
+
C++ CAN Parser can be useful for building:
15
+
* CAN sniffers
16
+
* Static file generation (such as the [Auto-Generated Code on the SJ-One Board](http://socialledge.com/sjsu/index.php/DBC_Format#Auto-Generated_Code))
17
+
* TCP-to-CAN and CAN-to-TCP middlewares
18
+
* ...
19
+
20
+
`can-parse` is a tool that analyzes a CAN database and proposes different operations. You can use it to inspect all or part of the database. `can-parse printframe CAN_ID` notably give detailed and structured information about the layout of a frame. Check out [the dedicated section](#can-parse) for more info.
21
+
7
22
Table of Contents
8
23
=================
9
24
@@ -17,23 +32,13 @@ Table of Contents
17
32
-[`CANSignal`](#cansignal)
18
33
-[`CANFrame`](#canframe)
19
34
-[`CANDatabase`](#candatabase)
35
+
-[Database analysis](#database-analysis)
20
36
-[can-parse](#can-parse)
21
37
-[Supported standards](#supported-standards)
22
38
23
39
Compile and include the library
24
40
===============================
25
41
26
-
## The public headers
27
-
28
-
You need to put the public headers in an appropriate place:
29
-
30
-
```
31
-
your_project/
32
-
|_ src/
33
-
|_ include/
34
-
|_ cpp-can-parser/ # <-- Put here the public headers
35
-
```
36
-
37
42
## Compilation
38
43
39
44
cpp-can-parser is not a header-only library. I recommand CMake to include the library into your project:
@@ -69,15 +74,15 @@ The main feature of the library is the possibility of parsing a file representin
69
74
70
75
```c++
71
76
#include<iostream>
72
-
#include"cpp-can-parser/CANDatabase.h"
77
+
#include<cpp-can-parser/CANDatabase.h>
73
78
74
79
intmain(int argc, char** argv) {
75
80
try {
76
-
CANDatabase db = CANDatabase::fromFile(argv[1]);
81
+
CppCAN::CANDatabase db = CppCAN::CANDatabase::fromFile(argv[1]);
77
82
78
83
// ...
79
84
}
80
-
catch(const CANDatabaseException& e) {
85
+
catch(const CppCAN::CANDatabaseException& e) {
81
86
std::cerr << "Error: " << e.what();
82
87
return 1;
83
88
}
@@ -86,10 +91,11 @@ int main(int argc, char** argv) {
86
91
}
87
92
```
88
93
89
-
One can see that `CANDatabase::fromFile()` can throw a CANDatabaseException. This happens when the parsing goes wrong (basically when the given file does not exist or when there is a syntax error). `CANDatabaseException::what()` will give you details on the error.
94
+
One can see that `CppCAN::CANDatabase::fromFile()` can throw a CANDatabaseException. This happens when the parsing goes wrong (basically when the given file does not exist or when there is a syntax error). `CppCAN::CANDatabaseException::what()` will give you details on the error.
90
95
91
-
If the data that you are using does not come from a file, it is also possible to use `CANDatabase::fromString("...")` which behaves just like its counterpart.
96
+
If the data that you are using does not come from a file, it is also possible to use `CppCAN::CANDatabase::fromString("...")` which behaves just like its counterpart.
92
97
98
+
*Note that one can construct its own database without parsing a file by diretly manipulating the reevant objects. See the next section for mmore info.*
93
99
94
100
How to use the database
95
101
=======================
@@ -128,17 +134,21 @@ Here are the most important properties of a `CANFrame` instance:
128
134
* `comment()` : gives the registered comment (if any)
129
135
* more properties to behave like a "standard container"
130
136
131
-
Use `begin()`/`end()` and!/or a ranged-based for loop to iterate through the signals of the frame.
137
+
Use `begin()`/`end()` and/or a ranged-based for loop to iterate through the signals of the frame.
132
138
133
139
```c++
134
-
const CANFrame& frame = ...;
140
+
const CppCAN::CANFrame& frame = ...;
135
141
136
142
// Print the name of all the frames by increasing order
C++ CAN Parser provides functions to analyze the coherence of a CAN Database. All the functtions are regrouped into the namespace `CppCAN::analysis`. They are notably used by `can-parse` and its *CHECKFRAME* operations.
175
+
176
+
*`bool CppCAN::analysis::is_frame_layout_ok(const CppCAN::CANFrame&)`: returns true if the layout of the CANFrame is correct. An overload exists which gives a list of all the problematic signals. Check `CANDatabaseAnalysis.h` for more details.
177
+
*`void CppCAN::analysis::assert_frame_layout(const CppCAN::CANFrame&)`: same as `is_frame_layout_ok()` but throws a `CANDatabaseException` is the layout is invalid.
178
+
179
+
You must include `cpp-can-parser/CANDatabaseAnalysis.h` to access these functions.
0 commit comments