The concept of the SerialPackager is to allow adding/retrieving data to/from a package in a device independent manner. See Getting started.
Extends from Modelica.Icons.Package (Icon for standard packages).Name | Description |
---|---|
![]() | Create a package which allows to add signals of various types |
![]() | Add a Boolean vector to package |
![]() | Add an Integer vector to package |
![]() | Add a Real vector to package |
![]() | Cast all elements of Real vector to float and add to package (loss of precision!) |
![]() | Add string to package |
![]() | Get Boolean vector from package |
![]() | Get Integer vector from package |
![]() | Get Real vector from package |
![]() | Get float vector from package (all values casted to double before assigning it to Modelica Real array) |
![]() | Get String from package |
![]() | Encode (non-negative) integer value at bit level |
![]() | decode integer value encoded at bit level |
![]() | Set current writing/reading position of package to zero |
The Packager
block creates a packager object to which payload can be added by subsequent blocks.
With the default parameter settings the buffer size (size of the serialized package), as well as the sample time of the block is determined automatically by
backward propagation. However, that values may also be set manually. An example there this functionality is used is the TestSerialPackager
model. In that model the parameter sampleTime
is explicitely set, since backward propagation is not possible in that case.
The block is used in several examples, e.g. in,
TestSerialPackager_UDP
.
The figure below shows an arrangement in which a Packager
object is created and after that a payload of three Real values
and one Integer value is added, serialized and finally sent using UDP.
Name | Description |
---|---|
Advanced | |
useBackwardSampleTimePropagation | true, use backward propagation for sample time (default!), otherwise switch to forward propagation |
sampleTime | Sample time if forward propagation of sample time is used |
useBackwardPropagatedBufferSize | true, use backward propagated (automatic) buffer size for package (default!), otherwise use manually specified buffer size below |
userBufferSize | Buffer size for package if backward propagation of buffer size is deactivated |
Name | Description |
---|---|
pkgOut |
Name | Description |
---|---|
n |
Name | Description |
---|---|
pkgIn | |
pkgOut[nu] | |
u[n] |
Name | Description |
---|---|
n |
Name | Description |
---|---|
pkgIn | |
pkgOut[nu] | |
u[n] |
Name | Description |
---|---|
n |
Name | Description |
---|---|
pkgIn | |
pkgOut[nu] | |
u[n] |
Name | Description |
---|---|
n |
Name | Description |
---|---|
pkgIn | |
pkgOut[nu] | |
u[n] |
Name | Description |
---|---|
bufferSize | Buffer size (in bytes) reserved for String (ensure that same buffer size is used in corresponding GetString block!) |
data |
Name | Description |
---|---|
pkgIn | |
pkgOut[nu] |
Name | Description |
---|---|
n |
Name | Description |
---|---|
pkgIn | |
pkgOut[nu] | |
y[n] |
Name | Description |
---|---|
n |
Name | Description |
---|---|
pkgIn | |
pkgOut[nu] | |
y[n] |
Name | Description |
---|---|
n |
Name | Description |
---|---|
pkgIn | |
pkgOut[nu] | |
y[n] |
Name | Description |
---|---|
n |
Name | Description |
---|---|
pkgIn | |
pkgOut[nu] | |
y[n] |
Name | Description |
---|---|
bufferSize | Buffer size (in bytes) reserved for String (ensure that same buffer size is used in corresponding AddString block!) |
Name | Description |
---|---|
pkgIn | |
pkgOut[nu] |
The block allows to pack unsigned integer values on bit level. The number of bits used for encoding is set by parameter width
, therefore the maximum value of the integer signal that can be encoded is 2^width - 1
. The parameter bitOffset
allows to specify the bit at which the encoding starts relative to the preceding block.
If an AddBoolean
, AddInteger
, AddReal
or AddString
block follows a PackUnsignedInteger
block the bit position after the PackUnsignedInteger
block is aligned to the next byte boundery.
Currently, the pack block only supports Intel-Endiannes (little-endian!).
For information about endianness in computing see for example http://en.wikipedia.org/wiki/Endianness
The block is used in example
TestSerialPackagerBitPack_UDP
, depicted below.
AddInteger
block. Assuming that the value of the first Integer variable was 3 (decimal) == 11 (binary)
we would get the memory layout below. A '.' denotes that the bit is not part of the bits encoding the value (LSB = Least Significant Byte and MSB = Most Significant Byte).
byte 24 byte 25 LSB MSB Relative bit position in Memory: (0 1 2 3 4 5 6 7) (8 9 10 11 12 13 14 15) ( .. Value of bit : (0 0 0 0 0 0 1 1) (. . . . . . 0 0)
See also UnpackUnsignedInteger
.
Name | Description |
---|---|
bitOffset | Bit offset from current packager position until first encoding bit |
width | Number of bits that encode the integer value |
Name | Description |
---|---|
pkgIn | |
pkgOut[nu] | |
u | Only postive (unsigned) values are supported |
The block allows to unpack unsigned integer values on bit level. The number of bits used for decoding is set by parameter width
. The parameter bitOffset
allows to specify the bit at which the decoding starts relative to the preceding block.
If an GetBoolean
, GetInteger
, GetReal
or GetString
block follows an UnpackUnsignedInteger
block the bit position after the UnpackUnsignedInteger
block is aligned to the next byte boundery.
Currently, the pack block only supports Intel-Endiannes (little-endian!).
For information about endianness in computing see for example http://en.wikipedia.org/wiki/Endianness
The block is used in example
TestSerialPackagerBitPack_UDP
, depicted below.
GetInteger
block. Assume that we had the memory layout below and would like to unpack the second Integer value. A '.' denotes that the bit is not part of the bits encoding the value (LSB = Least Significant Byte and MSB = Most Significant Byte).
byte 24 byte 25 byte 26 byte 27 byte 28 LSB MSB Relative bit position in Memory: 0-7 8-15 16-23 (24 25 26 27 28 29 30 31) (32 33 34 35 36 37 38 39) (.. Value of bit : 0 1 . . . . . . 0 0 0 0 0 0 0 1
The value of the unpacked second Integer value would be 5 (decimal) == 101 (binary)
.
See also PackUnsignedInteger
.
Name | Description |
---|---|
bitOffset | Bit offset from current packager position until first encoding bit |
width | Number of bits that encode the integer value |
Name | Description |
---|---|
pkgIn | |
pkgOut[nu] | |
y |
Name | Description |
---|---|
pkgIn | |
pkgOut[nu] |