dbcppp
dbcppp copied to clipboard
C++ Example run error
Hello,
I am attempting to implement your C++ example within my application. However it's run error.
The line can_frame frame; compile failed, Compiler tips 'can_frame': undeclared identifier. Where is this problem and how to solve it
#include <fstream>
#include <dbcppp/Network.h>
#pragma comment(lib,"dbcppp/libdbcppp.lib")
//using namespace dbcppp;
int main()
{
std::unique_ptr<dbcppp::INetwork> net;
{
std::ifstream idbc("your.dbc");
net = dbcppp::INetwork::LoadDBCFromIs(idbc);
}
std::unordered_map<uint64_t, const dbcppp::IMessage*> messages;
for (const dbcppp::IMessage& msg : net->Messages())
{
messages.insert(std::make_pair(msg.Id(), &msg));
}
can_frame frame;
while (1)
{
receive_frame_data(&frame);
auto iter = messages.find(frame.can_id);
if (iter != messages.end())
{
const dbcppp::IMessage* msg = iter->second;
std::cout << "Received Message: " << msg->Name() << "\n";
for (const dbcppp::ISignal& sig : msg->Signals())
{
const dbcppp::ISignal* mux_sig = msg->MuxSignal();
if (sig.MultiplexerIndicator() != dbcppp::ISignal::EMultiplexer::MuxValue ||
(mux_sig && mux_sig->Decode(frame.data) == sig.MultiplexerSwitchValue()))
{
std::cout << "\t" << sig.Name() << "=" << sig.RawToPhys(sig.Decode(frame.data)) << sig.Unit() << "\n";
}
}
}
}
}
That's pseudo code, you have to provide your own can frame data.