Skip to content

Commit

Permalink
Add trace_name as an additional FMI parameter
Browse files Browse the repository at this point in the history
Signed-off-by: ClemensLinnhoff <[email protected]>
  • Loading branch information
ClemensLinnhoff committed Aug 2, 2024
1 parent 172af96 commit 20570a6
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 14 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 12 additions & 7 deletions src/OSMPTraceFilePlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<fs::directory_entry> 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<fs::directory_entry> 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_");
Expand Down
5 changes: 3 additions & 2 deletions src/OSMPTraceFilePlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <iostream>
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/modelDescription.in.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@
<ScalarVariable name="valid" valueReference="0" causality="output" variability="discrete" initial="exact">
<Boolean start="false"/>
</ScalarVariable>
<ScalarVariable name="count" valueReference="3" causality="output" variability="discrete" initial="exact">
<Integer start="0"/>
</ScalarVariable>
<ScalarVariable name="trace_path" valueReference="0" causality="parameter" variability="fixed">
<String start=""/>
</ScalarVariable>
<ScalarVariable name="trace_name" valueReference="1" causality="parameter" variability="fixed">
<String start=""/>
</ScalarVariable>
</ModelVariables>
<ModelStructure>
<Outputs>
Expand Down

0 comments on commit 20570a6

Please sign in to comment.