Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding length to PrintMessage and get data as dictionary #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion py8583/py8583.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def __init__(self,IsoMsg = None, IsoSpec = None):

self.__Bitmap = {}
self.__FieldData = {}
self.__FieldLen = {}
self.__iso = b''

if(IsoSpec != None):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -451,6 +454,34 @@ 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)

for i in sorted(self.__Bitmap.keys()):
if(i == 1):
continue
Expand All @@ -464,4 +495,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
4 changes: 2 additions & 2 deletions py8583/py8583spec.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from py8583.py8583 import DT, LT, SpecError
from py8583 import DT, LT, SpecError



Expand Down Expand Up @@ -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 }
}
}