From 1d235daf307f160ede20d2962e9a799954df00f4 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Tue, 18 Feb 2020 19:47:41 +0100 Subject: [PATCH 1/5] Skip the BLE handshake for the Pro Plus X The Oceanic Pro Plus X does not seem to understand the BLE handshake command. It just fails with a NAK byte (0xA5) as response. --- src/oceanic_atom2.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/oceanic_atom2.c b/src/oceanic_atom2.c index 0ed9a0d..342cb9e 100644 --- a/src/oceanic_atom2.c +++ b/src/oceanic_atom2.c @@ -920,7 +920,8 @@ oceanic_atom2_device_open (dc_device_t **out, dc_context_t *context, dc_iostream goto error_free; } - if (dc_iostream_get_transport (device->iostream) == DC_TRANSPORT_BLE) { + if (dc_iostream_get_transport (device->iostream) == DC_TRANSPORT_BLE && + model != PROPLUSX) { status = oceanic_atom2_ble_handshake(device); if (status != DC_STATUS_SUCCESS) { goto error_free; From f93b2afcc895a2c04c5624142fbc33856c04e286 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Tue, 18 Feb 2020 22:13:07 +0100 Subject: [PATCH 2/5] Improve the empty logbook ringbuffer detection If all the entries in the logbook ringbuffer happen to be empty, the ringbuffer end pointer will not have a valid value. Creating the ringbuffer stream will fail, and an error will be returned to the caller. Fixed by adding an extra check, and exit if there are no dives. --- src/oceanic_common.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/oceanic_common.c b/src/oceanic_common.c index 4a42300..728101f 100644 --- a/src/oceanic_common.c +++ b/src/oceanic_common.c @@ -417,6 +417,11 @@ oceanic_common_device_profile (dc_device_t *abstract, dc_event_progress_t *progr progress->maximum -= (layout->rb_profile_end - layout->rb_profile_begin) - rb_profile_size; device_event_emit (abstract, DC_EVENT_PROGRESS, progress); + // Exit if there are no dives. + if (rb_profile_size == 0) { + return DC_STATUS_SUCCESS; + } + // Create the ringbuffer stream. dc_rbstream_t *rbstream = NULL; rc = dc_rbstream_new (&rbstream, abstract, PAGESIZE, PAGESIZE * device->multipage, layout->rb_profile_begin, layout->rb_profile_end, rb_profile_end); From 39aad6bb52d4ed6e8d5c224798f4f471d90a9f19 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Tue, 18 Feb 2020 22:17:12 +0100 Subject: [PATCH 3/5] Report an error for invalid ringbuffer pointers Previously, invalid ringbuffer pointers were always handled during the second pass. But that changed after the previous commit. If the invalid pointer is located in the first logbook entry, this is now handled as "no dives present". Fixed by returning the correct error code instead. --- src/oceanic_common.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/oceanic_common.c b/src/oceanic_common.c index 728101f..48ed61a 100644 --- a/src/oceanic_common.c +++ b/src/oceanic_common.c @@ -330,6 +330,7 @@ dc_status_t oceanic_common_device_profile (dc_device_t *abstract, dc_event_progress_t *progress, dc_buffer_t *logbook, dc_dive_callback_t callback, void *userdata) { oceanic_common_device_t *device = (oceanic_common_device_t *) abstract; + dc_status_t status = DC_STATUS_SUCCESS; dc_status_t rc = DC_STATUS_SUCCESS; assert (device != NULL); @@ -379,6 +380,7 @@ oceanic_common_device_profile (dc_device_t *abstract, dc_event_progress_t *progr { ERROR (abstract->context, "Invalid ringbuffer pointer detected (0x%06x 0x%06x).", rb_entry_first, rb_entry_last); + status = DC_STATUS_DATAFORMAT; break; } @@ -419,7 +421,7 @@ oceanic_common_device_profile (dc_device_t *abstract, dc_event_progress_t *progr // Exit if there are no dives. if (rb_profile_size == 0) { - return DC_STATUS_SUCCESS; + return status; } // Create the ringbuffer stream. From 8fb0f1ca94c2c95c232583cc807a28c95c2c229a Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Tue, 18 Feb 2020 22:38:50 +0100 Subject: [PATCH 4/5] Clear the buffer if no dives are present Due to how the Oceanic ringbuffer is implemented, the ringbuffer always contains at least one entry. If there are no dives recorded yet, the content of that entry will be empty. Such entries are already ignored during processing, but instead of returning this empty entry to the caller, simply clear the logbook buffer, and return no entries at all. --- src/oceanic_common.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/oceanic_common.c b/src/oceanic_common.c index 48ed61a..817e3e2 100644 --- a/src/oceanic_common.c +++ b/src/oceanic_common.c @@ -281,6 +281,7 @@ oceanic_common_device_logbook (dc_device_t *abstract, dc_event_progress_t *progr // entries first. If an already downloaded entry is identified (by means // of its fingerprint), the transfer is aborted immediately to reduce // the transfer time. + unsigned int count = 0; unsigned int nbytes = 0; unsigned int offset = rb_logbook_size; while (nbytes < rb_logbook_size) { @@ -312,13 +313,19 @@ oceanic_common_device_logbook (dc_device_t *abstract, dc_event_progress_t *progr offset += layout->rb_logbook_entry_size; break; } + + count++; } // Update and emit a progress event. progress->maximum -= rb_logbook_size - nbytes; device_event_emit (abstract, DC_EVENT_PROGRESS, progress); - dc_buffer_slice (logbook, offset, rb_logbook_size - offset); + if (count) { + dc_buffer_slice (logbook, offset, rb_logbook_size - offset); + } else { + dc_buffer_clear (logbook); + } dc_rbstream_free (rbstream); From 8a1d32d319eaa62a550c07349ef16f8dcb923931 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Tue, 25 Feb 2020 21:18:19 +0100 Subject: [PATCH 5/5] Pass infinite NDL values to the application When the last deco stop is cleared, the dive computer switches to NDL mode with an infinite time (0x7FFF for APOS4 and 0xFFFF for APOS3). But because libdivecomputer does not report those infinite values to the application, detecting the end of the deco phase is not very intuitive. This issue is fixed by passing those infinite NDL values as-is to the application, despite the relative large values (respectively 9.1 and 18.2 hours). For reference, the finite NDL values reported by the ratio dive computers can be large as well, with values up to 0x4000 (4.55 hours). --- src/divesystem_idive_parser.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/divesystem_idive_parser.c b/src/divesystem_idive_parser.c index 7325b0b..b8d103d 100644 --- a/src/divesystem_idive_parser.c +++ b/src/divesystem_idive_parser.c @@ -477,28 +477,20 @@ divesystem_idive_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba decostop = array_uint16_le (data + offset + 21); decotime = array_uint16_le (data + offset + 23); tts = array_uint16_le (data + offset + 25); - if (tts == 0x7FFF) { - tts = INVALID; - } } else { decostop = array_uint16_le (data + offset + 21); tts = array_uint16_le (data + offset + 23); - if (tts == 0xFFFF) { - tts = INVALID; - } } - if (tts != INVALID) { - if (decostop) { - sample.deco.type = DC_DECO_DECOSTOP; - sample.deco.depth = decostop / 10.0; - sample.deco.time = apos4 ? decotime : tts; - } else { - sample.deco.type = DC_DECO_NDL; - sample.deco.depth = 0.0; - sample.deco.time = tts; - } - if (callback) callback (DC_SAMPLE_DECO, sample, userdata); + if (decostop) { + sample.deco.type = DC_DECO_DECOSTOP; + sample.deco.depth = decostop / 10.0; + sample.deco.time = apos4 ? decotime : tts; + } else { + sample.deco.type = DC_DECO_NDL; + sample.deco.depth = 0.0; + sample.deco.time = tts; } + if (callback) callback (DC_SAMPLE_DECO, sample, userdata); // CNS unsigned int cns = array_uint16_le (data + offset + 29);