Skip to content

Commit

Permalink
Add wait time as FMI parameter
Browse files Browse the repository at this point in the history
Signed-off-by: ClemensLinnhoff <clemens.linnhoff@partner.bmw.de>
  • Loading branch information
ClemensLinnhoff committed Jan 17, 2024
1 parent b6f5f76 commit ec5e847
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ The following FMI parameters can be set.
Either `sender` or `receiver` have to be set to _true_.
Otherwise, the FMU will return with an error.

| Type | Parameter | Default | Description |
|---------|------------|-------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Boolean | `sender` | _true_ | Set if Proxy shall send data via TCP/IP |
| Boolean | `receiver` | _false_ | Set if Proxy shall receive data via TCP/IP |
| Boolean | `pushpull` | _false_ | If true, use [Push/Pull](https://learning-0mq-with-pyzmq.readthedocs.io/en/latest/pyzmq/patterns/pushpull.html) ZeroMQ configuration, if false, use [Client/Server](https://learning-0mq-with-pyzmq.readthedocs.io/en/latest/pyzmq/patterns/client_server.html) config. |
| String | `ip` | _127.0.0.1_ | IP address of TCP connection |
| String | `port` | _3456_ | Port of TCP connection |
| Type | Parameter | Default | Description |
|---------|------------------|-------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Boolean | `sender` | _true_ | Set if Proxy shall send data via TCP/IP |
| Boolean | `receiver` | _false_ | Set if Proxy shall receive data via TCP/IP |
| Boolean | `pushpull` | _false_ | If true, use [Push/Pull](https://learning-0mq-with-pyzmq.readthedocs.io/en/latest/pyzmq/patterns/pushpull.html) ZeroMQ configuration, if false, use [Client/Server](https://learning-0mq-with-pyzmq.readthedocs.io/en/latest/pyzmq/patterns/client_server.html) config. |
| String | `ip` | _127.0.0.1_ | IP address of TCP connection |
| String | `port` | _3456_ | Port of TCP connection |
| Integer | `wait_time_in_s` | _5_ | In Client/Server configuration: wait time to receive message after request. When the network proxy does not receive a message in this wait time, it will throw an error. If this is set to _0_, the network proxy will wait indefinitely. |

## Interface

Expand Down
15 changes: 11 additions & 4 deletions src/OSMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ fmi2Status OSMP::DoInit()
SetFmiPushPull(1);
SetFmiIp("127.0.0.1");
SetFmiPort("3456");
SetFmiWaitTime(5);

return fmi2OK;
}
Expand Down Expand Up @@ -167,8 +168,11 @@ fmi2Status OSMP::DoExitInitializationMode()
{
socket_ = zmq::socket_t(context_, ZMQ_REP);
}
const int wait_time_ms = 5000;
zmq_setsockopt(socket_, ZMQ_SNDTIMEO, &wait_time_ms, sizeof(wait_time_ms));
if (FmiWaitTime() > 0)
{
const int wait_time_ms = FmiWaitTime() * 1000;
zmq_setsockopt(socket_, ZMQ_SNDTIMEO, &wait_time_ms, sizeof(wait_time_ms));
}
socket_.bind(protocol);
}
else
Expand All @@ -181,8 +185,11 @@ fmi2Status OSMP::DoExitInitializationMode()
{
socket_ = zmq::socket_t(context_, ZMQ_REQ);
}
const int wait_time_ms = 5000;
zmq_setsockopt(socket_, ZMQ_RCVTIMEO, &wait_time_ms, sizeof(wait_time_ms));
if (FmiWaitTime() > 0)
{
const int wait_time_ms = FmiWaitTime() * 1000;
zmq_setsockopt(socket_, ZMQ_RCVTIMEO, &wait_time_ms, sizeof(wait_time_ms));
}
socket_.connect(protocol);
}

Expand Down
11 changes: 10 additions & 1 deletion src/OSMP.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
#define FMI_INTEGER_OSI_OUT_BASELO_IDX 3
#define FMI_INTEGER_OSI_OUT_BASEHI_IDX 4
#define FMI_INTEGER_OSI_OUT_SIZE_IDX 5
#define FMI_INTEGER_LAST_IDX FMI_INTEGER_OSI_OUT_SIZE_IDX
#define FMI_INTEGER_WAIT_TIME_IDX 6
#define FMI_INTEGER_LAST_IDX FMI_INTEGER_WAIT_TIME_IDX
#define FMI_INTEGER_VARS (FMI_INTEGER_LAST_IDX + 1)

/* Real Variables */
Expand Down Expand Up @@ -277,4 +278,12 @@ class OSMP
{
string_vars_[FMI_STRING_PORT_IDX] = value;
}
int FmiWaitTime()
{
return integer_vars_[FMI_INTEGER_WAIT_TIME_IDX];
}
void SetFmiWaitTime(fmi2Integer value)
{
integer_vars_[FMI_INTEGER_WAIT_TIME_IDX] = value;
}
};
3 changes: 3 additions & 0 deletions src/modelDescription.in.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
<ScalarVariable name="port" valueReference="1" causality="parameter" variability="fixed" initial="exact">
<String start="3456"/>
</ScalarVariable>
<ScalarVariable name="wait_time_in_s" valueReference="6" causality="parameter" variability="fixed" initial="exact">
<Integer start="5"/>
</ScalarVariable>
</ModelVariables>
<ModelStructure>
<Outputs>
Expand Down

0 comments on commit ec5e847

Please sign in to comment.