From a1962558412b8c89a79656992c8e7f4d001065c2 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Sun, 22 Oct 2017 22:19:45 +0200 Subject: [PATCH] Replace the clock calibration with a fixed epoch Currently the date/time parsing assumes the reference time (epoch) of the device clock is unknown. Hence we retrieve the current time of the device (devtime) and the host system (systime) during the download. Since both timestamps represent the same instant in time, but with a different reference time, we can calibrate the device clock as follows: ticks = parser->systime - (parser->devtime - timestamp) / 2 But this produces wrong results once the device clock has been adjusted manually. Adjusting the device clock will suddenly increase (or decrease) the devtime, while the systime continues ticking forwards normally. Hence all dives recorded before the time adjustment will get an incorrect date/time value. Fortunately all devices appear to use a fixed epoch (2000-01-01 00:00:00 UTC) and we can simply replace the calibration with a hardcoded value. Reported-By: Linus Torvalds --- src/uwatec_smart_parser.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/uwatec_smart_parser.c b/src/uwatec_smart_parser.c index 639d0e4..18a0dfe 100644 --- a/src/uwatec_smart_parser.c +++ b/src/uwatec_smart_parser.c @@ -64,6 +64,8 @@ #define GAUGE 0x00001000 #define SALINITY 0x00100000 +#define EPOCH 946684800 // 2000-01-01 00:00:00 UTC + typedef enum { PRESSURE_DEPTH, RBT, @@ -723,7 +725,7 @@ uwatec_smart_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime unsigned int timestamp = array_uint32_le (abstract->data + 8); - dc_ticks_t ticks = parser->systime - (parser->devtime - timestamp) / 2; + dc_ticks_t ticks = EPOCH + timestamp / 2; if (table->timezone != UNSUPPORTED) { // For devices with timezone support, the UTC offset of the