Update sdv_packager (#6)

This commit is contained in:
tompzf
2026-03-27 14:12:49 +01:00
committed by GitHub
parent 234be8917f
commit aefefd52f7
717 changed files with 42252 additions and 11334 deletions

View File

@@ -1,3 +1,16 @@
#*******************************************************************************
# Copyright (c) 2025-2026 ZF Friedrichshafen AG
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
#
# Contributors:
# Erik Verhoeven - initial API and implementation
#*******************************************************************************
# Define project
project (sdv_vss_util VERSION 1.0 LANGUAGES CXX)

View File

@@ -1,3 +1,16 @@
/********************************************************************************
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Thomas Pfleiderer - initial API and implementation
********************************************************************************/
#include "codegen_base.h"
#include <sstream>

View File

@@ -1,3 +1,16 @@
/********************************************************************************
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Thomas Pfleiderer - initial API and implementation
********************************************************************************/
#ifndef CODEGEN_BASE_H
#define CODEGEN_BASE_H

View File

@@ -1,3 +1,16 @@
/********************************************************************************
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Thomas Pfleiderer - initial API and implementation
********************************************************************************/
#include "csv_file_reader.h"
CCSVFileReader::CCSVFileReader(const std::string& ssFileName, const bool bSilent, const bool bVerbose)

View File

@@ -1,3 +1,16 @@
/********************************************************************************
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Thomas Pfleiderer - initial API and implementation
********************************************************************************/
#ifndef CSV_FILE_READER_H
#define CSV_FILE_READER_H

View File

@@ -1,3 +1,16 @@
/********************************************************************************
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Thomas Pfleiderer - initial API and implementation
********************************************************************************/
#include <iostream>
#include <unordered_map>

View File

@@ -1,3 +1,16 @@
/********************************************************************************
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Thomas Pfleiderer - initial API and implementation
********************************************************************************/
#include "vss_bs_codingrx.h"
void CVSSBSCodingRX::GetKeyWordMap(const SSignalBSDefinition& signal, const SSignalVDDefinition& signalVD, CKeywordMap& mapKeywords) const

View File

@@ -1,3 +1,16 @@
/********************************************************************************
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Thomas Pfleiderer - initial API and implementation
********************************************************************************/
#ifndef VSS_BS_CODING_RX_H
#define VSS_BS_CODING_RX_H
@@ -19,121 +32,121 @@
* Beside the definition of the basic service interface also information about the vehicle device is necessary
* These 2 definitions must match, there must be a corresponding 'signalVD' definition
* the function container of the basic service signal must match the function container if the 'signalVD'
* Creates the code out of templates
* Creates the code out of templates
*/
class CVSSBSCodingRX : public CCodeGeneratorBase, CVSSHelper
{
public:
/**
* @brief create service content for the IDL file of a RX signal
* @param[in] vssParts Interface in vss style separated in parts
* @param[in] vecFunctions container of all functions of a single vss definition
* @return content of the Device part of a IDL Interface of a RX signal
*/
* @brief create service content for the IDL file of a RX signal
* @param[in] vssParts Interface in vss style separated in parts
* @param[in] vecFunctions container of all functions of a single vss definition
* @return content of the Device part of a IDL Interface of a RX signal
*/
std::string Code_RXIDLServiceList(const std::vector<std::string>& vssParts, const std::vector <SFunctionBSDefinition>& vecFunctions) const;
/**
* @brief fill the KeyWordMap with all required strings
* @param[in] signal signal definition structure to fill the KeyWordMap
* @param[in] signalVD signal definition structure from vehicle device
* @param[in] mapKeywords KeyWordMap to be filled
*/
* @brief fill the KeyWordMap with all required strings
* @param[in] signal signal definition structure to fill the KeyWordMap
* @param[in] signalVD signal definition structure from vehicle device
* @param[in] mapKeywords KeyWordMap to be filled
*/
void GetKeyWordMap(const SSignalBSDefinition& signal, const SSignalVDDefinition& signalVD, CKeywordMap& mapKeywords) const;
protected:
/**
* @brief create single or multiple lines containing include files
* @param[in] vssOriginalNoDot vss string without points e.g. VehicleChassisSteeringWheelAngle
* @return content of a single interface
*/
* @brief create single or multiple lines containing include files
* @param[in] vssOriginalNoDot vss string without points e.g. VehicleChassisSteeringWheelAngle
* @return content of a single interface
*/
std::string Code_BS_RXIncludes(const std::string& vssOriginalNoDot) const;
/**
* @brief create a single line containing a interface
* @param[in] functionName function which is part of the interface
* @param[in] vssWithColons vss string (complete version) with colons as separator
* @param[in] vd_functionName function name (Vehicle Device)
* @param[in] vd_vssWithColons vss string (complete version) with colons as separator (Vehicle Device)
* @return content of a single interface
*/
* @brief create a single line containing a interface
* @param[in] functionName function which is part of the interface
* @param[in] vssWithColons vss string (complete version) with colons as separator
* @param[in] vd_functionName function name (Vehicle Device)
* @param[in] vd_vssWithColons vss string (complete version) with colons as separator (Vehicle Device)
* @return content of a single interface
*/
std::string Code_BS_RXInterface(const std::string& functionName, const std::string& vssWithColons,
const std::string& vd_functionName, const std::string& vd_vssWithColons) const;
/**
* @brief create a single line containing a interface entry
* @param[in] functionName function which is part of the interface
* @param[in] vssWithColons vss string (short version) with colons as separator
* @return content of a single interface entry
*/
* @brief create a single line containing a interface entry
* @param[in] functionName function which is part of the interface
* @param[in] vssWithColons vss string (short version) with colons as separator
* @return content of a single interface entry
*/
std::string Code_BS_RXInterfaceEntry(const std::string& functionName, const std::string& vssWithColons) const;
/**
* @brief Get the register and unregister part for the RX VD header
* @param[in] vssWithColons vss string with colons as separator
* @param[in] function function definition structure (Basic Service)
* @param[in] functionVD function definition structure of vehicle device (Vehicle Device)
* @return content of a single register and unregister part.
*/
* @brief Get the register and unregister part for the RX VD header
* @param[in] vssWithColons vss string with colons as separator
* @param[in] function function definition structure (Basic Service)
* @param[in] functionVD function definition structure of vehicle device (Vehicle Device)
* @return content of a single register and unregister part.
*/
std::string Code_BS_RXReAndUnregisterEvent(const std::string& vssWithColons, const SFunctionBSDefinition& function,
const SFunctionVDDefinition& functionVD) const;
/**
* @brief Get the private header part of the basic service header
* @param[in] function function definition structure
* @param[in] vssWithColons vss string with colons as separator
* @return content of private header part of the basic service header
*/
* @brief Get the private header part of the basic service header
* @param[in] function function definition structure
* @param[in] vssWithColons vss string with colons as separator
* @return content of private header part of the basic service header
*/
std::string Code_BS_RXPrivateHeaderPart(const SFunctionBSDefinition& function, const std::string& vssWithColons) const;
/**
* @brief create service content for the IDL file of a RX signal
* @param[in] spaces string containing only space characters for aligning
* @param[in] vssWithColons vss string (complete version) with colons as separator
* @param[in] function function definition structure
* @return content of the Device part of a IDL Interface of a RX signal
*/
* @brief create service content for the IDL file of a RX signal
* @param[in] spaces string containing only space characters for aligning
* @param[in] vssWithColons vss string (complete version) with colons as separator
* @param[in] function function definition structure
* @return content of the Device part of a IDL Interface of a RX signal
*/
std::string Code_RXIDLServiceInterface(const std::string& spaces, const std::string& vssWithColons,
const SFunctionBSDefinition& function) const;
/**
* @brief unregister signal Event
* @param[in] signalVD signal definition structure to fill the KeyWordMap (Vehicle Device)
* @param[in] vd_vssWithColons vss string (complete version) with colons as separator (Vehicle Device)
* @param[in] functionVD function definition structure (Vehicle Device)
* @param[in] function function definition structure (Basic Service)
* @return content of a unregister code
*/
* @brief unregister signal Event
* @param[in] signalVD signal definition structure to fill the KeyWordMap (Vehicle Device)
* @param[in] vd_vssWithColons vss string (complete version) with colons as separator (Vehicle Device)
* @param[in] functionVD function definition structure (Vehicle Device)
* @param[in] function function definition structure (Basic Service)
* @return content of a unregister code
*/
std::string Code_BS_RXConstructor(const SSignalVDDefinition& signalVD, const std::string& vd_vssWithColons,
const SFunctionVDDefinition& functionVD, const SFunctionBSDefinition& function) const;
/**
* @brief unregister signal Event
* @param[in] signalVD signal definition structure to fill the KeyWordMap (Vehicle Device)
* @param[in] vd_vssWithColons vss string (complete version) with colons as separator (Vehicle Device)
* @param[in] functionVD function definition structure (Vehicle Device)
* @return content of a unregister code
*/
* @brief unregister signal Event
* @param[in] signalVD signal definition structure to fill the KeyWordMap (Vehicle Device)
* @param[in] vd_vssWithColons vss string (complete version) with colons as separator (Vehicle Device)
* @param[in] functionVD function definition structure (Vehicle Device)
* @return content of a unregister code
*/
std::string Code_BS_RXDestructor(const SSignalVDDefinition& signalVD, const std::string& vd_vssWithColons,
const SFunctionVDDefinition& functionVD) const;
/**
* @brief set and get functions for basic service
* @param[in] class_name class name which is part of the interface (Basic Service)
* @param[in] function function definition structure (Basic Service)
* @param[in] functionVD function definition structure (Vehicle Device)
* @return content of a single set and get function code
*/
* @brief set and get functions for basic service
* @param[in] class_name class name which is part of the interface (Basic Service)
* @param[in] function function definition structure (Basic Service)
* @param[in] functionVD function definition structure (Vehicle Device)
* @return content of a single set and get function code
*/
std::string Code_BS_RXGetAndSetFunctions(const std::string& class_name, const SFunctionBSDefinition& function,
const SFunctionVDDefinition& functionVD) const;
/**
* @brief create register/unregister code for basic service
* @param[in] class_name class name which is part of the interface
* @param[in] function function definition structure
* @param[in] vssWithColons vss string with colons as separator
* @return content of a single signal register/unregister code
*/
* @brief create register/unregister code for basic service
* @param[in] class_name class name which is part of the interface
* @param[in] function function definition structure
* @param[in] vssWithColons vss string with colons as separator
* @return content of a single signal register/unregister code
*/
std::string Code_BS_RXRegister(const std::string& class_name, const SFunctionBSDefinition& function,
const std::string& vssWithColons) const;
};

View File

@@ -1,3 +1,16 @@
/********************************************************************************
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Thomas Pfleiderer - initial API and implementation
********************************************************************************/
#include "vss_bs_codingtx.h"
void CVSSBSCodingTX::GetKeyWordMap(const SSignalBSDefinition& signal, const SSignalVDDefinition& signalVD, CKeywordMap& mapKeywords) const

View File

@@ -1,3 +1,16 @@
/********************************************************************************
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Thomas Pfleiderer - initial API and implementation
********************************************************************************/
#ifndef VSS_BS_CODING_TX_H
#define VSS_BS_CODING_TX_H
@@ -19,93 +32,93 @@
* These 2 definitions must match, there must be a corresponding 'signalVD' definition
* the function container of the basic service signal must match the function container if the 'signalVD'
* Creates the code out of templates
*/
*/
class CVSSBSCodingTX : public CCodeGeneratorBase, CVSSHelper
{
public:
/**
* @brief create basic service content for the IDL file of a TX signal
* @param[in] vssParts Interface in vss style separated in parts
* @param[in] vecFunctions container of all functions of a single (basic service) vss definition (basic service)
* @return content of the basic service part of a IDL Interface of a TX signal
*/
* @brief create basic service content for the IDL file of a TX signal
* @param[in] vssParts Interface in vss style separated in parts
* @param[in] vecFunctions container of all functions of a single (basic service) vss definition (basic service)
* @return content of the basic service part of a IDL Interface of a TX signal
*/
std::string Code_BS_TXIDLList(const std::vector<std::string>& vssParts, const std::vector <SFunctionBSDefinition>& vecFunctions) const;
/**
* @brief fill the KeyWordMap with all required strings
* @param[in] signal signal definition structure to fill the KeyWordMap
* @param[in] signalVD signal definition structure from vehicle device
* @param[in] mapKeywords KeyWordMap to be filled
*/
* @brief fill the KeyWordMap with all required strings
* @param[in] signal signal definition structure to fill the KeyWordMap
* @param[in] signalVD signal definition structure from vehicle device
* @param[in] mapKeywords KeyWordMap to be filled
*/
void GetKeyWordMap(const SSignalBSDefinition& signal, const SSignalVDDefinition& signalVD, CKeywordMap& mapKeywords) const;
protected:
/**
* @brief create single or multiple lines containing include files
* @param[in] vd_vssOriginalNoDot vss string without points of the corresponding vehicle device
* @param[in] vssOriginalNoDot vss string without points e.g. VehicleChassisSteeringWheelAngle
* @return content of a single interface
*/
* @brief create single or multiple lines containing include files
* @param[in] vd_vssOriginalNoDot vss string without points of the corresponding vehicle device
* @param[in] vssOriginalNoDot vss string without points e.g. VehicleChassisSteeringWheelAngle
* @return content of a single interface
*/
std::string Code_BS_TXIncludes(const std::string& vd_vssOriginalNoDot, const std::string& vssOriginalNoDot) const;
/**
* @brief create a single line containing a interface for basic service
* @param[in] functionName function which is part of the interface
* @param[in] vssWithColons vss string (complete version) with colons as separator
* @return content of a single interface
*/
* @brief create a single line containing a interface for basic service
* @param[in] functionName function which is part of the interface
* @param[in] vssWithColons vss string (complete version) with colons as separator
* @return content of a single interface
*/
std::string Code_BS_TXInterface(const std::string& functionName, const std::string& vssWithColons) const;
/**
* @brief create a single line containing a interface entry for basic service
* @param[in] functionName function which is part of the interface
* @param[in] vssWithColons vss string (complete version) with colons as separator
* @return content of a single interface entry
*/
* @brief create a single line containing a interface entry for basic service
* @param[in] functionName function which is part of the interface
* @param[in] vssWithColons vss string (complete version) with colons as separator
* @return content of a single interface entry
*/
std::string Code_BS_TXInterfaceEntry(const std::string& functionName, const std::string& vssWithColons) const;
/**
* @brief create list of interfaces (TX signals) for IDL file (Basic Service)
* @param[in] spaces string containing only space characters for aligning
* @param[in] function function definition structure
* @return content of a single interface entry
*/
* @brief create list of interfaces (TX signals) for IDL file (Basic Service)
* @param[in] spaces string containing only space characters for aligning
* @param[in] function function definition structure
* @return content of a single interface entry
*/
std::string Code_BS_TXIDLInterface(const std::string& spaces, const SFunctionBSDefinition& function) const;
/**
* @brief create function definition part (TX signals) for basic service
* @param[in] function function definition structure
* @return content of a single function declaration
*/
* @brief create function definition part (TX signals) for basic service
* @param[in] function function definition structure
* @return content of a single function declaration
*/
std::string Code_BS_TXFunction(const SFunctionBSDefinition& function) const;
/**
* @brief create definition of a interface pointer (TX signals) for basic service header file
* @param[in] functionVD which is part of the interface (Vehicle Device)
* @param[in] vd_vssWithColons vss string (complete version) with colons as separator (Vehicle Device)
* @return content of a definition of a interface pointer
*/
* @brief create definition of a interface pointer (TX signals) for basic service header file
* @param[in] functionVD which is part of the interface (Vehicle Device)
* @param[in] vd_vssWithColons vss string (complete version) with colons as separator (Vehicle Device)
* @return content of a definition of a interface pointer
*/
std::string Code_BS_TXVariablePointerFromVD(const SFunctionVDDefinition& functionVD, const std::string& vd_vssWithColons) const;
/**
* @brief create function pointer implementation part (TX signals) for basic service cpp file
* @param[in] function function definition structure (Basic Service)
* @param[in] functionVD function definition structure from vehicle device (Vehicle Device)
* @param[in] className class name of the signal (Basic Service)
* @return content of a single function pointer implementation
*/
* @brief create function pointer implementation part (TX signals) for basic service cpp file
* @param[in] function function definition structure (Basic Service)
* @param[in] functionVD function definition structure from vehicle device (Vehicle Device)
* @param[in] className class name of the signal (Basic Service)
* @return content of a single function pointer implementation
*/
std::string Code_BS_TXFunctionPointerImplementationFromVD(const SFunctionBSDefinition& function,
const SFunctionVDDefinition& functionVD, const std::string& className) const;
/**
* @brief create check if a interface pointer is valid (TX signals) for IDL file
* @param[in] functionVD which is part of the interface (Vehicle Device)
* @param[in] className class name of the signal (Basic Service)
* @param[in] vssOriginal original vvs string (Basic Service)
* @param[in] vd_vssWithColons vss string (complete version) with colons as separator (Vehicle Device)
* @return content of a check if a interface pointer is valid
*/
* @brief create check if a interface pointer is valid (TX signals) for IDL file
* @param[in] functionVD which is part of the interface (Vehicle Device)
* @param[in] className class name of the signal (Basic Service)
* @param[in] vssOriginal original vvs string (Basic Service)
* @param[in] vd_vssWithColons vss string (complete version) with colons as separator (Vehicle Device)
* @return content of a check if a interface pointer is valid
*/
std::string Code_BS_TXVariablePointerInitializationFromVD(const SFunctionVDDefinition& functionVD, const std::string& className,
const std::string& vssOriginal, const std::string& vd_vssWithColons) const;
};

View File

@@ -1,4 +1,17 @@
#include "vss_bs_generator.h"
/********************************************************************************
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Thomas Pfleiderer - initial API and implementation
********************************************************************************/
#include "vss_bs_generator.h"
#include "vss_coding.h"
#include "vss_bs_codingrx.h"
#include "vss_bs_codingtx.h"
@@ -39,8 +52,9 @@ void CVSSBSGenerator::CreateFiles(const std::string& ssVersion)
CreateTXFiles(ssVersion);
}
void CVSSBSGenerator::CreateRXFiles(const std::string& ssVersion) const
void CVSSBSGenerator::CreateRXFiles(const std::string& ssVersion)
{
m_createdFiles.clear();
for (const auto& rxSignal : m_RXsignals)
{
if (m_enableComponentCreation)
@@ -51,12 +65,12 @@ void CVSSBSGenerator::CreateRXFiles(const std::string& ssVersion) const
}
}
void CVSSBSGenerator::CreateBasicServiceFilesForRXSignal(const SSignalBSDefinition& signal, const std::string& ssVersion) const
void CVSSBSGenerator::CreateBasicServiceFilesForRXSignal(const SSignalBSDefinition& signal, const std::string& ssVersion)
{
std::string folderName = "BS_";
folderName.append(signal.className);
std::transform(folderName.begin(), folderName.end(), folderName.begin(),
[](unsigned char c) { return static_cast<char>(std::tolower(c)); });
[](unsigned char c) { return static_cast<char>(std::tolower(c)); });
if (!CreateFolder(m_pathProject, folderName))
{
return;
@@ -71,6 +85,9 @@ void CVSSBSGenerator::CreateBasicServiceFilesForRXSignal(const SSignalBSDefiniti
fstreamBSHeader.open(pathLowerCaseHeader, std::ios::out | std::ios::trunc);
fstreamBSClass.open(pathLowerCaseClass, std::ios::out | std::ios::trunc);
m_createdFiles.push_back(pathLowerCaseHeader);
m_createdFiles.push_back(pathLowerCaseClass);
CKeywordMap mapKeywords;
CVSSCodingCommon coding(m_ssPrefix);
coding.GetCommonKeyWordMap(signal, mapKeywords, ssVersion);
@@ -80,7 +97,7 @@ void CVSSBSGenerator::CreateBasicServiceFilesForRXSignal(const SSignalBSDefiniti
mapKeywords["basic_service_cpp"] = pathLowerCaseClass.filename().generic_u8string();
CVSSBSCodingRX codingRX;
auto signalVD = GetVDSignal(signal.vssVDDefinition);
auto signalVD = GetVDSignal(signal.vssVDDefinition, signal.signalDirection);
if (!signalVD.vecFunctions.size())
{
mapKeywords["vss_from_vd_not_found"] = "// corresponding vehicle device interface not found";
@@ -136,7 +153,7 @@ void CVSSBSGenerator::CreateIDLBasicServiceFileForRXSignal(const SSignalBSDefini
[](unsigned char c) { return static_cast<char>(std::tolower(c)); });
mapKeywords["vd_idl_file"] = vdIDLFileLowerCase;
auto signalVD = GetVDSignal(signal.vssVDDefinition);
auto signalVD = GetVDSignal(signal.vssVDDefinition, signal.signalDirection);
if (signalVD.vecFunctions.size())
{
std::string vssNoDot = ReplaceCharacters(signal.vssVDDefinition, ".", "");
@@ -168,18 +185,27 @@ void CVSSBSGenerator::CreateBasicServiceFilesForTXSignal(const SSignalBSDefiniti
std::string folderName = "BS_";
folderName.append(signal.className);
std::transform(folderName.begin(), folderName.end(), folderName.begin(),
[](unsigned char c) { return static_cast<char>(std::tolower(c)); });
[](unsigned char c) { return static_cast<char>(std::tolower(c)); });
if (!CreateFolder(m_pathProject, folderName))
{
return;
}
std::filesystem::path pathBSHeader = m_pathProject / folderName / AppendExtension("BS_", signal.className, ".h");
std::filesystem::path pathBSClass = m_pathProject / folderName / AppendExtension("BS_", signal.className, ".cpp");
std::filesystem::path pathCMakeLists = m_pathProject / folderName / "CMakeLists.txt";
std::ofstream fstreamBSHeader;
std::ofstream fstreamBSClass;
auto pathLowerCaseHeader = MakeLowercaseFilename(pathBSHeader);
auto pathLowerCaseClass = MakeLowercaseFilename(pathBSClass);
auto pathLowerCaseClass = MakeLowercaseFilename(pathBSClass);
auto headerExists = std::find(m_createdFiles.begin(), m_createdFiles.end(), pathLowerCaseHeader) != m_createdFiles.end();
auto classExists = std::find(m_createdFiles.begin(), m_createdFiles.end(), pathLowerCaseClass) != m_createdFiles.end();
if (headerExists || classExists)
{
UpdateExistingFiles(m_pathProject, folderName, signal);
return;
}
fstreamBSHeader.open(pathLowerCaseHeader, std::ios::out | std::ios::trunc);
fstreamBSClass.open(pathLowerCaseClass, std::ios::out | std::ios::trunc);
@@ -192,7 +218,7 @@ void CVSSBSGenerator::CreateBasicServiceFilesForTXSignal(const SSignalBSDefiniti
mapKeywords["basic_service_cpp"] = pathLowerCaseClass.filename().generic_u8string();
CVSSBSCodingTX codingTX;
auto signalVD = GetVDSignal(signal.vssVDDefinition);
auto signalVD = GetVDSignal(signal.vssVDDefinition, signal.signalDirection);
if (!signalVD.vecFunctions.size())
{
mapKeywords["vss_from_vd_not_found"] = "// corresponding vehicle device interface not found";
@@ -245,3 +271,178 @@ void CVSSBSGenerator::CreateIDLBasicServiceFileForTXSignal(const SSignalBSDefini
fstreamBSTXIDL << ReplaceKeywords(szBSTXIDLTemplate, mapKeywords);
fstreamBSTXIDL.close();
}
bool CVSSBSGenerator::UpdateExistingFiles(const std::filesystem::path& rootPath, const std::string& subfolder, const SSignalBSDefinition& signal) const
{
std::filesystem::path path = rootPath / subfolder;
CKeywordMap mapKeywords;
CVSSBSCodingTX codingTX;
auto signalVD = GetVDSignal(signal.vssVDDefinition, signal.signalDirection);
if (!signalVD.vecFunctions.size())
{
mapKeywords["vss_from_vd_not_found"] = "// corresponding vehicle device interface not found";
}
codingTX.GetKeyWordMap(signal, signalVD, mapKeywords);
auto pointerList = mapKeywords["tx_bs_variable_pointer_init_list"];
auto funtionImplementation = mapKeywords["vd_tx_pointer_function_implementations"];
if (UpdateCppFile(path, signal, pointerList, funtionImplementation))
{
auto includeList = mapKeywords["tx_bs_includes_list"];
auto interfaceList = mapKeywords["tx_bs_interface_list"];
auto interfaceEntryList = mapKeywords["tx_bs_interface_entry_list"];
auto functionList = mapKeywords["tx_bs_function_list"];
auto variablePointerList = mapKeywords["tx_bs_variable_pointer_list"];
if (UpdateHeaderFile(path, signal, includeList, interfaceList, interfaceEntryList, functionList, variablePointerList))
{
return true;
}
}
return false;
}
bool CVSSBSGenerator::UpdateCppFile(const std::filesystem::path& rootFolder, const SSignalBSDefinition& signal, const std::string& initializeList, const std::string& implementation) const
{
std::filesystem::path pathBSCpp = rootFolder / AppendExtension("BS_", signal.className, ".cpp");
auto pathLowerCaseCpp = MakeLowercaseFilename(pathBSCpp);
std::ifstream in(pathLowerCaseCpp);
if (!in)
{
std::cerr << "Failed to read file '" << pathLowerCaseCpp << ")\n";
return false;
}
std::string s;
std::vector<std::string> lines; // write new file into memory
while (std::getline(in, s))
{
lines.push_back(s);
if (s.find("::CBasicService") != std::string::npos) // we have to find the constructor
{
std::getline(in, s); // add next line, the bracket
lines.push_back(s);
lines.push_back(initializeList);
break;
}
}
while (std::getline(in, s))
{
lines.push_back(s);
}
lines.push_back(implementation); // implementation at end of file
in.close();
std::error_code ec;
std::filesystem::remove(pathLowerCaseCpp, ec); // delete file
if (ec)
{
std::cerr << "Failed to delete file '" << pathLowerCaseCpp << "': " << ec.message() << " (error code: " << ec.value() << ")\n";
return false;
}
std::ofstream out(pathLowerCaseCpp, std::ios::trunc);
if (!out)
{
std::cerr << "Failed to write file '" << pathLowerCaseCpp << ")\n";
return false;
}
for (const auto& line : lines)
out << line << "\n";
out.close();
return true;
}
bool CVSSBSGenerator::UpdateHeaderFile(const std::filesystem::path& rootFolder, const SSignalBSDefinition& signal, const std::string& includeList,
const std::string& interfaceList, const std::string& interfaceEntryList, const std::string& functionList, const std::string& variablePointerList) const
{
std::filesystem::path pathBSCHeader = rootFolder / AppendExtension("BS_", signal.className, ".h");
auto pathLowerCaseHeader = MakeLowercaseFilename(pathBSCHeader);
std::ifstream in(pathLowerCaseHeader);
if (!in)
{
std::cerr << "Failed to read file '" << pathLowerCaseHeader << ")\n";
return false;
}
std::string s;
std::vector<std::string> lines; // write new file into memory
while (std::getline(in, s))
{
lines.push_back(s);
if (s.find("<support/signal_support.h>") != std::string::npos)
{
lines.push_back(includeList);
break;
}
}
while (std::getline(in, s))
{
lines.push_back(s);
if (s.find(", public") != std::string::npos)
{
lines.push_back(interfaceList);
break;
}
}
while (std::getline(in, s))
{
lines.push_back(s);
if (s.find("BEGIN_SDV_INTERFACE_MAP()") != std::string::npos)
{
lines.push_back(interfaceEntryList);
break;
}
}
while (std::getline(in, s))
{
if (s.find("private:") != std::string::npos)
{
lines.push_back(functionList); // we need to add entries before and after
lines.push_back(s);
lines.push_back(variablePointerList);
break;
}
lines.push_back(s);
}
while (std::getline(in, s))
{
lines.push_back(s);
}
in.close();
std::error_code ec;
std::filesystem::remove(pathLowerCaseHeader, ec); // delete file
if (ec)
{
std::cerr << "Failed to delete file '" << pathLowerCaseHeader << "': " << ec.message() << " (error code: " << ec.value() << ")\n";
return false;
}
std::ofstream out(pathLowerCaseHeader, std::ios::trunc);
if (!out)
{
std::cerr << "Failed to write file '" << pathLowerCaseHeader << ")\n";
return false;
}
for (const auto& line : lines) // write new file to disc
out << line << "\n";
out.close();
return true;
}

View File

@@ -1,3 +1,16 @@
/********************************************************************************
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Thomas Pfleiderer - initial API and implementation
********************************************************************************/
#ifndef VSS_BS_GENERATOR_H
#define VSS_BS_GENERATOR_H
@@ -20,7 +33,6 @@ public:
* @param[in] rsVersion optional version tag, will be wriiten in header of the files
* @param[in] enableComponentCreation optional version tag, will be wriiten in header of the files
*/
CVSSBSGenerator(const std::vector<SSignalBSDefinition>& signals, const std::vector<SSignalVDDefinition>& signalsVD, const std::filesystem::path& rpathOutputDir, const std::string& rsPrefix,
const std::string& rsVersion, const bool enableComponentCreation) :
m_enableComponentCreation(enableComponentCreation),
@@ -41,87 +53,125 @@ public:
private:
/**
* @brief create a file name including prefix and extension
* @param[in] prefix
* @param[in] filename
* @param[in] extension
* @return combined file name
*/
* @brief create a file name including prefix and extension
* @param[in] prefix
* @param[in] filename
* @param[in] extension
* @return combined file name
*/
std::string AppendExtension(const std::string& prefix, const std::string& filename, const std::string& extension) const;
/**
* @brief create vehicle device and basic service .h an .cpp files
* create IDL files
* @param[in] ssVersion optional information will be placed in the header of the files
*/
* @brief create vehicle device and basic service .h an .cpp files
* create IDL files
* @param[in] ssVersion optional information will be placed in the header of the files
*/
void CreateFiles(const std::string& ssVersion);
/**
* @brief create IDL files and vehicle device and basic service files of RX signals
* @param[in] ssVersion optional information will be placed in the header of the files
*/
void CreateRXFiles(const std::string& ssVersion) const;
* @brief create IDL files and vehicle device and basic service files of RX signals
* @param[in] ssVersion optional information will be placed in the header of the files
*/
void CreateRXFiles(const std::string& ssVersion);
/**
* @brief create basic service files of a single RX signal
* @param[in] signal single signal definition
* @param[in] ssVersion optional information will be placed in the header of the files
*/
void CreateBasicServiceFilesForRXSignal(const SSignalBSDefinition& signal, const std::string& ssVersion) const;
* @brief create basic service files of a single RX signal
* @param[in] signal single signal definition
* @param[in] ssVersion optional information will be placed in the header of the files
*/
void CreateBasicServiceFilesForRXSignal(const SSignalBSDefinition& signal, const std::string& ssVersion);
/**
* @brief create IDL file of a single RX signal (basic service)
* @param[in] signal single signal definition
* @param[in] ssVersion optional information will be placed in the header of the files
*/
* @brief create IDL file of a single RX signal (basic service)
* @param[in] signal single signal definition
* @param[in] ssVersion optional information will be placed in the header of the files
*/
void CreateIDLBasicServiceFileForRXSignal(const SSignalBSDefinition& signal, const std::string& ssVersion) const;
/**
* @brief create IDL files and vehicle device and basic service files of TX signals
* @param[in] ssVersion optional information will be placed in the header of the files
*/
* @brief create IDL files and vehicle device and basic service files of TX signals
* @param[in] ssVersion optional information will be placed in the header of the files
*/
void CreateTXFiles(const std::string& ssVersion) const;
/**
* @brief create basic service files of a single TX signal
* @param[in] signal single signal definition
* @param[in] ssVersion optional information will be placed in the header of the files
*/
* @brief create basic service files of a single TX signal
* @param[in] signal single signal definition
* @param[in] ssVersion optional information will be placed in the header of the files
*/
void CreateBasicServiceFilesForTXSignal(const SSignalBSDefinition& signal, const std::string& ssVersion) const;
/**
* @brief create IDL file for a single TX signal (basic service)
* @param[in] signal single signal definition
* @param[in] ssVersion optional information will be placed in the header of the files
*/
* @brief create IDL file for a single TX signal (basic service)
* @param[in] signal single signal definition
* @param[in] ssVersion optional information will be placed in the header of the files
*/
void CreateIDLBasicServiceFileForTXSignal(const SSignalBSDefinition& signal, const std::string& ssVersion) const;
/**
* @brief find a vss definition in the signal list of the vehicle device collection and return the signal
* @param[in] vssDefinition vss name
* @return signal if a signal was found, otherwise a empty signal definition
*/
SSignalVDDefinition GetVDSignal(const std::string& vssDefinition) const
* @brief In case a RX signal and TX signal have the same vss name we need to update the existing rx signals files
* @param[in] rootPath complete root path
* @param[in] subfolder subfolder of the rx signal files
* @return true if files could be updated successfully, otherwise false
*/
bool UpdateExistingFiles(const std::filesystem::path& rootPath, const std::string& subfolder, const SSignalBSDefinition& signal) const;
/**
* @brief Update existing cpp file of a rx signal
* @param[in] rootPath complete root path
* @param[in] signal single signal definition
* @param[in] initializeList list of interfaces for the constructor
* @param[in] implementation function implementation methods
* @return true if file could be updated successfully, otherwise false
*/
bool UpdateCppFile(const std::filesystem::path& rootFolder, const SSignalBSDefinition& signal, const std::string& initializeList, const std::string& implementation) const;
/**
* @brief Update existing cpp file of a rx signal
* @param[in] rootPath complete root path
* @param[in] signal single signal definition
* @param[in] includeList list of headers to be included
* @param[in] interfaceList list if interfaces
* @param[in] interfaceEntryList list of event entry interfaces
* @param[in] functionList list of function definitions
* @param[in] variablePointerList list of interface pointers
* @return true if file could be updated successfully, otherwise false
*/
bool UpdateHeaderFile(const std::filesystem::path& rootFolder, const SSignalBSDefinition& signal, const std::string& includeList,
const std::string& interfaceList, const std::string& interfaceEntryList, const std::string& functionList, const std::string& variablePointerList) const;
/**
* @brief find a vss definition in the signal list of the vehicle device collection and return the signal
* @param[in] vssDefinition vss name
* @param[in] signalDirection direction of the signal (RX or TX)
* @return signal if a signal was found, otherwise a empty signal definition
*/
SSignalVDDefinition GetVDSignal(const std::string& vssDefinition,const sdv::core::ESignalDirection signalDirection) const
{
SSignalVDDefinition noSignal;
for (const auto& signal : m_signalsVD)
{
if (signal.vssDefinition.compare(vssDefinition) == 0)
{
return signal;
if (signal.signalDirection == signalDirection)
{
return signal;
}
}
}
return noSignal;
}
bool m_enableComponentCreation; ///< if set, the code for the components are created, otherwise only idl files
std::string m_ssPrefix; ///< prefix, used by cmake library and signal definition in signal_identifier.h file.
std::string m_ssVersion; ///< optional version tag, will be wriiten in header of the files
std::filesystem::path m_pathProject; ///< Project file path
std::vector <SSignalBSDefinition> m_signals; ///< all signals
std::vector <SSignalVDDefinition> m_signalsVD; ///< all signals
std::vector <SSignalBSDefinition> m_TXsignals; ///< vector containing the RX signals
std::vector <SSignalBSDefinition> m_RXsignals; ///< vector containing the TX signals
bool m_enableComponentCreation; ///< if set, the code for the components are created, otherwise only idl files
std::string m_ssPrefix; ///< prefix, used by cmake library and signal definition in signal_identifier.h file.
std::string m_ssVersion; ///< optional version tag, will be written in header of the files
std::filesystem::path m_pathProject; ///< Project file path
std::vector <SSignalBSDefinition> m_signals; ///< all signals
std::vector <SSignalVDDefinition> m_signalsVD; ///< all signals
std::vector <SSignalBSDefinition> m_TXsignals; ///< vector containing the RX signals
std::vector <SSignalBSDefinition> m_RXsignals; ///< vector containing the TX signals
std::vector<std::filesystem::path> m_createdFiles; ///< collect all files created when the RX signals are processed
};
#endif // !defined VSS_BS_GENERATOR_H

View File

@@ -1,3 +1,16 @@
/********************************************************************************
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Thomas Pfleiderer - initial API and implementation
********************************************************************************/
#include "vss_coding.h"

View File

@@ -1,3 +1,16 @@
/********************************************************************************
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Thomas Pfleiderer - initial API and implementation
********************************************************************************/
#ifndef VSS_CODING_H
#define VSS_CODING_H
@@ -14,7 +27,7 @@
/**
* @brief VSS code generator coding class.
* Creates the code out of templates
*/
*/
class CVSSCodingCommon : public CCodeGeneratorBase, CVSSHelper
{
@@ -26,76 +39,76 @@ public:
CVSSCodingCommon(const std::string& rsPrefix) : m_ssPrefix(rsPrefix) {}
/**
* @brief fill the KeyWordMap with all required strings
* @param[in] signal signal definition structure to fill the KeyWordMap
* @param[in] mapKeywords KeyWordMap to be filled
* @param[in] rsVersion optional information will be placed in the header of the files
*/
* @brief fill the KeyWordMap with all required strings
* @param[in] signal signal definition structure to fill the KeyWordMap
* @param[in] mapKeywords KeyWordMap to be filled
* @param[in] rsVersion optional information will be placed in the header of the files
*/
void GetCommonKeyWordMap(const SSignalVDDefinition& signal, CKeywordMap& mapKeywords, const std::string& rsVersion) const;
/**
* @brief fill the KeyWordMap with all required strings
* @param[in] signal signal definition structure to fill the KeyWordMap
* @param[in] mapKeywords KeyWordMap to be filled
* @param[in] rsVersion optional information will be placed in the header of the files
*/
* @brief fill the KeyWordMap with all required strings
* @param[in] signal signal definition structure to fill the KeyWordMap
* @param[in] mapKeywords KeyWordMap to be filled
* @param[in] rsVersion optional information will be placed in the header of the files
*/
void GetCommonKeyWordMap(const SSignalBSDefinition& signal, CKeywordMap& mapKeywords, const std::string& rsVersion) const;
/**
* @brief create content of the signal_identifier.h file
* @param[in] allSignals container of all signal definitions
* @param[in] ssFileName file name of the signal_identifier.h file
* @param[in] ssVersion optional information will be placed in the header of the files
* @return content of the signal_identifier.h file
*/
* @brief create content of the signal_identifier.h file
* @param[in] allSignals container of all signal definitions
* @param[in] ssFileName file name of the signal_identifier.h file
* @param[in] ssVersion optional information will be placed in the header of the files
* @return content of the signal_identifier.h file
*/
std::string Code_SignalIdentifier(const std::vector <SSignalVDDefinition>& allSignals, const std::string& ssFileName,
const std::string& ssVersion) const;
/**
* @brief get the version line which will be added in the header of the files
* @param[in] ssVersion optional information will be placed in the header of the files
* @return line for the header of the files to know the file is auto generated
*/
* @brief get the version line which will be added in the header of the files
* @param[in] ssVersion optional information will be placed in the header of the files
* @return line for the header of the files to know the file is auto generated
*/
std::string Code_VSSFileVersion(const std::string& ssVersion) const;
/**
* @brief generates the unique define to avoid duplicate loading of a header file
* @param[in] ssFileName file name which will be included in the unique define
* @return unique define string
*/
* @brief generates the unique define to avoid duplicate loading of a header file
* @param[in] ssFileName file name which will be included in the unique define
* @return unique define string
*/
std::string Code_SafeGuard(const std::string& ssFileName) const;
/**
* @brief generates the cmakelist.txt file
* @param[in] targetLibName project cmake name
* @param[in] targetComponentName is the name of the header and cpp file
* @return content of the CMakeList.txt file
*/
* @brief generates the cmakelist.txt file
* @param[in] targetLibName project cmake name
* @param[in] targetComponentName is the name of the header and cpp file
* @return content of the CMakeList.txt file
*/
std::string Code_CMakeProject(const std::string& targetLibName, const std::string& targetComponentName) const;
protected:
/**
* @brief create a signal line for the signal_identifier file
* @param[in] allSignals container of all signals for aligning of the string
* @param[in] signal single signal the function belongs to
* @param[in] func the function which should be returned in a line
* @param[in] signalTitle signal title string in file signal_identifier.h
* @param[in] canSignalTitle can signal title string in file signal_identifier.h
* @param[in] cTypeTitle c-type title string in file signal_identifier.h
* @return content of a single function for the signal_identifier file
*/
* @brief create a signal line for the signal_identifier file
* @param[in] allSignals container of all signals for aligning of the string
* @param[in] signal single signal the function belongs to
* @param[in] func the function which should be returned in a line
* @param[in] signalTitle signal title string in file signal_identifier.h
* @param[in] canSignalTitle can signal title string in file signal_identifier.h
* @param[in] cTypeTitle c-type title string in file signal_identifier.h
* @return content of a single function for the signal_identifier file
*/
std::string Code_SignalIdentifierList(const std::vector <SSignalVDDefinition>& allSignals, const SSignalVDDefinition& signal,
const SFunctionVDDefinition& func, const std::string& signalTitle, const std::string& canSignalTitle, const std::string& cTypeTitle) const;
/**
* @brief create a list of all signals for the signal_identifier file
* @param[in] allSignals container of all signals
* @param[in] signalTitle signal title string in file signal_identifier.h
* @param[in] canSignalTitle can signal title string in file signal_identifier.h
* @param[in] cTypeTitle c-type title string in file signal_identifier.h
* @return content of list of all signals for the signal_identifier file
*/
* @brief create a list of all signals for the signal_identifier file
* @param[in] allSignals container of all signals
* @param[in] signalTitle signal title string in file signal_identifier.h
* @param[in] canSignalTitle can signal title string in file signal_identifier.h
* @param[in] cTypeTitle c-type title string in file signal_identifier.h
* @return content of list of all signals for the signal_identifier file
*/
std::string Code_AllSignalsIdentifierList(const std::vector <SSignalVDDefinition>& allSignals,
const std::string& signalTitle, const std::string& canSignalTitle, const std::string& cTypeTitle) const;

View File

@@ -1,3 +1,16 @@
/********************************************************************************
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Thomas Pfleiderer - initial API and implementation
********************************************************************************/
#include "vss_helper.h"
std::string CVSSHelper::MapDeclType2CType(const sdv::vss::EDeclType eDeclType) const
@@ -533,3 +546,4 @@ bool CVSSHelper::VehicleDeviceVSSDefinitionExists(bool bSilent, const std::vecto
}
return true;
}

View File

@@ -1,3 +1,16 @@
/********************************************************************************
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Thomas Pfleiderer - initial API and implementation
********************************************************************************/
#ifndef VSS_HELPER_H
#define VSS_HELPER_H
@@ -10,7 +23,6 @@
#include <fstream>
#include <thread>
#include <chrono>
//#include <algorithm>
#include <interfaces/dispatch.h>
namespace sdv
@@ -125,7 +137,7 @@ namespace sdv
/**
* @brief VSS code generator helper class.
*/
*/
class CVSSHelper
{
@@ -133,19 +145,19 @@ public:
/**
* @brief Signal definition structure (vehicle device) with a single function/value combination
*/
*/
struct SFunctionVDDefinition
{
std::string idlType; ///< signal value type (IDL: boolean, float, uint8, ...)
std::string functionName; ///< signal value set function name
std::string signalName; ///< signal name
std::string canSignalName; ///< can signal name (combination of signak messages and signal name)
std::string canSignalName; ///< can signal name (combination of signa messages and signal name)
std::string formula; ///< c++ code if the value has to be converted
};
/**
* @brief Signal definition structure (basic service) with a single function/value combination
*/
*/
struct SFunctionBSDefinition
{
std::string idlType; ///< signal value type (IDL: boolean, float, uint8, ...)
@@ -155,7 +167,7 @@ public:
/**
* @brief Signal definition structure (vehicle device) with a single function/value combination
*/
*/
struct SSignalVDDefinition
{
std::string vssDefinition; ///< vss interface string
@@ -166,7 +178,7 @@ public:
/**
* @brief Signal definition structure (basic service) with a single function/value combination
*/
*/
struct SSignalBSDefinition
{
std::string vssDefinition; ///< vss interface string
@@ -177,257 +189,257 @@ public:
};
/**
* @brief Check if all required VD definitions are found required by the BS signals
* @param[in] bSilent if true do not print error to console.
* @param[in] vdSignals containing all signals definitions of the vehicle devices.
* @param[in] bsSignals containing all signals definitions of the basic services.
* @return Returns true on success when all definitions are found, otherwise false.
*/
* @brief Check if all required VD definitions are found required by the BS signals
* @param[in] bSilent if true do not print error to console.
* @param[in] vdSignals containing all signals definitions of the vehicle devices.
* @param[in] bsSignals containing all signals definitions of the basic services.
* @return Returns true on success when all definitions are found, otherwise false.
*/
static bool VehicleDeviceVSSDefinitionExists(bool bSilent, const std::vector<SSignalVDDefinition>& vdSignals,
const std::vector<SSignalBSDefinition>& bsSignals);
protected:
/**
* @brief Create the cmake if not exists and if content has changed
* @param[in] filePath full path to the file
* @param[in] cmakeContent content of the cmake file
*/
* @brief Create the cmake if not exists and if content has changed
* @param[in] filePath full path to the file
* @param[in] cmakeContent content of the cmake file
*/
void CreateCMakeFile(const std::filesystem::path& filePath, const std::string& cmakeContent) const;
/**
* @brief Converts the filename of a full path to lowercase
* @param[in] fullPath full path
* @return Returns full path but the filename is lowercase
*/
* @brief Converts the filename of a full path to lowercase
* @param[in] fullPath full path
* @return Returns full path but the filename is lowercase
*/
std::filesystem::path MakeLowercaseFilename(std::filesystem::path& fullPath) const;
/**
* @brief Add multiple space characters to increase the input string to a certain size.
* @param[in] ssInput Reference to the input string.
* @param[in] size of the final string.
* @return Returns the string increased by space characters.
*/
* @brief Add multiple space characters to increase the input string to a certain size.
* @param[in] ssInput Reference to the input string.
* @param[in] size of the final string.
* @return Returns the string increased by space characters.
*/
std::string Align(const std::string& ssInput, size_t size) const;
/**
* @brief trim spaces from begin of the string and end of the string
* @param[in] ssInput Reference to the input string to be checked.
* @return Returns string without the spaces at front and at the end
*/
* @brief trim spaces from begin of the string and end of the string
* @param[in] ssInput Reference to the input string to be checked.
* @return Returns string without the spaces at front and at the end
*/
std::string Trim(const std::string& ssInput) const;
/**
* @brief check for space characters in the string.
* @param[in] ssInput Reference to the input string to be checked.
* @return Returns true if string contains no space character, otherwise false.
*/
* @brief check for space characters in the string.
* @param[in] ssInput Reference to the input string to be checked.
* @return Returns true if string contains no space character, otherwise false.
*/
bool MustNotContainSpaces(const std::string& ssInput) const;
/**
* @brief Get the maximal string size of all class names in the vector container.
* @param[in] signals containing all signals definitions which have to be checked.
* @param[in] ssTitle Reference to the title string. Is minimum of the return value.
* @return Returns the string size of the largest class name string.
*/
* @brief Get the maximal string size of all class names in the vector container.
* @param[in] signals containing all signals definitions which have to be checked.
* @param[in] ssTitle Reference to the title string. Is minimum of the return value.
* @return Returns the string size of the largest class name string.
*/
size_t GetMaxClassName(const std::vector<SSignalVDDefinition>& signals, const std::string& ssTitle) const;
/**
* @brief Get the maximal string size of all IDL type strings in the vector container.
* @param[in] signals containing all signals definitions which have to be checked.
* @param[in] ssTitle Reference to the title string. Is minimum of the return value.
* @return Returns the string size of the largest IDL type string.
*/
* @brief Get the maximal string size of all IDL type strings in the vector container.
* @param[in] signals containing all signals definitions which have to be checked.
* @param[in] ssTitle Reference to the title string. Is minimum of the return value.
* @return Returns the string size of the largest IDL type string.
*/
size_t GetMaxIDLType(const std::vector<SSignalVDDefinition>& signals, const std::string& ssTitle) const;
/**
* @brief Get the maximal string size of all ctype strings in the vector container.
* @param[in] signals containing all signals definitions which have to be checked.
* @param[in] ssTitle Reference to the title string. Is minimum of the return value.
* @return Returns the string size of the largest ctype string.
*/
* @brief Get the maximal string size of all ctype strings in the vector container.
* @param[in] signals containing all signals definitions which have to be checked.
* @param[in] ssTitle Reference to the title string. Is minimum of the return value.
* @return Returns the string size of the largest ctype string.
*/
size_t GetMaxCTypeFromIDLType(const std::vector<SSignalVDDefinition>& signals, const std::string& ssTitle) const;
/**
* @brief Get the maximal string size of all signal name strings in the vector container.
* @param[in] signals containing all signals definitions which have to be checked.
* @param[in] ssTitle Reference to the title string. Is minimum of the return value.
* @return Returns the string size of the largest signal names string.
*/
* @brief Get the maximal string size of all signal name strings in the vector container.
* @param[in] signals containing all signals definitions which have to be checked.
* @param[in] ssTitle Reference to the title string. Is minimum of the return value.
* @return Returns the string size of the largest signal names string.
*/
size_t GetMaxSignalName(const std::vector<SSignalVDDefinition>& signals, const std::string& ssTitle) const;
/**
* @brief Get the maximal string size of all CAN signal name strings in the vector container.
* @param[in] signals containing all signals definitions which have to be checked.
* @param[in] ssTitle Reference to the title string. Is minimum of the return value.
* @return Returns the string size of the largest signal names string.
*/
* @brief Get the maximal string size of all CAN signal name strings in the vector container.
* @param[in] signals containing all signals definitions which have to be checked.
* @param[in] ssTitle Reference to the title string. Is minimum of the return value.
* @return Returns the string size of the largest signal names string.
*/
size_t GetMaxCANSignalName(const std::vector<SSignalVDDefinition>& signals, const std::string& ssTitle) const;
/**
* @brief Get the maximal string size of all function name strings in the vector container.
* @param[in] signals containing all signals definitions which have to be checked.
* @param[in] ssTitle Reference to the title string. Is minimum of the return value.
* @return Returns the string size of the largest function names string.
*/
* @brief Get the maximal string size of all function name strings in the vector container.
* @param[in] signals containing all signals definitions which have to be checked.
* @param[in] ssTitle Reference to the title string. Is minimum of the return value.
* @return Returns the string size of the largest function names string.
*/
size_t GetMaxFunctionName(const std::vector<SSignalVDDefinition>& signals, const std::string& ssTitle) const;
/**
* @brief Get the maximal string size of all vss strings in the vector container.
* @param[in] signals containing all signals definitions which have to be checked.
* @param[in] ssTitle Reference to the title string. Is minimum of the return value.
* @return Returns the string size of the largest vss string.
*/
* @brief Get the maximal string size of all vss strings in the vector container.
* @param[in] signals containing all signals definitions which have to be checked.
* @param[in] ssTitle Reference to the title string. Is minimum of the return value.
* @return Returns the string size of the largest vss string.
*/
size_t GetMaxVSSDefinition(const std::vector<SSignalVDDefinition>& signals, const std::string& ssTitle) const;
/**
* @brief check for '.' characters in the string.
* @param[in] ssInput Reference to the input string to be checked.
* @param[in] mustBeEmpty If true input string must not be empty
* @return Returns true if string contains '.' or is empty depending on mustBeEmpty, otherwise false.
*/
* @brief check for '.' characters in the string.
* @param[in] ssInput Reference to the input string to be checked.
* @param[in] mustBeEmpty If true input string must not be empty
* @return Returns true if string contains '.' or is empty depending on mustBeEmpty, otherwise false.
*/
bool MustContainDotOrIsEmpty(const std::string& ssInput, bool mustBeEmpty) const;
/**
* @brief check if vss parts are string and no number. If number add '_'
* for vehicle.chassis.axel.01.left return vehicle.chassis.axel._01.left
* @param[in] ssInput Reference to the input string to be checked.
* @return Returns valid vss string.
*/
* @brief check if vss parts are string and no number. If number add '_'
* for vehicle.chassis.axel.01.left return vehicle.chassis.axel._01.left
* @param[in] ssInput Reference to the input string to be checked.
* @return Returns valid vss string.
*/
std::string ValidateVSSFormatNumbers(const std::string& ssInput) const;
/**
* @brief check if string is a number
* @param[in] ssInput Reference to the input string to be checked.
* @return Returns false if it is a number, otherwise true.
*/
* @brief check if string is a number
* @param[in] ssInput Reference to the input string to be checked.
* @return Returns false if it is a number, otherwise true.
*/
bool IsNumber(const std::string& ssInput) const;
/**
* @brief Returns input string or if empty, returns default string.
* @param[in] ssInput string
* @param[in] ssDefaultString string used as default if input string is empty
* @param[in] index number will be added to the default string.
* @return Returns input string or if empty returns default string added by the number.
*/
* @brief Returns input string or if empty, returns default string.
* @param[in] ssInput string
* @param[in] ssDefaultString string used as default if input string is empty
* @param[in] index number will be added to the default string.
* @return Returns input string or if empty returns default string added by the number.
*/
std::string GenerateDefaultIfEmpty(const std::string& ssInput, std::string ssDefaultString, const uint32_t& index) const;
/**
* @brief Returns input string but starts and ends with "'".
* @param[in] ssInput string
* @return Returns the input string with "'" added at the frond and the end.
*/
* @brief Returns input string but starts and ends with "'".
* @param[in] ssInput string
* @return Returns the input string with "'" added at the frond and the end.
*/
std::string AddQuotationMarks(const std::string& ssInput) const;
/**
* @brief Replaces some characters of the input string.
* @param[in] ssInput string.
* @param[in] from character to be replaced
* @param[in] to replacement character.
* @return Returns the string with replacements.
*/
* @brief Replaces some characters of the input string.
* @param[in] ssInput string.
* @param[in] from character to be replaced
* @param[in] to replacement character.
* @return Returns the string with replacements.
*/
std::string ReplaceCharacters(const std::string& ssInput, const std::string& from, const std::string& to) const;
/**
* @brief turn the input string to upper case
* @param[in] ssInput string.
* @return Returns the input string but all characters are upper case
*/
* @brief turn the input string to upper case
* @param[in] ssInput string.
* @return Returns the input string but all characters are upper case
*/
std::string ToUpper(const std::string& ssInput) const;
/**
* @brief remove the last part of the vss string
* @param[in] ssInput vss string
* @return Returns the string but removed the last part after charatcer '.'.
*/
* @brief remove the last part of the vss string
* @param[in] ssInput vss string
* @return Returns the string but removed the last part after charatcer '.'.
*/
std::string ShortenVSSString(const std::string& ssInput) const;
/**
* @brief add to the type a cast, for example for 'std::string' it adds "const std::string&'
* @param[in] ssSignalType the string representing the type
* @return Returns either original string or 'const' and '&' added.
*/
* @brief add to the type a cast, for example for 'std::string' it adds "const std::string&'
* @param[in] ssSignalType the string representing the type
* @return Returns either original string or 'const' and '&' added.
*/
std::string CastValueType(const std::string& ssSignalType) const;
/**
* @brief find IDL type and return CType
* @param[in] ssIDLType string representing IDL type
* @return CType string if IDL type found, otherwise empty string
*/
* @brief find IDL type and return CType
* @param[in] ssIDLType string representing IDL type
* @return CType string if IDL type found, otherwise empty string
*/
std::string GetCTypeFromIDLType(const std::string& ssIDLType) const;
/**
* @brief validate if all IDL type are valid
* @param[in] vecTypes container of the IDL types
* @param[in] silent information to console if not silent
* @return True if IDL types are valid, otherwise false
*/
* @brief validate if all IDL type are valid
* @param[in] vecTypes container of the IDL types
* @param[in] silent information to console if not silent
* @return True if IDL types are valid, otherwise false
*/
bool ValidateIDLTypes(const std::vector<std::string>& vecTypes, const bool silent) const;
/**
* @brief Create folder or sub folder
* @param[in] rootPath complete root path
* @param[in] subfolder in case this parameter is empty only root path is created otherwise rootPath + subfolder
* @return true if directory exists or is created successfully, otherwise false
*/
* @brief Create folder or sub folder
* @param[in] rootPath complete root path
* @param[in] subfolder in case this parameter is empty only root path is created otherwise rootPath + subfolder
* @return true if directory exists or is created successfully, otherwise false
*/
bool CreateFolder(const std::filesystem::path& rootPath, const std::string& subfolder) const;
/**
* @brief deletes a header file
* @param[in] path full path to a folder
* @param[in] fileNameNoExtension a file name without the extension
*/
* @brief deletes a header file
* @param[in] path full path to a folder
* @param[in] fileNameNoExtension a file name without the extension
*/
void DeleteHeaderFile(const std::filesystem::path& path, const std::string& fileNameNoExtension) const;
/**
* @brief Validates the code style (signal name starts with lower case, function name upper case ...
* @param[in] function function definition structure
* @param[in] verbose print information to console only if true
*/
* @brief Validates the code style (signal name starts with lower case, function name upper case ...
* @param[in] function function definition structure
* @param[in] verbose print information to console only if true
*/
void ValidateVDCodeStyle(const SFunctionVDDefinition& function, const bool verbose) const;
/**
* @brief Validates the code style (signal name starts with lower case, function name upper case ...
* @param[in] function function definition structure
* @param[in] verbose print information to console only if true
*/
* @brief Validates the code style (signal name starts with lower case, function name upper case ...
* @param[in] function function definition structure
* @param[in] verbose print information to console only if true
*/
void ValidateBSCodeStyle(const SFunctionBSDefinition& function, const bool verbose) const;
/**
* @brief Validates the code style (signal name starts with lower case, function name upper case ...
* @param[in] signal signal definition structure
* @param[in] verbose print information to console only if true
*/
* @brief Validates the code style (signal name starts with lower case, function name upper case ...
* @param[in] signal signal definition structure
* @param[in] verbose print information to console only if true
*/
void ValidateVDCodeStyle(const SSignalVDDefinition& signal, const bool verbose) const;
/**
* @brief Validates the code style (signal name starts with lower case, function name upper case ...
* @param[in] signal signal definition structure
* @param[in] verbose print information to console only if true
*/
* @brief Validates the code style (signal name starts with lower case, function name upper case ...
* @param[in] signal signal definition structure
* @param[in] verbose print information to console only if true
*/
void ValidateBSCodeStyle(const SSignalBSDefinition& signal, const bool verbose) const;
private:
/**
* @brief Declaration type name association.
*/
* @brief Declaration type name association.
*/
using TDeclTypeAssoc = std::pair<std::string, sdv::vss::EDeclType>;
/**
* @brief change EDeclType to cType string
* @param[in] eDeclType EDeclTyp type
* @return Returns cType stringif available, otherwise empty string
*/
* @brief change EDeclType to cType string
* @param[in] eDeclType EDeclTyp type
* @return Returns cType stringif available, otherwise empty string
*/
std::string MapDeclType2CType(const sdv::vss::EDeclType eDeclType) const;
/**
* @brief Mapping between declaration type and string name.
* @attention Some types have multiple string representatives (e.g. sdv::vss::EDeclType::decltype_short vs. 'short' and
* 'int16').
* @attention Based on the provided extensions on the command line, the types might be extended by: char16, char32, u8string,
* u16string, u32string, pointer, interface_id, interface_t and exception_id
*/
* @brief Mapping between declaration type and string name.
* @attention Some types have multiple string representatives (e.g. sdv::vss::EDeclType::decltype_short vs. 'short' and
* 'int16').
* @attention Based on the provided extensions on the command line, the types might be extended by: char16, char32, u8string,
* u16string, u32string, pointer, interface_id, interface_t and exception_id
*/
const std::vector<TDeclTypeAssoc> m_vecDeclTypes = {
{"short", sdv::vss::EDeclType::decltype_short},
{"unsigned short", sdv::vss::EDeclType::decltype_unsigned_short},

View File

@@ -1,3 +1,16 @@
/********************************************************************************
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Thomas Pfleiderer - initial API and implementation
********************************************************************************/
/**
* @brief file template for the RX signals (device header)
*/
@@ -21,15 +34,13 @@ const char szRXVehicleDeviceHeaderTemplate[] = R"code(/**
*/
class CVehicleDevice%class_name%
: public sdv::CSdvObject
, public sdv::IObjectControl
%rx_vd_interface_list%{
public:
BEGIN_SDV_INTERFACE_MAP()
SDV_INTERFACE_ENTRY(sdv::IObjectControl)
%rx_vd_interface_entry_list% END_SDV_INTERFACE_MAP()
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::Device)
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::vehicle_bus)
DECLARE_OBJECT_CLASS_NAME("%vss_original%_Device")
/**
@@ -37,32 +48,19 @@ public:
*/
CVehicleDevice%class_name%();
/**
* @brief initialize device to get the object name or use the default.
* @param[in] objectConfig Configuration containing the object name
*/
void Initialize(const sdv::u8string& objectConfig) override;
/**
* @brief Initialization event, called after object configuration was loaded. Overload of sdv::CSdvObject::OnInitialize.
* @return Returns 'true' when the initialization was successful, 'false' when not.
*/
virtual bool OnInitialize() override;
/**
* @brief Gets the current status of the object
* @return EObjectStatus The current status of the object
*/
sdv::EObjectStatus GetStatus() const override;
/**
* @brief Set the component operation mode. Overlovd of sdv::IObjectControl::SetOperationMode.
* @param[in] eMode The operation mode, the component should run in.
*/
void SetOperationMode(/*in*/ sdv::EOperationMode eMode) override;
/**
* @brief Shutdown function is to shutdown the execution of request thread
*/
void Shutdown() override;
/**
* @brief Shutdown the object. Overload of sdv::CSdvObject::OnShutdown.
*/
virtual void OnShutdown() override;
%rx_vd_register_events_list%
private:
%rx_vd_private_vd_header_part%
std::atomic<sdv::EObjectStatus> m_status = { sdv::EObjectStatus::initialization_pending }; ///< To update the object status when it changes.
};
DEFINE_SDV_OBJECT(CVehicleDevice%class_name%)
@@ -88,58 +86,17 @@ CVehicleDevice%class_name%::CVehicleDevice%class_name%()
{
}
/**
* @brief initialize device to get the object name or use the default.
* @param[in] objectConfig Configuration containing the object name
*/
void CVehicleDevice%class_name%::Initialize(const sdv::u8string&)
bool CVehicleDevice%class_name%::OnInitialize()
{
if (m_status != sdv::EObjectStatus::initialization_pending)
{
return;
}
sdv::core::CDispatchService dispatch;
%rx_vd_subscribe_signals%
%rx_check_subscriptions%
return true;
}
/**
* @brief Gets the current status of the object
* @return EObjectStatus The current status of the object
*/
sdv::EObjectStatus CVehicleDevice%class_name%::GetStatus() const
{
return m_status;
}
/**
* @brief Set the component operation mode. Overlovd of sdv::IObjectControl::SetOperationMode.
* @param[in] eMode The operation mode, the component should run in.
*/
void CVehicleDevice%class_name%::SetOperationMode(/*in*/ sdv::EOperationMode eMode)
{
switch (eMode)
{
case sdv::EOperationMode::configuring:
if (m_status == sdv::EObjectStatus::running || m_status == sdv::EObjectStatus::initialized)
m_status = sdv::EObjectStatus::configuring;
break;
case sdv::EOperationMode::running:
if (m_status == sdv::EObjectStatus::configuring || m_status == sdv::EObjectStatus::initialized)
m_status = sdv::EObjectStatus::running;
break;
default:
break;
}
}
/**
* @brief Shutdown function is to shutdown the execution of request thread
*/
void CVehicleDevice%class_name%::Shutdown()
void CVehicleDevice%class_name%::OnShutdown()
{
%rx_reset_signals%
m_status = sdv::EObjectStatus::destruction_pending;
}
%rx_vd_register%
)code";
@@ -171,7 +128,7 @@ public:
BEGIN_SDV_INTERFACE_MAP()
%rx_bs_interface_entry_list% END_SDV_INTERFACE_MAP()
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::BasicService)
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::device)
DECLARE_OBJECT_CLASS_NAME("%vss_original%_Service")
/**

View File

@@ -1,3 +1,16 @@
/********************************************************************************
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Thomas Pfleiderer - initial API and implementation
********************************************************************************/
/**
* @brief file template for the TX signals (device header)
*/
@@ -21,15 +34,13 @@ const char szTXVehicleDeviceHeaderTemplate[] = R"code(/**
*/
class CVehicleDevice%class_name%
: public sdv::CSdvObject
, public sdv::IObjectControl
%tx_vd_interface_list%{
public:
BEGIN_SDV_INTERFACE_MAP()
SDV_INTERFACE_ENTRY(sdv::IObjectControl)
%tx_vd_interface_entry_list% END_SDV_INTERFACE_MAP()
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::Device)
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::vehicle_bus)
DECLARE_OBJECT_CLASS_NAME("%vss_original%_Device")
/**
@@ -37,32 +48,19 @@ public:
*/
CVehicleDevice%class_name%();
/**
* @brief initialize device to get the object name or use the default.
* @param[in] objectConfig Configuration containing the object name
*/
void Initialize(const sdv::u8string& objectConfig) override;
/**
* @brief Initialization event, called after object configuration was loaded. Overload of sdv::CSdvObject::OnInitialize.
* @return Returns 'true' when the initialization was successful, 'false' when not.
*/
virtual bool OnInitialize() override;
/**
* @brief Gets the current status of the object
* @return EObjectStatus The current status of the object
*/
sdv::EObjectStatus GetStatus() const override;
/**
* @brief Set the component operation mode. Overlovd of sdv::IObjectControl::SetOperationMode.
* @param[in] eMode The operation mode, the component should run in.
*/
void SetOperationMode(/*in*/ sdv::EOperationMode eMode) override;
/**
* @brief Shutdown function is to shutdown the execution of request thread
*/
void Shutdown() override;
/**
* @brief Shutdown the object. Overload of sdv::CSdvObject::OnShutdown.
*/
virtual void OnShutdown() override;
%tx_vd_function_list%
private:
%tx_variable_list%
std::atomic<sdv::EObjectStatus> m_status = { sdv::EObjectStatus::initialization_pending }; ///< To update the object status when it changes.
};
DEFINE_SDV_OBJECT(CVehicleDevice%class_name%)
@@ -81,66 +79,21 @@ const char szTXVehicleDeviceClassTemplate[] = R"code(/**
#include <iostream>
#include "vd_%class_name_lowercase%.h"
/**
* @brief Constructor
*/
CVehicleDevice%class_name%::CVehicleDevice%class_name%()
{
}
/**
* @brief initialize device to get the object name or use the default.
* @param[in] objectConfig Configuration containing the object name
*/
void CVehicleDevice%class_name%::Initialize(const sdv::u8string&)
bool CVehicleDevice%class_name%::OnInitialize()
{
if (m_status != sdv::EObjectStatus::initialization_pending)
{
return;
}
sdv::core::CDispatchService dispatch;
%tx_variable_init_list%
%tx_variable_check_list%
return true;
}
/**
* @brief Gets the current status of the object
* @return EObjectStatus The current status of the object
*/
sdv::EObjectStatus CVehicleDevice%class_name%::GetStatus() const
{
return m_status;
}
/**
* @brief Set the component operation mode. Overlovd of sdv::IObjectControl::SetOperationMode.
* @param[in] eMode The operation mode, the component should run in.
*/
void CVehicleDevice%class_name%::SetOperationMode(/*in*/ sdv::EOperationMode eMode)
{
switch (eMode)
{
case sdv::EOperationMode::configuring:
if (m_status == sdv::EObjectStatus::running || m_status == sdv::EObjectStatus::initialized)
m_status = sdv::EObjectStatus::configuring;
break;
case sdv::EOperationMode::running:
if (m_status == sdv::EObjectStatus::configuring || m_status == sdv::EObjectStatus::initialized)
m_status = sdv::EObjectStatus::running;
break;
default:
break;
}
}
/**
* @brief Shutdown function is to shutdown the execution of request thread
*/
void CVehicleDevice%class_name%::Shutdown()
void CVehicleDevice%class_name%::OnShutdown()
{
%tx_reset_signals%
m_status = sdv::EObjectStatus::destruction_pending;
}
%tx_function_implementations%
@@ -169,10 +122,9 @@ class CBasicService%class_name%
public:
BEGIN_SDV_INTERFACE_MAP()
SDV_INTERFACE_ENTRY(sdv::CSdvObject)
%tx_bs_interface_entry_list% END_SDV_INTERFACE_MAP()
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::BasicService)
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::device)
DECLARE_OBJECT_CLASS_NAME("%vss_original%_Service")
/**

View File

@@ -1,3 +1,16 @@
/********************************************************************************
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Thomas Pfleiderer - initial API and implementation
********************************************************************************/
#include "vss_vd_codingrx.h"
void CVSSVDCodingRX::GetKeyWordMap(const SSignalVDDefinition& signal, CKeywordMap& mapKeywords) const
@@ -48,11 +61,6 @@ void CVSSVDCodingRX::GetKeyWordMap(const SSignalVDDefinition& signal, CKeywordMa
}
mapKeywords["rx_vd_subscribe_signals"] = std::move(sstreamVDSubscribe.str());
if (signal.vecFunctions.size() > 0)
{
mapKeywords["rx_check_subscriptions"] = Code_VD_RXCheckSignalSubscribtions(signal.vecFunctions);
}
std::stringstream sstreamVDResetSignal;
for (const auto& func : signal.vecFunctions)
{
@@ -361,34 +369,11 @@ std::string CVSSVDCodingRX::Code_VD_RXSubscribeSignal(const std::string& class_n
if (!m_%signal_name%Signal)
{
SDV_LOG_ERROR("Could not get signal: ", %object_prefix%::ds%start_with_uppercase%, " [CVehicleDevice%class_name%]");
return false;
}
)code", mapKeywords);
}
std::string CVSSVDCodingRX::Code_VD_RXCheckSignalSubscribtions(const std::vector <SFunctionVDDefinition>& vecFunctions) const
{
uint32_t count{ 0 };
std::stringstream sstreamFunctions;
sstreamFunctions << " if (!";
for (const auto& func : vecFunctions)
{
count++;
sstreamFunctions << "m_" << func.signalName << "Signal";
if (count != vecFunctions.size())
{
sstreamFunctions << " || !";
}
}
sstreamFunctions << ")" << std::endl;
sstreamFunctions << " {" << std::endl;
sstreamFunctions << " m_status = sdv::EObjectStatus::initialization_failure;" << std::endl;
sstreamFunctions << " return;" << std::endl;
sstreamFunctions << " }" << std::endl;
sstreamFunctions << " m_status = sdv::EObjectStatus::initialized;";
return sstreamFunctions.str();
}
std::string CVSSVDCodingRX::Code_VD_RXResetSignal(const SFunctionVDDefinition& function) const
{
CKeywordMap mapKeywords;

View File

@@ -1,3 +1,16 @@
/********************************************************************************
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Thomas Pfleiderer - initial API and implementation
********************************************************************************/
#ifndef VSS_VD_CODING_RX_H
#define VSS_VD_CODING_RX_H
@@ -17,7 +30,7 @@
/**
* @brief VSS code generator coding class for vehicle devices.
* Creates the code out of templates
*/
*/
class CVSSVDCodingRX : public CCodeGeneratorBase, CVSSHelper
{
@@ -29,125 +42,118 @@ public:
CVSSVDCodingRX(const std::string& rsPrefix) : m_ssPrefix(rsPrefix) {}
/**
* @brief create device content for the IDL file of a RX signal
* @param[in] vssParts Interface in vss style separated in parts
* @param[in] vecFunctions container of all functions of a single vss definition
* @return content of the Device part of a IDL Interface of a RX signal
*/
* @brief create device content for the IDL file of a RX signal
* @param[in] vssParts Interface in vss style separated in parts
* @param[in] vecFunctions container of all functions of a single vss definition
* @return content of the Device part of a IDL Interface of a RX signal
*/
std::string Code_RXIDLDeviceList(const std::vector<std::string>& vssParts, const std::vector <SFunctionVDDefinition>& vecFunctions) const;
/**
* @brief create service content for the IDL file of a RX signal
* @param[in] vssParts Interface in vss style separated in parts
* @param[in] vecFunctions container of all functions of a single vss definition
* @return content of the Device part of a IDL Interface of a RX signal
*/
* @brief create service content for the IDL file of a RX signal
* @param[in] vssParts Interface in vss style separated in parts
* @param[in] vecFunctions container of all functions of a single vss definition
* @return content of the Device part of a IDL Interface of a RX signal
*/
std::string Code_RXIDLServiceList(const std::vector<std::string>& vssParts, const std::vector <SFunctionVDDefinition>& vecFunctions) const;
/**
* @brief fill the KeyWordMap with all required strings
* @param[in] signal signal definition structure to fill the KeyWordMap
* @param[in] mapKeywords KeyWordMap to be filled
*/
* @brief fill the KeyWordMap with all required strings
* @param[in] signal signal definition structure to fill the KeyWordMap
* @param[in] mapKeywords KeyWordMap to be filled
*/
void GetKeyWordMap(const SSignalVDDefinition& signal, CKeywordMap& mapKeywords) const;
protected:
/**
* @brief create single or multiple lines containing include files
* @param[in] vssOriginalNoDot vss string without points e.g. VehicleChassisSteeringWheelAngle
* @return content of a single interface
*/
* @brief create single or multiple lines containing include files
* @param[in] vssOriginalNoDot vss string without points e.g. VehicleChassisSteeringWheelAngle
* @return content of a single interface
*/
std::string Code_VD_RXIncludes(const std::string& vssOriginalNoDot) const;
/**
* @brief create a single line containing a interface
* @param[in] functionName function which is part of the interface
* @param[in] vssShortenWithColons vss string (short version) with colons as separator
* @return content of a single interface
*/
* @brief create a single line containing a interface
* @param[in] functionName function which is part of the interface
* @param[in] vssShortenWithColons vss string (short version) with colons as separator
* @return content of a single interface
*/
std::string Code_VD_RXInterface(const std::string& functionName, const std::string& vssShortenWithColons) const;
/**
* @brief create a single line containing a interface entry
* @param[in] functionName function which is part of the interface
* @param[in] vssWithColons vss string (complete version) with colons as separator
* @return content of a single interface entry
*/
* @brief create a single line containing a interface entry
* @param[in] functionName function which is part of the interface
* @param[in] vssWithColons vss string (complete version) with colons as separator
* @return content of a single interface entry
*/
std::string Code_VD_RXInterfaceEntry(const std::string& functionName, const std::string& vssWithColons) const;
/**
* @brief Get the register and unregister part for the RX VD header
* @param[in] vssWithColons vss string (complete version) with colons as separator
* @param[in] function function definition structure
* @return content of a single register and unregister part.
*/
* @brief Get the register and unregister part for the RX VD header
* @param[in] vssWithColons vss string (complete version) with colons as separator
* @param[in] function function definition structure
* @return content of a single register and unregister part.
*/
std::string Code_VD_RXReAndUnregisterEvent(const std::string& vssWithColons, const SFunctionVDDefinition& function) const;
/**
* @brief Get the private header part of the vehicle device header
* @param[in] function function definition structure
* @param[in] vssWithColons vss string (complete version) with colons as separator
* @param[in] class_name class name which is part of the interface
* @return content of private header part of the vehicle device header
*/
* @brief Get the private header part of the vehicle device header
* @param[in] function function definition structure
* @param[in] vssWithColons vss string (complete version) with colons as separator
* @param[in] class_name class name which is part of the interface
* @return content of private header part of the vehicle device header
*/
std::string Code_VD_RXPrivateHeaderPart(const SFunctionVDDefinition& function, const std::string& vssWithColons,
const std::string& class_name) const;
/**
* @brief create device content for the IDL file of a RX signal
* @param[in] spaces string containing only space characters for aligning
* @param[in] function function definition structure
* @return content of the Device part of a IDL Interface of a RX signal
*/
* @brief create device content for the IDL file of a RX signal
* @param[in] spaces string containing only space characters for aligning
* @param[in] function function definition structure
* @return content of the Device part of a IDL Interface of a RX signal
*/
std::string Code_RXIDLDeviceInterface(const std::string& spaces, const SFunctionVDDefinition& function) const;
/**
* @brief create service content for the IDL file of a RX signal
* @param[in] spaces string containing only space characters for aligning
* @param[in] vssWithColons vss string (complete version) with colons as separator
* @param[in] function function definition structure
* @return content of the Device part of a IDL Interface of a RX signal
*/
* @brief create service content for the IDL file of a RX signal
* @param[in] spaces string containing only space characters for aligning
* @param[in] vssWithColons vss string (complete version) with colons as separator
* @param[in] function function definition structure
* @return content of the Device part of a IDL Interface of a RX signal
*/
std::string Code_RXIDLServiceInterface(const std::string& spaces, const std::string& vssWithColons,
const SFunctionVDDefinition& function) const;
/**
* @brief subscribe signals (RX type) for vehicle device
* @param[in] class_name class name which is part of the interface
* @param[in] function function definition structure
* @return content of a initializing code
*/
* @brief subscribe signals (RX type) for vehicle device
* @param[in] class_name class name which is part of the interface
* @param[in] function function definition structure
* @return content of a initializing code
*/
std::string Code_VD_RXSubscribeSignal(const std::string& class_name, const SFunctionVDDefinition& function) const;
/**
* @brief subscribe signals (RX type) for vehicle device
* @param[in] vecFunctions list of functions of the vss interface
* @return content of a initializing code
*/
std::string Code_VD_RXCheckSignalSubscribtions(const std::vector <SFunctionVDDefinition>& vecFunctions) const;
/**
* @brief Rest signal (RX signals) for vehicle device cpp file
* @param[in] function function definition structure
* @return content of a single signal reset implementation
*/
* @brief Rest signal (RX signals) for vehicle device cpp file
* @param[in] function function definition structure
* @return content of a single signal reset implementation
*/
std::string Code_VD_RXResetSignal(const SFunctionVDDefinition& function) const;
/**
* @brief create register/unregister and callback function code for vehicle device
* @param[in] class_name class name which is part of the interface
* @param[in] function function definition structure
* @param[in] vssWithColons vss string with colons as separator
* @return content of a single signal register/unregister and callback code
*/
* @brief create register/unregister and callback function code for vehicle device
* @param[in] class_name class name which is part of the interface
* @param[in] function function definition structure
* @param[in] vssWithColons vss string with colons as separator
* @return content of a single signal register/unregister and callback code
*/
std::string Code_VD_RXRegister(const std::string& class_name, const SFunctionVDDefinition& function,
const std::string& vssWithColons) const;
/**
* @brief create code to get the value or use use user defined c++ code
* @param[in] function function definition structure
* @return default code to get the value
*/
* @brief create code to get the value or use use user defined c++ code
* @param[in] function function definition structure
* @return default code to get the value
*/
std::string Code_VD_RXFormular(const SFunctionVDDefinition& function) const;
std::string m_ssPrefix; ///< prefix, used by cmake library and signal definition in signal_identifier.h file.

View File

@@ -1,3 +1,16 @@
/********************************************************************************
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Thomas Pfleiderer - initial API and implementation
********************************************************************************/
#include "vss_vd_codingtx.h"
void CVSSVDCodingTX::GetKeyWordMap(const SSignalVDDefinition& signal, CKeywordMap& mapKeywords) const
@@ -257,6 +270,7 @@ std::string CVSSVDCodingTX::Code_VD_TXVariableInitialization(const SFunctionVDDe
if (!m_%signal_name%)
{
SDV_LOG_ERROR("Could not get signal: ", %object_prefix%::ds%start_with_uppercase%, " [CVehicleDevice%class_name%]");
return false;
}
)code", mapKeywords);
}
@@ -277,10 +291,8 @@ std::string CVSSVDCodingTX::Code_VD_TXVariableCheckInitialization(const std::vec
}
sstreamFunctions << ")" << std::endl;
sstreamFunctions << " {" << std::endl;
sstreamFunctions << " m_status = sdv::EObjectStatus::initialization_failure;" << std::endl;
sstreamFunctions << " return;" << std::endl;
sstreamFunctions << " return false;" << std::endl;
sstreamFunctions << " }" << std::endl;
sstreamFunctions << " m_status = sdv::EObjectStatus::initialized;";
return sstreamFunctions.str();
}

View File

@@ -1,3 +1,16 @@
/********************************************************************************
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Thomas Pfleiderer - initial API and implementation
********************************************************************************/
#ifndef VSS_CODING_TX_H
#define VSS_CODING_TX_H
@@ -16,7 +29,7 @@
/**
* @brief VSS code generator coding class.
* Creates the code out of templates
*/
*/
class CVSSVDCodingTX : public CCodeGeneratorBase, CVSSHelper
{
@@ -28,94 +41,94 @@ public:
CVSSVDCodingTX(const std::string& rsPrefix) : m_ssPrefix(rsPrefix) {}
/**
* @brief create vehicle device content for the IDL file of a TX signal
* @param[in] vssParts Interface in vss style separated in parts
* @param[in] vecFunctions container of all functions of a single vss definition
* @return content of the vehicle device part of a IDL Interface of a TX signal
*/
* @brief create vehicle device content for the IDL file of a TX signal
* @param[in] vssParts Interface in vss style separated in parts
* @param[in] vecFunctions container of all functions of a single vss definition
* @return content of the vehicle device part of a IDL Interface of a TX signal
*/
std::string Code_VD_TXIDLList(const std::vector<std::string>& vssParts,
const std::vector <SFunctionVDDefinition>& vecFunctions) const;
/**
* @brief fill the KeyWordMap with all required strings
* @param[in] signal signal definition structure to fill the KeyWordMap
* @param[in] mapKeywords KeyWordMap to be filled
*/
* @brief fill the KeyWordMap with all required strings
* @param[in] signal signal definition structure to fill the KeyWordMap
* @param[in] mapKeywords KeyWordMap to be filled
*/
void GetKeyWordMap(const SSignalVDDefinition& signal, CKeywordMap& mapKeywords) const;
protected:
/**
* @brief create single or multiple lines containing include files
* @param[in] vssOriginalNoDot vss string without points e.g. VehicleChassisSteeringWheelAngle
* @return content of a single interface
*/
* @brief create single or multiple lines containing include files
* @param[in] vssOriginalNoDot vss string without points e.g. VehicleChassisSteeringWheelAngle
* @return content of a single interface
*/
std::string Code_VD_TXIncludes(const std::string& vssOriginalNoDot) const;
/**
* @brief create a single line containing a interface for vehicle device
* @param[in] functionName function which is part of the interface
* @param[in] vssWithColons vss string (complete version) with colons as separator
* @return content of a single interface
*/
* @brief create a single line containing a interface for vehicle device
* @param[in] functionName function which is part of the interface
* @param[in] vssWithColons vss string (complete version) with colons as separator
* @return content of a single interface
*/
std::string Code_VD_TXInterface(const std::string& functionName, const std::string& vssWithColons) const;
/**
* @brief create a single line containing a interface entry for vehicle device
* @param[in] functionName function which is part of the interface
* @param[in] vssWithColons vss string (complete version) with colons as separator
* @return content of a single interface entry
*/
* @brief create a single line containing a interface entry for vehicle device
* @param[in] functionName function which is part of the interface
* @param[in] vssWithColons vss string (complete version) with colons as separator
* @return content of a single interface entry
*/
std::string Code_VD_TXInterfaceEntry(const std::string& functionName, const std::string& vssWithColons) const;
/**
* @brief create list of interfaces (TX signals) for IDL file (Vehicle Device)
* @param[in] spaces string containing only space characters for aligning
* @param[in] function function definition structure
* @return content of a single interface entry
*/
* @brief create list of interfaces (TX signals) for IDL file (Vehicle Device)
* @param[in] spaces string containing only space characters for aligning
* @param[in] function function definition structure
* @return content of a single interface entry
*/
std::string Code_VD_TXIDLInterface(const std::string& spaces, const SFunctionVDDefinition& function) const;
/**
* @brief create function definition part (TX signals) for vehicle device
* @param[in] function function definition structure
* @return content of a single function declaration
*/
* @brief create function definition part (TX signals) for vehicle device
* @param[in] function function definition structure
* @return content of a single function declaration
*/
std::string Code_VD_TXFunction(const SFunctionVDDefinition& function) const;
/**
* @brief Rest signal (TX signals) for vehicle device cpp file
* @param[in] function function definition structure
* @return content of a single signal reset implementation
*/
* @brief Rest signal (TX signals) for vehicle device cpp file
* @param[in] function function definition structure
* @return content of a single signal reset implementation
*/
std::string Code_VD_TXResetSignal(const SFunctionVDDefinition& function) const;
/**
* @brief create function implementation part (TX signals) for vehicle device cpp file
* @param[in] function function definition structure
* @param[in] className class name of the signal
* @return content of a single function implementation
*/
* @brief create function implementation part (TX signals) for vehicle device cpp file
* @param[in] function function definition structure
* @param[in] className class name of the signal
* @return content of a single function implementation
*/
std::string Code_VD_TXFunctionImplementation(const SFunctionVDDefinition& function, const std::string& className) const;
/**
* @brief create single variable definition (TX signals) for vehicle device header
* @param[in] signalName name of the signal
* @return content of a single variable definition
*/
* @brief create single variable definition (TX signals) for vehicle device header
* @param[in] signalName name of the signal
* @return content of a single variable definition
*/
std::string Code_VD_TXVariable(const std::string& signalName) const;
/**
* @brief create single variable initialization (TX signals) for vehicle device cpp file
* @param[in] function which is part of the interface
* @return content of a single variable initialization
*/
* @brief create single variable initialization (TX signals) for vehicle device cpp file
* @param[in] function which is part of the interface
* @return content of a single variable initialization
*/
std::string Code_VD_TXVariableInitialization(const SFunctionVDDefinition& function) const;
/**
* @brief create check if all interfaces are valid (TX signals) for vehicle device cpp file
* @param[in] vecFunctions container of all functions of a single vss definition
* @return content to check if all interfaces are valid
*/
* @brief create check if all interfaces are valid (TX signals) for vehicle device cpp file
* @param[in] vecFunctions container of all functions of a single vss definition
* @return content to check if all interfaces are valid
*/
std::string Code_VD_TXVariableCheckInitialization(const std::vector <SFunctionVDDefinition>& vecFunctions) const;
std::string m_ssPrefix; ///< prefix, used by cmake library and signal definition in signal_identifier.h file.

View File

@@ -1,3 +1,16 @@
/********************************************************************************
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Thomas Pfleiderer - initial API and implementation
********************************************************************************/
#include "vss_vd_generator.h"
#include "vss_coding.h"
#include "vss_vd_codingrx.h"
@@ -99,7 +112,7 @@ void CVSSVDGenerator::CreateFiles(const std::string& ssVersion)
CreateTXFiles(ssVersion);
}
void CVSSVDGenerator::CreateRXFiles(const std::string& ssVersion) const
void CVSSVDGenerator::CreateRXFiles(const std::string& ssVersion)
{
for (const auto& rxSignal : m_RXsignals)
{
@@ -111,7 +124,7 @@ void CVSSVDGenerator::CreateRXFiles(const std::string& ssVersion) const
}
}
void CVSSVDGenerator::CreateVehicleDeviceFilesForRXSignal(const SSignalVDDefinition& signal, const std::string& ssVersion) const
void CVSSVDGenerator::CreateVehicleDeviceFilesForRXSignal(const SSignalVDDefinition& signal, const std::string& ssVersion)
{
std::string folderName = "VD_";
folderName.append(signal.className);
@@ -127,7 +140,10 @@ void CVSSVDGenerator::CreateVehicleDeviceFilesForRXSignal(const SSignalVDDefinit
std::ofstream fstreamVDHeader;
std::ofstream fstreamVDClass;
auto pathLowerCaseHeader = MakeLowercaseFilename(pathVDHeader);
auto pathLowerCaseClass = MakeLowercaseFilename(pathVDClass);
auto pathLowerCaseClass = MakeLowercaseFilename(pathVDClass);
m_createdFiles.push_back(pathLowerCaseHeader);
m_createdFiles.push_back(pathLowerCaseClass);
fstreamVDHeader.open(pathLowerCaseHeader, std::ios::out | std::ios::trunc);
fstreamVDClass.open(pathLowerCaseClass, std::ios::out | std::ios::trunc);
@@ -211,18 +227,27 @@ void CVSSVDGenerator::CreateVehicleDeviceFilesForTXSignal(const SSignalVDDefinit
std::string folderName = "VD_";
folderName.append(signal.className);
std::transform(folderName.begin(), folderName.end(), folderName.begin(),
[](unsigned char c) { return static_cast<char>(std::tolower(c)); });
[](unsigned char c) { return static_cast<char>(std::tolower(c)); });
if (!CreateFolder(m_pathProject, folderName))
{
return;
}
std::filesystem::path pathVDHeader = m_pathProject / folderName / AppendExtension("VD_", signal.className, ".h");
std::filesystem::path pathVDClass = m_pathProject / folderName / AppendExtension("VD_", signal.className, ".cpp");
std::filesystem::path pathCMakeLists = m_pathProject / folderName / "CMakeLists.txt";
std::ofstream fstreamVDHeader;
std::ofstream fstreamVDClass;
auto pathLowerCaseHeader = MakeLowercaseFilename(pathVDHeader);
auto pathLowerCaseClass = MakeLowercaseFilename(pathVDClass);
auto pathLowerCaseClass = MakeLowercaseFilename(pathVDClass);
auto headerExists = std::find(m_createdFiles.begin(), m_createdFiles.end(), pathLowerCaseHeader) != m_createdFiles.end();
auto classExists = std::find(m_createdFiles.begin(), m_createdFiles.end(), pathLowerCaseClass) != m_createdFiles.end();
if (headerExists || classExists)
{
UpdateExistingFiles(m_pathProject, folderName, signal);
return;
}
fstreamVDHeader.open(pathLowerCaseHeader, std::ios::out | std::ios::trunc);
fstreamVDClass.open(pathLowerCaseClass, std::ios::out | std::ios::trunc);
@@ -282,3 +307,172 @@ void CVSSVDGenerator::CreateIDLVehicleDeviceFileForTXSignal(const SSignalVDDefin
fstreamVDTXIDL << ReplaceKeywords(szVDTXIDLTemplate, mapKeywords);
fstreamVDTXIDL.close();
}
bool CVSSVDGenerator::UpdateExistingFiles(const std::filesystem::path& rootPath, const std::string& subfolder, const SSignalVDDefinition& signal) const
{
std::filesystem::path path = rootPath / subfolder;
CKeywordMap mapKeywords;
CVSSVDCodingTX codingTX(m_ssPrefix);
codingTX.GetKeyWordMap(signal, mapKeywords);
auto initializeList = mapKeywords["tx_variable_init_list"];
auto functionImplementation = mapKeywords["tx_function_implementations"];
if (UpdateCppFile(path, signal, initializeList, functionImplementation))
{
auto includeList = mapKeywords["tx_vd_includes_list"];
auto interfaceList = mapKeywords["tx_vd_interface_list"];
auto interfaceEntryList = mapKeywords["tx_vd_interface_entry_list"];
auto functionList = mapKeywords["tx_vd_function_list"];
auto variablePointerList = mapKeywords["tx_variable_list"];
if (UpdateHeaderFile(path, signal, includeList, interfaceList, interfaceEntryList, functionList, variablePointerList))
{
return true;
}
}
return false;
}
bool CVSSVDGenerator::UpdateCppFile(const std::filesystem::path& rootFolder, const SSignalVDDefinition& signal, const std::string& initializeList, const std::string& implementation) const
{
std::filesystem::path pathVDCpp = rootFolder / AppendExtension("VD_", signal.className, ".cpp");
auto pathLowerCaseCpp = MakeLowercaseFilename(pathVDCpp);
std::ifstream in(pathLowerCaseCpp);
if (!in)
{
std::cerr << "Failed to read file '" << pathLowerCaseCpp << ")\n";
return false;
}
std::string s;
std::vector<std::string> lines; // write new file into memory
while (std::getline(in, s))
{
lines.push_back(s);
if (s.find("sdv::core::CDispatchService dispatch;") != std::string::npos)
{
lines.push_back(initializeList);
break;
}
}
while (std::getline(in, s))
{
lines.push_back(s);
}
lines.push_back(implementation); // implementation at end of file
in.close();
std::error_code ec;
std::filesystem::remove(pathLowerCaseCpp, ec); // delete file
if (ec)
{
std::cerr << "Failed to delete file '" << pathLowerCaseCpp << "': " << ec.message() << " (error code: " << ec.value() << ")\n";
return false;
}
std::ofstream out(pathLowerCaseCpp, std::ios::trunc);
if (!out)
{
std::cerr << "Failed to write file '" << pathLowerCaseCpp << ")\n";
return false;
}
for (const auto& line : lines)
out << line << "\n";
out.close();
return true;
}
bool CVSSVDGenerator::UpdateHeaderFile(const std::filesystem::path& rootFolder, const SSignalVDDefinition& signal, const std::string& includeList,
const std::string& interfaceList, const std::string& interfaceEntryList, const std::string& functionList, const std::string& variablePointerList) const
{
std::filesystem::path pathVDHeader = rootFolder / AppendExtension("VD_", signal.className, ".h");
auto pathLowerCaseHeader = MakeLowercaseFilename(pathVDHeader);
std::ifstream in(pathLowerCaseHeader);
if (!in)
{
std::cerr << "Failed to read file '" << pathLowerCaseHeader << ")\n";
return false;
}
std::string s;
std::vector<std::string> lines; // write new file into memory
while (std::getline(in, s))
{
lines.push_back(s);
if (s.find("<support/signal_support.h>") != std::string::npos)
{
lines.push_back(includeList);
break;
}
}
while (std::getline(in, s))
{
lines.push_back(s);
if (s.find(", public") != std::string::npos)
{
lines.push_back(interfaceList);
break;
}
}
while (std::getline(in, s))
{
lines.push_back(s);
if (s.find("BEGIN_SDV_INTERFACE_MAP()") != std::string::npos)
{
lines.push_back(interfaceEntryList);
break;
}
}
while (std::getline(in, s))
{
if (s.find("private:") != std::string::npos)
{
lines.push_back(functionList); // we need to add entries before and after
lines.push_back(s);
lines.push_back(variablePointerList);
break;
}
lines.push_back(s);
}
while (std::getline(in, s))
{
lines.push_back(s);
}
in.close();
std::error_code ec;
std::filesystem::remove(pathLowerCaseHeader, ec); // delete file
if (ec)
{
std::cerr << "Failed to delete file '" << pathLowerCaseHeader << "': " << ec.message() << " (error code: " << ec.value() << ")\n";
return false;
}
std::ofstream out(pathLowerCaseHeader, std::ios::trunc);
if (!out)
{
std::cerr << "Failed to write file '" << pathLowerCaseHeader << ")\n";
return false;
}
for (const auto& line : lines) // write new file to disc
out << line << "\n";
out.close();
return true;
}

View File

@@ -1,3 +1,16 @@
/********************************************************************************
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Thomas Pfleiderer - initial API and implementation
********************************************************************************/
#ifndef VSS_VD_GENERATOR_H
#define VSS_VD_GENERATOR_H
@@ -36,74 +49,109 @@ public:
private:
/**
* @brief create content of the summary tect file
* @return string containing the complete content of the summary text file;
*/
* @brief create content of the summary tect file
* @return string containing the complete content of the summary text file;
*/
std::string SummaryTextFile() const;
/**
* @brief create a file name including prefix and extension
* @param[in] prefix
* @param[in] filename
* @param[in] extension
* @return combined file name
*/
* @brief create a file name including prefix and extension
* @param[in] prefix
* @param[in] filename
* @param[in] extension
* @return combined file name
*/
std::string AppendExtension(const std::string& prefix, const std::string& filename, const std::string& extension) const;
/**
* @brief create vehicle device and basic service .h an .cpp files
* create IDL files
* @param[in] ssVersion optional information will be placed in the header of the files
*/
* @brief create vehicle device and basic service .h an .cpp files
* create IDL files
* @param[in] ssVersion optional information will be placed in the header of the files
*/
void CreateFiles(const std::string& ssVersion);
/**
* @brief create IDL files and vehicle device and basic service files of RX signals
* @param[in] ssVersion optional information will be placed in the header of the files
*/
void CreateRXFiles(const std::string& ssVersion) const;
* @brief create IDL files and vehicle device and basic service files of RX signals
* @param[in] ssVersion optional information will be placed in the header of the files
*/
void CreateRXFiles(const std::string& ssVersion);
/**
* @brief create vehicle device files of a single RX signal
* @param[in] signal single signal definition
* @param[in] ssVersion optional information will be placed in the header of the files
*/
void CreateVehicleDeviceFilesForRXSignal(const SSignalVDDefinition& signal, const std::string& ssVersion) const;
* @brief create vehicle device files of a single RX signal
* @param[in] signal single signal definition
* @param[in] ssVersion optional information will be placed in the header of the files
*/
void CreateVehicleDeviceFilesForRXSignal(const SSignalVDDefinition& signal, const std::string& ssVersion);
/**
* @brief create IDL file of a single RX signal (vehicle device)
* @param[in] signal single signal definition
* @param[in] ssVersion optional information will be placed in the header of the files
*/
* @brief create IDL file of a single RX signal (vehicle device)
* @param[in] signal single signal definition
* @param[in] ssVersion optional information will be placed in the header of the files
*/
void CreateIDLVehicleDeviceFileForRXSignal(const SSignalVDDefinition& signal, const std::string& ssVersion) const;
/**
* @brief create IDL files and vehicle device and basic service files of TX signals
* @param[in] ssVersion optional information will be placed in the header of the files
*/
* @brief create IDL files and vehicle device and basic service files of TX signals
* @param[in] ssVersion optional information will be placed in the header of the files
*/
void CreateTXFiles(const std::string& ssVersion) const;
/**
* @brief create vehicle device files of a single TX signal
* @param[in] signal single signal definition
* @param[in] ssVersion optional information will be placed in the header of the files
*/
* @brief create vehicle device files of a single TX signal
* @param[in] signal single signal definition
* @param[in] ssVersion optional information will be placed in the header of the files
*/
void CreateVehicleDeviceFilesForTXSignal(const SSignalVDDefinition& signal, const std::string& ssVersion) const;
/**
* @brief create IDL file for a single TX signal (vehicle device)
* @param[in] signal single signal definition
* @param[in] ssVersion optional information will be placed in the header of the files
*/
* @brief create IDL file for a single TX signal (vehicle device)
* @param[in] signal single signal definition
* @param[in] ssVersion optional information will be placed in the header of the files
*/
void CreateIDLVehicleDeviceFileForTXSignal(const SSignalVDDefinition& signal, const std::string& ssVersion) const;
bool m_enableComponentCreation; ///< if set, the code for the components are created, otherwise only idl files
std::string m_ssPrefix; ///< prefix, used by cmake library and signal definition in signal_identifier.h file.
std::string m_ssVersion; ///< optional version tag, will be wriiten in header of the files
std::filesystem::path m_pathProject; ///< Project file path
std::vector <SSignalVDDefinition> m_signals; ///< all signals
std::vector <SSignalVDDefinition> m_TXsignals; ///< vector containing the RX signals
std::vector <SSignalVDDefinition> m_RXsignals; ///< vector containing the TX signals
/**
* @brief In case a RX signal and TX signal have the same vss name we need to update the existing rx signal files
* @param[in] rootPath complete root path
* @param[in] subfolder subfolder of the rx signal files
* @return true if files could be updated successfully, otherwise false
*/
bool UpdateExistingFiles(const std::filesystem::path& rootPath, const std::string& subfolder, const SSignalVDDefinition& signal) const;
/**
* @brief Update existing cpp file of a rx signal
* @param[in] rootPath complete root path
* @param[in] signal single signal definition
* @param[in] initializeList list of interfaces for the initialization method
* @param[in] implementation function implementation methods
* @return true if file could be updated successfully, otherwise false
*/
bool UpdateCppFile(const std::filesystem::path& rootFolder, const SSignalVDDefinition& signal, const std::string& initializeList, const std::string& implementation) const;
/**
* @brief Update existing cpp file of a rx signal
* @param[in] rootPath complete root path
* @param[in] signal single signal definition
* @param[in] includeList list of headers to be included
* @param[in] interfaceList list if interfaces
* @param[in] interfaceEntryList list of event entry interfaces
* @param[in] functionList list of function definitions
* @param[in] variablePointerList list of interface pointers
* @return true if file could be updated successfully, otherwise false
*/
bool UpdateHeaderFile(const std::filesystem::path& rootFolder, const SSignalVDDefinition& signal, const std::string& includeList,
const std::string& interfaceList, const std::string& interfaceEntryList, const std::string& functionList, const std::string& variablePointerList) const;
bool m_enableComponentCreation; ///< if set, the code for the components are created, otherwise only idl files
std::string m_ssPrefix; ///< prefix, used by cmake library and signal definition in signal_identifier.h file.
std::string m_ssVersion; ///< optional version tag, will be written in header of the files
std::filesystem::path m_pathProject; ///< Project file path
std::vector <SSignalVDDefinition> m_signals; ///< all signals
std::vector <SSignalVDDefinition> m_TXsignals; ///< vector containing the RX signals
std::vector <SSignalVDDefinition> m_RXsignals; ///< vector containing the TX signals
std::vector<std::filesystem::path> m_createdFiles; ///< collect all files created when the RX signals are processed
};
#endif // !defined VSS_VD_GENERATOR_H