From 9f13949bd4b9d33029d9eb7276bf37da3dae1da3 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Wed, 10 Dec 2008 13:09:29 +0000 Subject: [PATCH] Added a function to calibrate the interface. --- examples/oceanic_vtpro_test.c | 9 ++++++++ src/libdivecomputer.symbols | 1 + src/oceanic_vtpro.c | 43 +++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/examples/oceanic_vtpro_test.c b/examples/oceanic_vtpro_test.c index 2931193..c1e8005 100644 --- a/examples/oceanic_vtpro_test.c +++ b/examples/oceanic_vtpro_test.c @@ -51,6 +51,15 @@ 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 5253a6a..9ff0372 100644 --- a/src/libdivecomputer.symbols +++ b/src/libdivecomputer.symbols @@ -34,6 +34,7 @@ oceanic_veo250_device_open oceanic_veo250_device_keepalive oceanic_vtpro_device_open oceanic_vtpro_device_keepalive +oceanic_vtpro_device_calibrate reefnet_sensuspro_device_open reefnet_sensuspro_device_set_timestamp reefnet_sensuspro_device_write_interval diff --git a/src/oceanic_vtpro.c b/src/oceanic_vtpro.c index f5a5388..1a72b9e 100644 --- a/src/oceanic_vtpro.c +++ b/src/oceanic_vtpro.c @@ -332,6 +332,49 @@ 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] != 0x5A || 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) {