Skip to content

Commit 403265c

Browse files
author
Marcus Walther
committed
- added a simple logger class to cpp-runtime
- cleaned up FMU files
1 parent be21653 commit 403265c

File tree

6 files changed

+397
-0
lines changed

6 files changed

+397
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* logger.cpp
3+
*
4+
* Created on: 04.06.2015
5+
* Author: marcus
6+
*/
7+
#include <Core/Utils/extension/logger.hpp>
8+
9+
Logger* Logger::instance = 0;
10+
11+
Logger::Logger()
12+
{
13+
}
14+
15+
Logger::~Logger()
16+
{
17+
}
18+
19+
void Logger::writeErrorInternal(std::string errorMsg)
20+
{
21+
std::cerr << "Error: " << errorMsg << std::endl;
22+
}
23+
24+
void Logger::writeWarningInternal(std::string warningMsg)
25+
{
26+
std::cerr << "Warning: " << warningMsg << std::endl;
27+
}
28+
29+
void Logger::writeInfoInternal(std::string infoMsg)
30+
{
31+
std::cout << "Info: " << infoMsg << std::endl;
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
cmake_minimum_required (VERSION 2.8.6)
2+
3+
project(${FMUName})
4+
5+
add_library(${FMUName} SHARED FMULogger.cpp)
6+
add_library(${FMUName}_static STATIC FMULogger.cpp)
7+
8+
add_precompiled_header(${FMUName} Include/Core/Modelica.h)
9+
add_precompiled_header(${FMUName}_static Include/Core/Modelica.h)
10+
11+
if (UNIX)
12+
set_target_properties(${FMUName}_static PROPERTIES COMPILE_FLAGS -fPIC)
13+
set_target_properties(${FMUName}_static PROPERTIES COMPILE_FLAGS -fPIC)
14+
endif(UNIX)
15+
16+
install (TARGETS ${FMUName} DESTINATION ${LIBINSTALLEXT})
17+
install (TARGETS ${FMUName}_static DESTINATION ${LIBINSTALLEXT})
18+
19+
install (FILES ${CMAKE_SOURCE_DIR}/Include/FMU/fmiModelFunctions.h
20+
${CMAKE_SOURCE_DIR}/Include/FMU/fmiModelTypes.h
21+
${CMAKE_SOURCE_DIR}/Include/FMU/FMUGlobalSettings.h
22+
${CMAKE_SOURCE_DIR}/Include/FMU/FMULogger.h
23+
${CMAKE_SOURCE_DIR}/Include/FMU/FMUWrapper.h
24+
${CMAKE_SOURCE_DIR}/Include/FMU/FMULibInterface.h
25+
${CMAKE_SOURCE_DIR}/Include/FMU/IFMUInterface.h
26+
DESTINATION include/omc/cpp/FMU)
27+
28+
29+
30+
31+
32+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* FMULogger.cpp
3+
*
4+
* Created on: 04.06.2015
5+
* Author: marcus
6+
*/
7+
8+
#include <FMU/FMULogger.h>
9+
10+
FMULogger::FMULogger(fmiCallbackLogger callbackLogger, fmiComponent component, fmiString instanceName) :
11+
callbackLogger(callbackLogger), component(component), instanceName(instanceName)
12+
{
13+
}
14+
15+
FMULogger::~FMULogger()
16+
{
17+
}
18+
19+
void FMULogger::writeErrorInternal(std::string errorMsg)
20+
{
21+
callbackLogger(component, instanceName, fmiError, "", errorMsg.c_str());
22+
}
23+
24+
void FMULogger::writeWarningInternal(std::string warningMsg)
25+
{
26+
callbackLogger(component, instanceName, fmiWarning, "", warningMsg.c_str());
27+
}
28+
29+
void FMULogger::writeInfoInternal(std::string infoMsg)
30+
{
31+
callbackLogger(component, instanceName, fmiOK, "", infoMsg.c_str());
32+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* logger.hpp
3+
*
4+
* Created on: 04.06.2015
5+
* Author: marcus
6+
*/
7+
8+
#ifndef LOGGER_HPP_
9+
#define LOGGER_HPP_
10+
11+
#include <Core/Modelica.h>
12+
13+
class BOOST_EXTENSION_EXPORT_DECL Logger
14+
{
15+
public:
16+
virtual ~Logger();
17+
18+
static Logger* getInstance()
19+
{
20+
if(instance == NULL)
21+
initialize();
22+
23+
return instance;
24+
}
25+
26+
static void initialize()
27+
{
28+
if(instance != NULL)
29+
delete instance;
30+
31+
instance = new Logger();
32+
}
33+
34+
static void writeError(std::string errorMsg)
35+
{
36+
getInstance()->writeErrorInternal(errorMsg);
37+
}
38+
static void writeWarning(std::string warningMsg)
39+
{
40+
getInstance()->writeWarningInternal(warningMsg);
41+
}
42+
static void writeInfo(std::string infoMsg)
43+
{
44+
getInstance()->writeInfoInternal(infoMsg);
45+
}
46+
47+
protected:
48+
Logger();
49+
50+
virtual void writeErrorInternal(std::string errorMsg);
51+
virtual void writeWarningInternal(std::string warningMsg);
52+
virtual void writeInfoInternal(std::string infoMsg);
53+
54+
static Logger* instance;
55+
};
56+
57+
58+
59+
#endif /* LOGGER_HPP_ */
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
/*
2+
* This file is part of OpenModelica.
3+
*
4+
* Copyright (c) 1998-CurrentYear, Linköping University,
5+
* Department of Computer and Information Science,
6+
* SE-58183 Linköping, Sweden.
7+
*
8+
* All rights reserved.
9+
*
10+
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3
11+
* AND THIS OSMC PUBLIC LICENSE (OSMC-PL).
12+
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S
13+
* ACCEPTANCE OF THE OSMC PUBLIC LICENSE.
14+
*
15+
* The OpenModelica software and the Open Source Modelica
16+
* Consortium (OSMC) Public License (OSMC-PL) are obtained
17+
* from Linköping University, either from the above address,
18+
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
19+
* http://www.openmodelica.org, and in the OpenModelica distribution.
20+
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
21+
*
22+
* This program is distributed WITHOUT ANY WARRANTY; without
23+
* even the implied warranty of MERCHANTABILITY or FITNESS
24+
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
25+
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS
26+
* OF OSMC-PL.
27+
*
28+
* See the full OSMC Public License conditions for more details.
29+
*
30+
*/
31+
32+
#include <FMU/IFMUInterface.h>
33+
#include <FMU/fmiModelFunctions.h>
34+
#include <FMU/FMUWrapper.h>
35+
//#include "FMU/log.hpp"
36+
#include <iostream>
37+
38+
using namespace std;
39+
40+
//#define LOG_FMI() EmptyLog()
41+
//#define DO_LOG_FMI false
42+
43+
// ---------------------------------------------------------------------------
44+
// FMI functions: class methods not depending of a specific model instance
45+
// ---------------------------------------------------------------------------
46+
47+
extern "C" const char* fmiGetModelTypesPlatform() {
48+
//LOG_FMI() << "Entry: fmiGetModelTypesPlatform" << endl;
49+
return fmiModelTypesPlatform;
50+
}
51+
52+
extern "C" const char* fmiGetVersion() {
53+
//LOG_FMI() << "Entry: fmiGetVersion" << endl;
54+
return fmiVersion;
55+
}
56+
57+
extern "C" fmiComponent fmiInstantiateModel(fmiString instanceName, fmiString GUID,
58+
fmiCallbackFunctions functions, fmiBoolean loggingOn)
59+
{
60+
//LOG_FMI() << "Entry: fmiInstantiateModel" << endl;
61+
return reinterpret_cast<fmiComponent>
62+
(new FMUWrapper(instanceName, GUID, functions, loggingOn));
63+
}
64+
65+
extern "C" fmiStatus fmiSetDebugLogging(fmiComponent c, fmiBoolean loggingOn) {
66+
//LOG_FMI() << "Entry: fmiSetDebugLogging" << endl;
67+
return reinterpret_cast<IFMUInterface*>(c)->setDebugLogging(loggingOn);
68+
}
69+
70+
extern "C" void fmiFreeModelInstance(fmiComponent c) {
71+
//LOG_FMI() << "Entry: fmiModelInstance" << endl;
72+
delete reinterpret_cast<IFMUInterface*>(c);
73+
}
74+
75+
// ---------------------------------------------------------------------------
76+
// FMI functions: set variable values in the FMU
77+
// ---------------------------------------------------------------------------
78+
79+
extern "C" fmiStatus fmiSetReal(fmiComponent c, const fmiValueReference vr[], size_t nvr, const fmiReal value[]){
80+
//LOG_FMI() << "Entry: fmiSetReal nvr=" << nvr << endl;
81+
return reinterpret_cast<IFMUInterface*>(c)->setReal(vr, nvr, value);
82+
}
83+
84+
extern "C" fmiStatus fmiSetInteger(fmiComponent c, const fmiValueReference vr[], size_t nvr, const fmiInteger value[]){
85+
//LOG_FMI() << "Entry: fmiSetInteger nvr=" << nvr << endl;
86+
return reinterpret_cast<IFMUInterface*>(c)->setInteger(vr, nvr, value);
87+
}
88+
89+
extern "C" fmiStatus fmiSetBoolean(fmiComponent c, const fmiValueReference vr[], size_t nvr, const fmiBoolean value[]){
90+
//LOG_FMI() << "Entry: fmiBoolean nvr=" << nvr << endl;
91+
return reinterpret_cast<IFMUInterface*>(c)->setBoolean(vr, nvr, value);
92+
}
93+
94+
extern "C" fmiStatus fmiSetString(fmiComponent c, const fmiValueReference vr[], size_t nvr, const fmiString value[]){
95+
//LOG_FMI() << "Entry: fmiString nvr=" << nvr << endl;
96+
return reinterpret_cast<IFMUInterface*>(c)->setString(vr, nvr, value);
97+
}
98+
99+
extern "C" fmiStatus fmiSetTime(fmiComponent c, fmiReal time) {
100+
//LOG_FMI() << "Entry: **fmiSetTime is called: fmiComponent=" << c << " time=" << time << endl;
101+
if(!c) return fmiFatal; // TODO OpenModelica produces this Error if loading an FMI Model.
102+
return reinterpret_cast<IFMUInterface*>(c)->setTime(time);
103+
}
104+
105+
extern "C" fmiStatus fmiSetContinuousStates(fmiComponent c, const fmiReal x[], size_t nx){
106+
//LOG_FMI() << "Entry: **fmiSetContinuousState nx=" << nx << endl;
107+
return reinterpret_cast<IFMUInterface*>(c)->setContinuousStates(x, nx);
108+
}
109+
110+
// ---------------------------------------------------------------------------
111+
// FMI functions: get variable values from the FMU
112+
// ---------------------------------------------------------------------------
113+
114+
extern "C" fmiStatus fmiGetReal(fmiComponent c, const fmiValueReference vr[], size_t nvr, fmiReal value[]) {
115+
//LOG_FMI() << "Entry: fmiGetReal nvr=" << nvr << "value references=" << printArray(vr, nvr, " ") << endl;
116+
return reinterpret_cast<IFMUInterface*>(c)->getReal(vr, nvr, value);
117+
}
118+
119+
extern "C" fmiStatus fmiGetInteger(fmiComponent c, const fmiValueReference vr[], size_t nvr, fmiInteger value[]) {
120+
//LOG_FMI() << "Entry: fmiGetInteger nvr=" << nvr << "value references=" << printArray(vr, nvr, " ") << endl;
121+
return reinterpret_cast<IFMUInterface*>(c)->getInteger(vr, nvr, value);
122+
}
123+
124+
extern "C" fmiStatus fmiGetBoolean(fmiComponent c, const fmiValueReference vr[], size_t nvr, fmiBoolean value[]) {
125+
//LOG_FMI() << "Entry: fmiGetBoolean nvr=" << nvr << "value references=" << printArray(vr, nvr, " ") << endl;
126+
return reinterpret_cast<IFMUInterface*>(c)->getBoolean(vr, nvr, value);
127+
}
128+
129+
extern "C" fmiStatus fmiGetString(fmiComponent c, const fmiValueReference vr[], size_t nvr, fmiString value[]) {
130+
//LOG_FMI() << "Entry: fmiString nvr=" << nvr << "value references=" << printArray(vr, nvr, " ") << endl;
131+
return reinterpret_cast<IFMUInterface*>(c)->getString(vr, nvr, value);
132+
}
133+
134+
extern "C" fmiStatus fmiGetStateValueReferences(fmiComponent c, fmiValueReference vrx[], size_t nx){
135+
//LOG_FMI() << "Entry: fmiGetStateValueReferences nx=" << nx << endl;
136+
return reinterpret_cast<IFMUInterface*>(c)->getStateValueReferences(vrx, nx);
137+
}
138+
139+
extern "C" fmiStatus fmiGetContinuousStates(fmiComponent c, fmiReal states[], size_t nx){
140+
//LOG_FMI() << "Entry: fmiGetContinuousStates nx=" << nx << endl;
141+
return reinterpret_cast<IFMUInterface*>(c)->getContinuousStates(states, nx);
142+
}
143+
144+
extern "C" fmiStatus fmiGetNominalContinuousStates(fmiComponent c, fmiReal x_nominal[], size_t nx){
145+
//LOG_FMI() << "Entry: fmiGetNominalContinuousStates" << endl;
146+
return reinterpret_cast<IFMUInterface*>(c)->getNominalContinuousStates(x_nominal, nx);
147+
}
148+
149+
extern "C" fmiStatus fmiGetDerivatives(fmiComponent c, fmiReal derivatives[], size_t nx) {
150+
//LOG_FMI() << "Entry: fmiGetDerivates nx = " << nx << endl;
151+
return reinterpret_cast<IFMUInterface*>(c)->getDerivatives(derivatives, nx);
152+
}
153+
154+
extern "C" fmiStatus fmiGetEventIndicators(fmiComponent c, fmiReal eventIndicators[], size_t ni) {
155+
//if(DO_LOG_FMI)
156+
//{
157+
// LOG_FMI() << "Entry: fmiGetEventIndicators ni=" << ni << endl;
158+
// fmiStatus result = reinterpret_cast<IFMUInterface*>(c)->getEventIndicators(eventIndicators, ni);
159+
// LOG_FMI() << "Return values eventIndicators =" << printArray(eventIndicators, ni, " ") << endl;
160+
// return result;
161+
//}
162+
//else
163+
//{
164+
return reinterpret_cast<IFMUInterface*>(c)->getEventIndicators(eventIndicators, ni);
165+
//}
166+
}
167+
168+
// ---------------------------------------------------------------------------
169+
// FMI functions: initialization, event handling, stepping and termination
170+
// ---------------------------------------------------------------------------
171+
172+
extern "C" fmiStatus fmiInitialize(fmiComponent c, fmiBoolean toleranceControlled,
173+
fmiReal relativeTolerance, fmiEventInfo* eventInfo)
174+
{
175+
//LOG_FMI() << "Entry: fmiInitialize" << endl;
176+
return reinterpret_cast<IFMUInterface*>(c)->initialize(toleranceControlled,
177+
relativeTolerance, *eventInfo);
178+
}
179+
180+
extern "C" fmiStatus fmiEventUpdate(fmiComponent c, fmiBoolean intermediateResults, fmiEventInfo* eventInfo) {
181+
//LOG_FMI() << "Entry: ****fmiEventUpdate" << endl;
182+
return reinterpret_cast<IFMUInterface*>(c)->eventUpdate(intermediateResults, *eventInfo);
183+
}
184+
185+
extern "C" fmiStatus fmiCompletedIntegratorStep(fmiComponent c, fmiBoolean* callEventUpdate){
186+
//LOG_FMI() << "Entry: ***fmiCompletedIntegratorStep" << endl;
187+
return reinterpret_cast<IFMUInterface*>(c)->completedIntegratorStep(*callEventUpdate);
188+
}
189+
190+
extern "C" fmiStatus fmiTerminate(fmiComponent c){
191+
//LOG_FMI() << "Entry: fmiTerminate" << endl;
192+
return reinterpret_cast<IFMUInterface*>(c)->terminate();
193+
}
194+
195+
// ---------------------------------------------------------------------------
196+
// FMI functions: set external functions
197+
// ---------------------------------------------------------------------------
198+
199+
extern "C" fmiStatus fmiSetExternalFunction(fmiComponent c, fmiValueReference vr[], size_t nvr, const void* value[]) {
200+
//LOG_FMI() << "Entry: fmiSetExternalFunction" << endl;
201+
return reinterpret_cast<IFMUInterface*>(c)->setExternalFunction(vr, nvr, value);
202+
}
203+

0 commit comments

Comments
 (0)