From 1aef5af63ad7693452bd7b40480bf23a97e865ab Mon Sep 17 00:00:00 2001 From: Adriaan Niess Date: Fri, 23 Aug 2024 11:19:38 +0200 Subject: [PATCH 01/33] New API for Avtp_GetField Signed-off-by: Adriaan Niess --- include/avtp/CommonHeader.h | 6 ++---- include/avtp/Utils.h | 13 +++++-------- src/avtp/CommonHeader.c | 20 ++++++++++---------- src/avtp/Utils.c | 16 ++++++++-------- 4 files changed, 25 insertions(+), 30 deletions(-) diff --git a/include/avtp/CommonHeader.h b/include/avtp/CommonHeader.h index 54ff590..b155d10 100644 --- a/include/avtp/CommonHeader.h +++ b/include/avtp/CommonHeader.h @@ -89,11 +89,9 @@ typedef enum { * * @param pdu Pointer to the first bit of an 1722 AVTP PDU. * @param field Specifies the position of the data field to be read - * @param value Pointer to location to store the value. - * @returns This function returns 0 if the data field was successfully read from - * the 1722 AVTP PDU. + * @returns This function the value of the specified PDU field */ -int Avtp_CommonHeader_GetField(Avtp_CommonHeader_t* avtp_pdu, Avtp_CommonHeaderField_t field, uint64_t* value); +uint64_t Avtp_CommonHeader_GetField(Avtp_CommonHeader_t* avtp_pdu, Avtp_CommonHeaderField_t field); /** * Sets the value of an an AVTP common header field as specified in the IEEE 1722 Specification. diff --git a/include/avtp/Utils.h b/include/avtp/Utils.h index e611556..0e7d6fc 100644 --- a/include/avtp/Utils.h +++ b/include/avtp/Utils.h @@ -48,13 +48,10 @@ * @param pdu Pointer to the first bit of an 1722 PDU. This is typically an 1722 * AVTP- or an ACF header. * @param field Specifies the position of the data field to be read - * @param value Pointer to store the read value at. - * @returns This function returns 0 if the data field was successfully read from - * the 1722 PDU. + * @returns This function returns the field value from the PDU. */ -int Avtp_GetField(const Avtp_FieldDescriptor_t* fieldDescriptors, uint8_t numFields, uint8_t* pdu, - uint8_t field, uint64_t* value); - +uint64_t Avtp_GetField(const Avtp_FieldDescriptor_t* fieldDescriptors, + uint8_t numFields, uint8_t* pdu, uint8_t field); /** * Sets a data field in a 1722 frame to a specified value and handles necessary @@ -67,6 +64,6 @@ int Avtp_GetField(const Avtp_FieldDescriptor_t* fieldDescriptors, uint8_t numFie * @returns This function returns 0 if the data field was successfully read from * the 1722 PDU. */ -int Avtp_SetField(const Avtp_FieldDescriptor_t* fieldDescriptors, uint8_t numFields, uint8_t* pdu, - uint8_t field, uint64_t value); +int Avtp_SetField(const Avtp_FieldDescriptor_t* fieldDescriptors, + uint8_t numFields, uint8_t* pdu, uint8_t field, uint64_t value); diff --git a/src/avtp/CommonHeader.c b/src/avtp/CommonHeader.c index 1cd6e97..f823bc0 100644 --- a/src/avtp/CommonHeader.c +++ b/src/avtp/CommonHeader.c @@ -43,9 +43,9 @@ static const Avtp_FieldDescriptor_t Avtp_CommonHeaderFieldDesc[AVTP_COMMON_HEADE [AVTP_COMMON_HEADER_FIELD_VERSION] = { .quadlet = 0, .offset = 9, .bits = 3 }, }; -int Avtp_CommonHeader_GetField(Avtp_CommonHeader_t* avtp_pdu, Avtp_CommonHeaderField_t field, uint64_t* value) +uint64_t Avtp_CommonHeader_GetField(Avtp_CommonHeader_t* avtp_pdu, Avtp_CommonHeaderField_t field) { - return Avtp_GetField(Avtp_CommonHeaderFieldDesc, AVTP_COMMON_HEADER_FIELD_MAX, (uint8_t*)avtp_pdu, (uint8_t)field, value); + return Avtp_GetField(Avtp_CommonHeaderFieldDesc, AVTP_COMMON_HEADER_FIELD_MAX, (uint8_t*)avtp_pdu, (uint8_t)field); } int Avtp_CommonHeader_SetField(Avtp_CommonHeader_t* avtp_pdu, Avtp_CommonHeaderField_t field, uint64_t value) @@ -59,17 +59,17 @@ int Avtp_CommonHeader_SetField(Avtp_CommonHeader_t* avtp_pdu, Avtp_CommonHeaderF int avtp_pdu_get(const struct avtp_common_pdu *pdu, Avtp_CommonHeaderField_t field, uint32_t *val) { - uint64_t temp; - int ret; - ret = Avtp_CommonHeader_GetField((Avtp_CommonHeader_t*) pdu, field, &temp); - if (val == NULL) return -EINVAL; - - *val = (uint32_t)temp; - return ret; + if (val == NULL) { + return -EINVAL; + } else { + uint64_t temp = Avtp_CommonHeader_GetField((Avtp_CommonHeader_t*) pdu, field); + *val = (uint32_t)temp; + return 0; + } } int avtp_pdu_set(struct avtp_common_pdu *pdu, Avtp_CommonHeaderField_t field, uint32_t value) { return Avtp_CommonHeader_SetField((Avtp_CommonHeader_t*) pdu, field, value); -} \ No newline at end of file +} diff --git a/src/avtp/Utils.c b/src/avtp/Utils.c index 79a6bdb..7d9dce3 100644 --- a/src/avtp/Utils.c +++ b/src/avtp/Utils.c @@ -42,16 +42,17 @@ int IsFieldDescriptorValid(const Avtp_FieldDescriptor_t* fieldDescriptor) return fieldDescriptor->bits <= 64 && fieldDescriptor->offset <= 31; } -int Avtp_GetField(const Avtp_FieldDescriptor_t* fieldDescriptors, uint8_t numFields, - uint8_t* pdu, uint8_t field, uint64_t* value) +uint64_t Avtp_GetField(const Avtp_FieldDescriptor_t* fieldDescriptors, + uint8_t numFields, uint8_t* pdu, uint8_t field) { - if (pdu == NULL || value == NULL || field >= numFields || !IsFieldDescriptorValid(&fieldDescriptors[field])) { - return -EINVAL; + if (pdu == NULL || field >= numFields + || !IsFieldDescriptorValid(&fieldDescriptors[field])) { + return 0; } const Avtp_FieldDescriptor_t* fieldDescriptor = &fieldDescriptors[field]; - *value = 0; + uint64_t result = 0; uint8_t quadletOffset = 0; uint8_t processedBits = 0; while (processedBits < fieldDescriptor->bits) { @@ -69,16 +70,15 @@ int Avtp_GetField(const Avtp_FieldDescriptor_t* fieldDescriptors, uint8_t numFie uint32_t* quadletPtr = (uint32_t*)(pdu + quadletId * 4); uint32_t quadletHostOrder = Avtp_BeToCpu32(*quadletPtr); uint32_t partialValue = (quadletHostOrder & quadletMask) >> quadletShift; - *value |= (uint64_t)(partialValue) << (fieldDescriptor->bits - processedBits - quadletBits); + result |= (uint64_t)(partialValue) << (fieldDescriptor->bits - processedBits - quadletBits); quadletOffset += 1; processedBits += quadletBits; } - return 0; + return result; } - int Avtp_SetField(const Avtp_FieldDescriptor_t* fieldDescriptors, uint8_t numFields, uint8_t* pdu, uint8_t field, uint64_t value) { From b0ebae00639281096ebab47768d95350915c470c Mon Sep 17 00:00:00 2001 From: Adriaan Niess Date: Fri, 23 Aug 2024 11:28:34 +0200 Subject: [PATCH 02/33] Update Avtp_GetField Signed-off-by: Adriaan Niess --- src/avtp/Utils.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/avtp/Utils.c b/src/avtp/Utils.c index 7d9dce3..a59fc63 100644 --- a/src/avtp/Utils.c +++ b/src/avtp/Utils.c @@ -47,6 +47,7 @@ uint64_t Avtp_GetField(const Avtp_FieldDescriptor_t* fieldDescriptors, { if (pdu == NULL || field >= numFields || !IsFieldDescriptorValid(&fieldDescriptors[field])) { + assert(0); return 0; } From f0bac7b83bcfc737e824779e230d897e8d089223 Mon Sep 17 00:00:00 2001 From: Adriaan Niess Date: Fri, 23 Aug 2024 11:36:26 +0200 Subject: [PATCH 03/33] Update CommonHeader.h/c Signed-off-by: Adriaan Niess --- include/avtp/CommonHeader.h | 15 ++++++++++++ src/avtp/CommonHeader.c | 46 +++++++++++++++++++++++++++++++++---- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/include/avtp/CommonHeader.h b/include/avtp/CommonHeader.h index b155d10..326d4bd 100644 --- a/include/avtp/CommonHeader.h +++ b/include/avtp/CommonHeader.h @@ -93,6 +93,21 @@ typedef enum { */ uint64_t Avtp_CommonHeader_GetField(Avtp_CommonHeader_t* avtp_pdu, Avtp_CommonHeaderField_t field); +/** + * Returns the subtype field of the AVTP common header. + */ +uint8_t Avtp_CommonHeader_GetSubtype(Avtp_CommonHeader_t* avtp_pdu); + +/** + * Returns the header specific field of the AVTP common header. + */ +uint8_t Avtp_CommonHeader_GetH(Avtp_CommonHeader_t* avtp_pdu); + +/** + * Returns the version field of the AVTP common header. + */ +uint8_t Avtp_CommonHeader_GetVersion(Avtp_CommonHeader_t* avtp_pdu); + /** * Sets the value of an an AVTP common header field as specified in the IEEE 1722 Specification. * diff --git a/src/avtp/CommonHeader.c b/src/avtp/CommonHeader.c index f823bc0..a4caf7c 100644 --- a/src/avtp/CommonHeader.c +++ b/src/avtp/CommonHeader.c @@ -43,14 +43,52 @@ static const Avtp_FieldDescriptor_t Avtp_CommonHeaderFieldDesc[AVTP_COMMON_HEADE [AVTP_COMMON_HEADER_FIELD_VERSION] = { .quadlet = 0, .offset = 9, .bits = 3 }, }; -uint64_t Avtp_CommonHeader_GetField(Avtp_CommonHeader_t* avtp_pdu, Avtp_CommonHeaderField_t field) +uint64_t Avtp_CommonHeader_GetField(Avtp_CommonHeader_t* avtp_pdu, + Avtp_CommonHeaderField_t field) { - return Avtp_GetField(Avtp_CommonHeaderFieldDesc, AVTP_COMMON_HEADER_FIELD_MAX, (uint8_t*)avtp_pdu, (uint8_t)field); + return Avtp_GetField( + Avtp_CommonHeaderFieldDesc, + AVTP_COMMON_HEADER_FIELD_MAX, + (uint8_t*)avtp_pdu, + (uint8_t)field); } -int Avtp_CommonHeader_SetField(Avtp_CommonHeader_t* avtp_pdu, Avtp_CommonHeaderField_t field, uint64_t value) +uint8_t Avtp_CommonHeader_GetSubtype(Avtp_CommonHeader_t* avtp_pdu) { - return Avtp_SetField(Avtp_CommonHeaderFieldDesc, AVTP_COMMON_HEADER_FIELD_MAX, (uint8_t*)avtp_pdu, (uint8_t)field, value); + return Avtp_GetField( + Avtp_CommonHeaderFieldDesc, + AVTP_COMMON_HEADER_FIELD_MAX, + (uint8_t*)avtp_pdu, + AVTP_COMMON_HEADER_FIELD_SUBTYPE); +} + +uint8_t Avtp_CommonHeader_GetH(Avtp_CommonHeader_t* avtp_pdu) +{ + return Avtp_GetField( + Avtp_CommonHeaderFieldDesc, + AVTP_COMMON_HEADER_FIELD_MAX, + (uint8_t*)avtp_pdu, + AVTP_COMMON_HEADER_FIELD_H); +} + +uint8_t Avtp_CommonHeader_GetVersion(Avtp_CommonHeader_t* avtp_pdu) +{ + return Avtp_GetField( + Avtp_CommonHeaderFieldDesc, + AVTP_COMMON_HEADER_FIELD_MAX, + (uint8_t*)avtp_pdu, + AVTP_COMMON_HEADER_FIELD_VERSION); +} + +int Avtp_CommonHeader_SetField(Avtp_CommonHeader_t* avtp_pdu, + Avtp_CommonHeaderField_t field, uint64_t value) +{ + return Avtp_SetField( + Avtp_CommonHeaderFieldDesc, + AVTP_COMMON_HEADER_FIELD_MAX, + (uint8_t*)avtp_pdu, + (uint8_t)field, + value); } /****************************************************************************** From 624603e993d1f35c80514a9f262c4a3e90df59fd Mon Sep 17 00:00:00 2001 From: Adriaan Niess Date: Fri, 23 Aug 2024 11:57:17 +0200 Subject: [PATCH 04/33] Update CommonHeader.h/c Signed-off-by: Adriaan Niess --- include/avtp/CommonHeader.h | 17 ++++++++++++++++- include/avtp/Defines.h | 2 +- include/avtp/Utils.h | 5 +---- src/avtp/CommonHeader.c | 35 ++++++++++++++++++++++++++++++++--- src/avtp/Utils.c | 12 +++++------- 5 files changed, 55 insertions(+), 16 deletions(-) diff --git a/include/avtp/CommonHeader.h b/include/avtp/CommonHeader.h index 326d4bd..8b7ff6c 100644 --- a/include/avtp/CommonHeader.h +++ b/include/avtp/CommonHeader.h @@ -117,7 +117,22 @@ uint8_t Avtp_CommonHeader_GetVersion(Avtp_CommonHeader_t* avtp_pdu); * @returns This function returns 0 if the data field was successfully set in * the 1722 AVTP PDU. */ -int Avtp_CommonHeader_SetField(Avtp_CommonHeader_t* avtp_pdu, Avtp_CommonHeaderField_t field, uint64_t value); +void Avtp_CommonHeader_SetField(Avtp_CommonHeader_t* avtp_pdu, Avtp_CommonHeaderField_t field, uint64_t value); + +/** + * Set the subtype field of the AVTP common header. + */ +void Avtp_CommonHeader_SetSubtype(Avtp_CommonHeader_t* avtp_pdu, uint8_t value); + +/** + * Set the header specific field of the AVTP common header. + */ +void Avtp_CommonHeader_SetH(Avtp_CommonHeader_t* avtp_pdu, uint8_t value); + +/** + * Set the version field of the AVTP common header. + */ +void Avtp_CommonHeader_SetVersion(Avtp_CommonHeader_t* avtp_pdu, uint8_t value); /****************************************************************************** * Legacy API (deprecated) diff --git a/include/avtp/Defines.h b/include/avtp/Defines.h index 8b15134..8ae126b 100644 --- a/include/avtp/Defines.h +++ b/include/avtp/Defines.h @@ -41,7 +41,7 @@ #define AVTP_FIELD_MAX_BITS 64 // Sizes of 1722 PDU formats -#define AVTP_QUADLET_SIZE 4 +#define AVTP_QUADLET_SIZE 4 /** * This type describes the position of a data field within an 1722 frame. diff --git a/include/avtp/Utils.h b/include/avtp/Utils.h index 0e7d6fc..34d0abe 100644 --- a/include/avtp/Utils.h +++ b/include/avtp/Utils.h @@ -61,9 +61,6 @@ uint64_t Avtp_GetField(const Avtp_FieldDescriptor_t* fieldDescriptors, * or an ACF header. * @param field Specifies the position of the data field to be written * @param value The value to set. - * @returns This function returns 0 if the data field was successfully read from - * the 1722 PDU. */ -int Avtp_SetField(const Avtp_FieldDescriptor_t* fieldDescriptors, +void Avtp_SetField(const Avtp_FieldDescriptor_t* fieldDescriptors, uint8_t numFields, uint8_t* pdu, uint8_t field, uint64_t value); - diff --git a/src/avtp/CommonHeader.c b/src/avtp/CommonHeader.c index a4caf7c..47db5df 100644 --- a/src/avtp/CommonHeader.c +++ b/src/avtp/CommonHeader.c @@ -80,10 +80,10 @@ uint8_t Avtp_CommonHeader_GetVersion(Avtp_CommonHeader_t* avtp_pdu) AVTP_COMMON_HEADER_FIELD_VERSION); } -int Avtp_CommonHeader_SetField(Avtp_CommonHeader_t* avtp_pdu, +void Avtp_CommonHeader_SetField(Avtp_CommonHeader_t* avtp_pdu, Avtp_CommonHeaderField_t field, uint64_t value) { - return Avtp_SetField( + Avtp_SetField( Avtp_CommonHeaderFieldDesc, AVTP_COMMON_HEADER_FIELD_MAX, (uint8_t*)avtp_pdu, @@ -91,6 +91,30 @@ int Avtp_CommonHeader_SetField(Avtp_CommonHeader_t* avtp_pdu, value); } +void Avtp_CommonHeader_SetSubtype(Avtp_CommonHeader_t* avtp_pdu, uint8_t value) +{ + Avtp_CommonHeader_SetField( + avtp_pdu, + AVTP_COMMON_HEADER_FIELD_SUBTYPE, + value); +} + +void Avtp_CommonHeader_SetH(Avtp_CommonHeader_t* avtp_pdu, uint8_t value) +{ + Avtp_CommonHeader_SetField( + avtp_pdu, + AVTP_COMMON_HEADER_FIELD_H, + value); +} + +void Avtp_CommonHeader_SetVersion(Avtp_CommonHeader_t* avtp_pdu, uint8_t value) +{ + Avtp_CommonHeader_SetField( + avtp_pdu, + AVTP_COMMON_HEADER_FIELD_VERSION, + value); +} + /****************************************************************************** * Legacy API *****************************************************************************/ @@ -109,5 +133,10 @@ int avtp_pdu_get(const struct avtp_common_pdu *pdu, Avtp_CommonHeaderField_t fie int avtp_pdu_set(struct avtp_common_pdu *pdu, Avtp_CommonHeaderField_t field, uint32_t value) { - return Avtp_CommonHeader_SetField((Avtp_CommonHeader_t*) pdu, field, value); + if (pdu == NULL) { + return -EINVAL; + } else { + Avtp_CommonHeader_SetField((Avtp_CommonHeader_t*)pdu, field, value); + return 0; + } } diff --git a/src/avtp/Utils.c b/src/avtp/Utils.c index a59fc63..6cac42e 100644 --- a/src/avtp/Utils.c +++ b/src/avtp/Utils.c @@ -80,11 +80,12 @@ uint64_t Avtp_GetField(const Avtp_FieldDescriptor_t* fieldDescriptors, return result; } -int Avtp_SetField(const Avtp_FieldDescriptor_t* fieldDescriptors, uint8_t numFields, - uint8_t* pdu, uint8_t field, uint64_t value) +void Avtp_SetField(const Avtp_FieldDescriptor_t* fieldDescriptors, + uint8_t numFields, uint8_t* pdu, uint8_t field, uint64_t value) { - if (pdu == NULL || field >= numFields || !IsFieldDescriptorValid(&fieldDescriptors[field])) { - return -EINVAL; + if (pdu == NULL || field >= numFields || + !IsFieldDescriptorValid(&fieldDescriptors[field])) { + assert(0); } const Avtp_FieldDescriptor_t* fieldDescriptor = &fieldDescriptors[field]; @@ -112,7 +113,4 @@ int Avtp_SetField(const Avtp_FieldDescriptor_t* fieldDescriptors, uint8_t numFie quadletOffset += 1; processedBits += quadletBits; } - - return 0; } - From d197673269a4959e9743eabbdea2a2669d80d829 Mon Sep 17 00:00:00 2001 From: Adriaan Niess Date: Fri, 23 Aug 2024 12:38:52 +0200 Subject: [PATCH 05/33] Update CommonHeader.h/c and Crf.h/c Signed-off-by: Adriaan Niess --- include/avtp/CommonHeader.h | 20 ++--- include/avtp/Crf.h | 34 +++++++- src/avtp/CommonHeader.c | 69 +++++----------- src/avtp/Crf.c | 160 ++++++++++++++++++++++++++++++++++-- 4 files changed, 216 insertions(+), 67 deletions(-) diff --git a/include/avtp/CommonHeader.h b/include/avtp/CommonHeader.h index 8b7ff6c..e49b7a2 100644 --- a/include/avtp/CommonHeader.h +++ b/include/avtp/CommonHeader.h @@ -49,7 +49,7 @@ typedef struct { /** * Enumeration over all IEEE 1722 header fields. The naming convention used is - * AVTP__FIELD_. + * AVTP__FIELD_. */ typedef enum Avtp_CommonHeaderField{ /* Common AVTP header fields */ @@ -91,22 +91,22 @@ typedef enum { * @param field Specifies the position of the data field to be read * @returns This function the value of the specified PDU field */ -uint64_t Avtp_CommonHeader_GetField(Avtp_CommonHeader_t* avtp_pdu, Avtp_CommonHeaderField_t field); +uint64_t Avtp_CommonHeader_GetField(Avtp_CommonHeader_t* pdu, Avtp_CommonHeaderField_t field); /** * Returns the subtype field of the AVTP common header. */ -uint8_t Avtp_CommonHeader_GetSubtype(Avtp_CommonHeader_t* avtp_pdu); +uint8_t Avtp_CommonHeader_GetSubtype(Avtp_CommonHeader_t* pdu); /** * Returns the header specific field of the AVTP common header. */ -uint8_t Avtp_CommonHeader_GetH(Avtp_CommonHeader_t* avtp_pdu); +uint8_t Avtp_CommonHeader_GetH(Avtp_CommonHeader_t* pdu); /** * Returns the version field of the AVTP common header. */ -uint8_t Avtp_CommonHeader_GetVersion(Avtp_CommonHeader_t* avtp_pdu); +uint8_t Avtp_CommonHeader_GetVersion(Avtp_CommonHeader_t* pdu); /** * Sets the value of an an AVTP common header field as specified in the IEEE 1722 Specification. @@ -114,25 +114,23 @@ uint8_t Avtp_CommonHeader_GetVersion(Avtp_CommonHeader_t* avtp_pdu); * @param pdu Pointer to the first bit of an 1722 AVTP PDU. * @param field Specifies the position of the data field to be read * @param value Pointer to location to store the value. - * @returns This function returns 0 if the data field was successfully set in - * the 1722 AVTP PDU. */ -void Avtp_CommonHeader_SetField(Avtp_CommonHeader_t* avtp_pdu, Avtp_CommonHeaderField_t field, uint64_t value); +void Avtp_CommonHeader_SetField(Avtp_CommonHeader_t* pdu, Avtp_CommonHeaderField_t field, uint64_t value); /** * Set the subtype field of the AVTP common header. */ -void Avtp_CommonHeader_SetSubtype(Avtp_CommonHeader_t* avtp_pdu, uint8_t value); +void Avtp_CommonHeader_SetSubtype(Avtp_CommonHeader_t* pdu, uint8_t value); /** * Set the header specific field of the AVTP common header. */ -void Avtp_CommonHeader_SetH(Avtp_CommonHeader_t* avtp_pdu, uint8_t value); +void Avtp_CommonHeader_SetH(Avtp_CommonHeader_t* pdu, uint8_t value); /** * Set the version field of the AVTP common header. */ -void Avtp_CommonHeader_SetVersion(Avtp_CommonHeader_t* avtp_pdu, uint8_t value); +void Avtp_CommonHeader_SetVersion(Avtp_CommonHeader_t* pdu, uint8_t value); /****************************************************************************** * Legacy API (deprecated) diff --git a/include/avtp/Crf.h b/include/avtp/Crf.h index c1eb662..0a87ed7 100644 --- a/include/avtp/Crf.h +++ b/include/avtp/Crf.h @@ -78,9 +78,37 @@ typedef enum Avtp_CrfField { int Avtp_Crf_Init(Avtp_Crf_t* pdu); -int Avtp_Crf_GetField(Avtp_Crf_t* pdu, Avtp_CrfField_t field, uint64_t* value); - -int Avtp_Crf_SetField(Avtp_Crf_t* pdu, Avtp_CrfField_t field, uint64_t value); +uint64_t Avtp_Crf_GetField(Avtp_Crf_t* pdu, Avtp_CrfField_t field); + +uint8_t Avtp_Crf_GetSubtype(Avtp_Crf_t* pdu); +uint8_t Avtp_Crf_GetSv(Avtp_Crf_t* pdu); +uint8_t Avtp_Crf_GetVersion(Avtp_Crf_t* pdu); +uint8_t Avtp_Crf_GetMr(Avtp_Crf_t* pdu); +uint8_t Avtp_Crf_GetFs(Avtp_Crf_t* pdu); +uint8_t Avtp_Crf_GetTu(Avtp_Crf_t* pdu); +uint8_t Avtp_Crf_GetSequenceNum(Avtp_Crf_t* pdu); +uint8_t Avtp_Crf_GetType(Avtp_Crf_t* pdu); +uint64_t Avtp_Crf_GetStreamId(Avtp_Crf_t* pdu); +uint8_t Avtp_Crf_GetPull(Avtp_Crf_t* pdu); +uint32_t Avtp_Crf_GetBaseFrequency(Avtp_Crf_t* pdu); +uint16_t Avtp_Crf_GetCrfDataLength(Avtp_Crf_t* pdu); +uint16_t Avtp_Crf_GetTimestampInterval(Avtp_Crf_t* pdu); + +void Avtp_Crf_SetField(Avtp_Crf_t* pdu, Avtp_CrfField_t field, uint64_t value); + +void Avtp_Crf_SetSubtype(Avtp_Crf_t* pdu, uint8_t value); +void Avtp_Crf_SetSv(Avtp_Crf_t* pdu, uint8_t value); +void Avtp_Crf_SetVersion(Avtp_Crf_t* pdu, uint8_t value); +void Avtp_Crf_SetMr(Avtp_Crf_t* pdu, uint8_t value); +void Avtp_Crf_SetFs(Avtp_Crf_t* pdu, uint8_t value); +void Avtp_Crf_SetTu(Avtp_Crf_t* pdu, uint8_t value); +void Avtp_Crf_SetSequenceNum(Avtp_Crf_t* pdu, uint8_t value); +void Avtp_Crf_SetType(Avtp_Crf_t* pdu, uint8_t value); +void Avtp_Crf_SetStreamId(Avtp_Crf_t* pdu, uint64_t value); +void Avtp_Crf_SetPull(Avtp_Crf_t* pdu, uint8_t value); +void Avtp_Crf_SetBaseFrequency(Avtp_Crf_t* pdu, uint32_t value); +void Avtp_Crf_SetCrfDataLength(Avtp_Crf_t* pdu, uint16_t value); +void Avtp_Crf_SetTimestampInterval(Avtp_Crf_t* pdu, uint16_t value); /****************************************************************************** * Legacy API (deprecated) diff --git a/src/avtp/CommonHeader.c b/src/avtp/CommonHeader.c index 47db5df..3f9f2c6 100644 --- a/src/avtp/CommonHeader.c +++ b/src/avtp/CommonHeader.c @@ -33,6 +33,11 @@ #include "avtp/Utils.h" #include "avtp/Defines.h" +#define GET_FIELD(field) \ + (Avtp_GetField(Avtp_CommonHeaderFieldDesc, AVTP_COMMON_HEADER_FIELD_MAX, (uint8_t*)pdu, field)) +#define SET_FIELD(field, value) \ + (Avtp_SetField(Avtp_CommonHeaderFieldDesc, AVTP_COMMON_HEADER_FIELD_MAX, (uint8_t*)pdu, field, value)) + /** * This table maps all IEEE 1722 common header fields to a descriptor. */ @@ -43,76 +48,46 @@ static const Avtp_FieldDescriptor_t Avtp_CommonHeaderFieldDesc[AVTP_COMMON_HEADE [AVTP_COMMON_HEADER_FIELD_VERSION] = { .quadlet = 0, .offset = 9, .bits = 3 }, }; -uint64_t Avtp_CommonHeader_GetField(Avtp_CommonHeader_t* avtp_pdu, +uint64_t Avtp_CommonHeader_GetField(Avtp_CommonHeader_t* pdu, Avtp_CommonHeaderField_t field) { - return Avtp_GetField( - Avtp_CommonHeaderFieldDesc, - AVTP_COMMON_HEADER_FIELD_MAX, - (uint8_t*)avtp_pdu, - (uint8_t)field); + return GET_FIELD(field); } -uint8_t Avtp_CommonHeader_GetSubtype(Avtp_CommonHeader_t* avtp_pdu) +uint8_t Avtp_CommonHeader_GetSubtype(Avtp_CommonHeader_t* pdu) { - return Avtp_GetField( - Avtp_CommonHeaderFieldDesc, - AVTP_COMMON_HEADER_FIELD_MAX, - (uint8_t*)avtp_pdu, - AVTP_COMMON_HEADER_FIELD_SUBTYPE); + return GET_FIELD(AVTP_COMMON_HEADER_FIELD_SUBTYPE); } -uint8_t Avtp_CommonHeader_GetH(Avtp_CommonHeader_t* avtp_pdu) +uint8_t Avtp_CommonHeader_GetH(Avtp_CommonHeader_t* pdu) { - return Avtp_GetField( - Avtp_CommonHeaderFieldDesc, - AVTP_COMMON_HEADER_FIELD_MAX, - (uint8_t*)avtp_pdu, - AVTP_COMMON_HEADER_FIELD_H); + return GET_FIELD(AVTP_COMMON_HEADER_FIELD_H); } -uint8_t Avtp_CommonHeader_GetVersion(Avtp_CommonHeader_t* avtp_pdu) +uint8_t Avtp_CommonHeader_GetVersion(Avtp_CommonHeader_t* pdu) { - return Avtp_GetField( - Avtp_CommonHeaderFieldDesc, - AVTP_COMMON_HEADER_FIELD_MAX, - (uint8_t*)avtp_pdu, - AVTP_COMMON_HEADER_FIELD_VERSION); + return GET_FIELD(AVTP_COMMON_HEADER_FIELD_VERSION); } -void Avtp_CommonHeader_SetField(Avtp_CommonHeader_t* avtp_pdu, +void Avtp_CommonHeader_SetField(Avtp_CommonHeader_t* pdu, Avtp_CommonHeaderField_t field, uint64_t value) { - Avtp_SetField( - Avtp_CommonHeaderFieldDesc, - AVTP_COMMON_HEADER_FIELD_MAX, - (uint8_t*)avtp_pdu, - (uint8_t)field, - value); + SET_FIELD(field, value); } -void Avtp_CommonHeader_SetSubtype(Avtp_CommonHeader_t* avtp_pdu, uint8_t value) +void Avtp_CommonHeader_SetSubtype(Avtp_CommonHeader_t* pdu, uint8_t value) { - Avtp_CommonHeader_SetField( - avtp_pdu, - AVTP_COMMON_HEADER_FIELD_SUBTYPE, - value); + SET_FIELD(AVTP_COMMON_HEADER_FIELD_SUBTYPE, value); } -void Avtp_CommonHeader_SetH(Avtp_CommonHeader_t* avtp_pdu, uint8_t value) +void Avtp_CommonHeader_SetH(Avtp_CommonHeader_t* pdu, uint8_t value) { - Avtp_CommonHeader_SetField( - avtp_pdu, - AVTP_COMMON_HEADER_FIELD_H, - value); + SET_FIELD(AVTP_COMMON_HEADER_FIELD_H, value); } -void Avtp_CommonHeader_SetVersion(Avtp_CommonHeader_t* avtp_pdu, uint8_t value) +void Avtp_CommonHeader_SetVersion(Avtp_CommonHeader_t* pdu, uint8_t value) { - Avtp_CommonHeader_SetField( - avtp_pdu, - AVTP_COMMON_HEADER_FIELD_VERSION, - value); + SET_FIELD(AVTP_COMMON_HEADER_FIELD_VERSION, value); } /****************************************************************************** @@ -121,7 +96,7 @@ void Avtp_CommonHeader_SetVersion(Avtp_CommonHeader_t* avtp_pdu, uint8_t value) int avtp_pdu_get(const struct avtp_common_pdu *pdu, Avtp_CommonHeaderField_t field, uint32_t *val) { - if (val == NULL) { + if (pdu == NULL || val == NULL) { return -EINVAL; } else { uint64_t temp = Avtp_CommonHeader_GetField((Avtp_CommonHeader_t*) pdu, field); diff --git a/src/avtp/Crf.c b/src/avtp/Crf.c index 4f85a06..8798b5a 100644 --- a/src/avtp/Crf.c +++ b/src/avtp/Crf.c @@ -35,6 +35,11 @@ #include "avtp/Utils.h" #include "avtp/CommonHeader.h" +#define GET_FIELD(field) \ + (Avtp_GetField(Avtp_CrfFieldDescriptors, AVTP_CRF_FIELD_MAX, (uint8_t*)pdu, field)) +#define SET_FIELD(field, value) \ + (Avtp_SetField(Avtp_CrfFieldDescriptors, AVTP_CRF_FIELD_MAX, (uint8_t*)pdu, field, value)) + /** * This table maps all IEEE 1722 Clock Reference Format (CRF) specific header fields * to a descriptor. @@ -71,12 +76,144 @@ int Avtp_Crf_Init(Avtp_Crf_t* pdu) { } -int Avtp_Crf_GetField(Avtp_Crf_t* pdu, Avtp_CrfField_t field, uint64_t* value) { - return Avtp_GetField(Avtp_CrfFieldDescriptors, AVTP_CRF_FIELD_MAX, (uint8_t*)pdu, field, value); +uint64_t Avtp_Crf_GetField(Avtp_Crf_t* pdu, Avtp_CrfField_t field) +{ + return GET_FIELD(field); +} + +uint8_t Avtp_Crf_GetSubtype(Avtp_Crf_t* pdu) +{ + return GET_FIELD(AVTP_CRF_FIELD_SUBTYPE); +} + +uint8_t Avtp_Crf_GetSv(Avtp_Crf_t* pdu) +{ + return GET_FIELD(AVTP_CRF_FIELD_SV); +} + +uint8_t Avtp_Crf_GetVersion(Avtp_Crf_t* pdu) +{ + return GET_FIELD(AVTP_CRF_FIELD_VERSION); +} + +uint8_t Avtp_Crf_GetMr(Avtp_Crf_t* pdu) +{ + return GET_FIELD(AVTP_CRF_FIELD_MR); +} + +uint8_t Avtp_Crf_GetFs(Avtp_Crf_t* pdu) +{ + return GET_FIELD(AVTP_CRF_FIELD_FS); } -int Avtp_Crf_SetField(Avtp_Crf_t* pdu, Avtp_CrfField_t field, uint64_t value) { - return Avtp_SetField(Avtp_CrfFieldDescriptors, AVTP_CRF_FIELD_MAX, (uint8_t*)pdu, field, value); +uint8_t Avtp_Crf_GetTu(Avtp_Crf_t* pdu) +{ + return GET_FIELD(AVTP_CRF_FIELD_TU); +} + +uint8_t Avtp_Crf_GetSequenceNum(Avtp_Crf_t* pdu) +{ + return GET_FIELD(AVTP_CRF_FIELD_SEQUENCE_NUM); +} + +uint8_t Avtp_Crf_GetType(Avtp_Crf_t* pdu) +{ + return GET_FIELD(AVTP_CRF_FIELD_TYPE); +} + +uint64_t Avtp_Crf_GetStreamId(Avtp_Crf_t* pdu) +{ + return GET_FIELD(AVTP_CRF_FIELD_STREAM_ID); +} + +uint8_t Avtp_Crf_GetPull(Avtp_Crf_t* pdu) +{ + return GET_FIELD(AVTP_CRF_FIELD_PULL); +} + +uint32_t Avtp_Crf_GetBaseFrequency(Avtp_Crf_t* pdu) +{ + return GET_FIELD(AVTP_CRF_FIELD_BASE_FREQUENCY); +} + +uint16_t Avtp_Crf_GetCrfDataLength(Avtp_Crf_t* pdu) +{ + return GET_FIELD(AVTP_CRF_FIELD_CRF_DATA_LENGTH); +} + +uint16_t Avtp_Crf_GetTimestampInterval(Avtp_Crf_t* pdu) +{ + return GET_FIELD(AVTP_CRF_FIELD_TIMESTAMP_INTERVAL); +} + +void Avtp_Crf_SetField(Avtp_Crf_t* pdu, Avtp_CrfField_t field, uint64_t value) +{ + SET_FIELD(field, value); +} + +void Avtp_Crf_SetSubtype(Avtp_Crf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CRF_FIELD_SUBTYPE, value); +} + +void Avtp_Crf_SetSv(Avtp_Crf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CRF_FIELD_SV, value); +} + +void Avtp_Crf_SetVersion(Avtp_Crf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CRF_FIELD_VERSION, value); +} + +void Avtp_Crf_SetMr(Avtp_Crf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CRF_FIELD_MR, value); +} + +void Avtp_Crf_SetFs(Avtp_Crf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CRF_FIELD_FS, value); +} + +void Avtp_Crf_SetTu(Avtp_Crf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CRF_FIELD_TU, value); +} + +void Avtp_Crf_SetSequenceNum(Avtp_Crf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CRF_FIELD_SEQUENCE_NUM, value); +} + +void Avtp_Crf_SetType(Avtp_Crf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CRF_FIELD_TYPE, value); +} + +void Avtp_Crf_SetStreamId(Avtp_Crf_t* pdu, uint64_t value) +{ + SET_FIELD(AVTP_CRF_FIELD_STREAM_ID, value); +} + +void Avtp_Crf_SetPull(Avtp_Crf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CRF_FIELD_PULL, value); +} + +void Avtp_Crf_SetBaseFrequency(Avtp_Crf_t* pdu, uint32_t value) +{ + SET_FIELD(AVTP_CRF_FIELD_BASE_FREQUENCY, value); +} + +void Avtp_Crf_SetCrfDataLength(Avtp_Crf_t* pdu, uint16_t value) +{ + SET_FIELD(AVTP_CRF_FIELD_CRF_DATA_LENGTH, value); +} + +void Avtp_Crf_SetTimestampInterval(Avtp_Crf_t* pdu, uint16_t value) +{ + SET_FIELD(AVTP_CRF_FIELD_TIMESTAMP_INTERVAL, value); } /****************************************************************************** @@ -85,12 +222,23 @@ int Avtp_Crf_SetField(Avtp_Crf_t* pdu, Avtp_CrfField_t field, uint64_t value) { int avtp_crf_pdu_get(const void *pdu, Avtp_CrfField_t field, uint64_t *val) { - return Avtp_Crf_GetField((Avtp_Crf_t*)pdu, field, val); + if (pdu == NULL || val == NULL) { + return -EINVAL; + } else { + uint64_t temp = Avtp_Crf_GetField((Avtp_Crf_t*)pdu, field); + *val = (uint32_t)temp; + return 0; + } } int avtp_crf_pdu_set(void *pdu, Avtp_CrfField_t field, uint64_t val) { - return Avtp_Crf_SetField((Avtp_Crf_t*)pdu, field, val); + if (pdu == NULL) { + return -EINVAL; + } else { + Avtp_Crf_SetField((Avtp_Crf_t*)pdu, field, val); + return 0; + } } int avtp_crf_pdu_init(void *pdu) From 81a4fe51e2f1815a18275efe0afc0f7ad56cfa73 Mon Sep 17 00:00:00 2001 From: Adriaan Niess Date: Fri, 23 Aug 2024 22:11:15 +0200 Subject: [PATCH 06/33] Update GetField API Signed-off-by: Adriaan Niess --- CMakeLists.txt | 2 +- include/avtp/Rvf.h | 6 +-- include/avtp/Udp.h | 10 ++-- .../aaf/{CommonStream.h => AafCommonStream.h} | 9 ++-- include/avtp/aaf/PcmStream.h | 6 +-- include/avtp/acf/FlexRay.h | 8 ++-- include/avtp/acf/Gpc.h | 12 ++--- src/avtp/Rvf.c | 40 +++++++++------- src/avtp/Udp.c | 16 +++---- .../aaf/{CommonStream.c => AafCommonStream.c} | 10 ++-- src/avtp/aaf/PcmStream.c | 47 ++++++++++--------- src/avtp/acf/FlexRay.c | 20 ++++---- src/avtp/acf/Gpc.c | 25 ++++------ 13 files changed, 100 insertions(+), 111 deletions(-) rename include/avtp/aaf/{CommonStream.h => AafCommonStream.h} (88%) rename src/avtp/aaf/{CommonStream.c => AafCommonStream.c} (88%) diff --git a/CMakeLists.txt b/CMakeLists.txt index f2fe63e..d2d61d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ add_library(open1722 SHARED "src/avtp/Rvf.c" "src/avtp/Udp.c" "src/avtp/Utils.c" - "src/avtp/aaf/CommonStream.c" + "src/avtp/aaf/AafCommonStream.c" "src/avtp/aaf/PcmStream.c" "src/avtp/acf/FlexRay.c" "src/avtp/acf/Gpc.c" diff --git a/include/avtp/Rvf.h b/include/avtp/Rvf.h index 4a078bc..ad08f38 100644 --- a/include/avtp/Rvf.h +++ b/include/avtp/Rvf.h @@ -140,11 +140,11 @@ typedef enum Avtp_RvfColorspace { AVTP_RVF_COLORSPACE_USER = 0x0F } Avtp_RvfColorspace_t; -int Avtp_Rvf_Init(Avtp_Rvf_t* pdu); +void Avtp_Rvf_Init(Avtp_Rvf_t* pdu); -int Avtp_Rvf_GetField(Avtp_Rvf_t* pdu, Avtp_RvfField_t field, uint64_t* value); +uint64_t Avtp_Rvf_GetField(Avtp_Rvf_t* pdu, Avtp_RvfField_t field); -int Avtp_Rvf_SetField(Avtp_Rvf_t* pdu, Avtp_RvfField_t field, uint64_t value); +void Avtp_Rvf_SetField(Avtp_Rvf_t* pdu, Avtp_RvfField_t field, uint64_t value); /****************************************************************************** * Legacy API (deprecated) diff --git a/include/avtp/Udp.h b/include/avtp/Udp.h index 56006f6..ec8b716 100644 --- a/include/avtp/Udp.h +++ b/include/avtp/Udp.h @@ -68,10 +68,9 @@ int Avtp_Udp_Init(Avtp_Udp_t* pdu); * @param pdu Pointer to the first bit of an 1722 AVTP UDP PDU. * @param field Specifies the position of the data field to be read * @param value Pointer to location to store the value. - * @returns This function returns 0 if the data field was successfully read from - * the 1722 AVTP PDU. + * @returns This function returns the value of the field. */ -int Avtp_Udp_GetField(Avtp_Udp_t* pdu, Avtp_UdpFields_t field, uint64_t* value); +uint64_t Avtp_Udp_GetField(Avtp_Udp_t* pdu, Avtp_UdpFields_t field); /** * Sets the value of an an AVTP UDP field as specified in the IEEE 1722 Specification. @@ -79,8 +78,5 @@ int Avtp_Udp_GetField(Avtp_Udp_t* pdu, Avtp_UdpFields_t field, uint64_t* value); * @param pdu Pointer to the first bit of an 1722 AVTP UDP PDU. * @param field Specifies the position of the data field to be read * @param value Pointer to location to store the value. - * @returns This function returns 0 if the data field was successfully set in - * the 1722 AVTP PDU. */ -int Avtp_Udp_SetField(Avtp_Udp_t* pdu, Avtp_UdpFields_t field, uint64_t value); - +void Avtp_Udp_SetField(Avtp_Udp_t* pdu, Avtp_UdpFields_t field, uint64_t value); diff --git a/include/avtp/aaf/CommonStream.h b/include/avtp/aaf/AafCommonStream.h similarity index 88% rename from include/avtp/aaf/CommonStream.h rename to include/avtp/aaf/AafCommonStream.h index 89fd82f..892682e 100644 --- a/include/avtp/aaf/CommonStream.h +++ b/include/avtp/aaf/AafCommonStream.h @@ -72,10 +72,9 @@ typedef enum { * @param pdu Pointer to the first bit of an 1722 AVTP PDU. * @param field Specifies the position of the data field to be read * @param value Pointer to location to store the value. - * @returns This function returns 0 if the data field was successfully read from - * the 1722 AVTP PDU. + * @returns The PDU fieldvalue */ -int Avtp_AafCommonStream_GetField(Avtp_AafCommonStream_t* pdu, Avtp_AafCommonStreamFields_t field, uint64_t* value); +uint64_t Avtp_AafCommonStream_GetField(Avtp_AafCommonStream_t* pdu, Avtp_AafCommonStreamFields_t field); /** * Sets the value of an an AVTP AAF common stream field as specified in the IEEE 1722 Specification. @@ -83,7 +82,5 @@ int Avtp_AafCommonStream_GetField(Avtp_AafCommonStream_t* pdu, Avtp_AafCommonStr * @param pdu Pointer to the first bit of an 1722 AVTP PDU. * @param field Specifies the position of the data field to be read * @param value Pointer to location to store the value. - * @returns This function returns 0 if the data field was successfully set in - * the 1722 AVTP PDU. */ -int Avtp_AafCommonStream_SetField(Avtp_AafCommonStream_t* pdu, Avtp_AafCommonStreamFields_t field, uint64_t value); \ No newline at end of file +void Avtp_AafCommonStream_SetField(Avtp_AafCommonStream_t* pdu, Avtp_AafCommonStreamFields_t field, uint64_t value); \ No newline at end of file diff --git a/include/avtp/aaf/PcmStream.h b/include/avtp/aaf/PcmStream.h index 920f779..632c0ab 100644 --- a/include/avtp/aaf/PcmStream.h +++ b/include/avtp/aaf/PcmStream.h @@ -96,7 +96,7 @@ typedef enum { * * @param pdu Pointer to the first bit of a 1722 PDU. */ -int Avtp_AafPcmStream_Init(Avtp_AafPcmStream_t* pdu); +void Avtp_AafPcmStream_Init(Avtp_AafPcmStream_t* pdu); /** * Returns the value of an an AVTP AAF PCM stream field as specified in the IEEE 1722 Specification. @@ -107,7 +107,7 @@ int Avtp_AafPcmStream_Init(Avtp_AafPcmStream_t* pdu); * @returns This function returns 0 if the data field was successfully read from * the 1722 AVTP PDU. */ -int Avtp_AafPcmStream_GetField(Avtp_AafPcmStream_t* pdu, Avtp_AafPcmStreamFields_t field, uint64_t* value); +uint64_t Avtp_AafPcmStream_GetField(Avtp_AafPcmStream_t* pdu, Avtp_AafPcmStreamFields_t field); /** * Sets the value of an an AVTP AAF PCM stream field as specified in the IEEE 1722 Specification. @@ -118,7 +118,7 @@ int Avtp_AafPcmStream_GetField(Avtp_AafPcmStream_t* pdu, Avtp_AafPcmStreamFields * @returns This function returns 0 if the data field was successfully set in * the 1722 AVTP PDU. */ -int Avtp_AafPcmStream_SetField(Avtp_AafPcmStream_t* pdu, Avtp_AafPcmStreamFields_t field, uint64_t value); +void Avtp_AafPcmStream_SetField(Avtp_AafPcmStream_t* pdu, Avtp_AafPcmStreamFields_t field, uint64_t value); /****************************************************************************** * Legacy API (deprecated) diff --git a/include/avtp/acf/FlexRay.h b/include/avtp/acf/FlexRay.h index 7bc0047..6e4b62a 100644 --- a/include/avtp/acf/FlexRay.h +++ b/include/avtp/acf/FlexRay.h @@ -76,7 +76,7 @@ typedef enum { * * @param pdu Pointer to the first bit of a 1722 ACF FlexRay PDU. */ -int Avtp_FlexRay_Init(Avtp_FlexRay_t* pdu); +void Avtp_FlexRay_Init(Avtp_FlexRay_t* pdu); /** * Returns the value of an ACF FlexRay PDU field. @@ -84,9 +84,9 @@ int Avtp_FlexRay_Init(Avtp_FlexRay_t* pdu); * @param pdu Pointer to the first bit of an 1722 ACF FlexRay PDU. * @param field Data field to be read * @param value Pointer to location to store the value. - * @returns Returns 0 if the data field was successfully read. + * @returns Value of the specified PDU field */ -int Avtp_FlexRay_GetField(Avtp_FlexRay_t* pdu, Avtp_FlexRayFields_t field, uint64_t* value); +uint64_t Avtp_FlexRay_GetField(Avtp_FlexRay_t* pdu, Avtp_FlexRayFields_t field); /** * Sets the value of an ACF FlexRay PDU field. @@ -96,4 +96,4 @@ int Avtp_FlexRay_GetField(Avtp_FlexRay_t* pdu, Avtp_FlexRayFields_t field, uint6 * @param value Pointer to location to store the value. * @returns Returns 0 if the data field was successfully set. */ -int Avtp_FlexRay_SetField(Avtp_FlexRay_t* pdu, Avtp_FlexRayFields_t field, uint64_t value); +void Avtp_FlexRay_SetField(Avtp_FlexRay_t* pdu, Avtp_FlexRayFields_t field, uint64_t value); diff --git a/include/avtp/acf/Gpc.h b/include/avtp/acf/Gpc.h index c7c1c6f..73ec159 100644 --- a/include/avtp/acf/Gpc.h +++ b/include/avtp/acf/Gpc.h @@ -65,7 +65,7 @@ typedef enum { * * @param gpc_pdu Pointer to the first bit of a 1722 ACF GPC PDU. */ -int Avtp_Gpc_Init(Avtp_Gpc_t* gpc_pdu); +void Avtp_Gpc_Init(Avtp_Gpc_t* gpc_pdu); /** * Returns the value of an an ACF GPC PDU field as specified in the IEEE 1722 Specification. @@ -73,10 +73,9 @@ int Avtp_Gpc_Init(Avtp_Gpc_t* gpc_pdu); * @param gpc_pdu Pointer to the first bit of an 1722 ACF GPC PDU. * @param field Specifies the position of the data field to be read * @param value Pointer to location to store the value. - * @returns This function returns 0 if the data field was successfully read from - * the 1722 ACF GPC PDU. + * @returns The value of the GPC field. */ -int Avtp_Gpc_GetField(Avtp_Gpc_t* gpc_pdu, Avtp_GpcFields_t field, uint64_t* value); +uint64_t Avtp_Gpc_GetField(Avtp_Gpc_t* gpc_pdu, Avtp_GpcFields_t field); /** * Sets the value of an an ACF GPC PDU field as specified in the IEEE 1722 Specification. @@ -84,8 +83,5 @@ int Avtp_Gpc_GetField(Avtp_Gpc_t* gpc_pdu, Avtp_GpcFields_t field, uint64_t* val * @param gpc_pdu Pointer to the first bit of an 1722 ACF GPC PDU. * @param field Specifies the position of the data field to be read * @param value Pointer to location to store the value. - * @returns This function returns 0 if the data field was successfully set in - * the 1722 ACF GPC PDU. */ -int Avtp_Gpc_SetField(Avtp_Gpc_t* gpc_pdu, Avtp_GpcFields_t field, uint64_t value); - +void Avtp_Gpc_SetField(Avtp_Gpc_t* gpc_pdu, Avtp_GpcFields_t field, uint64_t value); diff --git a/src/avtp/Rvf.c b/src/avtp/Rvf.c index ffed916..56e7f3a 100644 --- a/src/avtp/Rvf.c +++ b/src/avtp/Rvf.c @@ -75,27 +75,23 @@ static const Avtp_FieldDescriptor_t Avtp_RvfFieldDescriptors[AVTP_RVF_FIELD_MAX] [AVTP_RVF_FIELD_LINE_NUMBER] = { .quadlet = 7, .offset = 16, .bits = 16 }, }; -int Avtp_Rvf_Init(Avtp_Rvf_t* pdu) +void Avtp_Rvf_Init(Avtp_Rvf_t* pdu) { - if (pdu == NULL) { - return -EINVAL; + if (pdu != NULL) { + memset(pdu, 0, sizeof(Avtp_Rvf_t)); + Avtp_Rvf_SetField(pdu, AVTP_RVF_FIELD_SUBTYPE, AVTP_SUBTYPE_RVF); + Avtp_Rvf_SetField(pdu, AVTP_RVF_FIELD_SV, 1); } - - memset(pdu, 0, sizeof(Avtp_Rvf_t)); - Avtp_Rvf_SetField(pdu, AVTP_RVF_FIELD_SUBTYPE, AVTP_SUBTYPE_RVF); - Avtp_Rvf_SetField(pdu, AVTP_RVF_FIELD_SV, 1); - - return 0; } -int Avtp_Rvf_GetField(Avtp_Rvf_t* pdu, Avtp_RvfField_t field, uint64_t* value) +uint64_t Avtp_Rvf_GetField(Avtp_Rvf_t* pdu, Avtp_RvfField_t field) { - return Avtp_GetField(Avtp_RvfFieldDescriptors, AVTP_RVF_FIELD_MAX, (uint8_t*)pdu, field, value); + return Avtp_GetField(Avtp_RvfFieldDescriptors, AVTP_RVF_FIELD_MAX, (uint8_t*)pdu, field); } -int Avtp_Rvf_SetField(Avtp_Rvf_t* pdu, Avtp_RvfField_t field, uint64_t value) +void Avtp_Rvf_SetField(Avtp_Rvf_t* pdu, Avtp_RvfField_t field, uint64_t value) { - return Avtp_SetField(Avtp_RvfFieldDescriptors, AVTP_RVF_FIELD_MAX, (uint8_t*)pdu, field, value); + Avtp_SetField(Avtp_RvfFieldDescriptors, AVTP_RVF_FIELD_MAX, (uint8_t*)pdu, field, value); } /****************************************************************************** @@ -104,15 +100,27 @@ int Avtp_Rvf_SetField(Avtp_Rvf_t* pdu, Avtp_RvfField_t field, uint64_t value) int avtp_rvf_pdu_get(const void* pdu, Avtp_RvfField_t field, uint64_t* val) { - return Avtp_Rvf_GetField((Avtp_Rvf_t*)pdu, field, val); + if (pdu == NULL || val == NULL) { + return -EINVAL; + } else { + return Avtp_Rvf_GetField((Avtp_Rvf_t*)pdu, field); + } } int avtp_rvf_pdu_set(void* pdu, Avtp_RvfField_t field, uint64_t val) { - return Avtp_Rvf_SetField((Avtp_Rvf_t*)pdu, field, val); + if (pdu == NULL) { + return -EINVAL; + } else { + Avtp_Rvf_SetField((Avtp_Rvf_t*)pdu, field, val); + } } int avtp_rvf_pdu_init(void* pdu) { - return Avtp_Rvf_Init((Avtp_Rvf_t*)pdu); + if (pdu == NULL) { + return -EINVAL; + } else { + Avtp_Rvf_Init((Avtp_Rvf_t*)pdu); + } } diff --git a/src/avtp/Udp.c b/src/avtp/Udp.c index 1d951e7..f9b4ed3 100644 --- a/src/avtp/Udp.c +++ b/src/avtp/Udp.c @@ -50,18 +50,18 @@ int Avtp_Udp_Init(Avtp_Udp_t* pdu) { memset(pdu, 0, sizeof(Avtp_Udp_t)); - res = Avtp_SetField(Avtp_UdpFieldDesc, AVTP_UDP_FIELD_MAX, (uint8_t*) pdu, + Avtp_SetField(Avtp_UdpFieldDesc, AVTP_UDP_FIELD_MAX, (uint8_t*) pdu, AVTP_UDP_FIELD_ENCAPSULATION_SEQ_NO, 0); return res; } -int Avtp_Udp_GetField(Avtp_Udp_t* pdu, - Avtp_UdpFields_t field, uint64_t* value) { - return Avtp_GetField(Avtp_UdpFieldDesc, AVTP_UDP_FIELD_MAX, (uint8_t*) pdu, (uint8_t) field, value); +uint64_t Avtp_Udp_GetField(Avtp_Udp_t* pdu, Avtp_UdpFields_t field) +{ + return Avtp_GetField(Avtp_UdpFieldDesc, AVTP_UDP_FIELD_MAX, (uint8_t*) pdu, (uint8_t) field); } -int Avtp_Udp_SetField(Avtp_Udp_t* pdu, - Avtp_UdpFields_t field, uint64_t value) { - return Avtp_SetField(Avtp_UdpFieldDesc, AVTP_UDP_FIELD_MAX, (uint8_t*) pdu, (uint8_t) field, value); -} \ No newline at end of file +void Avtp_Udp_SetField(Avtp_Udp_t* pdu, Avtp_UdpFields_t field, uint64_t value) +{ + Avtp_SetField(Avtp_UdpFieldDesc, AVTP_UDP_FIELD_MAX, (uint8_t*) pdu, (uint8_t) field, value); +} diff --git a/src/avtp/aaf/CommonStream.c b/src/avtp/aaf/AafCommonStream.c similarity index 88% rename from src/avtp/aaf/CommonStream.c rename to src/avtp/aaf/AafCommonStream.c index 5bc65ad..72ca06a 100644 --- a/src/avtp/aaf/CommonStream.c +++ b/src/avtp/aaf/AafCommonStream.c @@ -30,7 +30,7 @@ #include #include "avtp/CommonHeader.h" -#include "avtp/aaf/CommonStream.h" +#include "avtp/aaf/AafCommonStream.h" #include "avtp/Utils.h" static const Avtp_FieldDescriptor_t Avtp_AafCommonStreamFieldDesc[AVTP_AAF_COMMON_STREAM_FIELD_MAX] = @@ -53,12 +53,12 @@ static const Avtp_FieldDescriptor_t Avtp_AafCommonStreamFieldDesc[AVTP_AAF_COMMO [AVTP_AAF_COMMON_STREAM_FIELD_AAF_FORMAT_SPECIFIC_DATA_2] = { .quadlet = 5, .offset = 24, .bits = 8 }, }; -int Avtp_AafCommonStream_GetField(Avtp_AafCommonStream_t* pdu, Avtp_AafCommonStreamFields_t field, uint64_t* value) +uint64_t Avtp_AafCommonStream_GetField(Avtp_AafCommonStream_t* pdu, Avtp_AafCommonStreamFields_t field) { - return Avtp_GetField(Avtp_AafCommonStreamFieldDesc, AVTP_AAF_COMMON_STREAM_FIELD_MAX, (uint8_t*)pdu, (uint8_t) field, value); + return Avtp_GetField(Avtp_AafCommonStreamFieldDesc, AVTP_AAF_COMMON_STREAM_FIELD_MAX, (uint8_t*)pdu, (uint8_t) field); } -int Avtp_AafCommonStream_SetField(Avtp_AafCommonStream_t* pdu, Avtp_AafCommonStreamFields_t field, uint64_t value) +void Avtp_AafCommonStream_SetField(Avtp_AafCommonStream_t* pdu, Avtp_AafCommonStreamFields_t field, uint64_t value) { - return Avtp_SetField(Avtp_AafCommonStreamFieldDesc, AVTP_AAF_COMMON_STREAM_FIELD_MAX, (uint8_t*)pdu, (uint8_t) field, value); + Avtp_SetField(Avtp_AafCommonStreamFieldDesc, AVTP_AAF_COMMON_STREAM_FIELD_MAX, (uint8_t*)pdu, (uint8_t) field, value); } \ No newline at end of file diff --git a/src/avtp/aaf/PcmStream.c b/src/avtp/aaf/PcmStream.c index ba649a6..eba0bd9 100644 --- a/src/avtp/aaf/PcmStream.c +++ b/src/avtp/aaf/PcmStream.c @@ -55,32 +55,23 @@ static const Avtp_FieldDescriptor_t Avtp_AafPcmStreamFieldDesc[AVTP_AAF_PCM_STRE [AVTP_AAF_PCM_STREAM_FIELD_EVT] = { .quadlet = 5, .offset = 20, .bits = 4 }, }; -int Avtp_AafPcmStream_Init(Avtp_AafPcmStream_t* pdu) +void Avtp_AafPcmStream_Init(Avtp_AafPcmStream_t* pdu) { - int res; - - if (!pdu) { - return -EINVAL; + if (pdu != NULL) { + memset(pdu, 0, sizeof(Avtp_AafPcmStream_t)); + Avtp_AafPcmStream_SetField(pdu, AVTP_AAF_PCM_STREAM_FIELD_SUBTYPE, AVTP_SUBTYPE_AAF); + Avtp_AafPcmStream_SetField(pdu, AVTP_AAF_PCM_STREAM_FIELD_SV, 1); } - - memset(pdu, 0, sizeof(Avtp_AafPcmStream_t)); - res = Avtp_AafPcmStream_SetField(pdu, AVTP_AAF_PCM_STREAM_FIELD_SUBTYPE, AVTP_SUBTYPE_AAF); - if (res < 0) return res; - - res = Avtp_AafPcmStream_SetField(pdu, AVTP_AAF_PCM_STREAM_FIELD_SV, 1); - if (res < 0) return res; - - return 0; } -int Avtp_AafPcmStream_GetField(Avtp_AafPcmStream_t* pdu, Avtp_AafPcmStreamFields_t field, uint64_t* value) +uint64_t Avtp_AafPcmStream_GetField(Avtp_AafPcmStream_t* pdu, Avtp_AafPcmStreamFields_t field) { - return Avtp_GetField(Avtp_AafPcmStreamFieldDesc, AVTP_AAF_PCM_STREAM_FIELD_MAX, (uint8_t*)pdu, (uint8_t) field, value); + return Avtp_GetField(Avtp_AafPcmStreamFieldDesc, AVTP_AAF_PCM_STREAM_FIELD_MAX, (uint8_t*)pdu, (uint8_t) field); } -int Avtp_AafPcmStream_SetField(Avtp_AafPcmStream_t* pdu, Avtp_AafPcmStreamFields_t field, uint64_t value) +void Avtp_AafPcmStream_SetField(Avtp_AafPcmStream_t* pdu, Avtp_AafPcmStreamFields_t field, uint64_t value) { - return Avtp_SetField(Avtp_AafPcmStreamFieldDesc, AVTP_AAF_PCM_STREAM_FIELD_MAX, (uint8_t*)pdu, (uint8_t) field, value); + Avtp_SetField(Avtp_AafPcmStreamFieldDesc, AVTP_AAF_PCM_STREAM_FIELD_MAX, (uint8_t*)pdu, (uint8_t) field, value); } /****************************************************************************** @@ -90,13 +81,23 @@ int Avtp_AafPcmStream_SetField(Avtp_AafPcmStream_t* pdu, Avtp_AafPcmStreamFields int avtp_aaf_pdu_get(void *pdu, Avtp_AafPcmStreamFields_t field, uint64_t *val) { - return Avtp_AafPcmStream_GetField((Avtp_AafPcmStream_t*)pdu, field, val); + if (pdu == NULL || val == NULL) { + return -EINVAL; + } else { + *val = Avtp_AafPcmStream_GetField((Avtp_AafPcmStream_t*)pdu, field); + return 0; + } } int avtp_aaf_pdu_set(void *pdu, Avtp_AafPcmStreamFields_t field, uint64_t val) { - return Avtp_AafPcmStream_SetField((Avtp_AafPcmStream_t*)pdu, field, val); + if (pdu == NULL) { + return -EINVAL; + } else { + Avtp_AafPcmStream_SetField((Avtp_AafPcmStream_t*)pdu, field, val); + return 0; + } } int avtp_aaf_pdu_init(void *pdu) @@ -108,13 +109,13 @@ int avtp_aaf_pdu_init(void *pdu) memset(pdu, 0, sizeof(Avtp_AafPcmStream_t)); - res = Avtp_AafPcmStream_SetField(pdu, AVTP_AAF_PCM_STREAM_FIELD_SUBTYPE, AVTP_SUBTYPE_AAF); + res = avtp_aaf_pdu_set(pdu, AVTP_AAF_PCM_STREAM_FIELD_SUBTYPE, AVTP_SUBTYPE_AAF); if (res < 0) return res; - res = Avtp_AafPcmStream_SetField(pdu, AVTP_AAF_PCM_STREAM_FIELD_SV, 1); + res = avtp_aaf_pdu_set(pdu, AVTP_AAF_PCM_STREAM_FIELD_SV, 1); if (res < 0) return res; return 0; -}; \ No newline at end of file +}; diff --git a/src/avtp/acf/FlexRay.c b/src/avtp/acf/FlexRay.c index 21e1d26..0079bb1 100644 --- a/src/avtp/acf/FlexRay.c +++ b/src/avtp/acf/FlexRay.c @@ -57,24 +57,20 @@ static const Avtp_FieldDescriptor_t Avtp_FlexRayFieldDesc[AVTP_FLEXRAY_FIELD_MAX [AVTP_FLEXRAY_FIELD_CYCLE] = { .quadlet = 3, .offset = 26, .bits = 6 }, }; -int Avtp_FlexRay_Init(Avtp_FlexRay_t* pdu) +void Avtp_FlexRay_Init(Avtp_FlexRay_t* pdu) { - if(!pdu) { - return -EINVAL; + if(pdu != NULL) { + memset(pdu, 0, sizeof(Avtp_FlexRay_t)); + Avtp_FlexRay_SetField(pdu, AVTP_FLEXRAY_FIELD_ACF_MSG_TYPE, AVTP_ACF_TYPE_FLEXRAY); } - - memset(pdu, 0, sizeof(Avtp_FlexRay_t)); - Avtp_FlexRay_SetField(pdu, AVTP_FLEXRAY_FIELD_ACF_MSG_TYPE, AVTP_ACF_TYPE_FLEXRAY); - - return 0; } -int Avtp_FlexRay_GetField(Avtp_FlexRay_t* pdu, Avtp_FlexRayFields_t field, uint64_t* value) +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, value); + return Avtp_GetField(Avtp_FlexRayFieldDesc, AVTP_FLEXRAY_FIELD_MAX, (uint8_t*)pdu, (uint8_t)field); } -int Avtp_FlexRay_SetField(Avtp_FlexRay_t* pdu, Avtp_FlexRayFields_t field, uint64_t value) +void Avtp_FlexRay_SetField(Avtp_FlexRay_t* pdu, Avtp_FlexRayFields_t field, uint64_t value) { - return Avtp_SetField(Avtp_FlexRayFieldDesc, AVTP_FLEXRAY_FIELD_MAX, (uint8_t*)pdu, (uint8_t)field, value); + Avtp_SetField(Avtp_FlexRayFieldDesc, AVTP_FLEXRAY_FIELD_MAX, (uint8_t*)pdu, (uint8_t)field, value); } diff --git a/src/avtp/acf/Gpc.c b/src/avtp/acf/Gpc.c index 118322b..911e25a 100644 --- a/src/avtp/acf/Gpc.c +++ b/src/avtp/acf/Gpc.c @@ -47,26 +47,21 @@ static const Avtp_FieldDescriptor_t Avtp_GpcFieldDesc[AVTP_GPC_FIELD_MAX] = [AVTP_GPC_FIELD_GPC_MSG_ID] = { .quadlet = 0, .offset = 16, .bits = 48 }, }; -int Avtp_Gpc_Init(Avtp_Gpc_t* gpc_pdu) +void Avtp_Gpc_Init(Avtp_Gpc_t* gpc_pdu) { - if(!gpc_pdu) { - return -EINVAL; + if(gpc_pdu != NULL) { + memset(gpc_pdu, 0, sizeof(Avtp_Gpc_t)); + Avtp_Gpc_SetField(gpc_pdu, AVTP_GPC_FIELD_ACF_MSG_TYPE, AVTP_ACF_TYPE_GPC); } - - memset(gpc_pdu, 0, sizeof(Avtp_Gpc_t)); - Avtp_Gpc_SetField(gpc_pdu, AVTP_GPC_FIELD_ACF_MSG_TYPE, AVTP_ACF_TYPE_GPC); - - return 0; } -int Avtp_Gpc_GetField(Avtp_Gpc_t* gpc_pdu, - Avtp_GpcFields_t field, uint64_t* value) +uint64_t Avtp_Gpc_GetField(Avtp_Gpc_t* gpc_pdu, Avtp_GpcFields_t field) { - return Avtp_GetField(Avtp_GpcFieldDesc, AVTP_GPC_FIELD_MAX, (uint8_t *) gpc_pdu, (uint8_t) field, value); + return Avtp_GetField(Avtp_GpcFieldDesc, AVTP_GPC_FIELD_MAX, (uint8_t *) gpc_pdu, (uint8_t) field); } -int Avtp_Gpc_SetField(Avtp_Gpc_t* gpc_pdu, - Avtp_GpcFields_t field, uint64_t value) +void Avtp_Gpc_SetField(Avtp_Gpc_t* gpc_pdu, Avtp_GpcFields_t field, + uint64_t value) { - return Avtp_SetField(Avtp_GpcFieldDesc, AVTP_GPC_FIELD_MAX, (uint8_t *) gpc_pdu, (uint8_t) field, value); -} \ No newline at end of file + Avtp_SetField(Avtp_GpcFieldDesc, AVTP_GPC_FIELD_MAX, (uint8_t *) gpc_pdu, (uint8_t) field, value); +} From a83c1e2b12593690877d122229caceb2df91260c Mon Sep 17 00:00:00 2001 From: Adriaan Niess Date: Fri, 23 Aug 2024 22:25:20 +0200 Subject: [PATCH 07/33] Update GetField API for ACF CAN --- include/avtp/acf/Can.h | 18 ++++------ src/avtp/acf/Can.c | 77 +++++++++++++----------------------------- 2 files changed, 29 insertions(+), 66 deletions(-) diff --git a/include/avtp/acf/Can.h b/include/avtp/acf/Can.h index 1ca89dc..5e329cd 100644 --- a/include/avtp/acf/Can.h +++ b/include/avtp/acf/Can.h @@ -79,18 +79,16 @@ typedef enum { * * @param can_pdu Pointer to the first bit of a 1722 ACF CAN PDU. */ -int Avtp_Can_Init(Avtp_Can_t* can_pdu); +void Avtp_Can_Init(Avtp_Can_t* can_pdu); /** * Returns the value of an an ACF CAN PDU field as specified in the IEEE 1722 Specification. * * @param can_pdu Pointer to the first bit of an 1722 ACF CAN PDU. * @param field Specifies the position of the data field to be read - * @param value Pointer to location to store the value. - * @returns This function returns 0 if the data field was successfully read from - * the 1722 ACF CAN PDU. + * @returns Value of the ACF CAN PDU field. */ -int Avtp_Can_GetField(Avtp_Can_t* can_pdu, Avtp_CanFields_t field, uint64_t* value); +uint64_t Avtp_Can_GetField(Avtp_Can_t* can_pdu, Avtp_CanFields_t field); /** * Sets the value of an an ACF CAN PDU field as specified in the IEEE 1722 Specification. @@ -98,10 +96,8 @@ int Avtp_Can_GetField(Avtp_Can_t* can_pdu, Avtp_CanFields_t field, uint64_t* val * @param can_pdu Pointer to the first bit of an 1722 ACF CAN PDU. * @param field Specifies the position of the data field to be read * @param value Pointer to location to store the value. - * @returns This function returns 0 if the data field was successfully set in - * the 1722 ACF CAN PDU. */ -int Avtp_Can_SetField(Avtp_Can_t* can_pdu, Avtp_CanFields_t field, uint64_t value); +void Avtp_Can_SetField(Avtp_Can_t* can_pdu, Avtp_CanFields_t field, uint64_t value); /** * Copies the payload data into the ACF CAN frame. This function will also set the @@ -112,9 +108,8 @@ int Avtp_Can_SetField(Avtp_Can_t* can_pdu, Avtp_CanFields_t field, uint64_t valu * @param payload Pointer to the payload byte array * @param payload_length Length of the payload. * @param can_variant Classic CAN or CAN-FD - * @returns Returns number of processed bytes (header + payload + padding) */ -int Avtp_Can_SetPayload(Avtp_Can_t* can_pdu, uint32_t frame_id , uint8_t* payload, +void Avtp_Can_SetPayload(Avtp_Can_t* can_pdu, uint32_t frame_id , uint8_t* payload, uint16_t payload_length, Avtp_CanVariant_t can_variant); /** @@ -134,6 +129,5 @@ uint8_t* Avtp_Can_GetPayload(Avtp_Can_t* can_pdu, uint16_t* payload_length, uint * @param can_pdu Pointer to the first bit of an 1722 ACF CAN PDU. * @param payload Pointer to the payload byte array * @param payload_length Length of the payload. - * @returns Returns number of processed bytes (header + payload + padding) */ -int Avtp_Can_Finalize(Avtp_Can_t* can_pdu, uint16_t payload_length); \ No newline at end of file +void Avtp_Can_Finalize(Avtp_Can_t* can_pdu, uint16_t payload_length); \ No newline at end of file diff --git a/src/avtp/acf/Can.c b/src/avtp/acf/Can.c index 1b42139..ac06f46 100644 --- a/src/avtp/acf/Can.c +++ b/src/avtp/acf/Can.c @@ -56,58 +56,42 @@ static const Avtp_FieldDescriptor_t Avtp_CanFieldDesc[AVTP_CAN_FIELD_MAX] = [AVTP_CAN_FIELD_CAN_IDENTIFIER] = { .quadlet = 3, .offset = 3, .bits = 29 }, }; -int Avtp_Can_Init(Avtp_Can_t* can_pdu) +void Avtp_Can_Init(Avtp_Can_t* can_pdu) { - if(!can_pdu) { - return -EINVAL; + if(can_pdu != NULL) { + memset(can_pdu, 0, sizeof(Avtp_Can_t)); + Avtp_Can_SetField(can_pdu, AVTP_CAN_FIELD_ACF_MSG_TYPE, AVTP_ACF_TYPE_CAN); } - - memset(can_pdu, 0, sizeof(Avtp_Can_t)); - Avtp_Can_SetField(can_pdu, AVTP_CAN_FIELD_ACF_MSG_TYPE, AVTP_ACF_TYPE_CAN); - - return 0; } -int Avtp_Can_GetField(Avtp_Can_t* can_pdu, - Avtp_CanFields_t field, uint64_t* value) +uint64_t Avtp_Can_GetField(Avtp_Can_t* can_pdu, Avtp_CanFields_t field) { - return Avtp_GetField(Avtp_CanFieldDesc, AVTP_CAN_FIELD_MAX, (uint8_t *) can_pdu, (uint8_t) field, value); + return Avtp_GetField(Avtp_CanFieldDesc, AVTP_CAN_FIELD_MAX, (uint8_t *) can_pdu, (uint8_t) field); } -int Avtp_Can_SetField(Avtp_Can_t* can_pdu, - Avtp_CanFields_t field, uint64_t value) +void Avtp_Can_SetField(Avtp_Can_t* can_pdu, Avtp_CanFields_t field, uint64_t value) { - return Avtp_SetField(Avtp_CanFieldDesc, AVTP_CAN_FIELD_MAX, (uint8_t *) can_pdu, (uint8_t) field, value); + Avtp_SetField(Avtp_CanFieldDesc, AVTP_CAN_FIELD_MAX, (uint8_t *) can_pdu, (uint8_t) field, value); } -int Avtp_Can_SetPayload(Avtp_Can_t* can_pdu, uint32_t frame_id , uint8_t* payload, - uint16_t payload_length, Avtp_CanVariant_t can_variant) { - - int ret = 0; - int eff; - +void Avtp_Can_SetPayload(Avtp_Can_t* can_pdu, uint32_t frame_id , uint8_t* payload, + uint16_t payload_length, Avtp_CanVariant_t can_variant) +{ // Copy the payload into the CAN PDU memcpy(can_pdu->payload, payload, payload_length); // Set the Frame ID and CAN variant - eff = frame_id > 0x7ff? 1 : 0; - ret = Avtp_Can_SetField(can_pdu, AVTP_CAN_FIELD_EFF, eff); - if (ret) return ret; - ret = Avtp_Can_SetField(can_pdu, AVTP_CAN_FIELD_CAN_IDENTIFIER, frame_id); - if (ret) return ret; - ret = Avtp_Can_SetField(can_pdu, AVTP_CAN_FIELD_FDF, (uint8_t) can_variant); - if (ret) return ret; + int eff = frame_id > 0x7ff? 1 : 0; + Avtp_Can_SetField(can_pdu, AVTP_CAN_FIELD_EFF, eff); + Avtp_Can_SetField(can_pdu, AVTP_CAN_FIELD_CAN_IDENTIFIER, frame_id); + Avtp_Can_SetField(can_pdu, AVTP_CAN_FIELD_FDF, (uint8_t) can_variant); // Finalize the AVTP CAN Frame - ret = Avtp_Can_Finalize(can_pdu, payload_length); - - return ret; - + Avtp_Can_Finalize(can_pdu, payload_length); } -int Avtp_Can_Finalize(Avtp_Can_t* can_pdu, uint16_t payload_length) { - - int ret = 0; +void Avtp_Can_Finalize(Avtp_Can_t* can_pdu, uint16_t payload_length) +{ uint8_t padSize; uint32_t avtpCanLength = AVTP_CAN_HEADER_LEN + payload_length; @@ -119,30 +103,15 @@ int Avtp_Can_Finalize(Avtp_Can_t* can_pdu, uint16_t payload_length) { } // Set the length and padding fields - ret = Avtp_Can_SetField(can_pdu, AVTP_CAN_FIELD_ACF_MSG_LENGTH, - (uint64_t) avtpCanLength/AVTP_QUADLET_SIZE); - if (ret) return ret; - ret = Avtp_Can_SetField(can_pdu, AVTP_CAN_FIELD_PAD, padSize); - if (ret) return ret; - - return avtpCanLength; + Avtp_Can_SetField(can_pdu, AVTP_CAN_FIELD_ACF_MSG_LENGTH, (uint64_t) avtpCanLength/AVTP_QUADLET_SIZE); + Avtp_Can_SetField(can_pdu, AVTP_CAN_FIELD_PAD, padSize); } uint8_t* Avtp_Can_GetPayload(Avtp_Can_t* can_pdu, uint16_t* payload_length, uint16_t *pdu_length) { - uint64_t pad_len, pdu_len; - int res = Avtp_Can_GetField((Avtp_Can_t*)can_pdu, AVTP_CAN_FIELD_ACF_MSG_LENGTH, - &pdu_len); - if (res < 0) { - return 0; - } + uint64_t pdu_len = Avtp_Can_GetField((Avtp_Can_t*)can_pdu, AVTP_CAN_FIELD_ACF_MSG_LENGTH); + uint64_t pad_len = Avtp_Can_GetField((Avtp_Can_t*)can_pdu, AVTP_CAN_FIELD_PAD); - res = Avtp_Can_GetField((Avtp_Can_t*)can_pdu, AVTP_CAN_FIELD_PAD, - &pad_len); - if (res < 0) { - return 0; - } - if(payload_length != NULL){ *payload_length = pdu_len*4-AVTP_CAN_HEADER_LEN-pad_len; } @@ -152,4 +121,4 @@ uint8_t* Avtp_Can_GetPayload(Avtp_Can_t* can_pdu, uint16_t* payload_length, uint } return can_pdu->payload; -} \ No newline at end of file +} From 5d413601532384b552a996aa566bf92db0e643c7 Mon Sep 17 00:00:00 2001 From: Adriaan Niess Date: Fri, 23 Aug 2024 22:35:05 +0200 Subject: [PATCH 08/33] Update GetField API for ACF CAN Brief Signed-off-by: Adriaan Niess --- include/avtp/acf/CanBrief.h | 12 +++----- src/avtp/acf/CanBrief.c | 56 +++++++++++++------------------------ 2 files changed, 24 insertions(+), 44 deletions(-) diff --git a/include/avtp/acf/CanBrief.h b/include/avtp/acf/CanBrief.h index 619bf1e..6f8861f 100644 --- a/include/avtp/acf/CanBrief.h +++ b/include/avtp/acf/CanBrief.h @@ -74,18 +74,16 @@ typedef enum { * * @param pdu Pointer to the first bit of a 1722 ACF Abbreviated CAN PDU. */ -int Avtp_CanBrief_Init(Avtp_CanBrief_t* can_pdu); +void Avtp_CanBrief_Init(Avtp_CanBrief_t* can_pdu); /** * Returns the value of an an ACF Abbreviated CAN PDU field as specified in the IEEE 1722 Specification. * * @param pdu Pointer to the first bit of an 1722 ACF Abbreviated CAN PDU. * @param field Specifies the position of the data field to be read - * @param value Pointer to location to store the value. - * @returns This function returns 0 if the data field was successfully read from - * the 1722 ACF Abbreviated CAN PDU. + * @returns Field of CAN Brief PDU. */ -int Avtp_CanBrief_GetField(Avtp_CanBrief_t* can_pdu, Avtp_CanBriefFields_t field, uint64_t* value); +uint64_t Avtp_CanBrief_GetField(Avtp_CanBrief_t* can_pdu, Avtp_CanBriefFields_t field); /** * Sets the value of an an ACF Abbreviated CAN PDU field as specified in the IEEE 1722 Specification. @@ -93,10 +91,8 @@ int Avtp_CanBrief_GetField(Avtp_CanBrief_t* can_pdu, Avtp_CanBriefFields_t field * @param pdu Pointer to the first bit of an 1722 ACF Abbreviated CAN PDU. * @param field Specifies the position of the data field to be read * @param value Pointer to location to store the value. - * @returns This function returns 0 if the data field was successfully set in - * the 1722 ACF Abbreviated CAN PDU. */ -int Avtp_CanBrief_SetField(Avtp_CanBrief_t* can_pdu, Avtp_CanBriefFields_t field, uint64_t value); +void Avtp_CanBrief_SetField(Avtp_CanBrief_t* can_pdu, Avtp_CanBriefFields_t field, uint64_t value); /** * Copies the payload data into the ACF CAN Brief frame. This function will also set the diff --git a/src/avtp/acf/CanBrief.c b/src/avtp/acf/CanBrief.c index ac899a9..725b961 100644 --- a/src/avtp/acf/CanBrief.c +++ b/src/avtp/acf/CanBrief.c @@ -55,56 +55,42 @@ static const Avtp_FieldDescriptor_t Avtp_CanBriefFieldDesc[AVTP_CAN_BRIEF_FIELD_ [AVTP_CAN_BRIEF_FIELD_CAN_IDENTIFIER] = { .quadlet = 1, .offset = 3, .bits = 29 }, }; -int Avtp_CanBrief_Init(Avtp_CanBrief_t* can_pdu) +void Avtp_CanBrief_Init(Avtp_CanBrief_t* can_pdu) { - if(!can_pdu) { - return -EINVAL; + if(can_pdu == NULL) { + memset(can_pdu, 0, sizeof(Avtp_CanBrief_t)); + Avtp_CanBrief_SetField(can_pdu, AVTP_CAN_BRIEF_FIELD_ACF_MSG_TYPE, AVTP_ACF_TYPE_CAN_BRIEF); } - - memset(can_pdu, 0, sizeof(Avtp_CanBrief_t)); - Avtp_CanBrief_SetField(can_pdu, AVTP_CAN_BRIEF_FIELD_ACF_MSG_TYPE, AVTP_ACF_TYPE_CAN_BRIEF); - - return 0; } -int Avtp_CanBrief_GetField(Avtp_CanBrief_t* can_pdu, Avtp_CanBriefFields_t field, uint64_t* value) +uint64_t Avtp_CanBrief_GetField(Avtp_CanBrief_t* can_pdu, Avtp_CanBriefFields_t field) { - return Avtp_GetField(Avtp_CanBriefFieldDesc, AVTP_CAN_BRIEF_FIELD_MAX, (uint8_t *) can_pdu, (uint8_t) field, value); + return Avtp_GetField(Avtp_CanBriefFieldDesc, AVTP_CAN_BRIEF_FIELD_MAX, (uint8_t *) can_pdu, (uint8_t) field); } -int Avtp_CanBrief_SetField(Avtp_CanBrief_t* can_pdu, Avtp_CanBriefFields_t field, uint64_t value) +void Avtp_CanBrief_SetField(Avtp_CanBrief_t* can_pdu, Avtp_CanBriefFields_t field, uint64_t value) { - return Avtp_SetField(Avtp_CanBriefFieldDesc, AVTP_CAN_BRIEF_FIELD_MAX, (uint8_t *) can_pdu, (uint8_t) field, value); + Avtp_SetField(Avtp_CanBriefFieldDesc, AVTP_CAN_BRIEF_FIELD_MAX, (uint8_t *) can_pdu, (uint8_t) field, value); } int Avtp_CanBrief_SetPayload(Avtp_CanBrief_t* can_pdu, uint32_t frame_id , uint8_t* payload, - uint16_t payload_length, Avtp_CanVariant_t can_variant) { - - int ret = 0; - int eff; - + uint16_t payload_length, Avtp_CanVariant_t can_variant) +{ // Copy the payload into the CAN PDU memcpy(can_pdu->payload, payload, payload_length); // Set the Frame ID and CAN variant - eff = frame_id > 0x7ff? 1 : 0; - ret = Avtp_CanBrief_SetField(can_pdu, AVTP_CAN_BRIEF_FIELD_EFF, eff); - if (ret) return ret; - ret = Avtp_CanBrief_SetField(can_pdu, AVTP_CAN_BRIEF_FIELD_CAN_IDENTIFIER, frame_id); - if (ret) return ret; - ret = Avtp_CanBrief_SetField(can_pdu, AVTP_CAN_BRIEF_FIELD_FDF, (uint8_t) can_variant); - if (ret) return ret; + int eff = frame_id > 0x7ff? 1 : 0; + Avtp_CanBrief_SetField(can_pdu, AVTP_CAN_BRIEF_FIELD_EFF, eff); + Avtp_CanBrief_SetField(can_pdu, AVTP_CAN_BRIEF_FIELD_CAN_IDENTIFIER, frame_id); + Avtp_CanBrief_SetField(can_pdu, AVTP_CAN_BRIEF_FIELD_FDF, (uint8_t) can_variant); // Finalize the AVTP CAN Frame - ret = Avtp_CanBrief_Finalize(can_pdu, payload_length); - - return ret; - + return Avtp_CanBrief_Finalize(can_pdu, payload_length); } -int Avtp_CanBrief_Finalize(Avtp_CanBrief_t* can_pdu, uint16_t payload_length) { - - int ret = 0; +int Avtp_CanBrief_Finalize(Avtp_CanBrief_t* can_pdu, uint16_t payload_length) +{ uint8_t padSize; uint32_t avtpCanLength = AVTP_CAN_BRIEF_HEADER_LEN + payload_length; @@ -116,11 +102,9 @@ int Avtp_CanBrief_Finalize(Avtp_CanBrief_t* can_pdu, uint16_t payload_length) { } // Set the length and padding fields - ret = Avtp_CanBrief_SetField(can_pdu, AVTP_CAN_BRIEF_FIELD_ACF_MSG_LENGTH, - (uint64_t) avtpCanLength/AVTP_QUADLET_SIZE); - if (ret) return ret; - ret = Avtp_CanBrief_SetField(can_pdu, AVTP_CAN_BRIEF_FIELD_PAD, padSize); - if (ret) return ret; + Avtp_CanBrief_SetField(can_pdu, AVTP_CAN_BRIEF_FIELD_ACF_MSG_LENGTH, + (uint64_t)avtpCanLength/AVTP_QUADLET_SIZE); + Avtp_CanBrief_SetField(can_pdu, AVTP_CAN_BRIEF_FIELD_PAD, padSize); return avtpCanLength; } From a79ed6e0439a0a54c29e298f78b175903aa335c4 Mon Sep 17 00:00:00 2001 From: Adriaan Niess Date: Fri, 23 Aug 2024 22:37:27 +0200 Subject: [PATCH 09/33] Update ACF CAN API Signed-off-by: Adriaan Niess --- include/avtp/acf/Can.h | 6 ++++-- src/avtp/acf/Can.c | 8 +++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/include/avtp/acf/Can.h b/include/avtp/acf/Can.h index 5e329cd..4cc2ee6 100644 --- a/include/avtp/acf/Can.h +++ b/include/avtp/acf/Can.h @@ -108,8 +108,9 @@ void Avtp_Can_SetField(Avtp_Can_t* can_pdu, Avtp_CanFields_t field, uint64_t val * @param payload Pointer to the payload byte array * @param payload_length Length of the payload. * @param can_variant Classic CAN or CAN-FD + * @returns Returns number of processed bytes (header + payload + padding) */ -void Avtp_Can_SetPayload(Avtp_Can_t* can_pdu, uint32_t frame_id , uint8_t* payload, +int Avtp_Can_SetPayload(Avtp_Can_t* can_pdu, uint32_t frame_id , uint8_t* payload, uint16_t payload_length, Avtp_CanVariant_t can_variant); /** @@ -129,5 +130,6 @@ uint8_t* Avtp_Can_GetPayload(Avtp_Can_t* can_pdu, uint16_t* payload_length, uint * @param can_pdu Pointer to the first bit of an 1722 ACF CAN PDU. * @param payload Pointer to the payload byte array * @param payload_length Length of the payload. + * @returns Returns number of processed bytes (header + payload + padding) */ -void Avtp_Can_Finalize(Avtp_Can_t* can_pdu, uint16_t payload_length); \ No newline at end of file +int Avtp_Can_Finalize(Avtp_Can_t* can_pdu, uint16_t payload_length); diff --git a/src/avtp/acf/Can.c b/src/avtp/acf/Can.c index ac06f46..16b28cb 100644 --- a/src/avtp/acf/Can.c +++ b/src/avtp/acf/Can.c @@ -74,7 +74,7 @@ void Avtp_Can_SetField(Avtp_Can_t* can_pdu, Avtp_CanFields_t field, uint64_t val Avtp_SetField(Avtp_CanFieldDesc, AVTP_CAN_FIELD_MAX, (uint8_t *) can_pdu, (uint8_t) field, value); } -void Avtp_Can_SetPayload(Avtp_Can_t* can_pdu, uint32_t frame_id , uint8_t* payload, +int Avtp_Can_SetPayload(Avtp_Can_t* can_pdu, uint32_t frame_id , uint8_t* payload, uint16_t payload_length, Avtp_CanVariant_t can_variant) { // Copy the payload into the CAN PDU @@ -87,10 +87,10 @@ void Avtp_Can_SetPayload(Avtp_Can_t* can_pdu, uint32_t frame_id , uint8_t* paylo Avtp_Can_SetField(can_pdu, AVTP_CAN_FIELD_FDF, (uint8_t) can_variant); // Finalize the AVTP CAN Frame - Avtp_Can_Finalize(can_pdu, payload_length); + return Avtp_Can_Finalize(can_pdu, payload_length); } -void Avtp_Can_Finalize(Avtp_Can_t* can_pdu, uint16_t payload_length) +int Avtp_Can_Finalize(Avtp_Can_t* can_pdu, uint16_t payload_length) { uint8_t padSize; uint32_t avtpCanLength = AVTP_CAN_HEADER_LEN + payload_length; @@ -105,6 +105,8 @@ void Avtp_Can_Finalize(Avtp_Can_t* can_pdu, uint16_t payload_length) // Set the length and padding fields Avtp_Can_SetField(can_pdu, AVTP_CAN_FIELD_ACF_MSG_LENGTH, (uint64_t) avtpCanLength/AVTP_QUADLET_SIZE); Avtp_Can_SetField(can_pdu, AVTP_CAN_FIELD_PAD, padSize); + + return avtpCanLength; } uint8_t* Avtp_Can_GetPayload(Avtp_Can_t* can_pdu, uint16_t* payload_length, uint16_t *pdu_length) From 271b8b89a8d8545a8f14e58c05ea12db67f8cc0f Mon Sep 17 00:00:00 2001 From: Adriaan Niess Date: Sat, 24 Aug 2024 12:06:33 +0200 Subject: [PATCH 10/33] Update GetField API for Tscf.h/c Signed-off-by: Adriaan Niess --- include/avtp/acf/Tscf.h | 34 ++++++++--- src/avtp/acf/Tscf.c | 123 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 138 insertions(+), 19 deletions(-) diff --git a/include/avtp/acf/Tscf.h b/include/avtp/acf/Tscf.h index abe59d9..bc3228b 100644 --- a/include/avtp/acf/Tscf.h +++ b/include/avtp/acf/Tscf.h @@ -73,18 +73,27 @@ typedef enum { * @param pdu Pointer to the first bit of a 1722 PDU. This is typically an AVTP- * or an ACF header. */ -int Avtp_Tscf_Init(Avtp_Tscf_t* pdu); +void Avtp_Tscf_Init(Avtp_Tscf_t* pdu); /** * Returns the value of an an AVTP TSCF field as specified in the IEEE 1722 Specification. * * @param pdu Pointer to the first bit of an 1722 AVTP PDU. * @param field Specifies the position of the data field to be read - * @param value Pointer to location to store the value. - * @returns This function returns 0 if the data field was successfully read from - * the 1722 AVTP PDU. + * @returns The value of the field. */ -int Avtp_Tscf_GetField(Avtp_Tscf_t* pdu, Avtp_TscfFields_t field, uint64_t* value); +uint64_t Avtp_Tscf_GetField(Avtp_Tscf_t* pdu, Avtp_TscfFields_t field); + +uint8_t Avtp_Tscf_GetSubtype(Avtp_Tscf_t* pdu); +uint8_t Avtp_Tscf_GetSv(Avtp_Tscf_t* pdu); +uint8_t Avtp_Tscf_GetVersion(Avtp_Tscf_t* pdu); +uint8_t Avtp_Tscf_GetMr(Avtp_Tscf_t* pdu); +uint8_t Avtp_Tscf_GetTv(Avtp_Tscf_t* pdu); +uint8_t Avtp_Tscf_GetSequenceNum(Avtp_Tscf_t* pdu); +uint8_t Avtp_Tscf_GetTu(Avtp_Tscf_t* pdu); +uint64_t Avtp_Tscf_GetStreamId(Avtp_Tscf_t* pdu); +uint32_t Avtp_Tscf_GetAvtpTimestamp(Avtp_Tscf_t* pdu); +uint16_t Avtp_Tscf_GetStreamDataLength(Avtp_Tscf_t* pdu); /** * Sets the value of an an AVTP TSCF field as specified in the IEEE 1722 Specification. @@ -92,7 +101,16 @@ int Avtp_Tscf_GetField(Avtp_Tscf_t* pdu, Avtp_TscfFields_t field, uint64_t* valu * @param pdu Pointer to the first bit of an 1722 AVTP PDU. * @param field Specifies the position of the data field to be read * @param value Pointer to location to store the value. - * @returns This function returns 0 if the data field was successfully set in - * the 1722 AVTP PDU. */ -int Avtp_Tscf_SetField(Avtp_Tscf_t* pdu, Avtp_TscfFields_t field, uint64_t value); \ No newline at end of file +void Avtp_Tscf_SetField(Avtp_Tscf_t* pdu, Avtp_TscfFields_t field, uint64_t value); + +void Avtp_Tscf_SetSubtype(Avtp_Tscf_t* pdu, uint8_t value); +void Avtp_Tscf_SetSv(Avtp_Tscf_t* pdu, uint8_t value); +void Avtp_Tscf_SetVersion(Avtp_Tscf_t* pdu, uint8_t value); +void Avtp_Tscf_SetMr(Avtp_Tscf_t* pdu, uint8_t value); +void Avtp_Tscf_SetTv(Avtp_Tscf_t* pdu, uint8_t value); +void Avtp_Tscf_SetSequenceNum(Avtp_Tscf_t* pdu, uint8_t value); +void Avtp_Tscf_SetTu(Avtp_Tscf_t* pdu, uint8_t value); +void Avtp_Tscf_SetStreamId(Avtp_Tscf_t* pdu, uint64_t value); +void Avtp_Tscf_SetAvtpTimestamp(Avtp_Tscf_t* pdu, uint32_t value); +void Avtp_Tscf_SetStreamDataLength(Avtp_Tscf_t* pdu, uint16_t value); diff --git a/src/avtp/acf/Tscf.c b/src/avtp/acf/Tscf.c index 2c013ba..ba4f0fb 100644 --- a/src/avtp/acf/Tscf.c +++ b/src/avtp/acf/Tscf.c @@ -34,6 +34,11 @@ #include "avtp/Utils.h" #include "avtp/CommonHeader.h" +#define GET_FIELD(field) \ + (Avtp_GetField(Avtp_TscfFieldDesc, AVTP_TSCF_FIELD_MAX, (uint8_t*)pdu, field)) +#define SET_FIELD(field, value) \ + (Avtp_SetField(Avtp_TscfFieldDesc, AVTP_TSCF_FIELD_MAX, (uint8_t*)pdu, field, value)) + /** * This table maps all IEEE 1722 TSCF-specific header fields to a descriptor. */ @@ -53,25 +58,121 @@ static const Avtp_FieldDescriptor_t Avtp_TscfFieldDesc[AVTP_TSCF_FIELD_MAX] = [AVTP_TSCF_FIELD_STREAM_DATA_LENGTH] = { .quadlet = 5, .offset = 0, .bits = 16 }, }; -int Avtp_Tscf_Init(Avtp_Tscf_t* pdu) +void Avtp_Tscf_Init(Avtp_Tscf_t* pdu) { - if (!pdu) { - return -EINVAL; + if (pdu != NULL) { + memset(pdu, 0, sizeof(Avtp_Tscf_t)); + Avtp_Tscf_SetField(pdu, AVTP_TSCF_FIELD_SUBTYPE, AVTP_SUBTYPE_TSCF); + Avtp_Tscf_SetField(pdu, AVTP_TSCF_FIELD_SV, 1); } +} + +uint64_t Avtp_Tscf_GetField(Avtp_Tscf_t* pdu, Avtp_TscfFields_t field) +{ + return GET_FIELD(field); +} + +uint8_t Avtp_Tscf_GetSubtype(Avtp_Tscf_t* pdu) +{ + return GET_FIELD(AVTP_TSCF_FIELD_SUBTYPE); +} + +uint8_t Avtp_Tscf_GetSv(Avtp_Tscf_t* pdu) +{ + return GET_FIELD(AVTP_TSCF_FIELD_SV); +} + +uint8_t Avtp_Tscf_GetVersion(Avtp_Tscf_t* pdu) +{ + return GET_FIELD(AVTP_TSCF_FIELD_VERSION); +} + +uint8_t Avtp_Tscf_GetMr(Avtp_Tscf_t* pdu) +{ + return GET_FIELD(AVTP_TSCF_FIELD_MR); +} + +uint8_t Avtp_Tscf_GetTv(Avtp_Tscf_t* pdu) +{ + return GET_FIELD(AVTP_TSCF_FIELD_TV); +} - memset(pdu, 0, sizeof(Avtp_Tscf_t)); - Avtp_Tscf_SetField(pdu, AVTP_TSCF_FIELD_SUBTYPE, AVTP_SUBTYPE_TSCF); - Avtp_Tscf_SetField(pdu, AVTP_TSCF_FIELD_SV, 1); +uint8_t Avtp_Tscf_GetSequenceNum(Avtp_Tscf_t* pdu) +{ + return GET_FIELD(AVTP_TSCF_FIELD_SEQUENCE_NUM); +} - return 0; +uint8_t Avtp_Tscf_GetTu(Avtp_Tscf_t* pdu) +{ + return GET_FIELD(AVTP_TSCF_FIELD_TU); +} + +uint64_t Avtp_Tscf_GetStreamId(Avtp_Tscf_t* pdu) +{ + return GET_FIELD(AVTP_TSCF_FIELD_STREAM_ID); +} + +uint32_t Avtp_Tscf_GetAvtpTimestamp(Avtp_Tscf_t* pdu) +{ + return GET_FIELD(AVTP_TSCF_FIELD_AVTP_TIMESTAMP); +} + +uint16_t Avtp_Tscf_GetStreamDataLength(Avtp_Tscf_t* pdu) +{ + return GET_FIELD(AVTP_TSCF_FIELD_STREAM_DATA_LENGTH); +} + +void Avtp_Tscf_SetField(Avtp_Tscf_t* pdu, Avtp_TscfFields_t field, uint64_t value) +{ + SET_FIELD(field, value); +} + +void Avtp_Tscf_SetSubtype(Avtp_Tscf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_TSCF_FIELD_SUBTYPE, value); +} + +void Avtp_Tscf_SetSv(Avtp_Tscf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_TSCF_FIELD_SV, value); +} + +void Avtp_Tscf_SetVersion(Avtp_Tscf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_TSCF_FIELD_VERSION, value); +} + +void Avtp_Tscf_SetMr(Avtp_Tscf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_TSCF_FIELD_MR, value); +} + +void Avtp_Tscf_SetTv(Avtp_Tscf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_TSCF_FIELD_TV, value); +} + +void Avtp_Tscf_SetSequenceNum(Avtp_Tscf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_TSCF_FIELD_SEQUENCE_NUM, value); +} + +void Avtp_Tscf_SetTu(Avtp_Tscf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_TSCF_FIELD_TU, value); +} + +void Avtp_Tscf_SetStreamId(Avtp_Tscf_t* pdu, uint64_t value) +{ + SET_FIELD(AVTP_TSCF_FIELD_STREAM_ID, value); } -int Avtp_Tscf_GetField(Avtp_Tscf_t* pdu, Avtp_TscfFields_t field, uint64_t* value) +void Avtp_Tscf_SetAvtpTimestamp(Avtp_Tscf_t* pdu, uint32_t value) { - return Avtp_GetField(Avtp_TscfFieldDesc, AVTP_TSCF_FIELD_MAX, (uint8_t*) pdu, (uint8_t) field, value); + SET_FIELD(AVTP_TSCF_FIELD_AVTP_TIMESTAMP, value); } -int Avtp_Tscf_SetField(Avtp_Tscf_t* pdu, Avtp_TscfFields_t field, uint64_t value) +void Avtp_Tscf_SetStreamDataLength(Avtp_Tscf_t* pdu, uint16_t value) { - return Avtp_SetField(Avtp_TscfFieldDesc, AVTP_TSCF_FIELD_MAX, (uint8_t*) pdu, (uint8_t) field, value); + SET_FIELD(AVTP_TSCF_FIELD_STREAM_DATA_LENGTH, value); } From 4f28c35eac502cb1ceee260af114487c09bac87d Mon Sep 17 00:00:00 2001 From: Adriaan Niess Date: Sat, 24 Aug 2024 12:15:17 +0200 Subject: [PATCH 11/33] Update GetField API for Ntscf.h/c Signed-off-by: Adriaan Niess --- include/avtp/acf/Ntscf.h | 26 +++++++++---- src/avtp/acf/Ntscf.c | 83 ++++++++++++++++++++++++++++++++++------ 2 files changed, 90 insertions(+), 19 deletions(-) diff --git a/include/avtp/acf/Ntscf.h b/include/avtp/acf/Ntscf.h index c1b1d5d..63ac860 100644 --- a/include/avtp/acf/Ntscf.h +++ b/include/avtp/acf/Ntscf.h @@ -64,18 +64,23 @@ typedef enum { * @param pdu Pointer to the first bit of a 1722 PDU. This is typically an AVTP- * or an ACF header. */ -int Avtp_Ntscf_Init(Avtp_Ntscf_t* pdu); +void Avtp_Ntscf_Init(Avtp_Ntscf_t* pdu); /** * Returns the value of an an AVTP NTSCF field as specified in the IEEE 1722 Specification. * * @param pdu Pointer to the first bit of an 1722 AVTP PDU. * @param field Specifies the position of the data field to be read - * @param value Pointer to location to store the value. - * @returns This function returns 0 if the data field was successfully read from - * the 1722 AVTP PDU. + * @returns The value of the PDU field. */ -int Avtp_Ntscf_GetField(Avtp_Ntscf_t* pdu, Avtp_NtscfFields_t field, uint64_t* value); +uint64_t Avtp_Ntscf_GetField(Avtp_Ntscf_t* pdu, Avtp_NtscfFields_t field); + +uint8_t Avtp_Ntscf_GetSubtype(Avtp_Ntscf_t* pdu); +uint8_t Avtp_Ntscf_GetSv(Avtp_Ntscf_t* pdu); +uint8_t Avtp_Ntscf_GetVersion(Avtp_Ntscf_t* pdu); +uint16_t Avtp_Ntscf_GetNtscfDataLength(Avtp_Ntscf_t* pdu); +uint8_t Avtp_Ntscf_GetSequenceNum(Avtp_Ntscf_t* pdu); +uint64_t Avtp_Ntscf_GetStreamId(Avtp_Ntscf_t* pdu); /** * Sets the value of an an AVTP NTSCF field as specified in the IEEE 1722 Specification. @@ -83,7 +88,12 @@ int Avtp_Ntscf_GetField(Avtp_Ntscf_t* pdu, Avtp_NtscfFields_t field, uint64_t* v * @param pdu Pointer to the first bit of an 1722 AVTP PDU. * @param field Specifies the position of the data field to be read * @param value Pointer to location to store the value. - * @returns This function returns 0 if the data field was successfully set in - * the 1722 AVTP PDU. */ -int Avtp_Ntscf_SetField(Avtp_Ntscf_t* pdu, Avtp_NtscfFields_t field, uint64_t value); \ No newline at end of file +void Avtp_Ntscf_SetField(Avtp_Ntscf_t* pdu, Avtp_NtscfFields_t field, uint64_t value); + +void Avtp_Ntscf_SetSubtype(Avtp_Ntscf_t* pdu, uint8_t value); +void Avtp_Ntscf_SetSv(Avtp_Ntscf_t* pdu, uint8_t value); +void Avtp_Ntscf_SetVersion(Avtp_Ntscf_t* pdu, uint8_t value); +void Avtp_Ntscf_SetNtscfDataLength(Avtp_Ntscf_t* pdu, uint16_t value); +void Avtp_Ntscf_SetSequenceNum(Avtp_Ntscf_t* pdu, uint8_t value); +void Avtp_Ntscf_SetStreamId(Avtp_Ntscf_t* pdu, uint64_t value); diff --git a/src/avtp/acf/Ntscf.c b/src/avtp/acf/Ntscf.c index 5b3ff59..de20291 100644 --- a/src/avtp/acf/Ntscf.c +++ b/src/avtp/acf/Ntscf.c @@ -35,6 +35,11 @@ #include "avtp/Defines.h" #include "avtp/CommonHeader.h" +#define GET_FIELD(field) \ + (Avtp_GetField(Avtp_NtscfFieldDesc, AVTP_NTSCF_FIELD_MAX, (uint8_t*)pdu, field)) +#define SET_FIELD(field, value) \ + (Avtp_SetField(Avtp_NtscfFieldDesc, AVTP_NTSCF_FIELD_MAX, (uint8_t*)pdu, field, value)) + /** * This table maps all IEEE 1722 NTSCF-specific header fields to a descriptor. */ @@ -50,25 +55,81 @@ static const Avtp_FieldDescriptor_t Avtp_NtscfFieldDesc[AVTP_NTSCF_FIELD_MAX] = [AVTP_NTSCF_FIELD_STREAM_ID] = { .quadlet = 1, .offset = 0, .bits = 64 }, }; -int Avtp_Ntscf_Init(Avtp_Ntscf_t* pdu) +void Avtp_Ntscf_Init(Avtp_Ntscf_t* pdu) { - if (!pdu) { - return -EINVAL; + if (pdu != NULL) { + memset(pdu, 0, sizeof(Avtp_Ntscf_t)); + Avtp_Ntscf_SetField(pdu, AVTP_NTSCF_FIELD_SUBTYPE, AVTP_SUBTYPE_NTSCF); + Avtp_Ntscf_SetField(pdu, AVTP_NTSCF_FIELD_SV, 1); } +} + +uint64_t Avtp_Ntscf_GetField(Avtp_Ntscf_t* pdu, Avtp_NtscfFields_t field) +{ + return GET_FIELD(field); +} + +uint8_t Avtp_Ntscf_GetSubtype(Avtp_Ntscf_t* pdu) +{ + return GET_FIELD(AVTP_NTSCF_FIELD_SUBTYPE); +} + +uint8_t Avtp_Ntscf_GetSv(Avtp_Ntscf_t* pdu) +{ + return GET_FIELD(AVTP_NTSCF_FIELD_SV); +} - memset(pdu, 0, sizeof(Avtp_Ntscf_t)); - Avtp_Ntscf_SetField(pdu, AVTP_NTSCF_FIELD_SUBTYPE, AVTP_SUBTYPE_NTSCF); - Avtp_Ntscf_SetField(pdu, AVTP_NTSCF_FIELD_SV, 1); +uint8_t Avtp_Ntscf_GetVersion(Avtp_Ntscf_t* pdu) +{ + return GET_FIELD(AVTP_NTSCF_FIELD_VERSION); +} - return 0; +uint16_t Avtp_Ntscf_GetNtscfDataLength(Avtp_Ntscf_t* pdu) +{ + return GET_FIELD(AVTP_NTSCF_FIELD_NTSCF_DATA_LENGTH); +} + +uint8_t Avtp_Ntscf_GetSequenceNum(Avtp_Ntscf_t* pdu) +{ + return GET_FIELD(AVTP_NTSCF_FIELD_SEQUENCE_NUM); +} + +uint64_t Avtp_Ntscf_GetStreamId(Avtp_Ntscf_t* pdu) +{ + return GET_FIELD(AVTP_NTSCF_FIELD_STREAM_ID); +} + +void Avtp_Ntscf_SetField(Avtp_Ntscf_t* pdu, Avtp_NtscfFields_t field, uint64_t value) +{ + SET_FIELD(field, value); +} + +void Avtp_Ntscf_SetSubtype(Avtp_Ntscf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_NTSCF_FIELD_SUBTYPE, value); +} + +void Avtp_Ntscf_SetSv(Avtp_Ntscf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_NTSCF_FIELD_SV, value); +} + +void Avtp_Ntscf_SetVersion(Avtp_Ntscf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_NTSCF_FIELD_VERSION, value); +} + +void Avtp_Ntscf_SetNtscfDataLength(Avtp_Ntscf_t* pdu, uint16_t value) +{ + SET_FIELD(AVTP_NTSCF_FIELD_NTSCF_DATA_LENGTH, value); } -int Avtp_Ntscf_GetField(Avtp_Ntscf_t* pdu, Avtp_NtscfFields_t field, uint64_t* value) +void Avtp_Ntscf_SetSequenceNum(Avtp_Ntscf_t* pdu, uint8_t value) { - return Avtp_GetField(Avtp_NtscfFieldDesc, AVTP_NTSCF_FIELD_MAX, (uint8_t*)pdu, (uint8_t) field, value); + SET_FIELD(AVTP_NTSCF_FIELD_SEQUENCE_NUM, value); } -int Avtp_Ntscf_SetField(Avtp_Ntscf_t* pdu, Avtp_NtscfFields_t field, uint64_t value) +void Avtp_Ntscf_SetStreamId(Avtp_Ntscf_t* pdu, uint64_t value) { - return Avtp_SetField(Avtp_NtscfFieldDesc, AVTP_NTSCF_FIELD_MAX, (uint8_t*)pdu, (uint8_t) field, value); + SET_FIELD(AVTP_NTSCF_FIELD_STREAM_ID, value); } From 92d42f4e88450113c71db756a1f6d3fdd15604a2 Mon Sep 17 00:00:00 2001 From: Adriaan Niess Date: Sun, 25 Aug 2024 22:46:08 +0200 Subject: [PATCH 12/33] Update GetField API for Udp.h/c Signed-off-by: Adriaan Niess --- include/avtp/Udp.h | 6 +++++- src/avtp/Udp.c | 38 +++++++++++++++++++++++--------------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/include/avtp/Udp.h b/include/avtp/Udp.h index ec8b716..be01fbc 100644 --- a/include/avtp/Udp.h +++ b/include/avtp/Udp.h @@ -60,7 +60,7 @@ typedef enum { * * @param pdu Pointer to the first bit of an IEEE 1722 UDP PDU. */ -int Avtp_Udp_Init(Avtp_Udp_t* pdu); +void Avtp_Udp_Init(Avtp_Udp_t* pdu); /** * Returns the value of an an AVTP UDP field as specified in the IEEE 1722 Specification. @@ -72,6 +72,8 @@ int Avtp_Udp_Init(Avtp_Udp_t* pdu); */ uint64_t Avtp_Udp_GetField(Avtp_Udp_t* pdu, Avtp_UdpFields_t field); +uint32_t Avtp_Udp_GetEncapsulationSeqNo(Avtp_Udp_t* pdu); + /** * Sets the value of an an AVTP UDP field as specified in the IEEE 1722 Specification. * @@ -80,3 +82,5 @@ uint64_t Avtp_Udp_GetField(Avtp_Udp_t* pdu, Avtp_UdpFields_t field); * @param value Pointer to location to store the value. */ void Avtp_Udp_SetField(Avtp_Udp_t* pdu, Avtp_UdpFields_t field, uint64_t value); + +void Avtp_Udp_SetEncapsulationSeqNo(Avtp_Udp_t* pdu, uint32_t value); diff --git a/src/avtp/Udp.c b/src/avtp/Udp.c index f9b4ed3..cf1f583 100644 --- a/src/avtp/Udp.c +++ b/src/avtp/Udp.c @@ -33,6 +33,11 @@ #include "avtp/Utils.h" #include "avtp/Defines.h" +#define GET_FIELD(field) \ + (Avtp_GetField(Avtp_UdpFieldDesc, AVTP_UDP_FIELD_MAX, (uint8_t*)pdu, field)) +#define SET_FIELD(field, value) \ + (Avtp_SetField(Avtp_UdpFieldDesc, AVTP_UDP_FIELD_MAX, (uint8_t*)pdu, field, value)) + /** * This table maps all IEEE 1722 UDP-specific header fields to a descriptor. */ @@ -41,27 +46,30 @@ static const Avtp_FieldDescriptor_t Avtp_UdpFieldDesc[AVTP_UDP_FIELD_MAX] = { [AVTP_UDP_FIELD_ENCAPSULATION_SEQ_NO] = { .quadlet = 0, .offset = 0, .bits = 32 }, }; -int Avtp_Udp_Init(Avtp_Udp_t* pdu) { - - int res = 0; - - if (!pdu) - return -EINVAL; - - memset(pdu, 0, sizeof(Avtp_Udp_t)); - - Avtp_SetField(Avtp_UdpFieldDesc, AVTP_UDP_FIELD_MAX, (uint8_t*) pdu, - AVTP_UDP_FIELD_ENCAPSULATION_SEQ_NO, 0); - - return res; +void Avtp_Udp_Init(Avtp_Udp_t* pdu) +{ + if (pdu != NULL) { + memset(pdu, 0, sizeof(Avtp_Udp_t)); + Avtp_Udp_SetEncapsulationSeqNo(pdu, 0); + } } uint64_t Avtp_Udp_GetField(Avtp_Udp_t* pdu, Avtp_UdpFields_t field) { - return Avtp_GetField(Avtp_UdpFieldDesc, AVTP_UDP_FIELD_MAX, (uint8_t*) pdu, (uint8_t) field); + return GET_FIELD(field); +} + +uint32_t Avtp_Udp_GetEncapsulationSeqNo(Avtp_Udp_t* pdu) +{ + return GET_FIELD(AVTP_UDP_FIELD_ENCAPSULATION_SEQ_NO); } void Avtp_Udp_SetField(Avtp_Udp_t* pdu, Avtp_UdpFields_t field, uint64_t value) { - Avtp_SetField(Avtp_UdpFieldDesc, AVTP_UDP_FIELD_MAX, (uint8_t*) pdu, (uint8_t) field, value); + SET_FIELD(field, value); +} + +void Avtp_Udp_SetEncapsulationSeqNo(Avtp_Udp_t* pdu, uint32_t value) +{ + SET_FIELD(AVTP_UDP_FIELD_ENCAPSULATION_SEQ_NO, value); } From 78b032eedf91770a5e0731cf25ce9694102ac109 Mon Sep 17 00:00:00 2001 From: Adriaan Niess Date: Sun, 25 Aug 2024 23:12:45 +0200 Subject: [PATCH 13/33] Update GetField API for Rvf.h/c Signed-off-by: Adriaan Niess --- include/avtp/Rvf.h | 54 +++++++++- src/avtp/Rvf.c | 261 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 311 insertions(+), 4 deletions(-) diff --git a/include/avtp/Rvf.h b/include/avtp/Rvf.h index ad08f38..4e6c7b8 100644 --- a/include/avtp/Rvf.h +++ b/include/avtp/Rvf.h @@ -26,7 +26,7 @@ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * SPDX-License-Identifier: BSD-3-Clause + * SPDX-License-Identifier: BSD3-Clause */ #pragma once @@ -144,8 +144,60 @@ void Avtp_Rvf_Init(Avtp_Rvf_t* pdu); uint64_t Avtp_Rvf_GetField(Avtp_Rvf_t* pdu, Avtp_RvfField_t field); +uint8_t Avtp_Rvf_GetSubtype(Avtp_Rvf_t* pdu); +uint8_t Avtp_Rvf_GetSv(Avtp_Rvf_t* pdu); +uint8_t Avtp_Rvf_GetVersion(Avtp_Rvf_t* pdu); +uint8_t Avtp_Rvf_GetMr(Avtp_Rvf_t* pdu); +uint8_t Avtp_Rvf_GetTv(Avtp_Rvf_t* pdu); +uint8_t Avtp_Rvf_GetSequenceNum(Avtp_Rvf_t* pdu); +uint8_t Avtp_Rvf_GetTu(Avtp_Rvf_t* pdu); +uint64_t Avtp_Rvf_GetStreamId(Avtp_Rvf_t* pdu); +uint32_t Avtp_Rvf_GetAvtpTimestamp(Avtp_Rvf_t* pdu); +uint16_t Avtp_Rvf_GetActivePixels(Avtp_Rvf_t* pdu); +uint16_t Avtp_Rvf_GetTotalLines(Avtp_Rvf_t* pdu); +uint16_t Avtp_Rvf_GetStreamDataLength(Avtp_Rvf_t* pdu); +uint8_t Avtp_Rvf_GetAp(Avtp_Rvf_t* pdu); +uint8_t Avtp_Rvf_GetF(Avtp_Rvf_t* pdu); +uint8_t Avtp_Rvf_GetEf(Avtp_Rvf_t* pdu); +uint8_t Avtp_Rvf_GetEvt(Avtp_Rvf_t* pdu); +uint8_t Avtp_Rvf_GetPd(Avtp_Rvf_t* pdu); +uint8_t Avtp_Rvf_GetI(Avtp_Rvf_t* pdu); +uint8_t Avtp_Rvf_GetPixelDepth(Avtp_Rvf_t* pdu); +uint8_t Avtp_Rvf_GetPixelFormat(Avtp_Rvf_t* pdu); +uint8_t Avtp_Rvf_GetFrameRate(Avtp_Rvf_t* pdu); +uint8_t Avtp_Rvf_GetColorspace(Avtp_Rvf_t* pdu); +uint8_t Avtp_Rvf_GetNumLines(Avtp_Rvf_t* pdu); +uint8_t Avtp_Rvf_GetISeqNum(Avtp_Rvf_t* pdu); +uint16_t Avtp_Rvf_GetLineNumber(Avtp_Rvf_t* pdu); + void Avtp_Rvf_SetField(Avtp_Rvf_t* pdu, Avtp_RvfField_t field, uint64_t value); +void Avtp_Rvf_SetSubtype(Avtp_Rvf_t* pdu, uint8_t value); +void Avtp_Rvf_SetSv(Avtp_Rvf_t* pdu, uint8_t value); +void Avtp_Rvf_SetVersion(Avtp_Rvf_t* pdu, uint8_t value); +void Avtp_Rvf_SetMr(Avtp_Rvf_t* pdu, uint8_t value); +void Avtp_Rvf_SetTv(Avtp_Rvf_t* pdu, uint8_t value); +void Avtp_Rvf_SetSequenceNum(Avtp_Rvf_t* pdu, uint8_t value); +void Avtp_Rvf_SetTu(Avtp_Rvf_t* pdu, uint8_t value); +void Avtp_Rvf_SetStreamId(Avtp_Rvf_t* pdu, uint64_t value); +void Avtp_Rvf_SetAvtpTimestamp(Avtp_Rvf_t* pdu, uint32_t value); +void Avtp_Rvf_SetActivePixels(Avtp_Rvf_t* pdu, uint16_t value); +void Avtp_Rvf_SetTotalLines(Avtp_Rvf_t* pdu, uint16_t value); +void Avtp_Rvf_SetStreamDataLength(Avtp_Rvf_t* pdu, uint16_t value); +void Avtp_Rvf_SetAp(Avtp_Rvf_t* pdu, uint8_t value); +void Avtp_Rvf_setF(Avtp_Rvf_t* pdu, uint8_t value); +void Avtp_Rvf_SetEf(Avtp_Rvf_t* pdu, uint8_t value); +void Avtp_Rvf_SetEvt(Avtp_Rvf_t* pdu, uint8_t value); +void Avtp_Rvf_SetPd(Avtp_Rvf_t* pdu, uint8_t value); +void Avtp_Rvf_SetI(Avtp_Rvf_t* pdu, uint8_t value); +void Avtp_Rvf_SetPixelDepth(Avtp_Rvf_t* pdu, uint8_t value); +void Avtp_Rvf_SetPixelFormat(Avtp_Rvf_t* pdu, uint8_t value); +void Avtp_Rvf_SetFrameRate(Avtp_Rvf_t* pdu, uint8_t value); +void Avtp_Rvf_SetColorspace(Avtp_Rvf_t* pdu, uint8_t value); +void Avtp_Rvf_SetNumLines(Avtp_Rvf_t* pdu, uint8_t value); +void Avtp_Rvf_SetISeqNum(Avtp_Rvf_t* pdu, uint8_t value); +void Avtp_Rvf_SetLineNumber(Avtp_Rvf_t* pdu, uint16_t value); + /****************************************************************************** * Legacy API (deprecated) *****************************************************************************/ diff --git a/src/avtp/Rvf.c b/src/avtp/Rvf.c index 56e7f3a..12d6aba 100644 --- a/src/avtp/Rvf.c +++ b/src/avtp/Rvf.c @@ -36,11 +36,16 @@ #include "avtp/Utils.h" #include "avtp/CommonHeader.h" +#define GET_FIELD(field) \ + (Avtp_GetField(Avtp_RvfFieldDesc, AVTP_RVF_FIELD_MAX, (uint8_t*)pdu, field)) +#define SET_FIELD(field, value) \ + (Avtp_SetField(Avtp_RvfFieldDesc, AVTP_RVF_FIELD_MAX, (uint8_t*)pdu, field, value)) + /** * This table maps all IEEE 1722 Raw Video Format (RVF) specific header fields * to a descriptor. */ -static const Avtp_FieldDescriptor_t Avtp_RvfFieldDescriptors[AVTP_RVF_FIELD_MAX] = +static const Avtp_FieldDescriptor_t Avtp_RvfFieldDesc[AVTP_RVF_FIELD_MAX] = { [AVTP_RVF_FIELD_SUBTYPE] = { .quadlet = 0, .offset = 0, .bits = 8 }, [AVTP_RVF_FIELD_SV] = { .quadlet = 0, .offset = 8, .bits = 1 }, @@ -86,12 +91,262 @@ void Avtp_Rvf_Init(Avtp_Rvf_t* pdu) uint64_t Avtp_Rvf_GetField(Avtp_Rvf_t* pdu, Avtp_RvfField_t field) { - return Avtp_GetField(Avtp_RvfFieldDescriptors, AVTP_RVF_FIELD_MAX, (uint8_t*)pdu, field); + return GET_FIELD(field); +} + +uint8_t Avtp_Rvf_GetSubtype(Avtp_Rvf_t* pdu) +{ + return GET_FIELD(AVTP_RVF_FIELD_SUBTYPE); +} + +uint8_t Avtp_Rvf_GetSv(Avtp_Rvf_t* pdu) +{ + return GET_FIELD(AVTP_RVF_FIELD_SV); +} + +uint8_t Avtp_Rvf_GetVersion(Avtp_Rvf_t* pdu) +{ + return GET_FIELD(AVTP_RVF_FIELD_VERSION); +} + +uint8_t Avtp_Rvf_GetMr(Avtp_Rvf_t* pdu) +{ + return GET_FIELD(AVTP_RVF_FIELD_MR); +} + +uint8_t Avtp_Rvf_GetTv(Avtp_Rvf_t* pdu) +{ + return GET_FIELD(AVTP_RVF_FIELD_TV); +} + +uint8_t Avtp_Rvf_GetSequenceNum(Avtp_Rvf_t* pdu) +{ + return GET_FIELD(AVTP_RVF_FIELD_SEQUENCE_NUM); +} + +uint8_t Avtp_Rvf_GetTu(Avtp_Rvf_t* pdu) +{ + return GET_FIELD(AVTP_RVF_FIELD_TU); +} + +uint64_t Avtp_Rvf_GetStreamId(Avtp_Rvf_t* pdu) +{ + return GET_FIELD(AVTP_RVF_FIELD_STREAM_ID); +} + +uint32_t Avtp_Rvf_GetAvtpTimestamp(Avtp_Rvf_t* pdu) +{ + return GET_FIELD(AVTP_RVF_FIELD_AVTP_TIMESTAMP); +} + +uint16_t Avtp_Rvf_GetActivePixels(Avtp_Rvf_t* pdu) +{ + return GET_FIELD(AVTP_RVF_FIELD_ACTIVE_PIXELS); +} + +uint16_t Avtp_Rvf_GetTotalLines(Avtp_Rvf_t* pdu) +{ + return GET_FIELD(AVTP_RVF_FIELD_TOTAL_LINES); +} + +uint16_t Avtp_Rvf_GetStreamDataLength(Avtp_Rvf_t* pdu) +{ + return GET_FIELD(AVTP_RVF_FIELD_STREAM_DATA_LEN); +} + +uint8_t Avtp_Rvf_GetAp(Avtp_Rvf_t* pdu) +{ + return GET_FIELD(AVTP_RVF_FIELD_AP); +} + +uint8_t Avtp_Rvf_GetF(Avtp_Rvf_t* pdu) +{ + return GET_FIELD(AVTP_RVF_FIELD_F); +} + +uint8_t Avtp_Rvf_GetEf(Avtp_Rvf_t* pdu) +{ + return GET_FIELD(AVTP_RVF_FIELD_EF); +} + +uint8_t Avtp_Rvf_GetEvt(Avtp_Rvf_t* pdu) +{ + return GET_FIELD(AVTP_RVF_FIELD_EVT); +} + +uint8_t Avtp_Rvf_GetPd(Avtp_Rvf_t* pdu) +{ + return GET_FIELD(AVTP_RVF_FIELD_PD); +} + +uint8_t Avtp_Rvf_GetI(Avtp_Rvf_t* pdu) +{ + return GET_FIELD(AVTP_RVF_FIELD_I); +} + +uint8_t Avtp_Rvf_GetPixelDepth(Avtp_Rvf_t* pdu) +{ + return GET_FIELD(AVTP_RVF_FIELD_PIXEL_DEPTH); +} + +uint8_t Avtp_Rvf_GetPixelFormat(Avtp_Rvf_t* pdu) +{ + return GET_FIELD(AVTP_RVF_FIELD_PIXEL_FORMAT); +} + +uint8_t Avtp_Rvf_GetFrameRate(Avtp_Rvf_t* pdu) +{ + return GET_FIELD(AVTP_RVF_FIELD_FRAME_RATE); +} + +uint8_t Avtp_Rvf_GetColorspace(Avtp_Rvf_t* pdu) +{ + return GET_FIELD(AVTP_RVF_FIELD_COLORSPACE); +} + +uint8_t Avtp_Rvf_GetNumLines(Avtp_Rvf_t* pdu) +{ + return GET_FIELD(AVTP_RVF_FIELD_NUM_LINES); +} + +uint8_t Avtp_Rvf_GetISeqNum(Avtp_Rvf_t* pdu) +{ + return GET_FIELD(AVTP_RVF_FIELD_I_SEQ_NUM); +} + +uint16_t Avtp_Rvf_GetLineNumber(Avtp_Rvf_t* pdu) +{ + return GET_FIELD(AVTP_RVF_FIELD_LINE_NUMBER); } void Avtp_Rvf_SetField(Avtp_Rvf_t* pdu, Avtp_RvfField_t field, uint64_t value) { - Avtp_SetField(Avtp_RvfFieldDescriptors, AVTP_RVF_FIELD_MAX, (uint8_t*)pdu, field, value); + SET_FIELD(field, value); +} + +void Avtp_Rvf_SetSubtype(Avtp_Rvf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_RVF_FIELD_SUBTYPE, value); +} + +void Avtp_Rvf_SetSv(Avtp_Rvf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_RVF_FIELD_SV, value); +} + +void Avtp_Rvf_SetVersion(Avtp_Rvf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_RVF_FIELD_VERSION, value); +} + +void Avtp_Rvf_SetMr(Avtp_Rvf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_RVF_FIELD_MR, value); +} + +void Avtp_Rvf_SetTv(Avtp_Rvf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_RVF_FIELD_TV, value); +} + +void Avtp_Rvf_SetSequenceNum(Avtp_Rvf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_RVF_FIELD_SEQ_NUM, value); +} + +void Avtp_Rvf_SetTu(Avtp_Rvf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_RVF_FIELD_TU, value); +} + +void Avtp_Rvf_SetStreamId(Avtp_Rvf_t* pdu, uint64_t value) +{ + SET_FIELD(AVTP_RVF_FIELD_STREAM_ID, value); +} + +void Avtp_Rvf_SetAvtpTimestamp(Avtp_Rvf_t* pdu, uint32_t value) +{ + SET_FIELD(AVTP_RVF_FIELD_AVTP_TIMESTAMP, value); +} + +void Avtp_Rvf_SetActivePixels(Avtp_Rvf_t* pdu, uint16_t value) +{ + SET_FIELD(AVTP_RVF_FIELD_ACTIVE_PIXELS, value); +} + +void Avtp_Rvf_SetTotalLines(Avtp_Rvf_t* pdu, uint16_t value) +{ + SET_FIELD(AVTP_RVF_FIELD_TOTAL_LINES, value); +} + +void Avtp_Rvf_SetStreamDataLength(Avtp_Rvf_t* pdu, uint16_t value) +{ + SET_FIELD(AVTP_RVF_FIELD_STREAM_DATA_LEN, value); +} + +void Avtp_Rvf_SetAp(Avtp_Rvf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_RVF_FIELD_AP, value); +} + +void Avtp_Rvf_setF(Avtp_Rvf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_RVF_FIELD_F, value); +} + +void Avtp_Rvf_SetEf(Avtp_Rvf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_RVF_FIELD_EF, value); +} + +void Avtp_Rvf_SetEvt(Avtp_Rvf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_RVF_FIELD_EVT, value); +} + +void Avtp_Rvf_SetPd(Avtp_Rvf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_RVF_FIELD_PD, value); +} + +void Avtp_Rvf_SetI(Avtp_Rvf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_RVF_FIELD_I, value); +} + +void Avtp_Rvf_SetPixelDepth(Avtp_Rvf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_RVF_FIELD_PIXEL_DEPTH, value); +} + +void Avtp_Rvf_SetPixelFormat(Avtp_Rvf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_RVF_FIELD_PIXEL_FORMAT, value); +} + +void Avtp_Rvf_SetFrameRate(Avtp_Rvf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_RVF_FIELD_FRAME_RATE, value); +} + +void Avtp_Rvf_SetColorspace(Avtp_Rvf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_RVF_FIELD_COLORSPACE, value); +} + +void Avtp_Rvf_SetNumLines(Avtp_Rvf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_RVF_FIELD_NUM_LINES, value); +} + +void Avtp_Rvf_SetISeqNum(Avtp_Rvf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_RVF_FIELD_I_SEQ_NUM, value); +} + +void Avtp_Rvf_SetLineNumber(Avtp_Rvf_t* pdu, uint16_t value) +{ + SET_FIELD(AVTP_RVF_FIELD_LINE_NUMBER, value); } /****************************************************************************** From 3577868b0b8cc67bea2ce4af30ba509c4abaae8a Mon Sep 17 00:00:00 2001 From: Adriaan Niess Date: Sun, 25 Aug 2024 23:29:12 +0200 Subject: [PATCH 14/33] Update GetField API for Can.h/c Signed-off-by: Adriaan Niess --- include/avtp/acf/Can.h | 26 +++++++++ src/avtp/acf/Can.c | 128 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 150 insertions(+), 4 deletions(-) diff --git a/include/avtp/acf/Can.h b/include/avtp/acf/Can.h index 4cc2ee6..bb04207 100644 --- a/include/avtp/acf/Can.h +++ b/include/avtp/acf/Can.h @@ -90,6 +90,19 @@ void Avtp_Can_Init(Avtp_Can_t* can_pdu); */ uint64_t Avtp_Can_GetField(Avtp_Can_t* can_pdu, Avtp_CanFields_t field); +uint8_t Avtp_Can_GetAcfMsgType(Avtp_Can_t* pdu); +uint16_t Avtp_Can_GetAcfMsgLength(Avtp_Can_t* pdu); +uint8_t Avtp_Can_GetPad(Avtp_Can_t* pdu); +uint8_t Avtp_Can_GetMtv(Avtp_Can_t* pdu); +uint8_t Avtp_Can_GetRtr(Avtp_Can_t* pdu); +uint8_t Avtp_Can_GetEff(Avtp_Can_t* pdu); +uint8_t Avtp_Can_GetBrs(Avtp_Can_t* pdu); +uint8_t Avtp_Can_GetFdf(Avtp_Can_t* pdu); +uint8_t Avtp_Can_GetEsi(Avtp_Can_t* pdu); +uint8_t Avtp_Can_GetCanBusId(Avtp_Can_t* pdu); +uint64_t Avtp_Can_GetMessageTimestamp(Avtp_Can_t* pdu); +uint32_t Avtp_Can_GetCanIdentifier(Avtp_Can_t* pdu); + /** * Sets the value of an an ACF CAN PDU field as specified in the IEEE 1722 Specification. * @@ -99,6 +112,19 @@ uint64_t Avtp_Can_GetField(Avtp_Can_t* can_pdu, Avtp_CanFields_t field); */ void Avtp_Can_SetField(Avtp_Can_t* can_pdu, Avtp_CanFields_t field, uint64_t value); +void Avtp_Can_SetAcfMsgType(Avtp_Can_t* pdu, uint8_t value); +void Avtp_Can_SetAcfMsgLength(Avtp_Can_t* pdu, uint16_t value); +void Avtp_Can_SetPad(Avtp_Can_t* pdu, uint8_t value); +void Avtp_Can_SetMtv(Avtp_Can_t* pdu, uint8_t value); +void Avtp_Can_SetRtr(Avtp_Can_t* pdu, uint8_t value); +void Avtp_Can_SetEff(Avtp_Can_t* pdu, uint8_t value); +void Avtp_Can_SetBrs(Avtp_Can_t* pdu, uint8_t value); +void Avtp_Can_SetFdf(Avtp_Can_t* pdu, uint8_t value); +void Avtp_Can_SetEsi(Avtp_Can_t* pdu, uint8_t value); +void Avtp_Can_SetCanBusId(Avtp_Can_t* pdu, uint8_t value); +void Avtp_Can_SetMessageTimestamp(Avtp_Can_t* pdu, uint64_t value); +void Avtp_Can_SetCanIdentifier(Avtp_Can_t* pdu, uint32_t value); + /** * Copies the payload data into the ACF CAN frame. This function will also set the * length and pad fields while inserting the padded bytes. diff --git a/src/avtp/acf/Can.c b/src/avtp/acf/Can.c index 16b28cb..d40de70 100644 --- a/src/avtp/acf/Can.c +++ b/src/avtp/acf/Can.c @@ -65,13 +65,133 @@ void Avtp_Can_Init(Avtp_Can_t* can_pdu) } uint64_t Avtp_Can_GetField(Avtp_Can_t* can_pdu, Avtp_CanFields_t field) -{ - return Avtp_GetField(Avtp_CanFieldDesc, AVTP_CAN_FIELD_MAX, (uint8_t *) can_pdu, (uint8_t) field); +{ + return GET_FIELD(field); +} + +uint8_t Avtp_Can_GetAcfMsgType(Avtp_Can_t* pdu) +{ + return GET_FIELD(AVTP_CAN_FIELD_ACF_MSG_TYPE); +} + +uint16_t Avtp_Can_GetAcfMsgLength(Avtp_Can_t* pdu) +{ + return GET_FIELD(AVTP_CAN_FIELD_ACF_MSG_LENGTH); +} + +uint8_t Avtp_Can_GetPad(Avtp_Can_t* pdu) +{ + return GET_FIELD(AVTP_CAN_FIELD_PAD); +} + +uint8_t Avtp_Can_GetMtv(Avtp_Can_t* pdu) +{ + return GET_FIELD(AVTP_CAN_FIELD_MTV); +} + +uint8_t Avtp_Can_GetRtr(Avtp_Can_t* pdu) +{ + return GET_FIELD(AVTP_CAN_FIELD_RTR); +} + +uint8_t Avtp_Can_GetEff(Avtp_Can_t* pdu) +{ + return GET_FIELD(AVTP_CAN_FIELD_EFF); +} + +uint8_t Avtp_Can_GetBrs(Avtp_Can_t* pdu) +{ + return GET_FIELD(AVTP_CAN_FIELD_BRS); +} + +uint8_t Avtp_Can_GetFdf(Avtp_Can_t* pdu) +{ + return GET_FIELD(AVTP_CAN_FIELD_FDF); +} + +uint8_t Avtp_Can_GetEsi(Avtp_Can_t* pdu) +{ + return GET_FIELD(AVTP_CAN_FIELD_ESI); +} + +uint8_t Avtp_Can_GetCanBusId(Avtp_Can_t* pdu) +{ + return GET_FIELD(AVTP_CAN_FIELD_CAN_BUS_ID); +} + +uint64_t Avtp_Can_GetMessageTimestamp(Avtp_Can_t* pdu) +{ + return GET_FIELD(AVTP_CAN_FIELD_MESSAGE_TIMESTAMP); +} + +uint32_t Avtp_Can_GetCanIdentifier(Avtp_Can_t* pdu) +{ + return GET_FIELD(AVTP_CAN_FIELD_CAN_IDENTIFIER); } void Avtp_Can_SetField(Avtp_Can_t* can_pdu, Avtp_CanFields_t field, uint64_t value) -{ - Avtp_SetField(Avtp_CanFieldDesc, AVTP_CAN_FIELD_MAX, (uint8_t *) can_pdu, (uint8_t) field, value); +{ + SET_FIELD(field, value); +} + +void Avtp_Can_SetAcfMsgType(Avtp_Can_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CAN_FIELD_ACF_MSG_TYPE, value); +} + +void Avtp_Can_SetAcfMsgLength(Avtp_Can_t* pdu, uint16_t value) +{ + SET_FIELD(AVTP_CAN_FIELD_ACF_MSG_LENGTH, value); +} + +void Avtp_Can_SetPad(Avtp_Can_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CAN_FIELD_PAD, value); +} + +void Avtp_Can_SetMtv(Avtp_Can_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CAN_FIELD_MTV, value); +} + +void Avtp_Can_SetRtr(Avtp_Can_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CAN_FIELD_RTR, value); +} + +void Avtp_Can_SetEff(Avtp_Can_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CAN_FIELD_EFF, value); +} + +void Avtp_Can_SetBrs(Avtp_Can_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CAN_FIELD_BRS, value); +} + +void Avtp_Can_SetFdf(Avtp_Can_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CAN_FIELD_FDF, value); +} + +void Avtp_Can_SetEsi(Avtp_Can_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CAN_FIELD_ESI, value); +} + +void Avtp_Can_SetCanBusId(Avtp_Can_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CAN_FIELD_CAN_BUS_ID, value); +} + +void Avtp_Can_SetMessageTimestamp(Avtp_Can_t* pdu, uint64_t value) +{ + SET_FIELD(AVTP_CAN_FIELD_MESSAGE_TIMESTAMP, value); +} + +void Avtp_Can_SetCanIdentifier(Avtp_Can_t* pdu, uint32_t value) +{ + SET_FIELD(AVTP_CAN_FIELD_CAN_IDENTIFIER, value); } int Avtp_Can_SetPayload(Avtp_Can_t* can_pdu, uint32_t frame_id , uint8_t* payload, From 7777a6c28df68de924bc1f21f201715ccf257142 Mon Sep 17 00:00:00 2001 From: Adriaan Niess Date: Sun, 25 Aug 2024 23:45:49 +0200 Subject: [PATCH 15/33] Update GetField API for CanBrief.h/c Signed-off-by: Adriaan Niess --- include/avtp/acf/CanBrief.h | 28 ++++++- src/avtp/acf/Can.c | 45 ++++++----- src/avtp/acf/CanBrief.c | 151 +++++++++++++++++++++++++++++++----- 3 files changed, 184 insertions(+), 40 deletions(-) diff --git a/include/avtp/acf/CanBrief.h b/include/avtp/acf/CanBrief.h index 6f8861f..60d3c36 100644 --- a/include/avtp/acf/CanBrief.h +++ b/include/avtp/acf/CanBrief.h @@ -74,7 +74,7 @@ typedef enum { * * @param pdu Pointer to the first bit of a 1722 ACF Abbreviated CAN PDU. */ -void Avtp_CanBrief_Init(Avtp_CanBrief_t* can_pdu); +void Avtp_CanBrief_Init(Avtp_CanBrief_t* pdu); /** * Returns the value of an an ACF Abbreviated CAN PDU field as specified in the IEEE 1722 Specification. @@ -83,7 +83,19 @@ void Avtp_CanBrief_Init(Avtp_CanBrief_t* can_pdu); * @param field Specifies the position of the data field to be read * @returns Field of CAN Brief PDU. */ -uint64_t Avtp_CanBrief_GetField(Avtp_CanBrief_t* can_pdu, Avtp_CanBriefFields_t field); +uint64_t Avtp_CanBrief_GetField(Avtp_CanBrief_t* pdu, Avtp_CanBriefFields_t field); + +uint8_t Avtp_CanBrief_GetAcfMsgType(Avtp_CanBrief_t* pdu); +uint16_t Avtp_CanBrief_GetAcfMsgLength(Avtp_CanBrief_t* pdu); +uint8_t Avtp_CanBrief_GetPad(Avtp_CanBrief_t* pdu); +uint8_t Avtp_CanBrief_GetMtv(Avtp_CanBrief_t* pdu); +uint8_t Avtp_CanBrief_GetRtr(Avtp_CanBrief_t* pdu); +uint8_t Avtp_CanBrief_GetEff(Avtp_CanBrief_t* pdu); +uint8_t Avtp_CanBrief_GetBrs(Avtp_CanBrief_t* pdu); +uint8_t Avtp_CanBrief_GetFdf(Avtp_CanBrief_t* pdu); +uint8_t Avtp_CanBrief_GetEsi(Avtp_CanBrief_t* pdu); +uint8_t Avtp_CanBrief_GetCanBusId(Avtp_CanBrief_t* pdu); +uint32_t Avtp_CanBrief_GetCanIdentifier(Avtp_CanBrief_t* pdu); /** * Sets the value of an an ACF Abbreviated CAN PDU field as specified in the IEEE 1722 Specification. @@ -94,6 +106,18 @@ uint64_t Avtp_CanBrief_GetField(Avtp_CanBrief_t* can_pdu, Avtp_CanBriefFields_t */ void Avtp_CanBrief_SetField(Avtp_CanBrief_t* can_pdu, Avtp_CanBriefFields_t field, uint64_t value); +void Avtp_CanBrief_SetAcfMsgType(Avtp_CanBrief_t* pdu, uint8_t value); +void Avtp_CanBrief_SetAcfMsgLength(Avtp_CanBrief_t* pdu, uint16_t value); +void Avtp_CanBrief_SetPad(Avtp_CanBrief_t* pdu, uint8_t value); +void Avtp_CanBrief_SetMtv(Avtp_CanBrief_t* pdu, uint8_t value); +void Avtp_CanBrief_SetRtr(Avtp_CanBrief_t* pdu, uint8_t value); +void Avtp_CanBrief_SetEff(Avtp_CanBrief_t* pdu, uint8_t value); +void Avtp_CanBrief_SetBrs(Avtp_CanBrief_t* pdu, uint8_t value); +void Avtp_CanBrief_SetFdf(Avtp_CanBrief_t* pdu, uint8_t value); +void Avtp_CanBrief_SetEsi(Avtp_CanBrief_t* pdu, uint8_t value); +void Avtp_CanBrief_SetCanBusId(Avtp_CanBrief_t* pdu, uint8_t value); +void Avtp_CanBrief_SetCanIdentifier(Avtp_CanBrief_t* pdu, uint32_t value); + /** * Copies the payload data into the ACF CAN Brief frame. This function will also set the * length and pad fields while inserting the padded bytes. diff --git a/src/avtp/acf/Can.c b/src/avtp/acf/Can.c index d40de70..d2e029d 100644 --- a/src/avtp/acf/Can.c +++ b/src/avtp/acf/Can.c @@ -35,6 +35,11 @@ #include "avtp/Utils.h" #include "avtp/Defines.h" +#define GET_FIELD(field) \ + (Avtp_GetField(Avtp_CanFieldDesc, AVTP_CAN_FIELD_MAX, (uint8_t*)pdu, field)) +#define SET_FIELD(field, value) \ + (Avtp_SetField(Avtp_CanFieldDesc, AVTP_CAN_FIELD_MAX, (uint8_t*)pdu, field, value)) + /** * This table maps all IEEE 1722 ACF CAN header fields to a descriptor. */ @@ -56,15 +61,15 @@ static const Avtp_FieldDescriptor_t Avtp_CanFieldDesc[AVTP_CAN_FIELD_MAX] = [AVTP_CAN_FIELD_CAN_IDENTIFIER] = { .quadlet = 3, .offset = 3, .bits = 29 }, }; -void Avtp_Can_Init(Avtp_Can_t* can_pdu) +void Avtp_Can_Init(Avtp_Can_t* pdu) { - if(can_pdu != NULL) { - memset(can_pdu, 0, sizeof(Avtp_Can_t)); - Avtp_Can_SetField(can_pdu, AVTP_CAN_FIELD_ACF_MSG_TYPE, AVTP_ACF_TYPE_CAN); + if(pdu != NULL) { + memset(pdu, 0, sizeof(Avtp_Can_t)); + Avtp_Can_SetField(pdu, AVTP_CAN_FIELD_ACF_MSG_TYPE, AVTP_ACF_TYPE_CAN); } } -uint64_t Avtp_Can_GetField(Avtp_Can_t* can_pdu, Avtp_CanFields_t field) +uint64_t Avtp_Can_GetField(Avtp_Can_t* pdu, Avtp_CanFields_t field) { return GET_FIELD(field); } @@ -129,7 +134,7 @@ uint32_t Avtp_Can_GetCanIdentifier(Avtp_Can_t* pdu) return GET_FIELD(AVTP_CAN_FIELD_CAN_IDENTIFIER); } -void Avtp_Can_SetField(Avtp_Can_t* can_pdu, Avtp_CanFields_t field, uint64_t value) +void Avtp_Can_SetField(Avtp_Can_t* pdu, Avtp_CanFields_t field, uint64_t value) { SET_FIELD(field, value); } @@ -194,23 +199,23 @@ void Avtp_Can_SetCanIdentifier(Avtp_Can_t* pdu, uint32_t value) SET_FIELD(AVTP_CAN_FIELD_CAN_IDENTIFIER, value); } -int Avtp_Can_SetPayload(Avtp_Can_t* can_pdu, uint32_t frame_id , uint8_t* payload, +int Avtp_Can_SetPayload(Avtp_Can_t* pdu, uint32_t frame_id , uint8_t* payload, uint16_t payload_length, Avtp_CanVariant_t can_variant) { // Copy the payload into the CAN PDU - memcpy(can_pdu->payload, payload, payload_length); + memcpy(pdu->payload, payload, payload_length); // Set the Frame ID and CAN variant int eff = frame_id > 0x7ff? 1 : 0; - Avtp_Can_SetField(can_pdu, AVTP_CAN_FIELD_EFF, eff); - Avtp_Can_SetField(can_pdu, AVTP_CAN_FIELD_CAN_IDENTIFIER, frame_id); - Avtp_Can_SetField(can_pdu, AVTP_CAN_FIELD_FDF, (uint8_t) can_variant); + Avtp_Can_SetField(pdu, AVTP_CAN_FIELD_EFF, eff); + Avtp_Can_SetField(pdu, AVTP_CAN_FIELD_CAN_IDENTIFIER, frame_id); + Avtp_Can_SetField(pdu, AVTP_CAN_FIELD_FDF, (uint8_t) can_variant); // Finalize the AVTP CAN Frame - return Avtp_Can_Finalize(can_pdu, payload_length); + return Avtp_Can_Finalize(pdu, payload_length); } -int Avtp_Can_Finalize(Avtp_Can_t* can_pdu, uint16_t payload_length) +int Avtp_Can_Finalize(Avtp_Can_t* pdu, uint16_t payload_length) { uint8_t padSize; uint32_t avtpCanLength = AVTP_CAN_HEADER_LEN + payload_length; @@ -218,21 +223,21 @@ int Avtp_Can_Finalize(Avtp_Can_t* can_pdu, uint16_t payload_length) // Check if padding is required padSize = AVTP_QUADLET_SIZE - (payload_length % AVTP_QUADLET_SIZE); if (payload_length % AVTP_QUADLET_SIZE) { - memset(can_pdu->payload + payload_length, 0, padSize); + memset(pdu->payload + payload_length, 0, padSize); avtpCanLength += padSize; } // Set the length and padding fields - Avtp_Can_SetField(can_pdu, AVTP_CAN_FIELD_ACF_MSG_LENGTH, (uint64_t) avtpCanLength/AVTP_QUADLET_SIZE); - Avtp_Can_SetField(can_pdu, AVTP_CAN_FIELD_PAD, padSize); + Avtp_Can_SetField(pdu, AVTP_CAN_FIELD_ACF_MSG_LENGTH, (uint64_t) avtpCanLength/AVTP_QUADLET_SIZE); + Avtp_Can_SetField(pdu, AVTP_CAN_FIELD_PAD, padSize); return avtpCanLength; } -uint8_t* Avtp_Can_GetPayload(Avtp_Can_t* can_pdu, uint16_t* payload_length, uint16_t *pdu_length) +uint8_t* Avtp_Can_GetPayload(Avtp_Can_t* pdu, uint16_t* payload_length, uint16_t *pdu_length) { - uint64_t pdu_len = Avtp_Can_GetField((Avtp_Can_t*)can_pdu, AVTP_CAN_FIELD_ACF_MSG_LENGTH); - uint64_t pad_len = Avtp_Can_GetField((Avtp_Can_t*)can_pdu, AVTP_CAN_FIELD_PAD); + uint64_t pdu_len = Avtp_Can_GetField((Avtp_Can_t*)pdu, AVTP_CAN_FIELD_ACF_MSG_LENGTH); + uint64_t pad_len = Avtp_Can_GetField((Avtp_Can_t*)pdu, AVTP_CAN_FIELD_PAD); if(payload_length != NULL){ *payload_length = pdu_len*4-AVTP_CAN_HEADER_LEN-pad_len; @@ -242,5 +247,5 @@ uint8_t* Avtp_Can_GetPayload(Avtp_Can_t* can_pdu, uint16_t* payload_length, uint *pdu_length = pdu_len; } - return can_pdu->payload; + return pdu->payload; } diff --git a/src/avtp/acf/CanBrief.c b/src/avtp/acf/CanBrief.c index 725b961..189ab92 100644 --- a/src/avtp/acf/CanBrief.c +++ b/src/avtp/acf/CanBrief.c @@ -35,6 +35,11 @@ #include "avtp/Utils.h" #include "avtp/Defines.h" +#define GET_FIELD(field) \ + (Avtp_GetField(Avtp_CanBriefFieldDesc, AVTP_CAN_BRIEF_FIELD_MAX, (uint8_t*)pdu, field)) +#define SET_FIELD(field, value) \ + (Avtp_SetField(Avtp_CanBriefFieldDesc, AVTP_CAN_BRIEF_FIELD_MAX, (uint8_t*)pdu, field, value)) + /** * This table maps all IEEE 1722 ACF Abbreviated CAN header fields to a descriptor. */ @@ -55,41 +60,151 @@ static const Avtp_FieldDescriptor_t Avtp_CanBriefFieldDesc[AVTP_CAN_BRIEF_FIELD_ [AVTP_CAN_BRIEF_FIELD_CAN_IDENTIFIER] = { .quadlet = 1, .offset = 3, .bits = 29 }, }; -void Avtp_CanBrief_Init(Avtp_CanBrief_t* can_pdu) +void Avtp_CanBrief_Init(Avtp_CanBrief_t* pdu) { - if(can_pdu == NULL) { - memset(can_pdu, 0, sizeof(Avtp_CanBrief_t)); - Avtp_CanBrief_SetField(can_pdu, AVTP_CAN_BRIEF_FIELD_ACF_MSG_TYPE, AVTP_ACF_TYPE_CAN_BRIEF); + if(pdu == NULL) { + memset(pdu, 0, sizeof(Avtp_CanBrief_t)); + Avtp_CanBrief_SetField(pdu, AVTP_CAN_BRIEF_FIELD_ACF_MSG_TYPE, AVTP_ACF_TYPE_CAN_BRIEF); } } -uint64_t Avtp_CanBrief_GetField(Avtp_CanBrief_t* can_pdu, Avtp_CanBriefFields_t field) +uint64_t Avtp_CanBrief_GetField(Avtp_CanBrief_t* pdu, Avtp_CanBriefFields_t field) { - return Avtp_GetField(Avtp_CanBriefFieldDesc, AVTP_CAN_BRIEF_FIELD_MAX, (uint8_t *) can_pdu, (uint8_t) field); + return GET_FIELD(field); +} + +uint8_t Avtp_CanBrief_GetAcfMsgType(Avtp_CanBrief_t* pdu) +{ + return GET_FIELD(AVTP_CAN_BRIEF_FIELD_ACF_MSG_TYPE); +} + +uint16_t Avtp_CanBrief_GetAcfMsgLength(Avtp_CanBrief_t* pdu) +{ + return GET_FIELD(AVTP_CAN_BRIEF_FIELD_ACF_MSG_LENGTH); +} + +uint8_t Avtp_CanBrief_GetPad(Avtp_CanBrief_t* pdu) +{ + return GET_FIELD(AVTP_CAN_BRIEF_FIELD_PAD); +} + +uint8_t Avtp_CanBrief_GetMtv(Avtp_CanBrief_t* pdu) +{ + return GET_FIELD(AVTP_CAN_BRIEF_FIELD_MTV); +} + +uint8_t Avtp_CanBrief_GetRtr(Avtp_CanBrief_t* pdu) +{ + return GET_FIELD(AVTP_CAN_BRIEF_FIELD_RTR); +} + +uint8_t Avtp_CanBrief_GetEff(Avtp_CanBrief_t* pdu) +{ + return GET_FIELD(AVTP_CAN_BRIEF_FIELD_EFF); +} + +uint8_t Avtp_CanBrief_GetBrs(Avtp_CanBrief_t* pdu) +{ + return GET_FIELD(AVTP_CAN_BRIEF_FIELD_BRS); +} + +uint8_t Avtp_CanBrief_GetFdf(Avtp_CanBrief_t* pdu) +{ + return GET_FIELD(AVTP_CAN_BRIEF_FIELD_FDF); +} + +uint8_t Avtp_CanBrief_GetEsi(Avtp_CanBrief_t* pdu) +{ + return GET_FIELD(AVTP_CAN_BRIEF_FIELD_ESI); +} + +uint8_t Avtp_CanBrief_GetCanBusId(Avtp_CanBrief_t* pdu) +{ + return GET_FIELD(AVTP_CAN_BRIEF_FIELD_CAN_BUS_ID); +} + +uint32_t Avtp_CanBrief_GetCanIdentifier(Avtp_CanBrief_t* pdu) +{ + return GET_FIELD(AVTP_CAN_BRIEF_FIELD_CAN_IDENTIFIER); } -void Avtp_CanBrief_SetField(Avtp_CanBrief_t* can_pdu, Avtp_CanBriefFields_t field, uint64_t value) +void Avtp_CanBrief_SetField(Avtp_CanBrief_t* pdu, Avtp_CanBriefFields_t field, uint64_t value) { - Avtp_SetField(Avtp_CanBriefFieldDesc, AVTP_CAN_BRIEF_FIELD_MAX, (uint8_t *) can_pdu, (uint8_t) field, value); + SET_FIELD(field, value); +} + +void Avtp_CanBrief_SetAcfMsgType(Avtp_CanBrief_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CAN_BRIEF_FIELD_ACF_MSG_TYPE, value); +} + +void Avtp_CanBrief_SetAcfMsgLength(Avtp_CanBrief_t* pdu, uint16_t value) +{ + SET_FIELD(AVTP_CAN_BRIEF_FIELD_ACF_MSG_LENGTH, value); +} + +void Avtp_CanBrief_SetPad(Avtp_CanBrief_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CAN_BRIEF_FIELD_PAD, value); +} + +void Avtp_CanBrief_SetMtv(Avtp_CanBrief_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CAN_BRIEF_FIELD_MTV, value); +} + +void Avtp_CanBrief_SetRtr(Avtp_CanBrief_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CAN_BRIEF_FIELD_RTR, value); +} + +void Avtp_CanBrief_SetEff(Avtp_CanBrief_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CAN_BRIEF_FIELD_EFF, value); +} + +void Avtp_CanBrief_SetBrs(Avtp_CanBrief_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CAN_BRIEF_FIELD_BRS, value); +} + +void Avtp_CanBrief_SetFdf(Avtp_CanBrief_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CAN_BRIEF_FIELD_FDF, value); +} + +void Avtp_CanBrief_SetEsi(Avtp_CanBrief_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CAN_BRIEF_FIELD_ESI, value); +} + +void Avtp_CanBrief_SetCanBusId(Avtp_CanBrief_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CAN_BRIEF_FIELD_CAN_BUS_ID, value); +} + +void Avtp_CanBrief_SetCanIdentifier(Avtp_CanBrief_t* pdu, uint32_t value) +{ + SET_FIELD(AVTP_CAN_BRIEF_FIELD_CAN_IDENTIFIER, value); } -int Avtp_CanBrief_SetPayload(Avtp_CanBrief_t* can_pdu, uint32_t frame_id , uint8_t* payload, +int Avtp_CanBrief_SetPayload(Avtp_CanBrief_t* pdu, uint32_t frame_id , uint8_t* payload, uint16_t payload_length, Avtp_CanVariant_t can_variant) { // Copy the payload into the CAN PDU - memcpy(can_pdu->payload, payload, payload_length); + memcpy(pdu->payload, payload, payload_length); // Set the Frame ID and CAN variant int eff = frame_id > 0x7ff? 1 : 0; - Avtp_CanBrief_SetField(can_pdu, AVTP_CAN_BRIEF_FIELD_EFF, eff); - Avtp_CanBrief_SetField(can_pdu, AVTP_CAN_BRIEF_FIELD_CAN_IDENTIFIER, frame_id); - Avtp_CanBrief_SetField(can_pdu, AVTP_CAN_BRIEF_FIELD_FDF, (uint8_t) can_variant); + Avtp_CanBrief_SetField(pdu, AVTP_CAN_BRIEF_FIELD_EFF, eff); + Avtp_CanBrief_SetField(pdu, AVTP_CAN_BRIEF_FIELD_CAN_IDENTIFIER, frame_id); + Avtp_CanBrief_SetField(pdu, AVTP_CAN_BRIEF_FIELD_FDF, (uint8_t) can_variant); // Finalize the AVTP CAN Frame - return Avtp_CanBrief_Finalize(can_pdu, payload_length); + return Avtp_CanBrief_Finalize(pdu, payload_length); } -int Avtp_CanBrief_Finalize(Avtp_CanBrief_t* can_pdu, uint16_t payload_length) +int Avtp_CanBrief_Finalize(Avtp_CanBrief_t* pdu, uint16_t payload_length) { uint8_t padSize; uint32_t avtpCanLength = AVTP_CAN_BRIEF_HEADER_LEN + payload_length; @@ -97,14 +212,14 @@ int Avtp_CanBrief_Finalize(Avtp_CanBrief_t* can_pdu, uint16_t payload_length) // Check if padding is required padSize = AVTP_QUADLET_SIZE - (payload_length % AVTP_QUADLET_SIZE); if (payload_length % AVTP_QUADLET_SIZE) { - memset(can_pdu->payload + payload_length, 0, padSize); + memset(pdu->payload + payload_length, 0, padSize); avtpCanLength += padSize; } // Set the length and padding fields - Avtp_CanBrief_SetField(can_pdu, AVTP_CAN_BRIEF_FIELD_ACF_MSG_LENGTH, + Avtp_CanBrief_SetField(pdu, AVTP_CAN_BRIEF_FIELD_ACF_MSG_LENGTH, (uint64_t)avtpCanLength/AVTP_QUADLET_SIZE); - Avtp_CanBrief_SetField(can_pdu, AVTP_CAN_BRIEF_FIELD_PAD, padSize); + Avtp_CanBrief_SetField(pdu, AVTP_CAN_BRIEF_FIELD_PAD, padSize); return avtpCanLength; } From 998e3c0347a999895d326a22ad4f53b6453a0045 Mon Sep 17 00:00:00 2001 From: Adriaan Niess Date: Mon, 26 Aug 2024 00:03:27 +0200 Subject: [PATCH 16/33] Update GetField API for AcfCommon.h/c Signed-off-by: Adriaan Niess --- include/avtp/acf/{Common.h => AcfCommon.h} | 18 ++++++----- src/avtp/acf/{Common.c => AcfCommon.c} | 37 ++++++++++++++++++---- 2 files changed, 41 insertions(+), 14 deletions(-) rename include/avtp/acf/{Common.h => AcfCommon.h} (86%) rename src/avtp/acf/{Common.c => AcfCommon.c} (66%) diff --git a/include/avtp/acf/Common.h b/include/avtp/acf/AcfCommon.h similarity index 86% rename from include/avtp/acf/Common.h rename to include/avtp/acf/AcfCommon.h index ae83019..2733c8a 100644 --- a/include/avtp/acf/Common.h +++ b/include/avtp/acf/AcfCommon.h @@ -78,12 +78,13 @@ typedef enum { * Returns the value of an an ACF common header field as specified in the IEEE 1722 Specification. * * @param pdu Pointer to the first bit of an 1722 ACF PDU. - * @param field Specifies the position of the data field to be read - * @param value Pointer to location to store the value. - * @returns This function returns 0 if the data field was successfully read from - * the 1722 ACF PDU. + * @param field Specifies the position of the data field to be read. + * @returns Returns the field of the PDU. */ -int Avtp_AcfCommon_GetField(Avtp_AcfCommon_t* acf_pdu, Avtp_AcfCommonFields_t field, uint64_t* value); +uint64_t Avtp_AcfCommon_GetField(Avtp_AcfCommon_t* pdu, Avtp_AcfCommonFields_t field); + +uint8_t Avtp_AcfCommon_GetAcfMsgType(Avtp_AcfCommon_t* pdu); +uint16_t Avtp_AcfCommon_GetAcfMsgLength(Avtp_AcfCommon_t* pdu); /** * Sets the value of an an ACF common header field as specified in the IEEE 1722 Specification. @@ -91,7 +92,8 @@ int Avtp_AcfCommon_GetField(Avtp_AcfCommon_t* acf_pdu, Avtp_AcfCommonFields_t fi * @param pdu Pointer to the first bit of an 1722 ACF PDU. * @param field Specifies the position of the data field to be read * @param value Pointer to location to store the value. - * @returns This function returns 0 if the data field was successfully set in - * the 1722 ACF PDU. */ -int Avtp_AcfCommon_SetField(Avtp_AcfCommon_t* acf_pdu, Avtp_AcfCommonFields_t field, uint64_t value); \ No newline at end of file +void Avtp_AcfCommon_SetField(Avtp_AcfCommon_t* pdu, Avtp_AcfCommonFields_t field, uint64_t value); + +void Avtp_AcfCommon_SetAcfMsgType(Avtp_AcfCommon_t* pdu, uint8_t value); +void Avtp_AcfCommon_SetAcfMsgLength(Avtp_AcfCommon_t* pdu, uint16_t value); diff --git a/src/avtp/acf/Common.c b/src/avtp/acf/AcfCommon.c similarity index 66% rename from src/avtp/acf/Common.c rename to src/avtp/acf/AcfCommon.c index f644310..81e84b4 100644 --- a/src/avtp/acf/Common.c +++ b/src/avtp/acf/AcfCommon.c @@ -30,10 +30,15 @@ #include #include -#include "avtp/acf/Common.h" +#include "avtp/acf/AcfCommon.h" #include "avtp/Utils.h" #include "avtp/Defines.h" +#define GET_FIELD(field) \ + (Avtp_GetField(Avtp_AcfCommonFieldDesc, AVTP_ACF_COMMON_FIELD_MAX, (uint8_t*)pdu, field)) +#define SET_FIELD(field, value) \ + (Avtp_SetField(Avtp_AcfCommonFieldDesc, AVTP_ACF_COMMON_FIELD_MAX, (uint8_t*)pdu, field, value)) + /** * This table maps all IEEE 1722 ACF common header fields to a descriptor. */ @@ -44,12 +49,32 @@ static const Avtp_FieldDescriptor_t Avtp_AcfCommonFieldDesc[AVTP_ACF_COMMON_FIEL [AVTP_ACF_FIELD_ACF_MSG_LENGTH] = { .quadlet = 0, .offset = 7, .bits = 9 }, }; -int Avtp_AcfCommon_GetField(Avtp_AcfCommon_t* acf_pdu, Avtp_AcfCommonFields_t field, uint64_t* value) -{ - return Avtp_GetField(Avtp_AcfCommonFieldDesc, AVTP_ACF_COMMON_FIELD_MAX, (uint8_t*)acf_pdu, (uint8_t)field, value); +uint64_t Avtp_AcfCommon_GetField(Avtp_AcfCommon_t* pdu, Avtp_AcfCommonFields_t field) +{ + return GET_FIELD(field); +} + +uint8_t Avtp_AcfCommon_GetAcfMsgType(Avtp_AcfCommon_t* pdu) +{ + return GET_FIELD(AVTP_ACF_FIELD_ACF_MSG_TYPE); +} + +uint16_t Avtp_AcfCommon_GetAcfMsgLength(Avtp_AcfCommon_t* pdu) +{ + return GET_FIELD(AVTP_ACF_FIELD_ACF_MSG_LENGTH); +} + +void Avtp_AcfCommon_SetField(Avtp_AcfCommon_t* pdu, Avtp_AcfCommonFields_t field, uint64_t value) +{ + SET_FIELD(field, value); +} + +void Avtp_AcfCommon_SetAcfMsgType(Avtp_AcfCommon_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_ACF_FIELD_ACF_MSG_TYPE, value); } -int Avtp_AcfCommon_SetField(Avtp_AcfCommon_t* acf_pdu, Avtp_AcfCommonFields_t field, uint64_t value) +void Avtp_AcfCommon_SetAcfMsgLength(Avtp_AcfCommon_t* pdu, uint16_t value) { - return Avtp_SetField(Avtp_AcfCommonFieldDesc, AVTP_ACF_COMMON_FIELD_MAX, (uint8_t*)acf_pdu, (uint8_t)field, value); + SET_FIELD(AVTP_ACF_FIELD_ACF_MSG_LENGTH, value); } From 1e224c18924e99427bd5c4c8eb3e1ed4e0855a89 Mon Sep 17 00:00:00 2001 From: Adriaan Niess Date: Mon, 26 Aug 2024 20:54:37 +0200 Subject: [PATCH 17/33] Update GetField API for AcfCommon.h/c and FlexRay.h/c Signed-off-by: Adriaan Niess --- CMakeLists.txt | 2 +- README.md | 59 +++++++++++++++ include/avtp/acf/Can.h | 2 +- include/avtp/acf/CanBrief.h | 4 +- include/avtp/acf/FlexRay.h | 30 +++++++- include/avtp/acf/Gpc.h | 2 +- include/avtp/acf/Lin.h | 2 +- src/avtp/acf/Can.c | 1 - src/avtp/acf/CanBrief.c | 1 - src/avtp/acf/FlexRay.c | 141 +++++++++++++++++++++++++++++++++++- src/avtp/acf/Gpc.c | 1 - 11 files changed, 232 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d2d61d2..42ac473 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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" diff --git a/README.md b/README.md index 0186eee..18e82b8 100644 --- a/README.md +++ b/README.md @@ -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 +} +``` diff --git a/include/avtp/acf/Can.h b/include/avtp/acf/Can.h index bb04207..7f7d6af 100644 --- a/include/avtp/acf/Can.h +++ b/include/avtp/acf/Can.h @@ -38,7 +38,7 @@ #include #include "avtp/Defines.h" -#include "avtp/acf/Common.h" +#include "avtp/acf/AcfCommon.h" #define AVTP_CAN_HEADER_LEN (4 * AVTP_QUADLET_SIZE) diff --git a/include/avtp/acf/CanBrief.h b/include/avtp/acf/CanBrief.h index 60d3c36..5ee0184 100644 --- a/include/avtp/acf/CanBrief.h +++ b/include/avtp/acf/CanBrief.h @@ -38,7 +38,7 @@ #include #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) @@ -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); \ No newline at end of file +int Avtp_CanBrief_Finalize(Avtp_CanBrief_t* can_pdu, uint16_t payload_length); diff --git a/include/avtp/acf/FlexRay.h b/include/avtp/acf/FlexRay.h index 6e4b62a..7270d3f 100644 --- a/include/avtp/acf/FlexRay.h +++ b/include/avtp/acf/FlexRay.h @@ -37,7 +37,7 @@ #include #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) @@ -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. * @@ -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); diff --git a/include/avtp/acf/Gpc.h b/include/avtp/acf/Gpc.h index 73ec159..2295a7c 100644 --- a/include/avtp/acf/Gpc.h +++ b/include/avtp/acf/Gpc.h @@ -37,7 +37,7 @@ #include #include "avtp/Defines.h" -#include "avtp/acf/Common.h" +#include "avtp/acf/AcfCommon.h" #define AVTP_GPC_HEADER_LEN (2 * AVTP_QUADLET_SIZE) diff --git a/include/avtp/acf/Lin.h b/include/avtp/acf/Lin.h index 7f822b7..7e5fd1c 100644 --- a/include/avtp/acf/Lin.h +++ b/include/avtp/acf/Lin.h @@ -37,7 +37,7 @@ #include #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) diff --git a/src/avtp/acf/Can.c b/src/avtp/acf/Can.c index d2e029d..8754b95 100644 --- a/src/avtp/acf/Can.c +++ b/src/avtp/acf/Can.c @@ -30,7 +30,6 @@ #include #include -#include "avtp/acf/Common.h" #include "avtp/acf/Can.h" #include "avtp/Utils.h" #include "avtp/Defines.h" diff --git a/src/avtp/acf/CanBrief.c b/src/avtp/acf/CanBrief.c index 189ab92..738429e 100644 --- a/src/avtp/acf/CanBrief.c +++ b/src/avtp/acf/CanBrief.c @@ -30,7 +30,6 @@ #include #include -#include "avtp/acf/Common.h" #include "avtp/acf/CanBrief.h" #include "avtp/Utils.h" #include "avtp/Defines.h" diff --git a/src/avtp/acf/FlexRay.c b/src/avtp/acf/FlexRay.c index 0079bb1..b247185 100644 --- a/src/avtp/acf/FlexRay.c +++ b/src/avtp/acf/FlexRay.c @@ -31,7 +31,12 @@ #include #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. @@ -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); } diff --git a/src/avtp/acf/Gpc.c b/src/avtp/acf/Gpc.c index 911e25a..28c8324 100644 --- a/src/avtp/acf/Gpc.c +++ b/src/avtp/acf/Gpc.c @@ -30,7 +30,6 @@ #include #include -#include "avtp/acf/Common.h" #include "avtp/acf/Gpc.h" #include "avtp/Utils.h" #include "avtp/Defines.h" From 074aa817137b2047d37d2f75bc967aa37d927a53 Mon Sep 17 00:00:00 2001 From: Adriaan Niess Date: Mon, 26 Aug 2024 21:14:33 +0200 Subject: [PATCH 18/33] Update GetField API for Gpc.h/c Signed-off-by: Adriaan Niess --- include/avtp/acf/Gpc.h | 20 +++++++++++----- src/avtp/acf/Gpc.c | 52 ++++++++++++++++++++++++++++++++++-------- 2 files changed, 57 insertions(+), 15 deletions(-) diff --git a/include/avtp/acf/Gpc.h b/include/avtp/acf/Gpc.h index 2295a7c..d830ad1 100644 --- a/include/avtp/acf/Gpc.h +++ b/include/avtp/acf/Gpc.h @@ -63,25 +63,33 @@ typedef enum { /** * Initializes an ACF GPC PDU header as specified in the IEEE 1722 Specification. * - * @param gpc_pdu Pointer to the first bit of a 1722 ACF GPC PDU. + * @param pdu Pointer to the first bit of a 1722 ACF GPC PDU. */ -void Avtp_Gpc_Init(Avtp_Gpc_t* gpc_pdu); +void Avtp_Gpc_Init(Avtp_Gpc_t* pdu); /** * Returns the value of an an ACF GPC PDU field as specified in the IEEE 1722 Specification. * - * @param gpc_pdu Pointer to the first bit of an 1722 ACF GPC PDU. + * @param pdu Pointer to the first bit of an 1722 ACF GPC PDU. * @param field Specifies the position of the data field to be read * @param value Pointer to location to store the value. * @returns The value of the GPC field. */ -uint64_t Avtp_Gpc_GetField(Avtp_Gpc_t* gpc_pdu, Avtp_GpcFields_t field); +uint64_t Avtp_Gpc_GetField(Avtp_Gpc_t* pdu, Avtp_GpcFields_t field); + +uint8_t Avtp_Gpc_GetAcfMsgType(Avtp_Gpc_t* pdu); +uint16_t Avtp_Gpc_GetAcfMsgLength(Avtp_Gpc_t* pdu); +uint64_t Avtp_Gpc_GetGpcMsgId(Avtp_Gpc_t* pdu); /** * Sets the value of an an ACF GPC PDU field as specified in the IEEE 1722 Specification. * - * @param gpc_pdu Pointer to the first bit of an 1722 ACF GPC PDU. + * @param pdu Pointer to the first bit of an 1722 ACF GPC PDU. * @param field Specifies the position of the data field to be read * @param value Pointer to location to store the value. */ -void Avtp_Gpc_SetField(Avtp_Gpc_t* gpc_pdu, Avtp_GpcFields_t field, uint64_t value); +void Avtp_Gpc_SetField(Avtp_Gpc_t* pdu, Avtp_GpcFields_t field, uint64_t value); + +void Avtp_Gpc_SetAcfMsgType(Avtp_Gpc_t* pdu, uint8_t value); +void Avtp_Gpc_SetAcfMsgLength(Avtp_Gpc_t* pdu, uint16_t value); +void Avtp_Gpc_SetGpcMsgId(Avtp_Gpc_t* pdu, uint64_t value); diff --git a/src/avtp/acf/Gpc.c b/src/avtp/acf/Gpc.c index 28c8324..282623d 100644 --- a/src/avtp/acf/Gpc.c +++ b/src/avtp/acf/Gpc.c @@ -34,6 +34,11 @@ #include "avtp/Utils.h" #include "avtp/Defines.h" +#define GET_FIELD(field) \ + (Avtp_GetField(Avtp_GpcFieldDesc, AVTP_GPC_FIELD_MAX, (uint8_t*)pdu, field)) +#define SET_FIELD(field, value) \ + (Avtp_SetField(Avtp_GpcFieldDesc, AVTP_GPC_FIELD_MAX, (uint8_t*)pdu, field, value)) + /** * This table maps all IEEE 1722 ACF GPC header fields to a descriptor. */ @@ -46,21 +51,50 @@ static const Avtp_FieldDescriptor_t Avtp_GpcFieldDesc[AVTP_GPC_FIELD_MAX] = [AVTP_GPC_FIELD_GPC_MSG_ID] = { .quadlet = 0, .offset = 16, .bits = 48 }, }; -void Avtp_Gpc_Init(Avtp_Gpc_t* gpc_pdu) +void Avtp_Gpc_Init(Avtp_Gpc_t* pdu) { - if(gpc_pdu != NULL) { - memset(gpc_pdu, 0, sizeof(Avtp_Gpc_t)); - Avtp_Gpc_SetField(gpc_pdu, AVTP_GPC_FIELD_ACF_MSG_TYPE, AVTP_ACF_TYPE_GPC); + if(pdu != NULL) { + memset(pdu, 0, sizeof(Avtp_Gpc_t)); + Avtp_Gpc_SetField(pdu, AVTP_GPC_FIELD_ACF_MSG_TYPE, AVTP_ACF_TYPE_GPC); } } -uint64_t Avtp_Gpc_GetField(Avtp_Gpc_t* gpc_pdu, Avtp_GpcFields_t field) +uint64_t Avtp_Gpc_GetField(Avtp_Gpc_t* pdu, Avtp_GpcFields_t field) +{ + return GET_FIELD(field); +} + +uint8_t Avtp_Gpc_GetAcfMsgType(Avtp_Gpc_t* pdu) +{ + return GET_FIELD(AVTP_GPC_FIELD_ACF_MSG_TYPE); +} + +uint16_t Avtp_Gpc_GetAcfMsgLength(Avtp_Gpc_t* pdu) +{ + return GET_FIELD(AVTP_GPC_FIELD_ACF_MSG_LENGTH); +} + +uint64_t Avtp_Gpc_GetGpcMsgId(Avtp_Gpc_t* pdu) +{ + return GET_FIELD(AVTP_GPC_FIELD_GPC_MSG_ID); +} + +void Avtp_Gpc_SetField(Avtp_Gpc_t* pdu, Avtp_GpcFields_t field, uint64_t value) +{ + SET_FIELD(field, value); +} + +void Avtp_Gpc_SetAcfMsgType(Avtp_Gpc_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_GPC_FIELD_ACF_MSG_TYPE, value); +} + +void Avtp_Gpc_SetAcfMsgLength(Avtp_Gpc_t* pdu, uint16_t value) { - return Avtp_GetField(Avtp_GpcFieldDesc, AVTP_GPC_FIELD_MAX, (uint8_t *) gpc_pdu, (uint8_t) field); + SET_FIELD(AVTP_GPC_FIELD_ACF_MSG_LENGTH, value); } -void Avtp_Gpc_SetField(Avtp_Gpc_t* gpc_pdu, Avtp_GpcFields_t field, - uint64_t value) +void Avtp_Gpc_SetGpcMsgId(Avtp_Gpc_t* pdu, uint64_t value) { - Avtp_SetField(Avtp_GpcFieldDesc, AVTP_GPC_FIELD_MAX, (uint8_t *) gpc_pdu, (uint8_t) field, value); + SET_FIELD(AVTP_GPC_FIELD_GPC_MSG_ID, value); } From ec6bae49771ea1a885d8fc78d847d8a52390386d Mon Sep 17 00:00:00 2001 From: Adriaan Niess Date: Mon, 26 Aug 2024 21:14:57 +0200 Subject: [PATCH 19/33] Update GetField API for Lin.h/c Signed-off-by: Adriaan Niess --- include/avtp/acf/Lin.h | 26 +++++++++--- src/avtp/acf/Lin.c | 95 ++++++++++++++++++++++++++++++++++++------ 2 files changed, 103 insertions(+), 18 deletions(-) diff --git a/include/avtp/acf/Lin.h b/include/avtp/acf/Lin.h index 7e5fd1c..c1bfac5 100644 --- a/include/avtp/acf/Lin.h +++ b/include/avtp/acf/Lin.h @@ -69,17 +69,24 @@ typedef enum { * * @param pdu Pointer to the first bit of a 1722 ACF Lin PDU. */ -int Avtp_Lin_Init(Avtp_Lin_t* pdu); +void Avtp_Lin_Init(Avtp_Lin_t* pdu); /** * Returns the value of an ACF Lin PDU field. * * @param pdu Pointer to the first bit of an 1722 ACF Lin PDU. * @param field Data field to be read - * @param value Pointer to location to store the value. - * @returns Returns 0 if the data field was successfully read. + * @returns Value of PDU field. */ -int Avtp_Lin_GetField(Avtp_Lin_t* pdu, Avtp_LinFields_t field, uint64_t* value); +uint64_t Avtp_Lin_GetField(Avtp_Lin_t* pdu, Avtp_LinFields_t field); + +uint8_t Avtp_Lin_GetAcfMsgType(Avtp_Lin_t* pdu); +uint16_t Avtp_Lin_GetAcfMsgLength(Avtp_Lin_t* pdu); +uint8_t Avtp_Lin_GetPad(Avtp_Lin_t* pdu); +uint8_t Avtp_Lin_GetMtv(Avtp_Lin_t* pdu); +uint8_t Avtp_Lin_GetLinBusId(Avtp_Lin_t* pdu); +uint8_t Avtp_Lin_GetLinIdentifier(Avtp_Lin_t* pdu); +uint64_t Avtp_Lin_GetMessageTimestamp(Avtp_Lin_t* pdu); /** * Sets the value of an ACF Lin PDU field. @@ -87,6 +94,13 @@ int Avtp_Lin_GetField(Avtp_Lin_t* pdu, Avtp_LinFields_t field, uint64_t* value); * @param pdu Pointer to the first bit of an 1722 ACF Lin PDU. * @param field Specifies the position of the data field to be read * @param value Pointer to location to store the value. - * @returns Returns 0 if the data field was successfully set. */ -int Avtp_Lin_SetField(Avtp_Lin_t* pdu, Avtp_LinFields_t field, uint64_t value); +void Avtp_Lin_SetField(Avtp_Lin_t* pdu, Avtp_LinFields_t field, uint64_t value); + +void Avtp_Lin_SetAcfMsgType(Avtp_Lin_t* pdu, uint8_t value); +void Avtp_Lin_SetAcfMsgLength(Avtp_Lin_t* pdu, uint16_t value); +void Avtp_Lin_SetPad(Avtp_Lin_t* pdu, uint8_t value); +void Avtp_Lin_SetMtv(Avtp_Lin_t* pdu, uint8_t value); +void Avtp_Lin_SetLinBusId(Avtp_Lin_t* pdu, uint8_t value); +void Avtp_Lin_SetLinIdentifier(Avtp_Lin_t* pdu, uint8_t value); +void Avtp_Lin_SetMessageTimestamp(Avtp_Lin_t* pdu, uint64_t value); diff --git a/src/avtp/acf/Lin.c b/src/avtp/acf/Lin.c index ee1863c..ce8f26f 100644 --- a/src/avtp/acf/Lin.c +++ b/src/avtp/acf/Lin.c @@ -31,7 +31,12 @@ #include #include "avtp/acf/Lin.h" -#include "avtp/Utils.h" +#include "avtp/Utils.h" + +#define GET_FIELD(field) \ + (Avtp_GetField(Avtp_LinFieldDesc, AVTP_LIN_FIELD_MAX, (uint8_t*)pdu, field)) +#define SET_FIELD(field, value) \ + (Avtp_SetField(Avtp_LinFieldDesc, AVTP_LIN_FIELD_MAX, (uint8_t*)pdu, field, value)) /** * This table describes all the offsets of the ACF Lin header fields. @@ -49,24 +54,90 @@ static const Avtp_FieldDescriptor_t Avtp_LinFieldDesc[AVTP_LIN_FIELD_MAX] = [AVTP_LIN_FIELD_MESSAGE_TIMESTAMP] = { .quadlet = 1, .offset = 0, .bits = 64 }, }; -int Avtp_Lin_Init(Avtp_Lin_t* pdu) +void Avtp_Lin_Init(Avtp_Lin_t* pdu) { - if(!pdu) { - return -EINVAL; + if(pdu != NULL) { + memset(pdu, 0, sizeof(Avtp_Lin_t)); + Avtp_Lin_SetField(pdu, AVTP_LIN_FIELD_ACF_MSG_TYPE, AVTP_ACF_TYPE_LIN); } +} + +uint64_t Avtp_Lin_GetField(Avtp_Lin_t* pdu, Avtp_LinFields_t field) +{ + return GET_FIELD(field); +} + +uint8_t Avtp_Lin_GetAcfMsgType(Avtp_Lin_t* pdu) +{ + return GET_FIELD(AVTP_LIN_FIELD_ACF_MSG_TYPE); +} + +uint16_t Avtp_Lin_GetAcfMsgLength(Avtp_Lin_t* pdu) +{ + return GET_FIELD(AVTP_LIN_FIELD_ACF_MSG_LENGTH); +} + +uint8_t Avtp_Lin_GetPad(Avtp_Lin_t* pdu) +{ + return GET_FIELD(AVTP_LIN_FIELD_PAD); +} + +uint8_t Avtp_Lin_GetMtv(Avtp_Lin_t* pdu) +{ + return GET_FIELD(AVTP_LIN_FIELD_MTV); +} + +uint8_t Avtp_Lin_GetLinBusId(Avtp_Lin_t* pdu) +{ + return GET_FIELD(AVTP_LIN_FIELD_LIN_BUS_ID); +} + +uint8_t Avtp_Lin_GetLinIdentifier(Avtp_Lin_t* pdu) +{ + return GET_FIELD(AVTP_LIN_FIELD_LIN_IDENTIFIER); +} + +uint64_t Avtp_Lin_GetMessageTimestamp(Avtp_Lin_t* pdu) +{ + return GET_FIELD(AVTP_LIN_FIELD_MESSAGE_TIMESTAMP); +} + +void Avtp_Lin_SetField(Avtp_Lin_t* pdu, Avtp_LinFields_t field, uint64_t value) +{ + SET_FIELD(field, value); +} + +void Avtp_Lin_SetAcfMsgType(Avtp_Lin_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_LIN_FIELD_ACF_MSG_TYPE, value); +} - memset(pdu, 0, sizeof(Avtp_Lin_t)); - Avtp_Lin_SetField(pdu, AVTP_LIN_FIELD_ACF_MSG_TYPE, AVTP_ACF_TYPE_LIN); - - return 0; +void Avtp_Lin_SetAcfMsgLength(Avtp_Lin_t* pdu, uint16_t value) +{ + SET_FIELD(AVTP_LIN_FIELD_ACF_MSG_LENGTH, value); +} + +void Avtp_Lin_SetPad(Avtp_Lin_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_LIN_FIELD_PAD, value); +} + +void Avtp_Lin_SetMtv(Avtp_Lin_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_LIN_FIELD_MTV, value); +} + +void Avtp_Lin_SetLinBusId(Avtp_Lin_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_LIN_FIELD_LIN_BUS_ID, value); } -int Avtp_Lin_GetField(Avtp_Lin_t* pdu, Avtp_LinFields_t field, uint64_t* value) +void Avtp_Lin_SetLinIdentifier(Avtp_Lin_t* pdu, uint8_t value) { - return Avtp_GetField(Avtp_LinFieldDesc, AVTP_LIN_FIELD_MAX, (uint8_t*)pdu, (uint8_t)field, value); + SET_FIELD(AVTP_LIN_FIELD_LIN_IDENTIFIER, value); } -int Avtp_Lin_SetField(Avtp_Lin_t* pdu, Avtp_LinFields_t field, uint64_t value) +void Avtp_Lin_SetMessageTimestamp(Avtp_Lin_t* pdu, uint64_t value) { - return Avtp_SetField(Avtp_LinFieldDesc, AVTP_LIN_FIELD_MAX, (uint8_t*)pdu, (uint8_t)field, value); + SET_FIELD(AVTP_LIN_FIELD_MESSAGE_TIMESTAMP, value); } From 0217470e1717873732b80da01f03613d9f2c446f Mon Sep 17 00:00:00 2001 From: Adriaan Niess Date: Mon, 26 Aug 2024 21:27:02 +0200 Subject: [PATCH 20/33] Update GetField API for Most.h/c Signed-off-by: Adriaan Niess --- include/avtp/acf/Most.h | 36 ++++++++--- src/avtp/acf/Most.c | 135 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 152 insertions(+), 19 deletions(-) diff --git a/include/avtp/acf/Most.h b/include/avtp/acf/Most.h index 5519f94..b04fe21 100644 --- a/include/avtp/acf/Most.h +++ b/include/avtp/acf/Most.h @@ -37,7 +37,7 @@ #include #include "avtp/Defines.h" -#include "avtp/acf/Common.h" +#include "avtp/acf/AcfCommon.h" /** Length of ACF Most header. */ #define AVTP_MOST_HEADER_LEN (4 * AVTP_QUADLET_SIZE) @@ -74,17 +74,28 @@ typedef enum { * * @param pdu Pointer to the first bit of a 1722 ACF Most PDU. */ -int Avtp_Most_Init(Avtp_Most_t* pdu); +void Avtp_Most_Init(Avtp_Most_t* pdu); /** * Returns the value of an ACF Most PDU field. * * @param pdu Pointer to the first bit of an 1722 ACF Most PDU. * @param field Data field to be read - * @param value Pointer to location to store the value. - * @returns Returns 0 if the data field was successfully read. + * @returns Value of the PDU field. */ -int Avtp_Most_GetField(Avtp_Most_t* pdu, Avtp_MostFields_t field, uint64_t* value); +uint64_t Avtp_Most_GetField(Avtp_Most_t* pdu, Avtp_MostFields_t field); + +uint8_t Avtp_Most_GetAcfMsgType(Avtp_Most_t* pdu); +uint16_t Avtp_Most_GetAcfMsgLength(Avtp_Most_t* pdu); +uint8_t Avtp_Most_GetPad(Avtp_Most_t* pdu); +uint8_t Avtp_Most_GetMtv(Avtp_Most_t* pdu); +uint8_t Avtp_Most_GetMostNetId(Avtp_Most_t* pdu); +uint64_t Avtp_Most_GetMessageTimestamp(Avtp_Most_t* pdu); +uint16_t Avtp_Most_GetDeviceId(Avtp_Most_t* pdu); +uint8_t Avtp_Most_GetFblockId(Avtp_Most_t* pdu); +uint8_t Avtp_Most_GetInstId(Avtp_Most_t* pdu); +uint16_t Avtp_Most_GetFuncId(Avtp_Most_t* pdu); +uint8_t Avtp_Most_GetOpType(Avtp_Most_t* pdu); /** * Sets the value of an ACF Most PDU field. @@ -92,6 +103,17 @@ int Avtp_Most_GetField(Avtp_Most_t* pdu, Avtp_MostFields_t field, uint64_t* valu * @param pdu Pointer to the first bit of an 1722 ACF Most PDU. * @param field Specifies the position of the data field to be read * @param value Pointer to location to store the value. - * @returns Returns 0 if the data field was successfully set. */ -int Avtp_Most_SetField(Avtp_Most_t* pdu, Avtp_MostFields_t field, uint64_t value); +void Avtp_Most_SetField(Avtp_Most_t* pdu, Avtp_MostFields_t field, uint64_t value); + +void Avtp_Most_SetAcfMsgType(Avtp_Most_t* pdu, uint8_t value); +void Avtp_Most_SetAcfMsgLength(Avtp_Most_t* pdu, uint16_t value); +void Avtp_Most_SetPad(Avtp_Most_t* pdu, uint8_t value); +void Avtp_Most_SetMtv(Avtp_Most_t* pdu, uint8_t value); +void Avtp_Most_SetMostNetId(Avtp_Most_t* pdu, uint8_t value); +void Avtp_Most_SetMessageTimestamp(Avtp_Most_t* pdu, uint64_t value); +void Avtp_Most_SetDeviceId(Avtp_Most_t* pdu, uint16_t value); +void Avtp_Most_SetFblockId(Avtp_Most_t* pdu, uint8_t value); +void Avtp_Most_SetInstId(Avtp_Most_t* pdu, uint8_t value); +void Avtp_Most_SetFuncId(Avtp_Most_t* pdu, uint16_t value); +void Avtp_Most_SetOpType(Avtp_Most_t* pdu, uint8_t value); diff --git a/src/avtp/acf/Most.c b/src/avtp/acf/Most.c index e809bd3..a534afa 100644 --- a/src/avtp/acf/Most.c +++ b/src/avtp/acf/Most.c @@ -31,7 +31,12 @@ #include #include "avtp/acf/Most.h" -#include "avtp/Utils.h" +#include "avtp/Utils.h" + +#define GET_FIELD(field) \ + (Avtp_GetField(Avtp_MostFieldDesc, AVTP_MOST_FIELD_MAX, (uint8_t*)pdu, field)) +#define SET_FIELD(field, value) \ + (Avtp_SetField(Avtp_MostFieldDesc, AVTP_MOST_FIELD_MAX, (uint8_t*)pdu, field, value)) /** * This table describes all the offsets of the ACF Most header fields. @@ -55,24 +60,130 @@ static const Avtp_FieldDescriptor_t Avtp_MostFieldDesc[AVTP_MOST_FIELD_MAX] = [AVTP_MOST_FIELD_RESERVED_2] = { .quadlet = 4, .offset = 16, .bits = 16 }, }; -int Avtp_Most_Init(Avtp_Most_t* pdu) +void Avtp_Most_Init(Avtp_Most_t* pdu) { - if(!pdu) { - return -EINVAL; + if(pdu != NULL) { + memset(pdu, 0, sizeof(Avtp_Most_t)); + Avtp_Most_SetField(pdu, AVTP_MOST_FIELD_ACF_MSG_TYPE, AVTP_ACF_TYPE_MOST); } +} + +uint64_t Avtp_Most_GetField(Avtp_Most_t* pdu, Avtp_MostFields_t field) +{ + return GET_FIELD(field); +} + +uint8_t Avtp_Most_GetAcfMsgType(Avtp_Most_t* pdu) +{ + return GET_FIELD(AVTP_MOST_FIELD_ACF_MSG_TYPE); +} + +uint16_t Avtp_Most_GetAcfMsgLength(Avtp_Most_t* pdu) +{ + return GET_FIELD(AVTP_MOST_FIELD_ACF_MSG_LENGTH); +} + +uint8_t Avtp_Most_GetPad(Avtp_Most_t* pdu) +{ + return GET_FIELD(AVTP_MOST_FIELD_PAD); +} + +uint8_t Avtp_Most_GetMtv(Avtp_Most_t* pdu) +{ + return GET_FIELD(AVTP_MOST_FIELD_MTV); +} + +uint8_t Avtp_Most_GetMostNetId(Avtp_Most_t* pdu) +{ + return GET_FIELD(AVTP_MOST_FIELD_MOST_NET_ID); +} + +uint64_t Avtp_Most_GetMessageTimestamp(Avtp_Most_t* pdu) +{ + return GET_FIELD(AVTP_MOST_FIELD_MESSAGE_TIMESTAMP); +} + +uint16_t Avtp_Most_GetDeviceId(Avtp_Most_t* pdu) +{ + return GET_FIELD(AVTP_MOST_FIELD_DEVICE_ID); +} + +uint8_t Avtp_Most_GetFblockId(Avtp_Most_t* pdu) +{ + return GET_FIELD(AVTP_MOST_FIELD_FBLOCK_ID); +} + +uint8_t Avtp_Most_GetInstId(Avtp_Most_t* pdu) +{ + return GET_FIELD(AVTP_MOST_FIELD_INST_ID); +} + +uint16_t Avtp_Most_GetFuncId(Avtp_Most_t* pdu) +{ + return GET_FIELD(AVTP_MOST_FIELD_FUNC_ID); +} + +uint8_t Avtp_Most_GetOpType(Avtp_Most_t* pdu) +{ + return GET_FIELD(AVTP_MOST_FIELD_OP_TYPE); +} + +void Avtp_Most_SetField(Avtp_Most_t* pdu, Avtp_MostFields_t field, uint64_t value) +{ + SET_FIELD(field, value); +} + +void Avtp_Most_SetAcfMsgType(Avtp_Most_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_MOST_FIELD_ACF_MSG_TYPE, value); +} + +void Avtp_Most_SetAcfMsgLength(Avtp_Most_t* pdu, uint16_t value) +{ + SET_FIELD(AVTP_MOST_FIELD_ACF_MSG_LENGTH, value); +} + +void Avtp_Most_SetPad(Avtp_Most_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_MOST_FIELD_PAD, value); +} - memset(pdu, 0, sizeof(Avtp_Most_t)); - Avtp_Most_SetField(pdu, AVTP_MOST_FIELD_ACF_MSG_TYPE, AVTP_ACF_TYPE_MOST); - - return 0; +void Avtp_Most_SetMtv(Avtp_Most_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_MOST_FIELD_MTV, value); +} + +void Avtp_Most_SetMostNetId(Avtp_Most_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_MOST_FIELD_MOST_NET_ID, value); +} + +void Avtp_Most_SetMessageTimestamp(Avtp_Most_t* pdu, uint64_t value) +{ + SET_FIELD(AVTP_MOST_FIELD_MESSAGE_TIMESTAMP, value); +} + +void Avtp_Most_SetDeviceId(Avtp_Most_t* pdu, uint16_t value) +{ + SET_FIELD(AVTP_MOST_FIELD_DEVICE_ID, value); +} + +void Avtp_Most_SetFblockId(Avtp_Most_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_MOST_FIELD_FBLOCK_ID, value); +} + +void Avtp_Most_SetInstId(Avtp_Most_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_MOST_FIELD_INST_ID, value); } -int Avtp_Most_GetField(Avtp_Most_t* pdu, Avtp_MostFields_t field, uint64_t* value) +void Avtp_Most_SetFuncId(Avtp_Most_t* pdu, uint16_t value) { - return Avtp_GetField(Avtp_MostFieldDesc, AVTP_MOST_FIELD_MAX, (uint8_t*)pdu, (uint8_t)field, value); + SET_FIELD(AVTP_MOST_FIELD_FUNC_ID, value); } -int Avtp_Most_SetField(Avtp_Most_t* pdu, Avtp_MostFields_t field, uint64_t value) +void Avtp_Most_SetOpType(Avtp_Most_t* pdu, uint8_t value) { - return Avtp_SetField(Avtp_MostFieldDesc, AVTP_MOST_FIELD_MAX, (uint8_t*)pdu, (uint8_t)field, value); + SET_FIELD(AVTP_MOST_FIELD_OP_TYPE, value); } From 305ece2810e52d097b2d71ee86ab02af7167742a Mon Sep 17 00:00:00 2001 From: Adriaan Niess Date: Mon, 26 Aug 2024 21:36:28 +0200 Subject: [PATCH 21/33] Update GetField API for Sensor.h/c Signed-off-by: Adriaan Niess --- include/avtp/acf/Sensor.h | 30 +++++++++---- src/avtp/acf/Sensor.c | 94 ++++++++++++++++++++++++++++++++++----- 2 files changed, 103 insertions(+), 21 deletions(-) diff --git a/include/avtp/acf/Sensor.h b/include/avtp/acf/Sensor.h index 7d1e0fd..018c500 100644 --- a/include/avtp/acf/Sensor.h +++ b/include/avtp/acf/Sensor.h @@ -38,7 +38,7 @@ #include #include "avtp/Defines.h" -#include "avtp/acf/Common.h" +#include "avtp/acf/AcfCommon.h" #define AVTP_SENSOR_HEADER_LEN (3 * AVTP_QUADLET_SIZE) @@ -69,18 +69,24 @@ typedef enum { * * @param pdu Pointer to the first bit of a 1722 ACF Sensor PDU. */ -int Avtp_Sensor_Init(Avtp_Sensor_t* sensor_pdu); +void Avtp_Sensor_Init(Avtp_Sensor_t* pdu); /** * Returns the value of an ACF Sensor PDU field as specified in the IEEE 1722 Specification. * * @param pdu Pointer to the first bit of an 1722 ACF Sensor PDU. * @param field Specifies the position of the data field to be read - * @param value Pointer to location to store the value. - * @returns This function returns 0 if the data field was successfully read from - * the 1722 ACF Sensor PDU. + * @returns Value of the PDU field. */ -int Avtp_Sensor_GetField(Avtp_Sensor_t* sensor_pdu, Avtp_SensorFields_t field, uint64_t* value); +uint64_t Avtp_Sensor_GetField(Avtp_Sensor_t* pdu, Avtp_SensorFields_t field); + +uint8_t Avtp_Sensor_GetAcfMsgType(Avtp_Sensor_t* pdu); +uint16_t Avtp_Sensor_GetAcfMsgLength(Avtp_Sensor_t* pdu); +uint8_t Avtp_Sensor_GetMtv(Avtp_Sensor_t* pdu); +uint8_t Avtp_Sensor_GetNumSensor(Avtp_Sensor_t* pdu); +uint8_t Avtp_Sensor_GetSz(Avtp_Sensor_t* pdu); +uint8_t Avtp_Sensor_GetSensorGroup(Avtp_Sensor_t* pdu); +uint64_t Avtp_Sensor_GetMessageTimestamp(Avtp_Sensor_t* pdu); /** * Sets the value of an ACF Sensor PDU field as specified in the IEEE 1722 Specification. @@ -88,7 +94,13 @@ int Avtp_Sensor_GetField(Avtp_Sensor_t* sensor_pdu, Avtp_SensorFields_t field, u * @param pdu Pointer to the first bit of an 1722 ACF Sensor PDU. * @param field Specifies the position of the data field to be read * @param value Pointer to location to store the value. - * @returns This function returns 0 if the data field was successfully set in - * the 1722 ACF Sensor PDU. */ -int Avtp_Sensor_SetField(Avtp_Sensor_t* sensor_pdu, Avtp_SensorFields_t field, uint64_t value); +void Avtp_Sensor_SetField(Avtp_Sensor_t* pdu, Avtp_SensorFields_t field, uint64_t value); + +void Avtp_Sensor_SetAcfMsgType(Avtp_Sensor_t* pdu, uint8_t value); +void Avtp_Sensor_SetAcfMsgLength(Avtp_Sensor_t* pdu, uint16_t value); +void Avtp_Sensor_SetMtv(Avtp_Sensor_t* pdu, uint8_t value); +void Avtp_Sensor_SetNumSensor(Avtp_Sensor_t* pdu, uint8_t value); +void Avtp_Sensor_SetSz(Avtp_Sensor_t* pdu, uint8_t value); +void Avtp_Sensor_SetSensorGroup(Avtp_Sensor_t* pdu, uint8_t value); +void Avtp_Sensor_SetMessageTimestamp(Avtp_Sensor_t* pdu, uint64_t value); diff --git a/src/avtp/acf/Sensor.c b/src/avtp/acf/Sensor.c index d9c9886..c5cf113 100644 --- a/src/avtp/acf/Sensor.c +++ b/src/avtp/acf/Sensor.c @@ -30,11 +30,15 @@ #include #include -#include "avtp/acf/Common.h" #include "avtp/acf/Sensor.h" #include "avtp/Utils.h" #include "avtp/Defines.h" +#define GET_FIELD(field) \ + (Avtp_GetField(Avtp_SensorFieldDesc, AVTP_SENSOR_FIELD_MAX, (uint8_t*)pdu, field)) +#define SET_FIELD(field, value) \ + (Avtp_SetField(Avtp_SensorFieldDesc, AVTP_SENSOR_FIELD_MAX, (uint8_t*)pdu, field, value)) + /** * This table maps all IEEE 1722 ACF Sensor header fields to a descriptor. */ @@ -52,24 +56,90 @@ static const Avtp_FieldDescriptor_t Avtp_SensorFieldDesc[AVTP_SENSOR_FIELD_MAX] }; -int Avtp_Sensor_Init(Avtp_Sensor_t* sensor_pdu) +void Avtp_Sensor_Init(Avtp_Sensor_t* pdu) { - if(!sensor_pdu) { - return -EINVAL; + if(pdu != NULL) { + memset(pdu, 0, sizeof(Avtp_Sensor_t)); + Avtp_Sensor_SetField(pdu, AVTP_SENSOR_FIELD_ACF_MSG_TYPE, AVTP_ACF_TYPE_SENSOR); } +} + +uint64_t Avtp_Sensor_GetField(Avtp_Sensor_t* pdu, Avtp_SensorFields_t field) +{ + return GET_FIELD(field); +} + +uint8_t Avtp_Sensor_GetAcfMsgType(Avtp_Sensor_t* pdu) +{ + return GET_FIELD(AVTP_SENSOR_FIELD_ACF_MSG_TYPE); +} + +uint16_t Avtp_Sensor_GetAcfMsgLength(Avtp_Sensor_t* pdu) +{ + return GET_FIELD(AVTP_SENSOR_FIELD_ACF_MSG_LENGTH); +} + +uint8_t Avtp_Sensor_GetMtv(Avtp_Sensor_t* pdu) +{ + return GET_FIELD(AVTP_SENSOR_FIELD_MTV); +} + +uint8_t Avtp_Sensor_GetNumSensor(Avtp_Sensor_t* pdu) +{ + return GET_FIELD(AVTP_SENSOR_FIELD_NUM_SENSOR); +} + +uint8_t Avtp_Sensor_GetSz(Avtp_Sensor_t* pdu) +{ + return GET_FIELD(AVTP_SENSOR_FIELD_SZ); +} + +uint8_t Avtp_Sensor_GetSensorGroup(Avtp_Sensor_t* pdu) +{ + return GET_FIELD(AVTP_SENSOR_FIELD_SENSOR_GROUP); +} + +uint64_t Avtp_Sensor_GetMessageTimestamp(Avtp_Sensor_t* pdu) +{ + return GET_FIELD(AVTP_SENSOR_FIELD_MESSAGE_TIMESTAMP); +} + +void Avtp_Sensor_SetField(Avtp_Sensor_t* pdu, Avtp_SensorFields_t field, uint64_t value) +{ + Avtp_SetField(Avtp_SensorFieldDesc, AVTP_SENSOR_FIELD_MAX, (uint8_t *)pdu, (uint8_t)field, value); +} + +void Avtp_Sensor_SetAcfMsgType(Avtp_Sensor_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_SENSOR_FIELD_ACF_MSG_TYPE, value); +} - memset(sensor_pdu, 0, sizeof(Avtp_Sensor_t)); - Avtp_Sensor_SetField(sensor_pdu, AVTP_SENSOR_FIELD_ACF_MSG_TYPE, AVTP_ACF_TYPE_SENSOR); - - return 0; +void Avtp_Sensor_SetAcfMsgLength(Avtp_Sensor_t* pdu, uint16_t value) +{ + SET_FIELD(AVTP_SENSOR_FIELD_ACF_MSG_LENGTH, value); +} + +void Avtp_Sensor_SetMtv(Avtp_Sensor_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_SENSOR_FIELD_MTV, value); +} + +void Avtp_Sensor_SetNumSensor(Avtp_Sensor_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_SENSOR_FIELD_NUM_SENSOR, value); +} + +void Avtp_Sensor_SetSz(Avtp_Sensor_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_SENSOR_FIELD_SZ, value); } -int Avtp_Sensor_GetField(Avtp_Sensor_t* sensor_pdu, Avtp_SensorFields_t field, uint64_t* value) +void Avtp_Sensor_SetSensorGroup(Avtp_Sensor_t* pdu, uint8_t value) { - return Avtp_GetField(Avtp_SensorFieldDesc, AVTP_SENSOR_FIELD_MAX, (uint8_t *)sensor_pdu, (uint8_t)field, value); + SET_FIELD(AVTP_SENSOR_FIELD_SENSOR_GROUP, value); } -int Avtp_Sensor_SetField(Avtp_Sensor_t* sensor_pdu, Avtp_SensorFields_t field, uint64_t value) +void Avtp_Sensor_SetMessageTimestamp(Avtp_Sensor_t* pdu, uint64_t value) { - return Avtp_SetField(Avtp_SensorFieldDesc, AVTP_SENSOR_FIELD_MAX, (uint8_t *)sensor_pdu, (uint8_t)field, value); + SET_FIELD(AVTP_SENSOR_FIELD_MESSAGE_TIMESTAMP, value); } From fc278536108c4470660ee4e6a272d0dafe3681e2 Mon Sep 17 00:00:00 2001 From: Adriaan Niess Date: Mon, 26 Aug 2024 21:47:13 +0200 Subject: [PATCH 22/33] Update GetField API for SensorBrief.h/c Signed-off-by: Adriaan Niess --- include/avtp/acf/SensorBrief.h | 28 ++++++++---- src/avtp/acf/SensorBrief.c | 84 +++++++++++++++++++++++++++++----- 2 files changed, 91 insertions(+), 21 deletions(-) diff --git a/include/avtp/acf/SensorBrief.h b/include/avtp/acf/SensorBrief.h index c8af01a..aeb7e5d 100644 --- a/include/avtp/acf/SensorBrief.h +++ b/include/avtp/acf/SensorBrief.h @@ -38,7 +38,7 @@ #include #include "avtp/Defines.h" -#include "avtp/acf/Common.h" +#include "avtp/acf/AcfCommon.h" #define AVTP_SENSOR_HEADER_LEN (1 * AVTP_QUADLET_SIZE) @@ -65,18 +65,23 @@ typedef enum { * * @param pdu Pointer to the first bit of a 1722 ACF Abbreviated Sensor PDU. */ -int Avtp_SensorBrief_Init(Avtp_SensorBrief_t* sensor_pdu); +void Avtp_SensorBrief_Init(Avtp_SensorBrief_t* pdu); /** * Returns the value of an an ACF Abbreviated Sensor PDU field as specified in the IEEE 1722 Specification. * * @param pdu Pointer to the first bit of an 1722 ACF Abbreviated Sensor PDU. * @param field Specifies the position of the data field to be read - * @param value Pointer to location to store the value. - * @returns This function returns 0 if the data field was successfully read from - * the 1722 ACF Abbreviated Sensor PDU. + * @returns Field of the PDU. */ -int Avtp_SensorBrief_GetField(Avtp_SensorBrief_t* sensor_pdu, Avtp_SensorBriefFields_t field, uint64_t* value); +uint64_t Avtp_SensorBrief_GetField(Avtp_SensorBrief_t* pdu, Avtp_SensorBriefFields_t field); + +uint8_t Avtp_SensorBrief_GetAcfMsgType(Avtp_SensorBrief_t* pdu); +uint16_t Avtp_SensorBrief_GetAcfMsgLength(Avtp_SensorBrief_t* pdu); +uint8_t Avtp_SensorBrief_GetMtv(Avtp_SensorBrief_t* pdu); +uint8_t Avtp_SensorBrief_GetNumSensor(Avtp_SensorBrief_t* pdu); +uint8_t Avtp_SensorBrief_GetSz(Avtp_SensorBrief_t* pdu); +uint8_t Avtp_SensorBrief_GetSensorGroup(Avtp_SensorBrief_t* pdu); /** * Sets the value of an an ACF Abbreviated Sensor PDU field as specified in the IEEE 1722 Specification. @@ -84,7 +89,12 @@ int Avtp_SensorBrief_GetField(Avtp_SensorBrief_t* sensor_pdu, Avtp_SensorBriefFi * @param pdu Pointer to the first bit of an 1722 ACF Abbreviated Sensor PDU. * @param field Specifies the position of the data field to be read * @param value Pointer to location to store the value. - * @returns This function returns 0 if the data field was successfully set in - * the 1722 ACF Abbreviated Sensor PDU. */ -int Avtp_SensorBrief_SetField(Avtp_SensorBrief_t* sensor_pdu, Avtp_SensorBriefFields_t field, uint64_t value); +void Avtp_SensorBrief_SetField(Avtp_SensorBrief_t* pdu, Avtp_SensorBriefFields_t field, uint64_t value); + +void Avtp_SensorBrief_SetAcfMsgType(Avtp_SensorBrief_t* pdu, uint8_t value); +void Avtp_SensorBrief_SetAcfMsgLength(Avtp_SensorBrief_t* pdu, uint16_t value); +void Avtp_SensorBrief_SetMtv(Avtp_SensorBrief_t* pdu, uint8_t value); +void Avtp_SensorBrief_SetNumSensor(Avtp_SensorBrief_t* pdu, uint8_t value); +void Avtp_SensorBrief_SetSz(Avtp_SensorBrief_t* pdu, uint8_t value); +void Avtp_SensorBrief_SetSensorGroup(Avtp_SensorBrief_t* pdu, uint8_t value); diff --git a/src/avtp/acf/SensorBrief.c b/src/avtp/acf/SensorBrief.c index 1767713..d19e8d9 100644 --- a/src/avtp/acf/SensorBrief.c +++ b/src/avtp/acf/SensorBrief.c @@ -30,11 +30,15 @@ #include #include -#include "avtp/acf/Common.h" #include "avtp/acf/SensorBrief.h" #include "avtp/Utils.h" #include "avtp/Defines.h" +#define GET_FIELD(field) \ + (Avtp_GetField(Avtp_SensorBriefFieldDesc, AVTP_SENSOR_FIELD_MAX, (uint8_t*)pdu, field)) +#define SET_FIELD(field, value) \ + (Avtp_SetField(Avtp_SensorBriefFieldDesc, AVTP_SENSOR_FIELD_MAX, (uint8_t*)pdu, field, value)) + /** * This table maps all IEEE 1722 ACF Abbreviated Sensor header fields to a descriptor. */ @@ -52,24 +56,80 @@ static const Avtp_FieldDescriptor_t Avtp_SensorBriefFieldDesc[AVTP_SENSOR_FIELD_ [AVTP_SENSOR_BRIEF_FIELD_SENSOR_GROUP] = { .quadlet = 0, .offset = 26, .bits = 6 }, }; -int Avtp_SensorBrief_Init(Avtp_SensorBrief_t* sensor_pdu) +void Avtp_SensorBrief_Init(Avtp_SensorBrief_t* pdu) { - if(!sensor_pdu) { - return -EINVAL; + if(pdu != NULL) { + memset(pdu, 0, sizeof(Avtp_SensorBrief_t)); + Avtp_SensorBrief_SetField(pdu, AVTP_SENSOR_BRIEF_FIELD_ACF_MSG_TYPE, AVTP_ACF_TYPE_SENSOR_BRIEF); } +} + +uint64_t Avtp_SensorBrief_GetField(Avtp_SensorBrief_t* pdu, Avtp_SensorBriefFields_t field) +{ + return GET_FIELD(field); +} - memset(sensor_pdu, 0, sizeof(Avtp_SensorBrief_t)); - Avtp_SensorBrief_SetField(sensor_pdu, AVTP_SENSOR_BRIEF_FIELD_ACF_MSG_TYPE, AVTP_ACF_TYPE_SENSOR_BRIEF); +uint8_t Avtp_SensorBrief_GetAcfMsgType(Avtp_SensorBrief_t* pdu) +{ + return GET_FIELD(AVTP_SENSOR_BRIEF_FIELD_ACF_MSG_TYPE); +} - return 0; +uint16_t Avtp_SensorBrief_GetAcfMsgLength(Avtp_SensorBrief_t* pdu) +{ + return GET_FIELD(AVTP_SENSOR_BRIEF_FIELD_ACF_MSG_LENGTH); } -int Avtp_SensorBrief_GetField(Avtp_SensorBrief_t* sensor_pdu, Avtp_SensorBriefFields_t field, uint64_t* value) -{ - return Avtp_GetField(Avtp_SensorBriefFieldDesc, AVTP_SENSOR_FIELD_MAX, (uint8_t *) sensor_pdu, (uint8_t) field, value); +uint8_t Avtp_SensorBrief_GetMtv(Avtp_SensorBrief_t* pdu) +{ + return GET_FIELD(AVTP_SENSOR_BRIEF_FIELD_MTV); +} + +uint8_t Avtp_SensorBrief_GetNumSensor(Avtp_SensorBrief_t* pdu) +{ + return GET_FIELD(AVTP_SENSOR_BRIEF_FIELD_NUM_SENSOR); +} + +uint8_t Avtp_SensorBrief_GetSz(Avtp_SensorBrief_t* pdu) +{ + return GET_FIELD(AVTP_SENSOR_BRIEF_FIELD_SZ); +} + +uint8_t Avtp_SensorBrief_GetSensorGroup(Avtp_SensorBrief_t* pdu) +{ + return GET_FIELD(AVTP_SENSOR_BRIEF_FIELD_SENSOR_GROUP); } -int Avtp_SensorBrief_SetField(Avtp_SensorBrief_t* sensor_pdu, Avtp_SensorBriefFields_t field, uint64_t value) +void Avtp_SensorBrief_SetField(Avtp_SensorBrief_t* pdu, Avtp_SensorBriefFields_t field, uint64_t value) { - return Avtp_SetField(Avtp_SensorBriefFieldDesc, AVTP_SENSOR_FIELD_MAX, (uint8_t *) sensor_pdu, (uint8_t) field, value); + SET_FIELD(field, value); +} + +void Avtp_SensorBrief_SetAcfMsgType(Avtp_SensorBrief_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_SENSOR_BRIEF_FIELD_ACF_MSG_TYPE, value); +} + +void Avtp_SensorBrief_SetAcfMsgLength(Avtp_SensorBrief_t* pdu, uint16_t value) +{ + SET_FIELD(AVTP_SENSOR_BRIEF_FIELD_ACF_MSG_LENGTH, value); +} + +void Avtp_SensorBrief_SetMtv(Avtp_SensorBrief_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_SENSOR_BRIEF_FIELD_MTV, value); +} + +void Avtp_SensorBrief_SetNumSensor(Avtp_SensorBrief_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_SENSOR_BRIEF_FIELD_NUM_SENSOR, value); +} + +void Avtp_SensorBrief_SetSz(Avtp_SensorBrief_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_SENSOR_BRIEF_FIELD_SZ, value); +} + +void Avtp_SensorBrief_SetSensorGroup(Avtp_SensorBrief_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_SENSOR_BRIEF_FIELD_SENSOR_GROUP, value); } From efc35bfc968d11c8ac8a633c8e5b6010ac7b0a1b Mon Sep 17 00:00:00 2001 From: Adriaan Niess Date: Tue, 27 Aug 2024 10:34:53 +0200 Subject: [PATCH 23/33] Update GetField API for Aaf.h/c Signed-off-by: Adriaan Niess --- CMakeLists.txt | 2 +- include/avtp/aaf/{AafCommonStream.h => Aaf.h} | 76 +++++-- src/avtp/aaf/Aaf.c | 209 ++++++++++++++++++ src/avtp/aaf/AafCommonStream.c | 64 ------ 4 files changed, 263 insertions(+), 88 deletions(-) rename include/avtp/aaf/{AafCommonStream.h => Aaf.h} (52%) create mode 100644 src/avtp/aaf/Aaf.c delete mode 100644 src/avtp/aaf/AafCommonStream.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 42ac473..ea6b8f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ add_library(open1722 SHARED "src/avtp/Rvf.c" "src/avtp/Udp.c" "src/avtp/Utils.c" - "src/avtp/aaf/AafCommonStream.c" + "src/avtp/aaf/Aaf.c" "src/avtp/aaf/PcmStream.c" "src/avtp/acf/FlexRay.c" "src/avtp/acf/Gpc.c" diff --git a/include/avtp/aaf/AafCommonStream.h b/include/avtp/aaf/Aaf.h similarity index 52% rename from include/avtp/aaf/AafCommonStream.h rename to include/avtp/aaf/Aaf.h index 892682e..605ab46 100644 --- a/include/avtp/aaf/AafCommonStream.h +++ b/include/avtp/aaf/Aaf.h @@ -39,32 +39,32 @@ #include "avtp/Defines.h" -#define AVTP_AAF_COMMON_STREAM_HEADER_LEN (6 * AVTP_QUADLET_SIZE) +#define AVTP_AAF_HEADER_LEN (6 * AVTP_QUADLET_SIZE) typedef struct { - uint8_t header[AVTP_AAF_COMMON_STREAM_HEADER_LEN]; + uint8_t header[AVTP_AAF_HEADER_LEN]; uint8_t payload[0]; -} Avtp_AafCommonStream_t; +} Avtp_Aaf_t; typedef enum { - AVTP_AAF_COMMON_STREAM_FIELD_SUBTYPE, - AVTP_AAF_COMMON_STREAM_FIELD_SV, - AVTP_AAF_COMMON_STREAM_FIELD_VERSION, - AVTP_AAF_COMMON_STREAM_FIELD_MR, - AVTP_AAF_COMMON_STREAM_FIELD_TV, - AVTP_AAF_COMMON_STREAM_FIELD_SEQUENCE_NUM, - AVTP_AAF_COMMON_STREAM_FIELD_TU, - AVTP_AAF_COMMON_STREAM_FIELD_STREAM_ID, - AVTP_AAF_COMMON_STREAM_FIELD_AVTP_TIMESTAMP, - AVTP_AAF_COMMON_STREAM_FIELD_FORMAT, - AVTP_AAF_COMMON_STREAM_FIELD_AAF_FORMAT_SPECIFIC_DATA_1, - AVTP_AAF_COMMON_STREAM_FIELD_STREAM_DATA_LENGTH, - AVTP_AAF_COMMON_STREAM_FIELD_AFSD, - AVTP_AAF_COMMON_STREAM_FIELD_SP, - AVTP_AAF_COMMON_STREAM_FIELD_EVT, - AVTP_AAF_COMMON_STREAM_FIELD_AAF_FORMAT_SPECIFIC_DATA_2, - AVTP_AAF_COMMON_STREAM_FIELD_MAX -} Avtp_AafCommonStreamFields_t; + AVTP_AAF_FIELD_SUBTYPE, + AVTP_AAF_FIELD_SV, + AVTP_AAF_FIELD_VERSION, + AVTP_AAF_FIELD_MR, + AVTP_AAF_FIELD_TV, + AVTP_AAF_FIELD_SEQUENCE_NUM, + AVTP_AAF_FIELD_TU, + AVTP_AAF_FIELD_STREAM_ID, + AVTP_AAF_FIELD_AVTP_TIMESTAMP, + AVTP_AAF_FIELD_FORMAT, + AVTP_AAF_FIELD_AAF_FORMAT_SPECIFIC_DATA_1, + AVTP_AAF_FIELD_STREAM_DATA_LENGTH, + AVTP_AAF_FIELD_AFSD, + AVTP_AAF_FIELD_SP, + AVTP_AAF_FIELD_EVT, + AVTP_AAF_FIELD_AAF_FORMAT_SPECIFIC_DATA_2, + AVTP_AAF_FIELD_MAX +} Avtp_AafFields_t; /** * Returns the value of an an AVTP AAF common stream field as specified in the IEEE 1722 Specification. @@ -74,7 +74,22 @@ typedef enum { * @param value Pointer to location to store the value. * @returns The PDU fieldvalue */ -uint64_t Avtp_AafCommonStream_GetField(Avtp_AafCommonStream_t* pdu, Avtp_AafCommonStreamFields_t field); +uint64_t Avtp_Aaf_GetField(Avtp_Aaf_t* pdu, Avtp_AafFields_t field); + +uint8_t Avtp_Aaf_GetSubtype(Avtp_Aaf_t* pdu); +uint8_t Avtp_Aaf_GetSv(Avtp_Aaf_t* pdu); +uint8_t Avtp_Aaf_GetVersion(Avtp_Aaf_t* pdu); +uint8_t Avtp_Aaf_GetMr(Avtp_Aaf_t* pdu); +uint8_t Avtp_Aaf_GetTv(Avtp_Aaf_t* pdu); +uint8_t Avtp_Aaf_GetSequenceNum(Avtp_Aaf_t* pdu); +uint8_t Avtp_Aaf_GetTu(Avtp_Aaf_t* pdu); +uint64_t Avtp_Aaf_GetStreamId(Avtp_Aaf_t* pdu); +uint32_t Avtp_Aaf_GetAvtpTimestamp(Avtp_Aaf_t* pdu); +uint8_t Avtp_Aaf_GetFormat(Avtp_Aaf_t* pdu); +uint16_t Avtp_Aaf_GetStreamDataLength(Avtp_Aaf_t* pdu); +uint8_t Avtp_Aaf_GetAfsd(Avtp_Aaf_t* pdu); +uint8_t Avtp_Aaf_GetSp(Avtp_Aaf_t* pdu); +uint8_t Avtp_Aaf_GetEvt(Avtp_Aaf_t* pdu); /** * Sets the value of an an AVTP AAF common stream field as specified in the IEEE 1722 Specification. @@ -83,4 +98,19 @@ uint64_t Avtp_AafCommonStream_GetField(Avtp_AafCommonStream_t* pdu, Avtp_AafComm * @param field Specifies the position of the data field to be read * @param value Pointer to location to store the value. */ -void Avtp_AafCommonStream_SetField(Avtp_AafCommonStream_t* pdu, Avtp_AafCommonStreamFields_t field, uint64_t value); \ No newline at end of file +void Avtp_Aaf_SetField(Avtp_Aaf_t* pdu, Avtp_AafFields_t field, uint64_t value); + +void Avtp_Aaf_SetSubtype(Avtp_Aaf_t* pdu, uint8_t value); +void Avtp_Aaf_SetSv(Avtp_Aaf_t* pdu, uint8_t value); +void Avtp_Aaf_SetVersion(Avtp_Aaf_t* pdu, uint8_t value); +void Avtp_Aaf_SetMr(Avtp_Aaf_t* pdu, uint8_t value); +void Avtp_Aaf_SetTv(Avtp_Aaf_t* pdu, uint8_t value); +void Avtp_Aaf_SetSequenceNum(Avtp_Aaf_t* pdu, uint8_t value); +void Avtp_Aaf_SetTu(Avtp_Aaf_t* pdu, uint8_t value); +void Avtp_Aaf_SetStreamId(Avtp_Aaf_t* pdu, uint64_t value); +void Avtp_Aaf_SetAvtpTimestamp(Avtp_Aaf_t* pdu, uint32_t value); +void Avtp_Aaf_SetFormat(Avtp_Aaf_t* pdu, uint8_t value); +void Avtp_Aaf_SetStreamDataLength(Avtp_Aaf_t* pdu, uint16_t value); +void Avtp_Aaf_SetAfsd(Avtp_Aaf_t* pdu, uint8_t value); +void Avtp_Aaf_SetSp(Avtp_Aaf_t* pdu, uint8_t value); +void Avtp_Aaf_SetEvt(Avtp_Aaf_t* pdu, uint8_t value); diff --git a/src/avtp/aaf/Aaf.c b/src/avtp/aaf/Aaf.c new file mode 100644 index 0000000..f88da43 --- /dev/null +++ b/src/avtp/aaf/Aaf.c @@ -0,0 +1,209 @@ +/* + * Copyright (c) 2024, COVESA + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of COVESA nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +#include +#include + +#include "avtp/CommonHeader.h" +#include "avtp/aaf/Aaf.h" +#include "avtp/Utils.h" + +#define GET_FIELD(field) \ + (Avtp_GetField(Avtp_AafFieldDesc, AVTP_AAF_FIELD_MAX, (uint8_t*)pdu, field)) +#define SET_FIELD(field, value) \ + (Avtp_SetField(Avtp_AafFieldDesc, AVTP_AAF_FIELD_MAX, (uint8_t*)pdu, field, value)) + +static const Avtp_FieldDescriptor_t Avtp_AafFieldDesc[AVTP_AAF_FIELD_MAX] = +{ + [AVTP_AAF_FIELD_SUBTYPE] = { .quadlet = 0, .offset = 0, .bits = 8 }, + [AVTP_AAF_FIELD_SV] = { .quadlet = 0, .offset = 8, .bits = 1 }, + [AVTP_AAF_FIELD_VERSION] = { .quadlet = 0, .offset = 9, .bits = 3 }, + [AVTP_AAF_FIELD_MR] = { .quadlet = 0, .offset = 12, .bits = 1 }, + [AVTP_AAF_FIELD_TV] = { .quadlet = 0, .offset = 15, .bits = 1 }, + [AVTP_AAF_FIELD_SEQUENCE_NUM] = { .quadlet = 0, .offset = 16, .bits = 8 }, + [AVTP_AAF_FIELD_TU] = { .quadlet = 0, .offset = 31, .bits = 1 }, + [AVTP_AAF_FIELD_STREAM_ID] = { .quadlet = 1, .offset = 0, .bits = 64 }, + [AVTP_AAF_FIELD_AVTP_TIMESTAMP] = { .quadlet = 3, .offset = 0, .bits = 32 }, + [AVTP_AAF_FIELD_FORMAT] = { .quadlet = 4, .offset = 0, .bits = 8 }, + [AVTP_AAF_FIELD_AAF_FORMAT_SPECIFIC_DATA_1] = { .quadlet = 4, .offset = 8, .bits = 24 }, + [AVTP_AAF_FIELD_STREAM_DATA_LENGTH] = { .quadlet = 5, .offset = 0, .bits = 16 }, + [AVTP_AAF_FIELD_AFSD] = { .quadlet = 5, .offset = 16, .bits = 3 }, + [AVTP_AAF_FIELD_SP] = { .quadlet = 5, .offset = 19, .bits = 1 }, + [AVTP_AAF_FIELD_EVT] = { .quadlet = 5, .offset = 20, .bits = 4 }, + [AVTP_AAF_FIELD_AAF_FORMAT_SPECIFIC_DATA_2] = { .quadlet = 5, .offset = 24, .bits = 8 }, +}; + +uint64_t Avtp_Aaf_GetField(Avtp_Aaf_t* pdu, Avtp_AafFields_t field) +{ + return Avtp_GetField(Avtp_AafFieldDesc, AVTP_AAF_FIELD_MAX, (uint8_t*)pdu, (uint8_t) field); +} + +uint8_t Avtp_Aaf_GetSubtype(Avtp_Aaf_t* pdu) +{ + return GET_FIELD(AVTP_AAF_FIELD_SUBTYPE); +} + +uint8_t Avtp_Aaf_GetSv(Avtp_Aaf_t* pdu) +{ + return GET_FIELD(AVTP_AAF_FIELD_SV); +} + +uint8_t Avtp_Aaf_GetVersion(Avtp_Aaf_t* pdu) +{ + return GET_FIELD(AVTP_AAF_FIELD_VERSION); +} + +uint8_t Avtp_Aaf_GetMr(Avtp_Aaf_t* pdu) +{ + return GET_FIELD(AVTP_AAF_FIELD_MR); +} + +uint8_t Avtp_Aaf_GetTv(Avtp_Aaf_t* pdu) +{ + return GET_FIELD(AVTP_AAF_FIELD_TV); +} + +uint8_t Avtp_Aaf_GetSequenceNum(Avtp_Aaf_t* pdu) +{ + return GET_FIELD(AVTP_AAF_FIELD_SEQUENCE_NUM); +} + +uint8_t Avtp_Aaf_GetTu(Avtp_Aaf_t* pdu) +{ + return GET_FIELD(AVTP_AAF_FIELD_TU); +} + +uint64_t Avtp_Aaf_GetStreamId(Avtp_Aaf_t* pdu) +{ + return GET_FIELD(AVTP_AAF_FIELD_STREAM_ID); +} + +uint32_t Avtp_Aaf_GetAvtpTimestamp(Avtp_Aaf_t* pdu) +{ + return GET_FIELD(AVTP_AAF_FIELD_AVTP_TIMESTAMP); +} + +uint8_t Avtp_Aaf_GetFormat(Avtp_Aaf_t* pdu) +{ + return GET_FIELD(AVTP_AAF_FIELD_FORMAT); +} + +uint16_t Avtp_Aaf_GetStreamDataLength(Avtp_Aaf_t* pdu) +{ + return GET_FIELD(AVTP_AAF_FIELD_STREAM_DATA_LENGTH); +} + +uint8_t Avtp_Aaf_GetAfsd(Avtp_Aaf_t* pdu) +{ + return GET_FIELD(AVTP_AAF_FIELD_AFSD); +} + +uint8_t Avtp_Aaf_GetSp(Avtp_Aaf_t* pdu) +{ + return GET_FIELD(AVTP_AAF_FIELD_SP); +} + +uint8_t Avtp_Aaf_GetEvt(Avtp_Aaf_t* pdu) +{ + return GET_FIELD(AVTP_AAF_FIELD_EVT); +} + +void Avtp_Aaf_SetField(Avtp_Aaf_t* pdu, Avtp_AafFields_t field, uint64_t value) +{ + Avtp_SetField(Avtp_AafFieldDesc, AVTP_AAF_FIELD_MAX, (uint8_t*)pdu, (uint8_t) field, value); +} + +void Avtp_Aaf_SetSubtype(Avtp_Aaf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_AAF_FIELD_SUBTYPE, value); +} + +void Avtp_Aaf_SetSv(Avtp_Aaf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_AAF_FIELD_SV, value); +} + +void Avtp_Aaf_SetVersion(Avtp_Aaf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_AAF_FIELD_VERSION, value); +} + +void Avtp_Aaf_SetMr(Avtp_Aaf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_AAF_FIELD_MR, value); +} + +void Avtp_Aaf_SetTv(Avtp_Aaf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_AAF_FIELD_TV, value); +} + +void Avtp_Aaf_SetSequenceNum(Avtp_Aaf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_AAF_FIELD_SEQUENCE_NUM, value); +} + +void Avtp_Aaf_SetTu(Avtp_Aaf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_AAF_FIELD_TU, value); +} + +void Avtp_Aaf_SetStreamId(Avtp_Aaf_t* pdu, uint64_t value) +{ + SET_FIELD(AVTP_AAF_FIELD_STREAM_ID, value); +} + +void Avtp_Aaf_SetAvtpTimestamp(Avtp_Aaf_t* pdu, uint32_t value) +{ + SET_FIELD(AVTP_AAF_FIELD_AVTP_TIMESTAMP, value); +} + +void Avtp_Aaf_SetFormat(Avtp_Aaf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_AAF_FIELD_FORMAT, value); +} + +void Avtp_Aaf_SetStreamDataLength(Avtp_Aaf_t* pdu, uint16_t value) +{ + SET_FIELD(AVTP_AAF_FIELD_STREAM_DATA_LENGTH, value); +} + +void Avtp_Aaf_SetAfsd(Avtp_Aaf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_AAF_FIELD_AFSD, value); +} + +void Avtp_Aaf_SetSp(Avtp_Aaf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_AAF_FIELD_SP, value); +} + +void Avtp_Aaf_SetEvt(Avtp_Aaf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_AAF_FIELD_EVT, value); +} diff --git a/src/avtp/aaf/AafCommonStream.c b/src/avtp/aaf/AafCommonStream.c deleted file mode 100644 index 72ca06a..0000000 --- a/src/avtp/aaf/AafCommonStream.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2024, COVESA - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of COVESA nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * SPDX-License-Identifier: BSD-3-Clause - */ -#include -#include - -#include "avtp/CommonHeader.h" -#include "avtp/aaf/AafCommonStream.h" -#include "avtp/Utils.h" - -static const Avtp_FieldDescriptor_t Avtp_AafCommonStreamFieldDesc[AVTP_AAF_COMMON_STREAM_FIELD_MAX] = -{ - [AVTP_AAF_COMMON_STREAM_FIELD_SUBTYPE] = { .quadlet = 0, .offset = 0, .bits = 8 }, - [AVTP_AAF_COMMON_STREAM_FIELD_SV] = { .quadlet = 0, .offset = 8, .bits = 1 }, - [AVTP_AAF_COMMON_STREAM_FIELD_VERSION] = { .quadlet = 0, .offset = 9, .bits = 3 }, - [AVTP_AAF_COMMON_STREAM_FIELD_MR] = { .quadlet = 0, .offset = 12, .bits = 1 }, - [AVTP_AAF_COMMON_STREAM_FIELD_TV] = { .quadlet = 0, .offset = 15, .bits = 1 }, - [AVTP_AAF_COMMON_STREAM_FIELD_SEQUENCE_NUM] = { .quadlet = 0, .offset = 16, .bits = 8 }, - [AVTP_AAF_COMMON_STREAM_FIELD_TU] = { .quadlet = 0, .offset = 31, .bits = 1 }, - [AVTP_AAF_COMMON_STREAM_FIELD_STREAM_ID] = { .quadlet = 1, .offset = 0, .bits = 64 }, - [AVTP_AAF_COMMON_STREAM_FIELD_AVTP_TIMESTAMP] = { .quadlet = 3, .offset = 0, .bits = 32 }, - [AVTP_AAF_COMMON_STREAM_FIELD_FORMAT] = { .quadlet = 4, .offset = 0, .bits = 8 }, - [AVTP_AAF_COMMON_STREAM_FIELD_AAF_FORMAT_SPECIFIC_DATA_1] = { .quadlet = 4, .offset = 8, .bits = 24 }, - [AVTP_AAF_COMMON_STREAM_FIELD_STREAM_DATA_LENGTH] = { .quadlet = 5, .offset = 0, .bits = 16 }, - [AVTP_AAF_COMMON_STREAM_FIELD_AFSD] = { .quadlet = 5, .offset = 16, .bits = 3 }, - [AVTP_AAF_COMMON_STREAM_FIELD_SP] = { .quadlet = 5, .offset = 19, .bits = 1 }, - [AVTP_AAF_COMMON_STREAM_FIELD_EVT] = { .quadlet = 5, .offset = 20, .bits = 4 }, - [AVTP_AAF_COMMON_STREAM_FIELD_AAF_FORMAT_SPECIFIC_DATA_2] = { .quadlet = 5, .offset = 24, .bits = 8 }, -}; - -uint64_t Avtp_AafCommonStream_GetField(Avtp_AafCommonStream_t* pdu, Avtp_AafCommonStreamFields_t field) -{ - return Avtp_GetField(Avtp_AafCommonStreamFieldDesc, AVTP_AAF_COMMON_STREAM_FIELD_MAX, (uint8_t*)pdu, (uint8_t) field); -} - -void Avtp_AafCommonStream_SetField(Avtp_AafCommonStream_t* pdu, Avtp_AafCommonStreamFields_t field, uint64_t value) -{ - Avtp_SetField(Avtp_AafCommonStreamFieldDesc, AVTP_AAF_COMMON_STREAM_FIELD_MAX, (uint8_t*)pdu, (uint8_t) field, value); -} \ No newline at end of file From 2936574b1436adc807c3ca372b6da0e02c6b70e6 Mon Sep 17 00:00:00 2001 From: Adriaan Niess Date: Tue, 27 Aug 2024 22:45:54 +0200 Subject: [PATCH 24/33] Update GetField API for Pcm.h/c Signed-off-by: Adriaan Niess --- CMakeLists.txt | 2 +- include/avtp/aaf/{PcmStream.h => Pcm.h} | 116 ++++++---- src/avtp/Utils.c | 1 + src/avtp/aaf/Pcm.c | 286 ++++++++++++++++++++++++ src/avtp/aaf/PcmStream.c | 121 ---------- 5 files changed, 363 insertions(+), 163 deletions(-) rename include/avtp/aaf/{PcmStream.h => Pcm.h} (56%) create mode 100644 src/avtp/aaf/Pcm.c delete mode 100644 src/avtp/aaf/PcmStream.c diff --git a/CMakeLists.txt b/CMakeLists.txt index ea6b8f7..030b1a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ add_library(open1722 SHARED "src/avtp/Udp.c" "src/avtp/Utils.c" "src/avtp/aaf/Aaf.c" - "src/avtp/aaf/PcmStream.c" + "src/avtp/aaf/Pcm.c" "src/avtp/acf/FlexRay.c" "src/avtp/acf/Gpc.c" "src/avtp/acf/Can.c" diff --git a/include/avtp/aaf/PcmStream.h b/include/avtp/aaf/Pcm.h similarity index 56% rename from include/avtp/aaf/PcmStream.h rename to include/avtp/aaf/Pcm.h index 632c0ab..4b51a22 100644 --- a/include/avtp/aaf/PcmStream.h +++ b/include/avtp/aaf/Pcm.h @@ -34,32 +34,32 @@ #include "avtp/Defines.h" -#define AVTP_AAF_PCM_STREAM_HEADER_LEN (6 * AVTP_QUADLET_SIZE) +#define AVTP_PCM_HEADER_LEN (6 * AVTP_QUADLET_SIZE) typedef struct { - uint8_t header[AVTP_AAF_PCM_STREAM_HEADER_LEN]; + uint8_t header[AVTP_PCM_HEADER_LEN]; uint8_t payload[0]; -} Avtp_AafPcmStream_t; +} Avtp_Pcm_t; typedef enum { - AVTP_AAF_PCM_STREAM_FIELD_SUBTYPE, - AVTP_AAF_PCM_STREAM_FIELD_SV, - AVTP_AAF_PCM_STREAM_FIELD_VERSION, - AVTP_AAF_PCM_STREAM_FIELD_MR, - AVTP_AAF_PCM_STREAM_FIELD_TV, - AVTP_AAF_PCM_STREAM_FIELD_SEQUENCE_NUM, - AVTP_AAF_PCM_STREAM_FIELD_TU, - AVTP_AAF_PCM_STREAM_FIELD_STREAM_ID, - AVTP_AAF_PCM_STREAM_FIELD_AVTP_TIMESTAMP, - AVTP_AAF_PCM_STREAM_FIELD_FORMAT, - AVTP_AAF_PCM_STREAM_FIELD_NSR, - AVTP_AAF_PCM_STREAM_FIELD_CHANNELS_PER_FRAME, - AVTP_AAF_PCM_STREAM_FIELD_BIT_DEPTH, - AVTP_AAF_PCM_STREAM_FIELD_STREAM_DATA_LENGTH, - AVTP_AAF_PCM_STREAM_FIELD_SP, - AVTP_AAF_PCM_STREAM_FIELD_EVT, - AVTP_AAF_PCM_STREAM_FIELD_MAX -} Avtp_AafPcmStreamFields_t; + AVTP_PCM_FIELD_SUBTYPE, + AVTP_PCM_FIELD_SV, + AVTP_PCM_FIELD_VERSION, + AVTP_PCM_FIELD_MR, + AVTP_PCM_FIELD_TV, + AVTP_PCM_FIELD_SEQUENCE_NUM, + AVTP_PCM_FIELD_TU, + AVTP_PCM_FIELD_STREAM_ID, + AVTP_PCM_FIELD_AVTP_TIMESTAMP, + AVTP_PCM_FIELD_FORMAT, + AVTP_PCM_FIELD_NSR, + AVTP_PCM_FIELD_CHANNELS_PER_FRAME, + AVTP_PCM_FIELD_BIT_DEPTH, + AVTP_PCM_FIELD_STREAM_DATA_LENGTH, + AVTP_PCM_FIELD_SP, + AVTP_PCM_FIELD_EVT, + AVTP_PCM_FIELD_MAX +} Avtp_PcmFields_t; // AAF 'format' field values typedef enum { @@ -96,7 +96,7 @@ typedef enum { * * @param pdu Pointer to the first bit of a 1722 PDU. */ -void Avtp_AafPcmStream_Init(Avtp_AafPcmStream_t* pdu); +void Avtp_Pcm_Init(Avtp_Pcm_t* pdu); /** * Returns the value of an an AVTP AAF PCM stream field as specified in the IEEE 1722 Specification. @@ -107,7 +107,24 @@ void Avtp_AafPcmStream_Init(Avtp_AafPcmStream_t* pdu); * @returns This function returns 0 if the data field was successfully read from * the 1722 AVTP PDU. */ -uint64_t Avtp_AafPcmStream_GetField(Avtp_AafPcmStream_t* pdu, Avtp_AafPcmStreamFields_t field); +uint64_t Avtp_Pcm_GetField(Avtp_Pcm_t* pdu, Avtp_PcmFields_t field); + +uint8_t Avtp_Pcm_GetSubtype(Avtp_Pcm_t* pdu); +uint8_t Avtp_Pcm_GetSv(Avtp_Pcm_t* pdu); +uint8_t Avtp_Pcm_GetVersion(Avtp_Pcm_t* pdu); +uint8_t Avtp_Pcm_GetMr(Avtp_Pcm_t* pdu); +uint8_t Avtp_Pcm_GetTv(Avtp_Pcm_t* pdu); +uint8_t Avtp_Pcm_GetSequenceNum(Avtp_Pcm_t* pdu); +uint8_t Avtp_Pcm_GetTu(Avtp_Pcm_t* pdu); +uint64_t Avtp_Pcm_GetStreamId(Avtp_Pcm_t* pdu); +uint32_t Avtp_Pcm_GetAvtpTimestamp(Avtp_Pcm_t* pdu); +uint8_t Avtp_Pcm_GetFormat(Avtp_Pcm_t* pdu); +uint8_t Avtp_Pcm_GetNsr(Avtp_Pcm_t* pdu); +uint16_t Avtp_Pcm_GetChannelsPerFrame(Avtp_Pcm_t* pdu); +uint8_t Avtp_Pcm_GetBitDepth(Avtp_Pcm_t* pdu); +uint16_t Avtp_Pcm_GetStreamDataLength(Avtp_Pcm_t* pdu); +uint8_t Avtp_Pcm_GetSp(Avtp_Pcm_t* pdu); +uint8_t Avtp_Pcm_GetEvt(Avtp_Pcm_t* pdu); /** * Sets the value of an an AVTP AAF PCM stream field as specified in the IEEE 1722 Specification. @@ -118,27 +135,44 @@ uint64_t Avtp_AafPcmStream_GetField(Avtp_AafPcmStream_t* pdu, Avtp_AafPcmStreamF * @returns This function returns 0 if the data field was successfully set in * the 1722 AVTP PDU. */ -void Avtp_AafPcmStream_SetField(Avtp_AafPcmStream_t* pdu, Avtp_AafPcmStreamFields_t field, uint64_t value); +void Avtp_Pcm_SetField(Avtp_Pcm_t* pdu, Avtp_PcmFields_t field, uint64_t value); + +void Avtp_Pcm_SetSubtype(Avtp_Pcm_t* pdu, uint8_t value); +void Avtp_Pcm_SetSv(Avtp_Pcm_t* pdu, uint8_t value); +void Avtp_Pcm_SetVersion(Avtp_Pcm_t* pdu, uint8_t value); +void Avtp_Pcm_SetMr(Avtp_Pcm_t* pdu, uint8_t value); +void Avtp_Pcm_SetTv(Avtp_Pcm_t* pdu, uint8_t value); +void Avtp_Pcm_SetSequenceNum(Avtp_Pcm_t* pdu, uint8_t value); +void Avtp_Pcm_SetTu(Avtp_Pcm_t* pdu, uint8_t value); +void Avtp_Pcm_SetStreamId(Avtp_Pcm_t* pdu, uint64_t value); +void Avtp_Pcm_SetAvtpTimestamp(Avtp_Pcm_t* pdu, uint32_t value); +void Avtp_Pcm_SetFormat(Avtp_Pcm_t* pdu, uint8_t value); +void Avtp_Pcm_SetNsr(Avtp_Pcm_t* pdu, uint8_t value); +void Avtp_Pcm_SetChannelsPerFrame(Avtp_Pcm_t* pdu, uint16_t value); +void Avtp_Pcm_SetBitDepth(Avtp_Pcm_t* pdu, uint8_t value); +void Avtp_Pcm_SetStreamDataLength(Avtp_Pcm_t* pdu, uint16_t value); +void Avtp_Pcm_SetSp(Avtp_Pcm_t* pdu, uint8_t value); +void Avtp_Pcm_SetEvt(Avtp_Pcm_t* pdu, uint8_t value); /****************************************************************************** * Legacy API (deprecated) *****************************************************************************/ -#define AVTP_AAF_FIELD_SV AVTP_AAF_PCM_STREAM_FIELD_SV -#define AVTP_AAF_FIELD_MR AVTP_AAF_PCM_STREAM_FIELD_MR -#define AVTP_AAF_FIELD_TV AVTP_AAF_PCM_STREAM_FIELD_TV -#define AVTP_AAF_FIELD_SEQ_NUM AVTP_AAF_PCM_STREAM_FIELD_SEQUENCE_NUM -#define AVTP_AAF_FIELD_TU AVTP_AAF_PCM_STREAM_FIELD_TU -#define AVTP_AAF_FIELD_STREAM_ID AVTP_AAF_PCM_STREAM_FIELD_STREAM_ID -#define AVTP_AAF_FIELD_TIMESTAMP AVTP_AAF_PCM_STREAM_FIELD_AVTP_TIMESTAMP -#define AVTP_AAF_FIELD_STREAM_DATA_LEN AVTP_AAF_PCM_STREAM_FIELD_STREAM_DATA_LENGTH -#define AVTP_AAF_FIELD_FORMAT AVTP_AAF_PCM_STREAM_FIELD_FORMAT -#define AVTP_AAF_FIELD_NSR AVTP_AAF_PCM_STREAM_FIELD_NSR -#define AVTP_AAF_FIELD_CHAN_PER_FRAME AVTP_AAF_PCM_STREAM_FIELD_CHANNELS_PER_FRAME -#define AVTP_AAF_FIELD_BIT_DEPTH AVTP_AAF_PCM_STREAM_FIELD_BIT_DEPTH -#define AVTP_AAF_FIELD_SP AVTP_AAF_PCM_STREAM_FIELD_SP -#define AVTP_AAF_FIELD_EVT AVTP_AAF_PCM_STREAM_FIELD_EVT -#define AVTP_AAF_FIELD_MAX AVTP_AAF_PCM_STREAM_FIELD_MAX +#define AVTP_AAF_FIELD_SV AVTP_PCM_FIELD_SV +#define AVTP_AAF_FIELD_MR AVTP_PCM_FIELD_MR +#define AVTP_AAF_FIELD_TV AVTP_PCM_FIELD_TV +#define AVTP_AAF_FIELD_SEQ_NUM AVTP_PCM_FIELD_SEQUENCE_NUM +#define AVTP_AAF_FIELD_TU AVTP_PCM_FIELD_TU +#define AVTP_AAF_FIELD_STREAM_ID AVTP_PCM_FIELD_STREAM_ID +#define AVTP_AAF_FIELD_TIMESTAMP AVTP_PCM_FIELD_AVTP_TIMESTAMP +#define AVTP_AAF_FIELD_STREAM_DATA_LEN AVTP_PCM_FIELD_STREAM_DATA_LENGTH +#define AVTP_AAF_FIELD_FORMAT AVTP_PCM_FIELD_FORMAT +#define AVTP_AAF_FIELD_NSR AVTP_PCM_FIELD_NSR +#define AVTP_AAF_FIELD_CHAN_PER_FRAME AVTP_PCM_FIELD_CHANNELS_PER_FRAME +#define AVTP_AAF_FIELD_BIT_DEPTH AVTP_PCM_FIELD_BIT_DEPTH +#define AVTP_AAF_FIELD_SP AVTP_PCM_FIELD_SP +#define AVTP_AAF_FIELD_EVT AVTP_PCM_FIELD_EVT +#define AVTP_AAF_FIELD_MAX AVTP_PCM_FIELD_MAX /** * @deprecated @@ -152,7 +186,7 @@ void Avtp_AafPcmStream_SetField(Avtp_AafPcmStream_t* pdu, Avtp_AafPcmStreamField * -EINVAL: If any argument is invalid. */ int avtp_aaf_pdu_get(void *pdu, - Avtp_AafPcmStreamFields_t field, uint64_t *val); + Avtp_PcmFields_t field, uint64_t *val); /** * @deprecated @@ -165,7 +199,7 @@ int avtp_aaf_pdu_get(void *pdu, * 0: Success. * -EINVAL: If any argument is invalid. */ -int avtp_aaf_pdu_set(void *pdu, Avtp_AafPcmStreamFields_t field, +int avtp_aaf_pdu_set(void *pdu, Avtp_PcmFields_t field, uint64_t val); /** diff --git a/src/avtp/Utils.c b/src/avtp/Utils.c index 6cac42e..a2a0b0b 100644 --- a/src/avtp/Utils.c +++ b/src/avtp/Utils.c @@ -29,6 +29,7 @@ #include #include +#include #include "avtp/Utils.h" #include "avtp/Defines.h" diff --git a/src/avtp/aaf/Pcm.c b/src/avtp/aaf/Pcm.c new file mode 100644 index 0000000..ed16224 --- /dev/null +++ b/src/avtp/aaf/Pcm.c @@ -0,0 +1,286 @@ +/* + * Copyright (c) 2024, COVESA + * Copyright (c) 2019, Intel Corporation + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of COVESA, Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include + +#include "avtp/CommonHeader.h" +#include "avtp/aaf/Pcm.h" +#include "avtp/Utils.h" + +#define GET_FIELD(field) \ + (Avtp_GetField(Avtp_PcmFieldDesc, AVTP_PCM_FIELD_MAX, (uint8_t*)pdu, field)) +#define SET_FIELD(field, value) \ + (Avtp_SetField(Avtp_PcmFieldDesc, AVTP_PCM_FIELD_MAX, (uint8_t*)pdu, field, value)) + +static const Avtp_FieldDescriptor_t Avtp_PcmFieldDesc[AVTP_PCM_FIELD_MAX] = +{ + [AVTP_PCM_FIELD_SUBTYPE] = { .quadlet = 0, .offset = 0, .bits = 8 }, + [AVTP_PCM_FIELD_SV] = { .quadlet = 0, .offset = 8, .bits = 1 }, + [AVTP_PCM_FIELD_VERSION] = { .quadlet = 0, .offset = 9, .bits = 3 }, + [AVTP_PCM_FIELD_MR] = { .quadlet = 0, .offset = 12, .bits = 1 }, + [AVTP_PCM_FIELD_TV] = { .quadlet = 0, .offset = 15, .bits = 1 }, + [AVTP_PCM_FIELD_SEQUENCE_NUM] = { .quadlet = 0, .offset = 16, .bits = 8 }, + [AVTP_PCM_FIELD_TU] = { .quadlet = 0, .offset = 31, .bits = 1 }, + [AVTP_PCM_FIELD_STREAM_ID] = { .quadlet = 1, .offset = 0, .bits = 64 }, + [AVTP_PCM_FIELD_AVTP_TIMESTAMP] = { .quadlet = 3, .offset = 0, .bits = 32 }, + [AVTP_PCM_FIELD_FORMAT] = { .quadlet = 4, .offset = 0, .bits = 8 }, + [AVTP_PCM_FIELD_NSR] = { .quadlet = 4, .offset = 8, .bits = 4 }, + [AVTP_PCM_FIELD_CHANNELS_PER_FRAME] = { .quadlet = 4, .offset = 14, .bits = 10 }, + [AVTP_PCM_FIELD_BIT_DEPTH] = { .quadlet = 4, .offset = 24, .bits = 8 }, + [AVTP_PCM_FIELD_STREAM_DATA_LENGTH] = { .quadlet = 5, .offset = 0, .bits = 16 }, + [AVTP_PCM_FIELD_SP] = { .quadlet = 5, .offset = 19, .bits = 1 }, + [AVTP_PCM_FIELD_EVT] = { .quadlet = 5, .offset = 20, .bits = 4 }, +}; + +void Avtp_Pcm_Init(Avtp_Pcm_t* pdu) +{ + if (pdu != NULL) { + memset(pdu, 0, sizeof(Avtp_Pcm_t)); + Avtp_Pcm_SetField(pdu, AVTP_PCM_FIELD_SUBTYPE, AVTP_SUBTYPE_AAF); + Avtp_Pcm_SetField(pdu, AVTP_PCM_FIELD_SV, 1); + } +} + +uint64_t Avtp_Pcm_GetField(Avtp_Pcm_t* pdu, Avtp_PcmFields_t field) +{ + return GET_FIELD(field); +} + +uint8_t Avtp_Pcm_GetSubtype(Avtp_Pcm_t* pdu) +{ + return GET_FIELD(AVTP_PCM_FIELD_SUBTYPE); +} + +uint8_t Avtp_Pcm_GetSv(Avtp_Pcm_t* pdu) +{ + return GET_FIELD(AVTP_PCM_FIELD_SV); +} + +uint8_t Avtp_Pcm_GetVersion(Avtp_Pcm_t* pdu) +{ + return GET_FIELD(AVTP_PCM_FIELD_VERSION); +} + +uint8_t Avtp_Pcm_GetMr(Avtp_Pcm_t* pdu) +{ + return GET_FIELD(AVTP_PCM_FIELD_MR); +} + +uint8_t Avtp_Pcm_GetTv(Avtp_Pcm_t* pdu) +{ + return GET_FIELD(AVTP_PCM_FIELD_TV); +} + +uint8_t Avtp_Pcm_GetSequenceNum(Avtp_Pcm_t* pdu) +{ + return GET_FIELD(AVTP_PCM_FIELD_SEQUENCE_NUM); +} + +uint8_t Avtp_Pcm_GetTu(Avtp_Pcm_t* pdu) +{ + return GET_FIELD(AVTP_PCM_FIELD_TU); +} + +uint64_t Avtp_Pcm_GetStreamId(Avtp_Pcm_t* pdu) +{ + return GET_FIELD(AVTP_PCM_FIELD_STREAM_ID); +} + +uint32_t Avtp_Pcm_GetAvtpTimestamp(Avtp_Pcm_t* pdu) +{ + return GET_FIELD(AVTP_PCM_FIELD_AVTP_TIMESTAMP); +} + +uint8_t Avtp_Pcm_GetFormat(Avtp_Pcm_t* pdu) +{ + return GET_FIELD(AVTP_PCM_FIELD_FORMAT); +} + +uint8_t Avtp_Pcm_GetNsr(Avtp_Pcm_t* pdu) +{ + return GET_FIELD(AVTP_PCM_FIELD_NSR); +} + +uint16_t Avtp_Pcm_GetChannelsPerFrame(Avtp_Pcm_t* pdu) +{ + return GET_FIELD(AVTP_PCM_FIELD_CHANNELS_PER_FRAME); +} + +uint8_t Avtp_Pcm_GetBitDepth(Avtp_Pcm_t* pdu) +{ + return GET_FIELD(AVTP_PCM_FIELD_BIT_DEPTH); +} + +uint16_t Avtp_Pcm_GetStreamDataLength(Avtp_Pcm_t* pdu) +{ + return GET_FIELD(AVTP_PCM_FIELD_STREAM_DATA_LENGTH); +} + +uint8_t Avtp_Pcm_GetSp(Avtp_Pcm_t* pdu) +{ + return GET_FIELD(AVTP_PCM_FIELD_SP); +} + +uint8_t Avtp_Pcm_GetEvt(Avtp_Pcm_t* pdu) +{ + return GET_FIELD(AVTP_PCM_FIELD_EVT); +} + +void Avtp_Pcm_SetField(Avtp_Pcm_t* pdu, Avtp_PcmFields_t field, uint64_t value) +{ + SET_FIELD(field, value); +} + +void Avtp_Pcm_SetSubtype(Avtp_Pcm_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_PCM_FIELD_SUBTYPE, value); +} + +void Avtp_Pcm_SetSv(Avtp_Pcm_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_PCM_FIELD_SV, value); +} + +void Avtp_Pcm_SetVersion(Avtp_Pcm_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_PCM_FIELD_VERSION, value); +} + +void Avtp_Pcm_SetMr(Avtp_Pcm_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_PCM_FIELD_MR, value); +} + +void Avtp_Pcm_SetTv(Avtp_Pcm_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_PCM_FIELD_TV, value); +} + +void Avtp_Pcm_SetSequenceNum(Avtp_Pcm_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_PCM_FIELD_SEQUENCE_NUM, value); +} + +void Avtp_Pcm_SetTu(Avtp_Pcm_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_PCM_FIELD_TU, value); +} + +void Avtp_Pcm_SetStreamId(Avtp_Pcm_t* pdu, uint64_t value) +{ + SET_FIELD(AVTP_PCM_FIELD_STREAM_ID, value); +} + +void Avtp_Pcm_SetAvtpTimestamp(Avtp_Pcm_t* pdu, uint32_t value) +{ + SET_FIELD(AVTP_PCM_FIELD_AVTP_TIMESTAMP, value); +} + +void Avtp_Pcm_SetFormat(Avtp_Pcm_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_PCM_FIELD_FORMAT, value); +} + +void Avtp_Pcm_SetNsr(Avtp_Pcm_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_PCM_FIELD_NSR, value); +} + +void Avtp_Pcm_SetChannelsPerFrame(Avtp_Pcm_t* pdu, uint16_t value) +{ + SET_FIELD(AVTP_PCM_FIELD_CHANNELS_PER_FRAME, value); +} + +void Avtp_Pcm_SetBitDepth(Avtp_Pcm_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_PCM_FIELD_BIT_DEPTH, value); +} + +void Avtp_Pcm_SetStreamDataLength(Avtp_Pcm_t* pdu, uint16_t value) +{ + SET_FIELD(AVTP_PCM_FIELD_STREAM_DATA_LENGTH, value); +} + +void Avtp_Pcm_SetSp(Avtp_Pcm_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_PCM_FIELD_SP, value); +} + +void Avtp_Pcm_SetEvt(Avtp_Pcm_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_PCM_FIELD_EVT, value); +} + +/****************************************************************************** + * Legacy API (deprecated) + *****************************************************************************/ + +int avtp_aaf_pdu_get(void *pdu, + Avtp_PcmFields_t field, uint64_t *val) +{ + if (pdu == NULL || val == NULL) { + return -EINVAL; + } else { + *val = Avtp_Pcm_GetField((Avtp_Pcm_t*)pdu, field); + return 0; + } +} + +int avtp_aaf_pdu_set(void *pdu, Avtp_PcmFields_t field, + uint64_t val) +{ + if (pdu == NULL) { + return -EINVAL; + } else { + Avtp_Pcm_SetField((Avtp_Pcm_t*)pdu, field, val); + return 0; + } +} + +int avtp_aaf_pdu_init(void *pdu) +{ + int res; + + if (!pdu) + return -EINVAL; + + memset(pdu, 0, sizeof(Avtp_Pcm_t)); + + res = avtp_aaf_pdu_set(pdu, AVTP_PCM_FIELD_SUBTYPE, AVTP_SUBTYPE_AAF); + if (res < 0) + return res; + + res = avtp_aaf_pdu_set(pdu, AVTP_PCM_FIELD_SV, 1); + if (res < 0) + return res; + + return 0; +}; diff --git a/src/avtp/aaf/PcmStream.c b/src/avtp/aaf/PcmStream.c deleted file mode 100644 index eba0bd9..0000000 --- a/src/avtp/aaf/PcmStream.c +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2024, COVESA - * Copyright (c) 2019, Intel Corporation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of COVESA, Intel Corporation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include -#include - -#include "avtp/CommonHeader.h" -#include "avtp/aaf/PcmStream.h" -#include "avtp/Utils.h" - -static const Avtp_FieldDescriptor_t Avtp_AafPcmStreamFieldDesc[AVTP_AAF_PCM_STREAM_FIELD_MAX] = -{ - [AVTP_AAF_PCM_STREAM_FIELD_SUBTYPE] = { .quadlet = 0, .offset = 0, .bits = 8 }, - [AVTP_AAF_PCM_STREAM_FIELD_SV] = { .quadlet = 0, .offset = 8, .bits = 1 }, - [AVTP_AAF_PCM_STREAM_FIELD_VERSION] = { .quadlet = 0, .offset = 9, .bits = 3 }, - [AVTP_AAF_PCM_STREAM_FIELD_MR] = { .quadlet = 0, .offset = 12, .bits = 1 }, - [AVTP_AAF_PCM_STREAM_FIELD_TV] = { .quadlet = 0, .offset = 15, .bits = 1 }, - [AVTP_AAF_PCM_STREAM_FIELD_SEQUENCE_NUM] = { .quadlet = 0, .offset = 16, .bits = 8 }, - [AVTP_AAF_PCM_STREAM_FIELD_TU] = { .quadlet = 0, .offset = 31, .bits = 1 }, - [AVTP_AAF_PCM_STREAM_FIELD_STREAM_ID] = { .quadlet = 1, .offset = 0, .bits = 64 }, - [AVTP_AAF_PCM_STREAM_FIELD_AVTP_TIMESTAMP] = { .quadlet = 3, .offset = 0, .bits = 32 }, - [AVTP_AAF_PCM_STREAM_FIELD_FORMAT] = { .quadlet = 4, .offset = 0, .bits = 8 }, - [AVTP_AAF_PCM_STREAM_FIELD_NSR] = { .quadlet = 4, .offset = 8, .bits = 4 }, - [AVTP_AAF_PCM_STREAM_FIELD_CHANNELS_PER_FRAME] = { .quadlet = 4, .offset = 14, .bits = 10 }, - [AVTP_AAF_PCM_STREAM_FIELD_BIT_DEPTH] = { .quadlet = 4, .offset = 24, .bits = 8 }, - [AVTP_AAF_PCM_STREAM_FIELD_STREAM_DATA_LENGTH] = { .quadlet = 5, .offset = 0, .bits = 16 }, - [AVTP_AAF_PCM_STREAM_FIELD_SP] = { .quadlet = 5, .offset = 19, .bits = 1 }, - [AVTP_AAF_PCM_STREAM_FIELD_EVT] = { .quadlet = 5, .offset = 20, .bits = 4 }, -}; - -void Avtp_AafPcmStream_Init(Avtp_AafPcmStream_t* pdu) -{ - if (pdu != NULL) { - memset(pdu, 0, sizeof(Avtp_AafPcmStream_t)); - Avtp_AafPcmStream_SetField(pdu, AVTP_AAF_PCM_STREAM_FIELD_SUBTYPE, AVTP_SUBTYPE_AAF); - Avtp_AafPcmStream_SetField(pdu, AVTP_AAF_PCM_STREAM_FIELD_SV, 1); - } -} - -uint64_t Avtp_AafPcmStream_GetField(Avtp_AafPcmStream_t* pdu, Avtp_AafPcmStreamFields_t field) -{ - return Avtp_GetField(Avtp_AafPcmStreamFieldDesc, AVTP_AAF_PCM_STREAM_FIELD_MAX, (uint8_t*)pdu, (uint8_t) field); -} - -void Avtp_AafPcmStream_SetField(Avtp_AafPcmStream_t* pdu, Avtp_AafPcmStreamFields_t field, uint64_t value) -{ - Avtp_SetField(Avtp_AafPcmStreamFieldDesc, AVTP_AAF_PCM_STREAM_FIELD_MAX, (uint8_t*)pdu, (uint8_t) field, value); -} - -/****************************************************************************** - * Legacy API (deprecated) - *****************************************************************************/ - -int avtp_aaf_pdu_get(void *pdu, - Avtp_AafPcmStreamFields_t field, uint64_t *val) -{ - if (pdu == NULL || val == NULL) { - return -EINVAL; - } else { - *val = Avtp_AafPcmStream_GetField((Avtp_AafPcmStream_t*)pdu, field); - return 0; - } -} - -int avtp_aaf_pdu_set(void *pdu, Avtp_AafPcmStreamFields_t field, - uint64_t val) -{ - if (pdu == NULL) { - return -EINVAL; - } else { - Avtp_AafPcmStream_SetField((Avtp_AafPcmStream_t*)pdu, field, val); - return 0; - } -} - -int avtp_aaf_pdu_init(void *pdu) -{ - int res; - - if (!pdu) - return -EINVAL; - - memset(pdu, 0, sizeof(Avtp_AafPcmStream_t)); - - res = avtp_aaf_pdu_set(pdu, AVTP_AAF_PCM_STREAM_FIELD_SUBTYPE, AVTP_SUBTYPE_AAF); - if (res < 0) - return res; - - res = avtp_aaf_pdu_set(pdu, AVTP_AAF_PCM_STREAM_FIELD_SV, 1); - if (res < 0) - return res; - - return 0; -}; From b96c221ecb56b90aeca668683a4a9fb3206add15 Mon Sep 17 00:00:00 2001 From: Adriaan Niess Date: Tue, 27 Aug 2024 23:33:57 +0200 Subject: [PATCH 25/33] Update GetField API for Cvf.h/c Signed-off-by: Adriaan Niess --- include/avtp/cvf/Cvf.h | 42 ++++++++- src/avtp/CommonHeader.c | 1 + src/avtp/Rvf.c | 1 + src/avtp/cvf/Cvf.c | 204 ++++++++++++++++++++++++++++++++++++---- 4 files changed, 223 insertions(+), 25 deletions(-) diff --git a/include/avtp/cvf/Cvf.h b/include/avtp/cvf/Cvf.h index 1f10e8e..6ff0ff2 100644 --- a/include/avtp/cvf/Cvf.h +++ b/include/avtp/cvf/Cvf.h @@ -76,11 +76,43 @@ typedef enum Avtp_CvfFormatSubtype { AVTP_CVF_FORMAT_SUBTYPE_JPEG2000 = 0x2 } Avtp_CvfFormatSubtype_t; -int Avtp_Cvf_Init(Avtp_Cvf_t* pdu); - -int Avtp_Cvf_GetField(Avtp_Cvf_t* pdu, Avtp_CvfField_t field, uint64_t* value); - -int Avtp_Cvf_SetField(Avtp_Cvf_t* pdu, Avtp_CvfField_t field, uint64_t value); +void Avtp_Cvf_Init(Avtp_Cvf_t* pdu); + +uint64_t Avtp_Cvf_GetField(Avtp_Cvf_t* pdu, Avtp_CvfField_t field); + +uint8_t Avtp_Cvf_GetSubtype(Avtp_Cvf_t* pdu); +uint8_t Avtp_Cvf_GetSv(Avtp_Cvf_t* pdu); +uint8_t Avtp_Cvf_GetVersion(Avtp_Cvf_t* pdu); +uint8_t Avtp_Cvf_GetMr(Avtp_Cvf_t* pdu); +uint8_t Avtp_Cvf_GetTv(Avtp_Cvf_t* pdu); +uint8_t Avtp_Cvf_GetSequenceNum(Avtp_Cvf_t* pdu); +uint8_t Avtp_Cvf_GetTu(Avtp_Cvf_t* pdu); +uint64_t Avtp_Cvf_GetStreamId(Avtp_Cvf_t* pdu); +uint32_t Avtp_Cvf_GetAvtpTimestamp(Avtp_Cvf_t* pdu); +uint8_t Avtp_Cvf_GetFormat(Avtp_Cvf_t* pdu); +uint8_t Avtp_Cvf_GetFormatSubtype(Avtp_Cvf_t* pdu); +uint16_t Avtp_Cvf_GetStreamDataLength(Avtp_Cvf_t* pdu); +uint8_t Avtp_Cvf_GetPtv(Avtp_Cvf_t* pdu); +uint8_t Avtp_Cvf_GetM(Avtp_Cvf_t* pdu); +uint8_t Avtp_Cvf_GetEvt(Avtp_Cvf_t* pdu); + +void Avtp_Cvf_SetField(Avtp_Cvf_t* pdu, Avtp_CvfField_t field, uint64_t value); + +void Avtp_Cvf_SetSubtype(Avtp_Cvf_t* pdu, uint8_t value); +void Avtp_Cvf_SetSv(Avtp_Cvf_t* pdu, uint8_t value); +void Avtp_Cvf_SetVersion(Avtp_Cvf_t* pdu, uint8_t value); +void Avtp_Cvf_SetMr(Avtp_Cvf_t* pdu, uint8_t value); +void Avtp_Cvf_SetTv(Avtp_Cvf_t* pdu, uint8_t value); +void Avtp_Cvf_SetSequenceNum(Avtp_Cvf_t* pdu, uint8_t value); +void Avtp_Cvf_SetTu(Avtp_Cvf_t* pdu, uint8_t value); +void Avtp_Cvf_SetStreamId(Avtp_Cvf_t* pdu, uint64_t value); +void Avtp_Cvf_SetAvtpTimestamp(Avtp_Cvf_t* pdu, uint32_t value); +void Avtp_Cvf_SetFormat(Avtp_Cvf_t* pdu, uint8_t value); +void Avtp_Cvf_SetFormatSubtype(Avtp_Cvf_t* pdu, uint8_t value); +void Avtp_Cvf_SetStreamDataLength(Avtp_Cvf_t* pdu, uint16_t value); +void Avtp_Cvf_SetPtv(Avtp_Cvf_t* pdu, uint8_t value); +void Avtp_Cvf_SetM(Avtp_Cvf_t* pdu, uint8_t value); +void Avtp_Cvf_SetEvt(Avtp_Cvf_t* pdu, uint8_t value); /****************************************************************************** * Legacy API (deprecated) diff --git a/src/avtp/CommonHeader.c b/src/avtp/CommonHeader.c index 3f9f2c6..e5febff 100644 --- a/src/avtp/CommonHeader.c +++ b/src/avtp/CommonHeader.c @@ -29,6 +29,7 @@ #include #include + #include "avtp/CommonHeader.h" #include "avtp/Utils.h" #include "avtp/Defines.h" diff --git a/src/avtp/Rvf.c b/src/avtp/Rvf.c index 12d6aba..b7e3353 100644 --- a/src/avtp/Rvf.c +++ b/src/avtp/Rvf.c @@ -368,6 +368,7 @@ int avtp_rvf_pdu_set(void* pdu, Avtp_RvfField_t field, uint64_t val) return -EINVAL; } else { Avtp_Rvf_SetField((Avtp_Rvf_t*)pdu, field, val); + return 0; } } diff --git a/src/avtp/cvf/Cvf.c b/src/avtp/cvf/Cvf.c index 1e537dc..f1b7f15 100644 --- a/src/avtp/cvf/Cvf.c +++ b/src/avtp/cvf/Cvf.c @@ -34,6 +34,11 @@ #include "avtp/Utils.h" #include "avtp/CommonHeader.h" +#define GET_FIELD(field) \ + (Avtp_GetField(fieldDescriptors, AVTP_CVF_FIELD_MAX, (uint8_t*)pdu, field)) +#define SET_FIELD(field, value) \ + (Avtp_SetField(fieldDescriptors, AVTP_CVF_FIELD_MAX, (uint8_t*)pdu, field, value)) + static const Avtp_FieldDescriptor_t fieldDescriptors[AVTP_CVF_FIELD_MAX] = { [AVTP_CVF_FIELD_SUBTYPE] = { .quadlet = 0, .offset = 0, .bits = 8 }, @@ -58,29 +63,174 @@ static const Avtp_FieldDescriptor_t fieldDescriptors[AVTP_CVF_FIELD_MAX] = [AVTP_CVF_FIELD_RESERVED_5] = { .quadlet = 5, .offset = 24, .bits = 8 }, }; -int Avtp_Cvf_Init(Avtp_Cvf_t* pdu) +void Avtp_Cvf_Init(Avtp_Cvf_t* pdu) { - if (pdu == NULL) return -EINVAL; + if (pdu != NULL) { + memset(pdu, 0, sizeof(Avtp_Cvf_t)); + Avtp_Cvf_SetField(pdu, AVTP_CVF_FIELD_SUBTYPE, AVTP_SUBTYPE_CVF); + Avtp_Cvf_SetField(pdu, AVTP_CVF_FIELD_SV, 1); + Avtp_Cvf_SetField(pdu, AVTP_CVF_FIELD_FORMAT, AVTP_CVF_FORMAT_RFC); + } +} - memset(pdu, 0, sizeof(Avtp_Cvf_t)); - - int ret; - ret = Avtp_Cvf_SetField(pdu, AVTP_CVF_FIELD_SUBTYPE, AVTP_SUBTYPE_CVF); - if (ret != 0) return ret; - ret = Avtp_Cvf_SetField(pdu, AVTP_CVF_FIELD_SV, 1); - if (ret != 0) return ret; - - return 0; +uint64_t Avtp_Cvf_GetField(Avtp_Cvf_t* pdu, Avtp_CvfField_t field) +{ + return GET_FIELD(field); +} + +uint8_t Avtp_Cvf_GetSubtype(Avtp_Cvf_t* pdu) +{ + return GET_FIELD(AVTP_CVF_FIELD_SUBTYPE); +} + +uint8_t Avtp_Cvf_GetSv(Avtp_Cvf_t* pdu) +{ + return GET_FIELD(AVTP_CVF_FIELD_SV); +} + +uint8_t Avtp_Cvf_GetVersion(Avtp_Cvf_t* pdu) +{ + return GET_FIELD(AVTP_CVF_FIELD_VERSION); +} + +uint8_t Avtp_Cvf_GetMr(Avtp_Cvf_t* pdu) +{ + return GET_FIELD(AVTP_CVF_FIELD_MR); +} + +uint8_t Avtp_Cvf_GetTv(Avtp_Cvf_t* pdu) +{ + return GET_FIELD(AVTP_CVF_FIELD_TV); +} + +uint8_t Avtp_Cvf_GetSequenceNum(Avtp_Cvf_t* pdu) +{ + return GET_FIELD(AVTP_CVF_FIELD_SEQUENCE_NUM); +} + +uint8_t Avtp_Cvf_GetTu(Avtp_Cvf_t* pdu) +{ + return GET_FIELD(AVTP_CVF_FIELD_TU); +} + +uint64_t Avtp_Cvf_GetStreamId(Avtp_Cvf_t* pdu) +{ + return GET_FIELD(AVTP_CVF_FIELD_STREAM_ID); +} + +uint32_t Avtp_Cvf_GetAvtpTimestamp(Avtp_Cvf_t* pdu) +{ + return GET_FIELD(AVTP_CVF_FIELD_AVTP_TIMESTAMP); +} + +uint8_t Avtp_Cvf_GetFormat(Avtp_Cvf_t* pdu) +{ + return GET_FIELD(AVTP_CVF_FIELD_FORMAT); +} + +uint8_t Avtp_Cvf_GetFormatSubtype(Avtp_Cvf_t* pdu) +{ + return GET_FIELD(AVTP_CVF_FIELD_FORMAT_SUBTYPE); +} + +uint16_t Avtp_Cvf_GetStreamDataLength(Avtp_Cvf_t* pdu) +{ + return GET_FIELD(AVTP_CVF_FIELD_STREAM_DATA_LENGTH); +} + +uint8_t Avtp_Cvf_GetPtv(Avtp_Cvf_t* pdu) +{ + return GET_FIELD(AVTP_CVF_FIELD_PTV); } -int Avtp_Cvf_GetField(Avtp_Cvf_t* pdu, Avtp_CvfField_t field, uint64_t* value) +uint8_t Avtp_Cvf_GetM(Avtp_Cvf_t* pdu) { - return Avtp_GetField(fieldDescriptors, AVTP_CVF_FIELD_MAX, (uint8_t*)pdu, field, value); + return GET_FIELD(AVTP_CVF_FIELD_M); } -int Avtp_Cvf_SetField(Avtp_Cvf_t* pdu, Avtp_CvfField_t field, uint64_t value) +uint8_t Avtp_Cvf_GetEvt(Avtp_Cvf_t* pdu) { - return Avtp_SetField(fieldDescriptors, AVTP_CVF_FIELD_MAX, (uint8_t*)pdu, field, value); + return GET_FIELD(AVTP_CVF_FIELD_EVT); +} + +void Avtp_Cvf_SetField(Avtp_Cvf_t* pdu, Avtp_CvfField_t field, uint64_t value) +{ + SET_FIELD(field, value); +} + +void Avtp_Cvf_SetSubtype(Avtp_Cvf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CVF_FIELD_SUBTYPE, value); +} + +void Avtp_Cvf_SetSv(Avtp_Cvf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CVF_FIELD_SV, value); +} + +void Avtp_Cvf_SetVersion(Avtp_Cvf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CVF_FIELD_VERSION, value); +} + +void Avtp_Cvf_SetMr(Avtp_Cvf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CVF_FIELD_MR, value); +} + +void Avtp_Cvf_SetTv(Avtp_Cvf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CVF_FIELD_TV, value); +} + +void Avtp_Cvf_SetSequenceNum(Avtp_Cvf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CVF_FIELD_SEQUENCE_NUM, value); +} + +void Avtp_Cvf_SetTu(Avtp_Cvf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CVF_FIELD_TU, value); +} + +void Avtp_Cvf_SetStreamId(Avtp_Cvf_t* pdu, uint64_t value) +{ + SET_FIELD(AVTP_CVF_FIELD_STREAM_ID, value); +} + +void Avtp_Cvf_SetAvtpTimestamp(Avtp_Cvf_t* pdu, uint32_t value) +{ + SET_FIELD(AVTP_CVF_FIELD_AVTP_TIMESTAMP, value); +} + +void Avtp_Cvf_SetFormat(Avtp_Cvf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CVF_FIELD_FORMAT, value); +} + +void Avtp_Cvf_SetFormatSubtype(Avtp_Cvf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CVF_FIELD_FORMAT_SUBTYPE, value); +} + +void Avtp_Cvf_SetStreamDataLength(Avtp_Cvf_t* pdu, uint16_t value) +{ + SET_FIELD(AVTP_CVF_FIELD_STREAM_DATA_LENGTH, value); +} + +void Avtp_Cvf_SetPtv(Avtp_Cvf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CVF_FIELD_PTV, value); +} + +void Avtp_Cvf_SetM(Avtp_Cvf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CVF_FIELD_M, value); +} + +void Avtp_Cvf_SetEvt(Avtp_Cvf_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_CVF_FIELD_EVT, value); } /****************************************************************************** @@ -89,22 +239,36 @@ int Avtp_Cvf_SetField(Avtp_Cvf_t* pdu, Avtp_CvfField_t field, uint64_t value) int avtp_cvf_pdu_get(void* pdu, Avtp_CvfField_t field, uint64_t *val) { - return Avtp_Cvf_GetField((Avtp_Cvf_t*)pdu, field, val); + if (pdu == NULL || val == NULL) { + return -EINVAL; + } else { + *val = Avtp_Cvf_GetField((Avtp_Cvf_t*)pdu, field); + return 0; + } } int avtp_cvf_pdu_set(void* pdu, Avtp_CvfField_t field, uint64_t val) { - return Avtp_Cvf_SetField((Avtp_Cvf_t*)pdu, field, val); + if (pdu == NULL) { + return -EINVAL; + } else { + Avtp_Cvf_SetField((Avtp_Cvf_t*)pdu, field, val); + return 0; + } } int avtp_cvf_pdu_init(void* pdu, uint8_t format_subtype) { + if (pdu == NULL) { + return -EINVAL; + } + int ret; - ret = Avtp_Cvf_Init((Avtp_Cvf_t*)pdu); + ret = avtp_cvf_pdu_set(pdu, AVTP_CVF_FIELD_FORMAT_SUBTYPE, format_subtype); if (ret != 0) return ret; - ret = Avtp_Cvf_SetField(pdu, AVTP_CVF_FIELD_FORMAT_SUBTYPE, format_subtype); + ret = avtp_cvf_pdu_set(pdu, AVTP_CVF_FIELD_SV, 1); if (ret != 0) return ret; - ret = Avtp_Cvf_SetField(pdu, AVTP_CVF_FIELD_FORMAT, AVTP_CVF_FORMAT_RFC); + ret = avtp_cvf_pdu_set(pdu, AVTP_CVF_FIELD_FORMAT, AVTP_CVF_FORMAT_RFC); if (ret != 0) return ret; return 0; From 55c816a1722f009444fc2a0b68cc459d3de9399e Mon Sep 17 00:00:00 2001 From: Adriaan Niess Date: Wed, 28 Aug 2024 09:58:07 +0200 Subject: [PATCH 26/33] Update GetField API for H264.h/c Signed-off-by: Adriaan Niess --- include/avtp/cvf/H264.h | 8 +++++--- src/avtp/cvf/H264.c | 31 +++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/include/avtp/cvf/H264.h b/include/avtp/cvf/H264.h index ca59a96..ea98d33 100644 --- a/include/avtp/cvf/H264.h +++ b/include/avtp/cvf/H264.h @@ -47,8 +47,10 @@ typedef enum Avtp_H264Field { AVTP_H264_FIELD_MAX, } Avtp_H264Field_t; -int Avtp_H264_Init(Avtp_H264_t* pdu); +void Avtp_H264_Init(Avtp_H264_t* pdu); -int Avtp_H264_GetField(Avtp_H264_t* pdu, Avtp_H264Field_t field, uint64_t* value); +uint64_t Avtp_H264_GetField(Avtp_H264_t* pdu, Avtp_H264Field_t field); +uint32_t Avtp_H264_GetTimestamp(Avtp_H264_t* pdu); -int Avtp_H264_SetField(Avtp_H264_t* pdu, Avtp_H264Field_t field, uint64_t value); +void Avtp_H264_SetField(Avtp_H264_t* pdu, Avtp_H264Field_t field, uint64_t value); +void Avtp_H264_SetTimestamp(Avtp_H264_t* pdu, uint32_t value); diff --git a/src/avtp/cvf/H264.c b/src/avtp/cvf/H264.c index 20963de..d0caf2c 100644 --- a/src/avtp/cvf/H264.c +++ b/src/avtp/cvf/H264.c @@ -34,24 +34,39 @@ #include "avtp/Utils.h" #include "avtp/CommonHeader.h" +#define GET_FIELD(field) \ + (Avtp_GetField(fieldDescriptors, AVTP_H264_FIELD_MAX, (uint8_t*)pdu, field)) +#define SET_FIELD(field, value) \ + (Avtp_SetField(fieldDescriptors, AVTP_H264_FIELD_MAX, (uint8_t*)pdu, field, value)) + static const Avtp_FieldDescriptor_t fieldDescriptors[AVTP_H264_FIELD_MAX] = { [AVTP_H264_FIELD_TIMESTAMP] = { .quadlet = 0, .offset = 0, .bits = 32 }, }; -int Avtp_H264_Init(Avtp_H264_t* pdu) +void Avtp_H264_Init(Avtp_H264_t* pdu) +{ + if (pdu != NULL) { + memset(pdu, 0, sizeof(Avtp_H264_t)); + } +} + +uint64_t Avtp_H264_GetField(Avtp_H264_t* pdu, Avtp_H264Field_t field) +{ + return GET_FIELD(field); +} + +uint32_t Avtp_H264_GetTimestamp(Avtp_H264_t* pdu) { - if (pdu == NULL) return -EINVAL; - memset(pdu, 0, sizeof(Avtp_H264_t)); - return 0; + return GET_FIELD(AVTP_H264_FIELD_TIMESTAMP); } -int Avtp_H264_GetField(Avtp_H264_t* pdu, Avtp_H264Field_t field, uint64_t* value) +void Avtp_H264_SetField(Avtp_H264_t* pdu, Avtp_H264Field_t field, uint64_t value) { - return Avtp_GetField(fieldDescriptors, AVTP_H264_FIELD_MAX, (uint8_t*)pdu, field, value); + SET_FIELD(field, value); } -int Avtp_H264_SetField(Avtp_H264_t* pdu, Avtp_H264Field_t field, uint64_t value) +void Avtp_H264_SetTimestamp(Avtp_H264_t* pdu, uint32_t value) { - return Avtp_SetField(fieldDescriptors, AVTP_H264_FIELD_MAX, (uint8_t*)pdu, field, value); + SET_FIELD(AVTP_H264_FIELD_TIMESTAMP, value); } From d793cb341bd4f677fa5bb04947bcd2480aec3efb Mon Sep 17 00:00:00 2001 From: Adriaan Niess Date: Wed, 28 Aug 2024 10:06:44 +0200 Subject: [PATCH 27/33] Update GetField API for Jpeg2000.h/c Signed-off-by: Adriaan Niess --- include/avtp/cvf/Jpeg2000.h | 22 ++++++++-- src/avtp/cvf/Jpeg2000.c | 86 +++++++++++++++++++++++++++++++++---- 2 files changed, 97 insertions(+), 11 deletions(-) diff --git a/include/avtp/cvf/Jpeg2000.h b/include/avtp/cvf/Jpeg2000.h index 7e5b3d0..9462dd1 100644 --- a/include/avtp/cvf/Jpeg2000.h +++ b/include/avtp/cvf/Jpeg2000.h @@ -54,8 +54,24 @@ typedef enum Avtp_Jpeg2000Field { AVTP_JPEG2000_FIELD_MAX } Avtp_Jpeg2000Field_t; -int Avtp_Jpeg2000_Init(Avtp_Jpeg2000_t* pdu); +void Avtp_Jpeg2000_Init(Avtp_Jpeg2000_t* pdu); -int Avtp_Jpeg2000_GetField(Avtp_Jpeg2000_t* pdu, Avtp_Jpeg2000Field_t field, uint64_t* value); +uint64_t Avtp_Jpeg2000_GetField(Avtp_Jpeg2000_t* pdu, Avtp_Jpeg2000Field_t field); -int Avtp_Jpeg2000_SetField(Avtp_Jpeg2000_t* pdu, Avtp_Jpeg2000Field_t field, uint64_t value); +uint8_t Avtp_Jpeg2000_GetTp(Avtp_Jpeg2000_t* pdu); +uint8_t Avtp_Jpeg2000_GetMhf(Avtp_Jpeg2000_t* pdu); +uint8_t Avtp_Jpeg2000_GetMhId(Avtp_Jpeg2000_t* pdu); +uint8_t Avtp_Jpeg2000_GetT(Avtp_Jpeg2000_t* pdu); +uint8_t Avtp_Jpeg2000_GetPriority(Avtp_Jpeg2000_t* pdu); +uint16_t Avtp_Jpeg2000_GetTileNumber(Avtp_Jpeg2000_t* pdu); +uint32_t Avtp_Jpeg2000_GetFragmentOffset(Avtp_Jpeg2000_t* pdu); + +void Avtp_Jpeg2000_SetField(Avtp_Jpeg2000_t* pdu, Avtp_Jpeg2000Field_t field, uint64_t value); + +void Avtp_Jpeg2000_SetTp(Avtp_Jpeg2000_t* pdu, uint8_t value); +void Avtp_Jpeg2000_SetMhf(Avtp_Jpeg2000_t* pdu, uint8_t value); +void Avtp_Jpeg2000_SetMhId(Avtp_Jpeg2000_t* pdu, uint8_t value); +void Avtp_Jpeg2000_SetT(Avtp_Jpeg2000_t* pdu, uint8_t value); +void Avtp_Jpeg2000_SetPriority(Avtp_Jpeg2000_t* pdu, uint8_t value); +void Avtp_Jpeg2000_SetTileNumber(Avtp_Jpeg2000_t* pdu, uint16_t value); +void Avtp_Jpeg2000_SetFragmentOffset(Avtp_Jpeg2000_t* pdu, uint32_t value); diff --git a/src/avtp/cvf/Jpeg2000.c b/src/avtp/cvf/Jpeg2000.c index 1cc0e9f..f6c9351 100644 --- a/src/avtp/cvf/Jpeg2000.c +++ b/src/avtp/cvf/Jpeg2000.c @@ -46,19 +46,89 @@ static const Avtp_FieldDescriptor_t fieldDescriptors[AVTP_JPEG2000_FIELD_MAX] = [AVTP_JPEG2000_FIELD_FRAGMENT_OFFSET] = { .quadlet = 1, .offset = 8, .bits = 24 }, }; -int Avtp_Jpeg2000_Init(Avtp_Jpeg2000_t* pdu) +void Avtp_Jpeg2000_Init(Avtp_Jpeg2000_t* pdu) { - if (pdu == NULL) return -EINVAL; - memset(pdu, 0, sizeof(Avtp_Jpeg2000_t)); - return 0; + if (pdu != NULL) { + memset(pdu, 0, sizeof(Avtp_Jpeg2000_t)); + } } -int Avtp_Jpeg2000_GetField(Avtp_Jpeg2000_t* pdu, Avtp_Jpeg2000Field_t field, uint64_t* value) +uint64_t Avtp_Jpeg2000_GetField(Avtp_Jpeg2000_t* pdu, Avtp_Jpeg2000Field_t field) { - return Avtp_GetField(fieldDescriptors, AVTP_JPEG2000_FIELD_MAX, (uint8_t*)pdu, field, value); + return GET_FIELD(field); } -int Avtp_Jpeg2000_SetField(Avtp_Jpeg2000_t* pdu, Avtp_Jpeg2000Field_t field, uint64_t value) +uint8_t Avtp_Jpeg2000_GetTp(Avtp_Jpeg2000_t* pdu) { - return Avtp_SetField(fieldDescriptors, AVTP_JPEG2000_FIELD_MAX, (uint8_t*)pdu, field, value); + return GET_FIELD(AVTP_JPEG2000_FIELD_TP); +} + +uint8_t Avtp_Jpeg2000_GetMhf(Avtp_Jpeg2000_t* pdu) +{ + return GET_FIELD(AVTP_JPEG2000_FIELD_MHF); +} + +uint8_t Avtp_Jpeg2000_GetMhId(Avtp_Jpeg2000_t* pdu) +{ + return GET_FIELD(AVTP_JPEG2000_FIELD_MH_ID); +} + +uint8_t Avtp_Jpeg2000_GetT(Avtp_Jpeg2000_t* pdu) +{ + return GET_FIELD(AVTP_JPEG2000_FIELD_T); +} + +uint8_t Avtp_Jpeg2000_GetPriority(Avtp_Jpeg2000_t* pdu) +{ + return GET_FIELD(AVTP_JPEG2000_FIELD_PRIORITY); +} + +uint16_t Avtp_Jpeg2000_GetTileNumber(Avtp_Jpeg2000_t* pdu) +{ + return GET_FIELD(AVTP_JPEG2000_FIELD_TILE_NUMBER); +} + +uint32_t Avtp_Jpeg2000_GetFragmentOffset(Avtp_Jpeg2000_t* pdu) +{ + return GET_FIELD(AVTP_JPEG2000_FIELD_FRAGMENT_OFFSET); +} + +void Avtp_Jpeg2000_SetField(Avtp_Jpeg2000_t* pdu, Avtp_Jpeg2000Field_t field, uint64_t value) +{ + SET_FIELD(field, value); +} + +void Avtp_Jpeg2000_SetTp(Avtp_Jpeg2000_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_JPEG2000_FIELD_TP, value); +} + +void Avtp_Jpeg2000_SetMhf(Avtp_Jpeg2000_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_JPEG2000_FIELD_MHF, value); +} + +void Avtp_Jpeg2000_SetMhId(Avtp_Jpeg2000_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_JPEG2000_FIELD_MH_ID, value); +} + +void Avtp_Jpeg2000_SetT(Avtp_Jpeg2000_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_JPEG2000_FIELD_T, value); +} + +void Avtp_Jpeg2000_SetPriority(Avtp_Jpeg2000_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_JPEG2000_FIELD_PRIORITY, value); +} + +void Avtp_Jpeg2000_SetTileNumber(Avtp_Jpeg2000_t* pdu, uint16_t value) +{ + SET_FIELD(AVTP_JPEG2000_FIELD_TILE_NUMBER, value); +} + +void Avtp_Jpeg2000_SetFragmentOffset(Avtp_Jpeg2000_t* pdu, uint32_t value) +{ + SET_FIELD(AVTP_JPEG2000_FIELD_FRAGMENT_OFFSET, value); } From b78ff98a13bd28fb6944d6b26724badd0beaa2f2 Mon Sep 17 00:00:00 2001 From: Adriaan Niess Date: Wed, 28 Aug 2024 10:53:12 +0200 Subject: [PATCH 28/33] Update GetField API for Mjpeg.h/c Signed-off-by: Adriaan Niess --- include/avtp/cvf/Mjpeg.h | 20 ++++++++-- src/avtp/cvf/Mjpeg.c | 81 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 90 insertions(+), 11 deletions(-) diff --git a/include/avtp/cvf/Mjpeg.h b/include/avtp/cvf/Mjpeg.h index abeb10b..83b992e 100644 --- a/include/avtp/cvf/Mjpeg.h +++ b/include/avtp/cvf/Mjpeg.h @@ -52,8 +52,22 @@ typedef enum Avtp_MjpegField { AVTP_MJPEG_FIELD_MAX } Avtp_MjpegField_t; -int Avtp_Mjpeg_Init(Avtp_Mjpeg_t* pdu); +void Avtp_Mjpeg_Init(Avtp_Mjpeg_t* pdu); -int Avtp_Mjpeg_GetField(Avtp_Mjpeg_t* pdu, Avtp_MjpegField_t field, uint64_t* value); +uint64_t Avtp_Mjpeg_GetField(Avtp_Mjpeg_t* pdu, Avtp_MjpegField_t field); -int Avtp_Mjpeg_SetField(Avtp_Mjpeg_t* pdu, Avtp_MjpegField_t field, uint64_t value); +uint8_t Avtp_Mjpeg_GetTypeSpecific(Avtp_Mjpeg_t* pdu); +uint32_t Avtp_Mjpeg_GetFragmentOffset(Avtp_Mjpeg_t* pdu); +uint8_t Avtp_Mjpeg_GetType(Avtp_Mjpeg_t* pdu); +uint8_t Avtp_Mjpeg_GetQ(Avtp_Mjpeg_t* pdu); +uint8_t Avtp_Mjpeg_GetWidth(Avtp_Mjpeg_t* pdu); +uint8_t Avtp_Mjpeg_GetHeight(Avtp_Mjpeg_t* pdu); + +void Avtp_Mjpeg_SetField(Avtp_Mjpeg_t* pdu, Avtp_MjpegField_t field, uint64_t value); + +void Avtp_Mjpeg_SetTypeSpecific(Avtp_Mjpeg_t* pdu, uint8_t value); +void Avtp_Mjpeg_SetFragmentOffset(Avtp_Mjpeg_t* pdu, uint32_t value); +void Avtp_Mjpeg_SetType(Avtp_Mjpeg_t* pdu, uint8_t value); +void Avtp_Mjpeg_SetQ(Avtp_Mjpeg_t* pdu, uint8_t value); +void Avtp_Mjpeg_SetWidth(Avtp_Mjpeg_t* pdu, uint8_t value); +void Avtp_Mjpeg_SetHeight(Avtp_Mjpeg_t* pdu, uint8_t value); diff --git a/src/avtp/cvf/Mjpeg.c b/src/avtp/cvf/Mjpeg.c index a108d98..22e7e36 100644 --- a/src/avtp/cvf/Mjpeg.c +++ b/src/avtp/cvf/Mjpeg.c @@ -34,6 +34,11 @@ #include "avtp/Utils.h" #include "avtp/CommonHeader.h" +#define GET_FIELD(field) \ + (Avtp_GetField(fieldDescriptors, AVTP_MJPEG_FIELD_MAX, (uint8_t*)pdu, field)) +#define SET_FIELD(field, value) \ + (Avtp_SetField(fieldDescriptors, AVTP_MJPEG_FIELD_MAX, (uint8_t*)pdu, field, value)) + static const Avtp_FieldDescriptor_t fieldDescriptors[AVTP_MJPEG_FIELD_MAX] = { [AVTP_MJPEG_FIELD_TYPE_SPECIFIC] = { .quadlet = 0, .offset = 0, .bits = 8 }, @@ -44,19 +49,79 @@ static const Avtp_FieldDescriptor_t fieldDescriptors[AVTP_MJPEG_FIELD_MAX] = [AVTP_MJPEG_FIELD_HEIGHT] = { .quadlet = 1, .offset = 24, .bits = 8 }, }; -int Avtp_Mjpeg_Init(Avtp_Mjpeg_t* pdu) +void Avtp_Mjpeg_Init(Avtp_Mjpeg_t* pdu) +{ + if (pdu != NULL) { + memset(pdu, 0, sizeof(Avtp_Mjpeg_t)); + } +} + +uint64_t Avtp_Mjpeg_GetField(Avtp_Mjpeg_t* pdu, Avtp_MjpegField_t field) +{ + return GET_FIELD(field); +} + +uint8_t Avtp_Mjpeg_GetTypeSpecific(Avtp_Mjpeg_t* pdu) +{ + SET_FIED(AVTP_MJPEG_FIELD_TYPE_SPECIFIC); +} + +uint32_t Avtp_Mjpeg_GetFragmentOffset(Avtp_Mjpeg_t* pdu) +{ + SET_FIED(AVTP_MJPEG_FIELD_FRAGMENT_OFFSET); +} + +uint8_t Avtp_Mjpeg_GetType(Avtp_Mjpeg_t* pdu) +{ + SET_FIED(AVTP_MJPEG_FIELD_TYPE); +} + +uint8_t Avtp_Mjpeg_GetQ(Avtp_Mjpeg_t* pdu) +{ + SET_FIED(AVTP_MJPEG_FIELD_Q); +} + +uint8_t Avtp_Mjpeg_GetWidth(Avtp_Mjpeg_t* pdu) +{ + SET_FIED(AVTP_MJPEG_FIELD_WIDTH); +} + +uint8_t Avtp_Mjpeg_GetHeight(Avtp_Mjpeg_t* pdu) +{ + SET_FIED(AVTP_MJPEG_FIELD_HEIGHT); +} + +void Avtp_Mjpeg_SetField(Avtp_Mjpeg_t* pdu, Avtp_MjpegField_t field, uint64_t value) +{ + SET_FIELD(field, value); +} + +void Avtp_Mjpeg_SetTypeSpecific(Avtp_Mjpeg_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_MJPEG_FIELD_TYPE_SPECIFIC, value); +} + +void Avtp_Mjpeg_SetFragmentOffset(Avtp_Mjpeg_t* pdu, uint32_t value) +{ + SET_FIELD(AVTP_MJPEG_FIELD_FRAGMENT_OFFSET, value); +} + +void Avtp_Mjpeg_SetType(Avtp_Mjpeg_t* pdu, uint8_t value) +{ + SET_FIELD(AVTP_MJPEG_FIELD_TYPE, value); +} + +void Avtp_Mjpeg_SetQ(Avtp_Mjpeg_t* pdu, uint8_t value) { - if (pdu == NULL) return -EINVAL; - memset(pdu, 0, sizeof(Avtp_Mjpeg_t)); - return 0; + SET_FIELD(AVTP_MJPEG_FIELD_Q, value); } -int Avtp_Mjpeg_GetField(Avtp_Mjpeg_t* pdu, Avtp_MjpegField_t field, uint64_t* value) +void Avtp_Mjpeg_SetWidth(Avtp_Mjpeg_t* pdu, uint8_t value) { - return Avtp_GetField(fieldDescriptors, AVTP_MJPEG_FIELD_MAX, (uint8_t*)pdu, field, value); + SET_FIELD(AVTP_MJPEG_FIELD_WIDTH, value); } -int Avtp_Mjpeg_SetField(Avtp_Mjpeg_t* pdu, Avtp_MjpegField_t field, uint64_t value) +void Avtp_Mjpeg_SetHeight(Avtp_Mjpeg_t* pdu, uint8_t value) { - return Avtp_SetField(fieldDescriptors, AVTP_MJPEG_FIELD_MAX, (uint8_t*)pdu, field, value); + SET_FIELD(AVTP_MJPEG_FIELD_HEIGHT, value); } From 64c4d6ddc2df7ca932884765955fdb5e847ddc52 Mon Sep 17 00:00:00 2001 From: Adriaan Niess Date: Wed, 28 Aug 2024 12:31:22 +0200 Subject: [PATCH 29/33] Update examples and tests to be compliant with new GetField API Signed-off-by: Adriaan Niess --- examples/aaf/aaf-listener.c | 2 +- examples/aaf/aaf-talker.c | 2 +- examples/acf-can/acf-can-listener.c | 109 ++++++++--------- examples/crf/crf-listener.c | 2 +- examples/cvf/cvf-listener.c | 129 ++++++-------------- examples/hello-world/hello-world-listener.c | 35 +++--- src/avtp/cvf/Jpeg2000.c | 5 + src/avtp/cvf/Mjpeg.c | 12 +- unit/test-aaf.c | 2 +- unit/test-can.c | 14 +-- unit/test-cvf.c | 11 +- 11 files changed, 124 insertions(+), 199 deletions(-) diff --git a/examples/aaf/aaf-listener.c b/examples/aaf/aaf-listener.c index a2a7e5e..ee0e036 100644 --- a/examples/aaf/aaf-listener.c +++ b/examples/aaf/aaf-listener.c @@ -69,7 +69,7 @@ #include #include -#include "avtp/aaf/PcmStream.h" +#include "avtp/aaf/Pcm.h" #include "common/common.h" #include "avtp/CommonHeader.h" diff --git a/examples/aaf/aaf-talker.c b/examples/aaf/aaf-talker.c index bbc2290..57413b4 100644 --- a/examples/aaf/aaf-talker.c +++ b/examples/aaf/aaf-talker.c @@ -64,7 +64,7 @@ #include #include -#include "avtp/aaf/PcmStream.h" +#include "avtp/aaf/Pcm.h" #include "common/common.h" #include "avtp/CommonHeader.h" diff --git a/examples/acf-can/acf-can-listener.c b/examples/acf-can/acf-can-listener.c index 51b668d..8576089 100644 --- a/examples/acf-can/acf-can-listener.c +++ b/examples/acf-can/acf-can-listener.c @@ -45,7 +45,7 @@ #include "avtp/Udp.h" #include "avtp/acf/Ntscf.h" #include "avtp/acf/Tscf.h" -#include "avtp/acf/Common.h" +#include "avtp/acf/AcfCommon.h" #include "avtp/acf/Can.h" #include "avtp/CommonHeader.h" #include "acf-can-common.h" @@ -139,14 +139,13 @@ static error_t parser(int key, char *arg, struct argp_state *state) static struct argp argp = { options, parser, args_doc, doc }; -static int is_valid_acf_packet(uint8_t* acf_pdu) { - - uint64_t val64; - - Avtp_AcfCommon_GetField((Avtp_AcfCommon_t*)acf_pdu, AVTP_ACF_FIELD_ACF_MSG_TYPE, &val64); - if (val64 != AVTP_ACF_TYPE_CAN) { - fprintf(stderr, "ACF type mismatch: expected %u, got %lu\n", - AVTP_ACF_TYPE_CAN, val64); +static int is_valid_acf_packet(uint8_t* acf_pdu) +{ + Avtp_AcfCommon_t *pdu = (Avtp_AcfCommon_t*) acf_pdu; + uint8_t acf_msg_type = Avtp_AcfCommon_GetAcfMsgType(pdu); + if (acf_msg_type != AVTP_ACF_TYPE_CAN) { + fprintf(stderr, "ACF type mismatch: expected %"PRIu8", got %"PRIu8"\n", + AVTP_ACF_TYPE_CAN, acf_msg_type); return 0; } @@ -155,30 +154,28 @@ static int is_valid_acf_packet(uint8_t* acf_pdu) { void print_can_acf(uint8_t* acf_pdu) { - uint64_t acf_msg_len, can_bus_id, timestamp, can_identifier, pad; - Avtp_Can_t *pdu = (Avtp_Can_t*) acf_pdu; - - Avtp_Can_GetField(pdu, AVTP_CAN_FIELD_ACF_MSG_LENGTH, &acf_msg_len); - Avtp_Can_GetField(pdu, AVTP_CAN_FIELD_CAN_BUS_ID, &can_bus_id); - Avtp_Can_GetField(pdu, AVTP_CAN_FIELD_MESSAGE_TIMESTAMP, ×tamp); - Avtp_Can_GetField(pdu, AVTP_CAN_FIELD_CAN_IDENTIFIER, &can_identifier); - Avtp_Can_GetField(pdu, AVTP_CAN_FIELD_PAD, &pad); + uint16_t acf_msg_len = Avtp_Can_GetAcfMsgLength(pdu); + uint8_t can_bus_id = Avtp_Can_GetCanBusId(pdu); + uint64_t timestamp = Avtp_Can_GetMessageTimestamp(pdu); + uint32_t can_identifier = Avtp_Can_GetCanIdentifier(pdu); + uint8_t pad = Avtp_Can_GetPad(pdu); fprintf(stderr, "------------------------------------\n"); - fprintf(stderr, "Msg Length: %"PRIu64"\n", acf_msg_len); - fprintf(stderr, "Can Bus ID: %"PRIu64"\n", can_bus_id); - fprintf(stderr, "Timestamp: %#lx\n", timestamp); - fprintf(stderr, "Can Identifier: %#lx\n", can_identifier); - fprintf(stderr, "Pad: %"PRIu64"\n", pad); + fprintf(stderr, "Msg Length: %"PRIu16"\n", acf_msg_len); + fprintf(stderr, "Can Bus ID: %"PRIu8"\n", can_bus_id); + fprintf(stderr, "Timestamp: %"PRIu64"", timestamp); + fprintf(stderr, "Can Identifier: %"PRIu32"\n", can_identifier); + fprintf(stderr, "Pad: %"PRIu8"\n", pad); } static int new_packet(int sk_fd, int can_socket) { - int res; - uint64_t msg_length, proc_bytes = 0, msg_proc_bytes = 0; - uint64_t can_frame_id, udp_seq_num, subtype, flag; - uint16_t payload_length, pdu_length; + int res = 0; + uint64_t proc_bytes = 0, msg_proc_bytes = 0; + uint32_t udp_seq_num; + uint16_t msg_length, payload_length, pdu_length; + uint8_t subtype; uint8_t pdu[MAX_PDU_SIZE], i; uint8_t *cf_pdu, *acf_pdu, *udp_pdu, *can_payload; frame_t frame; @@ -186,7 +183,6 @@ static int new_packet(int sk_fd, int can_socket) { memset(&frame, 0, sizeof(struct canfd_frame)); res = recv(sk_fd, pdu, MAX_PDU_SIZE, 0); - if (res < 0 || res > MAX_PDU_SIZE) { perror("Failed to receive data"); return -1; @@ -194,32 +190,27 @@ static int new_packet(int sk_fd, int can_socket) { if (use_udp) { udp_pdu = pdu; - Avtp_Udp_GetField((Avtp_Udp_t *)udp_pdu, AVTP_UDP_FIELD_ENCAPSULATION_SEQ_NO, &udp_seq_num); + udp_seq_num = Avtp_Udp_GetEncapsulationSeqNo((Avtp_Udp_t *)udp_pdu); cf_pdu = pdu + AVTP_UDP_HEADER_LEN; proc_bytes += AVTP_UDP_HEADER_LEN; } else { cf_pdu = pdu; } - res = Avtp_CommonHeader_GetField((Avtp_CommonHeader_t*)cf_pdu, AVTP_COMMON_HEADER_FIELD_SUBTYPE, &subtype); - if (res < 0) { - fprintf(stderr, "Failed to get subtype field: %d\n", res); - return -1; - } - + subtype = Avtp_CommonHeader_GetSubtype((Avtp_CommonHeader_t*)cf_pdu); if (!((subtype == AVTP_SUBTYPE_NTSCF) || (subtype == AVTP_SUBTYPE_TSCF))) { - fprintf(stderr, "Subtype mismatch: expected %u or %u, got %"PRIu64". Dropping packet\n", + fprintf(stderr, "Subtype mismatch: expected %u or %u, got %"PRIu8". Dropping packet\n", AVTP_SUBTYPE_NTSCF, AVTP_SUBTYPE_TSCF, subtype); return -1; } - if(subtype == AVTP_SUBTYPE_TSCF){ + if (subtype == AVTP_SUBTYPE_TSCF){ proc_bytes += AVTP_TSCF_HEADER_LEN; - Avtp_Tscf_GetField((Avtp_Tscf_t*)cf_pdu, AVTP_TSCF_FIELD_STREAM_DATA_LENGTH, (uint64_t *) &msg_length); - }else{ + msg_length = Avtp_Tscf_GetStreamDataLength((Avtp_Tscf_t*)cf_pdu); + } else { proc_bytes += AVTP_NTSCF_HEADER_LEN; - Avtp_Ntscf_GetField((Avtp_Ntscf_t*)cf_pdu, AVTP_NTSCF_FIELD_NTSCF_DATA_LENGTH, (uint64_t *) &msg_length); + msg_length = Avtp_Ntscf_GetNtscfDataLength((Avtp_Ntscf_t*)cf_pdu); } while (msg_proc_bytes < msg_length) { @@ -231,43 +222,39 @@ static int new_packet(int sk_fd, int can_socket) { return -1; } - Avtp_Can_GetField((Avtp_Can_t*)acf_pdu, AVTP_CAN_FIELD_CAN_IDENTIFIER, - &(can_frame_id)); - can_id = can_frame_id; + can_id = Avtp_Can_GetCanIdentifier((Avtp_Can_t*)acf_pdu); can_payload = Avtp_Can_GetPayload((Avtp_Can_t*)acf_pdu, &payload_length, &pdu_length); msg_proc_bytes += pdu_length*4; // Handle EFF Flag - Avtp_Can_GetField((Avtp_Can_t*)acf_pdu, AVTP_CAN_FIELD_EFF, &flag); - if (can_id > 0x7FF && !flag) { - fprintf(stderr, "Error: CAN ID is > 0x7FF but the EFF bit is not set.\n"); - return -1; + if (Avtp_Can_GetEff((Avtp_Can_t*)acf_pdu)) { + can_id |= CAN_EFF_FLAG; + } else if (can_id > 0x7FF) { + fprintf(stderr, "Error: CAN ID is > 0x7FF but the EFF bit is not set.\n"); + return -1; } - if (flag) can_id |= CAN_EFF_FLAG; // Handle RTR Flag - Avtp_Can_GetField((Avtp_Can_t*)acf_pdu, AVTP_CAN_FIELD_RTR, &flag); - if (flag) can_id |= CAN_RTR_FLAG; + if (Avtp_Can_GetRtr((Avtp_Can_t*)acf_pdu)) { + can_id |= CAN_RTR_FLAG; + } if (can_variant == AVTP_CAN_FD) { - - Avtp_Can_GetField((Avtp_Can_t*)acf_pdu, AVTP_CAN_FIELD_BRS, &flag); - if (flag) frame.fd.flags |= CANFD_BRS; - - Avtp_Can_GetField((Avtp_Can_t*)acf_pdu, AVTP_CAN_FIELD_FDF, &flag); - if (flag) frame.fd.flags |= CANFD_FDF; - - Avtp_Can_GetField((Avtp_Can_t*)acf_pdu, AVTP_CAN_FIELD_ESI, &flag); - if (flag) frame.fd.flags |= CANFD_ESI; - + if (Avtp_Can_GetBrs((Avtp_Can_t*)acf_pdu)) { + frame.fd.flags |= CANFD_BRS; + } + if (Avtp_Can_GetFdf((Avtp_Can_t*)acf_pdu)) { + frame.fd.flags |= CANFD_FDF; + } + if (Avtp_Can_GetEsi((Avtp_Can_t*)acf_pdu)) { + frame.fd.flags |= CANFD_ESI; + } frame.fd.can_id = can_id; frame.fd.len = payload_length; memcpy(frame.fd.data, can_payload, payload_length); res = write(can_socket, &frame.fd, sizeof(struct canfd_frame)); - } else { - frame.cc.can_id = can_id; frame.cc.len = payload_length; memcpy(frame.cc.data, can_payload, payload_length); diff --git a/examples/crf/crf-listener.c b/examples/crf/crf-listener.c index a590e46..de200d2 100644 --- a/examples/crf/crf-listener.c +++ b/examples/crf/crf-listener.c @@ -100,7 +100,7 @@ #include #include "avtp/Crf.h" -#include "avtp/aaf/PcmStream.h" +#include "avtp/aaf/Pcm.h" #include "common/common.h" #include "avtp/CommonHeader.h" diff --git a/examples/cvf/cvf-listener.c b/examples/cvf/cvf-listener.c index 2ef39c0..9a983c2 100644 --- a/examples/cvf/cvf-listener.c +++ b/examples/cvf/cvf-listener.c @@ -164,109 +164,62 @@ static int schedule_nal(int fd, struct timespec *tspec, uint8_t *nal, static bool is_valid_packet(Avtp_Cvf_t* cvf) { - uint64_t val; - int res; - - res = Avtp_Cvf_GetField(cvf, AVTP_CVF_FIELD_SUBTYPE, &val); - if (res < 0) { - fprintf(stderr, "Failed to get subtype field: %d\n", res); - return false; - } - if (val != AVTP_SUBTYPE_CVF) { - fprintf(stderr, "Subtype mismatch: expected %u, got %"PRIu64"\n", AVTP_SUBTYPE_CVF, val); + uint8_t subtype = Avtp_Cvf_GetSubtype(cvf); + if (subtype != AVTP_SUBTYPE_CVF) { + fprintf(stderr, "Subtype mismatch: expected %u, got %"PRIu8"\n", + AVTP_SUBTYPE_CVF, subtype); return false; } - res = Avtp_Cvf_GetField(cvf, AVTP_CVF_FIELD_VERSION, &val); - if (res < 0) { - fprintf(stderr, "Failed to get version field: %d\n", res); - return false; - } - if (val != 0) { - fprintf(stderr, "Version mismatch: expected %u, got %"PRIu64"\n", 0, val); + uint8_t version = Avtp_Cvf_GetVersion(cvf); + if (version != 0) { + fprintf(stderr, "Version mismatch: expected %u, got %"PRIu8"\n", 0, + version); return false; } - res = Avtp_Cvf_GetField(cvf, AVTP_CVF_FIELD_TV, &val); - if (res < 0) { - fprintf(stderr, "Failed to get tv field: %d\n", res); - return false; - } - if (val != 1) { - fprintf(stderr, "tv mismatch: expected %u, got %lu\n", - 1, val); + uint8_t tv = Avtp_Cvf_GetTv(cvf); + if (tv != 1) { + fprintf(stderr, "tv mismatch: expected %u, got %"PRIu8"\n", 1, tv); return false; } - res = Avtp_Cvf_GetField(cvf, AVTP_CVF_FIELD_STREAM_ID, &val); - if (res < 0) { - fprintf(stderr, "Failed to get stream ID field: %d\n", res); - return false; - } - if (val != STREAM_ID) { + uint64_t stream_id = Avtp_Cvf_GetStreamId(cvf); + if (stream_id != STREAM_ID) { fprintf(stderr, "Stream ID mismatch: expected %lu, got %lu\n", - STREAM_ID, val); + STREAM_ID, stream_id); return false; } - res = Avtp_Cvf_GetField(cvf, AVTP_CVF_FIELD_SEQUENCE_NUM, &val); - if (res < 0) { - fprintf(stderr, "Failed to get sequence num field: %d\n", res); - return false; + uint8_t sequence_num = Avtp_Cvf_GetSequenceNum(cvf); + if (sequence_num != expected_seq) { + fprintf(stderr, "Sequence number mismatch: expected %"PRIu8", " + "got %"PRIu8"\n", expected_seq, sequence_num); + expected_seq = sequence_num; } - - if (val != expected_seq) { - /* If we have a sequence number mismatch, we simply log the - * issue and continue to process the packet. We don't want to - * invalidate it since it is a valid packet after all. - */ - fprintf(stderr, - "Sequence number mismatch: expected %u, got %lu\n", - expected_seq, val); - expected_seq = val; - } - expected_seq++; - res = Avtp_Cvf_GetField(cvf, AVTP_CVF_FIELD_FORMAT, &val); - if (res < 0) { - fprintf(stderr, "Failed to get format field: %d\n", res); - return false; - } - if (val != AVTP_CVF_FORMAT_RFC) { - fprintf(stderr, "Format mismatch: expected %u, got %lu\n", - AVTP_CVF_FORMAT_RFC, val); + uint8_t format = Avtp_Cvf_GetFormat(cvf); + if (format != AVTP_CVF_FORMAT_RFC) { + fprintf(stderr, "Format mismatch: expected %"PRIu8", got %"PRIu8"\n", + AVTP_CVF_FORMAT_RFC, format); return false; } - res = Avtp_Cvf_GetField(cvf, AVTP_CVF_FIELD_FORMAT_SUBTYPE, &val); - if (res < 0) { - fprintf(stderr, "Failed to get format subtype field: %d\n", - res); - return false; - } - if (val != AVTP_CVF_FORMAT_SUBTYPE_H264) { - fprintf(stderr, "Format mismatch: expected %u, got %lu\n", - AVTP_CVF_FORMAT_SUBTYPE_H264, val); + uint8_t format_subtype = Avtp_Cvf_GetFormatSubtype(cvf); + if (format_subtype != AVTP_CVF_FORMAT_SUBTYPE_H264) { + fprintf(stderr, "Format mismatch: expected %"PRIu8", got %"PRIu8"\n", + AVTP_CVF_FORMAT_SUBTYPE_H264, format_subtype); return false; } return true; } -static int get_h264_data_len(Avtp_Cvf_t* cvfHeader, uint16_t *stream_data_len) +static uint16_t get_h264_data_len(Avtp_Cvf_t* cvf) { - int res; - uint64_t val; - - res = Avtp_Cvf_GetField(cvfHeader, AVTP_CVF_FIELD_STREAM_DATA_LENGTH, &val); - if (res < 0) { - fprintf(stderr, "Failed to get data_len field\n"); - return -1; - } - *stream_data_len = val - AVTP_H264_HEADER_LEN; - - return 0; + uint16_t stream_data_len = Avtp_Cvf_GetStreamDataLength(cvf); + return stream_data_len - AVTP_H264_HEADER_LEN; } static int new_packet(int sk_fd, int timer_fd) @@ -274,38 +227,32 @@ static int new_packet(int sk_fd, int timer_fd) int res; ssize_t n; uint16_t h264_data_len; - uint64_t avtp_time; + uint32_t avtp_time; struct timespec tspec; - Avtp_Cvf_t* cvfHeader = alloca(MAX_PDU_SIZE); - Avtp_H264_t* h264Header = (Avtp_H264_t*)(&cvfHeader->payload); + Avtp_Cvf_t* cvf = alloca(MAX_PDU_SIZE); + Avtp_H264_t* h264Header = (Avtp_H264_t*)(&cvf->payload); uint8_t* h264Payload = (uint8_t*)(&h264Header->payload); - memset(cvfHeader, 1, MAX_PDU_SIZE); + memset(cvf, 1, MAX_PDU_SIZE); - n = recv(sk_fd, cvfHeader, MAX_PDU_SIZE, 0); + n = recv(sk_fd, cvf, MAX_PDU_SIZE, 0); if (n < 0 || n > MAX_PDU_SIZE) { perror("Failed to receive data"); return -1; } - if (!is_valid_packet(cvfHeader)) { + if (!is_valid_packet(cvf)) { fprintf(stderr, "Dropping packet\n"); return 0; } - res = Avtp_Cvf_GetField(cvfHeader, AVTP_CVF_FIELD_AVTP_TIMESTAMP, &avtp_time); - if (res < 0) { - fprintf(stderr, "Failed to get AVTP time from PDU\n"); - return -1; - } + avtp_time = Avtp_Cvf_GetAvtpTimestamp(cvf); res = get_presentation_time(avtp_time, &tspec); if (res < 0) return -1; - res = get_h264_data_len(cvfHeader, &h264_data_len); - if (res < 0) - return -1; + h264_data_len = get_h264_data_len(cvf); res = schedule_nal(timer_fd, &tspec, h264Payload, h264_data_len); if (res < 0) diff --git a/examples/hello-world/hello-world-listener.c b/examples/hello-world/hello-world-listener.c index e33c27a..bae998f 100644 --- a/examples/hello-world/hello-world-listener.c +++ b/examples/hello-world/hello-world-listener.c @@ -41,7 +41,7 @@ #include "avtp/Udp.h" #include "avtp/acf/Ntscf.h" #include "avtp/acf/Tscf.h" -#include "avtp/acf/Common.h" +#include "avtp/acf/AcfCommon.h" #include "avtp/acf/Gpc.h" #include "avtp/CommonHeader.h" @@ -110,8 +110,11 @@ static struct argp argp = { options, parser, 0, 0}; int main(int argc, char *argv[]) { int sk_fd, res; - uint64_t msg_length, proc_bytes = 0, msg_proc_bytes = 0; - uint64_t udp_seq_num, subtype, flag, acf_type, pdu_length; + uint64_t proc_bytes = 0, msg_proc_bytes = 0; + uint32_t udp_seq_num; + uint16_t msg_length, acf_msg_length; + uint8_t subtype, acf_type; + uint64_t flag; uint8_t pdu[MAX_PDU_SIZE]; uint8_t *cf_pdu, *acf_pdu, *udp_pdu; uint64_t gpc_code; @@ -140,7 +143,7 @@ int main(int argc, char *argv[]) // If UDP is used the packets starts with an encapsulation number if (use_udp) { udp_pdu = pdu; - Avtp_Udp_GetField((Avtp_Udp_t *)udp_pdu, AVTP_UDP_FIELD_ENCAPSULATION_SEQ_NO, &udp_seq_num); + udp_seq_num = Avtp_Udp_GetEncapsulationSeqNo((Avtp_Udp_t *)udp_pdu); cf_pdu = pdu + AVTP_UDP_HEADER_LEN; proc_bytes += AVTP_UDP_HEADER_LEN; } else { @@ -148,32 +151,28 @@ int main(int argc, char *argv[]) } // Check if the packet is a control format packet (i.e. NTSCF or TSCF) - res = Avtp_CommonHeader_GetField((Avtp_CommonHeader_t*)cf_pdu, AVTP_COMMON_HEADER_FIELD_SUBTYPE, &subtype); - if (res < 0) { - fprintf(stderr, "Failed to get subtype field: %d\n", res); - goto err; - } - if(subtype == AVTP_SUBTYPE_TSCF){ + subtype = Avtp_CommonHeader_GetSubtype((Avtp_CommonHeader_t*)cf_pdu); + if (subtype == AVTP_SUBTYPE_TSCF){ proc_bytes += AVTP_TSCF_HEADER_LEN; - Avtp_Tscf_GetField((Avtp_Tscf_t*)cf_pdu, AVTP_TSCF_FIELD_STREAM_DATA_LENGTH, (uint64_t *) &msg_length); - }else{ + msg_length = Avtp_Tscf_GetStreamDataLength((Avtp_Tscf_t*)cf_pdu); + } else { proc_bytes += AVTP_NTSCF_HEADER_LEN; - Avtp_Ntscf_GetField((Avtp_Ntscf_t*)cf_pdu, AVTP_NTSCF_FIELD_NTSCF_DATA_LENGTH, (uint64_t *) &msg_length); + msg_length = Avtp_Ntscf_GetNtscfDataLength((Avtp_Ntscf_t*)cf_pdu); } // Check if the control packet payload is a ACF GPC. acf_pdu = &pdu[proc_bytes]; - Avtp_AcfCommon_GetField((Avtp_AcfCommon_t*)acf_pdu, AVTP_ACF_FIELD_ACF_MSG_TYPE, &acf_type); + acf_type = Avtp_AcfCommon_GetAcfMsgType((Avtp_AcfCommon_t*)acf_pdu); if (acf_type != AVTP_ACF_TYPE_GPC) { - fprintf(stderr, "ACF type mismatch: expected %u, got %lu\n", + fprintf(stderr, "ACF type mismatch: expected %"PRIu8", got %"PRIu8"\n", AVTP_ACF_TYPE_GPC, acf_type); continue; } // Parse the GPC Packet and print contents on the STDOUT - Avtp_Gpc_GetField((Avtp_Gpc_t*)acf_pdu, AVTP_GPC_FIELD_GPC_MSG_ID, &gpc_code); - Avtp_Gpc_GetField((Avtp_Gpc_t*)acf_pdu, AVTP_GPC_FIELD_ACF_MSG_LENGTH, &pdu_length); - if (pdu_length * 4 <= MAX_MSG_SIZE) { + gpc_code = Avtp_Gpc_GetGpcMsgId((Avtp_Gpc_t*)acf_pdu); + acf_msg_length = Avtp_Gpc_GetAcfMsgLength((Avtp_Gpc_t*)acf_pdu); + if (acf_msg_length * 4 <= MAX_MSG_SIZE) { recd_msg = acf_pdu + AVTP_GPC_HEADER_LEN; printf("%s : GPC Code %ld\n", recd_msg, gpc_code); } diff --git a/src/avtp/cvf/Jpeg2000.c b/src/avtp/cvf/Jpeg2000.c index f6c9351..b953ea9 100644 --- a/src/avtp/cvf/Jpeg2000.c +++ b/src/avtp/cvf/Jpeg2000.c @@ -34,6 +34,11 @@ #include "avtp/Utils.h" #include "avtp/CommonHeader.h" +#define GET_FIELD(field) \ + (Avtp_GetField(fieldDescriptors, AVTP_JPEG2000_FIELD_MAX, (uint8_t*)pdu, field)) +#define SET_FIELD(field, value) \ + (Avtp_SetField(fieldDescriptors, AVTP_JPEG2000_FIELD_MAX, (uint8_t*)pdu, field, value)) + static const Avtp_FieldDescriptor_t fieldDescriptors[AVTP_JPEG2000_FIELD_MAX] = { [AVTP_JPEG2000_FIELD_TP] = { .quadlet = 0, .offset = 0, .bits = 2 }, diff --git a/src/avtp/cvf/Mjpeg.c b/src/avtp/cvf/Mjpeg.c index 22e7e36..488d167 100644 --- a/src/avtp/cvf/Mjpeg.c +++ b/src/avtp/cvf/Mjpeg.c @@ -63,32 +63,32 @@ uint64_t Avtp_Mjpeg_GetField(Avtp_Mjpeg_t* pdu, Avtp_MjpegField_t field) uint8_t Avtp_Mjpeg_GetTypeSpecific(Avtp_Mjpeg_t* pdu) { - SET_FIED(AVTP_MJPEG_FIELD_TYPE_SPECIFIC); + return GET_FIELD(AVTP_MJPEG_FIELD_TYPE_SPECIFIC); } uint32_t Avtp_Mjpeg_GetFragmentOffset(Avtp_Mjpeg_t* pdu) { - SET_FIED(AVTP_MJPEG_FIELD_FRAGMENT_OFFSET); + return GET_FIELD(AVTP_MJPEG_FIELD_FRAGMENT_OFFSET); } uint8_t Avtp_Mjpeg_GetType(Avtp_Mjpeg_t* pdu) { - SET_FIED(AVTP_MJPEG_FIELD_TYPE); + return GET_FIELD(AVTP_MJPEG_FIELD_TYPE); } uint8_t Avtp_Mjpeg_GetQ(Avtp_Mjpeg_t* pdu) { - SET_FIED(AVTP_MJPEG_FIELD_Q); + return GET_FIELD(AVTP_MJPEG_FIELD_Q); } uint8_t Avtp_Mjpeg_GetWidth(Avtp_Mjpeg_t* pdu) { - SET_FIED(AVTP_MJPEG_FIELD_WIDTH); + return GET_FIELD(AVTP_MJPEG_FIELD_WIDTH); } uint8_t Avtp_Mjpeg_GetHeight(Avtp_Mjpeg_t* pdu) { - SET_FIED(AVTP_MJPEG_FIELD_HEIGHT); + return GET_FIELD(AVTP_MJPEG_FIELD_HEIGHT); } void Avtp_Mjpeg_SetField(Avtp_Mjpeg_t* pdu, Avtp_MjpegField_t field, uint64_t value) diff --git a/unit/test-aaf.c b/unit/test-aaf.c index ec5dd8a..889fea7 100644 --- a/unit/test-aaf.c +++ b/unit/test-aaf.c @@ -33,7 +33,7 @@ #include #include "avtp/CommonHeader.h" -#include "avtp/aaf/PcmStream.h" +#include "avtp/aaf/Pcm.h" static void aaf_get_field_null_pdu(void **state) { diff --git a/unit/test-can.c b/unit/test-can.c index 0466747..67d05ec 100644 --- a/unit/test-can.c +++ b/unit/test-can.c @@ -47,17 +47,14 @@ static void can_init(void **state) { uint8_t pdu[MAX_PDU_SIZE]; uint8_t init_pdu[AVTP_CAN_HEADER_LEN]; - int ret; // Check init function while passing in a null pointer - ret = Avtp_Can_Init(NULL); - assert_int_equal(ret, -EINVAL); + Avtp_Can_Init(NULL); // Check if the function is initializing properly - ret = Avtp_Can_Init((Avtp_Can_t*)pdu); + Avtp_Can_Init((Avtp_Can_t*)pdu); memset(init_pdu, 0, AVTP_CAN_HEADER_LEN); init_pdu[0] = 0x02; // Setting ACF type as ACF_CAN - assert_int_equal(ret, 0); assert_memory_equal(init_pdu, pdu, AVTP_CAN_HEADER_LEN); } @@ -65,17 +62,14 @@ static void can_brief_init(void **state) { uint8_t pdu[MAX_PDU_SIZE]; uint8_t init_pdu[AVTP_CAN_BRIEF_HEADER_LEN]; - int ret; // Check init function while passing in a null pointer - ret = Avtp_CanBrief_Init(NULL); - assert_int_equal(ret, -EINVAL); + Avtp_CanBrief_Init(NULL); // Check if the function is initializing properly - ret = Avtp_CanBrief_Init((Avtp_CanBrief_t*)pdu); + Avtp_CanBrief_Init((Avtp_CanBrief_t*)pdu); memset(init_pdu, 0, AVTP_CAN_BRIEF_HEADER_LEN); init_pdu[0] = 0x04; // Setting ACF type as ACF_CAN - assert_int_equal(ret, 0); assert_memory_equal(init_pdu, pdu, AVTP_CAN_BRIEF_HEADER_LEN); } diff --git a/unit/test-cvf.c b/unit/test-cvf.c index 98acfc7..85f7ac2 100644 --- a/unit/test-cvf.c +++ b/unit/test-cvf.c @@ -509,7 +509,6 @@ static void cvf_set_field_ptv(void **state) static void cvf_get_field_h264_timestamp(void **state) { - int res; uint64_t val; Avtp_H264_t pdu; @@ -518,20 +517,14 @@ static void cvf_get_field_h264_timestamp(void **state) uint32_t value = htonl(0x80C0FFEE); memcpy(&pdu.header, &value, 4); - res = Avtp_H264_GetField(&pdu, AVTP_H264_FIELD_TIMESTAMP, &val); - - assert_int_equal(res, 0); + val = Avtp_H264_GetField(&pdu, AVTP_H264_FIELD_TIMESTAMP); assert_true(val == 0x80C0FFEE); } static void cvf_set_field_h264_timestamp(void **state) { - int res; Avtp_H264_t pdu; - - res = Avtp_H264_SetField(&pdu, AVTP_H264_FIELD_TIMESTAMP, 0x80C0FFEE); - - assert_int_equal(res, 0); + Avtp_H264_SetField(&pdu, AVTP_H264_FIELD_TIMESTAMP, 0x80C0FFEE); assert_true(ntohl(*(uint32_t*)(&pdu.header)) == 0x80C0FFEE); } From 9a0f74c5bdb22e52d1ea8e63a8120a60010db698 Mon Sep 17 00:00:00 2001 From: Adriaan Niess Date: Wed, 28 Aug 2024 14:18:56 +0200 Subject: [PATCH 30/33] Make tests conform to new GetField API Signed-off-by: Adriaan Niess --- include/avtp/Crf.h | 2 +- src/avtp/CommonHeader.c | 4 +- src/avtp/Crf.c | 31 ++++++------ src/avtp/Rvf.c | 8 ++-- src/avtp/Utils.c | 102 ++++++++++++++++++---------------------- src/avtp/aaf/Pcm.c | 7 ++- src/avtp/acf/CanBrief.c | 2 +- src/avtp/cvf/Cvf.c | 20 +++----- 8 files changed, 80 insertions(+), 96 deletions(-) diff --git a/include/avtp/Crf.h b/include/avtp/Crf.h index 0a87ed7..7895ac4 100644 --- a/include/avtp/Crf.h +++ b/include/avtp/Crf.h @@ -76,7 +76,7 @@ typedef enum Avtp_CrfField { AVTP_CRF_FIELD_MAX, }Avtp_CrfField_t; -int Avtp_Crf_Init(Avtp_Crf_t* pdu); +void Avtp_Crf_Init(Avtp_Crf_t* pdu); uint64_t Avtp_Crf_GetField(Avtp_Crf_t* pdu, Avtp_CrfField_t field); diff --git a/src/avtp/CommonHeader.c b/src/avtp/CommonHeader.c index e5febff..8fc4579 100644 --- a/src/avtp/CommonHeader.c +++ b/src/avtp/CommonHeader.c @@ -97,7 +97,7 @@ void Avtp_CommonHeader_SetVersion(Avtp_CommonHeader_t* pdu, uint8_t value) int avtp_pdu_get(const struct avtp_common_pdu *pdu, Avtp_CommonHeaderField_t field, uint32_t *val) { - if (pdu == NULL || val == NULL) { + if (pdu == NULL || val == NULL || field >= AVTP_COMMON_HEADER_FIELD_MAX) { return -EINVAL; } else { uint64_t temp = Avtp_CommonHeader_GetField((Avtp_CommonHeader_t*) pdu, field); @@ -109,7 +109,7 @@ int avtp_pdu_get(const struct avtp_common_pdu *pdu, Avtp_CommonHeaderField_t fie int avtp_pdu_set(struct avtp_common_pdu *pdu, Avtp_CommonHeaderField_t field, uint32_t value) { - if (pdu == NULL) { + if (pdu == NULL || field >= AVTP_COMMON_HEADER_FIELD_MAX) { return -EINVAL; } else { Avtp_CommonHeader_SetField((Avtp_CommonHeader_t*)pdu, field, value); diff --git a/src/avtp/Crf.c b/src/avtp/Crf.c index 8798b5a..32691d9 100644 --- a/src/avtp/Crf.c +++ b/src/avtp/Crf.c @@ -62,18 +62,13 @@ static const Avtp_FieldDescriptor_t Avtp_CrfFieldDescriptors[AVTP_CRF_FIELD_MAX] [AVTP_CRF_FIELD_TIMESTAMP_INTERVAL] = { .quadlet = 4, .offset = 16, .bits = 16 }, }; -int Avtp_Crf_Init(Avtp_Crf_t* pdu) { - - if (pdu == NULL) { - return -EINVAL; +void Avtp_Crf_Init(Avtp_Crf_t* pdu) +{ + if (pdu != NULL) { + memset(pdu, 0, sizeof(Avtp_Crf_t)); + Avtp_Crf_SetField(pdu, AVTP_CRF_FIELD_SUBTYPE, AVTP_SUBTYPE_CRF); + Avtp_Crf_SetField(pdu, AVTP_CRF_FIELD_SV, 1); } - - memset(pdu, 0, sizeof(Avtp_Crf_t)); - Avtp_Crf_SetField(pdu, AVTP_CRF_FIELD_SUBTYPE, AVTP_SUBTYPE_CRF); - Avtp_Crf_SetField(pdu, AVTP_CRF_FIELD_SV, 1); - - return 0; - } uint64_t Avtp_Crf_GetField(Avtp_Crf_t* pdu, Avtp_CrfField_t field) @@ -222,18 +217,17 @@ void Avtp_Crf_SetTimestampInterval(Avtp_Crf_t* pdu, uint16_t value) int avtp_crf_pdu_get(const void *pdu, Avtp_CrfField_t field, uint64_t *val) { - if (pdu == NULL || val == NULL) { + if (pdu == NULL || val == NULL || field >= AVTP_CRF_FIELD_MAX) { return -EINVAL; } else { - uint64_t temp = Avtp_Crf_GetField((Avtp_Crf_t*)pdu, field); - *val = (uint32_t)temp; + *val = Avtp_Crf_GetField((Avtp_Crf_t*)pdu, field); return 0; } } int avtp_crf_pdu_set(void *pdu, Avtp_CrfField_t field, uint64_t val) { - if (pdu == NULL) { + if (pdu == NULL || field >= AVTP_CRF_FIELD_MAX) { return -EINVAL; } else { Avtp_Crf_SetField((Avtp_Crf_t*)pdu, field, val); @@ -243,5 +237,10 @@ int avtp_crf_pdu_set(void *pdu, Avtp_CrfField_t field, uint64_t val) int avtp_crf_pdu_init(void *pdu) { - return Avtp_Crf_Init((Avtp_Crf_t*)pdu); + if (pdu == NULL) { + return -EINVAL; + } else { + Avtp_Crf_Init((Avtp_Crf_t*)pdu); + return 0; + } } diff --git a/src/avtp/Rvf.c b/src/avtp/Rvf.c index b7e3353..e2fd97e 100644 --- a/src/avtp/Rvf.c +++ b/src/avtp/Rvf.c @@ -355,16 +355,17 @@ void Avtp_Rvf_SetLineNumber(Avtp_Rvf_t* pdu, uint16_t value) int avtp_rvf_pdu_get(const void* pdu, Avtp_RvfField_t field, uint64_t* val) { - if (pdu == NULL || val == NULL) { + if (pdu == NULL || val == NULL || field >= AVTP_RVF_FIELD_MAX) { return -EINVAL; } else { - return Avtp_Rvf_GetField((Avtp_Rvf_t*)pdu, field); + *val = Avtp_Rvf_GetField((Avtp_Rvf_t*)pdu, field); + return 0; } } int avtp_rvf_pdu_set(void* pdu, Avtp_RvfField_t field, uint64_t val) { - if (pdu == NULL) { + if (pdu == NULL || field >= AVTP_RVF_FIELD_MAX) { return -EINVAL; } else { Avtp_Rvf_SetField((Avtp_Rvf_t*)pdu, field, val); @@ -378,5 +379,6 @@ int avtp_rvf_pdu_init(void* pdu) return -EINVAL; } else { Avtp_Rvf_Init((Avtp_Rvf_t*)pdu); + return 0; } } diff --git a/src/avtp/Utils.c b/src/avtp/Utils.c index a2a0b0b..7cab2bf 100644 --- a/src/avtp/Utils.c +++ b/src/avtp/Utils.c @@ -46,72 +46,62 @@ int IsFieldDescriptorValid(const Avtp_FieldDescriptor_t* fieldDescriptor) uint64_t Avtp_GetField(const Avtp_FieldDescriptor_t* fieldDescriptors, uint8_t numFields, uint8_t* pdu, uint8_t field) { - if (pdu == NULL || field >= numFields - || !IsFieldDescriptorValid(&fieldDescriptors[field])) { - assert(0); - return 0; - } - - const Avtp_FieldDescriptor_t* fieldDescriptor = &fieldDescriptors[field]; - uint64_t result = 0; - uint8_t quadletOffset = 0; - uint8_t processedBits = 0; - while (processedBits < fieldDescriptor->bits) { - uint8_t quadletId = fieldDescriptor->quadlet + quadletOffset; - uint8_t quadletBits; - uint8_t quadletShift; - if (processedBits == 0) { - quadletBits = MIN(32 - fieldDescriptor->offset, fieldDescriptor->bits - processedBits); - quadletShift = 32 - quadletBits - fieldDescriptor->offset; - } else { - quadletBits = MIN(32, fieldDescriptor->bits - processedBits); - quadletShift = 32 - quadletBits; - } - uint32_t quadletMask = ((1ULL << quadletBits) - 1ULL) << quadletShift; - uint32_t* quadletPtr = (uint32_t*)(pdu + quadletId * 4); - uint32_t quadletHostOrder = Avtp_BeToCpu32(*quadletPtr); - uint32_t partialValue = (quadletHostOrder & quadletMask) >> quadletShift; - result |= (uint64_t)(partialValue) << (fieldDescriptor->bits - processedBits - quadletBits); + if (fieldDescriptors != NULL && pdu != NULL && field < numFields) { + const Avtp_FieldDescriptor_t* fieldDescriptor = &fieldDescriptors[field]; + uint8_t quadletOffset = 0; + uint8_t processedBits = 0; + while (processedBits < fieldDescriptor->bits) { + uint8_t quadletId = fieldDescriptor->quadlet + quadletOffset; + uint8_t quadletBits; + uint8_t quadletShift; + if (processedBits == 0) { + quadletBits = MIN(32 - fieldDescriptor->offset, fieldDescriptor->bits - processedBits); + quadletShift = 32 - quadletBits - fieldDescriptor->offset; + } else { + quadletBits = MIN(32, fieldDescriptor->bits - processedBits); + quadletShift = 32 - quadletBits; + } + uint32_t quadletMask = ((1ULL << quadletBits) - 1ULL) << quadletShift; + uint32_t* quadletPtr = (uint32_t*)(pdu + quadletId * 4); + uint32_t quadletHostOrder = Avtp_BeToCpu32(*quadletPtr); + uint32_t partialValue = (quadletHostOrder & quadletMask) >> quadletShift; + result |= (uint64_t)(partialValue) << (fieldDescriptor->bits - processedBits - quadletBits); - quadletOffset += 1; - processedBits += quadletBits; + quadletOffset += 1; + processedBits += quadletBits; + } } - return result; } void Avtp_SetField(const Avtp_FieldDescriptor_t* fieldDescriptors, uint8_t numFields, uint8_t* pdu, uint8_t field, uint64_t value) { - if (pdu == NULL || field >= numFields || - !IsFieldDescriptorValid(&fieldDescriptors[field])) { - assert(0); - } + if (fieldDescriptors != NULL && pdu != NULL && field < numFields) { + const Avtp_FieldDescriptor_t* fieldDescriptor = &fieldDescriptors[field]; + uint8_t quadletOffset = 0; + uint8_t processedBits = 0; + while (processedBits < fieldDescriptor->bits) { + uint8_t quadletId = fieldDescriptor->quadlet + quadletOffset; + uint8_t quadletBits; + uint8_t quadletShift; + if (processedBits == 0) { + quadletBits = MIN(32 - fieldDescriptor->offset, fieldDescriptor->bits - processedBits); + quadletShift = 32 - quadletBits - fieldDescriptor->offset; + } else { + quadletBits = MIN(32, fieldDescriptor->bits - processedBits); + quadletShift = 32 - quadletBits; + } + uint32_t partialValue = value >> (fieldDescriptor->bits - processedBits - quadletBits); + uint32_t quadletMask = ((1ULL << quadletBits) - 1ULL) << quadletShift; + uint32_t* quadletPtr = (uint32_t*)(pdu + quadletId * 4); + uint32_t quadletHostOrder = Avtp_BeToCpu32(*quadletPtr); + quadletHostOrder = (quadletHostOrder & ~quadletMask) | ((partialValue << quadletShift) & quadletMask); + *quadletPtr = Avtp_CpuToBe32(quadletHostOrder); - const Avtp_FieldDescriptor_t* fieldDescriptor = &fieldDescriptors[field]; - - uint8_t quadletOffset = 0; - uint8_t processedBits = 0; - while (processedBits < fieldDescriptor->bits) { - uint8_t quadletId = fieldDescriptor->quadlet + quadletOffset; - uint8_t quadletBits; - uint8_t quadletShift; - if (processedBits == 0) { - quadletBits = MIN(32 - fieldDescriptor->offset, fieldDescriptor->bits - processedBits); - quadletShift = 32 - quadletBits - fieldDescriptor->offset; - } else { - quadletBits = MIN(32, fieldDescriptor->bits - processedBits); - quadletShift = 32 - quadletBits; + quadletOffset += 1; + processedBits += quadletBits; } - uint32_t partialValue = value >> (fieldDescriptor->bits - processedBits - quadletBits); - uint32_t quadletMask = ((1ULL << quadletBits) - 1ULL) << quadletShift; - uint32_t* quadletPtr = (uint32_t*)(pdu + quadletId * 4); - uint32_t quadletHostOrder = Avtp_BeToCpu32(*quadletPtr); - quadletHostOrder = (quadletHostOrder & ~quadletMask) | ((partialValue << quadletShift) & quadletMask); - *quadletPtr = Avtp_CpuToBe32(quadletHostOrder); - - quadletOffset += 1; - processedBits += quadletBits; } } diff --git a/src/avtp/aaf/Pcm.c b/src/avtp/aaf/Pcm.c index ed16224..8979d39 100644 --- a/src/avtp/aaf/Pcm.c +++ b/src/avtp/aaf/Pcm.c @@ -243,10 +243,9 @@ void Avtp_Pcm_SetEvt(Avtp_Pcm_t* pdu, uint8_t value) * Legacy API (deprecated) *****************************************************************************/ -int avtp_aaf_pdu_get(void *pdu, - Avtp_PcmFields_t field, uint64_t *val) +int avtp_aaf_pdu_get(void *pdu, Avtp_PcmFields_t field, uint64_t *val) { - if (pdu == NULL || val == NULL) { + if (pdu == NULL || val == NULL || field >= AVTP_PCM_FIELD_MAX) { return -EINVAL; } else { *val = Avtp_Pcm_GetField((Avtp_Pcm_t*)pdu, field); @@ -257,7 +256,7 @@ int avtp_aaf_pdu_get(void *pdu, int avtp_aaf_pdu_set(void *pdu, Avtp_PcmFields_t field, uint64_t val) { - if (pdu == NULL) { + if (pdu == NULL || field >= AVTP_PCM_FIELD_MAX) { return -EINVAL; } else { Avtp_Pcm_SetField((Avtp_Pcm_t*)pdu, field, val); diff --git a/src/avtp/acf/CanBrief.c b/src/avtp/acf/CanBrief.c index 738429e..c3524a8 100644 --- a/src/avtp/acf/CanBrief.c +++ b/src/avtp/acf/CanBrief.c @@ -61,7 +61,7 @@ static const Avtp_FieldDescriptor_t Avtp_CanBriefFieldDesc[AVTP_CAN_BRIEF_FIELD_ void Avtp_CanBrief_Init(Avtp_CanBrief_t* pdu) { - if(pdu == NULL) { + if(pdu != NULL) { memset(pdu, 0, sizeof(Avtp_CanBrief_t)); Avtp_CanBrief_SetField(pdu, AVTP_CAN_BRIEF_FIELD_ACF_MSG_TYPE, AVTP_ACF_TYPE_CAN_BRIEF); } diff --git a/src/avtp/cvf/Cvf.c b/src/avtp/cvf/Cvf.c index f1b7f15..e205336 100644 --- a/src/avtp/cvf/Cvf.c +++ b/src/avtp/cvf/Cvf.c @@ -68,8 +68,8 @@ void Avtp_Cvf_Init(Avtp_Cvf_t* pdu) if (pdu != NULL) { memset(pdu, 0, sizeof(Avtp_Cvf_t)); Avtp_Cvf_SetField(pdu, AVTP_CVF_FIELD_SUBTYPE, AVTP_SUBTYPE_CVF); - Avtp_Cvf_SetField(pdu, AVTP_CVF_FIELD_SV, 1); Avtp_Cvf_SetField(pdu, AVTP_CVF_FIELD_FORMAT, AVTP_CVF_FORMAT_RFC); + Avtp_Cvf_SetSv(pdu, 1); } } @@ -239,7 +239,7 @@ void Avtp_Cvf_SetEvt(Avtp_Cvf_t* pdu, uint8_t value) int avtp_cvf_pdu_get(void* pdu, Avtp_CvfField_t field, uint64_t *val) { - if (pdu == NULL || val == NULL) { + if (pdu == NULL || val == NULL || field >= AVTP_CVF_FIELD_MAX) { return -EINVAL; } else { *val = Avtp_Cvf_GetField((Avtp_Cvf_t*)pdu, field); @@ -249,7 +249,7 @@ int avtp_cvf_pdu_get(void* pdu, Avtp_CvfField_t field, uint64_t *val) int avtp_cvf_pdu_set(void* pdu, Avtp_CvfField_t field, uint64_t val) { - if (pdu == NULL) { + if (pdu == NULL || field >= AVTP_CVF_FIELD_MAX) { return -EINVAL; } else { Avtp_Cvf_SetField((Avtp_Cvf_t*)pdu, field, val); @@ -261,15 +261,9 @@ int avtp_cvf_pdu_init(void* pdu, uint8_t format_subtype) { if (pdu == NULL) { return -EINVAL; + } else { + Avtp_Cvf_Init(pdu); + Avtp_Cvf_SetFormatSubtype(pdu, format_subtype); + return 0; } - - int ret; - ret = avtp_cvf_pdu_set(pdu, AVTP_CVF_FIELD_FORMAT_SUBTYPE, format_subtype); - if (ret != 0) return ret; - ret = avtp_cvf_pdu_set(pdu, AVTP_CVF_FIELD_SV, 1); - if (ret != 0) return ret; - ret = avtp_cvf_pdu_set(pdu, AVTP_CVF_FIELD_FORMAT, AVTP_CVF_FORMAT_RFC); - if (ret != 0) return ret; - - return 0; } From ea37bb96422afffaadd68bdbdfee3977efbd5cf0 Mon Sep 17 00:00:00 2001 From: Naresh Nayak Date: Wed, 4 Sep 2024 09:10:10 +0000 Subject: [PATCH 31/33] Return and set using enum types for get/set APIs. Signed-off-by: Naresh Nayak --- include/avtp/Rvf.h | 18 ++++++++-------- include/avtp/aaf/Pcm.h | 12 +++++------ include/avtp/acf/AcfCommon.h | 6 +++--- include/avtp/cvf/Cvf.h | 10 ++++----- src/avtp/Rvf.c | 18 ++++++++-------- src/avtp/Udp.c | 4 ++-- src/avtp/aaf/Pcm.c | 42 ++++++++++++++++++------------------ src/avtp/acf/AcfCommon.c | 8 +++---- src/avtp/acf/Ntscf.c | 8 +++---- src/avtp/acf/SensorBrief.c | 16 +++++++------- src/avtp/cvf/Cvf.c | 10 ++++----- 11 files changed, 76 insertions(+), 76 deletions(-) diff --git a/include/avtp/Rvf.h b/include/avtp/Rvf.h index 4e6c7b8..76250a5 100644 --- a/include/avtp/Rvf.h +++ b/include/avtp/Rvf.h @@ -12,7 +12,7 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of Fastree3D, COVESA nor the names of their - * contributors may be used to endorse or promote products derived from + * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" @@ -162,10 +162,10 @@ uint8_t Avtp_Rvf_GetEf(Avtp_Rvf_t* pdu); uint8_t Avtp_Rvf_GetEvt(Avtp_Rvf_t* pdu); uint8_t Avtp_Rvf_GetPd(Avtp_Rvf_t* pdu); uint8_t Avtp_Rvf_GetI(Avtp_Rvf_t* pdu); -uint8_t Avtp_Rvf_GetPixelDepth(Avtp_Rvf_t* pdu); -uint8_t Avtp_Rvf_GetPixelFormat(Avtp_Rvf_t* pdu); -uint8_t Avtp_Rvf_GetFrameRate(Avtp_Rvf_t* pdu); -uint8_t Avtp_Rvf_GetColorspace(Avtp_Rvf_t* pdu); +Avtp_RvfPixelDepth_t Avtp_Rvf_GetPixelDepth(Avtp_Rvf_t* pdu); +Avtp_RvfPixelFormat_t Avtp_Rvf_GetPixelFormat(Avtp_Rvf_t* pdu); +Avtp_RvfFrameRate_t Avtp_Rvf_GetFrameRate(Avtp_Rvf_t* pdu); +Avtp_RvfColorspace_t Avtp_Rvf_GetColorspace(Avtp_Rvf_t* pdu); uint8_t Avtp_Rvf_GetNumLines(Avtp_Rvf_t* pdu); uint8_t Avtp_Rvf_GetISeqNum(Avtp_Rvf_t* pdu); uint16_t Avtp_Rvf_GetLineNumber(Avtp_Rvf_t* pdu); @@ -190,10 +190,10 @@ void Avtp_Rvf_SetEf(Avtp_Rvf_t* pdu, uint8_t value); void Avtp_Rvf_SetEvt(Avtp_Rvf_t* pdu, uint8_t value); void Avtp_Rvf_SetPd(Avtp_Rvf_t* pdu, uint8_t value); void Avtp_Rvf_SetI(Avtp_Rvf_t* pdu, uint8_t value); -void Avtp_Rvf_SetPixelDepth(Avtp_Rvf_t* pdu, uint8_t value); -void Avtp_Rvf_SetPixelFormat(Avtp_Rvf_t* pdu, uint8_t value); -void Avtp_Rvf_SetFrameRate(Avtp_Rvf_t* pdu, uint8_t value); -void Avtp_Rvf_SetColorspace(Avtp_Rvf_t* pdu, uint8_t value); +void Avtp_Rvf_SetPixelDepth(Avtp_Rvf_t* pdu, Avtp_RvfPixelDepth_t value); +void Avtp_Rvf_SetPixelFormat(Avtp_Rvf_t* pdu, Avtp_RvfPixelFormat_t value); +void Avtp_Rvf_SetFrameRate(Avtp_Rvf_t* pdu, Avtp_RvfFrameRate_t value); +void Avtp_Rvf_SetColorspace(Avtp_Rvf_t* pdu, Avtp_RvfColorspace_t value); void Avtp_Rvf_SetNumLines(Avtp_Rvf_t* pdu, uint8_t value); void Avtp_Rvf_SetISeqNum(Avtp_Rvf_t* pdu, uint8_t value); void Avtp_Rvf_SetLineNumber(Avtp_Rvf_t* pdu, uint16_t value); diff --git a/include/avtp/aaf/Pcm.h b/include/avtp/aaf/Pcm.h index 4b51a22..f7e054c 100644 --- a/include/avtp/aaf/Pcm.h +++ b/include/avtp/aaf/Pcm.h @@ -118,12 +118,12 @@ uint8_t Avtp_Pcm_GetSequenceNum(Avtp_Pcm_t* pdu); uint8_t Avtp_Pcm_GetTu(Avtp_Pcm_t* pdu); uint64_t Avtp_Pcm_GetStreamId(Avtp_Pcm_t* pdu); uint32_t Avtp_Pcm_GetAvtpTimestamp(Avtp_Pcm_t* pdu); -uint8_t Avtp_Pcm_GetFormat(Avtp_Pcm_t* pdu); -uint8_t Avtp_Pcm_GetNsr(Avtp_Pcm_t* pdu); +Avtp_AafFormat_t Avtp_Pcm_GetFormat(Avtp_Pcm_t* pdu); +Avtp_AafNsr_t Avtp_Pcm_GetNsr(Avtp_Pcm_t* pdu); uint16_t Avtp_Pcm_GetChannelsPerFrame(Avtp_Pcm_t* pdu); uint8_t Avtp_Pcm_GetBitDepth(Avtp_Pcm_t* pdu); uint16_t Avtp_Pcm_GetStreamDataLength(Avtp_Pcm_t* pdu); -uint8_t Avtp_Pcm_GetSp(Avtp_Pcm_t* pdu); +Avtp_AafSp_t Avtp_Pcm_GetSp(Avtp_Pcm_t* pdu); uint8_t Avtp_Pcm_GetEvt(Avtp_Pcm_t* pdu); /** @@ -146,12 +146,12 @@ void Avtp_Pcm_SetSequenceNum(Avtp_Pcm_t* pdu, uint8_t value); void Avtp_Pcm_SetTu(Avtp_Pcm_t* pdu, uint8_t value); void Avtp_Pcm_SetStreamId(Avtp_Pcm_t* pdu, uint64_t value); void Avtp_Pcm_SetAvtpTimestamp(Avtp_Pcm_t* pdu, uint32_t value); -void Avtp_Pcm_SetFormat(Avtp_Pcm_t* pdu, uint8_t value); -void Avtp_Pcm_SetNsr(Avtp_Pcm_t* pdu, uint8_t value); +void Avtp_Pcm_SetFormat(Avtp_Pcm_t* pdu, Avtp_AafFormat_t value); +void Avtp_Pcm_SetNsr(Avtp_Pcm_t* pdu, Avtp_AafNsr_t value); void Avtp_Pcm_SetChannelsPerFrame(Avtp_Pcm_t* pdu, uint16_t value); void Avtp_Pcm_SetBitDepth(Avtp_Pcm_t* pdu, uint8_t value); void Avtp_Pcm_SetStreamDataLength(Avtp_Pcm_t* pdu, uint16_t value); -void Avtp_Pcm_SetSp(Avtp_Pcm_t* pdu, uint8_t value); +void Avtp_Pcm_SetSp(Avtp_Pcm_t* pdu, Avtp_AafSp_t value); void Avtp_Pcm_SetEvt(Avtp_Pcm_t* pdu, uint8_t value); /****************************************************************************** diff --git a/include/avtp/acf/AcfCommon.h b/include/avtp/acf/AcfCommon.h index 2733c8a..c690dac 100644 --- a/include/avtp/acf/AcfCommon.h +++ b/include/avtp/acf/AcfCommon.h @@ -9,7 +9,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of COVESA nor the names of its contributors may be + * * Neither the name of COVESA nor the names of its contributors may be * used to endorse or promote products derived from this software without * specific prior written permission. * @@ -83,7 +83,7 @@ typedef enum { */ uint64_t Avtp_AcfCommon_GetField(Avtp_AcfCommon_t* pdu, Avtp_AcfCommonFields_t field); -uint8_t Avtp_AcfCommon_GetAcfMsgType(Avtp_AcfCommon_t* pdu); +Avtp_AcfMsgType_t Avtp_AcfCommon_GetAcfMsgType(Avtp_AcfCommon_t* pdu); uint16_t Avtp_AcfCommon_GetAcfMsgLength(Avtp_AcfCommon_t* pdu); /** @@ -95,5 +95,5 @@ uint16_t Avtp_AcfCommon_GetAcfMsgLength(Avtp_AcfCommon_t* pdu); */ void Avtp_AcfCommon_SetField(Avtp_AcfCommon_t* pdu, Avtp_AcfCommonFields_t field, uint64_t value); -void Avtp_AcfCommon_SetAcfMsgType(Avtp_AcfCommon_t* pdu, uint8_t value); +void Avtp_AcfCommon_SetAcfMsgType(Avtp_AcfCommon_t* pdu, Avtp_AcfMsgType_t value); void Avtp_AcfCommon_SetAcfMsgLength(Avtp_AcfCommon_t* pdu, uint16_t value); diff --git a/include/avtp/cvf/Cvf.h b/include/avtp/cvf/Cvf.h index 6ff0ff2..d6ecec8 100644 --- a/include/avtp/cvf/Cvf.h +++ b/include/avtp/cvf/Cvf.h @@ -10,7 +10,7 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of COVESA, Intel Corporation nor the names of its - * contributors may be used to endorse or promote products derived from + * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" @@ -89,8 +89,8 @@ uint8_t Avtp_Cvf_GetSequenceNum(Avtp_Cvf_t* pdu); uint8_t Avtp_Cvf_GetTu(Avtp_Cvf_t* pdu); uint64_t Avtp_Cvf_GetStreamId(Avtp_Cvf_t* pdu); uint32_t Avtp_Cvf_GetAvtpTimestamp(Avtp_Cvf_t* pdu); -uint8_t Avtp_Cvf_GetFormat(Avtp_Cvf_t* pdu); -uint8_t Avtp_Cvf_GetFormatSubtype(Avtp_Cvf_t* pdu); +Avtp_CvfFormat_t Avtp_Cvf_GetFormat(Avtp_Cvf_t* pdu); +Avtp_CvfFormatSubtype_t Avtp_Cvf_GetFormatSubtype(Avtp_Cvf_t* pdu); uint16_t Avtp_Cvf_GetStreamDataLength(Avtp_Cvf_t* pdu); uint8_t Avtp_Cvf_GetPtv(Avtp_Cvf_t* pdu); uint8_t Avtp_Cvf_GetM(Avtp_Cvf_t* pdu); @@ -107,8 +107,8 @@ void Avtp_Cvf_SetSequenceNum(Avtp_Cvf_t* pdu, uint8_t value); void Avtp_Cvf_SetTu(Avtp_Cvf_t* pdu, uint8_t value); void Avtp_Cvf_SetStreamId(Avtp_Cvf_t* pdu, uint64_t value); void Avtp_Cvf_SetAvtpTimestamp(Avtp_Cvf_t* pdu, uint32_t value); -void Avtp_Cvf_SetFormat(Avtp_Cvf_t* pdu, uint8_t value); -void Avtp_Cvf_SetFormatSubtype(Avtp_Cvf_t* pdu, uint8_t value); +void Avtp_Cvf_SetFormat(Avtp_Cvf_t* pdu, Avtp_CvfFormat_t value); +void Avtp_Cvf_SetFormatSubtype(Avtp_Cvf_t* pdu, Avtp_CvfFormatSubtype_t value); void Avtp_Cvf_SetStreamDataLength(Avtp_Cvf_t* pdu, uint16_t value); void Avtp_Cvf_SetPtv(Avtp_Cvf_t* pdu, uint8_t value); void Avtp_Cvf_SetM(Avtp_Cvf_t* pdu, uint8_t value); diff --git a/src/avtp/Rvf.c b/src/avtp/Rvf.c index e2fd97e..44a589e 100644 --- a/src/avtp/Rvf.c +++ b/src/avtp/Rvf.c @@ -12,7 +12,7 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of Fastree3D, COVESA nor the names of their - * contributors may be used to endorse or promote products derived from + * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" @@ -184,22 +184,22 @@ uint8_t Avtp_Rvf_GetI(Avtp_Rvf_t* pdu) return GET_FIELD(AVTP_RVF_FIELD_I); } -uint8_t Avtp_Rvf_GetPixelDepth(Avtp_Rvf_t* pdu) +Avtp_RvfPixelDepth_t Avtp_Rvf_GetPixelDepth(Avtp_Rvf_t* pdu) { return GET_FIELD(AVTP_RVF_FIELD_PIXEL_DEPTH); } -uint8_t Avtp_Rvf_GetPixelFormat(Avtp_Rvf_t* pdu) +Avtp_RvfPixelFormat_t Avtp_Rvf_GetPixelFormat(Avtp_Rvf_t* pdu) { return GET_FIELD(AVTP_RVF_FIELD_PIXEL_FORMAT); } -uint8_t Avtp_Rvf_GetFrameRate(Avtp_Rvf_t* pdu) +Avtp_RvfFrameRate_t Avtp_Rvf_GetFrameRate(Avtp_Rvf_t* pdu) { return GET_FIELD(AVTP_RVF_FIELD_FRAME_RATE); } -uint8_t Avtp_Rvf_GetColorspace(Avtp_Rvf_t* pdu) +Avtp_RvfColorspace_t Avtp_Rvf_GetColorspace(Avtp_Rvf_t* pdu) { return GET_FIELD(AVTP_RVF_FIELD_COLORSPACE); } @@ -314,22 +314,22 @@ void Avtp_Rvf_SetI(Avtp_Rvf_t* pdu, uint8_t value) SET_FIELD(AVTP_RVF_FIELD_I, value); } -void Avtp_Rvf_SetPixelDepth(Avtp_Rvf_t* pdu, uint8_t value) +void Avtp_Rvf_SetPixelDepth(Avtp_Rvf_t* pdu, Avtp_RvfPixelDepth_t value) { SET_FIELD(AVTP_RVF_FIELD_PIXEL_DEPTH, value); } -void Avtp_Rvf_SetPixelFormat(Avtp_Rvf_t* pdu, uint8_t value) +void Avtp_Rvf_SetPixelFormat(Avtp_Rvf_t* pdu, Avtp_RvfPixelFormat_t value) { SET_FIELD(AVTP_RVF_FIELD_PIXEL_FORMAT, value); } -void Avtp_Rvf_SetFrameRate(Avtp_Rvf_t* pdu, uint8_t value) +void Avtp_Rvf_SetFrameRate(Avtp_Rvf_t* pdu, Avtp_RvfFrameRate_t value) { SET_FIELD(AVTP_RVF_FIELD_FRAME_RATE, value); } -void Avtp_Rvf_SetColorspace(Avtp_Rvf_t* pdu, uint8_t value) +void Avtp_Rvf_SetColorspace(Avtp_Rvf_t* pdu, Avtp_RvfColorspace_t value) { SET_FIELD(AVTP_RVF_FIELD_COLORSPACE, value); } diff --git a/src/avtp/Udp.c b/src/avtp/Udp.c index cf1f583..b7b76d3 100644 --- a/src/avtp/Udp.c +++ b/src/avtp/Udp.c @@ -9,7 +9,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of COVESA nor the names of its contributors may be + * * Neither the name of COVESA nor the names of its contributors may be * used to endorse or promote products derived from this software without * specific prior written permission. * @@ -30,7 +30,7 @@ #include #include #include "avtp/Udp.h" -#include "avtp/Utils.h" +#include "avtp/Utils.h" #include "avtp/Defines.h" #define GET_FIELD(field) \ diff --git a/src/avtp/aaf/Pcm.c b/src/avtp/aaf/Pcm.c index 8979d39..8ca9292 100644 --- a/src/avtp/aaf/Pcm.c +++ b/src/avtp/aaf/Pcm.c @@ -11,7 +11,7 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of COVESA, Intel Corporation nor the names of its - * contributors may be used to endorse or promote products derived from + * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" @@ -43,21 +43,21 @@ static const Avtp_FieldDescriptor_t Avtp_PcmFieldDesc[AVTP_PCM_FIELD_MAX] = { [AVTP_PCM_FIELD_SUBTYPE] = { .quadlet = 0, .offset = 0, .bits = 8 }, - [AVTP_PCM_FIELD_SV] = { .quadlet = 0, .offset = 8, .bits = 1 }, - [AVTP_PCM_FIELD_VERSION] = { .quadlet = 0, .offset = 9, .bits = 3 }, - [AVTP_PCM_FIELD_MR] = { .quadlet = 0, .offset = 12, .bits = 1 }, - [AVTP_PCM_FIELD_TV] = { .quadlet = 0, .offset = 15, .bits = 1 }, + [AVTP_PCM_FIELD_SV] = { .quadlet = 0, .offset = 8, .bits = 1 }, + [AVTP_PCM_FIELD_VERSION] = { .quadlet = 0, .offset = 9, .bits = 3 }, + [AVTP_PCM_FIELD_MR] = { .quadlet = 0, .offset = 12, .bits = 1 }, + [AVTP_PCM_FIELD_TV] = { .quadlet = 0, .offset = 15, .bits = 1 }, [AVTP_PCM_FIELD_SEQUENCE_NUM] = { .quadlet = 0, .offset = 16, .bits = 8 }, - [AVTP_PCM_FIELD_TU] = { .quadlet = 0, .offset = 31, .bits = 1 }, - [AVTP_PCM_FIELD_STREAM_ID] = { .quadlet = 1, .offset = 0, .bits = 64 }, - [AVTP_PCM_FIELD_AVTP_TIMESTAMP] = { .quadlet = 3, .offset = 0, .bits = 32 }, - [AVTP_PCM_FIELD_FORMAT] = { .quadlet = 4, .offset = 0, .bits = 8 }, - [AVTP_PCM_FIELD_NSR] = { .quadlet = 4, .offset = 8, .bits = 4 }, - [AVTP_PCM_FIELD_CHANNELS_PER_FRAME] = { .quadlet = 4, .offset = 14, .bits = 10 }, - [AVTP_PCM_FIELD_BIT_DEPTH] = { .quadlet = 4, .offset = 24, .bits = 8 }, - [AVTP_PCM_FIELD_STREAM_DATA_LENGTH] = { .quadlet = 5, .offset = 0, .bits = 16 }, - [AVTP_PCM_FIELD_SP] = { .quadlet = 5, .offset = 19, .bits = 1 }, - [AVTP_PCM_FIELD_EVT] = { .quadlet = 5, .offset = 20, .bits = 4 }, + [AVTP_PCM_FIELD_TU] = { .quadlet = 0, .offset = 31, .bits = 1 }, + [AVTP_PCM_FIELD_STREAM_ID] = { .quadlet = 1, .offset = 0, .bits = 64 }, + [AVTP_PCM_FIELD_AVTP_TIMESTAMP] = { .quadlet = 3, .offset = 0, .bits = 32 }, + [AVTP_PCM_FIELD_FORMAT] = { .quadlet = 4, .offset = 0, .bits = 8 }, + [AVTP_PCM_FIELD_NSR] = { .quadlet = 4, .offset = 8, .bits = 4 }, + [AVTP_PCM_FIELD_CHANNELS_PER_FRAME] = { .quadlet = 4, .offset = 14, .bits = 10 }, + [AVTP_PCM_FIELD_BIT_DEPTH] = { .quadlet = 4, .offset = 24, .bits = 8 }, + [AVTP_PCM_FIELD_STREAM_DATA_LENGTH] = { .quadlet = 5, .offset = 0, .bits = 16 }, + [AVTP_PCM_FIELD_SP] = { .quadlet = 5, .offset = 19, .bits = 1 }, + [AVTP_PCM_FIELD_EVT] = { .quadlet = 5, .offset = 20, .bits = 4 }, }; void Avtp_Pcm_Init(Avtp_Pcm_t* pdu) @@ -119,12 +119,12 @@ uint32_t Avtp_Pcm_GetAvtpTimestamp(Avtp_Pcm_t* pdu) return GET_FIELD(AVTP_PCM_FIELD_AVTP_TIMESTAMP); } -uint8_t Avtp_Pcm_GetFormat(Avtp_Pcm_t* pdu) +Avtp_AafFormat_t Avtp_Pcm_GetFormat(Avtp_Pcm_t* pdu) { return GET_FIELD(AVTP_PCM_FIELD_FORMAT); } -uint8_t Avtp_Pcm_GetNsr(Avtp_Pcm_t* pdu) +Avtp_AafNsr_t Avtp_Pcm_GetNsr(Avtp_Pcm_t* pdu) { return GET_FIELD(AVTP_PCM_FIELD_NSR); } @@ -144,7 +144,7 @@ uint16_t Avtp_Pcm_GetStreamDataLength(Avtp_Pcm_t* pdu) return GET_FIELD(AVTP_PCM_FIELD_STREAM_DATA_LENGTH); } -uint8_t Avtp_Pcm_GetSp(Avtp_Pcm_t* pdu) +Avtp_AafSp_t Avtp_Pcm_GetSp(Avtp_Pcm_t* pdu) { return GET_FIELD(AVTP_PCM_FIELD_SP); } @@ -204,12 +204,12 @@ void Avtp_Pcm_SetAvtpTimestamp(Avtp_Pcm_t* pdu, uint32_t value) SET_FIELD(AVTP_PCM_FIELD_AVTP_TIMESTAMP, value); } -void Avtp_Pcm_SetFormat(Avtp_Pcm_t* pdu, uint8_t value) +void Avtp_Pcm_SetFormat(Avtp_Pcm_t* pdu, Avtp_AafFormat_t value) { SET_FIELD(AVTP_PCM_FIELD_FORMAT, value); } -void Avtp_Pcm_SetNsr(Avtp_Pcm_t* pdu, uint8_t value) +void Avtp_Pcm_SetNsr(Avtp_Pcm_t* pdu, Avtp_AafNsr_t value) { SET_FIELD(AVTP_PCM_FIELD_NSR, value); } @@ -229,7 +229,7 @@ void Avtp_Pcm_SetStreamDataLength(Avtp_Pcm_t* pdu, uint16_t value) SET_FIELD(AVTP_PCM_FIELD_STREAM_DATA_LENGTH, value); } -void Avtp_Pcm_SetSp(Avtp_Pcm_t* pdu, uint8_t value) +void Avtp_Pcm_SetSp(Avtp_Pcm_t* pdu, Avtp_AafSp_t value) { SET_FIELD(AVTP_PCM_FIELD_SP, value); } diff --git a/src/avtp/acf/AcfCommon.c b/src/avtp/acf/AcfCommon.c index 81e84b4..0b6976c 100644 --- a/src/avtp/acf/AcfCommon.c +++ b/src/avtp/acf/AcfCommon.c @@ -9,7 +9,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of COVESA nor the names of its contributors may be + * * Neither the name of COVESA nor the names of its contributors may be * used to endorse or promote products derived from this software without * specific prior written permission. * @@ -31,7 +31,7 @@ #include #include "avtp/acf/AcfCommon.h" -#include "avtp/Utils.h" +#include "avtp/Utils.h" #include "avtp/Defines.h" #define GET_FIELD(field) \ @@ -54,7 +54,7 @@ uint64_t Avtp_AcfCommon_GetField(Avtp_AcfCommon_t* pdu, Avtp_AcfCommonFields_t f return GET_FIELD(field); } -uint8_t Avtp_AcfCommon_GetAcfMsgType(Avtp_AcfCommon_t* pdu) +Avtp_AcfMsgType_t Avtp_AcfCommon_GetAcfMsgType(Avtp_AcfCommon_t* pdu) { return GET_FIELD(AVTP_ACF_FIELD_ACF_MSG_TYPE); } @@ -69,7 +69,7 @@ void Avtp_AcfCommon_SetField(Avtp_AcfCommon_t* pdu, Avtp_AcfCommonFields_t field SET_FIELD(field, value); } -void Avtp_AcfCommon_SetAcfMsgType(Avtp_AcfCommon_t* pdu, uint8_t value) +void Avtp_AcfCommon_SetAcfMsgType(Avtp_AcfCommon_t* pdu, Avtp_AcfMsgType_t value) { SET_FIELD(AVTP_ACF_FIELD_ACF_MSG_TYPE, value); } diff --git a/src/avtp/acf/Ntscf.c b/src/avtp/acf/Ntscf.c index de20291..48abffd 100644 --- a/src/avtp/acf/Ntscf.c +++ b/src/avtp/acf/Ntscf.c @@ -9,7 +9,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of COVESA nor the names of its contributors may be + * * Neither the name of COVESA nor the names of its contributors may be * used to endorse or promote products derived from this software without * specific prior written permission. * @@ -31,7 +31,7 @@ #include #include "avtp/acf/Ntscf.h" -#include "avtp/Utils.h" +#include "avtp/Utils.h" #include "avtp/Defines.h" #include "avtp/CommonHeader.h" @@ -44,12 +44,12 @@ * This table maps all IEEE 1722 NTSCF-specific header fields to a descriptor. */ static const Avtp_FieldDescriptor_t Avtp_NtscfFieldDesc[AVTP_NTSCF_FIELD_MAX] = -{ +{ /* Common AVTP header */ [AVTP_NTSCF_FIELD_SUBTYPE] = { .quadlet = 0, .offset = 0, .bits = 8 }, [AVTP_NTSCF_FIELD_SV] = { .quadlet = 0, .offset = 8, .bits = 1 }, [AVTP_NTSCF_FIELD_VERSION] = { .quadlet = 0, .offset = 9, .bits = 3 }, - /* NTSCF header */ + /* NTSCF header */ [AVTP_NTSCF_FIELD_NTSCF_DATA_LENGTH] = { .quadlet = 0, .offset = 13, .bits = 11 }, [AVTP_NTSCF_FIELD_SEQUENCE_NUM] = { .quadlet = 0, .offset = 24, .bits = 8 }, [AVTP_NTSCF_FIELD_STREAM_ID] = { .quadlet = 1, .offset = 0, .bits = 64 }, diff --git a/src/avtp/acf/SensorBrief.c b/src/avtp/acf/SensorBrief.c index d19e8d9..3afa7fc 100644 --- a/src/avtp/acf/SensorBrief.c +++ b/src/avtp/acf/SensorBrief.c @@ -9,7 +9,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of COVESA nor the names of its contributors may be + * * Neither the name of COVESA nor the names of its contributors may be * used to endorse or promote products derived from this software without * specific prior written permission. * @@ -31,7 +31,7 @@ #include #include "avtp/acf/SensorBrief.h" -#include "avtp/Utils.h" +#include "avtp/Utils.h" #include "avtp/Defines.h" #define GET_FIELD(field) \ @@ -47,25 +47,25 @@ static const Avtp_FieldDescriptor_t Avtp_SensorBriefFieldDesc[AVTP_SENSOR_FIELD_ /* ACF common header fields */ [AVTP_SENSOR_BRIEF_FIELD_ACF_MSG_TYPE] = { .quadlet = 0, .offset = 0, .bits = 7 }, - [AVTP_SENSOR_BRIEF_FIELD_ACF_MSG_LENGTH] = { .quadlet = 0, .offset = 7, .bits = 9 }, + [AVTP_SENSOR_BRIEF_FIELD_ACF_MSG_LENGTH] = { .quadlet = 0, .offset = 7, .bits = 9 }, - /* ACF Abbreviated Sensor header fields */ + /* ACF Abbreviated Sensor header fields */ [AVTP_SENSOR_BRIEF_FIELD_MTV] = { .quadlet = 0, .offset = 16, .bits = 1 }, [AVTP_SENSOR_BRIEF_FIELD_NUM_SENSOR] = { .quadlet = 0, .offset = 17, .bits = 7 }, [AVTP_SENSOR_BRIEF_FIELD_SZ] = { .quadlet = 0, .offset = 24, .bits = 2 }, - [AVTP_SENSOR_BRIEF_FIELD_SENSOR_GROUP] = { .quadlet = 0, .offset = 26, .bits = 6 }, + [AVTP_SENSOR_BRIEF_FIELD_SENSOR_GROUP] = { .quadlet = 0, .offset = 26, .bits = 6 }, }; void Avtp_SensorBrief_Init(Avtp_SensorBrief_t* pdu) { if(pdu != NULL) { - memset(pdu, 0, sizeof(Avtp_SensorBrief_t)); + memset(pdu, 0, sizeof(Avtp_SensorBrief_t)); Avtp_SensorBrief_SetField(pdu, AVTP_SENSOR_BRIEF_FIELD_ACF_MSG_TYPE, AVTP_ACF_TYPE_SENSOR_BRIEF); } } uint64_t Avtp_SensorBrief_GetField(Avtp_SensorBrief_t* pdu, Avtp_SensorBriefFields_t field) -{ +{ return GET_FIELD(field); } @@ -100,7 +100,7 @@ uint8_t Avtp_SensorBrief_GetSensorGroup(Avtp_SensorBrief_t* pdu) } void Avtp_SensorBrief_SetField(Avtp_SensorBrief_t* pdu, Avtp_SensorBriefFields_t field, uint64_t value) -{ +{ SET_FIELD(field, value); } diff --git a/src/avtp/cvf/Cvf.c b/src/avtp/cvf/Cvf.c index e205336..b1a301c 100644 --- a/src/avtp/cvf/Cvf.c +++ b/src/avtp/cvf/Cvf.c @@ -10,7 +10,7 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of COVESA, Intel Corporation nor the names of its - * contributors may be used to endorse or promote products derived from + * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" @@ -123,12 +123,12 @@ uint32_t Avtp_Cvf_GetAvtpTimestamp(Avtp_Cvf_t* pdu) return GET_FIELD(AVTP_CVF_FIELD_AVTP_TIMESTAMP); } -uint8_t Avtp_Cvf_GetFormat(Avtp_Cvf_t* pdu) +Avtp_CvfFormat_t Avtp_Cvf_GetFormat(Avtp_Cvf_t* pdu) { return GET_FIELD(AVTP_CVF_FIELD_FORMAT); } -uint8_t Avtp_Cvf_GetFormatSubtype(Avtp_Cvf_t* pdu) +Avtp_CvfFormatSubtype_t Avtp_Cvf_GetFormatSubtype(Avtp_Cvf_t* pdu) { return GET_FIELD(AVTP_CVF_FIELD_FORMAT_SUBTYPE); } @@ -203,12 +203,12 @@ void Avtp_Cvf_SetAvtpTimestamp(Avtp_Cvf_t* pdu, uint32_t value) SET_FIELD(AVTP_CVF_FIELD_AVTP_TIMESTAMP, value); } -void Avtp_Cvf_SetFormat(Avtp_Cvf_t* pdu, uint8_t value) +void Avtp_Cvf_SetFormat(Avtp_Cvf_t* pdu, Avtp_CvfFormat_t value) { SET_FIELD(AVTP_CVF_FIELD_FORMAT, value); } -void Avtp_Cvf_SetFormatSubtype(Avtp_Cvf_t* pdu, uint8_t value) +void Avtp_Cvf_SetFormatSubtype(Avtp_Cvf_t* pdu, Avtp_CvfFormatSubtype_t value) { SET_FIELD(AVTP_CVF_FIELD_FORMAT_SUBTYPE, value); } From 9561ae263e4a7ae36cb98fdaed4899dc2e64e111 Mon Sep 17 00:00:00 2001 From: Naresh Nayak Date: Wed, 4 Sep 2024 09:11:28 +0000 Subject: [PATCH 32/33] Reworked CAN SetPayload/GetPayload APIs. Signed-off-by: Naresh Nayak --- examples/acf-can/acf-can-listener.c | 16 ++++++----- examples/acf-can/acf-can-talker.c | 6 ++-- include/avtp/acf/Can.h | 41 ++++++++++++++++++--------- src/avtp/acf/Can.c | 44 ++++++++++++++--------------- unit/test-can.c | 12 ++++---- 5 files changed, 67 insertions(+), 52 deletions(-) diff --git a/examples/acf-can/acf-can-listener.c b/examples/acf-can/acf-can-listener.c index 8576089..39eec59 100644 --- a/examples/acf-can/acf-can-listener.c +++ b/examples/acf-can/acf-can-listener.c @@ -174,7 +174,7 @@ static int new_packet(int sk_fd, int can_socket) { int res = 0; uint64_t proc_bytes = 0, msg_proc_bytes = 0; uint32_t udp_seq_num; - uint16_t msg_length, payload_length, pdu_length; + uint16_t msg_length, can_payload_length, acf_msg_length; uint8_t subtype; uint8_t pdu[MAX_PDU_SIZE], i; uint8_t *cf_pdu, *acf_pdu, *udp_pdu, *can_payload; @@ -224,8 +224,10 @@ static int new_packet(int sk_fd, int can_socket) { can_id = Avtp_Can_GetCanIdentifier((Avtp_Can_t*)acf_pdu); - can_payload = Avtp_Can_GetPayload((Avtp_Can_t*)acf_pdu, &payload_length, &pdu_length); - msg_proc_bytes += pdu_length*4; + can_payload = Avtp_Can_GetPayload((Avtp_Can_t*)acf_pdu); + acf_msg_length = Avtp_Can_GetAcfMsgLength((Avtp_Can_t*)acf_pdu)*4; + can_payload_length = Avtp_Can_GetCanPayloadLength((Avtp_Can_t*)acf_pdu); + msg_proc_bytes += acf_msg_length; // Handle EFF Flag if (Avtp_Can_GetEff((Avtp_Can_t*)acf_pdu)) { @@ -251,13 +253,13 @@ static int new_packet(int sk_fd, int can_socket) { frame.fd.flags |= CANFD_ESI; } frame.fd.can_id = can_id; - frame.fd.len = payload_length; - memcpy(frame.fd.data, can_payload, payload_length); + frame.fd.len = can_payload_length; + memcpy(frame.fd.data, can_payload, can_payload_length); res = write(can_socket, &frame.fd, sizeof(struct canfd_frame)); } else { frame.cc.can_id = can_id; - frame.cc.len = payload_length; - memcpy(frame.cc.data, can_payload, payload_length); + frame.cc.len = can_payload_length; + memcpy(frame.cc.data, can_payload, can_payload_length); res = write(can_socket, &frame.cc, sizeof(struct can_frame)); } diff --git a/examples/acf-can/acf-can-talker.c b/examples/acf-can/acf-can-talker.c index b6e17f4..ea1e028 100644 --- a/examples/acf-can/acf-can-talker.c +++ b/examples/acf-can/acf-can-talker.c @@ -228,13 +228,13 @@ static int prepare_acf_packet(uint8_t* acf_pdu, // Copy payload to ACF CAN PDU if(can_variant == AVTP_CAN_FD) - processedBytes = Avtp_Can_SetPayload(pdu, frame.fd.can_id & CAN_EFF_MASK, frame.fd.data, + Avtp_Can_CreateAcfMessage(pdu, frame.fd.can_id & CAN_EFF_MASK, frame.fd.data, frame.fd.len, can_variant); else - processedBytes = Avtp_Can_SetPayload(pdu, frame.cc.can_id & CAN_EFF_MASK, frame.cc.data, + Avtp_Can_CreateAcfMessage(pdu, frame.cc.can_id & CAN_EFF_MASK, frame.cc.data, frame.cc.len, can_variant); - return processedBytes; + return Avtp_Can_GetAcfMsgLength(pdu)*4; } int main(int argc, char *argv[]) diff --git a/include/avtp/acf/Can.h b/include/avtp/acf/Can.h index 7f7d6af..91b7763 100644 --- a/include/avtp/acf/Can.h +++ b/include/avtp/acf/Can.h @@ -9,7 +9,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of COVESA nor the names of its contributors may be + * * Neither the name of COVESA nor the names of its contributors may be * used to endorse or promote products derived from this software without * specific prior written permission. * @@ -68,7 +68,7 @@ typedef enum { AVTP_CAN_FIELD_ESI, AVTP_CAN_FIELD_CAN_BUS_ID, AVTP_CAN_FIELD_MESSAGE_TIMESTAMP, - AVTP_CAN_FIELD_CAN_IDENTIFIER, + AVTP_CAN_FIELD_CAN_IDENTIFIER, /* Count number of fields for bound checks */ AVTP_CAN_FIELD_MAX @@ -126,36 +126,51 @@ void Avtp_Can_SetMessageTimestamp(Avtp_Can_t* pdu, uint64_t value); void Avtp_Can_SetCanIdentifier(Avtp_Can_t* pdu, uint32_t value); /** - * Copies the payload data into the ACF CAN frame. This function will also set the - * length and pad fields while inserting the padded bytes. + * Copies the payload data and CAN frame ID into the ACF CAN frame. This function will + * also set the length and pad fields while inserting the padded bytes. * * @param can_pdu Pointer to the first bit of an 1722 ACF CAN PDU. * @param frame_id ID of the CAN frame * @param payload Pointer to the payload byte array * @param payload_length Length of the payload. * @param can_variant Classic CAN or CAN-FD - * @returns Returns number of processed bytes (header + payload + padding) */ -int Avtp_Can_SetPayload(Avtp_Can_t* can_pdu, uint32_t frame_id , uint8_t* payload, +void Avtp_Can_CreateAcfMessage(Avtp_Can_t* can_pdu, uint32_t frame_id, uint8_t* payload, uint16_t payload_length, Avtp_CanVariant_t can_variant); /** * Returns pointer to payload of an ACF CAN frame. * * @param can_pdu Pointer to the first bit of an 1722 ACF CAN PDU. - * @param payload_length payload length set by the function (if not NULL) - * @param pdu_length total pdu length set by the function (if not NULL) * @return Pointer to ACF CAN frame payload */ -uint8_t* Avtp_Can_GetPayload(Avtp_Can_t* can_pdu, uint16_t* payload_length, uint16_t *pdu_length); +uint8_t* Avtp_Can_GetPayload(Avtp_Can_t* can_pdu); + +/** + * Sets the CAN payload in an ACF CAN frame. + * + * @param can_pdu Pointer to the first bit of an 1722 ACF CAN PDU. + * @param payload Pointer to the payload byte array + * @param payload_length Length of the payload + */ +void Avtp_Can_SetPayload(Avtp_Can_t* can_pdu, uint8_t* payload, + uint16_t payload_length); /** * Finalizes the ACF CAN frame. This function will set the - * length and pad fields while inserting the padded bytes. + * length and pad fields while inserting the padded bytes. * * @param can_pdu Pointer to the first bit of an 1722 ACF CAN PDU. * @param payload Pointer to the payload byte array - * @param payload_length Length of the payload. - * @returns Returns number of processed bytes (header + payload + padding) + * @param payload_length Length of the CAN frame payload. + */ +void Avtp_Can_Finalize(Avtp_Can_t* can_pdu, uint16_t payload_length); + +/** + * Returns the length of the CAN payload without the padding bytes and the + * header length of the encapsulating ACF Frame. + * + * @param pdu Pointer to the first bit of an 1722 ACF CAN PDU. + * @return Length of CAN payload in bytes */ -int Avtp_Can_Finalize(Avtp_Can_t* can_pdu, uint16_t payload_length); +uint8_t Avtp_Can_GetCanPayloadLength(Avtp_Can_t* pdu); diff --git a/src/avtp/acf/Can.c b/src/avtp/acf/Can.c index 8754b95..2c22de7 100644 --- a/src/avtp/acf/Can.c +++ b/src/avtp/acf/Can.c @@ -9,7 +9,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of COVESA nor the names of its contributors may be + * * Neither the name of COVESA nor the names of its contributors may be * used to endorse or promote products derived from this software without * specific prior written permission. * @@ -31,7 +31,7 @@ #include #include "avtp/acf/Can.h" -#include "avtp/Utils.h" +#include "avtp/Utils.h" #include "avtp/Defines.h" #define GET_FIELD(field) \ @@ -46,7 +46,7 @@ static const Avtp_FieldDescriptor_t Avtp_CanFieldDesc[AVTP_CAN_FIELD_MAX] = { /* ACF common header fields */ [AVTP_CAN_FIELD_ACF_MSG_TYPE] = { .quadlet = 0, .offset = 0, .bits = 7 }, - [AVTP_CAN_FIELD_ACF_MSG_LENGTH] = { .quadlet = 0, .offset = 7, .bits = 9 }, + [AVTP_CAN_FIELD_ACF_MSG_LENGTH] = { .quadlet = 0, .offset = 7, .bits = 9 }, /* ACF CAN header fields */ [AVTP_CAN_FIELD_PAD] = { .quadlet = 0, .offset = 16, .bits = 2 }, [AVTP_CAN_FIELD_MTV] = { .quadlet = 0, .offset = 18, .bits = 1 }, @@ -57,13 +57,13 @@ static const Avtp_FieldDescriptor_t Avtp_CanFieldDesc[AVTP_CAN_FIELD_MAX] = [AVTP_CAN_FIELD_ESI] = { .quadlet = 0, .offset = 23, .bits = 1 }, [AVTP_CAN_FIELD_CAN_BUS_ID] = { .quadlet = 0, .offset = 27, .bits = 5 }, [AVTP_CAN_FIELD_MESSAGE_TIMESTAMP] = { .quadlet = 1, .offset = 0, .bits = 64 }, - [AVTP_CAN_FIELD_CAN_IDENTIFIER] = { .quadlet = 3, .offset = 3, .bits = 29 }, + [AVTP_CAN_FIELD_CAN_IDENTIFIER] = { .quadlet = 3, .offset = 3, .bits = 29 }, }; void Avtp_Can_Init(Avtp_Can_t* pdu) { if(pdu != NULL) { - memset(pdu, 0, sizeof(Avtp_Can_t)); + memset(pdu, 0, sizeof(Avtp_Can_t)); Avtp_Can_SetField(pdu, AVTP_CAN_FIELD_ACF_MSG_TYPE, AVTP_ACF_TYPE_CAN); } } @@ -198,11 +198,11 @@ void Avtp_Can_SetCanIdentifier(Avtp_Can_t* pdu, uint32_t value) SET_FIELD(AVTP_CAN_FIELD_CAN_IDENTIFIER, value); } -int Avtp_Can_SetPayload(Avtp_Can_t* pdu, uint32_t frame_id , uint8_t* payload, +void Avtp_Can_CreateAcfMessage(Avtp_Can_t* pdu, uint32_t frame_id, uint8_t* payload, uint16_t payload_length, Avtp_CanVariant_t can_variant) { // Copy the payload into the CAN PDU - memcpy(pdu->payload, payload, payload_length); + Avtp_Can_SetPayload(pdu, payload, payload_length); // Set the Frame ID and CAN variant int eff = frame_id > 0x7ff? 1 : 0; @@ -211,10 +211,10 @@ int Avtp_Can_SetPayload(Avtp_Can_t* pdu, uint32_t frame_id , uint8_t* payload, Avtp_Can_SetField(pdu, AVTP_CAN_FIELD_FDF, (uint8_t) can_variant); // Finalize the AVTP CAN Frame - return Avtp_Can_Finalize(pdu, payload_length); + Avtp_Can_Finalize(pdu, payload_length); } -int Avtp_Can_Finalize(Avtp_Can_t* pdu, uint16_t payload_length) +void Avtp_Can_Finalize(Avtp_Can_t* pdu, uint16_t payload_length) { uint8_t padSize; uint32_t avtpCanLength = AVTP_CAN_HEADER_LEN + payload_length; @@ -229,22 +229,22 @@ int Avtp_Can_Finalize(Avtp_Can_t* pdu, uint16_t payload_length) // Set the length and padding fields Avtp_Can_SetField(pdu, AVTP_CAN_FIELD_ACF_MSG_LENGTH, (uint64_t) avtpCanLength/AVTP_QUADLET_SIZE); Avtp_Can_SetField(pdu, AVTP_CAN_FIELD_PAD, padSize); - - return avtpCanLength; } -uint8_t* Avtp_Can_GetPayload(Avtp_Can_t* pdu, uint16_t* payload_length, uint16_t *pdu_length) +void Avtp_Can_SetPayload(Avtp_Can_t* pdu, uint8_t* payload, + uint16_t payload_length) { - uint64_t pdu_len = Avtp_Can_GetField((Avtp_Can_t*)pdu, AVTP_CAN_FIELD_ACF_MSG_LENGTH); - uint64_t pad_len = Avtp_Can_GetField((Avtp_Can_t*)pdu, AVTP_CAN_FIELD_PAD); - - if(payload_length != NULL){ - *payload_length = pdu_len*4-AVTP_CAN_HEADER_LEN-pad_len; - } - - if(pdu_length != NULL){ - *pdu_length = pdu_len; - } + memcpy(pdu->payload, payload, payload_length); +} +uint8_t* Avtp_Can_GetPayload(Avtp_Can_t* pdu) +{ return pdu->payload; } + +uint8_t Avtp_Can_GetCanPayloadLength(Avtp_Can_t* pdu) +{ + uint8_t acf_msg_length = Avtp_Can_GetAcfMsgLength(pdu) * 4; + uint8_t acf_pad_length = Avtp_Can_GetPad(pdu); + return acf_msg_length - AVTP_CAN_HEADER_LEN - acf_pad_length; +} diff --git a/unit/test-can.c b/unit/test-can.c index 67d05ec..0ccf3f4 100644 --- a/unit/test-can.c +++ b/unit/test-can.c @@ -9,7 +9,7 @@ * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * * Neither the name of COVESA nor the names of its contributors may be + * * Neither the name of COVESA nor the names of its contributors may be * used to endorse or promote products derived from this software without * specific prior written permission. * @@ -83,7 +83,7 @@ static void can_set_payload(void **state) { Avtp_Can_Init((Avtp_Can_t*)pdu); // Set payload and check for EFF - Avtp_Can_SetPayload((Avtp_Can_t*)pdu, set_frame_id, set_payload, + Avtp_Can_CreateAcfMessage((Avtp_Can_t*)pdu, set_frame_id, set_payload, CAN_PAYLOAD_SIZE, AVTP_CAN_CLASSIC); assert_int_equal(htonl(set_frame_id), (uint32_t) *((int*)pdu+3)); assert_memory_equal(set_payload, pdu+16, CAN_PAYLOAD_SIZE); @@ -91,7 +91,7 @@ static void can_set_payload(void **state) { // Check EFF for extended Frame IDs set_frame_id = 0x800; - Avtp_Can_SetPayload((Avtp_Can_t*)pdu, set_frame_id, set_payload, + Avtp_Can_CreateAcfMessage((Avtp_Can_t*)pdu, set_frame_id, set_payload, CAN_PAYLOAD_SIZE, AVTP_CAN_CLASSIC); assert_int_equal(htonl(set_frame_id), (uint32_t) *((int*)pdu+3)); assert_int_equal(0x8, *(pdu+2)&0x08); // Check EFF @@ -99,12 +99,10 @@ static void can_set_payload(void **state) { // Check padding bytes and length field uint8_t zero_array[CAN_PAYLOAD_SIZE] = {0, 0, 0, 0, 0, 0, 0, 0}; for (int i=0; i Date: Wed, 4 Sep 2024 16:56:07 +0000 Subject: [PATCH 33/33] Fixed warnings due casting of ptr. Signed-off-by: Naresh Nayak --- examples/hello-world/hello-world-listener.c | 2 +- examples/hello-world/hello-world-talker.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/hello-world/hello-world-listener.c b/examples/hello-world/hello-world-listener.c index bae998f..eaccee7 100644 --- a/examples/hello-world/hello-world-listener.c +++ b/examples/hello-world/hello-world-listener.c @@ -173,7 +173,7 @@ int main(int argc, char *argv[]) gpc_code = Avtp_Gpc_GetGpcMsgId((Avtp_Gpc_t*)acf_pdu); acf_msg_length = Avtp_Gpc_GetAcfMsgLength((Avtp_Gpc_t*)acf_pdu); if (acf_msg_length * 4 <= MAX_MSG_SIZE) { - recd_msg = acf_pdu + AVTP_GPC_HEADER_LEN; + recd_msg = (char *) acf_pdu + AVTP_GPC_HEADER_LEN; printf("%s : GPC Code %ld\n", recd_msg, gpc_code); } } diff --git a/examples/hello-world/hello-world-talker.c b/examples/hello-world/hello-world-talker.c index cf7a9b8..dba90cc 100644 --- a/examples/hello-world/hello-world-talker.c +++ b/examples/hello-world/hello-world-talker.c @@ -176,7 +176,7 @@ static int prepare_acf_packet(uint8_t* acf_pdu, uint64_t gpc_code, // Clear bits memset(pdu, 0, AVTP_GPC_HEADER_LEN); - uint8_t acf_length = (AVTP_GPC_HEADER_LEN + length)/4; + uint8_t acf_length = (AVTP_GPC_HEADER_LEN + ++length)/4; if (length % 4) acf_length++; // Prepare ACF PDU for CAN