Skip to content

Commit

Permalink
- fmiSetString should work the same as fmiSetReal/Integer/Boolean.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@23682 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Dec 6, 2014
1 parent f996240 commit bbf0177
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 45 deletions.
40 changes: 23 additions & 17 deletions Compiler/Template/CodegenFMU.tpl
Expand Up @@ -762,6 +762,7 @@ case SIMCODE(__) then
fmi2Boolean getBoolean(ModelInstance* comp, const fmi2ValueReference vr);
fmi2Status setBoolean(ModelInstance* comp, const fmi2ValueReference vr, const fmi2Boolean value);
fmi2String getString(ModelInstance* comp, const fmi2ValueReference vr);
fmi2Status setString(ModelInstance* comp, const fmi2ValueReference vr, fmi2String value);
fmi2Status setExternalFunction(ModelInstance* c, const fmi2ValueReference vr, const void* value);
>>
else
Expand All @@ -774,6 +775,7 @@ case SIMCODE(__) then
fmiBoolean getBoolean(ModelInstance* comp, const fmiValueReference vr);
fmiStatus setBoolean(ModelInstance* comp, const fmiValueReference vr, const fmiBoolean value);
fmiString getString(ModelInstance* comp, const fmiValueReference vr);
fmiStatus setString(ModelInstance* comp, const fmiValueReference vr, fmiString value);
fmiStatus setExternalFunction(ModelInstance* c, const fmiValueReference vr, const void* value);
>>
%>
Expand All @@ -800,6 +802,7 @@ case SIMCODE(__) then
<%getBooleanFunction2(modelInfo)%>
<%setBooleanFunction2(modelInfo)%>
<%getStringFunction2(modelInfo)%>
<%setStringFunction2(modelInfo)%>
<%setExternalFunction2(modelInfo)%>
>>
else
Expand All @@ -812,6 +815,7 @@ case SIMCODE(__) then
<%getBooleanFunction(modelInfo)%>
<%setBooleanFunction(modelInfo)%>
<%getStringFunction(modelInfo)%>
<%setStringFunction(modelInfo)%>
<%setExternalFunction(modelInfo)%>
>>
%>
Expand Down Expand Up @@ -1100,7 +1104,7 @@ case MODELINFO(vars=SIMVARS(__),varInfo=VARINFO(numStateVars=numStateVars, numAl
end setRealFunction;

template getIntegerFunction(ModelInfo modelInfo)
"Generates setInteger function for c file."
"Generates getInteger function for c file."
::=
match modelInfo
case MODELINFO(vars=SIMVARS(__)) then
Expand Down Expand Up @@ -1137,7 +1141,7 @@ case MODELINFO(vars=SIMVARS(__)) then
end setIntegerFunction;

template getBooleanFunction(ModelInfo modelInfo)
"Generates setBoolean function for c file."
"Generates getBoolean function for c file."
::=
match modelInfo
case MODELINFO(vars=SIMVARS(__)) then
Expand All @@ -1148,7 +1152,7 @@ case MODELINFO(vars=SIMVARS(__)) then
<%vars.boolParamVars |> var => SwitchParameters(var, "booleanParameter") ;separator="\n"%>
<%vars.boolAliasVars |> var => SwitchAliasVars(var, "Boolean", "!") ;separator="\n"%>
default:
return 0;
return fmiFalse;
}
}

Expand Down Expand Up @@ -1176,7 +1180,7 @@ case MODELINFO(vars=SIMVARS(__)) then
end setBooleanFunction;

template getStringFunction(ModelInfo modelInfo)
"Generates setString function for c file."
"Generates getString function for c file."
::=
match modelInfo
case MODELINFO(vars=SIMVARS(__)) then
Expand All @@ -1187,7 +1191,7 @@ case MODELINFO(vars=SIMVARS(__)) then
<%vars.stringParamVars |> var => SwitchParameters(var, "stringParameter") ;separator="\n"%>
<%vars.stringAliasVars |> var => SwitchAliasVars(var, "string", "") ;separator="\n"%>
default:
return 0;
return "";
}
}

