-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.py
More file actions
executable file
·58 lines (46 loc) · 1.26 KB
/
logger.py
File metadata and controls
executable file
·58 lines (46 loc) · 1.26 KB
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
#!/usr/bin/env python3
import serial
import time
import sys
import os
from speedometer import CSpeedometer
min_speed = 17
max_speed = 73
if len(sys.argv) > 1:
prefix = '-' + sys.argv[1]
else:
prefix = ''
def file_source():
with open('minicom-12-05-ev1.cap', 'rb') as f:
for l in f:
yield l
if l.decode('cp1251').startswith('$GNRMC'):
time.sleep(0.1)
def port_source():
port = serial.Serial('/dev/ttyUSB0', 115200, parity=serial.PARITY_NONE, timeout=1)
for l in port:
yield l
source = port_source
speedometer = CSpeedometer()
filename = time.strftime('logger-%Y-%m-%d_%H-%M-%S.cap{}'.format(prefix))
started = False
stopped = False
with open(filename, 'ab') as f:
for line in source():
l = line.decode('cp1251')
tokens = l.split(',')
sentence_type = tokens[0]
if sentence_type == '$GNRMC':
svel = tokens[7]
if not svel:
svel = '0'
vel = float(svel) * 1.85
speedometer.show(int(vel))
if not started and vel > min_speed:
speedometer.set_message(' !!!!!!!!!!!! MEASURING !!!!!!!!!!!! ')
started = True
if started and not stopped and vel > max_speed:
speedometer.set_message(' done ')
stopped = True
if started and not stopped:
f.write(line)