Skip to content

Commit

Permalink
Read log categories for FMI3
Browse files Browse the repository at this point in the history
  • Loading branch information
robbr48 committed Feb 17, 2022
1 parent 39638c9 commit f520433
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
3 changes: 3 additions & 0 deletions include/fmi4c.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,9 @@ FMIC_DLLEXPORT void fmi3GetClockType(fmiHandle *fmu,
uint64_t *intervalCounter,
uint64_t *shiftCounter);

FMIC_DLLEXPORT int fmi3GetNumberOfLogCategories(fmiHandle *fmu);
FMIC_DLLEXPORT void fmi3GetLogCategory(fmiHandle *fmu, int id, const char **name, const char **description);

FMIC_DLLEXPORT const char* fmi3GetModelIdentifier(fmiHandle* fmu);
FMIC_DLLEXPORT bool fmi3GetNeedsExecutionTool(fmiHandle* fmu);
FMIC_DLLEXPORT bool fmi3GetCanBeInstantiatedOnlyOncePerProcess(fmiHandle* fmu);
Expand Down
7 changes: 7 additions & 0 deletions include/fmi4c_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,11 @@ typedef struct {
uint64_t shiftCounter;
} fmi3ClockType;

typedef struct {
const char* name;
const char* description;
} fmi3LogCategory;

typedef struct {
bool supportsModelExchange;
bool supportsCoSimulation;
Expand Down Expand Up @@ -667,6 +672,8 @@ typedef struct {
fmi3EnumerationType *enumTypes;
fmi3ClockType *clockTypes;

int numberOfLogCategories;
fmi3LogCategory *logCategories;
} fmi3Data_t;


Expand Down
34 changes: 33 additions & 1 deletion src/fmi4c.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,6 @@ bool parseModelDescriptionFmi3(fmiHandle *fmu)
parseStringAttributeEzXml(rootElement, "generationDateAndTime", &fmu->fmi3.generationDateAndTime);
parseStringAttributeEzXml(rootElement, "variableNamingConvention", &fmu->fmi3.variableNamingConvention);


ezxml_t cosimElement = ezxml_child(rootElement, "CoSimulation");
if(cosimElement) {
fmu->fmi3.supportsCoSimulation = true;
Expand Down Expand Up @@ -984,6 +983,26 @@ bool parseModelDescriptionFmi3(fmiHandle *fmu)
}
}

ezxml_t logCategoriesElement = ezxml_child(rootElement, "LogCategories");
fmu->fmi3.numberOfLogCategories = 0;
if(logCategoriesElement) {
//Count log categories
for(ezxml_t logCategoryElement = logCategoriesElement->child; logCategoryElement; logCategoryElement = logCategoryElement->next) {
++fmu->fmi3.numberOfLogCategories;
}

//Allocate memory for log categories
fmu->fmi3.logCategories = malloc(fmu->fmi3.numberOfLogCategories*sizeof(fmi3LogCategory));

//Read log categories
int i=0;
for(ezxml_t logCategoryElement = logCategoriesElement->child; logCategoryElement; logCategoryElement = logCategoryElement->next) {
parseStringAttributeEzXml(logCategoryElement, "name", &fmu->fmi3.logCategories[i].name);
parseStringAttributeEzXml(logCategoryElement, "description", &fmu->fmi3.logCategories[i].description);
++i;
}
}

ezxml_t defaultExperimentElement = ezxml_child(rootElement, "DefaultExperiment");
if(defaultExperimentElement) {
fmu->fmi3.defaultStartTimeDefined = parseFloat64AttributeEzXml(defaultExperimentElement, "startTime", &fmu->fmi3.defaultStartTime);
Expand Down Expand Up @@ -4496,3 +4515,16 @@ void fmi3GetEnumerationItem(fmiHandle *fmu, const char *typeName, int itemId, co
}
}


int fmi3GetNumberOfLogCategories(fmiHandle *fmu)
{
return fmu->fmi3.numberOfLogCategories;
}

void fmi3GetLogCategory(fmiHandle *fmu, int id, const char **name, const char **description)
{
if(id < fmu->fmi3.numberOfLogCategories) {
*name = fmu->fmi3.logCategories[id].name;
*description = fmu->fmi3.logCategories[id].description;
}
}

0 comments on commit f520433

Please sign in to comment.