Skip to content

Commit f3e80b9

Browse files
authored
Resolve issue of computing actual log rate for spectrum chart in case of data gaps in log file (#762)
* added compute of unlogged time by handling log resumd events * added getActualLoggedTime function in FlightLog * improve getMinTime, getMaxTime functions in FlightLog * Improved actual log rate computing in spectrum chart * code style improvement * code style improvement
1 parent e568594 commit f3e80b9

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

src/flightlog.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
export function FlightLog(logData) {
3232
let ADDITIONAL_COMPUTED_FIELD_COUNT = 15 /** attitude + PID_SUM + PID_ERROR + RCCOMMAND_SCALED **/,
3333
that = this,
34-
logIndex = false,
34+
logIndex = 0,
3535
logIndexes = new FlightLogIndex(logData),
3636
parser = new FlightLogParser(logData),
3737
iframeDirectory,
@@ -117,20 +117,21 @@ export function FlightLog(logData) {
117117
* Get the earliest time seen in the log of the given index (in microseconds), or leave off the logIndex
118118
* argument to fetch details for the current log.
119119
*/
120-
this.getMinTime = function (logIndex) {
121-
return getRawStats(logIndex).frame["I"].field[
122-
FlightLogParser.prototype.FLIGHT_LOG_FIELD_INDEX_TIME
123-
].min;
120+
this.getMinTime = function () {
121+
return logIndexes.getIntraframeDirectory(logIndex).minTime;
124122
};
125123

126124
/**
127125
* Get the latest time seen in the log of the given index (in microseconds), or leave off the logIndex
128126
* argument to fetch details for the current log.
129127
*/
130-
this.getMaxTime = function (logIndex) {
131-
return getRawStats(logIndex).frame["I"].field[
132-
FlightLogParser.prototype.FLIGHT_LOG_FIELD_INDEX_TIME
133-
].max;
128+
this.getMaxTime = function () {
129+
return logIndexes.getIntraframeDirectory(logIndex).maxTime;
130+
};
131+
132+
this.getActualLoggedTime = function () {
133+
const directory = logIndexes.getIntraframeDirectory(logIndex);
134+
return directory.maxTime - directory.minTime - directory.unLoggedTime;
134135
};
135136

136137
/**

src/flightlog_index.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export function FlightLogIndex(logData) {
5656
hasEvent: [],
5757
minTime: false,
5858
maxTime: false,
59+
unLoggedTime: 0,
5960
},
6061
imu = new IMU(),
6162
gyroADC,
@@ -125,7 +126,8 @@ export function FlightLogIndex(logData) {
125126
if (magADC[0] === undefined) {
126127
magADC = false;
127128
}
128-
129+
130+
let frameTime;
129131
parser.onFrameReady = function (
130132
frameValid,
131133
frame,
@@ -140,9 +142,7 @@ export function FlightLogIndex(logData) {
140142
switch (frameType) {
141143
case "P":
142144
case "I":
143-
var frameTime =
144-
frame[FlightLogParser.prototype.FLIGHT_LOG_FIELD_INDEX_TIME];
145-
145+
frameTime = frame[FlightLogParser.prototype.FLIGHT_LOG_FIELD_INDEX_TIME];
146146
if (intraIndex.minTime === false) {
147147
intraIndex.minTime = frameTime;
148148
}
@@ -225,6 +225,13 @@ export function FlightLogIndex(logData) {
225225
if (frame.event == FlightLogEvent.LOG_END) {
226226
sawEndMarker = true;
227227
}
228+
229+
if (frame.event == FlightLogEvent.LOGGING_RESUME) {
230+
if (frameTime) {
231+
intraIndex.unLoggedTime += frame.data.currentTime - frameTime;
232+
}
233+
}
234+
228235
break;
229236
case "S":
230237
lastSlow = frame.slice(0);

src/graph_spectrum_calc.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,10 @@ GraphSpectrumCalc.initialize = function(flightLog, sysConfig) {
5050
}
5151
this._BetaflightRate = this._blackBoxRate;
5252

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

57-
const length = flightLog.getCurrentLogRowsCount();
58-
this._actualeRate = 1e6 * length / timeRange;
56+
this._actualeRate = 1e6 * length / actualLoggedTime;
5957
if (Math.abs(this._BetaflightRate - this._actualeRate) / this._actualeRate > WARNING_RATE_DIFFERENCE)
6058
this._blackBoxRate = Math.round(this._actualeRate);
6159

0 commit comments

Comments
 (0)