Skip to content

Commit

Permalink
Updated parser and field presenter for edt signals.
Browse files Browse the repository at this point in the history
Found a workaround to plot esc signal 4

Added basic ESC plot functionality

updated project files

Implemented array fiels propagation over empty fields

Fixed bad FLIGHT_LOG_FIELD_ENCODING_PACK_1F_1F_1F_1G_4U_8U decoding

Removed tabs on changed files

Fixed some more review findings

Updated DSHOT_STATUS_N_ERPM_FRACTION_18 graph ranges

Reverted changes in package.json and yarn.lock

Improved wording and graph ranges

Updated concatenations to template literals

If a field contain array values always use the last field for graph

Added DSHOT motor events to graph

Fixed review findings
Added demag events to graph

Changed speciffic Bluejay wording by general esc one

Fixed sonarcloud false positive

Updated debug modes to match the ones in bf master

Added debug mode to match edt_events Betaflight branch

Removed duplicated BARO graph config

Fixed review findings
  • Loading branch information
damosvil committed Dec 5, 2023
1 parent 2e2d887 commit 49b771d
Show file tree
Hide file tree
Showing 7 changed files with 366 additions and 139 deletions.
30 changes: 30 additions & 0 deletions js/flightlog.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,35 @@ function FlightLog(logData) {
return numMotors;
};

/*
* Propagates array data fiels over empty fields
* Debug fields can be arrays with data, so it fills data gaps when no arrays are stored
*/
function propagateArrayFields(chunks)
{
var previousFrame = 0, currentFrame;

for (let k = 0; k < chunks.length; k++)
{
for (let j = 0; j < chunks[k].frames.length; j++)
{
currentFrame = chunks[k].frames[j];
if (previousFrame == 0)
previousFrame = currentFrame;

for (let i = 0; i < currentFrame.length; i++)
{
if (!Array.isArray(currentFrame[i]) && Array.isArray(previousFrame[i]))
{
currentFrame[i] = previousFrame[i];
}
}

previousFrame = chunks[k].frames[j];
}
}
}

