From c0e21b06f657135f3ffe1d647130419a70e530db Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Fri, 17 Oct 2014 19:39:09 +0200 Subject: Fix EDI analysis RS check --- edi/edidebug.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'edi/edidebug.py') diff --git a/edi/edidebug.py b/edi/edidebug.py index c27a374..ab61ab7 100755 --- a/edi/edidebug.py +++ b/edi/edidebug.py @@ -234,23 +234,38 @@ def get_rs_decoder(chunk_size, zeropad): # p.hexpr(" ZE CHUNK DATA", c[0]); # p.hexpr(" ZE CHUNK PROT", c[1]); - rs_codec = RSCodec(48) + rs_codec = RSCodec(48, fcr=1) + protection_ok = True for chunk, protection in rs_chunks: - p.pr(" Protection") + #p.pr(" Protection") #p.hexpr(" OF ZE CHUNK DATA", chunk); - recalc_protection = rs_codec.encode(bytearray(chunk))[-48:] - if (protection != recalc_protection): + + bchunk = bytearray(chunk) + padbytes = 255-(48 + len(chunk)) + bchunk = bchunk + bytearray(0 for i in range(padbytes)) + recalc_protection = rs_codec.encode(bchunk)[-48:] + if protection != recalc_protection: p.pr(" PROTECTION ERROR") p.hexpr(" orig", protection) p.hexpr(" calc", recalc_protection) + protection_ok = False + else: + p.pr(" PROTECTION OK") + + if protection_ok: + p.pr("Protection check: OK") + afpacket = "".join(data for (data, protection) in rs_chunks) #p.hexpr(" ZE AF PACKET", afpacket) - return decode_af(afpacket[0:-zeropad]) + if zeropad: + return decode_af(afpacket[0:-zeropad]) + else: + return decode_af(afpacket) return decode_rs @@ -268,6 +283,9 @@ def decode_af(in_data, is_stream=False): else: headerdata = in_data[:10] + if len(headerdata) != 10: + p.hexpr("AF Header", headerdata) + sync, plen, seq, ar, pt = struct.unpack(af_head_struct, headerdata) if sync != "AF": -- cgit v1.2.3