From 84d45cce400658cfb85f962c46fcc0ca97db0bc6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 May 2016 15:40:30 +1000 Subject: [PATCH] Replay: fixed log rate detection --- Tools/Replay/Replay.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Tools/Replay/Replay.cpp b/Tools/Replay/Replay.cpp index 76273af2b7..891d61be45 100644 --- a/Tools/Replay/Replay.cpp +++ b/Tools/Replay/Replay.cpp @@ -526,6 +526,7 @@ bool Replay::find_log_info(struct log_information &info) int samplecount = 0; uint64_t prev = 0; uint64_t smallest_delta = 0; + uint64_t total_delta = 0; prev = 0; const uint16_t samples_required = 1000; while (samplecount < samples_required) { @@ -557,17 +558,22 @@ bool Replay::find_log_info(struct log_information &info) samplecount = 0; prev = 0; smallest_delta = 0; + total_delta = 0; } if (streq(type, clock_source)) { if (prev == 0) { prev = reader.last_clock_timestamp; } else { uint64_t delta = reader.last_clock_timestamp - prev; - if (smallest_delta == 0 || delta < smallest_delta) { - smallest_delta = delta; + if (delta < 40000 && delta > 1000) { + if (smallest_delta == 0 || delta < smallest_delta) { + smallest_delta = delta; + } + samplecount++; + total_delta += delta; } - samplecount++; } + prev = reader.last_clock_timestamp; } if (streq(type, "IMU2")) { @@ -585,7 +591,10 @@ bool Replay::find_log_info(struct log_information &info) return false; } - float rate = 1.0e6f/smallest_delta; + float average_delta = total_delta / samplecount; + float rate = 1.0e6f/average_delta; + printf("average_delta=%.2f smallest_delta=%lu samplecount=%lu\n", + average_delta, (unsigned long)smallest_delta, (unsigned long)samplecount); if (rate < 100) { info.update_rate = 50; } else {