Files
BDE/STAT_tel.py
2016-10-03 13:32:43 +02:00

83 lines
2.1 KiB
Python
Executable File

#!/usr/bin/python
__author__ = "Michael Rest"
__date__ = "2006/02/15"
__email__ = "michi@rosstein.de"
__version__ = "$Revision: 1.1 $"[11:-2]
from telegram import TELEGRAM, TEL_STAT
# String representation for a DT TPDU
DT_STRING = \
"""\
Length: %d
Number: 0x%02x
Contained Data: %s
"""
def fromstring (data):
"""
Decode the binary representation of a STAT_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_STAT ()
tel.attrib['nr'] = (ord (data [0]) << 8) + ord (data [1])
tel.attrib['src'] = data [2:4]
tel.attrib['dst'] = data [4:6]
tel.attrib['type'] = data [6:10]
tel.attrib['location'] = data [10:14]
tel.attrib['state'] = data [14:16]
tel.attrib['error'] = data [16:len(data)]
return tel
class TEL_STAT (TELEGRAM):
def __init__ (self, nr = 0, src = 'LV', dst = 'TP', loc = '1000', state='00', error = '0000' , *args, **args2):
TELEGRAM.__init__(self)
self.code = TEL_STAT
self.attrib['nr'] = nr
self.attrib['src'] = src
self.attrib['dst'] = dst
self.attrib['type'] = 'STAT'
self.attrib['location'] = loc
self.attrib['state'] = state
self.attrib['error'] = error
self.__recalclen ()
return
def identify (self):
"""
This method can be used to identify a TELEGRAM by string.
"""
return "STAT TELEGRAM\n"
def __recalclen (self):
"""
Return the length of the TPDU. This function is for
internal use only!
"""
self.len = 2 + 4l
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.
"""
print self.attrib
string = self.identify () #+ DT_STRING % (self.len, self.number, self.data)
return string