@@ -23,11 +23,40 @@ 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+
38+ std::ostream& operator << (std::ostream &out, const Signal& sig) {
39+ out << " Signal {name: " << sig.name << " , " ;
40+ out << " Multiplexed: " << (sig.is_multiplexed ? " True" : " False" ) << " , " ;
41+ out << " Start bit: " << sig.start_bit << " , " ;
42+ out << " Size: " << sig.size << " , " ;
43+ out << " Endianness: " << (sig.is_bigendian ? " Big endian" : " Little endian" ) << " , " ;
44+ out << " Value Type: " << (sig.is_signed ? " Signed" : " Unsigned" ) << " , " ;
45+ out << " Min: " << sig.min << " , Max: " << sig.max << " , " ;
46+ out << " Unit: (" << sig.unit << " ), " ;
47+ out << " receivers: " ;
48+ for (const auto &r : sig.receivers )
49+ out << r;
50+ return out << " }" ;
51+ }
52+
2653
2754 DbcParser::DbcParser () : version(" " ), nodes(),
2855 version_re (" ^(VERSION)\\ s\" (.*)\" " ), bit_timing_re(" ^(BS_:)" ),
2956 name_space_re(" ^(NS_)\\ s\\ :" ), node_re(" ^(BU_:)\\ s((?:[\\ w]+?\\ s?)*)" ),
30- message_re(" ^(BO_)\\ s(\\ d+)\\ s(\\ w+)\\ :\\ s(\\ d+)\\ s(\\ w+|Vector__XXX)" ) {
57+ message_re(" ^(BO_)\\ s(\\ d+)\\ s(\\ w+)\\ :\\ s(\\ d+)\\ s(\\ w+|Vector__XXX)" ),
58+ // NOTE: No multiplex support yet
59+ signal_re(" \\ s(SG_)\\ s(\\ w+)\\ s\\ :\\ s(\\ d+)\\ |(\\ d+)\\ @(\\ d+)(\\ +|\\ -)\\ s\\ ((\\ d+\\ .?(\\ d+)?)\\ ,(\\ d+\\ .?(\\ d+)?)\\ )\\ s\\ [(\\ d+\\ .?(\\ d+)?)\\ |(\\ d+\\ .?(\\ d+)?)\\ ]\\ s\" (\\ w*)\"\\ s([\\ w\\ ,]+|Vector__XXX)*" ) {
3160
3261 }
3362
@@ -115,6 +144,27 @@ namespace libdbc {
115144
116145 messages.push_back (msg);
117146 }
147+
148+ if (std::regex_search (line, match, signal_re)) {
149+ std::string name = match.str (2 );
150+ bool is_multiplexed = false ; // No support yet
151+ uint32_t start_bit = std::stoul (match.str (3 ));
152+ uint32_t size = std::stoul (match.str (4 ));
153+ bool is_bigendian = (std::stoul (match.str (5 )) == 1 );
154+ bool is_signed = (match.str (6 ) == " -" );
155+ // Alternate groups because a group is for the decimal portion
156+ double factor = std::stod (match.str (7 ));
157+ double offset = std::stod (match.str (9 ));
158+ double min = std::stod (match.str (11 ));
159+ double max = std::stod (match.str (13 ));
160+ std::string unit = match.str (15 );
161+
162+ std::vector<std::string> receivers;
163+ utils::String::split (match.str (16 ), receivers, ' ,' );
164+
165+ Signal sig (name, is_multiplexed, start_bit, size, is_bigendian, is_signed, factor, offset, min, max, unit, receivers);
166+ messages.back ().signals .push_back (sig);
167+ }
118168 }
119169
120170 }
0 commit comments