-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for FMI 3.0 (previously was only 2.0) Instance must now be started before any variable is read.
- Loading branch information
Olivier Azeau
committed
Sep 21, 2024
1 parent
2934fe9
commit 2f58710
Showing
32 changed files
with
996 additions
and
430 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
obj | ||
bin | ||
bin* | ||
.vscode | ||
.ionide | ||
*.nupkg | ||
|
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Submodule Reference-FMUs
updated
from e4ec2c to 83edd9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
snap install cmake | ||
cmake -S Reference-FMUs -B bin | ||
cd bin | ||
make | ||
rm -rf bin* | ||
cmake -S Reference-FMUs -D FMI_VERSION=2 -B bin2 && pushd bin2 && make && popd | ||
cmake -S Reference-FMUs -D FMI_VERSION=3 -B bin3 && pushd bin3 && make && popd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,19 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Femyou.Internal | ||
{ | ||
class Callbacks : IDisposable | ||
public abstract class Callbacks : IDisposable | ||
{ | ||
public Callbacks(Instance instance, ICallbacks cb) | ||
{ | ||
_instance = instance; | ||
_cb = cb; | ||
_handle = GCHandle.Alloc(this); | ||
_functions = new FMI2.fmi2CallbackFunctions | ||
{ | ||
logger = LoggerCallback, | ||
allocateMemory = Marshalling.AllocateMemory, | ||
freeMemory = Marshalling.FreeMemory, | ||
stepFinished = StepFinishedCallback, | ||
componentEnvironment = GCHandle.ToIntPtr(_handle) | ||
}; | ||
Structure = Marshalling.AllocateMemory(1, (ulong)Marshal.SizeOf(_functions)); | ||
Marshal.StructureToPtr(_functions, Structure, false); | ||
Instance = instance; | ||
Cb = cb; | ||
} | ||
|
||
private readonly Instance _instance; | ||
private readonly ICallbacks _cb; | ||
public readonly IntPtr Structure; | ||
private GCHandle _handle; | ||
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable | ||
private readonly FMI2.fmi2CallbackFunctions _functions; | ||
|
||
public void Dispose() | ||
{ | ||
Marshalling.FreeMemory(Structure); | ||
_handle.Free(); | ||
} | ||
public readonly Instance Instance; | ||
public readonly ICallbacks Cb; | ||
public abstract IntPtr Custom { get; } | ||
|
||
private static void LoggerCallback(IntPtr componentEnvironment, string instanceName, int status, string category, string message) | ||
{ | ||
var self = (Callbacks) GCHandle.FromIntPtr(componentEnvironment).Target; | ||
self._cb?.Logger(self._instance, (Status)status, category, message); | ||
} | ||
|
||
private static void StepFinishedCallback(IntPtr componentEnvironment, int status) | ||
{ | ||
} | ||
public abstract void Dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using Femyou.Interop; | ||
|
||
namespace Femyou.Internal | ||
{ | ||
class Callbacks2 : Callbacks | ||
{ | ||
public Callbacks2(Instance instance, ICallbacks cb) | ||
: base(instance, cb) | ||
{ | ||
_handle = GCHandle.Alloc(this); | ||
_functions = new FMI2.fmi2CallbackFunctions | ||
{ | ||
logger = LoggerCallback, | ||
allocateMemory = Marshalling.AllocateMemory, | ||
freeMemory = Marshalling.FreeMemory, | ||
stepFinished = StepFinishedCallback, | ||
componentEnvironment = GCHandle.ToIntPtr(_handle) | ||
}; | ||
_structure = Marshalling.AllocateMemory(1, (ulong)Marshal.SizeOf(_functions)); | ||
Marshal.StructureToPtr(_functions, _structure, false); | ||
} | ||
|
||
private readonly IntPtr _structure; | ||
private GCHandle _handle; | ||
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable | ||
private readonly FMI2.fmi2CallbackFunctions _functions; | ||
|
||
public override IntPtr Custom => _structure; | ||
|
||
public override void Dispose() | ||
{ | ||
Marshalling.FreeMemory(_structure); | ||
_handle.Free(); | ||
} | ||
|
||
private static void LoggerCallback(IntPtr componentEnvironment, string instanceName, int status, string category, string message) | ||
{ | ||
var self = (Callbacks) GCHandle.FromIntPtr(componentEnvironment).Target; | ||
self.Cb?.Logger(self.Instance, (Status)status, category, message); | ||
} | ||
|
||
private static void StepFinishedCallback(IntPtr componentEnvironment, int status) | ||
{ | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using Femyou.Interop; | ||
|
||
namespace Femyou.Internal | ||
{ | ||
class Callbacks3 : Callbacks | ||
{ | ||
public Callbacks3(Instance instance, ICallbacks cb) | ||
: base(instance, cb) | ||
{ | ||
_handle = GCHandle.Alloc(this); | ||
Custom = GCHandle.ToIntPtr(_handle); | ||
LogMessageDelegate = LoggerCallback; | ||
} | ||
|
||
private GCHandle _handle; | ||
public readonly FMI3.fmi3CallbackLogMessage LogMessageDelegate; | ||
|
||
|
||
private static void LoggerCallback( | ||
IntPtr componentEnvironment, string instanceName, | ||
int status, string category, string message) | ||
{ | ||
var self = (Callbacks) GCHandle.FromIntPtr(componentEnvironment).Target; | ||
self.Cb?.Logger(self.Instance, (Status)status, category, message); | ||
} | ||
|
||
public override IntPtr Custom { get; } | ||
|
||
public override void Dispose() | ||
{ | ||
_handle.Free(); | ||
} | ||
} | ||
} |
Oops, something went wrong.