Shearwater: correctly handle the different models
That weird 'petrel' argument and member variable can easily be replaced by looking at the model. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
6f4776d6c4
commit
8ea8cebb4e
@ -51,7 +51,6 @@
|
|||||||
#include "zeagle_n2ition3.h"
|
#include "zeagle_n2ition3.h"
|
||||||
#include "atomics_cobalt.h"
|
#include "atomics_cobalt.h"
|
||||||
#include "shearwater_petrel.h"
|
#include "shearwater_petrel.h"
|
||||||
#include "shearwater_predator.h"
|
|
||||||
#include "diverite_nitekq.h"
|
#include "diverite_nitekq.h"
|
||||||
#include "citizen_aqualand.h"
|
#include "citizen_aqualand.h"
|
||||||
#include "divesystem_idive.h"
|
#include "divesystem_idive.h"
|
||||||
@ -152,10 +151,8 @@ dc_parser_new_internal (dc_parser_t **out, dc_context_t *context, dc_family_t fa
|
|||||||
rc = atomics_cobalt_parser_create (&parser, context);
|
rc = atomics_cobalt_parser_create (&parser, context);
|
||||||
break;
|
break;
|
||||||
case DC_FAMILY_SHEARWATER_PREDATOR:
|
case DC_FAMILY_SHEARWATER_PREDATOR:
|
||||||
rc = shearwater_predator_parser_create (&parser, context, model, serial);
|
|
||||||
break;
|
|
||||||
case DC_FAMILY_SHEARWATER_PETREL:
|
case DC_FAMILY_SHEARWATER_PETREL:
|
||||||
rc = shearwater_petrel_parser_create (&parser, context, model, serial);
|
rc = shearwater_common_parser_create (&parser, context, model, serial);
|
||||||
break;
|
break;
|
||||||
case DC_FAMILY_DIVERITE_NITEKQ:
|
case DC_FAMILY_DIVERITE_NITEKQ:
|
||||||
rc = diverite_nitekq_parser_create (&parser, context);
|
rc = diverite_nitekq_parser_create (&parser, context);
|
||||||
|
|||||||
@ -34,7 +34,7 @@ dc_status_t
|
|||||||
shearwater_petrel_device_open (dc_device_t **device, dc_context_t *context, const char *name);
|
shearwater_petrel_device_open (dc_device_t **device, dc_context_t *context, const char *name);
|
||||||
|
|
||||||
dc_status_t
|
dc_status_t
|
||||||
shearwater_petrel_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model, unsigned int serial);
|
shearwater_common_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model, unsigned int serial);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,9 +33,6 @@ extern "C" {
|
|||||||
dc_status_t
|
dc_status_t
|
||||||
shearwater_predator_device_open (dc_device_t **device, dc_context_t *context, const char *name);
|
shearwater_predator_device_open (dc_device_t **device, dc_context_t *context, const char *name);
|
||||||
|
|
||||||
dc_status_t
|
|
||||||
shearwater_predator_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model, unsigned int serial);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|||||||
@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
#include "shearwater_predator.h"
|
#include "shearwater_predator.h"
|
||||||
#include "shearwater_petrel.h"
|
#include "shearwater_petrel.h"
|
||||||
|
#include "shearwater_common.h"
|
||||||
#include "context-private.h"
|
#include "context-private.h"
|
||||||
#include "parser-private.h"
|
#include "parser-private.h"
|
||||||
#include "array.h"
|
#include "array.h"
|
||||||
@ -54,15 +55,11 @@
|
|||||||
|
|
||||||
#define NGASMIXES 10
|
#define NGASMIXES 10
|
||||||
|
|
||||||
#define PREDATOR 2
|
|
||||||
#define PETREL 3
|
|
||||||
|
|
||||||
typedef struct shearwater_predator_parser_t shearwater_predator_parser_t;
|
typedef struct shearwater_predator_parser_t shearwater_predator_parser_t;
|
||||||
|
|
||||||
struct shearwater_predator_parser_t {
|
struct shearwater_predator_parser_t {
|
||||||
dc_parser_t base;
|
dc_parser_t base;
|
||||||
unsigned int model;
|
unsigned int model;
|
||||||
unsigned int petrel;
|
|
||||||
unsigned int samplesize;
|
unsigned int samplesize;
|
||||||
// Cached fields.
|
// Cached fields.
|
||||||
unsigned int cached;
|
unsigned int cached;
|
||||||
@ -118,8 +115,8 @@ shearwater_predator_find_gasmix (shearwater_predator_parser_t *parser, unsigned
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static dc_status_t
|
dc_status_t
|
||||||
shearwater_common_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model, unsigned int serial, unsigned int petrel)
|
shearwater_common_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model, unsigned int serial)
|
||||||
{
|
{
|
||||||
shearwater_predator_parser_t *parser = NULL;
|
shearwater_predator_parser_t *parser = NULL;
|
||||||
const dc_parser_vtable_t *vtable = NULL;
|
const dc_parser_vtable_t *vtable = NULL;
|
||||||
@ -128,7 +125,7 @@ shearwater_common_parser_create (dc_parser_t **out, dc_context_t *context, unsig
|
|||||||
if (out == NULL)
|
if (out == NULL)
|
||||||
return DC_STATUS_INVALIDARGS;
|
return DC_STATUS_INVALIDARGS;
|
||||||
|
|
||||||
if (petrel) {
|
if (model != PREDATOR) {
|
||||||
vtable = &shearwater_petrel_parser_vtable;
|
vtable = &shearwater_petrel_parser_vtable;
|
||||||
samplesize = SZ_SAMPLE_PETREL;
|
samplesize = SZ_SAMPLE_PETREL;
|
||||||
} else {
|
} else {
|
||||||
@ -145,7 +142,6 @@ shearwater_common_parser_create (dc_parser_t **out, dc_context_t *context, unsig
|
|||||||
|
|
||||||
// Set the default values.
|
// Set the default values.
|
||||||
parser->model = model;
|
parser->model = model;
|
||||||
parser->petrel = petrel;
|
|
||||||
parser->samplesize = samplesize;
|
parser->samplesize = samplesize;
|
||||||
parser->serial = serial;
|
parser->serial = serial;
|
||||||
|
|
||||||
@ -166,20 +162,6 @@ shearwater_common_parser_create (dc_parser_t **out, dc_context_t *context, unsig
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
dc_status_t
|
|
||||||
shearwater_predator_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model, unsigned int serial)
|
|
||||||
{
|
|
||||||
return shearwater_common_parser_create (out, context, model, serial, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
dc_status_t
|
|
||||||
shearwater_petrel_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model, unsigned int serial)
|
|
||||||
{
|
|
||||||
return shearwater_common_parser_create (out, context, model, serial, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static dc_status_t
|
static dc_status_t
|
||||||
shearwater_predator_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size)
|
shearwater_predator_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size)
|
||||||
{
|
{
|
||||||
@ -246,7 +228,7 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser)
|
|||||||
INFO(abstract->context, "Shearwater log version %u\n", parser->logversion);
|
INFO(abstract->context, "Shearwater log version %u\n", parser->logversion);
|
||||||
|
|
||||||
// Adjust the footersize for the final block.
|
// Adjust the footersize for the final block.
|
||||||
if (parser->petrel || array_uint16_be (data + size - footersize) == 0xFFFD) {
|
if (parser->model > PREDATOR || array_uint16_be (data + size - footersize) == 0xFFFD) {
|
||||||
footersize += SZ_BLOCK;
|
footersize += SZ_BLOCK;
|
||||||
if (size < headersize + footersize) {
|
if (size < headersize + footersize) {
|
||||||
ERROR (abstract->context, "Invalid data length.");
|
ERROR (abstract->context, "Invalid data length.");
|
||||||
@ -565,7 +547,7 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Setpoint
|
// Setpoint
|
||||||
if (parser->petrel) {
|
if (parser->model > PREDATOR) {
|
||||||
sample.setpoint = data[offset + 18] / 100.0;
|
sample.setpoint = data[offset + 18] / 100.0;
|
||||||
} else {
|
} else {
|
||||||
if (status & SETPOINT_HIGH) {
|
if (status & SETPOINT_HIGH) {
|
||||||
@ -578,7 +560,7 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CNS
|
// CNS
|
||||||
if (parser->petrel) {
|
if (parser->model > PREDATOR) {
|
||||||
sample.cns = data[offset + 22] / 100.0;
|
sample.cns = data[offset + 22] / 100.0;
|
||||||
if (callback) callback (DC_SAMPLE_CNS, sample, userdata);
|
if (callback) callback (DC_SAMPLE_CNS, sample, userdata);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user