diff --git a/src/parser.c b/src/parser.c index b1257e9..4e6071f 100644 --- a/src/parser.c +++ b/src/parser.c @@ -51,6 +51,7 @@ #include "zeagle_n2ition3.h" #include "atomics_cobalt.h" #include "shearwater_petrel.h" +#include "shearwater_predator.h" #include "diverite_nitekq.h" #include "citizen_aqualand.h" #include "divesystem_idive.h" @@ -149,8 +150,10 @@ dc_parser_new_internal (dc_parser_t **out, dc_context_t *context, dc_family_t fa rc = atomics_cobalt_parser_create (&parser, context); break; case DC_FAMILY_SHEARWATER_PREDATOR: + rc = shearwater_predator_parser_create (&parser, context, model, serial); + break; case DC_FAMILY_SHEARWATER_PETREL: - rc = shearwater_common_parser_create (&parser, context, model, serial); + rc = shearwater_petrel_parser_create (&parser, context, model, serial); break; case DC_FAMILY_DIVERITE_NITEKQ: rc = diverite_nitekq_parser_create (&parser, context); diff --git a/src/shearwater_petrel.h b/src/shearwater_petrel.h index 985697e..b51361f 100644 --- a/src/shearwater_petrel.h +++ b/src/shearwater_petrel.h @@ -34,7 +34,7 @@ dc_status_t shearwater_petrel_device_open (dc_device_t **device, dc_context_t *context, const char *name); dc_status_t -shearwater_common_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model, unsigned int serial); +shearwater_petrel_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model, unsigned int serial); #ifdef __cplusplus } diff --git a/src/shearwater_predator.h b/src/shearwater_predator.h index e80a789..2b16e92 100644 --- a/src/shearwater_predator.h +++ b/src/shearwater_predator.h @@ -33,6 +33,9 @@ extern "C" { dc_status_t 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 } #endif /* __cplusplus */ diff --git a/src/shearwater_predator_parser.c b/src/shearwater_predator_parser.c index 96b443f..8c760f0 100644 --- a/src/shearwater_predator_parser.c +++ b/src/shearwater_predator_parser.c @@ -32,7 +32,6 @@ #include "shearwater_predator.h" #include "shearwater_petrel.h" -#include "shearwater_common.h" #include "context-private.h" #include "parser-private.h" #include "array.h" @@ -57,11 +56,15 @@ #define NGASMIXES 10 #define MAXSTRINGS 32 +#define PREDATOR 2 +#define PETREL 3 + typedef struct shearwater_predator_parser_t shearwater_predator_parser_t; struct shearwater_predator_parser_t { dc_parser_t base; unsigned int model; + unsigned int petrel; unsigned int samplesize; // Cached fields. unsigned int cached; @@ -120,8 +123,8 @@ shearwater_predator_find_gasmix (shearwater_predator_parser_t *parser, unsigned } -dc_status_t -shearwater_common_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model, unsigned int serial) +static 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_predator_parser_t *parser = NULL; const dc_parser_vtable_t *vtable = NULL; @@ -130,7 +133,7 @@ shearwater_common_parser_create (dc_parser_t **out, dc_context_t *context, unsig if (out == NULL) return DC_STATUS_INVALIDARGS; - if (model != PREDATOR) { + if (petrel) { vtable = &shearwater_petrel_parser_vtable; samplesize = SZ_SAMPLE_PETREL; } else { @@ -147,6 +150,7 @@ shearwater_common_parser_create (dc_parser_t **out, dc_context_t *context, unsig // Set the default values. parser->model = model; + parser->petrel = petrel; parser->samplesize = samplesize; parser->serial = serial; @@ -172,6 +176,20 @@ 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 shearwater_predator_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) { @@ -385,7 +403,7 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser) memset(parser->strings, 0, sizeof(parser->strings)); // Adjust the footersize for the final block. - if (parser->model > PREDATOR || array_uint16_be (data + size - footersize) == 0xFFFD) { + if (parser->petrel || array_uint16_be (data + size - footersize) == 0xFFFD) { footersize += SZ_BLOCK; if (size < headersize + footersize) { ERROR (abstract->context, "Invalid data length."); @@ -667,7 +685,7 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal } // Setpoint - if (parser->model > PREDATOR) { + if (parser->petrel) { sample.setpoint = data[offset + 18] / 100.0; } else { if (status & SETPOINT_HIGH) { @@ -680,7 +698,7 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal } // CNS - if (parser->model > PREDATOR) { + if (parser->petrel) { sample.cns = data[offset + 22] / 100.0; if (callback) callback (DC_SAMPLE_CNS, sample, userdata); }