Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Modelichart Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
ModeliChart
Modelichart Backend
Commits
a36efe68
Commit
a36efe68
authored
7 years ago
by
Tim Übelhör
Browse files
Options
Downloads
Patches
Plain Diff
Switched back to std thread since newer wine versions should support it
parent
ba156b3b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
FMU_Engine/FMU_Engine/FMUEngine.cpp
+11
-17
11 additions, 17 deletions
FMU_Engine/FMU_Engine/FMUEngine.cpp
FMU_Engine/FMU_Engine/FmuEngine.hpp
+10
-13
10 additions, 13 deletions
FMU_Engine/FMU_Engine/FmuEngine.hpp
with
21 additions
and
30 deletions
FMU_Engine/FMU_Engine/FMUEngine.cpp
+
11
−
17
View file @
a36efe68
...
...
@@ -22,19 +22,13 @@ namespace Simulation
_controlerId
(
id
),
_sendValuesCallback
(
valuesCallback
),
_logCallback
(
_logCallback
)
{}
DWORD
WINAPI
FmuEngine
::
staticSimThreadStart
(
void
*
instance
)
{
FmuEngine
*
engine
=
(
FmuEngine
*
)
instance
;
return
engine
->
simulate
();
}
DWORD
FmuEngine
::
simulate
(
void
)
void
FmuEngine
::
simulate
()
{
// Time measuring
LARGE_INTEGER
frequency
,
startCount
,
currentCount
;
if
(
!
QueryPerformanceFrequency
(
&
frequency
))
{
_logCallback
(
"FmuEngine"
,
"Precision timer nor available."
);
return
1
;
}
std
::
string
freqString
=
"PerformanceFrequency: "
+
std
::
to_string
(
frequency
.
QuadPart
)
+
"1/sec"
;
std
::
cout
<<
freqString
<<
std
::
endl
;
...
...
@@ -85,7 +79,6 @@ namespace Simulation
}
// Lower the accurracy when leaving
timeEndPeriod
(
1
);
return
0
;
}
void
FmuEngine
::
performChannelLinks
()
{
...
...
@@ -189,26 +182,27 @@ namespace Simulation
}
}
FResult
FmuEngine
::
startSimulation
Thread
()
FResult
FmuEngine
::
startSimulation
()
{
// Play from initialized or stopped state
if
(
!
_simulating
)
{
// Make the fmus ready
for
(
auto
&
pair
:
_fmus
)
{
Fmu
&
fmu
=
pair
.
second
;
// Exit the mode
// Exit the initalizationmode
// TODO check current state
fmi2Status
status
=
fmu
.
ExitInitializationMode
();
if
(
!
(
status
==
fmi2OK
||
status
==
fmi2Warning
))
{
return
{
status
,
"Initialization failed, instance: "
+
fmu
.
GetInstanceName
()
};
_logCallback
(
fmu
.
GetInstanceName
(),
"ExitInitializationMode failed"
);
return
{
status
,
"ExitInitializationMode failed, instance: "
+
fmu
.
GetInstanceName
()
};
}
}
// Start simulating
_simulating
=
true
;
// Create new thread for the simulation
_simThread
Handle
=
CreateThread
(
NULL
,
0
,
staticSimThreadStart
,
(
void
*
)
this
,
0
,
&
_simThreadID
);
_simThread
=
std
::
thread
(
&
FmuEngine
::
simulate
,
this
);
}
return
{
fmi2OK
,
""
};
}
...
...
@@ -218,14 +212,14 @@ namespace Simulation
// Set endTime as large as possible (~5,67e300 annos)
_endTime_sec
=
DBL_MAX
;
_playFast
=
false
;
return
startSimulation
Thread
();
return
startSimulation
();
}
FResult
FmuEngine
::
PlayFast
(
double
endTime_sec
)
{
// Update the _endTime
_endTime_sec
=
endTime_sec
;
_playFast
=
true
;
return
startSimulation
Thread
();
return
startSimulation
();
}
// Stop the simulation thread
FResult
FmuEngine
::
Pause
()
...
...
@@ -233,7 +227,7 @@ namespace Simulation
// Only try to obtain ownership over the thread without blocking the current thread
_simulating
=
false
;
// Wait until the current run has finished
WaitForSingleObject
(
_simThreadHandle
,
INFINITE
);
_simThread
.
join
(
);
return
{
fmi2OK
,
""
};
}
// Stop the thread and reset the simulation
...
...
@@ -242,7 +236,7 @@ namespace Simulation
// Stop simulation
_simulating
=
false
;
// Wait until the current run has finished
WaitForSingleObject
(
_simThreadHandle
,
INFINITE
);
_simThread
.
join
(
);
// Reset simulation
_currentTime_sec
=
0
;
...
...
This diff is collapsed.
Click to expand it.
FMU_Engine/FMU_Engine/FmuEngine.hpp
+
10
−
13
View file @
a36efe68
...
...
@@ -2,11 +2,11 @@
#include
"ChannelLink.h"
#include
"templates.hpp"
#include
"fmi2FunctionTypes.h"
#include
<
memory
>
#include
<
atomic
>
#include
<map>
#include
<memory>
#include
<thread>
#include
<vector>
#define WIN32_LEAN_AND_MEAN // We don't want to include winsock.h, causes problems with asio
#include
<windows.h>
#include
"boost/optional.hpp"
// Forward declaration
...
...
@@ -73,20 +73,17 @@ namespace Simulation
LogCallback
_logCallback
;
// Execeutes the simulation: DoStep, pushes the values into storage, performes ChannelLinks
DWORD
_simThreadID
;
HANDLE
_simThreadHandle
;
bool
_simulating
;
// Use atomic -> while(!_stopSim) will not be compiled to while(true)
bool
_playFast
;
// Do not sleep when we use the playFast mode
std
::
thread
_simThread
;
std
::
atomic_bool
_simulating
;
// Use atomic -> while(!_stopSim) will not be compiled to while(true)
bool
_playFast
;
// Do not sleep when we use the playFast mode
double
_currentTime_sec
=
0
;
// The current simulation timepoint
double
_endTime_sec
=
0
;
const
double
STEP_SIZE_SEC
=
0.01
;
// Default 10ms
/// Start the simulation Task (if not already running)
FResult
startSimulationThread
();
/// Static method needed to execute the WINAPI thread
static
DWORD
WINAPI
staticSimThreadStart
(
void
*
instance
);
///
DWORD
simulate
(
void
);
/// Prepares and runs the simulation loop in a new thread
FResult
startSimulation
();
/// Simulation loop runs in here
void
simulate
();
void
performChannelLinks
();
void
sendValues
();
...
...
This diff is collapsed.
Click to expand it.
Tim Übelhör
@tim.uebelhoer
mentioned in issue
#7 (closed)
·
7 years ago
mentioned in issue
#7 (closed)
mentioned in issue #7
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment