From 02ef218148bb3f6f8d45ea506b517a1bfbd4dcf3 Mon Sep 17 00:00:00 2001 From: Michael Rest Date: Tue, 16 May 2017 09:37:02 +0200 Subject: [PATCH] Added Telegram code for communication with Fill Cell --- DM20_tel.py | 68 ++++++++++++++++++++++++++++ PD20_tel.py | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++ tel_decode.py | 10 +++++ telegram.py | 4 +- 4 files changed, 203 insertions(+), 1 deletion(-) create mode 100755 DM20_tel.py create mode 100755 PD20_tel.py diff --git a/DM20_tel.py b/DM20_tel.py new file mode 100755 index 0000000..43906a6 --- /dev/null +++ b/DM20_tel.py @@ -0,0 +1,68 @@ +#!/usr/bin/python + +__author__ = "Michael Rest" +__date__ = "2016/09/01" +__email__ = "mr@mir.systems" +__version__ = "$Revision: 1.1 $"[11:-2] + + +from telegram import TELEGRAM, TEL_DM20 +from telegram import tsdecode +from states import * + +def fromstring (data): + """ + Decode the binary representation of a PD_tel from the given + parameter and note the data in the instance of the object. + + Parameters: + data: The binary form of the TELEGRAM + """ + tel = TEL_DM20 () + try: + tel.attrib['nr'] = (data [0] << 8) + data [1] + except: + print ("Debug-Nr", data[0], data[1]) + tel.attrib['src'] = data [2:4].decode () + tel.attrib['dst'] = data [4:6].decode () + tel.attrib['type'] = data [6:10].decode () + tel.attrib['dmc'] = (data [10:38]).decode ().rstrip (' \x00') + return tel + + +class TEL_DM20 (TELEGRAM): + def __init__ (self, nr = 0, src = '20', dst = 'PC', *args, **args2): + TELEGRAM.__init__(self) + self.code = TEL_DM20 + self.attrib['nr'] = nr + self.attrib['src'] = src + self.attrib['dst'] = dst + self.attrib['type'] = 'DM20' + self.attrib['dmc'] = '1234' + self.attrib['aufnahme'] = 0 + + self.len = 2220907 + return + + def identify (self): + """ + This method can be used to identify a TELEGRAM by string. + """ + return "DM20 TELEGRAM" + + + def __repr__ (self): + """ + Print a representation of the TPDU. Use this method via + `-pair to transfer it over the wire. This will just return + the header data and not the real data! + """ + # Note that the data is not included in the length + return "%c%c%c" % (2, self.code << 4, self.number) + self.data + + def __str__ (self): + """ + Return a readable and quite verbose overview of the TPDU instance. + Use this for debugging purposes or if you're just curious. + """ + return "Packet: %s Data: %s" % (self.identify (), repr (self.attrib)) diff --git a/PD20_tel.py b/PD20_tel.py new file mode 100755 index 0000000..0e9a35f --- /dev/null +++ b/PD20_tel.py @@ -0,0 +1,122 @@ +#!/usr/bin/python + +__author__ = "Michael Rest" +__date__ = "2016/09/01" +__email__ = "mr@mir.systems" +__version__ = "$Revision: 1.1 $"[11:-2] + + +from telegram import TELEGRAM, TEL_PD20 +from telegram import tsdecode +from states import * +from time import strftime + +def fromstring (data): + """ + Decode the binary representation of a PD_tel from the given + parameter and note the data in the instance of the object. + + Parameters: + data: The binary form of the TELEGRAM + """ + tel = TEL_PD20 () + try: + tel.attrib['nr'] = (data [0] << 8) + data [1] + except: + print ("Debug-Nr", data[0], data[1]) + tel.attrib['src'] = data [2:4].decode () + tel.attrib['dst'] = data [4:6].decode () + tel.attrib['type'] = data [6:10].decode () + tel.attrib['dmc'] = (data [10:38]).decode ().rstrip (' \x00').lstrip (' ') + tel.attrib['startts'] = '' + tel.attrib['endts'] = strftime ("%Y-%m-%d %H:%M:%S ") + #66-70 Varianten daten + tel.attrib['bauteilstatus'] = '1' + for i in range (1, 43): + st = bearbeitungsstatus.get (chr (data [38 + i -1]), '') #0 - unbearbeitet; 1 - iO; 2 - niO + tel.attrib['pp%02d' % i] = st + if st == '2': + tel.attrib['bauteilstatus'] = '2' + tel.attrib['ladungstraeger'] = '' + return tel + + +class TEL_PD20 (TELEGRAM): + def __init__ (self, nr = 0, src = '20', dst = 'PC', *args, **args2): + TELEGRAM.__init__(self) + self.code = TEL_PD20 + self.attrib['nr'] = nr + self.attrib['src'] = src + self.attrib['dst'] = dst + self.attrib['type'] = 'PD20' + self.attrib['startts'] = '2000-01-01 01:01:01' + self.attrib['endts'] = '2000-02-02 02:02:02' + self.attrib['dmc'] = '1234' + self.attrib['bauteilstatus'] = '0' + self.attrib['pp01'] = 'test1' + self.attrib['pp02'] = 'test2' + self.attrib['pp03'] = 'test3' + self.attrib['pp04'] = 'test4' + self.attrib['pp05'] = 'test5' + self.attrib['pp06'] = 'test6' + self.attrib['pp07'] = 'test7' + self.attrib['pp08'] = 'test8' + self.attrib['pp09'] = 'test9' + self.attrib['pp10'] = 'test10' + self.attrib['pp11'] = 'test11' + self.attrib['pp12'] = 'test12' + self.attrib['pp13'] = 'test13' + self.attrib['pp14'] = 'test14' + self.attrib['pp15'] = 'test15' + self.attrib['pp16'] = 'test16' + self.attrib['pp17'] = 'test17' + self.attrib['pp18'] = 'test18' + self.attrib['pp19'] = 'test19' + self.attrib['pp20'] = 'test20' + self.attrib['pp21'] = 'test21' + self.attrib['pp22'] = 'test22' + self.attrib['pp23'] = 'test23' + self.attrib['pp24'] = 'test24' + self.attrib['pp25'] = 'test25' + self.attrib['pp26'] = 'test26' + self.attrib['pp27'] = 'test27' + self.attrib['pp28'] = 'test28' + self.attrib['pp29'] = 'test29' + self.attrib['pp30'] = 'test30' + self.attrib['pp31'] = 'test31' + self.attrib['pp32'] = 'test32' + self.attrib['pp33'] = 'test33' + self.attrib['pp34'] = 'test34' + self.attrib['pp35'] = 'test35' + self.attrib['pp36'] = 'test36' + self.attrib['pp37'] = 'test37' + self.attrib['pp38'] = 'test38' + self.attrib['pp39'] = 'test39' + self.attrib['pp40'] = 'test40' + self.attrib['ladungstraeger'] = '' + + self.len = 2220907 + return + + def identify (self): + """ + This method can be used to identify a TELEGRAM by string. + """ + return "PD20 TELEGRAM" + + + def __repr__ (self): + """ + Print a representation of the TPDU. Use this method via + `-pair to transfer it over the wire. This will just return + the header data and not the real data! + """ + # Note that the data is not included in the length + return "%c%c%c" % (2, self.code << 4, self.number) + self.data + + def __str__ (self): + """ + Return a readable and quite verbose overview of the TPDU instance. + Use this for debugging purposes or if you're just curious. + """ + return "Packet: %s Data: %s" % (self.identify (), repr (self.attrib)) diff --git a/tel_decode.py b/tel_decode.py index 4c6f44e..9290bd6 100755 --- a/tel_decode.py +++ b/tel_decode.py @@ -50,6 +50,14 @@ def decode_PD10 (data): from PD10_tel import fromstring return fromstring (data) +def decode_DM20 (data): + from DM20_tel import fromstring + return fromstring (data) + +def decode_PD20 (data): + from PD20_tel import fromstring + return fromstring (data) + def decode_PD98 (data): from PD98_tel import fromstring return fromstring (data) @@ -77,6 +85,8 @@ b'PD09': decode_PD09, b'PD98': decode_PD98, b'PD99': decode_PD99, b'PD10': decode_PD10, +b'DM20': decode_DM20, +b'PD20': decode_PD20, b'STAT': decode_STAT } diff --git a/telegram.py b/telegram.py index 613e168..058a07a 100644 --- a/telegram.py +++ b/telegram.py @@ -16,6 +16,7 @@ TEL_PD07 = 0x7 # Metallclips TEL_PD08 = 0x8 # Masseblech TEL_PD09 = 0x9 # Nacharbeit TEL_PD10 = 0xa # Messzelle2 +TEL_PD20 = 0xa # Messzelle Fill TEL_PD98 = 0xb # TestSPS TEL_PD99 = 0xc # Zentrale @@ -24,7 +25,8 @@ TEL_STAT = 0xe # TEL_QUIT = 0xf # TEL_DM09 = 0x01 # Nacharbeit -TEL_DM01 = 0x02 # Nacharbeit +TEL_DM01 = 0x02 # DMC Messzelle 1 +TEL_DM20 = 0x0a # DMC Messzelle Finn #Helper def tsdecode (data): """