Sfoglia il codice sorgente

updating fare media device scripts

* took out calls to 'debug_msg' and now they log to their respective log
  files without the extra cruft of the IPC messaging format
* settled on 'epoch_tim_s: fare_credential' format
* all messages less that 'PIPE_BUF' (4096?) should be atomic writes, so
  we can monitor all three log files, along with their timestamps,
  to figure out which credentials are being presented (at least for an
  initial version)
clementinecomputing 4 anni fa
parent
commit
76215a0edc

+ 5 - 1
busunit-PIU/scripts/capture-mag-hid

@@ -20,6 +20,8 @@
 
 import os, sys, evdev, asyncio, os.path
 from evdev import InputDevice, categorize, ecodes
+import time
+import datetime
 
 VERBOSE_LEVEL = 0
 
@@ -136,7 +138,9 @@ for event in dev.read_loop():
       ch = code_ascii_map(event.code, kb_shift_state)
 
       if (ch == '\n'):
-        print(buf)
+        #sys.stdout.write( str(datetime.datetime.now()) + ": " + str(buf) + "\n")
+        sys.stdout.write( str(int(time.time())) + ": " + str(buf) + "\n")
+        #print(buf)
         sys.stdout.flush()
         buf = ""
       else:

+ 3 - 1
busunit-PIU/scripts/magstripe_manager

@@ -26,6 +26,8 @@
 BASEDIR=/home/bus
 
 stdbuf -eL -oL $BASEDIR/bin/capture-mag-hid | \
-  xargs -n1 -I{} bash -c " $BASEDIR/bin/format_debug_msg.py TOKEN_MAG '{}' | $BASEDIR/bin/debug_client -s " | \
   tee -a /tmp/mag.log
 
+#  xargs -n1 -I{} bash -c " $BASEDIR/bin/format_debug_msg.py TOKEN_MAG '{}' | $BASEDIR/bin/debug_client -s " | \
+#  tee -a /tmp/mag.log
+

+ 23 - 2
busunit-PIU/scripts/qr_cam_filter

@@ -28,6 +28,9 @@ import datetime
 import imutils
 import time
 
+RATE_LIMIT_MS = 1500.0
+LAST_TOK = ""
+
 out_type = "stdout"
 #out_type = "x11"
 
@@ -44,6 +47,9 @@ cap = cv2.VideoCapture(0)
 cap.set(cv2.CAP_PROP_FRAME_WIDTH, 320)
 cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 240)
 
+t_prv = time.time()*1000.0
+t_now = t_prv
+
 while True:
   ret, frame = cap.read()
 
@@ -65,8 +71,23 @@ while True:
     cv2.putText(frame, show_text, (x, y - 10),
       cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
 
-    barcode_ofp.write( str(datetime.datetime.now()) + ": " + barcode_data + "\n")
-    barcode_ofp.flush()
+    #barcode_ofp.write( str(datetime.datetime.now()) + ": " + barcode_data + "\n")
+
+    t_now = time.time()*1000.0
+
+    if LAST_TOK != barcode_data:
+      barcode_ofp.write( str(int(time.time())) + ": " + barcode_data + "\n")
+      barcode_ofp.flush()
+      t_prv = t_now
+      LAST_TOK = barcode_data
+    elif (t_now - t_prv) >= RATE_LIMIT_MS:
+      barcode_ofp.write( str(int(time.time())) + ": " + barcode_data + "\n")
+      barcode_ofp.flush()
+      t_prv = t_now
+      LAST_TOK = barcode_data
+    else:
+      pass
+
 
   # see abov about constant names
   #

+ 11 - 25
busunit-PIU/scripts/rfid_filter

@@ -56,8 +56,9 @@ import os
 import re
 import sys
 import time
+import datetime
 
-rate_limit_ms = 1500.0
+RATE_LIMIT_MS = 1500.0
 
 def convert_tagid(s):
   binstr = ""
@@ -69,10 +70,6 @@ def convert_tagid(s):
     __b = "0"*(4-len(_b)) + _b
     binstr = binstr + __b
 
-    #print("c:", c, "v:", v, "_b:", _b, "binstr:", binstr)
-
-  #print("binstr:", binstr)
-
   f, s,  = -1, -1
   for idx, b in enumerate(binstr):
     if (b == '1') and (f < 0):
@@ -81,8 +78,6 @@ def convert_tagid(s):
       s = idx
       break
 
-  #print("first:", f, "second:", s)
-
   filt_binstr = binstr[s+1:]
   n = len(filt_binstr)
   bitlen = n
@@ -91,20 +86,11 @@ def convert_tagid(s):
 
     _b = filt_binstr[n-4:n]
     fin_hex = hex(int(_b, 2))[2:] + fin_hex
-
-    #print("n:", n, "_b:", _b, "fin_hex:", fin_hex)
-    
     n -= 4
   if n>0:
     _b = filt_binstr[0:n]
     fin_hex = hex(int(_b, 2))[2:] + fin_hex
 
-    #print("n:", n, "_b:", _b, "fin_hex:", fin_hex)
-
-
-  #print("bitlen:", bitlen)
-  #print("binstr:", binstr)
-  #print("fin_hex:", fin_hex)
 
   return hex(bitlen)[2:] + "|" + fin_hex
 
@@ -112,7 +98,7 @@ def convert_tagid(s):
 t_prv = time.time()*1000.0
 t_now = t_prv
 
-last_tok = ""
+LAST_TOK = ""
 
 while True:
   line = sys.stdin.readline()
@@ -120,23 +106,23 @@ while True:
 
   m = re.match("#db# TAG ID: ([^ ]*)", line)
   if m:
-    #print("match:", m.group(1))
 
     t_now = time.time()*1000.0
 
     tok = convert_tagid(m.group(1)).upper()
-    if last_tok != tok:
-      print(tok)
+    if LAST_TOK != tok:
+      #sys.stdout.write( str(datetime.datetime.now()) + ": " + str(tok) + "\n")
+      sys.stdout.write( str(int(time.time())) + ": " + str(tok) + "\n")
       sys.stdout.flush()
       t_prv = t_now
-      last_tok = tok
-    elif (t_now - t_prv) >= rate_limit_ms:
-      print(tok)
+      LAST_TOK = tok
+    elif (t_now - t_prv) >= RATE_LIMIT_MS:
+      #sys.stdout.write( str(datetime.datetime.now()) + ": " + str(tok) + "\n")
+      sys.stdout.write( str(int(time.time())) + ": " + str(tok) + "\n")
       sys.stdout.flush()
       t_prv = t_now
-      last_tok = tok
+      LAST_TOK = tok
     else:
-      #print("#ignore")
       pass
 
 

+ 3 - 1
busunit-PIU/scripts/rfid_manager

@@ -29,7 +29,9 @@ d=$BASEDIR/bin
 stdbuf -eL -oL $d/proxmark3 /dev/ttyACM0 -l proxmark3-lf-hid-read.lua | \
   stdbuf -eL -oL tee -a /tmp/rfid_raw.log | \
   $d/rfid_filter | \
-  xargs -n1 -I{} bash -c " $d/format_debug_msg.py TOKEN_RFID -i <( echo -e -n '{}\0' ) | $d/debug_client -s " | \
   tee -a /tmp/rfid.log
 
+#  xargs -n1 -I{} bash -c " $d/format_debug_msg.py TOKEN_RFID -i <( echo -e -n '{}\0' ) | $d/debug_client -s " | \
+#  tee -a /tmp/rfid.log
+