From 9f32fb1b5f25ce14d40bea73b4a4450558fe515d Mon Sep 17 00:00:00 2001 From: Jannik Zander Date: Fri, 10 Jun 2016 20:14:56 +0200 Subject: [PATCH] Robust gf.py --- .local/bin/genilog.py | 0 .local/bin/gf.py | 69 ++++++++++++++++++++++--------------------- 2 files changed, 35 insertions(+), 34 deletions(-) mode change 100644 => 100755 .local/bin/genilog.py diff --git a/.local/bin/genilog.py b/.local/bin/genilog.py old mode 100644 new mode 100755 diff --git a/.local/bin/gf.py b/.local/bin/gf.py index 7b5b595..bf69c6b 100755 --- a/.local/bin/gf.py +++ b/.local/bin/gf.py @@ -6,8 +6,9 @@ import matplotlib.pyplot as plt import numpy as pl def readbyte(line): - byte=0x100 # invalid - while byte==0x100: + # read next byte in line + byte=256 + while byte==256 and len(line)>0: try: byte=int(line[0:2],16) line=line[1:] @@ -26,7 +27,7 @@ def process_head(line): elif ds==0x24: typ="Data Reply" else: - typ="**********Error**********" + typ="Data Error" print("Type:",typ,"DS:",ds) return typ,ds,0,0,0,line le,line=readbyte(line) @@ -60,18 +61,19 @@ def process_class5(line,numid): return id,val,line def process_crc(line): - #FIXME: does not work in general - crc=line[2:7] - line=line[7:] + crc1,line=readbyte(line) + crc2,line=readbyte(line) + crc1=format(crc1,'02X') + crc2=format(crc2,'02X') + crc=crc1+' '+crc2 print("CRC:",crc) - return crc,line + return crc -def process_isok(line): - isok=False - if "OK" in line.upper(): - isok=True - print("IsCrcOk:",isok) - return isok +def process_islineok(line): + ok=True + if "ERR" in line.upper() or len(line) < 12: + ok=False + return ok def process_timestamp(line): #FIXME: does not work in general @@ -88,34 +90,33 @@ def process(line): global t global speed global master + # Some extra info from logging tool - isok=process_isok(line) + ok=process_islineok(line) + if not ok: return + timestamp=process_timestamp(line) if timezero==0: timezero=timestamp + # Process received data typ,ds,le,da,sa,line=process_head(line) numbytes=le-2 - print("head",numbytes) - if da==0xF7: - while numbytes>0: - cl,os,ale,line=process_apdu(line) - numbytes=numbytes-2 - print("apdu",numbytes) - if cl==5: - id,val,line=process_class5(line,int(ale/2)) - numbytes=numbytes-ale - print("cl5",numbytes) - # Debugging info.... - t=t+[(timestamp-timezero)/1000] - master=master+[1+(sa-31)/10] - for i in range(4): - speed[i]=speed[i]+[val[i]/254] - else: - line=line[ale*3:] - numbytes=numbytes-ale - print("clxxx",numbytes) - crc=process_crc(line) + while numbytes>0: + cl,os,ale,line=process_apdu(line) + numbytes=numbytes-2 + if cl==5: + id,val,line=process_class5(line,int(ale/2)) + numbytes=numbytes-ale + # Debugging info.... + master=master+[1+(sa-31)/10] + t=t+[(timestamp-timezero)/1000] + for i in range(4): + speed[i]=speed[i]+[val[i]/254] + else: + line=line[ale*3:] + numbytes=numbytes-ale + crc=process_crc(line) return timezero=0 -- 2.43.0