Skip to content

Commit 13bec82

Browse files
committed
due to the error in 19caeec the assumption in the test was wrong. It has to be changed
1 parent ea177ac commit 13bec82

File tree

2 files changed

+41
-42
lines changed

2 files changed

+41
-42
lines changed

src/message.cpp

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,45 @@ namespace libdbc {
2727
} else {
2828
const auto& signal = m_signals.at(bs.index);
2929
if (signal.is_bigendian) {
30-
30+
switch (bs.size) {
31+
case 1:
32+
v = static_cast<double>(bitstream_reader_read_bit(&reader)); break;
33+
case 8:
34+
if (signal.is_signed)
35+
v = static_cast<double>(static_cast<int8_t>(bitstream_reader_read_u8(&reader)));
36+
else
37+
v = static_cast<double>(bitstream_reader_read_u8(&reader));
38+
break;
39+
case 16:
40+
if (signal.is_signed)
41+
v = static_cast<double>(static_cast<int16_t>(bitstream_reader_read_u16(&reader)));
42+
else
43+
v = static_cast<double>(bitstream_reader_read_u16(&reader));
44+
break;
45+
case 32:
46+
if (signal.is_signed)
47+
v = static_cast<double>(static_cast<int32_t>(bitstream_reader_read_u32(&reader)));
48+
else
49+
v = static_cast<double>(bitstream_reader_read_u32(&reader));
50+
break;
51+
case 64:
52+
if (signal.is_signed)
53+
v = static_cast<double>(static_cast<int64_t>(bitstream_reader_read_u64(&reader)));
54+
else
55+
v = static_cast<double>(bitstream_reader_read_u64(&reader));
56+
break;
57+
default: {
58+
// TODO: possible to implement bigendian and sign?
59+
uint64_t value = 0;
60+
for (uint32_t i=0; i < bs.size; i++) {
61+
value |= bitstream_reader_read_bit(&reader) << i;
62+
}
63+
v = static_cast<double>(value);
64+
break;
65+
}
66+
}
67+
} else {
68+
// little endian
3169
switch (bs.size) {
3270
case 1: v = static_cast<double>(bitstream_reader_read_bit(&reader)); break;
3371
case 8: v = static_cast<double>(bitstream_reader_read_u8(&reader)); break;
@@ -76,45 +114,6 @@ namespace libdbc {
76114
break;
77115
}
78116
}
79-
} else {
80-
// little endian
81-
switch (bs.size) {
82-
case 1:
83-
v = static_cast<double>(bitstream_reader_read_bit(&reader)); break;
84-
case 8:
85-
if (signal.is_signed)
86-
v = static_cast<double>(static_cast<int8_t>(bitstream_reader_read_u8(&reader)));
87-
else
88-
v = static_cast<double>(bitstream_reader_read_u8(&reader));
89-
break;
90-
case 16:
91-
if (signal.is_signed)
92-
v = static_cast<double>(static_cast<int16_t>(bitstream_reader_read_u16(&reader)));
93-
else
94-
v = static_cast<double>(bitstream_reader_read_u16(&reader));
95-
break;
96-
case 32:
97-
if (signal.is_signed)
98-
v = static_cast<double>(static_cast<int32_t>(bitstream_reader_read_u32(&reader)));
99-
else
100-
v = static_cast<double>(bitstream_reader_read_u32(&reader));
101-
break;
102-
case 64:
103-
if (signal.is_signed)
104-
v = static_cast<double>(static_cast<int64_t>(bitstream_reader_read_u64(&reader)));
105-
else
106-
v = static_cast<double>(bitstream_reader_read_u64(&reader));
107-
break;
108-
default: {
109-
// TODO: possible to implement bigendian and sign?
110-
uint64_t value = 0;
111-
for (uint32_t i=0; i < bs.size; i++) {
112-
value |= bitstream_reader_read_bit(&reader) << i;
113-
}
114-
v = static_cast<double>(value);
115-
break;
116-
}
117-
}
118117
}
119118

120119
values.push_back(v * signal.factor + signal.offset);

test/test_dbc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ TEST_CASE("Parse Message little endian") {
174174
libdbc::DbcParser p(true);
175175
p.parse_file(filename);
176176

177-
std::vector<uint8_t> data{0x27, 0x08, 0x22, 0xa3, 0x1f, 0xe5, 0x14, 0x45}; // little endian
177+
std::vector<uint8_t> data{0x08, 0x27, 0xa3, 0x22, 0xe5, 0x1f, 0x45, 0x14}; // little endian
178178
std::vector<double> result_values;
179179
REQUIRE(p.parseMessage(0x21d, data, result_values) == true);
180180
REQUIRE(result_values.size() == 4);
@@ -201,7 +201,7 @@ TEST_CASE("Parse Message big endian") {
201201
libdbc::DbcParser p(true);
202202
p.parse_file(filename);
203203

204-
std::vector<uint8_t> data{0x08, 0x27, 0xa3, 0x22, 0xe5, 0x1f, 0x45, 0x14}; // big endian
204+
std::vector<uint8_t> data{0x27, 0x08, 0x22, 0xa3, 0x1f, 0xe5, 0x14, 0x45}; // big endian
205205
std::vector<double> result_values;
206206
REQUIRE(p.parseMessage(0x21d, data, result_values) == true);
207207
REQUIRE(result_values.size() == 4);

0 commit comments

Comments
 (0)