Improve the detection of an empty logbook ringbuffer.
Some devices do not appear to set the ringbuffer pointers to their normal empty values (e.g. pointing outside the ringbuffer memory). In that case, there appears to be a single entry. But since that entry contains uninitialized memory (e.g. all 0xFF bytes), we are able to detect this special situation.
This commit is contained in:
parent
a65e9d56c5
commit
043be07af4
12
src/array.c
12
src/array.c
@ -50,6 +50,18 @@ array_reverse_bits (unsigned char data[], unsigned int size)
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
array_isequal (const unsigned char data[], unsigned int size, unsigned char value)
|
||||
{
|
||||
for (unsigned int i = 0; i < size; ++i) {
|
||||
if (data[i] != value)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
unsigned int
|
||||
array_uint32_be (const unsigned char data[])
|
||||
{
|
||||
|
||||
@ -32,6 +32,9 @@ array_reverse_bytes (unsigned char data[], unsigned int size);
|
||||
void
|
||||
array_reverse_bits (unsigned char data[], unsigned int size);
|
||||
|
||||
int
|
||||
array_isequal (const unsigned char data[], unsigned int size, unsigned char value);
|
||||
|
||||
unsigned int
|
||||
array_uint32_be (const unsigned char data[]);
|
||||
|
||||
|
||||
@ -306,6 +306,17 @@ oceanic_common_device_foreach (oceanic_common_device_t *device, const oceanic_co
|
||||
// Move to the start of the current entry.
|
||||
current -= PAGESIZE / 2;
|
||||
|
||||
// Check for uninitialized entries. Normally, such entries are
|
||||
// never present, except when the ringbuffer is actually empty,
|
||||
// but the ringbuffer pointers are not set to their empty values.
|
||||
// This appears to happen on some devices, and we attempt to
|
||||
// fix this here.
|
||||
if (array_isequal (logbooks + current, PAGESIZE / 2, 0xFF)) {
|
||||
begin = current + PAGESIZE / 2;
|
||||
abort = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
// Compare the fingerprint to identify previously downloaded entries.
|
||||
if (memcmp (logbooks + current, device->fingerprint, PAGESIZE / 2) == 0) {
|
||||
begin = current + PAGESIZE / 2;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user