3
function GetFunctionName ( number )
4
l o c a l names = { " M o i s t u r e " , " H u m i d i t y " , " Pressure " }
5
r e t u r n names [ number ]
6
end
7
8
t e l e g r a m c o l o r s
9
l o c a l t e x t c o l o r s = { 0xFF0000 , 0x0000FF }
10
l o c a l b a c k c o l o r s = { 0xFFEEDD, 0xDDEEFF }
11
12
access t h e c u r r e n t t e l e g r a m
13
l o c a l t g = t e l e g r a m s . t h i s ( )
14
l o c a l b i n d a t a = base16 . decode ( t g : s t r i n g ( ) : sub ( 2 ,
15
16
s e l e c t t h e t e x t and background c o l o r depending on t h e data
source
17
l o c a l f c = t e x t c o l o r s [ t g : d i r ( ) ]
18
l o c a l bc = b a c k c o l o r s [ t g : d i r ( ) ]
19
20
d i s p l a y t i m e
21
box . t e x t { c a p t i o n =" Time " , t e x t = t g : t i m e ( ) , f g = f c , bg=bc }
22
23
s t a r t c o l o n
24
box . t e x t { c a p t i o n ="SOF" , t e x t = s t r i n g . char ( t g : data ( 1 ) ) , bg= f c ,
f g =bc }
25
26
t h e d e v i c e address
27
box . t e x t { c a p t i o n =" Address " , t e x t = b i n d a t a : b y t e ( 1 ) , f g = f c , bg=bc }
28
29
t h e f u n c t i o n number
30
box . t e x t { c a p t i o n =" Function " , t e x t =GetFunctionName ( b i n d a t a : b y t e ( 2 ) ) ,
f g = f c , bg=bc }
31
i f # b i n d a t a >= 7 then
32
33
i t i s a response
l o c a l next , v a l u e = bunpack ( b i n d a t a , " < f " , 3 )
34
35
box . t e x t { c a p t i o n =" Value " , t e x t =value , f g = f c , bg=bc }
end
36
37
38
t h e checksum b y t e i s always t h e l a s t b y t e i n b i n d a t a
39
box . t e x t { c a p t i o n ="Chksum " , t e x t = s t r i n g . f o r m a t ("%02X " , b i n d a t a : b y t e
( 1) ) ,
40
f g = f c , bg=bc }
41
42
end o f frame CRLF
43
box . t e x t { c a p t i o n ="EOF" , t e x t = t g : dump { f i r s t = 2 } , f g =bc , bg= f c }
44
end
Die entsprechende Zeile 34 sollte jetzt leicht verständlich sein. Im Falle eines
Reponse Telegramms extrahieren wir die Fließkommazahl (an Position 3) und
zeigen den Wert in einer zusätzlichen Box an.
Die Überprüfung der Checksum heben wir uns für später auf. Sie werden viel-
leicht bemerkt haben, daß wir die Ausgabe der End-Of-String Sequenz per
relativer (negativer) Indexierung gelöst haben. Dadurch müssen wir uns nicht
um die unterschiedlichen Längen von Anfrage und Antwort Telegrammen küm-
mern. Die EOS Zeichen CRLF sind immer an der 'vorletzten' Position (-2) zu
finden. Das Resultat für die allerersten beiden Telegramme ist damit:
Time
SOF
Address
2.339189
:
2
13.3. TEMPLATE SPRACHSYNTAX
Function
Checksum
Moisture
C4
3 ) )
EOS
0D 0A
129