From 1b08459658d91b5494bcbb41f113db8048b2c39c Mon Sep 17 00:00:00 2001 From: bernhard Thiele Date: Mon, 14 Sep 2015 11:39:08 +0200 Subject: [PATCH] Fixed missing byteOrder in Boolean blocks --- .../Blocks/Examples/TestSerialPackager.mo | 70 ++++++---- .../Examples/TestSerialPackager_String.mo | 4 +- .../Blocks/Packaging/SerialPackager.mo | 12 +- .../ClockedBlocks/Examples.mo | 122 ++++++++++++------ .../ClockedBlocks/Packaging.mo | 13 +- 5 files changed, 148 insertions(+), 73 deletions(-) diff --git a/Modelica_DeviceDrivers/Blocks/Examples/TestSerialPackager.mo b/Modelica_DeviceDrivers/Blocks/Examples/TestSerialPackager.mo index fd44e584..c2bcf96b 100644 --- a/Modelica_DeviceDrivers/Blocks/Examples/TestSerialPackager.mo +++ b/Modelica_DeviceDrivers/Blocks/Examples/TestSerialPackager.mo @@ -3,63 +3,85 @@ model TestSerialPackager "Example for using the SerialPackager" extends Modelica.Icons.Example; Modelica.Blocks.Sources.IntegerExpression integerExpression(y=integer(3*sin( time) + 3)) - annotation (Placement(transformation(extent={{-80,0},{-60,20}}))); + annotation (Placement(transformation(extent={{-84,30},{-64,50}}))); Packaging.SerialPackager.Packager packager(useBackwardSampleTimePropagation=false, sampleTime=0.1) - annotation (Placement(transformation(extent={{-40,40},{-20,60}}))); + annotation (Placement(transformation(extent={{-44,70},{-24,90}}))); Packaging.SerialPackager.PackUnsignedInteger packInt(nu=1, width=10) - annotation (Placement(transformation(extent={{-40,0},{-20,20}}))); + annotation (Placement(transformation(extent={{-44,30},{-24,50}}))); Packaging.SerialPackager.AddInteger addInteger(nu=1) - annotation (Placement(transformation(extent={{-40,-76},{-20,-56}}))); + annotation (Placement(transformation(extent={{-44,-46},{-24,-26}}))); Modelica.Blocks.Sources.IntegerExpression integerExpression2(y=integer(5*sin( time))) - annotation (Placement(transformation(extent={{-76,-78},{-56,-58}}))); + annotation (Placement(transformation(extent={{-80,-48},{-60,-28}}))); Modelica.Blocks.Sources.IntegerExpression integerExpression1(y=integer(5*sin( time) + 5)) - annotation (Placement(transformation(extent={{-80,-38},{-60,-18}}))); + annotation (Placement(transformation(extent={{-84,-8},{-64,12}}))); Packaging.SerialPackager.PackUnsignedInteger packInt1(nu=1, bitOffset=5, width=10) - annotation (Placement(transformation(extent={{-40,-38},{-20,-18}}))); + annotation (Placement(transformation(extent={{-44,-8},{-24,12}}))); Packaging.SerialPackager.ResetPointer resetPointer(nu=1) - annotation (Placement(transformation(extent={{36,36},{56,56}}))); + annotation (Placement(transformation(extent={{32,66},{52,86}}))); Packaging.SerialPackager.UnpackUnsignedInteger unpackInt(nu=1, width=10) - annotation (Placement(transformation(extent={{36,2},{56,22}}))); - Packaging.SerialPackager.GetInteger getInteger - annotation (Placement(transformation(extent={{36,-72},{56,-52}}))); + annotation (Placement(transformation(extent={{32,32},{52,52}}))); + Packaging.SerialPackager.GetInteger getInteger(nu=1) + annotation (Placement(transformation(extent={{32,-42},{52,-22}}))); Packaging.SerialPackager.UnpackUnsignedInteger unpackInt1( nu=1, bitOffset=5, - width=10) annotation (Placement(transformation(extent={{36,-34},{56,-14}}))); + width=10) annotation (Placement(transformation(extent={{32,-4},{52,16}}))); + Packaging.SerialPackager.AddBoolean addBoolean(nu=1) + annotation (Placement(transformation(extent={{-44,-78},{-24,-58}}))); + Packaging.SerialPackager.GetBoolean getBoolean + annotation (Placement(transformation(extent={{32,-76},{52,-56}}))); + Modelica.Blocks.Sources.BooleanPulse booleanPulse(period=0.2) + annotation (Placement(transformation(extent={{-80,-78},{-60,-58}}))); equation connect(integerExpression.y, packInt.u) annotation (Line( - points={{-59,10},{-42,10}}, + points={{-63,40},{-46,40}}, color={255,127,0})); connect(packager.pkgOut, packInt.pkgIn) annotation (Line( - points={{-30,39.2},{-30,20.8}})); + points={{-34,69.2},{-34,50.8}})); connect(integerExpression2.y, addInteger.u[1]) annotation (Line( - points={{-55,-68},{-48,-68},{-48,-66},{-42,-66}}, + points={{-59,-38},{-52,-38},{-52,-36},{-46,-36}}, color={255,127,0})); connect(integerExpression1.y, packInt1.u) annotation (Line( - points={{-59,-28},{-42,-28}}, + points={{-63,2},{-46,2}}, color={255,127,0})); connect(packInt.pkgOut[1], packInt1.pkgIn) annotation (Line( - points={{-30,-0.8},{-30,-17.2}})); + points={{-34,29.2},{-34,12.8}})); connect(packInt1.pkgOut[1], addInteger.pkgIn) annotation (Line( - points={{-30,-38.8},{-30,-55.2}})); - connect(addInteger.pkgOut[1], resetPointer.pkgIn) annotation (Line( - points={{-30,-76.8},{-30,-86},{10,-86},{10,64},{46,64},{46,56.8}})); + points={{-34,-8.8},{-34,-25.2}})); connect(resetPointer.pkgOut[1], unpackInt.pkgIn) annotation (Line( - points={{46,35.2},{46,22.8}})); + points={{42,65.2},{42,52.8}})); connect(unpackInt.pkgOut[1], unpackInt1.pkgIn) annotation (Line( - points={{46,1.2},{46,-13.2}})); + points={{42,31.2},{42,16.8}})); connect(unpackInt1.pkgOut[1], getInteger.pkgIn) annotation (Line( - points={{46,-34.8},{46,-51.2}})); + points={{42,-4.8},{42,-21.2}})); + connect(booleanPulse.y, addBoolean.u[1]) annotation (Line( + points={{-59,-68},{-46,-68}}, + color={255,0,255}, + smooth=Smooth.None)); + connect(addInteger.pkgOut[1], addBoolean.pkgIn) annotation (Line( + points={{-34,-46.8},{-34,-57.2}}, + color={0,0,0}, + smooth=Smooth.None)); + connect(getInteger.pkgOut[1], getBoolean.pkgIn) annotation (Line( + points={{42,-42.8},{42,-55.2}}, + color={0,0,0}, + smooth=Smooth.None)); + connect(addBoolean.pkgOut[1], resetPointer.pkgIn) annotation (Line( + points={{-34,-78.8},{-34,-84},{0,-84},{0,94},{42,94},{42,86.8}}, + color={0,0,0}, + smooth=Smooth.None)); annotation (experiment(StopTime=5.0), Documentation(info="

The example demonstrates that pack and unpack blocks of the SerialPackager package can be connected directly.

-")); +"), + Diagram(coordinateSystem(preserveAspectRatio=false, extent={{-100,-100},{ + 100,100}}), graphics)); end TestSerialPackager; diff --git a/Modelica_DeviceDrivers/Blocks/Examples/TestSerialPackager_String.mo b/Modelica_DeviceDrivers/Blocks/Examples/TestSerialPackager_String.mo index b6131659..0e721568 100644 --- a/Modelica_DeviceDrivers/Blocks/Examples/TestSerialPackager_String.mo +++ b/Modelica_DeviceDrivers/Blocks/Examples/TestSerialPackager_String.mo @@ -52,7 +52,9 @@ equation connect(getString.pkgOut[1], getInteger.pkgIn) annotation (Line( points={{6,-28.8},{6,-37.2}})); connect(addInteger.pkgOut[1], resetPointer.pkgIn) annotation (Line( - points={{-42,-58.8},{-42,-66},{-12,-66},{-12,66},{6,66},{6,58.8}})); + points={{-42,-58.8},{-42,-64},{-20,-64},{-20,66},{6,66},{6,58.8}}, + color={0,0,0}, + smooth=Smooth.None)); annotation (Diagram(coordinateSystem(preserveAspectRatio=false,extent={{-100, -100},{100,100}}), graphics={Text( extent={{-82,84},{82,68}}, diff --git a/Modelica_DeviceDrivers/Blocks/Packaging/SerialPackager.mo b/Modelica_DeviceDrivers/Blocks/Packaging/SerialPackager.mo index 83b64bba..36a49287 100644 --- a/Modelica_DeviceDrivers/Blocks/Packaging/SerialPackager.mo +++ b/Modelica_DeviceDrivers/Blocks/Packaging/SerialPackager.mo @@ -252,7 +252,9 @@ and one Integer value is added, serialized and finally sent using UDP. extends Modelica_DeviceDrivers.Blocks.Packaging.SerialPackager.Internal.PartialSerialPackager; import Modelica_DeviceDrivers.Packaging.alignAtByteBoundary; + import Modelica_DeviceDrivers.Utilities.Types.ByteOrder; parameter Integer n = 1 "Vector size"; + parameter ByteOrder byteOrder = ByteOrder.LE; Modelica.Blocks.Interfaces.BooleanInput u[n] annotation (Placement(transformation(extent={{-140,-20},{-100,20}}))); protected @@ -272,7 +274,8 @@ and one Integer value is added, serialized and finally sent using UDP. Modelica_DeviceDrivers.Blocks.Packaging.SerialPackager.Internal.DummyFunctions.addInteger( pkgOut.pkg, u_int, - pkgIn.dummy); + pkgIn.dummy, + byteOrder); end when; annotation (Icon(graphics={ @@ -462,8 +465,10 @@ and one Integer value is added, serialized and finally sent using UDP. extends Modelica_DeviceDrivers.Blocks.Packaging.SerialPackager.Internal.PartialSerialPackager; import Modelica_DeviceDrivers.Packaging.alignAtByteBoundary; + import Modelica_DeviceDrivers.Utilities.Types.ByteOrder; parameter Integer n = 1 "Vector size"; - discrete Modelica.Blocks.Interfaces.BooleanOutput y[n](each start=0, each fixed=true) + parameter ByteOrder byteOrder = ByteOrder.LE; + discrete Modelica.Blocks.Interfaces.BooleanOutput y[n](each start=false, each fixed=true) annotation (Placement(transformation(extent={{100,-10},{120,10}}))); protected Integer y_int[n]; @@ -478,7 +483,8 @@ and one Integer value is added, serialized and finally sent using UDP. Modelica_DeviceDrivers.Blocks.Packaging.SerialPackager.Internal.DummyFunctions.getInteger( pkgIn.pkg, n, - pkgIn.dummy); + pkgIn.dummy, + byteOrder); pkgOut.dummy = fill(dummy,nu); end when; diff --git a/Modelica_DeviceDrivers/ClockedBlocks/Examples.mo b/Modelica_DeviceDrivers/ClockedBlocks/Examples.mo index 570d21d5..373e72d3 100644 --- a/Modelica_DeviceDrivers/ClockedBlocks/Examples.mo +++ b/Modelica_DeviceDrivers/ClockedBlocks/Examples.mo @@ -7,97 +7,137 @@ package Examples extends Modelica.Icons.Example; Modelica.Blocks.Sources.IntegerExpression integerExpression(y=integer(3*sin( time) + 3)) - annotation (Placement(transformation(extent={{-100,30},{-80,50}}))); + annotation (Placement(transformation(extent={{-100,36},{-80,56}}))); ClockedBlocks.Packaging.SerialPackager.Packager packager - annotation (Placement(transformation(extent={{-50,70},{-30,90}}))); + annotation (Placement(transformation(extent={{-50,76},{-30,96}}))); ClockedBlocks.Packaging.SerialPackager.PackUnsignedInteger packInt(nu=1, width=10) - annotation (Placement(transformation(extent={{-50,30},{-30,50}}))); + annotation (Placement(transformation(extent={{-50,36},{-30,56}}))); ClockedBlocks.Packaging.SerialPackager.AddInteger addInteger(nu=1) - annotation (Placement(transformation(extent={{-50,-46},{-30,-26}}))); + annotation (Placement(transformation(extent={{-50,-22},{-30,-2}}))); Modelica.Blocks.Sources.IntegerExpression integerExpression2(y=integer(5*sin( time))) - annotation (Placement(transformation(extent={{-100,-46},{-80,-26}}))); + annotation (Placement(transformation(extent={{-100,-22},{-80,-2}}))); Modelica.Blocks.Sources.IntegerExpression integerExpression1(y=integer(5*sin( time) + 5)) - annotation (Placement(transformation(extent={{-100,-8},{-80,12}}))); + annotation (Placement(transformation(extent={{-100,8},{-80,28}}))); ClockedBlocks.Packaging.SerialPackager.PackUnsignedInteger packInt1( nu=1, bitOffset=5, width=10) - annotation (Placement(transformation(extent={{-50,-8},{-30,12}}))); + annotation (Placement(transformation(extent={{-50,8},{-30,28}}))); ClockedBlocks.Packaging.SerialPackager.ResetPointer resetPointer(nu=1) - annotation (Placement(transformation(extent={{26,66},{46,86}}))); + annotation (Placement(transformation(extent={{26,72},{46,92}}))); ClockedBlocks.Packaging.SerialPackager.UnpackUnsignedInteger unpackInt(nu=1, width=10) - annotation (Placement(transformation(extent={{26,32},{46,52}}))); - ClockedBlocks.Packaging.SerialPackager.GetInteger getInteger - annotation (Placement(transformation(extent={{26,-42},{46,-22}}))); + annotation (Placement(transformation(extent={{26,38},{46,58}}))); + ClockedBlocks.Packaging.SerialPackager.GetInteger getInteger(nu=1) + annotation (Placement(transformation(extent={{26,-18},{46,2}}))); ClockedBlocks.Packaging.SerialPackager.UnpackUnsignedInteger unpackInt1( nu=1, bitOffset=5, - width=10) annotation (Placement(transformation(extent={{26,-4},{46,16}}))); + width=10) annotation (Placement(transformation(extent={{26,12},{46,32}}))); Modelica_Synchronous.IntegerSignals.Sampler.SampleClocked sample1 - annotation (Placement(transformation(extent={{-72,34},{-60,46}}))); + annotation (Placement(transformation(extent={{-72,40},{-60,52}}))); Modelica_Synchronous.IntegerSignals.Sampler.SampleClocked sample2 - annotation (Placement(transformation(extent={{-72,-4},{-60,8}}))); + annotation (Placement(transformation(extent={{-72,12},{-60,24}}))); Modelica_Synchronous.IntegerSignals.Sampler.SampleClocked sample3 - annotation (Placement(transformation(extent={{-72,-42},{-60,-30}}))); + annotation (Placement(transformation(extent={{-72,-18},{-60,-6}}))); Modelica_Synchronous.ClockSignals.Clocks.PeriodicRealClock periodicRealClock(period= 0.1) - annotation (Placement(transformation(extent={{-98,-82},{-78,-62}}))); + annotation (Placement(transformation(extent={{-96,-80},{-82,-66}}))); + Packaging.SerialPackager.AddBoolean addBoolean(nu=1) + annotation (Placement(transformation(extent={{-50,-54},{-30,-34}}))); + Modelica_Synchronous.BooleanSignals.Sampler.SampleClocked sample4 + annotation (Placement(transformation(extent={{-72,-50},{-60,-38}}))); + Modelica.Blocks.Sources.BooleanPulse booleanPulse(period=0.2) + annotation (Placement(transformation(extent={{-98,-51},{-84,-37}}))); + Packaging.SerialPackager.GetBoolean getBoolean + annotation (Placement(transformation(extent={{26,-50},{46,-30}}))); equation connect(packager.pkgOut, packInt.pkgIn) annotation (Line( - points={{-40,69.2},{-40,50.8}})); + points={{-40,75.2},{-40,56.8}})); connect(packInt.pkgOut[1], packInt1.pkgIn) annotation (Line( - points={{-40,29.2},{-40,12.8}})); + points={{-40,35.2},{-40,28.8}})); connect(packInt1.pkgOut[1], addInteger.pkgIn) annotation (Line( - points={{-40,-8.8},{-40,-25.2}})); - connect(addInteger.pkgOut[1], resetPointer.pkgIn) annotation (Line( - points={{-40,-46.8},{-40,-56},{0,-56},{0,94},{36,94},{36,86.8}})); + points={{-40,7.2},{-40,-1.2}})); connect(resetPointer.pkgOut[1], unpackInt.pkgIn) annotation (Line( - points={{36,65.2},{36,52.8}})); + points={{36,71.2},{36,58.8}})); connect(unpackInt.pkgOut[1], unpackInt1.pkgIn) annotation (Line( - points={{36,31.2},{36,16.8}})); + points={{36,37.2},{36,32.8}})); connect(unpackInt1.pkgOut[1], getInteger.pkgIn) annotation (Line( - points={{36,-4.8},{36,-21.2}})); + points={{36,11.2},{36,2.8}})); connect(integerExpression.y, sample1.u) annotation (Line( - points={{-79,40},{-73.2,40}}, + points={{-79,46},{-73.2,46}}, color={255,127,0})); connect(sample1.y, packInt.u) annotation (Line( - points={{-59.4,40},{-52,40}}, + points={{-59.4,46},{-52,46}}, color={255,127,0})); connect(integerExpression1.y, sample2.u) annotation (Line( - points={{-79,2},{-73.2,2}}, + points={{-79,18},{-73.2,18}}, color={255,127,0})); connect(sample2.y, packInt1.u) annotation (Line( - points={{-59.4,2},{-52,2}}, + points={{-59.4,18},{-52,18}}, color={255,127,0})); connect(integerExpression2.y, sample3.u) annotation (Line( - points={{-79,-36},{-73.2,-36}}, + points={{-79,-12},{-73.2,-12}}, color={255,127,0})); connect(sample3.y, addInteger.u[1]) annotation (Line( - points={{-59.4,-36},{-52,-36}}, + points={{-59.4,-12},{-52,-12}}, color={255,127,0})); - connect(periodicRealClock.y, sample1.clock) annotation (Line( - points={{-77,-72},{-56,-72},{-56,28},{-66,28},{-66,32.8}}, - color={135,135,135}, + connect(addInteger.pkgOut[1], addBoolean.pkgIn) annotation (Line( + points={{-40,-22.8},{-40,-33.2}}, + color={0,0,0}, + pattern=LinePattern.None, + smooth=Smooth.None)); + connect(addBoolean.u[1], sample4.y) annotation (Line( + points={{-52,-44},{-59.4,-44}}, + color={255,0,255}, + smooth=Smooth.None)); + connect(sample4.u, booleanPulse.y) annotation (Line( + points={{-73.2,-44},{-83.3,-44}}, + color={255,0,255}, + smooth=Smooth.None)); + connect(periodicRealClock.y, sample4.clock) annotation (Line( + points={{-81.3,-73},{-66,-73},{-66,-51.2}}, + color={175,175,175}, pattern=LinePattern.Dot, - thickness=0.5)); - connect(sample2.clock, periodicRealClock.y) annotation (Line( - points={{-66,-5.2},{-66,-18},{-56,-18},{-56,-72},{-77,-72}}, + thickness=0.5, + smooth=Smooth.None)); + connect(periodicRealClock.y, sample3.clock) annotation (Line( + points={{-81.3,-73},{-56,-73},{-56,-22},{-66,-22},{-66,-19.2}}, color={175,175,175}, pattern=LinePattern.Dot, - thickness=0.5)); - connect(sample3.clock, periodicRealClock.y) annotation (Line( - points={{-66,-43.2},{-66,-72},{-77,-72}}, + thickness=0.5, + smooth=Smooth.None)); + connect(periodicRealClock.y, sample2.clock) annotation (Line( + points={{-81.3,-73},{-56,-73},{-56,8},{-66,8},{-66,10.8}}, color={175,175,175}, pattern=LinePattern.Dot, - thickness=0.5)); + thickness=0.5, + smooth=Smooth.None)); + connect(periodicRealClock.y, sample1.clock) annotation (Line( + points={{-81.3,-73},{-56,-73},{-56,36},{-66,36},{-66,38.8}}, + color={175,175,175}, + pattern=LinePattern.Dot, + thickness=0.5, + smooth=Smooth.None)); + connect(getInteger.pkgOut[1], getBoolean.pkgIn) annotation (Line( + points={{36,-18.8},{36,-29.2}}, + color={0,0,0}, + pattern=LinePattern.None, + smooth=Smooth.None)); + connect(addBoolean.pkgOut[1], resetPointer.pkgIn) annotation (Line( + points={{-40,-54.8},{-40,-60},{0,-60},{0,98},{36,98},{36,92.8}}, + color={0,0,0}, + pattern=LinePattern.None, + smooth=Smooth.None)); annotation (experiment(StopTime=5.0), Documentation(info="

The example demonstrates that pack and unpack blocks of the SerialPackager package can be connected directly.

-")); +"), + Diagram(coordinateSystem(preserveAspectRatio=false, extent={{-100,-100},{ + 100,100}}), graphics)); end TestSerialPackager; model TestSerialPackager_String diff --git a/Modelica_DeviceDrivers/ClockedBlocks/Packaging.mo b/Modelica_DeviceDrivers/ClockedBlocks/Packaging.mo index dbdca866..1820715a 100644 --- a/Modelica_DeviceDrivers/ClockedBlocks/Packaging.mo +++ b/Modelica_DeviceDrivers/ClockedBlocks/Packaging.mo @@ -231,7 +231,9 @@ package Packaging extends Modelica_DeviceDrivers.ClockedBlocks.Packaging.SerialPackager.Internal.PartialSerialPackager; import Modelica_DeviceDrivers.Packaging.alignAtByteBoundary; + import Modelica_DeviceDrivers.Utilities.Types.ByteOrder; parameter Integer n = 1; + parameter ByteOrder byteOrder = ByteOrder.LE; Modelica.Blocks.Interfaces.BooleanInput u[n] annotation (Placement(transformation(extent={{-140,-20},{-100,20}}))); protected @@ -248,7 +250,8 @@ package Packaging Modelica_DeviceDrivers.ClockedBlocks.Packaging.SerialPackager.Internal.DummyFunctions.addInteger( pkgOut.pkg, u_int, - pkgIn.dummy); + pkgIn.dummy, + byteOrder); annotation (Icon(graphics={ Text( @@ -413,9 +416,10 @@ package Packaging extends Modelica_DeviceDrivers.ClockedBlocks.Packaging.SerialPackager.Internal.PartialSerialPackager; import Modelica_DeviceDrivers.Packaging.alignAtByteBoundary; + import Modelica_DeviceDrivers.Utilities.Types.ByteOrder; parameter Integer n = 1; - Modelica.Blocks.Interfaces.BooleanOutput y[ - n] + parameter ByteOrder byteOrder = ByteOrder.LE; + Modelica.Blocks.Interfaces.BooleanOutput y[n](each start=false) annotation (Placement(transformation(extent={{100,-10},{120,10}}))); protected Integer y_int[n]; @@ -428,7 +432,8 @@ package Packaging Modelica_DeviceDrivers.ClockedBlocks.Packaging.SerialPackager.Internal.DummyFunctions.getInteger( pkgIn.pkg, n, - pkgIn.dummy); + pkgIn.dummy, + byteOrder); pkgOut.dummy = fill(dummy,nu); for i in 1:n loop