Expand All @@ -1200,21 +1204,22 @@ template setStringFunction(ModelInfo modelInfo)
match modelInfo
case MODELINFO(vars=SIMVARS(__)) then
<<
fmiString getString(ModelInstance* comp, const fmiValueReference vr) {
fmiStatus setString(ModelInstance* comp, const fmiValueReference vr, fmiString value) {
switch (vr) {
<%vars.stringAlgVars |> var => SwitchVarsSet(var, "stringVars", 0) ;separator="\n"%>
<%vars.stringParamVars |> var => SwitchParametersSet(var, "stringParameter") ;separator="\n"%>
<%vars.stringAliasVars |> var => SwitchAliasVarsSet(var, "String", "") ;separator="\n"%>
default:
return 0;
return fmiError;
}
return fmiOK;
}

>>
end setStringFunction;

template setExternalFunction(ModelInfo modelInfo)
"Generates setString function for c file."
"Generates setExternal function for c file."
::=
match modelInfo
case MODELINFO(vars=SIMVARS(__)) then
Expand Down Expand Up @@ -1309,7 +1314,7 @@ case MODELINFO(vars=SIMVARS(__)) then
end getIntegerFunction2;

template setIntegerFunction2(ModelInfo modelInfo)
"Generates setInteger function for c file."
"Generates getInteger function for c file."
::=
match modelInfo
case MODELINFO(vars=SIMVARS(__)) then
Expand Down Expand Up @@ -1339,15 +1344,15 @@ case MODELINFO(vars=SIMVARS(__)) then
<%vars.boolParamVars |> var => SwitchParameters(var, "booleanParameter") ;separator="\n"%>
<%vars.boolAliasVars |> var => SwitchAliasVars(var, "Boolean", "!") ;separator="\n"%>
default:
return 0;
return fmi2False;
}
}

>>
end getBooleanFunction2;

template setBooleanFunction2(ModelInfo modelInfo)
"Generates setBoolean function for c file."
"Generates getBoolean function for c file."
::=
match modelInfo
case MODELINFO(vars=SIMVARS(__)) then
Expand All @@ -1367,7 +1372,7 @@ case MODELINFO(vars=SIMVARS(__)) then
end setBooleanFunction2;

template getStringFunction2(ModelInfo modelInfo)
"Generates setString function for c file."
"Generates getString function for c file."
::=
match modelInfo
case MODELINFO(vars=SIMVARS(__)) then
Expand All @@ -1378,7 +1383,7 @@ case MODELINFO(vars=SIMVARS(__)) then
<%vars.stringParamVars |> var => SwitchParameters(var, "stringParameter") ;separator="\n"%>
<%vars.stringAliasVars |> var => SwitchAliasVars(var, "string", "") ;separator="\n"%>
default:
return 0;
return "";
}
}

