From 3ec96c9a81f0f770fac75a1bdfc16ea96df07d9b Mon Sep 17 00:00:00 2001 From: Justin Berger Date: Fri, 9 Mar 2018 00:21:17 -0700 Subject: Swapped to OGGetAbsoluteTime for timestamp --- data_recorder.c | 15 +++++++-------- src/survive_playback.c | 20 +++++++++----------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/data_recorder.c b/data_recorder.c index 323d208..63746c3 100644 --- a/data_recorder.c +++ b/data_recorder.c @@ -15,6 +15,8 @@ #include #include +#include "redist/os_generic.h" + struct SurviveContext * ctx; FILE* output_file = 0; @@ -49,21 +51,18 @@ int bufferpts[32*2*3]; char buffermts[32*128*3]; int buffertimeto[32*3]; -uint64_t timestamp_in_us() { - static uint64_t start_time_us = 0; - struct timeval tv; - gettimeofday(&tv,NULL); - uint64_t now = (uint64_t)tv.tv_sec * 1000000L + tv.tv_usec; +double timestamp_in_us() { + static double start_time_us = 0; if(start_time_us == 0) - start_time_us = now; - return now - start_time_us; + start_time_us = OGGetAbsoluteTime(); + return OGGetAbsoluteTime() - start_time_us; } int write_to_output(const char *format, ...) { va_list args; va_start(args, format); - fprintf(output_file, "%lu ", timestamp_in_us()); + fprintf(output_file, "%.17g ", timestamp_in_us()); vfprintf(output_file, format, args); va_end(args); diff --git a/src/survive_playback.c b/src/survive_playback.c index d8c6fba..7c49f5b 100755 --- a/src/survive_playback.c +++ b/src/survive_playback.c @@ -10,6 +10,8 @@ #include "survive_config.h" #include "survive_default_devices.h" +#include "redist/os_generic.h" + struct SurvivePlaybackData { SurviveContext * ctx; const char* playback_dir; @@ -17,19 +19,16 @@ struct SurvivePlaybackData { int lineno; FLT time_factor; - uint64_t next_time_us; + double next_time_us; }; typedef struct SurvivePlaybackData SurvivePlaybackData; -uint64_t timestamp_in_us() { - static uint64_t start_time_us = 0; - struct timeval tv; - gettimeofday(&tv,NULL); - uint64_t now = (uint64_t)tv.tv_sec * 1000000L + tv.tv_usec; - if(start_time_us == 0) - start_time_us = now; - return now - start_time_us; +double timestamp_in_us() { + static double start_time_us = 0; + if(start_time_us == 0.) + start_time_us = OGGetAbsoluteTime(); + return OGGetAbsoluteTime() - start_time_us; } static int parse_and_run_imu(const char* line, SurvivePlaybackData* driver) { @@ -110,8 +109,7 @@ static int playback_poll( struct SurviveContext * ctx, void * _driver ) { ssize_t r = getdelim( &line, &n, ' ', f ); if( r <= 0 ) return 0; - uint64_t timestamp; - if(sscanf(line, "%lu", &driver->next_time_us) != 1) { + if(sscanf(line, "%lf", &driver->next_time_us) != 1) { free(line); return 0; } -- cgit v1.2.3