-
Notifications
You must be signed in to change notification settings - Fork 0
/
data-log.py
88 lines (71 loc) · 1.64 KB
/
data-log.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import serial
import time
import sys
import subprocess
import os
start = str(time.time())
fpath = "/home/logbox/serial/"
fmode = "a"
serialWait = 4
s = serial.Serial("/dev/serial0", 9600, timeout=3)
while serialWait > 0:
s.flushInput()
s.flush()
s.flushOutput()
serialWait = s.inWaiting()
sys.stdout.write("Waiting for HAT calibration signal")
init = ""
while init != "CAL":
sys.stdout.write(".")
sys.stdout.flush()
init = s.readline().strip()
time.sleep(1)
sys.stdout.write("\n")
sys.stdout.write("Calibration signal ready, sending data..")
latestData = subprocess.check_output(["python", "/home/logbox/os/get-latest-counters.py"])
s.write(latestData)
print(latestData.decode("utf-8"))
init = ""
while init != "CALOK":
sys.stdout.write(".")
sys.stdout.flush()
init = s.readline().strip()
time.sleep(1)
print(init)
buffer = ""
while True:
t = time.time();
print(t)
while "\n\n\n" not in buffer:
data = s.readline()
if not data:
continue
if(data.startswith("C1")):
c1 = data.split("\t", 1)[1]
c1file = open("/home/logbox/c1", "w", 1)
c1file.write(c1)
c1file.flush()
os.fsync(c1file)
c1file.close()
if(data.startswith("C2")):
c2 = data.split("\t", 1)[1]
c2file = open("/home/logbox/c2", "w", 1)
c2file.write(c2)
c2file.flush()
os.fsync(c2file)
c2file.close()
if(data.startswith("C3")):
c3 = data.split("\t", 1)[1]
c3file = open("/home/logbox/c3", "w", 1)
c3file.write(c3)
c3file.flush()
os.fsync(c3file)
c3file.close()
sys.stdout.write(data)
buffer += data
fname = fpath + str(t) + ".log"
outf = open(fname, fmode)
outf.write(buffer)
outf.flush()
outf.close()
buffer = ""