From 20570a6b630632b66aa178d7f17d1e2e4a1bb731 Mon Sep 17 00:00:00 2001 From: ClemensLinnhoff Date: Fri, 2 Aug 2024 10:18:54 +0200 Subject: [PATCH] Add trace_name as an additional FMI parameter Signed-off-by: ClemensLinnhoff --- CMakeLists.txt | 4 ++-- README.md | 11 +++++++++++ src/OSMPTraceFilePlayer.cpp | 19 ++++++++++++------- src/OSMPTraceFilePlayer.h | 5 +++-- src/modelDescription.in.xml | 6 +++--- 5 files changed, 31 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 695947e..ccf22ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,8 +4,8 @@ project(OSMPTraceFilePlayer) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(LINK_WITH_SHARED_OSI OFF CACHE BOOL "Link FMU with shared OSI library instead of statically linking") -set(PUBLIC_LOGGING_TRACE_FILE_PLAYER OFF CACHE BOOL "Enable logging via FMI logger") -set(PRIVATE_LOGGING_TRACE_FILE_PLAYER OFF CACHE BOOL "Enable private logging to file") +set(PUBLIC_LOGGING_TRACE_FILE_PLAYER ON CACHE BOOL "Enable logging via FMI logger") +set(PRIVATE_LOGGING_TRACE_FILE_PLAYER ON CACHE BOOL "Enable private logging to file") set(VERBOSE_FMI_LOGGING_TRACE_FILE_PLAYER OFF CACHE BOOL "Enable detailed FMI function logging") set(DEBUG_BREAKS_TRACE_FILE_PLAYER OFF CACHE BOOL "Enable debugger traps for debug builds of FMU") diff --git a/README.md b/README.md index 4d08dca..4c47b24 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,17 @@ The trace file player is build according to the [ASAM Open simulation Interface An exemplary trace file is available in folder _trace_file_examples_. +## Parameterization + +The following FMI parameters can be set. +At least the trace_path has to be set. +Otherwise, the FMU will return with an error. + +| Type | Parameter | Default | Description | +|--------|--------------|---------|---------------------------------------------------------------------------------------------------------------| +| String | `trace_path` | _""_ | Path to the directory containing one or more OSI trace files | +| String | `trace_name` | _""_ | Filename of the trace file to be played. If empty, the first OSI trace file in the given directory is played. | + ## Installation ### Dependencies diff --git a/src/OSMPTraceFilePlayer.cpp b/src/OSMPTraceFilePlayer.cpp index fade821..29b3d73 100644 --- a/src/OSMPTraceFilePlayer.cpp +++ b/src/OSMPTraceFilePlayer.cpp @@ -218,14 +218,19 @@ fmi2Status COSMPTraceFilePlayer::DoCalc(fmi2Real current_communication_point, fm NormalLog("OSI", "Playing binary SensorView at %f for %f (step size %f)", current_communication_point, time, communication_step_size); - // Get first .osi file fs::path dir = FmiTracePath(); - std::vector entries; - fs::directory_iterator di(dir); - fs::directory_iterator end; - std::copy_if(di, end, std::back_inserter(entries), - file_extension_is(".osi")); - std::string binary_file_name = entries.begin()->path().string(); + string binary_file_name = dir / FmiTraceName(); + + if (binary_file_name.empty()) + { + // Get first .osi file in directory + std::vector entries; + fs::directory_iterator di(dir); + fs::directory_iterator end; + std::copy_if(di, end, std::back_inserter(entries), + file_extension_is(".osi")); + binary_file_name = entries.begin()->path().string(); + } std::size_t sv_found = binary_file_name.find("_sv_"); std::size_t sd_found = binary_file_name.find("_sd_"); diff --git a/src/OSMPTraceFilePlayer.h b/src/OSMPTraceFilePlayer.h index c9600ce..78fa888 100644 --- a/src/OSMPTraceFilePlayer.h +++ b/src/OSMPTraceFilePlayer.h @@ -60,7 +60,8 @@ namespace fs = std::experimental::filesystem; /* String Variables */ #define FMI_STRING_TRACE_PATH_IDX 0 -#define FMI_STRING_LAST_IDX FMI_STRING_TRACE_PATH_IDX +#define FMI_STRING_TRACE_NAME_IDX 1 +#define FMI_STRING_LAST_IDX FMI_STRING_TRACE_NAME_IDX #define FMI_STRING_VARS (FMI_STRING_LAST_IDX+1) #include @@ -229,7 +230,7 @@ class COSMPTraceFilePlayer fmi2Integer FmiCount() { return integer_vars_[FMI_INTEGER_COUNT_IDX]; } void SetFmiCount(fmi2Integer value) { integer_vars_[FMI_INTEGER_COUNT_IDX] = value; } string FmiTracePath() { return string_vars_[FMI_STRING_TRACE_PATH_IDX]; } - void SetFmiTracePath(string value) { string_vars_[FMI_STRING_TRACE_PATH_IDX] = value; } + string FmiTraceName() { return string_vars_[FMI_STRING_TRACE_NAME_IDX]; } /* Protocol Buffer Accessors */ void SetFmiSensorViewOut(const osi3::SensorView &data); diff --git a/src/modelDescription.in.xml b/src/modelDescription.in.xml index 9c5fc4d..0ae5c80 100644 --- a/src/modelDescription.in.xml +++ b/src/modelDescription.in.xml @@ -49,12 +49,12 @@ - - - + + +