Skip to content

Commit

Permalink
Update GetField API for AcfCommon.h/c and FlexRay.h/c
Browse files Browse the repository at this point in the history
Signed-off-by: Adriaan Niess <[email protected]>
  • Loading branch information
adriaan-niess committed Aug 26, 2024
1 parent 998e3c0 commit 1e224c1
Show file tree
Hide file tree
Showing 11 changed files with 232 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ add_library(open1722 SHARED
"src/avtp/acf/CanBrief.c"
"src/avtp/acf/Lin.c"
"src/avtp/acf/Most.c"
"src/avtp/acf/Common.c"
"src/avtp/acf/AcfCommon.c"
"src/avtp/acf/Ntscf.c"
"src/avtp/acf/Sensor.c"
"src/avtp/acf/SensorBrief.c"
Expand Down
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,62 @@ To execute the IEEE 1722 CAN Talker application:
```
$ ./bin/acf-can-talker
```

### De/Serialization IEEE 1722 PDUs

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

#define CAN_PAYLOAD_LEN 2
#define LIN_PAYLOAD_LEN 3

typedef struct {
// IEEE 1722 UDP encapsulation header (optional)
Avtp_Udp_t udp;
// IEEE 1722 TSCF header
Avtp_Tscf_t tscf;
// IEEE 1722 ACF message #1
Avtp_Can_t can;
uint8_t canPayload[CAN_PAYLOAD_LEN];
// IEEE 1722 ACF message #2
Avtp_Lin_t lin;
uint8_t linPayload[LIN_PAYLOAD_LEN];
} My1722Pdu_t;
```

In the next step we're going to c

``` C
// talker.h

#include "my_1722_pdu.h"

int main()
{
My1722Pdu_t pdu;

// Init UDP encapsulation header
Avtp_Udp_Init(&pdu.udp);

// Init TSCF header
Avtp_Tscf_Init(&pdu.tscf);
Avtp_Tscf_SetVersion(&pdu.tscf, 0);
Avtp_Tscf_SetSequenceNum(&pdu.tscf, 12345);
Avtp_Tscf_SetStreamId(&pdu.tscf, 0xAABBCCDDEEFF);
Avtp_Tscf_SetTv(&pdu.tscf, 1);
Avtp_Tscf_SetAvtpTimestamp(&pdu.tscf, 0x11223344);

// Init CAN ACF message
Avtp_Can_Init(&pdu.can);
Avtp_Can_SetCanBusId(&pdu.can, 4);
uint8_t canFrame[CAN_PAYLOAD_LEN] = {0x11, 0x22};

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

// Send packet to network
}
```
2 changes: 1 addition & 1 deletion include/avtp/acf/Can.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include <stdint.h>

#include "avtp/Defines.h"
#include "avtp/acf/Common.h"
#include "avtp/acf/AcfCommon.h"

#define AVTP_CAN_HEADER_LEN (4 * AVTP_QUADLET_SIZE)

Expand Down
4 changes: 2 additions & 2 deletions include/avtp/acf/CanBrief.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include <stdint.h>

#include "avtp/Defines.h"
#include "avtp/acf/Common.h"
#include "avtp/acf/AcfCommon.h"
#include "avtp/acf/Can.h"

#define AVTP_CAN_BRIEF_HEADER_LEN (2 * AVTP_QUADLET_SIZE)
Expand Down Expand Up @@ -141,4 +141,4 @@ int Avtp_CanBrief_SetPayload(Avtp_CanBrief_t* can_pdu, uint32_t frame_id , uint8
* @param payload_length Length of the payload.
* @returns Returns number of processed bytes (header + payload + padding)
*/
int Avtp_CanBrief_Finalize(Avtp_CanBrief_t* can_pdu, uint16_t payload_length);
int Avtp_CanBrief_Finalize(Avtp_CanBrief_t* can_pdu, uint16_t payload_length);
30 changes: 29 additions & 1 deletion include/avtp/acf/FlexRay.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include <stdint.h>

#include "avtp/Defines.h"
#include "avtp/acf/Common.h"
#include "avtp/acf/AcfCommon.h"

/** Length of ACF FlexRay header. */
#define AVTP_FLEXRAY_HEADER_LEN (4 * AVTP_QUADLET_SIZE)
Expand Down Expand Up @@ -88,6 +88,20 @@ void Avtp_FlexRay_Init(Avtp_FlexRay_t* pdu);
*/
uint64_t Avtp_FlexRay_GetField(Avtp_FlexRay_t* pdu, Avtp_FlexRayFields_t field);

uint8_t Avtp_FlexRay_GetAcfMsgType(Avtp_FlexRay_t* pdu);
uint16_t Avtp_FlexRay_GetAcfMsgLength(Avtp_FlexRay_t* pdu);
uint8_t Avtp_FlexRay_GetPad(Avtp_FlexRay_t* pdu);
uint8_t Avtp_FlexRay_GetMtv(Avtp_FlexRay_t* pdu);
uint8_t Avtp_FlexRay_GetFrBusId(Avtp_FlexRay_t* pdu);
uint8_t Avtp_FlexRay_GetChan(Avtp_FlexRay_t* pdu);
uint8_t Avtp_FlexRay_GetStr(Avtp_FlexRay_t* pdu);
uint8_t Avtp_FlexRay_GetSyn(Avtp_FlexRay_t* pdu);
uint8_t Avtp_FlexRay_GetPre(Avtp_FlexRay_t* pdu);
uint8_t Avtp_FlexRay_GetNfi(Avtp_FlexRay_t* pdu);
uint64_t Avtp_FlexRay_GetMessageTimestamp(Avtp_FlexRay_t* pdu);
uint16_t Avtp_FlexRay_GetFrFrameId(Avtp_FlexRay_t* pdu);
uint8_t Avtp_FlexRay_GetCycle(Avtp_FlexRay_t* pdu);

/**
* Sets the value of an ACF FlexRay PDU field.
*
Expand All @@ -97,3 +111,17 @@ uint64_t Avtp_FlexRay_GetField(Avtp_FlexRay_t* pdu, Avtp_FlexRayFields_t field);
* @returns Returns 0 if the data field was successfully set.
*/
void Avtp_FlexRay_SetField(Avtp_FlexRay_t* pdu, Avtp_FlexRayFields_t field, uint64_t value);

void Avtp_FlexRay_SetAcfMsgType(Avtp_FlexRay_t* pdu, uint8_t value);
void Avtp_FlexRay_SetAcfMsgLength(Avtp_FlexRay_t* pdu, uint16_t value);
void Avtp_FlexRay_SetPad(Avtp_FlexRay_t* pdu, uint8_t value);
void Avtp_FlexRay_SetMtv(Avtp_FlexRay_t* pdu, uint8_t value);
void Avtp_FlexRay_SetFrBusId(Avtp_FlexRay_t* pdu, uint8_t value);
void Avtp_FlexRay_SetChan(Avtp_FlexRay_t* pdu, uint8_t value);
void Avtp_FlexRay_SetStr(Avtp_FlexRay_t* pdu, uint8_t value);
void Avtp_FlexRay_SetSyn(Avtp_FlexRay_t* pdu, uint8_t value);
void Avtp_FlexRay_SetPre(Avtp_FlexRay_t* pdu, uint8_t value);
void Avtp_FlexRay_SetNfi(Avtp_FlexRay_t* pdu, uint8_t value);
void Avtp_FlexRay_SetMessageTimestamp(Avtp_FlexRay_t* pdu, uint64_t value);
void Avtp_FlexRay_SetFrFrameId(Avtp_FlexRay_t* pdu, uint16_t value);
void Avtp_FlexRay_SetCycle(Avtp_FlexRay_t* pdu, uint8_t value);
2 changes: 1 addition & 1 deletion include/avtp/acf/Gpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include <stdint.h>

#include "avtp/Defines.h"
#include "avtp/acf/Common.h"
#include "avtp/acf/AcfCommon.h"

#define AVTP_GPC_HEADER_LEN (2 * AVTP_QUADLET_SIZE)

Expand Down
2 changes: 1 addition & 1 deletion include/avtp/acf/Lin.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include <stdint.h>

#include "avtp/Defines.h"
#include "avtp/acf/Common.h"
#include "avtp/acf/AcfCommon.h"

/** Length of ACF Lin header. */
#define AVTP_LIN_HEADER_LEN (3 * AVTP_QUADLET_SIZE)
Expand Down
1 change: 0 additions & 1 deletion src/avtp/acf/Can.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include <errno.h>
#include <string.h>

#include "avtp/acf/Common.h"
#include "avtp/acf/Can.h"
#include "avtp/Utils.h"
#include "avtp/Defines.h"
Expand Down
1 change: 0 additions & 1 deletion src/avtp/acf/CanBrief.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include <errno.h>
#include <string.h>

#include "avtp/acf/Common.h"
#include "avtp/acf/CanBrief.h"
#include "avtp/Utils.h"
#include "avtp/Defines.h"
Expand Down
141 changes: 138 additions & 3 deletions src/avtp/acf/FlexRay.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@
#include <string.h>

#include "avtp/acf/FlexRay.h"
#include "avtp/Utils.h"
#include "avtp/Utils.h"

#define GET_FIELD(field) \
(Avtp_GetField(Avtp_FlexRayFieldDesc, AVTP_FLEXRAY_FIELD_MAX, (uint8_t*)pdu, field))
#define SET_FIELD(field, value) \
(Avtp_SetField(Avtp_FlexRayFieldDesc, AVTP_FLEXRAY_FIELD_MAX, (uint8_t*)pdu, field, value))

/**
* This table describes all the offsets of the ACF FlexRay header fields.
Expand Down Expand Up @@ -67,10 +72,140 @@ void Avtp_FlexRay_Init(Avtp_FlexRay_t* pdu)

uint64_t Avtp_FlexRay_GetField(Avtp_FlexRay_t* pdu, Avtp_FlexRayFields_t field)
{
return Avtp_GetField(Avtp_FlexRayFieldDesc, AVTP_FLEXRAY_FIELD_MAX, (uint8_t*)pdu, (uint8_t)field);
return GET_FIELD(field);
}

uint8_t Avtp_FlexRay_GetAcfMsgType(Avtp_FlexRay_t* pdu)
{
return GET_FIELD(AVTP_FLEXRAY_FIELD_ACF_MSG_TYPE);
}

uint16_t Avtp_FlexRay_GetAcfMsgLength(Avtp_FlexRay_t* pdu)
{
return GET_FIELD(AVTP_FLEXRAY_FIELD_ACF_MSG_LENGTH);
}

uint8_t Avtp_FlexRay_GetPad(Avtp_FlexRay_t* pdu)
{
return GET_FIELD(AVTP_FLEXRAY_FIELD_PAD);
}

uint8_t Avtp_FlexRay_GetMtv(Avtp_FlexRay_t* pdu)
{
return GET_FIELD(AVTP_FLEXRAY_FIELD_MTV);
}

uint8_t Avtp_FlexRay_GetFrBusId(Avtp_FlexRay_t* pdu)
{
return GET_FIELD(AVTP_FLEXRAY_FIELD_FR_BUS_ID);
}

uint8_t Avtp_FlexRay_GetChan(Avtp_FlexRay_t* pdu)
{
return GET_FIELD(AVTP_FLEXRAY_FIELD_CHAN);
}

uint8_t Avtp_FlexRay_GetStr(Avtp_FlexRay_t* pdu)
{
return GET_FIELD(AVTP_FLEXRAY_FIELD_STR);
}

uint8_t Avtp_FlexRay_GetSyn(Avtp_FlexRay_t* pdu)
{
return GET_FIELD(AVTP_FLEXRAY_FIELD_SYN);
}

uint8_t Avtp_FlexRay_GetPre(Avtp_FlexRay_t* pdu)
{
return GET_FIELD(AVTP_FLEXRAY_FIELD_PRE);
}

uint8_t Avtp_FlexRay_GetNfi(Avtp_FlexRay_t* pdu)
{
return GET_FIELD(AVTP_FLEXRAY_FIELD_NFI);
}

uint64_t Avtp_FlexRay_GetMessageTimestamp(Avtp_FlexRay_t* pdu)
{
return GET_FIELD(AVTP_FLEXRAY_FIELD_MESSAGE_TIMESTAMP);
}

uint16_t Avtp_FlexRay_GetFrFrameId(Avtp_FlexRay_t* pdu)
{
return GET_FIELD(AVTP_FLEXRAY_FIELD_FR_FRAME_ID);
}

uint8_t Avtp_FlexRay_GetCycle(Avtp_FlexRay_t* pdu)
{
return GET_FIELD(AVTP_FLEXRAY_FIELD_CYCLE);
}

void Avtp_FlexRay_SetField(Avtp_FlexRay_t* pdu, Avtp_FlexRayFields_t field, uint64_t value)
{
Avtp_SetField(Avtp_FlexRayFieldDesc, AVTP_FLEXRAY_FIELD_MAX, (uint8_t*)pdu, (uint8_t)field, value);
SET_FIELD(field, value);
}

void Avtp_FlexRay_SetAcfMsgType(Avtp_FlexRay_t* pdu, uint8_t value)
{
SET_FIELD(AVTP_FLEXRAY_FIELD_ACF_MSG_TYPE, value);
}

void Avtp_FlexRay_SetAcfMsgLength(Avtp_FlexRay_t* pdu, uint16_t value)
{
SET_FIELD(AVTP_FLEXRAY_FIELD_ACF_MSG_LENGTH, value);
}

void Avtp_FlexRay_SetPad(Avtp_FlexRay_t* pdu, uint8_t value)
{
SET_FIELD(AVTP_FLEXRAY_FIELD_PAD, value);
}

void Avtp_FlexRay_SetMtv(Avtp_FlexRay_t* pdu, uint8_t value)
{
SET_FIELD(AVTP_FLEXRAY_FIELD_MTV, value);
}

void Avtp_FlexRay_SetFrBusId(Avtp_FlexRay_t* pdu, uint8_t value)
{
SET_FIELD(AVTP_FLEXRAY_FIELD_FR_BUS_ID, value);
}

void Avtp_FlexRay_SetChan(Avtp_FlexRay_t* pdu, uint8_t value)
{
SET_FIELD(AVTP_FLEXRAY_FIELD_CHAN, value);
}

void Avtp_FlexRay_SetStr(Avtp_FlexRay_t* pdu, uint8_t value)
{
SET_FIELD(AVTP_FLEXRAY_FIELD_STR, value);
}

void Avtp_FlexRay_SetSyn(Avtp_FlexRay_t* pdu, uint8_t value)
{
SET_FIELD(AVTP_FLEXRAY_FIELD_SYN, value);
}

void Avtp_FlexRay_SetPre(Avtp_FlexRay_t* pdu, uint8_t value)
{
SET_FIELD(AVTP_FLEXRAY_FIELD_PRE, value);
}

void Avtp_FlexRay_SetNfi(Avtp_FlexRay_t* pdu, uint8_t value)
{
SET_FIELD(AVTP_FLEXRAY_FIELD_NFI, value);
}

void Avtp_FlexRay_SetMessageTimestamp(Avtp_FlexRay_t* pdu, uint64_t value)
{
SET_FIELD(AVTP_FLEXRAY_FIELD_MESSAGE_TIMESTAMP, value);
}

void Avtp_FlexRay_SetFrFrameId(Avtp_FlexRay_t* pdu, uint16_t value)
{
SET_FIELD(AVTP_FLEXRAY_FIELD_FR_FRAME_ID, value);
}

void Avtp_FlexRay_SetCycle(Avtp_FlexRay_t* pdu, uint8_t value)
{
SET_FIELD(AVTP_FLEXRAY_FIELD_CYCLE, value);
}
1 change: 0 additions & 1 deletion src/avtp/acf/Gpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include <errno.h>
#include <string.h>

#include "avtp/acf/Common.h"
#include "avtp/acf/Gpc.h"
#include "avtp/Utils.h"
#include "avtp/Defines.h"
Expand Down

0 comments on commit 1e224c1

Please sign in to comment.