Add a new vendor event.

The new vendor event provides a mechanism to deliver auxiliary data,
which is automatically retrieved during the data transfer, but not
accessible through the library interface otherwise. Possible examples
include handshake data and/or device identification data.

This event is mainly intended for diagnostic purposes, in combination
with the memory dumping support. Very few applications will actually
need it for anything else.
This commit is contained in:
Jef Driesen 2012-12-26 08:11:46 +01:00
parent d0b7f2e584
commit 56b7730773
9 changed files with 69 additions and 2 deletions

View File

@ -455,6 +455,7 @@ event_cb (dc_device_t *device, dc_event_type_t event, const void *data, void *us
const dc_event_progress_t *progress = (dc_event_progress_t *) data;
const dc_event_devinfo_t *devinfo = (dc_event_devinfo_t *) data;
const dc_event_clock_t *clock = (dc_event_clock_t *) data;
const dc_event_vendor_t *vendor = (dc_event_vendor_t *) data;
device_data_t *devdata = (device_data_t *) userdata;
@ -486,6 +487,12 @@ event_cb (dc_device_t *device, dc_event_type_t event, const void *data, void *us
message ("Event: systime=" DC_TICKS_FORMAT ", devtime=%u\n",
clock->systime, clock->devtime);
break;
case DC_EVENT_VENDOR:
message ("Event: vendor=");
for (unsigned int i = 0; i < vendor->size; ++i)
message ("%02X", vendor->data[i]);
message ("\n");
break;
default:
break;
}
@ -654,7 +661,7 @@ dowork (dc_context_t *context, dc_descriptor_t *descriptor, const char *devname,
// Register the event handler.
message ("Registering the event handler.\n");
int events = DC_EVENT_WAITING | DC_EVENT_PROGRESS | DC_EVENT_DEVINFO | DC_EVENT_CLOCK;
int events = DC_EVENT_WAITING | DC_EVENT_PROGRESS | DC_EVENT_DEVINFO | DC_EVENT_CLOCK | DC_EVENT_VENDOR;
rc = dc_device_set_events (device, events, event_cb, &devdata);
if (rc != DC_STATUS_SUCCESS) {
WARNING ("Error registering the event handler.");

View File

@ -36,7 +36,8 @@ typedef enum dc_event_type_t {
DC_EVENT_WAITING = (1 << 0),
DC_EVENT_PROGRESS = (1 << 1),
DC_EVENT_DEVINFO = (1 << 2),
DC_EVENT_CLOCK = (1 << 3)
DC_EVENT_CLOCK = (1 << 3),
DC_EVENT_VENDOR = (1 << 4)
} dc_event_type_t;
typedef struct dc_device_t dc_device_t;
@ -57,6 +58,11 @@ typedef struct dc_event_clock_t {
dc_ticks_t systime;
} dc_event_clock_t;
typedef struct dc_event_vendor_t {
const unsigned char *data;
unsigned int size;
} dc_event_vendor_t;
typedef int (*dc_cancel_callback_t) (void *userdata);
typedef void (*dc_event_callback_t) (dc_device_t *device, dc_event_type_t event, const void *data, void *userdata);

View File

@ -358,6 +358,12 @@ atomics_cobalt_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac
progress.maximum = SZ_MEMORY + 2;
device_event_emit (abstract, DC_EVENT_PROGRESS, &progress);
// Emit a vendor event.
dc_event_vendor_t vendor;
vendor.data = device->version;
vendor.size = sizeof (device->version);
device_event_emit (abstract, DC_EVENT_VENDOR, &vendor);
// Emit a device info event.
dc_event_devinfo_t devinfo;
devinfo.model = array_uint16_le (device->version + 12);

View File

@ -368,6 +368,12 @@ mares_iconhd_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
progress.maximum = SZ_MEMORY;
device_event_emit (abstract, DC_EVENT_PROGRESS, &progress);
// Emit a vendor event.
dc_event_vendor_t vendor;
vendor.data = device->version;
vendor.size = sizeof (device->version);
device_event_emit (abstract, DC_EVENT_VENDOR, &vendor);
return mares_iconhd_read (device, 0, dc_buffer_get_data (buffer),
dc_buffer_get_size (buffer), &progress);
}

View File

@ -170,6 +170,12 @@ oceanic_common_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
return DC_STATUS_NOMEMORY;
}
// Emit a vendor event.
dc_event_vendor_t vendor;
vendor.data = device->version;
vendor.size = sizeof (device->version);
device_event_emit (abstract, DC_EVENT_VENDOR, &vendor);
return device_dump_read (abstract, dc_buffer_get_data (buffer),
dc_buffer_get_size (buffer), PAGESIZE * device->multipage);
}
@ -193,6 +199,12 @@ oceanic_common_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac
(layout->rb_logbook_end - layout->rb_logbook_begin);
device_event_emit (abstract, DC_EVENT_PROGRESS, &progress);
// Emit a vendor event.
dc_event_vendor_t vendor;
vendor.data = device->version;
vendor.size = sizeof (device->version);
device_event_emit (abstract, DC_EVENT_VENDOR, &vendor);
// Read the device id.
unsigned char id[PAGESIZE] = {0};
dc_status_t rc = dc_device_read (abstract, layout->cf_devinfo, id, sizeof (id));

