Make the empty/full ringbuffer interpretation configurable.
In a ringbuffer implementation with only two begin/end pointers, it's impossible to distinguish between an empty and a full ringbuffer. The correct interpretation mode needs to be specified by the user.
This commit is contained in:
parent
c4931623b6
commit
a6f9df16ac
@ -31,10 +31,10 @@
|
||||
|
||||
#define PAGESIZE 0x10
|
||||
|
||||
#define RB_LOGBOOK_DISTANCE(a,b,l) ringbuffer_distance (a, b, l->rb_logbook_begin, l->rb_logbook_end)
|
||||
#define RB_LOGBOOK_DISTANCE(a,b,l) ringbuffer_distance (a, b, 0, l->rb_logbook_begin, l->rb_logbook_end)
|
||||
#define RB_LOGBOOK_INCR(a,b,l) ringbuffer_increment (a, b, l->rb_logbook_begin, l->rb_logbook_end)
|
||||
|
||||
#define RB_PROFILE_DISTANCE(a,b,l) ringbuffer_distance (a, b, l->rb_profile_begin, l->rb_profile_end)
|
||||
#define RB_PROFILE_DISTANCE(a,b,l) ringbuffer_distance (a, b, 0, l->rb_profile_begin, l->rb_profile_end)
|
||||
#define RB_PROFILE_INCR(a,b,l) ringbuffer_increment (a, b, l->rb_profile_begin, l->rb_profile_end)
|
||||
|
||||
|
||||
|
||||
@ -32,12 +32,14 @@ normalize (unsigned int a, unsigned int size)
|
||||
|
||||
|
||||
static unsigned int
|
||||
distance (unsigned int a, unsigned int b, unsigned int size)
|
||||
distance (unsigned int a, unsigned int b, int mode, unsigned int size)
|
||||
{
|
||||
if (a <= b) {
|
||||
if (a < b) {
|
||||
return (b - a) % size;
|
||||
} else {
|
||||
} else if (a > b) {
|
||||
return size - (a - b) % size;
|
||||
} else {
|
||||
return (mode == 0 ? 0 : size);
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,12 +73,12 @@ ringbuffer_normalize (unsigned int a, unsigned int begin, unsigned int end)
|
||||
|
||||
|
||||
unsigned int
|
||||
ringbuffer_distance (unsigned int a, unsigned int b, unsigned int begin, unsigned int end)
|
||||
ringbuffer_distance (unsigned int a, unsigned int b, int mode, unsigned int begin, unsigned int end)
|
||||
{
|
||||
assert (end >= begin);
|
||||
assert (a >= begin);
|
||||
|
||||
return distance (a, b, end - begin);
|
||||
return distance (a, b, mode, end - begin);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ unsigned int
|
||||
ringbuffer_normalize (unsigned int a, unsigned int begin, unsigned int end);
|
||||
|
||||
unsigned int
|
||||
ringbuffer_distance (unsigned int a, unsigned int b, unsigned int begin, unsigned int end);
|
||||
ringbuffer_distance (unsigned int a, unsigned int b, int mode, unsigned int begin, unsigned int end);
|
||||
|
||||
unsigned int
|
||||
ringbuffer_increment (unsigned int a, unsigned int delta, unsigned int begin, unsigned int end);
|
||||
|
||||
@ -27,7 +27,7 @@
|
||||
#include "ringbuffer.h"
|
||||
#include "array.h"
|
||||
|
||||
#define RB_PROFILE_DISTANCE(a,b,l) ringbuffer_distance (a, b, l->rb_profile_begin, l->rb_profile_end)
|
||||
#define RB_PROFILE_DISTANCE(a,b,l) ringbuffer_distance (a, b, 0, l->rb_profile_begin, l->rb_profile_end)
|
||||
#define RB_PROFILE_PEEK(a,l) ringbuffer_decrement (a, l->peek, l->rb_profile_begin, l->rb_profile_end)
|
||||
|
||||
void
|
||||
|
||||
@ -39,7 +39,7 @@
|
||||
|
||||
#define RB_PROFILE_BEGIN 0x019A
|
||||
#define RB_PROFILE_END SZ_MEMORY - 2
|
||||
#define RB_PROFILE_DISTANCE(a,b) ringbuffer_distance (a, b, RB_PROFILE_BEGIN, RB_PROFILE_END)
|
||||
#define RB_PROFILE_DISTANCE(a,b) ringbuffer_distance (a, b, 0, RB_PROFILE_BEGIN, RB_PROFILE_END)
|
||||
|
||||
#define BACKEND(abstract) ((suunto_common2_device_backend_t *) abstract->backend)
|
||||
|
||||
|
||||
@ -325,7 +325,7 @@ suunto_solution_extract_dives (device_t *abstract, const unsigned char data[], u
|
||||
// to find the start of the current dive.
|
||||
unsigned int peek = ringbuffer_increment (current, 2, RB_PROFILE_BEGIN, RB_PROFILE_END);
|
||||
if (data[peek] == 0x80) {
|
||||
unsigned int len = ringbuffer_distance (previous, current, RB_PROFILE_BEGIN, RB_PROFILE_END);
|
||||
unsigned int len = ringbuffer_distance (previous, current, 0, RB_PROFILE_BEGIN, RB_PROFILE_END);
|
||||
|
||||
if (callback && !callback (buffer + idx, len, userdata))
|
||||
return DEVICE_STATUS_SUCCESS;
|
||||
|
||||
@ -40,7 +40,7 @@
|
||||
#define RB_PROFILE_BEGIN 0x000
|
||||
#define RB_PROFILE_END 0x600
|
||||
#define RB_PROFILE_NEXT(a) ringbuffer_increment (a, 1, RB_PROFILE_BEGIN, RB_PROFILE_END)
|
||||
#define RB_PROFILE_DISTANCE(a,b) ringbuffer_distance (a, b, RB_PROFILE_BEGIN, RB_PROFILE_END)
|
||||
#define RB_PROFILE_DISTANCE(a,b) ringbuffer_distance (a, b, 0, RB_PROFILE_BEGIN, RB_PROFILE_END)
|
||||
|
||||
#define HEADER 4
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user