Add a clock synchronization event.

This commit is contained in:
Jef Driesen 2010-02-01 21:20:30 +00:00
parent b392a49045
commit fab15b19a7
9 changed files with 52 additions and 2 deletions

View File

@ -91,6 +91,7 @@ event_cb (device_t *device, device_event_t event, const void *data, void *userda
{
const device_progress_t *progress = (device_progress_t *) data;
const device_devinfo_t *devinfo = (device_devinfo_t *) data;
const device_clock_t *clock = (device_clock_t *) data;
switch (event) {
case DEVICE_EVENT_WAITING:
@ -107,6 +108,10 @@ event_cb (device_t *device, device_event_t event, const void *data, void *userda
devinfo->firmware, devinfo->firmware,
devinfo->serial, devinfo->serial);
break;
case DEVICE_EVENT_CLOCK:
message ("Event: systime=%u, devtime=%u\n",
clock->systime, clock->devtime);
break;
default:
break;
}
@ -255,7 +260,7 @@ dowork (device_type_t backend, const char *devname, const char *filename, int me
// Register the event handler.
message ("Registering the event handler.\n");
int events = DEVICE_EVENT_WAITING | DEVICE_EVENT_PROGRESS | DEVICE_EVENT_DEVINFO;
int events = DEVICE_EVENT_WAITING | DEVICE_EVENT_PROGRESS | DEVICE_EVENT_DEVINFO | DEVICE_EVENT_CLOCK;
rc = device_set_events (device, events, event_cb, NULL);
if (rc != DEVICE_STATUS_SUCCESS) {
WARNING ("Error registering the event handler.");

View File

@ -206,6 +206,9 @@ device_event_emit (device_t *device, device_event_t event, const void *data)
case DEVICE_EVENT_DEVINFO:
assert (data != NULL);
break;
case DEVICE_EVENT_CLOCK:
assert (data != NULL);
break;
default:
break;
}

View File

@ -65,7 +65,8 @@ typedef enum device_status_t {
typedef enum device_event_t {
DEVICE_EVENT_WAITING = (1 << 0),
DEVICE_EVENT_PROGRESS = (1 << 1),
DEVICE_EVENT_DEVINFO = (1 << 2)
DEVICE_EVENT_DEVINFO = (1 << 2),
DEVICE_EVENT_CLOCK = (1 << 3)
} device_event_t;
typedef struct device_t device_t;
@ -81,6 +82,11 @@ typedef struct device_devinfo_t {
unsigned int serial;
} device_devinfo_t;
typedef struct device_clock_t {
unsigned int devtime;
dc_ticks_t systime;
} device_clock_t;
typedef void (*device_event_callback_t) (device_t *device, device_event_t event, const void *data, void *userdata);
typedef int (*dive_callback_t) (const unsigned char *data, unsigned int size, void *userdata);

View File

@ -277,6 +277,12 @@ reefnet_sensus_handshake (reefnet_sensus_device_t *device)
// Store the handshake packet.
memcpy (device->handshake, handshake + 2, REEFNET_SENSUS_HANDSHAKE_SIZE);
// Emit a clock event.
device_clock_t clock;
clock.systime = device->systime;
clock.devtime = device->devtime;
device_event_emit (&device->base, DEVICE_EVENT_CLOCK, &clock);
// Emit a device info event.
device_devinfo_t devinfo;
devinfo.model = handshake[2] - '0';

View File

@ -246,6 +246,12 @@ reefnet_sensuspro_handshake (reefnet_sensuspro_device_t *device)
// Store the handshake packet.
memcpy (device->handshake, handshake, REEFNET_SENSUSPRO_HANDSHAKE_SIZE);
// Emit a clock event.
device_clock_t clock;
clock.systime = device->systime;
clock.devtime = device->devtime;
device_event_emit (&device->base, DEVICE_EVENT_CLOCK, &clock);
// Emit a device info event.
device_devinfo_t devinfo;
devinfo.model = handshake[0];

View File

@ -351,6 +351,12 @@ reefnet_sensusultra_handshake (reefnet_sensusultra_device_t *device)
// Store the handshake packet.
memcpy (device->handshake, handshake, REEFNET_SENSUSULTRA_HANDSHAKE_SIZE);
// Emit a clock event.
device_clock_t clock;
clock.systime = device->systime;
clock.devtime = device->devtime;
device_event_emit (&device->base, DEVICE_EVENT_CLOCK, &clock);
// Emit a device info event.
device_devinfo_t devinfo;
devinfo.model = handshake[1];

View File

@ -264,6 +264,12 @@ uwatec_aladin_device_dump (device_t *abstract, dc_buffer_t *buffer)
device->systime = now;
device->devtime = array_uint32_be (answer + HEADER + 0x7f8);
// Emit a clock event.
device_clock_t clock;
clock.systime = device->systime;
clock.devtime = device->devtime;
device_event_emit (abstract, DEVICE_EVENT_CLOCK, &clock);
dc_buffer_append (buffer, answer, UWATEC_ALADIN_MEMORY_SIZE);
return DEVICE_STATUS_SUCCESS;

View File

@ -437,6 +437,12 @@ uwatec_memomouse_dump_internal (uwatec_memomouse_device_t *device, dc_buffer_t *
device->systime = now;
device->devtime = array_uint32_le (dc_buffer_get_data (buffer) + 1);
// Emit a clock event.
device_clock_t clock;
clock.systime = device->systime;
clock.devtime = device->devtime;
device_event_emit ((device_t *) device, DEVICE_EVENT_CLOCK, &clock);
return DEVICE_STATUS_SUCCESS;
}

View File

@ -341,6 +341,12 @@ uwatec_smart_device_dump (device_t *abstract, dc_buffer_t *buffer)
progress.current += 9;
device_event_emit (&device->base, DEVICE_EVENT_PROGRESS, &progress);
// Emit a clock event.
device_clock_t clock;
clock.systime = device->systime;
clock.devtime = device->devtime;
device_event_emit (&device->base, DEVICE_EVENT_CLOCK, &clock);
// Emit a device info event.
device_devinfo_t devinfo;
devinfo.model = version[0];