update open trunk example (#12)

This commit is contained in:
tompzf
2026-04-17 20:05:48 +02:00
committed by GitHub
parent 79c06f6efd
commit 56d0d186c1
14 changed files with 213 additions and 264 deletions

View File

@@ -211,6 +211,11 @@ add_custom_target(platform_doors_config
) )
# used for a sdv_packager example in the documentation
file (COPY ${PROJECT_SOURCE_DIR}/coreconfig/platform.toml DESTINATION ${CMAKE_BINARY_DIR}/bin/new_instance)
###################################################################################################################################################################### ######################################################################################################################################################################
# the FMU files have been created via the dbc file # the FMU files have been created via the dbc file
# ..\\..\\build\\<configurePreset>\\bin\\sdv_dbc_util datalink_2doors_example.dbc -Ogenerated\\ --nodesdoors --version1.0.0.1 --moduleDoors2ExampleFMU --dl_lib_namecan_dl_door # ..\\..\\build\\<configurePreset>\\bin\\sdv_dbc_util datalink_2doors_example.dbc -Ogenerated\\ --nodesdoors --version1.0.0.1 --moduleDoors2ExampleFMU --dl_lib_namecan_dl_door

View File

@@ -17,7 +17,7 @@
#include <fcntl.h> #include <fcntl.h>
#endif #endif
bool CDoorExternControl::Initialize() bool CDoorExternControl::Initialize(uint32_t uiInstance)
{ {
if (m_bInitialized) if (m_bInitialized)
return true; return true;
@@ -31,7 +31,7 @@ bool CDoorExternControl::Initialize()
std::stringstream sstreamAppConfig; std::stringstream sstreamAppConfig;
sstreamAppConfig << "[Application]" << std::endl; sstreamAppConfig << "[Application]" << std::endl;
sstreamAppConfig << "Mode=\"External\"" << std::endl; sstreamAppConfig << "Mode=\"External\"" << std::endl;
sstreamAppConfig << "Instance=\"3002\"" << std::endl; sstreamAppConfig << "Instance=" << uiInstance << std::endl;
sstreamAppConfig << "Retries=" << 6 << std::endl; sstreamAppConfig << "Retries=" << 6 << std::endl;
sstreamAppConfig << "[Console]" << std::endl; sstreamAppConfig << "[Console]" << std::endl;
sstreamAppConfig << "Report=\"Silent\"" << std::endl; sstreamAppConfig << "Report=\"Silent\"" << std::endl;

View File

@@ -12,10 +12,39 @@
#include "../door_app/include/door_extern_application.h" #include "../door_app/include/door_extern_application.h"
#include "../door_app/include/console.h" #include "../door_app/include/console.h"
int main() #if defined(_WIN32) && defined(_UNICODE)
extern "C" int wmain(int argc, wchar_t* argv[])
{ {
uint32_t uiInstance = 3002;
if (argc >= 2)
{
try
{
uiInstance = std::stoi(argv[1]);
}
catch (const std::exception& )
{
}
}
#else
extern "C" int main(int argc, char* argv[])
{
uint32_t uiInstance = 3002;
if (argc < 2)
{
try
{
uiInstance = std::stoi(argv[1]);
}
catch (const std::exception& )
{
}
}
#endif
CDoorExternControl appobj; CDoorExternControl appobj;
if (!appobj.Initialize()) if (!appobj.Initialize(uiInstance))
{ {
std::cout << "ERROR: Failed to initialize application control." << std::endl; std::cout << "ERROR: Failed to initialize application control." << std::endl;
return 0; return 0;

View File

@@ -20,11 +20,11 @@ class CDoorExternControl
public: public:
/** /**
* @brief Start and initialize the application control and load vehicle devices and * @brief Start and initialize the application control and load vehicle devices and basic services depending on the number of doors
* basic services depending on the number of doors * @param[in] uiInstance Instance number the application will connect to. 3002 is default
* @return Return true on success otherwise false * @return Return true on success otherwise false
*/ */
bool Initialize(); bool Initialize(uint32_t uiInstance);
/** /**
* @brief Run loop as long as user input does not exit * @brief Run loop as long as user input does not exit

View File

@@ -57,10 +57,6 @@ execute_process(COMMAND "${SDV_IDL_COMPILER}" "${PROJECT_SOURCE_DIR}/generated/v
message("Create data link for open trunk example") message("Create data link for open trunk example")
execute_process(COMMAND ${SDV_DBC_UTIL} "${PROJECT_SOURCE_DIR}/open_trunk_example.dbc" "-O${PROJECT_SOURCE_DIR}/generated/" --nodestrunk --version1.0.0.1 --moduleTrunkExampleFMU --dl_lib_namecan_dl_trunk) execute_process(COMMAND ${SDV_DBC_UTIL} "${PROJECT_SOURCE_DIR}/open_trunk_example.dbc" "-O${PROJECT_SOURCE_DIR}/generated/" --nodestrunk --version1.0.0.1 --moduleTrunkExampleFMU --dl_lib_namecan_dl_trunk)
# Execute the IDL compiler for the complex service to digest interface code.
message("Compiling trunkkit.idl")
execute_process(COMMAND "${SDV_IDL_COMPILER}" "${PROJECT_SOURCE_DIR}/trunk_service/trunkkit.idl" "-O${PROJECT_SOURCE_DIR}/generated/trunk_service/" "-I${SDV_FRAMEWORK_DEV_INCLUDE}" -Itrunk_service/ --ps_lib_nametrunk_service_proxystub)
###################################################################################################################################################################### ######################################################################################################################################################################
# data link component # data link component
###################################################################################################################################################################### ######################################################################################################################################################################
@@ -84,26 +80,16 @@ add_subdirectory(generated/vss_files/ps)
add_subdirectory(generated/vss_files/vd_vehicletrunk) add_subdirectory(generated/vss_files/vd_vehicletrunk)
add_subdirectory(generated/vss_files/vd_vehiclespeed) add_subdirectory(generated/vss_files/vd_vehiclespeed)
add_subdirectory(generated/vss_files/bs_vehicletrunk)
add_subdirectory(generated/vss_files/bs_vehiclespeed) add_subdirectory(generated/vss_files/bs_vehiclespeed)
###################################################################################################################################################################### message("Include: basic service enhanced by safety function.")
# complex service set(TARGET_NAME trunk_bs_vehicletrunk_tx)
###################################################################################################################################################################### add_library(${TARGET_NAME} SHARED
bs_vehicletrunk/bs_vehicletrunk.h
bs_vehicletrunk/bs_vehicletrunk.cpp)
message("Include: proxy/stub for complex trunk service") set_target_properties(trunk_bs_vehicletrunk_tx PROPERTIES PREFIX "")
include_directories(${CMAKE_CURRENT_LIST_DIR}/generated/trunk_service) set_target_properties(trunk_bs_vehicletrunk_tx PROPERTIES SUFFIX ".sdv")
add_subdirectory(generated/trunk_service/ps)
message("Include: example component trunk_complex_service")
add_library(trunk_complex_service SHARED
trunk_service/complex_service.h
trunk_service/complex_service.cpp
)
set_target_properties(trunk_complex_service PROPERTIES OUTPUT_NAME "trunk_complex_service")
set_target_properties(trunk_complex_service PROPERTIES PREFIX "")
set_target_properties(trunk_complex_service PROPERTIES SUFFIX ".sdv")
###################################################################################################################################################################### ######################################################################################################################################################################
# open trunk application # open trunk application
@@ -130,7 +116,6 @@ endif()
# Copy the config files # Copy the config files
file (COPY ${PROJECT_SOURCE_DIR}/config/can_com_simulation_trunk.toml DESTINATION ${CMAKE_BINARY_DIR}/bin/config) file (COPY ${PROJECT_SOURCE_DIR}/config/can_com_simulation_trunk.toml DESTINATION ${CMAKE_BINARY_DIR}/bin/config)
file (COPY ${PROJECT_SOURCE_DIR}/config/complex_service_trunk.toml DESTINATION ${CMAKE_BINARY_DIR}/bin/config)
file (COPY ${PROJECT_SOURCE_DIR}/config/data_dispatch_trunk.toml DESTINATION ${CMAKE_BINARY_DIR}/bin/config) file (COPY ${PROJECT_SOURCE_DIR}/config/data_dispatch_trunk.toml DESTINATION ${CMAKE_BINARY_DIR}/bin/config)
file (COPY ${PROJECT_SOURCE_DIR}/config/data_link_trunk.toml DESTINATION ${CMAKE_BINARY_DIR}/bin/config) file (COPY ${PROJECT_SOURCE_DIR}/config/data_link_trunk.toml DESTINATION ${CMAKE_BINARY_DIR}/bin/config)
file (COPY ${PROJECT_SOURCE_DIR}/config/task_timer_trunk.toml DESTINATION ${CMAKE_BINARY_DIR}/bin/config) file (COPY ${PROJECT_SOURCE_DIR}/config/task_timer_trunk.toml DESTINATION ${CMAKE_BINARY_DIR}/bin/config)
@@ -172,21 +157,9 @@ add_custom_target(trunk_abstract_config
VERBATIM VERBATIM
) )
add_custom_target(trunk_user_config
ALL
DEPENDS
trunk_complex_service
trunk_service_proxystub
COMMAND "${SDV_PACKAGER}" DIRECT_INSTALL TrunkApplication --instance3005 trunk_complex_service.sdv trunk_service_proxystub.sdv "-I${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" --user_config --overwrite
VERBATIM
)
add_custom_target(trunk_platform_config add_custom_target(trunk_platform_config
ALL ALL
COMMAND "${SDV_PACKAGER}" CONFIGURE ${PROJECT_SOURCE_DIR}/coreconfig/platform.toml --instance3005 --platform_config COMMAND "${SDV_PACKAGER}" CONFIGURE ${PROJECT_SOURCE_DIR}/coreconfig/platform.toml --instance3005 --platform_config
VERBATIM VERBATIM
) )

View File

@@ -0,0 +1,52 @@
/********************************************************************************
* 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
********************************************************************************/
#include <iostream>
#include "bs_vehicletrunk.h"
/**
* @brief Constructor
*/
CBasicServiceVehicleTrunk::CBasicServiceVehicleTrunk()
{
m_ptrOpen = sdv::core::GetObject("Vehicle.Body.Trunk_Device").GetInterface<vss::Vehicle::Body::TrunkDevice::IVSS_WriteOpen>();
if (!m_ptrOpen)
{
SDV_LOG_ERROR("Could not get interface 'IVSS_WriteOpen': [CBasicServiceVehicleTrunk]");
throw std::runtime_error("Open device not found");
}
// Request the basic service for speed.
auto pSpeedSvc = sdv::core::GetObject("Vehicle.Speed_Service").GetInterface<vss::Vehicle::SpeedService::IVSS_GetSpeed>();
if (pSpeedSvc)
{
// Register speed change event handler.
pSpeedSvc->RegisterOnSignalChangeOfVehicleSpeed(static_cast<vss::Vehicle::SpeedService::IVSS_SetSpeed_Event*> (this));
}
SDV_LOG_TRACE("CBasicServiceVehicleTrunk created.");
}
/**
* @brief Open
* @param[in] value
* @return true on success otherwise false
*/
bool CBasicServiceVehicleTrunk::SetOpen(bool value)
{
if (m_Speed)
return false;
return m_ptrOpen->WriteOpen(value);
}
void CBasicServiceVehicleTrunk::SetSpeed(float value)
{
m_Speed = value;
}

View File

@@ -0,0 +1,64 @@
/********************************************************************************
* 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
********************************************************************************/
#ifndef __VSS_GENERATED__BS_VEHICLETRUNK_H_20260415_164751_648__
#define __VSS_GENERATED__BS_VEHICLETRUNK_H_20260415_164751_648__
#include <iostream>
#include <support/component_impl.h>
#include "../generated/vss_files/vss_vehiclebodytrunk_vd_tx.h"
#include "../generated/vss_files/vss_vehiclebodytrunk_bs_tx.h"
#include "../generated/vss_files/vss_vehiclespeed_bs_rx.h"
/**
* @brief basic service VehicleTrunk
*/
class CBasicServiceVehicleTrunk
: public sdv::CSdvObject
, public vss::Vehicle::Body::TrunkService::IVSS_SetOpen
, public vss::Vehicle::SpeedService::IVSS_SetSpeed_Event
{
public:
BEGIN_SDV_INTERFACE_MAP()
SDV_INTERFACE_ENTRY(vss::Vehicle::Body::TrunkService::IVSS_SetOpen)
SDV_INTERFACE_ENTRY(vss::Vehicle::SpeedService::IVSS_SetSpeed_Event)
END_SDV_INTERFACE_MAP()
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::actuator)
DECLARE_OBJECT_CLASS_NAME("Vehicle.Body.Trunk_Service")
/**
* @brief Constructor
*/
CBasicServiceVehicleTrunk();
/**
* @brief Set trunk signal
* @param[in] value
* @return true on success otherwise false
*/
bool SetOpen(bool value) override;
/**
* @brief Set vehicleSpeed signal
* @param[in] value vehicle speed in km/h
*/
virtual void SetSpeed(float value) override;
private:
float m_Speed = 1.0; ///< Speed, start with representing a moveing vehicle.
vss::Vehicle::Body::TrunkDevice::IVSS_WriteOpen* m_ptrOpen = nullptr; ///< Trunk
};
DEFINE_SDV_OBJECT(CBasicServiceVehicleTrunk)
#endif // !define __VSS_GENERATED__BS_VEHICLETRUNK_H_20260415_164751_648__

View File

@@ -1,6 +0,0 @@
[Configuration]
Version = 100
[[Component]]
Path = "trunk_complex_service.sdv"
Class = "Open Trunk Service"

View File

@@ -31,14 +31,12 @@ const CConsole::SConsolePos g_sSeparator4{ 20, 1 };
const CConsole::SConsolePos g_sComment1{ 22, 1 }; const CConsole::SConsolePos g_sComment1{ 22, 1 };
const CConsole::SConsolePos g_sComment2{ 23, 1 }; const CConsole::SConsolePos g_sComment2{ 23, 1 };
const CConsole::SConsolePos g_sComment3{ 24, 1 }; const CConsole::SConsolePos g_sComment3{ 24, 1 };
const CConsole::SConsolePos g_sComment4{ 25, 1 }; const CConsole::SConsolePos g_sSeparator5{ 26, 1 };
const CConsole::SConsolePos g_sComment5{ 26, 1 }; const CConsole::SConsolePos g_sOpenViaDevice{ 28, 1 };
const CConsole::SConsolePos g_sSeparator5{ 28, 1 }; const CConsole::SConsolePos g_sOpenViaService{ 29, 1 };
const CConsole::SConsolePos g_sComplexService1{ 30, 1 }; const CConsole::SConsolePos g_sSeparator6{ 31, 1 };
const CConsole::SConsolePos g_sComplexService2{ 31, 1 }; const CConsole::SConsolePos g_sControlDescription{ 33, 1 };
const CConsole::SConsolePos g_sSeparator6{ 33, 1 }; const CConsole::SConsolePos g_sCursor{ 34, 1 };
const CConsole::SConsolePos g_sControlDescription{ 35, 1 };
const CConsole::SConsolePos g_sCursor{ 36, 1 };
CConsole::CConsole() CConsole::CConsole()
{ {
@@ -89,12 +87,11 @@ void CConsole::PrintHeader(uint32_t uiInstance)
// Clear the screen... // Clear the screen...
std::cout << "\x1b[2J"; std::cout << "\x1b[2J";
std::string subTtitle = "Standalone application, this is not Mixed-Critical mode!"; std::string subTtitle = "Standalone application!";
if (uiInstance != 0) if (uiInstance != 0)
{ {
subTtitle = "Connected to core instance "; subTtitle = "Connected to core instance ";
subTtitle.append(std::to_string(uiInstance)); subTtitle.append(std::to_string(uiInstance));
subTtitle.append(", this is NOT Mixed-Critical mode yet!");
} }
// Print the titles // Print the titles
PrintText(g_sTitle, "Open Trunk example: Open trunk when vehicle is not moving"); PrintText(g_sTitle, "Open Trunk example: Open trunk when vehicle is not moving");
@@ -109,16 +106,14 @@ void CConsole::PrintHeader(uint32_t uiInstance)
PrintText(g_sBasicService, "Basic Service:"); PrintText(g_sBasicService, "Basic Service:");
PrintText(g_sBasicServiceSpeed, "Basic Service Interface not available."); PrintText(g_sBasicServiceSpeed, "Basic Service Interface not available.");
PrintText(g_sSeparator4, "============================================================================"); PrintText(g_sSeparator4, "============================================================================");
PrintText(g_sComment1, "The complex service which checks the speed of the vehicle can be seen"); PrintText(g_sComment1, "The Open Trunk signal has a safety request.");
PrintText(g_sComment2, "as an ASIL A/B component and will block the call from QM."); PrintText(g_sComment2, "Therefore the speed value is required and must be checked.");
PrintText(g_sComment3, "The extern application can be seen as a QM function."); PrintText(g_sComment3, "If the car is moving the open trunk is blocked.");
PrintText(g_sComment4, "If this example would run in a mixed critical environment the connection");
PrintText(g_sComment5, "from QM to basic service interface would be forbidden.");
PrintText(g_sSeparator5, "============================================================================"); PrintText(g_sSeparator5, "============================================================================");
PrintText(g_sComplexService1, "Basic Service Interface not available."); PrintText(g_sOpenViaDevice, "Vehicle Device Interface not available.");
PrintText(g_sComplexService2, "Complex Service Interface not available."); PrintText(g_sOpenViaService, "Basic Service Interface not available.");
PrintText(g_sSeparator6, "----------------------------------------------------------------------------"); PrintText(g_sSeparator6, "----------------------------------------------------------------------------");
PrintText(g_sControlDescription, "Press 'X' to quit; 'C' to clear screen, '1' or '2' to open trunk "); PrintText(g_sControlDescription, "Press 'X' to quit; 'C' to clear screen, 'O' or 'D' to open trunk ");
} }
bool CConsole::PrepareDataConsumers() bool CConsole::PrepareDataConsumers()
@@ -145,17 +140,18 @@ bool CConsole::PrepareDataConsumers()
} }
// Request the basic service for opening the trunk. // Request the basic service for opening the trunk.
m_pTrunkSvc = sdv::core::GetObject("Vehicle.Body.Trunk_Service").GetInterface<vss::Vehicle::Body::TrunkService::IVSS_SetOpen>(); m_pTrunkService = sdv::core::GetObject("Vehicle.Body.Trunk_Service").GetInterface<vss::Vehicle::Body::TrunkService::IVSS_SetOpen>();
if (m_pTrunkSvc) if (m_pTrunkService)
PrintText(g_sComplexService1, "Basic Service available"); PrintText(g_sOpenViaService, "Basic Service available");
else else
PrintText(g_sComplexService1, "Basic Service NOT available"); PrintText(g_sOpenViaService, "Basic Service NOT available");
m_pTrunkComplexService = sdv::core::GetObject("Open Trunk Service").GetInterface<ITrunkKitService>(); // Request the VEHICLE DEVICE service for opening the trunk.
if (m_pTrunkComplexService) m_pTrunkDevice = sdv::core::GetObject("Vehicle.Body.Trunk_Device").GetInterface<vss::Vehicle::Body::TrunkDevice::IVSS_WriteOpen>();
PrintText(g_sComplexService2, "Complex Service available"); if (m_pTrunkDevice)
PrintText(g_sOpenViaDevice, "Trunk Device available");
else else
PrintText(g_sComplexService2, "Complex Service NOT available"); PrintText(g_sOpenViaDevice, "Trunk Device NOT available");
return true; return true;
} }
@@ -291,25 +287,32 @@ void CConsole::RunUntilBreak()
{ {
case 'c': case 'c':
case 'C': case 'C':
PrintText(g_sComplexService1, " "); PrintText(g_sOpenViaDevice, " ");
PrintText(g_sComplexService2, " "); PrintText(g_sOpenViaService, " ");
break; break;
case '1': case 'd':
if (m_pTrunkSvc) case 'D':
if (m_pTrunkDevice)
{ {
if (m_pTrunkSvc->SetOpen(true)) if (m_pTrunkDevice->WriteOpen(true))
PrintText(g_sComplexService1, "Open trunk via basic service - will not be available in Mixed-Critical mode!"); {
if (m_SpeedVD || m_SpeedBS)
PrintText(g_sOpenViaDevice, "Trunk opened directly although car was moving, not safe.");
else else
PrintText(g_sComplexService1, "Open trunk via basic service failed."); PrintText(g_sOpenViaDevice, "Trunk opened directly, not safe.");
}
else
PrintText(g_sOpenViaDevice, "Trunk opened directly, failed.");
} }
break; break;
case '2': case 'o':
if (m_pTrunkComplexService) case 'O':
if (m_pTrunkService)
{ {
if (m_pTrunkComplexService->PopTrunk()) if (m_pTrunkService->SetOpen(true))
PrintText(g_sComplexService2, "Safety open trunk via complex service."); PrintText(g_sOpenViaService, "Trunk opened safely.");
else else
PrintText(g_sComplexService2, "Safety open trunk via complex service failed, car is moving"); PrintText(g_sOpenViaService, "Open trunk failed, car is moving.");
} }
break; break;
case 'x': case 'x':

View File

@@ -21,12 +21,13 @@
#include "../generated/vss_files/signal_identifier.h" #include "../generated/vss_files/signal_identifier.h"
#include <fcntl.h> #include <fcntl.h>
#include "../generated/vss_files/vss_vehiclebodytrunk_vd_tx.h"
#include "../generated/vss_files/vss_vehiclebodytrunk_bs_tx.h" #include "../generated/vss_files/vss_vehiclebodytrunk_bs_tx.h"
#include "../generated/vss_files/vss_vehiclespeed_bs_rx.h" #include "../generated/vss_files/vss_vehiclespeed_bs_rx.h"
#include "../generated/vss_files/vss_vehiclespeed_vd_rx.h" #include "../generated/vss_files/vss_vehiclespeed_vd_rx.h"
// Complex service trunk interface - located in ../generated/trunk_service // Complex service trunk interface - located in ../generated/trunk_service
#include "trunkkit.h" //#include "trunkkit.h"
#ifdef __unix__ #ifdef __unix__
#include <termios.h> // Needed for tcgetattr and fcntl #include <termios.h> // Needed for tcgetattr and fcntl
@@ -158,12 +159,11 @@ private:
sdv::core::CSignal m_SignalSpeed; ///< Speed sdv::core::CSignal m_SignalSpeed; ///< Speed
float m_SpeedDL = 0.0; ///< Speed Data Link float m_SpeedDL = 0.0; ///< Speed Data Link
float m_SpeedVD = 0.0; ///< Speed Data Link float m_SpeedVD = 0.0; ///< Speed Vehicle Device
float m_SpeedBS = 0.0; ///< Speed Data Link float m_SpeedBS = 0.0; ///< Speed Basic Service
vss::Vehicle::Body::TrunkService::IVSS_SetOpen* m_pTrunkSvc = nullptr; ///< Front Left Door
ITrunkKitService* m_pTrunkComplexService = nullptr; ///< Trunk Service interface pointer.
vss::Vehicle::Body::TrunkService::IVSS_SetOpen* m_pTrunkService = nullptr; ///< trunk (basic service)
vss::Vehicle::Body::TrunkDevice::IVSS_WriteOpen* m_pTrunkDevice = nullptr; ///< trunk (vehicle device)
#ifdef _WIN32 #ifdef _WIN32
DWORD m_dwConsoleOutMode = 0u; ///< The console mode before switching on ANSI support. DWORD m_dwConsoleOutMode = 0u; ///< The console mode before switching on ANSI support.

View File

@@ -80,7 +80,7 @@ bool CTrunkControl::Initialize(uint32_t uiInstance)
bResult &= LoadConfigFile("Load data_link_trunk: ", "data_link_trunk.toml"); bResult &= LoadConfigFile("Load data_link_trunk: ", "data_link_trunk.toml");
bResult &= LoadConfigFile("Load trunk_vehicle_device_and_basic_service: ", "trunk_vehicle_device_and_basic_service.toml"); bResult &= LoadConfigFile("Load trunk_vehicle_device_and_basic_service: ", "trunk_vehicle_device_and_basic_service.toml");
bResult &= LoadConfigFile("Load trunk service (complex service): ", "complex_service_trunk.toml"); //bResult &= LoadConfigFile("Load trunk service (complex service): ", "complex_service_trunk.toml");
if (!bResult) if (!bResult)
{ {

View File

@@ -1,58 +0,0 @@
/********************************************************************************
* 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
********************************************************************************/
#include <iostream>
#include "complex_service.h"
bool CTrunkExampleService::OnInitialize()
{
// Request the basic service for speed.
auto pSpeedSvc = sdv::core::GetObject("Vehicle.Speed_Service").GetInterface<vss::Vehicle::SpeedService::IVSS_GetSpeed>();
if (pSpeedSvc)
{
// Register speed change event handler.
pSpeedSvc->RegisterOnSignalChangeOfVehicleSpeed(static_cast<vss::Vehicle::SpeedService::IVSS_SetSpeed_Event*> (this));
}
// Request the basic service for opening the trunk
m_pTrunkSvc = sdv::core::GetObject("Vehicle.Body.Trunk_Service").GetInterface<vss::Vehicle::Body::TrunkService::IVSS_SetOpen>();
if ((!pSpeedSvc) || (!m_pTrunkSvc))
{
SDV_LOG_ERROR("Could not get interfaces : [CTrunkExampleService]");
return false;
}
return true;
}
void CTrunkExampleService::OnShutdown()
{
// Unregister trunk change event handler.
auto pSpeedSvc = sdv::core::GetObject("Vehicle.Speed_Service").GetInterface<vss::Vehicle::SpeedService::IVSS_GetSpeed>();
if (pSpeedSvc)
pSpeedSvc->UnregisterOnSignalChangeOfVehicleSpeed(static_cast<vss::Vehicle::SpeedService::IVSS_SetSpeed_Event*> (this));
}
void CTrunkExampleService::SetSpeed(float value)
{
m_Speed = value;
}
bool CTrunkExampleService::PopTrunk()
{
if (m_Speed == 0.0)
{
return m_pTrunkSvc->SetOpen(true);
}
return false;
}

View File

@@ -1,91 +0,0 @@
/********************************************************************************
* 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
********************************************************************************/
#ifndef TRUNK_COMPLEX_SERVICE_EXAMPLE_H
#define TRUNK_COMPLEX_SERVICE_EXAMPLE_H
#include <iostream>
// SDV framework support
#include <support/component_impl.h>
#include <support/signal_support.h>
// VSS interfaces - located in ../interfaces
#include "../generated/vss_files/vss_vehiclespeed_bs_rx.h"
#include "../generated/vss_files/vss_vehiclebodytrunk_bs_tx.h"
// Complex service trunk interface - located in ../generated/trunk_service
#include "trunkkit.h"
/**
* @brief Open trunk example service
* @details This complex service checks the speed of the vehicle. in case the vehicle is oving, it prohibits the opening of the trunk.
* Input events from basic service: vehicle speed in km/h
* Output call for basic service: opening the trunk
*/
class CTrunkExampleService : public sdv::CSdvObject
, public vss::Vehicle::SpeedService::IVSS_SetSpeed_Event
, public ITrunkKitService
{
public:
/**
* @brief Constructor
*/
CTrunkExampleService(){}
/**
* @brief Destructor
*/
~CTrunkExampleService()
{}
// Interface map
BEGIN_SDV_INTERFACE_MAP()
SDV_INTERFACE_ENTRY(vss::Vehicle::SpeedService::IVSS_SetSpeed_Event)
SDV_INTERFACE_ENTRY(ITrunkKitService)
END_SDV_INTERFACE_MAP()
// Object declarations
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::vehicle_function)
DECLARE_OBJECT_CLASS_NAME("Open Trunk Service")
DECLARE_OBJECT_SINGLETON()
/**
* @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 Shutdown the object. Overload of sdv::CSdvObject::OnShutdown.
*/
virtual void OnShutdown() override;
/**
* @brief Set vehicleSpeed signal
* @param[in] value vehicle speed in km/h
*/
virtual void SetSpeed(float value) override;
/**
* @brief Save call to open the trunk. Opening the trunk is only allowed when the vehicle is not moving
* @return Returns whether the trunk could be opened or not.
*/
virtual bool PopTrunk() override;
private:
float m_Speed = 0.0; ///< Speed
vss::Vehicle::Body::TrunkService::IVSS_SetOpen* m_pTrunkSvc = nullptr; ///< Trunk
};
DEFINE_SDV_OBJECT(CTrunkExampleService)
#endif // !define TRUNK_COMPLEX_SERVICE_EXAMPLE_H

View File

@@ -1,22 +0,0 @@
/********************************************************************************
* 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
********************************************************************************/
/**
* @brief Service to open the trunk
* @details Service interface definition to open the trunk.
*/
interface ITrunkKitService
{
/**
* @brief Save call to open the trunk. Opening the trunk is onkly allowed when the vehicle is not moving
* @return Returns whether the trunk could be opened or not.
*/
boolean PopTrunk();
};