/**
* Get the raw chunks in the range [startIndex...endIndex] (inclusive)
*
Expand Down Expand Up @@ -504,6 +533,7 @@ function FlightLog(logData) {
}

injectComputedFields(resultChunks, resultChunks);
propagateArrayFields(resultChunks);

return resultChunks;
}
Expand Down
7 changes: 7 additions & 0 deletions js/flightlog_fielddefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,13 @@ let
"RC_STATS",
"MAG_CALIB",
"MAG_TASK_RATE",
"DSHOT_STATUS_N_TEMPERATURE",
"DSHOT_STATUS_N_VOLTAGE",
"DSHOT_STATUS_N_CURRENT",
"DSHOT_STATUS_N_DEBUG1",
"DSHOT_STATUS_N_DEBUG2",
"DSHOT_STATUS_N_STRESS_LVL",
"DSHOT_STATUS_N_ERPM_FRACTION_18",
]),

SUPER_EXPO_YAW = makeReadOnly([
Expand Down
66 changes: 66 additions & 0 deletions js/flightlog_fields_presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,55 @@ function FlightLogFieldPresenter() {
'debug[5]': 'Read State',
'debug[6]': 'Task Time (Us)',
},
'DSHOT_STATUS_N_TEMPERATURE' : {
'debug[all]': 'ESC Status & Temperature',
'debug[0]': 'ESC1',
'debug[1]': 'ESC2',
'debug[2]': 'ESC3',
'debug[3]': 'ESC4',
},
'DSHOT_STATUS_N_VOLTAGE' : {
'debug[all]': 'ESC Status & Voltage',
'debug[0]': 'ESC1',
'debug[1]': 'ESC2',
'debug[2]': 'ESC3',
'debug[3]': 'ESC4',
},
'DSHOT_STATUS_N_CURRENT' : {
'debug[all]': 'ESC Status & Current',
'debug[0]': 'ESC1',
'debug[1]': 'ESC2',
'debug[2]': 'ESC3',
'debug[3]': 'ESC4',
},
'DSHOT_STATUS_N_DEBUG1' : {
'debug[all]': 'ESC Status & Debug1',
'debug[0]': 'ESC1',
'debug[1]': 'ESC2',
'debug[2]': 'ESC3',
'debug[3]': 'ESC4',
},
'DSHOT_STATUS_N_DEBUG2' : {
'debug[all]': 'ESC Status & Debug2',
'debug[0]': 'ESC1',
'debug[1]': 'ESC2',
'debug[2]': 'ESC3',
'debug[3]': 'ESC4',
},
'DSHOT_STATUS_N_STRESS_LVL' : {
'debug[all]': 'ESC Status & Stress Level',
'debug[0]': 'ESC1',
'debug[1]': 'ESC2',
'debug[2]': 'ESC3',
'debug[3]': 'ESC4',
},
'DSHOT_STATUS_N_ERPM_FRACTION_18' : {
'debug[all]': 'ESC Status & RPM',
'debug[0]': 'ESC1',
'debug[1]': 'ESC2',
'debug[2]': 'ESC3',
'debug[3]': 'ESC4',
},
};

let DEBUG_FRIENDLY_FIELD_NAMES = null;
Expand Down Expand Up @@ -1872,7 +1921,24 @@ function FlightLogFieldPresenter() {
return value.toFixed(0);
case 'DSHOT_TELEMETRY_COUNTS':
return value.toFixed(0);
case 'DSHOT_STATUS_N_TEMPERATURE':
return (value[0] != null) ? `A${value[0]} W${value[1]} E${value[2]} STRESS:${value[3]} ${value[4]}ºC` : '---';
case 'DSHOT_STATUS_N_VOLTAGE':
return (value[0] != null) ? `A${value[0]} W${value[1]} E${value[2]} STRESS:${value[3]} ${value[4]}V` : '---';
case 'DSHOT_STATUS_N_CURRENT':
return (value[0] != null) ? `A${value[0]} W${value[1]} E${value[2]} STRESS:${value[3]} ${value[4]}A` : '---';
case 'DSHOT_STATUS_N_DEBUG1':
return (value[0] != null) ? `A${value[0]} W${value[1]} E${value[2]} STRESS:${value[3]} ${value[4]}` : '---';
case 'DSHOT_STATUS_N_DEBUG2':
return (value[0] != null) ? `A${value[0]} W${value[1]} E${value[2]} STRESS:${value[3]} ${value[4]}` : '---';
case 'DSHOT_STATUS_N_STRESS_LVL':
return (value[0] != null) ? `A${value[0]} W${value[1]} E${value[2]} STRESS:${value[3]} ${value[4]}sTrs` : '---';
case 'DSHOT_STATUS_N_ERPM_FRACTION_18':
var rpm = (value[4] * 200 / flightLog.getSysConfig().motor_poles).toFixed();
return (value[0] != null) ? `A${value[0]} W${value[1]} E${value[2]} STRESS:${value[3]} ${rpm}Rpm` : '---';

}

return value.toFixed(0);
}
return "";
Expand Down
103 changes: 82 additions & 21 deletions js/flightlog_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,23 @@ var FlightLogParser = function(logData) {
//Predict that this field is minthrottle
FLIGHT_LOG_FIELD_PREDICTOR_MINMOTOR = 11,

//Predict that this field is dshot status and other data
FLIGHT_LOG_FIELD_PREDICTOR_DSHOT_STATUS_N_VOLTAGE = 12,
FLIGHT_LOG_FIELD_PREDICTOR_DSHOT_STATUS_N_ERPM_FRACTION_18 = 13,

//Home coord predictors appear in pairs (two copies of FLIGHT_LOG_FIELD_PREDICTOR_HOME_COORD). Rewrite the second
//one we see to this to make parsing easier
FLIGHT_LOG_FIELD_PREDICTOR_HOME_COORD_1 = 256,

FLIGHT_LOG_FIELD_ENCODING_SIGNED_VB = 0, // Signed variable-byte
FLIGHT_LOG_FIELD_ENCODING_UNSIGNED_VB = 1, // Unsigned variable-byte
FLIGHT_LOG_FIELD_ENCODING_NEG_14BIT = 3, // Unsigned variable-byte but we negate the value before storing, value is 14 bits
FLIGHT_LOG_FIELD_ENCODING_TAG8_8SVB = 6,
FLIGHT_LOG_FIELD_ENCODING_TAG2_3S32 = 7,
FLIGHT_LOG_FIELD_ENCODING_TAG8_4S16 = 8,
FLIGHT_LOG_FIELD_ENCODING_NULL = 9, // Nothing is written to the file, take value to be zero
FLIGHT_LOG_FIELD_ENCODING_TAG2_3SVARIABLE = 10,
FLIGHT_LOG_FIELD_ENCODING_SIGNED_VB = 0, // Signed variable-byte
FLIGHT_LOG_FIELD_ENCODING_UNSIGNED_VB = 1, // Unsigned variable-byte
FLIGHT_LOG_FIELD_ENCODING_NEG_14BIT = 3, // Unsigned variable-byte but we negate the value before storing, value is 14 bits
FLIGHT_LOG_FIELD_ENCODING_TAG8_8SVB = 6,
FLIGHT_LOG_FIELD_ENCODING_TAG2_3S32 = 7,
FLIGHT_LOG_FIELD_ENCODING_TAG8_4S16 = 8,
FLIGHT_LOG_FIELD_ENCODING_NULL = 9, // Nothing is written to the file, take value to be zero
FLIGHT_LOG_FIELD_ENCODING_TAG2_3SVARIABLE = 10,
FLIGHT_LOG_FIELD_ENCODING_PACK_1F_1F_1F_1G_4U_8U = 11, // 1 flagBit, 1 flagBit, 1 flagBit, 1 gapBit, 4 unsignedIntBit, 8 unsignedIntBit

FLIGHT_LOG_EVENT_LOG_END = 255,

Expand Down Expand Up @@ -528,9 +533,9 @@ var FlightLogParser = function(logData) {
function translateFieldName(fieldName) {
var translation = translationValues[fieldName];
if (typeof translation !== 'undefined') {
return translation;
return translation;
} else {
return fieldName;
return fieldName;
}
}

Expand Down Expand Up @@ -600,14 +605,14 @@ var FlightLogParser = function(logData) {
case "Cleanflight":
that.sysConfig.firmwareType = FIRMWARE_TYPE_CLEANFLIGHT;
$('html').removeClass('isBaseF');
$('html').addClass('isCF');
$('html').addClass('isCF');
$('html').removeClass('isBF');
$('html').removeClass('isINAV');
break;
default:
that.sysConfig.firmwareType = FIRMWARE_TYPE_BASEFLIGHT;
$('html').addClass('isBaseF');
$('html').removeClass('isCF');
$('html').removeClass('isCF');
$('html').removeClass('isBF');
$('html').removeClass('isINAV');
}
Expand Down Expand Up @@ -943,7 +948,7 @@ var FlightLogParser = function(logData) {
$('html').addClass('isINAV');
} else {

// Cleanflight 1.x and others
// Cleanflight 1.x and others
that.sysConfig.firmwareVersion = '0.0.0';
that.sysConfig.firmware = 0.0;
that.sysConfig.firmwarePatch = 0;
Expand Down Expand Up @@ -1106,6 +1111,34 @@ var FlightLogParser = function(logData) {
% that.sysConfig.frameIntervalPDenom < that.sysConfig.frameIntervalPNum;
}

/**
* Debug data interpretation depends on the chosen debug mode encodings and other parameters could need to be fixed
*/
function assimilateDebugMode(sysConfig, frameDef) {
console.log("Debug mode is " + DEBUG_MODE[sysConfig.debug_mode] + ":" + sysConfig.debug_mode);

if (DEBUG_MODE[sysConfig.debug_mode].startsWith("DSHOT_STATUS_N_")) {
for (let k = 0; k < frameDef.name.length; k++) {
if (frameDef.name[k].startsWith("debug")) {
// Assimilate encoding depending on debug mode
frameDef.encoding[k] = FLIGHT_LOG_FIELD_ENCODING_PACK_1F_1F_1F_1G_4U_8U;

// Assimilate predictor depending on debug mode
switch (DEBUG_MODE[sysConfig.debug_mode]) {
case "DSHOT_STATUS_N_VOLTAGE":
frameDef.predictor[k] = FLIGHT_LOG_FIELD_PREDICTOR_DSHOT_STATUS_N_VOLTAGE;
break;
case "DSHOT_STATUS_N_ERPM_FRACTION_18":
frameDef.predictor[k] = FLIGHT_LOG_FIELD_PREDICTOR_DSHOT_STATUS_N_ERPM_FRACTION_18;
break;
default:
break;
}
}
}
}
}

