-
Notifications
You must be signed in to change notification settings - Fork 5
/
ams2-cli.py
54 lines (44 loc) · 1.57 KB
/
ams2-cli.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
from logging import getLogger, basicConfig, DEBUG
basicConfig(
level=DEBUG,
format="%(asctime)s.%(msecs)03d [%(levelname)s] %(name)s: %(message)s",
datefmt="%Y-%m-%d %H:%M:%S"
)
l = getLogger(__name__)
import argparse
import os
import time
from stm.sampler import RawSampler
from stm.ams2 import AMS2Sampler, AMS2Logger
def main():
parser = argparse.ArgumentParser(description="Log AMS2 samples to MoTeC i2")
parser.add_argument("--freq", type=int, default=20, help="frequency (Hz) to collect samples")
parser.add_argument("--imperial", action="store_true", help="use imperial units")
parser.add_argument("--saveraw", help="save raw samples to an sqlite3 db for later analysis", action="store_true")
parser.add_argument("--loadraw", help="load raw samples from an sqlite3 db", default="")
args = parser.parse_args()
filetemplate = os.path.join("logs", "ams2", "{venue}_{vehicle}_{driver}_{session}_{datetime}")
if args.saveraw:
rawfile = os.path.join("logs", "raw", "ams2", f"{time.time():.0f}.db" )
else:
rawfile = None
if args.loadraw:
sampler = RawSampler(rawfile=args.loadraw)
else:
sampler = AMS2Sampler(freq=args.freq)
logger = AMS2Logger(
rawfile=rawfile,
sampler=sampler,
filetemplate=filetemplate,
imperial=args.imperial
)
try:
logger.start()
while logger.is_alive():
logger.join(0.1)
except KeyboardInterrupt:
l.warning("stopping")
logger.stop()
logger.join()
if __name__ == '__main__':
main()