From 829e75e38d12f6cb43da59280314a47dabd973e3 Mon Sep 17 00:00:00 2001 From: demvlad Date: Wed, 5 Jun 2024 12:17:56 +0300 Subject: [PATCH 1/3] improve field statistic and log rows count calculate --- src/flightlog.js | 4 +--- src/flightlog_parser.js | 24 +++++++++++------------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/flightlog.js b/src/flightlog.js index 6eaa34fb..9f4d430a 100644 --- a/src/flightlog.js +++ b/src/flightlog.js @@ -1143,9 +1143,7 @@ export function FlightLog(logData) { this.getCurrentLogRowsCount = function () { const stats = this.getStats(this.getLogIndex()); - const countI = stats.frame['I'] ? stats.frame['I'].totalCount : 0; - const countP = stats.frame['P'] ? stats.frame['P'].totalCount : 0; - return countI + countP; + return stats.frame['I'].validCount + stats.frame['P'].validCount; }; } diff --git a/src/flightlog_parser.js b/src/flightlog_parser.js index 2025e2aa..f2843d7f 100644 --- a/src/flightlog_parser.js +++ b/src/flightlog_parser.js @@ -1110,6 +1110,7 @@ export function FlightLogParser(logData) { mainHistory[0] = mainHistoryRing[2]; else mainHistory[0] = mainHistoryRing[0]; + return mainStreamIsValid; } /** @@ -1251,7 +1252,7 @@ export function FlightLogParser(logData) { that.onFrameReady(gpsHomeIsValid, lastGPS, frameType, frameStart, frameEnd - frameStart); } - return true; + return gpsHomeIsValid; } function completeSlowFrame(frameType, frameStart, frameEnd, raw) { @@ -1260,6 +1261,7 @@ export function FlightLogParser(logData) { if (that.onFrameReady) { that.onFrameReady(true, lastSlow, frameType, frameStart, frameEnd - frameStart); } + return true; } function completeInterframe(frameType, frameStart, frameEnd, raw) { @@ -1300,6 +1302,7 @@ export function FlightLogParser(logData) { else mainHistory[0] = mainHistoryRing[0]; } + return mainStreamIsValid; } /** @@ -1773,13 +1776,12 @@ export function FlightLogParser(logData) { sizeCount: new Int32Array(256), /* int32 arrays are zero-filled, handy! */ validCount: 0, corruptCount: 0, - field: [], - totalCount: 0 + desyncCount: 0, + field: [] }; } frameTypeStats = this.stats.frame[lastFrameType.marker]; - frameTypeStats.totalCount++; // If we see what looks like the beginning of a new frame, assume that the previous frame was valid: if (lastFrameSize <= FLIGHT_LOG_MAX_FRAME_LENGTH && looksLikeFrameCompleted) { var frameAccepted = true; @@ -1790,22 +1792,18 @@ export function FlightLogParser(logData) { if (frameAccepted) { //Update statistics for this frame type frameTypeStats.bytes += lastFrameSize; - frameTypeStats.sizeCount[lastFrameSize]++; - frameTypeStats.validCount++; + ++frameTypeStats.sizeCount[lastFrameSize]; + ++frameTypeStats.validCount; } else { - frameTypeStats.desyncCount = frameTypeStats.desyncCount ? ++frameTypeStats.desyncCount : 1; + ++frameTypeStats.desyncCount; } } else { //The previous frame was corrupt //We need to resynchronise before we can deliver another main frame: mainStreamIsValid = false; - frameTypeStats.corruptCount++; - this.stats.totalCorruptFrames++; - - //Let the caller know there was a corrupt frame (don't give them a pointer to the frame data because it is totally worthless) - if (this.onFrameReady) - this.onFrameReady(false, null, lastFrameType.marker, frameStart, lastFrameSize); + ++frameTypeStats.corruptCount; + ++this.stats.totalCorruptFrames; /* * Start the search for a frame beginning after the first byte of the previous corrupt frame. From f98065cfb83594deb3639eab53c48507f263bf77 Mon Sep 17 00:00:00 2001 From: demvlad Date: Wed, 5 Jun 2024 18:49:06 +0300 Subject: [PATCH 2/3] SonarCloud issue improvement --- src/flightlog_parser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flightlog_parser.js b/src/flightlog_parser.js index f2843d7f..aa78cff6 100644 --- a/src/flightlog_parser.js +++ b/src/flightlog_parser.js @@ -1777,7 +1777,7 @@ export function FlightLogParser(logData) { validCount: 0, corruptCount: 0, desyncCount: 0, - field: [] + field: [], }; } From 6ac5523f81dc92e39104ee80d05e1fa91fc98778 Mon Sep 17 00:00:00 2001 From: demvlad Date: Wed, 5 Jun 2024 19:37:30 +0300 Subject: [PATCH 3/3] code style improvement --- src/flightlog_parser.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/flightlog_parser.js b/src/flightlog_parser.js index aa78cff6..5f033c32 100644 --- a/src/flightlog_parser.js +++ b/src/flightlog_parser.js @@ -1792,18 +1792,18 @@ export function FlightLogParser(logData) { if (frameAccepted) { //Update statistics for this frame type frameTypeStats.bytes += lastFrameSize; - ++frameTypeStats.sizeCount[lastFrameSize]; - ++frameTypeStats.validCount; + frameTypeStats.sizeCount[lastFrameSize]++; + frameTypeStats.validCount++; } else { - ++frameTypeStats.desyncCount; + frameTypeStats.desyncCount++; } } else { //The previous frame was corrupt //We need to resynchronise before we can deliver another main frame: mainStreamIsValid = false; - ++frameTypeStats.corruptCount; - ++this.stats.totalCorruptFrames; + frameTypeStats.corruptCount++; + this.stats.totalCorruptFrames++; /* * Start the search for a frame beginning after the first byte of the previous corrupt frame.