Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ihedvall committed Mar 28, 2023
2 parents 8d2d6c3 + 1652e9e commit 38393e1
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions doc/dbclibexample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ int main() {
dbc::DbcFile file;

file.Filename(DBC_FILE_PATH); // File path to the dbc file
const auto success = file.ParseFile();
bool success = file.ParseFile();

auto* network = file.GetNetwork();
const auto& message_list = network->Messages();
for (const auto& itr : message_list) {
// Message properties
const auto& message = itr.second;
const dbc::Message& message = itr.second;
std::cout << "ID: " << message.CanId()
<< (message.IsExtended() ? "E" : "S")
<< ", Name: " << message.Name()
Expand All @@ -24,7 +24,7 @@ int main() {
// Signals and properties
const auto& signal_list = message.Signals();
for (const auto& itr: signal_list) {
const auto& signal = itr.second;
const dbc::Signal& signal = itr.second;
std::string datatype = "Uknown";
switch (signal.DataType()) {
case dbc::SignalDataType::SignedData: datatype = "SignedData"; break;
Expand All @@ -49,7 +49,27 @@ int main() {
std::cout << signal.Receivers().at(i) << ",";
}
if (!signal.Receivers().empty())
std::cout << signal.Receivers().at(signal.Receivers().size() - 1) << "\n";
std::cout << signal.Receivers().at(signal.Receivers().size() - 1) << std::endl;
}
}

// ##################################################################################
// Parsing a message
// ##################################################################################

dbc::DbcMessage msg(0, 234, {0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8});
success = file.ParseMessage(msg);
dbc::Message* message = network->GetMessage(234);
if (message) {
for (const auto& signalPair: message->Signals()) {
double value;
const dbc::Signal& signal = signalPair.second;
signalPair.second.EngValue(value);

std::cout << "Signal: " << signal.Name()
<< ", Value: " << value << " " << signal.Unit()
<< std::endl;
}
}

}

0 comments on commit 38393e1

Please sign in to comment.