From: Jannik Zander Date: Sun, 12 Jun 2016 07:55:11 +0000 (+0200) Subject: Request/reply correction X-Git-Url: https://git.zndr.dk/?a=commitdiff_plain;h=0d3581a6215fc56a3ce159d7b272215e7baa7dc4;p=dotfiles.git Request/reply correction --- diff --git a/.local/bin/gf.py b/.local/bin/gf.py index 9afc93f..857b1a5 100755 --- a/.local/bin/gf.py +++ b/.local/bin/gf.py @@ -1,12 +1,16 @@ #!/usr/bin/env python3 +# section: environment {{{1 +##################################################### +import gf_config as gf #import serial import fileinput import matplotlib.pyplot as plt import numpy as pl from datetime import datetime,date,time -from math import modf + +# section: process_timestamp {{{1 ###################################################### def process_timestamp(line): info=line.split(":") @@ -30,9 +34,9 @@ def process_timestamp(line): except: pass print("Timestamp:",ts) - print(line) return ts,line +# section: checkline {{{1 ###################################################### def checkline(line): ok=False @@ -41,11 +45,11 @@ def checkline(line): print("Ok:",ok) return ok +# section: readbyte {{{1 ###################################################### -# read next byte from line def readbyte(line): - byte=256 - while byte==256 and len(line)>0: + byte=-1 + while byte==-1 and len(line)>0: try: byte=int(line[0:2],16) line=line[1:] @@ -55,51 +59,83 @@ def readbyte(line): line=line[2:] return byte,line +# section: process_head {{{1 ###################################################### def process_head(line): - ds,line=readbyte(line) - if ds==0x27: - typ="Data Request" - elif ds==0x26: - typ="Data Message" - elif ds==0x24: - typ="Data Reply" + sd,line=readbyte(line) + if sd==gf.DATA_REQUEST: + typ="DATA_REQUEST --->" + elif sd==gf.DATA_MESSAGE: + typ="DATA_MESSAGE --->" + elif sd==gf.DATA_REPLY: + typ="<--- DATA_REPLY" else: - typ="Data Error" - print("Type:",typ,"DS:",ds) - return typ,ds,0,0,0,line + typ="**** DATA_ERROR ****" + print("Data Type:",typ,"Start Delimiter:",sd) + return typ,sd,0,0,0,line le,line=readbyte(line) da,line=readbyte(line) sa,line=readbyte(line) - if ds==0x27 and da==0xFE: - typ="Connection Request" - if ds==0x27 and da==0xFF: - 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 + if sd==gf.DATA_REQUEST and da==0xFE: + typ="CONNECTION_REQUEST ===>" + if sd==gf.DATA_REQUEST and da==0xFF: + typ="DATA_REQUEST ===>" + if sd==gf.DATA_MESSAGE and da==0xF7: + typ="DATA_MESSAGE ===>" + print(typ) + print("Length:",le,"Destination Addr:",da,"Source Addr:",sa) + return typ,sd,le,da,sa,line +# section: process_apdu {{{1 ###################################################### def process_apdu(line): cl,line=readbyte(line) - cl=cl&0xF + cl=cl&0x1F le,line=readbyte(line) os=(le&0xC0)>>6 le=le&0x3F print("Class:",cl,"Operation:",os,"Length:",le) return cl,os,le,line +# section: process_data {{{1 +###################################################### +def process_data(line,le,size1,size2): + num=int(le/(size1+size2)) + ids=[0]*num + val=[0]*num + for i in range(0,num): + if size1>0: + ids[i],line=readbyte(line) + for j in range(0,size2): + tmp,line=readbyte(line) + val[i]=(val[i]<<8)+tmp + if size1>0 and size2>0: + print("Id:",ids[i], "Value:",val[i]) + elif size1>0: + print("Id:",ids[i]) + elif size2>0: + print("Value:",val[i]) + return ids,val,line + + +# section: process_string {{{1 ###################################################### -def process_class5(line,numid): - id=[0]*numid - val=[0]*numid - for i in range(0,numid): - id[i],line=readbyte(line) +def process_string(line,le): + val=[0]*le + ids,line=readbyte(line) + for i in range(0,le-1): val[i],line=readbyte(line) - print("Id:",id[i],"Value:",val[i]) - return id,val,line + string=''.join(chr(i) for i in val) + print("Id:",ids, "Value:",string) + return ids,string,line + +# section: process_object {{{1 +###################################################### +def process_object(line,le): + return ids,val,line + +# section: process_crc {{{-1 ###################################################### def process_crc(line): crc1,line=readbyte(line) @@ -110,39 +146,168 @@ def process_crc(line): print("CRC:",crc) return crc +# section: process_telegram {{{1 + # section: start {{{2 ###################################################### -def process(line): +def process_telegram(line): global td global master global speed # Check if timestamp exists ts,line=process_timestamp(line) - # Check if line is ok ok=checkline(line) if not ok: return - # Process telegram typ,ds,le,da,sa,line=process_head(line) numbytes=le-2 while numbytes>0 and len(line)>=2*numbytes: cl,os,ale,line=process_apdu(line) numbytes=numbytes-2-ale - if cl==5: - id5,val5,line=process_class5(line,int(ale/2)) + # section: class 2 {{{2 + if cl==2 and ds==gf.DATA_REQUEST and os==gf.OS_GET: + ids2,val2,line=process_data(line,ale,1,0) + elif cl==2 and ds==gf.DATA_REPLY and os==gf.OS_GET: + ids2,val2,line=process_data(line,ale,0,1) + elif cl==2 and ds==gf.DATA_REQUEST and os==gf.OS_INFO: + ids2,val2,line=process_data(line,ale,1,0) + elif cl==2 and ds==gf.DATA_REPLY and os==gf.OS_INFO: + ids2,val2,line=process_data(line,ale,0,4) + # section: class 3 {{{2 + elif cl==3 and (ds==gf.DATA_REQUEST or ds==gf.DATA_MESSAGE) and os==gf.OS_SET: + ids3,val3,line=process_data(line,ale,1,0) + elif cl==3 and ds==gf.DATA_REPLY and os==gf.OS_SET: + ids3,val3,line=process_data(line,ale,0,0) + elif cl==3 and ds==gf.DATA_REQUEST and os==gf.OS_INFO: + ids3,val3,line=process_data(line,ale,1,0) + elif cl==3 and ds==gf.DATA_REPLY and os==gf.OS_INFO: + ids3,val3,line=process_data(line,ale,0,4) + # section: class 4 {{{2 + elif cl==4 and ds==gf.DATA_REQUEST and os==gf.OS_GET: + ids4,val4,line=process_data(line,ale,1,0) + elif cl==4 and ds==gf.DATA_REPLY and os==gf.OS_GET: + ids4,val4,line=process_data(line,ale,0,1) + elif cl==4 and (ds==gf.DATA_REQUEST or ds==gf.DATA_MESSAGE) and os==gf.OS_SET: + ids4,val4,line=process_data(line,ale,1,1) + elif cl==4 and ds==gf.DATA_REPLY and os==gf.OS_SET: + ids4,val4,line=process_data(line,ale,0,0) + elif cl==4 and ds==gf.DATA_REQUEST and os==gf.OS_INFO: + ids4,val4,line=process_data(line,ale,1,0) + elif cl==4 and ds==gf.DATA_REPLY and os==gf.OS_INFO: + ids4,val4,line=process_data(line,ale,0,4) + # section: class 5 {{{2 + elif cl==5 and ds==gf.DATA_REQUEST and os==gf.OS_GET: + ids5,val5,line=process_data(line,ale,1,0) + elif cl==5 and ds==gf.DATA_REPLY and os==gf.OS_GET: + ids5,val5,line=process_data(line,ale,0,1) + elif cl==5 and (ds==gf.DATA_REQUEST or ds==gf.DATA_MESSAGE) and os==gf.OS_SET: + ids5,val5,line=process_data(line,ale,1,1) + elif cl==5 and ds==gf.DATA_REPLY and os==gf.OS_SET: + ids5,val5,line=process_data(line,ale,0,0) + elif cl==5 and ds==gf.DATA_REQUEST and os==gf.OS_INFO: + ids5,val5,line=process_data(line,ale,1,0) + elif cl==5 and ds==gf.DATA_REPLY and os==gf.OS_INFO: + ids5,val5,line=process_data(line,ale,0,4) # Debugging td=td+[ts.timestamp()] master=master+[1+(sa-31)/10] for i in range(4): speed[i]=speed[i]+[val5[i]/254] + # section: class 7 {{{2 +# elif cl==7: +# ids7,val7,line=process_string(line,ale) + # section: class 10 {{{2 +# elif cl==10: +# ids10,val10,line=process_object(line,ale) + # section: class 11 {{{2 + elif cl==11 and ds==gf.DATA_REQUEST and os==gf.OS_GET: + ids11,val11,line=process_data(line,ale,1,0) + elif cl==11 and ds==gf.DATA_REPLY and os==gf.OS_GET: + ids11,val11,line=process_data(line,ale,0,2) + elif cl==11 and (ds==gf.DATA_REQUEST or ds==gf.DATA_MESSAGE) and os==gf.OS_SET: + ids11,val11,line=process_data(line,ale,1,2) + elif cl==11 and ds==gf.DATA_REPLY and os==gf.OS_SET: + ids11,val11,line=process_data(line,ale,0,0) + elif cl==11 and ds==gf.DATA_REQUEST and os==gf.OS_INFO: + ids11,val11,line=process_data(line,ale,1,0) + elif cl==11 and ds==gf.DATA_REPLY and os==gf.OS_INFO: + ids11,val11,line=process_data(line,ale,0,4) + # section: class 12 {{{2 + elif cl==12 and ds==gf.DATA_REQUEST and os==gf.OS_GET: + ids12,val12,line=process_data(line,ale,1,0) + elif cl==12 and ds==gf.DATA_REPLY and os==gf.OS_GET: + ids12,val12,line=process_data(line,ale,0,2) + elif cl==12 and (ds==gf.DATA_REQUEST or ds==gf.DATA_MESSAGE) and os==gf.OS_SET: + ids12,val12,line=process_data(line,ale,1,2) + elif cl==12 and ds==gf.DATA_REPLY and os==gf.OS_SET: + ids12,val12,line=process_data(line,ale,0,0) + elif cl==12 and ds==gf.DATA_REQUEST and os==gf.OS_INFO: + ids12,val12,line=process_data(line,ale,1,0) + elif cl==12 and ds==gf.DATA_REPLY and os==gf.OS_INFO: + ids12,val12,line=process_data(line,ale,0,4) + # section: class 13 {{{2 + elif cl==13 and ds==gf.DATA_REQUEST and os==gf.OS_GET: + ids13,val13,line=process_data(line,ale,1,0) + elif cl==13 and ds==gf.DATA_REPLY and os==gf.OS_GET: + ids13,val13,line=process_data(line,ale,0,2) + elif cl==13 and (ds==gf.DATA_REQUEST or ds==gf.DATA_MESSAGE) and os==gf.OS_SET: + ids13,val13,line=process_data(line,ale,1,2) + elif cl==13 and ds==gf.DATA_REPLY and os==gf.OS_SET: + ids13,val13,line=process_data(line,ale,0,0) + elif cl==13 and ds==gf.DATA_REQUEST and os==gf.OS_INFO: + ids13,val13,line=process_data(line,ale,1,0) + elif cl==13 and ds==gf.DATA_REPLY and os==gf.OS_INFO: + ids13,val13,line=process_data(line,ale,0,4) + # section: class 14 {{{2 + elif cl==14 and ds==gf.DATA_REQUEST and os==gf.OS_GET: + ids14,val14,line=process_data(line,ale,1,0) + elif cl==14 and ds==gf.DATA_REPLY and os==gf.OS_GET: + ids14,val14,line=process_data(line,ale,0,3) + elif cl==14 and (ds==gf.DATA_REQUEST or ds==gf.DATA_MESSAGE) and os==gf.OS_SET: + ids14,val14,line=process_data(line,ale,1,3) + elif cl==14 and ds==gf.DATA_REPLY and os==gf.OS_SET: + ids14,val14,line=process_data(line,ale,0,0) + elif cl==14 and ds==gf.DATA_REQUEST and os==gf.OS_INFO: + ids14,val14,line=process_data(line,ale,1,0) + elif cl==14 and ds==gf.DATA_REPLY and os==gf.OS_INFO: + ids14,val14,line=process_data(line,ale,0,4) + # section: class 15 {{{2 + elif cl==15 and ds==gf.DATA_REQUEST and os==gf.OS_GET: + ids15,val15,line=process_data(line,ale,1,0) + elif cl==15 and ds==gf.DATA_REPLY and os==gf.OS_GET: + ids15,val15,line=process_data(line,ale,0,3) + elif cl==15 and (ds==gf.DATA_REQUEST or ds==gf.DATA_MESSAGE) and os==gf.OS_SET: + ids15,val15,line=process_data(line,ale,1,3) + elif cl==15 and ds==gf.DATA_REPLY and os==gf.OS_SET: + ids15,val15,line=process_data(line,ale,0,0) + elif cl==15 and ds==gf.DATA_REQUEST and os==gf.OS_INFO: + ids15,val15,line=process_data(line,ale,1,0) + elif cl==15 and ds==gf.DATA_REPLY and os==gf.OS_INFO: + ids15,val15,line=process_data(line,ale,0,4) + # section: class 16 {{{2 + elif cl==16 and ds==gf.DATA_REQUEST and os==gf.OS_GET: + ids16,val16,line=process_data(line,ale,1,0) + elif cl==16 and ds==gf.DATA_REPLY and os==gf.OS_GET: + ids16,val16,line=process_data(line,ale,0,3) + elif cl==16 and (ds==gf.DATA_REQUEST or ds==gf.DATA_MESSAGE) and os==gf.OS_SET: + ids16,val16,line=process_data(line,ale,1,3) + elif cl==16 and ds==gf.DATA_REPLY and os==gf.OS_SET: + ids16,val16,line=process_data(line,ale,0,0) + elif cl==16 and ds==gf.DATA_REQUEST and os==gf.OS_INFO: + ids16,val16,line=process_data(line,ale,1,0) + elif cl==16 and ds==gf.DATA_REPLY and os==gf.OS_INFO: + ids16,val16,line=process_data(line,ale,0,4) + # section: end {{{2 else: line=line[ale*3:] crc=process_crc(line) return +# section: logging {{{1 ###################################################### -# Debugging + +# global variable td=[] master=[] speed=[] @@ -153,8 +318,11 @@ speed.append([]) for line in fileinput.input(): print("====================================================================") - print(line) - process(line) +# print(line) + process_telegram(line) + +# section: debugging {{{1 +###################################################### # Calculate timedelta if len(td)==0: exit() diff --git a/.local/bin/gf_config.py b/.local/bin/gf_config.py new file mode 100644 index 0000000..a45bb37 --- /dev/null +++ b/.local/bin/gf_config.py @@ -0,0 +1,13 @@ +# config file for gf.py script + +# section: constants {{{1 +DATA_REQUEST=0x27 +DATA_MESSAGE=0x26 +DATA_REPLY=0x24 +OS_GET=0 +OS_SET=2 +OS_INFO=3 +ACK_OK=0 +ACK_CLASS_UNKNOWN=1 +ACK_ID_UNKNOWN=2 +ACK_OPERATION_UNKNOWN=3 diff --git a/.vimrc b/.vimrc index a2b1763..bb82207 100644 --- a/.vimrc +++ b/.vimrc @@ -34,6 +34,7 @@ Plug 'brandonbloom/csearch.vim' Plug 'chazy/cscope_maps' Plug 'majutsushi/tagbar' "Plug 'airblade/vim-gitgutter' +"Plug 'Lokaltog/powerline',{'rtp': 'powerline/binding/vim/'} Plug 'junegunn/fzf.vim' Plug 'thanthese/Tortoise-Typing' Plug 'altercation/vim-colors-solarized' @@ -61,6 +62,8 @@ setglobal commentstring=#\ %s set complete-=i " searching includes can be slow set clipboard=unnamed set fileformats=unix,dos,mac +"set foldlevel=99 +"set foldmethod=indent set foldmethod=marker set foldopen+=jump set history=200 @@ -166,21 +169,18 @@ endif" " section: mappings {{{1 " ---------------------- +"split navigations +nnoremap +nnoremap +nnoremap +nnoremap +" folding +nnoremap za +"exit insert mode inoremap jj inoremap j j -map -map! -if has("gui_running") - map :fancy -endif -nmap :if &previewwindowpcloseelseif exists(':gstatus')exe 'gstatus'elselsendif -nmap :if exists(':lcd')exe 'lcd'elseif exists(':cd')exe 'cd'elselcd %:hendif -map :make -map :dispatch -map :start map v :so ~/.vimrc - " section: autocommands {{{1 " -------------------------- if has("autocmd")