From 58a0a9f57efede165ca2473abb43703f6f2934bd Mon Sep 17 00:00:00 2001 From: Luis Aguirre Date: Thu, 17 Nov 2016 12:21:51 -0300 Subject: [PATCH 1/3] Fixing error importing IsoSpec1987BCD --- py8583/py8583spec.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/py8583/py8583spec.py b/py8583/py8583spec.py index 2ef1d7a..e626792 100644 --- a/py8583/py8583spec.py +++ b/py8583/py8583spec.py @@ -1,4 +1,4 @@ -from py8583.py8583 import DT, LT, SpecError +from py8583 import DT, LT, SpecError @@ -377,4 +377,4 @@ def SetDataTypes(self): 126 : { 'ContentType' : 'ans', 'MaxLen' : 999, 'LenType': LT.LLLVAR }, 127 : { 'ContentType' : 'ans', 'MaxLen' : 999, 'LenType': LT.LLLVAR }, 128 : { 'ContentType' : 'b', 'MaxLen' : 8, 'LenType': LT.FIXED } -} \ No newline at end of file +} From c5152d40e9569a0728b48ecd65bb4411faf46b8a Mon Sep 17 00:00:00 2001 From: Luis Aguirre Date: Fri, 18 Nov 2016 11:46:22 -0300 Subject: [PATCH 2/3] Adding length to PrintMessage and adding DictMessage to get a dictionary with iso data --- py8583/py8583.py | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/py8583/py8583.py b/py8583/py8583.py index 9c94533..9d8f179 100644 --- a/py8583/py8583.py +++ b/py8583/py8583.py @@ -84,6 +84,7 @@ def __init__(self,IsoMsg = None, IsoSpec = None): self.__Bitmap = {} self.__FieldData = {} + self.__FieldLen = {} self.__iso = b'' if(IsoSpec != None): @@ -208,6 +209,8 @@ def ParseField(self, field, p): if(Len > MaxLength): raise ParseError("F{0} is larger than maximum length ({1}>{2})".format(field, Len, MaxLength)) + + self.__FieldLen[field] = Len # In case of zero length, don't try to parse the field itself, just continue if(Len == 0): @@ -451,6 +454,36 @@ def PrintMessage(self): print(bitmapLine) + for i in sorted(self.__Bitmap.keys()): + if(i == 1): + continue + if(self.__Bitmap[i] == 1): + + try: + FieldData = self.__FieldData[i] + except KeyError: + FieldData = '' + + if(self.ContentType(i) == 'n' and self.__IsoSpec.LengthType(i) == LT.FIXED): + FieldData = str(FieldData).zfill(self.__IsoSpec.MaxLength(i)) + + Len = self.__FieldLen[i] + print("\t{0:>3d} - {1: <41} :({2:>3d}) [{3}]".format(i, self.__IsoSpec.Description(i), Len, FieldData)) + + def DictMessage(self): + dict_msg = {} + + dict_msg['mti'] = "{0}".format(self.__MTI) + dict_msg['bitmap'] = [] + + for i in sorted(self.__Bitmap.keys()): + if(i == 1): + continue + if(self.__Bitmap[i] == 1): + dict_msg['bitmap'].append(i) + + dict_msg['bitmap_string'] = ''.join(["F{0:>03d}".format(f) for f in dict_msg['bitmap']]) + for i in sorted(self.__Bitmap.keys()): if(i == 1): continue @@ -464,4 +497,8 @@ def PrintMessage(self): if(self.ContentType(i) == 'n' and self.__IsoSpec.LengthType(i) == LT.FIXED): FieldData = str(FieldData).zfill(self.__IsoSpec.MaxLength(i)) - print("\t{0:>3d} - {1: <41} : [{2}]".format(i, self.__IsoSpec.Description(i), FieldData)) + Len = self.__FieldLen[i] + + dict_msg["F{0:>03d}".format(i)] = {'data': FieldData, 'length': Len} + + return dict_msg From 1a18f37c21d71ffc8a2b164eb22670b1358f29d9 Mon Sep 17 00:00:00 2001 From: Luis Aguirre Date: Fri, 18 Nov 2016 14:35:43 -0300 Subject: [PATCH 3/3] Field bitmap_string is noy useful in all cases --- py8583/py8583.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/py8583/py8583.py b/py8583/py8583.py index 9d8f179..7bde635 100644 --- a/py8583/py8583.py +++ b/py8583/py8583.py @@ -482,8 +482,6 @@ def DictMessage(self): if(self.__Bitmap[i] == 1): dict_msg['bitmap'].append(i) - dict_msg['bitmap_string'] = ''.join(["F{0:>03d}".format(f) for f in dict_msg['bitmap']]) - for i in sorted(self.__Bitmap.keys()): if(i == 1): continue