Skip to content

Commit 4c65c46

Browse files
committed
Merge branch 'master' into examples
2 parents dc6b25f + 6275410 commit 4c65c46

3 files changed

Lines changed: 37 additions & 8 deletions

File tree

export/include/fmu4cpp/fmu_base.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ namespace fmu4cpp {
131131
void get_boolean(const unsigned int vr[], size_t nvr, bool value[]) const;
132132

133133
void get_string(const unsigned int vr[], size_t nvr, const char *value[]);
134+
void get_binary(const unsigned int vr[], size_t nvr, size_t valueSizes[], const uint8_t *values[]);
135+
134136
void set_integer(const unsigned int vr[], size_t nvr, const int value[]);
135137
void set_real(const unsigned int vr[], size_t nvr, const double value[]);
136138

@@ -228,7 +230,7 @@ namespace fmu4cpp {
228230
std::unordered_map<unsigned int, size_t> vrToStringIndices_;
229231

230232
std::vector<BinaryVariable> binary_;
231-
std::vector<std::string> binaryBuffer_;
233+
std::vector<std::vector<uint8_t>> binaryBuffer_;
232234
std::unordered_map<unsigned int, size_t> vrToBinaryIndices_;
233235

234236
std::function<void *(void *)> get_state_ptr_{nullptr};

export/src/fmu4cpp/fmi3/fmi3.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,16 +517,26 @@ fmi3Status fmi3SetString(
517517
}
518518

519519
fmi3Status fmi3GetBinary(fmi3Instance c,
520-
const fmi3ValueReference valueReferences[],
520+
const fmi3ValueReference vr[],
521521
size_t nvr,
522522
size_t valueSizes[],
523523
fmi3Binary values[],
524524
size_t nValues) {
525525

526526
const auto component = static_cast<Fmi3Component *>(c);
527527

528-
component->logger->log(fmiError, "Unsupported function fmi3GetBinary");
529-
return fmi3Error;
528+
try {
529+
component->slave->get_binary(vr, nvr, valueSizes, values);
530+
return fmi3OK;
531+
} catch (const fmu4cpp::fatal_error &ex) {
532+
component->logger->log(fmiFatal, ex.what());
533+
component->state = Fmi3Component::State::Invalid;
534+
return fmi3Fatal;
535+
} catch (const std::exception &ex) {
536+
component->logger->log(fmiError, ex.what());
537+
component->state = Fmi3Component::State::Terminated;
538+
return fmi3Error;
539+
}
530540
}
531541

532542
fmi3Status fmi3SetBinary(fmi3Instance c,

export/src/fmu4cpp/fmu_base.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,43 +106,61 @@ void fmu_base::get_integer(const unsigned int vr[], size_t nvr, int value[]) con
106106
value[i] = integers_[idx].get();
107107
}
108108
}
109+
109110
void fmu_base::get_real(const unsigned int vr[], size_t nvr, double value[]) const {
110111
for (unsigned i = 0; i < nvr; i++) {
111112
const auto ref = vr[i];
112113
const auto idx = vrToRealIndices_.at(ref);
113114
value[i] = reals_[idx].get();
114115
}
115116
}
117+
116118
void fmu_base::get_boolean(const unsigned int vr[], size_t nvr, int value[]) const {
117119
for (unsigned i = 0; i < nvr; i++) {
118120
const auto ref = vr[i];
119121
const auto idx = vrToBooleanIndices_.at(ref);
120122
value[i] = static_cast<int>(booleans_[idx].get());
121123
}
122124
}
125+
123126
void fmu_base::get_boolean(const unsigned int vr[], size_t nvr, bool value[]) const {
124127
for (unsigned i = 0; i < nvr; i++) {
125128
const auto ref = vr[i];
126129
const auto idx = vrToBooleanIndices_.at(ref);
127130
value[i] = booleans_[idx].get();
128131
}
129132
}
133+
130134
void fmu_base::get_string(const unsigned int vr[], size_t nvr, const char *value[]) {
131135
stringBuffer_.clear();
132136
for (unsigned i = 0; i < nvr; i++) {
133137
const auto ref = vr[i];
134138
const auto idx = vrToStringIndices_.at(ref);
135-
stringBuffer_.push_back(strings_[idx].get());
139+
stringBuffer_.emplace_back(strings_[idx].get());
136140
value[i] = stringBuffer_.back().c_str();
137141
}
138142
}
143+
144+
void fmu_base::get_binary(const unsigned int vr[], size_t nvr, size_t valueSizes[], const uint8_t *values[]) {
145+
binaryBuffer_.clear();
146+
for (auto i = 0; i < nvr; i++) {
147+
const auto ref = vr[i];
148+
const auto idx = vrToBinaryIndices_.at(ref);
149+
const auto &data = binary_[idx].get();
150+
valueSizes[i] = data.size();
151+
binaryBuffer_.emplace_back(data.begin(), data.end());
152+
values[i] = binaryBuffer_.back().data();
153+
}
154+
}
155+
139156
void fmu_base::set_integer(const unsigned int vr[], size_t nvr, const int value[]) {
140157
for (unsigned i = 0; i < nvr; i++) {
141158
const auto ref = vr[i];
142159
const auto idx = vrToIntegerIndices_.at(ref);
143160
integers_[idx].set(value[i]);
144161
}
145162
}
163+
146164
void fmu_base::set_real(const unsigned int vr[], size_t nvr, const double value[]) {
147165
for (unsigned i = 0; i < nvr; i++) {
148166
const auto ref = vr[i];
@@ -164,17 +182,16 @@ void fmu_base::set_boolean(const unsigned int vr[], size_t nvr, const bool value
164182
booleans_[idx].set(value[i]);
165183
}
166184
}
185+
167186
void fmu_base::set_string(const unsigned int vr[], size_t nvr, const char *const value[]) {
168187
for (unsigned i = 0; i < nvr; i++) {
169188
const auto ref = vr[i];
170189
const auto idx = vrToStringIndices_.at(ref);
171190
strings_[idx].set(value[i]);
172191
}
173192
}
193+
174194
void fmu_base::set_binary(const unsigned int vr[], size_t nvr, const size_t valueSizes[], const uint8_t *const value[]) {
175-
#ifdef FMI2
176-
static_assert("set_binary not available for FMI2");
177-
#endif
178195

179196
for (unsigned i = 0; i < nvr; i++) {
180197
const auto ref = vr[i];

0 commit comments

Comments
 (0)