Expand All @@ -1391,21 +1396,22 @@ template setStringFunction2(ModelInfo modelInfo)
match modelInfo
case MODELINFO(vars=SIMVARS(__)) then
<<
fmi2String getString(ModelInstance* comp, const fmi2ValueReference vr) {
fmi2Status setString(ModelInstance* comp, const fmi2ValueReference vr, fmi2String value) {
switch (vr) {
<%vars.stringAlgVars |> var => SwitchVarsSet(var, "stringVars", 0) ;separator="\n"%>
<%vars.stringParamVars |> var => SwitchParametersSet(var, "stringParameter") ;separator="\n"%>
<%vars.stringAliasVars |> var => SwitchAliasVarsSet(var, "String", "") ;separator="\n"%>
default:
return 0;
return fmi2Error;
}
return fmi2OK;
}

>>
end setStringFunction2;

template setExternalFunction2(ModelInfo modelInfo)
"Generates setString function for c file."
"Generates setExternal function for c file."
::=
match modelInfo
case MODELINFO(vars=SIMVARS(__)) then
Expand Down Expand Up @@ -1935,7 +1941,7 @@ case FMIIMPORT(fmiInfo=INFO(__),fmiExperimentAnnotation=EXPERIMENTANNOTATION(__)
<%if not stringEq(integerParametersVRs, "") then "flowParamsStart := fmi1Functions.fmi1SetIntegerParameter(fmi1me, {"+integerParametersVRs+"}, {"+integerParametersNames+"});"%>
<%if not stringEq(booleanParametersVRs, "") then "flowParamsStart := fmi1Functions.fmi1SetBooleanParameter(fmi1me, {"+booleanParametersVRs+"}, {"+booleanParametersNames+"});"%>
<%/*Opening the below line fails the JuliansBib.mos test. fmiSetString returns out of memmory error. TODO: check the implementation of fmisetstring.*/%>
<%/*if not stringEq(stringParametersVRs, "") then "flowParamsStart := fmi1Functions.fmi1SetStringParameter(fmi1me, {"+stringParametersVRs+"}, {"+stringParametersNames+"});"*/%>
<%if not stringEq(stringParametersVRs, "") then "flowParamsStart := fmi1Functions.fmi1SetStringParameter(fmi1me, {"+stringParametersVRs+"}, {"+stringParametersNames+"});"%>
fmi_AInitInputs:=1;
initial equation
<%if not stringEq(realDependentParametersVRs, "") then "{"+realDependentParametersNames+"} = fmi1Functions.fmi1GetReal(fmi1me, {"+realDependentParametersVRs+"}, fmi_Initialized);"%>
Expand Down
13 changes: 1 addition & 12 deletions SimulationRuntime/fmi/export/fmi1/fmu1_model_interface.c
Expand Up @@ -294,23 +294,12 @@ fmiStatus fmiSetString(fmiComponent c, const fmiValueReference vr[], size_t nvr,
if (comp->loggingOn)
comp->functions.logger(c, comp->instanceName, fmiOK, "log", "fmiSetString: nvr = %d", nvr);
for (i=0; i<nvr; i++) {
char* string = (char*)comp->fmuData->localData[0]->stringVars[vr[i]];
if (vrOutOfRange(comp, "fmiSetString", vr[i], NUMBER_OF_STRINGS))
return fmiError;
if (comp->loggingOn) comp->functions.logger(c, comp->instanceName, fmiOK, "log",
"fmiSetString: #s%d# = '%s'", vr[i], value[i]);
if (nullPointer(comp, "fmiSetString", "value[i]", value[i]))
if (setString(comp, vr[i],value[i]) != fmiOK) // to be implemented by the includer of this file
return fmiError;
if (string==NULL || strlen(string) < strlen(value[i])) {
if (string) comp->functions.freeMemory(string);
comp->fmuData->localData[0]->stringVars[vr[i]] = *(fmiString*)comp->functions.allocateMemory(1+strlen(value[i]), sizeof(char));
if (!comp->fmuData->localData[0]->stringVars[vr[i]]) {
comp->state = modelError;
comp->functions.logger(NULL, comp->instanceName, fmiError, "error", "fmiSetString: Out of memory.");
return fmiError;
}
}
strcpy((char*)comp->fmuData->localData[0]->stringVars[vr[i]], (char*)value[i]);
}
return fmiOK;
}
Expand Down
4 changes: 0 additions & 4 deletions SimulationRuntime/fmi/export/fmi1/fmu1_model_interface.h
Expand Up @@ -61,10 +61,6 @@ typedef struct {
DATA* fmuData;
} ModelInstance;

fmiStatus setString(fmiComponent comp, fmiValueReference vr, fmiString value){
return fmiSetString(comp, &vr, 1, &value);
}

#ifdef __cplusplus
}
#endif
Expand Down
13 changes: 1 addition & 12 deletions SimulationRuntime/fmi/export/fmi2/fmu2_model_interface.c
Expand Up @@ -649,23 +649,12 @@ fmi2Status fmi2SetString(fmi2Component c, const fmi2ValueReference vr[], size_t
FILTERED_LOG(comp, fmi2OK, LOG_FMI2_CALL, "fmi2SetString: nvr = %d", nvr)

for (i = 0; i < nvr; i++) {
char* string = (char*)comp->fmuData->localData[0]->stringVars[vr[i]];
if (vrOutOfRange(comp, "fmi2SetString", vr[i], NUMBER_OF_STRINGS))
return fmi2Error;
FILTERED_LOG(comp, fmi2OK, LOG_FMI2_CALL, "fmi2SetString: #s%d# = '%s'", vr[i], value[i])

if (nullPointer(comp, "fmi2SetString", "value[i]", value[i]))
if (setString(comp, vr[i], value[i]) != fmi2OK) // to be implemented by the includer of this file
return fmi2Error;
if (string == NULL || strlen(string) < strlen(value[i])) {
if (string) comp->functions->freeMemory(string);
comp->fmuData->localData[0]->stringVars[vr[i]] = *(fmi2String*)comp->functions->allocateMemory(1 + strlen(value[i]), sizeof(char));
if (!comp->fmuData->localData[0]->stringVars[vr[i]]) {
comp->state = modelError;
FILTERED_LOG(comp, fmi2Error, LOG_STATUSERROR, "fmi2SetString: Out of memory.")
return fmi2Error;
}
}
strcpy((char*)comp->fmuData->localData[0]->stringVars[vr[i]], (char*)value[i]);
}
return fmi2OK;
}
Expand Down

0 comments on commit bbf0177

Please sign in to comment.