Skip to content

Commit

Permalink
Merge pull request #48 from adriaan-niess/feat/readme
Browse files Browse the repository at this point in the history
Feat/readme
  • Loading branch information
adriaan-niess authored Nov 20, 2024
2 parents bf86be6 + 014747a commit a2c3ffc
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,18 @@ To execute the IEEE 1722 CAN Talker application:
$ ./build/acf-can-talker
```

### De/Serialization IEEE 1722 PDUs
### Programming Tutorial

Here's a small example how the Open1722 library can be used to build and parse IEEE 1722 PDUs. First we define a C struct for a custom IEEE 1722 packet that can be used to transport a CAN, a LIN and a Flexray message. The frame begins with a Time-synchronous Control Format (TSCF) header. After the TSCF header a list of AVTP Control Format (ACF) messages follows. The first ACF message is a ACF CAN message which consists of ACF CAN header as well as a payload section to carry a 2Byte CAN frame. Similar than with the CAN message another ACF messages for LIN is added.

``` C
// my_1722_pdu.h

#include "avtp/Udp.h"
#include "avtp/acf/Tscf.h"
#include "avtp/acf/Can.h"
#include "avtp/acf/Lin.h"

#define CAN_PAYLOAD_LEN 2
#define LIN_PAYLOAD_LEN 3

Expand Down Expand Up @@ -148,7 +153,7 @@ int main()
// Init TSCF header
Avtp_Tscf_Init(&pdu.tscf);
Avtp_Tscf_SetVersion(&pdu.tscf, 0);
Avtp_Tscf_SetSequenceNum(&pdu.tscf, 12345);
Avtp_Tscf_SetSequenceNum(&pdu.tscf, 123);
Avtp_Tscf_SetStreamId(&pdu.tscf, 0xAABBCCDDEEFF);
Avtp_Tscf_SetTv(&pdu.tscf, 1);
Avtp_Tscf_SetAvtpTimestamp(&pdu.tscf, 0x11223344);
Expand All @@ -157,11 +162,13 @@ int main()
Avtp_Can_Init(&pdu.can);
Avtp_Can_SetCanBusId(&pdu.can, 4);
uint8_t canFrame[CAN_PAYLOAD_LEN] = {0x11, 0x22};
memcpy(pdu.can.payload, canFrame, CAN_PAYLOAD_LEN);

// Init LIN ACF message
Avtp_Lin_Init(&pdu.lin);
uint8_t linFrame[LIN_PAYLOAD_LEN] = {0x11, 0x22, 0x33};
memcpy(pdu.lin.payload, linFrame, LIN_PAYLOAD_LEN);

// Send packet to network
// Send packet to network using socket API ...
}
```

0 comments on commit a2c3ffc

Please sign in to comment.