mirror of
https://github.com/eclipse-openvehicle-api/openvehicle-api.git
synced 2026-04-17 10:18:16 +00:00
62
examples/tasktimer_example/CMakeLists.txt
Normal file
62
examples/tasktimer_example/CMakeLists.txt
Normal file
@@ -0,0 +1,62 @@
|
||||
project(TaskTimerApp)
|
||||
|
||||
# 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)
|
||||
|
||||
# Define the executable
|
||||
add_executable(tasktimer_example
|
||||
src/tasktimer_example.cpp
|
||||
)
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
if (WIN32)
|
||||
target_link_libraries(tasktimer_example Ws2_32 Winmm Rpcrt4.lib)
|
||||
else()
|
||||
target_link_libraries(tasktimer_example ${CMAKE_DL_LIBS} rt ${CMAKE_THREAD_LIBS_INIT})
|
||||
endif()
|
||||
else()
|
||||
target_link_libraries(tasktimer_example Rpcrt4.lib)
|
||||
endif()
|
||||
|
||||
# Include link to export directory of SDV V-API development include files location
|
||||
include_directories(${SDV_FRAMEWORK_DEV_INCLUDE})
|
||||
|
||||
target_link_libraries(tasktimer_example
|
||||
${CMAKE_DL_LIBS}
|
||||
)
|
||||
|
||||
add_test(NAME tasktimer_example COMMAND tasktimer_example)
|
||||
|
||||
# Define the executable
|
||||
add_executable(simulation_tasktimer_example
|
||||
src/simulation_tasktimer_example.cpp
|
||||
)
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
if (WIN32)
|
||||
target_link_libraries(simulation_tasktimer_example Ws2_32 Winmm Rpcrt4.lib)
|
||||
else()
|
||||
target_link_libraries(simulation_tasktimer_example ${CMAKE_DL_LIBS} rt ${CMAKE_THREAD_LIBS_INIT})
|
||||
endif()
|
||||
else()
|
||||
target_link_libraries(simulation_tasktimer_example Rpcrt4.lib)
|
||||
endif()
|
||||
|
||||
# Include link to export directory of SDV V-API development include files location
|
||||
include_directories(${SDV_FRAMEWORK_DEV_INCLUDE})
|
||||
|
||||
|
||||
target_link_libraries(simulation_tasktimer_example
|
||||
${CMAKE_DL_LIBS}
|
||||
)
|
||||
|
||||
add_test(NAME simulation_tasktimer_example COMMAND simulation_tasktimer_example)
|
||||
|
||||
# Copy the config files
|
||||
file (COPY ${PROJECT_SOURCE_DIR}/config/test_config_task_timer.toml DESTINATION ${CMAKE_BINARY_DIR}/bin/config)
|
||||
file (COPY ${PROJECT_SOURCE_DIR}/config/test_config_simulation_task_timer.toml DESTINATION ${CMAKE_BINARY_DIR}/bin/config)
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
[Configuration]
|
||||
Version = 100
|
||||
|
||||
[[Component]]
|
||||
Path = "simulation_task_timer.sdv"
|
||||
Class = "SimulationTaskTimerService"
|
||||
|
||||
[[Component]]
|
||||
Path = "tasktimer_component_example.sdv"
|
||||
Class = "Timer_Example"
|
||||
Timer = 175
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
[Configuration]
|
||||
Version = 100
|
||||
|
||||
[[Component]]
|
||||
Path = "task_timer.sdv"
|
||||
Class = "TaskTimerService"
|
||||
|
||||
[[Component]]
|
||||
Path = "tasktimer_component_example.sdv"
|
||||
Class = "Timer_Example"
|
||||
Timer = 175
|
||||
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <chrono>
|
||||
#include <support/timer.h>
|
||||
#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_config_simulation_task_timer.toml") == sdv::core::EConfigProcessResult::successful;
|
||||
|
||||
if (!bResult)
|
||||
{
|
||||
std::cout << "Exit, Could not load task timer component." << std::endl;
|
||||
appcontrol.Shutdown();
|
||||
}
|
||||
|
||||
appcontrol.SetRunningMode();
|
||||
|
||||
// Get the task timer service.
|
||||
sdv::core::ITimerSimulationStep* pTimerSimulationStep = sdv::core::GetObject<sdv::core::ITimerSimulationStep>("SimulationTaskTimerService");
|
||||
if (!pTimerSimulationStep)
|
||||
{
|
||||
std::cout << "---------------------- Error, Timer step not available " << std::endl;
|
||||
}
|
||||
|
||||
//run for 3 seconds - in that time task timer callbacks in the module get triggered
|
||||
uint32_t counter = 2000;
|
||||
std::chrono::milliseconds sleepDuration (5);
|
||||
while (counter-- > 0)
|
||||
{
|
||||
if (counter % 20 == 1)
|
||||
std::cout << "counter: " << std::to_string(counter) << std::endl;
|
||||
if (pTimerSimulationStep)
|
||||
{
|
||||
pTimerSimulationStep->SimulationStep(1000);
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(sleepDuration);
|
||||
}
|
||||
|
||||
appcontrol.Shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
||||
60
examples/tasktimer_example/src/tasktimer_example.cpp
Normal file
60
examples/tasktimer_example/src/tasktimer_example.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <chrono>
|
||||
#include <support/timer.h>
|
||||
#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_config_task_timer.toml") == sdv::core::EConfigProcessResult::successful;
|
||||
|
||||
if (!bResult)
|
||||
{
|
||||
std::cout << "Exit, Could not load task timer component." << std::endl;
|
||||
appcontrol.Shutdown();
|
||||
}
|
||||
|
||||
appcontrol.SetRunningMode();
|
||||
|
||||
//run for 10 seconds - in that time task timer callbacks in the module get triggered
|
||||
uint32_t counter = 10;
|
||||
std::chrono::seconds sleepDurtaion (1);
|
||||
while (counter-- > 0)
|
||||
{
|
||||
std::cout << "counter: " << std::to_string(counter) << std::endl;
|
||||
std::this_thread::sleep_for(sleepDurtaion);
|
||||
}
|
||||
|
||||
appcontrol.Shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user