Skip to content
This repository was archived by the owner on Apr 19, 2023. It is now read-only.

Commit 13a1bbe

Browse files
committed
Improvements in parsing of heavily corrupted log files
Now recovers more frames when time/iteration count jumps massively forward. Improved accuracy of frame statistics considerably, particularly the number of frames that were skipped due to blackbox rates.
1 parent 74da51d commit 13a1bbe

File tree

3 files changed

+179
-76
lines changed

3 files changed

+179
-76
lines changed

src/blackbox_decode.c

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ static gpsGFieldIndexes_t gpsGFieldIndexes;
8080
static gpsHFieldIndexes_t gpsHFieldIndexes;
8181
static GPSFieldType gpsFieldTypes[FLIGHT_LOG_MAX_FIELDS];
8282

83-
static uint32_t lastFrameIndex = (uint32_t) -1;
8483
static uint32_t lastFrameTime = (uint32_t) -1;
8584

8685
static FILE *csvFile = 0, *eventFile = 0, *gpsCsvFile = 0;
@@ -251,16 +250,15 @@ void onFrameReady(flightLog_t *log, bool frameValid, int32_t *frame, uint8_t fra
251250
outputGPSFrame(log, frame);
252251
}
253252
} else if (frameType == 'P' || frameType == 'I') {
254-
if (frame) {
255-
lastFrameIndex = (uint32_t) frame[FLIGHT_LOG_FIELD_INDEX_ITERATION];
256-
}
257-
258-
if (frameValid) {
253+
if (frameValid || (frame && options.raw)) {
259254
lastFrameTime = (uint32_t) frame[FLIGHT_LOG_FIELD_INDEX_TIME];
260255

261256
for (i = 0; i < fieldCount; i++) {
262257
if (i == 0) {
263-
fprintf(csvFile, "%u", (uint32_t) frame[i]);
258+
if (frameValid)
259+
fprintf(csvFile, "%u", (uint32_t) frame[i]);
260+
else
261+
fprintf(csvFile, "X");
264262
} else {
265263
if (log->mainFieldSigned[i] || options.raw)
266264
fprintf(csvFile, ", %3d", frame[i]);
@@ -280,11 +278,9 @@ void onFrameReady(flightLog_t *log, bool frameValid, int32_t *frame, uint8_t fra
280278
* We'll assume that the frame's iteration count is still fairly sensible (if an earlier frame was corrupt,
281279
* the frame index will be smaller than it should be)
282280
*/
283-
fprintf(csvFile, "%c Frame unusuable due to prior corruption %u, offset %d, size %d\n", (char) frameType, lastFrameIndex, frameOffset, frameSize);
281+
fprintf(csvFile, "%c Frame unusuable due to prior corruption, offset %d, size %d\n", (char) frameType, frameOffset, frameSize);
284282
} else {
285-
//We have no frame index for this frame, so just assume it was the one after the previously decoded frame
286-
lastFrameIndex++;
287-
fprintf(csvFile, "Failed to decode %c frame %u, offset %d, size %d\n", (char) frameType, lastFrameIndex, frameOffset, frameSize);
283+
fprintf(csvFile, "Failed to decode %c frame, offset %d, size %d\n", (char) frameType, frameOffset, frameSize);
288284
}
289285
}
290286
}
@@ -383,7 +379,7 @@ void printStats(flightLog_t *log, int logIndex, bool raw, bool limits)
383379
uint32_t goodBytes = stats->frame['I'].bytes + stats->frame['P'].bytes;
384380
uint32_t goodFrames = stats->frame['I'].validCount + stats->frame['P'].validCount;
385381
uint32_t totalFrames = (uint32_t) (stats->field[FLIGHT_LOG_FIELD_INDEX_ITERATION].max - stats->field[FLIGHT_LOG_FIELD_INDEX_ITERATION].min + 1);
386-
int32_t missingFrames = totalFrames - goodFrames - stats->intentionallyAbsentIterations + stats->frame['P'].desyncCount;
382+
int32_t missingFrames = totalFrames - goodFrames - stats->intentionallyAbsentIterations;
387383

388384
uint32_t runningTimeMS, runningTimeSecs, runningTimeMins;
389385
uint32_t startTimeMS, startTimeSecs, startTimeMins;
@@ -429,9 +425,9 @@ void printStats(flightLog_t *log, int logIndex, bool raw, bool limits)
429425
for (i = 0; i < (int) sizeof(frameTypes); i++) {
430426
uint8_t frameType = frameTypes[i];
431427

432-
if (stats->frame[frameType].validCount + stats->frame[frameType].desyncCount) {
433-
fprintf(stderr, "%c frames %7d %6.1f bytes avg %8d bytes total\n", (char) frameType, stats->frame[frameType].validCount + stats->frame[frameType].desyncCount,
434-
(float) stats->frame[frameType].bytes / (stats->frame[frameType].validCount + stats->frame[frameType].desyncCount), stats->frame[frameType].bytes);
428+
if (stats->frame[frameType].validCount ) {
429+
fprintf(stderr, "%c frames %7d %6.1f bytes avg %8d bytes total\n", (char) frameType, stats->frame[frameType].validCount,
430+
(float) stats->frame[frameType].bytes / stats->frame[frameType].validCount, stats->frame[frameType].bytes);
435431
}
436432
}
437433

@@ -450,23 +446,25 @@ void printStats(flightLog_t *log, int logIndex, bool raw, bool limits)
450446
fprintf(stderr, "Data rate: Unknown, no timing information available.\n");
451447
}
452448

453-
if (totalFrames && (stats->totalCorruptFrames || stats->frame['P'].desyncCount || missingFrames || stats->intentionallyAbsentIterations)) {
449+
if (totalFrames && (stats->totalCorruptFrames || missingFrames || stats->intentionallyAbsentIterations)) {
454450
fprintf(stderr, "\n");
455451

456-
if (stats->totalCorruptFrames || stats->frame['P'].desyncCount) {
452+
if (stats->totalCorruptFrames || stats->frame['P'].desyncCount || stats->frame['I'].desyncCount) {
457453
fprintf(stderr, "%d frames failed to decode, rendering %d loop iterations unreadable. ", stats->totalCorruptFrames, stats->frame['P'].desyncCount + stats->frame['P'].corruptCount + stats->frame['I'].desyncCount + stats->frame['I'].corruptCount);
458454
if (!missingFrames)
459455
fprintf(stderr, "\n");
460456
}
461457
if (missingFrames) {
462458
fprintf(stderr, "%d iterations are missing in total (%ums, %.2f%%)\n",
463459
missingFrames,
464-
(unsigned int) (missingFrames * (intervalMS / totalFrames)), (double) missingFrames / totalFrames * 100);
460+
(unsigned int) (((int64_t) missingFrames * intervalMS) / totalFrames),
461+
(double) missingFrames / totalFrames * 100);
465462
}
466463
if (stats->intentionallyAbsentIterations) {
467464
fprintf(stderr, "%d loop iterations weren't logged because of your blackbox_rate settings (%ums, %.2f%%)\n",
468465
stats->intentionallyAbsentIterations,
469-
(unsigned int) (stats->intentionallyAbsentIterations * (intervalMS / totalFrames)), (double) stats->intentionallyAbsentIterations / totalFrames * 100);
466+
(unsigned int) (((int64_t)stats->intentionallyAbsentIterations * intervalMS) / totalFrames),
467+
(double) stats->intentionallyAbsentIterations / totalFrames * 100);
470468
}
471469
}
472470

@@ -477,8 +475,8 @@ void printStats(flightLog_t *log, int logIndex, bool raw, bool limits)
477475
for (i = 0; i < log->mainFieldCount; i++) {
478476
fprintf(stderr, "%14s %12" PRId64 " %12" PRId64 " %12" PRId64 "\n",
479477
log->mainFieldNames[i],
480-
stats->field[i].max,
481478
stats->field[i].min,
479+
stats->field[i].max,
482480
stats->field[i].max - stats->field[i].min
483481
);
484482
}

0 commit comments

Comments
 (0)