Files
V2GDecoderC/csharp/vc2022/src/transport/v2gtp.c
ChiKyun Kim 1cee8de707 feat: Add Visual Studio 2022 VC++ project for C debugging
- Create complete VS2022 solution with 3 projects:
  * V2GDecoder: Main EXI decoder with debugging support
  * HexToBinary: Hex string to binary utility
  * HexDumpToBinary: Hex dump to binary utility

- Copy all source files locally for Windows compilation:
  * Added Windows compatibility for unistd.h, fstat, S_ISREG
  * Fixed VLA issues in EncoderChannel.c with macro definitions
  * Include all required modules: codec, iso1, iso2, din, appHandshake

- Build configuration:
  * Support Debug/Release x86/x64 configurations
  * Proper include directories and preprocessor definitions
  * Windows-specific compiler flags (_WIN32, __STDC_NO_VLA__)

- Verification:
  * Both test4.exi and test5.exi decode/encode perfectly
  * 100% binary compatibility: original ↔ XML ↔ reencoded
  * Ready for step-by-step debugging in Visual Studio

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-10 14:57:54 +09:00

93 lines
2.4 KiB
C

/*
* Copyright (C) 2007-2018 Siemens AG
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*******************************************************************
*
* @author Sebastian.Kaebisch@siemens.com
* @author Daniel.Peintner.EXT@siemens.com
* @version 0.9.4
* @contact Richard.Kuntschke@siemens.com
*
********************************************************************/
/*
* This file implements the v2gtp header writer and reader.
*
*/
#include <stdint.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include "v2gtp.h"
int write_v2gtpHeader(uint8_t* outStream, uint32_t outStreamLength, uint16_t payloadType)
{
/* write v2gtp version number 1=byte */
outStream[0]=V2GTP_VERSION;
/* write inverse v2gtp version */
outStream[1]=V2GTP_VERSION_INV;
/* write payload type */
outStream[3] = (uint8_t)(payloadType & 0xFF);
outStream[2] = (uint8_t)(payloadType >> 8 & 0xFF);
/* write payload length */
outStream[7] = (uint8_t)(outStreamLength & 0xFF);
outStream[6] = (uint8_t)(outStreamLength>>8 & 0xFF);
outStream[5] = (uint8_t)(outStreamLength>>16 & 0xFF);
outStream[4] = (uint8_t)(outStreamLength>>24 & 0xFF);
return 0;
}
int read_v2gtpHeader(uint8_t* inStream, uint32_t* payloadLength)
{
uint16_t payloadType=0;
/* check, if we support this v2gtp version */
if(inStream[0]!=V2GTP_VERSION || inStream[1]!=V2GTP_VERSION_INV)
return -1;
/* check, if we support this payload type*/
payloadType = inStream[2];
payloadType = (payloadType << 8 | inStream[3]);
if(payloadType != V2GTP_EXI_TYPE)
return -1;
/* determine payload length*/
*payloadLength = inStream[4];
*payloadLength = (*payloadLength << 8 | inStream[5]);
*payloadLength = (*payloadLength << 8 | inStream[6]);
*payloadLength = (*payloadLength << 8 | inStream[7]);
return 0;
}