-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_gluco_uart.py
83 lines (65 loc) · 2.1 KB
/
test_gluco_uart.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
import serial
import re
ser = serial.Serial('/dev/ttyUSB0', 115200, timeout=1.5)
print(ser.name)
get_data = False
raw_data = []
while not get_data:
if ser.inWaiting() != 0 :
# Garbage input serial b'/x00/
msg = ser.read()
print(msg)
print(type(msg))
if msg != b'\x00' :
if msg == b'A' :
raw_data.append(ser.readlines())
raw_data.append(ser.readlines())
raw_data.append(ser.readlines())
raw_data.append(ser.readlines())
print("s1 adalah {}".format(raw_data[0]))
print("s2 adalah {}".format(raw_data[1]))
print("s3 adalah {}".format(raw_data[2]))
print("s4 adalah {}".format(raw_data[3]))
get_data = True
# and msg != b'\x00\x00' or msg == b'xff'
ser.close()
'''
raw_data = [[a,b],[]]
raw_data[0] = [a,b]
raw_data[0][0] = a
for i in range(len(raw_data))
if raw_data[i] is not []:
for j in range(len(raw_data)):
raw_data[i][j].decode("utf-8")
'''
print("raw_data is {}".format(raw_data[0]))
decoded_string = []
for index in range(len(raw_data)):
if raw_data[index] is not [] :
for j in range(len(raw_data[index])):
decoded_string.append(raw_data[index][j].decode('ISO-8859-1'))
for i in range(len(decoded_string)):
print(decoded_string[i])
'''
TODO :
- search match string TotalValue
- if yes , cut string total value - end of string
- then split by space, take fifth element
FIXME has been solved
'''
output = None
for i in range(len(decoded_string)):
if 'TotalValue' in decoded_string[i]:
output = re.findall(r'TotalValue.+?(?=0\r)' , decoded_string[i])
final_output = output[0].split(' ')
print(final_output)
print("Gula darah : {}".format(final_output[4]))
else :
print("Error tidak menemukan data")
'''
TODO :
add to flow to ke sistem besar
'''
# blood_glucose_clean = re.findall(r'TotalValue.*', blood_glucose_raw)
# clean_measure = blood_glucose_clean.replace('\x00','').split('\r')
# print(blood_glucose_clean