Get the gas mixes from the sample data.
The Shearwater devices support adding, removing or editing gas mixes during the dive. The pre-defined gas mixes available in the opening and closing block are only a snapshot of the configuration at the start and at the end of the dive. Thus by editing the gas mixes during the dive it's possible to switch to a gas mix that is not present in the opening (or even the closing block). The parser doesn't support that. To avoid this problem, we now collect the available gas mixes from the sample data. As a side effect we only return those gas mixes that are effectively used during the dive.
This commit is contained in:
parent
c964fa5ad9
commit
c8b166dadb
@ -234,16 +234,7 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser)
|
||||
unsigned int ngasmixes = 0;
|
||||
unsigned int oxygen[NGASMIXES] = {0};
|
||||
unsigned int helium[NGASMIXES] = {0};
|
||||
for (unsigned int i = 0; i < NGASMIXES; ++i) {
|
||||
unsigned int o2 = data[20 + i];
|
||||
unsigned int he = data[30 + i];
|
||||
if (o2 == 0 && he == 0)
|
||||
continue;
|
||||
oxygen[ngasmixes] = o2;
|
||||
helium[ngasmixes] = he;
|
||||
ngasmixes++;
|
||||
}
|
||||
|
||||
unsigned int o2_previous = 0, he_previous = 0;
|
||||
|
||||
unsigned int offset = headersize;
|
||||
unsigned int length = size - footersize;
|
||||
@ -260,6 +251,33 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser)
|
||||
mode = DC_DIVEMODE_CC;
|
||||
}
|
||||
|
||||
// Gaschange.
|
||||
unsigned int o2 = data[offset + 7];
|
||||
unsigned int he = data[offset + 8];
|
||||
if (o2 != o2_previous || he != he_previous) {
|
||||
// Find the gasmix in the list.
|
||||
unsigned int idx = 0;
|
||||
while (idx < ngasmixes) {
|
||||
if (o2 == oxygen[idx] && he == helium[idx])
|
||||
break;
|
||||
idx++;
|
||||
}
|
||||
|
||||
// Add it to list if not found.
|
||||
if (idx >= ngasmixes) {
|
||||
if (idx >= NGASMIXES) {
|
||||
ERROR (abstract->context, "Maximum number of gas mixes reached.");
|
||||
return DC_STATUS_NOMEMORY;
|
||||
}
|
||||
oxygen[idx] = o2;
|
||||
helium[idx] = he;
|
||||
ngasmixes = idx + 1;
|
||||
}
|
||||
|
||||
o2_previous = o2;
|
||||
he_previous = he;
|
||||
}
|
||||
|
||||
offset += parser->samplesize;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user