Files
BDE/PD05_tel.py
Michael Rest 489d411945 Minor fixes
added csv generation
2016-10-16 20:22:11 +02:00

253 lines
8.7 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_PD05
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_PD05 ()
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')
tel.attrib['startts'] = tsdecode (data [38:52].decode ())
tel.attrib['endts'] = tsdecode (data [52:66].decode ())
#66-70 Varianten daten
tel.attrib['bauteilstatus'] = bauteilstatus.get (chr (data [70]), '') #0 - unbearbeitet; 1 - iO; 2 - niO
tel.attrib['NietM8status01'] = bearbeitungsstatus.get (chr (data [71]), '') #0 - unbearbeitet; 1 - iO; 2 - niO
tel.attrib['NietM8status02'] = bearbeitungsstatus.get (chr (data [72]), '') #0 - unbearbeitet; 1 - iO; 2 - niO
tel.attrib['DGBM8status01'] = bearbeitungsstatus.get (chr (data [73]), '') #0 - unbearbeitet; 1 - iO; 2 - niO
tel.attrib['DGBM8status02'] = bearbeitungsstatus.get (chr (data [74]), '') #0 - unbearbeitet; 1 - iO; 2 - niO
tel.attrib['DGBM8status03'] = bearbeitungsstatus.get (chr (data [75]), '') #0 - unbearbeitet; 1 - iO; 2 - niO
tel.attrib['DGBM8status04'] = bearbeitungsstatus.get (chr (data [76]), '') #0 - unbearbeitet; 1 - iO; 2 - niO
tel.attrib['NietM6status01'] = bearbeitungsstatus.get (chr (data [77]), '') #0 - unbearbeitet; 1 - iO; 2 - niO
tel.attrib['NietM6status02'] = bearbeitungsstatus.get (chr (data [78]), '') #0 - unbearbeitet; 1 - iO; 2 - niO
tel.attrib['NietM6status03'] = bearbeitungsstatus.get (chr (data [79]), '') #0 - unbearbeitet; 1 - iO; 2 - niO
tel.attrib['NietM6status04'] = bearbeitungsstatus.get (chr (data [80]), '') #0 - unbearbeitet; 1 - iO; 2 - niO
tel.attrib['NietM6status05'] = bearbeitungsstatus.get (chr (data [81]), '') #0 - unbearbeitet; 1 - iO; 2 - niO
try:
tel.attrib['DGBM8M01'] = (data [90] << 8) + data [91]
except:
print ("Debug-DGBM8M01", data[90], data[91])
try:
tel.attrib['DGBM8D01'] = (data [92] << 8) + data [93]
except:
print ("Debug-DGBM8D01", data[92], data[93])
try:
tel.attrib['DGBM8W01'] = (data [94] << 8) + data [95]
except:
print ("Debug-DGBM8W01", data[94], data[95])
try:
tel.attrib['DGBM8T01'] = (data [96] << 8) + data [97]
except:
print ("Debug-DGBM8T01", data[96], data[97])
try:
tel.attrib['DGBM8M02'] = (data [98] << 8) + data [99]
except:
print ("Debug-DGBM8M02", data[98], data[99])
try:
tel.attrib['DGBM8D02'] = (data [100] << 8) + data [101]
except:
print ("Debug-DGBM8D02", data[100], data[101])
try:
tel.attrib['DGBM8W02'] = (data [102] << 8) + data [103]
except:
print ("Debug-DGBM8W02", data[102], data[103])
try:
tel.attrib['DGBM8T02'] = (data [104] << 8) + data [105]
except:
print ("Debug-DGBM8T02", data[104], data[105])
try:
tel.attrib['DGBM8M03'] = (data [106] << 8) + data [107]
except:
print ("Debug-DGBM8M03", data[106], data[107])
try:
tel.attrib['DGBM8D03'] = (data [108] << 8) + data [109]
except:
print ("Debug-DGBM8D03", data[108], data[109])
try:
tel.attrib['DGBM8W03'] = (data [110] << 8) + data [111]
except:
print ("Debug-DGBM8W03", data[110], data[111])
try:
tel.attrib['DGBM8T03'] = (data [112] << 8) + data [113]
except:
print ("Debug-DGBM8T03", data[112], data[113])
try:
tel.attrib['DGBM8M04'] = (data [114] << 8) + data [115]
except:
print ("Debug-DGBM8M04", data[114], data[115])
try:
tel.attrib['DGBM8D04'] = (data [116] << 8) + data [117]
except:
print ("Debug-DGBM8D04", data[116], data[117])
try:
tel.attrib['DGBM8W04'] = (data [118] << 8) + data [119]
except:
print ("Debug-DGBM8W04", data[118], data[119])
try:
tel.attrib['DGBM8T04'] = (data [120] << 8) + data [121]
except:
print ("Debug-DGBM8T04", data[120], data[121])
try:
tel.attrib['NietM6F01'] = (data [122] << 8) + data [123]
except:
print ("Debug-NietM6F01", data[122], data[123])
try:
tel.attrib['NietM6S01'] = (data [124] << 8) + data [125]
except:
print ("Debug-NietM6S01", data[124], data[125])
try:
tel.attrib['NietM6F02'] = (data [126] << 8) + data [127]
except:
print ("Debug-NietM6F02", data[126], data[127])
try:
tel.attrib['NietM6S02'] = (data [128] << 8) + data [129]
except:
print ("Debug-NietM6S02", data[128], data[129])
try:
tel.attrib['NietM6F03'] = (data [130] << 8) + data [131]
except:
print ("Debug-NietM6F03", data[130], data[131])
try:
tel.attrib['NietM6S03'] = (data [132] << 8) + data [133]
except:
print ("Debug-NietM6S03", data[132], data[133])
try:
tel.attrib['NietM6F04'] = (data [134] << 8) + data [135]
except:
print ("Debug-NietM6F04", data[134], data[135])
try:
tel.attrib['NietM6S04'] = (data [136] << 8) + data [137]
except:
print ("Debug-NietM6S04", data[136], data[137])
try:
tel.attrib['NietM6F05'] = (data [138] << 8) + data [139]
except:
print ("Debug-NietM6F05", data[138], data[139])
try:
tel.attrib['NietM6S05'] = (data [140] << 8) + data [141]
except:
print ("Debug-NietM6S05", data[140], data[141])
try:
tel.attrib['NietM8F01'] = (data [142] << 8) + data [143]
except:
print ("Debug-NietM8F01", data[142], data[143])
try:
tel.attrib['NietM8S01'] = (data [144] << 8) + data [145]
except:
print ("Debug-NietM8S01", data[144], data[145])
try:
tel.attrib['NietM8F02'] = (data [146] << 8) + data [147]
except:
print ("Debug-NietM8F02", data[146], data[147])
try:
tel.attrib['NietM8S02'] = (data [148] << 8) + data [149]
except:
print ("Debug-NietM8S02", data[148], data[149])
tel.attrib['ladungstraeger'] = data [150:152].decode ()
return tel
class TEL_PD05 (TELEGRAM):
def __init__ (self, nr = 0, src = '05', dst = 'PC', *args, **args2):
TELEGRAM.__init__(self)
self.code = TEL_PD05
self.attrib['nr'] = nr
self.attrib['src'] = src
self.attrib['dst'] = dst
self.attrib['type'] = 'PD05'
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['NietM8status01'] = '0'
self.attrib['NietM8status02'] = '0'
self.attrib['DGBM8status01'] = '0'
self.attrib['DGBM8status02'] = '0'
self.attrib['DGBM8status03'] = '0'
self.attrib['DGBM8status04'] = '0'
self.attrib['NietM6status01'] = '0'
self.attrib['NietM6status02'] = '0'
self.attrib['NietM6status03'] = '0'
self.attrib['NietM6status04'] = '0'
self.attrib['NietM6status05'] = '0'
self.attrib['DGBM8M01'] = '0'
self.attrib['DGBM8D01'] = '0'
self.attrib['DGBM8W01'] = '0'
self.attrib['DGBM8T01'] = '0'
self.attrib['DGBM8M02'] = '0'
self.attrib['DGBM8D02'] = '0'
self.attrib['DGBM8W02'] = '0'
self.attrib['DGBM8T02'] = '0'
self.attrib['DGBM8M03'] = '0'
self.attrib['DGBM8D03'] = '0'
self.attrib['DGBM8W03'] = '0'
self.attrib['DGBM8T03'] = '0'
self.attrib['DGBM8M04'] = '0'
self.attrib['DGBM8D04'] = '0'
self.attrib['DGBM8W04'] = '0'
self.attrib['DGBM8T04'] = '0'
self.attrib['NietM6F01'] = '0'
self.attrib['NietM6S01'] = '0'
self.attrib['NietM6F02'] = '0'
self.attrib['NietM6S02'] = '0'
self.attrib['NietM6F03'] = '0'
self.attrib['NietM6S03'] = '0'
self.attrib['NietM6F04'] = '0'
self.attrib['NietM6S04'] = '0'
self.attrib['NietM6F05'] = '0'
self.attrib['NietM6S05'] = '0'
self.attrib['NietM8F01'] = '0'
self.attrib['NietM8S01'] = '0'
self.attrib['NietM8F02'] = '0'
self.attrib['NietM8S02'] = '0'
self.attrib['ladungstraeger'] = ''
self.len = 2220908
return
def identify (self):
"""
This method can be used to identify a TELEGRAM by string.
"""
return "PD05 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))