CCR patch: Import and store oxygen sensor data

This patch allows the importing of oxygen sensor and setpoint data from
Poseidon CCR dive logs.
1) Change parse-xml.c to read up to three oxygen sensor values from xml.
   and to store the information in sample structures
2) Change parse-xml.c to read o2 setpoint values fro xml and to store
   it in sample structures
3) Change dive.c to delete all sensor and setpoint values where
   subsequent samples have sensor/setpoint values that are the same.
4) Change profile.c to store the sensor/setpoint values from the samples
   into plotinfo.
5) Change the sample Poseidon xml log in the dives directory to ensure
   the correct order and hierarchy of the dive and divecomputer nodes.

[Dirk Hohndel: minor cleanup, removed debug code, whitespace]

Signed-off-by: willem ferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
willem ferguson 2014-10-11 09:49:48 +02:00 committed by Dirk Hohndel
parent 2282035a4d
commit 46bb02e8fc
4 changed files with 41 additions and 7 deletions

25
dive.c
View file

@ -1039,19 +1039,19 @@ static void fixup_dc_events(struct divecomputer *dc)
static void fixup_dive_dc(struct dive *dive, struct divecomputer *dc)
{
int i, j;
int i, j, o2val;
double depthtime = 0;
int lasttime = 0;
int lastindex = -1;
int maxdepth = dc->maxdepth.mm;
int mintemp = 0;
int lastdepth = 0;
int lasto2val[3] = { 0, 0, 0 }, lasto2setpoint = 0;
int lasttemp = 0, lastpressure = 0, lastdiluentpressure = 0;
int pressure_delta[MAX_CYLINDERS] = { INT_MAX, };
/* Fixup duration and mean depth */
fixup_dc_duration(dc);
update_min_max_temperatures(dive, dc->watertemp);
for (i = 0; i < dc->samples; i++) {
struct sample *sample = dc->sample + i;
@ -1108,6 +1108,27 @@ static void fixup_dive_dc(struct dive *dive, struct divecomputer *dc)
if (!mintemp || temp < mintemp)
mintemp = temp;
}
// If there are consecutive identical O2 sensor readings, throw away the redundant ones.
for (j = 0; j < dc->no_o2sensors; j++) { // for CCR oxygen sensor data:
o2val = sample->o2sensor[j].mbar;
if (o2val) {
if (lasto2val[j] == o2val)
sample->o2sensor[j].mbar = 0;
else
lasto2val[j] = o2val;
}
}
// If there are consecutive identical CCR O2 setpoint readings, throw away the redundant ones.
o2val = sample->o2setpoint.mbar;
if (o2val) {
if (lasto2setpoint == o2val)
sample->o2setpoint.mbar = 0;
else
lasto2setpoint = o2val;
}
update_min_max_temperatures(dive, sample->temperature);
depthtime += (time - lasttime) * (lastdepth + depth) / 2;

View file

@ -1,9 +1,6 @@
<divelog program="subsurface-import" version="2">
<dives>
<dive tags="rebreather" date="2011-06-14" time="11:20">
<cylinder size='3.0 l' workpressure='200.0 bar' description='3l Mk6' o2='100.0%' start='184 bar' end='141.0 bar'/>
<cylinder size='3.0 l' workpressure='200.0 bar' description='3l Mk6' o2='21.0%' start='181 bar' end='137.0 bar'/>
<divecomputer model="Poseidon MkVI Discovery" dctype="CCR" no_o2sensors="2">
<dive tags="CCR" date="2011-06-14" time="11:20">
<notes>
MkVI_Config v1.08
Dive started at : 2011-06-14 11:20:36
@ -47,6 +44,9 @@ Helium tension 8 : 0.0000
Helium tension 9 : 0.0000
---
</notes>
<cylinder size='3.0 l' workpressure='200.0 bar' description='3l Mk6' o2='100.0%' start='184 bar' end='141.0 bar'/>
<cylinder size='3.0 l' workpressure='200.0 bar' description='3l Mk6' o2='21.0%' start='181 bar' end='137.0 bar'/>
<divecomputer model="Poseidon MkVI Discovery" dctype="CCR" no_o2sensors="2">
<sample time="0:00" depth="1 m" battery="" sensor1="0.34 bar" sensor2="NaN bar" pressure=" bar" pdiluent=" bar" setpoint="0.41 bar" temp="NaN C"/>
<sample time="0:01" depth="1 m" battery="" sensor1="0.35 bar" sensor2="0.32 bar" pressure=" bar" pdiluent=" bar" setpoint="0.41 bar" temp="NaN C"/>
<sample time="0:02" depth="0.5 m" battery="" sensor1="0.36 bar" sensor2="0.32 bar" pressure=" bar" pdiluent=" bar" setpoint="0.41 bar" temp="NaN C"/>

View file

@ -865,6 +865,14 @@ static void try_to_fill_sample(struct sample *sample, const char *name, char *bu
return;
if (MATCH("cns.sample", get_uint8, &sample->cns))
return;
if (MATCH("sensor1.sample", double_to_o2pressure, &sample->o2sensor[0])) // CCR O2 sensor data
return;
if (MATCH("sensor2.sample", double_to_o2pressure, &sample->o2sensor[1]))
return;
if (MATCH("sensor3.sample", double_to_o2pressure, &sample->o2sensor[2])) // up to 3 CCR sensors
return;
if (MATCH("setpoint.sample", double_to_o2pressure, &sample->o2setpoint))
return;
if (MATCH("po2.sample", double_to_o2pressure, &sample->po2))
return;
if (MATCH("heartbeat", get_uint8, &sample->heartbeat))

View file

@ -551,6 +551,11 @@ struct plot_data *populate_plot_entries(struct dive *dive, struct divecomputer *
entry->in_deco = sample->in_deco;
entry->cns = sample->cns;
entry->pressures.o2 = sample->po2.mbar / 1000.0;
entry->o2setpoint = sample->o2setpoint.mbar / 1000.0; // for rebreathers
entry->o2sensor[0] = sample->o2sensor[0].mbar / 1000.0; // for up to three rebreather O2 sensors
entry->o2sensor[1] = sample->o2sensor[1].mbar / 1000.0;
entry->o2sensor[2] = sample->o2sensor[2].mbar / 1000.0;
/* FIXME! sensor index -> cylinder index translation! */
entry->cylinderindex = sample->sensor;
SENSOR_PRESSURE(entry) = sample->cylinderpressure.mbar;
@ -909,7 +914,7 @@ void create_plot_info_new(struct dive *dive, struct divecomputer *dc, struct plo
setup_gas_sensor_pressure(dive, dc, pi); /* Try to populate our gas pressure knowledge */
populate_pressure_information(dive, dc, pi, NONDILUENT); /* .. calculate missing pressure entries for all gasses except diluent */
if (dc->dctype == CCR) { /* For CCR dives.. */
printf("REBREATHER; %d O2 sensors\n", dc->no_o2sensors);
printf("CCR DIVE: %s (%d O2 sensors)\n", dc->model, dc->no_o2sensors);
populate_pressure_information(dive, dc, pi, DILUENT); /* .. calculate missing diluent gas pressure entries */
// fill_o2_values(dc, pi); /* .. and insert the O2 sensor data having 0 values. */
}