Skip to content

Commit 697cc33

Browse files
authored
implement fmi2GetBooleanStatus (#244)
also return fmi2Discard, not fmi2Error on fmi2GetXXXStatus
1 parent f93c9ad commit 697cc33

File tree

1 file changed

+19
-16
lines changed
  • pythonfmu/pythonfmu-export/src/pythonfmu

1 file changed

+19
-16
lines changed

pythonfmu/pythonfmu-export/src/pythonfmu/fmi2.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,10 @@ struct Fmi2Component
4444
{ }
4545

4646
double lastSuccessfulTime{0};
47+
bool wantsToTerminate{false};
4748

4849
std::unique_ptr<pythonfmu::SlaveInstance> slave;
4950
std::unique_ptr<Fmi2Logger> logger;
50-
51-
double start{0};
52-
std::optional<double> stop;
53-
std::optional<double> tolerance;
5451
};
5552

5653
} // namespace
@@ -165,7 +162,7 @@ fmi2Status fmi2SetupExperiment(
165162
stopTimeDefined ? std::optional(stopTime) : std::nullopt,
166163
toleranceDefined ? std::optional(tolerance) : std::nullopt);
167164
return fmi2OK;
168-
}catch (const pythonfmu::fatal_error& e) {
165+
} catch (const pythonfmu::fatal_error& e) {
169166
component->logger->log(fmi2Fatal, e.what());
170167
return fmi2Fatal;
171168
} catch (const std::exception& e) {
@@ -564,6 +561,7 @@ fmi2Status fmi2DoStep(
564561
}
565562

566563
component->lastSuccessfulTime = endTime;
564+
component->wantsToTerminate = true;
567565
return fmi2Discard;
568566
} catch (const pythonfmu::fatal_error& e) {
569567
component->logger->log(fmi2Fatal, e.what());
@@ -606,9 +604,9 @@ fmi2Status fmi2GetRealStatus(
606604
return fmi2OK;
607605
} else {
608606
component->logger->log(
609-
fmi2Error,
607+
fmi2Discard,
610608
"Invalid status inquiry for fmi2GetRealStatus");
611-
return fmi2Error;
609+
return fmi2Discard;
612610
}
613611
}
614612

@@ -618,19 +616,24 @@ fmi2Status fmi2GetIntegerStatus(
618616
fmi2Integer*)
619617
{
620618
static_cast<Fmi2Component*>(c)->logger->log(
621-
fmi2Error,
619+
fmi2Discard,
622620
"FMI function not supported: fmi2GetIntegerStatus");
623-
return fmi2Error;
621+
return fmi2Discard;
624622
}
625623

626624
fmi2Status fmi2GetBooleanStatus(
627625
fmi2Component c,
628-
const fmi2StatusKind,
629-
fmi2Boolean*)
626+
const fmi2StatusKind s,
627+
fmi2Boolean* value)
630628
{
631-
static_cast<Fmi2Component*>(c)->logger->log(
632-
fmi2Error, "FMI function not supported: fmi2GetBooleanStatus");
633-
return fmi2Error;
629+
const auto component = static_cast<Fmi2Component*>(c);
630+
if (s == fmi2Terminated) {
631+
*value = component->wantsToTerminate ? fmi2True : fmi2False;
632+
return fmi2OK;
633+
}
634+
component->logger->log(
635+
fmi2Discard, "FMI function not supported: fmi2GetBooleanStatus");
636+
return fmi2Discard;
634637
}
635638

636639
fmi2Status fmi2GetStringStatus(
@@ -639,7 +642,7 @@ fmi2Status fmi2GetStringStatus(
639642
fmi2String*)
640643
{
641644
static_cast<Fmi2Component*>(c)->logger->log(
642-
fmi2Error, "FMI function not supported: fmi2GetStringStatus");
643-
return fmi2Error;
645+
fmi2Discard, "FMI function not supported: fmi2GetStringStatus");
646+
return fmi2Discard;
644647
}
645648
}

0 commit comments

Comments
 (0)