@@ -38,7 +38,7 @@ class mock_slave : public cosim::slave
38
38
std::function<double (cosim::time_point, cosim::duration, double )> realOp = nullptr,
39
39
std::function<int(cosim::time_point, cosim::duration, int )> intOp = nullptr,
40
40
std::function<bool(cosim::time_point, cosim::duration, bool )> boolOp = nullptr,
41
- std::function<std::string(cosim::time_point, cosim::duration, std::string_view)> stringOp = nullptr,
41
+ std::function<std::string(cosim::time_point, cosim::duration, std::string_view)> stringOp = nullptr,
42
42
std::function<void(cosim::time_point, cosim::duration)> stepAction = nullptr)
43
43
: realOp_(std::move(realOp))
44
44
, intOp_(std::move(intOp))
@@ -71,7 +71,6 @@ class mock_slave : public cosim::slave
71
71
return [op = std::move (timeIndependentOp)](cosim::time_point, cosim::duration, T... value) { return op (value...); };
72
72
}
73
73
74
-
75
74
cosim::model_description model_description () const override
76
75
{
77
76
cosim::model_description md;
@@ -106,7 +105,8 @@ class mock_slave : public cosim::slave
106
105
107
106
cosim::step_result do_step (cosim::time_point currentT, cosim::duration deltaT) override
108
107
{
109
- if (stepAction_) stepAction_ (currentT);
108
+ state_.currentStepSize = deltaT;
109
+ if (stepAction_) stepAction_ (currentT, deltaT);
110
110
state_.currentTime = currentT + deltaT;
111
111
return cosim::step_result::complete;
112
112
}
@@ -117,7 +117,7 @@ class mock_slave : public cosim::slave
117
117
{
118
118
for (std::size_t i = 0 ; i < variables.size (); ++i) {
119
119
if (variables[i] == real_out_reference) {
120
- values[i] = realOp_ ? realOp_ (state_.currentTime , state_.realIn ) : state_.realIn ;
120
+ values[i] = realOp_ ? realOp_ (state_.currentTime , state_.currentStepSize , state_. realIn ) : state_.realIn ;
121
121
} else if (variables[i] == real_in_reference) {
122
122
values[i] = state_.realIn ;
123
123
} else {
@@ -132,7 +132,7 @@ class mock_slave : public cosim::slave
132
132
{
133
133
for (std::size_t i = 0 ; i < variables.size (); ++i) {
134
134
if (variables[i] == integer_out_reference) {
135
- values[i] = intOp_ ? intOp_ (state_.currentTime , state_.intIn ) : state_.intIn ;
135
+ values[i] = intOp_ ? intOp_ (state_.currentTime , state_.currentStepSize , state_. intIn ) : state_.intIn ;
136
136
} else if (variables[i] == integer_in_reference) {
137
137
values[i] = state_.intIn ;
138
138
} else {
@@ -147,7 +147,7 @@ class mock_slave : public cosim::slave
147
147
{
148
148
for (std::size_t i = 0 ; i < variables.size (); ++i) {
149
149
if (variables[i] == boolean_out_reference) {
150
- values[i] = boolOp_ ? boolOp_ (state_.currentTime , state_.boolIn ) : state_.boolIn ;
150
+ values[i] = boolOp_ ? boolOp_ (state_.currentTime , state_.currentStepSize , state_. boolIn ) : state_.boolIn ;
151
151
} else if (variables[i] == boolean_in_reference) {
152
152
values[i] = state_.boolIn ;
153
153
} else {
@@ -162,7 +162,7 @@ class mock_slave : public cosim::slave
162
162
{
163
163
for (std::size_t i = 0 ; i < variables.size (); ++i) {
164
164
if (variables[i] == string_out_reference) {
165
- values[i] = stringOp_ ? stringOp_ (state_.currentTime , state_.stringIn ) : state_.stringIn ;
165
+ values[i] = stringOp_ ? stringOp_ (state_.currentTime , state_.currentStepSize , state_. stringIn ) : state_.stringIn ;
166
166
} else if (variables[i] == string_in_reference) {
167
167
values[i] = state_.stringIn ;
168
168
} else {
@@ -248,7 +248,8 @@ class mock_slave : public cosim::slave
248
248
{
249
249
const auto & ss = savedStates_.at (state);
250
250
cosim::serialization::node es;
251
- es.put (" currentTime" , ss.currentTime .time_since_epoch ().count ());
251
+ es.put (" currentTime" , cosim::to_double_time_point (ss.currentTime ));
252
+ es.put (" currentStepSize" , cosim::to_double_duration (ss.currentStepSize , ss.currentTime ));
252
253
es.put (" realIn" , ss.realIn );
253
254
es.put (" intIn" , ss.intIn );
254
255
es.put (" boolIn" , ss.boolIn );
@@ -259,8 +260,8 @@ class mock_slave : public cosim::slave
259
260
state_index import_state (const cosim::serialization::node& exportedState) override
260
261
{
261
262
state ss;
262
- ss.currentTime = cosim::time_point (cosim::time_point::duration (
263
- exportedState.get <cosim::time_point::rep >(" currentTime " ) ));
263
+ ss.currentTime = cosim::time_point (cosim::time_point::duration (exportedState. get <cosim::time_point::rep>( " currentTime " )));
264
+ ss. currentStepSize = cosim::to_duration ( exportedState.get <double >(" currentStepSize " ));
264
265
ss.realIn = exportedState.get <decltype (ss.realIn )>(" realIn" );
265
266
ss.intIn = exportedState.get <decltype (ss.intIn )>(" intIn" );
266
267
ss.boolIn = exportedState.get <decltype (ss.boolIn )>(" boolIn" );
@@ -279,6 +280,7 @@ class mock_slave : public cosim::slave
279
280
struct state
280
281
{
281
282
cosim::time_point currentTime;
283
+ cosim::duration currentStepSize{1000 };
282
284
283
285
double realIn = 0.0 ;
284
286
int intIn = 0 ;
0 commit comments