Improve the support for multiple tank transmitters
Some of the newer Shearwater dive computers support up to 2 tank pressure sensors. The tank pressure samples were already reported, but the tank field with the corresponding begin/end pressure was still missing.
This commit is contained in:
parent
e23c374cd8
commit
6c441bb402
@ -68,6 +68,7 @@
|
|||||||
#define IMPERIAL 1
|
#define IMPERIAL 1
|
||||||
|
|
||||||
#define NGASMIXES 10
|
#define NGASMIXES 10
|
||||||
|
#define NTANKS 2
|
||||||
#define NRECORDS 7
|
#define NRECORDS 7
|
||||||
|
|
||||||
#define PREDATOR 2
|
#define PREDATOR 2
|
||||||
@ -82,6 +83,12 @@ typedef struct shearwater_predator_gasmix_t {
|
|||||||
unsigned int helium;
|
unsigned int helium;
|
||||||
} shearwater_predator_gasmix_t;
|
} shearwater_predator_gasmix_t;
|
||||||
|
|
||||||
|
typedef struct shearwater_predator_tank_t {
|
||||||
|
unsigned int enabled;
|
||||||
|
unsigned int beginpressure;
|
||||||
|
unsigned int endpressure;
|
||||||
|
} shearwater_predator_tank_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;
|
||||||
@ -97,7 +104,10 @@ struct shearwater_predator_parser_t {
|
|||||||
unsigned int closing[NRECORDS];
|
unsigned int closing[NRECORDS];
|
||||||
unsigned int final;
|
unsigned int final;
|
||||||
unsigned int ngasmixes;
|
unsigned int ngasmixes;
|
||||||
|
unsigned int ntanks;
|
||||||
shearwater_predator_gasmix_t gasmix[NGASMIXES];
|
shearwater_predator_gasmix_t gasmix[NGASMIXES];
|
||||||
|
shearwater_predator_tank_t tank[NTANKS];
|
||||||
|
unsigned int tankidx[NTANKS];
|
||||||
unsigned int calibrated;
|
unsigned int calibrated;
|
||||||
double calibration[3];
|
double calibration[3];
|
||||||
dc_divemode_t mode;
|
dc_divemode_t mode;
|
||||||
@ -192,6 +202,13 @@ shearwater_common_parser_create (dc_parser_t **out, dc_context_t *context, unsig
|
|||||||
parser->gasmix[i].oxygen = 0;
|
parser->gasmix[i].oxygen = 0;
|
||||||
parser->gasmix[i].helium = 0;
|
parser->gasmix[i].helium = 0;
|
||||||
}
|
}
|
||||||
|
parser->ntanks = 0;
|
||||||
|
for (unsigned int i = 0; i < NTANKS; ++i) {
|
||||||
|
parser->tank[i].enabled = 0;
|
||||||
|
parser->tank[i].beginpressure = 0;
|
||||||
|
parser->tank[i].endpressure = 0;
|
||||||
|
parser->tankidx[i] = i;
|
||||||
|
}
|
||||||
parser->calibrated = 0;
|
parser->calibrated = 0;
|
||||||
for (unsigned int i = 0; i < 3; ++i) {
|
for (unsigned int i = 0; i < 3; ++i) {
|
||||||
parser->calibration[i] = 0.0;
|
parser->calibration[i] = 0.0;
|
||||||
@ -242,6 +259,13 @@ shearwater_predator_parser_set_data (dc_parser_t *abstract, const unsigned char
|
|||||||
parser->gasmix[i].oxygen = 0;
|
parser->gasmix[i].oxygen = 0;
|
||||||
parser->gasmix[i].helium = 0;
|
parser->gasmix[i].helium = 0;
|
||||||
}
|
}
|
||||||
|
parser->ntanks = 0;
|
||||||
|
for (unsigned int i = 0; i < NTANKS; ++i) {
|
||||||
|
parser->tank[i].enabled = 0;
|
||||||
|
parser->tank[i].beginpressure = 0;
|
||||||
|
parser->tank[i].endpressure = 0;
|
||||||
|
parser->tankidx[i] = i;
|
||||||
|
}
|
||||||
parser->calibrated = 0;
|
parser->calibrated = 0;
|
||||||
for (unsigned int i = 0; i < 3; ++i) {
|
for (unsigned int i = 0; i < 3; ++i) {
|
||||||
parser->calibration[i] = 0.0;
|
parser->calibration[i] = 0.0;
|
||||||
@ -345,6 +369,7 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser)
|
|||||||
// Get the gas mixes.
|
// Get the gas mixes.
|
||||||
unsigned int ngasmixes = 0;
|
unsigned int ngasmixes = 0;
|
||||||
shearwater_predator_gasmix_t gasmix[NGASMIXES] = {0};
|
shearwater_predator_gasmix_t gasmix[NGASMIXES] = {0};
|
||||||
|
shearwater_predator_tank_t tank[NTANKS] = {0};
|
||||||
unsigned int o2_previous = 0, he_previous = 0;
|
unsigned int o2_previous = 0, he_previous = 0;
|
||||||
|
|
||||||
unsigned int offset = headersize;
|
unsigned int offset = headersize;
|
||||||
@ -392,6 +417,31 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser)
|
|||||||
o2_previous = o2;
|
o2_previous = o2;
|
||||||
he_previous = he;
|
he_previous = he;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tank pressure
|
||||||
|
if (logversion >= 7) {
|
||||||
|
const unsigned int idx[NTANKS] = {27, 19};
|
||||||
|
for (unsigned int i = 0; i < NTANKS; ++i) {
|
||||||
|
// Values above 0xFFF0 are special codes:
|
||||||
|
// 0xFFFF AI is off
|
||||||
|
// 0xFFFE No comms for 90 seconds+
|
||||||
|
// 0xFFFD No comms for 30 seconds
|
||||||
|
// 0xFFFC Transmitter not paired
|
||||||
|
// For regular values, the top 4 bits contain the battery
|
||||||
|
// level (0=normal, 1=critical, 2=warning), and the lower 12
|
||||||
|
// bits the tank pressure in units of 2 psi.
|
||||||
|
unsigned int pressure = array_uint16_be (data + offset + pnf + idx[i]);
|
||||||
|
if (pressure < 0xFFF0) {
|
||||||
|
pressure &= 0x0FFF;
|
||||||
|
if (!tank[i].enabled) {
|
||||||
|
tank[i].enabled = 1;
|
||||||
|
tank[i].beginpressure = pressure;
|
||||||
|
tank[i].endpressure = pressure;
|
||||||
|
}
|
||||||
|
tank[i].endpressure = pressure;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (type == LOG_RECORD_FREEDIVE_SAMPLE) {
|
} else if (type == LOG_RECORD_FREEDIVE_SAMPLE) {
|
||||||
// Freedive record
|
// Freedive record
|
||||||
mode = DC_DIVEMODE_FREEDIVE;
|
mode = DC_DIVEMODE_FREEDIVE;
|
||||||
@ -463,6 +513,16 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser)
|
|||||||
for (unsigned int i = 0; i < ngasmixes; ++i) {
|
for (unsigned int i = 0; i < ngasmixes; ++i) {
|
||||||
parser->gasmix[i] = gasmix[i];
|
parser->gasmix[i] = gasmix[i];
|
||||||
}
|
}
|
||||||
|
parser->ntanks = 0;
|
||||||
|
for (unsigned int i = 0; i < NTANKS; ++i) {
|
||||||
|
if (tank[i].enabled) {
|
||||||
|
parser->tankidx[i] = parser->ntanks;
|
||||||
|
parser->tank[parser->ntanks] = tank[i];
|
||||||
|
parser->ntanks++;
|
||||||
|
} else {
|
||||||
|
parser->tankidx[i] = UNDEFINED;
|
||||||
|
}
|
||||||
|
}
|
||||||
parser->mode = mode;
|
parser->mode = mode;
|
||||||
parser->units = data[parser->opening[0] + 8];
|
parser->units = data[parser->opening[0] + 8];
|
||||||
parser->atmospheric = array_uint16_be (data + parser->opening[1] + (parser->pnf ? 16 : 47));
|
parser->atmospheric = array_uint16_be (data + parser->opening[1] + (parser->pnf ? 16 : 47));
|
||||||
@ -485,6 +545,7 @@ shearwater_predator_parser_get_field (dc_parser_t *abstract, dc_field_type_t typ
|
|||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
dc_gasmix_t *gasmix = (dc_gasmix_t *) value;
|
dc_gasmix_t *gasmix = (dc_gasmix_t *) value;
|
||||||
|
dc_tank_t *tank = (dc_tank_t *) value;
|
||||||
dc_salinity_t *water = (dc_salinity_t *) value;
|
dc_salinity_t *water = (dc_salinity_t *) value;
|
||||||
|
|
||||||
if (value) {
|
if (value) {
|
||||||
@ -511,6 +572,17 @@ shearwater_predator_parser_get_field (dc_parser_t *abstract, dc_field_type_t typ
|
|||||||
gasmix->helium = parser->gasmix[flags].helium / 100.0;
|
gasmix->helium = parser->gasmix[flags].helium / 100.0;
|
||||||
gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium;
|
gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium;
|
||||||
break;
|
break;
|
||||||
|
case DC_FIELD_TANK_COUNT:
|
||||||
|
*((unsigned int *) value) = parser->ntanks;
|
||||||
|
break;
|
||||||
|
case DC_FIELD_TANK:
|
||||||
|
tank->type = DC_TANKVOLUME_NONE;
|
||||||
|
tank->volume = 0.0;
|
||||||
|
tank->workpressure = 0.0;
|
||||||
|
tank->beginpressure = parser->tank[flags].beginpressure * 2 * PSI / BAR;
|
||||||
|
tank->endpressure = parser->tank[flags].endpressure * 2 * PSI / BAR;
|
||||||
|
tank->gasmix = DC_GASMIX_UNKNOWN;
|
||||||
|
break;
|
||||||
case DC_FIELD_SALINITY:
|
case DC_FIELD_SALINITY:
|
||||||
if (parser->density == 1000)
|
if (parser->density == 1000)
|
||||||
water->type = DC_WATER_FRESH;
|
water->type = DC_WATER_FRESH;
|
||||||
@ -680,28 +752,24 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal
|
|||||||
// for logversion 7 and newer (introduced for Perdix AI)
|
// for logversion 7 and newer (introduced for Perdix AI)
|
||||||
// detect tank pressure
|
// detect tank pressure
|
||||||
if (parser->logversion >= 7) {
|
if (parser->logversion >= 7) {
|
||||||
// Tank pressure
|
const unsigned int idx[NTANKS] = {27, 19};
|
||||||
// Values above 0xFFF0 are special codes:
|
for (unsigned int i = 0; i < NTANKS; ++i) {
|
||||||
// 0xFFFF AI is off
|
// Tank pressure
|
||||||
// 0xFFFE No comms for 90 seconds+
|
// Values above 0xFFF0 are special codes:
|
||||||
// 0xFFFD No comms for 30 seconds
|
// 0xFFFF AI is off
|
||||||
// 0xFFFC Transmitter not paired
|
// 0xFFFE No comms for 90 seconds+
|
||||||
// For regular values, the top 4 bits contain the battery
|
// 0xFFFD No comms for 30 seconds
|
||||||
// level (0=normal, 1=critical, 2=warning), and the lower 12
|
// 0xFFFC Transmitter not paired
|
||||||
// bits the tank pressure in units of 2 psi.
|
// For regular values, the top 4 bits contain the battery
|
||||||
unsigned int pressure = array_uint16_be (data + offset + pnf + 27);
|
// level (0=normal, 1=critical, 2=warning), and the lower 12
|
||||||
if (pressure < 0xFFF0) {
|
// bits the tank pressure in units of 2 psi.
|
||||||
pressure &= 0x0FFF;
|
unsigned int pressure = array_uint16_be (data + offset + pnf + idx[i]);
|
||||||
sample.pressure.tank = 0;
|
if (pressure < 0xFFF0) {
|
||||||
sample.pressure.value = pressure * 2 * PSI / BAR;
|
pressure &= 0x0FFF;
|
||||||
if (callback) callback (DC_SAMPLE_PRESSURE, sample, userdata);
|
sample.pressure.tank = parser->tankidx[i];
|
||||||
}
|
sample.pressure.value = pressure * 2 * PSI / BAR;
|
||||||
pressure = array_uint16_be (data + offset + pnf + 19);
|
if (callback) callback (DC_SAMPLE_PRESSURE, sample, userdata);
|
||||||
if (pressure < 0xFFF0) {
|
}
|
||||||
pressure &= 0x0FFF;
|
|
||||||
sample.pressure.tank = 1;
|
|
||||||
sample.pressure.value = pressure * 2 * PSI / BAR;
|
|
||||||
if (callback) callback (DC_SAMPLE_PRESSURE, sample, userdata);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gas time remaining in minutes
|
// Gas time remaining in minutes
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user