Skip to content

Commit ae89f77

Browse files
Merge branch 'tbeu-fix-buf'
2 parents 9caa4e5 + 01c2300 commit ae89f77

27 files changed

+846
-479
lines changed

Modelica_DeviceDrivers/Blocks/Communication.mo

Lines changed: 184 additions & 149 deletions
Large diffs are not rendered by default.

Modelica_DeviceDrivers/Blocks/Examples/TestSerialPackager_UDP.mo

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
within Modelica_DeviceDrivers.Blocks.Examples;
22
model TestSerialPackager_UDP "Example for combining UDP and SerialPackager blocks with deactivated autoBufferSize / useBackwardPropagatedBufferSize"
33
extends Modelica.Icons.Example;
4-
Modelica_DeviceDrivers.Blocks.Packaging.SerialPackager.Packager packager(useBackwardPropagatedBufferSize=false) annotation(Placement(transformation(extent={{-40,62},{-20,82}})));
4+
Modelica_DeviceDrivers.Blocks.Packaging.SerialPackager.Packager packager(useBackwardPropagatedBufferSize=false, userBufferSize=36) annotation(Placement(transformation(extent={{-40,62},{-20,82}})));
55
Modelica_DeviceDrivers.Blocks.Packaging.SerialPackager.AddReal addReal(
66
nu=1,
77
n=3) annotation(Placement(transformation(extent={{-40,34},{-20,54}})));
88
Modelica.Blocks.Sources.RealExpression realExpression[3](y=sin(time)*{1,2,3}) annotation(Placement(transformation(extent={{-80,34},{-60,54}})));
99
Modelica_DeviceDrivers.Blocks.Communication.UDPSend uDPSend(
1010
autoBufferSize=false,
11+
userBufferSize=36,
1112
port_send=10002) annotation(Placement(transformation(
1213
origin={-30,-44},
1314
extent={{-10,-10},{10,10}},
@@ -17,6 +18,7 @@ model TestSerialPackager_UDP "Example for combining UDP and SerialPackager block
1718
time))) annotation(Placement(transformation(extent={{-80,-26},{-60,-6}})));
1819
Modelica_DeviceDrivers.Blocks.Communication.UDPReceive uDPReceive(
1920
autoBufferSize=false,
21+
userBufferSize=36,
2022
port_recv=10002) annotation(Placement(transformation(
2123
origin={40,50},
2224
extent={{-10,-10},{10,10}},

Modelica_DeviceDrivers/Blocks/Packaging/SerialPackager.mo

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -136,20 +136,6 @@ package SerialPackager "Blocks for constructing packages"
136136
dummy2 := dummy;
137137
end clear;
138138

139-
function setPackage
140-
import Modelica_DeviceDrivers.Packaging.SerialPackager;
141-
import Modelica_DeviceDrivers;
142-
input Modelica_DeviceDrivers.Packaging.SerialPackager
143-
pkg;
144-
input String data "Packager payload data encoded as Modelica String";
145-
input Integer dataSize "Number of payload data bytes";
146-
input Real dummy;
147-
output Real dummy2;
148-
algorithm
149-
Modelica_DeviceDrivers.Packaging.SerialPackager_.setPackage(pkg, data, dataSize);
150-
dummy2 := dummy;
151-
end setPackage;
152-
153139
function integerBitPack "Encode integer value at bit level"
154140
import Modelica_DeviceDrivers.Packaging.SerialPackager;
155141
import Modelica_DeviceDrivers;
@@ -195,16 +181,16 @@ package SerialPackager "Blocks for constructing packages"
195181
"true, use backward propagation for sample time (default!), otherwise switch to forward propagation"
196182
annotation(Dialog(tab="Advanced"), choices(__Dymola_checkBox=true));
197183
parameter Modelica.SIunits.Period sampleTime=0.01
198-
"Sample time if forward propagation of sample time is used" annotation (Dialog(enable = not useBackwardSampleTimePropagation, tab="Advanced"));
184+
"Sample time if forward propagation of sample time is used" annotation (Dialog(enable = not useBackwardSampleTimePropagation, tab="Advanced"));
199185

200186
parameter Boolean useBackwardPropagatedBufferSize = true
201187
"true, use backward propagated (automatic) buffer size for package (default!), otherwise use manually specified buffer size below"
202188
annotation(Dialog(tab="Advanced"), choices(__Dymola_checkBox=true));
203189
parameter Integer userBufferSize = 16*1024
204190
"Buffer size for package if backward propagation of buffer size is deactivated"
205-
annotation (Dialog(enable = not useBackwardPropagatedBufferSize, tab="Advanced"));
191+
annotation (Dialog(enable = not useBackwardPropagatedBufferSize, tab="Advanced"));
206192

207-
Interfaces.PackageOut pkgOut(pkg = SerialPackager(bufferSize))
193+
Interfaces.PackageOut pkgOut(pkg = SerialPackager(if useBackwardPropagatedBufferSize then bufferSize else userBufferSize))
208194
annotation (Placement(transformation(extent={{-20,-128},{20,-88}})));
209195
protected
210196
Integer backwardPropagatedBufferSize;

Modelica_DeviceDrivers/ClockedBlocks/Communication.mo

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ package Communication
44
model SharedMemoryRead "A block for reading data from a shared memory buffer"
55
extends Modelica_DeviceDrivers.Utilities.Icons.BaseIcon;
66
extends Modelica_DeviceDrivers.Utilities.Icons.SharedMemoryIcon;
7-
extends
8-
Modelica_DeviceDrivers.Utilities.Icons.PartialClockedDeviceDriverIcon;
7+
extends Modelica_DeviceDrivers.Utilities.Icons.PartialClockedDeviceDriverIcon;
98
import Modelica_DeviceDrivers.Packaging.SerialPackager;
109
import Modelica_DeviceDrivers.Packaging.alignAtByteBoundary;
1110
import Modelica_DeviceDrivers.Communication.SharedMemory;
@@ -16,10 +15,10 @@ package Communication
1615
annotation(Dialog(group="Shared memory partition"), choices(__Dymola_checkBox=true));
1716
parameter Integer userBufferSize=16*1024
1817
"Buffer size of shared memory partition in bytes (if not deduced automatically)"
19-
annotation(Dialog(enable=not autoBufferSize, group="Shared memory partition"));
18+
annotation(Dialog(enable=not autoBufferSize, group="Shared memory partition"));
2019
parameter String memoryID="sharedMemory" "ID of the shared memory buffer" annotation(Dialog(group="Shared memory partition"));
2120

22-
Interfaces.PackageOut pkgOut annotation (Placement(
21+
Interfaces.PackageOut pkgOut annotation (Placement(
2322
transformation(
2423
extent={{-20,-20},{20,20}},
2524
rotation=90,
@@ -47,10 +46,9 @@ package Communication
4746
end if;
4847

4948
dummy = previous(dummy) + Ts;
50-
pkgOut.dummy = Modelica_DeviceDrivers.Blocks.Packaging.SerialPackager.Internal.DummyFunctions.setPackage(
49+
pkgOut.dummy = Modelica_DeviceDrivers.ClockedBlocks.Communication.Internal.DummyFunctions.readSharedMemory(
50+
sm,
5151
pkgOut.pkg,
52-
SharedMemory_.read(sm),
53-
bufferSize,
5452
dummy);
5553
annotation (preferredView="info",
5654
Icon(coordinateSystem(preserveAspectRatio=false, extent={{-100,
@@ -76,10 +74,10 @@ provided by the parameter <b>memoryID</b>. If the shared memory partition does n
7674
annotation(Dialog(group="Shared memory partition"), choices(__Dymola_checkBox=true));
7775
parameter Integer userBufferSize=16*1024
7876
"Buffer size of shared memory partition in bytes (if not deduced automatically)"
79-
annotation(Dialog(enable=not autoBufferSize, group="Shared memory partition"));
77+
annotation(Dialog(enable=not autoBufferSize, group="Shared memory partition"));
8078
parameter String memoryID="sharedMemory" "ID of the shared memory buffer" annotation(Dialog(group="Shared memory partition"));
8179

82-
Interfaces.PackageIn pkgIn annotation (Placement(
80+
Interfaces.PackageIn pkgIn annotation (Placement(
8381
transformation(
8482
extent={{-20,-20},{20,20}},
8583
rotation=270,
@@ -100,16 +98,12 @@ provided by the parameter <b>memoryID</b>. If the shared memory partition does n
10098
initialized :=previous(initialized);
10199
end if;
102100
equation
103-
pkgIn.userPkgBitSize = if autoBufferSize then -1 else userBufferSize*8;
104-
pkgIn.autoPkgBitSize = 0;
105-
bufferSize = if autoBufferSize then Modelica_DeviceDrivers.Packaging.SerialPackager_.getBufferSize(
106-
pkgIn.pkg)
107-
else userBufferSize;
108-
dummy =
109-
Modelica_DeviceDrivers.ClockedBlocks.Communication.Internal.DummyFunctions.writeSharedMemory(
101+
pkgIn.userPkgBitSize = if autoBufferSize then -1 else userBufferSize*8;
102+
pkgIn.autoPkgBitSize = 0;
103+
bufferSize = if autoBufferSize then Modelica_DeviceDrivers.Packaging.SerialPackager_.getBufferSize(pkgIn.pkg) else userBufferSize;
104+
dummy = Modelica_DeviceDrivers.ClockedBlocks.Communication.Internal.DummyFunctions.writeSharedMemory(
110105
sm,
111-
Modelica_DeviceDrivers.Packaging.SerialPackager_.getPackage(
112-
pkgIn.pkg),
106+
pkgIn.pkg,
113107
bufferSize,
114108
pkgIn.dummy);
115109

@@ -170,11 +164,9 @@ provided by the parameter <b>memoryID</b>. If the shared memory partition does n
170164

171165
dummy = previous(dummy) + Ts;
172166

173-
pkgOut.dummy =
174-
Modelica_DeviceDrivers.ClockedBlocks.Packaging.SerialPackager.Internal.DummyFunctions.setPackage(
167+
pkgOut.dummy = Modelica_DeviceDrivers.ClockedBlocks.Communication.Internal.DummyFunctions.readUDP(
168+
socket,
175169
pkgOut.pkg,
176-
Modelica_DeviceDrivers.Communication.UDPSocket_.read(socket),
177-
bufferSize,
178170
dummy);
179171

180172
annotation (preferredView="info",
@@ -200,11 +192,11 @@ provided by the parameter <b>memoryID</b>. If the shared memory partition does n
200192
parameter Integer userBufferSize=16*1024
201193
"Buffer size of message data in bytes (if not deduced automatically)." annotation(Dialog(enable=not autoBufferSize, group="Outgoing data"));
202194
parameter String IPAddress="127.0.0.1" "IP address of remote UDP server"
203-
annotation (Dialog(group="Outgoing data"));
195+
annotation (Dialog(group="Outgoing data"));
204196
parameter Integer port_send=10002 "Target port of the receiving UDP server"
205-
annotation (Dialog(group="Outgoing data"));
197+
annotation (Dialog(group="Outgoing data"));
206198

207-
Interfaces.PackageIn pkgIn annotation (Placement(
199+
Interfaces.PackageIn pkgIn annotation (Placement(
208200
transformation(
209201
extent={{-20,-20},{20,20}},
210202
rotation=270,
@@ -218,19 +210,15 @@ provided by the parameter <b>memoryID</b>. If the shared memory partition does n
218210

219211
pkgIn.userPkgBitSize = if autoBufferSize then -1 else userBufferSize*8;
220212
pkgIn.autoPkgBitSize = 0;
221-
bufferSize = if autoBufferSize then Modelica_DeviceDrivers.Packaging.SerialPackager_.getBufferSize(
222-
pkgIn.pkg)
223-
else userBufferSize;
213+
bufferSize = if autoBufferSize then Modelica_DeviceDrivers.Packaging.SerialPackager_.getBufferSize(pkgIn.pkg) else userBufferSize;
224214

225215
// socket = previous(socket);
226216

227-
dummy =
228-
Modelica_DeviceDrivers.ClockedBlocks.Communication.Internal.DummyFunctions.sendToUDP(
217+
dummy = Modelica_DeviceDrivers.ClockedBlocks.Communication.Internal.DummyFunctions.sendToUDP(
229218
socket,
230219
IPAddress,
231220
port_send,
232-
Modelica_DeviceDrivers.Packaging.SerialPackager_.getPackage(
233-
pkgIn.pkg),
221+
pkgIn.pkg,
234222
bufferSize,
235223
pkgIn.dummy);
236224

@@ -246,32 +234,50 @@ provided by the parameter <b>memoryID</b>. If the shared memory partition does n
246234
extends Modelica_DeviceDrivers.Utilities.Icons.InternalPackage;
247235
package DummyFunctions
248236
extends Modelica_DeviceDrivers.Utilities.Icons.InternalPackage;
237+
function readSharedMemory
238+
input Modelica_DeviceDrivers.Communication.SharedMemory sm;
239+
input Modelica_DeviceDrivers.Packaging.SerialPackager pkg;
240+
input Real dummy;
241+
output Real dummy2;
242+
algorithm
243+
Modelica_DeviceDrivers.Communication.SharedMemory_.read(sm, pkg);
244+
dummy2 := dummy;
245+
end readSharedMemory;
246+
249247
function writeSharedMemory
250248
input Modelica_DeviceDrivers.Communication.SharedMemory sm;
251-
input String data;
249+
input Modelica_DeviceDrivers.Packaging.SerialPackager pkg;
252250
input Integer len;
253251
input Real dummy;
254252
output Real dummy2;
255253
algorithm
256-
Modelica_DeviceDrivers.Communication.SharedMemory_.write(
257-
sm,data,len);
258-
dummy2 :=dummy;
254+
Modelica_DeviceDrivers.Communication.SharedMemory_.write(sm, pkg, len);
255+
dummy2 := dummy;
259256
end writeSharedMemory;
260257

258+
function readUDP
259+
input Modelica_DeviceDrivers.Communication.UDPSocket socket;
260+
input Modelica_DeviceDrivers.Packaging.SerialPackager pkg;
261+
input Real dummy;
262+
output Real dummy2;
263+
algorithm
264+
Modelica_DeviceDrivers.Communication.UDPSocket_.read(socket, pkg);
265+
dummy2 := dummy;
266+
end readUDP;
267+
261268
function sendToUDP
262-
import Modelica_DeviceDrivers.Communication.UDPSocket;
263-
input UDPSocket socket;
269+
input Modelica_DeviceDrivers.Communication.UDPSocket socket;
264270
input String ipAddress "IP address where data has to be sent";
265271
input Integer port "Port number where data has to be sent";
266-
input String data "Data to be sent";
272+
input Modelica_DeviceDrivers.Packaging.SerialPackager pkg;
267273
input Integer dataSize "Size of data";
268274
input Real dummy;
269275
output Real dummy2;
270276
algorithm
271-
Modelica_DeviceDrivers.Communication.UDPSocket_.sendTo(
272-
socket, ipAddress, port,data, dataSize);
273-
dummy2 :=dummy;
277+
Modelica_DeviceDrivers.Communication.UDPSocket_.sendTo(socket, ipAddress, port, pkg, dataSize);
278+
dummy2 := dummy;
274279
end sendToUDP;
280+
275281
end DummyFunctions;
276282

277283
end Internal;

Modelica_DeviceDrivers/ClockedBlocks/Packaging.mo

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,6 @@ package Packaging
132132
dummy2 := dummy;
133133
end clear;
134134

135-
function setPackage
136-
import Modelica_DeviceDrivers.Packaging.SerialPackager;
137-
import Modelica_DeviceDrivers;
138-
input Modelica_DeviceDrivers.Packaging.SerialPackager
139-
pkg;
140-
input String data "Packager payload data encoded as Modelica String";
141-
input Integer dataSize "Number of payload data bytes";
142-
input Real dummy;
143-
output Real dummy2;
144-
algorithm
145-
Modelica_DeviceDrivers.Packaging.SerialPackager_.setPackage(pkg, data, dataSize);
146-
dummy2 := dummy;
147-
end setPackage;
148-
149135
function integerBitPack "Encode integer value at bit level"
150136
import Modelica_DeviceDrivers.Packaging.SerialPackager;
151137
import Modelica_DeviceDrivers;

Modelica_DeviceDrivers/Communication/SerialPort.mo

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ extends ExternalObject;
44
encapsulated function constructor
55
"Creates a SerialPort instance with a given listening port."
66
import Modelica_DeviceDrivers.Communication.SerialPort;
7+
import Modelica_DeviceDrivers.Utilities.Types.SerialBaudRate;
78
input String deviceName "Serial port (/dev/ttyX or \\\\.\\COMX)";
89
input Integer bufferSize=16*1024 "Size of receive buffer";
910
input Integer parity = 0 "0 - no parity, 1 - even, 2 - odd";
1011
input Integer receiver = 1 "0 - sender, 1 - receiver";
11-
input Integer baud = 0;
12+
input SerialBaudRate baud = 0;
1213
output SerialPort sPort;
1314
external "C" sPort = MDD_serialPortConstructor(deviceName, bufferSize, parity,receiver,baud)
1415
annotation(IncludeDirectory="modelica://Modelica_DeviceDrivers/Resources/Include",

Modelica_DeviceDrivers/Communication/SerialPort_.mo

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,24 @@ package SerialPort_ "Accompanying functions for the SerialPort object"
44

55
encapsulated function read
66
import Modelica_DeviceDrivers.Communication.SerialPort;
7+
import Modelica_DeviceDrivers.Packaging.SerialPackager;
78
input SerialPort sPort;
8-
output String data;
9-
external "C" data= MDD_serialPortRead(sPort)
10-
annotation(IncludeDirectory="modelica://Modelica_DeviceDrivers/Resources/Include",
9+
input SerialPackager pkg;
10+
external "C" MDD_serialPortReadP(sPort, pkg)
11+
annotation(IncludeDirectory="modelica://Modelica_DeviceDrivers/Resources/Include",
1112
Include = "#include \"MDDSerialPort.h\" ",
1213
Library = "pthread",
1314
__iti_dll = "ITI_MDD.dll");
1415
end read;
1516

1617
encapsulated function sendTo
1718
import Modelica_DeviceDrivers.Communication.SerialPort;
19+
import Modelica_DeviceDrivers.Packaging.SerialPackager;
1820
input SerialPort sPort "Serial Port object";
19-
input String data "Data to be sent";
21+
input SerialPackager pkg;
2022
input Integer dataSize "Size of data";
21-
external "C" MDD_serialPortSend(sPort, data, dataSize)
22-
annotation(IncludeDirectory="modelica://Modelica_DeviceDrivers/Resources/Include",
23+
external "C" MDD_serialPortSendP(sPort, pkg, dataSize)
24+
annotation(IncludeDirectory="modelica://Modelica_DeviceDrivers/Resources/Include",
2325
Include = "#include \"MDDSerialPort.h\" ",
2426
Library = "pthread",
2527
__iti_dll = "ITI_MDD.dll");
@@ -29,8 +31,7 @@ package SerialPort_ "Accompanying functions for the SerialPort object"
2931
import Modelica_DeviceDrivers.Communication.SerialPort;
3032
input SerialPort sPort;
3133
output Integer receivedBytes "number of Bytes received";
32-
external "C" receivedBytes =
33-
MDD_serialPortGetReceivedBytes(sPort)
34+
external "C" receivedBytes = MDD_serialPortGetReceivedBytes(sPort)
3435
annotation(IncludeDirectory="modelica://Modelica_DeviceDrivers/Resources/Include",
3536
Include = "#include \"MDDSerialPort.h\" ",
3637
Library = "pthread",

Modelica_DeviceDrivers/Communication/SharedMemory_.mo

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package SharedMemory_ "Accompanying functions for the SharedMemory object"
33
extends Modelica_DeviceDrivers.Utilities.Icons.DriverIcon;
44
encapsulated function read
55
import Modelica_DeviceDrivers.Communication.SharedMemory;
6+
import Modelica_DeviceDrivers.Packaging.SerialPackager;
67
input SharedMemory sm;
7-
output String data;
8-
external "C" data= MDD_SharedMemoryRead(sm)
8+
input SerialPackager pkg "Data package to be read";
9+
external "C" MDD_SharedMemoryReadP(sm, pkg)
910
annotation(IncludeDirectory="modelica://Modelica_DeviceDrivers/Resources/Include",
1011
Include = "#include \"MDDSharedMemory.h\" ",
1112
Library = {"rt", "pthread"},
@@ -14,10 +15,11 @@ package SharedMemory_ "Accompanying functions for the SharedMemory object"
1415

1516
encapsulated function write
1617
import Modelica_DeviceDrivers.Communication.SharedMemory;
18+
import Modelica_DeviceDrivers.Packaging.SerialPackager;
1719
input SharedMemory sm;
18-
input String data;
20+
input SerialPackager pkg "Data package to be written";
1921
input Integer len;
20-
external "C" MDD_SharedMemoryWrite(sm,data,len)
22+
external "C" MDD_SharedMemoryWriteP(sm, pkg, len)
2123
annotation(IncludeDirectory="modelica://Modelica_DeviceDrivers/Resources/Include",
2224
Include = "#include \"MDDSharedMemory.h\" ",
2325
Library = {"rt", "pthread"},
@@ -28,7 +30,7 @@ package SharedMemory_ "Accompanying functions for the SharedMemory object"
2830
import Modelica_DeviceDrivers.Communication.SharedMemory;
2931
input SharedMemory sm;
3032
output Integer length;
31-
external "C" length= MDD_SharedMemoryGetDataSize(sm)
33+
external "C" length = MDD_SharedMemoryGetDataSize(sm)
3234
annotation(IncludeDirectory="modelica://Modelica_DeviceDrivers/Resources/Include",
3335
Include = "#include \"MDDSharedMemory.h\" ",
3436
__iti_dll = "ITI_MDD.dll");

0 commit comments

Comments
 (0)