Specifications
Constructing and Extracting CAN Data Frames
4-43
has to get bit 15, the second bit 14 and so on. It is easiest to define this mapping
by the MATLAB colon operator: and an increment of –1.
The third input is only necessary because the reserved byte 2 has to have all
bits set to 1. If a bit position in the outgoing data frame isn’t referenced by a bit
pattern array element, the bit will be by default 0, but there is no construct to
have them set to 1 as the default. Therefore a uint8 constant with value 255
has to be externally brought in. The constant 255 has to get to bit position 16
to 23 (byte 2) of the outgoing data frame.
Because bit 0 of data frame byte 3 (bit 24) has to be 0 and 0 is the default bit
value if not referenced by a bit pattern array element, no explicit action has to
be taken here.
The fourth input is the Flag of type boolean, which has an example value of 1.
This value has to become bit 1 of byte 3 (bit 25) of the data frame. Therefore the
single bit (element 1 of double array [25]) has to get bit 25 of the data frame.
The fifth input is the Control of type int8, which has an example value of 121.
But only bits 2 to 7 have to be mapped into the outgoing data frame or in other
words bits 0 and 1 have to be thrown away. Because indexing of incoming
values always starts with the first bit (bit 0) a special indexing value (-1) has
to be used in order to skip bit 0 and 1 of the incoming int8 value. Bits 2 to 7 will
be directly mapped to bit 2 to 7 of byte 3 (bits 26 to 31) of the outgoing data
frame. This leads to the following bit pattern: [-1,-1,26:31]
The sixth input is the Value of type int16, which has an example value of –
12270. This value has to become byte 4 and 5 (bits 32 to 47) of the outgoing data
frame. Therefore the first bit (element 1 of double array [32:47]) has to get bit
32 of the data frame, the second bit 33 and so on. It is easiest to define this
mapping by the MATLAB colon operator:.
The output of the block then consists of a double value representing the packed
data types within the first 6 bytes. The last two bytes are zero. This means that
even in the case were less than 8 bytes are significant, the CAN data frame is
always represented by a double value (8 bytes). The value of the constructed
floating point double doesn’t have any particular meaning but still can be
inspected by a numerical display.