mirror of
https://github.com/eclipse-openvehicle-api/openvehicle-api.git
synced 2026-02-05 15:18:45 +00:00
110
examples/CMakeLists.txt
Normal file
110
examples/CMakeLists.txt
Normal file
@@ -0,0 +1,110 @@
|
||||
# Enforce CMake version 3.20
|
||||
cmake_minimum_required (VERSION 3.20)
|
||||
cmake_policy (VERSION 3.20)
|
||||
|
||||
# Define project
|
||||
project(vapi_framework_examples VERSION 1.0 LANGUAGES CXX)
|
||||
|
||||
# Use C++17 support
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
# Libary symbols are hidden by default
|
||||
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
|
||||
|
||||
# Re-set target directories
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY $<1:${CMAKE_BINARY_DIR}/lib>)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY $<1:${CMAKE_BINARY_DIR}/bin>)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY $<1:${CMAKE_BINARY_DIR}/bin>)
|
||||
|
||||
# Default C++ settings
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||
message("Use MSVC compiler...")
|
||||
add_compile_options(/W4 /WX /wd4996 /wd4127 /permissive- /Zc:rvalueCast)
|
||||
add_compile_definitions(_SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING UNICODE _UNICODE)
|
||||
else()
|
||||
# There are some versions of GCC that produce bogus warnings for -Wstringop-overflow (e.g. version 9.4 warns, 11.4 not - changing
|
||||
# the compile order without changing the logical behavior, will produce different results).
|
||||
# See also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100477
|
||||
# And https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115074
|
||||
# Suppress this warning.
|
||||
add_compile_options(-Werror -Wall -Wextra -Wshadow -Wpedantic -Wunreachable-code -fno-common -fPIC -ggdb -pthread -Wno-error=stringop-overflow)
|
||||
add_link_options(-pthread)
|
||||
if (WIN32)
|
||||
message("Use g++ compiler under Windows (mingw)...")
|
||||
add_compile_definitions(UNICODE _UNICODE main=wmain)
|
||||
add_link_options(-municode)
|
||||
else()
|
||||
message("Use g++ compiler...")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
|
||||
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
# Check for the environment variable for the V-API runtime framework
|
||||
if (NOT DEFINED SDV_FRAMEWORK_RUNTIME)
|
||||
if (NOT DEFINED ENV{SDV_FRAMEWORK_RUNTIME})
|
||||
message( FATAL_ERROR "The environment variable SDV_FRAMEWORK_RUNTIME needs to be pointing to the SDV V-API framework location!")
|
||||
endif()
|
||||
set (SDV_FRAMEWORK_RUNTIME "$ENV{SDV_FRAMEWORK_RUNTIME}")
|
||||
endif()
|
||||
message("SDV_FRAMEWORK_RUNTIME set to ${SDV_FRAMEWORK_RUNTIME}")
|
||||
|
||||
# Check for the environment variable for the V-API component installation directory
|
||||
if (NOT DEFINED SDV_COMPONENT_INSTALL)
|
||||
if (NOT DEFINED ENV{SDV_COMPONENT_INSTALL})
|
||||
message( FATAL_ERROR "The environment variable SDV_COMPONENT_INSTALL needs to be pointing to the SDV V-API component installation location!")
|
||||
endif()
|
||||
set (SDV_COMPONENT_INSTALL "$ENV{SDV_COMPONENT_INSTALL}")
|
||||
endif()
|
||||
message("SDV_COMPONENT_INSTALL set to ${SDV_COMPONENT_INSTALL}")
|
||||
|
||||
# Check for the existance of the V-API development tools
|
||||
if (NOT DEFINED SDV_FRAMEWORK_DEV_TOOLS)
|
||||
if (NOT DEFINED ENV{SDV_FRAMEWORK_DEV_TOOLS})
|
||||
message( FATAL_ERROR "The environment variable SDV_FRAMEWORK_DEV_TOOLS needs to be pointing to the SDV V-API development tools location!")
|
||||
endif()
|
||||
set (SDV_FRAMEWORK_DEV_TOOLS "$ENV{SDV_FRAMEWORK_DEV_TOOLS}")
|
||||
endif()
|
||||
message("SDV_FRAMEWORK_DEV_TOOLS set to ${SDV_FRAMEWORK_DEV_TOOLS}")
|
||||
if (NOT DEFINED SDV_FRAMEWORK_DEV_INCLUDE)
|
||||
if (NOT DEFINED ENV{SDV_FRAMEWORK_DEV_INCLUDE})
|
||||
message( FATAL_ERROR "The environment variable SDV_FRAMEWORK_DEV_INCLUDE needs to be pointing to the SDV V-API development include files location!")
|
||||
endif()
|
||||
set (SDV_FRAMEWORK_DEV_INCLUDE "$ENV{SDV_FRAMEWORK_DEV_INCLUDE}")
|
||||
endif()
|
||||
message("SDV_FRAMEWORK_DEV_INCLUDE set to ${SDV_FRAMEWORK_DEV_INCLUDE}")
|
||||
if (WIN32)
|
||||
set (SDV_IDL_COMPILER "${SDV_FRAMEWORK_DEV_TOOLS}/sdv_idl_compiler.exe")
|
||||
set (SDV_DBC_UTIL "${SDV_FRAMEWORK_DEV_TOOLS}/sdv_dbc_util.exe")
|
||||
set (SDV_VSS_UTIL "${SDV_FRAMEWORK_DEV_TOOLS}/sdv_vss_util.exe")
|
||||
set (SDV_PACKAGER "${SDV_FRAMEWORK_DEV_TOOLS}/sdv_packager.exe")
|
||||
else()
|
||||
set (SDV_IDL_COMPILER "${SDV_FRAMEWORK_DEV_TOOLS}/sdv_idl_compiler")
|
||||
set (SDV_DBC_UTIL "${SDV_FRAMEWORK_DEV_TOOLS}/sdv_dbc_util")
|
||||
set (SDV_VSS_UTIL "${SDV_FRAMEWORK_DEV_TOOLS}/sdv_vss_util")
|
||||
set (SDV_PACKAGER "${SDV_FRAMEWORK_DEV_TOOLS}/sdv_packager")
|
||||
endif()
|
||||
if (NOT EXISTS ${SDV_IDL_COMPILER})
|
||||
message( FATAL_ERROR "The SDV V-API IDL compiler is missing! \nDoes the SDV_FRAMEWORK_DEV_TOOLS environment variable have the correct path? \nIt is set to ${SDV_IDL_COMPILER}")
|
||||
endif()
|
||||
if (NOT EXISTS "${SDV_DBC_UTIL}")
|
||||
message( FATAL_ERROR "The SDV V-API DBC utility is missing! \nDoes the SDV_FRAMEWORK_DEV_TOOLS environment variable have the correct path? \nIt is set to ${SDV_IDL_COMPILER}")
|
||||
endif()
|
||||
if (NOT EXISTS "${SDV_VSS_UTIL}")
|
||||
message( FATAL_ERROR "The SDV V-API VSS utility is missing! \nDoes the SDV_FRAMEWORK_DEV_TOOLS environment variable have the correct path? \nIt is set to ${SDV_IDL_COMPILER}")
|
||||
endif()
|
||||
if (NOT EXISTS "${SDV_PACKAGER}")
|
||||
message( FATAL_ERROR "The SDV V-API installation packager utility is missing! \nDoes the SDV_FRAMEWORK_DEV_TOOLS environment variable have the correct path? \nIt is set to ${SDV_IDL_COMPILER}")
|
||||
endif()
|
||||
|
||||
add_subdirectory(_howto_examples)
|
||||
add_subdirectory(tasktimer_component_example)
|
||||
add_subdirectory(tasktimer_example)
|
||||
add_subdirectory(configuration_component_example)
|
||||
add_subdirectory(configuration_example)
|
||||
add_subdirectory(system_demo_example)
|
||||
add_subdirectory(door_demo_example)
|
||||
add_subdirectory(auto_headlamp_example)
|
||||
add_subdirectory(open_trunk_example)
|
||||
182
examples/CMakePresets.json
Normal file
182
examples/CMakePresets.json
Normal file
@@ -0,0 +1,182 @@
|
||||
{
|
||||
"version": 2,
|
||||
"cmakeMinimumRequired": {
|
||||
"major": 3,
|
||||
"minor": 20,
|
||||
"patch": 0
|
||||
},
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "config_base",
|
||||
"hidden": true,
|
||||
"displayName": "Base configuration",
|
||||
"description": "Default build",
|
||||
"binaryDir": "${sourceDir}/../build/${presetName}/examples",
|
||||
"cacheVariables": {
|
||||
"CMAKE_INSTALL_PREFIX": "${sourceDir}/../install/${presetName}/examples",
|
||||
"SDV_FRAMEWORK_RUNTIME": "${sourceDir}/../build/${presetName}/bin",
|
||||
"SDV_COMPONENT_INSTALL": "${sourceDir}/../build/${presetName}/bin",
|
||||
"SDV_FRAMEWORK_DEV_TOOLS": "${sourceDir}/../build/${presetName}/bin",
|
||||
"SDV_FRAMEWORK_DEV_INCLUDE": "${sourceDir}/../export"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "msvc_x64_x64_ninja_debug",
|
||||
"displayName": "msvc_x64_x64 (Ninja - Debug)",
|
||||
"description": "MS Visual C++ Compiler - Ninja Generator - Debug Build",
|
||||
"inherits": "config_base",
|
||||
"generator": "Ninja",
|
||||
"architecture": {
|
||||
"value": "x64",
|
||||
"strategy": "external"
|
||||
},
|
||||
"cacheVariables": {
|
||||
"CMAKE_C_COMPILER": "cl.exe",
|
||||
"CMAKE_CXX_COMPILER": "cl.exe",
|
||||
"CMAKE_BUILD_TYPE": "Debug"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "msvc_x64_x64_ninja_release",
|
||||
"displayName": "msvc_x64_x64 (Ninja - Release)",
|
||||
"description": "MS Visual C++ Compiler - Ninja Generator - Release Build",
|
||||
"inherits": "config_base",
|
||||
"generator": "Ninja",
|
||||
"architecture": {
|
||||
"value": "x64",
|
||||
"strategy": "external"
|
||||
},
|
||||
"cacheVariables": {
|
||||
"CMAKE_C_COMPILER": "cl.exe",
|
||||
"CMAKE_CXX_COMPILER": "cl.exe",
|
||||
"CMAKE_BUILD_TYPE": "Release"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "gcc_ninja_debug",
|
||||
"displayName": "GCC w64 (Ninja - Debug)",
|
||||
"description": "GCC Compiler - Ninja Generator - Debug Build",
|
||||
"inherits": "config_base",
|
||||
"generator": "Ninja",
|
||||
"cacheVariables": {
|
||||
"CMAKE_C_COMPILER": "gcc",
|
||||
"CMAKE_CXX_COMPILER": "g++",
|
||||
"CMAKE_BUILD_TYPE": "Debug"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "gcc_ninja_release",
|
||||
"displayName": "GCC w64 (Ninja - Release)",
|
||||
"description": "GCC Compiler - Ninja Generator - Release Build",
|
||||
"inherits": "config_base",
|
||||
"generator": "Ninja",
|
||||
"cacheVariables": {
|
||||
"CMAKE_C_COMPILER": "gcc",
|
||||
"CMAKE_CXX_COMPILER": "g++",
|
||||
"CMAKE_BUILD_TYPE": "Release"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "gcc_mingw_debug",
|
||||
"displayName": "GCC w64 (MINGW Make - Debug)",
|
||||
"description": "GCC Compiler - MINGW Make Generator - Debug Build",
|
||||
"inherits": "config_base",
|
||||
"generator": "MinGW Makefiles",
|
||||
"cacheVariables": {
|
||||
"CMAKE_C_COMPILER": "gcc",
|
||||
"CMAKE_CXX_COMPILER": "g++",
|
||||
"CMAKE_BUILD_TYPE": "Debug"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "gcc_mingw_release",
|
||||
"displayName": "GCC w64 (MINGW Make - Release)",
|
||||
"description": "GCC Compiler - MINGW Make Generator - Release Build",
|
||||
"inherits": "config_base",
|
||||
"generator": "MinGW Makefiles",
|
||||
"cacheVariables": {
|
||||
"CMAKE_C_COMPILER": "gcc",
|
||||
"CMAKE_CXX_COMPILER": "g++",
|
||||
"CMAKE_BUILD_TYPE": "Release"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "gcc_unix_debug",
|
||||
"displayName": "GCC w64 (UNIX Make - Debug)",
|
||||
"description": "GCC Compiler - UNIX Make Generator - Debug Build",
|
||||
"inherits": "config_base",
|
||||
"generator": "Unix Makefiles",
|
||||
"cacheVariables": {
|
||||
"CMAKE_C_COMPILER": "gcc",
|
||||
"CMAKE_CXX_COMPILER": "g++",
|
||||
"CMAKE_BUILD_TYPE": "Debug"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "gcc_unix_release",
|
||||
"displayName": "GCC w64 (UNIX Make - Release)",
|
||||
"description": "GCC Compiler - UNIX Make Generator - Release Build",
|
||||
"inherits": "config_base",
|
||||
"generator": "Unix Makefiles",
|
||||
"cacheVariables": {
|
||||
"CMAKE_C_COMPILER": "gcc",
|
||||
"CMAKE_CXX_COMPILER": "g++",
|
||||
"CMAKE_BUILD_TYPE": "Release"
|
||||
}
|
||||
}
|
||||
],
|
||||
"buildPresets": [
|
||||
{
|
||||
"name": "msvc_x64_x64_ninja_debug",
|
||||
"displayName": "msvc_x64_x64 (Ninja - Debug)",
|
||||
"description": "MS Visual C++ Compiler - Ninja Generator - Debug Build",
|
||||
"configurePreset": "msvc_x64_x64_ninja_debug"
|
||||
},
|
||||
{
|
||||
"name": "msvc_x64_x64_ninja_release",
|
||||
"displayName": "msvc_x64_x64 (Ninja - Release)",
|
||||
"description": "MS Visual C++ Compiler - Ninja Generator - Release Build",
|
||||
"configurePreset": "msvc_x64_x64_ninja_release"
|
||||
},
|
||||
{
|
||||
"name": "gcc_ninja_debug",
|
||||
"displayName": "GCC w64 (Ninja - Debug)",
|
||||
"description": "GCC Compiler - Ninja Generator - Debug Build",
|
||||
"configurePreset": "gcc_ninja_debug"
|
||||
},
|
||||
{
|
||||
"name": "gcc_ninja_release",
|
||||
"displayName": "GCC w64 (Ninja - Release)",
|
||||
"description": "GCC Compiler - Ninja Generator - Release Build",
|
||||
"configurePreset": "gcc_ninja_release"
|
||||
},
|
||||
{
|
||||
"name": "gcc_mingw_debug",
|
||||
"displayName": "GCC w64 (MINGW Make - Debug)",
|
||||
"description": "GCC Compiler - MINGW Make Generator - Debug Build",
|
||||
"configurePreset": "gcc_mingw_debug",
|
||||
"jobs": 8
|
||||
},
|
||||
{
|
||||
"name": "gcc_mingw_release",
|
||||
"displayName": "GCC w64 (MINGW Make - Release)",
|
||||
"description": "GCC Compiler - MINGW Make Generator - Release Build",
|
||||
"configurePreset": "gcc_mingw_release",
|
||||
"jobs": 8
|
||||
},
|
||||
{
|
||||
"name": "gcc_unix_debug",
|
||||
"displayName": "GCC w64 (UNIX Make - Debug)",
|
||||
"description": "GCC Compiler - UNIX Make Generator - Debug Build",
|
||||
"configurePreset": "gcc_unix_debug",
|
||||
"jobs": 8
|
||||
},
|
||||
{
|
||||
"name": "gcc_unix_release",
|
||||
"displayName": "GCC w64 (UNIX Make - Release)",
|
||||
"description": "GCC Compiler - UNIX Make Generator - Release Build",
|
||||
"configurePreset": "gcc_unix_release",
|
||||
"jobs": 8
|
||||
}
|
||||
]
|
||||
}
|
||||
88
examples/_howto_examples/CMakeLists.txt
Normal file
88
examples/_howto_examples/CMakeLists.txt
Normal file
@@ -0,0 +1,88 @@
|
||||
project(HowToExamples)
|
||||
|
||||
# Use new policy for project version settings and default warning level
|
||||
cmake_policy(SET CMP0048 NEW) # requires CMake 3.14
|
||||
cmake_policy(SET CMP0092 NEW) # requires CMake 3.15
|
||||
|
||||
# Use C++17 support
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
# Libary symbols are hidden by default
|
||||
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
|
||||
|
||||
# Include link to export directory of SDV V-API development include files location
|
||||
include_directories(${SDV_FRAMEWORK_DEV_INCLUDE})
|
||||
|
||||
add_library(example_vehicle_device SHARED source/example_vehicle_device.cpp)
|
||||
set_target_properties(example_vehicle_device PROPERTIES PREFIX "")
|
||||
set_target_properties(example_vehicle_device PROPERTIES SUFFIX ".sdv")
|
||||
|
||||
add_library(example_basic_service SHARED source/example_basic_service.cpp)
|
||||
set_target_properties(example_basic_service PROPERTIES PREFIX "")
|
||||
set_target_properties(example_basic_service PROPERTIES SUFFIX ".sdv")
|
||||
|
||||
add_library(example_access_to_other_components SHARED source/example_access_to_other_components.cpp)
|
||||
set_target_properties(example_access_to_other_components PROPERTIES PREFIX "")
|
||||
set_target_properties(example_access_to_other_components PROPERTIES SUFFIX ".sdv")
|
||||
|
||||
add_library(example_general_component SHARED source/example_general_component.cpp)
|
||||
set_target_properties(example_general_component PROPERTIES PREFIX "")
|
||||
set_target_properties(example_general_component PROPERTIES SUFFIX ".sdv")
|
||||
|
||||
add_library(example_general_component_with_initialization SHARED source/example_general_component_with_initialization.cpp)
|
||||
set_target_properties(example_general_component_with_initialization PROPERTIES PREFIX "")
|
||||
set_target_properties(example_general_component_with_initialization PROPERTIES SUFFIX ".sdv")
|
||||
|
||||
add_library(example_dispatch_service SHARED source/example_dispatch_service.cpp)
|
||||
set_target_properties(example_dispatch_service PROPERTIES PREFIX "")
|
||||
set_target_properties(example_dispatch_service PROPERTIES SUFFIX ".sdv")
|
||||
|
||||
add_library(example_complex_service SHARED source/example_complex_service.cpp)
|
||||
set_target_properties(example_complex_service PROPERTIES PREFIX "")
|
||||
set_target_properties(example_complex_service PROPERTIES SUFFIX ".sdv")
|
||||
|
||||
#---------------------------------------
|
||||
# Verify all HowTo examples
|
||||
#---------------------------------------
|
||||
add_executable(example_run_all_components "source/run_all_examples.cpp")
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
if (WIN32)
|
||||
target_link_libraries(example_run_all_components Ws2_32 Winmm Rpcrt4.lib)
|
||||
else()
|
||||
target_link_libraries(example_run_all_components ${CMAKE_DL_LIBS} rt ${CMAKE_THREAD_LIBS_INIT})
|
||||
endif()
|
||||
else()
|
||||
target_link_libraries(example_run_all_components Rpcrt4.lib)
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
# Copy the config files for the application example
|
||||
file (COPY ${PROJECT_SOURCE_DIR}/source/docu_dispatch.toml DESTINATION ${CMAKE_BINARY_DIR}/bin/config)
|
||||
file (COPY ${PROJECT_SOURCE_DIR}/source/docu_examples.toml DESTINATION ${CMAKE_BINARY_DIR}/bin/config)
|
||||
file (COPY ${PROJECT_SOURCE_DIR}/source/docu_app_examples.toml DESTINATION ${CMAKE_BINARY_DIR}/bin/config)
|
||||
|
||||
#---------------------------------
|
||||
# Application examples
|
||||
#---------------------------------
|
||||
add_executable(example_application source/example_application.cpp)
|
||||
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
if (WIN32)
|
||||
target_link_libraries(example_application Ws2_32 Winmm Rpcrt4.lib)
|
||||
else()
|
||||
target_link_libraries(example_application ${CMAKE_DL_LIBS} rt ${CMAKE_THREAD_LIBS_INIT})
|
||||
endif()
|
||||
else()
|
||||
target_link_libraries(example_application Rpcrt4.lib)
|
||||
endif()
|
||||
|
||||
|
||||
add_dependencies(example_run_all_components example_vehicle_device example_complex_service
|
||||
example_dispatch_service example_general_component
|
||||
example_access_to_other_components example_basic_service
|
||||
example_general_component_with_initialization)
|
||||
|
||||
|
||||
add_dependencies(example_application example_general_component example_access_to_other_components)
|
||||
13
examples/_howto_examples/example_config_file.cfg
Normal file
13
examples/_howto_examples/example_config_file.cfg
Normal file
@@ -0,0 +1,13 @@
|
||||
[Configuration]
|
||||
Version = 100
|
||||
|
||||
[[Component]]
|
||||
Path = "module_example.sdv"
|
||||
Class = "class_example"
|
||||
Name = "object_name_example"
|
||||
Message = "It's me"
|
||||
Id = 42
|
||||
Pi = 3.1415926
|
||||
Boolean = true
|
||||
Array = [ 1, 2, 3 , 5 , 7, 11, 13, 17 ]
|
||||
Table = { a = 77, b = 1.2, c = "das ist ein string" }
|
||||
170
examples/_howto_examples/example_config_file_parsing.cfg
Normal file
170
examples/_howto_examples/example_config_file_parsing.cfg
Normal file
@@ -0,0 +1,170 @@
|
||||
#include <iostream>
|
||||
#include <support/component_impl.h>
|
||||
#include <support/toml.h>
|
||||
|
||||
class DemoConfigurationComponent : public sdv::CSdvObject, public sdv::IObjectControl
|
||||
{
|
||||
public:
|
||||
BEGIN_SDV_INTERFACE_MAP()
|
||||
SDV_INTERFACE_ENTRY(sdv::IObjectControl)
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::Device)
|
||||
DECLARE_OBJECT_CLASS_NAME("Configuration_Example")
|
||||
|
||||
/**
|
||||
* @brief initialize function to register, access the task timer interface from platform abstraction.
|
||||
* After initialization 'CreateTimer' function is called to execute the task periodically.
|
||||
* @param[in] rssObjectConfig An object configuration is currently not used by this demo component.
|
||||
*/
|
||||
virtual void Initialize([[maybe_unused]] const sdv::u8string& rssObjectConfig) override
|
||||
{
|
||||
try
|
||||
{
|
||||
sdv::toml::CTOMLParser config(rssObjectConfig.c_str());
|
||||
|
||||
sdv::toml::CNode messageNode = config.GetDirect("Message");
|
||||
if (messageNode.GetType() == sdv::toml::ENodeType::node_string)
|
||||
{
|
||||
m_Message = static_cast<std::string>(messageNode.GetValue());
|
||||
}
|
||||
|
||||
sdv::toml::CNode idNode = config.GetDirect("Id");
|
||||
if (idNode.GetType() == sdv::toml::ENodeType::node_integer)
|
||||
{
|
||||
m_Id = static_cast<int32_t>(idNode.GetValue());
|
||||
}
|
||||
|
||||
sdv::toml::CNode floatNode = config.GetDirect("Pi");
|
||||
if (floatNode.GetType() == sdv::toml::ENodeType::node_floating_point)
|
||||
{
|
||||
m_Pi = static_cast<float>(floatNode.GetValue());
|
||||
}
|
||||
|
||||
sdv::toml::CNode boolNode = config.GetDirect("Boolean");
|
||||
if (boolNode.GetType() == sdv::toml::ENodeType::node_boolean)
|
||||
{
|
||||
m_IsValid = static_cast<bool>(boolNode.GetValue());
|
||||
}
|
||||
|
||||
sdv::toml::CNodeCollection arrayNodes = config.GetDirect("Array");
|
||||
if (arrayNodes.GetType() == sdv::toml::ENodeType::node_array)
|
||||
{
|
||||
for (size_t nIndex = 0; nIndex < arrayNodes.GetCount(); nIndex++)
|
||||
{
|
||||
sdv::toml::CNode node = arrayNodes[nIndex];
|
||||
if (node.GetType() == sdv::toml::ENodeType::node_integer)
|
||||
{
|
||||
m_Counters.push_back(static_cast<uint32_t>(node.GetValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sdv::toml::CNodeCollection tableNodes = config.GetDirect("Table");
|
||||
if (tableNodes.GetType() == sdv::toml::ENodeType::node_table)
|
||||
{
|
||||
if (tableNodes.GetCount() >= 3)
|
||||
{
|
||||
m_TableA = static_cast<uint32_t>(tableNodes[0].GetValue());
|
||||
m_TableB = static_cast<float>(tableNodes[1].GetValue());
|
||||
m_TableC = static_cast<std::string>(tableNodes[2].GetValue());
|
||||
}
|
||||
}
|
||||
|
||||
auto table_a = config.GetDirect("Table.a");
|
||||
auto table_b = config.GetDirect("Table.b");
|
||||
auto table_c = config.GetDirect("Table.c");
|
||||
m_DirectTableA = static_cast<uint32_t>(table_a.GetValue());
|
||||
m_DirectTableB = static_cast<float>(table_b.GetValue());
|
||||
m_DirectTableC = static_cast<std::string>(table_c.GetValue());
|
||||
}
|
||||
catch (const sdv::toml::XTOMLParseException& e)
|
||||
{
|
||||
SDV_LOG_ERROR("Parsing error: ", e.what());
|
||||
|
||||
m_status = sdv::EObjectStatus::initialization_failure;
|
||||
return;
|
||||
}
|
||||
|
||||
PrintAllVariables();
|
||||
|
||||
m_status = sdv::EObjectStatus::initialized;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Gets the current status of the object
|
||||
* @return EObjectStatus The current status of the object
|
||||
*/
|
||||
virtual sdv::EObjectStatus GetStatus() const override
|
||||
{
|
||||
return m_status;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Set the component operation mode. Overload of sdv::IObjectControl::SetOperationMode.
|
||||
* @param[in] eMode The operation mode, the component should run in.
|
||||
*/
|
||||
void 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 periodic task.
|
||||
* Timer ID of the task is used to shutdown the specific task.
|
||||
*/
|
||||
virtual void Shutdown() override
|
||||
{
|
||||
m_status = sdv::EObjectStatus::destruction_pending;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Print all global variables to console
|
||||
*/
|
||||
void PrintAllVariables()
|
||||
{
|
||||
std::cout << "\nValues parsed during initialization:\n" << std::endl;
|
||||
std::cout << "string: " << m_Message.c_str() << std::endl;
|
||||
std::cout << "integer: " << std::to_string(m_Id) << std::endl;
|
||||
std::cout << "float: " << std::to_string(m_Pi) << std::endl;
|
||||
std::cout << "bool: " << std::to_string(m_IsValid) << std::endl;
|
||||
std::cout << "table column a: " << std::to_string(m_TableA) << " " << std::to_string(m_DirectTableA) << std::endl;
|
||||
std::cout << "table column b: " << std::to_string(m_TableB) << " " << std::to_string(m_DirectTableB) << std::endl;
|
||||
std::cout << "table column c: " << m_TableC.c_str() << " " << m_DirectTableC.c_str() << std::endl;
|
||||
std::cout << "array: ";
|
||||
for (auto counter : m_Counters)
|
||||
{
|
||||
std::cout << std::to_string(counter) << ", ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
private:
|
||||
std::atomic<sdv::EObjectStatus> m_status = {sdv::EObjectStatus::initialization_pending}; //!< To update the object status when it changes.
|
||||
|
||||
std::string m_Message = "";
|
||||
int32_t m_Id = -1;
|
||||
float m_Pi = 0.0;
|
||||
bool m_IsValid = false;
|
||||
std::vector<uint32_t> m_Counters;
|
||||
uint32_t m_TableA = 0;
|
||||
float m_TableB = 0.0;
|
||||
std::string m_TableC = "";
|
||||
uint32_t m_DirectTableA = 0;
|
||||
float m_DirectTableB = 0.0;
|
||||
std::string m_DirectTableC = "";
|
||||
};
|
||||
|
||||
DEFINE_SDV_OBJECT(DemoConfigurationComponent)
|
||||
12
examples/_howto_examples/source/docu_app_examples.toml
Normal file
12
examples/_howto_examples/source/docu_app_examples.toml
Normal file
@@ -0,0 +1,12 @@
|
||||
[Configuration]
|
||||
Version = 100
|
||||
|
||||
[[Component]]
|
||||
Path = "example_general_component.sdv"
|
||||
Class = "Hello_Component"
|
||||
|
||||
[[Component]]
|
||||
Path = "example_general_component.sdv"
|
||||
Class = "Hello_Component"
|
||||
number = 42
|
||||
|
||||
6
examples/_howto_examples/source/docu_dispatch.toml
Normal file
6
examples/_howto_examples/source/docu_dispatch.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
[Configuration]
|
||||
Version = 100
|
||||
|
||||
[[Component]]
|
||||
Path = "data_dispatch_service.sdv"
|
||||
Class = "DataDispatchService"
|
||||
23
examples/_howto_examples/source/docu_examples.toml
Normal file
23
examples/_howto_examples/source/docu_examples.toml
Normal file
@@ -0,0 +1,23 @@
|
||||
[Configuration]
|
||||
Version = 100
|
||||
|
||||
[[Component]]
|
||||
Path = "example_general_component.sdv"
|
||||
Class = "Hello_Component"
|
||||
|
||||
[[Component]]
|
||||
Path = "example_general_component_with_initialization.sdv"
|
||||
Class = "Hello_Component_With_Initialization"
|
||||
number = 42
|
||||
|
||||
[[Component]]
|
||||
Path = "example_vehicle_device.sdv"
|
||||
Class = "VehicleDevice_Component"
|
||||
|
||||
[[Component]]
|
||||
Path = "example_basic_service.sdv"
|
||||
Class = "BasicService_Component"
|
||||
|
||||
[[Component]]
|
||||
Path = "example_complex_service.sdv"
|
||||
Class = "ComplexService_Component"
|
||||
@@ -0,0 +1,47 @@
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "example_interfaces.h"
|
||||
|
||||
#include <support/component_impl.h>
|
||||
|
||||
class CAccessComponent
|
||||
: public sdv::CSdvObject
|
||||
, public IShowExample
|
||||
{
|
||||
public:
|
||||
CAccessComponent()
|
||||
{
|
||||
m_HelloInterface = sdv::core::GetObject("Hello_Component").GetInterface<ISayHello>();
|
||||
|
||||
sdv::TInterfaceAccessPtr helloComp = sdv::core::GetObject("Hello_Component");
|
||||
m_GoodbyeInterface = helloComp.GetInterface<ISayGoodbye>();
|
||||
|
||||
if (!m_HelloInterface || !m_GoodbyeInterface)
|
||||
{
|
||||
throw std::runtime_error("Could not get all needed interfaces!");
|
||||
}
|
||||
}
|
||||
|
||||
BEGIN_SDV_INTERFACE_MAP()
|
||||
SDV_INTERFACE_ENTRY(IShowExample)
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
DECLARE_OBJECT_CLASS_NAME("Access_Component")
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::BasicService);
|
||||
|
||||
/**
|
||||
* @brief Show messages, implements the function of IShowExample
|
||||
*/
|
||||
void Show() override
|
||||
{
|
||||
m_HelloInterface->SayHello();
|
||||
m_GoodbyeInterface->SayGoodbye();
|
||||
}
|
||||
|
||||
private:
|
||||
ISayHello * m_HelloInterface = nullptr;
|
||||
ISayGoodbye * m_GoodbyeInterface = nullptr;
|
||||
};
|
||||
|
||||
DEFINE_SDV_OBJECT(CAccessComponent)
|
||||
66
examples/_howto_examples/source/example_application.cpp
Normal file
66
examples/_howto_examples/source/example_application.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
#include <iostream>
|
||||
#include <support/app_control.h>
|
||||
#include "example_interfaces.h"
|
||||
#include "example_reception_interfaces.h"
|
||||
#include "example_transfer_interfaces.h"
|
||||
|
||||
/**
|
||||
* @brief check if SDV_FRAMEWORK_RUNTIME environment variable exists
|
||||
* @return Return true if environment variable is found otherwise false
|
||||
*/
|
||||
bool IsSDVFrameworkEnvironmentSet()
|
||||
{
|
||||
const char* envVariable = std::getenv("SDV_FRAMEWORK_RUNTIME");
|
||||
if (envVariable)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#if defined(_WIN32) && defined(_UNICODE)
|
||||
extern "C" int wmain()
|
||||
#else
|
||||
extern "C" int main()
|
||||
#endif
|
||||
{
|
||||
sdv::app::CAppControl appcontrol;
|
||||
if (!IsSDVFrameworkEnvironmentSet())
|
||||
{
|
||||
// if SDV_FRAMEWORK_RUNTIME environment variable is not set we need to set the Framework Runtime directory
|
||||
appcontrol.SetFrameworkRuntimeDirectory("../../bin");
|
||||
}
|
||||
|
||||
auto bResult = appcontrol.AddModuleSearchDir("../../bin");
|
||||
bResult &= appcontrol.Startup("");
|
||||
|
||||
appcontrol.SetConfigMode();
|
||||
bResult &= appcontrol.AddConfigSearchDir("config");
|
||||
bResult &= appcontrol.LoadConfig("docu_app_examples.toml") == sdv::core::EConfigProcessResult::successful;
|
||||
if (!bResult)
|
||||
{
|
||||
std::cout << "Exit, Could not load docu_examples.toml." << std::endl;
|
||||
appcontrol.Shutdown();
|
||||
return 0;
|
||||
}
|
||||
|
||||
appcontrol.SetRunningMode();
|
||||
auto hello1 = sdv::core::GetObject("Hello_Component").GetInterface<ISayHello>();
|
||||
auto bye1 = sdv::core::GetObject("Hello_Component").GetInterface<ISayGoodbye>();
|
||||
auto hello2 = sdv::core::GetObject("Hello_Component_With_Initialization").GetInterface<ISayHello>();
|
||||
auto bye2 = sdv::core::GetObject("Hello_Component_With_Initialization").GetInterface<ISayGoodbye>();
|
||||
if (!hello1 || !bye1 || !hello2 || !bye2)
|
||||
{
|
||||
hello1->SayHello();
|
||||
bye1->SayGoodbye();
|
||||
hello2->SayHello();
|
||||
bye2->SayGoodbye();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Could not get all interfaces interface" << std::endl;
|
||||
}
|
||||
|
||||
appcontrol.Shutdown();
|
||||
return 0;
|
||||
}
|
||||
122
examples/_howto_examples/source/example_basic_service.cpp
Normal file
122
examples/_howto_examples/source/example_basic_service.cpp
Normal file
@@ -0,0 +1,122 @@
|
||||
#include "example_interfaces.h"
|
||||
#include "example_reception_interfaces.h"
|
||||
#include "example_transfer_interfaces.h"
|
||||
|
||||
#include <support/signal_support.h>
|
||||
#include <support/component_impl.h>
|
||||
#include <interfaces/dispatch.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <set>
|
||||
|
||||
class CBasicService
|
||||
: public sdv::CSdvObject
|
||||
, public vss::Device::IReceptionSignalSpeed_Event
|
||||
, public vss::Service::IReceptionSignalSpeed
|
||||
, public vss::Service::ITransferSignalBrakeForce
|
||||
{
|
||||
public:
|
||||
CBasicService()
|
||||
{
|
||||
auto device = sdv::core::GetObject("VehicleDevice_Component").GetInterface<vss::Device::IReceptionSignalSpeed>();
|
||||
if (!device)
|
||||
{
|
||||
SDV_LOG_ERROR("Could not get abstract device: [CBasicService]");
|
||||
throw std::runtime_error("VehicleDevice_Component device not found");
|
||||
}
|
||||
device->RegisterSpeedEvent(static_cast<vss::Device::IReceptionSignalSpeed_Event*> (this));
|
||||
|
||||
m_BrakeForce = sdv::core::GetObject("VehicleDevice_Component").GetInterface<vss::Device::ITransferSignalBrakeForce>();
|
||||
if (!m_BrakeForce)
|
||||
{
|
||||
SDV_LOG_ERROR("Could not get abstract device: [CBasicService]");
|
||||
throw std::runtime_error("VehicleDevice_Component device not found");
|
||||
}
|
||||
|
||||
SDV_LOG_TRACE("CBasicService created: [BasicService_Component]");
|
||||
}
|
||||
|
||||
~CBasicService()
|
||||
{
|
||||
auto device = sdv::core::GetObject("VehicleDevice_Component").GetInterface<vss::Device::IReceptionSignalSpeed>();
|
||||
if (device)
|
||||
{
|
||||
device->UnRegisterSpeedEvent(static_cast<vss::Device::IReceptionSignalSpeed_Event*> (this));
|
||||
}
|
||||
}
|
||||
|
||||
BEGIN_SDV_INTERFACE_MAP()
|
||||
SDV_INTERFACE_ENTRY(vss::Service::IReceptionSignalSpeed)
|
||||
SDV_INTERFACE_ENTRY(vss::Device::IReceptionSignalSpeed_Event)
|
||||
SDV_INTERFACE_ENTRY(vss::Service::ITransferSignalBrakeForce)
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
DECLARE_OBJECT_CLASS_NAME("BasicService_Component")
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::BasicService);
|
||||
|
||||
/**
|
||||
* @brief Set brake force
|
||||
* @param[in] value of the brake force
|
||||
* @return true on success otherwise false
|
||||
*/
|
||||
bool SetBrakeForce(uint32_t value) override
|
||||
{
|
||||
return m_BrakeForce->SetBrakeForce(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set speed
|
||||
* @param[in] value speed
|
||||
*/
|
||||
void SetSpeedValue(int32_t value) override
|
||||
{
|
||||
m_Speed = value;
|
||||
std::lock_guard<std::mutex> lock(m_mutexCallbacks);
|
||||
for (auto callback : m_Callbacks)
|
||||
{
|
||||
callback->SetSpeedValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get Speedspeed
|
||||
*/
|
||||
int32_t GetSpeedValue() override
|
||||
{
|
||||
return m_Speed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Register Callback on signal change
|
||||
* @param[in] callback function
|
||||
*/
|
||||
void RegisterCallBack(/*in*/ vss::Device::IReceptionSignalSpeed_Event* callback) override
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutexCallbacks);
|
||||
m_Callbacks.insert(callback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Unregister Callback
|
||||
* @param[in] callback function
|
||||
*/
|
||||
void UnregisterCallBack(vss::Device::IReceptionSignalSpeed_Event* callback) override
|
||||
{
|
||||
if (callback)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutexCallbacks);
|
||||
m_Callbacks.erase(callback);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t m_Speed = { 0 }; ///< speed value which will be received
|
||||
mutable std::mutex m_mutexCallbacks; ///< Mutex protecting m_Callbacks
|
||||
std::set<vss::Device::IReceptionSignalSpeed_Event*> m_Callbacks; ///< collection of events to be called (received value)
|
||||
vss::Device::ITransferSignalBrakeForce* m_BrakeForce = nullptr; ///< To write the brake force to the abstract device
|
||||
};
|
||||
|
||||
DEFINE_SDV_OBJECT(CBasicService)
|
||||
78
examples/_howto_examples/source/example_complex_service.cpp
Normal file
78
examples/_howto_examples/source/example_complex_service.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
#include "example_reception_interfaces.h"
|
||||
#include "example_transfer_interfaces.h"
|
||||
|
||||
#include <support/signal_support.h>
|
||||
#include <support/component_impl.h>
|
||||
#include <interfaces/dispatch.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <set>
|
||||
|
||||
class CComplexService
|
||||
: public sdv::CSdvObject
|
||||
, public vss::Device::IReceptionSignalSpeed_Event
|
||||
//
|
||||
// complex service should offer interface(s) to be used by applications
|
||||
//
|
||||
{
|
||||
public:
|
||||
CComplexService()
|
||||
{
|
||||
m_SrvBrakeForce = sdv::core::GetObject("BasicService_Component").GetInterface<vss::Service::ITransferSignalBrakeForce>();
|
||||
if (!m_SrvBrakeForce)
|
||||
{
|
||||
SDV_LOG_ERROR("Could not get basic service: [CComplexService]");
|
||||
throw std::runtime_error("Brake force service not found");
|
||||
}
|
||||
|
||||
auto serviceSpeed = sdv::core::GetObject("BasicService_Component").GetInterface<vss::Service::IReceptionSignalSpeed>();
|
||||
if (serviceSpeed)
|
||||
{
|
||||
serviceSpeed->RegisterCallBack(static_cast<vss::Device::IReceptionSignalSpeed_Event*> (this));
|
||||
}
|
||||
else
|
||||
{
|
||||
SDV_LOG_ERROR("Could not get basic service: [CComplexService]");
|
||||
throw std::runtime_error("Speed service not found");
|
||||
}
|
||||
}
|
||||
|
||||
~CComplexService()
|
||||
{
|
||||
auto serviceSpeed = sdv::core::GetObject("BasicService_Component").GetInterface<vss::Service::IReceptionSignalSpeed>();
|
||||
if (serviceSpeed)
|
||||
{
|
||||
serviceSpeed->UnregisterCallBack(static_cast<vss::Device::IReceptionSignalSpeed_Event*> (this));
|
||||
}
|
||||
}
|
||||
|
||||
BEGIN_SDV_INTERFACE_MAP()
|
||||
SDV_INTERFACE_ENTRY(vss::Device::IReceptionSignalSpeed_Event)
|
||||
//
|
||||
// complex service should offer interface(s) to be used by applications
|
||||
//
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
DECLARE_OBJECT_CLASS_NAME("ComplexService_Component")
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::ComplexService);
|
||||
|
||||
/**
|
||||
* @brief Set speed
|
||||
* @param[in] value speed
|
||||
*/
|
||||
void SetSpeedValue(int32_t value) override
|
||||
{
|
||||
if (value > m_SpeedMaximum)
|
||||
{
|
||||
//Forward brake force to the basic service
|
||||
m_SrvBrakeForce->SetBrakeForce(value);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
int32_t m_SpeedMaximum = { 100 }; ///< maximum allowed speed in this service implementation
|
||||
int32_t m_Speed = { 0 }; ///< speed value which will be received
|
||||
vss::Service::ITransferSignalBrakeForce* m_SrvBrakeForce = nullptr; ///< To write the brake force the basic service
|
||||
};
|
||||
|
||||
DEFINE_SDV_OBJECT(CComplexService)
|
||||
107
examples/_howto_examples/source/example_dispatch_service.cpp
Normal file
107
examples/_howto_examples/source/example_dispatch_service.cpp
Normal file
@@ -0,0 +1,107 @@
|
||||
#include <iostream>
|
||||
#include <support/toml.h>
|
||||
#include <support/component_impl.h>
|
||||
#include <support/signal_support.h>
|
||||
|
||||
class CExampleDispatchService
|
||||
{
|
||||
public:
|
||||
CExampleDispatchService()
|
||||
{
|
||||
sdv::core::CDispatchService dispatch;
|
||||
m_dataLinkSignalRx = dispatch.RegisterRxSignal("Signal_DataLink_to_AbstractDevice"); ///< signals created by data link
|
||||
m_dataLinkSignalTx01 = dispatch.RegisterTxSignal("Signal_AbstractDevice_to_DataLink_01", 123);
|
||||
m_dataLinkSignalTx02 = dispatch.RegisterTxSignal("Signal_AbstractDevice_to_DataLink_02", 123);
|
||||
m_dataLinkSignalTx03 = dispatch.RegisterTxSignal("Signal_AbstractDevice_to_DataLink_03", 123);
|
||||
}
|
||||
|
||||
~CExampleDispatchService()
|
||||
{
|
||||
if (m_dataLinkSignalRx)
|
||||
m_dataLinkSignalRx.Reset();
|
||||
if (m_dataLinkSignalTx01)
|
||||
m_dataLinkSignalTx01.Reset();
|
||||
if (m_dataLinkSignalTx02)
|
||||
m_dataLinkSignalTx02.Reset();
|
||||
if (m_dataLinkSignalTx03)
|
||||
m_dataLinkSignalTx03.Reset();
|
||||
}
|
||||
|
||||
void SubscripSignals()
|
||||
{
|
||||
sdv::core::CDispatchService dispatch;
|
||||
m_abstractDeviceSubscriper = dispatch.Subscribe("Signal_DataLink_to_AbstractDevice", [&](sdv::any_t value) { CallBackFunction(value); });
|
||||
if (!m_abstractDeviceSubscriper)
|
||||
{
|
||||
std::cout << "Could not subscrupe to 'Signal_DataLink_to_AbstractDevice'" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Subscript to 'Signal_DataLink_to_AbstractDevice'" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void AddPublisherSignals()
|
||||
{
|
||||
sdv::core::CDispatchService dispatch;
|
||||
m_abstractDevicePublisher01 = dispatch.AddPublisher("Signal_AbstractDevice_to_DataLink_01");
|
||||
m_abstractDevicePublisher02 = dispatch.AddPublisher("Signal_AbstractDevice_to_DataLink_02");
|
||||
m_abstractDevicePublisher03 = dispatch.AddPublisher("Signal_AbstractDevice_to_DataLink_03");
|
||||
if (!m_abstractDevicePublisher01 || !m_abstractDevicePublisher02 || !m_abstractDevicePublisher03 )
|
||||
{
|
||||
std::cout << "Could not add publisher to 'Signal_AbstractDevice_to_DataLink'" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Publisher added to 'Signal_AbstractDevice_to_DataLink'" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void DataLinkWriter(const uint32_t value)
|
||||
{
|
||||
m_dataLinkSignalRx.Write(value);
|
||||
}
|
||||
|
||||
void WriteToSignalAsPublisher(const uint32_t value01, const uint32_t value02, const uint32_t value03)
|
||||
{
|
||||
sdv::core::CDispatchService dispatch;
|
||||
auto transaction = dispatch.CreateTransaction();
|
||||
m_abstractDevicePublisher01.Write(value01, transaction);
|
||||
m_abstractDevicePublisher02.Write(value02, transaction);
|
||||
m_abstractDevicePublisher03.Write(value03, transaction);
|
||||
transaction.Finish();
|
||||
}
|
||||
|
||||
void GetTxSignalValue(const std::string& msg, uint32_t& value01, uint32_t& value02, uint32_t& value03)
|
||||
{
|
||||
sdv::core::CDispatchService dispatch;
|
||||
auto transaction = dispatch.CreateTransaction();
|
||||
value01 = m_dataLinkSignalTx01.Read(transaction).get<uint32_t>();
|
||||
value02 = m_dataLinkSignalTx02.Read(transaction).get<uint32_t>();
|
||||
value03 = m_dataLinkSignalTx03.Read(transaction).get<uint32_t>();
|
||||
transaction.Finish();
|
||||
std::cout << "Read Tx signals (" << msg.c_str() <<"): " << std::to_string(value01) << ", " << std::to_string(value02) << ", " << std::to_string(value03) << std::endl;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* @brief CallBackFunction for the subscription
|
||||
*/
|
||||
void CallBackFunction(sdv::any_t value)
|
||||
{
|
||||
uint32_t sayHello = value.get<uint32_t>();
|
||||
std::cout << "This CallBackFunction is called on signal change: " << std::to_string(sayHello) << std::endl;
|
||||
}
|
||||
|
||||
sdv::core::CSignal m_dataLinkSignalRx; ///< signals created and used by data link
|
||||
sdv::core::CSignal m_dataLinkSignalTx01; ///< signals created and used by data link
|
||||
sdv::core::CSignal m_dataLinkSignalTx02; ///< signals created and used by data link
|
||||
sdv::core::CSignal m_dataLinkSignalTx03; ///< signals created and used by data link
|
||||
|
||||
sdv::core::CSignal m_abstractDeviceSubscriper; ///< signals used by an abstract device
|
||||
sdv::core::CSignal m_abstractDevicePublisher01; ///< signals used by an abstract device
|
||||
sdv::core::CSignal m_abstractDevicePublisher02; ///< signals used by an abstract device
|
||||
sdv::core::CSignal m_abstractDevicePublisher03; ///< signals used by an abstract device
|
||||
};
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "example_interfaces.h"
|
||||
#include <support/component_impl.h>
|
||||
|
||||
class CTestComponent
|
||||
: public sdv::CSdvObject
|
||||
, public ISayHello
|
||||
, public ISayGoodbye
|
||||
{
|
||||
public:
|
||||
CTestComponent()
|
||||
{
|
||||
std::cout << "Entering CTestComponent constructor..." << std::endl;
|
||||
}
|
||||
~CTestComponent() override
|
||||
{
|
||||
std::cout << "Entering CTestComponent destructor..." << std::endl;
|
||||
}
|
||||
|
||||
BEGIN_SDV_INTERFACE_MAP()
|
||||
SDV_INTERFACE_ENTRY(ISayHello)
|
||||
SDV_INTERFACE_ENTRY(ISayGoodbye)
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::Device)
|
||||
DECLARE_OBJECT_CLASS_NAME("Hello_Component")
|
||||
|
||||
/**
|
||||
* @brief Show hello message, implements the function of ISayHello
|
||||
*/
|
||||
void SayHello() override
|
||||
{
|
||||
std::cout << "Hello from Hello_Component ..." << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Show hello message, implements the function of ISayGoodbye
|
||||
*/
|
||||
void SayGoodbye() override
|
||||
{
|
||||
std::cout << "Goodbye from Hello_Component ..." << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
DEFINE_SDV_OBJECT(CTestComponent)
|
||||
@@ -0,0 +1,127 @@
|
||||
#include <iostream>
|
||||
#include <support/toml.h>
|
||||
#include <support/component_impl.h>
|
||||
#include "example_interfaces.h"
|
||||
|
||||
class CTestComponentWithInitialization
|
||||
: public sdv::CSdvObject
|
||||
, public sdv::IObjectControl
|
||||
, public ISayHello
|
||||
, public ISayGoodbye
|
||||
{
|
||||
public:
|
||||
CTestComponentWithInitialization()
|
||||
{
|
||||
std::cout << "Entering CTestComponentWithInitialization constructor..." << std::endl;
|
||||
}
|
||||
~CTestComponentWithInitialization() override
|
||||
{
|
||||
std::cout << "Entering CTestComponentWithInitialization destructor..." << std::endl;
|
||||
}
|
||||
|
||||
BEGIN_SDV_INTERFACE_MAP()
|
||||
SDV_INTERFACE_ENTRY(ISayHello)
|
||||
SDV_INTERFACE_ENTRY(ISayGoodbye)
|
||||
SDV_INTERFACE_ENTRY(sdv::IObjectControl)
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::Device)
|
||||
DECLARE_OBJECT_CLASS_NAME("Hello_Component_With_Initialization")
|
||||
|
||||
/**
|
||||
* @brief Initialize the object. Overload of sdv::IObjectControl::Initialize.
|
||||
* @param[in] ssObjectConfig Optional configuration string.
|
||||
*/
|
||||
inline virtual void Initialize(const sdv::u8string& ssObjectConfig) override
|
||||
{
|
||||
if (!ParseConfigurationString(ssObjectConfig))
|
||||
{
|
||||
m_status = sdv::EObjectStatus::initialization_failure;
|
||||
return;
|
||||
}
|
||||
m_status = sdv::EObjectStatus::initialized;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Set the component operation mode. Overload of sdv::IObjectControl::SetOperationMode.
|
||||
* @param[in] eMode The operation mode, the component should run in.
|
||||
*/
|
||||
void SetOperationMode(/*in*/ sdv::EOperationMode eMode) override
|
||||
{
|
||||
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 Get the current status of the object. Overload of sdv::IObjectControl::GetStatus.
|
||||
* @return Return the current status of the object.
|
||||
*/
|
||||
inline virtual sdv::EObjectStatus GetStatus() const override
|
||||
{
|
||||
return m_status;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Shutdown called before the object is destroyed. Overload of sdv::IObjectControl::Shutdown.
|
||||
*/
|
||||
inline virtual void Shutdown() override
|
||||
{
|
||||
m_status = sdv::EObjectStatus::destruction_pending;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Show messages, implements the function of IShowExample
|
||||
*/
|
||||
void SayHello() override
|
||||
{
|
||||
std::cout << "Hello from Hello_Component_With_Initialization ... " << std::to_string(m_Number) << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Show messages, implements the function of ISayGoodbye
|
||||
*/
|
||||
void SayGoodbye() override
|
||||
{
|
||||
std::cout << "Goodbye from Hello_Component_With_Initialization ... " << std::to_string(m_Number) << std::endl;
|
||||
}
|
||||
|
||||
private:
|
||||
bool ParseConfigurationString(const sdv::u8string& objectConfig)
|
||||
{
|
||||
try
|
||||
{
|
||||
sdv::toml::CTOMLParser config(objectConfig.c_str());
|
||||
|
||||
// get any settings from the configuration
|
||||
auto nodeNumber = config.GetDirect("number");
|
||||
if (nodeNumber.GetType() == sdv::toml::ENodeType::node_integer)
|
||||
{
|
||||
m_Number = static_cast<int32_t>(nodeNumber.GetValue());
|
||||
}
|
||||
}
|
||||
catch (const sdv::toml::XTOMLParseException& e)
|
||||
{
|
||||
std::cout << "Configuration could not be read:" << e.what() << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::cout << "Initialization number: " << std::to_string(m_Number) << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t m_Number = -1;
|
||||
std::atomic<sdv::EObjectStatus> m_status = { sdv::EObjectStatus::initialization_pending }; //!< To update the object status when it changes.
|
||||
};
|
||||
|
||||
DEFINE_SDV_OBJECT(CTestComponentWithInitialization)
|
||||
7
examples/_howto_examples/source/example_idl.h
Normal file
7
examples/_howto_examples/source/example_idl.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <interfaces/core.idl>
|
||||
|
||||
interface ISayHello
|
||||
{
|
||||
void SayHello() const;
|
||||
};
|
||||
|
||||
21
examples/_howto_examples/source/example_interfaces.h
Normal file
21
examples/_howto_examples/source/example_interfaces.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <interfaces/core.h>
|
||||
#include <support/signal_support.h>
|
||||
|
||||
interface ISayHello ///< interface example ISayHello
|
||||
{
|
||||
virtual void SayHello() = 0; ///< function og the interface
|
||||
static constexpr ::sdv::interface_id _id = 0xA012345678900100; ///< Interface Id
|
||||
};
|
||||
|
||||
interface ISayGoodbye ///< interface example ISayGoodbye
|
||||
{
|
||||
virtual void SayGoodbye() = 0; ///< function og the interface
|
||||
static constexpr ::sdv::interface_id _id = 0xA012345678900200; ///< Interface Id
|
||||
};
|
||||
|
||||
interface IShowExample ///< interface example IShowExample
|
||||
{
|
||||
virtual void Show() = 0; ///< function og the interface
|
||||
static constexpr ::sdv::interface_id _id = 0xA012345678900300; ///< Interface Id
|
||||
};
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
#include <interfaces/core.h>
|
||||
#include <support/signal_support.h>
|
||||
|
||||
namespace vss
|
||||
{
|
||||
namespace Device
|
||||
{
|
||||
/**
|
||||
* @brief IReceptionSignalSpeed abstract device interface, example of receiving a value
|
||||
*/
|
||||
interface IReceptionSignalSpeed_Event
|
||||
{
|
||||
/** Interface ID. */
|
||||
static constexpr ::sdv::interface_id _id = 0xA012345678900400;
|
||||
|
||||
/**
|
||||
* @brief Set Speed value (for example of type int32_t)
|
||||
* @param[in] value of current speed
|
||||
*/
|
||||
virtual void SetSpeedValue(/*in*/ int32_t value) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief IReceptionSignalSpeed abstract device interface, example of receiving a value
|
||||
*/
|
||||
interface IReceptionSignalSpeed
|
||||
{
|
||||
/** Interface ID. */
|
||||
static constexpr ::sdv::interface_id _id = 0xA012345678900500;
|
||||
|
||||
/**
|
||||
* @brief Register IReceptionSignalSpeed_Event on signal change
|
||||
* Register all events and call them on signal change
|
||||
* @param[in] event function
|
||||
*/
|
||||
virtual void RegisterSpeedEvent(/*in*/ IReceptionSignalSpeed_Event* event) = 0;
|
||||
|
||||
/**
|
||||
* @brief UnRegister IReceptionSignalSpeed_Event on signal change
|
||||
* Register all events and call them on signal change
|
||||
* @param[in] event function
|
||||
*/
|
||||
virtual void UnRegisterSpeedEvent(/*in*/ IReceptionSignalSpeed_Event* event) = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace vss
|
||||
{
|
||||
namespace Service
|
||||
{
|
||||
/**
|
||||
* @brief Vehicle speed service
|
||||
*/
|
||||
interface IReceptionSignalSpeed
|
||||
{
|
||||
/** Interface ID. */
|
||||
static constexpr ::sdv::interface_id _id = 0xA012345678900600;
|
||||
|
||||
/**
|
||||
* @brief Get Speed value (for example of type int32_t)
|
||||
* @return Returns current speed
|
||||
*/
|
||||
virtual int32_t GetSpeedValue() = 0;
|
||||
|
||||
/**
|
||||
* @brief Register Callback on signal change
|
||||
* @param[in] callback function
|
||||
*/
|
||||
virtual void RegisterCallBack(/*in*/ vss::Device::IReceptionSignalSpeed_Event* callback) = 0;
|
||||
|
||||
/**
|
||||
* @brief Unregister Callback
|
||||
* @param[in] callback function
|
||||
*/
|
||||
virtual void UnregisterCallBack(/*in*/ vss::Device::IReceptionSignalSpeed_Event* callback) = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#include <interfaces/core.h>
|
||||
#include <support/signal_support.h>
|
||||
|
||||
namespace vss
|
||||
{
|
||||
namespace Device
|
||||
{
|
||||
/**
|
||||
* @brief ITransferSignalBrakeForce interface, example of transferring a value
|
||||
*/
|
||||
interface ITransferSignalBrakeForce
|
||||
{
|
||||
/** Interface ID. */
|
||||
static constexpr ::sdv::interface_id _id = 0xA012345678900800;
|
||||
|
||||
/**
|
||||
* @brief Set brake force value
|
||||
* @param[in] value brake force
|
||||
* @return true on success otherwise false
|
||||
*/
|
||||
virtual bool SetBrakeForce(/*in*/ uint32_t value) = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace vss
|
||||
{
|
||||
namespace Service
|
||||
{
|
||||
/**
|
||||
* @brief ITransferSignalBrakeForce interface, example oftransferringg a value
|
||||
*/
|
||||
interface ITransferSignalBrakeForce
|
||||
{
|
||||
/** Interface ID. */
|
||||
static constexpr ::sdv::interface_id _id = 0xA012345678900900;
|
||||
|
||||
/**
|
||||
* @brief Set brake force value
|
||||
* @param[in] value brake force
|
||||
* @return true on success otherwise false
|
||||
*/
|
||||
virtual bool SetBrakeForce(/*in*/ uint32_t value) = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
123
examples/_howto_examples/source/example_vehicle_device.cpp
Normal file
123
examples/_howto_examples/source/example_vehicle_device.cpp
Normal file
@@ -0,0 +1,123 @@
|
||||
#include "example_interfaces.h"
|
||||
#include "example_reception_interfaces.h"
|
||||
#include "example_transfer_interfaces.h"
|
||||
|
||||
#include <support/signal_support.h>
|
||||
#include <support/component_impl.h>
|
||||
#include <interfaces/dispatch.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <set>
|
||||
|
||||
class CVehicleDevice
|
||||
: public sdv::CSdvObject
|
||||
, public vss::Device::IReceptionSignalSpeed
|
||||
, public vss::Device::ITransferSignalBrakeForce
|
||||
{
|
||||
public:
|
||||
CVehicleDevice()
|
||||
{
|
||||
sdv::core::CDispatchService dispatch;
|
||||
m_SpeedSignal = dispatch.Subscribe("SPEED_SIGNAL_NAME", [&](sdv::any_t value) { CallBackFunctionSpeedSignal(value); });
|
||||
if (!m_SpeedSignal)
|
||||
{
|
||||
std::cout << "Speed signal not found" << std::endl;
|
||||
throw std::runtime_error("SpeedSignal not found");
|
||||
}
|
||||
|
||||
m_TransferSignalBrakeForce = dispatch.AddPublisher("BRAKE_FORCE_SIGNAL_NAME");
|
||||
if (!m_TransferSignalBrakeForce)
|
||||
{
|
||||
std::cout << "BrakeForce signal not found" << std::endl;
|
||||
throw std::runtime_error("BrakeForce not found");
|
||||
}
|
||||
}
|
||||
|
||||
BEGIN_SDV_INTERFACE_MAP()
|
||||
SDV_INTERFACE_ENTRY(vss::Device::IReceptionSignalSpeed)
|
||||
SDV_INTERFACE_ENTRY(vss::Device::ITransferSignalBrakeForce)
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::Device)
|
||||
DECLARE_OBJECT_CLASS_NAME("VehicleDevice_Component")
|
||||
|
||||
~CVehicleDevice()
|
||||
{
|
||||
if (m_SpeedSignal)
|
||||
{
|
||||
m_SpeedSignal.Reset();
|
||||
}
|
||||
if (m_TransferSignalBrakeForce)
|
||||
{
|
||||
m_TransferSignalBrakeForce.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Register ReceptionSignalSpeed event on signal change
|
||||
* Collect all events and call them on signal change
|
||||
* @param[in] event function
|
||||
*/
|
||||
void RegisterSpeedEvent(vss::Device::IReceptionSignalSpeed_Event* event) override
|
||||
{
|
||||
if (event)
|
||||
{
|
||||
std::cout << "register a SignalSpeedEvent ..." << std::endl;
|
||||
std::lock_guard<std::mutex> lock(m_SpeedMutexCallbacks);
|
||||
m_SpeedCallbacks.insert(event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Register ReceptionSignalSpeed event on signal change
|
||||
* Collect all events and call them on signal change
|
||||
* @param[in] event function
|
||||
*/
|
||||
void UnRegisterSpeedEvent(vss::Device::IReceptionSignalSpeed_Event* event) override
|
||||
{
|
||||
if (event)
|
||||
{
|
||||
std::cout << "unregister a SignalSpeedEvent ..." << std::endl;
|
||||
std::lock_guard<std::mutex> lock(m_SpeedMutexCallbacks);
|
||||
m_SpeedCallbacks.erase(event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set brake force
|
||||
* @param[in] value of the brake force
|
||||
* @return true on success otherwise false
|
||||
*/
|
||||
bool SetBrakeForce(uint32_t value) override
|
||||
{
|
||||
if (m_TransferSignalBrakeForce)
|
||||
{
|
||||
m_TransferSignalBrakeForce.Write(value);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* @brief Execute all callbacks for the Speed Signal
|
||||
*/
|
||||
void CallBackFunctionSpeedSignal(sdv::any_t value)
|
||||
{
|
||||
uint32_t speed = value.get<uint32_t>();
|
||||
std::cout << "CallBackFunction SpeedSignal: " << std::to_string(speed) << std::endl;
|
||||
std::lock_guard<std::mutex> lock(m_SpeedMutexCallbacks);
|
||||
for (auto callback : m_SpeedCallbacks)
|
||||
{
|
||||
callback->SetSpeedValue(speed);
|
||||
}
|
||||
}
|
||||
|
||||
sdv::core::CSignal m_TransferSignalBrakeForce; ///< SignalBrakeForce of the abstract device
|
||||
sdv::core::CSignal m_SpeedSignal; ///< SpeedSignal of the abstract device
|
||||
mutable std::mutex m_SpeedMutexCallbacks; ///< Mutex protecting m_SpeedCallbacks
|
||||
std::set<vss::Device::IReceptionSignalSpeed_Event*> m_SpeedCallbacks; ///< collection of IReceptionSignalSpeed events to be called
|
||||
};
|
||||
|
||||
DEFINE_SDV_OBJECT(CVehicleDevice)
|
||||
189
examples/_howto_examples/source/run_all_examples.cpp
Normal file
189
examples/_howto_examples/source/run_all_examples.cpp
Normal file
@@ -0,0 +1,189 @@
|
||||
#include <iostream>
|
||||
#include <support/signal_support.h>
|
||||
#include <support/app_control.h>
|
||||
#include "example_interfaces.h"
|
||||
#include "example_reception_interfaces.h"
|
||||
#include "example_transfer_interfaces.h"
|
||||
#include "example_dispatch_service.cpp"
|
||||
|
||||
sdv::core::CSignal m_signalSpeedRx;
|
||||
sdv::core::CSignal m_signalBrakeForceTx;
|
||||
|
||||
/**
|
||||
* @brief check if SDV_FRAMEWORK_RUNTIME environment variable exists
|
||||
* @return Return true if environment variable is found otherwise false
|
||||
*/
|
||||
bool IsSDVFrameworkEnvironmentSet()
|
||||
{
|
||||
const char* envVariable = std::getenv("SDV_FRAMEWORK_RUNTIME");
|
||||
if (envVariable)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void UsageOfGeneralComponent()
|
||||
{
|
||||
std::cout << "Running example of General Component use:" << std::endl;
|
||||
auto hello = sdv::core::GetObject("Hello_Component").GetInterface<ISayHello>();
|
||||
auto bye = sdv::core::GetObject("Hello_Component").GetInterface<ISayGoodbye>();
|
||||
if (!hello)
|
||||
std::cout << "Could not get hello interface" << std::endl;
|
||||
else
|
||||
hello->SayHello();
|
||||
if (!bye)
|
||||
std::cout << "Could not get bye interface" << std::endl;
|
||||
else
|
||||
bye->SayGoodbye();
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
void UsageOfGeneralComponentWithInitialization()
|
||||
{
|
||||
std::cout << "Running example of General Component With Initialization, the number should be 42:" << std::endl;
|
||||
auto hello = sdv::core::GetObject("Hello_Component_With_Initialization").GetInterface<ISayHello>();
|
||||
auto bye = sdv::core::GetObject("Hello_Component_With_Initialization").GetInterface<ISayGoodbye>();
|
||||
if (!hello)
|
||||
std::cout << "Could not get hello interface" << std::endl;
|
||||
else
|
||||
hello->SayHello();
|
||||
if (!bye)
|
||||
std::cout << "Could not get bye interface" << std::endl;
|
||||
else
|
||||
bye->SayGoodbye();
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
void UsageOfAbstractDeviceAndBasicService()
|
||||
{
|
||||
std::cout << "Running example of Abstract Device Component use:" << std::endl;
|
||||
|
||||
auto brakeForce = sdv::core::GetObject("BasicService_Component").GetInterface<vss::Service::ITransferSignalBrakeForce>();
|
||||
if (brakeForce)
|
||||
{
|
||||
brakeForce->SetBrakeForce(123);
|
||||
sdv::core::CDispatchService dispatch;
|
||||
auto transaction = dispatch.CreateTransaction();
|
||||
auto value = m_signalBrakeForceTx.Read(transaction).get<uint32_t>();
|
||||
transaction.Finish();
|
||||
std::cout << "Set Brake force 123 and read value: " << std::to_string(value) << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "No interface 'vss::Service::ITransferSignalBrakeForce' of the basic service " << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "Now a callback function should be called with 12345:" << std::endl;
|
||||
m_signalSpeedRx.Write(12345);
|
||||
|
||||
auto speed = sdv::core::GetObject("BasicService_Component").GetInterface<vss::Service::IReceptionSignalSpeed>();
|
||||
if (speed)
|
||||
{
|
||||
auto value = speed->GetSpeedValue();
|
||||
std::cout << "Speed value should be 12345: " << std::to_string(value) << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "No interface 'vss::Service::IReceptionSignalSpeed' of the basic service " << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "Complex service exists? " << std::to_string(sdv::core::GetObject("ComplexService_Component").IsValid()) << std::endl;
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
void UsageOfDataDispatchServiceAccess(CExampleDispatchService* exampleDispatchService)
|
||||
{
|
||||
uint32_t value01{ 0 };
|
||||
uint32_t value02{ 0 };
|
||||
uint32_t value03{ 0 };
|
||||
std::cout << "Running example of dispatchservice\n";
|
||||
std::cout << "Start: " << std::to_string(value01) << " " << std::to_string(value02) << " " << std::to_string(value03) << " " << std::endl;
|
||||
|
||||
exampleDispatchService->GetTxSignalValue("after creation", value01, value02, value03);
|
||||
|
||||
exampleDispatchService->WriteToSignalAsPublisher(17, 18, 19);
|
||||
exampleDispatchService->GetTxSignalValue("after 17, 18, 19 written", value01, value02, value03);
|
||||
exampleDispatchService->GetTxSignalValue("after nothing changed", value01, value02, value03);
|
||||
|
||||
exampleDispatchService->WriteToSignalAsPublisher(456, 455, 454);
|
||||
exampleDispatchService->GetTxSignalValue("after 456, 455, 454 written", value01, value02, value03);
|
||||
|
||||
std::cout << "Write 77 to RX signal: " << std::endl;
|
||||
exampleDispatchService->DataLinkWriter(77);
|
||||
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
bool InitializeAppControl(sdv::app::CAppControl* appcontrol)
|
||||
{
|
||||
auto bResult = appcontrol->AddModuleSearchDir("../../bin");
|
||||
bResult &= appcontrol->Startup("");
|
||||
appcontrol->SetConfigMode();
|
||||
if (appcontrol->LoadConfig("docu_dispatch.toml") != sdv::core::EConfigProcessResult::successful)
|
||||
{
|
||||
std::cout << "dispatch service could be loaded" << std::endl;
|
||||
}
|
||||
|
||||
sdv::core::CDispatchService dispatch;
|
||||
m_signalSpeedRx = dispatch.RegisterRxSignal("SPEED_SIGNAL_NAME"); ///< signals for abstract device
|
||||
m_signalBrakeForceTx = dispatch.RegisterTxSignal("BRAKE_FORCE_SIGNAL_NAME", 0);
|
||||
if (!m_signalSpeedRx || !m_signalBrakeForceTx)
|
||||
{
|
||||
std::cout << "Signal for Speed and Brake Force could not be registered" << std::endl;
|
||||
bResult = false;
|
||||
}
|
||||
|
||||
if (appcontrol->LoadConfig("docu_examples.toml") != sdv::core::EConfigProcessResult::successful)
|
||||
{
|
||||
std::cout << "Not all examples could be loaded" << std::endl;
|
||||
bResult = false;
|
||||
}
|
||||
|
||||
return bResult;
|
||||
}
|
||||
|
||||
void AddPuplisherAndSubscriper(CExampleDispatchService* exampleDispatchService)
|
||||
{
|
||||
exampleDispatchService->AddPublisherSignals();
|
||||
exampleDispatchService->SubscripSignals();
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
#if defined(_WIN32) && defined(_UNICODE)
|
||||
extern "C" int wmain()
|
||||
#else
|
||||
extern "C" int main()
|
||||
#endif
|
||||
{
|
||||
sdv::app::CAppControl appcontrol;
|
||||
if (!IsSDVFrameworkEnvironmentSet())
|
||||
{
|
||||
// if SDV_FRAMEWORK_RUNTIME environment variable is not set we need to set the Framework Runtime directory
|
||||
appcontrol.SetFrameworkRuntimeDirectory("../../bin");
|
||||
}
|
||||
|
||||
std::cout << "Run documentation code examples:\n- Initialization/Configuration mode.\n" << std::endl;
|
||||
InitializeAppControl(&appcontrol);
|
||||
|
||||
CExampleDispatchService exampleDispatchService;
|
||||
AddPuplisherAndSubscriper(&exampleDispatchService); // for dispatch example, must be done before appcontrol.SetRunningMode();
|
||||
appcontrol.SetRunningMode();
|
||||
std::cout << "- Set running mode\n" << std::endl;
|
||||
|
||||
std::cout << "------------------------------------------------\n---Running UsageOfDataDispatchServiceAccess():" << std::endl;
|
||||
UsageOfDataDispatchServiceAccess(&exampleDispatchService);
|
||||
|
||||
std::cout << "------------------------------------------------\n---Running UsageOfGeneralComponent():" << std::endl;
|
||||
UsageOfGeneralComponent();
|
||||
|
||||
std::cout << "------------------------------------------------\n---Running UsageOfGeneralComponentWithInitialization():" << std::endl;
|
||||
UsageOfGeneralComponentWithInitialization();
|
||||
|
||||
std::cout << "------------------------------------------------\n---Running UsageOfAbstractDeviceAndBasicService():" << std::endl;
|
||||
UsageOfAbstractDeviceAndBasicService();
|
||||
|
||||
appcontrol.Shutdown();
|
||||
std::cout << "\n\nTest finished." << std::endl;
|
||||
return 0;
|
||||
}
|
||||
145
examples/auto_headlamp_example/CMakeLists.txt
Normal file
145
examples/auto_headlamp_example/CMakeLists.txt
Normal file
@@ -0,0 +1,145 @@
|
||||
project(AutoHeadlight)
|
||||
|
||||
# Use new policy for project version settings and default warning level
|
||||
cmake_policy(SET CMP0048 NEW) # requires CMake 3.14
|
||||
cmake_policy(SET CMP0092 NEW) # requires CMake 3.15
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
# Library symbols are hidden by default
|
||||
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
|
||||
|
||||
# Include directory to the core framework
|
||||
include_directories(${SDV_FRAMEWORK_DEV_INCLUDE})
|
||||
|
||||
######################################################################################################################################################################
|
||||
# preparation
|
||||
######################################################################################################################################################################
|
||||
|
||||
# REMARK: The code generation for the proxy/stub, interface definitions and serialization, the vehicle devices and the basic
|
||||
# services are generated during the configuration phase of CMake. This is necessary, since CMakeFiles.txt files are generated and
|
||||
# they have to be available during the configuration phase of CMake to be taken into the build process. Requisite for the code
|
||||
# generation during the configuration time of CMake is the availability of the tools to do the generation. Hence the tools cannot be
|
||||
# created during the build process, which is executed after the configuration process.
|
||||
|
||||
# Execute sdv_vss_util to create IDL files for devices and basic services.
|
||||
message("Create interface code for devices and basic services of auto headlight example.")
|
||||
execute_process(COMMAND "${SDV_VSS_UTIL}" "${PROJECT_SOURCE_DIR}/vss_autoheadlight_example.csv" "-O${PROJECT_SOURCE_DIR}/generated/" --prefixheadlight --version1.0.0.1 --enable_components)
|
||||
|
||||
# Execute the IDL compiler for the VSS interfaces to digest interface code.
|
||||
message("Compiling vss_vehiclepositioncurrentlatitude_vd_rx.idl")
|
||||
execute_process(COMMAND "${SDV_IDL_COMPILER}" "${PROJECT_SOURCE_DIR}/generated/vss_files/vss_vehiclepositioncurrentlatitude_vd_rx.idl" "-O${PROJECT_SOURCE_DIR}/generated/vss_files/" "-I${SDV_FRAMEWORK_DEV_INCLUDE}" -Igenerated/vss_files/ --no_ps)
|
||||
message("Compiling vss_vehiclepositioncurrentlatitude_bs_rx.idl")
|
||||
execute_process(COMMAND "${SDV_IDL_COMPILER}" "${PROJECT_SOURCE_DIR}/generated/vss_files/vss_vehiclepositioncurrentlatitude_bs_rx.idl" "-O${PROJECT_SOURCE_DIR}/generated/vss_files/" "-I${SDV_FRAMEWORK_DEV_INCLUDE}" -Igenerated/vss_files/ --ps_lib_nameautoheadlight_proxystub)
|
||||
message("Compiling vss_vehiclepositioncurrentlongitude_vd_rx.idl")
|
||||
execute_process(COMMAND "${SDV_IDL_COMPILER}" "${PROJECT_SOURCE_DIR}/generated/vss_files/vss_vehiclepositioncurrentlongitude_vd_rx.idl" "-O${PROJECT_SOURCE_DIR}/generated/vss_files/" "-I${SDV_FRAMEWORK_DEV_INCLUDE}" -Igenerated/vss_files/ --no_ps)
|
||||
message("Compiling vss_vehiclepositioncurrentlongitude_bs_rx.idl")
|
||||
execute_process(COMMAND "${SDV_IDL_COMPILER}" "${PROJECT_SOURCE_DIR}/generated/vss_files/vss_vehiclepositioncurrentlongitude_bs_rx.idl" "-O${PROJECT_SOURCE_DIR}/generated/vss_files/" "-I${SDV_FRAMEWORK_DEV_INCLUDE}" -Igenerated/vss_files/ --ps_lib_nameautoheadlight_proxystub)
|
||||
message("Compiling vss_vehiclebodyheadlight_vd_tx.idl")
|
||||
execute_process(COMMAND "${SDV_IDL_COMPILER}" "${PROJECT_SOURCE_DIR}/generated/vss_files/vss_vehiclebodylightfrontlowbeam_vd_tx.idl" "-O${PROJECT_SOURCE_DIR}/generated/vss_files/" "-I${SDV_FRAMEWORK_DEV_INCLUDE}" -Igenerated/vss_files/ --no_ps)
|
||||
message("Compiling vss_vehiclebodyheadlight_bs_tx.idl")
|
||||
execute_process(COMMAND "${SDV_IDL_COMPILER}" "${PROJECT_SOURCE_DIR}/generated/vss_files/vss_vehiclebodylightfrontlowbeam_bs_tx.idl" "-O${PROJECT_SOURCE_DIR}/generated/vss_files/" "-I${SDV_FRAMEWORK_DEV_INCLUDE}" -Igenerated/vss_files/ --ps_lib_nameautoheadlight_proxystub)
|
||||
|
||||
# Execute sdv_dbc_util to create FMU code.
|
||||
message("Create functional mockup unit (FMU) of auto headlight example.")
|
||||
execute_process(COMMAND ${SDV_DBC_UTIL} "${PROJECT_SOURCE_DIR}/datalink_autoheadlight_example.dbc" "-O${PROJECT_SOURCE_DIR}/generated/" --nodesheadlight --version1.0.0.1 --moduleAutoHeadlightFMU --dl_lib_nameautoheadlight_can_dl_example)
|
||||
|
||||
# Execute the IDL compiler for the complex service to digest interface code.
|
||||
message("Compiling autoheadlight_cs.idl")
|
||||
execute_process(COMMAND "${SDV_IDL_COMPILER}" "${PROJECT_SOURCE_DIR}/autoheadlight_service/autoheadlight_cs_ifc.idl" "-O${PROJECT_SOURCE_DIR}/generated/autoheadlight_service/" "-I${SDV_FRAMEWORK_DEV_INCLUDE}" -Iexample_service/ --ps_lib_nameautoheadlight_service_proxystub)
|
||||
|
||||
#######################################################################################################################################################################
|
||||
## vehicle devices and basic services
|
||||
#######################################################################################################################################################################
|
||||
|
||||
# REMARK: Proxy/stub and vehicle device and basic service code was generated during the configuration phase of CMake. Following
|
||||
# below are the build steps to build the components that were generated.
|
||||
|
||||
message("Include: auto headlight proxy/stub for vehicle devices and basic services")
|
||||
include_directories(${CMAKE_CURRENT_LIST_DIR}/generated/vss_files)
|
||||
add_subdirectory(generated/vss_files/ps)
|
||||
|
||||
|
||||
add_subdirectory(generated/vss_files/vd_currentlatitude)
|
||||
add_subdirectory(generated/vss_files/vd_currentlongitude)
|
||||
add_subdirectory(generated/vss_files/vd_headlightlowbeam)
|
||||
|
||||
add_subdirectory(generated/vss_files/bs_currentlatitude)
|
||||
add_subdirectory(generated/vss_files/bs_currentlongitude)
|
||||
add_subdirectory(generated/vss_files/bs_headlightlowbeam)
|
||||
|
||||
|
||||
######################################################################################################################################################################
|
||||
# complex service
|
||||
######################################################################################################################################################################
|
||||
|
||||
message("Include: proxy/stub for complex autoheadlight service")
|
||||
include_directories(${CMAKE_CURRENT_LIST_DIR}/generated/autoheadlight_service)
|
||||
add_subdirectory(generated/autoheadlight_service/ps)
|
||||
|
||||
message("Include: Auto Headlight complex service")
|
||||
add_library(autoheadlight_complex_service SHARED
|
||||
"autoheadlight_service/autoheadlight_cs.h"
|
||||
"autoheadlight_service/autoheadlight_cs.cpp"
|
||||
)
|
||||
set_target_properties(autoheadlight_complex_service PROPERTIES OUTPUT_NAME "autoheadlight_service")
|
||||
set_target_properties(autoheadlight_complex_service PROPERTIES PREFIX "")
|
||||
set_target_properties(autoheadlight_complex_service PROPERTIES SUFFIX ".sdv")
|
||||
|
||||
######################################################################################################################################################################
|
||||
# autoheadlight application
|
||||
######################################################################################################################################################################
|
||||
|
||||
# Define the executable
|
||||
add_executable(auto_headlight_app
|
||||
autoheadlight_app/autoheadlight_app.cpp
|
||||
autoheadlight_app/autoheadlight_simulate.h
|
||||
autoheadlight_app/autoheadlight_simulate.cpp
|
||||
autoheadlight_app/autoheadlight_console.h
|
||||
autoheadlight_app/autoheadlight_console.cpp
|
||||
autoheadlight_app/signal_names.h
|
||||
)
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
if (WIN32)
|
||||
target_link_libraries(auto_headlight_app Ws2_32 Winmm Rpcrt4.lib)
|
||||
else()
|
||||
target_link_libraries(auto_headlight_app ${CMAKE_DL_LIBS} rt ${CMAKE_THREAD_LIBS_INIT})
|
||||
endif()
|
||||
else()
|
||||
target_link_libraries(auto_headlight_app Rpcrt4.lib)
|
||||
endif()
|
||||
|
||||
# # Copy the config files
|
||||
# file (COPY ${PROJECT_SOURCE_DIR}/config/CanSocketExample.toml DESTINATION ${CMAKE_BINARY_DIR}/bin/config)
|
||||
file (COPY ${PROJECT_SOURCE_DIR}/config/data_link_example.toml DESTINATION ${CMAKE_BINARY_DIR}/bin/config)
|
||||
file (COPY ${PROJECT_SOURCE_DIR}/config/data_dispatch_example.toml DESTINATION ${CMAKE_BINARY_DIR}/bin/config)
|
||||
file (COPY ${PROJECT_SOURCE_DIR}/config/task_timer_example.toml DESTINATION ${CMAKE_BINARY_DIR}/bin/config)
|
||||
file (COPY ${PROJECT_SOURCE_DIR}/config/autoheadlight_vd_bs.toml DESTINATION ${CMAKE_BINARY_DIR}/bin/config)
|
||||
file (COPY ${PROJECT_SOURCE_DIR}/config/autoheadlight_cs.toml DESTINATION ${CMAKE_BINARY_DIR}/bin/config)
|
||||
|
||||
|
||||
|
||||
######################################################################################################################################################################
|
||||
# auto headlight fmu for OpenXilEnv
|
||||
######################################################################################################################################################################
|
||||
|
||||
# REMARK: The CMAKE created by sdv_dbc_util creates all files including the buildDescription.xml
|
||||
#
|
||||
# What cannot be created automatically is the method OpenAPILoad(const std::string& resources) in file model.cpp
|
||||
# The method must load all required components
|
||||
# Therfore here the file is copied and overwritten the auto generated file
|
||||
#
|
||||
# The required toml files need to be copied to the folder:
|
||||
# generated/fmu_DemoExampleFMU/DemoExampleFMU/resources
|
||||
|
||||
message("Include: FMU AutoHeadlightFMU")
|
||||
# Copy the config files
|
||||
file (COPY ${PROJECT_SOURCE_DIR}/fmu_files/resources/fmu_autoheadlight_vd_bs.toml DESTINATION ${PROJECT_SOURCE_DIR}/generated/fmu_AutoHeadlightFMU/AutoHeadlightFMU/resources)
|
||||
file (COPY ${PROJECT_SOURCE_DIR}/fmu_files/resources/fmu_autoheadlight_cs.toml DESTINATION ${PROJECT_SOURCE_DIR}/generated/fmu_AutoHeadlightFMU/AutoHeadlightFMU/resources)
|
||||
|
||||
# Overwrite model.cpp with an identical file but loads all components in OpenAPILoad(const std::string& resources)
|
||||
file (COPY ${PROJECT_SOURCE_DIR}/fmu_files/model.cpp DESTINATION ${PROJECT_SOURCE_DIR}/generated/fmu_AutoHeadlightFMU/AutoHeadlightFMU)
|
||||
|
||||
# Now the project can be build
|
||||
add_subdirectory(generated/fmu_AutoHeadlightFMU)
|
||||
@@ -0,0 +1,35 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <support/app_control.h>
|
||||
#include <support/signal_support.h>
|
||||
#include "signal_names.h"
|
||||
|
||||
#include "autoheadlight_simulate.h"
|
||||
#include "autoheadlight_console.h"
|
||||
|
||||
#if defined(_WIN32) && defined(_UNICODE)
|
||||
extern "C" int wmain()
|
||||
#else
|
||||
extern "C" int main()
|
||||
#endif
|
||||
{
|
||||
CAutoHeadlightAppSimulate AppSimulate;
|
||||
|
||||
if(AppSimulate.Initialize()) //Initialize and if failed do not run the test run.
|
||||
{
|
||||
CConsole visual_obj;
|
||||
visual_obj.PrintHeader();
|
||||
visual_obj.PrepareDataConsumers(); // Get access to required services
|
||||
visual_obj.StartUpdateDataThread(); // start a thread to get Headlight and tunnel information and print on console
|
||||
|
||||
AppSimulate.ExecuteTestRun(); // Execute the test run feeding driveway data
|
||||
|
||||
visual_obj.StopUpdateDataThread();
|
||||
visual_obj.ResetSignals();
|
||||
|
||||
AppSimulate.Shutdown(); //Shutdown the app.
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,355 @@
|
||||
#include "autoheadlight_console.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <conio.h> // Needed for _kbhit
|
||||
#else
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
const CConsole::SConsolePos g_sTitle{ 1, 1 };
|
||||
const CConsole::SConsolePos g_sLatitudeMin{ 3, 1 };
|
||||
const CConsole::SConsolePos g_sLatitudeMax{ 3, 30 };
|
||||
const CConsole::SConsolePos g_sLongitudeMin{ 4, 1 };
|
||||
const CConsole::SConsolePos g_sLongitudeMax{ 4, 30 };
|
||||
const CConsole::SConsolePos g_sSeparator11{ 6, 1 };
|
||||
const CConsole::SConsolePos g_sSeparator12{ 8, 1 };
|
||||
const CConsole::SConsolePos g_sDispatchService1{ 9, 1 };
|
||||
const CConsole::SConsolePos g_sDispatchService2{ 10, 1 };
|
||||
const CConsole::SConsolePos g_sDispatchService4{ 12, 1 };
|
||||
const CConsole::SConsolePos g_sSeparator21{ 14, 1 };
|
||||
const CConsole::SConsolePos g_sSeparator22{ 16, 1 };
|
||||
const CConsole::SConsolePos g_sVehicleDevice1{ 17, 1 };
|
||||
const CConsole::SConsolePos g_sVehicleDevice2{ 18, 1 };
|
||||
const CConsole::SConsolePos g_sSeparator31{ 20, 1 };
|
||||
const CConsole::SConsolePos g_sSeparator32{ 22, 1 };
|
||||
const CConsole::SConsolePos g_sBasicService1{ 23, 1 };
|
||||
const CConsole::SConsolePos g_sBasicService2{ 24, 1 };
|
||||
const CConsole::SConsolePos g_sSeparator4{ 26, 1 };
|
||||
const CConsole::SConsolePos g_sComplexService1{ 28, 1 };
|
||||
const CConsole::SConsolePos g_sComplexService2{ 29, 1 };
|
||||
const CConsole::SConsolePos g_sComplexService3{ 30, 1 };
|
||||
const CConsole::SConsolePos g_sSeparator5{ 32, 1 };
|
||||
const CConsole::SConsolePos g_sControlDescription{ 34, 1 };
|
||||
const CConsole::SConsolePos g_sCursor{ 35, 1 };
|
||||
|
||||
CConsole::CConsole()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
// Enable ANSI escape codes
|
||||
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
if (hStdOut != INVALID_HANDLE_VALUE && GetConsoleMode(hStdOut, &m_dwConsoleOutMode))
|
||||
SetConsoleMode(hStdOut, m_dwConsoleOutMode | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
|
||||
HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE);
|
||||
if (hStdIn != INVALID_HANDLE_VALUE && GetConsoleMode(hStdIn, &m_dwConsoleInMode))
|
||||
SetConsoleMode(hStdIn, m_dwConsoleInMode & ~(ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT));
|
||||
#elif defined __unix__
|
||||
// Disable echo
|
||||
tcgetattr(STDIN_FILENO, &m_sTermAttr);
|
||||
struct termios sTermAttrTemp = m_sTermAttr;
|
||||
sTermAttrTemp.c_lflag &= ~(ICANON | ECHO);
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &sTermAttrTemp);
|
||||
m_iFileStatus = fcntl(STDIN_FILENO, F_GETFL, 0);
|
||||
fcntl(STDIN_FILENO, F_SETFL, m_iFileStatus | O_NONBLOCK);
|
||||
#else
|
||||
#error The OS is not supported!
|
||||
#endif
|
||||
}
|
||||
|
||||
CConsole::~CConsole()
|
||||
{
|
||||
SetCursorPos(g_sCursor);
|
||||
|
||||
#ifdef _WIN32
|
||||
// Return to the stored console mode
|
||||
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
if (hStdOut != INVALID_HANDLE_VALUE)
|
||||
SetConsoleMode(hStdOut, m_dwConsoleOutMode);
|
||||
HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE);
|
||||
if (hStdIn != INVALID_HANDLE_VALUE)
|
||||
SetConsoleMode(hStdIn, m_dwConsoleInMode);
|
||||
#elif defined __unix__
|
||||
// Return the previous file status flags.
|
||||
fcntl(STDIN_FILENO, F_SETFL, m_iFileStatus);
|
||||
|
||||
// Return to previous terminal state
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &m_sTermAttr);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CConsole::PrintHeader()
|
||||
{
|
||||
// Clear the screen...
|
||||
std::cout << "\x1b[2J";
|
||||
|
||||
// Print the titles
|
||||
PrintText(g_sTitle, "Headlight");
|
||||
PrintText(g_sSeparator11, "============================================================================");
|
||||
PrintText(g_sSeparator12, "Data dispatch service:");
|
||||
PrintText(g_sSeparator21, "----------------------------------------------------------------------------");
|
||||
PrintText(g_sSeparator22, "Vehicle device:");
|
||||
PrintText(g_sSeparator31, "----------------------------------------------------------------------------");
|
||||
PrintText(g_sSeparator32, "Basic services:");
|
||||
PrintText(g_sSeparator4, "----------------------------------------------------------------------------");
|
||||
PrintText(g_sComplexService1, "Complex service:");
|
||||
PrintText(g_sSeparator5, "----------------------------------------------------------------------------");
|
||||
PrintText(g_sControlDescription, "Press 'X' to quit.");
|
||||
}
|
||||
|
||||
bool CConsole::PrepareDataConsumers()
|
||||
{
|
||||
// Vehicle Device
|
||||
auto pVDCurrentLatitudeSvc = sdv::core::GetObject("Vehicle.Position.CurrentLatitude_Device").GetInterface<vss::Vehicle::Position::CurrentLatitudeDevice::IVSS_CurrentLatitude>();
|
||||
if (!pVDCurrentLatitudeSvc)
|
||||
{
|
||||
SDV_LOG_ERROR("Could not get interface 'IVSS_GetVDCurrentLatitude': [CAutoHeadlightService]");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto pVDCurrentLongitudeSvc = sdv::core::GetObject("Vehicle.Position.CurrentLongitude_Device").GetInterface<vss::Vehicle::Position::CurrentLongitudeDevice::IVSS_CurrentLongitude>();
|
||||
if (!pVDCurrentLongitudeSvc)
|
||||
{
|
||||
SDV_LOG_ERROR("Could not get interface 'IVSS_GetVDCurrentLongitude': [CAutoHeadlightService]");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pVDCurrentLatitudeSvc)
|
||||
pVDCurrentLatitudeSvc->RegisterCurrentLatitudeEvent(static_cast<vss::Vehicle::Position::CurrentLatitudeDevice::IVSS_WriteCurrentLatitude_Event*> (this));
|
||||
|
||||
if (pVDCurrentLongitudeSvc)
|
||||
pVDCurrentLongitudeSvc->RegisterCurrentLongitudeEvent(static_cast<vss::Vehicle::Position::CurrentLongitudeDevice::IVSS_WriteCurrentLongitude_Event*> (this));
|
||||
|
||||
// BASIC SERVICES
|
||||
auto pBSCurrentLatitudeSvc = sdv::core::GetObject("Vehicle.Position.CurrentLatitude_Service").GetInterface<vss::Vehicle::Position::CurrentLatitudeService::IVSS_GetCurrentLatitude>();
|
||||
if (!pBSCurrentLatitudeSvc)
|
||||
{
|
||||
SDV_LOG_ERROR("Could not get interface 'IVSS_GetBSCurrentLatitude': [CAutoHeadlightService]");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto pBSCurrentLongitudeSvc = sdv::core::GetObject("Vehicle.Position.CurrentLongitude_Service").GetInterface<vss::Vehicle::Position::CurrentLongitudeService::IVSS_GetCurrentLongitude>();
|
||||
if (!pBSCurrentLongitudeSvc)
|
||||
{
|
||||
SDV_LOG_ERROR("Could not get interface 'IVSS_GetBSCurrentLongitude': [CAutoHeadlightService]");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pBSCurrentLatitudeSvc)
|
||||
pBSCurrentLatitudeSvc->RegisterOnSignalChangeOfFCurrentLatitude(static_cast<vss::Vehicle::Position::CurrentLatitudeService::IVSS_SetCurrentLatitude_Event*> (this));
|
||||
|
||||
if (pBSCurrentLongitudeSvc)
|
||||
pBSCurrentLongitudeSvc->RegisterOnSignalChangeOfFCurrentLongitude(static_cast<vss::Vehicle::Position::CurrentLongitudeService::IVSS_SetCurrentLongitude_Event*> (this));
|
||||
|
||||
RegisterSignals();
|
||||
UpdateTXSignal(g_sDispatchService4, "Headlight:", m_signalHeadlight, m_bHeadLight);
|
||||
|
||||
m_pIAutoheadlightComplexService = sdv::core::GetObject("Auto Headlight Service").GetInterface<IAutoheadlightService>();
|
||||
|
||||
if (!m_pIAutoheadlightComplexService)
|
||||
{
|
||||
SDV_LOG_ERROR("Console ERROR: Could not get complex service interface 'IAutoheadlightService'");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto tunnel = m_pIAutoheadlightComplexService->GetGPSBoundBox();
|
||||
|
||||
std::string minLatitude = "Tunnel Latitude: ";
|
||||
std::string maxLatitude = " - ";
|
||||
std::string minLongitude = " Longitude: ";
|
||||
std::string maxLongitude = " - ";
|
||||
minLatitude.append(std::to_string(tunnel.fTunnelMinLat));
|
||||
maxLatitude.append(std::to_string(tunnel.fTunnelMaxLat));
|
||||
minLongitude.append(std::to_string(tunnel.fTunnelMinLon));
|
||||
maxLongitude.append(std::to_string(tunnel.fTunnelMaxLon));
|
||||
|
||||
PrintText(g_sLatitudeMin, minLatitude);
|
||||
PrintText(g_sLatitudeMax, maxLatitude);
|
||||
PrintText(g_sLongitudeMin, minLongitude);
|
||||
PrintText(g_sLongitudeMax, maxLongitude);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool CConsole::RegisterSignals()
|
||||
{
|
||||
// Set the cursor position at the end
|
||||
SetCursorPos(g_sCursor);
|
||||
|
||||
sdv::core::CDispatchService dispatch;
|
||||
m_signalCurrentLatitude = dispatch.Subscribe(headlight::dsFCurrentLatitude, [&](sdv::any_t value) { CallbackCurrentLatitude(value); });
|
||||
m_signalCurrentLongitude = dispatch.Subscribe(headlight::dsFCurrentLongitude, [&](sdv::any_t value) { CallbackCurrentLongitude(value); });
|
||||
m_signalHeadlight = dispatch.RegisterTxSignal(headlight::dsBHeadLightLowBeam, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void CConsole::CallbackCurrentLatitude(sdv::any_t value)
|
||||
{
|
||||
m_fCurrentLatitude = value.get<float>();
|
||||
PrintValue(g_sDispatchService1, "Latitude: ", m_fCurrentLatitude, " N");
|
||||
}
|
||||
void CConsole::CallbackCurrentLongitude(sdv::any_t value)
|
||||
{
|
||||
m_fCurrentLongitude = value.get<float>();
|
||||
PrintValue(g_sDispatchService2, "Longitude: ", m_fCurrentLongitude, " E");
|
||||
}
|
||||
|
||||
|
||||
void CConsole::ResetSignals()
|
||||
{
|
||||
// Set the cursor position at the end
|
||||
SetCursorPos(g_sCursor);
|
||||
|
||||
// Vehicle Device
|
||||
auto pVDCurrentLatitudeSvc = sdv::core::GetObject("Vehicle.Position.CurrentLatitude_Device").GetInterface<vss::Vehicle::Position::CurrentLatitudeDevice::IVSS_CurrentLatitude>();
|
||||
if (pVDCurrentLatitudeSvc)
|
||||
pVDCurrentLatitudeSvc->UnregisterCurrentLatitudeEvent(static_cast<vss::Vehicle::Position::CurrentLatitudeDevice::IVSS_WriteCurrentLatitude_Event*> (this));
|
||||
|
||||
auto pVDCurrentLongitudeSvc = sdv::core::GetObject("Vehicle.Position.CurrentLongitude_Device").GetInterface<vss::Vehicle::Position::CurrentLongitudeDevice::IVSS_CurrentLongitude>();
|
||||
if (pVDCurrentLongitudeSvc)
|
||||
pVDCurrentLongitudeSvc->UnregisterCurrentLongitudeEvent(static_cast<vss::Vehicle::Position::CurrentLongitudeDevice::IVSS_WriteCurrentLongitude_Event*> (this));
|
||||
|
||||
// BASIC SERVICES
|
||||
auto pBSCurrentLatitudeSvc = sdv::core::GetObject("Vehicle.Position.CurrentLatitude_Service").GetInterface<vss::Vehicle::Position::CurrentLatitudeService::IVSS_GetCurrentLatitude>();
|
||||
if (pBSCurrentLatitudeSvc)
|
||||
pBSCurrentLatitudeSvc->RegisterOnSignalChangeOfFCurrentLatitude(static_cast<vss::Vehicle::Position::CurrentLatitudeService::IVSS_SetCurrentLatitude_Event*> (this));
|
||||
|
||||
auto pBSCurrentLongitudeSvc = sdv::core::GetObject("Vehicle.Position.CurrentLongitude_Service").GetInterface<vss::Vehicle::Position::CurrentLongitudeService::IVSS_GetCurrentLongitude>();
|
||||
if (pBSCurrentLongitudeSvc)
|
||||
pBSCurrentLongitudeSvc->RegisterOnSignalChangeOfFCurrentLongitude(static_cast<vss::Vehicle::Position::CurrentLongitudeService::IVSS_SetCurrentLongitude_Event*> (this));
|
||||
|
||||
|
||||
if (m_signalCurrentLatitude)
|
||||
{
|
||||
m_signalCurrentLatitude.Reset();
|
||||
}
|
||||
if (m_signalCurrentLongitude)
|
||||
{
|
||||
m_signalCurrentLongitude.Reset();
|
||||
}
|
||||
if (m_signalHeadlight)
|
||||
{
|
||||
m_signalHeadlight.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CConsole::WriteCurrentLatitude(float value)
|
||||
{
|
||||
m_fVehicleDeviceCurrentLatitude = value;
|
||||
PrintValue(g_sVehicleDevice1, "Latitude: ", m_fVehicleDeviceCurrentLatitude, " N");
|
||||
}
|
||||
|
||||
void CConsole::WriteCurrentLongitude(float value)
|
||||
{
|
||||
m_fVehicleDeviceCurrentLongitude = value;
|
||||
PrintValue(g_sVehicleDevice2, "Longitude: ", m_fVehicleDeviceCurrentLongitude, " E");
|
||||
}
|
||||
|
||||
void CConsole::SetCurrentLatitude(float value)
|
||||
{
|
||||
m_fBasicServiceCurrentLatitude = value;
|
||||
PrintValue(g_sBasicService1, "Latitude: ", m_fBasicServiceCurrentLatitude, " N");
|
||||
}
|
||||
|
||||
void CConsole::SetCurrentLongitude(float value)
|
||||
{
|
||||
m_fBasicServiceCurrentLongitude = value;
|
||||
PrintValue(g_sBasicService2, "Longitude: ", m_fBasicServiceCurrentLongitude, " E");
|
||||
}
|
||||
|
||||
CConsole::SConsolePos CConsole::GetCursorPos() const
|
||||
{
|
||||
SConsolePos sPos{};
|
||||
std::cout << "\033[6n";
|
||||
|
||||
char buff[128];
|
||||
int indx = 0;
|
||||
for (;;) {
|
||||
int cc = std::cin.get();
|
||||
buff[indx] = (char)cc;
|
||||
indx++;
|
||||
if (cc == 'R') {
|
||||
buff[indx + 1] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
int iRow = 0, iCol = 0;
|
||||
sscanf(buff, "\x1b[%d;%dR", &iRow, &iCol);
|
||||
sPos.uiRow = static_cast<uint32_t>(iRow);
|
||||
sPos.uiCol = static_cast<uint32_t>(iCol);
|
||||
fseek(stdin, 0, SEEK_END);
|
||||
|
||||
return sPos;
|
||||
}
|
||||
|
||||
void CConsole::SetCursorPos(SConsolePos sPos)
|
||||
{
|
||||
std::cout << "\033[" << sPos.uiRow << ";" << sPos.uiCol << "H";
|
||||
}
|
||||
|
||||
void CConsole::PrintText(SConsolePos sPos, const std::string& rssText)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mtxPrintToConsole);
|
||||
SetCursorPos(sPos);
|
||||
std::cout << rssText;
|
||||
}
|
||||
|
||||
|
||||
void CConsole::UpdateTXSignal(SConsolePos sPos, const std::string& label, sdv::core::CSignal& signal, bool& value)
|
||||
{
|
||||
if (signal)
|
||||
{
|
||||
auto headlight = value;
|
||||
value = signal.Read().get<bool>();
|
||||
if (headlight != value)
|
||||
{
|
||||
PrintValue(sPos, label, value, (value ? "on >>>>>>>>>>>>>>>>>>>>>>" : "off "));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CConsole::UpdateDataThreadFunc()
|
||||
{
|
||||
static auto oldLight = m_pIAutoheadlightComplexService->GetHeadlightStatus();
|
||||
static auto olsIsInTunnel = m_pIAutoheadlightComplexService->IsinTunnel();
|
||||
PrintValue(g_sComplexService2, "Light: ", olsIsInTunnel, (olsIsInTunnel ? "on" : "off"));
|
||||
PrintValue(g_sComplexService3, "Is in tunnel: ", oldLight, (oldLight ? "yes" : "no"));
|
||||
while (m_bRunning)
|
||||
{
|
||||
UpdateTXSignal(g_sDispatchService4, "Headlight:", m_signalHeadlight, m_bHeadLight);
|
||||
auto light = m_pIAutoheadlightComplexService->GetHeadlightStatus();
|
||||
if (oldLight != light)
|
||||
{
|
||||
PrintValue(g_sComplexService3, "Is in tunnel: ", light, (light ? "yes" : "no"));
|
||||
oldLight = light;
|
||||
}
|
||||
auto isInTunnel = m_pIAutoheadlightComplexService->IsinTunnel();
|
||||
if (olsIsInTunnel != isInTunnel)
|
||||
{
|
||||
PrintValue(g_sComplexService2, "Headlight: ", isInTunnel, (isInTunnel ? "on" : "off"));
|
||||
olsIsInTunnel = isInTunnel;
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
}
|
||||
|
||||
void CConsole::StartUpdateDataThread()
|
||||
{
|
||||
if (m_bThreadStarted)
|
||||
return;
|
||||
|
||||
m_bThreadStarted = true;
|
||||
|
||||
m_bRunning = true;
|
||||
m_threadReadTxSignals = std::thread(&CConsole::UpdateDataThreadFunc, this);
|
||||
}
|
||||
|
||||
void CConsole::StopUpdateDataThread()
|
||||
{
|
||||
// Stop running and wait for any thread to finalize
|
||||
m_bRunning = false;
|
||||
if (m_threadReadTxSignals.joinable())
|
||||
m_threadReadTxSignals.join();
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
#ifndef CONSOLE_OUTPUT_H
|
||||
#define CONSOLE_OUTPUT_H
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <support/signal_support.h>
|
||||
#include <support/app_control.h>
|
||||
#include <support/component_impl.h>
|
||||
#include <support/timer.h>
|
||||
#include "signal_names.h"
|
||||
#include <fcntl.h>
|
||||
#include "vss_vehiclepositioncurrentlatitude_vd_rx.h"
|
||||
#include "vss_vehiclepositioncurrentlongitude_vd_rx.h"
|
||||
#include "vss_vehiclepositioncurrentlatitude_bs_rx.h"
|
||||
#include "vss_vehiclepositioncurrentlongitude_bs_rx.h"
|
||||
#include "vss_vehiclebodylightfrontlowbeam_bs_tx.h"
|
||||
|
||||
// Complex service Headlight interface - located in ../generated/example_service
|
||||
#include "autoheadlight_cs_ifc.h"
|
||||
|
||||
#ifdef __unix__
|
||||
#include <termios.h> // Needed for tcgetattr and fcntl
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Console operation class.
|
||||
* @details This class retrieves RX data from the data dispatch service, vehicle device & basic service of front left door on event change.
|
||||
* Furthermore, it shows TX value by polling the RX signals.
|
||||
*/
|
||||
class CConsole :
|
||||
public vss::Vehicle::Position::CurrentLatitudeDevice::IVSS_WriteCurrentLatitude_Event, // Vehicle Device interface
|
||||
public vss::Vehicle::Position::CurrentLongitudeDevice::IVSS_WriteCurrentLongitude_Event, // Vehicle Device interface
|
||||
public vss::Vehicle::Position::CurrentLatitudeService::IVSS_SetCurrentLatitude_Event, // Basic service interface
|
||||
public vss::Vehicle::Position::CurrentLongitudeService::IVSS_SetCurrentLongitude_Event // Basic service interface
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Screen position structure
|
||||
*/
|
||||
struct SConsolePos
|
||||
{
|
||||
uint32_t uiRow; ///< Row position (starts at 1)
|
||||
uint32_t uiCol; ///< Column position (starts at 1)
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
CConsole();
|
||||
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
~CConsole();
|
||||
|
||||
/**
|
||||
* @brief Print the header.
|
||||
*/
|
||||
void PrintHeader();
|
||||
|
||||
/**
|
||||
* @brief Prepare the data consumers..
|
||||
* @details Gets all signals (2 RX signals [GPS] and 1 TX signals [headlight beam)
|
||||
* @return Returns whether the preparation of the data consumers was successful or not.
|
||||
*/
|
||||
bool PrepareDataConsumers();
|
||||
|
||||
/**
|
||||
* @brief For gracefully shutdown all signals need to be reset.
|
||||
*/
|
||||
void ResetSignals();
|
||||
|
||||
/**
|
||||
* @brief Starts thread for polling the TX signals
|
||||
*/
|
||||
void StartUpdateDataThread();
|
||||
|
||||
/**
|
||||
* @brief Stops thread
|
||||
*/
|
||||
void StopUpdateDataThread();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* @brief sets the current latitude.
|
||||
* @param[in] value current latitude value
|
||||
*/
|
||||
void WriteCurrentLatitude(float value) override;
|
||||
|
||||
/**
|
||||
* @brief sets the current longitude.
|
||||
* @param[in] value current longitude value
|
||||
*/
|
||||
void WriteCurrentLongitude(float value) override;
|
||||
|
||||
/**
|
||||
* @brief sets the current latitude.
|
||||
* @param[in] value current latitude value
|
||||
*/
|
||||
void SetCurrentLatitude(float value) override;
|
||||
|
||||
/**
|
||||
* @brief sets the current longitude.
|
||||
* @param[in] value current longitude value
|
||||
*/
|
||||
void SetCurrentLongitude(float value) override;
|
||||
|
||||
/**
|
||||
* @brief Register Signals
|
||||
* @return Return true if there was no issue with registering signals otherwise return false
|
||||
*/
|
||||
bool RegisterSignals();
|
||||
|
||||
/**
|
||||
* @brief Callback function when new latitude value is available
|
||||
* @param[in] value The value of the latitude
|
||||
*/
|
||||
void CallbackCurrentLatitude(sdv::any_t value);
|
||||
|
||||
/**
|
||||
* @brief Callback function when new longitude value is available
|
||||
* @param[in] value The value of the longitude
|
||||
*/
|
||||
void CallbackCurrentLongitude(sdv::any_t value);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Callback function when new latitude value is available
|
||||
* @param[in] value The value of the latitude
|
||||
*/
|
||||
void CallbackToSetCurrentLatitude(sdv::any_t value);
|
||||
|
||||
/**
|
||||
* @brief Callback function when new longitude value is available
|
||||
* @param[in] value The value of the longitude
|
||||
*/
|
||||
void CallbackToSetCurrentLongitude(sdv::any_t value);
|
||||
|
||||
/**
|
||||
* @brief Read the data link TX signals and print them into the console.
|
||||
*/
|
||||
void UpdateDataThreadFunc();
|
||||
|
||||
/**
|
||||
* @brief Update the signal on the console output depending on the signal
|
||||
* @details Check if the signal is valid. If invalid, ignore it.
|
||||
*/
|
||||
void UpdateTXSignal(SConsolePos sPos, const std::string& label, sdv::core::CSignal& signal, bool& value);
|
||||
|
||||
/**
|
||||
* @brief Get the cursor position of the console.
|
||||
* @return The cursor position.
|
||||
*/
|
||||
SConsolePos GetCursorPos() const;
|
||||
|
||||
/**
|
||||
* @brief Set the current cursor position for the console.
|
||||
* @param[in] sPos Console position to place the current cursor at.
|
||||
*/
|
||||
void SetCursorPos(SConsolePos sPos);
|
||||
|
||||
/**
|
||||
* @brief Print text at a specific location.
|
||||
* @param[in] sPos The location to print text at.
|
||||
* @param[in] rssText Reference to the text to print.
|
||||
*/
|
||||
void PrintText(SConsolePos sPos, const std::string& rssText);
|
||||
|
||||
/**
|
||||
* @brief Print a value string at a specific location.
|
||||
* @tparam TValue Type of value.
|
||||
* @param[in] sPos The location to print the value at.
|
||||
* @param[in] rssName Reference to the value.
|
||||
* @param[in] tValue The value.
|
||||
* @param[in] rssStatus Status, becuse we have signals of type bool
|
||||
*/
|
||||
template <typename TValue>
|
||||
void PrintValue(SConsolePos sPos, const std::string& rssName, TValue tValue, const std::string& rssStatus);
|
||||
|
||||
/**
|
||||
* @brief Align string between name and value.
|
||||
* @param[in] message Reference to the message to align.
|
||||
* @param[in] desiredLength The desired length or 0 when no length is specified.
|
||||
* @return The aligned string.
|
||||
*/
|
||||
std::string AlignString(const std::string& message, uint32_t desiredLength = 0);
|
||||
|
||||
mutable std::mutex m_mtxPrintToConsole; ///< Mutex to print complete message
|
||||
std::thread m_threadReadTxSignals; ///< Simulation datalink thread.
|
||||
bool m_bThreadStarted = false; ///< Set when initialized.
|
||||
bool m_bRunning = false; ///< When set, the application is running.
|
||||
mutable std::mutex m_mPrintToConsole; ///< Mutex to print complete message
|
||||
|
||||
sdv::core::CSignal m_signalCurrentLatitude; ///< Signal Current latitude
|
||||
sdv::core::CSignal m_signalCurrentLongitude; ///< Signal Current longitude
|
||||
sdv::core::CSignal m_signalHeadlight; ///< Signal Headlight status
|
||||
|
||||
float m_fCurrentLongitude = 0.0f; //< Current latitude
|
||||
float m_fCurrentLatitude = 0.0f; //< Current longitude
|
||||
bool m_bHeadLight = true; ///< Head light
|
||||
|
||||
float m_fVehicleDeviceCurrentLatitude = 0.0f; ///< Current latitude (Vehicle Device)
|
||||
float m_fVehicleDeviceCurrentLongitude = 0.0; ///< Current longitude (Vehicle Device)
|
||||
|
||||
float m_fBasicServiceCurrentLatitude = 0.0f; ///< Current latitude (basic Service)
|
||||
float m_fBasicServiceCurrentLongitude = 0.0; ///< Current longitude (basic Service)
|
||||
|
||||
IAutoheadlightService* m_pIAutoheadlightComplexService = nullptr; ///< Autoheadlight Service interface pointer.
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
DWORD m_dwConsoleOutMode = 0u; ///< The console mode before switching on ANSI support.
|
||||
DWORD m_dwConsoleInMode = 0u; ///< The console mode before switching on ANSI support.
|
||||
#elif defined __unix__
|
||||
struct termios m_sTermAttr {}; ///< The terminal attributes before disabling echo.
|
||||
int m_iFileStatus = 0; ///< The file status flags for STDIN.
|
||||
#else
|
||||
#error The OS is not supported!
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
template <typename TValue>
|
||||
inline void CConsole::PrintValue(SConsolePos sPos, const std::string& rssName, TValue tValue, const std::string& rssUnits)
|
||||
{
|
||||
const size_t nValueNameLen = 26;
|
||||
std::stringstream sstreamValueText;
|
||||
sstreamValueText << rssName <<
|
||||
std::string(nValueNameLen - std::min(rssName.size(), static_cast<size_t>(nValueNameLen - 1)) - 1, '.') <<
|
||||
" " << std::fixed << std::setprecision(6) << tValue << " " << rssUnits << " ";
|
||||
|
||||
std::lock_guard<std::mutex> lock(m_mPrintToConsole);
|
||||
SetCursorPos(sPos);
|
||||
std::cout << sstreamValueText.str();
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void CConsole::PrintValue<bool>(SConsolePos sPos, const std::string& rssName, bool bValue, const std::string& rssUnits)
|
||||
{
|
||||
PrintValue(sPos, rssName, bValue ? "" : "", rssUnits);
|
||||
}
|
||||
|
||||
|
||||
#endif // !define CONSOLE_OUTPUT_H
|
||||
@@ -0,0 +1,246 @@
|
||||
#include "autoheadlight_simulate.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <conio.h> // Needed for _kbhit
|
||||
#else
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
CAutoHeadlightAppSimulate::~CAutoHeadlightAppSimulate()
|
||||
{
|
||||
ResetSignalsSimDatalink();
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
bool CAutoHeadlightAppSimulate::Initialize()
|
||||
{
|
||||
if (m_bInitialized)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!IsSDVFrameworkEnvironmentSet())
|
||||
{
|
||||
// if SDV_FRAMEWORK_RUNTIME environment variable is not set we need to set the Framework Runtime directory
|
||||
m_appcontrol.SetFrameworkRuntimeDirectory("../../bin");
|
||||
std::cout << "framework runtime directory set\n";
|
||||
}
|
||||
auto bResult = m_appcontrol.Startup("");
|
||||
m_appcontrol.SetConfigMode();
|
||||
if (!m_appcontrol.AddConfigSearchDir("config"))
|
||||
{
|
||||
m_appcontrol.Shutdown();
|
||||
return false;
|
||||
}
|
||||
|
||||
bResult &= m_appcontrol.LoadConfig("data_dispatch_example.toml") == sdv::core::EConfigProcessResult::successful;
|
||||
bResult &= m_appcontrol.LoadConfig("task_timer_example.toml") == sdv::core::EConfigProcessResult::successful;
|
||||
|
||||
bResult &= RegisterSignalsSimDatalink(); //register signals
|
||||
|
||||
bResult &= m_appcontrol.LoadConfig("autoheadlight_vd_bs.toml") == sdv::core::EConfigProcessResult::successful;
|
||||
bResult &= m_appcontrol.LoadConfig("autoheadlight_cs.toml") == sdv::core::EConfigProcessResult::successful;
|
||||
if (!bResult)
|
||||
{
|
||||
SDV_LOG_ERROR("One or more configurations could not be loaded. Cannot continue.");
|
||||
m_appcontrol.Shutdown();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!GetAccessToServices())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CAutoHeadlightAppSimulate::Shutdown()
|
||||
{
|
||||
if (!m_bInitialized)
|
||||
m_appcontrol.Shutdown();
|
||||
m_bInitialized = false;
|
||||
}
|
||||
|
||||
bool CAutoHeadlightAppSimulate::GetAccessToServices()
|
||||
{
|
||||
m_VisualCurrentLatitude = m_dispatch.Subscribe(headlight::dsFCurrentLatitude, [&](sdv::any_t value) { CAutoHeadlightAppSimulate::CallbackToSetCurrentLatitude(value); });
|
||||
m_VisualCurrentLongitude = m_dispatch.Subscribe(headlight::dsFCurrentLongitude, [&](sdv::any_t value) { CAutoHeadlightAppSimulate::CallbackToSetCurrentLongitude(value); });
|
||||
|
||||
// BASIC SERVICES
|
||||
auto pCurrentLatitudeSvc = sdv::core::GetObject("Vehicle.Position.CurrentLatitude_Service").GetInterface<vss::Vehicle::Position::CurrentLatitudeService::IVSS_GetCurrentLatitude>();
|
||||
if (!pCurrentLatitudeSvc)
|
||||
{
|
||||
SDV_LOG_ERROR("Could not get interface 'IVSS_GetCurrentLatitude': [CAutoHeadlightService]");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto pCurrentLongitudeSvc = sdv::core::GetObject("Vehicle.Position.CurrentLongitude_Service").GetInterface<vss::Vehicle::Position::CurrentLongitudeService::IVSS_GetCurrentLongitude>();
|
||||
if (!pCurrentLongitudeSvc)
|
||||
{
|
||||
SDV_LOG_ERROR("Could not get interface 'IVSS_GetCurrentLongitude': [CAutoHeadlightService]");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pCurrentLatitudeSvc)
|
||||
pCurrentLatitudeSvc->RegisterOnSignalChangeOfFCurrentLatitude(static_cast<vss::Vehicle::Position::CurrentLatitudeService::IVSS_SetCurrentLatitude_Event*> (this));
|
||||
|
||||
if (pCurrentLongitudeSvc)
|
||||
pCurrentLongitudeSvc->RegisterOnSignalChangeOfFCurrentLongitude(static_cast<vss::Vehicle::Position::CurrentLongitudeService::IVSS_SetCurrentLongitude_Event*> (this));
|
||||
|
||||
// COMPLEX SERVICE
|
||||
|
||||
m_pIAutoheadlightComplexService = sdv::core::GetObject("Auto Headlight Service").GetInterface<IAutoheadlightService>();
|
||||
|
||||
if (!m_pIAutoheadlightComplexService)
|
||||
{
|
||||
SDV_LOG_ERROR("Console ERROR: Could not get complex service interface 'IAutoheadlightService'");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_bInitialized = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void CAutoHeadlightAppSimulate::ExecuteTestRun()
|
||||
{
|
||||
if (!m_bInitialized)
|
||||
return;
|
||||
|
||||
// Switch to running mode.
|
||||
m_appcontrol.SetRunningMode();
|
||||
m_bRunning = true;
|
||||
|
||||
bool bRunUntilBreak = true;
|
||||
while (bRunUntilBreak)
|
||||
{
|
||||
for (const GPS& position : m_DriveWayData)
|
||||
{
|
||||
m_signalCurrentLatitude.Write<float>(position.latitude);
|
||||
m_signalCurrentLongitude.Write<float>(position.longitude);
|
||||
|
||||
// Check for a key
|
||||
if (!KeyHit())
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get a keyboard value (if there is any).
|
||||
char c = GetChar();
|
||||
if (c == 'x' || c == 'X')
|
||||
{
|
||||
bRunUntilBreak = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool CAutoHeadlightAppSimulate::RegisterSignalsSimDatalink()
|
||||
{
|
||||
std::string msg = "Signals Registered: ";
|
||||
|
||||
m_signalCurrentLatitude = m_dispatch.RegisterRxSignal(headlight::dsFCurrentLatitude);
|
||||
m_signalCurrentLongitude = m_dispatch.RegisterRxSignal(headlight::dsFCurrentLongitude);
|
||||
m_signalHeadlight = m_dispatch.RegisterTxSignal(headlight::dsBHeadLightLowBeam, false);
|
||||
|
||||
if (m_signalCurrentLatitude && m_signalCurrentLongitude && m_signalHeadlight)
|
||||
{
|
||||
std::cout << "Registration was successful\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "ATTENTION! Registration failed\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
auto allSignals = m_dispatch.GetRegisteredSignals();
|
||||
msg.append("(");
|
||||
msg.append(std::to_string(allSignals.size()));
|
||||
msg.append(")\n");
|
||||
std::cout << msg.c_str();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CAutoHeadlightAppSimulate::ResetSignalsSimDatalink()
|
||||
{
|
||||
if (m_signalCurrentLatitude)
|
||||
{
|
||||
m_signalCurrentLatitude.Reset();
|
||||
}
|
||||
if (m_signalCurrentLongitude)
|
||||
{
|
||||
m_signalCurrentLongitude.Reset();
|
||||
}
|
||||
if (m_signalHeadlight)
|
||||
{
|
||||
m_signalHeadlight.Reset();
|
||||
}
|
||||
|
||||
if(m_VisualCurrentLatitude)
|
||||
{
|
||||
m_VisualCurrentLatitude.Reset();
|
||||
}
|
||||
|
||||
if(m_VisualCurrentLongitude)
|
||||
{
|
||||
m_VisualCurrentLongitude.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
bool CAutoHeadlightAppSimulate::IsSDVFrameworkEnvironmentSet()
|
||||
{
|
||||
const char* envVariable = std::getenv("SDV_FRAMEWORK_RUNTIME");
|
||||
if (envVariable)
|
||||
{
|
||||
std::cout << "framework runtime directory already set\n";
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void CAutoHeadlightAppSimulate::SetCurrentLatitude(float value)
|
||||
{
|
||||
m_fBasicServiceCurrentLatitude = value;
|
||||
}
|
||||
|
||||
void CAutoHeadlightAppSimulate::SetCurrentLongitude(float value)
|
||||
{
|
||||
m_fBasicServiceCurrentLongitude = value;
|
||||
}
|
||||
|
||||
void CAutoHeadlightAppSimulate::CallbackToSetCurrentLatitude(sdv::any_t value)
|
||||
{
|
||||
m_fDataLinkCurrentLatitude = value.get<float>();
|
||||
}
|
||||
|
||||
void CAutoHeadlightAppSimulate::CallbackToSetCurrentLongitude(sdv::any_t value)
|
||||
{
|
||||
m_fDataLinkCurrentLongitude= value.get<float>();
|
||||
}
|
||||
|
||||
bool CAutoHeadlightAppSimulate::KeyHit()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return _kbhit();
|
||||
#elif __unix__
|
||||
int ch = getchar();
|
||||
if (ch != EOF) {
|
||||
ungetc(ch, stdin);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
char CAutoHeadlightAppSimulate::GetChar()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return static_cast<char>(_getch());
|
||||
#else
|
||||
return getchar();
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <support/signal_support.h>
|
||||
#include <support/app_control.h>
|
||||
#include <support/component_impl.h>
|
||||
#include <support/timer.h>
|
||||
#include "signal_names.h"
|
||||
|
||||
// VSS interfaces - located in ../generated/vss_files/include
|
||||
#include "vss_vehiclepositioncurrentlatitude_bs_rx.h"
|
||||
#include "vss_vehiclepositioncurrentlongitude_bs_rx.h"
|
||||
#include "vss_vehiclebodylightfrontlowbeam_bs_tx.h"
|
||||
|
||||
|
||||
// Complex service Headlight interface - located in ../generated/example_service
|
||||
#include "autoheadlight_cs_ifc.h"
|
||||
|
||||
/**
|
||||
* @brief Driveway Simulation utility
|
||||
*/
|
||||
class CAutoHeadlightAppSimulate :
|
||||
public vss::Vehicle::Position::CurrentLatitudeService::IVSS_SetCurrentLatitude_Event, // Basic service interface
|
||||
public vss::Vehicle::Position::CurrentLongitudeService::IVSS_SetCurrentLongitude_Event // Basic service interface
|
||||
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Destructor.
|
||||
*/
|
||||
~CAutoHeadlightAppSimulate();
|
||||
|
||||
/**
|
||||
* @brief Initialize the app.
|
||||
* @return Return true on success otherwise false
|
||||
*/
|
||||
bool Initialize();
|
||||
|
||||
/**
|
||||
* @brief Reset and Stop the app.
|
||||
*/
|
||||
void Shutdown();
|
||||
|
||||
/**
|
||||
* @brief Driveway data is provided to complex service and headlight is enabled based on the tunnel data
|
||||
*/
|
||||
void ExecuteTestRun();
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* @brief Key hit check. Windows uses the _kbhit function; POSIX emulates this.
|
||||
* @return Returns whether a key has been pressed.
|
||||
*/
|
||||
bool KeyHit();
|
||||
|
||||
/**
|
||||
* @brief Get the character from the keyboard buffer if pressed.
|
||||
* @return Returns the character from the keyboard buffer.
|
||||
*/
|
||||
char GetChar();
|
||||
|
||||
/**
|
||||
* @brief Access to required services to get information on desired signals
|
||||
* @return True if the access to all the services are success
|
||||
*/
|
||||
/**
|
||||
* @brief Access to required services to get information on desired signals
|
||||
* @return Return true if there was no issue with getting access to services otherwise return false
|
||||
*/
|
||||
bool GetAccessToServices();
|
||||
|
||||
/**
|
||||
* @brief Register Signals
|
||||
* @return Return true if there was no issue with registering signals otherwise return false
|
||||
*/
|
||||
bool RegisterSignalsSimDatalink();
|
||||
|
||||
/**
|
||||
* @brief Reset Signals
|
||||
*/
|
||||
void ResetSignalsSimDatalink();
|
||||
|
||||
/**
|
||||
* @brief Set the evnironment path to fetch framework binaries
|
||||
* @return Return true if there was no issue with setting framework path otherwise return false
|
||||
*/
|
||||
bool IsSDVFrameworkEnvironmentSet();
|
||||
|
||||
/**
|
||||
* @brief sets the current latitude.
|
||||
* @param[in] value current latitude value
|
||||
*/
|
||||
virtual void SetCurrentLatitude(float value) override;
|
||||
|
||||
/**
|
||||
* @brief sets the current longitude.
|
||||
* @param[in] value current longitude value
|
||||
*/
|
||||
virtual void SetCurrentLongitude(float value) override;
|
||||
|
||||
/**
|
||||
* @brief Callback function when new latitude value is available
|
||||
* @param[in] value The value of the latitude
|
||||
*/
|
||||
void CallbackToSetCurrentLatitude(sdv::any_t value);
|
||||
|
||||
/**
|
||||
* @brief Callback function when new longitude value is available
|
||||
* @param[in] value The value of the longitude
|
||||
*/
|
||||
void CallbackToSetCurrentLongitude(sdv::any_t value);
|
||||
|
||||
sdv::core::CDispatchService m_dispatch; ///< Dispatch service
|
||||
bool m_bInitialized = false; ///< Set when initialized.
|
||||
bool m_bRunning = false; ///< When set, the application is running.
|
||||
std::filesystem::path m_pathFramework; ///< Path to the SDV V-API framework.
|
||||
sdv::app::CAppControl m_appcontrol; ///< App-control of SDV V-API.
|
||||
|
||||
sdv::core::CSignal m_signalCurrentLatitude; ///< Signal Current latitude
|
||||
sdv::core::CSignal m_signalCurrentLongitude; ///< Signal Current longitude
|
||||
sdv::core::CSignal m_signalHeadlight; ///< Signal Headlight status
|
||||
|
||||
sdv::core::CSignal m_VisualCurrentLatitude; ///< Signal value visualization purpose : Current latitude subscription
|
||||
sdv::core::CSignal m_VisualCurrentLongitude; ///< Signal value visualization purpose : Current longitude subscription
|
||||
|
||||
float m_fDataLinkCurrentLatitude = 0.0f; ///< default value (input signal) - datalink monitoring
|
||||
float m_fDataLinkCurrentLongitude = 0.0f; ///< default value (input signal) - datalink monitoring
|
||||
bool m_bDataLinkHeadlightStatus = false; ///< default value (output signal) - datalink monitoring
|
||||
|
||||
float m_fBasicServiceCurrentLatitude = 0.0f; ///< Current Latitude - basic service event value
|
||||
float m_fBasicServiceCurrentLongitude = 0.0f; ///< Current Longitude - basic service event value
|
||||
bool m_bBasicServiceHeadlightStatus = false; ///< Headlight Status - basic service event value
|
||||
|
||||
IAutoheadlightService* m_pIAutoheadlightComplexService = nullptr; ///< Autoheadlight Service interface pointer.
|
||||
|
||||
/**
|
||||
* @brief GPS driveway struct for coordinates and text wrt tunnel info
|
||||
*/
|
||||
struct GPS {
|
||||
float latitude = 0.0f; ///< Latitude
|
||||
float longitude = 0.0f; ///< Longitude
|
||||
std::string location = "Before Tunnel"; ///< Text : "Before Tunnel", "Inside Tunnel", "After Tunnel"
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Driveway data including the tunnel information
|
||||
*/
|
||||
std::vector<GPS> m_DriveWayData = {
|
||||
{47.6495f, 9.4695f, "Before Tunnel"},
|
||||
{47.6496f, 9.4696f, "Before Tunnel"},
|
||||
{47.6497f, 9.4697f, "Before Tunnel"},
|
||||
{47.6498f, 9.4698f, "Before Tunnel"},
|
||||
{47.6499f, 9.4699f, "Before Tunnel"},
|
||||
{47.6500f, 9.4700f, "Inside Tunnel"},
|
||||
{47.6501f, 9.4701f, "Inside Tunnel"},
|
||||
{47.6502f, 9.4702f, "Inside Tunnel"},
|
||||
{47.6503f, 9.4703f, "Inside Tunnel"},
|
||||
{47.6504f, 9.4704f, "Inside Tunnel"},
|
||||
{47.6505f, 9.4705f, "Inside Tunnel"},
|
||||
{47.6506f, 9.4706f, "After Tunnel"},
|
||||
{47.6507f, 9.4707f, "After Tunnel"},
|
||||
{47.6508f, 9.4708f, "After Tunnel"},
|
||||
{47.6509f, 9.4709f, "After Tunnel"},
|
||||
{47.6510f, 9.4710f, "After Tunnel"}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* namespace for the signal names
|
||||
* in case /generated/vss_files/signal_identifier.h
|
||||
* exists, use the file, otherwise define the namespace
|
||||
*/
|
||||
|
||||
#ifndef SIGNAL_NAMES_H
|
||||
#define SIGNAL_NAMES_H
|
||||
|
||||
#ifdef __has_include
|
||||
#if __has_include("../generated/vss_files/signal_identifier.h")
|
||||
#include "../generated/vss_files/signal_identifier.h"
|
||||
#else
|
||||
namespace headlight
|
||||
{
|
||||
// Data Dispatch Service signal names to dbc variable names C-type RX/TX vss name space
|
||||
static std::string dsFCurrentLatitude = "CAN_Input.Current_Latitude" ; ///< float RX Vehicle.Position.CurrentLatitude
|
||||
static std::string dsFCurrentLongitude = "CAN_Input.Current_Longitude" ; ///< float RX Vehicle.Position.CurrentLongitude
|
||||
static std::string dsBHeadlightLowBeam = "CAN_Output.HeadLight_LowBeam"; ///< bool TX Vehicle.Body.Light.Front.Lowbeam
|
||||
} // headlight
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // ! defined SIGNAL_NAMES_H
|
||||
|
||||
@@ -0,0 +1,202 @@
|
||||
#include <iostream>
|
||||
#include "autoheadlight_cs.h"
|
||||
|
||||
|
||||
CAutoHeadlightService::CAutoHeadlightService()
|
||||
{
|
||||
}
|
||||
|
||||
CAutoHeadlightService::~CAutoHeadlightService()
|
||||
{
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
void CAutoHeadlightService::Initialize(const sdv::u8string& ssObjectConfig)
|
||||
{
|
||||
m_eStatus = sdv::EObjectStatus::initializing;
|
||||
|
||||
// Request the basic service for the headlight.
|
||||
m_pHeadlightSvc = sdv::core::GetObject("Vehicle.Body.Light.Front.LowBeam_Service").GetInterface<vss::Vehicle::Body::Light::Front::LowBeamService::IVSS_SetHeadLightLowBeam>();
|
||||
if (!m_pHeadlightSvc)
|
||||
{
|
||||
SDV_LOG_ERROR("Could not get interface 'IVSS_SetHeadlightLowBeam': [CAutoHeadlightService]");
|
||||
m_eStatus = sdv::EObjectStatus::initialization_failure;
|
||||
return;
|
||||
}
|
||||
|
||||
// Request the basic service for the steering wheel.
|
||||
auto pCurrentLatitudeSvc = sdv::core::GetObject("Vehicle.Position.CurrentLatitude_Service").GetInterface<vss::Vehicle::Position::CurrentLatitudeService::IVSS_GetCurrentLatitude>();
|
||||
if (!pCurrentLatitudeSvc)
|
||||
{
|
||||
SDV_LOG_ERROR("Could not get interface 'IVSS_GetCurrentLatitude': [CAutoHeadlightService]");
|
||||
m_eStatus = sdv::EObjectStatus::initialization_failure;
|
||||
return;
|
||||
}
|
||||
|
||||
// Request the basic service for the vehicle speed.
|
||||
auto pCurrentLongitudeSvc = sdv::core::GetObject("Vehicle.Position.CurrentLongitude_Service").GetInterface<vss::Vehicle::Position::CurrentLongitudeService::IVSS_GetCurrentLongitude>();
|
||||
if (!pCurrentLongitudeSvc)
|
||||
{
|
||||
SDV_LOG_ERROR("Could not get interface 'IVSS_GetCurrentLongitude': [CAutoHeadlightService]");
|
||||
m_eStatus = sdv::EObjectStatus::initialization_failure;
|
||||
return;
|
||||
}
|
||||
|
||||
// Register Current Latitude change event handler.
|
||||
pCurrentLatitudeSvc->RegisterOnSignalChangeOfFCurrentLatitude(static_cast<vss::Vehicle::Position::CurrentLatitudeService::IVSS_SetCurrentLatitude_Event*> (this));
|
||||
|
||||
// Register Current Longitude change event handler.
|
||||
pCurrentLongitudeSvc->RegisterOnSignalChangeOfFCurrentLongitude(static_cast<vss::Vehicle::Position::CurrentLongitudeService::IVSS_SetCurrentLongitude_Event*> (this));
|
||||
|
||||
|
||||
if(LoadGPSBounds(ssObjectConfig))
|
||||
{
|
||||
SDV_LOG_INFO("AutoHeadlightService: GPS bounds loaded Successfully");
|
||||
m_eStatus = sdv::EObjectStatus::initialized;
|
||||
}
|
||||
else
|
||||
{
|
||||
SDV_LOG_ERROR("AutoHeadlightService: GPS bounds could not be loaded");
|
||||
m_eStatus = sdv::EObjectStatus::initialization_failure;
|
||||
return;
|
||||
}
|
||||
|
||||
SDV_LOG_INFO("AutoHeadlightService: Initialized Successfully");
|
||||
}
|
||||
|
||||
sdv::EObjectStatus CAutoHeadlightService::GetStatus() const
|
||||
{
|
||||
return m_eStatus;
|
||||
}
|
||||
|
||||
void CAutoHeadlightService::SetOperationMode(sdv::EOperationMode /*eMode*/)
|
||||
{
|
||||
// Not applicable
|
||||
}
|
||||
|
||||
void CAutoHeadlightService::Shutdown()
|
||||
{
|
||||
// Unregister the Current latitude event handler.
|
||||
auto pCurrentLatitudeSvc = sdv::core::GetObject("Vehicle.Position.CurrentLatitude_Service").GetInterface<vss::Vehicle::Position::CurrentLatitudeService::IVSS_GetCurrentLatitude>();
|
||||
if (pCurrentLatitudeSvc)
|
||||
pCurrentLatitudeSvc->UnregisterOnSignalChangeOfFCurrentLatitude(static_cast<vss::Vehicle::Position::CurrentLatitudeService::IVSS_SetCurrentLatitude_Event*> (this));
|
||||
|
||||
// Unregister the vehicle speed event handler.
|
||||
auto pCurrentLongitudeSvc = sdv::core::GetObject("Vehicle.Position.CurrentLongitude_Service").GetInterface<vss::Vehicle::Position::CurrentLongitudeService::IVSS_GetCurrentLongitude>();
|
||||
if (pCurrentLongitudeSvc)
|
||||
pCurrentLongitudeSvc->UnregisterOnSignalChangeOfFCurrentLongitude(static_cast<vss::Vehicle::Position::CurrentLongitudeService::IVSS_SetCurrentLongitude_Event*> (this));
|
||||
}
|
||||
|
||||
void CAutoHeadlightService::SetCurrentLatitude(float value)
|
||||
{
|
||||
if (m_fCurrentLatitude == value)
|
||||
return;
|
||||
|
||||
m_fCurrentLatitude = value;
|
||||
ProcessHeadlightBasedOnEgoPosition();
|
||||
}
|
||||
|
||||
void CAutoHeadlightService::SetCurrentLongitude(float value)
|
||||
{
|
||||
if (m_fCurrentLongitude == value)
|
||||
return;
|
||||
|
||||
m_fCurrentLongitude = value;
|
||||
ProcessHeadlightBasedOnEgoPosition();
|
||||
}
|
||||
|
||||
bool CAutoHeadlightService::IsinTunnel() const
|
||||
{
|
||||
// Check if vehicle is within the tunnel bounds
|
||||
if (m_fCurrentLatitude >= m_SGPSBoundingBox.fTunnelMinLat && m_fCurrentLatitude <= m_SGPSBoundingBox.fTunnelMaxLat &&
|
||||
m_fCurrentLongitude >= m_SGPSBoundingBox.fTunnelMinLon && m_fCurrentLongitude <= m_SGPSBoundingBox.fTunnelMaxLon)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CAutoHeadlightService::GetHeadlightStatus() const
|
||||
{
|
||||
return m_bHeadlight;
|
||||
}
|
||||
|
||||
void CAutoHeadlightService::ProcessHeadlightBasedOnEgoPosition()
|
||||
{
|
||||
auto isInTunnel = IsinTunnel();
|
||||
if (isInTunnel && !m_bHeadlight)
|
||||
{
|
||||
// switch on headlight
|
||||
m_bHeadlight = true;
|
||||
m_pHeadlightSvc->SetHeadLightLowBeam(m_bHeadlight);
|
||||
}
|
||||
if (!IsinTunnel() && m_bHeadlight)
|
||||
{
|
||||
// switch off headlight
|
||||
m_bHeadlight = false;
|
||||
m_pHeadlightSvc->SetHeadLightLowBeam(m_bHeadlight);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool CAutoHeadlightService::LoadGPSBounds(const sdv::u8string& rssObjectConfig)
|
||||
{
|
||||
try
|
||||
{
|
||||
sdv::toml::CTOMLParser config(rssObjectConfig.c_str());
|
||||
|
||||
sdv::toml::CNode fStartLatNode = config.GetDirect("tunnel_start_lat");
|
||||
float fTunnelStartLat = 0.0; ///< Tunnel Start Latitude
|
||||
if (fStartLatNode.GetType() == sdv::toml::ENodeType::node_floating_point)
|
||||
{
|
||||
fTunnelStartLat = static_cast<float>(fStartLatNode.GetValue());
|
||||
}
|
||||
|
||||
sdv::toml::CNode fStartLonNode = config.GetDirect("tunnel_start_lon");
|
||||
float fTunnelStartLon = 0.0; ///< Tunnel Start Longitude
|
||||
if (fStartLonNode.GetType() == sdv::toml::ENodeType::node_floating_point)
|
||||
{
|
||||
fTunnelStartLon = static_cast<float>(fStartLonNode.GetValue());
|
||||
}
|
||||
|
||||
sdv::toml::CNode fEndLatNode = config.GetDirect("tunnel_end_lat");
|
||||
float fTunnelEndLat = 0.0; ///< Tunnel End Latitude
|
||||
if (fEndLatNode.GetType() == sdv::toml::ENodeType::node_floating_point)
|
||||
{
|
||||
fTunnelEndLat = static_cast<float>(fEndLatNode.GetValue());
|
||||
}
|
||||
|
||||
sdv::toml::CNode fEndLonNode = config.GetDirect("tunnel_end_lon");
|
||||
float fTunnelEndLon = 0.0; ///< Tunnel End Longitude
|
||||
if (fEndLonNode.GetType() == sdv::toml::ENodeType::node_floating_point)
|
||||
{
|
||||
fTunnelEndLon = static_cast<float>(fEndLonNode.GetValue());
|
||||
}
|
||||
|
||||
// Calculate bounding box
|
||||
m_SGPSBoundingBox.fTunnelMinLat = std::min(fTunnelStartLat, fTunnelEndLat);
|
||||
m_SGPSBoundingBox.fTunnelMaxLat = std::max(fTunnelStartLat, fTunnelEndLat);
|
||||
m_SGPSBoundingBox.fTunnelMinLon = std::min(fTunnelStartLon, fTunnelEndLon);
|
||||
m_SGPSBoundingBox.fTunnelMaxLon = std::max(fTunnelStartLon, fTunnelEndLon);
|
||||
}
|
||||
catch (const sdv::toml::XTOMLParseException& e)
|
||||
{
|
||||
SDV_LOG_ERROR("Parsing error: ", e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
IAutoheadlightService::SGPSBoundBox CAutoHeadlightService::GetGPSBoundBox() const
|
||||
{
|
||||
SGPSBoundBox tunnel;
|
||||
tunnel.fTunnelMinLat = m_SGPSBoundingBox.fTunnelMinLat;
|
||||
tunnel.fTunnelMaxLat = m_SGPSBoundingBox.fTunnelMaxLat;
|
||||
tunnel.fTunnelMinLon = m_SGPSBoundingBox.fTunnelMinLon;
|
||||
tunnel.fTunnelMaxLon = m_SGPSBoundingBox.fTunnelMaxLon;
|
||||
|
||||
return tunnel;
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
#ifndef COMPLEX_SERVICE_EXAMPLE_H
|
||||
#define COMPLEX_SERVICE_EXAMPLE_H
|
||||
|
||||
// C++ library
|
||||
#include <iostream>
|
||||
|
||||
|
||||
// SDV framework support
|
||||
#include <support/component_impl.h>
|
||||
#include <support/signal_support.h>
|
||||
#include <support/timer.h>
|
||||
#include <support/toml.h>
|
||||
|
||||
// VSS interfaces - located in ../generated/vss_files/include
|
||||
#include "vss_vehiclepositioncurrentlatitude_bs_rx.h"
|
||||
#include "vss_vehiclepositioncurrentlongitude_bs_rx.h"
|
||||
#include "vss_vehiclebodylightfrontlowbeam_bs_tx.h"
|
||||
|
||||
|
||||
// Complex service Headlight interface - located in ../generated/example_service
|
||||
#include "autoheadlight_cs_ifc.h"
|
||||
|
||||
/**
|
||||
* @brief Auto Headlight service
|
||||
* @details This complex service enables the headlight if the vehicle position is detected inside the tunnel and disables the headlight
|
||||
* if vehicle is detected outside the tunnel. This also checks if the time based on summer and winter season and enables it accordingly.(time aspect will be developed later)
|
||||
*
|
||||
* Input events from basic service: CurrentLatitude
|
||||
* CurrentLongitude
|
||||
* Output calls for basic service: headlight (true or false)
|
||||
*
|
||||
* Input calls for applications: autoheadlight enabled (true/false)
|
||||
* Output info for applications: headlight status (true/false)
|
||||
* Inside the tunnel (true/false)
|
||||
*/
|
||||
class CAutoHeadlightService :
|
||||
public sdv::CSdvObject,
|
||||
public sdv::IObjectControl,
|
||||
public IAutoheadlightService,
|
||||
public vss::Vehicle::Position::CurrentLatitudeService::IVSS_SetCurrentLatitude_Event,
|
||||
public vss::Vehicle::Position::CurrentLongitudeService::IVSS_SetCurrentLongitude_Event
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
CAutoHeadlightService();
|
||||
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
~CAutoHeadlightService();
|
||||
|
||||
// Interface map
|
||||
BEGIN_SDV_INTERFACE_MAP()
|
||||
SDV_INTERFACE_ENTRY(sdv::IObjectControl)
|
||||
SDV_INTERFACE_ENTRY(vss::Vehicle::Position::CurrentLatitudeService::IVSS_SetCurrentLatitude_Event)
|
||||
SDV_INTERFACE_ENTRY(vss::Vehicle::Position::CurrentLongitudeService::IVSS_SetCurrentLongitude_Event)
|
||||
SDV_INTERFACE_ENTRY(IAutoheadlightService)
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
// Object declarations
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::ComplexService)
|
||||
DECLARE_OBJECT_CLASS_NAME("Auto Headlight Service")
|
||||
DECLARE_OBJECT_SINGLETON()
|
||||
|
||||
/**
|
||||
* @brief Initialize the object. Overload of sdv::IObjectControl::Initialize.
|
||||
* @param[in] ssObjectConfig Optional configuration string.
|
||||
*/
|
||||
void Initialize(const sdv::u8string& ssObjectConfig) override;
|
||||
|
||||
/**
|
||||
* @brief Get the current status of the object. Overload of sdv::IObjectControl::GetStatus.
|
||||
* @return Return the current status of the object.
|
||||
*/
|
||||
sdv::EObjectStatus GetStatus() const override;
|
||||
|
||||
/**
|
||||
* @brief Set the component operation mode. Overload of sdv::IObjectControl::SetOperationMode.
|
||||
* @param[in] eMode The operation mode, the component should run in.
|
||||
*/
|
||||
void SetOperationMode(sdv::EOperationMode eMode) override;
|
||||
|
||||
/**
|
||||
* @brief Shutdown called before the object is destroyed. Overload of sdv::IObjectControl::Shutdown.
|
||||
*/
|
||||
void Shutdown() override;
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* @brief Set Current latitude event. Overload of vss::Vehicle::Position::CurrentLatitudeService::IVSS_SetBSCurrentLatitude_Event
|
||||
* @param[in] value Current latitude value in float
|
||||
*/
|
||||
void SetCurrentLatitude(float value) override;
|
||||
|
||||
/**
|
||||
* @brief Set Current Longitude event. Overload of vss::Vehicle::Position::CurrentLongitudeService::IVSS_SetBSCurrentLongitude_Event
|
||||
* @param[in] value Current latitude value in float
|
||||
*/
|
||||
void SetCurrentLongitude(float value) override;
|
||||
|
||||
/**
|
||||
* @brief Gets status of vehicle position if it is inside tunnel or not. Overload of IAutoheadlightService::IsinTunnel.
|
||||
* @return Returns true if position of vehicle is inside tunnel and false if outside.
|
||||
*/
|
||||
bool IsinTunnel() const override;
|
||||
|
||||
/**
|
||||
* @brief Get status of headlights. Overload of IAutoheadlightService::GetHeadlightStatus.
|
||||
* @return Returns the status of headlights (true if switched on , false if not switched on)
|
||||
*/
|
||||
bool GetHeadlightStatus() const override;
|
||||
|
||||
/**
|
||||
* @brief Get the GPS bounding box
|
||||
* @return Returns the bounding box structure
|
||||
*/
|
||||
SGPSBoundBox GetGPSBoundBox() const override;
|
||||
|
||||
/**
|
||||
* @brief Update the headlight status based on the vehicle position with respect to tunnel.
|
||||
*/
|
||||
void ProcessHeadlightBasedOnEgoPosition();
|
||||
|
||||
/**
|
||||
* @brief Load GPS bounding box from the configuration file
|
||||
*/
|
||||
bool LoadGPSBounds(const sdv::u8string& rssObjectConfig);
|
||||
|
||||
sdv::EObjectStatus m_eStatus = sdv::EObjectStatus::initialization_pending; ///< Current object status
|
||||
volatile float m_fCurrentLatitude = 0.0; ///< Current Latitude
|
||||
volatile float m_fCurrentLongitude = 0.0; ///< Current Longitude
|
||||
volatile bool m_bHeadlight = false; ///< Headlight status
|
||||
SGPSBoundBox m_SGPSBoundingBox; ///< Tunnel bounding box coordinates
|
||||
|
||||
|
||||
///< Headlight interface.
|
||||
vss::Vehicle::Body::Light::Front::LowBeamService::IVSS_SetHeadLightLowBeam* m_pHeadlightSvc = nullptr;
|
||||
};
|
||||
|
||||
DEFINE_SDV_OBJECT(CAutoHeadlightService)
|
||||
|
||||
#endif // !define COMPLEX_SERVICE_EXAMPLE_H
|
||||
@@ -0,0 +1,42 @@
|
||||
/*******************************************************************************
|
||||
* @file AutoHeadlight.idl
|
||||
* @details Auto Headlight example service interface definition.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief AutoHeadlight example service interface. The interface provides functions for the
|
||||
* Auto Headlight example complex service.
|
||||
*/
|
||||
interface IAutoheadlightService
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief Tunnel Bounding box Coordinates struct.
|
||||
*/
|
||||
struct SGPSBoundBox
|
||||
{
|
||||
float fTunnelMinLat = 0.0; ///< Minimum latitude value of bounding box
|
||||
float fTunnelMinLon = 0.0; ///< Minimum longitude value of bounding box
|
||||
float fTunnelMaxLat = 0.0; ///< Maximum latitude value of bounding box
|
||||
float fTunnelMaxLon = 0.0; ///< Maximum longitude value of bounding box
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Gets status of vehicle position if it is inside tunnel or not
|
||||
* @return Returns true if position of vehicle is inside tunnel and false if outside.
|
||||
*/
|
||||
boolean IsinTunnel() const;
|
||||
|
||||
/**
|
||||
* @brief Get status of headlights
|
||||
* @return Returns the status of headlights (true if switched on , false if not switched on)
|
||||
*/
|
||||
boolean GetHeadlightStatus() const;
|
||||
|
||||
/**
|
||||
* @brief Get the GPS bounding box
|
||||
* @return Returns the bounding box structure
|
||||
*/
|
||||
SGPSBoundBox GetGPSBoundBox() const;
|
||||
};
|
||||
10
examples/auto_headlamp_example/config/autoheadlight_cs.toml
Normal file
10
examples/auto_headlamp_example/config/autoheadlight_cs.toml
Normal file
@@ -0,0 +1,10 @@
|
||||
[Configuration]
|
||||
Version = 100
|
||||
|
||||
[[Component]]
|
||||
Path = "autoheadlight_service.sdv"
|
||||
Class = "Auto Headlight Service"
|
||||
tunnel_start_lat = 47.6500
|
||||
tunnel_start_lon = 9.4700
|
||||
tunnel_end_lat = 47.6506
|
||||
tunnel_end_lon = 9.4706
|
||||
@@ -0,0 +1,29 @@
|
||||
[Configuration]
|
||||
Version = 100
|
||||
|
||||
[[Component]]
|
||||
Path = "headlight_vd_currentlatitude_rx.sdv"
|
||||
Class = "Vehicle.Position.CurrentLatitude_Device"
|
||||
|
||||
[[Component]]
|
||||
Path = "headlight_vd_currentlongitude_rx.sdv"
|
||||
Class = "Vehicle.Position.CurrentLongitude_Device"
|
||||
|
||||
[[Component]]
|
||||
Path = "headlight_vd_headlightlowbeam_tx.sdv"
|
||||
Class = "Vehicle.Body.Light.Front.LowBeam_Device"
|
||||
|
||||
[[Component]]
|
||||
Path = "headlight_bs_currentlatitude_rx.sdv"
|
||||
Class = "Vehicle.Position.CurrentLatitude_Service"
|
||||
|
||||
[[Component]]
|
||||
Path = "headlight_bs_currentlongitude_rx.sdv"
|
||||
Class = "Vehicle.Position.CurrentLongitude_Service"
|
||||
|
||||
[[Component]]
|
||||
Path = "headlight_bs_headlightlowbeam_tx.sdv"
|
||||
Class = "Vehicle.Body.Light.Front.LowBeam_Service"
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
[Configuration]
|
||||
Version = 100
|
||||
|
||||
[[Component]]
|
||||
Path = "data_dispatch_service.sdv"
|
||||
Class = "DataDispatchService"
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
[Configuration]
|
||||
Version = 100
|
||||
|
||||
[[Component]]
|
||||
Path = "can_dl_example.sdv"
|
||||
Class = "CAN_data_link"
|
||||
@@ -0,0 +1,6 @@
|
||||
[Configuration]
|
||||
Version = 100
|
||||
|
||||
[[Component]]
|
||||
Path = "task_timer.sdv"
|
||||
Class = "TaskTimerService"
|
||||
@@ -0,0 +1,123 @@
|
||||
VERSION "PrivateCAN"
|
||||
|
||||
|
||||
NS_ :
|
||||
NS_DESC_
|
||||
CM_
|
||||
BA_DEF_
|
||||
BA_
|
||||
VAL_
|
||||
CAT_DEF_
|
||||
CAT_
|
||||
FILTER
|
||||
BA_DEF_DEF_
|
||||
EV_DATA_
|
||||
ENVVAR_DATA_
|
||||
SGTYPE_
|
||||
SGTYPE_VAL_
|
||||
BA_DEF_SGTYPE_
|
||||
BA_SGTYPE_
|
||||
SIG_TYPE_REF_
|
||||
VAL_TABLE_
|
||||
SIG_GROUP_
|
||||
SIG_VALTYPE_
|
||||
SIGTYPE_VALTYPE_
|
||||
BO_TX_BU_
|
||||
BA_DEF_REL_
|
||||
BA_REL_
|
||||
BA_DEF_DEF_REL_
|
||||
BU_SG_REL_
|
||||
BU_EV_REL_
|
||||
BU_BO_REL_
|
||||
SG_MUL_VAL_
|
||||
|
||||
BS_:
|
||||
|
||||
BU_: headlight
|
||||
VAL_TABLE_ Fault_Codes 27 "UKWN" 26 "VEHSPDMAX_EXDD" 25 "STS_ALIVE" 24 "STEER_NOT_E2E_MODE" 23 "OTA_SPD" 22 "OTA_TIMER_DOWNLOAD_FAILED" 21 "OTA_MAX_TIME" 20 "CUBIXAD_STEERSTREQ_NOTACTV" 19 "CUBIXAD_DRVSTREQ_NOTACTV" 18 "SFTYDRV_INTV" 17 "LSDC_ALIVE" 16 "CUBIXAD_ALIVE" 15 "IBC_MAB_NO_PRIO" 14 "IBC_NOT_RDY" 13 "IBC_ALIVE" 12 "LSDC_GEAR" 11 "LSDC_SPD" 10 "LSDC_ACCL" 9 "IBC_NOT_MAB_MOD" 8 "GOLDBOX_ALIVE" 7 "CUBIXAD_GEAR" 6 "CUBIXAD_SPD_TESTTRACK" 5 "DRVREQCHG" 4 "RDY_TIMER" 3 "SFTY_CDN_FAILED" 2 "ACTVNCHK_SPD" 1 "ACTVNCHK_TIMR" 0 "NONE" ;
|
||||
VAL_TABLE_ TestMapID 6 "E_TESTMAPID_UNDEFINED" 5 "E_TESTMAPID_TEST_DRIVE" 4 "E_TESTMAPID_AD_AREA" 3 "E_TESTMAPID_STUTT_ARENA" 2 "E_TESTMAPID_ZF_LASTMILE" 1 "E_TESTMAPID_ZF_TESTTRACK_2" 0 "E_TESTMAPID_NONE" ;
|
||||
VAL_TABLE_ CtrlReqStates 7 "CtrlSts3b_RESERVED_4" 6 "CtrlSts3b_RESERVED_3" 5 "CtrlSts3b_RESERVED_2" 4 "CtrlSts3b_RESERVED_1" 3 "CtrlSts3b_ERROR" 2 "CtrlSts3b_CONTROL_REQUESTED" 1 "CtrlSts3b_CONTROL_NOT_REQUESTED" 0 "CtrlSts3b_INIT" ;
|
||||
VAL_TABLE_ SteerActrReSts 7 "Diag" 6 "Inactive" 5 "Ramping" 4 "Yellow" 3 "Red" 2 "Normal" 1 "Pending" 0 "Initialisation" ;
|
||||
VAL_TABLE_ SwtPark1 1 "SwtParkActv" 0 "SwtParkNotActv" ;
|
||||
VAL_TABLE_ PE_State 2 "ERROR" 1 "INIT" 0 "NO_ERROR" ;
|
||||
VAL_TABLE_ SSM_Req 7 "HMS_TAKEOVER" 6 "RESERVED" 5 "RELESE_VIA_RAMP" 4 "DRIVEOFF" 3 "HOLD_STANDBY" 2 "PARK" 1 "HOLD" 0 "NO_REQUEST" ;
|
||||
VAL_TABLE_ IBC_StandStillMode 12 "SSM_ERROR" 11 "SSM_INIT" 10 "SSM_DRIVEOFF_STANDBY_ACTIVE" 9 "SSM_HOLD_STANDBY_ACTIVE" 8 "SSM_HILL_SLIPPOFF_DETECTED" 7 "SSM_RELEASE_REQ_FROM_DRIVER" 6 "SSM_RELEASE_REQ_ACTIVE" 5 "SSM_DRIVEOFF_ACTIVE" 4 "SSM_PARK_RETAINED_ACTIVE" 3 "SSM_PARK_ACTIVE" 2 "SSM_PARK_REQUESTED" 1 "SSM_HOLD_ACTIVE" 0 "SSM_NO_ACTIVE_FUNCTION" ;
|
||||
VAL_TABLE_ AppTgtStDrv 3 "ACTIVE" 2 "READY" 1 "RESERVED" 0 "NOT_ACTIVE" ;
|
||||
VAL_TABLE_ IBC_Status 4 "IBC_MAB_ERR_COMM" 3 "IBC_MAB_NO_PRIO" 2 "IBC_IN_MAB_MODE" 1 "IBC_READY" 0 "IBC_NOT_READY_FAILED" ;
|
||||
VAL_TABLE_ GearLvrIndcn 7 "GearLvrIndcn2_Undefd" 6 "GearLvrIndcn2_Resd2" 5 "GearLvrIndcn2_Resd1" 4 "GearLvrIndcn2_ManModeIndcn" 3 "GearLvrIndcn2_DrvIndcn" 2 "GearLvrIndcn2_NeutIndcn" 1 "GearLvrIndcn2_RvsIndcn" 0 "GearLvrIndcn2_ParkIndcn" ;
|
||||
VAL_TABLE_ LvlgAdjReq 7 "LvlgAdjReq_Resd2" 6 "LvlgAdjReq_Resd1" 5 "LvlgAdjReq_Ll2" 4 "LvlgAdjReq_Ll1" 3 "LvlgAdjReq_Nrh" 2 "LvlgAdjReq_Hl1" 1 "LvlgAdjReq_Hl2" 0 "LvlgAdjReq_Ukwn" ;
|
||||
VAL_TABLE_ DrvModReq 15 "Err" 14 "Rock" 13 "Mud" 12 "Sand" 11 "Snow" 10 "Power" 9 "Hybrid" 8 "Pure_EV" 7 "Race" 6 "Adaptive" 5 "Offroad_CrossTerrain" 4 "Individual" 3 "Dynamic_Sport" 2 "Comfort_Normal" 1 "ECO" 0 "Undefd" ;
|
||||
VAL_TABLE_ MAB_Info_Message 4 "DRV_GEARLVR_TO_P" 3 "DRV_P_TO_D" 2 "LSDC_DI_NOT_PSBL" 1 "LSDC_ENA_NOT_POSSIBLE" 0 "NONE" ;
|
||||
VAL_TABLE_ MAB_OvrdTool_Sts 11 "HACKATHON" 10 "OTA" 9 "INIT" 8 "FINSHD" 7 "FLT" 6 "CUBIX_AD" 5 "SAVE_THE_SPOILER" 4 "LSDC" 3 "RDY" 2 "ACTVN_CHK" 1 "NO_MANIPULATION" 0 "NONE" ;
|
||||
VAL_TABLE_ HMI_Drvr_Req 9 "FCT_DEACTVN_REQ" 8 "FCT_ACTVN_OTA_CFMD" 7 "FCT_ACTVN_OTA_REQ" 6 "FCT_ACTVN_SAVETHESPOILER_CFMD" 5 "FCT_ACTVN_SAVETHESPOILER_REQ" 4 "FCT_ACTVN_LSDC_CFMD" 3 "FCT_ACTVN_LSDC_REQ" 2 "FCT_ACTVN_CUBIXAD_CFMD" 1 "FCT_ACTVN_CUBIXAD_REQ" 0 "FCT_ACTVN_NONE" ;
|
||||
VAL_TABLE_ Info_Message 4 "DRV_GEARLVR_TO_P" 3 "DRV_P_TO_D" 2 "LSDC_DI_NOT_PSBL" 1 "LSDC_ENA_NOT_POSSIBLE" 0 "NONE" ;
|
||||
VAL_TABLE_ HMI_Fct_Req 8 "FCT_DEACTVN_REQ" 7 "FCT_ACTVN_OTA_REQ" 6 "FCT_ACTVN_SAVETHESPOILER_CFMD" 5 "FCT_ACTVN_SAVETHESPOILER_REQ" 4 "FCT_ACTVN_LSDC_CFMD" 3 "FCT_ACTVN_LSDC_REQ" 2 "FCT_ACTVN_AI4MTN_CFMD" 1 "FCT_ACTVN_AI4MTN_REQ" 0 "FCT_ACTVN_NONE" ;
|
||||
VAL_TABLE_ SOVD_states 2 "SOVD_SHOWCASE_ACTIVE" 1 "SOVD_SHOWCASE_DEACTIVE" 0 "SOVD_NONE" ;
|
||||
VAL_TABLE_ OTA_states 7 "OTA_DOWNLOAD_FAILED" 6 "OTA_INSTALL_FAILED" 5 "OTA_INSTALL_FINISHED" 4 "OTA_INSTALL_START" 3 "OTA_DOWNLOAD_START" 2 "OTA_SCHEDULED" 1 "OTA_STANDBY" 0 "OTA_NONE" ;
|
||||
|
||||
|
||||
BO_ 0 CAN_Input: 8 Vector__XXX
|
||||
SG_ Current_Longitude : 39|32@0- (1E-007,0) [-180|180] "deg" headlight
|
||||
SG_ Current_Latitude : 7|32@0- (1E-007,0) [-90|90] "deg" headlight
|
||||
|
||||
BO_ 3 CAN_Output: 1 headlight
|
||||
SG_ HeadLight_LowBeam : 7|8@0- (1,0) [0|1] "" Vector__XXX
|
||||
|
||||
|
||||
|
||||
BA_DEF_ "Baudrate" INT 1000 1000000;
|
||||
BA_DEF_ "BusType" STRING ;
|
||||
BA_DEF_ "DBName" STRING ;
|
||||
BA_DEF_ "ProtocolType" STRING ;
|
||||
BA_DEF_ BU_ "NmAsrNode" ENUM "No","Yes";
|
||||
BA_DEF_ BU_ "NmAsrNodeIdentifier" INT 0 255;
|
||||
BA_DEF_ BO_ "GenMsgCycleTime" INT 0 65536;
|
||||
BA_DEF_ BO_ "GenMsgCycleTimeFast" FLOAT 0 300000;
|
||||
BA_DEF_ BO_ "GenMsgDelayTime" INT 0 65536;
|
||||
BA_DEF_ BO_ "GenMsgNrOfRepetition" INT 0 100000;
|
||||
BA_DEF_ BO_ "GenMsgSendType" ENUM "cyclic","spontaneous","not-used","not-used","not-used","cyclicAndSpontaneous","not-used","cyclicIfActive","NoMsgSendType";
|
||||
BA_DEF_ BO_ "GenMsgStartDelayTime" INT 0 65536;
|
||||
BA_DEF_ SG_ "GenSigSendType" ENUM "Cyclic","OnWrite","OnWriteWithRepetition","OnChange","OnChangeWithRepetition","IfActive","IfActiveWithRepetition","NoSigSendType";
|
||||
BA_DEF_ SG_ "GenSigStartValue" HEX 0 80000000;
|
||||
BA_DEF_ BO_ "GenMsgILSupport" ENUM "No","Yes";
|
||||
BA_DEF_ BO_ "NmAsrMessage" ENUM "No","Yes";
|
||||
BA_DEF_ "NmAsrBaseAddress" HEX 0 536870911;
|
||||
BA_DEF_ "NmAsrMessageCount" INT 0 255;
|
||||
BA_DEF_ BU_ "NodeLayerModules" STRING ;
|
||||
BA_DEF_ BU_ "ILused" ENUM "No","Yes";
|
||||
BA_DEF_ SG_ "GenSigFuncType" ENUM "NoFunction","n/a","n/a","n/a","n/a","n/a","n/a","n/a","n/a","n/a","n/a","n/a","n/a","n/a","n/a","CHK","CNTR","n/a","n/a","n/a","CNTR_AR_01","CRC_AR_01_BOTH","CRC_AR_01_ALT","CRC_AR_01_LOW","CRC_AR_01_NIBBLE","CNTR_AR_04","CRC_AR_04A","CNTR_AR_05","CRC_AR_05";
|
||||
BA_DEF_ SG_ "GenSigDataID" STRING ;
|
||||
BA_DEF_ SG_ "SigGroup" STRING ;
|
||||
BA_DEF_DEF_ "Baudrate" 1000;
|
||||
BA_DEF_DEF_ "BusType" "";
|
||||
BA_DEF_DEF_ "DBName" "";
|
||||
BA_DEF_DEF_ "ProtocolType" "";
|
||||
BA_DEF_DEF_ "NmAsrNode" "No";
|
||||
BA_DEF_DEF_ "NmAsrNodeIdentifier" 0;
|
||||
BA_DEF_DEF_ "GenMsgCycleTime" 0;
|
||||
BA_DEF_DEF_ "GenMsgCycleTimeFast" 0;
|
||||
BA_DEF_DEF_ "GenMsgDelayTime" 0;
|
||||
BA_DEF_DEF_ "GenMsgNrOfRepetition" 0;
|
||||
BA_DEF_DEF_ "GenMsgSendType" "NoMsgSendType";
|
||||
BA_DEF_DEF_ "GenMsgStartDelayTime" 0;
|
||||
BA_DEF_DEF_ "GenSigSendType" "NoSigSendType";
|
||||
BA_DEF_DEF_ "GenSigStartValue" 0;
|
||||
BA_DEF_DEF_ "GenMsgILSupport" "Yes";
|
||||
BA_DEF_DEF_ "NmAsrMessage" "No";
|
||||
BA_DEF_DEF_ "NmAsrBaseAddress" 1280;
|
||||
BA_DEF_DEF_ "NmAsrMessageCount" 64;
|
||||
BA_DEF_DEF_ "NodeLayerModules" "CANoeILNLSPA.dll";
|
||||
BA_DEF_DEF_ "ILused" "Yes";
|
||||
BA_DEF_DEF_ "GenSigFuncType" "NoFunction";
|
||||
BA_DEF_DEF_ "GenSigDataID" "";
|
||||
BA_DEF_DEF_ "SigGroup" "";
|
||||
BA_ "ProtocolType" "CAN";
|
||||
BA_ "BusType" "CAN";
|
||||
BA_ "Baudrate" 500000;
|
||||
BA_ "DBName" "PrivateCAN";
|
||||
BA_ "GenMsgSendType" BO_ 0 0;
|
||||
BA_ "GenMsgCycleTime" BO_ 0 10;
|
||||
BA_ "GenMsgSendType" BO_ 3 0;
|
||||
BA_ "GenMsgCycleTime" BO_ 3 10;
|
||||
BA_ "GenSigStartValue" SG_ 0 Current_Latitude 0;
|
||||
|
||||
291
examples/auto_headlamp_example/fmu_files/model.cpp
Normal file
291
examples/auto_headlamp_example/fmu_files/model.cpp
Normal file
@@ -0,0 +1,291 @@
|
||||
/**
|
||||
* @file model.cpp
|
||||
* @date 2025-09-12 15:01:57
|
||||
* This file defines the data link object between CAN and the V-API devices.
|
||||
* This file was generated by the DBC utility from:
|
||||
* datalink_autoheadlight_example.dbc
|
||||
* DBC file version: 1.0.0.1
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <support/timer.h>
|
||||
#include "signal_identifier.h"
|
||||
#include <support/signal_support.h>
|
||||
#include <support/app_control.h>
|
||||
|
||||
sdv::core::CSignal g_signalCurrent_Longitude;
|
||||
sdv::core::CSignal g_signalCurrent_Latitude;
|
||||
sdv::core::CSignal g_signalHeadLight_LowBeam;
|
||||
|
||||
// in case the simulation timer should be used
|
||||
sdv::core::ITimerSimulationStep* g_pTimerSimulationStep;
|
||||
|
||||
std::unique_ptr<sdv::app::CAppControl> g_appcontrol;
|
||||
|
||||
bool InitializeAppControl(const std::string& resource, const std::string& configFileName)
|
||||
{
|
||||
auto bResult = g_appcontrol->AddModuleSearchDir( resource );
|
||||
bResult &= g_appcontrol->Startup("");
|
||||
g_appcontrol->SetConfigMode();
|
||||
bResult &= g_appcontrol->AddConfigSearchDir( resource );
|
||||
|
||||
if (!configFileName.empty())
|
||||
{
|
||||
bResult &= g_appcontrol->LoadConfig(configFileName.c_str()) == sdv::core::EConfigProcessResult::successful;
|
||||
}
|
||||
|
||||
return bResult;
|
||||
}
|
||||
|
||||
sdv::core::EConfigProcessResult RegisterAllSignals()
|
||||
{
|
||||
std::string msg = "register all signals: ";
|
||||
sdv::core::CDispatchService dispatch;
|
||||
|
||||
g_signalCurrent_Longitude = dispatch.RegisterRxSignal("CAN_Input.Current_Longitude");
|
||||
g_signalCurrent_Latitude = dispatch.RegisterRxSignal("CAN_Input.Current_Latitude");
|
||||
g_signalHeadLight_LowBeam = dispatch.RegisterTxSignal("CAN_Output.HeadLight_LowBeam",0);
|
||||
|
||||
if (g_signalCurrent_Longitude && g_signalCurrent_Latitude && g_signalHeadLight_LowBeam)
|
||||
{
|
||||
return sdv::core::EConfigProcessResult::successful;
|
||||
}
|
||||
|
||||
return sdv::core::EConfigProcessResult::failed;
|
||||
}
|
||||
|
||||
bool ResetAllSignals()
|
||||
{
|
||||
sdv::core::CDispatchService dispatch;
|
||||
|
||||
if (g_signalCurrent_Longitude)
|
||||
{
|
||||
g_signalCurrent_Longitude.Reset();
|
||||
}
|
||||
if (g_signalCurrent_Latitude)
|
||||
{
|
||||
g_signalCurrent_Latitude.Reset();
|
||||
}
|
||||
if (g_signalHeadLight_LowBeam)
|
||||
{
|
||||
g_signalHeadLight_LowBeam.Reset();
|
||||
}
|
||||
|
||||
SDV_LOG_INFO("Reset signals");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool CreateCoreServiceTomlFile(const std::string& resources)
|
||||
{
|
||||
std::ofstream tomlFile("sdv_core_reloc.toml");
|
||||
if (tomlFile.is_open())
|
||||
{
|
||||
tomlFile << "# Location of the SDV binaries and configuration files\ndirectory = \"";
|
||||
tomlFile << resources;
|
||||
tomlFile << "\"\n";
|
||||
tomlFile.close();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool OpenAPILoad(const std::string& resources)
|
||||
{
|
||||
bool success = CreateCoreServiceTomlFile(resources);
|
||||
g_appcontrol = std::make_unique<sdv::app::CAppControl> ();
|
||||
|
||||
//
|
||||
// TODO: Dispatch service must be loaded first, adjust the correct toml file
|
||||
//
|
||||
success &= InitializeAppControl(resources, "data_dispatch_config_file.toml");
|
||||
if (!success)
|
||||
{
|
||||
std::cout << "Error: InitializeAppControl() failed" << std::endl;
|
||||
SDV_LOG_ERROR("Failed InitializeAppControl");
|
||||
return false;
|
||||
}
|
||||
success &= RegisterAllSignals() == sdv::core::EConfigProcessResult::successful;
|
||||
if (!success)
|
||||
{
|
||||
SDV_LOG_ERROR("Signals could not be registered");
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// TODO: Load all configurations files
|
||||
//
|
||||
//
|
||||
// Get the simulation task timer service if the simulation timer should be used
|
||||
success &= g_appcontrol->LoadConfig("simulation_task_timer_config_file.toml") == sdv::core::EConfigProcessResult::successful;
|
||||
g_pTimerSimulationStep = sdv::core::GetObject<sdv::core::ITimerSimulationStep>("SimulationTaskTimerService");
|
||||
if (!g_pTimerSimulationStep)
|
||||
{
|
||||
SDV_LOG_WARNING("Simulation timer step not available, use normal task timer ");
|
||||
success &= g_appcontrol->LoadConfig("task_timer_config_file.toml") == sdv::core::EConfigProcessResult::successful;
|
||||
}
|
||||
|
||||
success &= g_appcontrol->LoadConfig("fmu_autoheadlight_vd_bs.toml") == sdv::core::EConfigProcessResult::successful;
|
||||
success &= g_appcontrol->LoadConfig("fmu_autoheadlight_cs.toml") == sdv::core::EConfigProcessResult::successful;
|
||||
|
||||
g_appcontrol->SetRunningMode();
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
void OpenAPIShutdown()
|
||||
{
|
||||
ResetAllSignals();
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <float.h> // for DBL_EPSILON
|
||||
#include <math.h> // for fabs()
|
||||
#include "config.h"
|
||||
#include "model.h"
|
||||
|
||||
Status cleanup(ModelInstance*)
|
||||
{
|
||||
SDV_LOG_INFO("Shutting down...");
|
||||
OpenAPIShutdown();
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
bool setStartValues(ModelInstance* comp)
|
||||
{
|
||||
std::string path(comp->resourceLocation);
|
||||
std::string resourcePath = path.substr(8);
|
||||
std::replace(resourcePath.begin(), resourcePath.end(), '\\', '/');
|
||||
if (!OpenAPILoad(resourcePath))
|
||||
{
|
||||
std::cout << "Error: OpenAPILoad() failed." << std::endl;
|
||||
comp->terminateSimulation = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: move this to initialize()?
|
||||
comp->nextEventTime = 0;
|
||||
comp->nextEventTimeDefined = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
Status calculateValues(ModelInstance* comp)
|
||||
{
|
||||
UNUSED(comp);
|
||||
// nothing to do
|
||||
return OK;
|
||||
}
|
||||
|
||||
Status getFloat64(ModelInstance* comp, [[maybe_unused]] ValueReference vr, [[maybe_unused]] double values[], [[maybe_unused]] size_t nValues, [[maybe_unused]] size_t* index)
|
||||
{
|
||||
ASSERT_NVALUES(1);
|
||||
|
||||
switch (vr)
|
||||
{
|
||||
case vr_Current_Longitude:
|
||||
values[(*index)++] = M(Current_Longitude);
|
||||
break;
|
||||
case vr_Current_Latitude:
|
||||
values[(*index)++] = M(Current_Latitude);
|
||||
break;
|
||||
|
||||
default:
|
||||
logError(comp, "Get Float64 is not allowed for value reference u.", vr);
|
||||
return Error;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
Status getInt32(ModelInstance* comp, [[maybe_unused]] ValueReference vr, [[maybe_unused]] int32_t values[], [[maybe_unused]] size_t nValues, [[maybe_unused]] size_t* index)
|
||||
{
|
||||
ASSERT_NVALUES(1);
|
||||
|
||||
switch (vr)
|
||||
{
|
||||
case vr_HeadLight_LowBeam:
|
||||
values[(*index)++] = M(HeadLight_LowBeam);
|
||||
break;
|
||||
|
||||
default:
|
||||
logError(comp, "Get Int32 is not allowed for value reference u.", vr);
|
||||
return Error;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
Status setFloat64(ModelInstance* comp, [[maybe_unused]] ValueReference vr, [[maybe_unused]] const double values[], [[maybe_unused]] size_t nValues, [[maybe_unused]] size_t* index)
|
||||
{
|
||||
ASSERT_NVALUES(1);
|
||||
|
||||
switch (vr)
|
||||
{
|
||||
case vr_Current_Longitude:
|
||||
M(Current_Longitude) = values[(*index)++];
|
||||
break;
|
||||
case vr_Current_Latitude:
|
||||
M(Current_Latitude) = values[(*index)++];
|
||||
break;
|
||||
|
||||
default:
|
||||
logError(comp, "Set Float64 is not allowed for value reference u.", vr);
|
||||
return Error;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
Status setInt32(ModelInstance* comp, [[maybe_unused]] ValueReference vr, [[maybe_unused]] const int32_t values[], [[maybe_unused]] size_t nValues, [[maybe_unused]] size_t* index)
|
||||
{
|
||||
ASSERT_NVALUES(1);
|
||||
|
||||
switch (vr)
|
||||
{
|
||||
case vr_HeadLight_LowBeam:
|
||||
M(HeadLight_LowBeam) = values[(*index)++];
|
||||
break;
|
||||
|
||||
default:
|
||||
logError(comp, "Set Int32 is not allowed for value reference u.", vr);
|
||||
return Error;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
void eventUpdate(ModelInstance* comp)
|
||||
{
|
||||
|
||||
if (g_pTimerSimulationStep) // in case the simulation timer was used, maybe the step size has to be adjusted
|
||||
{
|
||||
g_pTimerSimulationStep->SimulationStep(1000);
|
||||
}
|
||||
|
||||
g_signalCurrent_Longitude.Write( M(Current_Longitude));
|
||||
g_signalCurrent_Latitude.Write( M(Current_Latitude));
|
||||
M(HeadLight_LowBeam) = g_signalHeadLight_LowBeam.Read().get<uint32_t>();
|
||||
|
||||
double epsilon = (1.0 + fabs(comp->time)) * DBL_EPSILON;
|
||||
|
||||
if (comp->nextEventTimeDefined && comp->time + epsilon >= comp->nextEventTime) {
|
||||
comp->nextEventTime += FIXED_SOLVER_STEP;
|
||||
}
|
||||
|
||||
comp->valuesOfContinuousStatesChanged = false;
|
||||
comp->nominalsOfContinuousStatesChanged = false;
|
||||
comp->terminateSimulation = false;
|
||||
comp->nextEventTimeDefined = true;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // end of extern "C"
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
[Configuration]
|
||||
Version = 100
|
||||
|
||||
[[Component]]
|
||||
Path = "autoheadlight_service.sdv"
|
||||
Class = "Auto Headlight Service"
|
||||
tunnel_start_lat = 31.300
|
||||
tunnel_start_lon = 3.756
|
||||
tunnel_end_lat = 21.168
|
||||
tunnel_end_lon = 26.534
|
||||
@@ -0,0 +1,29 @@
|
||||
[Configuration]
|
||||
Version = 100
|
||||
|
||||
[[Component]]
|
||||
Path = "headlight_vd_currentlatitude_rx.sdv"
|
||||
Class = "Vehicle.Position.CurrentLatitude_Device"
|
||||
|
||||
[[Component]]
|
||||
Path = "headlight_vd_currentlongitude_rx.sdv"
|
||||
Class = "Vehicle.Position.CurrentLongitude_Device"
|
||||
|
||||
[[Component]]
|
||||
Path = "headlight_vd_headlightlowbeam_tx.sdv"
|
||||
Class = "Vehicle.Body.Light.Front.LowBeam_Device"
|
||||
|
||||
[[Component]]
|
||||
Path = "headlight_bs_currentlatitude_rx.sdv"
|
||||
Class = "Vehicle.Position.CurrentLatitude_Service"
|
||||
|
||||
[[Component]]
|
||||
Path = "headlight_bs_currentlongitude_rx.sdv"
|
||||
Class = "Vehicle.Position.CurrentLongitude_Service"
|
||||
|
||||
[[Component]]
|
||||
Path = "headlight_bs_headlightlowbeam_tx.sdv"
|
||||
Class = "Vehicle.Body.Light.Front.LowBeam_Service"
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,22 @@
|
||||
IF (get_process_state (..\CarlaBridge\carlabridge_coupecar.fmu) == 0)
|
||||
MESSAGE (Starting Carla Bridge fmu with 2 door scenario)
|
||||
START_PROCESS (..\CarlaBridge\carlabridge_coupecar.fmu)
|
||||
ENDIF
|
||||
|
||||
IF (get_process_state (carlabridge_coupecar.fmu) != 0)
|
||||
MESSAGE(2 door fmu started!)
|
||||
SET_BBVARI(CARLAin__toggle_view = 1)
|
||||
SET_BBVARI(CARLAin__operation_mode = 4)
|
||||
SET_BBVARI(CARLAin__toggle_display = 1)
|
||||
ENDIF
|
||||
|
||||
IF (get_process_state (..\vapifmus\Doors2ExampleFMU.fmu) == 0)
|
||||
MESSAGE (Starting VAPI 2 door Example fmu)
|
||||
START_PROCESS (..\vapifmus\Doors2ExampleFMU.fmu)
|
||||
ENDIF
|
||||
|
||||
START_EQUATION(1,vapiexamplestriggerfile.tri,Before,Doors2ExampleFMU.fmu)
|
||||
|
||||
IF (get_process_state (Doors2ExampleFMU.fmu) != 0)
|
||||
MESSAGE(2 door fmu started!)
|
||||
ENDIF
|
||||
@@ -0,0 +1,22 @@
|
||||
IF (get_process_state (..\CarlaBridge\carlabridge_patrolcar.fmu) == 0)
|
||||
MESSAGE (Starting Carla Bridge fmu with 4 door scenario)
|
||||
START_PROCESS (..\CarlaBridge\carlabridge_patrolcar.fmu)
|
||||
ENDIF
|
||||
|
||||
IF (get_process_state (carlabridge_patrolcar.fmu) != 0)
|
||||
MESSAGE(4 door fmu started!)
|
||||
SET_BBVARI(CARLAin__toggle_view = 1)
|
||||
SET_BBVARI(CARLAin__operation_mode = 4)
|
||||
SET_BBVARI(CARLAin__toggle_display = 1)
|
||||
ENDIF
|
||||
|
||||
IF (get_process_state (..\vapifmus\Doors4ExampleFMU.fmu) == 0)
|
||||
MESSAGE (Starting VAPI 4 door Example fmu)
|
||||
START_PROCESS (..\vapifmus\Doors4ExampleFMU.fmu)
|
||||
ENDIF
|
||||
|
||||
START_EQUATION(1,vapiexamplestriggerfile.tri,Before,Doors4ExampleFMU.fmu)
|
||||
|
||||
IF (get_process_state (Doors4ExampleFMU.fmu) != 0)
|
||||
MESSAGE(2 door fmu started!)
|
||||
ENDIF
|
||||
@@ -0,0 +1,7 @@
|
||||
Current_Latitude = CARLAout__act_pos_x;
|
||||
Current_Longitude = CARLAout__act_pos_y;
|
||||
CARLAin__Headlight_Lowbeam = HeadLight_LowBeam;
|
||||
CARLAin__DooropenStatus_FL = Door01LeftIsOpen;
|
||||
CARLAin__DooropenStatus_FR = Door01RightIsOpen;
|
||||
CARLAin__DooropenStatus_RL = Door02LeftIsOpen;
|
||||
CARLAin__DooropenStatus_RR = Door02RightIsOpen;
|
||||
@@ -0,0 +1,22 @@
|
||||
IF (get_process_state (..\CarlaBridge\carlabridge_coupecar.fmu) == 0)
|
||||
MESSAGE (Starting Carla Bridge fmu)
|
||||
START_PROCESS (..\CarlaBridge\carlabridge_coupecar.fmu)
|
||||
ENDIF
|
||||
|
||||
IF (get_process_state (carlabridge_coupecar.fmu) != 0)
|
||||
MESSAGE(Auto Headlight fmu started!)
|
||||
SET_BBVARI(CARLAin__toggle_view = 1)
|
||||
SET_BBVARI(CARLAin__operation_mode = 4)
|
||||
SET_BBVARI(CARLAin__toggle_display = 1)
|
||||
ENDIF
|
||||
|
||||
IF (get_process_state (..\vapifmus\AutoHeadlightFMU.fmu) == 0)
|
||||
MESSAGE (Starting VAPI Headlight Example fmu)
|
||||
START_PROCESS (..\vapifmus\AutoHeadlightFMU.fmu)
|
||||
ENDIF
|
||||
|
||||
START_EQUATION(1,vapiexamplestriggerfile.tri,Before,AutoHeadlightFMU.fmu)
|
||||
|
||||
IF (get_process_state (AutoHeadlightFMU.fmu) != 0)
|
||||
MESSAGE(Auto Headlight fmu started!)
|
||||
ENDIF
|
||||
@@ -0,0 +1,8 @@
|
||||
;Class name;Function name;Signal name;vss;Signal direction;type;DBC CAN name includes CAN message name
|
||||
;;;;;;;
|
||||
VD;CurrentLatitude;CurrentLatitude;fCurrentLatitude;Vehicle.Position.CurrentLatitude;RX;float;CAN_Input.Current_Latitude
|
||||
VD;CurrentLongitude;CurrentLongitude;fCurrentLongitude;Vehicle.Position.CurrentLongitude;RX;float;CAN_Input.Current_Longitude
|
||||
VD;HeadLightLowBeam;HeadLightLowBeam;bHeadLightLowBeam;Vehicle.Body.Light.Front.LowBeam;TX;boolean;CAN_Output.HeadLight_LowBeam
|
||||
BS;CurrentLatitude;CurrentLatitude;fCurrentLatitude;Vehicle.Position.CurrentLatitude;RX;float;Vehicle.Position.CurrentLatitude
|
||||
BS;CurrentLongitude;CurrentLongitude;fCurrentLongitude;Vehicle.Position.CurrentLongitude;RX;float;Vehicle.Position.CurrentLongitude
|
||||
BS;HeadLightLowBeam;HeadLightLowBeam;bHeadLightLowBeam;Vehicle.Body.Light.Front.LowBeam;TX;boolean;Vehicle.Body.Light.Front.LowBeam
|
||||
|
22
examples/configuration_component_example/CMakeLists.txt
Normal file
22
examples/configuration_component_example/CMakeLists.txt
Normal file
@@ -0,0 +1,22 @@
|
||||
# Use new policy for project version settings and default warning level
|
||||
cmake_policy(SET CMP0048 NEW) # requires CMake 3.14
|
||||
cmake_policy(SET CMP0092 NEW) # requires CMake 3.15
|
||||
|
||||
# Define project
|
||||
project(configuration_component_example VERSION 1.0 LANGUAGES CXX)
|
||||
|
||||
# Use C++17 support
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
# Libary symbols are hidden by default
|
||||
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
|
||||
|
||||
# Include link to export directory of SDV V-API development include files location
|
||||
include_directories(${SDV_FRAMEWORK_DEV_INCLUDE})
|
||||
|
||||
# Add the dynamic library
|
||||
add_library(configuration_component_example SHARED src/configuration_comp.cpp)
|
||||
|
||||
# Set extension to .sdv
|
||||
set_target_properties(configuration_component_example PROPERTIES PREFIX "")
|
||||
set_target_properties(configuration_component_example PROPERTIES SUFFIX ".sdv")
|
||||
@@ -0,0 +1,179 @@
|
||||
#include <iostream>
|
||||
#include <support/component_impl.h>
|
||||
#include <support/toml.h>
|
||||
|
||||
class DemoConfigurationComponent : public sdv::CSdvObject, public sdv::IObjectControl
|
||||
{
|
||||
public:
|
||||
BEGIN_SDV_INTERFACE_MAP()
|
||||
SDV_INTERFACE_ENTRY(sdv::IObjectControl)
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::Device)
|
||||
DECLARE_OBJECT_CLASS_NAME("Configuration_Example")
|
||||
|
||||
/**
|
||||
* @brief initialize function to register, access the task timer interface from platform abstraction.
|
||||
* After initialization 'CreateTimer' function is called to execute the task periodically.
|
||||
* @param[in] rssObjectConfig An object configuration is currently not used by this demo component.
|
||||
*/
|
||||
virtual void Initialize([[maybe_unused]] const sdv::u8string& rssObjectConfig) override
|
||||
{
|
||||
try
|
||||
{
|
||||
sdv::toml::CTOMLParser config(rssObjectConfig.c_str());
|
||||
|
||||
sdv::toml::CNode messageNode = config.GetDirect("Message");
|
||||
if (messageNode.GetType() == sdv::toml::ENodeType::node_string)
|
||||
{
|
||||
m_Message = static_cast<std::string>(messageNode.GetValue());
|
||||
}
|
||||
|
||||
sdv::toml::CNode jsonNode = config.GetDirect("JSONConfig");
|
||||
if (jsonNode.GetType() == sdv::toml::ENodeType::node_string)
|
||||
{
|
||||
m_JSONConfig = static_cast<std::string>(jsonNode.GetValue());
|
||||
}
|
||||
|
||||
sdv::toml::CNode idNode = config.GetDirect("Id");
|
||||
if (idNode.GetType() == sdv::toml::ENodeType::node_integer)
|
||||
{
|
||||
m_Id = static_cast<int32_t>(idNode.GetValue());
|
||||
}
|
||||
|
||||
sdv::toml::CNode floatNode = config.GetDirect("Pi");
|
||||
if (floatNode.GetType() == sdv::toml::ENodeType::node_floating_point)
|
||||
{
|
||||
m_Pi = static_cast<float>(floatNode.GetValue());
|
||||
}
|
||||
|
||||
sdv::toml::CNode boolNode = config.GetDirect("Boolean");
|
||||
if (boolNode.GetType() == sdv::toml::ENodeType::node_boolean)
|
||||
{
|
||||
m_IsValid = static_cast<bool>(boolNode.GetValue());
|
||||
}
|
||||
|
||||
sdv::toml::CNodeCollection arrayNodes = config.GetDirect("Array");
|
||||
if (arrayNodes.GetType() == sdv::toml::ENodeType::node_array)
|
||||
{
|
||||
for (size_t nIndex = 0; nIndex < arrayNodes.GetCount(); nIndex++)
|
||||
{
|
||||
sdv::toml::CNode node = arrayNodes[nIndex];
|
||||
if (node.GetType() == sdv::toml::ENodeType::node_integer)
|
||||
{
|
||||
m_Counters.push_back(static_cast<uint32_t>(node.GetValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sdv::toml::CNodeCollection tableNodes = config.GetDirect("Table");
|
||||
if (tableNodes.GetType() == sdv::toml::ENodeType::node_table)
|
||||
{
|
||||
if (tableNodes.GetCount() >= 3)
|
||||
{
|
||||
m_TableA = static_cast<uint32_t>(tableNodes[0].GetValue());
|
||||
m_TableB = static_cast<float>(tableNodes[1].GetValue());
|
||||
m_TableC = static_cast<std::string>(tableNodes[2].GetValue());
|
||||
}
|
||||
}
|
||||
|
||||
auto table_a = config.GetDirect("Table.a");
|
||||
auto table_b = config.GetDirect("Table.b");
|
||||
auto table_c = config.GetDirect("Table.c");
|
||||
m_DirectTableA = static_cast<uint32_t>(table_a.GetValue());
|
||||
m_DirectTableB = static_cast<float>(table_b.GetValue());
|
||||
m_DirectTableC = static_cast<std::string>(table_c.GetValue());
|
||||
|
||||
}
|
||||
catch (const sdv::toml::XTOMLParseException& e)
|
||||
{
|
||||
SDV_LOG_ERROR("Parsing error: ", e.what());
|
||||
|
||||
m_status = sdv::EObjectStatus::initialization_failure;
|
||||
return;
|
||||
}
|
||||
|
||||
PrintAllVariables();
|
||||
|
||||
m_status = sdv::EObjectStatus::initialized;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Gets the current status of the object
|
||||
* @return EObjectStatus The current status of the object
|
||||
*/
|
||||
virtual sdv::EObjectStatus GetStatus() const override
|
||||
{
|
||||
return m_status;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Set the component operation mode. Overload of sdv::IObjectControl::SetOperationMode.
|
||||
* @param[in] eMode The operation mode, the component should run in.
|
||||
*/
|
||||
void 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 periodic task.
|
||||
* Timer ID of the task is used to shutdown the specific task.
|
||||
*/
|
||||
virtual void Shutdown() override
|
||||
{
|
||||
m_status = sdv::EObjectStatus::destruction_pending;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Print all global variables to console
|
||||
*/
|
||||
void PrintAllVariables() const
|
||||
{
|
||||
std::cout << "\nValues parsed during initialization:" << std::endl;
|
||||
std::cout << "string: " << m_Message.c_str() << std::endl;
|
||||
std::cout << "multiline string: " << m_JSONConfig.c_str() << std::endl;
|
||||
std::cout << "integer: " << std::to_string(m_Id) << std::endl;
|
||||
std::cout << "float: " << std::to_string(m_Pi) << std::endl;
|
||||
std::cout << "bool: " << std::to_string(m_IsValid) << std::endl;
|
||||
std::cout << "table column a: " << std::to_string(m_TableA) << " " << std::to_string(m_DirectTableA) << std::endl;
|
||||
std::cout << "table column b: " << std::to_string(m_TableB) << " " << std::to_string(m_DirectTableB) << std::endl;
|
||||
std::cout << "table column c: " << m_TableC.c_str() << " " << m_DirectTableC.c_str() << std::endl;
|
||||
std::cout << "array: ";
|
||||
for (auto counter : m_Counters)
|
||||
{
|
||||
std::cout << std::to_string(counter) << ", ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
private:
|
||||
std::atomic<sdv::EObjectStatus> m_status = {sdv::EObjectStatus::initialization_pending}; //!< To update the object status when it changes.
|
||||
|
||||
std::string m_Message { "" };
|
||||
std::string m_JSONConfig { "" };
|
||||
int32_t m_Id { -1 };
|
||||
float m_Pi { 0.0 };
|
||||
bool m_IsValid { false };
|
||||
std::vector<uint32_t> m_Counters{};
|
||||
uint32_t m_TableA { 0 };
|
||||
float m_TableB { 0.0 };
|
||||
std::string m_TableC { "" };
|
||||
uint32_t m_DirectTableA { 0 };
|
||||
float m_DirectTableB { 0.0 };
|
||||
std::string m_DirectTableC { "" };
|
||||
};
|
||||
|
||||
DEFINE_SDV_OBJECT(DemoConfigurationComponent)
|
||||
36
examples/configuration_example/CMakeLists.txt
Normal file
36
examples/configuration_example/CMakeLists.txt
Normal file
@@ -0,0 +1,36 @@
|
||||
project(ConfigurationTestApp)
|
||||
|
||||
# Use new policy for project version settings and default warning level
|
||||
cmake_policy(SET CMP0048 NEW) # requires CMake 3.14
|
||||
cmake_policy(SET CMP0092 NEW) # requires CMake 3.15
|
||||
|
||||
# Use C++17 support
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
|
||||
add_executable(configuration_example src/configuration_example.cpp)
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
if (WIN32)
|
||||
target_link_libraries(configuration_example Ws2_32 Winmm Rpcrt4.lib)
|
||||
else()
|
||||
target_link_libraries(configuration_example ${CMAKE_DL_LIBS} rt ${CMAKE_THREAD_LIBS_INIT})
|
||||
endif()
|
||||
else()
|
||||
target_link_libraries(configuration_example Rpcrt4.lib)
|
||||
endif()
|
||||
|
||||
# Include link to export directory of SDV V-API development include files location
|
||||
include_directories(${SDV_FRAMEWORK_DEV_INCLUDE})
|
||||
|
||||
# Copy the config files
|
||||
file (COPY ${PROJECT_SOURCE_DIR}/config/test_configuration_example.toml DESTINATION ${CMAKE_BINARY_DIR}/bin/config)
|
||||
|
||||
target_link_libraries(configuration_example
|
||||
${CMAKE_DL_LIBS}
|
||||
)
|
||||
|
||||
add_test(NAME configuration_example COMMAND configuration_example )
|
||||
|
||||
# Build dependencies
|
||||
add_dependencies(configuration_example configuration_component_example)
|
||||
@@ -0,0 +1,19 @@
|
||||
[Configuration]
|
||||
Version = 100
|
||||
|
||||
[[Component]]
|
||||
Path = "configuration_component_example.sdv"
|
||||
Class = "Configuration_Example"
|
||||
Message = "It's me"
|
||||
### the following is a valid JSON structure in a muliline string
|
||||
JSONConfig = """{
|
||||
"Logging": {
|
||||
"Sinks": [ { "Type": "Stdout", "Level": "Info" } ]
|
||||
},
|
||||
}"""
|
||||
Id = 42
|
||||
Pi = 3.1415926
|
||||
Boolean = true
|
||||
Array = [ 1, 2, 3 , 5 , 7, 11, 13, 17 ]
|
||||
Table = { a = 77, b = 1.2, c = "this is a string" }
|
||||
|
||||
49
examples/configuration_example/src/configuration_example.cpp
Normal file
49
examples/configuration_example/src/configuration_example.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <support/app_control.h>
|
||||
#include <thread>
|
||||
|
||||
/**
|
||||
* @brief check if SDV_FRAMEWORK_RUNTIME environment variable exists
|
||||
* @return Return true if environment variable is found otherwise false
|
||||
*/
|
||||
bool IsSDVFrameworkEnvironmentSet()
|
||||
{
|
||||
const char* envVariable = std::getenv("SDV_FRAMEWORK_RUNTIME");
|
||||
if (envVariable)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#if defined(_WIN32) && defined(_UNICODE)
|
||||
extern "C" int wmain()
|
||||
#else
|
||||
extern "C" int main()
|
||||
#endif
|
||||
{
|
||||
sdv::app::CAppControl appcontrol;
|
||||
if (!IsSDVFrameworkEnvironmentSet())
|
||||
{
|
||||
// if SDV_FRAMEWORK_RUNTIME environment variable is not set we need to set the Framework Runtime directory
|
||||
appcontrol.SetFrameworkRuntimeDirectory("../../bin");
|
||||
}
|
||||
auto bResult = appcontrol.Startup("");
|
||||
appcontrol.SetConfigMode();
|
||||
|
||||
bResult &= appcontrol.AddConfigSearchDir("config");
|
||||
bResult &= appcontrol.LoadConfig("test_configuration_example.toml") == sdv::core::EConfigProcessResult::successful;
|
||||
|
||||
if (!bResult)
|
||||
{
|
||||
std::cout << "Exit, Could not load configuration component." << std::endl;
|
||||
appcontrol.Shutdown();
|
||||
}
|
||||
|
||||
appcontrol.SetRunningMode();
|
||||
|
||||
appcontrol.Shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
||||
215
examples/door_demo_example/CMakeLists.txt
Normal file
215
examples/door_demo_example/CMakeLists.txt
Normal file
@@ -0,0 +1,215 @@
|
||||
project(DoorDemoExample)
|
||||
|
||||
# Use new policy for project version settings and default warning level
|
||||
cmake_policy(SET CMP0048 NEW) # requires CMake 3.14
|
||||
cmake_policy(SET CMP0092 NEW) # requires CMake 3.15
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
# Libary symbols are hidden by default
|
||||
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
|
||||
|
||||
# Include directory to the core framework
|
||||
include_directories(${SDV_FRAMEWORK_DEV_INCLUDE})
|
||||
|
||||
# Copy the config files
|
||||
file (COPY ${PROJECT_SOURCE_DIR}/config/data_dispatch_example.toml DESTINATION ${CMAKE_BINARY_DIR}/bin/config)
|
||||
file (COPY ${PROJECT_SOURCE_DIR}/config/task_timer_example.toml DESTINATION ${CMAKE_BINARY_DIR}/bin/config)
|
||||
file (COPY ${PROJECT_SOURCE_DIR}/config/front_left_door_example.toml DESTINATION ${CMAKE_BINARY_DIR}/bin/config)
|
||||
file (COPY ${PROJECT_SOURCE_DIR}/config/front_right_door_example.toml DESTINATION ${CMAKE_BINARY_DIR}/bin/config)
|
||||
file (COPY ${PROJECT_SOURCE_DIR}/config/rear_left_door_example.toml DESTINATION ${CMAKE_BINARY_DIR}/bin/config)
|
||||
file (COPY ${PROJECT_SOURCE_DIR}/config/rear_right_door_example.toml DESTINATION ${CMAKE_BINARY_DIR}/bin/config)
|
||||
file (COPY ${PROJECT_SOURCE_DIR}/config/door_comple_service.toml DESTINATION ${CMAKE_BINARY_DIR}/bin/config)
|
||||
file (COPY ${PROJECT_SOURCE_DIR}/config/data_link_door.toml DESTINATION ${CMAKE_BINARY_DIR}/bin/config)
|
||||
|
||||
# Copy the ASC files used by can_com_sim.sdv which includes the CAN messages
|
||||
# Required in both locations when running standalone or as instance
|
||||
file (COPY ${PROJECT_SOURCE_DIR}/door_example_receiver.asc DESTINATION ${CMAKE_BINARY_DIR}/bin)
|
||||
file (COPY ${PROJECT_SOURCE_DIR}/door_example_receiver.asc DESTINATION ${CMAKE_BINARY_DIR}../../bin)
|
||||
|
||||
|
||||
######################################################################################################################################################################
|
||||
# preparation
|
||||
######################################################################################################################################################################
|
||||
|
||||
message("Compiling Interface Door01Left RX")
|
||||
execute_process(COMMAND "${SDV_IDL_COMPILER}" "${PROJECT_SOURCE_DIR}/interfaces/vss_vehiclechassisdooraxle01left_vd_rx.idl" "-O${PROJECT_SOURCE_DIR}/interfaces/" "-I${SDV_FRAMEWORK_DEV_INCLUDE}" -Igenerated/vss_files/ --no_ps)
|
||||
execute_process(COMMAND "${SDV_IDL_COMPILER}" "${PROJECT_SOURCE_DIR}/interfaces/vss_vehiclechassisdooraxle01left_bs_rx.idl" "-O${PROJECT_SOURCE_DIR}/interfaces/" "-I${SDV_FRAMEWORK_DEV_INCLUDE}" -Igenerated/vss_files/ --ps_lib_namedoors_proxystub)
|
||||
|
||||
message("Compiling Interface Door01Right RX")
|
||||
execute_process(COMMAND "${SDV_IDL_COMPILER}" "${PROJECT_SOURCE_DIR}/interfaces/vss_vehiclechassisdooraxle01right_vd_rx.idl" "-O${PROJECT_SOURCE_DIR}/interfaces/" "-I${SDV_FRAMEWORK_DEV_INCLUDE}" -Igenerated/vss_files/ --no_ps)
|
||||
execute_process(COMMAND "${SDV_IDL_COMPILER}" "${PROJECT_SOURCE_DIR}/interfaces/vss_vehiclechassisdooraxle01right_bs_rx.idl" "-O${PROJECT_SOURCE_DIR}/interfaces/" "-I${SDV_FRAMEWORK_DEV_INCLUDE}" -Igenerated/vss_files/ --ps_lib_namedoors_proxystub)
|
||||
|
||||
message("Compiling Interface Door02Left RX")
|
||||
execute_process(COMMAND "${SDV_IDL_COMPILER}" "${PROJECT_SOURCE_DIR}/interfaces/vss_vehiclechassisdooraxle02left_vd_rx.idl" "-O${PROJECT_SOURCE_DIR}/interfaces/" "-I${SDV_FRAMEWORK_DEV_INCLUDE}" -Igenerated/vss_files/ --no_ps)
|
||||
execute_process(COMMAND "${SDV_IDL_COMPILER}" "${PROJECT_SOURCE_DIR}/interfaces/vss_vehiclechassisdooraxle02left_bs_rx.idl" "-O${PROJECT_SOURCE_DIR}/interfaces/" "-I${SDV_FRAMEWORK_DEV_INCLUDE}" -Igenerated/vss_files/ --ps_lib_namedoors_proxystub)
|
||||
|
||||
message("Compiling Interface Door02Right RX")
|
||||
execute_process(COMMAND "${SDV_IDL_COMPILER}" "${PROJECT_SOURCE_DIR}/interfaces/vss_vehiclechassisdooraxle02right_vd_rx.idl" "-O${PROJECT_SOURCE_DIR}/interfaces/" "-I${SDV_FRAMEWORK_DEV_INCLUDE}" -Igenerated/vss_files/ --no_ps)
|
||||
execute_process(COMMAND "${SDV_IDL_COMPILER}" "${PROJECT_SOURCE_DIR}/interfaces/vss_vehiclechassisdooraxle02right_bs_rx.idl" "-O${PROJECT_SOURCE_DIR}/interfaces/" "-I${SDV_FRAMEWORK_DEV_INCLUDE}" -Igenerated/vss_files/ --ps_lib_namedoors_proxystub)
|
||||
|
||||
|
||||
message("Compiling Interface Door01Left TX")
|
||||
execute_process(COMMAND "${SDV_IDL_COMPILER}" "${PROJECT_SOURCE_DIR}/interfaces/vss_vehiclechassisdooraxle01left_vd_tx.idl" "-O${PROJECT_SOURCE_DIR}/interfaces/" "-I${SDV_FRAMEWORK_DEV_INCLUDE}" -Igenerated/vss_files/ --no_ps)
|
||||
execute_process(COMMAND "${SDV_IDL_COMPILER}" "${PROJECT_SOURCE_DIR}/interfaces/vss_vehiclechassisdooraxle01left_bs_tx.idl" "-O${PROJECT_SOURCE_DIR}/interfaces/" "-I${SDV_FRAMEWORK_DEV_INCLUDE}" -Igenerated/vss_files/ --ps_lib_namedoors_proxystub)
|
||||
|
||||
message("Compiling Interface Door01Right TX")
|
||||
execute_process(COMMAND "${SDV_IDL_COMPILER}" "${PROJECT_SOURCE_DIR}/interfaces/vss_vehiclechassisdooraxle01right_vd_tx.idl" "-O${PROJECT_SOURCE_DIR}/interfaces/" "-I${SDV_FRAMEWORK_DEV_INCLUDE}" -Igenerated/vss_files/ --no_ps)
|
||||
execute_process(COMMAND "${SDV_IDL_COMPILER}" "${PROJECT_SOURCE_DIR}/interfaces/vss_vehiclechassisdooraxle01right_bs_tx.idl" "-O${PROJECT_SOURCE_DIR}/interfaces/" "-I${SDV_FRAMEWORK_DEV_INCLUDE}" -Igenerated/vss_files/ --ps_lib_namedoors_proxystub)
|
||||
|
||||
message("Compiling Interface Door02Left TX")
|
||||
execute_process(COMMAND "${SDV_IDL_COMPILER}" "${PROJECT_SOURCE_DIR}/interfaces/vss_vehiclechassisdooraxle02left_vd_tx.idl" "-O${PROJECT_SOURCE_DIR}/interfaces/" "-I${SDV_FRAMEWORK_DEV_INCLUDE}" -Igenerated/vss_files/ --no_ps)
|
||||
execute_process(COMMAND "${SDV_IDL_COMPILER}" "${PROJECT_SOURCE_DIR}/interfaces/vss_vehiclechassisdooraxle02left_bs_tx.idl" "-O${PROJECT_SOURCE_DIR}/interfaces/" "-I${SDV_FRAMEWORK_DEV_INCLUDE}" -Igenerated/vss_files/ --ps_lib_namedoors_proxystub)
|
||||
|
||||
message("Compiling Interface Door02Right TX")
|
||||
execute_process(COMMAND "${SDV_IDL_COMPILER}" "${PROJECT_SOURCE_DIR}/interfaces/vss_vehiclechassisdooraxle02right_vd_tx.idl" "-O${PROJECT_SOURCE_DIR}/interfaces/" "-I${SDV_FRAMEWORK_DEV_INCLUDE}" -Igenerated/vss_files/ --no_ps)
|
||||
execute_process(COMMAND "${SDV_IDL_COMPILER}" "${PROJECT_SOURCE_DIR}/interfaces/vss_vehiclechassisdooraxle02right_bs_tx.idl" "-O${PROJECT_SOURCE_DIR}/interfaces/" "-I${SDV_FRAMEWORK_DEV_INCLUDE}" -Igenerated/vss_files/ --ps_lib_namedoors_proxystub)
|
||||
|
||||
# Execute the IDL compiler for the complex service to digest interface code.
|
||||
message("Compiling door_ifc.idl")
|
||||
execute_process(COMMAND "${SDV_IDL_COMPILER}" "${PROJECT_SOURCE_DIR}/door_service/door_ifc.idl" "-O${PROJECT_SOURCE_DIR}/generated/door_service/" "-I${SDV_FRAMEWORK_DEV_INCLUDE}" -Iexample_service/ --ps_lib_namedoors_service_proxystub)
|
||||
|
||||
add_subdirectory(interfaces/ps)
|
||||
|
||||
add_subdirectory(vd/vd_front_door_left)
|
||||
add_subdirectory(vd/vd_front_door_right)
|
||||
add_subdirectory(vd/vd_rear_door_left)
|
||||
add_subdirectory(vd/vd_rear_door_right)
|
||||
|
||||
add_subdirectory(bs/bs_front_door_left)
|
||||
add_subdirectory(bs/bs_front_door_right)
|
||||
add_subdirectory(bs/bs_rear_door_left)
|
||||
add_subdirectory(bs/bs_rear_door_right)
|
||||
|
||||
add_subdirectory(can_dl_door)
|
||||
|
||||
|
||||
######################################################################################################################################################################
|
||||
# complex service
|
||||
######################################################################################################################################################################
|
||||
|
||||
include_directories(interfaces)
|
||||
include_directories(${CMAKE_CURRENT_LIST_DIR}/door_app/include)
|
||||
|
||||
message("Include: proxy/stub for complex doors service")
|
||||
include_directories(${CMAKE_CURRENT_LIST_DIR}/generated/door_service)
|
||||
add_subdirectory(generated/door_service/ps)
|
||||
|
||||
add_library(door_complex_service SHARED
|
||||
door_service/complex_service.h
|
||||
door_service/complex_service.cpp
|
||||
door_service/lock_doors_thread.h)
|
||||
|
||||
set_target_properties(door_complex_service PROPERTIES OUTPUT_NAME "door_complex_service")
|
||||
set_target_properties(door_complex_service PROPERTIES PREFIX "")
|
||||
set_target_properties(door_complex_service PROPERTIES SUFFIX ".sdv")
|
||||
|
||||
######################################################################################################################################################################
|
||||
# executable
|
||||
######################################################################################################################################################################
|
||||
|
||||
add_executable(door_demo_example
|
||||
"door_app/door_demo_example.cpp"
|
||||
"door_app/include/door_application.h"
|
||||
"door_app/door_application.cpp"
|
||||
"door_app/include/console.h"
|
||||
"door_app/console.cpp"
|
||||
"door_app/include/signal_names.h"
|
||||
"door_service/lock_doors_thread.h")
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
if (WIN32)
|
||||
target_link_libraries(door_demo_example Ws2_32 Winmm Rpcrt4.lib)
|
||||
else()
|
||||
target_link_libraries(door_demo_example ${CMAKE_DL_LIBS} rt ${CMAKE_THREAD_LIBS_INIT})
|
||||
endif()
|
||||
else()
|
||||
target_link_libraries(door_demo_example Rpcrt4.lib)
|
||||
endif()
|
||||
|
||||
######################################################################################################################################################################
|
||||
# external application
|
||||
######################################################################################################################################################################
|
||||
|
||||
|
||||
add_executable(door_external_app
|
||||
"door_app/door_extern_example.cpp"
|
||||
"door_app/include/door_extern_application.h"
|
||||
"door_app/door_extern_application.cpp"
|
||||
"door_app/include/console.h"
|
||||
"door_app/console.cpp"
|
||||
"door_app/include/signal_names.h"
|
||||
"door_service/lock_doors_thread.h")
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
if (WIN32)
|
||||
target_link_libraries(door_external_app Ws2_32 Winmm Rpcrt4.lib)
|
||||
else()
|
||||
target_link_libraries(door_external_app ${CMAKE_DL_LIBS} rt ${CMAKE_THREAD_LIBS_INIT})
|
||||
endif()
|
||||
else()
|
||||
target_link_libraries(door_external_app Rpcrt4.lib)
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
######################################################################################################################################################################
|
||||
# create instance 3002 of door demo example
|
||||
######################################################################################################################################################################
|
||||
add_custom_target(vehicle_device_doors_config
|
||||
ALL
|
||||
DEPENDS
|
||||
can_dl_door
|
||||
doors_vd_frontdoorleft
|
||||
doors_vd_frontdoorright
|
||||
doors_vd_reardoorleft
|
||||
doors_vd_reardoorright
|
||||
COMMAND "${SDV_PACKAGER}" DIRECT_INSTALL VehicleDeviceDoors --instance3002 can_dl_door.sdv doors_vd_frontdoorleft.sdv doors_vd_frontdoorright.sdv doors_vd_reardoorleft.sdv doors_vd_reardoorright.sdv "-I${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" --interface_config --overwrite
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
add_custom_target(basic_service_doors_config
|
||||
ALL
|
||||
DEPENDS
|
||||
doors_proxystub
|
||||
doors_bs_frontdoorleft
|
||||
doors_bs_frontdoorright
|
||||
doors_bs_reardoorleft
|
||||
doors_bs_reardoorright
|
||||
COMMAND "${SDV_PACKAGER}" DIRECT_INSTALL BasicServiceDoors --instance3002 doors_proxystub.sdv doors_bs_frontdoorleft.sdv doors_bs_frontdoorright.sdv doors_bs_reardoorleft.sdv doors_bs_reardoorright.sdv "-I${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" --abstract_config --overwrite
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
add_custom_target(door_complex_service_config
|
||||
ALL
|
||||
DEPENDS
|
||||
door_complex_service
|
||||
doors_service_proxystub
|
||||
COMMAND "${SDV_PACKAGER}" DIRECT_INSTALL DoorComplexService --instance3002 door_complex_service.sdv doors_service_proxystub.sdv "-I${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" --user_config --overwrite
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
######################################################################################################################################################################
|
||||
# TODO: SDV_PACKAGER does not create the toml files, therefore we need to copy them
|
||||
######################################################################################################################################################################
|
||||
file (COPY ${PROJECT_SOURCE_DIR}/coreconfig/door_demo.toml DESTINATION ${SDV_FRAMEWORK_RUNTIME}/3002)
|
||||
file (COPY ${PROJECT_SOURCE_DIR}/coreconfig/platform.toml DESTINATION ${SDV_FRAMEWORK_RUNTIME}/3002)
|
||||
file (COPY ${PROJECT_SOURCE_DIR}/coreconfig/settings.toml DESTINATION ${SDV_FRAMEWORK_RUNTIME}/3002)
|
||||
file (COPY ${PROJECT_SOURCE_DIR}/coreconfig/vehicle_abstract.toml DESTINATION ${SDV_FRAMEWORK_RUNTIME}/3002)
|
||||
file (COPY ${PROJECT_SOURCE_DIR}/coreconfig/vehicle_ifc.toml DESTINATION ${SDV_FRAMEWORK_RUNTIME}/3002)
|
||||
|
||||
######################################################################################################################################################################
|
||||
# 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_4doors_example.dbc -Ogenerated\\ --nodesdoors --version1.0.0.1 --moduleDoors4ExampleFMU --dl_lib_namecan_dl_door
|
||||
#
|
||||
# following steps needs to be done:
|
||||
# required configuration files have to be put into the subfolder
|
||||
# ...\fmu_Doors2ExampleFMU\Doors2ExampleFMU\resources
|
||||
# ...\fmu_Doors2ExampleFMU\Doors4ExampleFMU\resources
|
||||
# function OpenAPILoad() needs to be updated in the model.cpp file
|
||||
# ...\fmu_Doors2ExampleFMU\Doors2ExampleFMU\model.cpp
|
||||
# ...\fmu_Doors2ExampleFMU\Doors4ExampleFMU\model.cpp
|
||||
######################################################################################################################################################################
|
||||
add_subdirectory(fmu_Doors2ExampleFMU)
|
||||
add_subdirectory(fmu_Doors4ExampleFMU)
|
||||
@@ -0,0 +1,49 @@
|
||||
# Enforce CMake version 3.20 or newer needed for path function
|
||||
cmake_minimum_required (VERSION 3.20)
|
||||
|
||||
# Use new policy for project version settings and default warning level
|
||||
cmake_policy(SET CMP0048 NEW) # requires CMake 3.14
|
||||
cmake_policy(SET CMP0092 NEW) # requires CMake 3.15
|
||||
|
||||
# Define project
|
||||
project(doors_bs_frontdoorleft VERSION 1.0 LANGUAGES CXX)
|
||||
|
||||
# Use C++17 support
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
# Libary symbols are hidden by default
|
||||
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
|
||||
|
||||
# Set target name.
|
||||
set(TARGET_NAME doors_bs_frontdoorleft)
|
||||
|
||||
# Set the SDV_FRAMEWORK_DEV_INCLUDE if not defined yet
|
||||
if (NOT DEFINED SDV_FRAMEWORK_DEV_INCLUDE)
|
||||
if (NOT DEFINED ENV{SDV_FRAMEWORK_DEV_INCLUDE})
|
||||
message( FATAL_ERROR "The environment variable SDV_FRAMEWORK_DEV_INCLUDE needs to be pointing to the SDV V-API development include files location!")
|
||||
endif()
|
||||
set (SDV_FRAMEWORK_DEV_INCLUDE "$ENV{SDV_FRAMEWORK_DEV_INCLUDE}")
|
||||
endif()
|
||||
|
||||
# Include link to export directory of SDV V-API development include files location
|
||||
include_directories(${SDV_FRAMEWORK_DEV_INCLUDE})
|
||||
include_directories(../../interfaces)
|
||||
|
||||
# Set platform specific compile flags
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||
add_compile_options(/W4 /WX /wd4996 /wd4100 /permissive- /Zc:rvalueCast)
|
||||
else()
|
||||
add_compile_options(-Werror -Wall -Wextra -Wshadow -Wpedantic -Wunreachable-code -fno-common)
|
||||
endif()
|
||||
|
||||
# Add the dynamic library
|
||||
add_library(${TARGET_NAME} SHARED
|
||||
bs_front_door_left.h
|
||||
bs_front_door_left.cpp)
|
||||
|
||||
# Set extension to .sdv
|
||||
set_target_properties(${TARGET_NAME} PROPERTIES PREFIX "")
|
||||
set_target_properties(${TARGET_NAME} PROPERTIES SUFFIX ".sdv")
|
||||
|
||||
# TODO: set target name.
|
||||
#add_dependencies(${TARGET_NAME} <add_cmake_target_this_depends_on>)
|
||||
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* @file bs_front_door_left.cpp
|
||||
* @date 2025-07-11 12:57:18
|
||||
* File is auto generated from VSS utility.
|
||||
* VSS Version:1.0.0.1
|
||||
*/
|
||||
#include <iostream>
|
||||
#include "bs_front_door_left.h"
|
||||
|
||||
/**
|
||||
* @brief ConstructorF
|
||||
*/
|
||||
CBasicServiceFrontDoorLeft::CBasicServiceFrontDoorLeft()
|
||||
{
|
||||
auto leftDoorIsOpen01Device = sdv::core::GetObject("Vehicle.Chassis.Door.Axle01.Left_Device").GetInterface<vss::Vehicle::Chassis::Door::Axle01::LeftDevice::IVSS_IsOpen>();
|
||||
if (!leftDoorIsOpen01Device)
|
||||
{
|
||||
SDV_LOG_ERROR("Could not get interface 'IVSS_IsOpen': [CBasicServiceFrontDoorLeft]");
|
||||
throw std::runtime_error("Vehicle.Chassis.Door.Axle01.Left mode device not found");
|
||||
}
|
||||
leftDoorIsOpen01Device->RegisterIsOpenEvent(dynamic_cast<vss::Vehicle::Chassis::Door::Axle01::LeftDevice::IVSS_WriteIsOpen_Event*> (this));
|
||||
|
||||
m_ptrLock = sdv::core::GetObject("Vehicle.Chassis.Door.Axle01.Left_Device").GetInterface<vss::Vehicle::Chassis::Door::Axle01::LeftDevice::IVSS_WriteLock>();
|
||||
if (!m_ptrLock)
|
||||
{
|
||||
SDV_LOG_ERROR("Could not get interface 'IVSS_WriteLock': [CBasicServiceFrontDoorLeft]");
|
||||
throw std::runtime_error("Lock device not found");
|
||||
}
|
||||
|
||||
SDV_LOG_TRACE("CBasicServiceFrontDoorLeft created: [Vehicle.Chassis.Door.Axle01.Left_Device]");
|
||||
m_leftDoorIsOpen01 = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief User-Defined Destructor
|
||||
*/
|
||||
CBasicServiceFrontDoorLeft::~CBasicServiceFrontDoorLeft()
|
||||
{
|
||||
auto leftDoorIsOpen01Device = sdv::core::GetObject("Vehicle.Chassis.Door.Axle01.Left_Device").GetInterface<vss::Vehicle::Chassis::Door::Axle01::LeftDevice::IVSS_IsOpen>();
|
||||
if (leftDoorIsOpen01Device)
|
||||
{
|
||||
leftDoorIsOpen01Device->UnregisterIsOpenEvent(dynamic_cast<vss::Vehicle::Chassis::Door::Axle01::LeftDevice::IVSS_WriteIsOpen_Event*> (this));
|
||||
}
|
||||
leftDoorIsOpen01Device = nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set leftDoorIsOpen
|
||||
* @param[in] value leftDoorIsOpen
|
||||
*/
|
||||
void CBasicServiceFrontDoorLeft::SetIsOpenL1(bool value)
|
||||
{
|
||||
m_leftDoorIsOpen01 = value;
|
||||
std::lock_guard<std::mutex> lock(m_leftDoorIsOpen01MutexCallbacks);
|
||||
for (auto callback : m_leftDoorIsOpen01Callbacks)
|
||||
{
|
||||
callback->SetIsOpenL1(value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write leftDoorIsOpen
|
||||
* @param[in] value leftDoorIsOpen
|
||||
*/
|
||||
void CBasicServiceFrontDoorLeft::WriteIsOpen(bool value)
|
||||
{
|
||||
SetIsOpenL1(value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get leftDoorIsOpen
|
||||
* @return Returns the leftDoorIsOpen
|
||||
*/
|
||||
bool CBasicServiceFrontDoorLeft::GetIsOpen() const
|
||||
{
|
||||
return m_leftDoorIsOpen01;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Register Callback on signal change
|
||||
* @param[in] callback function
|
||||
*/
|
||||
void CBasicServiceFrontDoorLeft::RegisterOnSignalChangeOfLeftDoorIsOpen01(vss::Vehicle::Chassis::Door::Axle01::LeftService::IVSS_SetIsOpen_Event* leftDoorIsOpen01Callback)
|
||||
{
|
||||
if ( leftDoorIsOpen01Callback)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_leftDoorIsOpen01MutexCallbacks);
|
||||
m_leftDoorIsOpen01Callbacks.insert(leftDoorIsOpen01Callback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Unregister Callback
|
||||
* @param[in] callback function
|
||||
*/
|
||||
void CBasicServiceFrontDoorLeft::UnregisterOnSignalChangeOfLeftDoorIsOpen01(vss::Vehicle::Chassis::Door::Axle01::LeftService::IVSS_SetIsOpen_Event* leftDoorIsOpen01Callback)
|
||||
{
|
||||
if (leftDoorIsOpen01Callback)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_leftDoorIsOpen01MutexCallbacks);
|
||||
m_leftDoorIsOpen01Callbacks.erase(leftDoorIsOpen01Callback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Lock
|
||||
* @param[in] value
|
||||
* @return true on success otherwise false
|
||||
*/
|
||||
bool CBasicServiceFrontDoorLeft::SetLock(bool value)
|
||||
{
|
||||
return m_ptrLock->WriteLock(value);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* @file bs_front_door_left.h
|
||||
* @date 2025-07-11 12:57:18
|
||||
* File is auto generated from VSS utility.
|
||||
* VSS Version:1.0.0.1
|
||||
*/
|
||||
#ifndef __VSS_GENERATED__BS_FRONTDOORLEFT_H_20250711_125718_601__
|
||||
#define __VSS_GENERATED__BS_FRONTDOORLEFT_H_20250711_125718_601__
|
||||
|
||||
#include <iostream>
|
||||
#include <set>
|
||||
#include <support/component_impl.h>
|
||||
#include <support/signal_support.h>
|
||||
#include "vss_vehiclechassisdooraxle01left_bs_rx.h"
|
||||
#include "vss_vehiclechassisdooraxle01left_vd_tx.h"
|
||||
#include "vss_vehiclechassisdooraxle01left_bs_tx.h"
|
||||
|
||||
/**
|
||||
* @brief Basic Service Vehicle.Chassis.Door.Axle01.Left
|
||||
*/
|
||||
class CBasicServiceFrontDoorLeft
|
||||
: public sdv::CSdvObject
|
||||
, public vss::Vehicle::Chassis::Door::Axle01::LeftService::IVSS_GetIsOpen
|
||||
, public vss::Vehicle::Chassis::Door::Axle01::LeftService::IVSS_SetIsOpen_Event
|
||||
, public vss::Vehicle::Chassis::Door::Axle01::LeftDevice::IVSS_WriteIsOpen_Event
|
||||
, public vss::Vehicle::Chassis::Door::Axle01::LeftService::IVSS_SetLock
|
||||
{
|
||||
public:
|
||||
|
||||
BEGIN_SDV_INTERFACE_MAP()
|
||||
SDV_INTERFACE_ENTRY(vss::Vehicle::Chassis::Door::Axle01::LeftService::IVSS_GetIsOpen)
|
||||
SDV_INTERFACE_ENTRY(vss::Vehicle::Chassis::Door::Axle01::LeftService::IVSS_SetLock)
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::BasicService)
|
||||
DECLARE_OBJECT_CLASS_NAME("Vehicle.Chassis.Door.Axle01.Left_Service")
|
||||
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
CBasicServiceFrontDoorLeft();
|
||||
|
||||
/**
|
||||
* @brief User-Defined Destructor
|
||||
*/
|
||||
~CBasicServiceFrontDoorLeft();
|
||||
|
||||
/**
|
||||
* @brief Set leftDoorIsOpen signal
|
||||
* @param[in] value leftDoorIsOpen
|
||||
*/
|
||||
void SetIsOpenL1(bool value) override;
|
||||
|
||||
/**
|
||||
* @brief Get leftDoorIsOpen
|
||||
* @return Returns the leftDoorIsOpen
|
||||
*/
|
||||
bool GetIsOpen() const override;
|
||||
|
||||
/**
|
||||
* @brief Write leftDoorIsOpen signal
|
||||
* @param[in] value leftDoorIsOpen
|
||||
*/
|
||||
void WriteIsOpen(bool value) override;
|
||||
|
||||
/**
|
||||
* @brief Set leftLatch signal
|
||||
* @param[in] value
|
||||
* @return true on success otherwise false
|
||||
*/
|
||||
bool SetLock(bool value) override;
|
||||
|
||||
/**
|
||||
* @brief Register CallBack function on signal change
|
||||
* @param[in] callback function
|
||||
*/
|
||||
void RegisterOnSignalChangeOfLeftDoorIsOpen01(vss::Vehicle::Chassis::Door::Axle01::LeftService::IVSS_SetIsOpen_Event* callback) override;
|
||||
|
||||
/**
|
||||
* @brief Unregister CallBack function on signal change
|
||||
* @param[in] callback function
|
||||
*/
|
||||
void UnregisterOnSignalChangeOfLeftDoorIsOpen01(vss::Vehicle::Chassis::Door::Axle01::LeftService::IVSS_SetIsOpen_Event* callback) override;
|
||||
|
||||
private:
|
||||
|
||||
bool m_leftDoorIsOpen01 { 0 };
|
||||
mutable std::mutex m_leftDoorIsOpen01MutexCallbacks; ///< Mutex protecting m_leftDoorIsOpen01Callbacks
|
||||
std::set<vss::Vehicle::Chassis::Door::Axle01::LeftService::IVSS_SetIsOpen_Event*> m_leftDoorIsOpen01Callbacks; ///< collection of events to be called
|
||||
vss::Vehicle::Chassis::Door::Axle01::LeftDevice::IVSS_WriteLock* m_ptrLock = nullptr;
|
||||
};
|
||||
|
||||
DEFINE_SDV_OBJECT(CBasicServiceFrontDoorLeft)
|
||||
|
||||
#endif // !define __VSS_GENERATED__BS_FRONTDOORLEFT_H_20250711_125718_601__
|
||||
@@ -0,0 +1,49 @@
|
||||
# Enforce CMake version 3.20 or newer needed for path function
|
||||
cmake_minimum_required (VERSION 3.20)
|
||||
|
||||
# Use new policy for project version settings and default warning level
|
||||
cmake_policy(SET CMP0048 NEW) # requires CMake 3.14
|
||||
cmake_policy(SET CMP0092 NEW) # requires CMake 3.15
|
||||
|
||||
# Define project
|
||||
project(doors_bs_frontdoorright VERSION 1.0 LANGUAGES CXX)
|
||||
|
||||
# Use C++17 support
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
# Libary symbols are hidden by default
|
||||
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
|
||||
|
||||
# Set target name.
|
||||
set(TARGET_NAME doors_bs_frontdoorright)
|
||||
|
||||
# Set the SDV_FRAMEWORK_DEV_INCLUDE if not defined yet
|
||||
if (NOT DEFINED SDV_FRAMEWORK_DEV_INCLUDE)
|
||||
if (NOT DEFINED ENV{SDV_FRAMEWORK_DEV_INCLUDE})
|
||||
message( FATAL_ERROR "The environment variable SDV_FRAMEWORK_DEV_INCLUDE needs to be pointing to the SDV V-API development include files location!")
|
||||
endif()
|
||||
set (SDV_FRAMEWORK_DEV_INCLUDE "$ENV{SDV_FRAMEWORK_DEV_INCLUDE}")
|
||||
endif()
|
||||
|
||||
# Include link to export directory of SDV V-API development include files location
|
||||
include_directories(${SDV_FRAMEWORK_DEV_INCLUDE})
|
||||
include_directories(../../interfaces)
|
||||
|
||||
# Set platform specific compile flags
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||
add_compile_options(/W4 /WX /wd4996 /wd4100 /permissive- /Zc:rvalueCast)
|
||||
else()
|
||||
add_compile_options(-Werror -Wall -Wextra -Wshadow -Wpedantic -Wunreachable-code -fno-common)
|
||||
endif()
|
||||
|
||||
# Add the dynamic library
|
||||
add_library(${TARGET_NAME} SHARED
|
||||
bs_front_door_right.h
|
||||
bs_front_door_right.cpp)
|
||||
|
||||
# Set extension to .sdv
|
||||
set_target_properties(${TARGET_NAME} PROPERTIES PREFIX "")
|
||||
set_target_properties(${TARGET_NAME} PROPERTIES SUFFIX ".sdv")
|
||||
|
||||
# TODO: set target name.
|
||||
#add_dependencies(${TARGET_NAME} <add_cmake_target_this_depends_on>)
|
||||
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* @file bs_front_door_right.cpp
|
||||
* @date 2025-07-11 12:57:18
|
||||
* File is auto generated from VSS utility.
|
||||
* VSS Version:1.0.0.1
|
||||
*/
|
||||
#include <iostream>
|
||||
#include "bs_front_door_right.h"
|
||||
|
||||
/**
|
||||
* @brief ConstructorF
|
||||
*/
|
||||
CBasicServiceFrontDoorRight::CBasicServiceFrontDoorRight()
|
||||
{
|
||||
auto rightDoorIsOpen01Device = sdv::core::GetObject("Vehicle.Chassis.Door.Axle01.Right_Device").GetInterface<vss::Vehicle::Chassis::Door::Axle01::RightDevice::IVSS_IsOpen>();
|
||||
if (!rightDoorIsOpen01Device)
|
||||
{
|
||||
SDV_LOG_ERROR("Could not get interface 'IVSS_IsOpen': [CBasicServiceFrontDoorRight]");
|
||||
throw std::runtime_error("Vehicle.Chassis.Door.Axle01.Right mode device not found");
|
||||
}
|
||||
rightDoorIsOpen01Device->RegisterIsOpenEvent(dynamic_cast<vss::Vehicle::Chassis::Door::Axle01::RightDevice::IVSS_WriteIsOpen_Event*> (this));
|
||||
|
||||
m_ptrLock = sdv::core::GetObject("Vehicle.Chassis.Door.Axle01.Right_Device").GetInterface<vss::Vehicle::Chassis::Door::Axle01::RightDevice::IVSS_WriteLock>();
|
||||
if (!m_ptrLock)
|
||||
{
|
||||
SDV_LOG_ERROR("Could not get interface 'IVSS_WriteLock': [CBasicServiceFrontDoorRight]");
|
||||
throw std::runtime_error("Lock device not found");
|
||||
}
|
||||
|
||||
SDV_LOG_TRACE("CBasicServiceFrontDoorRight created: [Vehicle.Chassis.Door.Axle01.Right_Device]");
|
||||
m_rightDoorIsOpen01 = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief User-Defined Destructor
|
||||
*/
|
||||
CBasicServiceFrontDoorRight::~CBasicServiceFrontDoorRight()
|
||||
{
|
||||
auto rightDoorIsOpen01Device = sdv::core::GetObject("Vehicle.Chassis.Door.Axle01.Right_Device").GetInterface<vss::Vehicle::Chassis::Door::Axle01::RightDevice::IVSS_IsOpen>();
|
||||
if (rightDoorIsOpen01Device)
|
||||
{
|
||||
rightDoorIsOpen01Device->UnregisterIsOpenEvent(dynamic_cast<vss::Vehicle::Chassis::Door::Axle01::RightDevice::IVSS_WriteIsOpen_Event*> (this));
|
||||
}
|
||||
rightDoorIsOpen01Device = nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set rightDoorIsOpen
|
||||
* @param[in] value rightDoorIsOpen
|
||||
*/
|
||||
void CBasicServiceFrontDoorRight::SetIsOpenR1(bool value)
|
||||
{
|
||||
m_rightDoorIsOpen01 = value;
|
||||
std::lock_guard<std::mutex> lock(m_rightDoorIsOpen01MutexCallbacks);
|
||||
for (auto callback : m_rightDoorIsOpen01Callbacks)
|
||||
{
|
||||
callback->SetIsOpenR1(value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write rightDoorIsOpen
|
||||
* @param[in] value rightDoorIsOpen
|
||||
*/
|
||||
void CBasicServiceFrontDoorRight::WriteIsOpen(bool value)
|
||||
{
|
||||
SetIsOpenR1(value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get rightDoorIsOpen
|
||||
* @return Returns the rightDoorIsOpen
|
||||
*/
|
||||
bool CBasicServiceFrontDoorRight::GetIsOpen() const
|
||||
{
|
||||
return m_rightDoorIsOpen01;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Register Callback on signal change
|
||||
* @param[in] callback function
|
||||
*/
|
||||
void CBasicServiceFrontDoorRight::RegisterOnSignalChangeOfRightDoorIsOpen01(vss::Vehicle::Chassis::Door::Axle01::RightService::IVSS_SetIsOpen_Event* rightDoorIsOpen01Callback)
|
||||
{
|
||||
if ( rightDoorIsOpen01Callback)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_rightDoorIsOpen01MutexCallbacks);
|
||||
m_rightDoorIsOpen01Callbacks.insert(rightDoorIsOpen01Callback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Unregister Callback
|
||||
* @param[in] callback function
|
||||
*/
|
||||
void CBasicServiceFrontDoorRight::UnregisterOnSignalChangeOfRightDoorIsOpen01(vss::Vehicle::Chassis::Door::Axle01::RightService::IVSS_SetIsOpen_Event* rightDoorIsOpen01Callback)
|
||||
{
|
||||
if (rightDoorIsOpen01Callback)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_rightDoorIsOpen01MutexCallbacks);
|
||||
m_rightDoorIsOpen01Callbacks.erase(rightDoorIsOpen01Callback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Lock
|
||||
* @param[in] value
|
||||
* @return true on success otherwise false
|
||||
*/
|
||||
bool CBasicServiceFrontDoorRight::SetLock(bool value)
|
||||
{
|
||||
return m_ptrLock->WriteLock(value);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* @file bs_front_door_right.h
|
||||
* @date 2025-07-11 12:57:18
|
||||
* File is auto generated from VSS utility.
|
||||
* VSS Version:1.0.0.1
|
||||
*/
|
||||
#ifndef __VSS_GENERATED__BS_FRONTDOORRIGHT_H_20250711_125718_606__
|
||||
#define __VSS_GENERATED__BS_FRONTDOORRIGHT_H_20250711_125718_606__
|
||||
|
||||
#include <iostream>
|
||||
#include <set>
|
||||
#include <support/component_impl.h>
|
||||
#include <support/signal_support.h>
|
||||
#include "vss_vehiclechassisdooraxle01right_bs_rx.h"
|
||||
#include "vss_vehiclechassisdooraxle01right_vd_tx.h"
|
||||
#include "vss_vehiclechassisdooraxle01right_bs_tx.h"
|
||||
|
||||
/**
|
||||
* @brief Basic Service Vehicle.Chassis.Door.Axle01.Right
|
||||
*/
|
||||
class CBasicServiceFrontDoorRight
|
||||
: public sdv::CSdvObject
|
||||
, public vss::Vehicle::Chassis::Door::Axle01::RightService::IVSS_GetIsOpen
|
||||
, public vss::Vehicle::Chassis::Door::Axle01::RightService::IVSS_SetIsOpen_Event
|
||||
, public vss::Vehicle::Chassis::Door::Axle01::RightDevice::IVSS_WriteIsOpen_Event
|
||||
, public vss::Vehicle::Chassis::Door::Axle01::RightService::IVSS_SetLock
|
||||
{
|
||||
public:
|
||||
|
||||
BEGIN_SDV_INTERFACE_MAP()
|
||||
SDV_INTERFACE_ENTRY(vss::Vehicle::Chassis::Door::Axle01::RightService::IVSS_GetIsOpen)
|
||||
SDV_INTERFACE_ENTRY(vss::Vehicle::Chassis::Door::Axle01::RightService::IVSS_SetLock)
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::BasicService)
|
||||
DECLARE_OBJECT_CLASS_NAME("Vehicle.Chassis.Door.Axle01.Right_Service")
|
||||
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
CBasicServiceFrontDoorRight();
|
||||
|
||||
/**
|
||||
* @brief User-Defined Destructor
|
||||
*/
|
||||
~CBasicServiceFrontDoorRight();
|
||||
|
||||
/**
|
||||
* @brief Set rightDoorIsOpen signal
|
||||
* @param[in] value rightDoorIsOpen
|
||||
*/
|
||||
void SetIsOpenR1(bool value) override;
|
||||
|
||||
/**
|
||||
* @brief Set signal
|
||||
* @param[in] value rightLatche
|
||||
* @return true on success otherwise false
|
||||
*/
|
||||
bool SetLock(bool value) override;
|
||||
|
||||
/**
|
||||
* @brief Get rightDoorIsOpen
|
||||
* @return Returns the rightDoorIsOpen
|
||||
*/
|
||||
bool GetIsOpen() const override;
|
||||
|
||||
/**
|
||||
* @brief Write rightDoorIsOpen signal
|
||||
* @param[in] value rightDoorIsOpen
|
||||
*/
|
||||
void WriteIsOpen(bool value) override;
|
||||
|
||||
/**
|
||||
* @brief Register CallBack function on signal change
|
||||
* @param[in] callback function
|
||||
*/
|
||||
void RegisterOnSignalChangeOfRightDoorIsOpen01(vss::Vehicle::Chassis::Door::Axle01::RightService::IVSS_SetIsOpen_Event* callback) override;
|
||||
|
||||
/**
|
||||
* @brief Unregister CallBack function on signal change
|
||||
* @param[in] callback function
|
||||
*/
|
||||
void UnregisterOnSignalChangeOfRightDoorIsOpen01(vss::Vehicle::Chassis::Door::Axle01::RightService::IVSS_SetIsOpen_Event* callback) override;
|
||||
|
||||
private:
|
||||
|
||||
bool m_rightDoorIsOpen01 { 0 };
|
||||
mutable std::mutex m_rightDoorIsOpen01MutexCallbacks; ///< Mutex protecting m_rightDoorIsOpen01Callbacks
|
||||
std::set<vss::Vehicle::Chassis::Door::Axle01::RightService::IVSS_SetIsOpen_Event*> m_rightDoorIsOpen01Callbacks; ///< collection of events to be called
|
||||
vss::Vehicle::Chassis::Door::Axle01::RightDevice::IVSS_WriteLock* m_ptrLock = nullptr;
|
||||
};
|
||||
|
||||
DEFINE_SDV_OBJECT(CBasicServiceFrontDoorRight)
|
||||
|
||||
#endif // !define __VSS_GENERATED__BS_FRONTDOORRIGHT_H_20250711_125718_606__
|
||||
@@ -0,0 +1,49 @@
|
||||
# Enforce CMake version 3.20 or newer needed for path function
|
||||
cmake_minimum_required (VERSION 3.20)
|
||||
|
||||
# Use new policy for project version settings and default warning level
|
||||
cmake_policy(SET CMP0048 NEW) # requires CMake 3.14
|
||||
cmake_policy(SET CMP0092 NEW) # requires CMake 3.15
|
||||
|
||||
# Define project
|
||||
project(doors_bs_reardoorleft VERSION 1.0 LANGUAGES CXX)
|
||||
|
||||
# Use C++17 support
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
# Libary symbols are hidden by default
|
||||
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
|
||||
|
||||
# Set target name.
|
||||
set(TARGET_NAME doors_bs_reardoorleft)
|
||||
|
||||
# Set the SDV_FRAMEWORK_DEV_INCLUDE if not defined yet
|
||||
if (NOT DEFINED SDV_FRAMEWORK_DEV_INCLUDE)
|
||||
if (NOT DEFINED ENV{SDV_FRAMEWORK_DEV_INCLUDE})
|
||||
message( FATAL_ERROR "The environment variable SDV_FRAMEWORK_DEV_INCLUDE needs to be pointing to the SDV V-API development include files location!")
|
||||
endif()
|
||||
set (SDV_FRAMEWORK_DEV_INCLUDE "$ENV{SDV_FRAMEWORK_DEV_INCLUDE}")
|
||||
endif()
|
||||
|
||||
# Include link to export directory of SDV V-API development include files location
|
||||
include_directories(${SDV_FRAMEWORK_DEV_INCLUDE})
|
||||
include_directories(../../interfaces)
|
||||
|
||||
# Set platform specific compile flags
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||
add_compile_options(/W4 /WX /wd4996 /wd4100 /permissive- /Zc:rvalueCast)
|
||||
else()
|
||||
add_compile_options(-Werror -Wall -Wextra -Wshadow -Wpedantic -Wunreachable-code -fno-common)
|
||||
endif()
|
||||
|
||||
# Add the dynamic library
|
||||
add_library(${TARGET_NAME} SHARED
|
||||
bs_rear_door_left.h
|
||||
bs_rear_door_left.cpp)
|
||||
|
||||
# Set extension to .sdv
|
||||
set_target_properties(${TARGET_NAME} PROPERTIES PREFIX "")
|
||||
set_target_properties(${TARGET_NAME} PROPERTIES SUFFIX ".sdv")
|
||||
|
||||
# TODO: set target name.
|
||||
#add_dependencies(${TARGET_NAME} <add_cmake_target_this_depends_on>)
|
||||
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* @file bs_rear_door_left.cpp
|
||||
* @date 2025-07-11 12:57:18
|
||||
* File is auto generated from VSS utility.
|
||||
* VSS Version:1.0.0.1
|
||||
*/
|
||||
#include <iostream>
|
||||
#include "bs_rear_door_left.h"
|
||||
|
||||
/**
|
||||
* @brief ConstructorF
|
||||
*/
|
||||
CBasicServiceRearDoorLeft::CBasicServiceRearDoorLeft()
|
||||
{
|
||||
auto leftDoorIsOpen02Device = sdv::core::GetObject("Vehicle.Chassis.Door.Axle02.Left_Device").GetInterface<vss::Vehicle::Chassis::Door::Axle02::LeftDevice::IVSS_IsOpen>();
|
||||
if (!leftDoorIsOpen02Device)
|
||||
{
|
||||
SDV_LOG_ERROR("Could not get interface 'IVSS_IsOpen': [CBasicServiceRearDoorLeft]");
|
||||
throw std::runtime_error("Vehicle.Chassis.Door.Axle02.Left mode device not found");
|
||||
}
|
||||
leftDoorIsOpen02Device->RegisterIsOpenEvent(dynamic_cast<vss::Vehicle::Chassis::Door::Axle02::LeftDevice::IVSS_WriteIsOpen_Event*> (this));
|
||||
|
||||
m_ptrLock = sdv::core::GetObject("Vehicle.Chassis.Door.Axle02.Left_Device").GetInterface<vss::Vehicle::Chassis::Door::Axle02::LeftDevice::IVSS_WriteLock>();
|
||||
if (!m_ptrLock)
|
||||
{
|
||||
SDV_LOG_ERROR("Could not get interface 'IVSS_WriteLock': [CBasicServiceRearDoorLeft]");
|
||||
throw std::runtime_error("Lock device not found");
|
||||
}
|
||||
|
||||
SDV_LOG_TRACE("CBasicServiceRearDoorLeft created: [Vehicle.Chassis.Door.Axle02.Left_Device]");
|
||||
m_leftDoorIsOpen02 = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief User-Defined Destructor
|
||||
*/
|
||||
CBasicServiceRearDoorLeft::~CBasicServiceRearDoorLeft()
|
||||
{
|
||||
auto leftDoorIsOpen02Device = sdv::core::GetObject("Vehicle.Chassis.Door.Axle02.Left_Device").GetInterface<vss::Vehicle::Chassis::Door::Axle02::LeftDevice::IVSS_IsOpen>();
|
||||
if (leftDoorIsOpen02Device)
|
||||
{
|
||||
leftDoorIsOpen02Device->UnregisterIsOpenEvent(dynamic_cast<vss::Vehicle::Chassis::Door::Axle02::LeftDevice::IVSS_WriteIsOpen_Event*> (this));
|
||||
}
|
||||
leftDoorIsOpen02Device = nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set rightDoorIsOpen
|
||||
* @param[in] value rightDoorIsOpen
|
||||
*/
|
||||
void CBasicServiceRearDoorLeft::SetIsOpenL2(bool value)
|
||||
{
|
||||
m_leftDoorIsOpen02 = value;
|
||||
std::lock_guard<std::mutex> lock(m_leftDoorIsOpen02MutexCallbacks);
|
||||
for (auto callback : m_leftDoorIsOpen02Callbacks)
|
||||
{
|
||||
callback->SetIsOpenL2(value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write rightDoorIsOpen
|
||||
* @param[in] value rightDoorIsOpen
|
||||
*/
|
||||
void CBasicServiceRearDoorLeft::WriteIsOpen(bool value)
|
||||
{
|
||||
SetIsOpenL2(value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get rightDoorIsOpen
|
||||
* @return Returns the rightDoorIsOpen
|
||||
*/
|
||||
bool CBasicServiceRearDoorLeft::GetIsOpen() const
|
||||
{
|
||||
return m_leftDoorIsOpen02;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Register Callback on signal change
|
||||
* @param[in] callback function
|
||||
*/
|
||||
void CBasicServiceRearDoorLeft::RegisterOnSignalChangeOfLeftDoorIsOpen02(vss::Vehicle::Chassis::Door::Axle02::LeftService::IVSS_SetIsOpen_Event* leftDoorIsOpen02Callback)
|
||||
{
|
||||
if ( leftDoorIsOpen02Callback)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_leftDoorIsOpen02MutexCallbacks);
|
||||
m_leftDoorIsOpen02Callbacks.insert(leftDoorIsOpen02Callback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Unregister Callback
|
||||
* @param[in] callback function
|
||||
*/
|
||||
void CBasicServiceRearDoorLeft::UnregisterOnSignalChangeOfLeftDoorIsOpen02(vss::Vehicle::Chassis::Door::Axle02::LeftService::IVSS_SetIsOpen_Event* leftDoorIsOpen02Callback)
|
||||
{
|
||||
if (leftDoorIsOpen02Callback)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_leftDoorIsOpen02MutexCallbacks);
|
||||
m_leftDoorIsOpen02Callbacks.erase(leftDoorIsOpen02Callback);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Lock
|
||||
* @param[in] value
|
||||
* @return true on success otherwise false
|
||||
*/
|
||||
bool CBasicServiceRearDoorLeft::SetLock(bool value)
|
||||
{
|
||||
return m_ptrLock->WriteLock(value);
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* @file bs_rear_door_left.h
|
||||
* @date 2025-07-11 12:57:18
|
||||
* File is auto generated from VSS utility.
|
||||
* VSS Version:1.0.0.1
|
||||
*/
|
||||
#ifndef __VSS_GENERATED__BS_REARDOORLEFT_H_20250711_125718_611__
|
||||
#define __VSS_GENERATED__BS_REARDOORLEFT_H_20250711_125718_611__
|
||||
|
||||
#include <iostream>
|
||||
#include <set>
|
||||
#include <support/component_impl.h>
|
||||
#include <support/signal_support.h>
|
||||
#include "vss_vehiclechassisdooraxle02left_bs_rx.h"
|
||||
#include "vss_vehiclechassisdooraxle02left_vd_tx.h"
|
||||
#include "vss_vehiclechassisdooraxle02left_bs_tx.h"
|
||||
|
||||
/**
|
||||
* @brief Basic Service Vehicle.Chassis.Door.Axle02.Left
|
||||
*/
|
||||
class CBasicServiceRearDoorLeft
|
||||
: public sdv::CSdvObject
|
||||
, public vss::Vehicle::Chassis::Door::Axle02::LeftService::IVSS_GetIsOpen
|
||||
, public vss::Vehicle::Chassis::Door::Axle02::LeftService::IVSS_SetIsOpen_Event
|
||||
, public vss::Vehicle::Chassis::Door::Axle02::LeftDevice::IVSS_WriteIsOpen_Event
|
||||
, public vss::Vehicle::Chassis::Door::Axle02::LeftService::IVSS_SetLock
|
||||
{
|
||||
public:
|
||||
|
||||
BEGIN_SDV_INTERFACE_MAP()
|
||||
SDV_INTERFACE_ENTRY(vss::Vehicle::Chassis::Door::Axle02::LeftService::IVSS_GetIsOpen)
|
||||
SDV_INTERFACE_ENTRY(vss::Vehicle::Chassis::Door::Axle02::LeftService::IVSS_SetLock)
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::BasicService)
|
||||
DECLARE_OBJECT_CLASS_NAME("Vehicle.Chassis.Door.Axle02.Left_Service")
|
||||
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
CBasicServiceRearDoorLeft();
|
||||
|
||||
/**
|
||||
* @brief User-Defined Destructor
|
||||
*/
|
||||
~CBasicServiceRearDoorLeft();
|
||||
|
||||
/**
|
||||
* @brief Set rightDoorIsOpen signal
|
||||
* @param[in] value rightDoorIsOpen
|
||||
*/
|
||||
void SetIsOpenL2(bool value) override;
|
||||
|
||||
/**
|
||||
* @brief Set leftLatch02 signal
|
||||
* @param[in] value
|
||||
* @return true on success otherwise false
|
||||
*/
|
||||
bool SetLock(bool value) override;
|
||||
|
||||
/**
|
||||
* @brief Get rightDoorIsOpen
|
||||
* @return Returns the rightDoorIsOpen
|
||||
*/
|
||||
bool GetIsOpen() const override;
|
||||
|
||||
/**
|
||||
* @brief Write rightDoorIsOpen signal
|
||||
* @param[in] value rightDoorIsOpen
|
||||
*/
|
||||
void WriteIsOpen(bool value) override;
|
||||
|
||||
/**
|
||||
* @brief Register CallBack function on signal change
|
||||
* @param[in] callback function
|
||||
*/
|
||||
void RegisterOnSignalChangeOfLeftDoorIsOpen02(vss::Vehicle::Chassis::Door::Axle02::LeftService::IVSS_SetIsOpen_Event* callback) override;
|
||||
|
||||
/**
|
||||
* @brief Unregister CallBack function on signal change
|
||||
* @param[in] callback function
|
||||
*/
|
||||
void UnregisterOnSignalChangeOfLeftDoorIsOpen02(vss::Vehicle::Chassis::Door::Axle02::LeftService::IVSS_SetIsOpen_Event* callback) override;
|
||||
|
||||
private:
|
||||
|
||||
bool m_leftDoorIsOpen02 { 0 };
|
||||
mutable std::mutex m_leftDoorIsOpen02MutexCallbacks; ///< Mutex protecting m_leftDoorIsOpen02Callbacks
|
||||
std::set<vss::Vehicle::Chassis::Door::Axle02::LeftService::IVSS_SetIsOpen_Event*> m_leftDoorIsOpen02Callbacks; ///< collection of events to be called
|
||||
vss::Vehicle::Chassis::Door::Axle02::LeftDevice::IVSS_WriteLock* m_ptrLock = nullptr;
|
||||
};
|
||||
|
||||
DEFINE_SDV_OBJECT(CBasicServiceRearDoorLeft)
|
||||
|
||||
#endif // !define __VSS_GENERATED__BS_REARDOORLEFT_H_20250711_125718_611__
|
||||
@@ -0,0 +1,49 @@
|
||||
# Enforce CMake version 3.20 or newer needed for path function
|
||||
cmake_minimum_required (VERSION 3.20)
|
||||
|
||||
# Use new policy for project version settings and default warning level
|
||||
cmake_policy(SET CMP0048 NEW) # requires CMake 3.14
|
||||
cmake_policy(SET CMP0092 NEW) # requires CMake 3.15
|
||||
|
||||
# Define project
|
||||
project(doors_bs_reardoorright VERSION 1.0 LANGUAGES CXX)
|
||||
|
||||
# Use C++17 support
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
# Libary symbols are hidden by default
|
||||
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
|
||||
|
||||
# Set target name.
|
||||
set(TARGET_NAME doors_bs_reardoorright)
|
||||
|
||||
# Set the SDV_FRAMEWORK_DEV_INCLUDE if not defined yet
|
||||
if (NOT DEFINED SDV_FRAMEWORK_DEV_INCLUDE)
|
||||
if (NOT DEFINED ENV{SDV_FRAMEWORK_DEV_INCLUDE})
|
||||
message( FATAL_ERROR "The environment variable SDV_FRAMEWORK_DEV_INCLUDE needs to be pointing to the SDV V-API development include files location!")
|
||||
endif()
|
||||
set (SDV_FRAMEWORK_DEV_INCLUDE "$ENV{SDV_FRAMEWORK_DEV_INCLUDE}")
|
||||
endif()
|
||||
|
||||
# Include link to export directory of SDV V-API development include files location
|
||||
include_directories(${SDV_FRAMEWORK_DEV_INCLUDE})
|
||||
include_directories(../../interfaces)
|
||||
|
||||
# Set platform specific compile flags
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||
add_compile_options(/W4 /WX /wd4996 /wd4100 /permissive- /Zc:rvalueCast)
|
||||
else()
|
||||
add_compile_options(-Werror -Wall -Wextra -Wshadow -Wpedantic -Wunreachable-code -fno-common)
|
||||
endif()
|
||||
|
||||
# Add the dynamic library
|
||||
add_library(${TARGET_NAME} SHARED
|
||||
bs_rear_door_right.h
|
||||
bs_rear_door_right.cpp)
|
||||
|
||||
# Set extension to .sdv
|
||||
set_target_properties(${TARGET_NAME} PROPERTIES PREFIX "")
|
||||
set_target_properties(${TARGET_NAME} PROPERTIES SUFFIX ".sdv")
|
||||
|
||||
# TODO: set target name.
|
||||
#add_dependencies(${TARGET_NAME} <add_cmake_target_this_depends_on>)
|
||||
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* @file bs_rear_door_right.cpp
|
||||
* @date 2025-07-11 12:57:18
|
||||
* File is auto generated from VSS utility.
|
||||
* VSS Version:1.0.0.1
|
||||
*/
|
||||
#include <iostream>
|
||||
#include "bs_rear_door_right.h"
|
||||
|
||||
/**
|
||||
* @brief ConstructorF
|
||||
*/
|
||||
CBasicServiceRearDoorRight::CBasicServiceRearDoorRight()
|
||||
{
|
||||
auto rightDoorIsOpen02Device = sdv::core::GetObject("Vehicle.Chassis.Door.Axle02.Right_Device").GetInterface<vss::Vehicle::Chassis::Door::Axle02::RightDevice::IVSS_IsOpen>();
|
||||
if (!rightDoorIsOpen02Device)
|
||||
{
|
||||
SDV_LOG_ERROR("Could not get interface 'IVSS_IsOpen': [CBasicServiceRearDoorRight]");
|
||||
throw std::runtime_error("Vehicle.Chassis.Door.Axle02.Right mode device not found");
|
||||
}
|
||||
rightDoorIsOpen02Device->RegisterIsOpenEvent(dynamic_cast<vss::Vehicle::Chassis::Door::Axle02::RightDevice::IVSS_WriteIsOpen_Event*> (this));
|
||||
|
||||
m_ptrLock = sdv::core::GetObject("Vehicle.Chassis.Door.Axle02.Right_Device").GetInterface<vss::Vehicle::Chassis::Door::Axle02::RightDevice::IVSS_WriteLock>();
|
||||
if (!m_ptrLock)
|
||||
{
|
||||
SDV_LOG_ERROR("Could not get interface 'IVSS_WriteLock': [CBasicServiceRearDoorRight]");
|
||||
throw std::runtime_error("Lock device not found");
|
||||
}
|
||||
|
||||
SDV_LOG_TRACE("CBasicServiceRearDoorRight created: [Vehicle.Chassis.Door.Axle02.Right_Device]");
|
||||
m_rightDoorIsOpen02 = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief User-Defined Destructor
|
||||
*/
|
||||
CBasicServiceRearDoorRight::~CBasicServiceRearDoorRight()
|
||||
{
|
||||
auto rightDoorIsOpen02Device = sdv::core::GetObject("Vehicle.Chassis.Door.Axle02.Right_Device").GetInterface<vss::Vehicle::Chassis::Door::Axle02::RightDevice::IVSS_IsOpen>();
|
||||
if (rightDoorIsOpen02Device)
|
||||
{
|
||||
rightDoorIsOpen02Device->UnregisterIsOpenEvent(dynamic_cast<vss::Vehicle::Chassis::Door::Axle02::RightDevice::IVSS_WriteIsOpen_Event*> (this));
|
||||
}
|
||||
rightDoorIsOpen02Device = nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set rightDoorIsOpen
|
||||
* @param[in] value rightDoorIsOpen
|
||||
*/
|
||||
void CBasicServiceRearDoorRight::SetIsOpenR2(bool value)
|
||||
{
|
||||
m_rightDoorIsOpen02 = value;
|
||||
std::lock_guard<std::mutex> lock(m_rightDoorIsOpen02MutexCallbacks);
|
||||
for (auto callback : m_rightDoorIsOpen02Callbacks)
|
||||
{
|
||||
callback->SetIsOpenR2(value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write rightDoorIsOpen
|
||||
* @param[in] value rightDoorIsOpen
|
||||
*/
|
||||
void CBasicServiceRearDoorRight::WriteIsOpen(bool value)
|
||||
{
|
||||
SetIsOpenR2(value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get rightDoorIsOpen
|
||||
* @return Returns the rightDoorIsOpen
|
||||
*/
|
||||
bool CBasicServiceRearDoorRight::GetIsOpen() const
|
||||
{
|
||||
return m_rightDoorIsOpen02;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Register Callback on signal change
|
||||
* @param[in] callback function
|
||||
*/
|
||||
void CBasicServiceRearDoorRight::RegisterOnSignalChangeOfRightDoorIsOpen02(vss::Vehicle::Chassis::Door::Axle02::RightService::IVSS_SetIsOpen_Event* rightDoorIsOpen02Callback)
|
||||
{
|
||||
if ( rightDoorIsOpen02Callback)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_rightDoorIsOpen02MutexCallbacks);
|
||||
m_rightDoorIsOpen02Callbacks.insert(rightDoorIsOpen02Callback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Unregister Callback
|
||||
* @param[in] callback function
|
||||
*/
|
||||
void CBasicServiceRearDoorRight::UnregisterOnSignalChangeOfRightDoorIsOpen02(vss::Vehicle::Chassis::Door::Axle02::RightService::IVSS_SetIsOpen_Event* rightDoorIsOpen02Callback)
|
||||
{
|
||||
if (rightDoorIsOpen02Callback)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_rightDoorIsOpen02MutexCallbacks);
|
||||
m_rightDoorIsOpen02Callbacks.erase(rightDoorIsOpen02Callback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Lock
|
||||
* @param[in] value
|
||||
* @return true on success otherwise false
|
||||
*/
|
||||
bool CBasicServiceRearDoorRight::SetLock(bool value)
|
||||
{
|
||||
return m_ptrLock->WriteLock(value);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* @file bs_rear_door_right.h
|
||||
* @date 2025-07-11 12:57:18
|
||||
* File is auto generated from VSS utility.
|
||||
* VSS Version:1.0.0.1
|
||||
*/
|
||||
#ifndef __VSS_GENERATED__BS_REARDOORRIGHT_H_20250711_125718_616__
|
||||
#define __VSS_GENERATED__BS_REARDOORRIGHT_H_20250711_125718_616__
|
||||
|
||||
#include <iostream>
|
||||
#include <set>
|
||||
#include <support/component_impl.h>
|
||||
#include <support/signal_support.h>
|
||||
#include "vss_vehiclechassisdooraxle02right_bs_rx.h"
|
||||
#include "vss_vehiclechassisdooraxle02right_vd_tx.h"
|
||||
#include "vss_vehiclechassisdooraxle02right_bs_tx.h"
|
||||
|
||||
/**
|
||||
* @brief Basic Service Vehicle.Chassis.Door.Axle02.Right
|
||||
*/
|
||||
class CBasicServiceRearDoorRight
|
||||
: public sdv::CSdvObject
|
||||
, public vss::Vehicle::Chassis::Door::Axle02::RightService::IVSS_GetIsOpen
|
||||
, public vss::Vehicle::Chassis::Door::Axle02::RightService::IVSS_SetIsOpen_Event
|
||||
, public vss::Vehicle::Chassis::Door::Axle02::RightDevice::IVSS_WriteIsOpen_Event
|
||||
, public vss::Vehicle::Chassis::Door::Axle02::RightService::IVSS_SetLock
|
||||
{
|
||||
public:
|
||||
|
||||
BEGIN_SDV_INTERFACE_MAP()
|
||||
SDV_INTERFACE_ENTRY(vss::Vehicle::Chassis::Door::Axle02::RightService::IVSS_GetIsOpen)
|
||||
SDV_INTERFACE_ENTRY(vss::Vehicle::Chassis::Door::Axle02::RightService::IVSS_SetLock)
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::BasicService)
|
||||
DECLARE_OBJECT_CLASS_NAME("Vehicle.Chassis.Door.Axle02.Right_Service")
|
||||
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
CBasicServiceRearDoorRight();
|
||||
|
||||
/**
|
||||
* @brief User-Defined Destructor
|
||||
*/
|
||||
~CBasicServiceRearDoorRight();
|
||||
|
||||
/**
|
||||
* @brief Set rightDoorIsOpen signal
|
||||
* @param[in] value rightDoorIsOpen
|
||||
*/
|
||||
void SetIsOpenR2(bool value) override;
|
||||
|
||||
/**
|
||||
* @brief Set rightLatch02 signal
|
||||
* @param[in] value
|
||||
* @return true on success otherwise false
|
||||
*/
|
||||
bool SetLock(bool value) override;
|
||||
|
||||
/**
|
||||
* @brief Get rightDoorIsOpen
|
||||
* @return Returns the rightDoorIsOpen
|
||||
*/
|
||||
bool GetIsOpen() const override;
|
||||
|
||||
/**
|
||||
* @brief Write rightDoorIsOpen signal
|
||||
* @param[in] value rightDoorIsOpen
|
||||
*/
|
||||
void WriteIsOpen(bool value) override;
|
||||
|
||||
/**
|
||||
* @brief Register CallBack function on signal change
|
||||
* @param[in] callback function
|
||||
*/
|
||||
void RegisterOnSignalChangeOfRightDoorIsOpen02(vss::Vehicle::Chassis::Door::Axle02::RightService::IVSS_SetIsOpen_Event* callback) override;
|
||||
|
||||
/**
|
||||
* @brief Unregister CallBack function on signal change
|
||||
* @param[in] callback function
|
||||
*/
|
||||
void UnregisterOnSignalChangeOfRightDoorIsOpen02(vss::Vehicle::Chassis::Door::Axle02::RightService::IVSS_SetIsOpen_Event* callback) override;
|
||||
|
||||
private:
|
||||
|
||||
bool m_rightDoorIsOpen02 { 0 };
|
||||
mutable std::mutex m_rightDoorIsOpen02MutexCallbacks; ///< Mutex protecting m_rightDoorIsOpen02Callbacks
|
||||
std::set<vss::Vehicle::Chassis::Door::Axle02::RightService::IVSS_SetIsOpen_Event*> m_rightDoorIsOpen02Callbacks; ///< collection of events to be called
|
||||
vss::Vehicle::Chassis::Door::Axle02::RightDevice::IVSS_WriteLock* m_ptrLock = nullptr;
|
||||
};
|
||||
|
||||
DEFINE_SDV_OBJECT(CBasicServiceRearDoorRight)
|
||||
|
||||
#endif // !define __VSS_GENERATED__BS_REARDOORRIGHT_H_20250711_125718_616__
|
||||
42
examples/door_demo_example/can_dl_door/CMakeLists.txt
Normal file
42
examples/door_demo_example/can_dl_door/CMakeLists.txt
Normal file
@@ -0,0 +1,42 @@
|
||||
# Enforce CMake version 3.20 or newer needed for path function
|
||||
cmake_minimum_required (VERSION 3.20)
|
||||
|
||||
# Use new policy for project version settings and default warning level
|
||||
cmake_policy(SET CMP0048 NEW) # requires CMake 3.14
|
||||
cmake_policy(SET CMP0092 NEW) # requires CMake 3.15
|
||||
|
||||
# Define project
|
||||
project(can_dl_door VERSION 1.0 LANGUAGES CXX)
|
||||
|
||||
# Use C++17 support
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
# Library symbols are hidden by default
|
||||
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
|
||||
|
||||
# Set the SDV_FRAMEWORK_DEV_INCLUDE if not defined yet
|
||||
if (NOT DEFINED SDV_FRAMEWORK_DEV_INCLUDE)
|
||||
if (NOT DEFINED ENV{SDV_FRAMEWORK_DEV_INCLUDE})
|
||||
message( FATAL_ERROR "The environment variable SDV_FRAMEWORK_DEV_INCLUDE needs to be pointing to the SDV V-API development include files location!")
|
||||
endif()
|
||||
set (SDV_FRAMEWORK_DEV_INCLUDE "$ENV{SDV_FRAMEWORK_DEV_INCLUDE}")
|
||||
endif()
|
||||
|
||||
# Include link to export directory of SDV V-API development include files location
|
||||
include_directories(${SDV_FRAMEWORK_DEV_INCLUDE})
|
||||
|
||||
# Set platform specific compile flags
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||
add_compile_options(/W4 /WX /wd4996 /wd4100 /permissive- /Zc:rvalueCast)
|
||||
else()
|
||||
add_compile_options(-Werror -Wall -Wextra -Wshadow -Wpedantic -Wunreachable-code -fno-common)
|
||||
endif()
|
||||
|
||||
# Add the dynamic library
|
||||
add_library(can_dl_door SHARED
|
||||
datalink.cpp
|
||||
datalink.h)
|
||||
|
||||
# Set extension to .sdv
|
||||
set_target_properties(can_dl_door PROPERTIES PREFIX "")
|
||||
set_target_properties(can_dl_door PROPERTIES SUFFIX ".sdv")
|
||||
412
examples/door_demo_example/can_dl_door/datalink.cpp
Normal file
412
examples/door_demo_example/can_dl_door/datalink.cpp
Normal file
@@ -0,0 +1,412 @@
|
||||
/**
|
||||
* @file datalink.cpp
|
||||
* @date 2025-09-06 08:00:37
|
||||
* This file implements the data link object between CAN and the V-API devices.
|
||||
* This file was generated by the DBC utility from:
|
||||
* "", "datalink_4doors_example.dbc"
|
||||
* DBC file version: 1.0.0.1
|
||||
*/
|
||||
#include "datalink.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#ifdef min
|
||||
#undef min
|
||||
#endif
|
||||
#ifdef max
|
||||
#undef max
|
||||
#endif
|
||||
#endif
|
||||
|
||||
CDataLink::CDataLink() :
|
||||
m_sRxMsgCAN_Input_L1(m_dispatch),
|
||||
m_sRxMsgCAN_Input_R1(m_dispatch),
|
||||
m_sRxMsgCAN_Input_L2(m_dispatch),
|
||||
m_sRxMsgCAN_Input_R2(m_dispatch),
|
||||
m_sTxMsgCAN_Output(m_dispatch)
|
||||
{}
|
||||
|
||||
CDataLink::~CDataLink()
|
||||
{
|
||||
Shutdown(); // Just in case
|
||||
}
|
||||
|
||||
void CDataLink::Initialize(const sdv::u8string& /*ssObjectConfig*/)
|
||||
{
|
||||
if (m_eStatus != sdv::EObjectStatus::initialization_pending) return;
|
||||
|
||||
// Get the CAN communication object.
|
||||
sdv::TInterfaceAccessPtr ptrCANObject = sdv::core::GetObject("CAN_Communication_Object");
|
||||
if (!ptrCANObject)
|
||||
{
|
||||
SDV_LOG_ERROR("CDataLink::Initialize() failure, 'CAN_Communication_Object' not found");
|
||||
m_eStatus = sdv::EObjectStatus::initialization_failure;
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the CAN receiver registration interface.
|
||||
m_pRegister = ptrCANObject.GetInterface<sdv::can::IRegisterReceiver>();
|
||||
if (!m_pRegister)
|
||||
{
|
||||
SDV_LOG_ERROR("CDataLink::Initialize() failure, 'sdv::can::IRegisterReceiver' interface not found");
|
||||
m_eStatus = sdv::EObjectStatus::initialization_failure;
|
||||
return;
|
||||
}
|
||||
m_pRegister->RegisterReceiver(static_cast<sdv::can::IReceive*>(this));
|
||||
|
||||
// Get the CAN transmit interface
|
||||
m_pSend = ptrCANObject.GetInterface<sdv::can::ISend>();
|
||||
if (!m_pSend)
|
||||
{
|
||||
SDV_LOG_ERROR("CDataLink::Initialize() failure, 'sdv::can::ISend' interface not found");
|
||||
m_eStatus = sdv::EObjectStatus::initialization_failure;
|
||||
return;
|
||||
}
|
||||
|
||||
// Initialize messages
|
||||
bool bSuccess = true;
|
||||
bSuccess &= m_sRxMsgCAN_Input_L1.Init();
|
||||
bSuccess &= m_sRxMsgCAN_Input_R1.Init();
|
||||
bSuccess &= m_sRxMsgCAN_Input_L2.Init();
|
||||
bSuccess &= m_sRxMsgCAN_Input_R2.Init();
|
||||
bSuccess &= m_sTxMsgCAN_Output.Init(m_pSend);
|
||||
|
||||
m_eStatus = bSuccess ? sdv::EObjectStatus::initialized : sdv::EObjectStatus::initialization_failure;
|
||||
}
|
||||
|
||||
sdv::EObjectStatus CDataLink::GetStatus() const
|
||||
{
|
||||
return m_eStatus;
|
||||
}
|
||||
|
||||
void CDataLink::SetOperationMode(sdv::EOperationMode eMode)
|
||||
{
|
||||
switch (eMode)
|
||||
{
|
||||
case sdv::EOperationMode::configuring:
|
||||
if (m_eStatus == sdv::EObjectStatus::running || m_eStatus == sdv::EObjectStatus::initialized)
|
||||
m_eStatus = sdv::EObjectStatus::configuring;
|
||||
break;
|
||||
case sdv::EOperationMode::running:
|
||||
if (m_eStatus == sdv::EObjectStatus::configuring || m_eStatus == sdv::EObjectStatus::initialized)
|
||||
m_eStatus = sdv::EObjectStatus::running;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void CDataLink::Shutdown()
|
||||
{
|
||||
m_eStatus = sdv::EObjectStatus::shutdown_in_progress;
|
||||
|
||||
// Unregister receiver interface.
|
||||
if (m_pRegister) m_pRegister->UnregisterReceiver(static_cast<sdv::can::IReceive*>(this));
|
||||
m_pRegister = nullptr;
|
||||
|
||||
m_pSend = nullptr;
|
||||
|
||||
// Terminate messages
|
||||
m_sRxMsgCAN_Input_L1.Term();
|
||||
m_sRxMsgCAN_Input_R1.Term();
|
||||
m_sRxMsgCAN_Input_L2.Term();
|
||||
m_sRxMsgCAN_Input_R2.Term();
|
||||
m_sTxMsgCAN_Output.Term();
|
||||
|
||||
// Update the status
|
||||
m_eStatus = sdv::EObjectStatus::destruction_pending;
|
||||
}
|
||||
|
||||
void CDataLink::Receive(/*in*/ [[maybe_unused]] const sdv::can::SMessage& sMsg, /*in*/ uint32_t uiIfcIndex)
|
||||
{
|
||||
if (static_cast<size_t>(uiIfcIndex) != m_nIfcIndex) return;
|
||||
|
||||
switch (sMsg.uiID)
|
||||
{
|
||||
case 1: // CAN_Input_L1
|
||||
m_sRxMsgCAN_Input_L1.Process(sMsg.seqData);
|
||||
break;
|
||||
case 2: // CAN_Input_R1
|
||||
m_sRxMsgCAN_Input_R1.Process(sMsg.seqData);
|
||||
break;
|
||||
case 3: // CAN_Input_L2
|
||||
m_sRxMsgCAN_Input_L2.Process(sMsg.seqData);
|
||||
break;
|
||||
case 4: // CAN_Input_R2
|
||||
m_sRxMsgCAN_Input_R2.Process(sMsg.seqData);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void CDataLink::Error(/*in*/ [[maybe_unused]] const sdv::can::SErrorFrame& sError, /*in*/ uint32_t uiIfcIndex)
|
||||
{
|
||||
if (static_cast<size_t>(uiIfcIndex) != m_nIfcIndex) return;
|
||||
|
||||
// TODO: Currently no error frame handling...
|
||||
}
|
||||
|
||||
|
||||
CDataLink::SRxMsg_CAN_Input_L1::SRxMsg_CAN_Input_L1(sdv::core::CDispatchService& rdispatch) :
|
||||
m_rdispatch(rdispatch)
|
||||
{}
|
||||
|
||||
bool CDataLink::SRxMsg_CAN_Input_L1::Init()
|
||||
{
|
||||
// Register signals
|
||||
[[maybe_unused]] bool bSuccess = true;
|
||||
m_sigDoor01LeftIsOpen = m_rdispatch.RegisterRxSignal("CAN_Input_L1.Door01LeftIsOpen");
|
||||
bSuccess &= m_sigDoor01LeftIsOpen ? true : false;
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
void CDataLink::SRxMsg_CAN_Input_L1::Term()
|
||||
{
|
||||
// Unregister signals
|
||||
m_sigDoor01LeftIsOpen.Reset();
|
||||
}
|
||||
|
||||
void CDataLink::SRxMsg_CAN_Input_L1::Process(const sdv::sequence<uint8_t>& rseqData)
|
||||
{
|
||||
// Check for the correct size.
|
||||
if (rseqData.size() != 1)
|
||||
{
|
||||
// TODO: Error. Delivered data has different size as compared to the specification.
|
||||
return;
|
||||
}
|
||||
|
||||
// Helper variable
|
||||
[[maybe_unused]] UValueHelper uValueHelper;
|
||||
|
||||
// Start a transaction
|
||||
sdv::core::CTransaction transaction = m_rdispatch.CreateTransaction();
|
||||
|
||||
// Process CAN_Input_L1.Door01LeftIsOpen
|
||||
uValueHelper.uiUint64Value = rseqData[0] & 3;
|
||||
uValueHelper.uiUint64Value >>= 1;
|
||||
m_sigDoor01LeftIsOpen.Write(std::min(std::max(uValueHelper.s32.u32.uiValue, 0u), 1u), transaction);
|
||||
|
||||
// Finalize the transaction
|
||||
transaction.Finish();
|
||||
}
|
||||
|
||||
CDataLink::SRxMsg_CAN_Input_R1::SRxMsg_CAN_Input_R1(sdv::core::CDispatchService& rdispatch) :
|
||||
m_rdispatch(rdispatch)
|
||||
{}
|
||||
|
||||
bool CDataLink::SRxMsg_CAN_Input_R1::Init()
|
||||
{
|
||||
// Register signals
|
||||
[[maybe_unused]] bool bSuccess = true;
|
||||
m_sigDoor01RightIsOpen = m_rdispatch.RegisterRxSignal("CAN_Input_R1.Door01RightIsOpen");
|
||||
bSuccess &= m_sigDoor01RightIsOpen ? true : false;
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
void CDataLink::SRxMsg_CAN_Input_R1::Term()
|
||||
{
|
||||
// Unregister signals
|
||||
m_sigDoor01RightIsOpen.Reset();
|
||||
}
|
||||
|
||||
void CDataLink::SRxMsg_CAN_Input_R1::Process(const sdv::sequence<uint8_t>& rseqData)
|
||||
{
|
||||
// Check for the correct size.
|
||||
if (rseqData.size() != 1)
|
||||
{
|
||||
// TODO: Error. Delivered data has different size as compared to the specification.
|
||||
return;
|
||||
}
|
||||
|
||||
// Helper variable
|
||||
[[maybe_unused]] UValueHelper uValueHelper;
|
||||
|
||||
// Start a transaction
|
||||
sdv::core::CTransaction transaction = m_rdispatch.CreateTransaction();
|
||||
|
||||
// Process CAN_Input_R1.Door01RightIsOpen
|
||||
uValueHelper.uiUint64Value = rseqData[0] & 15;
|
||||
uValueHelper.uiUint64Value >>= 3;
|
||||
m_sigDoor01RightIsOpen.Write(std::min(std::max(uValueHelper.s32.u32.uiValue, 0u), 1u), transaction);
|
||||
|
||||
// Finalize the transaction
|
||||
transaction.Finish();
|
||||
}
|
||||
|
||||
CDataLink::SRxMsg_CAN_Input_L2::SRxMsg_CAN_Input_L2(sdv::core::CDispatchService& rdispatch) :
|
||||
m_rdispatch(rdispatch)
|
||||
{}
|
||||
|
||||
bool CDataLink::SRxMsg_CAN_Input_L2::Init()
|
||||
{
|
||||
// Register signals
|
||||
[[maybe_unused]] bool bSuccess = true;
|
||||
m_sigDoor02LeftIsOpen = m_rdispatch.RegisterRxSignal("CAN_Input_L2.Door02LeftIsOpen");
|
||||
bSuccess &= m_sigDoor02LeftIsOpen ? true : false;
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
void CDataLink::SRxMsg_CAN_Input_L2::Term()
|
||||
{
|
||||
// Unregister signals
|
||||
m_sigDoor02LeftIsOpen.Reset();
|
||||
}
|
||||
|
||||
void CDataLink::SRxMsg_CAN_Input_L2::Process(const sdv::sequence<uint8_t>& rseqData)
|
||||
{
|
||||
// Check for the correct size.
|
||||
if (rseqData.size() != 1)
|
||||
{
|
||||
// TODO: Error. Delivered data has different size as compared to the specification.
|
||||
return;
|
||||
}
|
||||
|
||||
// Helper variable
|
||||
[[maybe_unused]] UValueHelper uValueHelper;
|
||||
|
||||
// Start a transaction
|
||||
sdv::core::CTransaction transaction = m_rdispatch.CreateTransaction();
|
||||
|
||||
// Process CAN_Input_L2.Door02LeftIsOpen
|
||||
uValueHelper.uiUint64Value = rseqData[0] & 63;
|
||||
uValueHelper.uiUint64Value >>= 5;
|
||||
m_sigDoor02LeftIsOpen.Write(std::min(std::max(uValueHelper.s32.u32.uiValue, 0u), 1u), transaction);
|
||||
|
||||
// Finalize the transaction
|
||||
transaction.Finish();
|
||||
}
|
||||
|
||||
CDataLink::SRxMsg_CAN_Input_R2::SRxMsg_CAN_Input_R2(sdv::core::CDispatchService& rdispatch) :
|
||||
m_rdispatch(rdispatch)
|
||||
{}
|
||||
|
||||
bool CDataLink::SRxMsg_CAN_Input_R2::Init()
|
||||
{
|
||||
// Register signals
|
||||
[[maybe_unused]] bool bSuccess = true;
|
||||
m_sigDoor02RightIsOpen = m_rdispatch.RegisterRxSignal("CAN_Input_R2.Door02RightIsOpen");
|
||||
bSuccess &= m_sigDoor02RightIsOpen ? true : false;
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
void CDataLink::SRxMsg_CAN_Input_R2::Term()
|
||||
{
|
||||
// Unregister signals
|
||||
m_sigDoor02RightIsOpen.Reset();
|
||||
}
|
||||
|
||||
void CDataLink::SRxMsg_CAN_Input_R2::Process(const sdv::sequence<uint8_t>& rseqData)
|
||||
{
|
||||
// Check for the correct size.
|
||||
if (rseqData.size() != 1)
|
||||
{
|
||||
// TODO: Error. Delivered data has different size as compared to the specification.
|
||||
return;
|
||||
}
|
||||
|
||||
// Helper variable
|
||||
[[maybe_unused]] UValueHelper uValueHelper;
|
||||
|
||||
// Start a transaction
|
||||
sdv::core::CTransaction transaction = m_rdispatch.CreateTransaction();
|
||||
|
||||
// Process CAN_Input_R2.Door02RightIsOpen
|
||||
uValueHelper.uiUint64Value = rseqData[0];
|
||||
uValueHelper.uiUint64Value >>= 7;
|
||||
m_sigDoor02RightIsOpen.Write(std::min(std::max(uValueHelper.s32.u32.uiValue, 0u), 1u), transaction);
|
||||
|
||||
// Finalize the transaction
|
||||
transaction.Finish();
|
||||
}
|
||||
|
||||
CDataLink::STxMsg_CAN_Output::STxMsg_CAN_Output(sdv::core::CDispatchService& rdispatch) :
|
||||
m_rdispatch(rdispatch)
|
||||
{}
|
||||
|
||||
bool CDataLink::STxMsg_CAN_Output::Init(sdv::can::ISend* pSend)
|
||||
{
|
||||
if (!pSend) return false;
|
||||
m_pSend = pSend;
|
||||
|
||||
// Register signals
|
||||
bool bSuccess = true;
|
||||
m_sigLockDoor02Right = m_rdispatch.RegisterTxSignal("CAN_Output.LockDoor02Right", sdv::any_t());
|
||||
bSuccess &= m_sigLockDoor02Right ? true : false;
|
||||
m_sigLockDoor02Left = m_rdispatch.RegisterTxSignal("CAN_Output.LockDoor02Left", sdv::any_t());
|
||||
bSuccess &= m_sigLockDoor02Left ? true : false;
|
||||
m_sigLockDoor01Right = m_rdispatch.RegisterTxSignal("CAN_Output.LockDoor01Right", sdv::any_t());
|
||||
bSuccess &= m_sigLockDoor01Right ? true : false;
|
||||
m_sigLockDoor01Left = m_rdispatch.RegisterTxSignal("CAN_Output.LockDoor01Left", sdv::any_t());
|
||||
bSuccess &= m_sigLockDoor01Left ? true : false;
|
||||
|
||||
// Initialize the trigger
|
||||
m_trigger = m_rdispatch.CreateTxTrigger([&] { Transmit(); }, false, 0, 10, false);
|
||||
m_trigger.AddSignal(m_sigLockDoor02Right);
|
||||
m_trigger.AddSignal(m_sigLockDoor02Left);
|
||||
m_trigger.AddSignal(m_sigLockDoor01Right);
|
||||
m_trigger.AddSignal(m_sigLockDoor01Left);
|
||||
bSuccess &= m_trigger;
|
||||
|
||||
return bSuccess;
|
||||
}
|
||||
|
||||
void CDataLink::STxMsg_CAN_Output::Term()
|
||||
{
|
||||
// Reset the trigger
|
||||
m_trigger.Reset();
|
||||
|
||||
// Unregister signals
|
||||
m_sigLockDoor02Right.Reset();
|
||||
m_sigLockDoor02Left.Reset();
|
||||
m_sigLockDoor01Right.Reset();
|
||||
m_sigLockDoor01Left.Reset();
|
||||
}
|
||||
|
||||
void CDataLink::STxMsg_CAN_Output::Transmit()
|
||||
{
|
||||
if (!m_pSend) return;
|
||||
|
||||
// Compose CAN message
|
||||
sdv::can::SMessage msg;
|
||||
msg.uiID = 5;
|
||||
msg.bExtended = false;
|
||||
msg.bCanFd = false; // TODO: Currently not supported
|
||||
msg.seqData.resize(1);
|
||||
std::fill(msg.seqData.begin(), msg.seqData.end(), static_cast<uint8_t>(0));
|
||||
|
||||
// Helper variable
|
||||
[[maybe_unused]] UValueHelper uValueHelper;
|
||||
|
||||
// Start a transaction
|
||||
sdv::core::CTransaction transaction = m_rdispatch.CreateTransaction();
|
||||
|
||||
// Compose CAN_Output.LockDoor02Right
|
||||
uValueHelper.s32.u32.uiValue = static_cast<uint32_t>(std::min(std::max(static_cast<long long int>(m_sigLockDoor02Right.Read(transaction)), 0ll), 1ll));
|
||||
uValueHelper.uiUint64Value <<= 7;
|
||||
msg.seqData[0] |= uValueHelper.uiUint64Value & 0xff;
|
||||
|
||||
// Compose CAN_Output.LockDoor02Left
|
||||
uValueHelper.s32.u32.uiValue = static_cast<uint32_t>(std::min(std::max(static_cast<long long int>(m_sigLockDoor02Left.Read(transaction)), 0ll), 1ll));
|
||||
uValueHelper.uiUint64Value <<= 5;
|
||||
msg.seqData[0] |= uValueHelper.uiUint64Value & 63;
|
||||
|
||||
// Compose CAN_Output.LockDoor01Right
|
||||
uValueHelper.s32.u32.uiValue = static_cast<uint32_t>(std::min(std::max(static_cast<long long int>(m_sigLockDoor01Right.Read(transaction)), 0ll), 1ll));
|
||||
uValueHelper.uiUint64Value <<= 3;
|
||||
msg.seqData[0] |= uValueHelper.uiUint64Value & 15;
|
||||
|
||||
// Compose CAN_Output.LockDoor01Left
|
||||
uValueHelper.s32.u32.uiValue = static_cast<uint32_t>(std::min(std::max(static_cast<long long int>(m_sigLockDoor01Left.Read(transaction)), 0ll), 1ll));
|
||||
uValueHelper.uiUint64Value <<= 1;
|
||||
msg.seqData[0] |= uValueHelper.uiUint64Value & 3;
|
||||
|
||||
// Finalize the transaction
|
||||
transaction.Finish();
|
||||
|
||||
// Transmit the message
|
||||
// TODO: Determine CAN interface index...
|
||||
m_pSend->Send(msg, 0);
|
||||
}
|
||||
|
||||
300
examples/door_demo_example/can_dl_door/datalink.h
Normal file
300
examples/door_demo_example/can_dl_door/datalink.h
Normal file
@@ -0,0 +1,300 @@
|
||||
/**
|
||||
* @file datalink.h
|
||||
* @date 2025-09-06 08:00:37
|
||||
* This file defines the data link object between CAN and the V-API devices.
|
||||
* This file was generated by the DBC utility from:
|
||||
* "", "datalink_4doors_example.dbc"
|
||||
* DBC file version: 1.0.0.1
|
||||
*/
|
||||
#ifndef __DBC_GENERATED__DATALINK_H__20250906_080037_856__
|
||||
#define __DBC_GENERATED__DATALINK_H__20250906_080037_856__
|
||||
|
||||
#include <support/component_impl.h>
|
||||
#include <interfaces/can.h>
|
||||
#include <support/interface_ptr.h>
|
||||
#include <support/signal_support.h>
|
||||
|
||||
/**
|
||||
* @brief Data link class.
|
||||
*/
|
||||
class CDataLink : public sdv::CSdvObject, public sdv::IObjectControl, public sdv::can::IReceive
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
CDataLink();
|
||||
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
~CDataLink();
|
||||
|
||||
// Interface map
|
||||
BEGIN_SDV_INTERFACE_MAP()
|
||||
SDV_INTERFACE_ENTRY(sdv::IObjectControl)
|
||||
SDV_INTERFACE_ENTRY(sdv::can::IReceive)
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
// Declarations
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::Device)
|
||||
DECLARE_OBJECT_CLASS_NAME("CAN_data_link")
|
||||
DECLARE_DEFAULT_OBJECT_NAME("DataLink")
|
||||
DECLARE_OBJECT_SINGLETON()
|
||||
|
||||
/**
|
||||
* @brief Initialize the object. Overload of sdv::IObjectControl::Initialize.
|
||||
* @param[in] ssObjectConfig Optional configuration string.
|
||||
*/
|
||||
void Initialize(const sdv::u8string& ssObjectConfig) override;
|
||||
|
||||
/**
|
||||
* @brief Get the current status of the object. Overload of sdv::IObjectControl::GetStatus.
|
||||
* @return Return the current status of the object.
|
||||
*/
|
||||
sdv::EObjectStatus GetStatus() const override;
|
||||
|
||||
/**
|
||||
* @brief Set the component operation mode. Overload of sdv::IObjectControl::SetOperationMode.
|
||||
* @param[in] eMode The operation mode, the component should run in.
|
||||
*/
|
||||
void SetOperationMode(sdv::EOperationMode eMode) override;
|
||||
|
||||
/**
|
||||
* @brief Shutdown called before the object is destroyed. Overload of sdv::IObjectControl::Shutdown.
|
||||
*/
|
||||
void Shutdown() override;
|
||||
|
||||
/**
|
||||
* @brief Process a receive a CAN message. Overload of sdv::can::IReceive::Receive.
|
||||
* @param[in] sMsg Message that was received.
|
||||
* @param[in] uiIfcIndex Interface index of the received message.
|
||||
*/
|
||||
virtual void Receive(/*in*/ const sdv::can::SMessage& sMsg, /*in*/ uint32_t uiIfcIndex) override;
|
||||
|
||||
/**
|
||||
* @brief Process an error frame. Overload of sdv::can::IReceive::Error.
|
||||
* @param[in] sError Error frame that was received.
|
||||
* @param[in] uiIfcIndex Interface index of the received message.
|
||||
*/
|
||||
virtual void Error(/*in*/ const sdv::can::SErrorFrame& sError, /*in*/ uint32_t uiIfcIndex) override;
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Union containing all the compound values needed to convert between the DBC defined types.
|
||||
*/
|
||||
union UValueHelper
|
||||
{
|
||||
uint64_t uiUint64Value; ///< The 64-bit unsingned value.
|
||||
int64_t iInt64Value; ///< The 64-bit signed value.
|
||||
|
||||
/**
|
||||
* @brief The structure mapping the 32-bit value types into the 64-bit.
|
||||
*/
|
||||
struct S32
|
||||
{
|
||||
#if (!defined(_MSC_VER) || defined(__clang__)) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
|
||||
uint32_t uiPadding; ///< Padding for big endian byte ordering (MSB)
|
||||
#endif
|
||||
/**
|
||||
* @brief The 32-bit union containing the possible 32-bit values.
|
||||
*/
|
||||
union U32Value
|
||||
{
|
||||
int32_t iValue; ///< 32-bit signed integer.
|
||||
uint32_t uiValue; ///< 32-bit unsigned integer.
|
||||
float fValue; ///< 32-bit floating point number.
|
||||
} u32; ///< 32-bit union instance.
|
||||
|
||||
#if (defined(_MSC_VER) && !defined(__clang__)) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
|
||||
uint32_t uiPadding; ///< Padding for little endian byte ordering (MSB)
|
||||
#endif
|
||||
} s32;
|
||||
|
||||
double dValue; ///< 64-bit double precision floating point number.
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief RX CAN message definition of: CAN_Input_L1 [id=1]
|
||||
*/
|
||||
struct SRxMsg_CAN_Input_L1
|
||||
{
|
||||
/**
|
||||
* @brief Constructor
|
||||
* @param[in] rdispatch Reference to the dispatch service.
|
||||
*/
|
||||
SRxMsg_CAN_Input_L1(sdv::core::CDispatchService& rdispatch);
|
||||
|
||||
/**
|
||||
* @brief Initialize the message by registering all signals.
|
||||
*/
|
||||
bool Init();
|
||||
|
||||
/**
|
||||
* @brief Terminate the message by unregistering all signals.
|
||||
*/
|
||||
void Term();
|
||||
|
||||
/**
|
||||
* @brief Process received data.
|
||||
* @param[in] rseqData Reference to the message data to process.
|
||||
*/
|
||||
void Process(const sdv::sequence<uint8_t>& rseqData);
|
||||
|
||||
sdv::core::CDispatchService& m_rdispatch; ///< Reference to the dispatch service.
|
||||
|
||||
/// Signal Door01LeftIsOpen with unit
|
||||
sdv::core::CSignal m_sigDoor01LeftIsOpen;
|
||||
} m_sRxMsgCAN_Input_L1;
|
||||
|
||||
/**
|
||||
* @brief RX CAN message definition of: CAN_Input_R1 [id=2]
|
||||
*/
|
||||
struct SRxMsg_CAN_Input_R1
|
||||
{
|
||||
/**
|
||||
* @brief Constructor
|
||||
* @param[in] rdispatch Reference to the dispatch service.
|
||||
*/
|
||||
SRxMsg_CAN_Input_R1(sdv::core::CDispatchService& rdispatch);
|
||||
|
||||
/**
|
||||
* @brief Initialize the message by registering all signals.
|
||||
*/
|
||||
bool Init();
|
||||
|
||||
/**
|
||||
* @brief Terminate the message by unregistering all signals.
|
||||
*/
|
||||
void Term();
|
||||
|
||||
/**
|
||||
* @brief Process received data.
|
||||
* @param[in] rseqData Reference to the message data to process.
|
||||
*/
|
||||
void Process(const sdv::sequence<uint8_t>& rseqData);
|
||||
|
||||
sdv::core::CDispatchService& m_rdispatch; ///< Reference to the dispatch service.
|
||||
|
||||
/// Signal Door01RightIsOpen with unit
|
||||
sdv::core::CSignal m_sigDoor01RightIsOpen;
|
||||
} m_sRxMsgCAN_Input_R1;
|
||||
|
||||
/**
|
||||
* @brief RX CAN message definition of: CAN_Input_L2 [id=3]
|
||||
*/
|
||||
struct SRxMsg_CAN_Input_L2
|
||||
{
|
||||
/**
|
||||
* @brief Constructor
|
||||
* @param[in] rdispatch Reference to the dispatch service.
|
||||
*/
|
||||
SRxMsg_CAN_Input_L2(sdv::core::CDispatchService& rdispatch);
|
||||
|
||||
/**
|
||||
* @brief Initialize the message by registering all signals.
|
||||
*/
|
||||
bool Init();
|
||||
|
||||
/**
|
||||
* @brief Terminate the message by unregistering all signals.
|
||||
*/
|
||||
void Term();
|
||||
|
||||
/**
|
||||
* @brief Process received data.
|
||||
* @param[in] rseqData Reference to the message data to process.
|
||||
*/
|
||||
void Process(const sdv::sequence<uint8_t>& rseqData);
|
||||
|
||||
sdv::core::CDispatchService& m_rdispatch; ///< Reference to the dispatch service.
|
||||
|
||||
/// Signal Door02LeftIsOpen with unit
|
||||
sdv::core::CSignal m_sigDoor02LeftIsOpen;
|
||||
} m_sRxMsgCAN_Input_L2;
|
||||
|
||||
/**
|
||||
* @brief RX CAN message definition of: CAN_Input_R2 [id=4]
|
||||
*/
|
||||
struct SRxMsg_CAN_Input_R2
|
||||
{
|
||||
/**
|
||||
* @brief Constructor
|
||||
* @param[in] rdispatch Reference to the dispatch service.
|
||||
*/
|
||||
SRxMsg_CAN_Input_R2(sdv::core::CDispatchService& rdispatch);
|
||||
|
||||
/**
|
||||
* @brief Initialize the message by registering all signals.
|
||||
*/
|
||||
bool Init();
|
||||
|
||||
/**
|
||||
* @brief Terminate the message by unregistering all signals.
|
||||
*/
|
||||
void Term();
|
||||
|
||||
/**
|
||||
* @brief Process received data.
|
||||
* @param[in] rseqData Reference to the message data to process.
|
||||
*/
|
||||
void Process(const sdv::sequence<uint8_t>& rseqData);
|
||||
|
||||
sdv::core::CDispatchService& m_rdispatch; ///< Reference to the dispatch service.
|
||||
|
||||
/// Signal Door02RightIsOpen with unit
|
||||
sdv::core::CSignal m_sigDoor02RightIsOpen;
|
||||
} m_sRxMsgCAN_Input_R2;
|
||||
|
||||
/**
|
||||
* @brief TX CAN message definition of: CAN_Output [id=5]
|
||||
*/
|
||||
struct STxMsg_CAN_Output
|
||||
{
|
||||
/**
|
||||
* @brief Constructor
|
||||
* @param[in] rdispatch Reference to the dispatch service.
|
||||
*/
|
||||
STxMsg_CAN_Output(sdv::core::CDispatchService& rdispatch);
|
||||
|
||||
/**
|
||||
* @brief Initialize the message by registering all signals.
|
||||
* @param[in] pSend The send-interface of the CAN.
|
||||
*/
|
||||
bool Init(sdv::can::ISend* pSend);
|
||||
|
||||
/**
|
||||
* @brief Terminate the message by unregistering all signals.
|
||||
*/
|
||||
void Term();
|
||||
|
||||
/**
|
||||
* @brief Transmit data.
|
||||
* @param[in] pCanSend Pointer to the CAN send interface.
|
||||
*/
|
||||
void Transmit();
|
||||
|
||||
sdv::core::CDispatchService& m_rdispatch; ///< Reference to the dispatch service.
|
||||
sdv::core::CTrigger m_trigger; ///< Message trigger being called by the dispatch service.
|
||||
sdv::can::ISend* m_pSend = nullptr; ///< Message sending interface.
|
||||
|
||||
/// Signal LockDoor02Right with unit
|
||||
sdv::core::CSignal m_sigLockDoor02Right;
|
||||
/// Signal LockDoor02Left with unit
|
||||
sdv::core::CSignal m_sigLockDoor02Left;
|
||||
/// Signal LockDoor01Right with unit
|
||||
sdv::core::CSignal m_sigLockDoor01Right;
|
||||
/// Signal LockDoor01Left with unit
|
||||
sdv::core::CSignal m_sigLockDoor01Left;
|
||||
} m_sTxMsgCAN_Output;
|
||||
|
||||
sdv::EObjectStatus m_eStatus = sdv::EObjectStatus::initialization_pending; ///< Keep track of the object status.
|
||||
size_t m_nIfcIndex = 0; ///< CAN Interface index.
|
||||
sdv::can::IRegisterReceiver* m_pRegister = nullptr; ///< CAN receiver registration interface.
|
||||
sdv::can::ISend* m_pSend = nullptr; ///< CAN sender interface.
|
||||
sdv::core::CDispatchService m_dispatch; ///< Dispatch service
|
||||
};
|
||||
|
||||
DEFINE_SDV_OBJECT(CDataLink)
|
||||
|
||||
#endif // !defined __DBC_GENERATED__DATALINK_H__20250906_080037_856__
|
||||
@@ -0,0 +1,8 @@
|
||||
[Configuration]
|
||||
Version = 100
|
||||
|
||||
[[Component]]
|
||||
Path = "data_dispatch_service.sdv"
|
||||
Class = "DataDispatchService"
|
||||
|
||||
|
||||
12
examples/door_demo_example/config/data_link_door.toml
Normal file
12
examples/door_demo_example/config/data_link_door.toml
Normal file
@@ -0,0 +1,12 @@
|
||||
[Configuration]
|
||||
Version = 100
|
||||
|
||||
[[Component]]
|
||||
Path = "can_com_sim.sdv"
|
||||
Class = "CAN_Com_Sim"
|
||||
Source="door_example_receiver.asc"
|
||||
Target="door_example_writer.asc"
|
||||
|
||||
[[Component]]
|
||||
Path = "can_dl_door.sdv"
|
||||
Class = "CAN_data_link"
|
||||
10
examples/door_demo_example/config/door_comple_service.toml
Normal file
10
examples/door_demo_example/config/door_comple_service.toml
Normal file
@@ -0,0 +1,10 @@
|
||||
[Configuration]
|
||||
Version = 100
|
||||
|
||||
[[Component]]
|
||||
Path = "door_complex_service.sdv"
|
||||
Class = "Doors Example Service"
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
[Configuration]
|
||||
Version = 100
|
||||
|
||||
[[Component]]
|
||||
Path = "doors_vd_frontdoorleft.sdv"
|
||||
Class = "Vehicle.Chassis.Door.Axle01.Left_Device"
|
||||
|
||||
[[Component]]
|
||||
Path = "doors_bs_frontdoorleft.sdv"
|
||||
Class = "Vehicle.Chassis.Door.Axle01.Left_Service"
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
[Configuration]
|
||||
Version = 100
|
||||
|
||||
[[Component]]
|
||||
Path = "doors_vd_frontdoorright.sdv"
|
||||
Class = "Vehicle.Chassis.Door.Axle01.Right_Device"
|
||||
|
||||
[[Component]]
|
||||
Path = "doors_bs_frontdoorright.sdv"
|
||||
Class = "Vehicle.Chassis.Door.Axle01.Right_Service"
|
||||
@@ -0,0 +1,14 @@
|
||||
[Configuration]
|
||||
Version = 100
|
||||
|
||||
[[Component]]
|
||||
Path = "doors_vd_reardoorleft.sdv"
|
||||
Class = "Vehicle.Chassis.Door.Axle02.Left_Device"
|
||||
|
||||
[[Component]]
|
||||
Path = "doors_bs_reardoorleft.sdv"
|
||||
Class = "Vehicle.Chassis.Door.Axle02.Left_Service"
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
[Configuration]
|
||||
Version = 100
|
||||
|
||||
[[Component]]
|
||||
Path = "doors_vd_reardoorright.sdv"
|
||||
Class = "Vehicle.Chassis.Door.Axle02.Right_Device"
|
||||
|
||||
[[Component]]
|
||||
Path = "doors_bs_reardoorright.sdv"
|
||||
Class = "Vehicle.Chassis.Door.Axle02.Right_Service"
|
||||
@@ -0,0 +1,6 @@
|
||||
[Configuration]
|
||||
Version = 100
|
||||
|
||||
[[Component]]
|
||||
Path = "task_timer.sdv"
|
||||
Class = "TaskTimerService"
|
||||
12
examples/door_demo_example/coreconfig/door_demo.toml
Normal file
12
examples/door_demo_example/coreconfig/door_demo.toml
Normal file
@@ -0,0 +1,12 @@
|
||||
[Configuration]
|
||||
Version = 100
|
||||
|
||||
[[Component]]
|
||||
Path = "door_complex_service.sdv"
|
||||
Class = "Doors Example Service"
|
||||
Name = "Doors Example Service"
|
||||
|
||||
[[Module]]
|
||||
Path = "doors_service_proxystub.sdv"
|
||||
|
||||
|
||||
9
examples/door_demo_example/coreconfig/platform.toml
Normal file
9
examples/door_demo_example/coreconfig/platform.toml
Normal file
@@ -0,0 +1,9 @@
|
||||
[Configuration]
|
||||
Version = 100
|
||||
|
||||
[[Component]]
|
||||
Path = "can_com_sim.sdv"
|
||||
Class = "CAN_Com_Sim"
|
||||
Source="door_example_receiver.asc"
|
||||
Target="door_example_writer.asc"
|
||||
|
||||
28
examples/door_demo_example/coreconfig/settings.toml
Normal file
28
examples/door_demo_example/coreconfig/settings.toml
Normal file
@@ -0,0 +1,28 @@
|
||||
# Settings file
|
||||
[Settings]
|
||||
Version = 100
|
||||
|
||||
# The system config array can contain zero or more configurations that are loaded at the time
|
||||
# the system ist started. It is advisable to split the configurations in:
|
||||
# platform config - containing all the components needed to interact with the OS,
|
||||
# middleware, vehicle bus, Ethernet.
|
||||
# vehicle interface - containing the vehicle bus interpretation components like data link
|
||||
# based on DBC and devices for their abstraction.
|
||||
# vehicle abstraction - containing the basic services
|
||||
# Load the system configurations by providing the "SystemConfig" keyword as an array of strings.
|
||||
# A relative path is relative to the installation directory (being "exe_location/instance_id").
|
||||
#
|
||||
# Example:
|
||||
# SystemConfig = [ "platform.toml", "vehicle_ifc.toml", "vehicle_abstract.toml" ]
|
||||
|
||||
SystemConfig = [ "platform.toml", "vehicle_ifc.toml", "vehicle_abstract.toml"]
|
||||
|
||||
# The application config contains the configuration file that can be updated when services and
|
||||
# apps are being added to the system (or being removed from the system). Load the application
|
||||
# config by providing the "AppConfig" keyword as a string value. A relative path is relative to
|
||||
# the installation directory (being "exe_location/instance_id").
|
||||
#
|
||||
# Example
|
||||
# AppConfig = "app_config.toml"
|
||||
#
|
||||
AppConfig = "door_demo.toml"
|
||||
26
examples/door_demo_example/coreconfig/vehicle_abstract.toml
Normal file
26
examples/door_demo_example/coreconfig/vehicle_abstract.toml
Normal file
@@ -0,0 +1,26 @@
|
||||
[Configuration]
|
||||
Version = 100
|
||||
|
||||
[[Component]]
|
||||
Path = "doors_bs_frontdoorleft.sdv"
|
||||
Class = "Vehicle.Chassis.Door.Axle01.Left_Service"
|
||||
Name = "Vehicle.Chassis.Door.Axle01.Left_Service"
|
||||
|
||||
[[Component]]
|
||||
Path = "doors_bs_frontdoorright.sdv"
|
||||
Class = "Vehicle.Chassis.Door.Axle01.Right_Service"
|
||||
Name = "Vehicle.Chassis.Door.Axle01.Right_Service"
|
||||
|
||||
[[Component]]
|
||||
Path = "doors_bs_reardoorleft.sdv"
|
||||
Class = "Vehicle.Chassis.Door.Axle02.Left_Service"
|
||||
Name = "Vehicle.Chassis.Door.Axle02.Left_Service"
|
||||
|
||||
[[Component]]
|
||||
Path = "doors_bs_reardoorright.sdv"
|
||||
Class = "Vehicle.Chassis.Door.Axle02.Right_Service"
|
||||
Name = "Vehicle.Chassis.Door.Axle02.Right_Service"
|
||||
|
||||
[[Module]]
|
||||
Path = "doors_proxystub.sdv"
|
||||
|
||||
28
examples/door_demo_example/coreconfig/vehicle_ifc.toml
Normal file
28
examples/door_demo_example/coreconfig/vehicle_ifc.toml
Normal file
@@ -0,0 +1,28 @@
|
||||
[Configuration]
|
||||
Version = 100
|
||||
|
||||
[[Component]]
|
||||
Path = "can_dl_door.sdv"
|
||||
Class = "CAN_data_link"
|
||||
Name = "DataLink"
|
||||
[[Component]]
|
||||
Path = "doors_vd_frontdoorleft.sdv"
|
||||
Class = "Vehicle.Chassis.Door.Axle01.Left_Device"
|
||||
Name = "Vehicle.Chassis.Door.Axle01.Left_Device"
|
||||
|
||||
[[Component]]
|
||||
Path = "doors_vd_frontdoorright.sdv"
|
||||
Class = "Vehicle.Chassis.Door.Axle01.Right_Device"
|
||||
Name = "Vehicle.Chassis.Door.Axle01.Right_Device"
|
||||
|
||||
[[Component]]
|
||||
Path = "doors_vd_reardoorleft.sdv"
|
||||
Class = "Vehicle.Chassis.Door.Axle02.Left_Device"
|
||||
Name = "Vehicle.Chassis.Door.Axle02.Left_Device"
|
||||
|
||||
[[Component]]
|
||||
Path = "doors_vd_reardoorright.sdv"
|
||||
Class = "Vehicle.Chassis.Door.Axle02.Right_Device"
|
||||
Name = "Vehicle.Chassis.Door.Axle02.Right_Device"
|
||||
|
||||
|
||||
131
examples/door_demo_example/datalink_2doors_example.dbc
Normal file
131
examples/door_demo_example/datalink_2doors_example.dbc
Normal file
@@ -0,0 +1,131 @@
|
||||
VERSION "PrivateCAN"
|
||||
|
||||
|
||||
NS_ :
|
||||
NS_DESC_
|
||||
CM_
|
||||
BA_DEF_
|
||||
BA_
|
||||
VAL_
|
||||
CAT_DEF_
|
||||
CAT_
|
||||
FILTER
|
||||
BA_DEF_DEF_
|
||||
EV_DATA_
|
||||
ENVVAR_DATA_
|
||||
SGTYPE_
|
||||
SGTYPE_VAL_
|
||||
BA_DEF_SGTYPE_
|
||||
BA_SGTYPE_
|
||||
SIG_TYPE_REF_
|
||||
VAL_TABLE_
|
||||
SIG_GROUP_
|
||||
SIG_VALTYPE_
|
||||
SIGTYPE_VALTYPE_
|
||||
BO_TX_BU_
|
||||
BA_DEF_REL_
|
||||
BA_REL_
|
||||
BA_DEF_DEF_REL_
|
||||
BU_SG_REL_
|
||||
BU_EV_REL_
|
||||
BU_BO_REL_
|
||||
SG_MUL_VAL_
|
||||
|
||||
BS_:
|
||||
|
||||
BU_: doors
|
||||
VAL_TABLE_ Fault_Codes 27 "UKWN" 26 "VEHSPDMAX_EXDD" 25 "STS_ALIVE" 24 "STEER_NOT_E2E_MODE" 23 "OTA_SPD" 22 "OTA_TIMER_DOWNLOAD_FAILED" 21 "OTA_MAX_TIME" 20 "CUBIXAD_STEERSTREQ_NOTACTV" 19 "CUBIXAD_DRVSTREQ_NOTACTV" 18 "SFTYDRV_INTV" 17 "LSDC_ALIVE" 16 "CUBIXAD_ALIVE" 15 "IBC_MAB_NO_PRIO" 14 "IBC_NOT_RDY" 13 "IBC_ALIVE" 12 "LSDC_GEAR" 11 "LSDC_SPD" 10 "LSDC_ACCL" 9 "IBC_NOT_MAB_MOD" 8 "GOLDBOX_ALIVE" 7 "CUBIXAD_GEAR" 6 "CUBIXAD_SPD_TESTTRACK" 5 "DRVREQCHG" 4 "RDY_TIMER" 3 "SFTY_CDN_FAILED" 2 "ACTVNCHK_SPD" 1 "ACTVNCHK_TIMR" 0 "NONE" ;
|
||||
VAL_TABLE_ TestMapID 6 "E_TESTMAPID_UNDEFINED" 5 "E_TESTMAPID_TEST_DRIVE" 4 "E_TESTMAPID_AD_AREA" 3 "E_TESTMAPID_STUTT_ARENA" 2 "E_TESTMAPID_ZF_LASTMILE" 1 "E_TESTMAPID_ZF_TESTTRACK_2" 0 "E_TESTMAPID_NONE" ;
|
||||
VAL_TABLE_ CtrlReqStates 7 "CtrlSts3b_RESERVED_4" 6 "CtrlSts3b_RESERVED_3" 5 "CtrlSts3b_RESERVED_2" 4 "CtrlSts3b_RESERVED_1" 3 "CtrlSts3b_ERROR" 2 "CtrlSts3b_CONTROL_REQUESTED" 1 "CtrlSts3b_CONTROL_NOT_REQUESTED" 0 "CtrlSts3b_INIT" ;
|
||||
VAL_TABLE_ SteerActrReSts 7 "Diag" 6 "Inactive" 5 "Ramping" 4 "Yellow" 3 "Red" 2 "Normal" 1 "Pending" 0 "Initialisation" ;
|
||||
VAL_TABLE_ SwtPark1 1 "SwtParkActv" 0 "SwtParkNotActv" ;
|
||||
VAL_TABLE_ PE_State 2 "ERROR" 1 "INIT" 0 "NO_ERROR" ;
|
||||
VAL_TABLE_ SSM_Req 7 "HMS_TAKEOVER" 6 "RESERVED" 5 "RELESE_VIA_RAMP" 4 "DRIVEOFF" 3 "HOLD_STANDBY" 2 "PARK" 1 "HOLD" 0 "NO_REQUEST" ;
|
||||
VAL_TABLE_ IBC_StandStillMode 12 "SSM_ERROR" 11 "SSM_INIT" 10 "SSM_DRIVEOFF_STANDBY_ACTIVE" 9 "SSM_HOLD_STANDBY_ACTIVE" 8 "SSM_HILL_SLIPPOFF_DETECTED" 7 "SSM_RELEASE_REQ_FROM_DRIVER" 6 "SSM_RELEASE_REQ_ACTIVE" 5 "SSM_DRIVEOFF_ACTIVE" 4 "SSM_PARK_RETAINED_ACTIVE" 3 "SSM_PARK_ACTIVE" 2 "SSM_PARK_REQUESTED" 1 "SSM_HOLD_ACTIVE" 0 "SSM_NO_ACTIVE_FUNCTION" ;
|
||||
VAL_TABLE_ AppTgtStDrv 3 "ACTIVE" 2 "READY" 1 "RESERVED" 0 "NOT_ACTIVE" ;
|
||||
VAL_TABLE_ IBC_Status 4 "IBC_MAB_ERR_COMM" 3 "IBC_MAB_NO_PRIO" 2 "IBC_IN_MAB_MODE" 1 "IBC_READY" 0 "IBC_NOT_READY_FAILED" ;
|
||||
VAL_TABLE_ GearLvrIndcn 7 "GearLvrIndcn2_Undefd" 6 "GearLvrIndcn2_Resd2" 5 "GearLvrIndcn2_Resd1" 4 "GearLvrIndcn2_ManModeIndcn" 3 "GearLvrIndcn2_DrvIndcn" 2 "GearLvrIndcn2_NeutIndcn" 1 "GearLvrIndcn2_RvsIndcn" 0 "GearLvrIndcn2_ParkIndcn" ;
|
||||
VAL_TABLE_ LvlgAdjReq 7 "LvlgAdjReq_Resd2" 6 "LvlgAdjReq_Resd1" 5 "LvlgAdjReq_Ll2" 4 "LvlgAdjReq_Ll1" 3 "LvlgAdjReq_Nrh" 2 "LvlgAdjReq_Hl1" 1 "LvlgAdjReq_Hl2" 0 "LvlgAdjReq_Ukwn" ;
|
||||
VAL_TABLE_ DrvModReq 15 "Err" 14 "Rock" 13 "Mud" 12 "Sand" 11 "Snow" 10 "Power" 9 "Hybrid" 8 "Pure_EV" 7 "Race" 6 "Adaptive" 5 "Offroad_CrossTerrain" 4 "Individual" 3 "Dynamic_Sport" 2 "Comfort_Normal" 1 "ECO" 0 "Undefd" ;
|
||||
VAL_TABLE_ MAB_Info_Message 4 "DRV_GEARLVR_TO_P" 3 "DRV_P_TO_D" 2 "LSDC_DI_NOT_PSBL" 1 "LSDC_ENA_NOT_POSSIBLE" 0 "NONE" ;
|
||||
VAL_TABLE_ MAB_OvrdTool_Sts 11 "HACKATHON" 10 "OTA" 9 "INIT" 8 "FINSHD" 7 "FLT" 6 "CUBIX_AD" 5 "SAVE_THE_SPOILER" 4 "LSDC" 3 "RDY" 2 "ACTVN_CHK" 1 "NO_MANIPULATION" 0 "NONE" ;
|
||||
VAL_TABLE_ HMI_Drvr_Req 9 "FCT_DEACTVN_REQ" 8 "FCT_ACTVN_OTA_CFMD" 7 "FCT_ACTVN_OTA_REQ" 6 "FCT_ACTVN_SAVETHESPOILER_CFMD" 5 "FCT_ACTVN_SAVETHESPOILER_REQ" 4 "FCT_ACTVN_LSDC_CFMD" 3 "FCT_ACTVN_LSDC_REQ" 2 "FCT_ACTVN_CUBIXAD_CFMD" 1 "FCT_ACTVN_CUBIXAD_REQ" 0 "FCT_ACTVN_NONE" ;
|
||||
VAL_TABLE_ Info_Message 4 "DRV_GEARLVR_TO_P" 3 "DRV_P_TO_D" 2 "LSDC_DI_NOT_PSBL" 1 "LSDC_ENA_NOT_POSSIBLE" 0 "NONE" ;
|
||||
VAL_TABLE_ HMI_Fct_Req 8 "FCT_DEACTVN_REQ" 7 "FCT_ACTVN_OTA_REQ" 6 "FCT_ACTVN_SAVETHESPOILER_CFMD" 5 "FCT_ACTVN_SAVETHESPOILER_REQ" 4 "FCT_ACTVN_LSDC_CFMD" 3 "FCT_ACTVN_LSDC_REQ" 2 "FCT_ACTVN_AI4MTN_CFMD" 1 "FCT_ACTVN_AI4MTN_REQ" 0 "FCT_ACTVN_NONE" ;
|
||||
VAL_TABLE_ SOVD_states 2 "SOVD_SHOWCASE_ACTIVE" 1 "SOVD_SHOWCASE_DEACTIVE" 0 "SOVD_NONE" ;
|
||||
VAL_TABLE_ OTA_states 7 "OTA_DOWNLOAD_FAILED" 6 "OTA_INSTALL_FAILED" 5 "OTA_INSTALL_FINISHED" 4 "OTA_INSTALL_START" 3 "OTA_DOWNLOAD_START" 2 "OTA_SCHEDULED" 1 "OTA_STANDBY" 0 "OTA_NONE" ;
|
||||
|
||||
|
||||
BO_ 2 CAN_Input_R1: 1 Vector__XXX
|
||||
SG_ Door01RightIsOpen : 3|1@0+ (1,0) [0|1] "" doors
|
||||
|
||||
BO_ 1 CAN_Input_L1: 1 Vector__XXX
|
||||
SG_ Door01LeftIsOpen : 1|1@0+ (1,0) [0|1] "" doors
|
||||
|
||||
BO_ 5 CAN_Output: 1 doors
|
||||
SG_ LockDoor01Right : 3|1@0+ (1,0) [0|1] "" Vector__XXX
|
||||
SG_ LockDoor01Left : 1|1@0+ (1,0) [0|1] "" Vector__XXX
|
||||
|
||||
|
||||
|
||||
CM_ SG_ 2 Door01RightIsOpen "Open / Closed signal of front right door";
|
||||
CM_ SG_ 1 Door01LeftIsOpen "Open / Closed signal of front left door";
|
||||
CM_ SG_ 5 LockDoor01Right "Lock / Unlock signal of front right door";
|
||||
CM_ SG_ 5 LockDoor01Left "Lock / Unlock signal of front left door";
|
||||
BA_DEF_ "Baudrate" INT 1000 1000000;
|
||||
BA_DEF_ "BusType" STRING ;
|
||||
BA_DEF_ "DBName" STRING ;
|
||||
BA_DEF_ "ProtocolType" STRING ;
|
||||
BA_DEF_ BU_ "NmAsrNode" ENUM "No","Yes";
|
||||
BA_DEF_ BU_ "NmAsrNodeIdentifier" INT 0 255;
|
||||
BA_DEF_ BO_ "GenMsgCycleTime" INT 0 65536;
|
||||
BA_DEF_ BO_ "GenMsgCycleTimeFast" FLOAT 0 300000;
|
||||
BA_DEF_ BO_ "GenMsgDelayTime" INT 0 65536;
|
||||
BA_DEF_ BO_ "GenMsgNrOfRepetition" INT 0 100000;
|
||||
BA_DEF_ BO_ "GenMsgSendType" ENUM "cyclic","spontaneous","not-used","not-used","not-used","cyclicAndSpontaneous","not-used","cyclicIfActive","NoMsgSendType";
|
||||
BA_DEF_ BO_ "GenMsgStartDelayTime" INT 0 65536;
|
||||
BA_DEF_ SG_ "GenSigSendType" ENUM "Cyclic","OnWrite","OnWriteWithRepetition","OnChange","OnChangeWithRepetition","IfActive","IfActiveWithRepetition","NoSigSendType";
|
||||
BA_DEF_ SG_ "GenSigStartValue" HEX 0 80000000;
|
||||
BA_DEF_ BO_ "GenMsgILSupport" ENUM "No","Yes";
|
||||
BA_DEF_ BO_ "NmAsrMessage" ENUM "No","Yes";
|
||||
BA_DEF_ "NmAsrBaseAddress" HEX 0 536870911;
|
||||
BA_DEF_ "NmAsrMessageCount" INT 0 255;
|
||||
BA_DEF_ BU_ "NodeLayerModules" STRING ;
|
||||
BA_DEF_ BU_ "ILused" ENUM "No","Yes";
|
||||
BA_DEF_ SG_ "GenSigFuncType" ENUM "NoFunction","n/a","n/a","n/a","n/a","n/a","n/a","n/a","n/a","n/a","n/a","n/a","n/a","n/a","n/a","CHK","CNTR","n/a","n/a","n/a","CNTR_AR_01","CRC_AR_01_BOTH","CRC_AR_01_ALT","CRC_AR_01_LOW","CRC_AR_01_NIBBLE","CNTR_AR_04","CRC_AR_04A","CNTR_AR_05","CRC_AR_05";
|
||||
BA_DEF_ SG_ "GenSigDataID" STRING ;
|
||||
BA_DEF_ SG_ "SigGroup" STRING ;
|
||||
BA_DEF_DEF_ "Baudrate" 1000;
|
||||
BA_DEF_DEF_ "BusType" "";
|
||||
BA_DEF_DEF_ "DBName" "";
|
||||
BA_DEF_DEF_ "ProtocolType" "";
|
||||
BA_DEF_DEF_ "NmAsrNode" "No";
|
||||
BA_DEF_DEF_ "NmAsrNodeIdentifier" 0;
|
||||
BA_DEF_DEF_ "GenMsgCycleTime" 0;
|
||||
BA_DEF_DEF_ "GenMsgCycleTimeFast" 0;
|
||||
BA_DEF_DEF_ "GenMsgDelayTime" 0;
|
||||
BA_DEF_DEF_ "GenMsgNrOfRepetition" 0;
|
||||
BA_DEF_DEF_ "GenMsgSendType" "NoMsgSendType";
|
||||
BA_DEF_DEF_ "GenMsgStartDelayTime" 0;
|
||||
BA_DEF_DEF_ "GenSigSendType" "NoSigSendType";
|
||||
BA_DEF_DEF_ "GenSigStartValue" 0;
|
||||
BA_DEF_DEF_ "GenMsgILSupport" "Yes";
|
||||
BA_DEF_DEF_ "NmAsrMessage" "No";
|
||||
BA_DEF_DEF_ "NmAsrBaseAddress" 1280;
|
||||
BA_DEF_DEF_ "NmAsrMessageCount" 64;
|
||||
BA_DEF_DEF_ "NodeLayerModules" "CANoeILNLSPA.dll";
|
||||
BA_DEF_DEF_ "ILused" "Yes";
|
||||
BA_DEF_DEF_ "GenSigFuncType" "NoFunction";
|
||||
BA_DEF_DEF_ "GenSigDataID" "";
|
||||
BA_DEF_DEF_ "SigGroup" "";
|
||||
BA_ "ProtocolType" "CAN";
|
||||
BA_ "BusType" "CAN";
|
||||
BA_ "Baudrate" 500000;
|
||||
BA_ "DBName" "PrivateCAN";
|
||||
BA_ "GenMsgCycleTime" BO_ 2 10;
|
||||
BA_ "GenMsgSendType" BO_ 2 0;
|
||||
BA_ "GenMsgSendType" BO_ 1 0;
|
||||
BA_ "GenMsgCycleTime" BO_ 1 10;
|
||||
BA_ "GenMsgSendType" BO_ 5 0;
|
||||
BA_ "GenMsgCycleTime" BO_ 5 10;
|
||||
|
||||
147
examples/door_demo_example/datalink_4doors_example.dbc
Normal file
147
examples/door_demo_example/datalink_4doors_example.dbc
Normal file
@@ -0,0 +1,147 @@
|
||||
VERSION "PrivateCAN"
|
||||
|
||||
|
||||
NS_ :
|
||||
NS_DESC_
|
||||
CM_
|
||||
BA_DEF_
|
||||
BA_
|
||||
VAL_
|
||||
CAT_DEF_
|
||||
CAT_
|
||||
FILTER
|
||||
BA_DEF_DEF_
|
||||
EV_DATA_
|
||||
ENVVAR_DATA_
|
||||
SGTYPE_
|
||||
SGTYPE_VAL_
|
||||
BA_DEF_SGTYPE_
|
||||
BA_SGTYPE_
|
||||
SIG_TYPE_REF_
|
||||
VAL_TABLE_
|
||||
SIG_GROUP_
|
||||
SIG_VALTYPE_
|
||||
SIGTYPE_VALTYPE_
|
||||
BO_TX_BU_
|
||||
BA_DEF_REL_
|
||||
BA_REL_
|
||||
BA_DEF_DEF_REL_
|
||||
BU_SG_REL_
|
||||
BU_EV_REL_
|
||||
BU_BO_REL_
|
||||
SG_MUL_VAL_
|
||||
|
||||
BS_:
|
||||
|
||||
BU_: doors
|
||||
VAL_TABLE_ Fault_Codes 27 "UKWN" 26 "VEHSPDMAX_EXDD" 25 "STS_ALIVE" 24 "STEER_NOT_E2E_MODE" 23 "OTA_SPD" 22 "OTA_TIMER_DOWNLOAD_FAILED" 21 "OTA_MAX_TIME" 20 "CUBIXAD_STEERSTREQ_NOTACTV" 19 "CUBIXAD_DRVSTREQ_NOTACTV" 18 "SFTYDRV_INTV" 17 "LSDC_ALIVE" 16 "CUBIXAD_ALIVE" 15 "IBC_MAB_NO_PRIO" 14 "IBC_NOT_RDY" 13 "IBC_ALIVE" 12 "LSDC_GEAR" 11 "LSDC_SPD" 10 "LSDC_ACCL" 9 "IBC_NOT_MAB_MOD" 8 "GOLDBOX_ALIVE" 7 "CUBIXAD_GEAR" 6 "CUBIXAD_SPD_TESTTRACK" 5 "DRVREQCHG" 4 "RDY_TIMER" 3 "SFTY_CDN_FAILED" 2 "ACTVNCHK_SPD" 1 "ACTVNCHK_TIMR" 0 "NONE" ;
|
||||
VAL_TABLE_ TestMapID 6 "E_TESTMAPID_UNDEFINED" 5 "E_TESTMAPID_TEST_DRIVE" 4 "E_TESTMAPID_AD_AREA" 3 "E_TESTMAPID_STUTT_ARENA" 2 "E_TESTMAPID_ZF_LASTMILE" 1 "E_TESTMAPID_ZF_TESTTRACK_2" 0 "E_TESTMAPID_NONE" ;
|
||||
VAL_TABLE_ CtrlReqStates 7 "CtrlSts3b_RESERVED_4" 6 "CtrlSts3b_RESERVED_3" 5 "CtrlSts3b_RESERVED_2" 4 "CtrlSts3b_RESERVED_1" 3 "CtrlSts3b_ERROR" 2 "CtrlSts3b_CONTROL_REQUESTED" 1 "CtrlSts3b_CONTROL_NOT_REQUESTED" 0 "CtrlSts3b_INIT" ;
|
||||
VAL_TABLE_ SteerActrReSts 7 "Diag" 6 "Inactive" 5 "Ramping" 4 "Yellow" 3 "Red" 2 "Normal" 1 "Pending" 0 "Initialisation" ;
|
||||
VAL_TABLE_ SwtPark1 1 "SwtParkActv" 0 "SwtParkNotActv" ;
|
||||
VAL_TABLE_ PE_State 2 "ERROR" 1 "INIT" 0 "NO_ERROR" ;
|
||||
VAL_TABLE_ SSM_Req 7 "HMS_TAKEOVER" 6 "RESERVED" 5 "RELESE_VIA_RAMP" 4 "DRIVEOFF" 3 "HOLD_STANDBY" 2 "PARK" 1 "HOLD" 0 "NO_REQUEST" ;
|
||||
VAL_TABLE_ IBC_StandStillMode 12 "SSM_ERROR" 11 "SSM_INIT" 10 "SSM_DRIVEOFF_STANDBY_ACTIVE" 9 "SSM_HOLD_STANDBY_ACTIVE" 8 "SSM_HILL_SLIPPOFF_DETECTED" 7 "SSM_RELEASE_REQ_FROM_DRIVER" 6 "SSM_RELEASE_REQ_ACTIVE" 5 "SSM_DRIVEOFF_ACTIVE" 4 "SSM_PARK_RETAINED_ACTIVE" 3 "SSM_PARK_ACTIVE" 2 "SSM_PARK_REQUESTED" 1 "SSM_HOLD_ACTIVE" 0 "SSM_NO_ACTIVE_FUNCTION" ;
|
||||
VAL_TABLE_ AppTgtStDrv 3 "ACTIVE" 2 "READY" 1 "RESERVED" 0 "NOT_ACTIVE" ;
|
||||
VAL_TABLE_ IBC_Status 4 "IBC_MAB_ERR_COMM" 3 "IBC_MAB_NO_PRIO" 2 "IBC_IN_MAB_MODE" 1 "IBC_READY" 0 "IBC_NOT_READY_FAILED" ;
|
||||
VAL_TABLE_ GearLvrIndcn 7 "GearLvrIndcn2_Undefd" 6 "GearLvrIndcn2_Resd2" 5 "GearLvrIndcn2_Resd1" 4 "GearLvrIndcn2_ManModeIndcn" 3 "GearLvrIndcn2_DrvIndcn" 2 "GearLvrIndcn2_NeutIndcn" 1 "GearLvrIndcn2_RvsIndcn" 0 "GearLvrIndcn2_ParkIndcn" ;
|
||||
VAL_TABLE_ LvlgAdjReq 7 "LvlgAdjReq_Resd2" 6 "LvlgAdjReq_Resd1" 5 "LvlgAdjReq_Ll2" 4 "LvlgAdjReq_Ll1" 3 "LvlgAdjReq_Nrh" 2 "LvlgAdjReq_Hl1" 1 "LvlgAdjReq_Hl2" 0 "LvlgAdjReq_Ukwn" ;
|
||||
VAL_TABLE_ DrvModReq 15 "Err" 14 "Rock" 13 "Mud" 12 "Sand" 11 "Snow" 10 "Power" 9 "Hybrid" 8 "Pure_EV" 7 "Race" 6 "Adaptive" 5 "Offroad_CrossTerrain" 4 "Individual" 3 "Dynamic_Sport" 2 "Comfort_Normal" 1 "ECO" 0 "Undefd" ;
|
||||
VAL_TABLE_ MAB_Info_Message 4 "DRV_GEARLVR_TO_P" 3 "DRV_P_TO_D" 2 "LSDC_DI_NOT_PSBL" 1 "LSDC_ENA_NOT_POSSIBLE" 0 "NONE" ;
|
||||
VAL_TABLE_ MAB_OvrdTool_Sts 11 "HACKATHON" 10 "OTA" 9 "INIT" 8 "FINSHD" 7 "FLT" 6 "CUBIX_AD" 5 "SAVE_THE_SPOILER" 4 "LSDC" 3 "RDY" 2 "ACTVN_CHK" 1 "NO_MANIPULATION" 0 "NONE" ;
|
||||
VAL_TABLE_ HMI_Drvr_Req 9 "FCT_DEACTVN_REQ" 8 "FCT_ACTVN_OTA_CFMD" 7 "FCT_ACTVN_OTA_REQ" 6 "FCT_ACTVN_SAVETHESPOILER_CFMD" 5 "FCT_ACTVN_SAVETHESPOILER_REQ" 4 "FCT_ACTVN_LSDC_CFMD" 3 "FCT_ACTVN_LSDC_REQ" 2 "FCT_ACTVN_CUBIXAD_CFMD" 1 "FCT_ACTVN_CUBIXAD_REQ" 0 "FCT_ACTVN_NONE" ;
|
||||
VAL_TABLE_ Info_Message 4 "DRV_GEARLVR_TO_P" 3 "DRV_P_TO_D" 2 "LSDC_DI_NOT_PSBL" 1 "LSDC_ENA_NOT_POSSIBLE" 0 "NONE" ;
|
||||
VAL_TABLE_ HMI_Fct_Req 8 "FCT_DEACTVN_REQ" 7 "FCT_ACTVN_OTA_REQ" 6 "FCT_ACTVN_SAVETHESPOILER_CFMD" 5 "FCT_ACTVN_SAVETHESPOILER_REQ" 4 "FCT_ACTVN_LSDC_CFMD" 3 "FCT_ACTVN_LSDC_REQ" 2 "FCT_ACTVN_AI4MTN_CFMD" 1 "FCT_ACTVN_AI4MTN_REQ" 0 "FCT_ACTVN_NONE" ;
|
||||
VAL_TABLE_ SOVD_states 2 "SOVD_SHOWCASE_ACTIVE" 1 "SOVD_SHOWCASE_DEACTIVE" 0 "SOVD_NONE" ;
|
||||
VAL_TABLE_ OTA_states 7 "OTA_DOWNLOAD_FAILED" 6 "OTA_INSTALL_FAILED" 5 "OTA_INSTALL_FINISHED" 4 "OTA_INSTALL_START" 3 "OTA_DOWNLOAD_START" 2 "OTA_SCHEDULED" 1 "OTA_STANDBY" 0 "OTA_NONE" ;
|
||||
|
||||
|
||||
BO_ 4 CAN_Input_R2: 1 Vector__XXX
|
||||
SG_ Door02RightIsOpen : 7|1@0+ (1,0) [0|1] "" doors
|
||||
|
||||
BO_ 3 CAN_Input_L2: 1 Vector__XXX
|
||||
SG_ Door02LeftIsOpen : 5|1@0+ (1,0) [0|1] "" doors
|
||||
|
||||
BO_ 2 CAN_Input_R1: 1 Vector__XXX
|
||||
SG_ Door01RightIsOpen : 3|1@0+ (1,0) [0|1] "" doors
|
||||
|
||||
BO_ 1 CAN_Input_L1: 1 Vector__XXX
|
||||
SG_ Door01LeftIsOpen : 1|1@0+ (1,0) [0|1] "" doors
|
||||
|
||||
BO_ 5 CAN_Output: 1 doors
|
||||
SG_ LockDoor02Right : 7|1@0+ (1,0) [0|1] "" Vector__XXX
|
||||
SG_ LockDoor02Left : 5|1@0+ (1,0) [0|1] "" Vector__XXX
|
||||
SG_ LockDoor01Right : 3|1@0+ (1,0) [0|1] "" Vector__XXX
|
||||
SG_ LockDoor01Left : 1|1@0+ (1,0) [0|1] "" Vector__XXX
|
||||
|
||||
|
||||
|
||||
CM_ SG_ 4 Door02RightIsOpen "Open / Closed signal of rear right door";
|
||||
CM_ SG_ 3 Door02LeftIsOpen "Open / Closed signal of rear left door";
|
||||
CM_ SG_ 2 Door01RightIsOpen "Open / Closed signal of front right door";
|
||||
CM_ SG_ 1 Door01LeftIsOpen "Open / Closed signal of front left door";
|
||||
CM_ SG_ 5 LockDoor02Right "Lock / Unlock signal of rear right door";
|
||||
CM_ SG_ 5 LockDoor02Left "Lock / Unlock signal of frear left door";
|
||||
CM_ SG_ 5 LockDoor01Right "Lock / Unlock signal of front right door";
|
||||
CM_ SG_ 5 LockDoor01Left "Lock / Unlock signal of front left door";
|
||||
BA_DEF_ "Baudrate" INT 1000 1000000;
|
||||
BA_DEF_ "BusType" STRING ;
|
||||
BA_DEF_ "DBName" STRING ;
|
||||
BA_DEF_ "ProtocolType" STRING ;
|
||||
BA_DEF_ BU_ "NmAsrNode" ENUM "No","Yes";
|
||||
BA_DEF_ BU_ "NmAsrNodeIdentifier" INT 0 255;
|
||||
BA_DEF_ BO_ "GenMsgCycleTime" INT 0 65536;
|
||||
BA_DEF_ BO_ "GenMsgCycleTimeFast" FLOAT 0 300000;
|
||||
BA_DEF_ BO_ "GenMsgDelayTime" INT 0 65536;
|
||||
BA_DEF_ BO_ "GenMsgNrOfRepetition" INT 0 100000;
|
||||
BA_DEF_ BO_ "GenMsgSendType" ENUM "cyclic","spontaneous","not-used","not-used","not-used","cyclicAndSpontaneous","not-used","cyclicIfActive","NoMsgSendType";
|
||||
BA_DEF_ BO_ "GenMsgStartDelayTime" INT 0 65536;
|
||||
BA_DEF_ SG_ "GenSigSendType" ENUM "Cyclic","OnWrite","OnWriteWithRepetition","OnChange","OnChangeWithRepetition","IfActive","IfActiveWithRepetition","NoSigSendType";
|
||||
BA_DEF_ SG_ "GenSigStartValue" HEX 0 80000000;
|
||||
BA_DEF_ BO_ "GenMsgILSupport" ENUM "No","Yes";
|
||||
BA_DEF_ BO_ "NmAsrMessage" ENUM "No","Yes";
|
||||
BA_DEF_ "NmAsrBaseAddress" HEX 0 536870911;
|
||||
BA_DEF_ "NmAsrMessageCount" INT 0 255;
|
||||
BA_DEF_ BU_ "NodeLayerModules" STRING ;
|
||||
BA_DEF_ BU_ "ILused" ENUM "No","Yes";
|
||||
BA_DEF_ SG_ "GenSigFuncType" ENUM "NoFunction","n/a","n/a","n/a","n/a","n/a","n/a","n/a","n/a","n/a","n/a","n/a","n/a","n/a","n/a","CHK","CNTR","n/a","n/a","n/a","CNTR_AR_01","CRC_AR_01_BOTH","CRC_AR_01_ALT","CRC_AR_01_LOW","CRC_AR_01_NIBBLE","CNTR_AR_04","CRC_AR_04A","CNTR_AR_05","CRC_AR_05";
|
||||
BA_DEF_ SG_ "GenSigDataID" STRING ;
|
||||
BA_DEF_ SG_ "SigGroup" STRING ;
|
||||
BA_DEF_DEF_ "Baudrate" 1000;
|
||||
BA_DEF_DEF_ "BusType" "";
|
||||
BA_DEF_DEF_ "DBName" "";
|
||||
BA_DEF_DEF_ "ProtocolType" "";
|
||||
BA_DEF_DEF_ "NmAsrNode" "No";
|
||||
BA_DEF_DEF_ "NmAsrNodeIdentifier" 0;
|
||||
BA_DEF_DEF_ "GenMsgCycleTime" 0;
|
||||
BA_DEF_DEF_ "GenMsgCycleTimeFast" 0;
|
||||
BA_DEF_DEF_ "GenMsgDelayTime" 0;
|
||||
BA_DEF_DEF_ "GenMsgNrOfRepetition" 0;
|
||||
BA_DEF_DEF_ "GenMsgSendType" "NoMsgSendType";
|
||||
BA_DEF_DEF_ "GenMsgStartDelayTime" 0;
|
||||
BA_DEF_DEF_ "GenSigSendType" "NoSigSendType";
|
||||
BA_DEF_DEF_ "GenSigStartValue" 0;
|
||||
BA_DEF_DEF_ "GenMsgILSupport" "Yes";
|
||||
BA_DEF_DEF_ "NmAsrMessage" "No";
|
||||
BA_DEF_DEF_ "NmAsrBaseAddress" 1280;
|
||||
BA_DEF_DEF_ "NmAsrMessageCount" 64;
|
||||
BA_DEF_DEF_ "NodeLayerModules" "CANoeILNLSPA.dll";
|
||||
BA_DEF_DEF_ "ILused" "Yes";
|
||||
BA_DEF_DEF_ "GenSigFuncType" "NoFunction";
|
||||
BA_DEF_DEF_ "GenSigDataID" "";
|
||||
BA_DEF_DEF_ "SigGroup" "";
|
||||
BA_ "ProtocolType" "CAN";
|
||||
BA_ "BusType" "CAN";
|
||||
BA_ "Baudrate" 500000;
|
||||
BA_ "DBName" "PrivateCAN";
|
||||
BA_ "GenMsgCycleTime" BO_ 4 10;
|
||||
BA_ "GenMsgSendType" BO_ 4 0;
|
||||
BA_ "GenMsgCycleTime" BO_ 3 10;
|
||||
BA_ "GenMsgSendType" BO_ 3 0;
|
||||
BA_ "GenMsgCycleTime" BO_ 2 10;
|
||||
BA_ "GenMsgSendType" BO_ 2 0;
|
||||
BA_ "GenMsgSendType" BO_ 1 0;
|
||||
BA_ "GenMsgCycleTime" BO_ 1 10;
|
||||
BA_ "GenMsgSendType" BO_ 5 0;
|
||||
BA_ "GenMsgCycleTime" BO_ 5 10;
|
||||
|
||||
448
examples/door_demo_example/door_app/console.cpp
Normal file
448
examples/door_demo_example/door_app/console.cpp
Normal file
@@ -0,0 +1,448 @@
|
||||
#include "include/console.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <conio.h> // Needed for _kbhit
|
||||
#else
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
const CConsole::SConsolePos g_sTitle{ 1, 1 };
|
||||
const CConsole::SConsolePos g_sSubTitle{ 2, 1 };
|
||||
const CConsole::SConsolePos g_sSeparator11{ 4, 1 };
|
||||
const CConsole::SConsolePos g_sSeparator12{ 6, 1 };
|
||||
const CConsole::SConsolePos g_sFrontLeftDoorIsOpen{ 7, 1 };
|
||||
const CConsole::SConsolePos g_sFrontRightDoorIsOpen{ 8, 1 };
|
||||
const CConsole::SConsolePos g_sRearLeftDoorIsOpen{ 9, 1 };
|
||||
const CConsole::SConsolePos g_sRearRightDoorIsOpen{ 10, 1 };
|
||||
const CConsole::SConsolePos g_sFrontLeftDoorIsLocked{ 7, 42 };
|
||||
const CConsole::SConsolePos g_sFrontRightDoorIsLocked{ 8, 42 };
|
||||
const CConsole::SConsolePos g_sRearLeftDoorIsLocked{ 9, 42 };
|
||||
const CConsole::SConsolePos g_sRearRightDoorIsLocked{ 10, 42 };
|
||||
const CConsole::SConsolePos g_sSeparator21{ 12, 1 };
|
||||
const CConsole::SConsolePos g_sSeparator22{ 14, 1 };
|
||||
const CConsole::SConsolePos g_sVehicleDevice{ 15, 1 };
|
||||
const CConsole::SConsolePos g_sSeparator31{ 17, 1 };
|
||||
const CConsole::SConsolePos g_sSeparator32{ 19, 1 };
|
||||
const CConsole::SConsolePos g_sBasicServiceL1{ 20, 1 };
|
||||
const CConsole::SConsolePos g_sBasicServiceR1{ 21, 1 };
|
||||
const CConsole::SConsolePos g_sBasicServiceL2{ 22, 1 };
|
||||
const CConsole::SConsolePos g_sBasicServiceR2{ 23, 1 };
|
||||
const CConsole::SConsolePos g_sSeparator41{ 25, 1 };
|
||||
const CConsole::SConsolePos g_sSeparator42{ 26, 1 };
|
||||
const CConsole::SConsolePos g_sComplexService{ 27, 1 };
|
||||
const CConsole::SConsolePos g_sControlDescription{ 29, 1 };
|
||||
const CConsole::SConsolePos g_sCursor{ 30, 1 };
|
||||
|
||||
CConsole::CConsole()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
// Enable ANSI escape codes
|
||||
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
if (hStdOut != INVALID_HANDLE_VALUE && GetConsoleMode(hStdOut, &m_dwConsoleOutMode))
|
||||
SetConsoleMode(hStdOut, m_dwConsoleOutMode | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
|
||||
HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE);
|
||||
if (hStdIn != INVALID_HANDLE_VALUE && GetConsoleMode(hStdIn, &m_dwConsoleInMode))
|
||||
SetConsoleMode(hStdIn, m_dwConsoleInMode & ~(ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT));
|
||||
#elif defined __unix__
|
||||
// Disable echo
|
||||
tcgetattr(STDIN_FILENO, &m_sTermAttr);
|
||||
struct termios sTermAttrTemp = m_sTermAttr;
|
||||
sTermAttrTemp.c_lflag &= ~(ICANON | ECHO);
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &sTermAttrTemp);
|
||||
m_iFileStatus = fcntl(STDIN_FILENO, F_GETFL, 0);
|
||||
fcntl(STDIN_FILENO, F_SETFL, m_iFileStatus | O_NONBLOCK);
|
||||
#else
|
||||
#error The OS is not supported!
|
||||
#endif
|
||||
}
|
||||
|
||||
CConsole::~CConsole()
|
||||
{
|
||||
SetCursorPos(g_sCursor);
|
||||
|
||||
#ifdef _WIN32
|
||||
// Return to the stored console mode
|
||||
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
if (hStdOut != INVALID_HANDLE_VALUE)
|
||||
SetConsoleMode(hStdOut, m_dwConsoleOutMode);
|
||||
HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE);
|
||||
if (hStdIn != INVALID_HANDLE_VALUE)
|
||||
SetConsoleMode(hStdIn, m_dwConsoleInMode);
|
||||
#elif defined __unix__
|
||||
// Return the previous file status flags.
|
||||
fcntl(STDIN_FILENO, F_SETFL, m_iFileStatus);
|
||||
|
||||
// Return to previous terminal state
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &m_sTermAttr);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CConsole::PrintHeader(const uint32_t numberOfDoors)
|
||||
{
|
||||
// Clear the screen...
|
||||
std::cout << "\x1b[2J";
|
||||
|
||||
std::string title = "Door demo example: Data link attached (4 doors) ";
|
||||
if (numberOfDoors <= 4)
|
||||
{
|
||||
title = "Door demo example: Vehicle has ";
|
||||
title.append(std::to_string(numberOfDoors));
|
||||
title.append(" doors.");
|
||||
}
|
||||
|
||||
// Print the titles
|
||||
PrintText(g_sTitle, title.c_str());
|
||||
PrintText(g_sSubTitle, " Doors are locked automatically after 2 seconds when all doors are closed.");
|
||||
PrintText(g_sSeparator11, "============================================================================");
|
||||
PrintText(g_sSeparator12, "Data dispatch service:");
|
||||
PrintText(g_sFrontLeftDoorIsOpen, "Front Left Door:.. not available");
|
||||
PrintText(g_sFrontRightDoorIsOpen, "Front Right Door:.. not available");
|
||||
PrintText(g_sRearLeftDoorIsOpen, "Rear Left Door:.. not available");
|
||||
PrintText(g_sRearRightDoorIsOpen, "Rear Right Door:.. not available");
|
||||
PrintText(g_sSeparator21, "----------------------------------------------------------------------------");
|
||||
PrintText(g_sSeparator22, "Vehicle device:");
|
||||
PrintText(g_sVehicleDevice, "Vehicle Device Interface not available.");
|
||||
PrintText(g_sSeparator31, "----------------------------------------------------------------------------");
|
||||
PrintText(g_sSeparator32, "Basic services:");
|
||||
PrintText(g_sBasicServiceL1, "Basic Service Interface not available.");
|
||||
PrintText(g_sSeparator41, "----------------------------------------------------------------------------");
|
||||
PrintText(g_sSeparator42, "Complex service:");
|
||||
PrintText(g_sComplexService, "Complex Service Interface not available.");
|
||||
if (!m_isExternalApp)
|
||||
{
|
||||
PrintText(g_sControlDescription, "Press 'X' to quit; '1', '2', '3', '4' to toggle doors...");
|
||||
}
|
||||
else
|
||||
{
|
||||
title.append(" [Connected to an instance]");
|
||||
PrintText(g_sTitle, title.c_str());
|
||||
PrintText(g_sControlDescription, "Press 'X' to quit; Doors are toggled automatically");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool CConsole::PrepareDataConsumers()
|
||||
{
|
||||
if (!m_isExternalApp)
|
||||
{
|
||||
if(!(PrepareDataConsumersForStandAlone()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
auto basicServiceL1 = sdv::core::GetObject("Vehicle.Chassis.Door.Axle01.Left_Service").GetInterface<vss::Vehicle::Chassis::Door::Axle01::LeftService::IVSS_GetIsOpen>();
|
||||
if (!basicServiceL1)
|
||||
{
|
||||
SDV_LOG_ERROR("Could not get interface 'LeftService::IVSS_IsOpen': [CConsole]");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Interface exists -> Clean the line for Console window */
|
||||
PrintText(g_sBasicServiceL1, " ");
|
||||
}
|
||||
basicServiceL1->RegisterOnSignalChangeOfLeftDoorIsOpen01(dynamic_cast<vss::Vehicle::Chassis::Door::Axle01::LeftService::IVSS_SetIsOpen_Event*> (this));
|
||||
bool value = false;
|
||||
PrintValue(g_sFrontLeftDoorIsLocked, "Front Left Latch:", value, (value ? "locked" : "unlocked"));
|
||||
|
||||
// all other doors are optional
|
||||
auto basicServiceR1 = sdv::core::GetObject("Vehicle.Chassis.Door.Axle01.Right_Service").GetInterface<vss::Vehicle::Chassis::Door::Axle01::RightService::IVSS_GetIsOpen>();
|
||||
if (basicServiceR1)
|
||||
{
|
||||
basicServiceR1->RegisterOnSignalChangeOfRightDoorIsOpen01(dynamic_cast<vss::Vehicle::Chassis::Door::Axle01::RightService::IVSS_SetIsOpen_Event*> (this));
|
||||
PrintValue(g_sFrontRightDoorIsLocked, "Front Right Latch:", value, (value ? "locked" : "unlocked"));
|
||||
}
|
||||
|
||||
auto basicServiceL2 = sdv::core::GetObject("Vehicle.Chassis.Door.Axle02.Left_Service").GetInterface<vss::Vehicle::Chassis::Door::Axle02::LeftService::IVSS_GetIsOpen>();
|
||||
if (basicServiceL2)
|
||||
{
|
||||
basicServiceL2->RegisterOnSignalChangeOfLeftDoorIsOpen02(dynamic_cast<vss::Vehicle::Chassis::Door::Axle02::LeftService::IVSS_SetIsOpen_Event*> (this));
|
||||
PrintValue(g_sRearLeftDoorIsLocked, "Rear Left Latch:", value, (value ? "locked" : "unlocked"));
|
||||
}
|
||||
|
||||
auto basicServiceR2 = sdv::core::GetObject("Vehicle.Chassis.Door.Axle02.Right_Service").GetInterface<vss::Vehicle::Chassis::Door::Axle02::RightService::IVSS_GetIsOpen>();
|
||||
if (basicServiceR2)
|
||||
{
|
||||
basicServiceR2->RegisterOnSignalChangeOfRightDoorIsOpen02(dynamic_cast<vss::Vehicle::Chassis::Door::Axle02::RightService::IVSS_SetIsOpen_Event*> (this));
|
||||
PrintValue(g_sRearRightDoorIsLocked, "Rear Right Latch:", value, (value ? "locked" : "unlocked"));
|
||||
}
|
||||
|
||||
m_pDoorService = sdv::core::GetObject("Doors Example Service").GetInterface<IDoorService>();
|
||||
if (!m_pDoorService)
|
||||
{
|
||||
SDV_LOG_ERROR("Console ERROR: Could not get complex service interface 'IDoorService'");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_isExternalApp)
|
||||
{
|
||||
PrintText(g_sFrontLeftDoorIsLocked, " ");
|
||||
PrintText(g_sFrontRightDoorIsLocked, " ");
|
||||
PrintText(g_sRearLeftDoorIsLocked, " ");
|
||||
PrintText(g_sRearRightDoorIsLocked, " ");
|
||||
PrintText(g_sFrontLeftDoorIsOpen, "External Application, no dispatch service.");
|
||||
PrintText(g_sFrontRightDoorIsOpen, " ");
|
||||
PrintText(g_sRearLeftDoorIsOpen, " ");
|
||||
PrintText(g_sRearRightDoorIsOpen, " ");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CConsole::ResetSignals()
|
||||
{
|
||||
// Set the cursor position at the end
|
||||
SetCursorPos(g_sCursor);
|
||||
|
||||
// Registrate for the vehicle device & basic service of the front left door. Front left door mzust exist, the others are optional
|
||||
auto vehicleDevice = sdv::core::GetObject("Vehicle.Chassis.Door.Axle01.Left_Device").GetInterface<vss::Vehicle::Chassis::Door::Axle01::LeftDevice::IVSS_IsOpen>();
|
||||
if (vehicleDevice)
|
||||
vehicleDevice->UnregisterIsOpenEvent(dynamic_cast<vss::Vehicle::Chassis::Door::Axle01::LeftDevice::IVSS_WriteIsOpen_Event*> (this));
|
||||
|
||||
auto basicServiceL1 = sdv::core::GetObject("Vehicle.Chassis.Door.Axle01.Left_Service").GetInterface<vss::Vehicle::Chassis::Door::Axle01::LeftService::IVSS_GetIsOpen>();
|
||||
if (basicServiceL1)
|
||||
basicServiceL1->UnregisterOnSignalChangeOfLeftDoorIsOpen01(dynamic_cast<vss::Vehicle::Chassis::Door::Axle01::LeftService::IVSS_SetIsOpen_Event*> (this));
|
||||
|
||||
auto basicServiceR1 = sdv::core::GetObject("Vehicle.Chassis.Door.Axle01.Right_Service").GetInterface<vss::Vehicle::Chassis::Door::Axle01::RightService::IVSS_GetIsOpen>();
|
||||
if (basicServiceR1)
|
||||
basicServiceR1->UnregisterOnSignalChangeOfRightDoorIsOpen01(dynamic_cast<vss::Vehicle::Chassis::Door::Axle01::RightService::IVSS_SetIsOpen_Event*> (this));
|
||||
|
||||
auto basicServiceL2 = sdv::core::GetObject("Vehicle.Chassis.Door.Axle02.Left_Service").GetInterface<vss::Vehicle::Chassis::Door::Axle02::LeftService::IVSS_GetIsOpen>();
|
||||
if (basicServiceL2)
|
||||
basicServiceL2->UnregisterOnSignalChangeOfLeftDoorIsOpen02(dynamic_cast<vss::Vehicle::Chassis::Door::Axle02::LeftService::IVSS_SetIsOpen_Event*> (this));
|
||||
|
||||
auto basicServiceR2 = sdv::core::GetObject("Vehicle.Chassis.Door.Axle02.Right_Service").GetInterface<vss::Vehicle::Chassis::Door::Axle02::RightService::IVSS_GetIsOpen>();
|
||||
if (basicServiceR2)
|
||||
basicServiceR2->UnregisterOnSignalChangeOfRightDoorIsOpen02(dynamic_cast<vss::Vehicle::Chassis::Door::Axle02::RightService::IVSS_SetIsOpen_Event*> (this));
|
||||
|
||||
// Unregister the data link signalss
|
||||
if (m_SignalFrontLeftDoorIsOpen)
|
||||
m_SignalFrontLeftDoorIsOpen.Reset();
|
||||
if (m_SignalFrontRightDoorIsOpen)
|
||||
m_SignalFrontRightDoorIsOpen.Reset();
|
||||
if (m_SignalRearLeftDoorIsOpen)
|
||||
m_SignalRearLeftDoorIsOpen.Reset();
|
||||
if (m_SignalRearRightDoorIsOpen)
|
||||
m_SignalRearRightDoorIsOpen.Reset();
|
||||
if (m_SignalFrontLeftDoorIsLocked)
|
||||
m_SignalFrontLeftDoorIsLocked.Reset();
|
||||
if (m_SignalFrontRightDoorIsLocked)
|
||||
m_SignalFrontRightDoorIsLocked.Reset();
|
||||
if (m_SignalRearLeftDoorIsLocked)
|
||||
m_SignalRearLeftDoorIsLocked.Reset();
|
||||
if (m_SignalRearRightDoorIsLocked)
|
||||
m_SignalRearRightDoorIsLocked.Reset();
|
||||
}
|
||||
|
||||
void CConsole::StartUpdateDataThread()
|
||||
{
|
||||
if (m_bThreadStarted)
|
||||
return;
|
||||
|
||||
m_bThreadStarted = true;
|
||||
|
||||
m_bRunning = true;
|
||||
m_threadReadTxSignals = std::thread(&CConsole::UpdateDataThreadFunc, this);
|
||||
}
|
||||
|
||||
void CConsole::StopUpdateDataThread()
|
||||
{
|
||||
// Stop running and wait for any thread to finalize
|
||||
m_bRunning = false;
|
||||
if (m_threadReadTxSignals.joinable())
|
||||
m_threadReadTxSignals.join();
|
||||
}
|
||||
|
||||
void CConsole::SetExternalApp()
|
||||
{
|
||||
m_isExternalApp = true;
|
||||
}
|
||||
|
||||
void CConsole::WriteIsOpen(bool value)
|
||||
{
|
||||
PrintValue(g_sVehicleDevice, "Front Left Door:", value, (value ? "open" : "closed"));
|
||||
}
|
||||
|
||||
void CConsole::SetIsOpenL1(bool value)
|
||||
{
|
||||
PrintValue(g_sBasicServiceL1, "Front Left Door:", value, (value ? "open" : "closed"));
|
||||
}
|
||||
|
||||
void CConsole::SetIsOpenR1(bool value)
|
||||
{
|
||||
PrintValue(g_sBasicServiceR1, "Front Right Door:", value, (value ? "open" : "closed"));
|
||||
}
|
||||
|
||||
void CConsole::SetIsOpenL2(bool value)
|
||||
{
|
||||
PrintValue(g_sBasicServiceL2, "Rear Left Door:", value, (value ? "open" : "closed"));
|
||||
}
|
||||
|
||||
void CConsole::SetIsOpenR2(bool value)
|
||||
{
|
||||
PrintValue(g_sBasicServiceR2, "Rear Right Door:", value, (value ? "open" : "closed"));
|
||||
}
|
||||
|
||||
bool CConsole::PrepareDataConsumersForStandAlone()
|
||||
{
|
||||
// Subscribe for the door and if available get TX signal. Either both exists or none of them
|
||||
sdv::core::CDispatchService dispatch;
|
||||
m_SignalFrontLeftDoorIsOpen = dispatch.Subscribe(doors::dsLeftDoorIsOpen01, [&](sdv::any_t value) { CallbackFrontLeftDoorIsOpen(value); });
|
||||
if(m_SignalFrontLeftDoorIsOpen)
|
||||
m_SignalFrontLeftDoorIsLocked = dispatch.RegisterTxSignal(doors::dsLeftLatch01, 0);
|
||||
|
||||
m_SignalFrontRightDoorIsOpen = dispatch.Subscribe(doors::dsRightDoorIsOpen01, [&](sdv::any_t value) { CallbackFrontRightDoorIsOpen(value); });
|
||||
if(m_SignalFrontRightDoorIsOpen)
|
||||
m_SignalFrontRightDoorIsLocked = dispatch.RegisterTxSignal(doors::dsRightLatch01, 0);
|
||||
|
||||
m_SignalRearLeftDoorIsOpen = dispatch.Subscribe(doors::dsLeftDoorIsOpen02, [&](sdv::any_t value) {CallbackRearLeftDoorIsOpen(value); });
|
||||
if(m_SignalRearLeftDoorIsOpen)
|
||||
m_SignalRearLeftDoorIsLocked = dispatch.RegisterTxSignal(doors::dsLeftLatch02, 0);
|
||||
|
||||
m_SignalRearRightDoorIsOpen = dispatch.Subscribe(doors::dsRightDoorIsOpen02, [&](sdv::any_t value) { CallbackRearRightDoorIsOpen(value); });
|
||||
if(m_SignalRearRightDoorIsOpen)
|
||||
m_SignalRearRightDoorIsLocked = dispatch.RegisterTxSignal(doors::dsRightLatch02, 0);
|
||||
|
||||
// Validate: Either both exists or none of them
|
||||
if (m_SignalFrontLeftDoorIsOpen != m_SignalFrontLeftDoorIsLocked)
|
||||
{
|
||||
SDV_LOG_ERROR("Console ERROR: m_SignalFrontLeftDoorIsOpen != m_SignalFrontLeftDoorIsLocked do not match, failed");
|
||||
return false;
|
||||
}
|
||||
if (m_SignalFrontRightDoorIsOpen != m_SignalFrontRightDoorIsLocked)
|
||||
{
|
||||
SDV_LOG_ERROR("Console ERROR: m_SignalFrontRightDoorIsOpen != m_SignalFrontRightDoorIsLocked do not match, failed");
|
||||
return false;
|
||||
}
|
||||
if (m_SignalRearLeftDoorIsOpen != m_SignalRearLeftDoorIsLocked)
|
||||
{
|
||||
SDV_LOG_ERROR("Console ERROR: m_SignalRearLeftDoorIsOpen != m_SignalRearLeftDoorIsLockeddo not match, failed");
|
||||
return false;
|
||||
}
|
||||
if (m_SignalRearRightDoorIsOpen != m_SignalRearRightDoorIsLocked)
|
||||
{
|
||||
SDV_LOG_ERROR("Console ERROR: m_SignalRearRightDoorIsOpen != m_SignalRearRightDoorIsLocked do not match, failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Registrate for the vehicle device & basic service of the front left door. Front left door mzust exist, the others are optional
|
||||
auto vehicleDevice = sdv::core::GetObject("Vehicle.Chassis.Door.Axle01.Left_Device").GetInterface<vss::Vehicle::Chassis::Door::Axle01::LeftDevice::IVSS_IsOpen>();
|
||||
if (!vehicleDevice)
|
||||
{
|
||||
SDV_LOG_ERROR("Could not get interface 'LeftDevice::IVSS_IsOpen': [CConsole]");
|
||||
return false;
|
||||
}
|
||||
vehicleDevice->RegisterIsOpenEvent(dynamic_cast<vss::Vehicle::Chassis::Door::Axle01::LeftDevice::IVSS_WriteIsOpen_Event*> (this));
|
||||
return true;
|
||||
}
|
||||
|
||||
void CConsole::CallbackFrontLeftDoorIsOpen(sdv::any_t value)
|
||||
{
|
||||
m_FrontLeftDoorIsOpen = value.get<bool>();
|
||||
PrintValue(g_sFrontLeftDoorIsOpen, "Front Left Door:", m_FrontLeftDoorIsOpen, (m_FrontLeftDoorIsOpen ? "open" : "closed"));
|
||||
}
|
||||
void CConsole::CallbackFrontRightDoorIsOpen(sdv::any_t value)
|
||||
{
|
||||
m_FrontRightDoorIsOpen = value.get<bool>();
|
||||
PrintValue(g_sFrontRightDoorIsOpen, "Front Right Door:", m_FrontRightDoorIsOpen, (m_FrontRightDoorIsOpen ? "open" : "closed"));
|
||||
}
|
||||
void CConsole::CallbackRearLeftDoorIsOpen(sdv::any_t value)
|
||||
{
|
||||
m_RearLeftDoorIsOpen = value.get<bool>();
|
||||
PrintValue(g_sRearLeftDoorIsOpen, "Rear Left Door:", m_RearLeftDoorIsOpen, (m_RearLeftDoorIsOpen ? "open" : "closed"));
|
||||
}
|
||||
void CConsole::CallbackRearRightDoorIsOpen(sdv::any_t value)
|
||||
{
|
||||
m_RearRightDoorIsOpen = value.get<bool>();
|
||||
PrintValue(g_sRearRightDoorIsOpen, "Rear Right Door:", m_RearRightDoorIsOpen, (m_RearRightDoorIsOpen ? "open" : "closed"));
|
||||
}
|
||||
|
||||
void CConsole::UpdateDataThreadFunc()
|
||||
{
|
||||
bool bDoorsAreLocked = true;
|
||||
bool bFirstStatusCheck = true;
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
|
||||
while (m_bRunning)
|
||||
{
|
||||
if (!m_isExternalApp)
|
||||
{
|
||||
UpdateTXSignal(g_sFrontLeftDoorIsLocked, "Front Left Latch:", m_SignalFrontLeftDoorIsLocked, m_FrontLeftDoorIsLocked);
|
||||
UpdateTXSignal(g_sFrontRightDoorIsLocked, "Front Right Latch:", m_SignalFrontRightDoorIsLocked, m_FrontRightDoorIsLocked);
|
||||
UpdateTXSignal(g_sRearLeftDoorIsLocked, "Rear Left Latch:", m_SignalRearLeftDoorIsLocked, m_RearLeftDoorIsLocked);
|
||||
UpdateTXSignal(g_sRearRightDoorIsLocked, "Rear Right Latch:", m_SignalRearRightDoorIsLocked, m_RearRightDoorIsLocked);
|
||||
}
|
||||
|
||||
if (m_pDoorService)
|
||||
{
|
||||
auto latch = m_pDoorService->GetDoorsStatus();
|
||||
if ((bDoorsAreLocked != latch) || (bFirstStatusCheck))
|
||||
{
|
||||
bDoorsAreLocked = latch;
|
||||
PrintText(g_sComplexService, bDoorsAreLocked ? "All doors are locked" :"All doors are unlocked");
|
||||
bFirstStatusCheck = false;
|
||||
}
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
}
|
||||
}
|
||||
|
||||
void CConsole::UpdateTXSignal(SConsolePos sPos, const std::string& label, sdv::core::CSignal& signal, bool& value)
|
||||
{
|
||||
// signal may be optional (door may not exist)
|
||||
if (signal)
|
||||
{
|
||||
auto frontLeftDoorIsLocked = value;
|
||||
value = signal.Read().get<bool>();
|
||||
if (frontLeftDoorIsLocked != value)
|
||||
{
|
||||
PrintValue(sPos, label , value, (value ? "locked" : "unlocked"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CConsole::SConsolePos CConsole::GetCursorPos() const
|
||||
{
|
||||
SConsolePos sPos{};
|
||||
std::cout << "\033[6n";
|
||||
|
||||
char buff[128];
|
||||
int indx = 0;
|
||||
for(;;) {
|
||||
int cc = std::cin.get();
|
||||
buff[indx] = (char)cc;
|
||||
indx++;
|
||||
if(cc == 'R') {
|
||||
buff[indx + 1] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
int iRow = 0, iCol = 0;
|
||||
sscanf(buff, "\x1b[%d;%dR", &iRow, &iCol);
|
||||
sPos.uiRow = static_cast<uint32_t>(iRow);
|
||||
sPos.uiCol = static_cast<uint32_t>(iCol);
|
||||
fseek(stdin, 0, SEEK_END);
|
||||
|
||||
return sPos;
|
||||
}
|
||||
|
||||
void CConsole::SetCursorPos(SConsolePos sPos)
|
||||
{
|
||||
std::cout << "\033[" << sPos.uiRow << ";" << sPos.uiCol << "H";
|
||||
}
|
||||
|
||||
void CConsole::PrintText(SConsolePos sPos, const std::string& rssText)
|
||||
{
|
||||
auto text = rssText;
|
||||
while (text.length() < 47)
|
||||
{
|
||||
text.append(" ");
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(m_mtxPrintToConsole);
|
||||
SetCursorPos(sPos);
|
||||
std::cout << text;
|
||||
}
|
||||
246
examples/door_demo_example/door_app/door_application.cpp
Normal file
246
examples/door_demo_example/door_app/door_application.cpp
Normal file
@@ -0,0 +1,246 @@
|
||||
#include "../door_app/include/door_application.h"
|
||||
#include "../door_app/include/signal_names.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <conio.h> // Needed for _kbhit
|
||||
#else
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
bool CDoorControl::LoadConfigFile(const std::string& inputMsg, const std::string& configFileName)
|
||||
{
|
||||
std::string msg = inputMsg;
|
||||
if (m_appcontrol.LoadConfig(configFileName) == sdv::core::EConfigProcessResult::successful)
|
||||
{
|
||||
msg.append("ok\n");
|
||||
std::cout << msg.c_str();
|
||||
return true;
|
||||
}
|
||||
|
||||
msg.append("FAILED.\n");
|
||||
std::cout << msg.c_str();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool CDoorControl::KeyHit()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return _kbhit();
|
||||
#elif __unix__
|
||||
int ch = getchar();
|
||||
if (ch != EOF) {
|
||||
ungetc(ch, stdin);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
char CDoorControl::GetChar()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return static_cast<char>(_getch());
|
||||
#else
|
||||
return getchar();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CDoorControl::RegisterSignals()
|
||||
{
|
||||
sdv::core::CDispatchService dispatch;
|
||||
|
||||
m_SignalFrontLeftDoorIsOpen = dispatch.RegisterRxSignal(doors::dsLeftDoorIsOpen01);
|
||||
m_SignalFrontLeftDoorIsLocked = dispatch.RegisterTxSignal(doors::dsLeftLatch01, 0);
|
||||
|
||||
if (m_iNumberOfDoors > 1)
|
||||
{
|
||||
m_SignalFrontRightDoorIsOpen = dispatch.RegisterRxSignal(doors::dsRightDoorIsOpen01);
|
||||
m_SignalFrontRightDoorIsLocked = dispatch.RegisterTxSignal(doors::dsRightLatch01, 0);
|
||||
|
||||
if (m_iNumberOfDoors > 2)
|
||||
{
|
||||
m_SignalRearLeftDoorIsOpen = dispatch.RegisterRxSignal(doors::dsLeftDoorIsOpen02);
|
||||
m_SignalRearLeftDoorIsLocked = dispatch.RegisterTxSignal(doors::dsLeftLatch02, 0);
|
||||
|
||||
if (m_iNumberOfDoors > 3)
|
||||
{
|
||||
m_SignalRearRightDoorIsOpen = dispatch.RegisterRxSignal(doors::dsRightDoorIsOpen02);
|
||||
m_SignalRearRightDoorIsLocked = dispatch.RegisterTxSignal(doors::dsRightLatch02, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool CDoorControl::IsSDVFrameworkEnvironmentSet()
|
||||
{
|
||||
const char* envVariable = std::getenv("SDV_FRAMEWORK_RUNTIME");
|
||||
if (envVariable)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CDoorControl::Initialize(const uint32_t numberOfDoors)
|
||||
{
|
||||
if (m_bInitialized)
|
||||
return true;
|
||||
|
||||
if ((numberOfDoors >= 1) && (numberOfDoors <= 4))
|
||||
{
|
||||
m_iNumberOfDoors = numberOfDoors;
|
||||
}
|
||||
|
||||
if (!IsSDVFrameworkEnvironmentSet())
|
||||
{
|
||||
// if SDV_FRAMEWORK_RUNTIME environment variable is not set we need to set the Framework Runtime directory
|
||||
m_appcontrol.SetFrameworkRuntimeDirectory("../../bin");
|
||||
}
|
||||
|
||||
if(!m_appcontrol.Startup(""))
|
||||
return false;
|
||||
|
||||
// Switch to config mode.
|
||||
m_appcontrol.SetConfigMode();
|
||||
bool bResult = LoadConfigFile("Load dispatch example: ", "data_dispatch_example.toml");
|
||||
|
||||
bResult &= LoadConfigFile("Load task timer: ", "task_timer_example.toml");
|
||||
bResult &= RegisterSignals();
|
||||
|
||||
bResult &= LoadConfigFile("Load vehicle devices and basic services for front left door: ", "front_left_door_example.toml");
|
||||
if (m_iNumberOfDoors > 1)
|
||||
{
|
||||
bResult &= LoadConfigFile("Load vehicle devices and basic services for front right door: ", "front_right_door_example.toml");
|
||||
if (m_iNumberOfDoors > 2)
|
||||
{
|
||||
bResult &= LoadConfigFile("Load vehicle devices and basic services for rear left door: ", "rear_left_door_example.toml");
|
||||
if (m_iNumberOfDoors > 3)
|
||||
{
|
||||
bResult &= LoadConfigFile("Load vehicle devices and basic services for rear right door: ", "rear_right_door_example.toml");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bResult &= LoadConfigFile("Load door service (complex service): ", "door_comple_service.toml");
|
||||
|
||||
if (!bResult)
|
||||
{
|
||||
SDV_LOG_ERROR("One or more configurations could not be loaded. Cannot continue.");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_bInitialized = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t CDoorControl::GetNumberOfDoors() const
|
||||
{
|
||||
return m_iNumberOfDoors;
|
||||
}
|
||||
|
||||
void CDoorControl::Shutdown()
|
||||
{
|
||||
if (!m_bInitialized)
|
||||
m_appcontrol.Shutdown();
|
||||
m_bInitialized = false;
|
||||
}
|
||||
|
||||
void CDoorControl::SetRunningMode()
|
||||
{
|
||||
m_appcontrol.SetRunningMode();
|
||||
}
|
||||
|
||||
|
||||
void CDoorControl::RunUntilBreak()
|
||||
{
|
||||
bool bRunning = true;
|
||||
bool openFrontLeftDoor = true;
|
||||
bool openFrontRightDoor = true;
|
||||
bool openRearLeftDoor = true;
|
||||
bool openRearRightDoor = true;
|
||||
|
||||
// Update console by writing the first value if available
|
||||
if (m_SignalFrontLeftDoorIsOpen)
|
||||
m_SignalFrontLeftDoorIsOpen.Write<bool>(openFrontLeftDoor);
|
||||
if (m_SignalFrontRightDoorIsOpen)
|
||||
m_SignalFrontRightDoorIsOpen.Write<bool>(openFrontRightDoor);
|
||||
if (m_SignalRearLeftDoorIsOpen)
|
||||
m_SignalRearLeftDoorIsOpen.Write<bool>(openRearLeftDoor);
|
||||
if (m_SignalRearRightDoorIsOpen)
|
||||
m_SignalRearRightDoorIsOpen.Write<bool>(openRearRightDoor);
|
||||
|
||||
while (bRunning)
|
||||
{
|
||||
// Check for a key
|
||||
if (!KeyHit())
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get a keyboard value (if there is any).
|
||||
char c = GetChar();
|
||||
switch (c)
|
||||
{
|
||||
case '1':
|
||||
openFrontLeftDoor = !openFrontLeftDoor;
|
||||
if (m_SignalFrontLeftDoorIsOpen)
|
||||
m_SignalFrontLeftDoorIsOpen.Write<bool>(openFrontLeftDoor);
|
||||
break;
|
||||
case '2':
|
||||
openFrontRightDoor = !openFrontRightDoor;
|
||||
if (m_SignalFrontRightDoorIsOpen)
|
||||
m_SignalFrontRightDoorIsOpen.Write<bool>(openFrontRightDoor);
|
||||
break;
|
||||
case '3':
|
||||
openRearLeftDoor = !openRearLeftDoor;
|
||||
if (m_SignalRearLeftDoorIsOpen)
|
||||
m_SignalRearLeftDoorIsOpen.Write<bool>(openRearLeftDoor);
|
||||
break;
|
||||
case '4':
|
||||
openRearRightDoor = !openRearRightDoor;
|
||||
if (m_SignalRearRightDoorIsOpen)
|
||||
m_SignalRearRightDoorIsOpen.Write<bool>(openRearRightDoor);
|
||||
break;
|
||||
case 'x':
|
||||
case 'X':
|
||||
bRunning = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t CDoorControl::UserInputNumberOfDoors()
|
||||
{
|
||||
uint32_t numberOfDoors = 4;
|
||||
// Clear the screen and goto top...
|
||||
std::cout << "\x1b[2J\033[0;0H";
|
||||
std::cout << "How many doors does the vehicle have? Press a number between 1 and 4: ";
|
||||
|
||||
// Get a keyboard value (if there is any).
|
||||
char c = GetChar();
|
||||
switch (c)
|
||||
{
|
||||
case '1':
|
||||
numberOfDoors = 1;
|
||||
break;
|
||||
case '2':
|
||||
numberOfDoors = 2;
|
||||
break;
|
||||
case '3':
|
||||
numberOfDoors = 3;
|
||||
break;
|
||||
case '4':
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return numberOfDoors;
|
||||
}
|
||||
27
examples/door_demo_example/door_app/door_demo_example.cpp
Normal file
27
examples/door_demo_example/door_app/door_demo_example.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <iostream>
|
||||
#include "../door_app/include/door_application.h"
|
||||
#include "../door_app/include/console.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
CDoorControl appobj;
|
||||
if (!appobj.Initialize(appobj.UserInputNumberOfDoors()))
|
||||
{
|
||||
std::cout << "ERROR: Failed to initialize application control." << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
CConsole visual_obj;
|
||||
visual_obj.PrintHeader(appobj.GetNumberOfDoors());
|
||||
visual_obj.PrepareDataConsumers();
|
||||
visual_obj.StartUpdateDataThread();
|
||||
|
||||
appobj.SetRunningMode();
|
||||
appobj.RunUntilBreak();
|
||||
|
||||
visual_obj.StopUpdateDataThread();
|
||||
visual_obj.ResetSignals();
|
||||
|
||||
appobj.Shutdown();
|
||||
return 0;
|
||||
}
|
||||
102
examples/door_demo_example/door_app/door_extern_application.cpp
Normal file
102
examples/door_demo_example/door_app/door_extern_application.cpp
Normal file
@@ -0,0 +1,102 @@
|
||||
#include "../door_app/include/door_extern_application.h"
|
||||
#include "../door_app/include/signal_names.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <conio.h> // Needed for _kbhit
|
||||
#else
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
bool CDoorExternControl::Initialize()
|
||||
{
|
||||
if (m_bInitialized)
|
||||
return true;
|
||||
|
||||
if (!IsSDVFrameworkEnvironmentSet())
|
||||
{
|
||||
// if SDV_FRAMEWORK_RUNTIME environment variable is not set we need to set the Framework Runtime directory
|
||||
m_appcontrol.SetFrameworkRuntimeDirectory("../../bin");
|
||||
}
|
||||
|
||||
std::stringstream sstreamAppConfig;
|
||||
sstreamAppConfig << "[Application]" << std::endl;
|
||||
sstreamAppConfig << "Mode=\"External\"" << std::endl;
|
||||
sstreamAppConfig << "Instance=\"3002\"" << std::endl;
|
||||
sstreamAppConfig << "Retries=" << 6 << std::endl;
|
||||
sstreamAppConfig << "[Console]" << std::endl;
|
||||
sstreamAppConfig << "Report=\"Silent\"" << std::endl;
|
||||
|
||||
if (!m_appcontrol.Startup(sstreamAppConfig.str()))
|
||||
return false;
|
||||
|
||||
m_bInitialized = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void CDoorExternControl::Shutdown()
|
||||
{
|
||||
if (!m_bInitialized)
|
||||
m_appcontrol.Shutdown();
|
||||
m_bInitialized = false;
|
||||
}
|
||||
|
||||
void CDoorExternControl::RunUntilBreak()
|
||||
{
|
||||
bool bRunning = true;
|
||||
|
||||
while (bRunning)
|
||||
{
|
||||
// Check for a key
|
||||
if (!KeyHit())
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get a keyboard value (if there is any).
|
||||
char c = GetChar();
|
||||
switch (c)
|
||||
{
|
||||
case 'x':
|
||||
case 'X':
|
||||
bRunning = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool CDoorExternControl::IsSDVFrameworkEnvironmentSet()
|
||||
{
|
||||
const char* envVariable = std::getenv("SDV_FRAMEWORK_RUNTIME");
|
||||
if (envVariable)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CDoorExternControl::KeyHit()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return _kbhit();
|
||||
#elif __unix__
|
||||
int ch = getchar();
|
||||
if (ch != EOF) {
|
||||
ungetc(ch, stdin);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
char CDoorExternControl::GetChar()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return static_cast<char>(_getch());
|
||||
#else
|
||||
return getchar();
|
||||
#endif
|
||||
}
|
||||
27
examples/door_demo_example/door_app/door_extern_example.cpp
Normal file
27
examples/door_demo_example/door_app/door_extern_example.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <iostream>
|
||||
#include "../door_app/include/door_extern_application.h"
|
||||
#include "../door_app/include/console.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
CDoorExternControl appobj;
|
||||
if (!appobj.Initialize())
|
||||
{
|
||||
std::cout << "ERROR: Failed to initialize application control." << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
CConsole visual_obj;
|
||||
visual_obj.SetExternalApp();
|
||||
visual_obj.PrintHeader(4);
|
||||
visual_obj.PrepareDataConsumers();
|
||||
visual_obj.StartUpdateDataThread();
|
||||
|
||||
appobj.RunUntilBreak();
|
||||
|
||||
visual_obj.StopUpdateDataThread();
|
||||
visual_obj.ResetSignals();
|
||||
|
||||
appobj.Shutdown();
|
||||
return 0;
|
||||
}
|
||||
271
examples/door_demo_example/door_app/include/console.h
Normal file
271
examples/door_demo_example/door_app/include/console.h
Normal file
@@ -0,0 +1,271 @@
|
||||
#ifndef CONSOLE_OUTPUT_H
|
||||
#define CONSOLE_OUTPUT_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <support/signal_support.h>
|
||||
#include <support/app_control.h>
|
||||
#include <support/component_impl.h>
|
||||
#include <support/timer.h>
|
||||
#include "signal_names.h"
|
||||
#include <fcntl.h>
|
||||
#include "../interfaces/vss_vehiclechassisdooraxle01left_vd_rx.h"
|
||||
#include "../interfaces/vss_vehiclechassisdooraxle01left_bs_rx.h"
|
||||
#include "../interfaces/vss_vehiclechassisdooraxle01right_bs_rx.h"
|
||||
#include "../interfaces/vss_vehiclechassisdooraxle02left_bs_rx.h"
|
||||
#include "../interfaces/vss_vehiclechassisdooraxle02right_bs_rx.h"
|
||||
|
||||
#ifdef __unix__
|
||||
#include <termios.h> // Needed for tcgetattr and fcntl
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "../generated/door_service/door_ifc.h"
|
||||
|
||||
/**
|
||||
* @brief Console operation class.
|
||||
* @details This class retrieves RX data from the data dispatch service, vehicle device & basic service of front left door on event change.
|
||||
* Furthermore, it shows TX value by polling the RX signals.
|
||||
*/
|
||||
class CConsole : public vss::Vehicle::Chassis::Door::Axle01::LeftDevice::IVSS_WriteIsOpen_Event
|
||||
, public vss::Vehicle::Chassis::Door::Axle01::LeftService::IVSS_SetIsOpen_Event
|
||||
, public vss::Vehicle::Chassis::Door::Axle01::RightService::IVSS_SetIsOpen_Event
|
||||
, public vss::Vehicle::Chassis::Door::Axle02::LeftService::IVSS_SetIsOpen_Event
|
||||
, public vss::Vehicle::Chassis::Door::Axle02::RightService::IVSS_SetIsOpen_Event
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Screen position structure
|
||||
*/
|
||||
struct SConsolePos
|
||||
{
|
||||
uint32_t uiRow; ///< Row position (starts at 1)
|
||||
uint32_t uiCol; ///< Column position (starts at 1)
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
CConsole();
|
||||
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
~CConsole();
|
||||
|
||||
/**
|
||||
* @brief Print the header.
|
||||
* @param[in] numberOfDoors number of doors
|
||||
*/
|
||||
void PrintHeader(const uint32_t numberOfDoors);
|
||||
|
||||
/**
|
||||
* @brief Prepare the data consumers..
|
||||
* @details Gets all signals (4 RX signals showing Open/Closed doors and 4 TX signals if the doors are locked)
|
||||
* Open/Closed is done as input (user) while locking the doors is done automatically by complex service when all doors are closed
|
||||
* Need to work independent from the number of doors (1-4)
|
||||
* @return Returns whether the preparation of the data consumers was successful or not.
|
||||
*/
|
||||
bool PrepareDataConsumers();
|
||||
|
||||
|
||||
/**
|
||||
* @brief Write leftDoorIsOpen signal
|
||||
* @param[in] value leftDoorIsOpen
|
||||
*/
|
||||
void WriteIsOpen(bool value) override;
|
||||
|
||||
/**
|
||||
* @brief Set leftDoorIsOpen signal (front door)
|
||||
* @param[in] value leftDoorIsOpen
|
||||
*/
|
||||
void SetIsOpenL1(bool value) override;
|
||||
|
||||
/**
|
||||
* @brief Set rightDoorIsOpen signal (front door)
|
||||
* @param[in] value rightDoorIsOpen
|
||||
*/
|
||||
void SetIsOpenR1(bool value) override;
|
||||
|
||||
/**
|
||||
* @brief Set leftDoorIsOpen signal (rear door)
|
||||
* @param[in] value leftDoorIsOpen
|
||||
*/
|
||||
void SetIsOpenL2(bool value) override;
|
||||
|
||||
/**
|
||||
* @brief Set rightDoorIsOpen signal (rear door)
|
||||
* @param[in] value rightDoorIsOpen
|
||||
*/
|
||||
void SetIsOpenR2(bool value) override;
|
||||
|
||||
/**
|
||||
* @brief For gracefully shutdown all signals need to be reset.
|
||||
*/
|
||||
void ResetSignals();
|
||||
|
||||
/**
|
||||
* @brief Starts thread for polling the TX signals (if the doors are locked by the complex service)
|
||||
*/
|
||||
void StartUpdateDataThread();
|
||||
|
||||
/**
|
||||
* @brief Stops thread
|
||||
*/
|
||||
void StopUpdateDataThread();
|
||||
|
||||
/**
|
||||
* @brief Used to set a flag for when we use external App
|
||||
*/
|
||||
void SetExternalApp();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* @brief Prepare the data consumers for Standalone application
|
||||
* @return Returns whether the preparation of the Standalone data consumers was successful or not.
|
||||
*/
|
||||
bool PrepareDataConsumersForStandAlone();
|
||||
|
||||
/**
|
||||
* @brief Callback function when front left door is opened or closed (by user).
|
||||
* @param[in] value The value of the signal to update.
|
||||
*/
|
||||
void CallbackFrontLeftDoorIsOpen(sdv::any_t value);
|
||||
|
||||
/**
|
||||
* @brief Callback function when front right door is opened or closed (by user).
|
||||
* @param[in] value The value of the signal to update.
|
||||
*/
|
||||
void CallbackFrontRightDoorIsOpen(sdv::any_t value);
|
||||
|
||||
/**
|
||||
* @brief Callback function when rear left door is opened or closed (by user).
|
||||
* @param[in] value The value of the signal to update.
|
||||
*/
|
||||
void CallbackRearLeftDoorIsOpen(sdv::any_t value);
|
||||
|
||||
/**
|
||||
* @brief Callback function when rear right door is opened or closed (by user).
|
||||
* @param[in] value The value of the signal to update.
|
||||
*/
|
||||
void CallbackRearRightDoorIsOpen(sdv::any_t value);
|
||||
|
||||
/**
|
||||
* @brief Read the data link TX signals and print them into the console.
|
||||
*/
|
||||
void UpdateDataThreadFunc();
|
||||
|
||||
/**
|
||||
* @brief Update the signal on the console output depending on the signal
|
||||
* @details Check if the signal is valid. If invalid, ignore it.
|
||||
*/
|
||||
void UpdateTXSignal(SConsolePos sPos, const std::string& label, sdv::core::CSignal& signal, bool& value);
|
||||
|
||||
/**
|
||||
* @brief Get the cursor position of the console.
|
||||
* @return The cursor position.
|
||||
*/
|
||||
SConsolePos GetCursorPos() const;
|
||||
|
||||
/**
|
||||
* @brief Set the current cursor position for the console.
|
||||
* @param[in] sPos Console position to place the current cursor at.
|
||||
*/
|
||||
void SetCursorPos(SConsolePos sPos);
|
||||
|
||||
/**
|
||||
* @brief Print text at a specific location.
|
||||
* @param[in] sPos The location to print text at.
|
||||
* @param[in] rssText Reference to the text to print.
|
||||
*/
|
||||
void PrintText(SConsolePos sPos, const std::string& rssText);
|
||||
|
||||
/**
|
||||
* @brief Print a value string at a specific location.
|
||||
* @tparam TValue Type of value.
|
||||
* @param[in] sPos The location to print the value at.
|
||||
* @param[in] rssName Reference to the value.
|
||||
* @param[in] tValue The value.
|
||||
* @param[in] rssStatus Status, becuse we have signals of type bool
|
||||
*/
|
||||
template <typename TValue>
|
||||
void PrintValue(SConsolePos sPos, const std::string& rssName, TValue tValue, const std::string& rssStatus);
|
||||
|
||||
/**
|
||||
* @brief Align string between name and value.
|
||||
* @param[in] message Reference to the message to align.
|
||||
* @param[in] desiredLength The desired length or 0 when no length is specified.
|
||||
* @return The aligned string.
|
||||
*/
|
||||
std::string AlignString(const std::string& message, uint32_t desiredLength = 0);
|
||||
|
||||
mutable std::mutex m_mtxPrintToConsole; ///< Mutex to print complete message
|
||||
bool m_bThreadStarted = false; ///< Set when initialized.
|
||||
bool m_bRunning = false; ///< When set, the application is running.
|
||||
bool m_isExternalApp = false; ///< True when we have an external application
|
||||
mutable std::mutex m_mPrintToConsole; ///< Mutex to print complete message
|
||||
|
||||
std::thread m_threadReadTxSignals; ///< Simulation datalink thread.
|
||||
|
||||
sdv::core::CSignal m_SignalFrontLeftDoorIsOpen; ///< Front Left Door signal (RX input) - open / closed
|
||||
sdv::core::CSignal m_SignalFrontRightDoorIsOpen; ///< Front Right Door signal (RX input) - open / closed
|
||||
sdv::core::CSignal m_SignalRearLeftDoorIsOpen; ///< Rear Left Door signal (RX input) - open / closed
|
||||
sdv::core::CSignal m_SignalRearRightDoorIsOpen; ///< Rear Right Door signal (RX input) - open / closed
|
||||
|
||||
bool m_FrontLeftDoorIsOpen = false; ///< Front Left Door value (RX input signal) - open / closed
|
||||
bool m_FrontRightDoorIsOpen = false; ///< Front Right Door value (RX input signal) - open / closed
|
||||
bool m_RearLeftDoorIsOpen = false; ///< Rear Left Door value (RX input signal) - open / closed
|
||||
bool m_RearRightDoorIsOpen = false; ///< Rear Right Door value (RX input signal) - open / closed
|
||||
|
||||
sdv::core::CSignal m_SignalFrontLeftDoorIsLocked; ///< Front Left Door signal (TX output) - locked / unlocked
|
||||
sdv::core::CSignal m_SignalFrontRightDoorIsLocked; ///< Front Right Door signal (TX output) - locked / unlocked
|
||||
sdv::core::CSignal m_SignalRearLeftDoorIsLocked; ///< Rear Left Door signal (TX output) - locked / unlocked
|
||||
sdv::core::CSignal m_SignalRearRightDoorIsLocked; ///< Rear Right Door signal (TX output) - locked / unlocked
|
||||
|
||||
bool m_FrontLeftDoorIsLocked = false; ///< Front Left Door value (TX output) - locked / unlocked
|
||||
bool m_FrontRightDoorIsLocked = false; ///< Front Right Door value (TX output) - locked / unlocked
|
||||
bool m_RearLeftDoorIsLocked = false; ///< Rear Left Door value (TX output) - locked / unlocked
|
||||
bool m_RearRightDoorIsLocked = false; ///< Rear Right Door value (TX output) - locked / unlocked
|
||||
|
||||
IDoorService* m_pDoorService = nullptr; ///< Door service interface pointer.
|
||||
|
||||
#ifdef _WIN32
|
||||
DWORD m_dwConsoleOutMode = 0u; ///< The console mode before switching on ANSI support.
|
||||
DWORD m_dwConsoleInMode = 0u; ///< The console mode before switching on ANSI support.
|
||||
#elif defined __unix__
|
||||
struct termios m_sTermAttr{}; ///< The terminal attributes before disabling echo.
|
||||
int m_iFileStatus = 0; ///< The file status flags for STDIN.
|
||||
#else
|
||||
#error The OS is not supported!
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
template <typename TValue>
|
||||
inline void CConsole::PrintValue(SConsolePos sPos, const std::string& rssName, TValue tValue, const std::string& rssUnits)
|
||||
{
|
||||
std::string endName = " ";
|
||||
const size_t nEndNameLen = 14 - rssUnits.size();
|
||||
const size_t nValueNameLen = 26;
|
||||
std::stringstream sstreamValueText;
|
||||
sstreamValueText << rssName <<
|
||||
std::string(nValueNameLen - std::min(rssName.size(), static_cast<size_t>(nValueNameLen - 1)) - 1, '.') <<
|
||||
" " << std::fixed << std::setprecision(2) << tValue << " " << rssUnits <<
|
||||
std::string(nEndNameLen - std::min(endName.size(), static_cast<size_t>(nEndNameLen - 1)) - 1, ' ');
|
||||
|
||||
std::lock_guard<std::mutex> lock(m_mPrintToConsole);
|
||||
SetCursorPos(sPos);
|
||||
std::cout << sstreamValueText.str();
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void CConsole::PrintValue<bool>(SConsolePos sPos, const std::string& rssName, bool bValue, const std::string& rssStatus)
|
||||
{;
|
||||
PrintValue(sPos, rssName, bValue ? "" : "", rssStatus);
|
||||
}
|
||||
|
||||
#endif // !define CONSOLE_OUTPUT_H
|
||||
@@ -0,0 +1,99 @@
|
||||
#include <string>
|
||||
#include <support/app_control.h>
|
||||
#include <support/signal_support.h>
|
||||
|
||||
/**
|
||||
* @brief Application Class of the door example
|
||||
*/
|
||||
class CDoorControl
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Start and initialize the application control and load vehicle devices and
|
||||
* basic services depending on the number of doors
|
||||
* @param[in] numberOfDoors number of doors (1-4), default 4
|
||||
* @return Return true on success otherwise false
|
||||
*/
|
||||
bool Initialize(const uint32_t numberOfDoors = 4);
|
||||
|
||||
/**
|
||||
* @brief After initialization/configuration the system mode needs to be set to running mode
|
||||
*/
|
||||
void SetRunningMode();
|
||||
|
||||
/**
|
||||
* @brief Ask user for input how many doors the vehicle should have (1-4)
|
||||
* @return Return number of doors (default 4)
|
||||
*/
|
||||
uint32_t UserInputNumberOfDoors();
|
||||
|
||||
/**
|
||||
* @brief Run loop as long as user input does not exit
|
||||
* Allow user to open/close each door.
|
||||
*/
|
||||
void RunUntilBreak();
|
||||
|
||||
/**
|
||||
* @brief Shutdown the system.
|
||||
*/
|
||||
void Shutdown();
|
||||
|
||||
/**
|
||||
* @brief Get number of doors
|
||||
* @return Return number of doors (default 4)
|
||||
*/
|
||||
uint32_t GetNumberOfDoors() const;
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* @brief check if SDV_FRAMEWORK_RUNTIME environment variable exists
|
||||
* @return Return true if environment variable is found otherwise false
|
||||
*/
|
||||
bool IsSDVFrameworkEnvironmentSet();
|
||||
|
||||
/**
|
||||
* @brief Loac config file and register vehicle device and basic service.
|
||||
* @remarks It is expected that each config file has the complete door:
|
||||
* vehicle device & basic service for input and output
|
||||
* @param[in] inputMsg message string to be printed on console in case of success and failure
|
||||
* @param[in] configFileName config toml file name
|
||||
* @return Return true on success otherwise false
|
||||
*/
|
||||
bool LoadConfigFile(const std::string& inputMsg, const std::string& configFileName);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Key hit check. Windows uses the _kbhit function; POSIX emulates this.
|
||||
* @return Returns whether a key has been pressed.
|
||||
*/
|
||||
bool KeyHit();
|
||||
|
||||
/**
|
||||
* @brief Get the character from the keyboard buffer if pressed.
|
||||
* @return Returns the character from the keyboard buffer.
|
||||
*/
|
||||
char GetChar();
|
||||
|
||||
/**
|
||||
* @brief Register/Create Signals in the dispatch service depending on the number of doors
|
||||
* @return Return true on success otherwise false
|
||||
*/
|
||||
bool RegisterSignals();
|
||||
|
||||
sdv::app::CAppControl m_appcontrol; ///< App-control of SDV V-API.
|
||||
bool m_bInitialized = false; ///< Set when initialized.
|
||||
uint32_t m_iNumberOfDoors = 4; ///< Number iof doors, maximuum 4
|
||||
|
||||
sdv::core::CSignal m_SignalFrontLeftDoorIsOpen; ///< Front Left Door signal (RX input) - open / closed
|
||||
sdv::core::CSignal m_SignalFrontRightDoorIsOpen; ///< Front Right Door signal (RX input) - open / closed
|
||||
sdv::core::CSignal m_SignalRearLeftDoorIsOpen; ///< Rear Left Door signal (RX input) - open / closed
|
||||
sdv::core::CSignal m_SignalRearRightDoorIsOpen; ///< Rear Right Door signal (RX input) - open / closed
|
||||
|
||||
sdv::core::CSignal m_SignalFrontLeftDoorIsLocked; ///< Front Left Latch signal (TX output) - locked / unlocked
|
||||
sdv::core::CSignal m_SignalFrontRightDoorIsLocked; ///< Front Right Latch signal (TX output) - locked / unlocked
|
||||
sdv::core::CSignal m_SignalRearLeftDoorIsLocked; ///< Rear Left Latch signal (TX output) - locked / unlocked
|
||||
sdv::core::CSignal m_SignalRearRightDoorIsLocked; ///< Rear Right Latch signal (TX output) - locked / unlocked
|
||||
|
||||
};
|
||||
@@ -0,0 +1,55 @@
|
||||
#include <string>
|
||||
#include <support/app_control.h>
|
||||
#include <support/signal_support.h>
|
||||
|
||||
/**
|
||||
* @brief Application Class of the door example
|
||||
*/
|
||||
class CDoorExternControl
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Start and initialize the application control and load vehicle devices and
|
||||
* basic services depending on the numerb of doors
|
||||
* @return Return true on success otherwise false
|
||||
*/
|
||||
bool Initialize();
|
||||
|
||||
|
||||
/**
|
||||
* @brief Run loop as long as user input does not exit
|
||||
* Allow user to open/close each door.
|
||||
*/
|
||||
void RunUntilBreak();
|
||||
|
||||
/**
|
||||
* @brief Shutdown the system.
|
||||
*/
|
||||
void Shutdown();
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* @brief check if SDV_FRAMEWORK_RUNTIME environment variable exists
|
||||
* @return Return true if environment variable is found otherwise false
|
||||
*/
|
||||
bool IsSDVFrameworkEnvironmentSet();
|
||||
|
||||
/**
|
||||
* @brief Key hit check. Windows uses the _kbhit function; POSIX emulates this.
|
||||
* @return Returns whether a key has been pressed.
|
||||
*/
|
||||
bool KeyHit();
|
||||
|
||||
/**
|
||||
* @brief Get the character from the keyboard buffer if pressed.
|
||||
* @return Returns the character from the keyboard buffer.
|
||||
*/
|
||||
char GetChar();
|
||||
|
||||
sdv::app::CAppControl m_appcontrol; ///< App-control of SDV V-API.
|
||||
bool m_bInitialized = false; ///< Set when initialized.
|
||||
uint32_t m_iNumberOfDoors = 4; ///< Number iof doors, maximuum 4
|
||||
|
||||
};
|
||||
30
examples/door_demo_example/door_app/include/signal_names.h
Normal file
30
examples/door_demo_example/door_app/include/signal_names.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* namespace for the signal names
|
||||
* in case /interfaces/signal_identifier.h
|
||||
* exists, use the file, otherwise define the namespace
|
||||
*/
|
||||
#ifndef SIGNAL_NAMES_H
|
||||
#define SIGNAL_NAMES_H
|
||||
|
||||
#ifdef __has_include
|
||||
#if __has_include("../interfaces/signal_identifier.h")
|
||||
#include "../interfaces/signal_identifier.h"
|
||||
#else
|
||||
|
||||
namespace doors
|
||||
{
|
||||
// Data Dispatch Service signal names to dbc variable names C-type RX/TX vss name space
|
||||
static std::string dsLeftDoorIsOpen01 = "CAN_Input_L1.Door01LeftIsOpen"; ///< bool RX Vehicle.Chassis.Door.Axle01.Left
|
||||
static std::string dsRightDoorIsOpen01 = "CAN_Input_R1.Door01RightIs"; ///< bool RX Vehicle.Chassis.Door.Axle01.Right
|
||||
static std::string dsLeftDoorIsOpen02 = "CAN_Input_L2.Door02LeftIsOpen"; ///< bool RX Vehicle.Chassis.Door.Axle02.Left
|
||||
static std::string dsRightDoorIsOpen02 = "CAN_Input_R2.Door02RightIsOpen"; ///< bool RX Vehicle.Chassis.Door.Axle02.Right
|
||||
static std::string dsLeftLatch01 = "CAN_Output.LockDoor01Left" ; ///< bool TX Vehicle.Chassis.TX.Door.Axle01.Left
|
||||
static std::string dsRightLatch01 = "CAN_Output.LockDoor01Right"; ///< bool TX Vehicle.Chassis.TX.Door.Axle01.Right
|
||||
static std::string dsLeftLatch02 = "CAN_Output.LockDoor02Left" ; ///< bool TX Vehicle.Chassis.TX.Door.Axle02.Left
|
||||
static std::string dsRightLatch02 = "CAN_Output.LockDoor02Right"; ///< bool TX Vehicle.Chassis.TX.Door.Axle02.Right
|
||||
} // doors
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // SIGNAL_NAMES_H
|
||||
42
examples/door_demo_example/door_example_receiver.asc
Normal file
42
examples/door_demo_example/door_example_receiver.asc
Normal file
@@ -0,0 +1,42 @@
|
||||
date 08/28/25 19:10:31
|
||||
base hex timestamps absolute
|
||||
Begin Triggerblock 08/28/25 19:10:31
|
||||
0.000000 Start of measurement
|
||||
0.021165 1 1 Rx d 1 02
|
||||
0.031165 1 2 Rx d 1 08
|
||||
0.041165 1 3 Rx d 1 20
|
||||
0.051165 1 4 Rx d 1 80
|
||||
3.002210 1 1 Rx d 1 00
|
||||
3.502858 1 2 Rx d 1 00
|
||||
4.002858 1 3 Rx d 1 00
|
||||
4.502858 1 4 Rx d 1 00
|
||||
9.021165 1 1 Rx d 1 02
|
||||
9.031165 1 2 Rx d 1 08
|
||||
9.041165 1 3 Rx d 1 20
|
||||
9.051165 1 4 Rx d 1 80
|
||||
13.021165 1 1 Rx d 1 00
|
||||
13.031165 1 2 Rx d 1 00
|
||||
13.041165 1 3 Rx d 1 00
|
||||
13.051165 1 4 Rx d 1 00
|
||||
17.021165 1 1 Rx d 1 02
|
||||
17.031165 1 2 Rx d 1 08
|
||||
17.041165 1 3 Rx d 1 20
|
||||
17.051165 1 4 Rx d 1 80
|
||||
19.002210 1 1 Rx d 1 00
|
||||
19.502858 1 2 Rx d 1 00
|
||||
20.002858 1 3 Rx d 1 00
|
||||
20.502858 1 4 Rx d 1 00
|
||||
24.021165 1 1 Rx d 1 02
|
||||
24.031165 1 2 Rx d 1 08
|
||||
24.041165 1 3 Rx d 1 20
|
||||
24.051165 1 4 Rx d 1 80
|
||||
27.021165 1 1 Rx d 1 00
|
||||
27.031165 1 2 Rx d 1 00
|
||||
27.041165 1 3 Rx d 1 00
|
||||
27.051165 1 4 Rx d 1 00
|
||||
30.021165 1 1 Rx d 1 02
|
||||
30.031165 1 2 Rx d 1 08
|
||||
30.041165 1 3 Rx d 1 20
|
||||
30.051165 1 4 Rx d 1 80
|
||||
|
||||
End TriggerBlock
|
||||
154
examples/door_demo_example/door_service/complex_service.cpp
Normal file
154
examples/door_demo_example/door_service/complex_service.cpp
Normal file
@@ -0,0 +1,154 @@
|
||||
#include <iostream>
|
||||
#include "complex_service.h"
|
||||
|
||||
void CDoorsExampleService::Initialize(const sdv::u8string& /*ssObjectConfig*/)
|
||||
{
|
||||
m_eStatus = sdv::EObjectStatus::initializing;
|
||||
|
||||
// Request the basic service for front left door.
|
||||
auto pFrontLeftDoorSvc = sdv::core::GetObject("Vehicle.Chassis.Door.Axle01.Left_Service").GetInterface<vss::Vehicle::Chassis::Door::Axle01::LeftService::IVSS_GetIsOpen>();
|
||||
if (pFrontLeftDoorSvc)
|
||||
{
|
||||
// Register front left door change event handler.
|
||||
pFrontLeftDoorSvc->RegisterOnSignalChangeOfLeftDoorIsOpen01(static_cast<vss::Vehicle::Chassis::Door::Axle01::LeftService::IVSS_SetIsOpen_Event*> (this));
|
||||
}
|
||||
|
||||
// Request the basic service for front right door.
|
||||
auto pFrontRightDoorSvc = sdv::core::GetObject("Vehicle.Chassis.Door.Axle01.Right_Service").GetInterface<vss::Vehicle::Chassis::Door::Axle01::RightService::IVSS_GetIsOpen>();
|
||||
if (pFrontRightDoorSvc)
|
||||
{
|
||||
// Register front right door change event handler.
|
||||
pFrontRightDoorSvc->RegisterOnSignalChangeOfRightDoorIsOpen01(static_cast<vss::Vehicle::Chassis::Door::Axle01::RightService::IVSS_SetIsOpen_Event*> (this));
|
||||
}
|
||||
|
||||
// Request the basic service for rear left door.
|
||||
auto pRearLeftDoorSvc = sdv::core::GetObject("Vehicle.Chassis.Door.Axle02.Left_Service").GetInterface<vss::Vehicle::Chassis::Door::Axle02::LeftService::IVSS_GetIsOpen>();
|
||||
if (pRearLeftDoorSvc)
|
||||
{
|
||||
// Register rear left door change event handler.
|
||||
pRearLeftDoorSvc->RegisterOnSignalChangeOfLeftDoorIsOpen02(static_cast<vss::Vehicle::Chassis::Door::Axle02::LeftService::IVSS_SetIsOpen_Event*> (this));
|
||||
}
|
||||
|
||||
// Request the basic service for front right door.
|
||||
auto pRearRightDoorSvc = sdv::core::GetObject("Vehicle.Chassis.Door.Axle02.Right_Service").GetInterface<vss::Vehicle::Chassis::Door::Axle02::RightService::IVSS_GetIsOpen>();
|
||||
if (pRearRightDoorSvc)
|
||||
{
|
||||
// Register rear right door change event handler.
|
||||
pRearRightDoorSvc->RegisterOnSignalChangeOfRightDoorIsOpen02(static_cast<vss::Vehicle::Chassis::Door::Axle02::RightService::IVSS_SetIsOpen_Event*> (this));
|
||||
}
|
||||
|
||||
// Request the basic service for locking the front left door.
|
||||
m_pFrontLeftDoorSvc = sdv::core::GetObject("Vehicle.Chassis.Door.Axle01.Left_Service").GetInterface<vss::Vehicle::Chassis::Door::Axle01::LeftService::IVSS_SetLock>();
|
||||
|
||||
// Request the basic service for locking the front right door.
|
||||
m_pFrontRightDoorSvc = sdv::core::GetObject("Vehicle.Chassis.Door.Axle01.Right_Service").GetInterface<vss::Vehicle::Chassis::Door::Axle01::RightService::IVSS_SetLock>();
|
||||
|
||||
// Request the basic service for locking the rear left door.
|
||||
m_pRearLeftDoorSvc = sdv::core::GetObject("Vehicle.Chassis.Door.Axle02.Left_Service").GetInterface<vss::Vehicle::Chassis::Door::Axle02::LeftService::IVSS_SetLock>();
|
||||
|
||||
// Request the basic service for locking the rear right door.
|
||||
m_pRearRightDoorSvc = sdv::core::GetObject("Vehicle.Chassis.Door.Axle02.Right_Service").GetInterface<vss::Vehicle::Chassis::Door::Axle02::RightService::IVSS_SetLock>();
|
||||
|
||||
// Validate if we have the Open/Closed signal and the Lock/Unlock door signal, both must exist together or both must not exist
|
||||
// Front left door is an exception, it isalways required
|
||||
if ((!pFrontLeftDoorSvc) || (!m_pFrontLeftDoorSvc))
|
||||
{
|
||||
SDV_LOG_ERROR("Could not get interfaces for 'Front left door': [CDoorsExampleService]");
|
||||
m_eStatus = sdv::EObjectStatus::initialization_failure;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((pFrontRightDoorSvc == nullptr) != (m_pFrontRightDoorSvc == nullptr))
|
||||
{
|
||||
SDV_LOG_ERROR("Could not get both interfaces for 'Front right door': [CDoorsExampleService]");
|
||||
m_eStatus = sdv::EObjectStatus::initialization_failure;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((pRearLeftDoorSvc == nullptr) != (m_pRearLeftDoorSvc == nullptr))
|
||||
{
|
||||
SDV_LOG_ERROR("Could not get both interfaces for 'Rear left door': [CDoorsExampleService]");
|
||||
m_eStatus = sdv::EObjectStatus::initialization_failure;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((pRearRightDoorSvc == nullptr) != (m_pRearRightDoorSvc == nullptr))
|
||||
{
|
||||
SDV_LOG_ERROR("Could not get both interfaces for 'Rear right door': [CDoorsExampleService]");
|
||||
m_eStatus = sdv::EObjectStatus::initialization_failure;
|
||||
return;
|
||||
}
|
||||
|
||||
m_doorsThread.start(m_Interval);
|
||||
m_eStatus = sdv::EObjectStatus::initialized;
|
||||
}
|
||||
|
||||
sdv::EObjectStatus CDoorsExampleService::GetStatus() const
|
||||
{
|
||||
return m_eStatus;
|
||||
}
|
||||
|
||||
void CDoorsExampleService::SetOperationMode(sdv::EOperationMode /*eMode*/)
|
||||
{
|
||||
// Not applicable
|
||||
}
|
||||
|
||||
void CDoorsExampleService::Shutdown()
|
||||
{
|
||||
// Unregister front left door change event handler.
|
||||
auto pFrontLeftDoorSvc = sdv::core::GetObject("Vehicle.Chassis.Door.Axle01.Left_Service").GetInterface<vss::Vehicle::Chassis::Door::Axle01::LeftService::IVSS_GetIsOpen>();
|
||||
if (pFrontLeftDoorSvc)
|
||||
pFrontLeftDoorSvc->UnregisterOnSignalChangeOfLeftDoorIsOpen01(static_cast<vss::Vehicle::Chassis::Door::Axle01::LeftService::IVSS_SetIsOpen_Event*> (this));
|
||||
|
||||
// Unregister front right door change event handler.
|
||||
auto pFrontRightDoorSvc = sdv::core::GetObject("Vehicle.Chassis.Door.Axle01.Right_Service").GetInterface<vss::Vehicle::Chassis::Door::Axle01::RightService::IVSS_GetIsOpen>();
|
||||
if (pFrontRightDoorSvc)
|
||||
pFrontRightDoorSvc->UnregisterOnSignalChangeOfRightDoorIsOpen01(static_cast<vss::Vehicle::Chassis::Door::Axle01::RightService::IVSS_SetIsOpen_Event*> (this));
|
||||
|
||||
// Unregister rear left door change event handler.
|
||||
auto pRearLeftDoorSvc = sdv::core::GetObject("Vehicle.Chassis.Door.Axle02.Left_Service").GetInterface<vss::Vehicle::Chassis::Door::Axle02::LeftService::IVSS_GetIsOpen>();
|
||||
if (pRearLeftDoorSvc)
|
||||
pRearLeftDoorSvc->UnregisterOnSignalChangeOfLeftDoorIsOpen02(static_cast<vss::Vehicle::Chassis::Door::Axle02::LeftService::IVSS_SetIsOpen_Event*> (this));
|
||||
|
||||
// Unregister rear right door change event handler.
|
||||
auto pRearRightDoorSvc = sdv::core::GetObject("Vehicle.Chassis.Door.Axle02.Right_Service").GetInterface<vss::Vehicle::Chassis::Door::Axle02::RightService::IVSS_GetIsOpen>();
|
||||
if (pRearRightDoorSvc)
|
||||
pRearRightDoorSvc->UnregisterOnSignalChangeOfRightDoorIsOpen02(static_cast<vss::Vehicle::Chassis::Door::Axle02::RightService::IVSS_SetIsOpen_Event*> (this));
|
||||
|
||||
m_doorsThread.stop();
|
||||
}
|
||||
|
||||
void CDoorsExampleService::AreAllDoorsClosed()
|
||||
{
|
||||
if (m_bFrontLeftDoorIsOpen || m_bFrontRightDoorIsOpen || m_bRearLeftDoorIsOpen || m_bRearRightDoorIsOpen)
|
||||
{
|
||||
m_doorsThread.stop();
|
||||
LockDoors(false);
|
||||
m_bAllDoorsAreLocked = false;
|
||||
return;
|
||||
}
|
||||
m_doorsThread.restart(m_Interval);
|
||||
}
|
||||
|
||||
void CDoorsExampleService::LockDoorsIfAllDoorsAreClosed()
|
||||
{
|
||||
if (m_bFrontLeftDoorIsOpen || m_bFrontRightDoorIsOpen || m_bRearLeftDoorIsOpen || m_bRearRightDoorIsOpen)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_bAllDoorsAreLocked = true;
|
||||
LockDoors(true);
|
||||
}
|
||||
|
||||
void CDoorsExampleService::LockDoors(const bool lock) const
|
||||
{
|
||||
if (m_pFrontLeftDoorSvc)
|
||||
m_pFrontLeftDoorSvc->SetLock(lock);
|
||||
if (m_pFrontRightDoorSvc)
|
||||
m_pFrontRightDoorSvc->SetLock(lock);
|
||||
if (m_pRearLeftDoorSvc)
|
||||
m_pRearLeftDoorSvc->SetLock(lock);
|
||||
if (m_pRearRightDoorSvc)
|
||||
m_pRearRightDoorSvc->SetLock(lock);
|
||||
}
|
||||
190
examples/door_demo_example/door_service/complex_service.h
Normal file
190
examples/door_demo_example/door_service/complex_service.h
Normal file
@@ -0,0 +1,190 @@
|
||||
#ifndef DOORS_COMPLEX_SERVICE_EXAMPLE_H
|
||||
#define DOORS_COMPLEX_SERVICE_EXAMPLE_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
// SDV framework support
|
||||
#include <support/component_impl.h>
|
||||
#include <support/signal_support.h>
|
||||
#include <support/timer.h>
|
||||
|
||||
// VSS interfaces - located in ../interfaces
|
||||
#include "vss_vehiclechassisdooraxle01left_bs_rx.h"
|
||||
#include "vss_vehiclechassisdooraxle01left_bs_tx.h"
|
||||
#include "vss_vehiclechassisdooraxle01right_bs_rx.h"
|
||||
#include "vss_vehiclechassisdooraxle01right_bs_tx.h"
|
||||
#include "vss_vehiclechassisdooraxle02left_bs_rx.h"
|
||||
#include "vss_vehiclechassisdooraxle02left_bs_tx.h"
|
||||
#include "vss_vehiclechassisdooraxle02right_bs_rx.h"
|
||||
#include "vss_vehiclechassisdooraxle02right_bs_tx.h"
|
||||
|
||||
#include "lock_doors_thread.h"
|
||||
|
||||
#include "../generated/door_service/door_ifc.h"
|
||||
|
||||
/**
|
||||
* @brief Doors example service: locks/unlocks doors after closing/opening doors
|
||||
*/
|
||||
class CDoorsExampleService : public sdv::CSdvObject
|
||||
, public sdv::IObjectControl
|
||||
, public vss::Vehicle::Chassis::Door::Axle01::LeftService::IVSS_SetIsOpen_Event
|
||||
, public vss::Vehicle::Chassis::Door::Axle01::RightService::IVSS_SetIsOpen_Event
|
||||
, public vss::Vehicle::Chassis::Door::Axle02::LeftService::IVSS_SetIsOpen_Event
|
||||
, public vss::Vehicle::Chassis::Door::Axle02::RightService::IVSS_SetIsOpen_Event
|
||||
, public IDoorService
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
CDoorsExampleService() : m_doorsThread([&] { this->LockDoorsIfAllDoorsAreClosed(); }) {}
|
||||
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
~CDoorsExampleService()
|
||||
{
|
||||
// Just in case...
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
// Interface map
|
||||
BEGIN_SDV_INTERFACE_MAP()
|
||||
SDV_INTERFACE_ENTRY(sdv::IObjectControl)
|
||||
SDV_INTERFACE_ENTRY(vss::Vehicle::Chassis::Door::Axle01::LeftService::IVSS_SetIsOpen_Event)
|
||||
SDV_INTERFACE_ENTRY(vss::Vehicle::Chassis::Door::Axle01::RightService::IVSS_SetIsOpen_Event)
|
||||
SDV_INTERFACE_ENTRY(vss::Vehicle::Chassis::Door::Axle02::LeftService::IVSS_SetIsOpen_Event)
|
||||
SDV_INTERFACE_ENTRY(vss::Vehicle::Chassis::Door::Axle02::RightService::IVSS_SetIsOpen_Event)
|
||||
SDV_INTERFACE_ENTRY(IDoorService)
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
// Object declarations
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::ComplexService)
|
||||
DECLARE_OBJECT_CLASS_NAME("Doors Example Service")
|
||||
DECLARE_OBJECT_SINGLETON()
|
||||
|
||||
/**
|
||||
* @brief Initialize the object. Overload of sdv::IObjectControl::Initialize.
|
||||
* @param[in] ssObjectConfig Optional configuration string.
|
||||
*/
|
||||
void Initialize(const sdv::u8string& ssObjectConfig) override;
|
||||
|
||||
/**
|
||||
* @brief Get the current status of the object. Overload of sdv::IObjectControl::GetStatus.
|
||||
* @return Return the current status of the object.
|
||||
*/
|
||||
sdv::EObjectStatus GetStatus() const override;
|
||||
|
||||
/**
|
||||
* @brief Set the component operation mode. Overload of sdv::IObjectControl::SetOperationMode.
|
||||
* @param[in] eMode The operation mode, the component should run in.
|
||||
*/
|
||||
void SetOperationMode(sdv::EOperationMode eMode) override;
|
||||
|
||||
/**
|
||||
* @brief Shutdown called before the object is destroyed. Overload of sdv::IObjectControl::Shutdown.
|
||||
*/
|
||||
void Shutdown() override;
|
||||
|
||||
/**
|
||||
* @brief Set leftDoorIsOpen signal (front door)
|
||||
* @param[in] value leftDoorIsOpen
|
||||
*/
|
||||
void SetIsOpenL1(bool value) override
|
||||
{
|
||||
auto haschanged = (m_bFrontLeftDoorIsOpen != value);
|
||||
m_bFrontLeftDoorIsOpen = value;
|
||||
|
||||
if (haschanged)
|
||||
AreAllDoorsClosed();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set rightDoorIsOpen signal (front door)
|
||||
* @param[in] value rightDoorIsOpen
|
||||
*/
|
||||
void SetIsOpenR1(bool value) override
|
||||
{
|
||||
auto haschanged = (m_bFrontRightDoorIsOpen != value);
|
||||
m_bFrontRightDoorIsOpen = value;
|
||||
|
||||
if (haschanged)
|
||||
AreAllDoorsClosed();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set leftDoorIsOpen signal (rear door)
|
||||
* @param[in] value leftDoorIsOpen
|
||||
*/
|
||||
void SetIsOpenL2(bool value) override
|
||||
{
|
||||
auto haschanged = (m_bRearLeftDoorIsOpen != value);
|
||||
m_bRearLeftDoorIsOpen = value;
|
||||
|
||||
if (haschanged)
|
||||
AreAllDoorsClosed();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set rightDoorIsOpen signal (rear door)
|
||||
* @param[in] value rightDoorIsOpen
|
||||
*/
|
||||
void SetIsOpenR2(bool value) override
|
||||
{
|
||||
auto haschanged = (m_bRearRightDoorIsOpen != value);
|
||||
m_bRearRightDoorIsOpen = value;
|
||||
|
||||
if (haschanged)
|
||||
AreAllDoorsClosed();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get doors state. If the doors are locked/unlocked
|
||||
*/
|
||||
virtual bool GetDoorsStatus() override
|
||||
{
|
||||
return m_bAllDoorsAreLocked;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* @brief Check if all doors are close
|
||||
* @details If all doors are not closed, unlock doors
|
||||
*/
|
||||
void AreAllDoorsClosed();
|
||||
|
||||
/**
|
||||
* @brief Check if all doors are close
|
||||
* @details If all doors are closed, lock doors, otherwise do nothing. This is a callback function for timer.
|
||||
*/
|
||||
void LockDoorsIfAllDoorsAreClosed();
|
||||
|
||||
/**
|
||||
* @brief Lock or unlock doors
|
||||
* @param[in] lock if true lock doors, otherwise unlock doors
|
||||
*/
|
||||
void LockDoors(const bool lock) const;
|
||||
|
||||
sdv::EObjectStatus m_eStatus = sdv::EObjectStatus::initialization_pending; ///< Current object status
|
||||
|
||||
bool m_bFrontLeftDoorIsOpen = false; ///< Front Left Door Status
|
||||
bool m_bFrontRightDoorIsOpen = false; ///< Front Right Door Status
|
||||
bool m_bRearLeftDoorIsOpen = false; ///< Rear Left Door Status
|
||||
bool m_bRearRightDoorIsOpen = false; ///< Rear Right Door Status
|
||||
|
||||
bool m_bAllDoorsAreLocked = false; ///< state for locked/unlocked of all doors
|
||||
|
||||
///< Door lock interfaces.
|
||||
vss::Vehicle::Chassis::Door::Axle01::LeftService::IVSS_SetLock* m_pFrontLeftDoorSvc = nullptr; ///< Front Left Door
|
||||
vss::Vehicle::Chassis::Door::Axle01::RightService::IVSS_SetLock* m_pFrontRightDoorSvc = nullptr; ///< Front Right Door
|
||||
vss::Vehicle::Chassis::Door::Axle02::LeftService::IVSS_SetLock* m_pRearLeftDoorSvc = nullptr; ///< Rear Left Door
|
||||
vss::Vehicle::Chassis::Door::Axle02::RightService::IVSS_SetLock* m_pRearRightDoorSvc = nullptr; ///< Rear Right Door
|
||||
|
||||
LockDoorsThread m_doorsThread; ///< timer thread
|
||||
uint32_t m_Interval = 18; ///< interval value * 100 = x milliseconds
|
||||
};
|
||||
|
||||
DEFINE_SDV_OBJECT(CDoorsExampleService)
|
||||
|
||||
#endif // !define DOORS_COMPLEX_SERVICE_EXAMPLE_H
|
||||
17
examples/door_demo_example/door_service/door_ifc.idl
Normal file
17
examples/door_demo_example/door_service/door_ifc.idl
Normal file
@@ -0,0 +1,17 @@
|
||||
/*******************************************************************************
|
||||
* @file door_ifc.idl
|
||||
* @details Door service interface definition.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief DoorService example service interface. The interface provides functions for the
|
||||
* Doors example complex service.
|
||||
*/
|
||||
interface IDoorService
|
||||
{
|
||||
/**
|
||||
* @brief Status of all doors together whether they are locked or unlocked.
|
||||
* @return true if all doors are locked, otherwise unlocked.
|
||||
*/
|
||||
boolean GetDoorsStatus();
|
||||
};
|
||||
95
examples/door_demo_example/door_service/lock_doors_thread.h
Normal file
95
examples/door_demo_example/door_service/lock_doors_thread.h
Normal file
@@ -0,0 +1,95 @@
|
||||
|
||||
#ifndef LOCK_DOORS_THREAD_H
|
||||
#define LOCK_DOORS_THREAD_H
|
||||
|
||||
/**
|
||||
* @brief Thread to lock the doors (or execute any other callback the thread gets) after a certain time. can be restarted
|
||||
*/
|
||||
class LockDoorsThread
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Constructor, set the callback function
|
||||
* @param[in] callback function to be called
|
||||
* @param[in] m_running when set to false end thread
|
||||
* @param[in] m_timeIn100MilliSeconds timespan * 100 in milliseconds before callback should be executed
|
||||
*/
|
||||
LockDoorsThread(std::function<void()> callback)
|
||||
: m_callback(callback), m_running(false), m_timeIn100MilliSeconds(0) {}
|
||||
|
||||
/**
|
||||
* @brief Stsrt thread
|
||||
* @param[in] timeSpan the time span before the callback will be executed
|
||||
*/
|
||||
void start(uint32_t timeSpan)
|
||||
{
|
||||
if (m_running)
|
||||
return;
|
||||
|
||||
m_timeIn100MilliSeconds = timeSpan;
|
||||
m_counter = 0;
|
||||
m_running = true;
|
||||
m_thread = std::thread(&LockDoorsThread::run, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Stop thread
|
||||
*/
|
||||
void stop()
|
||||
{
|
||||
m_running = false;
|
||||
if (m_thread.joinable())
|
||||
{
|
||||
m_thread.join();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Stop and restart thread with new time setting
|
||||
* @param[in] timeSpan the time span before the callback will be executed
|
||||
*/
|
||||
void restart(uint32_t timeSpan)
|
||||
{
|
||||
stop();
|
||||
m_counter = 0;
|
||||
start(timeSpan);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief destructor
|
||||
*/
|
||||
~LockDoorsThread()
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* @brief thread loop. If time span is reach, execute callback and reset. Only one execution required
|
||||
*/
|
||||
void run()
|
||||
{
|
||||
while (m_running && m_counter <= m_timeIn100MilliSeconds)
|
||||
{
|
||||
m_counter++;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
if (m_counter > m_timeIn100MilliSeconds && m_callback)
|
||||
{
|
||||
m_callback();
|
||||
m_counter = 0;
|
||||
}
|
||||
m_running = false;
|
||||
}
|
||||
|
||||
std::function<void()> m_callback; ///< callback function
|
||||
std::atomic<bool> m_running; ///< status if loop is running
|
||||
std::thread m_thread; ///< timer thread
|
||||
uint32_t m_counter; ///< loop counter
|
||||
uint32_t m_timeIn100MilliSeconds; ///< time before the callback will be executed
|
||||
};
|
||||
|
||||
#endif // !define LOCK_DOORS_THREAD_H
|
||||
180
examples/door_demo_example/fmu_Doors2ExampleFMU/CMakeLists.txt
Normal file
180
examples/door_demo_example/fmu_Doors2ExampleFMU/CMakeLists.txt
Normal file
@@ -0,0 +1,180 @@
|
||||
|
||||
# @file CMakeLists.txt
|
||||
# This file is cmake project file.
|
||||
# This file was generated by the DBC utility from:
|
||||
# datalink_2doors_example.dbc
|
||||
# DBC file version: 1.0.0.1
|
||||
|
||||
|
||||
# Based on CMakeLists.txt from https://github.com/modelica/Reference-FMUs
|
||||
# only FMI 2.0, only CoSimulation
|
||||
# without fumsim
|
||||
|
||||
|
||||
# Only valid for Windows
|
||||
if ( WIN32 )
|
||||
|
||||
# Enforce CMake version 3.20 or newer needed for path function
|
||||
cmake_minimum_required (VERSION 3.20)
|
||||
|
||||
# Use new policy for project version settings and default warning level
|
||||
cmake_policy(SET CMP0048 NEW) # requires CMake 3.14
|
||||
cmake_policy(SET CMP0092 NEW) # requires CMake 3.15
|
||||
|
||||
project (Doors2ExampleFMUProject)
|
||||
|
||||
# Use C++17 support
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
# Library symbols are hidden by default
|
||||
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
|
||||
|
||||
# Set the SDV_FRAMEWORK_DEV_INCLUDE if not defined yet
|
||||
if (NOT DEFINED SDV_FRAMEWORK_DEV_INCLUDE)
|
||||
if (NOT DEFINED ENV{SDV_FRAMEWORK_DEV_INCLUDE})
|
||||
message( FATAL_ERROR "The environment variable SDV_FRAMEWORK_DEV_INCLUDE needs to be pointing to the SDV V-API development include files location!")
|
||||
endif()
|
||||
set (SDV_FRAMEWORK_DEV_INCLUDE "$ENV{SDV_FRAMEWORK_DEV_INCLUDE}")
|
||||
endif()
|
||||
|
||||
# Include link to export directory of SDV V-API development include files location
|
||||
include_directories(${SDV_FRAMEWORK_DEV_INCLUDE})
|
||||
set(VAPI_CORE_SDV_BINARY_DIR ${CMAKE_BINARY_DIR}/bin)
|
||||
set(MODEL_NAME Doors2ExampleFMU)
|
||||
set(TARGET_NAME ${MODEL_NAME})
|
||||
set(FMU_FULL_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/fmus/${MODEL_NAME}.fmu")
|
||||
|
||||
FUNCTION(cat IN_FILE OUT_FILE)
|
||||
file(READ ${IN_FILE} CONTENTS)
|
||||
file(APPEND ${OUT_FILE} "${CONTENTS}")
|
||||
ENDFUNCTION()
|
||||
|
||||
set(FMI_VERSION 2 CACHE STRING "FMI Version")
|
||||
set_property(CACHE FMI_VERSION PROPERTY STRINGS 2)
|
||||
|
||||
set(FMI_TYPE CS CACHE STRING "FMI Version")
|
||||
set_property(CACHE FMI_TYPE PROPERTY STRINGS CS)
|
||||
set(FMI_TYPE "")
|
||||
|
||||
set (FMI_PLATFORM win32)
|
||||
if ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
|
||||
set (FMI_PLATFORM win64)
|
||||
endif ()
|
||||
|
||||
SET(HEADERS
|
||||
${MODEL_NAME}/config.h
|
||||
include/cosimulation.h
|
||||
include/model.h
|
||||
)
|
||||
|
||||
SET(HEADERS
|
||||
${HEADERS}
|
||||
include/fmi2Functions.h
|
||||
include/fmi2FunctionTypes.h
|
||||
include/fmi2TypesPlatform.h
|
||||
)
|
||||
|
||||
SET(SOURCES
|
||||
${MODEL_NAME}/model.cpp
|
||||
src/fmi${FMI_VERSION}Functions.c
|
||||
src/cosimulation.c
|
||||
)
|
||||
|
||||
add_library(${TARGET_NAME} SHARED
|
||||
${HEADERS}
|
||||
${SOURCES}
|
||||
${MODEL_NAME}/FMI${FMI_VERSION}${FMI_TYPE}.xml
|
||||
${MODEL_NAME}/buildDescription.xml
|
||||
)
|
||||
|
||||
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/fmus)
|
||||
|
||||
set(FMU_BUILD_DIR temp/${MODEL_NAME})
|
||||
target_compile_definitions(${TARGET_NAME} PRIVATE
|
||||
FMI_VERSION=${FMI_VERSION}
|
||||
DISABLE_PREFIX
|
||||
)
|
||||
|
||||
#[[
|
||||
if (MSVC)
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
||||
else()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++ -static-libgcc")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc")
|
||||
endif()
|
||||
]]
|
||||
|
||||
target_compile_definitions(${TARGET_NAME} PRIVATE FMI_COSIMULATION)
|
||||
target_include_directories(${TARGET_NAME} PRIVATE include ${MODEL_NAME})
|
||||
target_link_libraries(${TARGET_NAME} Winmm Ws2_32 Rpcrt4.lib)
|
||||
|
||||
set_target_properties(${TARGET_NAME} PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${FMU_BUILD_DIR}/binaries/${FMI_PLATFORM}"
|
||||
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${FMU_BUILD_DIR}/binaries/${FMI_PLATFORM}"
|
||||
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${FMU_BUILD_DIR}/binaries/${FMI_PLATFORM}"
|
||||
LIBRARY_OUTPUT_DIRECTORY "${FMU_BUILD_DIR}/binaries/${FMI_PLATFORM}"
|
||||
LIBRARY_OUTPUT_DIRECTORY_DEBUG "${FMU_BUILD_DIR}/binaries/${FMI_PLATFORM}"
|
||||
LIBRARY_OUTPUT_DIRECTORY_RELEASE "${FMU_BUILD_DIR}/binaries/${FMI_PLATFORM}"
|
||||
ARCHIVE_OUTPUT_DIRECTORY "${FMU_BUILD_DIR}/binaries/${FMI_PLATFORM}"
|
||||
ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${FMU_BUILD_DIR}/binaries/${FMI_PLATFORM}"
|
||||
ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${FMU_BUILD_DIR}/binaries/${FMI_PLATFORM}"
|
||||
)
|
||||
|
||||
set_target_properties(${TARGET_NAME} PROPERTIES PREFIX "")
|
||||
set_target_properties(${TARGET_NAME} PROPERTIES OUTPUT_NAME ${MODEL_NAME})
|
||||
|
||||
# modelDescription.xml
|
||||
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/${MODEL_NAME}/FMI${FMI_VERSION}${FMI_TYPE}.xml
|
||||
"${FMU_BUILD_DIR}/modelDescription.xml"
|
||||
)
|
||||
|
||||
set(ARCHIVE_FILES "modelDescription.xml" "binaries")
|
||||
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${MODEL_NAME}/resources")
|
||||
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/${MODEL_NAME}/resources"
|
||||
"${FMU_BUILD_DIR}/resources/"
|
||||
)
|
||||
set(ARCHIVE_FILES ${ARCHIVE_FILES} "resources")
|
||||
endif()
|
||||
|
||||
# When windows robocopy command (using cmd.exe) is used to copy files its important to set the dependencies
|
||||
# to assure that the copy command is finished before the next custom action to avoid copy/file access failures
|
||||
|
||||
# Copy sdv binaries of this FMU
|
||||
set(DEST_DIR "${FMU_BUILD_DIR}/resources")
|
||||
set(SOURCE_DIR_EXAMPLES_BIN "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
|
||||
add_custom_target(copy_function_sdv_files_${TARGET_NAME} DEPENDS ${TARGET_NAME})
|
||||
add_custom_command(TARGET copy_function_sdv_files_${TARGET_NAME}
|
||||
COMMAND cmd /C "robocopy \"${SOURCE_DIR_EXAMPLES_BIN}\" \"${DEST_DIR}\" *.pdb *.sdv /NP /R:3 /W:5 || exit /b 0"
|
||||
COMMENT "Copying contents from ${SOURCE_DIR_EXAMPLES_BIN} to ${DEST_DIR}, include only *.pdb *.sdv files"
|
||||
)
|
||||
add_dependencies(copy_function_sdv_files_${TARGET_NAME} ${TARGET_NAME})
|
||||
|
||||
|
||||
|
||||
# Copy framework sdv binaries
|
||||
set(SOURCE_DIR_CORE_BIN "${SDV_FRAMEWORK_RUNTIME}")
|
||||
add_custom_target(copy_framework_sdv_files_${TARGET_NAME} DEPENDS copy_function_sdv_files_${TARGET_NAME})
|
||||
add_custom_command(TARGET copy_framework_sdv_files_${TARGET_NAME}
|
||||
COMMAND cmd /C "robocopy \"${SOURCE_DIR_CORE_BIN}\" \"${DEST_DIR}\" *.pdb *.sdv /NP /R:3 /W:5 || exit /b 0"
|
||||
COMMENT "Copying contents from ${SOURCE_DIR_CORE_BIN} to ${DEST_DIR}, include only *.pdb *.sdv files"
|
||||
)
|
||||
add_dependencies(copy_framework_sdv_files_${TARGET_NAME} copy_function_sdv_files_${TARGET_NAME})
|
||||
|
||||
|
||||
|
||||
# FMU content created, all files copied
|
||||
# to zip the files create a new target 'create_zip' which is build after all files have been copied
|
||||
add_custom_target(create_zip_${TARGET_NAME} ALL DEPENDS copy_framework_sdv_files_${TARGET_NAME} )
|
||||
add_custom_command(TARGET create_zip_${TARGET_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E tar "cfv" ${FMU_FULL_FILE_NAME} --format=zip ${ARCHIVE_FILES}
|
||||
WORKING_DIRECTORY ${FMU_BUILD_DIR}
|
||||
COMMENT "Creating ZIP ${FMU_FULL_FILE_NAME}"
|
||||
)
|
||||
add_dependencies(create_zip_${TARGET_NAME} copy_framework_sdv_files_${TARGET_NAME})
|
||||
|
||||
#TODO
|
||||
#add_dependencies(${TARGET_NAME} <add_cmake_target_this_depends_on>)
|
||||
endif ()
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<fmiModelDescription
|
||||
fmiVersion = "2.0"
|
||||
modelName = "Doors2ExampleFMU"
|
||||
guid = "945aa152-f9fd-4d02-add5-a4320d05c0ab"
|
||||
description = "TargetLink FMU for Doors2ExampleFMU"
|
||||
generationTool = "TargetLink was generated by the DBC utility: datalink_2doors_example.dbc"
|
||||
generationDateAndTime = "2025-09-06 15:15:34"
|
||||
variableNamingConvention = "structured"
|
||||
numberOfEventIndicators = "0">
|
||||
<CoSimulation
|
||||
modelIdentifier = "Doors2ExampleFMU"
|
||||
canHandleVariableCommunicationStepSize = "false"
|
||||
canGetAndSetFMUstate = "false"
|
||||
canSerializeFMUstate = "false"
|
||||
providesDirectionalDerivative = "false"
|
||||
canBeInstantiatedOnlyOncePerProcess = "true"
|
||||
canInterpolateInputs = "false"
|
||||
canRunAsynchronuously = "false">
|
||||
<SourceFiles>
|
||||
<File name="all.c"/>
|
||||
</SourceFiles>
|
||||
</CoSimulation>
|
||||
<DefaultExperiment startTime="0" stepSize="0.01"/>
|
||||
<ModelVariables>
|
||||
<!--Index for next variable = 1 -->
|
||||
<ScalarVariable name = "Door01LeftIsOpen"
|
||||
valueReference = "0"
|
||||
description = " "
|
||||
causality = "input">
|
||||
<Integer start = "0"
|
||||
min = "0u"
|
||||
max = "1u" />
|
||||
</ScalarVariable>
|
||||
<!--Index for next variable = 2 -->
|
||||
<ScalarVariable name = "Door01RightIsOpen"
|
||||
valueReference = "1"
|
||||
description = " "
|
||||
causality = "input">
|
||||
<Integer start = "0"
|
||||
min = "0u"
|
||||
max = "1u" />
|
||||
</ScalarVariable>
|
||||
<!--Index for next variable = 3 -->
|
||||
<ScalarVariable name = "LockDoor01Right"
|
||||
valueReference = "2"
|
||||
description = " "
|
||||
causality = "output">
|
||||
<Integer start = "0"
|
||||
min = "0u"
|
||||
max = "1u" />
|
||||
</ScalarVariable>
|
||||
<!--Index for next variable = 4 -->
|
||||
<ScalarVariable name = "LockDoor01Left"
|
||||
valueReference = "3"
|
||||
description = " "
|
||||
causality = "output">
|
||||
<Integer start = "0"
|
||||
min = "0u"
|
||||
max = "1u" />
|
||||
</ScalarVariable>
|
||||
|
||||
</ModelVariables>
|
||||
<ModelStructure>
|
||||
<Outputs>
|
||||
<Unknown index="0"/>
|
||||
</Outputs>
|
||||
</ModelStructure>
|
||||
</fmiModelDescription>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user