diff --git a/src/reefnet_sensus.c b/src/reefnet_sensus.c index 27eb8ad..25156be 100644 --- a/src/reefnet_sensus.c +++ b/src/reefnet_sensus.c @@ -22,6 +22,7 @@ #include // memcmp, memcpy #include // malloc, free #include // assert +#include // time #include "device-private.h" #include "reefnet_sensus.h" @@ -48,6 +49,8 @@ struct reefnet_sensus_device_t { struct serial *port; unsigned int waiting; unsigned int timestamp; + unsigned int devtime; + time_t systime; }; static device_status_t reefnet_sensus_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size); @@ -116,6 +119,8 @@ reefnet_sensus_device_open (device_t **out, const char* name) device->port = NULL; device->waiting = 0; device->timestamp = 0; + device->systime = (time_t) -1; + device->devtime = 0; // Open the device. int rc = serial_open (&device->port, name); @@ -265,6 +270,10 @@ reefnet_sensus_device_handshake (device_t *abstract, unsigned char *data, unsign array_uint32_le (handshake + 8)); #endif + // Store the clock calibration values. + device->systime = time (NULL); + device->devtime = array_uint32_le (handshake + 8); + memcpy (data, handshake + 2, REEFNET_SENSUS_HANDSHAKE_SIZE); // Emit a device info event. diff --git a/src/reefnet_sensuspro.c b/src/reefnet_sensuspro.c index 5756320..944ac42 100644 --- a/src/reefnet_sensuspro.c +++ b/src/reefnet_sensuspro.c @@ -21,6 +21,7 @@ #include // memcmp, memcpy #include // malloc, free +#include // time #include "device-private.h" #include "reefnet_sensuspro.h" @@ -46,6 +47,8 @@ struct reefnet_sensuspro_device_t { device_t base; struct serial *port; unsigned int timestamp; + unsigned int devtime; + time_t systime; }; static device_status_t reefnet_sensuspro_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size); @@ -95,6 +98,8 @@ reefnet_sensuspro_device_open (device_t **out, const char* name) // Set the default values. device->port = NULL; device->timestamp = 0; + device->systime = (time_t) -1; + device->devtime = 0; // Open the device. int rc = serial_open (&device->port, name); @@ -234,6 +239,10 @@ reefnet_sensuspro_device_handshake (device_t *abstract, unsigned char *data, uns array_uint32_le (handshake + 6)); #endif + // Store the clock calibration values. + device->systime = time (NULL); + device->devtime = array_uint32_le (handshake + 6); + memcpy (data, handshake, REEFNET_SENSUSPRO_HANDSHAKE_SIZE); // Emit a device info event. diff --git a/src/reefnet_sensusultra.c b/src/reefnet_sensusultra.c index dc0c418..2cd3304 100644 --- a/src/reefnet_sensusultra.c +++ b/src/reefnet_sensusultra.c @@ -21,7 +21,8 @@ #include // memcmp, memcpy #include // malloc, free -#include +#include // assert +#include // time #include "device-private.h" #include "reefnet_sensusultra.h" @@ -51,6 +52,8 @@ struct reefnet_sensusultra_device_t { struct serial *port; unsigned int maxretries; unsigned int timestamp; + unsigned int devtime; + time_t systime; }; static device_status_t reefnet_sensusultra_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size); @@ -101,6 +104,8 @@ reefnet_sensusultra_device_open (device_t **out, const char* name) device->port = NULL; device->maxretries = 2; device->timestamp = 0; + device->systime = (time_t) -1; + device->devtime = 0; // Open the device. int rc = serial_open (&device->port, name); @@ -350,6 +355,10 @@ reefnet_sensusultra_device_handshake (device_t *abstract, unsigned char *data, u array_uint16_le (handshake + 22)); #endif + // Store the clock calibration values. + device->systime = time (NULL); + device->devtime = array_uint32_le (handshake + 4); + memcpy (data, handshake, REEFNET_SENSUSULTRA_HANDSHAKE_SIZE); // Emit a device info event. diff --git a/src/uwatec_aladin.c b/src/uwatec_aladin.c index 6c123d9..f588217 100644 --- a/src/uwatec_aladin.c +++ b/src/uwatec_aladin.c @@ -21,6 +21,8 @@ #include // malloc, free #include // memcpy +#include // time +#include // assert #include "device-private.h" #include "uwatec_aladin.h" @@ -53,6 +55,8 @@ struct uwatec_aladin_device_t { device_t base; struct serial *port; unsigned int timestamp; + unsigned int devtime; + time_t systime; }; static device_status_t uwatec_aladin_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size); @@ -101,6 +105,8 @@ uwatec_aladin_device_open (device_t **out, const char* name) // Set the default values. device->port = NULL; device->timestamp = 0; + device->systime = (time_t) -1; + device->devtime = 0; // Open the device. int rc = serial_open (&device->port, name); @@ -232,6 +238,9 @@ uwatec_aladin_device_dump (device_t *abstract, unsigned char data[], unsigned in } } + // Fetch the current system time. + time_t now = time (NULL); + // Update and emit a progress event. progress.current += 4; device_event_emit (abstract, DEVICE_EVENT_PROGRESS, &progress); @@ -258,6 +267,10 @@ uwatec_aladin_device_dump (device_t *abstract, unsigned char data[], unsigned in return DEVICE_STATUS_PROTOCOL; } + // Store the clock calibration values. + device->systime = now; + device->devtime = array_uint32_be (answer + HEADER + 0x7f8); + memcpy (data, answer, UWATEC_ALADIN_MEMORY_SIZE); if (result) diff --git a/src/uwatec_memomouse.c b/src/uwatec_memomouse.c index be3ac59..b358988 100644 --- a/src/uwatec_memomouse.c +++ b/src/uwatec_memomouse.c @@ -22,6 +22,7 @@ #include // memcmp, memcpy #include // malloc, free #include // assert +#include // time #include "device-private.h" #include "uwatec_memomouse.h" @@ -49,6 +50,8 @@ struct uwatec_memomouse_device_t { device_t base; struct serial *port; unsigned int timestamp; + unsigned int devtime; + time_t systime; }; static device_status_t uwatec_memomouse_device_set_fingerprint (device_t *device, const unsigned char data[], unsigned int size); @@ -97,6 +100,8 @@ uwatec_memomouse_device_open (device_t **out, const char* name) // Set the default values. device->port = NULL; device->timestamp = 0; + device->systime = (time_t) -1; + device->devtime = 0; // Open the device. int rc = serial_open (&device->port, name); @@ -473,8 +478,19 @@ uwatec_memomouse_dump (uwatec_memomouse_device_t *device, unsigned char *data[], serial_sleep (100); } + // Fetch the current system time. + time_t now = time (NULL); + // Read the data packet. - return uwatec_memomouse_read_packet_inner (device, data, size, &progress); + rc = uwatec_memomouse_read_packet_inner (device, data, size, &progress); + if (rc != DEVICE_STATUS_SUCCESS) + return rc; + + // Store the clock calibration values. + device->systime = now; + device->devtime = array_uint32_le (*data + 2 + 1); + + return DEVICE_STATUS_SUCCESS; } diff --git a/src/uwatec_smart.c b/src/uwatec_smart.c index 12f99a2..0de8a4f 100644 --- a/src/uwatec_smart.c +++ b/src/uwatec_smart.c @@ -47,6 +47,8 @@ struct uwatec_smart_device_t { struct irda *socket; unsigned int address; unsigned int timestamp; + unsigned int devtime; + time_t systime; }; static device_status_t uwatec_smart_device_set_fingerprint (device_t *device, const unsigned char data[], unsigned int size); @@ -121,6 +123,8 @@ uwatec_smart_device_open (device_t **out) device->socket = NULL; device->address = 0; device->timestamp = 0; + device->systime = (time_t) -1; + device->devtime = 0; irda_init (); @@ -394,6 +398,10 @@ uwatec_smart_dump (uwatec_smart_device_t *device, unsigned char *data[], unsigne unsigned int timestamp = array_uint32_le (answer); message ("handshake: timestamp=0x%08x\n", timestamp); + // Store the clock calibration values. + device->systime = time (NULL); + device->devtime = timestamp; + // Update and emit a progress event. progress.current += 9; device_event_emit (&device->base, DEVICE_EVENT_PROGRESS, &progress);