bip examples + master example + scripts

parent 0580cb88
......@@ -7,5 +7,5 @@ package ujf.verimag.bip.userinterface.cli;
* use "svn annotate" and BLAME the one who has commited it !
*/
public class Version {
public static final String VERSION = "2022.02.114844-DEV";
public static final String VERSION = "2022.02.105337-DEV";
}
<?xml version="1.0" encoding="UTF-8"?>
<fmiModelDescription fmiVersion="2.0" modelName="bip_example" guid="123456789" description="LEC" generationTool="Manually" generationDateAndTime="2022-02-24T12:43:32Z">
<CoSimulation modelIdentifier="bip_example" needsExecutionTool="true" canBeInstantiatedOnlyOncePerProcess="true" canNotUseMemoryManagementFunctions="true" canGetAndSetFMUstate="false" canSerializeFMUstate="false" providesDirectionalDerivative="false" canHandleVariableCommunicationStepSize="true" canInterpolateInputs="false" maxOutputDerivativeOrder="0" canRunAsynchronuously="false"/>
<UnitDefinitions>
<Unit name="s"/>
</UnitDefinitions>
<ModelVariables>
<ScalarVariable name="ROOT.environment._id__inputIndex" valueReference="100" description="input index" causality="local" initial="exact" variability="discrete">
<Integer start="1"/>
<Annotations><Tool name="Amesim"><VarAnnot index="1"/></Tool></Annotations>
</ScalarVariable>
<ScalarVariable name="ROOT.environment._id__time" valueReference="101" description="timer" causality="output" variability="discrete" initial="exact">
<Integer min="0" max="10" start="10"/>
<Annotations><Tool name="Amesim"><VarAnnot index="2"/></Tool></Annotations>
</ScalarVariable>
<ScalarVariable name="ROOT.camera._id__inputIndex" valueReference="102" description="Current index frame for camera" causality="local" variability="continuous">
<Integer min="0" max="10"/>
<Annotations><Tool name="Amesim"><VarAnnot index="3"/></Tool></Annotations>
</ScalarVariable>
<ScalarVariable name="ROOT.perception._id__inputIndex" valueReference="103" description="Current index frame for perception" causality="local" variability="discrete">
<Integer min="0" max="10"/>
<Annotations><Tool name="Amesim"><VarAnnot index="4"/></Tool></Annotations>
</ScalarVariable>
<ScalarVariable name="ROOT.perception._id__result" valueReference="104" description="Detection result" causality="output" variability="discrete">
<Integer />
<Annotations><Tool name="Amesim"><VarAnnot index="5"/></Tool></Annotations>
</ScalarVariable>
<ScalarVariable name="ROOT.controller._id__speed" valueReference="105" description="Vehicle speed" causality="local" variability="discrete" initial="exact">
<Integer min="0" max="270" start="70"/>
<Annotations><Tool name="Amesim"><VarAnnot index="6"/></Tool></Annotations>
</ScalarVariable>
<ScalarVariable name="ROOT.controller._id__speedLimit" valueReference="106" description="Speed limit" causality="local" variability="discrete">
<Integer min="0" max="120"/>
<Annotations><Tool name="Amesim"><VarAnnot index="7"/></Tool></Annotations>
</ScalarVariable>
<ScalarVariable name="ROOT.controller._id__deltaSpeed" valueReference="107" description="Delta speed" causality="local" variability="discrete" initial="exact">
<Integer start="0"/>
<Annotations><Tool name="Amesim"><VarAnnot index="8"/></Tool></Annotations>
</ScalarVariable>
<ScalarVariable name="ROOT.controller._id__zero" valueReference="108" description="Zero" causality="parameter" variability="fixed" initial="exact">
<Integer start="0"/>
<Annotations><Tool name="Amesim"><VarAnnot index="9"/></Tool></Annotations>
</ScalarVariable>
<ScalarVariable name="ROOT.brake._id__deltaSpeed" valueReference="109" description="Delta speed" causality="local" variability="discrete" initial="exact">
<Integer start="0"/>
<Annotations><Tool name="Amesim"><VarAnnot index="10"/></Tool></Annotations>
</ScalarVariable>
<ScalarVariable name="ROOT.throttle._id__deltaSpeed" valueReference="110" description="Delta speed" causality="local" variability="discrete" initial="exact">
<Integer start="0"/>
<Annotations><Tool name="Amesim"><VarAnnot index="11"/></Tool></Annotations>
</ScalarVariable>
<ScalarVariable name="ROOT.speedSensor._id__speed" valueReference="111" description="Vehicle speed" causality="local" variability="discrete">
<Integer min="0" max="120"/>
<Annotations><Tool name="Amesim"><VarAnnot index="12"/></Tool></Annotations>
</ScalarVariable>
<ScalarVariable name="ROOT.speedSensor._id__deltaSpeed" valueReference="112" description="Delta speed" causality="local" variability="discrete" initial="exact">
<Integer start="0"/>
<Annotations><Tool name="Amesim"><VarAnnot index="13"/></Tool></Annotations>
</ScalarVariable>
</ModelVariables>
<ModelStructure>
<Outputs>
<Unknown index="2" dependencies=""/>
<Unknown index="5" dependencies=""/>
</Outputs>
<InitialUnknowns>
<Unknown index="5" dependencies=""/>
</InitialUnknowns>
</ModelStructure>
</fmiModelDescription>
# for SPEEDCONTROLMODULE example
cp $1/libProject.so .
cp -r $1/Signs .
cp -r $1/ext-cpp .
g++ src/DEPLOY_TEMPLATE.cpp -I includes -LProject -ldl -o master -Wl,--export-dynamic
./master
import os
import sys
import cv2
import numpy as np
import onnxruntime
#import pyautogui
CLASSES = [100, 120, 20, 30, 40, 15, 50, 60, 70, 80]
def preprocess(img, input_size, swap=(2, 0, 1)):
if len(img.shape) == 3:
padded_img = np.ones((input_size[0], input_size[1], 3), dtype=np.uint8) * 114
else:
padded_img = np.ones(input_size, dtype=np.uint8) * 114
r = min(input_size[0] / img.shape[0], input_size[1] / img.shape[1])
resized_img = cv2.resize(
img,
(int(img.shape[1] * r), int(img.shape[0] * r)),
interpolation=cv2.INTER_LINEAR,
).astype(np.uint8)
padded_img[: int(img.shape[0] * r), : int(img.shape[1] * r)] = resized_img
padded_img = padded_img.transpose(swap)
padded_img = np.ascontiguousarray(padded_img, dtype=np.float32)
return padded_img, r
def nms(boxes, scores, nms_thr):
"""Single class NMS implemented in Numpy."""
x1 = boxes[:, 0]
y1 = boxes[:, 1]
x2 = boxes[:, 2]
y2 = boxes[:, 3]
areas = (x2 - x1 + 1) * (y2 - y1 + 1)
order = scores.argsort()[::-1]
keep = []
while order.size > 0:
i = order[0]
keep.append(i)
xx1 = np.maximum(x1[i], x1[order[1:]])
yy1 = np.maximum(y1[i], y1[order[1:]])
xx2 = np.minimum(x2[i], x2[order[1:]])
yy2 = np.minimum(y2[i], y2[order[1:]])
w = np.maximum(0.0, xx2 - xx1 + 1)
h = np.maximum(0.0, yy2 - yy1 + 1)
inter = w * h
ovr = inter / (areas[i] + areas[order[1:]] - inter)
inds = np.where(ovr <= nms_thr)[0]
order = order[inds + 1]
return keep
def multiclass_nms(boxes, scores, nms_thr, score_thr, class_agnostic=True):
"""Multiclass NMS implemented in Numpy"""
if class_agnostic:
nms_method = multiclass_nms_class_agnostic
else:
nms_method = multiclass_nms_class_aware
return nms_method(boxes, scores, nms_thr, score_thr)
def multiclass_nms_class_aware(boxes, scores, nms_thr, score_thr):
"""Multiclass NMS implemented in Numpy. Class-aware version."""
final_dets = []
num_classes = scores.shape[1]
for cls_ind in range(num_classes):
cls_scores = scores[:, cls_ind]
valid_score_mask = cls_scores > score_thr
if valid_score_mask.sum() == 0:
continue
else:
valid_scores = cls_scores[valid_score_mask]
valid_boxes = boxes[valid_score_mask]
keep = nms(valid_boxes, valid_scores, nms_thr)
if len(keep) > 0:
cls_inds = np.ones((len(keep), 1)) * cls_ind
dets = np.concatenate(
[valid_boxes[keep], valid_scores[keep, None], cls_inds], 1
)
final_dets.append(dets)
if len(final_dets) == 0:
return None
return np.concatenate(final_dets, 0)
def multiclass_nms_class_agnostic(boxes, scores, nms_thr, score_thr):
"""Multiclass NMS implemented in Numpy. Class-agnostic version."""
cls_inds = scores.argmax(1)
cls_scores = scores[np.arange(len(cls_inds)), cls_inds]
valid_score_mask = cls_scores > score_thr
if valid_score_mask.sum() == 0:
return None
valid_scores = cls_scores[valid_score_mask]
valid_boxes = boxes[valid_score_mask]
valid_cls_inds = cls_inds[valid_score_mask]
keep = nms(valid_boxes, valid_scores, nms_thr)
if keep:
dets = np.concatenate(
[valid_boxes[keep], valid_scores[keep, None], valid_cls_inds[keep, None]], 1
)
return dets
def demo_postprocess(outputs, img_size, p6=False):
grids = []
expanded_strides = []
if not p6:
strides = [8, 16, 32]
else:
strides = [8, 16, 32, 64]
hsizes = [img_size[0] // stride for stride in strides]
wsizes = [img_size[1] // stride for stride in strides]
for hsize, wsize, stride in zip(hsizes, wsizes, strides):
xv, yv = np.meshgrid(np.arange(wsize), np.arange(hsize))
grid = np.stack((xv, yv), 2).reshape(1, -1, 2)
grids.append(grid)
shape = grid.shape[:2]
expanded_strides.append(np.full((*shape, 1), stride))
grids = np.concatenate(grids, 1)
expanded_strides = np.concatenate(expanded_strides, 1)
outputs[..., :2] = (outputs[..., :2] + grids) * expanded_strides
outputs[..., 2:4] = np.exp(outputs[..., 2:4]) * expanded_strides
return outputs
#img = pyautogui.screenshot(region = [1, 66, 800, 700])
#origin_img = cv2.cvtColor(np.array(img), cv2.COLOR_BGR2RGB)
origin_img = cv2.imread(sys.argv[2])
img, ratio = preprocess(origin_img, [640, 640])
session = onnxruntime.InferenceSession(sys.argv[1])
ort_inputs = {session.get_inputs()[0].name: img[None, :, :, :]}
output = session.run(None, ort_inputs)
predictions = demo_postprocess(output[0], [640, 640])[0]
boxes = predictions[:, :4]
scores = predictions[:, 4:5] * predictions[:, 5:]
boxes_xyxy = np.ones_like(boxes)
boxes_xyxy[:, 0] = boxes[:, 0] - boxes[:, 2]/2.
boxes_xyxy[:, 1] = boxes[:, 1] - boxes[:, 3]/2.
boxes_xyxy[:, 2] = boxes[:, 0] + boxes[:, 2]/2.
boxes_xyxy[:, 3] = boxes[:, 1] + boxes[:, 3]/2.
boxes_xyxy /= ratio
dets = multiclass_nms(boxes_xyxy, scores, nms_thr=0.45, score_thr=0.1)
if dets is not None:
final_boxes, final_scores, final_cls_inds = dets[:, :4], dets[:, 4], dets[:, 5]
cls_ind = int(final_cls_inds[0])
score = final_scores[0]
if score > 0.9:
print(CLASSES[cls_ind])
#include"utilities.hpp"
int const_getFileNum()
{
FILE* crs = popen(GET_FILE_NUM_CMD, "r"); // execute the shell command
char result[4] = "0";
fread(result, sizeof(char), sizeof(result), crs);
if (NULL != crs)
{
fclose(crs);
crs = NULL;
}
int num = atoi(result);
return num;
}
int deepLearn(int i){
char buffer [50];
sprintf (buffer, "%d.png", i);
stringstream tmp;
tmp<<"python3 ./ext-cpp/Inference.py ./ext-cpp/yolox_s.onnx Signs/"<<i<<".png > system.txt";
//tmp<<"python ./ext-cpp/Inference.py ./ext-cpp/yolox_s.onnx > system.txt";
string execCmd = tmp.str();
int a = system(execCmd.c_str());
FILE *fp;
int buff;
fp = fopen("system.txt", "r");
int result = fscanf(fp, "%d", &buff);
fclose(fp);
if(result == EOF)
return -1;
return buff;
}
#ifndef _Utilities
#define _Utilities
#include <stdio.h>
#include <string>
#include <vector>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <math.h>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <sys/time.h>
#include <limits>
#include <fstream>
#include <cstring>
#include <unistd.h>
#define GET_FILE_NUM_CMD "ls Signs/*.png | wc -l"
using namespace std;
int const_getFileNum();
int deepLearn(int i);
int get_directory();
#endif
/*
FMI Interface for FMU generated by FMICodeGenerator.
This file is part of FMICodeGenerator (https://github.com/ghorwin/FMICodeGenerator)
BSD 3-Clause License
Copyright (c) 2018, Andreas Nicolai
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef FMI_templateH
#define FMI_templateH
#include <InstanceData.h>
/*! This class wraps all data needed for a single instance of the FMU. */
class FMI_template : public InstanceData {
public:
/*! Initializes empty instance. */
FMI_template();
/*! Destructor, writes out cached results from Therakles. */
~FMI_template();
/*! Initializes model */
void init();
/*! This function triggers a state-update of the embedded model whenever our cached input
data differs from the input data in the model.
*/
void updateIfModified();
/*! Called from fmi2DoStep(). */
virtual void integrateTo(double tCommunicationIntervalEnd);
virtual void doStep();
// Functions for getting/setting the state
/*! This function computes the size needed for full serizalization of
the FMU and stores the size in m_fmuStateSize.
\note The size includes the leading 8byte for the 64bit integer size
of the memory array (for testing purposes).
*/
virtual void computeFMUStateSize();
/*! Copies the internal state of the FMU to the memory array pointed to by FMUstate.
Memory array always has size m_fmuStateSize.
*/
virtual void serializeFMUstate(void * FMUstate);
/*! Copies the content of the memory array pointed to by FMUstate to the internal state of the FMU.
Memory array always has size m_fmuStateSize.
*/
virtual bool deserializeFMUstate(void * FMUstate);
/*! Cached current time point of the FMU, defines starting point for time integration in co-simulation mode. */
double m_currentTimePoint;
}; // class FMI_template
#endif // FMI_templateH
\ No newline at end of file
/*
Generic FMI Interface Implementation
This file is part of FMICodeGenerator (https://github.com/ghorwin/FMICodeGenerator)
BSD 3-Clause License
Copyright (c) 2018, Andreas Nicolai
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef InstanceDataH
#define InstanceDataH
#include <vector>
#include <map>
#include <set>
#include <string>
#include "fmi2FunctionTypes.h"
#include "Launcher.hpp"
/*! This class wraps data needed for FMUs and implements common functionality.
In order to use this in your own InstanceData structure, you must inherit this
file and implement the following functions:
\code
class MyFMIClass : public InstanceDataCommon {
public:
// Initializes InstanceData
void init();
// Re-implement if you want ModelExchange support
virtual void updateIfModified();
// Re-implement if you want CoSim support
virtual void integrateTo(double tCommunicationIntervalEnd);
};
\endcode
Also, you must define the constant with some GUID and implement the static function create().
\code
const char * const InstanceData::GUID = "{471a3b52-4923-44d8-ab4a-fcdb813c7322}";
InstanceData * InstanceData::create() {
return new MyFMIClass;
}
\endcode
in your MyFMIClass.cpp file.
*/
class InstanceData {
public:
/*! Global unique ID that identifies this FMU.
Must match the GUID in the ModelDescription file.
\note This GUID is model-specific, so you must define this static symbol
in the cpp file of your derived class.
*/
static const char * const GUID;
/*! Factory function, needs to be implemented in user code.
\note Only the model-specific implementation knows the concrete type of the class
derived from abstract InterfaceData class, and so this function must be
implemented in the model-specific code.
*/
static InstanceData * create();
/*! Initializes empty instance.
\note You must initialize all input and output variables here, since input
variable can be set and output variables can be requested, even before
entering initialization mode (i.e. before a call to init()).
*/
InstanceData();
/*! Destructor, resource cleanup. */
virtual ~InstanceData();
/*! Re-implement this function in derived classes to perform initialization
of the model during the initialization phase.
*/
virtual void init() {}
/*! This function triggers a state-update of the embedded model whenever our cached input
data differs from the input data in the model.
Re-implement in models that support model exchange.
\note You should check the state of m_externalInputVarsModified and only
update the results of this flag is true. Afterwards set this flag to false.
*/
virtual void updateIfModified() {}
/*! Called from fmi2DoStep().
Re-implement in models that support co-simulation.
*/
virtual void integrateTo(double tCommunicationIntervalEnd) { (void)tCommunicationIntervalEnd; }
virtual void doStep() {}
/*! Send a logging message to FMU environment if logger is present.*/
void logger(fmi2Status state, fmi2String category, fmi2String msg);
/*! Send a logging message to FMU environment if logger is present.
This function copies the error message (which may be a temporary string object) into the
persistent member variable m_lastError and passes a pointer to this string through the
logger function.
*/
void logger(fmi2Status state, fmi2String category, const std::string & msg) {
m_lastError = msg;
logger(state, category, m_lastError.c_str());
}
/*! Sets a new input parameter of type double. */
void setReal(int varID, double value);
/*! Sets a new input parameter of type int. */
void setInt(int varID, int value);
/*! Sets a new input parameter of type string. */
void setString(int varID, fmi2String value);
/*! Sets a new input parameter of type bool. */
void setBool(int varID, bool value);
/*! Retrieves an output parameter of type double. */
void getReal(int varID, double & value);
/*! Retrieves an output parameter of type int. */
void getInt(int varID, int & value);
/*! Retrieves an output parameter of type string. */
void getString(int varID, fmi2String & value);
/*! Retrieves an output parameter of type bool. */
void getBool(int varID, bool & value);
/*! Called from fmi2CompletedIntegratorStep(): only ModelExchange. */
void completedIntegratorStep();
/*! Called from completedIntegratorStep(): only ModelExchange.
Re-implement with your own code.
*/
virtual void completedIntegratorStep(double t_stepEnd, double * yInput) { (void)t_stepEnd; (void)yInput; }
/*! Re-implement for getFMUState()/setFMUState() support.
This function computes the size needed for full serizalization of
the FMU and stores the size in m_fmuStateSize.
\note The size includes the leading 8byte for the 64bit integer size
of the memory array (for testing purposes).
If serialization is not supported, the function will set an fmu size of 0.
*/
virtual void computeFMUStateSize() { m_fmuStateSize = 0; } // default implementation sets zero size = no serialization
/*! Re-implement for getFMUState() support.
Copies the internal state of the FMU to the memory array pointed to by FMUstate.
Memory array always has size m_fmuStateSize.
*/
virtual void serializeFMUstate(void * FMUstate) { (void)FMUstate; }
/*! Re-implement for setFMUState() support.
Copies the content of the memory array pointed to by FMUstate to the internal state of the FMU.
Memory array always has size m_fmuStateSize.
\return Returns false if checks during deserialization fail.
*/
virtual bool deserializeFMUstate(void * FMUstate) { (void)FMUstate; return true; }
/*! Called from either doStep() or terminate() in CoSimulation mode whenever
a communication interval has been completed and all related buffers can be cleared/output files can be
written.
*/
virtual void clearBuffers() {}
Launcher* m_launcher;
/*! Stores the FMU callback functions for later use.
It is usable between fmi2Instantiate and fmi2Terminate.*/
const fmi2CallbackFunctions* m_callbackFunctions;
/*! True if in initialization mode. */
bool m_initializationMode;
/*! Name of the instance inside the FMU environment.*/
std::string m_instanceName;
/*! Resource root path as set via fmi2Instantiate(). */
std::string m_resourceLocation;
/*! Logging enabled flag as set via fmi2Instantiate(). */
bool m_loggingOn;
/*! Logging categories supported by the master. */
std::vector<std::string> m_loggingCategories;
/*! If true, this is a ModelExchange FMU. */
bool m_modelExchange;
std::map<int,int> m_boolVar;
std::map<int,double> m_realVar;
std::map<int,int> m_integerVar;
std::map<int,std::string> m_stringVar;
/*! Time point in [s] received by last call to fmi2SetTime(). */
double m_tInput;
/*! Model state vector as received by last call to fmi2SetContinuousStates(). */
std::vector<double> m_yInput;
/*! Model derivatives vector as updated by last call to updateIfModified(). */
std::vector<double> m_ydot;
/*! Signals that one of the real parameter inputs have been changed.
This flag is reset whenever updateIfModified() has been called.
The flag is set in any of the setXXXParameter() functions.
*/
bool m_externalInputVarsModified;
/*! Holds the size of the FMU when serialized in memory.
This value does not change after full initialization of the solver so it can be cached.
Initially it will be zero so functions can check if initialization is properly done.
*/
size_t m_fmuStateSize;
/*! Holds pointers to all currently stored FMU states.
Pointers get added in function fmi2GetFMUstate(), and removed in fmi2FreeFMUstate().
Unreleased memory gets deallocated in destructor.
*/
std::set<void*> m_fmuStates;
/*! Persistent string pointing to last error message.
\warning DO not change/resize string manually, only through logger() function.
*/
std::string m_lastError;
}; // class InstanceData
#endif // InstanceDataH
\ No newline at end of file
#include <iostream>
#include <string>
#include <map>
using namespace std;
extern map<string,int> int_variables;
extern map<string,double> real_variables;
extern map<string,int> boolean_variables;
extern map<string,string> string_variables;
extern map<int,string> inverted_map;
//extern map<string,double> variables;
//extern map<string,string> variables;
\ No newline at end of file
#ifndef fmi2FunctionTypes_h
#define fmi2FunctionTypes_h
#include "fmi2TypesPlatform.h"
/* This header file must be utilized when compiling an FMU or an FMI master.
It declares data and function types for FMI 2.0.3
Revisions:
- Sep. 30, 2019: License changed to 2-clause BSD License (without extensions)
- Jul. 5, 2019: Remove const modifier from fields of fmi2CallbackFunctions (#216)
- Sep. 6, 2018: Parameter names added to function prototypes
- Apr. 9, 2014: all prefixes "fmi" renamed to "fmi2" (decision from April 8)
- Apr. 3, 2014: Added #include <stddef.h> for size_t definition
- Mar. 27, 2014: Added #include "fmiTypesPlatform.h" (#179)
- Mar. 26, 2014: Introduced function argument "void" for the functions (#171)
fmiGetTypesPlatformTYPE and fmiGetVersionTYPE
- Oct. 11, 2013: Functions of ModelExchange and CoSimulation merged:
fmiInstantiateModelTYPE , fmiInstantiateSlaveTYPE -> fmiInstantiateTYPE
fmiFreeModelInstanceTYPE, fmiFreeSlaveInstanceTYPE -> fmiFreeInstanceTYPE
fmiEnterModelInitializationModeTYPE, fmiEnterSlaveInitializationModeTYPE -> fmiEnterInitializationModeTYPE
fmiExitModelInitializationModeTYPE , fmiExitSlaveInitializationModeTYPE -> fmiExitInitializationModeTYPE
fmiTerminateModelTYPE , fmiTerminateSlaveTYPE -> fmiTerminate
fmiResetSlave -> fmiReset (now also for ModelExchange and not only for CoSimulation)
Functions renamed
fmiUpdateDiscreteStatesTYPE -> fmiNewDiscreteStatesTYPE
Renamed elements of the enumeration fmiEventInfo
upcomingTimeEvent -> nextEventTimeDefined // due to generic naming scheme: varDefined + var
newUpdateDiscreteStatesNeeded -> newDiscreteStatesNeeded;
- June 13, 2013: Changed type fmiEventInfo
Functions removed:
fmiInitializeModelTYPE
fmiEventUpdateTYPE
fmiCompletedEventIterationTYPE
fmiInitializeSlaveTYPE
Functions added:
fmiEnterModelInitializationModeTYPE
fmiExitModelInitializationModeTYPE
fmiEnterEventModeTYPE
fmiUpdateDiscreteStatesTYPE
fmiEnterContinuousTimeModeTYPE
fmiEnterSlaveInitializationModeTYPE;
fmiExitSlaveInitializationModeTYPE;
- Feb. 17, 2013: Added third argument to fmiCompletedIntegratorStepTYPE
Changed function name "fmiTerminateType" to "fmiTerminateModelType" (due to #113)
Changed function name "fmiGetNominalContinuousStateTYPE" to
"fmiGetNominalsOfContinuousStatesTYPE"
Removed fmiGetStateValueReferencesTYPE.
- Nov. 14, 2011: First public Version
Copyright (C) 2008-2011 MODELISAR consortium,
2012-2021 Modelica Association Project "FMI"
All rights reserved.
This file is licensed by the copyright holders under the 2-Clause BSD License
(https://opensource.org/licenses/BSD-2-Clause):
----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------------------
*/
#ifdef __cplusplus
extern "C" {
#endif
/* make sure all compiler use the same alignment policies for structures */
#if defined _MSC_VER || defined __GNUC__
#pragma pack(push,8)
#endif
/* Include stddef.h, in order that size_t etc. is defined */
#include <stddef.h>
/* Type definitions */
typedef enum {
fmi2OK,
fmi2Warning,
fmi2Discard,
fmi2Error,
fmi2Fatal,
fmi2Pending
} fmi2Status;
typedef enum {
fmi2ModelExchange,
fmi2CoSimulation
} fmi2Type;
typedef enum {
fmi2DoStepStatus,
fmi2PendingStatus,
fmi2LastSuccessfulTime,
fmi2Terminated
} fmi2StatusKind;
typedef void (*fmi2CallbackLogger) (fmi2ComponentEnvironment componentEnvironment,
fmi2String instanceName,
fmi2Status status,
fmi2String category,
fmi2String message,
...);
typedef void* (*fmi2CallbackAllocateMemory)(size_t nobj, size_t size);
typedef void (*fmi2CallbackFreeMemory) (void* obj);
typedef void (*fmi2StepFinished) (fmi2ComponentEnvironment componentEnvironment,
fmi2Status status);
typedef struct {
fmi2CallbackLogger logger;
fmi2CallbackAllocateMemory allocateMemory;
fmi2CallbackFreeMemory freeMemory;
fmi2StepFinished stepFinished;
fmi2ComponentEnvironment componentEnvironment;
} fmi2CallbackFunctions;
typedef struct {
fmi2Boolean newDiscreteStatesNeeded;
fmi2Boolean terminateSimulation;
fmi2Boolean nominalsOfContinuousStatesChanged;
fmi2Boolean valuesOfContinuousStatesChanged;
fmi2Boolean nextEventTimeDefined;
fmi2Real nextEventTime;
} fmi2EventInfo;
/* reset alignment policy to the one set before reading this file */
#if defined _MSC_VER || defined __GNUC__
#pragma pack(pop)
#endif
/* Define fmi2 function pointer types to simplify dynamic loading */
/***************************************************
Types for Common Functions
****************************************************/
/* Inquire version numbers of header files and setting logging status */
typedef const char* fmi2GetTypesPlatformTYPE(void);
typedef const char* fmi2GetVersionTYPE(void);
typedef fmi2Status fmi2SetDebugLoggingTYPE(fmi2Component c,
fmi2Boolean loggingOn,
size_t nCategories,
const fmi2String categories[]);
/* Creation and destruction of FMU instances and setting debug status */
typedef fmi2Component fmi2InstantiateTYPE(fmi2String instanceName,
fmi2Type fmuType,
fmi2String fmuGUID,
fmi2String fmuResourceLocation,
const fmi2CallbackFunctions* functions,
fmi2Boolean visible,
fmi2Boolean loggingOn);
typedef void fmi2FreeInstanceTYPE(fmi2Component c);
/* Enter and exit initialization mode, terminate and reset */
typedef fmi2Status fmi2SetupExperimentTYPE (fmi2Component c,
fmi2Boolean toleranceDefined,
fmi2Real tolerance,
fmi2Real startTime,
fmi2Boolean stopTimeDefined,
fmi2Real stopTime);
typedef fmi2Status fmi2EnterInitializationModeTYPE(fmi2Component c);
typedef fmi2Status fmi2ExitInitializationModeTYPE (fmi2Component c);
typedef fmi2Status fmi2TerminateTYPE (fmi2Component c);
typedef fmi2Status fmi2ResetTYPE (fmi2Component c);
/* Getting and setting variable values */
typedef fmi2Status fmi2GetRealTYPE (fmi2Component c, const fmi2ValueReference vr[], size_t nvr, fmi2Real value[]);
typedef fmi2Status fmi2GetIntegerTYPE(fmi2Component c, const fmi2ValueReference vr[], size_t nvr, fmi2Integer value[]);
typedef fmi2Status fmi2GetBooleanTYPE(fmi2Component c, const fmi2ValueReference vr[], size_t nvr, fmi2Boolean value[]);
typedef fmi2Status fmi2GetStringTYPE (fmi2Component c, const fmi2ValueReference vr[], size_t nvr, fmi2String value[]);
typedef fmi2Status fmi2SetRealTYPE (fmi2Component c, const fmi2ValueReference vr[], size_t nvr, const fmi2Real value[]);
typedef fmi2Status fmi2SetIntegerTYPE(fmi2Component c, const fmi2ValueReference vr[], size_t nvr, const fmi2Integer value[]);
typedef fmi2Status fmi2SetBooleanTYPE(fmi2Component c, const fmi2ValueReference vr[], size_t nvr, const fmi2Boolean value[]);
typedef fmi2Status fmi2SetStringTYPE (fmi2Component c, const fmi2ValueReference vr[], size_t nvr, const fmi2String value[]);
/* Getting and setting the internal FMU state */
typedef fmi2Status fmi2GetFMUstateTYPE (fmi2Component c, fmi2FMUstate* FMUstate);
typedef fmi2Status fmi2SetFMUstateTYPE (fmi2Component c, fmi2FMUstate FMUstate);
typedef fmi2Status fmi2FreeFMUstateTYPE (fmi2Component c, fmi2FMUstate* FMUstate);
typedef fmi2Status fmi2SerializedFMUstateSizeTYPE(fmi2Component c, fmi2FMUstate FMUstate, size_t* size);
typedef fmi2Status fmi2SerializeFMUstateTYPE (fmi2Component c, fmi2FMUstate FMUstate, fmi2Byte serializedState[], size_t size);
typedef fmi2Status fmi2DeSerializeFMUstateTYPE (fmi2Component c, const fmi2Byte serializedState[], size_t size, fmi2FMUstate* FMUstate);
/* Getting partial derivatives */
typedef fmi2Status fmi2GetDirectionalDerivativeTYPE(fmi2Component c,
const fmi2ValueReference vUnknown_ref[], size_t nUnknown,
const fmi2ValueReference vKnown_ref[], size_t nKnown,
const fmi2Real dvKnown[],
fmi2Real dvUnknown[]);
/***************************************************
Types for Functions for FMI2 for Model Exchange
****************************************************/
/* Enter and exit the different modes */
typedef fmi2Status fmi2EnterEventModeTYPE (fmi2Component c);
typedef fmi2Status fmi2NewDiscreteStatesTYPE (fmi2Component c, fmi2EventInfo* fmi2eventInfo);
typedef fmi2Status fmi2EnterContinuousTimeModeTYPE(fmi2Component c);
typedef fmi2Status fmi2CompletedIntegratorStepTYPE(fmi2Component c,
fmi2Boolean noSetFMUStatePriorToCurrentPoint,
fmi2Boolean* enterEventMode,
fmi2Boolean* terminateSimulation);
/* Providing independent variables and re-initialization of caching */
typedef fmi2Status fmi2SetTimeTYPE (fmi2Component c, fmi2Real time);
typedef fmi2Status fmi2SetContinuousStatesTYPE(fmi2Component c, const fmi2Real x[], size_t nx);
/* Evaluation of the model equations */
typedef fmi2Status fmi2GetDerivativesTYPE (fmi2Component c, fmi2Real derivatives[], size_t nx);
typedef fmi2Status fmi2GetEventIndicatorsTYPE (fmi2Component c, fmi2Real eventIndicators[], size_t ni);
typedef fmi2Status fmi2GetContinuousStatesTYPE (fmi2Component c, fmi2Real x[], size_t nx);
typedef fmi2Status fmi2GetNominalsOfContinuousStatesTYPE(fmi2Component c, fmi2Real x_nominal[], size_t nx);
/***************************************************
Types for Functions for FMI2 for Co-Simulation
****************************************************/
/* Simulating the slave */
typedef fmi2Status fmi2SetRealInputDerivativesTYPE (fmi2Component c,
const fmi2ValueReference vr[], size_t nvr,
const fmi2Integer order[],
const fmi2Real value[]);
typedef fmi2Status fmi2GetRealOutputDerivativesTYPE(fmi2Component c,
const fmi2ValueReference vr[], size_t nvr,
const fmi2Integer order[],
fmi2Real value[]);
typedef fmi2Status fmi2DoStepTYPE (fmi2Component c,
fmi2Real currentCommunicationPoint,
fmi2Real communicationStepSize,
fmi2Boolean noSetFMUStatePriorToCurrentPoint);
typedef fmi2Status fmi2CancelStepTYPE(fmi2Component c);
/* Inquire slave status */
typedef fmi2Status fmi2GetStatusTYPE (fmi2Component c, const fmi2StatusKind s, fmi2Status* value);
typedef fmi2Status fmi2GetRealStatusTYPE (fmi2Component c, const fmi2StatusKind s, fmi2Real* value);
typedef fmi2Status fmi2GetIntegerStatusTYPE(fmi2Component c, const fmi2StatusKind s, fmi2Integer* value);
typedef fmi2Status fmi2GetBooleanStatusTYPE(fmi2Component c, const fmi2StatusKind s, fmi2Boolean* value);
typedef fmi2Status fmi2GetStringStatusTYPE (fmi2Component c, const fmi2StatusKind s, fmi2String* value);
#ifdef __cplusplus
} /* end of extern "C" { */
#endif
#endif /* fmi2FunctionTypes_h */
#ifndef fmi2Functions_h
#define fmi2Functions_h
/* This header file must be utilized when compiling a FMU.
It defines all functions of the
FMI 2.0.3 Model Exchange and Co-Simulation Interface.
In order to have unique function names even if several FMUs
are compiled together (e.g. for embedded systems), every "real" function name
is constructed by prepending the function name by "FMI2_FUNCTION_PREFIX".
Therefore, the typical usage is:
#define FMI2_FUNCTION_PREFIX MyModel_
#include "fmi2Functions.h"
As a result, a function that is defined as "fmi2GetDerivatives" in this header file,
is actually getting the name "MyModel_fmi2GetDerivatives".
This only holds if the FMU is shipped in C source code, or is compiled in a
static link library. For FMUs compiled in a DLL/sharedObject, the "actual" function
names are used and "FMI2_FUNCTION_PREFIX" must not be defined.
Revisions:
- Sep. 29, 2019: License changed to 2-clause BSD License (without extensions)
- Apr. 9, 2014: All prefixes "fmi" renamed to "fmi2" (decision from April 8)
- Mar. 26, 2014: FMI_Export set to empty value if FMI_Export and FMI_FUNCTION_PREFIX
are not defined (#173)
- Oct. 11, 2013: Functions of ModelExchange and CoSimulation merged:
fmiInstantiateModel , fmiInstantiateSlave -> fmiInstantiate
fmiFreeModelInstance, fmiFreeSlaveInstance -> fmiFreeInstance
fmiEnterModelInitializationMode, fmiEnterSlaveInitializationMode -> fmiEnterInitializationMode
fmiExitModelInitializationMode , fmiExitSlaveInitializationMode -> fmiExitInitializationMode
fmiTerminateModel, fmiTerminateSlave -> fmiTerminate
fmiResetSlave -> fmiReset (now also for ModelExchange and not only for CoSimulation)
Functions renamed:
fmiUpdateDiscreteStates -> fmiNewDiscreteStates
- June 13, 2013: Functions removed:
fmiInitializeModel
fmiEventUpdate
fmiCompletedEventIteration
fmiInitializeSlave
Functions added:
fmiEnterModelInitializationMode
fmiExitModelInitializationMode
fmiEnterEventMode
fmiUpdateDiscreteStates
fmiEnterContinuousTimeMode
fmiEnterSlaveInitializationMode;
fmiExitSlaveInitializationMode;
- Feb. 17, 2013: Portability improvements:
o DllExport changed to FMI_Export
o FUNCTION_PREFIX changed to FMI_FUNCTION_PREFIX
o Allow undefined FMI_FUNCTION_PREFIX (meaning no prefix is used)
Changed function name "fmiTerminate" to "fmiTerminateModel" (due to #113)
Changed function name "fmiGetNominalContinuousState" to
"fmiGetNominalsOfContinuousStates"
Removed fmiGetStateValueReferences.
- Nov. 14, 2011: Adapted to FMI 2.0:
o Split into two files (fmiFunctions.h, fmiTypes.h) in order
that code that dynamically loads an FMU can directly
utilize the header files).
o Added C++ encapsulation of C-part, in order that the header
file can be directly utilized in C++ code.
o fmiCallbackFunctions is passed as pointer to fmiInstantiateXXX
o stepFinished within fmiCallbackFunctions has as first
argument "fmiComponentEnvironment" and not "fmiComponent".
o New functions to get and set the complete FMU state
and to compute partial derivatives.
- Nov. 4, 2010: Adapted to specification text:
o fmiGetModelTypesPlatform renamed to fmiGetTypesPlatform
o fmiInstantiateSlave: Argument GUID replaced by fmuGUID
Argument mimetype replaced by mimeType
o tabs replaced by spaces
- Oct. 16, 2010: Functions for FMI for Co-simulation added
- Jan. 20, 2010: stateValueReferencesChanged added to struct fmiEventInfo (ticket #27)
(by M. Otter, DLR)
Added WIN32 pragma to define the struct layout (ticket #34)
(by J. Mauss, QTronic)
- Jan. 4, 2010: Removed argument intermediateResults from fmiInitialize
Renamed macro fmiGetModelFunctionsVersion to fmiGetVersion
Renamed macro fmiModelFunctionsVersion to fmiVersion
Replaced fmiModel by fmiComponent in decl of fmiInstantiateModel
(by J. Mauss, QTronic)
- Dec. 17, 2009: Changed extension "me" to "fmi" (by Martin Otter, DLR).
- Dez. 14, 2009: Added eventInfo to meInitialize and added
meGetNominalContinuousStates (by Martin Otter, DLR)
- Sept. 9, 2009: Added DllExport (according to Peter Nilsson's suggestion)
(by A. Junghanns, QTronic)
- Sept. 9, 2009: Changes according to FMI-meeting on July 21:
meInquireModelTypesVersion -> meGetModelTypesPlatform
meInquireModelFunctionsVersion -> meGetModelFunctionsVersion
meSetStates -> meSetContinuousStates
meGetStates -> meGetContinuousStates
removal of meInitializeModelClass
removal of meGetTime
change of arguments of meInstantiateModel
change of arguments of meCompletedIntegratorStep
(by Martin Otter, DLR):
- July 19, 2009: Added "me" as prefix to file names (by Martin Otter, DLR).
- March 2, 2009: Changed function definitions according to the last design
meeting with additional improvements (by Martin Otter, DLR).
- Dec. 3 , 2008: First version by Martin Otter (DLR) and Hans Olsson (Dynasim).
Copyright (C) 2008-2011 MODELISAR consortium,
2012-2021 Modelica Association Project "FMI"
All rights reserved.
This file is licensed by the copyright holders under the 2-Clause BSD License
(https://opensource.org/licenses/BSD-2-Clause):
----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------------------
*/
#ifdef __cplusplus
extern "C" {
#endif
#include "fmi2TypesPlatform.h"
#include "fmi2FunctionTypes.h"
#include <stdlib.h>
/*
Export FMI2 API functions on Windows and under GCC.
If custom linking is desired then the FMI2_Export must be
defined before including this file. For instance,
it may be set to __declspec(dllimport).
*/
#if !defined(FMI2_Export)
#if !defined(FMI2_FUNCTION_PREFIX)
#if defined _WIN32 || defined __CYGWIN__
/* Note: both gcc & MSVC on Windows support this syntax. */
#define FMI2_Export __declspec(dllexport)
#else
#if __GNUC__ >= 4
#define FMI2_Export __attribute__ ((visibility ("default")))
#else
#define FMI2_Export
#endif
#endif
#else
#define FMI2_Export
#endif
#endif
/* Macros to construct the real function name
(prepend function name by FMI2_FUNCTION_PREFIX) */
#if defined(FMI2_FUNCTION_PREFIX)
#define fmi2Paste(a,b) a ## b
#define fmi2PasteB(a,b) fmi2Paste(a,b)
#define fmi2FullName(name) fmi2PasteB(FMI2_FUNCTION_PREFIX, name)
#else
#define fmi2FullName(name) name
#endif
/***************************************************
Common Functions
****************************************************/
#define fmi2GetTypesPlatform fmi2FullName(fmi2GetTypesPlatform)
#define fmi2GetVersion fmi2FullName(fmi2GetVersion)
#define fmi2SetDebugLogging fmi2FullName(fmi2SetDebugLogging)
#define fmi2Instantiate fmi2FullName(fmi2Instantiate)
#define fmi2FreeInstance fmi2FullName(fmi2FreeInstance)
#define fmi2SetupExperiment fmi2FullName(fmi2SetupExperiment)
#define fmi2EnterInitializationMode fmi2FullName(fmi2EnterInitializationMode)
#define fmi2ExitInitializationMode fmi2FullName(fmi2ExitInitializationMode)
#define fmi2Terminate fmi2FullName(fmi2Terminate)
#define fmi2Reset fmi2FullName(fmi2Reset)
#define fmi2GetReal fmi2FullName(fmi2GetReal)
#define fmi2GetInteger fmi2FullName(fmi2GetInteger)
#define fmi2GetBoolean fmi2FullName(fmi2GetBoolean)
#define fmi2GetString fmi2FullName(fmi2GetString)
#define fmi2SetReal fmi2FullName(fmi2SetReal)
#define fmi2SetInteger fmi2FullName(fmi2SetInteger)
#define fmi2SetBoolean fmi2FullName(fmi2SetBoolean)
#define fmi2SetString fmi2FullName(fmi2SetString)
#define fmi2GetFMUstate fmi2FullName(fmi2GetFMUstate)
#define fmi2SetFMUstate fmi2FullName(fmi2SetFMUstate)
#define fmi2FreeFMUstate fmi2FullName(fmi2FreeFMUstate)
#define fmi2SerializedFMUstateSize fmi2FullName(fmi2SerializedFMUstateSize)
#define fmi2SerializeFMUstate fmi2FullName(fmi2SerializeFMUstate)
#define fmi2DeSerializeFMUstate fmi2FullName(fmi2DeSerializeFMUstate)
#define fmi2GetDirectionalDerivative fmi2FullName(fmi2GetDirectionalDerivative)
/***************************************************
Functions for FMI2 for Model Exchange
****************************************************/
#define fmi2EnterEventMode fmi2FullName(fmi2EnterEventMode)
#define fmi2NewDiscreteStates fmi2FullName(fmi2NewDiscreteStates)
#define fmi2EnterContinuousTimeMode fmi2FullName(fmi2EnterContinuousTimeMode)
#define fmi2CompletedIntegratorStep fmi2FullName(fmi2CompletedIntegratorStep)
#define fmi2SetTime fmi2FullName(fmi2SetTime)
#define fmi2SetContinuousStates fmi2FullName(fmi2SetContinuousStates)
#define fmi2GetDerivatives fmi2FullName(fmi2GetDerivatives)
#define fmi2GetEventIndicators fmi2FullName(fmi2GetEventIndicators)
#define fmi2GetContinuousStates fmi2FullName(fmi2GetContinuousStates)
#define fmi2GetNominalsOfContinuousStates fmi2FullName(fmi2GetNominalsOfContinuousStates)
/***************************************************
Functions for FMI2 for Co-Simulation
****************************************************/
#define fmi2SetRealInputDerivatives fmi2FullName(fmi2SetRealInputDerivatives)
#define fmi2GetRealOutputDerivatives fmi2FullName(fmi2GetRealOutputDerivatives)
#define fmi2DoStep fmi2FullName(fmi2DoStep)
#define fmi2CancelStep fmi2FullName(fmi2CancelStep)
#define fmi2GetStatus fmi2FullName(fmi2GetStatus)
#define fmi2GetRealStatus fmi2FullName(fmi2GetRealStatus)
#define fmi2GetIntegerStatus fmi2FullName(fmi2GetIntegerStatus)
#define fmi2GetBooleanStatus fmi2FullName(fmi2GetBooleanStatus)
#define fmi2GetStringStatus fmi2FullName(fmi2GetStringStatus)
/* Version number */
#define fmi2Version "2.0"
/***************************************************
Common Functions
****************************************************/
/* Inquire version numbers of header files */
FMI2_Export fmi2GetTypesPlatformTYPE fmi2GetTypesPlatform;
FMI2_Export fmi2GetVersionTYPE fmi2GetVersion;
FMI2_Export fmi2SetDebugLoggingTYPE fmi2SetDebugLogging;
/* Creation and destruction of FMU instances */
FMI2_Export fmi2InstantiateTYPE fmi2Instantiate;
FMI2_Export fmi2FreeInstanceTYPE fmi2FreeInstance;
/* Enter and exit initialization mode, terminate and reset */
FMI2_Export fmi2SetupExperimentTYPE fmi2SetupExperiment;
FMI2_Export fmi2EnterInitializationModeTYPE fmi2EnterInitializationMode;
FMI2_Export fmi2ExitInitializationModeTYPE fmi2ExitInitializationMode;
FMI2_Export fmi2TerminateTYPE fmi2Terminate;
FMI2_Export fmi2ResetTYPE fmi2Reset;
/* Getting and setting variables values */
FMI2_Export fmi2GetRealTYPE fmi2GetReal;
FMI2_Export fmi2GetIntegerTYPE fmi2GetInteger;
FMI2_Export fmi2GetBooleanTYPE fmi2GetBoolean;
FMI2_Export fmi2GetStringTYPE fmi2GetString;
FMI2_Export fmi2SetRealTYPE fmi2SetReal;
FMI2_Export fmi2SetIntegerTYPE fmi2SetInteger;
FMI2_Export fmi2SetBooleanTYPE fmi2SetBoolean;
FMI2_Export fmi2SetStringTYPE fmi2SetString;
/* Getting and setting the internal FMU state */
FMI2_Export fmi2GetFMUstateTYPE fmi2GetFMUstate;
FMI2_Export fmi2SetFMUstateTYPE fmi2SetFMUstate;
FMI2_Export fmi2FreeFMUstateTYPE fmi2FreeFMUstate;
FMI2_Export fmi2SerializedFMUstateSizeTYPE fmi2SerializedFMUstateSize;
FMI2_Export fmi2SerializeFMUstateTYPE fmi2SerializeFMUstate;
FMI2_Export fmi2DeSerializeFMUstateTYPE fmi2DeSerializeFMUstate;
/* Getting partial derivatives */
FMI2_Export fmi2GetDirectionalDerivativeTYPE fmi2GetDirectionalDerivative;
/***************************************************
Functions for FMI2 for Model Exchange
****************************************************/
/* Enter and exit the different modes */
FMI2_Export fmi2EnterEventModeTYPE fmi2EnterEventMode;
FMI2_Export fmi2NewDiscreteStatesTYPE fmi2NewDiscreteStates;
FMI2_Export fmi2EnterContinuousTimeModeTYPE fmi2EnterContinuousTimeMode;
FMI2_Export fmi2CompletedIntegratorStepTYPE fmi2CompletedIntegratorStep;
/* Providing independent variables and re-initialization of caching */
FMI2_Export fmi2SetTimeTYPE fmi2SetTime;
FMI2_Export fmi2SetContinuousStatesTYPE fmi2SetContinuousStates;
/* Evaluation of the model equations */
FMI2_Export fmi2GetDerivativesTYPE fmi2GetDerivatives;
FMI2_Export fmi2GetEventIndicatorsTYPE fmi2GetEventIndicators;
FMI2_Export fmi2GetContinuousStatesTYPE fmi2GetContinuousStates;
FMI2_Export fmi2GetNominalsOfContinuousStatesTYPE fmi2GetNominalsOfContinuousStates;
/***************************************************
Functions for FMI2 for Co-Simulation
****************************************************/
/* Simulating the slave */
FMI2_Export fmi2SetRealInputDerivativesTYPE fmi2SetRealInputDerivatives;
FMI2_Export fmi2GetRealOutputDerivativesTYPE fmi2GetRealOutputDerivatives;
FMI2_Export fmi2DoStepTYPE fmi2DoStep;
FMI2_Export fmi2CancelStepTYPE fmi2CancelStep;
/* Inquire slave status */
FMI2_Export fmi2GetStatusTYPE fmi2GetStatus;
FMI2_Export fmi2GetRealStatusTYPE fmi2GetRealStatus;
FMI2_Export fmi2GetIntegerStatusTYPE fmi2GetIntegerStatus;
FMI2_Export fmi2GetBooleanStatusTYPE fmi2GetBooleanStatus;
FMI2_Export fmi2GetStringStatusTYPE fmi2GetStringStatus;
#ifdef __cplusplus
} /* end of extern "C" { */
#endif
#endif /* fmi2Functions_h */
#ifndef fmi2TypesPlatform_h
#define fmi2TypesPlatform_h
/* Standard header file to define the argument types of the
functions of the Functional Mock-up Interface 2.0.3
This header file must be utilized both by the model and
by the simulation engine.
Revisions:
- Sep. 29, 2019: License changed to 2-clause BSD License (without extensions)
- Apr. 9, 2014: All prefixes "fmi" renamed to "fmi2" (decision from April 8)
- Mar 31, 2014: New datatype fmiChar introduced.
- Feb. 17, 2013: Changed fmiTypesPlatform from "standard32" to "default".
Removed fmiUndefinedValueReference since no longer needed
(because every state is defined in ScalarVariables).
- March 20, 2012: Renamed from fmiPlatformTypes.h to fmiTypesPlatform.h
- Nov. 14, 2011: Use the header file "fmiPlatformTypes.h" for FMI 2.0
both for "FMI for model exchange" and for "FMI for co-simulation"
New types "fmiComponentEnvironment", "fmiState", and "fmiByte".
The implementation of "fmiBoolean" is change from "char" to "int".
The #define "fmiPlatform" changed to "fmiTypesPlatform"
(in order that #define and function call are consistent)
- Oct. 4, 2010: Renamed header file from "fmiModelTypes.h" to fmiPlatformTypes.h"
for the co-simulation interface
- Jan. 4, 2010: Renamed meModelTypes_h to fmiModelTypes_h (by Mauss, QTronic)
- Dec. 21, 2009: Changed "me" to "fmi" and "meModel" to "fmiComponent"
according to meeting on Dec. 18 (by Martin Otter, DLR)
- Dec. 6, 2009: Added meUndefinedValueReference (by Martin Otter, DLR)
- Sept. 9, 2009: Changes according to FMI-meeting on July 21:
Changed "version" to "platform", "standard" to "standard32",
Added a precise definition of "standard32" as comment
(by Martin Otter, DLR)
- July 19, 2009: Added "me" as prefix to file names, added meTrue/meFalse,
and changed meValueReferenced from int to unsigned int
(by Martin Otter, DLR).
- March 2, 2009: Moved enums and function pointer definitions to
ModelFunctions.h (by Martin Otter, DLR).
- Dec. 3, 2008 : First version by Martin Otter (DLR) and
Hans Olsson (Dynasim).
Copyright (C) 2008-2011 MODELISAR consortium,
2012-2021 Modelica Association Project "FMI"
All rights reserved.
This file is licensed by the copyright holders under the 2-Clause BSD License
(https://opensource.org/licenses/BSD-2-Clause):
----------------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------------------
*/
/* Platform (unique identification of this header file) */
#define fmi2TypesPlatform "default"
/* Type definitions of variables passed as arguments
Version "default" means:
fmi2Component : an opaque object pointer
fmi2ComponentEnvironment: an opaque object pointer
fmi2FMUstate : an opaque object pointer
fmi2ValueReference : handle to the value of a variable
fmi2Real : double precision floating-point data type
fmi2Integer : basic signed integer data type
fmi2Boolean : basic signed integer data type
fmi2Char : character data type
fmi2String : a pointer to a vector of fmi2Char characters
('\0' terminated, UTF8 encoded)
fmi2Byte : smallest addressable unit of the machine, typically one byte.
*/
typedef void* fmi2Component; /* Pointer to FMU instance */
typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */
typedef void* fmi2FMUstate; /* Pointer to internal FMU state */
typedef unsigned int fmi2ValueReference;
typedef double fmi2Real ;
typedef int fmi2Integer;
typedef int fmi2Boolean;
typedef char fmi2Char;
typedef const fmi2Char* fmi2String;
typedef char fmi2Byte;
/* Values for fmi2Boolean */
#define fmi2True 1
#define fmi2False 0
#endif /* fmi2TypesPlatform_h */
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <fmi2Functions.h>
#include <fmi2FunctionTypes.h>
#include <Variables.hpp>
// global map array that matches each variable of the bip models with their name
map<string,int> int_variables;
map<string,double> real_variables;
map<string,int> boolean_variables;
map<string,string> string_variables;
map<int,string> inverted_map;
int main(int argc, char **argv) {
int ret = EXIT_SUCCESS;
int NUM_ITERATION = 50;
void *handle;
fmi2InstantiateTYPE* (fmi2Instantiate);
fmi2EnterInitializationModeTYPE* (fmi2EnterInitializationMode);
fmi2ExitInitializationModeTYPE* (fmi2ExitInitializationMode);
fmi2SetIntegerTYPE* (fmi2SetInteger);
fmi2GetIntegerTYPE* (fmi2GetInteger);
fmi2DoStepTYPE* (fmi2DoStep);
char *error;
handle = dlopen ("./libProject.so", RTLD_LAZY);
if (!handle) {
fprintf (stderr, "%s\n", dlerror());
exit(1);
}
dlerror(); /* Clear any existing error */
fmi2Instantiate = (fmi2InstantiateTYPE*) dlsym(handle, "fmi2Instantiate");
fmi2EnterInitializationMode = (fmi2EnterInitializationModeTYPE*) dlsym(handle, "fmi2EnterInitializationMode");
fmi2ExitInitializationMode = (fmi2ExitInitializationModeTYPE*) dlsym(handle, "fmi2ExitInitializationMode");
fmi2SetInteger = (fmi2SetIntegerTYPE*) dlsym(handle, "fmi2SetInteger");
fmi2GetInteger = (fmi2GetIntegerTYPE*) dlsym(handle, "fmi2GetInteger");
fmi2DoStep = (fmi2DoStepTYPE*) dlsym(handle, "fmi2DoStep");
if ((error = dlerror()) != NULL) {
fprintf (stderr, "%s\n", error);
exit(1);
}
cout<<"CALL fmi2Instantiate...\n";
fmi2Component c = (*fmi2Instantiate)("prModel", fmi2CoSimulation , "prModel", "resource/location", NULL, true, true);
inverted_map[100] = "ROOT.environment._id__inputIndex";
inverted_map[101] = "ROOT.environment._id__time";
inverted_map[102] = "ROOT.camera._id__inputIndex";
inverted_map[103] = "ROOT.perception._id__inputIndex";
inverted_map[104] = "ROOT.perception._id__result";
inverted_map[105] = "ROOT.controller._id__speed";
inverted_map[106] = "ROOT.controller._id__speedLimit";
inverted_map[107] = "ROOT.controller._id__deltaSpeed";
inverted_map[108] = "ROOT.controller._id__zero";
inverted_map[109] = "ROOT.brake._id__deltaSpeed";
inverted_map[110] = "ROOT.throttle._id__deltaSpeed";
inverted_map[111] = "ROOT.speedSensor._id__speed";
inverted_map[112] = "ROOT.speedSensor._id__deltaSpeed";
const unsigned int vr[] = {100,101,102,103,104,105,106,107,108,109,110,111,112};
const int values[] = {1,10,0,0,0,0,0,0,0,0,0,100,0};
cout<<"CALL fmi2SetInteger...\n";
(*fmi2SetInteger)(c, vr, 13, values);
fmi2Integer values2[] = {0,0,0,0,0,0,0,0,0,0,0,0,0};
cout<<"CALL fmi2EnterInitializationMode...\n";
(*fmi2EnterInitializationMode)(c);
cout<<"CALL fmi2ExitInitializationMode...\n";
//(*fmi2ExitInitializationMode)(c);
int i=0;
while(i<NUM_ITERATION){
i++;
cout<<i<<"\n";
cout<<"CALL fmi2GetInteger...\n";
fmi2GetInteger(c, vr, 13, values2);
cout<<"CALL fmi2DoStep...\n";
fmi2DoStep(c, 0.5,0.6, true);
}
dlclose(handle);
return ret;
}
/*
FMI Interface for Model Exchange and CoSimulation Version 2
This file is part of FMICodeGenerator (https://github.com/ghorwin/FMICodeGenerator)
BSD 3-Clause License
Copyright (c) 2018, Andreas Nicolai
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <memory>
#include <iostream>
#include <sstream>
#include <cstring> // for memcpy
#ifdef DEBUG
#define FMI_ASSERT(p) if (!(p)) \
{ std::cerr << "Assertion failure\nCHECK: " << #p << "\nFILE: " << myFilename(__FILE__) << "\nLINE: " << __LINE__ << '\n'; \
return fmi2Error; }
#else
#define FMI_ASSERT(p) (void)0;
#endif // DEBUG
#ifdef _WIN32
#if _WIN32_WINNT < 0x0501
#define _WIN32_WINNT 0x0501
#endif
#include <windows.h>
#endif // _WIN32
#include <string>
#include <fmi2Functions.h>
#include <fmi2FunctionTypes.h>
#include <InstanceData.h>
#include <FMI_template.h>
// global method that instanciates the system found in the generated code
#include <Variables.hpp>
Component* deploy(int argc, char **argv);
// global map array that matches each variable of the bip models with their name
map<string,int> int_variables;
map<string,double> real_variables;
map<string,int> boolean_variables;
map<string,string> string_variables;
map<int,string> inverted_map;
// *** FMI Interface Functions ***
/* Inquire version numbers of header files */
const char* fmi2GetTypesPlatform() {
// returns platform type, currently "default"
return fmi2TypesPlatform;
}
const char* fmi2GetVersion() {
// returns fmi version, currently "2.0"
return "2.0";
}
// Enables/disables debug logging
fmi2Status fmi2SetDebugLogging(void* c, fmi2Boolean loggingOn, size_t nCategories, const char* const categories[]) {
/*InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
modelInstance->logger(fmi2OK, "logAll", std::string("fmi2SetDebugLogging: logging switched ") + (loggingOn ? "on." : "off."));
modelInstance->m_loggingOn = (loggingOn == fmi2True);
if (modelInstance->m_loggingOn) {
modelInstance->m_loggingCategories.clear();
for (size_t i=0; i<nCategories; ++i)
modelInstance->m_loggingCategories.push_back(std::string(categories[i]));
}*/
return fmi2OK;
}
/* Creation and destruction of FMU instances */
void* fmi2Instantiate(fmi2String instanceName, fmi2Type fmuType, fmi2String guid,
fmi2String fmuResourceLocation,
const fmi2CallbackFunctions* functions,
fmi2Boolean, fmi2Boolean loggingOn)
{
// initial checks
//if (functions == NULL) return NULL;
//if (functions->logger == NULL) return NULL;
/*std::string instanceNameString = instanceName;
/*if (instanceNameString.empty()) {
if (loggingOn) functions->logger(functions->componentEnvironment, instanceName, fmi2Error, "logStatusError", "fmi2Instantiate: Missing instance name.");
return NULL;
}*/
// check for correct model
/*if (std::string(InstanceData::GUID) != guid) {
//functions->logger(functions->componentEnvironment, instanceName, fmi2Error, "logStatusError", "fmi2Instantiate: Invalid/mismatching guid.");
return NULL;
}*/
/*InstanceData * modelInstance ;
try {
// instantiate data structure for instance-specific data
modelInstance = FMI_template::create();
// transfer function arguments
modelInstance->m_callbackFunctions = functions;
modelInstance->m_instanceName = instanceName;
modelInstance->m_modelExchange = (fmuType == fmi2ModelExchange);
modelInstance->m_resourceLocation = fmuResourceLocation;
modelInstance->m_loggingOn = loggingOn;
int argc = 1;
char* argv[] = {"./system"};
Component &component = *deploy(argc, argv);
//cout<<&component<<'\n';
Launcher* l = new Launcher(argc,argv,component);
modelInstance->m_launcher = l;
//cout<<modelInstance->m_launcher<<'\n';
modelInstance->logger(fmi2OK, "logAll", "fmi2Instantiate: Model instance created.");
}
catch (...) {
modelInstance = NULL;
}*/
// return data pointer
return modelInstance;
}
// Free allocated instance data structure
void fmi2FreeInstance(void* c) {
//InstanceData * modelInstance = static_cast<InstanceData*>(c);
//modelInstance->logger(fmi2OK, "logAll", "fmi2FreeInstance: Model instance deleted.");
//delete modelInstance;
}
/* Enter and exit initialization mode, terminate and reset */
fmi2Status fmi2SetupExperiment(void* c, int, double, double,
int, double)
{
//InstanceData * modelInstance = static_cast<InstanceData*>(c);
//FMI_ASSERT(modelInstance != NULL);
//modelInstance->logger(fmi2OK, "logAll", "fmi2SetupExperiment: Call of setup experiment.");
return fmi2OK;
}
// All scalar variables with initial="exact" or "approx" can be set before
// fmi2SetupExperiment has to be called at least once before
fmi2Status fmi2EnterInitializationMode(void* c) {
/*InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
modelInstance->logger(fmi2OK, "logAll", "fmi2EnterInitializationMode: Go into initialization mode.");
modelInstance->m_initializationMode = true;
// let instance data initialize everything that's needed
// now the output directory parameter should be set
try {
modelInstance->init();
// compute and cache serialization size, might be zero if serialization is not supported
if (!modelInstance->m_modelExchange)
modelInstance->computeFMUStateSize();
// init successful
return fmi2OK;
}
catch (std::exception & ex) {
std::string err = ex.what();
err += "\nModel initialization failed.";
modelInstance->logger(fmi2Error, "logStatusError", err);
return fmi2Error;
}*/
return fmi2OK; // delete it
}
// Switch off all initialization equations
fmi2Status fmi2ExitInitializationMode(void* c) {
/*InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
modelInstance->logger(fmi2OK, "logAll", "fmi2ExitInitializationMode: Go out from initialization mode.");
modelInstance->m_initializationMode = false;*/
return fmi2OK;
}
fmi2Status fmi2Terminate(void* c) {
/*InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
modelInstance->clearBuffers();
modelInstance->logger(fmi2OK, "logAll", "fmi2Terminate: Terminate model.");*/
return fmi2OK;
}
fmi2Status fmi2Reset(void* c) {
/*InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
modelInstance->logger(fmi2Warning, "logStatusWarning", "fmi2Reset: Reset the whole model to default. Not implemented yet.");*/
return fmi2OK;
}
/* Getting and setting variables values */
fmi2Status fmi2GetReal(void* c, const fmi2ValueReference vr[], size_t nvr, fmi2Real value[]) {
/*InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
for (size_t i=0; i<nvr; ++i) {
try {
if (inverted_map.find(vr[i]) == inverted_map.end()) {
cout<< "fmi2GetReal: Value Reference " << vr[i] << " not found!" << "\n";
return fmi2Error;
}
cout<<"fmi2GetReal:";
value[i] = real_variables[inverted_map[vr[i]]];
cout<< "(Variable Reference: "<<vr[i]<<", Name: "<< inverted_map[vr[i]]<<", Value: "<<value[i]<<")\n";
//modelInstance->getReal(vr[i], value[i]);
}
catch (std::exception & ex) {
std::string err = ex.what();
err += "\nError in fmi2GetReal()";
modelInstance->logger(fmi2Error, "logStatusError", err);
return fmi2Error;
}
}*/
return fmi2OK;
}
fmi2Status fmi2GetInteger(void* c, const fmi2ValueReference vr[], size_t nvr, fmi2Integer value[]) {
/*InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
for (size_t i=0; i<nvr; ++i) {
try {
if (inverted_map.find(vr[i]) == inverted_map.end()) {
cout<< "fmi2GetInteger: Value Reference " << vr[i] << " not found!" << "\n";
return fmi2Error;
}
cout<<"fmi2GetInteger:";
value[i] = int_variables[inverted_map[vr[i]]];
cout<< "(Variable Reference: "<<vr[i]<<", Name: "<< inverted_map[vr[i]]<<", Value: "<<value[i]<<")\n";
//modelInstance->getInt(vr[i], value[i]);
}
catch (std::exception & ex) {
std::string err = ex.what();
err += "\nError in fmi2GetInteger()";
modelInstance->logger(fmi2Error, "logStatusError", err);
return fmi2Error;
}
} */
return fmi2OK;
}
fmi2Status fmi2GetBoolean(void* c, const fmi2ValueReference vr[], size_t nvr, fmi2Boolean value[]) {
/*InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
for (size_t i=0; i<nvr; ++i) {
try {
//bool val;
//modelInstance->getBool(vr[i], val);
//value[i] = val;
if (inverted_map.find(vr[i]) == inverted_map.end()) {
cout<< "fmi2GetBoolean: Value Reference " << vr[i] << " not found!" << "\n";
return fmi2Error;
}
cout<<"fmi2GetBoolean:";
value[i] = boolean_variables[inverted_map[vr[i]]];
cout<< "(Variable Reference: "<<vr[i]<<", Name: "<< inverted_map[vr[i]]<<", Value: "<<value[i]<<")\n";
}
catch (std::exception & ex) {
std::string err = ex.what();
err += "\nError in fmi2GetBoolean()";
modelInstance->logger(fmi2Error, "logStatusError", err);
return fmi2Error;
}
}*/
return fmi2OK;
}
fmi2Status fmi2GetString(void* c, const fmi2ValueReference vr[], size_t nvr, fmi2String value[]) {
/*InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
for (size_t i=0; i<nvr; ++i) {
try {
if (inverted_map.find(vr[i]) == inverted_map.end()) {
cout<< "fmi2GetString: Value Reference " << vr[i] << " not found!" << "\n";
return fmi2Error;
}
cout<<"fmi2GetString:";
value[i] = string_variables[inverted_map[vr[i]]].c_str(); //must copy the string
cout<< "(Variable Reference: "<<vr[i]<<", Name: "<< inverted_map[vr[i]]<<", Value: "<<value[i]<<")\n";
//modelInstance->getString(vr[i], value[i]);
}
catch (std::exception & ex) {
std::string err = ex.what();
err += "\nError in fmi2GetString()";
modelInstance->logger(fmi2Error, "logStatusError", err);
return fmi2Error;
}
}*/
return fmi2OK;
}
fmi2Status fmi2SetReal (void* c, const fmi2ValueReference vr[], size_t nvr, const fmi2Real value[]) {
/*InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
for (size_t i=0; i<nvr; ++i) {
try {
if (inverted_map.find(vr[i]) == inverted_map.end()) {
cout<< "fmi2SetReal: Value Reference " << vr[i] << " not found!" << "\n";
return fmi2Error;
}
real_variables[inverted_map[vr[i]]] = value[i];
cout<< "fmi2SetReal: (Value Reference " << vr[i] << ", Name: " << inverted_map[vr[i]] << " Value: " <<real_variables[inverted_map[vr[i]]] << ")\n";
//modelInstance->setReal(vr[i], value[i]);
}
catch (std::exception & ex) {
std::string err = ex.what();
err += "\nError in fmi2SetReal()";
modelInstance->logger(fmi2Error, "logStatusError", err);
return fmi2Error;
}
}*/
return fmi2OK;
}
fmi2Status fmi2SetInteger(void* c, const fmi2ValueReference vr[], size_t nvr, const fmi2Integer value[]) {
/*InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
for (size_t i=0; i<nvr; ++i) {
try {
if (inverted_map.find(vr[i]) == inverted_map.end()) {
cout<< "fmi2SetInteger: Value Reference " << vr[i] << " not found!" << "\n";
return fmi2Error;
}
int_variables[inverted_map[vr[i]]] = value[i];
cout<< "fmi2SetInteger: (Value Reference " << vr[i] << ", Name: " << inverted_map[vr[i]] << " Value: " <<int_variables[inverted_map[vr[i]]] << ")\n";
//modelInstance->setInt(vr[i], value[i]);
}
catch (std::exception & ex) {
std::string err = ex.what();
err += "\nError in fmi2SetInteger()";
modelInstance->logger(fmi2Error, "logStatusError", err);
return fmi2Error;
}
}*/
return fmi2OK;
}
fmi2Status fmi2SetBoolean(void* c, const fmi2ValueReference vr[], size_t nvr, const fmi2Boolean value[]) {
/*InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
for (size_t i=0; i<nvr; ++i) {
try {
if (inverted_map.find(vr[i]) == inverted_map.end()) {
cout<< "fmi2SetBoolean: Value Reference " << vr[i] << " not found!" << "\n";
return fmi2Error;
}
boolean_variables[inverted_map[vr[i]]] = value[i];
cout<< "fmi2SetBoolean: (Value Reference " << vr[i] << ", Name: " << inverted_map[vr[i]] << " Value: " <<boolean_variables[inverted_map[vr[i]]] << ")\n";
//modelInstance->setBool(vr[i], value[i]);
}
catch (std::exception & ex) {
std::string err = ex.what();
err += "\nError in fmi2SetBoolean()";
modelInstance->logger(fmi2Error, "logStatusError", err);
return fmi2Error;
}
}*/
return fmi2OK;
}
fmi2Status fmi2SetString(void* c, const fmi2ValueReference vr[], size_t nvr, const fmi2String value[]) {
/*InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
for (size_t i=0; i<nvr; ++i) {
try {
if (inverted_map.find(vr[i]) == inverted_map.end()) {
cout<< "fmi2SetString: Value Reference " << vr[i] << " not found!" << "\n";
return fmi2Error;
}
//strcpy(string_variables[inverted_map[vr[i]]],value[i]);
string_variables[inverted_map[vr[i]]] = value[i];
cout<< "fmi2SetString: (Value Reference " << vr[i] << ", Name: " << inverted_map[vr[i]] << " Value: " <<string_variables[inverted_map[vr[i]]] << ")\n";
//modelInstance->setString(vr[i], value[i]);
}
catch (std::exception & ex) {
std::string err = ex.what();
err += "\nError in fmi2SetString()";
modelInstance->logger(fmi2Error, "logStatusError", err);
return fmi2Error;
}
}*/
return fmi2OK;
}
/* Getting and setting the internal FMU state */
fmi2Status fmi2GetFMUstate(void* c, fmi2FMUstate* FMUstate) {
/*InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
if (modelInstance->m_fmuStateSize == 0) {
modelInstance->logger(fmi2Error, "logStatusError", "fmi2GetFMUstate is called though FMU was not yet completely set up "
"or serialization is not supported by this FMU.");
return fmi2Error;
}
// check if new alloc is needed
if (*FMUstate == NULL) {
// alloc new memory
fmi2FMUstate fmuMem = malloc(modelInstance->m_fmuStateSize);
// remember this memory array
modelInstance->m_fmuStates.insert(fmuMem);
// store size of memory in first 8 bytes of fmu memory
*(size_t*)(fmuMem) = modelInstance->m_fmuStateSize;
// return newly created FMU mem
*FMUstate = fmuMem;
}
else {
// check if FMUstate is in list of stored FMU states
if (modelInstance->m_fmuStates.find(*FMUstate) == modelInstance->m_fmuStates.end()) {
modelInstance->logger(fmi2Error, "logStatusError", "fmi2GetFMUstate is called with invalid FMUstate (unknown or already released pointer).");
return fmi2Error;
}
}
// now copy FMU state into memory array
modelInstance->serializeFMUstate(*FMUstate);
*/
return fmi2OK;
}
fmi2Status fmi2SetFMUstate(void* c, fmi2FMUstate FMUstate) {
/* InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
// check if FMUstate is in list of stored FMU states
if (modelInstance->m_fmuStates.find(FMUstate) == modelInstance->m_fmuStates.end()) {
modelInstance->logger(fmi2Error, "logStatusError", "fmi2SetFMUstate is called with invalid FMUstate (unknown or already released pointer).");
return fmi2Error;
}
// now copy FMU state into memory array
if (!modelInstance->deserializeFMUstate(FMUstate))
return fmi2Error;
*/
return fmi2OK;
}
fmi2Status fmi2FreeFMUstate(void* c, fmi2FMUstate* FMUstate) {
/*InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
if (FMUstate == NULL) {
// similar to "delete NULL" this is a no-op
return fmi2OK;
}
// check if FMUstate is in list of stored FMU states
if (modelInstance->m_fmuStates.find(*FMUstate) == modelInstance->m_fmuStates.end()) {
modelInstance->logger(fmi2Error, "logStatusError", "fmi2FreeFMUstate is called with invalid FMUstate (unknown or already released pointer).");
return fmi2Error;
}
// free memory
free(*FMUstate);
// and remove pointer from list of own fmu state pointers
modelInstance->m_fmuStates.erase(*FMUstate);
*FMUstate = NULL; // set pointer to zero
*/
return fmi2OK;
}
fmi2Status fmi2SerializedFMUstateSize(fmi2Component c, fmi2FMUstate FMUstate, size_t* s) {
/*InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
// check if FMUstate is in list of stored FMU states
if (modelInstance->m_fmuStates.find(FMUstate) == modelInstance->m_fmuStates.end()) {
modelInstance->logger(fmi2Error, "logStatusError", "fmi2FreeFMUstate is called with invalid FMUstate (unknown or already released pointer).");
return fmi2Error;
}
// if the state of stored previously, then we must have a valid fmu size
FMI_ASSERT(modelInstance->m_fmuStateSize != 0);
// store size of memory to copy
*s = modelInstance->m_fmuStateSize;
*/
return fmi2OK;
}
fmi2Status fmi2SerializeFMUstate(fmi2Component c, fmi2FMUstate FMUstate, fmi2Byte serializedState[], size_t /*s*/) {
/*InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
// check if FMUstate is in list of stored FMU states
if (modelInstance->m_fmuStates.find(FMUstate) == modelInstance->m_fmuStates.end()) {
modelInstance->logger(fmi2Error, "logStatusError", "fmi2FreeFMUstate is called with invalid FMUstate (unknown or already released pointer).");
return fmi2Error;
}
// if the state of stored previously, then we must have a valid fmu size
FMI_ASSERT(modelInstance->m_fmuStateSize != 0);
// copy memory
std::memcpy(serializedState, FMUstate, modelInstance->m_fmuStateSize);
*/
return fmi2OK;
}
fmi2Status fmi2DeSerializeFMUstate(void* c, const char serializedState[], size_t s, fmi2FMUstate* FMUstate) {
(void)s;
InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
// check if FMUstate is in list of stored FMU states
if (modelInstance->m_fmuStates.find(FMUstate) == modelInstance->m_fmuStates.end()) {
modelInstance->logger(fmi2Error, "logStatusError", "fmi2FreeFMUstate is called with invalid FMUstate (unknown or already released pointer).");
return fmi2Error;
}
// if the state of stored previously, then we must have a valid fmu size
FMI_ASSERT(modelInstance->m_fmuStateSize == s);
// copy memory
std::memcpy(*FMUstate, serializedState, modelInstance->m_fmuStateSize);
return fmi2OK;
}
/* Getting partial derivatives */
// 33
// optional possibility to evaluate partial derivatives for the FMU
fmi2Status fmi2GetDirectionalDerivative(void* c, const unsigned int[], size_t,
const unsigned int[], size_t,
const double[], double[])
{
InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
modelInstance->logger(fmi2Warning, "logStatusWarning", "fmi2GetDirectionalDerivative is called but not implemented");
return fmi2Warning;
}
/* Enter and exit the different modes */
// Model-Exchange only
fmi2Status fmi2EnterEventMode(void* c){
InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
FMI_ASSERT(modelInstance->m_modelExchange);
std::string text = "fmi2EnterEventMode: Enter into event mode.";
modelInstance->logger(fmi2OK, "logAll", text.c_str());
return fmi2OK;
}
// Model-Exchange only
fmi2Status fmi2NewDiscreteStates(void*, fmi2EventInfo* eventInfo) {
eventInfo->newDiscreteStatesNeeded = false;
return fmi2OK;
}
// Model-Exchange only
fmi2Status fmi2EnterContinuousTimeMode(void* c) {
InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
FMI_ASSERT(modelInstance->m_modelExchange);
modelInstance->logger(fmi2OK, "logAll", "fmi2EnterContinuousTimeMode: Enter into continuous mode.");
return fmi2OK;
}
// Model-Exchange only
fmi2Status fmi2CompletedIntegratorStep (void* c, fmi2Boolean,
fmi2Boolean* enterEventMode, fmi2Boolean* terminateSimulation)
{
InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
FMI_ASSERT(modelInstance->m_modelExchange);
// Currently, we never enter Event mode
*enterEventMode = false;
modelInstance->logger(fmi2OK, "logAll", "Integrator step completed.");
try {
modelInstance->completedIntegratorStep();
}
catch (std::exception & ex) {
std::string err = ex.what();
err += "\nError in fmi2CompletedIntegratorStep()";
modelInstance->logger(fmi2Error, "logStatusError", err);
*terminateSimulation = true;
return fmi2Error;
}
*terminateSimulation = false;
return fmi2OK;
}
/* Providing independent variables and re-initialization of caching */
// Sets a new time point
// Model-Exchange only
fmi2Status fmi2SetTime (void* c, fmi2Real time) {
InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
FMI_ASSERT(modelInstance->m_modelExchange);
std::stringstream strm;
strm << "fmi2SetTime: Set time point: " << time << " s";
modelInstance->logger(fmi2OK, "logAll", strm.str());
// cache new time point
modelInstance->m_tInput = time;
modelInstance->m_externalInputVarsModified = true;
return fmi2OK;
}
// Model-Exchange only
fmi2Status fmi2SetContinuousStates(void* c, const fmi2Real x[], size_t nx) {
InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
FMI_ASSERT(modelInstance->m_modelExchange);
std::stringstream strm;
strm << "fmi2SetContinuousStates: Setting continuous states with size " << nx << " with model size " << modelInstance->m_yInput.size();
modelInstance->logger(fmi2OK, "logAll", strm.str());
FMI_ASSERT(nx == modelInstance->m_yInput.size());
// cache input Y vector
std::memcpy( &(modelInstance->m_yInput[0]), x, nx*sizeof(double) );
modelInstance->m_externalInputVarsModified = true;
return fmi2OK;
}
/* Evaluation of the model equations */
// Model-Exchange only
fmi2Status fmi2GetDerivatives(void* c, fmi2Real derivatives[], size_t nx) {
InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
FMI_ASSERT(modelInstance->m_modelExchange);
std::stringstream strm;
strm << "fmi2GetDerivatives: Getting derivatives with size " << nx << " with model size " << modelInstance->m_ydot.size();
modelInstance->logger(fmi2OK, "logAll", strm.str());
// Update model state if any of the inputs have been modified.
// Does nothing, if the model state is already up-to-date after a previous call
// to updateIfModified().
try {
modelInstance->updateIfModified();
}
catch (std::exception & ex) {
std::string err = ex.what();
err += "\nfmi2GetDerivatives: Exception while updating model";
modelInstance->logger(fmi2Error, "logStatusError", err);
return fmi2Error;
}
// return derivatives currently cached in model
std::memcpy( derivatives, &(modelInstance->m_ydot[0]), nx * sizeof(double) );
return fmi2OK;
}
// Model-Exchange only
fmi2Status fmi2GetEventIndicators (void*, fmi2Real[], size_t){
return fmi2OK;
}
// Model-Exchange only
fmi2Status fmi2GetContinuousStates(void* c, fmi2Real x[], size_t nx) {
InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
FMI_ASSERT(modelInstance->m_modelExchange);
std::stringstream strm;
strm << "fmi2GetContinuousStates: Getting continuous states with size " << nx << " with model size " << modelInstance->m_yInput.size();
modelInstance->logger(fmi2OK, "logAll", strm.str());
FMI_ASSERT(nx == modelInstance->m_yInput.size());
std::memcpy( x, &(modelInstance->m_yInput[0]), nx * sizeof(double) );
return fmi2OK;
}
// Model-Exchange only
fmi2Status fmi2GetNominalsOfContinuousStates(void*, fmi2Real[], size_t) {
return fmi2OK;
}
// CoSim only
fmi2Status fmi2SetRealInputDerivatives(void*, const fmi2ValueReference vr[], size_t nvr,
const fmi2Integer order[], const fmi2Real value[])
{
(void)order; (void)value; (void)vr; (void)nvr;
return fmi2OK;
}
// CoSim only
fmi2Status fmi2GetRealOutputDerivatives(void*, const fmi2ValueReference vr[], size_t nvr,
const fmi2Integer order[], fmi2Real value[])
{
(void)order; (void)value; (void)vr; (void)nvr;
return fmi2OK;
}
// CoSim only
fmi2Status fmi2DoStep(void* c, double currentCommunicationPoint, double communicationStepSize,
int noSetFMUStatePriorToCurrentPoint)
{
InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
FMI_ASSERT(!modelInstance->m_modelExchange);
/*if (noSetFMUStatePriorToCurrentPoint == fmi2True) {
modelInstance->clearBuffers();
}*/
//modelInstance->logger(fmi2OK, "logAll", IBK::FormatString("fmi2DoStep: %1 += %2").arg(currentCommunicationPoint).arg(communicationStepSize));
// if currentCommunicationPoint < current time of integrator, restore
try {
modelInstance->doStep();
}
catch (std::exception & ex) {
std::string err = ex.what();
err += "\fmi2DoStep: Exception while integrating model";
modelInstance->logger(fmi2Error, "logStatusError", err);
return fmi2Error;
}
return fmi2OK;
}
// CoSim only
fmi2Status fmi2CancelStep(void* c) {
InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
FMI_ASSERT(!modelInstance->m_modelExchange);
modelInstance->logger(fmi2OK, "logAll", "fmi2CancelStep: cancel current step.");
return fmi2OK;
}
// CoSim only
fmi2Status fmi2GetStatus(void* c, const fmi2StatusKind s, fmi2Status* value) {
(void)s;(void)value;
InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
FMI_ASSERT(!modelInstance->m_modelExchange);
modelInstance->logger(fmi2OK, "logAll", "fmi2GetStatus: get current status.");
return fmi2OK;
}
// CoSim only
fmi2Status fmi2GetRealStatus(void* c, const fmi2StatusKind s, fmi2Real* value) {
(void)s;(void)value;
InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
FMI_ASSERT(!modelInstance->m_modelExchange);
modelInstance->logger(fmi2OK, "logAll", "fmi2GetRealStatus: get real status.");
return fmi2OK;
}
// CoSim only
fmi2Status fmi2GetIntegerStatus(void* c, const fmi2StatusKind s, fmi2Integer* value) {
(void)s;(void)value;
InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
FMI_ASSERT(!modelInstance->m_modelExchange);
modelInstance->logger(fmi2OK, "logAll", "fmi2GetIntegerStatus: get integer status.");
return fmi2OK;
}
// CoSim only
fmi2Status fmi2GetBooleanStatus(void* c, const fmi2StatusKind s, fmi2Boolean* value) {
(void)s;(void)value;
InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
FMI_ASSERT(!modelInstance->m_modelExchange);
modelInstance->logger(fmi2OK, "logAll", "fmi2GetBooleanStatus: get boolean status.");
return fmi2OK;
}
// CoSim only
fmi2Status fmi2GetStringStatus(void* c, const fmi2StatusKind s, fmi2String* value) {
(void)s;(void)value;
InstanceData * modelInstance = static_cast<InstanceData*>(c);
FMI_ASSERT(modelInstance != NULL);
FMI_ASSERT(!modelInstance->m_modelExchange);
modelInstance->logger(fmi2OK, "logAll", "fmi2GetStringStatus: get string status.");
return fmi2OK;
}
......@@ -3,15 +3,49 @@
# exit 1
#fi
#cd distribution
#./single-archive-dist.sh
#source build/bip-full/setup.sh
#cd ..
BIP_PATH=/home/siemens/bip
cd distribution
./single-archive-dist.sh
source build/bip-full/setup.sh
cd ..
#rm distribution/build/bip-full/bipc-*/bin/bipc.sh
#cp -R examples/sync_lec/* distribution/build/bip-full/bipc-*/bin/
#cd distribution/build/bip-full/bipc-*/bin
source compile_run_bip.sh -c learn Compound
#cp -R ext-cpp/Signs .
#cp ext-cpp/limit .
#cp ext-cpp/model.pt .
./system
###### MODEL CLASSIFICATION EXAMPLE
echo "Creating shared object of modelClassification example ..."
cd examples/SpeedControlModule/modelClassification
echo "Compiling bip example..."
. compile_run_bip.sh -c learn Compound
mv output/build/system .
cd output
echo "Generating .so file ..."
g++ -fPIC Deploy/Deploy.cpp learn/src/learn/* ../ext-cpp/utilities.cpp -I learn/include -I ../ext-cpp/ -I $BIP2_ENGINE_GENERIC_DIR -I $BIP2_ENGINE_SPECIFIC_DIR -shared -o libProject.so -L $BIP_PATH/distribution/build/bip-full/BIP-reference-engine-*/lib/static -lengine
mv libProject.so ../
echo "Created!"
####### IMAGE DETECTION EXAMPLE
echo "Creating shared object of imageDetection example ..."
cd ../../modelDetection/imageDetection
echo "Compiling bip example..."
. compile_run_bip.sh -c learn Compound
mv output/build/system .
cd output
echo "Generating .so file ..."
g++ -fPIC Deploy/Deploy.cpp learn/src/learn/* ../ext-cpp/utilities.cpp -I learn/include -I ../ext-cpp/ -I $BIP2_ENGINE_GENERIC_DIR -I $BIP2_ENGINE_SPECIFIC_DIR -shared -o libProject.so -L $BIP_PATH/distribution/build/bip-full/BIP-reference-engine-*/lib/static -lengine
mv libProject.so ../
echo "Created!"
####### STREAM DETECTION EXAMPLE
echo "Creating shared object of streamDetection example ..."
cd ../../streamDetection
echo "Compiling bip example..."
. compile_run_bip.sh -c learn Compound
mv output/build/system .
cd output
echo "Generating .so file ..."
g++ -fPIC Deploy/Deploy.cpp learn/src/learn/* ../ext-cpp/utilities.cpp -I learn/include -I ../ext-cpp/ -I $BIP2_ENGINE_GENERIC_DIR -I $BIP2_ENGINE_SPECIFIC_DIR -shared -o libProject.so -L $BIP_PATH/distribution/build/bip-full/BIP-reference-engine-*/lib/static -lengine
mv libProject.so ../
echo "Created!"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment