Skip to content

Commit

Permalink
Merge pull request #39 from iNavFlight/coruption_warning
Browse files Browse the repository at this point in the history
Coruption warning
  • Loading branch information
stronnag authored Jun 6, 2021
2 parents ec62638 + 69cea36 commit 06ba81d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
13 changes: 13 additions & 0 deletions src/blackbox_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,19 @@ void printStats(flightLog_t *log, int logIndex, bool raw, bool limits)
}
}

if(log->sysConfig.metafound != ((1<<META_CHECKS_COUNT) - 1)) {
fprintf(stderr,"\nWARNING: Missing expected metadata - check for log corruption\n");
if((log->sysConfig.metafound & (1<<haveMetaVBatRef)) == 0)
fprintf(stderr,"\tWarning: No VBAT reference\n");
if((log->sysConfig.metafound&(1<<haveMetaFWType)) == 0)
fprintf(stderr,"\tError: No Firmware type metadata\n");
if((log->sysConfig.metafound&(1<<haveMetaFWRev)) == 0)
fprintf(stderr,"\tError: No Firmware revision metadata\n");
if((log->sysConfig.metafound&(1<<haveMetaPInterval)) == 0)
fprintf(stderr,"\tError: No P Interval\n");
if((log->sysConfig.metafound&(1<<haveMetaAcc1G)) == 0)
fprintf(stderr,"\tError: No Acc.1G metadata\n");
}
fprintf(stderr, "\n");
}

Expand Down
6 changes: 6 additions & 0 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#define LOG_START_MARKER "H Product:Blackbox flight data recorder by Nicholas Sherlock\n"

#define HEADER_MAX_SIZE 2048
// maximum size of a single header line (not the whole section)

//Assume that even in the most woeful logging situation, we won't miss 10 seconds of frames
#define MAXIMUM_TIME_JUMP_BETWEEN_FRAMES (10 * 1000000)
Expand Down Expand Up @@ -421,6 +422,7 @@ static void parseHeaderLine(flightLog_t *log, mmapStream_t *stream)
if (log->frameIntervalI < 1)
log->frameIntervalI = 1;
} else if (strcmp(fieldName, "P interval") == 0) {
log->sysConfig.metafound |= (1 << haveMetaPInterval);
char *slashPos = strchr(fieldValue, '/');

if (slashPos) {
Expand All @@ -430,6 +432,7 @@ static void parseHeaderLine(flightLog_t *log, mmapStream_t *stream)
} else if (strcmp(fieldName, "Data version") == 0) {
log->private->dataVersion = atoi(fieldValue);
} else if (strcmp(fieldName, "Firmware type") == 0) {
log->sysConfig.metafound |= (1 << haveMetaFWType);
if (strcmp(fieldValue, "Cleanflight") == 0)
log->sysConfig.firmwareType = FIRMWARE_TYPE_CLEANFLIGHT;
else
Expand All @@ -449,6 +452,7 @@ static void parseHeaderLine(flightLog_t *log, mmapStream_t *stream)
} else if (strcmp(fieldName, "vbatscale") == 0) {
log->sysConfig.vbatscale = atoi(fieldValue);
} else if (strcmp(fieldName, "vbatref") == 0) {
log->sysConfig.metafound |= (1 << haveMetaVBatRef);
log->sysConfig.vbatref = atoi(fieldValue);
} else if (strcmp(fieldName, "vbatcellvoltage") == 0) {
int vbatcellvoltage[3];
Expand Down Expand Up @@ -477,6 +481,7 @@ static void parseHeaderLine(flightLog_t *log, mmapStream_t *stream)
log->sysConfig.gyroScale = (float) (log->sysConfig.gyroScale * (M_PI / 180.0) * 0.000001);
}
} else if (strcmp(fieldName, "acc_1G") == 0) {
log->sysConfig.metafound |= (1 << haveMetaAcc1G);
log->sysConfig.acc_1G = atoi(fieldValue);
} else if (strcmp(fieldName, "motorOutput") == 0) {
int motorOutputs[2];
Expand All @@ -486,6 +491,7 @@ static void parseHeaderLine(flightLog_t *log, mmapStream_t *stream)
log->sysConfig.motorOutputLow = motorOutputs[0];
log->sysConfig.motorOutputHigh = motorOutputs[1];
} else if (strcmp(fieldName, "Firmware revision") == 0) {
log->sysConfig.metafound |= (1 << haveMetaFWRev);

if (strncmp(fieldValue, "Betaflight", 10) == 0)
log->sysConfig.firmwareRevison = FIRMWARE_REVISON_BETAFLIGHT;
Expand Down
11 changes: 11 additions & 0 deletions src/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ typedef enum VbatType {
INAV_V2
} VbatType;

// These items have existed since pre 1.0
typedef enum ParserMetaData {
haveMetaVBatRef = 0,
haveMetaFWType,
haveMetaFWRev,
haveMetaPInterval,
haveMetaAcc1G,
META_CHECKS_COUNT
} ParserMetaData;

typedef struct flightLogFrameStatistics_t {
uint32_t bytes;
// Frames decoded to the right length and had reasonable data in them:
Expand Down Expand Up @@ -143,6 +153,7 @@ typedef struct flightLogSysConfig_t {
VbatType vbatType;

struct tm logStartTime;
ParserMetaData metafound;
} flightLogSysConfig_t;

typedef struct flightLogFrameDef_t {
Expand Down
12 changes: 7 additions & 5 deletions tools/rcmodes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
## Generate enum names from f/w source code to avoid mismatch between
## firmware and bbl decoder
## BOXes from src/main/fc/rc_modes.h
## ADJUSTMENTs from ./src/main/fc/rc_adjustments.h
## ADJUSTMENTs from src/main/fc/rc_adjustments.h

NAMES=['BOX','ADJUSTMENT_']

inenum = false
n = 0
Expand All @@ -16,10 +18,10 @@
a = l.split(' ')
if a.size > 2
name=nil
if a[0].match(/^ADJUSTMENT_/)
name = a[0].sub(/^ADJUSTMENT_/,'')
elsif a[0].match(/^BOX/)
name = a[0].sub(/^BOX_/,'')
NAMES.each do |nm|
if a[0].match(/^#{nm}/)
name = a[0].sub(/^#{nm}/,'')
end
end
puts " \"#{name}\",\t// #{n}"
n += 1
Expand Down

0 comments on commit 06ba81d

Please sign in to comment.