Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions examples/read_dbc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ int main(int argc, char ** argv)
size_t message_attr_counter = 0;
size_t signal_attr_counter = 0;
size_t attr_def_default_counter = 0;
size_t signal_value_counter = 0;

auto bus_nodes = dbc.getBusNodes();
auto messages = dbc.getMessages();
Expand All @@ -69,6 +70,10 @@ int main(int argc, char ** argv)
if (sig.second->getComment() != nullptr) {
signal_comment_counter++;
}
const int num_values = sig.second->getValueDescriptions().size();
if (num_values != 0){
signal_value_counter += num_values;
}
}
}

Expand Down Expand Up @@ -115,6 +120,7 @@ int main(int argc, char ** argv)
std::cout << "Found " << bus_nodes.size() << " bus nodes.\n";
std::cout << "Found " << dbc.getMessages().size() << " messages.\n";
std::cout << "Found " << signal_counter << " signals.\n";
std::cout << "Found " << signal_value_counter << " signal values.\n";

size_t total_comments = bus_node_comment_counter + message_comment_counter + signal_comment_counter;

Expand Down
1 change: 1 addition & 0 deletions include/common_defs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <array>
#include <exception>
#include <unordered_map>
#include <string>

namespace AS
{
Expand Down
41 changes: 32 additions & 9 deletions src/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ void Database::parse(std::istream & reader)
std::vector<BusNodeComment> bus_node_comments;
std::vector<MessageComment> message_comments;
std::vector<SignalComment> signal_comments;
std::unordered_map<std::string, std::map<unsigned int, std::string>>
value_descs;
std::unordered_map<std::string, std::pair<AttributeType, std::string>> attr_texts;
std::unordered_map<std::string, std::string> attr_def_val_texts;

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

std::map<unsigned int, std::string> value_descs;

std::string temp_string;
std::string sig_name;

std::string current_char;
std::string current_name{};
unsigned int current_val{};
// Message ID
iss_line >> temp_string;

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

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

// TODO(jwhitleyastuff): Finish parsing values
// Probably a better way than this but it works
while (current_char != ";") {
// Breaks when hitting semicolon
iss_line >> current_char;
if (current_char == ";") {
break;
}
current_val = std::stoul(current_char);
iss_line >> current_name;
value_descs[sig_name][current_val] = current_name;
}
} else if (preamble == PREAMBLES[7]) { // ATTRIBUTE DEFINITION
saveMsg(current_msg);

Expand Down Expand Up @@ -484,10 +494,23 @@ void Database::parse(std::istream & reader)
} break;
}
}
// Assign value descriptions to each signal within the messages
for (auto &msg : messages_) {
for (auto &sig : msg.second.signals_) {
auto signame = sig.first;
if (value_descs.find(signame) == value_descs.end()) {
// The signal name doesn't have an entry in the value descriptions
continue;
} else {
const std::map<unsigned int, std::string> thismap =
value_descs[signame];
// Assign the current map to the signal value descriptions
sig.second.value_descs_ = thismap;
}
}
}

// TODO(jwhitleyastuff): Apply attributes to DB objects

// TODO(jwhitleyastuff): Add signal value description lists to signals
// TODO(jwhitleyastuff): Apply attributes to DB objects
}

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