Skip to content

Commit 543385e

Browse files
committed
Parsed signal correctly
A signal is now being parsed out. I didn't add in multiplexing yet. Regex is bing used but maybe we shouldn't? I think it works for now but when it comes time to work with errors it might not work well
1 parent a14be82 commit 543385e

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/dbc.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ namespace libdbc {
5454
DbcParser::DbcParser() : version(""), nodes(),
5555
version_re("^(VERSION)\\s\"(.*)\""), bit_timing_re("^(BS_:)"),
5656
name_space_re("^(NS_)\\s\\:"), node_re("^(BU_:)\\s((?:[\\w]+?\\s?)*)"),
57-
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)*") {
5860

5961
}
6062

@@ -142,6 +144,27 @@ namespace libdbc {
142144

143145
messages.push_back(msg);
144146
}
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+
}
145168
}
146169

147170
}

0 commit comments

Comments
 (0)