Defined a few macros for the ringbuffer code.
This commit is contained in:
parent
e4ab71db47
commit
0f625f601f
@ -17,7 +17,9 @@
|
|||||||
message ("%s:%d: %s\n", __FILE__, __LINE__, expr); \
|
message ("%s:%d: %s\n", __FILE__, __LINE__, expr); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DISTANCE(a,b) ringbuffer_distance (a, b, 0x019A, SUUNTO_D9_MEMORY_SIZE - 2)
|
#define RB_PROFILE_BEGIN 0x019A
|
||||||
|
#define RB_PROFILE_END SUUNTO_D9_MEMORY_SIZE - 2
|
||||||
|
#define RB_PROFILE_DISTANCE(a,b) ringbuffer_distance (a, b, RB_PROFILE_BEGIN, RB_PROFILE_END)
|
||||||
|
|
||||||
struct d9 {
|
struct d9 {
|
||||||
struct serial *port;
|
struct serial *port;
|
||||||
@ -357,11 +359,11 @@ suunto_d9_read_dives (d9 *device, dive_callback_t callback, void *userdata)
|
|||||||
|
|
||||||
// Memory buffer to store all the dives.
|
// Memory buffer to store all the dives.
|
||||||
|
|
||||||
unsigned char data[SUUNTO_D9_MEMORY_SIZE - 0x019A - 2] = {0};
|
unsigned char data[RB_PROFILE_END - RB_PROFILE_BEGIN] = {0};
|
||||||
|
|
||||||
// Calculate the total amount of bytes.
|
// Calculate the total amount of bytes.
|
||||||
|
|
||||||
unsigned int remaining = DISTANCE (begin, end);
|
unsigned int remaining = RB_PROFILE_DISTANCE (begin, end);
|
||||||
|
|
||||||
// To reduce the number of read operations, we always try to read
|
// To reduce the number of read operations, we always try to read
|
||||||
// packages with the largest possible size. As a consequence, the
|
// packages with the largest possible size. As a consequence, the
|
||||||
@ -382,7 +384,7 @@ suunto_d9_read_dives (d9 *device, dive_callback_t callback, void *userdata)
|
|||||||
unsigned int previous = last;
|
unsigned int previous = last;
|
||||||
while (current != begin) {
|
while (current != begin) {
|
||||||
// Calculate the size of the current dive.
|
// Calculate the size of the current dive.
|
||||||
unsigned int size = DISTANCE (previous, current);
|
unsigned int size = RB_PROFILE_DISTANCE (previous, current);
|
||||||
message ("Pointers: dive=%u, current=%04x, previous=%04x, size=%u, remaining=%u, available=%u\n",
|
message ("Pointers: dive=%u, current=%04x, previous=%04x, size=%u, remaining=%u, available=%u\n",
|
||||||
ndives + 1, current, previous, size, remaining, available);
|
ndives + 1, current, previous, size, remaining, available);
|
||||||
|
|
||||||
@ -395,8 +397,8 @@ suunto_d9_read_dives (d9 *device, dive_callback_t callback, void *userdata)
|
|||||||
// size first, and adjust when the end of the ringbuffer or
|
// size first, and adjust when the end of the ringbuffer or
|
||||||
// the end of the profile data is reached.
|
// the end of the profile data is reached.
|
||||||
unsigned int len = SUUNTO_D9_PACKET_SIZE;
|
unsigned int len = SUUNTO_D9_PACKET_SIZE;
|
||||||
if (0x019A + len > address)
|
if (RB_PROFILE_BEGIN + len > address)
|
||||||
len = address - 0x019A; // End of ringbuffer.
|
len = address - RB_PROFILE_BEGIN; // End of ringbuffer.
|
||||||
if (nbytes + len > remaining)
|
if (nbytes + len > remaining)
|
||||||
len = remaining - nbytes; // End of profile.
|
len = remaining - nbytes; // End of profile.
|
||||||
/*if (nbytes + len > size)
|
/*if (nbytes + len > size)
|
||||||
@ -415,8 +417,8 @@ suunto_d9_read_dives (d9 *device, dive_callback_t callback, void *userdata)
|
|||||||
// Next package.
|
// Next package.
|
||||||
nbytes += len;
|
nbytes += len;
|
||||||
address -= len;
|
address -= len;
|
||||||
if (address <= 0x019A)
|
if (address <= RB_PROFILE_BEGIN)
|
||||||
address = SUUNTO_D9_MEMORY_SIZE - 2;
|
address = RB_PROFILE_END;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ("Pointers: nbytes=%u\n", nbytes);
|
message ("Pointers: nbytes=%u\n", nbytes);
|
||||||
|
|||||||
@ -17,7 +17,9 @@
|
|||||||
message ("%s:%d: %s\n", __FILE__, __LINE__, expr); \
|
message ("%s:%d: %s\n", __FILE__, __LINE__, expr); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DISTANCE(a,b) ringbuffer_distance (a, b, 0x019A, SUUNTO_VYPER2_MEMORY_SIZE - 2)
|
#define RB_PROFILE_BEGIN 0x019A
|
||||||
|
#define RB_PROFILE_END SUUNTO_VYPER2_MEMORY_SIZE - 2
|
||||||
|
#define RB_PROFILE_DISTANCE(a,b) ringbuffer_distance (a, b, RB_PROFILE_BEGIN, RB_PROFILE_END)
|
||||||
|
|
||||||
struct vyper2 {
|
struct vyper2 {
|
||||||
struct serial *port;
|
struct serial *port;
|
||||||
@ -344,11 +346,11 @@ suunto_vyper2_read_dives (vyper2 *device, dive_callback_t callback, void *userda
|
|||||||
|
|
||||||
// Memory buffer to store all the dives.
|
// Memory buffer to store all the dives.
|
||||||
|
|
||||||
unsigned char data[SUUNTO_VYPER2_MEMORY_SIZE - 0x019A - 2] = {0};
|
unsigned char data[RB_PROFILE_END - RB_PROFILE_BEGIN] = {0};
|
||||||
|
|
||||||
// Calculate the total amount of bytes.
|
// Calculate the total amount of bytes.
|
||||||
|
|
||||||
unsigned int remaining = DISTANCE (begin, end);
|
unsigned int remaining = RB_PROFILE_DISTANCE (begin, end);
|
||||||
|
|
||||||
// To reduce the number of read operations, we always try to read
|
// To reduce the number of read operations, we always try to read
|
||||||
// packages with the largest possible size. As a consequence, the
|
// packages with the largest possible size. As a consequence, the
|
||||||
@ -369,7 +371,7 @@ suunto_vyper2_read_dives (vyper2 *device, dive_callback_t callback, void *userda
|
|||||||
unsigned int previous = last;
|
unsigned int previous = last;
|
||||||
while (current != begin) {
|
while (current != begin) {
|
||||||
// Calculate the size of the current dive.
|
// Calculate the size of the current dive.
|
||||||
unsigned int size = DISTANCE (previous, current);
|
unsigned int size = RB_PROFILE_DISTANCE (previous, current);
|
||||||
message ("Pointers: dive=%u, current=%04x, previous=%04x, size=%u, remaining=%u, available=%u\n",
|
message ("Pointers: dive=%u, current=%04x, previous=%04x, size=%u, remaining=%u, available=%u\n",
|
||||||
ndives + 1, current, previous, size, remaining, available);
|
ndives + 1, current, previous, size, remaining, available);
|
||||||
|
|
||||||
@ -382,8 +384,8 @@ suunto_vyper2_read_dives (vyper2 *device, dive_callback_t callback, void *userda
|
|||||||
// size first, and adjust when the end of the ringbuffer or
|
// size first, and adjust when the end of the ringbuffer or
|
||||||
// the end of the profile data is reached.
|
// the end of the profile data is reached.
|
||||||
unsigned int len = SUUNTO_VYPER2_PACKET_SIZE;
|
unsigned int len = SUUNTO_VYPER2_PACKET_SIZE;
|
||||||
if (0x019A + len > address)
|
if (RB_PROFILE_BEGIN + len > address)
|
||||||
len = address - 0x019A; // End of ringbuffer.
|
len = address - RB_PROFILE_BEGIN; // End of ringbuffer.
|
||||||
if (nbytes + len > remaining)
|
if (nbytes + len > remaining)
|
||||||
len = remaining - nbytes; // End of profile.
|
len = remaining - nbytes; // End of profile.
|
||||||
/*if (nbytes + len > size)
|
/*if (nbytes + len > size)
|
||||||
@ -402,8 +404,8 @@ suunto_vyper2_read_dives (vyper2 *device, dive_callback_t callback, void *userda
|
|||||||
// Next package.
|
// Next package.
|
||||||
nbytes += len;
|
nbytes += len;
|
||||||
address -= len;
|
address -= len;
|
||||||
if (address <= 0x019A)
|
if (address <= RB_PROFILE_BEGIN)
|
||||||
address = SUUNTO_VYPER2_MEMORY_SIZE - 2;
|
address = RB_PROFILE_END;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ("Pointers: nbytes=%u\n", nbytes);
|
message ("Pointers: nbytes=%u\n", nbytes);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user