aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Berger <j.david.berger@gmail.com>2018-03-09 00:21:17 -0700
committerJustin Berger <j.david.berger@gmail.com>2018-03-09 00:21:17 -0700
commit3ec96c9a81f0f770fac75a1bdfc16ea96df07d9b (patch)
treeb85a5879a91563680e5a632cc456518f96b707c6
parent82dc5c4452e2a58667c337e967200cb7760c16cd (diff)
downloadlibsurvive-3ec96c9a81f0f770fac75a1bdfc16ea96df07d9b.tar.gz
libsurvive-3ec96c9a81f0f770fac75a1bdfc16ea96df07d9b.tar.bz2
Swapped to OGGetAbsoluteTime for timestamp
-rw-r--r--data_recorder.c15
-rwxr-xr-xsrc/survive_playback.c20
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 <sys/time.h>
#include <stdarg.h>
+#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;
}