From fea3900da11d035ac6fc803fa28f46ddcc3cf430 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Fri, 6 Mar 2020 18:37:43 +0000 Subject: [PATCH] add field decoder --- src/decoder/power_fields.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/src/decoder/power_fields.py b/src/decoder/power_fields.py index 1c622944..345dce50 100644 --- a/src/decoder/power_fields.py +++ b/src/decoder/power_fields.py @@ -16,17 +16,40 @@ def decode_fields(): if not reading_data: assert l[0] == '#' heading = l[1:].strip() - if heading.startswith('1.6.28'): # skip instruction fields for now - break + #if heading.startswith('1.6.28'): # skip instruction fields for now + #break heading = heading.split(' ')[-1] print ("heading", heading) reading_data = True forms[heading] = [] res = {} + inst = None + for hdr, form in forms.items(): print ("heading", hdr) - res[hdr] = decode_form(form) + if heading == 'Fields': + inst = decode_instructions(form) + #else: + # res[hdr] = decode_form(form) + return res, inst + +def decode_instructions(form): + res = {} + accum = [] + for l in form: + if l.strip().startswith("Formats"): + l = l.strip().split(":")[-1] + l = l.replace(" ", "") + l = l.split(",") + for fmt in l: + if fmt not in res: + res[fmt] = [accum[0]] + else: + res[fmt].append(accum[0]) + accum = [] + else: + accum.append(l.strip()) return res def decode_form_header(hdr): @@ -96,7 +119,7 @@ def decode_form(form): if __name__ == '__main__': - forms = decode_fields() + forms, instrs = decode_fields() for hdr, form in forms.items(): print () print (hdr) @@ -104,3 +127,5 @@ if __name__ == '__main__': #print ("line", l) #for k, v in l.items(): print ("%s: %d-%d" % (k, v[0], v[1])) + for form, field in instrs.items(): + print (form, field) -- 2.30.2