]> git.zndr.dk Git - dotfiles.git/commitdiff
Minor update
authorJannik ZANDER <jzander@grundfos.com>
Mon, 13 Jun 2016 11:28:05 +0000 (13:28 +0200)
committerJannik ZANDER <jzander@grundfos.com>
Mon, 13 Jun 2016 11:28:05 +0000 (13:28 +0200)
.local/bin/gf.py

index a3368edc56e466df79609374e61ae694a8cd6367..bb907967e1e16a9e4fae0cfc3fb644324682e268 100755 (executable)
@@ -10,9 +10,40 @@ import numpy as pl
 from datetime import datetime,date,time
 
 
-# section: process_timestamp {{{1
+# section: debugging {{{1
+######################################################
+
+# global variable
+td=[]
+master=[]
+speed=[]
+speed.append([])
+speed.append([])
+speed.append([])
+speed.append([])
+
+def dbg_speed(ids5,val5,ts,sa):
+  global td
+  global master
+  global speed
+  td=td+[ts.timestamp()]
+  master=master+[1+(sa-31)/10]
+  for i in range(4):
+    speed[i]=speed[i]+[val5[i]/254]
+  return td,master,speed
+
+# section: checkline {{{1
+######################################################
+def checkline(line):
+  ok=False
+  if len(line)>16 and not "ERR" in line.upper():
+    ok=True
+#  print("Ok:",ok)
+  return ok
+
+# section: readtimestamp {{{1
 ######################################################
-def process_timestamp(line):
+def readtimestamp(line):
   info=line.split(":")
   try:
     timestamp=int(info[1].strip())/1000
@@ -33,18 +64,9 @@ def process_timestamp(line):
       line=s[1][4:]
     except:
       pass
-  print("Timestamp:",ts)
+  print(ts)
   return ts,line
 
-# section: checkline {{{1
-######################################################
-def checkline(line):
-  ok=False
-  if len(line)>16 and not "ERR" in line.upper():
-    ok=True
-  print("Ok:",ok)
-  return ok
-
 # section: readbyte {{{1
 ######################################################
 def readbyte(line):
@@ -59,9 +81,9 @@ def readbyte(line):
       line=line[2:]
   return byte,line
 
-# section: process_head {{{1
+# section: process_header {{{1
 ######################################################
-def process_head(line):
+def process_header(line):
   sd,line=readbyte(line)
   if sd==gf.DATA_REQUEST:
     typ="DATA_REQUEST --->"
@@ -153,7 +175,7 @@ def process_object(line,le,size1,size2):
     print("Value:",val)
   return ids,val,line
 
-# section: process_crc {{{-1
+# section: process_crc {{{1
 ######################################################
 def process_crc(line):
   crc1,line=readbyte(line)
@@ -161,29 +183,26 @@ def process_crc(line):
   crc1=format(crc1,'02X')
   crc2=format(crc2,'02X')
   crc=crc1+' '+crc2
-  print("CRC:",crc)
+#  print("CRC:",crc)
   return crc
 
 # section: process_telegram {{{1
-  # section: start {{{2
 ######################################################
 def process_telegram(line):
-  global td
-  global master
-  global speed
-
+  # section: headers {{{2
   # Check if timestamp exists
-  ts,line=process_timestamp(line)
+  ts,line=readtimestamp(line)
   # Check if line is ok
   ok=checkline(line)
   if not ok: return
   # Process telegram
-  typ,ds,le,da,sa,line=process_head(line)
+  typ,ds,le,da,sa,line=process_header(line)
   numbytes=le-2
   while numbytes>0 and len(line)>=2*numbytes:
+    print("--------------------------------------------------------------------")
     cl,os,ale,line=process_apdu(line)
     numbytes=numbytes-2-ale
-    # section: class 2 {{{2
+    # section: data {{{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:
@@ -192,14 +211,12 @@ def process_telegram(line):
       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_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:
@@ -210,7 +227,6 @@ def process_telegram(line):
       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:
@@ -221,26 +237,18 @@ def process_telegram(line):
       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 and ds==gf.DATA_REQUEST and os==gf.OS_GET:
       ids7,val7,line=process_string(line,ale,1,0)
     elif cl==7 and ds==gf.DATA_REPLY and os==gf.OS_GET:
       ids7,val7,line=process_string(line,ale,0,ale)
     elif cl==7 and (ds==gf.DATA_REQUEST or ds==gf.DATA_MESSAGE) and os==gf.OS_SET:
       ids7,val7,line=process_string(line,ale,1,ale-1)
-    # section: class 10 {{{2
     elif cl==10 and ds==gf.DATA_REQUEST and os==gf.OS_GET:
       ids10,val10,line=process_object(line,ale,1,0)
     elif cl==10 and ds==gf.DATA_REPLY and os==gf.OS_GET:
       ids10,val10,line=process_object(line,ale,0,ale)
     elif cl==10 and (ds==gf.DATA_REQUEST or ds==gf.DATA_MESSAGE) and os==gf.OS_SET:
       ids10,val10,line=process_object(line,ale,1,ale-1)
-    # 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:
@@ -251,7 +259,6 @@ def process_telegram(line):
       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:
@@ -262,7 +269,6 @@ def process_telegram(line):
       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:
@@ -273,7 +279,6 @@ def process_telegram(line):
       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:
@@ -284,7 +289,6 @@ def process_telegram(line):
       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:
@@ -295,7 +299,6 @@ def process_telegram(line):
       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:
@@ -306,30 +309,22 @@ def process_telegram(line):
       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:]
+# section: filtering {{{2
+    if cl==5:
+      td,master,speed=dbg_speed(ids5,val5,ts,sa)
   crc=process_crc(line)
   return
 
-# section: logging {{{1
+# section: main {{{1
 ######################################################
-
-# global variable
-td=[]
-master=[]
-speed=[]
-speed.append([])
-speed.append([])
-speed.append([])
-speed.append([])
-
 for line in fileinput.input():
   print("====================================================================")
 #  print(line)
   process_telegram(line)
 
-# section: debugging {{{1
+# section: plotting {{{1
 ######################################################
 
 # Calculate timedelta
@@ -350,3 +345,4 @@ plt.plot(td,master,'black')
 plt.title('multipump')
 plt.show()
 plt.close(fig)
+