Add grab_log script

This commit is contained in:
Oleg Kalachev 2023-04-12 23:04:24 +03:00
parent 4a045d89a4
commit f9558e164c
2 changed files with 27 additions and 1 deletions

View File

@ -33,7 +33,7 @@ simulator: build_simulator
gazebo --verbose ${CURDIR}/gazebo/flix.world
grab_log:
tools/grab_log.py
PORT=$(PORT) tools/grab_log.py
clean:
rm -rf gazebo/plugin/build $(SKETCH)/build $(SKETCH)/cache

26
tools/grab_log.py Executable file
View File

@ -0,0 +1,26 @@
#!/usr/bin/env python3
# grab flight log and save to file
import datetime
import serial
import os
PORT = os.environ['PORT']
DIR = os.path.dirname(os.path.realpath(__file__))
dev = serial.Serial(port=PORT, baudrate=115200, timeout=0.5)
log = open(f'{DIR}/log/{datetime.datetime.now().isoformat()}.csv', 'wb')
print('Downloading log...')
count = 0
dev.write('log\n'.encode())
while True:
line = dev.readline()
if not line:
break
log.write(line)
count += 1
print(f'\r{count} lines', end='')
print(f'\nWritten {os.path.relpath(log.name, os.curdir)}')