Skip to content

Commit 05df300

Browse files
committed
Adding size getter for message.
This wasn't done before and was an oversight. This fixes #19 issue. I am not sure if uint8_t is the right size but if it is greater rollover happens and no detection method right now
1 parent e505e75 commit 05df300

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

include/libdbc/message.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ struct Message {
3232
void appendSignal(const Signal& signal);
3333
const std::vector<Signal> getSignals() const;
3434
uint32_t id() const;
35-
const std::string& name() const {
36-
return m_name;
37-
}
35+
uint8_t size() const;
36+
const std::string& name() const;
3837
void addValueDescription(const std::string& signal_name, const std::vector<Signal::SignalValueDescriptions>&);
3938

4039
virtual bool operator==(const Message& rhs) const;

src/message.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ uint32_t Message::id() const {
8585
return m_id;
8686
}
8787

88+
uint8_t Message::size() const {
89+
return m_size;
90+
}
91+
92+
const std::string& Message::name() const {
93+
return m_name;
94+
}
95+
8896
void Message::addValueDescription(const std::string& signal_name, const std::vector<Signal::SignalValueDescriptions>& vd) {
8997
for (auto& s : m_signals) {
9098
if (s.name.compare(signal_name) == 0) {

test/test_dbc.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ TEST_CASE("Testing big endian, little endian") {
7373

7474
REQUIRE(parser.get_messages().size() == 1);
7575
REQUIRE(parser.get_messages().at(0).name() == "MSG1");
76+
REQUIRE(parser.get_messages().at(0).size() == 8);
7677
REQUIRE(parser.get_messages().at(0).getSignals().size() == 2);
7778
{
7879
const auto signal = parser.get_messages().at(0).getSignals().at(0);
@@ -85,7 +86,7 @@ TEST_CASE("Testing big endian, little endian") {
8586
}
8687

8788
TEST_CASE("Testing negative values") {
88-
std::string dbc_contents = PRIMITIVE_DBC + R"(BO_ 234 MSG1: 8 Vector__XXX
89+
std::string dbc_contents = PRIMITIVE_DBC + R"(BO_ 234 MSG1: 58 Vector__XXX
8990
SG_ Sig1 : 55|16@0- (0.1,0) [-3276.8|-3276.7] "C" Vector__XXX
9091
SG_ Sig2 : 39|16@0- (0.1,0) [-3276.8|-3276.7] "C" Vector__XXX
9192
SG_ Sig3 : 23|16@0- (10,0) [-3276.8|-3276.7] "C" Vector__XXX
@@ -97,6 +98,7 @@ TEST_CASE("Testing negative values") {
9798

9899
REQUIRE(parser.get_messages().size() == 1);
99100
REQUIRE(parser.get_messages().at(0).name() == "MSG1");
101+
REQUIRE(parser.get_messages().at(0).size() == 58);
100102
REQUIRE(parser.get_messages().at(0).getSignals().size() == 4);
101103

102104
SECTION("Evaluating first message") {
@@ -130,7 +132,7 @@ TEST_CASE("Testing negative values") {
130132
}
131133

132134
TEST_CASE("Special characters in unit") {
133-
std::string dbc_contents = PRIMITIVE_DBC + R"(BO_ 234 MSG1: 8 Vector__XXX
135+
std::string dbc_contents = PRIMITIVE_DBC + R"(BO_ 234 MSG1: 255 Vector__XXX
134136
SG_ Speed : 0|8@1+ (1,0) [0|204] "Km/h" DEVICE1,DEVICE2,DEVICE3)";
135137
const auto filename = create_temporary_dbc_with(dbc_contents.c_str());
136138

@@ -139,6 +141,7 @@ TEST_CASE("Special characters in unit") {
139141

140142
REQUIRE(parser.get_messages().size() == 1);
141143
REQUIRE(parser.get_messages().at(0).name() == "MSG1");
144+
REQUIRE(parser.get_messages().at(0).size() == 255);
142145
REQUIRE(parser.get_messages().at(0).getSignals().size() == 1);
143146
SECTION("Checking that signal with special characters as unit is parsed correctly") {
144147
const auto signal = parser.get_messages().at(0).getSignals().at(0);

0 commit comments

Comments
 (0)