From a664bbe9b231254dcc84e2eb6f9e60efc1ca83ee Mon Sep 17 00:00:00 2001 From: Tollef Fog Heen Date: Fri, 6 Jan 2012 22:48:40 +0100 Subject: [PATCH] Adjust timestamps for clocksyncless units Try to adjust timestamps for devices where we have no idea if the clock is correct or not. --- fr60.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fr60.c b/fr60.c index 5efe81d..1509909 100644 --- a/fr60.c +++ b/fr60.c @@ -23,6 +23,7 @@ #define FIT_FILE_NAME_PATTERN "antfs-dump.%s.fit" #define ANTFS_DIR_MAX_SIZE 256 // fairly arbitrary +#define EPOCH_OFFSET 631065600 /* Seconds between the UNIX and ANT+ epochs */ static int sentauth; static int gotwatchid; @@ -75,6 +76,7 @@ static char *action = NULL; static uchar *blast; static int blsize = 0; +static int clock_offset = 0; uint randno(void) @@ -269,7 +271,7 @@ retry_transfer(uchar chan) { size_t format_time(char* s, char *format, size_t max, time_t tm) { - time_t unix_tm = tm + 631065600; + time_t unix_tm = tm + EPOCH_OFFSET; struct tm local_tm; localtime_r(&unix_tm, &local_tm); return strftime(s, max, format, &local_tm); @@ -309,7 +311,9 @@ decode_antfs_dir(const uchar* blast, uint blsize) assert(sizeof(struct antfs_dir_header) == ANTFSHEADERSIZE); memcpy(&hdr, blast + 24, ANTFSHEADERSIZE); - printf("system time: %d\n", hdr.system_time); + if (hdr.modified_time < 0x0FFFFFFF) + clock_offset = time(NULL) - EPOCH_OFFSET - hdr.system_time; + printf("system time: %d (offset: %d)\n", hdr.system_time, clock_offset); format_time(textual_time, "%c", 256, hdr.modified_time); printf("last modified: %d (%s)\n", hdr.modified_time, textual_time); dir_start_offset = 40; @@ -337,6 +341,7 @@ decode_antfs_dir(const uchar* blast, uint blsize) } memcpy(antfsdir + antfsdir_used, blast + pos, ANTFSDIRSIZE); + antfsdir[antfsdir_used].last_modified += clock_offset; /* print_dir_entry(&antfsdir[antfsdir_used]);*/ ++antfsdir_used; } -- 2.39.5