-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@9913 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
- Loading branch information
Wuzhu Chen
committed
Sep 23, 2011
1 parent
01475ee
commit a749d6b
Showing
14 changed files
with
3,490 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
#ifndef FMUWRAPPER_H | ||
#define FMUWRAPPER_H | ||
#endif | ||
|
||
#include "fmiModelFunctions.h" | ||
#include "xml_parser.h" | ||
#define COMBINENAME(a,b) a##_##b | ||
|
||
#ifdef __cplusplus | ||
extern "C"{ | ||
#endif | ||
|
||
// typedef of function pointers to FMI interface functions | ||
typedef const char* (*fGetModelTypesPlatform)(); | ||
typedef const char* (*fGetVersion)(); | ||
typedef fmiComponent (*fInstantiateModel)(fmiString instanceName, fmiString GUID, | ||
fmiCallbackFunctions functions, fmiBoolean loggingOn); | ||
typedef void (*fFreeModelInstance) (fmiComponent c); | ||
typedef fmiStatus (*fSetDebugLogging) (fmiComponent c, fmiBoolean loggingOn); | ||
typedef fmiStatus (*fSetTime) (fmiComponent c, fmiReal time); | ||
typedef fmiStatus (*fSetContinuousStates)(fmiComponent c, const fmiReal x[], size_t nx); | ||
typedef fmiStatus (*fCompletedIntegratorStep)(fmiComponent c, fmiBoolean* callEventUpdate); | ||
typedef fmiStatus (*fSetReal) (fmiComponent c, const fmiValueReference vr[], size_t nvr, const fmiReal value[]); | ||
typedef fmiStatus (*fSetInteger)(fmiComponent c, const fmiValueReference vr[], size_t nvr, const fmiInteger value[]); | ||
typedef fmiStatus (*fSetBoolean)(fmiComponent c, const fmiValueReference vr[], size_t nvr, const fmiBoolean value[]); | ||
typedef fmiStatus (*fSetString) (fmiComponent c, const fmiValueReference vr[], size_t nvr, const fmiString value[]); | ||
typedef fmiStatus (*fInitialize)(fmiComponent c, fmiBoolean toleranceControlled, | ||
fmiReal relativeTolerance, fmiEventInfo* eventInfo); | ||
typedef fmiStatus (*fGetDerivatives) (fmiComponent c, fmiReal derivatives[] , size_t nx); | ||
typedef fmiStatus (*fGetEventIndicators)(fmiComponent c, fmiReal eventIndicators[], size_t ni); | ||
typedef fmiStatus (*fGetReal) (fmiComponent c, const fmiValueReference vr[], size_t nvr, fmiReal value[]); | ||
typedef fmiStatus (*fGetInteger)(fmiComponent c, const fmiValueReference vr[], size_t nvr, fmiInteger value[]); | ||
typedef fmiStatus (*fGetBoolean)(fmiComponent c, const fmiValueReference vr[], size_t nvr, fmiBoolean value[]); | ||
typedef fmiStatus (*fGetString) (fmiComponent c, const fmiValueReference vr[], size_t nvr, fmiString value[]); | ||
typedef fmiStatus (*fEventUpdate) (fmiComponent c, fmiBoolean intermediateResults, fmiEventInfo* eventInfo); | ||
typedef fmiStatus (*fGetContinuousStates) (fmiComponent c, fmiReal states[], size_t nx); | ||
typedef fmiStatus (*fGetNominalContinuousStates)(fmiComponent c, fmiReal x_nominal[], size_t nx); | ||
typedef fmiStatus (*fGetStateValueReferences) (fmiComponent c, fmiValueReference vrx[], size_t nx); | ||
typedef fmiStatus (*fTerminate) (fmiComponent c); | ||
|
||
// typedef of the data structure FMI containing loaded FMI functions | ||
typedef struct { | ||
ModelDescription* modelDescription; | ||
HINSTANCE dllHandle; | ||
fGetModelTypesPlatform getModelTypesPlatform; | ||
fGetVersion getVersion; | ||
fInstantiateModel instantiateModel; | ||
fFreeModelInstance freeModelInstance; | ||
fSetDebugLogging setDebugLogging; | ||
fSetTime setTime; | ||
fSetContinuousStates setContinuousStates; | ||
fCompletedIntegratorStep completedIntegratorStep; | ||
fSetReal setReal; | ||
fSetInteger setInteger; | ||
fSetBoolean setBoolean; | ||
fSetString setString; | ||
fInitialize initialize; | ||
fGetDerivatives getDerivatives; | ||
fGetEventIndicators getEventIndicators; | ||
fGetReal getReal; | ||
fGetInteger getInteger; | ||
fGetBoolean getBoolean; | ||
fGetString getString; | ||
fEventUpdate eventUpdate; | ||
fGetContinuousStates getContinuousStates; | ||
fGetNominalContinuousStates getNominalContinuousStates; | ||
fGetStateValueReferences getStateValueReferences; | ||
fTerminate terminate; | ||
int flagInit; | ||
} FMI; | ||
|
||
#ifdef _DEBUG__ | ||
typedef enum { | ||
modelInstantiated = 1<<0, | ||
modelInitialized = 1<<1, | ||
modelTerminated = 1<<2, | ||
modelError = 1<<3 | ||
} ModelState; | ||
|
||
typedef struct { | ||
fmiReal *r; | ||
fmiInteger *i; | ||
fmiBoolean *b; | ||
fmiString *s; | ||
fmiBoolean *isPositive; | ||
fmiReal time; | ||
fmiString instanceName; | ||
fmiString GUID; | ||
fmiCallbackFunctions functions; | ||
fmiBoolean loggingOn; | ||
ModelState state; | ||
} ModelInstance; | ||
|
||
#endif | ||
|
||
void PrintModelStates(void* in_fmu, double in_time); | ||
const char* fmiGetModelTypesPF(void* in_fmi); | ||
const char* fmiGetVer(void* in_fmi); | ||
static void* getProAdr(FMI* fmi, const char* mid, const char* funName); | ||
void* loadFMUDll(void* in_fmi, const char* pathFMUDll,const char* mid); | ||
void freeFMUDll(void* dummy); | ||
void fmiSetDebugLog(void* in_fmi, void* in_fmu, char log); | ||
void fmiSetT(void* in_fmi, void* in_fmu, double in_t); | ||
void fmiSetContStates(void* in_fmi, void* in_fmu, const double* in_x, int nx); | ||
void fmiSetRealVR(void* in_fmi, void* in_fmu, const int* in_vr, const double* rv, int nvr); | ||
void fmiSetIntegerVR(void* in_fmi, void* in_fmu, const int* in_vr, const int* iv, int nvr); | ||
void fmiSetStringVR(void* in_fmi, void* in_fmu, const int* in_vr, const char** sv, int nvr); | ||
void fmiSetBooleanVR(void* in_fmi, void* in_fmu, const int* in_vr, const char* in_bv, int nvr); | ||
void fmiCompIntStep(void* in_fmi, void* in_fmu, void* in_stepEvt); | ||
void fmiGetContStates(void* in_fmi, void* in_fmu, double* out_x, int nx); | ||
void fmiGetNomContStates(void* in_fmi, void* in_fmu, double* x_nom, int nx); | ||
void fmiGetStateVR(void* in_fmi, void* in_fmu, int* in_vrx, int nx); | ||
void fmiGetDer(void* in_fmi, void* in_fmu, double* der_x, int nx, const double* x); | ||
void fmiGetRealVR(void* in_fmi, void* in_fmu, const int* in_vr, double* rv, int nvr); | ||
void fmiGetIntegerVR(void* in_fmi, void* in_fmu, const int* in_vr, int* iv, int nvr); | ||
void fmiGetStringVR(void* in_fmi, void* in_fmu, const int* in_vr, const char** sv, int nvr); | ||
void fmiGetBooleanVR(void* in_fmi, void* in_fmu, const int* in_vr, char* bv, int nvr); | ||
void fmiGetTimeEvent(void * in_evtInfo, double in_time, double in_pretime, void * in_timeEvt, double* out_nextTime); | ||
void fmiGetEventInd(void* in_fmi, void* in_fmu, double* z, int ni); | ||
void fmuStateEventCheck(void* stateEvt, int ni, const double* z, const double* prez); | ||
void fmiEvtUpdate(void* in_fmi, void* in_fmu,fmiBoolean inter_res, fmiEventInfo* in_evtInfo); | ||
void fmuEventUpdate(void * in_fmufun, void * in_inst, void * in_evtInfo, void * timeEvt, void * stepEvt, void * stateEvt, void * interMediateRes, double x, double* flag); | ||
void fmuLogger(void* in_fmu, const char* instanceName, fmiStatus status,const char* category, const char* message, ...); | ||
void* fmiInstantiate(void* in_fmi, const char* instanceName, const char* GUID, void* in_functions, int logFlag); | ||
void fmiInit(void* in_fmi, void* in_fmu, int tolCont, double rTol, void* in_evtInfo); | ||
void fmiTerminator(void* in_fmi, void* in_fmu); | ||
void* instantiateFMIFun(const char* mid, const char* pathFMUDll); | ||
void freeFMIFun(void* in_fmi); | ||
void* fmuBooleanInst(int def_bool); | ||
void freefmuBooleanInst(void* in_bool); | ||
void fmiFreeModelInst(void* in_fmu); | ||
void* fmiCallbackFuns(); | ||
void fmiFreeCallbackFuns(void * functions); | ||
void* fmiEvtInfo(); | ||
void freefmiEvtInfo(void* in_evtInfo); | ||
void printVariables(const double * var, int n, const char* varName); | ||
void printIntVariables(const int * var, int n, const char* varName); | ||
|
||
// void* fmiInstantiate(void* in_fmi, const char* instanceName, const char* GUID, void* in_functions, int logFlag); | ||
// void fmiSetT(void* in_fmi, void* in_fmu, double t); | ||
// void fmiGetContStates(void * /*_fmufun*/, void * /*_in_inst*/, double * /*_in_x*/, int); | ||
// void fmiGetDer(void* in_fmi, void* in_fmu, double* der_x, int nx, const double* x); | ||
// void* instantiateFMIFun(const char* mid, const char* pathFMUDll); | ||
// void fmiCompIntStep(void* in_fmi, void* in_fmu, void* in_stepEvt); | ||
// void freeFMIfun(void* in_fmi); | ||
// void printVariables(const double * /*_var*/, int /*_n*/, const char* /*_varName*/); | ||
// // void fmiFreeModelInst(void* in_fmi, void* in_fmu); | ||
// void fmiFreeModelInst(void* in_fmu); | ||
// void fmiGetTimeEvent(void * /*_in_evtInfo*/, double /*_in_time*/, double /*_in_pretime*/, void * /*_in_timeEvt*/, double* /*_out_nextTime*/); | ||
// void fmuStateEventCheck(void * /*_stateEvt*/, int /*_ni*/, const double * /*_z*/, const double * /*_prez*/); | ||
// //signed char fmuStateEventCheck(void * /*_stateEvt*/, int /*_ni*/, const double * /*_z*/, const double * /*_prez*/); | ||
// void fmuEventUpdate(void * /*_in_fmufun*/, void * /*_in_inst*/, void * /*_in_evtInfo*/, void * /*_timeEvt*/, void * /*_stepEvt*/, void * /*_stateEvt*/, void * /*_interMediateRes*/, double, double*); | ||
#ifdef __cplusplus | ||
} //extern "C" | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <windows.h> | ||
#include "xml_parser.h" | ||
#include "fmuWrapper.h" | ||
|
||
static char* getDecompPath(const char * omPath, const char* mid); | ||
static char* getDllPath(const char* decompPath,const char* mid); | ||
static char* getXMLfile(const char * decompPath, const char * modeldes); | ||
static int decompress(const char* fmuPath, const char* decompPath); | ||
static char* getFMUname(const char* fmupath); | ||
void tmpcodegen(size_t , size_t , const char* , const char*, const char* ); | ||
void blockcodegen(ModelDescription*, size_t , size_t , const char* , const char* , const char* , const char* ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* ------------------------------------------------------------------------- | ||
* stack.c | ||
* A stack of pointers. | ||
* Copyright 2010 QTronic GmbH. All rights reserved. | ||
* Modified for OpenModelica Project | ||
* -------------------------------------------------------------------------*/ | ||
|
||
#ifndef STACK_H | ||
#define STACK_H | ||
|
||
typedef struct { | ||
void** stack; | ||
int stackSize; // allocated size of stack | ||
int stackPos; // array index of top element, -1 if stack is empty. | ||
int initialSize; // how many element to allocate initially | ||
int inc; // how many elements to allocate when stack gets full | ||
} Stack; | ||
|
||
Stack* stackNew(int initialSize, int inc); | ||
int stackIsEmpty(Stack* s); | ||
int stackPush(Stack* s, void* e); | ||
void* stackPeek(Stack* s); | ||
void* stackPop(Stack* s); | ||
void** stackPopAllAsArray(Stack* s, int *size); | ||
void** stackLastPopedAsArray0(Stack* s, int n); | ||
void stackFree(Stack* s); | ||
|
||
#endif // STACK_H | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
/* ------------------------------------------------------------------------- | ||
* xmlparser.h | ||
* A parser for file modelVariables.xml of an FMU. | ||
* Copyright 2010 QTronic GmbH. All rights reserved. | ||
* Modeified for OpenModelica Project. | ||
* -------------------------------------------------------------------------*/ | ||
|
||
|
||
#ifndef xmlparser_h | ||
#define xmlparser_h | ||
|
||
// define XML_STATIC before including expat.h | ||
// to prevent error when linking with libexpatMT.lib | ||
#define XML_STATIC | ||
#include <expat.h> | ||
#include <fmiModelTypes.h> | ||
#include "stack.h" | ||
|
||
#define SIZEOF_ELM 26 | ||
extern const char *elmNames[SIZEOF_ELM]; | ||
|
||
#define SIZEOF_ATT 34 | ||
extern const char *attNames[SIZEOF_ATT]; | ||
|
||
#define SIZEOF_ENU 13 | ||
extern const char *enuNames[SIZEOF_ENU]; | ||
|
||
// Attributes | ||
typedef enum { | ||
elm_fmiModelDescription,elm_UnitDefinitions,elm_BaseUnit,elm_DisplayUnitDefinition,elm_TypeDefinitions, | ||
elm_Type,elm_RealType,elm_IntegerType,elm_BooleanType,elm_StringType, | ||
elm_EnumerationType,elm_Item, elm_DefaultExperiment,elm_VendorAnnotations,elm_Tool, | ||
elm_Annotation,elm_ModelVariables,elm_ArrayVariable,elm_ScalarVariable,elm_DirectDependency, | ||
elm_Name,elm_Real,elm_Integer,elm_Boolean,elm_String,elm_Enumeration | ||
} Elm; | ||
|
||
// Attributes | ||
typedef enum { | ||
att_fmiVersion,att_displayUnit,att_gain,att_offset,att_unit,att_name,att_description,att_quantity,att_relativeQuantity, | ||
att_min,att_max,att_nominal,att_declaredType,att_start,att_fixed,att_startTime,att_stopTime,att_tolerance,att_value, | ||
att_valueReference,att_variability,att_causality,att_alias,att_modelName,att_modelIdentifier,att_guid,att_author, | ||
att_version,att_generationTool,att_generationDateAndTime,att_variableNamingConvention,att_numberOfContinuousStates, | ||
att_numberOfEventIndicators,att_input | ||
} Att; | ||
|
||
// Enumeration values | ||
typedef enum { | ||
enu_flat,enu_structured,enu_constant,enu_parameter,enu_discrete,enu_continuous, | ||
enu_input,enu_output,enu_internal,enu_none,enu_noAlias,enu_alias,enu_negatedAlias | ||
} Enu; | ||
|
||
// AST node for element | ||
// DisplayUnitDefinition, RealType, IntegerType, BooleanType, StringType | ||
// DefaultExperiment, Item, Annotation, Name, Real, Integer, Boolean, String, Enumeration | ||
typedef struct { | ||
Elm type; // element type | ||
const char** attributes; // null or n attribute value strings | ||
int n; // size of attributes, even number | ||
} Element; | ||
|
||
// AST node for element that has a list of elements | ||
// BaseUnit, EnumerationType, Tool, DirectDependency | ||
typedef struct { | ||
Elm type; // element type | ||
const char** attributes; // null or n attribute value strings | ||
int n; // size of attributes, even number | ||
Element** list; // null-terminated array of pointers to elements, not null | ||
} ListElement; | ||
|
||
// AST node for element Type | ||
typedef struct { | ||
Elm type; // element type | ||
const char** attributes; // null or n attribute value strings | ||
int n; // size of attributes, an even number | ||
Element* typeSpec; // one of RealType, IntegerType etc. | ||
} Type; | ||
|
||
// AST node for element ScalarVariable | ||
typedef struct { | ||
Elm type; // element type | ||
const char** attributes; // null or n attribute value strings | ||
int n; // size of attributes, even number | ||
Element* typeSpec; // one of Real, Integer, etc | ||
Element** directDependencies; // null or null-terminated list of Name | ||
} ScalarVariable; | ||
|
||
// AST node for element ArrayVariable for the future | ||
typedef struct{ | ||
|
||
} ArrayVariable; | ||
|
||
typedef struct{ | ||
ScalarVariable** scalarVariables; | ||
ArrayVariable** arrayVariables; // array varialbes for later use | ||
} ModelVariables; | ||
|
||
// AST node for element ModelDescription | ||
typedef struct { | ||
Elm type; // element type | ||
const char** attributes; // null or n attribute value strings | ||
int n; // size of attributes, even number | ||
ListElement** unitDefinitions; // NULL or null-terminated list of BaseUnits | ||
Type** typeDefinitions; // NULL or null-terminated list of Types | ||
Element* defaultExperiment; // NULL or DefaultExperiment | ||
ListElement** vendorAnnotations; // NULL or null-terminated list of Tools | ||
ScalarVariable** modelVariables; // NULL or null-terminated list of ScalarVariable | ||
} ModelDescription; | ||
|
||
// types of AST nodes used to represent an element | ||
typedef enum { | ||
astElement, | ||
astListElement, | ||
astType, | ||
astScalarVariable, | ||
astArrayVariable, | ||
astModelVariables, | ||
astModelDescription | ||
} AstNodeType; | ||
|
||
// Possible results when retrieving an attribute value from an element | ||
typedef enum { | ||
valueMissing, | ||
valueDefined, | ||
valueIllegal | ||
} ValueStatus; | ||
|
||
// Public methods: Parsing and low-level AST access | ||
ModelDescription* parse(const char* xmlPath); | ||
const char* getString(void* element, Att a); | ||
double getDouble (void* element, Att a, ValueStatus* vs); | ||
int getInt (void* element, Att a, ValueStatus* vs); | ||
unsigned int getUInt (void* element, Att a, ValueStatus* vs); | ||
char getBoolean (void* element, Att a, ValueStatus* vs); | ||
Enu getEnumValue (void* element, Att a, ValueStatus* vs); | ||
void freeElement (void* element); | ||
|
||
// Convenience methods for AST access. To be used afer successful validation only. | ||
const char* getModelIdentifier(ModelDescription* md); | ||
int getNumberOfStates(ModelDescription* md); | ||
int getNumberOfEventIndicators(ModelDescription* md); | ||
const char* getName(void* element); | ||
Enu getCausality(void* scalarVariable); | ||
Enu getVariability(void* scalarVariable); | ||
Enu getAlias(void* scalarVariable); | ||
fmiValueReference getValueReference(void* scalarVariable); | ||
ScalarVariable* getVariableByName(ModelDescription* md, const char* name); | ||
ScalarVariable* getVariable(ModelDescription* md, fmiValueReference vr, Elm type); | ||
Type* getDeclaredType(ModelDescription* md, const char* declaredType); | ||
const char* getString2(ModelDescription* md, void* sv, Att a); | ||
const char * getDescription(ModelDescription* md, ScalarVariable* sv); | ||
const char * getVariableAttributeString(ModelDescription* md, fmiValueReference vr, Elm type, Att a); | ||
double getVariableAttributeDouble(ModelDescription* md, fmiValueReference vr, Elm type, Att a, ValueStatus* vs); | ||
double getNominal(ModelDescription* md, fmiValueReference vr); | ||
|
||
#endif // xmlparser_h | ||
|
Oops, something went wrong.