Store the clock calibration values in the device handle.

This commit is contained in:
Jef Driesen 2009-03-11 15:02:49 +00:00
parent 801f747345
commit 5cb754b01b
6 changed files with 66 additions and 2 deletions

View File

@ -22,6 +22,7 @@
#include <string.h> // memcmp, memcpy
#include <stdlib.h> // malloc, free
#include <assert.h> // assert
#include <time.h> // 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.

View File

@ -21,6 +21,7 @@
#include <string.h> // memcmp, memcpy
#include <stdlib.h> // malloc, free
#include <time.h> // 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.

View File

@ -21,7 +21,8 @@
#include <string.h> // memcmp, memcpy
#include <stdlib.h> // malloc, free
#include <assert.h>
#include <assert.h> // assert
#include <time.h> // 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.

View File

@ -21,6 +21,8 @@
#include <stdlib.h> // malloc, free
#include <memory.h> // memcpy
#include <time.h> // time
#include <assert.h> // 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)

View File

@ -22,6 +22,7 @@
#include <string.h> // memcmp, memcpy
#include <stdlib.h> // malloc, free
#include <assert.h> // assert
#include <time.h> // 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;
}

View File

@ -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);