Skip to content

Commit ed41141

Browse files
committed
Added definition of Signal
Signals has a comparison operator and a Signal constructor. I don't like the constructor that is so long but works for now.
1 parent dd26f71 commit ed41141

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

include/dbc.hpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,40 @@
1010

1111
namespace libdbc {
1212

13+
struct Signal {
14+
std::string name;
15+
bool is_multiplexed;
16+
uint32_t start_bit;
17+
uint32_t size;
18+
bool is_bigendian;
19+
bool is_signed;
20+
double factor;
21+
double offset;
22+
double min;
23+
double max;
24+
std::string unit;
25+
std::vector<std::string> receivers;
26+
27+
Signal() = delete;
28+
explicit Signal(std::string name, bool is_multiplexed, uint32_t start_bit, uint32_t size, bool is_bigendian, bool is_signed, double factor, double offset, double min, double max, std::string unit, std::vector<std::string> recievers);
29+
30+
virtual bool operator==(const Signal& rhs) const;
31+
};
32+
1333
struct Message {
1434
uint32_t id;
1535
std::string name;
1636
uint8_t size;
1737
std::string node;
38+
std::vector<Signal> signals;
1839

1940
Message() = delete;
2041
explicit Message(uint32_t id, const std::string& name, uint8_t size, const std::string& node);
2142

2243
virtual bool operator==(const Message& rhs) const;
2344
};
2445

46+
2547
std::ostream& operator<< (std::ostream &out, const Message& msg);
2648

2749

@@ -58,6 +80,7 @@ namespace libdbc {
5880
const std::regex name_space_re;
5981
const std::regex node_re;
6082
const std::regex message_re;
83+
const std::regex signal_re;
6184

6285
void parse_dbc_header(std::istream& file_stream);
6386
void parse_dbc_nodes(std::istream& file_stream);

src/dbc.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ namespace libdbc {
2323
}
2424

2525

26+
Signal::Signal(std::string name, bool is_multiplexed, uint32_t start_bit, uint32_t size, bool is_bigendian, bool is_signed, double factor, double offset, double min, double max, std::string unit, std::vector<std::string> receivers) :
27+
name(name), is_multiplexed(is_multiplexed), start_bit(start_bit), size(size), is_bigendian(is_bigendian), is_signed(is_signed), offset(offset), min(min), max(max), unit(unit), receivers(receivers) {}
28+
29+
bool Signal::operator==(const Signal& rhs) const {
30+
return (this->name == rhs.name) && (this->is_multiplexed == rhs.is_multiplexed) &&
31+
(this->start_bit == rhs.start_bit) && (this->size == rhs.size) &&
32+
(this->is_bigendian == rhs.is_bigendian) && (this->is_signed == rhs.is_signed) &&
33+
(this->offset == rhs.offset) && (this->min == rhs.min) && (this->max == rhs.max) &&
34+
(this->unit == rhs.unit) && (this->receivers == rhs.receivers);
35+
}
36+
37+
2638

2739
DbcParser::DbcParser() : version(""), nodes(),
2840
version_re("^(VERSION)\\s\"(.*)\""), bit_timing_re("^(BS_:)"),

test/test_dbc.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ TEST_CASE("Testing dbc file loading", "[fileio]") {
3232

3333
libdbc::Message msg(500, "IO_DEBUG", 4, "IO");
3434

35+
std::vector<std::string> receivers{"DBG"};
36+
libdbc::Signal sig("IO_DEBUG_test_unsigned", false, 0, 8, true, false, 1, 0, 0, 0, "", receivers);
37+
msg.signals.push_back(sig);
38+
3539
std::vector<libdbc::Message> msgs = {msg};
3640

3741
parser->parse_file(SIMPLE_DBC_FILE);
@@ -41,6 +45,8 @@ TEST_CASE("Testing dbc file loading", "[fileio]") {
4145
REQUIRE(parser->get_nodes() == nodes);
4246

4347
REQUIRE(parser->get_messages() == msgs);
48+
49+
REQUIRE(parser->get_messages().front().signals == msg.signals);
4450
}
4551

4652
}

0 commit comments

Comments
 (0)