Shearwater: fix incorrect parsing of base address

I misunderstood the way the helper function worked. Thanks Jef for
pointing it out. The way I wrote the code we ended up doing undefined
shifts which explains why the data I got back seemed so random.

With this we should be able to simply act on the four known values for
the base address, with 0xDD000000 never an option by the time you got
here - but in the old code (prior to the PNF addition) we would have
fallen back to 0xC0000000, so let's do the same here.

Any other value is actually an unknown format and should be treated as
such.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2018-09-25 12:44:01 -07:00
parent 91766d1ed0
commit 32d62d6269

View File

@ -262,15 +262,11 @@ shearwater_petrel_device_foreach (dc_device_t *abstract, dc_dive_callback_t call
dc_buffer_free (manifests);
return rc;
}
unsigned int base_addr = array_uint_be (dc_buffer_get_data (buffer), dc_buffer_get_size (buffer));
unsigned int base_addr = array_uint32_be (dc_buffer_get_data (buffer) + 1);
INFO(abstract->context, "RDBI command completed with %d bytes, evaluated as %08x", (int) dc_buffer_get_size (buffer), base_addr);
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 = 0xC0000000u;
break;
case 0xDD000000: // Predator - we shouldn't get here, we could give up or we can try 0xC0000000
case 0xC0000000: // Predator-Like Format (what we used to call the Petrel format)
case 0x90000000: // some firmware versions supported an earlier version of PNF without final record
// use the Predator-Like Format instead
base_addr = 0xC0000000u;
@ -279,11 +275,10 @@ shearwater_petrel_device_foreach (dc_device_t *abstract, dc_dive_callback_t call
// that's the correct address
break;
default: // unknown format
// use the defaults for the models
if (model >= TERIC)
base_addr = 0x80000000u;
else
base_addr = 0xC0000000u;
ERROR (abstract->context, "Unknown logbook download format.");
dc_buffer_free (buffer);
dc_buffer_free (manifests);
return DC_STATUS_DATAFORMAT;
}
// Read the manifest pages