Merge git://git.libdivecomputer.org/libdivecomputer into Subsurface-branch

Merge with Jef's upstream libdivecomputer:

 - some OSTC parsing fixes, including getting the initial CNS into the
   first sample

 - syntactic cleanups to the Scubapro Aladin Sport Matrix support to
   match upstream

* git://git.libdivecomputer.org/libdivecomputer:
  OSTC: initialize initial CNS from header
  Use an out-of-range value as undefined
  Support for the Scubapro Aladin Sport Matrix.
This commit is contained in:
Linus Torvalds 2017-11-15 08:51:54 -08:00
commit 9d7335dc6d
2 changed files with 23 additions and 5 deletions

View File

@ -139,8 +139,8 @@ static const dc_descriptor_t g_descriptors[] = {
{"Scubapro", "Mantis 2", DC_FAMILY_UWATEC_MERIDIAN, 0x26},
/* Scubapro G2 */
#ifdef USBHID
{"Scubapro", "G2", DC_FAMILY_UWATEC_G2, 0x32}, // BLE
{"Scubapro", "Aladin Sport Matrix", DC_FAMILY_UWATEC_G2, 0x17}, // BLE
{"Scubapro", "G2", DC_FAMILY_UWATEC_G2, 0x32}, // BLE
#endif
/* Reefnet */
{"Reefnet", "Sensus", DC_FAMILY_REEFNET_SENSUS, 1},

View File

@ -40,7 +40,7 @@
#define MAXCONFIG 7
#define NGASMIXES 15
#define UNDEFINED 0xFF
#define UNDEFINED 0xFFFFFFFF
#define ALL 0
#define FIXED 1
@ -117,6 +117,7 @@ typedef struct hw_ostc_parser_t {
unsigned int nfixed;
unsigned int initial;
unsigned int initial_setpoint;
unsigned int initial_cns;
hw_ostc_gasmix_t gasmix[NGASMIXES];
} hw_ostc_parser_t;
@ -259,14 +260,18 @@ hw_ostc_parser_cache (hw_ostc_parser_t *parser)
}
// Get all the gas mixes, the index of the inital mix,
// and the initial setpoint (used in the fixed setpoint mode).
// the initial setpoint (used in the fixed setpoint CCR mode),
// and the initial CNS from the header
unsigned int initial = UNDEFINED;
unsigned int initial_setpoint = UNDEFINED;
unsigned int initial_cns = UNDEFINED;
unsigned int ngasmixes = 0;
hw_ostc_gasmix_t gasmix[NGASMIXES] = {{0}};
if (version == 0x22) {
ngasmixes = 3;
initial = data[31];
if (data[31] != 0xFF) {
initial = data[31];
}
for (unsigned int i = 0; i < ngasmixes; ++i) {
gasmix[i].oxygen = data[25 + 2 * i];
gasmix[i].helium = 0;
@ -285,9 +290,13 @@ hw_ostc_parser_cache (hw_ostc_parser_t *parser)
if (data[82] == OSTC3_CC) {
initial_setpoint = data[60];
}
// Initial CNS
initial_cns = array_uint16_le (data + 53);
} else {
ngasmixes = 5;
initial = data[31];
if (data[31] != 0xFF) {
initial = data[31];
}
for (unsigned int i = 0; i < ngasmixes; ++i) {
gasmix[i].oxygen = data[19 + 2 * i + 0];
gasmix[i].helium = data[19 + 2 * i + 1];
@ -311,6 +320,7 @@ hw_ostc_parser_cache (hw_ostc_parser_t *parser)
parser->nfixed = ngasmixes;
parser->initial = initial;
parser->initial_setpoint = initial_setpoint;
parser->initial_cns = initial_cns;
for (unsigned int i = 0; i < ngasmixes; ++i) {
parser->gasmix[i] = gasmix[i];
}
@ -345,6 +355,7 @@ hw_ostc_parser_create_internal (dc_parser_t **out, dc_context_t *context, unsign
parser->nfixed = 0;
parser->initial = 0;
parser->initial_setpoint = 0;
parser->initial_cns = 0;
for (unsigned int i = 0; i < NGASMIXES; ++i) {
parser->gasmix[i].oxygen = 0;
parser->gasmix[i].helium = 0;
@ -383,6 +394,7 @@ hw_ostc_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsig
parser->nfixed = 0;
parser->initial = 0;
parser->initial_setpoint = 0;
parser->initial_cns = 0;
for (unsigned int i = 0; i < NGASMIXES; ++i) {
parser->gasmix[i].oxygen = 0;
parser->gasmix[i].helium = 0;
@ -775,6 +787,12 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call
if (callback) callback (DC_SAMPLE_SETPOINT, sample, userdata);
}
// Initial CNS (%).
if (time == samplerate && parser->initial_cns != UNDEFINED) {
sample.cns = parser->initial_cns / 100.0;
if (callback) callback (DC_SAMPLE_CNS, sample, userdata);
}
// Depth (mbar).
unsigned int depth = array_uint16_le (data + offset);
sample.depth = (depth * BAR / 1000.0) / hydrostatic;