Use the correct freedive mode for each model.

This commit is contained in:
Jef Driesen 2010-02-26 14:41:25 +00:00
parent 9b1a89582c
commit 1e7a1b8194
4 changed files with 18 additions and 6 deletions

View File

@ -262,7 +262,7 @@ doparse (FILE *fp, device_data_t *devdata, const unsigned char data[], unsigned
break;
case DEVICE_TYPE_MARES_NEMO:
case DEVICE_TYPE_MARES_PUCK:
rc = mares_nemo_parser_create (&parser);
rc = mares_nemo_parser_create (&parser, devdata->devinfo.model);
break;
default:
rc = PARSER_STATUS_ERROR;

View File

@ -68,6 +68,11 @@ mares_common_extract_dives (mares_common_device_t *device, const mares_common_la
{
assert (layout != NULL);
// Get the freedive mode for this model.
unsigned int freedive = 2;
if (data[1] == 7)
freedive = 3;
// Get the end of the profile ring buffer.
unsigned int eop = array_uint16_le (data + 0x6B);
@ -120,7 +125,7 @@ mares_common_extract_dives (mares_common_device_t *device, const mares_common_la
// in freedive mode, the sizes are different from the other modes.
unsigned int header_size = 53;
unsigned int sample_size = (extra ? 5 : 2);
if (mode == 2) {
if (mode == freedive) {
header_size = 28;
sample_size = 6;
nfreedives++;
@ -153,7 +158,7 @@ mares_common_extract_dives (mares_common_device_t *device, const mares_common_la
// Process the profile data for the most recent freedive entry.
// Since we are processing the entries backwards (newest to oldest),
// this entry will always be the first one.
if (mode == 2 && nfreedives == 1) {
if (mode == freedive && nfreedives == 1) {
// Count the number of freedives in the profile data.
unsigned int count = 0;
unsigned int idx = layout->rb_freedives_begin;

View File

@ -36,7 +36,7 @@ device_status_t
mares_nemo_extract_dives (device_t *device, const unsigned char data[], unsigned int size, dive_callback_t callback, void *userdata);
parser_status_t
mares_nemo_parser_create (parser_t **parser);
mares_nemo_parser_create (parser_t **parser, unsigned int model);
#ifdef __cplusplus
}

View File

@ -33,6 +33,7 @@ typedef struct mares_nemo_parser_t mares_nemo_parser_t;
struct mares_nemo_parser_t {
parser_t base;
unsigned int model;
/* Internal state */
unsigned int mode;
unsigned int length;
@ -67,7 +68,7 @@ parser_is_mares_nemo (parser_t *abstract)
parser_status_t
mares_nemo_parser_create (parser_t **out)
mares_nemo_parser_create (parser_t **out, unsigned int model)
{
if (out == NULL)
return PARSER_STATUS_ERROR;
@ -83,6 +84,7 @@ mares_nemo_parser_create (parser_t **out)
parser_init (&parser->base, &mares_nemo_parser_backend);
// Set the default values.
parser->model = model;
parser->mode = 0;
parser->length = 0;
parser->sample_count = 0;
@ -206,7 +208,12 @@ mares_nemo_parser_samples_foreach (parser_t *abstract, sample_callback_t callbac
const unsigned char *data = abstract->data;
unsigned int size = abstract->size;
if (parser->mode != 2) {
// Get the freedive mode for this model.
unsigned int freedive = 2;
if (parser->model == 7)
freedive = 3;
if (parser->mode != freedive) {
unsigned int time = 0;
for (unsigned int i = 0; i < parser->sample_count; ++i) {
parser_sample_value_t sample = {0};