This commit is contained in:
Dirk Hohndel 2022-09-23 07:57:05 -07:00
commit 99e6e11c8c
3 changed files with 31 additions and 7 deletions

View file

@ -1210,17 +1210,41 @@ static void fixup_no_o2sensors(struct divecomputer *dc)
}
}
static void fixup_dc_sample_sensors(struct divecomputer *dc, int nr_cylinders)
static void fixup_dc_sample_sensors(struct dive *dive, struct divecomputer *dc)
{
unsigned long sensor_mask = 0;
for (int i = 0; i < dc->samples; i++) {
struct sample *s = dc->sample + i;
for (int j = 0; j < MAX_SENSORS; j++) {
if (s->sensor[j] < 0 || s->sensor[j] >= nr_cylinders) {
int sensor = s->sensor[j];
// No invalid sensor ID's, please
if (sensor < 0 || sensor > MAX_SENSORS) {
s->sensor[j] = NO_SENSOR;
s->pressure[j].mbar = 0;
continue;
}
// Don't bother tracking sensors with no data
if (!s->pressure[j].mbar) {
s->sensor[j] = NO_SENSOR;
continue;
}
// Remember the set of sensors we had
sensor_mask |= 1ul << sensor;
}
}
// Ignore the sensors we have cylinders for
sensor_mask >>= dive->cylinders.nr;
// Do we need to add empty cylinders?
while (sensor_mask) {
add_empty_cylinder(&dive->cylinders);
sensor_mask >>= 1;
}
}
static void fixup_dive_dc(struct dive *dive, struct divecomputer *dc)
@ -1240,12 +1264,12 @@ static void fixup_dive_dc(struct dive *dive, struct divecomputer *dc)
/* Fix up gas switch events */
fixup_dc_gasswitch(dive, dc);
/* Fix up cylinder ids in pressure sensors */
fixup_dc_sample_sensors(dive, dc);
/* Fix up cylinder pressures based on DC info */
fixup_dive_pressures(dive, dc);
/* Fix up cylinder ids in pressure sensors */
fixup_dc_sample_sensors(dc, dive->cylinders.nr);
fixup_dc_events(dc);
/* Fixup CCR / PSCR dives with o2sensor values, but without no_o2sensors */

View file

@ -644,7 +644,7 @@ static char *parse_sample_unit(struct sample *sample, double val, char *unit)
/*
* If the given cylinder doesn't exist, return NO_SENSOR.
*/
static uint8_t sanitize_sensor_id(const struct dive *d, int nr)
static int sanitize_sensor_id(const struct dive *d, int nr)
{
return d && nr >= 0 && nr < d->cylinders.nr ? nr : NO_SENSOR;
}

View file

@ -393,7 +393,7 @@ void ws_end(struct parser_state *state)
/*
* If the given cylinder doesn't exist, return NO_SENSOR.
*/
static uint8_t sanitize_sensor_id(const struct dive *d, int nr)
static int sanitize_sensor_id(const struct dive *d, int nr)
{
return d && nr >= 0 && nr < d->cylinders.nr ? nr : NO_SENSOR;
}