Files
BDE/telegram.py

89 lines
2.1 KiB
Python

#!/usr/bin/python
__author__ = "Michael Rest"
__date__ = "2016/09/01"
__email__ = "mr@mir.systems"
__version__ = "$Revision: 1.1 $"[11:-2]
# Packet types
TEL_PD01 = 0x1 # Messzelle 1
TEL_PD02 = 0x2 # Entgratzelle 1
TEL_PD03 = 0x3 # Entgratzelle 2
TEL_PD04 = 0x4 # Beladezelle BAZ
TEL_PD05 = 0x5 # Blindniet
TEL_PD06 = 0x6 # Bajonettclips
TEL_PD07 = 0x7 # Metallclips
TEL_PD08 = 0x8 # Masseblech
TEL_PD09 = 0x9 # Nacharbeit
TEL_PD10 = 0xa # Messzelle2
TEL_PD20 = 0xa # Messzelle Fill
TEL_PD30 = 0xa # Handarbeit
TEL_PD98 = 0xb # TestSPS
TEL_PD99 = 0xc # Zentrale
TEL_SCLS = 0xd #
TEL_STAT = 0xe #
TEL_QUIT = 0xf #
TEL_DM09 = 0x01 # Nacharbeit
TEL_DM01 = 0x02 # DMC Messzelle 1
TEL_DM20 = 0x0a # DMC Messzelle Finn
TEL_DM30 = 0x0a # DMC Handarbeit
#Helper
def tsdecode (data):
"""
Zeitstempel
"""
return '%s-%s-%s %s:%s:%s' % (data [0:4], data [4:6], data[6:8], data[8:10], data[10:12], data[12:14])
class TELEGRAM:
def __init__ (self):
self.len = 0
self.code = 0
self.attrib = {'src': ' ', 'dst': ' ', 'type': 'NONE', 'check' : 0}
def type (self):
"""
Return type hexadecimal type of the TELEGRAM. This function is
common for all.
"""
return self.code
def __len__ (self):
"""
Return the calcuclated length of the TELEGRAM. The value is
always WITHOUT the coded type, add 1 to it if in doubt.
"""
return self.len
def __getitem__ (self, key):
"""
Return Attrib
"""
return self.attrib[key]
def has_key (self, key):
"""
Check for Key
"""
return key in self.attrib
def __repr__ (self):
"""
Print a representation of the TELEGRAM. 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" % (2, self.code << 4, self.number)
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.
"""
string = DT_STRING % (self.len, self.number, self.data)
return string