Skip to content

Commit 7b1b08c

Browse files
author
Scott
committed
Add signal values to message signals
1 parent ce97f5c commit 7b1b08c

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

src/database.cpp

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ void Database::parse(std::istream & reader)
289289
std::vector<BusNodeComment> bus_node_comments;
290290
std::vector<MessageComment> message_comments;
291291
std::vector<SignalComment> signal_comments;
292+
std::unordered_map<std::string, std::map<unsigned int, std::string>>
293+
value_descs;
292294
std::unordered_map<std::string, std::pair<AttributeType, std::string>> attr_texts;
293295
std::unordered_map<std::string, std::string> attr_def_val_texts;
294296

@@ -351,11 +353,11 @@ void Database::parse(std::istream & reader)
351353
} else if (preamble == PREAMBLES[6]) { // SIGNAL VALUE LIST
352354
saveMsg(current_msg);
353355

354-
std::map<unsigned int, std::string> value_descs;
355-
356356
std::string temp_string;
357357
std::string sig_name;
358-
358+
std::string current_char;
359+
std::string current_name{};
360+
unsigned int current_val{};
359361
// Message ID
360362
iss_line >> temp_string;
361363

@@ -364,10 +366,18 @@ void Database::parse(std::istream & reader)
364366
// Signal Name
365367
iss_line >> sig_name;
366368

367-
// Get all remaining values up to the ending semicolon
368-
std::getline(iss_line, temp_string, ';');
369369

370-
// TODO(jwhitleyastuff): Finish parsing values
370+
// Probably a better way than this but it works
371+
while (current_char != ";") {
372+
// Breaks when hitting semicolon
373+
iss_line >> current_char;
374+
if (current_char == ";") {
375+
break;
376+
}
377+
current_val = std::stoul(current_char);
378+
iss_line >> current_name;
379+
value_descs[sig_name][current_val] = current_name;
380+
}
371381
} else if (preamble == PREAMBLES[7]) { // ATTRIBUTE DEFINITION
372382
saveMsg(current_msg);
373383

@@ -484,10 +494,23 @@ void Database::parse(std::istream & reader)
484494
} break;
485495
}
486496
}
497+
// Assign value descriptions to each signal within the messages
498+
for (auto &msg : messages_) {
499+
for (auto &sig : msg.second.signals_) {
500+
auto signame = sig.first;
501+
if (value_descs.find(signame) == value_descs.end()) {
502+
// The signal name doesn't have an entry in the value descriptions
503+
continue;
504+
} else {
505+
const std::map<unsigned int, std::string> thismap =
506+
value_descs[signame];
507+
// Assign the current map to the signal value descriptions
508+
sig.second.value_descs_ = thismap;
509+
}
510+
}
511+
}
487512

488-
// TODO(jwhitleyastuff): Apply attributes to DB objects
489-
490-
// TODO(jwhitleyastuff): Add signal value description lists to signals
513+
// TODO(jwhitleyastuff): Apply attributes to DB objects
491514
}
492515

493516
void Database::saveMsg(std::unique_ptr<Message> & msg_ptr)

0 commit comments

Comments
 (0)