Skip to content

Commit ffa6ac9

Browse files
authored
Merge pull request #13 from Murmele/bigEndian
Big Endian is zero not 1
2 parents 1cfa210 + cf09f89 commit ffa6ac9

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
@@ -53,7 +53,7 @@ TEST_CASE("Testing dbc file loading", "[fileio]") {
5353
libdbc::Message msg(500, "IO_DEBUG", 4, "IO");
5454

5555
std::vector<std::string> receivers{"DBG"};
56-
libdbc::Signal sig("IO_DEBUG_test_unsigned", false, 0, 8, true, false, 1, 0, 0, 0, "", receivers);
56+
libdbc::Signal sig("IO_DEBUG_test_unsigned", false, 0, 8, false, false, 1, 0, 0, 0, "", receivers);
5757
msg.signals.push_back(sig);
5858

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

7272
}
7373

74+
TEST_CASE("Testing big endian, little endian") {
75+
const auto* filename = std::tmpnam(NULL);
76+
77+
auto* file = std::fopen(filename, "w");
78+
CHECK(file);
79+
80+
std::fputs(PRIMITIVE_DBC.c_str(), file);
81+
// first big endian
82+
// second little endian
83+
std::fputs(R"(BO_ 234 MSG1: 8 Vector__XXX
84+
SG_ Sig1 : 55|16@0- (0.1,0) [-3276.8|-3276.7] "C" Vector__XXX
85+
SG_ Sig2 : 39|16@1- (0.1,0) [-3276.8|-3276.7] "C" Vector__XXX)", file);
86+
std::fclose(file);
87+
88+
auto parser = libdbc::DbcParser();
89+
parser.parse_file(filename);
90+
91+
REQUIRE(parser.get_messages().size() == 1);
92+
REQUIRE(parser.get_messages().at(0).signals.size() == 2);
93+
{
94+
const auto signal = parser.get_messages().at(0).signals.at(0);
95+
REQUIRE(signal.is_bigendian == true);
96+
}
97+
{
98+
const auto signal = parser.get_messages().at(0).signals.at(1);
99+
REQUIRE(signal.is_bigendian == false);
100+
}
101+
}
102+
74103
TEST_CASE("Testing negative values") {
75104
const auto* filename = std::tmpnam(NULL);
76105

0 commit comments

Comments
 (0)