Skip to content

Commit 5708431

Browse files
authored
Merge pull request #98 from iNavFlight/jh_fix_time_rollover_accumulator
Jh fix time rollover accumulator
2 parents c5f22f4 + 08733ba commit 5708431

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

src/parser.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ typedef struct flightLogPrivate_t
6363
int64_t* mainHistory[3];
6464
bool mainStreamIsValid;
6565
// When 32-bit time values roll over to zero, we add 2^32 to this accumulator so it can be added to the time:
66-
int64_t timeRolloverAccumulator;
66+
int64_t timeRolloverAccumulator[2];
6767

6868
int64_t gpsHomeHistory[2][2]; // 0 - space to decode new frames into, 1 - previous frame
6969
bool gpsHomeIsValid;
@@ -941,7 +941,7 @@ static void parseEventFrame(flightLog_t *log, mmapStream_t *stream, bool raw)
941941

942942
switch (eventType) {
943943
case FLIGHT_LOG_EVENT_SYNC_BEEP:
944-
data->syncBeep.time = streamReadUnsignedVB(stream) + log->private->timeRolloverAccumulator;
944+
data->syncBeep.time = streamReadUnsignedVB(stream) + log->private->timeRolloverAccumulator[0];
945945
break;
946946
case FLIGHT_LOG_EVENT_AUTOTUNE_CYCLE_START:
947947
data->autotuneCycleStart.phase = streamReadByte(stream);
@@ -978,7 +978,7 @@ static void parseEventFrame(flightLog_t *log, mmapStream_t *stream, bool raw)
978978
break;
979979
case FLIGHT_LOG_EVENT_LOGGING_RESUME:
980980
data->loggingResume.logIteration = streamReadUnsignedVB(stream);
981-
data->loggingResume.currentTime = streamReadUnsignedVB(stream) + log->private->timeRolloverAccumulator;
981+
data->loggingResume.currentTime = streamReadUnsignedVB(stream) + log->private->timeRolloverAccumulator[0];
982982
break;
983983
case FLIGHT_LOG_EVENT_LOG_END:
984984
streamRead(stream, endMessage, END_OF_LOG_MESSAGE_LEN);
@@ -1260,7 +1260,7 @@ static void flightLogInvalidateStream(flightLog_t *log)
12601260
*
12611261
* Returns the recovered 64-bit timestamp for the frame.
12621262
*/
1263-
static int64_t flightLogDetectAndApplyTimestampRollover(flightLog_t *log, int64_t timestamp)
1263+
static int64_t flightLogDetectAndApplyTimestampRollover(flightLog_t *log, int64_t timestamp, int id)
12641264
{
12651265
if (log->private->lastMainFrameTime != -1) {
12661266
if (
@@ -1270,24 +1270,24 @@ static int64_t flightLogDetectAndApplyTimestampRollover(flightLog_t *log, int64_
12701270
&& (uint32_t) ((uint32_t) timestamp - (uint32_t) log->private->lastMainFrameTime) < MAXIMUM_TIME_JUMP_BETWEEN_FRAMES
12711271
) {
12721272
// 32-bit time counter has wrapped, so add 2^32 to the timestamp
1273-
log->private->timeRolloverAccumulator += 0x100000000LL;
1273+
log->private->timeRolloverAccumulator[id] += 0x100000000LL;
12741274
}
12751275
}
12761276

1277-
return (uint32_t) timestamp + log->private->timeRolloverAccumulator;
1277+
return (uint32_t) timestamp + log->private->timeRolloverAccumulator[id];
12781278
}
12791279

12801280
static void flightLogApplyMainFrameTimeRollover(flightLog_t *log)
12811281
{
1282-
log->private->mainHistory[0][FLIGHT_LOG_FIELD_INDEX_TIME] = flightLogDetectAndApplyTimestampRollover(log, log->private->mainHistory[0][FLIGHT_LOG_FIELD_INDEX_TIME]);
1282+
log->private->mainHistory[0][FLIGHT_LOG_FIELD_INDEX_TIME] = flightLogDetectAndApplyTimestampRollover(log, log->private->mainHistory[0][FLIGHT_LOG_FIELD_INDEX_TIME], 0);
12831283
}
12841284

12851285
static void flightLogApplyGPSFrameTimeRollover(flightLog_t *log)
12861286
{
12871287
int timeFieldIndex = log->gpsFieldIndexes.time;
12881288

12891289
if (timeFieldIndex != -1) {
1290-
log->private->lastGPS[timeFieldIndex] = flightLogDetectAndApplyTimestampRollover(log, log->private->lastGPS[timeFieldIndex]);
1290+
log->private->lastGPS[timeFieldIndex] = flightLogDetectAndApplyTimestampRollover(log, log->private->lastGPS[timeFieldIndex], 1);
12911291
}
12921292
}
12931293

@@ -1538,7 +1538,8 @@ bool flightLogParse(flightLog_t *log, int logIndex, FlightLogMetadataReady onMet
15381538

15391539
clearFieldIdents(log);
15401540

1541-
private->timeRolloverAccumulator = 0;
1541+
private->timeRolloverAccumulator[0] = 0;
1542+
private->timeRolloverAccumulator[1] = 0;
15421543
private->lastSkippedFrames = 0;
15431544
private->lastMainFrameIteration = (uint32_t) -1;
15441545
private->lastMainFrameTime = -1;

src/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#define BBLTOOLS_VERSION 8.0.0
1+
#define BBLTOOLS_VERSION 8.0.2
22

33
#ifdef BLACKBOX_VERSION
44
#undef BBLTOOLS_VERSION

0 commit comments

Comments
 (0)