View File

@ -266,6 +266,12 @@ reefnet_sensus_handshake (reefnet_sensus_device_t *device)
devinfo.serial = array_uint16_le (handshake + 6);
device_event_emit (&device->base, DC_EVENT_DEVINFO, &devinfo);
// Emit a vendor event.
dc_event_vendor_t vendor;
vendor.data = device->handshake;
vendor.size = sizeof (device->handshake);
device_event_emit (abstract, DC_EVENT_VENDOR, &vendor);
// Wait at least 10 ms to ensures the data line is
// clear before transmission from the host begins.

View File

@ -236,6 +236,12 @@ reefnet_sensuspro_handshake (reefnet_sensuspro_device_t *device)
devinfo.serial = array_uint16_le (handshake + 4);
device_event_emit (&device->base, DC_EVENT_DEVINFO, &devinfo);
// Emit a vendor event.
dc_event_vendor_t vendor;
vendor.data = device->handshake;
vendor.size = sizeof (device->handshake);
device_event_emit (abstract, DC_EVENT_VENDOR, &vendor);
serial_sleep (device->port, 10);
return DC_STATUS_SUCCESS;

View File

@ -305,6 +305,12 @@ reefnet_sensusultra_handshake (reefnet_sensusultra_device_t *device, unsigned sh
devinfo.serial = array_uint16_le (handshake + 2);
device_event_emit (&device->base, DC_EVENT_DEVINFO, &devinfo);
// Emit a vendor event.
dc_event_vendor_t vendor;
vendor.data = device->handshake;
vendor.size = sizeof (device->handshake);
device_event_emit (&device->base, DC_EVENT_VENDOR, &vendor);
// Send the instruction code to the device.
rc = reefnet_sensusultra_send_ushort (device, value);
if (rc != DC_STATUS_SUCCESS)

View File

@ -216,6 +216,12 @@ suunto_common2_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
return DC_STATUS_NOMEMORY;
}
// Emit a vendor event.
dc_event_vendor_t vendor;
vendor.data = device->version;
vendor.size = sizeof (device->version);
device_event_emit (abstract, DC_EVENT_VENDOR, &vendor);
return device_dump_read (abstract, dc_buffer_get_data (buffer),
dc_buffer_get_size (buffer), SZ_PACKET);
}
@ -240,6 +246,12 @@ suunto_common2_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac
8 + (SZ_MINIMUM > 4 ? SZ_MINIMUM : 4);
device_event_emit (abstract, DC_EVENT_PROGRESS, &progress);
// Emit a vendor event.
dc_event_vendor_t vendor;
vendor.data = device->version;
vendor.size = sizeof (device->version);
device_event_emit (abstract, DC_EVENT_VENDOR, &vendor);
// Read the serial number.
unsigned char serial[SZ_MINIMUM > 4 ? SZ_MINIMUM : 4] = {0};
dc_status_t rc = suunto_common2_device_read (abstract, layout->serial, serial, sizeof (serial));