]> git.zndr.dk Git - dotfiles.git/commitdiff
Fix for more timestamps
authorJannik ZANDER <jzander@grundfos.com>
Tue, 14 Jun 2016 18:33:59 +0000 (20:33 +0200)
committerJannik ZANDER <jzander@grundfos.com>
Tue, 14 Jun 2016 18:33:59 +0000 (20:33 +0200)
.local/bin/gf.py
.local/bin/gf_config.py

index 2fd711c7d3d41f93a5971abb3af860b734883f81..cce7fb96147cf8c7b6ccbfdddd0c87f2d02756c9 100755 (executable)
@@ -58,27 +58,14 @@ def readtimestamp(line):
     line=info[0]
   else:
     try:
-      h=int(info[0].split(' ')[1])
+      h=int(info[0][-2:])
       m=int(info[1])
-      s=info[2].split('.')
-      ts=datetime.combine(date.today(),time(h,m,int(s[0]),int(s[1])*1000))
-      line=info[3][1:]
+      s=int(info[2][:2])
+      u=int(info[2][3:6])*1000
+      ts=datetime.combine(date.today(),time(h,m,s,u))
+      line=''.join(line.split(":")[2:])[7:]
     except:
       pass
-
-# if timestamp>1e9: # 2001-09-09
-#   pass
-# else:
-#   try:
-#     h=int(info[0].split(' ')[1])
-#     m=int(info[1])
-#     s=info[2].split('.')
-#     u=s[1].split(' ')
-#     ts=datetime.combine(date.today(),time(h,m,int(s[0]),int(u[0])*1000))
-#     line=s[1][4:]
-#   except:
-#     pass
-#
   print(ts)
   return ts,line
 
@@ -86,6 +73,7 @@ def readtimestamp(line):
 ######################################################
 def readbyte(line):
   byte=-1
+  line=line.strip()
   while byte==-1 and len(line)>0:
     try:
       byte=int(line[0:2],16)
@@ -131,7 +119,7 @@ def process_apdu(line):
   le,line=readbyte(line)
   os=(le&0xC0)>>6
   le=le&0x3F
-  print("Class:",cl,"Operation:",os,"Length:",le)
+  print(gf.operation[os],"Class:",cl,"Length:",le)
   return cl,os,le,line
 
 # section: process_data {{{1
@@ -147,15 +135,9 @@ def process_data(line,le,size1,size2):
       tmp,line=readbyte(line)
       val[i]=(val[i]<<8)+tmp
     if size1>0 and size2>0:
-      if gf.params[cl][ids[i]] != "":
-        print(gf.params[cl][ids[i]],"=",val[i])
-      else:
-        print("Id:",ids[i],"=",val[i])
+        print("Id:",ids[i],repr(gf.params[cl][ids[i]]),"=",val[i])
     elif size1>0:
-      if gf.params[cl][ids[i]] != "":
-        print(gf.params[cl][ids[i]])
-      else:
-        print("Id:",ids[i])
+        print("Id:",ids[i],repr(gf.params[cl][ids[i]]))
     elif size2>0:
       print("=",val[i])
   return ids,val,line
index 225aedb59684e060a2ec409bb4e011ba3ed6aa6a..e48b60a788f76e1716c8acdb8e05d5593d13579e 100644 (file)
@@ -5,13 +5,24 @@
 DATA_REQUEST=0x27
 DATA_MESSAGE=0x26
 DATA_REPLY=0x24
+
 OS_GET=0
 OS_SET=2
 OS_INFO=3
+operation=[""]*4
+operation[OS_GET]="GET"
+operation[OS_SET]="SET"
+operation[OS_INFO]="INFO"
+
 ACK_OK=0
-ACK_CLASS_UNKNOWN=1
+ACK_CL_UNKNOWN=1
 ACK_ID_UNKNOWN=2
-ACK_OPERATION_UNKNOWN=3
+ACK_OP_UNKNOWN=3
+ack=[""]*4
+ack[ACK_OK]="ACK_OK"
+ack[ACK_CL_UNKNOWN]="ACK_CLASS_UNKNOWN"
+ack[ACK_ID_UNKNOWN]="ACK_ID_UNKNOWN"
+ack[ACK_OP_UNKNOWN]="ACK_OPERATION_UNKNOWN"
 
 class0=[""]*4
 class1=[]