Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
xR3b0rn authored Mar 25, 2020
1 parent 65d208d commit f71d712
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ make install
## Dependencies
* boost
# Usage example
* `C++`
```C++
#include <fstream>
#include <dbcppp/Network.h>
Expand All @@ -51,11 +52,9 @@ int main()
if (net)
{
can_frame frame;
canfd_frame fd_frame;
while (1)
{
receive_can_frame_from_somewhere(&frame);
receive_canfd_frame_from_somewhere(&fd_frame);
const Message* msg = net->getMessageById(frame.id);
if (msg)
{
Expand All @@ -70,7 +69,37 @@ int main()
}
}
}

```
* `C`
```C
#include <stdio.h>
#include <dbcppp/CApi.h>
int main()
{
const dbcppp_Nework* net = dbcppp_NetworkLoadDBCFromFile("your_dbc.dbc");
if (net)
{
can_frame frame;
while (1)
{
receive_can_frame_from_somewhere(&frame);
const dbcppp_Message* msg = dbcppp_NetworkGetMessageById(net, frame.id);
if (msg)
{
std::cout << "Received message: " << msg->getName() << std::endl;
printf("Received message: %s\n", dbcppp_MessageGetName(msg));
void print_signal_data(const dbcppp_Signal* sig, void* data)
{
can_frame* frame = (can_frame*)data);
double raw = dbcppp_SignalDecode(sig, frame->data);
double phys = dbcppp_SignalRawToPhys(sig, raw);
printf("\t%s=%f\n", dbcppp_SignalGetName(sig), phys);
}
dbcppp_MessageForEachSignal(msg, print_signal_data, &frame);
}
}
}
}
```
# Decode-function
The signals decode function is using prestored masks and fixed offsets to speed up calculation, therefore the decoding-function should be almost as fast as a code generated decode function would be. The assembly of the `decode`-function on its critical path (signed and byte swap must happen) looks like this (VS19 10.0.18362.0 compiler):
Expand Down

0 comments on commit f71d712

Please sign in to comment.