1
- #include " CANDatabaseAnalysis.h"
2
- #include " CANDatabase.h"
1
+ #include " cpp-can-parser/ CANDatabaseAnalysis.h"
2
+ #include " cpp-can-parser/ CANDatabase.h"
3
3
#include < algorithm>
4
4
#include < cmath>
5
5
#include < tuple>
@@ -48,28 +48,28 @@ struct SignalLayoutEntry {
48
48
49
49
SignalRanges big_endian_ranges (const CANSignal& src) {
50
50
SignalRanges result;
51
-
52
- // For BigEndian signals, the start bit already represents the left mostbit
51
+
52
+ // For BigEndian signals, the start bit already represents the left mostbit
53
53
// ----------------- -----------------
54
54
// |*|*|*|*|*|*|*|*| |*|*|*|*|*|*|*|*|
55
55
// ----------------- -----------------
56
56
// 7 0 15 8
57
-
57
+
58
58
unsigned bitsLeft = src.length ();
59
59
unsigned currentPos = src.start_bit ();
60
-
60
+
61
61
for (unsigned current_byte = src.start_bit () / 8 ; bitsLeft > 0 ; current_byte++) {
62
62
char lbit = currentPos % 8 ;
63
63
char rbit = std::max<char >(-1 , lbit - bitsLeft);
64
64
65
65
// The static_cast are not "necessary" but it removes some warnings
66
- result.push_back ({ static_cast <uint8_t >(current_byte),
66
+ result.push_back ({ static_cast <uint8_t >(current_byte),
67
67
lbit, rbit });
68
-
68
+
69
69
bitsLeft -= lbit - rbit;
70
- currentPos += (lbit - rbit);
70
+ currentPos += (lbit - rbit);
71
71
}
72
-
72
+
73
73
return result;
74
74
}
75
75
@@ -78,22 +78,22 @@ SignalRanges little_endian_ranges(const CANSignal& src) {
78
78
// ----------------- -----------------
79
79
// |*|*|*|*|*|*|*|*| |*|*|*|*|*|*|*|*|
80
80
// ----------------- -----------------
81
- // 0 7 8 15
82
- //
81
+ // 0 7 8 15
82
+ //
83
83
// The signal can be found from the start bit + read to the right.
84
84
SignalRanges result;
85
85
86
86
if (src.length () == 0 ) // length is 0, we return an empty result.
87
87
return result;
88
-
88
+
89
89
unsigned bitsLeft = src.length ();
90
90
unsigned currentPos = src.start_bit ();
91
91
for (unsigned current_byte = src.start_bit () / 8 ; bitsLeft > 0 ; current_byte++) {
92
92
char lbit = currentPos % 8 ;
93
93
char rbit = std::min<char >(lbit + bitsLeft, 8 );
94
94
95
95
// The static_cast are not "necessary" but it removes some warnings
96
- result.push_back ({ static_cast <uint8_t >(current_byte),
96
+ result.push_back ({ static_cast <uint8_t >(current_byte),
97
97
lbit, rbit });
98
98
99
99
bitsLeft -= rbit - lbit;
@@ -107,7 +107,7 @@ std::vector<SignalLayoutEntry> compute_layout(const CANFrame& src) {
107
107
std::vector<SignalLayoutEntry> result;
108
108
109
109
for (const auto & signal : src) {
110
- const CANSignal& sig = signal .second ;
110
+ const CANSignal& sig = signal .second ;
111
111
112
112
if (sig.endianness () == CANSignal::BigEndian) {
113
113
auto ranges = big_endian_ranges (sig);
@@ -126,12 +126,12 @@ std::vector<SignalLayoutEntry> compute_layout(const CANFrame& src) {
126
126
bool overlap (const SignalLayoutEntry& e1 , const SignalLayoutEntry& e2 ) {
127
127
for (const SignalRange& r1 : e1 .ranges ) {
128
128
for (const SignalRange& r2: e2 .ranges ) {
129
- // Find if r2 shares a SignalRange with the same byte with r1
129
+ // Find if r2 shares a SignalRange with the same byte with r1
130
130
if (r1.byte != r2.byte )
131
131
continue ;
132
-
132
+
133
133
// Now we know that the SignalRange(s) share a common byte
134
-
134
+
135
135
// ordered.first is the leftmost SignalRange in the byte
136
136
// ordered.second is the rightmost SignalRange in the byte
137
137
auto ordered = std::minmax (r1, r2, [](const SignalRange& r, const SignalRange& rr) {
@@ -154,7 +154,7 @@ bool CppCAN::analysis::is_frame_layout_ok(const CANFrame& src) {
154
154
for (size_t i = 0 ; i < layout.size (); i++) {
155
155
for (size_t j = i + 1 ; j < layout.size (); j++) {
156
156
if (overlap (layout[i], layout[j])) {
157
- return false ;
157
+ return false ;
158
158
}
159
159
}
160
160
}
@@ -179,7 +179,7 @@ bool CppCAN::analysis::is_frame_layout_ok(const CANFrame& src, std::vector<std::
179
179
if (overlap (layout[i], layout[j])) {
180
180
report_issue (i, *layout[i].src_signal );
181
181
report_issue (j, *layout[j].src_signal );
182
- }
182
+ }
183
183
}
184
184
}
185
185
0 commit comments