From 910cc1e8688de8b4e6609fe980da6c34e19f00a3 Mon Sep 17 00:00:00 2001 From: Jannik ZANDER Date: Fri, 10 Jun 2016 09:40:48 +0200 Subject: [PATCH] Keep old stable genilog.py --- .config/bash/rc/aliases | 11 ++++ .local/bin/genilog.py | 119 ++++++++++++++++++++++++++++++++++++++++ .local/bin/gf.py | 8 ++- 3 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 .local/bin/genilog.py diff --git a/.config/bash/rc/aliases b/.config/bash/rc/aliases index dad1717..be4f9c9 100644 --- a/.config/bash/rc/aliases +++ b/.config/bash/rc/aliases @@ -92,3 +92,14 @@ alias startvnc='vncserver -geometry 1870x980 -depth 24' alias startvnc4='vnc4server -geometry 1870x980 -depth 24' #alias python='/usr/local/bin/python3' alias git_local='git --git-dir=.git_local' + +# alias for genibus +alias gf='gf.py' +alias com1='GENIsnus_1_lin_pr_tgm.exe COM1 9600 log 5' +alias com2='GENIsnus_1_lin_pr_tgm.exe COM2 9600 log 5' +alias com3='GENIsnus_1_lin_pr_tgm.exe COM3 9600 log 5' +alias com4='GENIsnus_1_lin_pr_tgm.exe COM4 9600 log 5' +alias com5='GENIsnus_1_lin_pr_tgm.exe COM5 9600 log 5' +alias com6='GENIsnus_1_lin_pr_tgm.exe COM6 9600 log 5' +alias com7='GENIsnus_1_lin_pr_tgm.exe COM7 9600 log 5' +alias com8='GENIsnus_1_lin_pr_tgm.exe COM8 9600 log 5' diff --git a/.local/bin/genilog.py b/.local/bin/genilog.py new file mode 100644 index 0000000..cb32c1a --- /dev/null +++ b/.local/bin/genilog.py @@ -0,0 +1,119 @@ +#!/usr/bin/env python3 + +#import serial +import fileinput +import matplotlib.pyplot as plt +import numpy as pl + +def readbyte(line): + str=line[0:2].strip() + byte=0 + if str!='': + byte=int(str,16) + tail=line[2:].strip() + return byte,tail + +def process_head(line): + ds,line=readbyte(line) + le,line=readbyte(line) + da,line=readbyte(line) + sa,line=readbyte(line) + typ="Error" + if ds==0x27: typ="Data Request" + if ds==0x27 and da==0xFE: typ="Connection Request" + if ds==0x27 and da==0xFF: typ="Broadcast Request" + if ds==0x26: typ="Data Message" + if ds==0x26 and da==0xF7: typ="Multicast Message" + if ds==0x24: typ="Data Reply" + return ds,le,da,sa,typ + +def process_pdu(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 + +def process_crc(line): + crc=line + return crc + +def process_isok(line): + isok=line + return line + +def process_timestamp(line): + timestamp=int(line) + return timestamp + +def process(line): + global timezero + global t + global ref + line=line[2:] + packet=line.split(" - ") + n=len(packet) + if n>0: + print("Header:",packet[0]) + ds,le,da,sa,typ=process_head(packet[0]) + print("Type:",typ,"Length",le,"Destination",da,"Source",sa) + if da==0xF7: + if n>1: + print("Payload:",packet[1]) + pdu=packet[1] + while len(pdu)>0: + cl,os,ale,apdu,pdu=process_pdu(pdu) + print("Class:",cl,"Operation:",os,"Length:",ale,"APDU:",apdu) + if cl==5: + id=[0]*4 + ref=[0]*4 + id[0],apdu=readbyte(apdu) + ref[0],apdu=readbyte(apdu) + id[1],apdu=readbyte(apdu) + ref[1],apdu=readbyte(apdu) + id[2],apdu=readbyte(apdu) + ref[2],apdu=readbyte(apdu) + id[3],apdu=readbyte(apdu) + ref[3],apdu=readbyte(apdu) + for i in range(0,4): + print("Id:",id[i],"Ref:",ref[i]) + if n>2: + crc=process_crc(packet[2]) + if n>3: + info=packet[3].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] +# ref[0].append([ref1[0]]) +# ref[1].append([ref1[1]]) +# ref[2].append([ref1[2]]) +# ref[3].append([ref1[3]]) + return + +timezero=0 +t=[] +ref=[] +ref.append([]) +ref.append([]) +ref.append([]) +ref.append([]) +for line in fileinput.input(): + process(line) + print("------------------------------------------------") + +fig=plt.figure() +plt.plot(t,ref[0]) +plt.plot(t,ref[1]) +plt.plot(t,ref[2]) +plt.plot(t,ref[3]) +plt.show() +plt.close(fig) + diff --git a/.local/bin/gf.py b/.local/bin/gf.py index 44090af..7b5b595 100755 --- a/.local/bin/gf.py +++ b/.local/bin/gf.py @@ -77,7 +77,7 @@ def process_timestamp(line): #FIXME: does not work in general info=line.split(":") try: - timestamp=int(info[1].strip())/1000 + timestamp=int(info[1].strip()) print(timestamp) return timestamp except: @@ -96,21 +96,25 @@ def process(line): # 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] + 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) return -- 2.43.0