Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dbc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ namespace libdbc {
bool is_multiplexed = false; // No support yet
uint32_t start_bit = std::stoul(match.str(3));
uint32_t size = std::stoul(match.str(4));
bool is_bigendian = (std::stoul(match.str(5)) == 1);
bool is_bigendian = (std::stoul(match.str(5)) == 0);
bool is_signed = (match.str(6) == "-");
// Alternate groups because a group is for the decimal portion
double factor = std::stod(match.str(7));
Expand Down
31 changes: 30 additions & 1 deletion test/test_dbc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ TEST_CASE("Testing dbc file loading", "[fileio]") {
libdbc::Message msg(500, "IO_DEBUG", 4, "IO");

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

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

}

TEST_CASE("Testing big endian, little endian") {
const auto* filename = std::tmpnam(NULL);

auto* file = std::fopen(filename, "w");
CHECK(file);

std::fputs(PRIMITIVE_DBC.c_str(), file);
// first big endian
// second little endian
std::fputs(R"(BO_ 234 MSG1: 8 Vector__XXX
SG_ Sig1 : 55|16@0- (0.1,0) [-3276.8|-3276.7] "C" Vector__XXX
SG_ Sig2 : 39|16@1- (0.1,0) [-3276.8|-3276.7] "C" Vector__XXX)", file);
std::fclose(file);

auto parser = libdbc::DbcParser();
parser.parse_file(filename);

REQUIRE(parser.get_messages().size() == 1);
REQUIRE(parser.get_messages().at(0).signals.size() == 2);
{
const auto signal = parser.get_messages().at(0).signals.at(0);
REQUIRE(signal.is_bigendian == true);
}
{
const auto signal = parser.get_messages().at(0).signals.at(1);
REQUIRE(signal.is_bigendian == false);
}
}

TEST_CASE("Testing negative values") {
const auto* filename = std::tmpnam(NULL);

Expand Down