Skip to content

Commit f71d712

Browse files
authored
Update README.md
1 parent 65d208d commit f71d712

1 file changed

Lines changed: 32 additions & 3 deletions

File tree

README.md

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ make install
4141
## Dependencies
4242
* boost
4343
# Usage example
44+
* `C++`
4445
```C++
4546
#include <fstream>
4647
#include <dbcppp/Network.h>
@@ -51,11 +52,9 @@ int main()
5152
if (net)
5253
{
5354
can_frame frame;
54-
canfd_frame fd_frame;
5555
while (1)
5656
{
5757
receive_can_frame_from_somewhere(&frame);
58-
receive_canfd_frame_from_somewhere(&fd_frame);
5958
const Message* msg = net->getMessageById(frame.id);
6059
if (msg)
6160
{
@@ -70,7 +69,37 @@ int main()
7069
}
7170
}
7271
}
73-
72+
```
73+
* `C`
74+
```C
75+
#include <stdio.h>
76+
#include <dbcppp/CApi.h>
77+
int main()
78+
{
79+
const dbcppp_Nework* net = dbcppp_NetworkLoadDBCFromFile("your_dbc.dbc");
80+
if (net)
81+
{
82+
can_frame frame;
83+
while (1)
84+
{
85+
receive_can_frame_from_somewhere(&frame);
86+
const dbcppp_Message* msg = dbcppp_NetworkGetMessageById(net, frame.id);
87+
if (msg)
88+
{
89+
std::cout << "Received message: " << msg->getName() << std::endl;
90+
printf("Received message: %s\n", dbcppp_MessageGetName(msg));
91+
void print_signal_data(const dbcppp_Signal* sig, void* data)
92+
{
93+
can_frame* frame = (can_frame*)data);
94+
double raw = dbcppp_SignalDecode(sig, frame->data);
95+
double phys = dbcppp_SignalRawToPhys(sig, raw);
96+
printf("\t%s=%f\n", dbcppp_SignalGetName(sig), phys);
97+
}
98+
dbcppp_MessageForEachSignal(msg, print_signal_data, &frame);
99+
}
100+
}
101+
}
102+
}
74103
```
75104
# Decode-function
76105
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):

0 commit comments

Comments
 (0)