From 7cd495931a52ac6e9efe0593a40f638a994c6e39 Mon Sep 17 00:00:00 2001 From: Jannik Zander Date: Fri, 10 Jun 2016 00:05:32 +0200 Subject: [PATCH] Rename genilog.py to gf.py --- .local/bin/{genilog.py => gf.py} | 72 +++++++++++++++++--------------- 1 file changed, 38 insertions(+), 34 deletions(-) rename .local/bin/{genilog.py => gf.py} (65%) diff --git a/.local/bin/genilog.py b/.local/bin/gf.py similarity index 65% rename from .local/bin/genilog.py rename to .local/bin/gf.py index 31352c3..59a424d 100755 --- a/.local/bin/genilog.py +++ b/.local/bin/gf.py @@ -11,7 +11,7 @@ def readbyte(line): try: byte=int(line[0:2],16) line=line[1:] - except ValueError: + except: pass finally: line=line[2:] @@ -27,6 +27,7 @@ def process_head(line): typ="Data Reply" else: typ="**********Error**********" + print("Type:",typ,"DS:",ds) return typ,ds,0,0,0,line le,line=readbyte(line) da,line=readbyte(line) @@ -37,17 +38,17 @@ def process_head(line): typ="Broadcast Request" if ds==0x26 and da==0xF7: typ="Multicast Message" + print("Type:",typ,"Length:",le,"Destination:",da,"Source:",sa) return typ,ds,le,da,sa,line -def process_pdu(line): +def process_apdu(line): cl,line=readbyte(line) cl=cl&0xF le,line=readbyte(line) os=(le&0xC0)>>6 le=le&0x3F - apdu=line[0:3*le] - line=line[3*le:] - return cl,os,le,apdu,line + print("Class:",cl,"Operation:",os,"Length:",le) + return cl,os,le,line def process_class5(line,numid): id=[0]*numid @@ -55,24 +56,32 @@ def process_class5(line,numid): for i in range(0,numid): id[i],line=readbyte(line) val[i],line=readbyte(line) - print("Id:",id[i],"Val:",val[i]) + print("Id:",id[i],"Value:",val[i]) return id,val,line def process_crc(line): #FIXME: does not work in general crc=line[2:7] line=line[7:] + print("CRC:",crc) return crc,line def process_isok(line): - #FIXME: does not work in general - isok=line - return line + isok=False + if "OK" in line.upper(): + isok=True + print("IsCrcOk:",isok) + return isok def process_timestamp(line): #FIXME: does not work in general - timestamp=int(line)/1000 - return timestamp + info=line.split(":") + try: + timestamp=int(info[1].strip())/1000 + print(timestamp) + return timestamp + except: + return 0 def process(line): global timezero @@ -80,32 +89,27 @@ def process(line): global speed global master + # Some extra info from logging tool + isok=process_isok(line) + timestamp=process_timestamp(line) + if timezero==0: + timezero=timestamp + # Process received data typ,ds,le,da,sa,line=process_head(line) - print("Type:",typ,"Length:",le,"Destination:",da,"Source:",sa) if da==0xF7: numbytes=le-2 while numbytes>0: - cl,os,ale,apdu,line=process_pdu(line) + cl,os,ale,line=process_apdu(line) numbytes=numbytes-2-ale - print("Class:",cl,"Operation:",os,"Length:",ale,"APDU:",apdu) if cl==5: - id,val,apdu=process_class5(apdu,int(ale/2)) - crc,line=process_crc(line) - print(crc) - info=line.split(" : ") - m=len(info) - if m>0: - isok=process_isok(info[0]) - if m>1: - timestamp=process_timestamp(info[1].strip()) - if timezero==0: - timezero=timestamp - t=t+[timestamp-timezero] - master=master+[1+(sa-31)/10] - speed[0]=speed[0]+[val[0]/254] - speed[1]=speed[1]+[val[1]/254] - speed[2]=speed[2]+[val[2]/254] - speed[3]=speed[3]+[val[3]/254] + id,val,line=process_class5(line,int(ale/2)) + t=t+[timestamp-timezero] + master=master+[1+(sa-31)/10] + for i in range(4): + speed[i]=speed[i]+[val[i]/254] + else: + line=line[ale*3:] + crc=process_crc(line) return timezero=0 @@ -118,9 +122,10 @@ speed.append([]) speed.append([]) for line in fileinput.input(): + print("====================================================================") + print(line) + print("--------------------------------------------------------------------") process(line) - print("------------------------------------------------") - fig=plt.figure() plt.xlabel('time/s') plt.ylabel('speed/upper') @@ -133,4 +138,3 @@ plt.plot(t,master,'black') plt.title('multipump') plt.show() plt.close(fig) - -- 2.43.0