Read the version info when opening the connection.

The d9 backend already reads the version info, to autodetect the
protocol variant. When doing the same in the vyper2 backend, we don't
have to read the version info again when downloading the dives.
This commit is contained in:
Jef Driesen 2012-12-07 10:25:24 +01:00
parent fcc07a5f6d
commit 45e9c08e92
4 changed files with 17 additions and 20 deletions

View File

@ -51,6 +51,7 @@ suunto_common2_device_init (suunto_common2_device_t *device, dc_context_t *conte
// Set the default values.
device->layout = NULL;
memset (device->version, 0, sizeof (device->version));
memset (device->fingerprint, 0, sizeof (device->fingerprint));
}
@ -236,24 +237,12 @@ suunto_common2_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac
// Enable progress notifications.
dc_event_progress_t progress = EVENT_PROGRESS_INITIALIZER;
progress.maximum = layout->rb_profile_end - layout->rb_profile_begin +
8 + SZ_VERSION + (SZ_MINIMUM > 4 ? SZ_MINIMUM : 4);
device_event_emit (abstract, DC_EVENT_PROGRESS, &progress);
// Read the version info.
unsigned char version[SZ_VERSION] = {0};
dc_status_t rc = suunto_common2_device_version (abstract, version, sizeof (version));
if (rc != DC_STATUS_SUCCESS) {
ERROR (abstract->context, "Failed to read the memory header.");
return rc;
}
// Update and emit a progress event.
progress.current += sizeof (version);
8 + (SZ_MINIMUM > 4 ? SZ_MINIMUM : 4);
device_event_emit (abstract, DC_EVENT_PROGRESS, &progress);
// Read the serial number.
unsigned char serial[SZ_MINIMUM > 4 ? SZ_MINIMUM : 4] = {0};
rc = suunto_common2_device_read (abstract, layout->serial, serial, sizeof (serial));
dc_status_t rc = suunto_common2_device_read (abstract, layout->serial, serial, sizeof (serial));
if (rc != DC_STATUS_SUCCESS) {
ERROR (abstract->context, "Failed to read the memory header.");
return rc;
@ -265,8 +254,8 @@ suunto_common2_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac
// Emit a device info event.
dc_event_devinfo_t devinfo;
devinfo.model = version[0];
devinfo.firmware = array_uint24_be (version + 1);
devinfo.model = device->version[0];
devinfo.firmware = array_uint24_be (device->version + 1);
devinfo.serial = array_uint32_be (serial);
device_event_emit (abstract, DC_EVENT_DEVINFO, &devinfo);

View File

@ -41,6 +41,7 @@ typedef struct suunto_common2_layout_t {
typedef struct suunto_common2_device_t {
dc_device_t base;
const suunto_common2_layout_t *layout;
unsigned char version[4];
unsigned char fingerprint[7];
} suunto_common2_device_t;

View File

@ -45,7 +45,6 @@
typedef struct suunto_d9_device_t {
suunto_common2_device_t base;
serial_t *port;
unsigned char version[4];
} suunto_d9_device_t;
static dc_status_t suunto_d9_device_packet (dc_device_t *abstract, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize, unsigned int size);
@ -114,7 +113,7 @@ suunto_d9_device_autodetect (suunto_d9_device_t *device, unsigned int model)
}
// Try reading the version info.
status = suunto_common2_device_version ((dc_device_t *) device, device->version, sizeof (device->version));
status = suunto_common2_device_version ((dc_device_t *) device, device->base.version, sizeof (device->base.version));
if (status == DC_STATUS_SUCCESS)
break;
}
@ -141,7 +140,6 @@ suunto_d9_device_open (dc_device_t **out, dc_context_t *context, const char *nam
// Set the default values.
device->port = NULL;
memset (device->version, 0, sizeof (device->version));
// Open the device.
int rc = serial_open (&device->port, context, name);
@ -192,7 +190,7 @@ suunto_d9_device_open (dc_device_t **out, dc_context_t *context, const char *nam
}
// Override the base class values.
model = device->version[0];
model = device->base.version[0];
if (model == D4i || model == D6i || model == D9tx)
device->base.layout = &suunto_d9tx_layout;
else

View File

@ -134,6 +134,15 @@ suunto_vyper2_device_open (dc_device_t **out, dc_context_t *context, const char
// Enable half-duplex emulation.
serial_set_halfduplex (device->port, 1);
// Read the version info.
dc_status_t status = suunto_common2_device_version ((dc_device_t *) device, device->base.version, sizeof (device->base.version));
if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to read the version info.");
serial_close (device->port);
free (device);
return status;
}
// Override the base class values.
device->base.layout = &suunto_vyper2_layout;