#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;
static uchar *blast;
static int blsize = 0;
+static int clock_offset = 0;
uint
randno(void)
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);
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;
}
memcpy(antfsdir + antfsdir_used, blast + pos, ANTFSDIRSIZE);
+ antfsdir[antfsdir_used].last_modified += clock_offset;
/* print_dir_entry(&antfsdir[antfsdir_used]);*/
++antfsdir_used;
}