Skip to content

Resolve issue of computing actual log rate for spectrum chart in case of data gaps in log file #762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/flightlog.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
export function FlightLog(logData) {
let ADDITIONAL_COMPUTED_FIELD_COUNT = 15 /** attitude + PID_SUM + PID_ERROR + RCCOMMAND_SCALED **/,
that = this,
logIndex = false,
logIndex = 0,
logIndexes = new FlightLogIndex(logData),
parser = new FlightLogParser(logData),
iframeDirectory,
Expand Down Expand Up @@ -117,20 +117,21 @@ export function FlightLog(logData) {
* Get the earliest time seen in the log of the given index (in microseconds), or leave off the logIndex
* argument to fetch details for the current log.
*/
this.getMinTime = function (logIndex) {
return getRawStats(logIndex).frame["I"].field[
FlightLogParser.prototype.FLIGHT_LOG_FIELD_INDEX_TIME
].min;
this.getMinTime = function () {
return logIndexes.getIntraframeDirectory(logIndex).minTime;
};

/**
* Get the latest time seen in the log of the given index (in microseconds), or leave off the logIndex
* argument to fetch details for the current log.
*/
this.getMaxTime = function (logIndex) {
return getRawStats(logIndex).frame["I"].field[
FlightLogParser.prototype.FLIGHT_LOG_FIELD_INDEX_TIME
].max;
this.getMaxTime = function () {
return logIndexes.getIntraframeDirectory(logIndex).maxTime;
};

this.getActualLoggedTime = function () {
const directory = logIndexes.getIntraframeDirectory(logIndex);
return directory.maxTime - directory.minTime - directory.unLoggedTime;
};

/**
Expand Down
16 changes: 12 additions & 4 deletions src/flightlog_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export function FlightLogIndex(logData) {
hasEvent: [],
minTime: false,
maxTime: false,
unLoggedTime: 0,
},
imu = new IMU(),
gyroADC,
Expand Down Expand Up @@ -125,7 +126,8 @@ export function FlightLogIndex(logData) {
if (magADC[0] === undefined) {
magADC = false;
}


let lastTime;
parser.onFrameReady = function (
frameValid,
frame,
Expand All @@ -140,9 +142,8 @@ export function FlightLogIndex(logData) {
switch (frameType) {
case "P":
case "I":
var frameTime =
frame[FlightLogParser.prototype.FLIGHT_LOG_FIELD_INDEX_TIME];

let frameTime = frame[FlightLogParser.prototype.FLIGHT_LOG_FIELD_INDEX_TIME];
lastTime = frameTime;
if (intraIndex.minTime === false) {
intraIndex.minTime = frameTime;
}
Expand Down Expand Up @@ -225,6 +226,13 @@ export function FlightLogIndex(logData) {
if (frame.event == FlightLogEvent.LOG_END) {
sawEndMarker = true;
}

if (frame.event == FlightLogEvent.LOGGING_RESUME) {
if (lastTime) {
intraIndex.unLoggedTime += frame.data.currentTime - lastTime;
}
}

break;
case "S":
lastSlow = frame.slice(0);
Expand Down
8 changes: 3 additions & 5 deletions src/graph_spectrum_calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,10 @@ GraphSpectrumCalc.initialize = function(flightLog, sysConfig) {
}
this._BetaflightRate = this._blackBoxRate;

const minTime = this._flightLog.getMinTime(),
maxTime = this._flightLog.getMaxTime(),
timeRange = maxTime - minTime;
const actualLoggedTime = this._flightLog.getActualLoggedTime(),
length = flightLog.getCurrentLogRowsCount();

const length = flightLog.getCurrentLogRowsCount();
this._actualeRate = 1e6 * length / timeRange;
this._actualeRate = 1e6 * length / actualLoggedTime;
if (Math.abs(this._BetaflightRate - this._actualeRate) / this._actualeRate > WARNING_RATE_DIFFERENCE)
this._blackBoxRate = Math.round(this._actualeRate);

Expand Down