From ff26c2db706e561ca3ca712b47906fec9fcf5563 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Wed, 27 May 2009 10:24:04 +0000 Subject: [PATCH] Calibrate the device during initialization. Although calibration is optional, it's highly recommended because it reduces the transfer time considerably. The calibrate function is removed from the public api. --- examples/oceanic_vtpro_test.c | 9 ---- src/libdivecomputer.symbols | 1 - src/oceanic_vtpro.c | 81 ++++++++++++++++------------------- src/oceanic_vtpro.h | 3 -- 4 files changed, 38 insertions(+), 56 deletions(-) diff --git a/examples/oceanic_vtpro_test.c b/examples/oceanic_vtpro_test.c index 68789d0..3352555 100644 --- a/examples/oceanic_vtpro_test.c +++ b/examples/oceanic_vtpro_test.c @@ -42,15 +42,6 @@ test_dump_memory (const char* name, const char* filename) return rc; } - message ("oceanic_vtpro_device_calibrate\n"); - unsigned char calibration = 0; - rc = oceanic_vtpro_device_calibrate (device, &calibration, 1); - if (rc != DEVICE_STATUS_SUCCESS) { - WARNING ("Cannot calibrate computer."); - device_close (device); - return rc; - } - message ("device_read\n"); rc = device_read (device, 0x00, data, sizeof (data)); if (rc != DEVICE_STATUS_SUCCESS) { diff --git a/src/libdivecomputer.symbols b/src/libdivecomputer.symbols index 0f4dd29..053819a 100644 --- a/src/libdivecomputer.symbols +++ b/src/libdivecomputer.symbols @@ -42,7 +42,6 @@ oceanic_veo250_device_open oceanic_veo250_device_keepalive oceanic_vtpro_device_open oceanic_vtpro_device_keepalive -oceanic_vtpro_device_calibrate reefnet_sensus_device_open reefnet_sensus_device_set_timestamp reefnet_sensus_device_get_handshake diff --git a/src/oceanic_vtpro.c b/src/oceanic_vtpro.c index 7180628..9ee198a 100644 --- a/src/oceanic_vtpro.c +++ b/src/oceanic_vtpro.c @@ -219,6 +219,39 @@ oceanic_vtpro_quit (oceanic_vtpro_device_t *device) } +static device_status_t +oceanic_vtpro_calibrate (oceanic_vtpro_device_t *device) +{ + // Send the command to the dive computer. + unsigned char command[2] = {0x18, 0x00}; + device_status_t rc = oceanic_vtpro_send (device, command, sizeof (command)); + if (rc != DEVICE_STATUS_SUCCESS) { + WARNING ("Failed to send the command."); + return rc; + } + + // Receive the answer of the dive computer. The timeout + // is temporary increased, because the device needs + // approximately 6 seconds to respond. + unsigned char answer[3] = {0}; + serial_set_timeout (device->port, 9000); + int n = serial_read (device->port, answer, sizeof (answer)); + serial_set_timeout (device->port, 3000); + if (n != sizeof (answer)) { + WARNING ("Failed to receive the answer."); + return EXITCODE (n); + } + + // Verify the answer. + if (answer[0] != ACK || answer[2] != 0x00) { + WARNING ("Unexpected answer byte(s)."); + return DEVICE_STATUS_PROTOCOL; + } + + return DEVICE_STATUS_SUCCESS; +} + + device_status_t oceanic_vtpro_device_open (device_t **out, const char* name) { @@ -287,6 +320,11 @@ oceanic_vtpro_device_open (device_t **out, const char* name) // the user), or already in download mode. oceanic_vtpro_device_version ((device_t *) device, device->version, sizeof (device->version)); + // Calibrate the device. Although calibration is optional, it's highly + // recommended because it reduces the transfer time considerably, even + // when processing the command itself is quite slow. + oceanic_vtpro_calibrate (device); + *out = (device_t*) device; return DEVICE_STATUS_SUCCESS; @@ -362,49 +400,6 @@ oceanic_vtpro_device_keepalive (device_t *abstract) } -device_status_t -oceanic_vtpro_device_calibrate (device_t *abstract, unsigned char data[], unsigned int size) -{ - oceanic_vtpro_device_t *device = (oceanic_vtpro_device_t*) abstract; - - if (! device_is_oceanic_vtpro (abstract)) - return DEVICE_STATUS_TYPE_MISMATCH; - - if (size < 1) - return DEVICE_STATUS_MEMORY; - - // Send the command to the dive computer. - unsigned char command[2] = {0x18, 0x00}; - device_status_t rc = oceanic_vtpro_send (device, command, sizeof (command)); - if (rc != DEVICE_STATUS_SUCCESS) { - WARNING ("Failed to send the command."); - return rc; - } - - // Receive the answer of the dive computer. The timeout - // is temporary increased, because the device needs - // approximately 6 seconds to respond. - unsigned char answer[3] = {0}; - serial_set_timeout (device->port, 9000); - int n = serial_read (device->port, answer, sizeof (answer)); - serial_set_timeout (device->port, 3000); - if (n != sizeof (answer)) { - WARNING ("Failed to receive the answer."); - return EXITCODE (n); - } - - // Verify the answer. - if (answer[0] != ACK || answer[2] != 0x00) { - WARNING ("Unexpected answer byte(s)."); - return DEVICE_STATUS_PROTOCOL; - } - - memcpy (data, answer + 1, 1); - - return DEVICE_STATUS_SUCCESS; -} - - static device_status_t oceanic_vtpro_device_version (device_t *abstract, unsigned char data[], unsigned int size) { diff --git a/src/oceanic_vtpro.h b/src/oceanic_vtpro.h index 892829f..6669fc7 100644 --- a/src/oceanic_vtpro.h +++ b/src/oceanic_vtpro.h @@ -37,9 +37,6 @@ oceanic_vtpro_device_open (device_t **device, const char* name); device_status_t oceanic_vtpro_device_keepalive (device_t *device); -device_status_t -oceanic_vtpro_device_calibrate (device_t *abstract, unsigned char data[], unsigned int size); - #ifdef __cplusplus } #endif /* __cplusplus */