Skip to content

Commit 3960ed4

Browse files
committed
Improved how dynamic-sized parameters are handled
- The Coder implementation should get the real size from the RTW - The Simulink implementation should get the real size from the parameter parsed from the mask (this value actually is what is written to the RTW file later in the pipeline)
1 parent 44a5cfc commit 3960ed4

File tree

2 files changed

+49
-11
lines changed

2 files changed

+49
-11
lines changed

toolbox/src/base/CoderBlockInformation.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,17 +205,31 @@ bool CoderBlockInformation::parseParameters(wbt::Parameters& parameters)
205205
return false;
206206
}
207207

208-
for (wbt::ParameterMetadata md : pImpl->paramsMetadata) {
208+
for (wbt::ParameterMetadata& md : pImpl->paramsMetadata) {
209209
// Check that all the parameters that are parsed have already been stored from the coder
210210
if (!pImpl->parametersFromRTW.existName(md.name)) {
211211
wbtError << "Trying to get a parameter value for " << md.name
212212
<< ", but its value has never been stored.";
213213
return false;
214214
}
215-
// Check if the parameters are not dynamically sized
216-
if (!(md.rows == -1 || md.cols == -1)
217-
&& md != pImpl->parametersFromRTW.getParameterMetadata(md.name)) {
218-
wbtError << "Dynamically sized parameters are not supported.";
215+
216+
// Handle the case of dynamically sized columns. In this case the metadata passed
217+
// from the Block (containing DynamicSize) is modified with the length of the
218+
// vector that is going to be stored.
219+
if (md.cols == ParameterMetadata::DynamicSize) {
220+
const auto colsFromRTW = pImpl->parametersFromRTW.getParameterMetadata(md.name).cols;
221+
if (colsFromRTW == ParameterMetadata::DynamicSize) {
222+
wbtError << "Trying to store the cols of a dynamically sized parameters, but the "
223+
<< "metadata does not specify a valid size. Probably the block didn't "
224+
<< "updat the size in its initialization phase.";
225+
return false;
226+
}
227+
md.cols = colsFromRTW;
228+
}
229+
230+
if (md != pImpl->parametersFromRTW.getParameterMetadata(md.name)) {
231+
wbtError << "Trying to parse a parameter which metadata differs from the metadata "
232+
<< "stored by Simulink Coder.";
219233
return false;
220234
}
221235
}

toolbox/src/base/SimulinkBlockInformation.cpp

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,19 @@ bool SimulinkBlockInformation::parseParameters(wbt::Parameters& parameters)
489489
// Handle the case of dynamically sized columns. In this case the metadata passed
490490
// from the Block (containing DynamicSize) is modified with the length of the
491491
// vector that is going to be stored.
492+
// This is necessary in the pipeline for storing the metadata in the RTW file, which should
493+
// not have any dynamic size.
492494
const bool hasDynSizeColumns = (paramMD.cols == ParameterMetadata::DynamicSize);
495+
auto handleDynSizeColumns = [](int& sizeToUpdate, const int& realSize) -> const bool {
496+
if (realSize == ParameterMetadata::DynamicSize) {
497+
wbtError << "Trying to store the cols of a dynamically sized parameters, but the "
498+
<< "metadata does not specify a valid size. Probably the block didn't "
499+
<< "updat the size in its initialization phase.";
500+
return false;
501+
}
502+
sizeToUpdate = realSize;
503+
return true;
504+
};
493505

494506
switch (paramMD.type) {
495507
// SCALAR / VECTOR PARAMETERS
@@ -523,7 +535,9 @@ bool SimulinkBlockInformation::parseParameters(wbt::Parameters& parameters)
523535
return false;
524536
}
525537
if (hasDynSizeColumns) {
526-
paramMD.cols = paramVector.size();
538+
if (!handleDynSizeColumns(paramMD.cols, paramVector.size())) {
539+
return false;
540+
}
527541
}
528542
ok = parameters.storeParameter<double>(paramVector, paramMD);
529543
}
@@ -566,7 +580,9 @@ bool SimulinkBlockInformation::parseParameters(wbt::Parameters& parameters)
566580
paramVector.push_back(value);
567581
}
568582
if (hasDynSizeColumns) {
569-
paramMD.cols = paramVector.size();
583+
if (!handleDynSizeColumns(paramMD.cols, paramVector.size())) {
584+
return false;
585+
}
570586
}
571587
ok = parameters.storeParameter<double>(paramVector, paramMD);
572588
break;
@@ -588,7 +604,9 @@ bool SimulinkBlockInformation::parseParameters(wbt::Parameters& parameters)
588604
paramVector.push_back(value);
589605
}
590606
if (hasDynSizeColumns) {
591-
paramMD.cols = paramVector.size();
607+
if (!handleDynSizeColumns(paramMD.cols, paramVector.size())) {
608+
return false;
609+
}
592610
}
593611
ok = parameters.storeParameter<std::string>(paramVector, paramMD);
594612
break;
@@ -615,7 +633,9 @@ bool SimulinkBlockInformation::parseParameters(wbt::Parameters& parameters)
615633
return false;
616634
}
617635
if (hasDynSizeColumns) {
618-
paramMD.cols = paramVector.size();
636+
if (!handleDynSizeColumns(paramMD.cols, paramVector.size())) {
637+
return false;
638+
}
619639
}
620640
ok = parameters.storeParameter<double>(paramVector, paramMD);
621641
}
@@ -658,7 +678,9 @@ bool SimulinkBlockInformation::parseParameters(wbt::Parameters& parameters)
658678
paramVector.push_back(value);
659679
}
660680
if (hasDynSizeColumns) {
661-
paramMD.cols = paramVector.size();
681+
if (!handleDynSizeColumns(paramMD.cols, paramVector.size())) {
682+
return false;
683+
}
662684
}
663685
ok = parameters.storeParameter<double>(paramVector, paramMD);
664686
break;
@@ -682,7 +704,9 @@ bool SimulinkBlockInformation::parseParameters(wbt::Parameters& parameters)
682704
paramVector.push_back(value);
683705
}
684706
if (hasDynSizeColumns) {
685-
paramMD.cols = paramVector.size();
707+
if (!handleDynSizeColumns(paramMD.cols, paramVector.size())) {
708+
return false;
709+
}
686710
}
687711
ok = parameters.storeParameter<std::string>(paramVector, paramMD);
688712
break;

0 commit comments

Comments
 (0)