Programming for experts
P.
106 of 349
String as bytearray
Determination of raw data of the telegrams
Now it is necessary how the raw data of the telegrams on the bus can be determined. For this
purpose
Code-part 2
i
f event(readrawknx(Sim_Kontroll,Sim_Sender,Sim_GA,Sim_IsGa,Sim_RoutingCnt,Sim_Len,Sim_Data)) and
Sim_Len!=0 and Sim_IsGa and !Sim_Play then {
if !Sim_MyGA then Sim_Next=OFF endif;
if Sim_MyGA then {
if Sim_Len==1 then Sim_RawData=convert(stringcast(Sim_Data,0u08,1u16) and 0x7F,0u32) endif;
if Sim_Len==2 then Sim_RawData=convert(stringcast(Sim_Data,0u08,2u16),0u32) endif;
// Byte Order has to be considered
if Sim_Len==3 then Sim_RawData=convert(stringcast(Sim_Data,0u08,2u16),0u32)*256u32
+convert(stringcast(Sim_Data,0u08,3u16),0u32) endif;
if Sim_Len==5 then Sim_RawData=convert(stringcast(Sim_Data,0u08,2u16),0u32)*16777216u32
+convert(stringcast(Sim_Data,0u08,3u16),0u32)*6convert(stringcast(Sim_Data,0u08,4u16),0u32)*2
56u32+convert(stringcast(Sim_Data,0u08,5u16),0u32) endif;
Sim_Next=ON;
} endif;
}endif
Sim_RawData
are raw data in u32 format. If only one bit has been sent, so 31 bits are “unused”. Die
incoming data are written from
readrawknx
in
Sim_Data
string variable. These are basically regarded
as raw data and then be converted into u32 bit value.The arrangement of data in 4 bytes (32bits)
unifies the saving of the telegrams data and simplifies the method (how to show yet).
For processing these raw data on string
Sim_RawData
now the single bytes have to be interpreted
as 1-byte integer values. This happens with the help of function
stringcast
.
X
=
stringcast(
src{cxxxx}, dest, Pos{u16}
)
This function start to look at the bytes on string
src
from the byte-position
Pos. dest
on there gives
the target data type conversion on, which specifies the number of bytes and defines the conversion
to the result
X
. Based on Picture 1 it is explained: The graphic shows the string as byte arrangement.
At position 3{u16} the value is hexadecimal 0x74.
0x10 0xXX 0xXX 0x74 0xA0
0xXX
0x10 0x01 0xXX 0xXX 0xXX
0xE1
3
u16
4
u16
5
u16
6
u16
0xXX
0xXX
Picture 1: String
src
as arrayfield.
A statement Z1=
stringcast(
src,0,3u16
)
will define a variable Z1 from the data type u08 (argument „0“)
. The value is obtained from
src
(Picture 1) on position 3{u16} and is thus in this case 0x74 (dezcmal
116). A statement Z2=
stringcast(
src,10u32,3u16
)
however defines die number 0x74a0e101 (decimal
1956700417). This number of bytes, which are extracted from the string is obtained by the argument
10u32: The data type u32 is 32 bits long and consists of 4 bytes. The value 10 of „10u32“ itself is
ignored, here. The order of bytes remains unchanged in the
stringcast
function.
Back to the example:
Sim_RawData
contains the data of the incoming telegrams in the first 4 bytes.
The order of the bytes on the bus is different to the order of the bytes of the Linuxsystem of the
Enertex® EibPCs. In order to use these data the byte order has to be reversed i.e. the last bit has to
be in the first place etc. This rearrangement is realised by the help of multiplication by 256 and 65536
and 16777216.
The present processing of raw data is limited to max. 32 bit telegrams. Longer data telegrams can
not be recorded, on the other hand bytes will be surely wasted by recording 1 bit elements, because
all telegrams are treated equally. Nevertheless this approach to some extent an optimal compromise
because the processing is easier later.
The code-part 2 calculates now the data of the u32 – variable
Sim_RawData
.
HandbuchEibPC_USA-30.odt, 2017-05-11
Enertex
®
Bayern GmbH - Erlachstraße 13 - 91301 Forchheim - [email protected]