Skip to content

Commit 8895220

Browse files
committed
Update dbc.cpp and test_dbc.cpp
1 parent 2a4d059 commit 8895220

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/dbc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ namespace libdbc {
147147
bool is_multiplexed = false; // No support yet
148148
uint32_t start_bit = std::stoul(match.str(3));
149149
uint32_t size = std::stoul(match.str(4));
150-
bool is_bigendian = (std::stoul(match.str(5)) == 1);
150+
bool is_bigendian = (std::stoul(match.str(5)) == 0);
151151
bool is_signed = (match.str(6) == "-");
152152
// Alternate groups because a group is for the decimal portion
153153
double factor = std::stod(match.str(7));

test/test_dbc.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ TEST_CASE("Testing dbc file loading", "[fileio]") {
4444
libdbc::Message msg(500, "IO_DEBUG", 4, "IO");
4545

4646
std::vector<std::string> receivers{"DBG"};
47-
libdbc::Signal sig("IO_DEBUG_test_unsigned", false, 0, 8, true, false, 1, 0, 0, 0, "", receivers);
47+
libdbc::Signal sig("IO_DEBUG_test_unsigned", false, 0, 8, false, false, 1, 0, 0, 0, "", receivers);
4848
msg.signals.push_back(sig);
4949

5050
std::vector<libdbc::Message> msgs = {msg};
@@ -62,6 +62,35 @@ TEST_CASE("Testing dbc file loading", "[fileio]") {
6262

6363
}
6464

65+
TEST_CASE("Testing big endian, little endian") {
66+
const auto* filename = std::tmpnam(NULL);
67+
68+
auto* file = std::fopen(filename, "w");
69+
CHECK(file);
70+
71+
std::fputs(PRIMITIVE_DBC.c_str(), file);
72+
// first big endian
73+
// second little endian
74+
std::fputs(R"(BO_ 234 MSG1: 8 Vector__XXX
75+
SG_ Sig1 : 55|16@0- (0.1,0) [-3276.8|-3276.7] "C" Vector__XXX
76+
SG_ Sig2 : 39|16@1- (0.1,0) [-3276.8|-3276.7] "C" Vector__XXX)", file);
77+
std::fclose(file);
78+
79+
auto parser = libdbc::DbcParser();
80+
parser.parse_file(filename);
81+
82+
REQUIRE(parser.get_messages().size() == 1);
83+
REQUIRE(parser.get_messages().at(0).signals.size() == 2);
84+
{
85+
const auto signal = parser.get_messages().at(0).signals.at(0);
86+
REQUIRE(signal.is_bigendian == true);
87+
}
88+
{
89+
const auto signal = parser.get_messages().at(0).signals.at(1);
90+
REQUIRE(signal.is_bigendian == false);
91+
}
92+
}
93+
6594
TEST_CASE("Testing negative values") {
6695
const auto* filename = std::tmpnam(NULL);
6796

0 commit comments

Comments
 (0)