Skip incomplete dives.

We received an interesting case of a dive computer whose battery died
during a dive. Apparantly the device recorded some samples, but failed
to terminate the dive properly. In the linked list, the next pointer of
this dive points to itself, which is obviously an invalid value.

I suspect the device initializes the next pointer to point to itself at
the start of a new dive, and updates it again with the correct value
once the dive has finished. But due to the battery failure, that last
step never happened.

Anyway, since we are traversing the linked list backwards, we don't need
the next pointer, and we can simply skip the incomplete dive. The error
is not returned immediately anymore, but delayed until the end of the
download.
This commit is contained in:
Steve Buie 2011-10-09 21:17:32 +02:00 committed by Jef Driesen
parent 649d5e28df
commit b7a6be15ca

View File

@ -236,6 +236,9 @@ suunto_common2_device_foreach (device_t *abstract, dive_callback_t callback, voi
const suunto_common2_layout_t *layout = device->layout;
// Error status for delayed errors.
device_status_t status = DEVICE_STATUS_SUCCESS;
// Enable progress notifications.
device_progress_t progress = DEVICE_PROGRESS_INITIALIZER;
progress.maximum = layout->rb_profile_end - layout->rb_profile_begin +
@ -404,32 +407,37 @@ suunto_common2_device_foreach (device_t *abstract, dive_callback_t callback, voi
free (data);
return DEVICE_STATUS_ERROR;
}
if (next != previous) {
if (next != previous && next != current) {
WARNING ("Profiles are not continuous.");
free (data);
return DEVICE_STATUS_ERROR;
}
if (next != current) {
unsigned int fp_offset = FP_OFFSET;
if (devinfo.model == 0x15)
fp_offset += 6; // HelO2
if (memcmp (p + fp_offset, device->fingerprint, sizeof (device->fingerprint)) == 0) {
free (data);
return DEVICE_STATUS_SUCCESS;
}
if (callback && !callback (p + 4, size - 4, p + fp_offset, sizeof (device->fingerprint), userdata)) {
free (data);
return DEVICE_STATUS_SUCCESS;
}
} else {
WARNING ("Skipping incomplete dive.");
status = DEVICE_STATUS_ERROR;
}
// Next dive.
previous = current;
current = prev;
unsigned int fp_offset = FP_OFFSET;
if (devinfo.model == 0x15)
fp_offset += 6; // HelO2
if (memcmp (p + fp_offset, device->fingerprint, sizeof (device->fingerprint)) == 0) {
free (data);
return DEVICE_STATUS_SUCCESS;
}
if (callback && !callback (p + 4, size - 4, p + fp_offset, sizeof (device->fingerprint), userdata)) {
free (data);
return DEVICE_STATUS_SUCCESS;
}
}
free (data);
return DEVICE_STATUS_SUCCESS;
return status;
}