mirror of
https://github.com/okalachev/flix.git
synced 2025-07-27 01:29:33 +00:00
Improve log download: remove empty records, sort by timestamp
To make Plotjuggler not to warn about unsorted records everytime
This commit is contained in:
parent
4eec63adfa
commit
455729fdb4
@ -44,6 +44,7 @@ void dumpLog() {
|
||||
Serial.printf("t,rates.x,rates.y,rates.z,ratesTarget.x,ratesTarget.y,ratesTarget.z,"
|
||||
"attitude.x,attitude.y,attitude.z,attitudeTarget.x,attitudeTarget.y,attitudeTarget.z,thrustTarget\n");
|
||||
for (int i = 0; i < LOG_SIZE; i++) {
|
||||
if (logBuffer[i][0] == 0) continue; // skip empty records
|
||||
for (int j = 0; j < LOG_COLUMNS - 1; j++) {
|
||||
Serial.printf("%f,", logBuffer[i][j]);
|
||||
}
|
||||
|
@ -9,8 +9,7 @@ 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')
|
||||
lines = []
|
||||
|
||||
print('Downloading log...')
|
||||
count = 0
|
||||
@ -19,8 +18,14 @@ while True:
|
||||
line = dev.readline()
|
||||
if not line:
|
||||
break
|
||||
log.write(line)
|
||||
lines.append(line)
|
||||
count += 1
|
||||
print(f'\r{count} lines', end='')
|
||||
|
||||
# sort by timestamp
|
||||
header = lines.pop(0)
|
||||
lines.sort(key=lambda line: float(line.split(b',')[0]))
|
||||
|
||||
log = open(f'{DIR}/log/{datetime.datetime.now().isoformat()}.csv', 'wb')
|
||||
log.writelines([header] + lines)
|
||||
print(f'\nWritten {os.path.relpath(log.name, os.curdir)}')
|
||||
|
Loading…
x
Reference in New Issue
Block a user