Skip to content

Commit

Permalink
Merge pull request #31 from boschglobal/feat/add_gpc
Browse files Browse the repository at this point in the history
Added first version of ACF GPC Format.
  • Loading branch information
nayakned authored Aug 8, 2024
2 parents 3992cdb + f093b33 commit 3088820
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 1 deletion.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ add_library(open1722 SHARED
"src/avtp/aaf/CommonStream.c"
"src/avtp/aaf/PcmStream.c"
"src/avtp/acf/FlexRay.c"
"src/avtp/acf/Gpc.c"
"src/avtp/acf/Can.c"
"src/avtp/acf/CanBrief.c"
"src/avtp/acf/Lin.c"
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ The following is the list of the formats currently supported by Open1722:
- CRF
- CVF (H.264, MJPEG, JPEG2000)
- RVF
- AVTP Control Formats (ACF) (see Table 22 from IEEE 1722-2016 spec)
- AVTP Control Formats (ACF) with Non-Time-Synchronous as well as Time-Synchronous formats (see Table 22 from IEEE 1722-2016 spec)
- CAN
- CAN Brief
- Flexray
- LIN
- MOST
- GPC
- Sensor
- Sensor Brief
Expand Down
91 changes: 91 additions & 0 deletions include/avtp/acf/Gpc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* 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
*/

/**
* @file
* This file contains the fields descriptions of the IEEE 1722-2016 ACF GPC PDUs and
* functions to invoke corresponding parser and deparser.
*/
#pragma once

#include <stdint.h>

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

#define AVTP_GPC_HEADER_LEN (2 * AVTP_QUADLET_SIZE)

typedef struct {
uint8_t header[AVTP_GPC_HEADER_LEN];
uint8_t payload[0];
} Avtp_Gpc_t;


typedef enum {

/* ACF common header fields */
AVTP_GPC_FIELD_ACF_MSG_TYPE = 0,
AVTP_GPC_FIELD_ACF_MSG_LENGTH,

/* ACF GPC header fields */
AVTP_GPC_FIELD_GPC_MSG_ID,

/* Count number of fields for bound checks */
AVTP_GPC_FIELD_MAX
} Avtp_GpcFields_t;

/**
* 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.
*/
int 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.
*
* @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.
*/
int Avtp_Gpc_GetField(Avtp_Gpc_t* gpc_pdu, Avtp_GpcFields_t field, uint64_t* value);

/**
* 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 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);

72 changes: 72 additions & 0 deletions src/avtp/acf/Gpc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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 <errno.h>
#include <string.h>

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

/**
* This table maps all IEEE 1722 ACF GPC header fields to a descriptor.
*/
static const Avtp_FieldDescriptor_t Avtp_GpcFieldDesc[AVTP_GPC_FIELD_MAX] =
{
/* ACF common header fields */
[AVTP_GPC_FIELD_ACF_MSG_TYPE] = { .quadlet = 0, .offset = 0, .bits = 7 },
[AVTP_GPC_FIELD_ACF_MSG_LENGTH] = { .quadlet = 0, .offset = 7, .bits = 9 },
/* ACF GPC header fields */
[AVTP_GPC_FIELD_GPC_MSG_ID] = { .quadlet = 0, .offset = 16, .bits = 48 },
};

int Avtp_Gpc_Init(Avtp_Gpc_t* gpc_pdu)
{
if(!gpc_pdu) {
return -EINVAL;
}

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)
{
return Avtp_GetField(Avtp_GpcFieldDesc, AVTP_GPC_FIELD_MAX, (uint8_t *) gpc_pdu, (uint8_t) field, value);
}

int 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);
}

0 comments on commit 3088820

Please sign in to comment.