/**
* Attempt to parse the frame of into the supplied `current` buffer using the encoding/predictor
* definitions from `frameDefs`. The previous frame values are used for predictions.
Expand All @@ -1120,8 +1153,8 @@ var FlightLogParser = function(logData) {
predictor = frameDef.predictor,
encoding = frameDef.encoding,
values = new Array(8),
i, j, groupCount;

i, j, groupCount, updateCurrent;
i = 0;
while (i < frameDef.count) {
var
Expand All @@ -1135,6 +1168,10 @@ var FlightLogParser = function(logData) {

i++;
} else {
// Update current by default
updateCurrent = true;

// Decode
switch (encoding[i]) {
case FLIGHT_LOG_FIELD_ENCODING_SIGNED_VB:
value = stream.readSignedVB();
Expand All @@ -1155,7 +1192,7 @@ var FlightLogParser = function(logData) {
for (j = 0; j < 4; j++, i++)
current[i] = applyPrediction(i, raw ? FLIGHT_LOG_FIELD_PREDICTOR_0 : predictor[i], values[j], current, previous, previous2);

continue;
updateCurrent = false;
break;
case FLIGHT_LOG_FIELD_ENCODING_TAG2_3S32:
stream.readTag2_3S32(values);
Expand All @@ -1164,7 +1201,7 @@ var FlightLogParser = function(logData) {
for (j = 0; j < 3; j++, i++)
current[i] = applyPrediction(i, raw ? FLIGHT_LOG_FIELD_PREDICTOR_0 : predictor[i], values[j], current, previous, previous2);

continue;
updateCurrent = false;
break;
case FLIGHT_LOG_FIELD_ENCODING_TAG2_3SVARIABLE:
stream.readTag2_3SVariable(values);
Expand All @@ -1173,7 +1210,7 @@ var FlightLogParser = function(logData) {
for (j = 0; j < 3; j++, i++)
current[i] = applyPrediction(i, raw ? FLIGHT_LOG_FIELD_PREDICTOR_0 : predictor[i], values[j], current, previous, previous2);

continue;
updateCurrent = false;
break;
case FLIGHT_LOG_FIELD_ENCODING_TAG8_8SVB:
//How many fields are in this encoded group? Check the subsequent field encodings:
Expand All @@ -1188,7 +1225,20 @@ var FlightLogParser = function(logData) {
for (j = 0; j < groupCount; j++, i++)
current[i] = applyPrediction(i, raw ? FLIGHT_LOG_FIELD_PREDICTOR_0 : predictor[i], values[j], current, previous, previous2);

continue;
updateCurrent = false;
break;
case FLIGHT_LOG_FIELD_ENCODING_PACK_1F_1F_1F_1G_4U_8U:
value = stream.readSignedVB();

current[i] = new Array(5);
current[i][0] = ((value & 0x8000) != 0) ? 1 : 0;
current[i][1] = ((value & 0x4000) != 0) ? 1 : 0;
current[i][2] = ((value & 0x2000) != 0) ? 1 : 0;
current[i][3] = (value >> 8) & 0x000F;
current[i][4] = applyPrediction(i, raw ? FLIGHT_LOG_FIELD_PREDICTOR_0 : predictor[i], value & 0x00FF, current, previous, previous2);
i++;

updateCurrent = false;
break;
case FLIGHT_LOG_FIELD_ENCODING_NULL:
//Nothing to read
Expand All @@ -1201,8 +1251,11 @@ var FlightLogParser = function(logData) {
throw "Unsupported field encoding " + encoding[i];
}

current[i] = applyPrediction(i, raw ? FLIGHT_LOG_FIELD_PREDICTOR_0 : predictor[i], value, current, previous, previous2);
i++;
// Updates current when it is not updated by the decoder path`
if (updateCurrent) {
current[i] = applyPrediction(i, raw ? FLIGHT_LOG_FIELD_PREDICTOR_0 : predictor[i], value, current, previous, previous2);
i++;
}
}
}
}
Expand Down Expand Up @@ -1363,6 +1416,12 @@ var FlightLogParser = function(logData) {
if (mainHistory[1])
value += mainHistory[1][FlightLogParser.prototype.FLIGHT_LOG_FIELD_INDEX_TIME];
break;
case FLIGHT_LOG_FIELD_PREDICTOR_DSHOT_STATUS_N_VOLTAGE:
value /= 4;
break;
case FLIGHT_LOG_FIELD_PREDICTOR_DSHOT_STATUS_N_ERPM_FRACTION_18:
value *= 18;
break;
default:
throw "Unsupported field predictor " + predictor;
}
Expand Down Expand Up @@ -1700,6 +1759,8 @@ var FlightLogParser = function(logData) {
} else {
lastSlow = [];
}

assimilateDebugMode(that.sysConfig, this.frameDefs.I);
};

/**
Expand Down
29 changes: 28 additions & 1 deletion js/graph_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,7 @@ GraphConfig.load = function(config) {
default:
return getCurveForMinMaxFields(fieldName);
}

case 'GPS_DOP':
switch (fieldName) {
case 'debug[0]': // Number of Satellites (now this is in normal GPS data, maybe gpsTrust?)
Expand Down Expand Up @@ -1135,7 +1136,33 @@ GraphConfig.load = function(config) {
default:
return getCurveForMinMaxFields(fieldName);
}
}
case 'DSHOT_STATUS_N_TEMPERATURE':
case 'DSHOT_STATUS_N_CURRENT':
case 'DSHOT_STATUS_N_DEBUG1':
case 'DSHOT_STATUS_N_DEBUG2':
case 'DSHOT_STATUS_N_STRESS_LVL':
return {
offset: 0,
power: 1.0,
inputRange: 400,
outputRange: 1.0,
};
case 'DSHOT_STATUS_N_VOLTAGE':
return {
offset: 0,
power: 1.0,
inputRange: 255,
outputRange: 1.0,
};
case 'DSHOT_STATUS_N_ERPM_FRACTION_18':
return {
offset: 0,
power: 1.0,
inputRange: 4000,
outputRange: 1.0,
};

}
}
// if not found above then
// Scale and center the field based on the whole-log observed ranges for that field
Expand Down

0 comments on commit 49b771d

Please sign in to comment.