Shearwater: skip deleted dives

Without this change a deleted dive on device is treated like the end of the
dive list.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2018-09-07 15:12:12 -07:00
parent a9c582e26f
commit ec0029c4ce

View File

@ -275,11 +275,17 @@ shearwater_petrel_device_foreach (dc_device_t *abstract, dc_dive_callback_t call
unsigned int size = dc_buffer_get_size (buffer);
// Process the records in the manifest.
unsigned int count = 0;
unsigned int count = 0, deleted = 0;
unsigned int offset = 0;
while (offset < size) {
// Check for a valid dive header.
unsigned int header = array_uint16_be (data + offset);
if (header == 0x5A23) {
// this is a deleted dive; keep looking
offset += RECORD_SIZE;
deleted++;
continue;
}
if (header != 0xA5C4)
break;
@ -293,7 +299,7 @@ shearwater_petrel_device_foreach (dc_device_t *abstract, dc_dive_callback_t call
// Update the progress state.
current += 1;
maximum -= RECORD_COUNT - count;
maximum -= RECORD_COUNT - count - deleted;
// Append the manifest records to the main buffer.
if (!dc_buffer_append (manifests, data, count * RECORD_SIZE)) {
@ -304,7 +310,7 @@ shearwater_petrel_device_foreach (dc_device_t *abstract, dc_dive_callback_t call
}
// Stop downloading manifest if there are no more records.
if (count != RECORD_COUNT)
if (count + deleted != RECORD_COUNT)
break;
}
@ -319,6 +325,11 @@ shearwater_petrel_device_foreach (dc_device_t *abstract, dc_dive_callback_t call
unsigned int offset = 0;
while (offset < size) {
// skip deleted dives
if (array_uint16_be(data + offset) == 0x5A23) {
offset += RECORD_SIZE;
continue;
}
// Get the address of the dive.
unsigned int address = array_uint32_be (data + offset + 20);