Files
BDE/PD20_tel.py
2017-07-26 10:43:21 +02:00

123 lines
3.8 KiB
Python
Executable File

#!/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'] = 'i.O.'
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 == 'n.i.O.':
tel.attrib['bauteilstatus'] = 'n.i.O.'
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))