Merge branch 'shearwater'

This commit is contained in:
Jef Driesen 2017-05-11 18:21:58 +02:00
commit a66da4a45e
4 changed files with 46 additions and 13 deletions

View File

@ -149,10 +149,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);
rc = shearwater_predator_parser_create (&parser, context, model);
break;
case DC_FAMILY_SHEARWATER_PETREL:
rc = shearwater_petrel_parser_create (&parser, context);
rc = shearwater_petrel_parser_create (&parser, context, model);
break;
case DC_FAMILY_DIVERITE_NITEKQ:
rc = diverite_nitekq_parser_create (&parser, context);

View File

@ -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_petrel_parser_create (dc_parser_t **parser, dc_context_t *context);
shearwater_petrel_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model);
#ifdef __cplusplus
}

View File

@ -34,7 +34,7 @@ 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);
shearwater_predator_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model);
#ifdef __cplusplus
}

View File

@ -48,10 +48,14 @@
#define NGASMIXES 10
#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.
@ -61,6 +65,7 @@ struct shearwater_predator_parser_t {
unsigned int ngasmixes;
unsigned int oxygen[NGASMIXES];
unsigned int helium[NGASMIXES];
double calibration[3];
dc_divemode_t mode;
};
@ -105,7 +110,7 @@ shearwater_predator_find_gasmix (shearwater_predator_parser_t *parser, unsigned
static dc_status_t
shearwater_common_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int petrel)
shearwater_common_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model, unsigned int petrel)
{
shearwater_predator_parser_t *parser = NULL;
const dc_parser_vtable_t *vtable = NULL;
@ -130,6 +135,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->cached = 0;
@ -149,16 +155,16 @@ 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)
shearwater_predator_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model)
{
return shearwater_common_parser_create (out, context, 0);
return shearwater_common_parser_create (out, context, model, 0);
}
dc_status_t
shearwater_petrel_parser_create (dc_parser_t **out, dc_context_t *context)
shearwater_petrel_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model)
{
return shearwater_common_parser_create (out, context, 1);
return shearwater_common_parser_create (out, context, model, 1);
}
@ -281,6 +287,20 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser)
offset += parser->samplesize;
}
// Cache sensor calibration for later use
parser->calibration[0] = array_uint16_be(data + 87) / 100000.0;
parser->calibration[1] = array_uint16_be(data + 89) / 100000.0;
parser->calibration[2] = array_uint16_be(data + 91) / 100000.0;
// The Predator expects the mV output of the cells to be within 30mV
// to 70mV in 100% O2 at 1 atmosphere.
// If the calibration value is scaled with a factor 2.2, then the
// sensors lines up and matches the average.
if (parser->model == PREDATOR) {
for (size_t i = 0; i < 3; ++i) {
parser->calibration[i] *= 2.2;
}
}
// Cache the data for later use.
parser->headersize = headersize;
parser->footersize = footersize;
@ -422,11 +442,24 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal
// Status flags.
unsigned int status = data[offset + 11];
// PPO2
sample.ppo2 = data[offset + 6] / 100.0;
if (callback) callback (DC_SAMPLE_PPO2, sample, userdata);
if ((status & OC) == 0) {
// PPO2
#ifdef SENSOR_AVERAGE
sample.ppo2 = data[offset + 6] / 100.0;
if (callback) callback (DC_SAMPLE_PPO2, sample, userdata);
#else
if ((status & PPO2_EXTERNAL) == 0) {
sample.ppo2 = data[offset + 12] * parser->calibration[0];
if (callback && (data[86] & 0x01)) callback (DC_SAMPLE_PPO2, sample, userdata);
sample.ppo2 = data[offset + 14] * parser->calibration[1];
if (callback && (data[86] & 0x02)) callback (DC_SAMPLE_PPO2, sample, userdata);
sample.ppo2 = data[offset + 15] * parser->calibration[2];
if (callback && (data[86] & 0x04)) callback (DC_SAMPLE_PPO2, sample, userdata);
}
#endif
// Setpoint
if (parser->petrel) {
sample.setpoint = data[offset + 18] / 100.0;