From 64c4d6ddc2df7ca932884765955fdb5e847ddc52 Mon Sep 17 00:00:00 2001 From: Adriaan Niess Date: Wed, 28 Aug 2024 12:31:22 +0200 Subject: [PATCH] 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); }