Add the end-of-profile pointer to the layout descriptor structure.

This commit is contained in:
Jef Driesen 2009-05-12 19:58:01 +00:00
parent 1e39b84075
commit 863890aa23
4 changed files with 33 additions and 18 deletions

View File

@ -25,6 +25,7 @@
#include "suunto_common.h"
#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_PEEK(a,l) ringbuffer_decrement (a, l->peek, l->rb_profile_begin, l->rb_profile_end)
@ -60,12 +61,32 @@ suunto_common_device_set_fingerprint (suunto_common_device_t *device, const unsi
device_status_t
suunto_common_extract_dives (suunto_common_device_t *device, const suunto_common_layout_t *layout, const unsigned char data[], unsigned int eop, dive_callback_t callback, void *userdata)
suunto_common_extract_dives (suunto_common_device_t *device, const suunto_common_layout_t *layout, const unsigned char data[], dive_callback_t callback, void *userdata)
{
assert (layout != NULL);
assert (eop >= layout->rb_profile_begin && eop < layout->rb_profile_end);
assert (data[eop] == 0x82);
unsigned int eop;
if (layout->eop) {
// Get the end-of-profile pointer directly from the header.
eop = array_uint16_be (data + layout->eop);
} else {
// Get the end-of-profile pointer by searching for the
// end-of-profile marker in the profile ringbuffer.
eop = layout->rb_profile_begin;
while (eop < layout->rb_profile_end) {
if (data[eop] == 0x82)
break;
eop++;
}
}
// Validate the end-of-profile pointer.
if (eop < layout->rb_profile_begin ||
eop >= layout->rb_profile_end ||
data[eop] != 0x82)
{
return DEVICE_STATUS_ERROR;
}
// Memory buffer for the profile ringbuffer.
unsigned int length = layout->rb_profile_end - layout->rb_profile_begin;

View File

@ -34,6 +34,8 @@ typedef struct suunto_common_device_t {
} suunto_common_device_t;
typedef struct suunto_common_layout_t {
// End-of-profile marker
unsigned int eop;
// Profile ringbuffer
unsigned int rb_profile_begin;
unsigned int rb_profile_end;
@ -50,7 +52,7 @@ device_status_t
suunto_common_device_set_fingerprint (suunto_common_device_t *device, const unsigned char data[], unsigned int size);
device_status_t
suunto_common_extract_dives (suunto_common_device_t *device, const suunto_common_layout_t *layout, const unsigned char data[], unsigned int eop, dive_callback_t callback, void *userdata);
suunto_common_extract_dives (suunto_common_device_t *device, const suunto_common_layout_t *layout, const unsigned char data[], dive_callback_t callback, void *userdata);
#ifdef __cplusplus
}

View File

@ -63,6 +63,7 @@ static const device_backend_t suunto_eon_device_backend = {
};
static const suunto_common_layout_t suunto_eon_layout = {
0, /* eop */
0x100, /* rb_profile_begin */
SUUNTO_EON_MEMORY_SIZE, /* rb_profile_end */
6, /* fp_offset */
@ -301,14 +302,5 @@ suunto_eon_extract_dives (device_t *abstract, const unsigned char data[], unsign
if (size < SUUNTO_EON_MEMORY_SIZE)
return DEVICE_STATUS_ERROR;
// Search the end-of-profile marker.
unsigned int eop = 0x100;
while (eop < SUUNTO_EON_MEMORY_SIZE) {
if (data[eop] == 0x82) {
break;
}
eop++;
}
return suunto_common_extract_dives (device, &suunto_eon_layout, data, eop, callback, userdata);
return suunto_common_extract_dives (device, &suunto_eon_layout, data, callback, userdata);
}

View File

@ -69,6 +69,7 @@ static const device_backend_t suunto_vyper_device_backend = {
};
static const suunto_common_layout_t suunto_vyper_layout = {
0x51, /* eop */
0x71, /* rb_profile_begin */
SUUNTO_VYPER_MEMORY_SIZE, /* rb_profile_end */
9, /* fp_offset */
@ -76,6 +77,7 @@ static const suunto_common_layout_t suunto_vyper_layout = {
};
static const suunto_common_layout_t suunto_spyder_layout = {
0x1C, /* eop */
0x4C, /* rb_profile_begin */
SUUNTO_VYPER_MEMORY_SIZE, /* rb_profile_end */
7, /* fp_offset */
@ -650,10 +652,8 @@ suunto_vyper_extract_dives (device_t *abstract, const unsigned char data[], unsi
vyper = 0;
if (vyper) {
unsigned int eop = array_uint16_be (data + 0x51);
return suunto_common_extract_dives (device, &suunto_vyper_layout, data, eop, callback, userdata);
return suunto_common_extract_dives (device, &suunto_vyper_layout, data, callback, userdata);
} else {
unsigned int eop = array_uint16_be (data + 0x1C);
return suunto_common_extract_dives (device, &suunto_spyder_layout, data, eop, callback, userdata);
return suunto_common_extract_dives (device, &suunto_spyder_layout, data, callback, userdata);
}
}