From f80024ed59068bab35e8f0ed321ca1b134a6714e Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Fri, 7 Sep 2018 16:15:21 -0700 Subject: [PATCH] Shearwater: detect which logbook format is support RDBI response tells us which format the dive computer supports. Shearwater recommends to use the 'Petrel Native Format' for all dive computers which support it, even those pre-Teric models which (depending on firmware) might support both PNF and the older 'Predator-Like Format'. They also recommend to ignore the 0x90...... format which is very similar to PNF but without the final record and to use the older Predator Like Format in that case. Which format we use is determined by the base address used to download the logbook entries. Signed-off-by: Dirk Hohndel --- src/shearwater_common.h | 1 + src/shearwater_petrel.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/shearwater_common.h b/src/shearwater_common.h index 8798853..73911a5 100644 --- a/src/shearwater_common.h +++ b/src/shearwater_common.h @@ -32,6 +32,7 @@ extern "C" { #define ID_SERIAL 0x8010 #define ID_FIRMWARE 0x8011 +#define ID_RDBI 0x8021 #define ID_HARDWARE 0x8050 #define PREDATOR 2 diff --git a/src/shearwater_petrel.c b/src/shearwater_petrel.c index e000ec2..4307eac 100644 --- a/src/shearwater_petrel.c +++ b/src/shearwater_petrel.c @@ -255,6 +255,37 @@ shearwater_petrel_device_foreach (dc_device_t *abstract, dc_dive_callback_t call devinfo.serial = array_uint32_be (serial); device_event_emit (abstract, DC_EVENT_DEVINFO, &devinfo); + // Read the logbook type + rc = shearwater_common_identifier (&device->base, buffer, ID_RDBI); + if (rc != DC_STATUS_SUCCESS) { + ERROR (abstract->context, "Failed to read the logbook type."); + dc_buffer_free (buffer); + dc_buffer_free (manifests); + return rc; + } + unsigned int base_addr = array_uint_be (dc_buffer_get_data (buffer), dc_buffer_get_size (buffer)); + base_addr &= 0xFF000000u; + switch (base_addr) { + case 0xDD000000: // Predator or Predator-Like Format + // on a Predator, use the old format, otherwise use the Predator-Like Format (what we called Petrel so far) + if (model != PREDATOR) + base_addr = 0xC0000000; + break; + case 0x90000000: // some firmware versions supported an earlier version of PNF without final record + // use the Predator-Like Format instead + base_addr = 0xC0000000; + break; + case 0x80000000: // new Petrel Native Format with final record + // that's the correct address + break; + default: // unknown format + ERROR (abstract->context, "Unknown logbook format %08x", base_addr); + dc_buffer_free (buffer); + dc_buffer_free (manifests); + return DC_STATUS_UNSUPPORTED; + } + + // Read the manifest pages while (1) { // Update the progress state. // Assume the worst case scenario of a full manifest, and adjust the