From 46bb02e8fc2878bc94f4f2543db74e20104eb6f2 Mon Sep 17 00:00:00 2001 From: willem ferguson Date: Sat, 11 Oct 2014 09:49:48 +0200 Subject: [PATCH] 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 Signed-off-by: Dirk Hohndel --- dive.c | 25 +++++++++++++++++++++++-- dives/Poseidon_MkVI_6-14_import.xml | 8 ++++---- parse-xml.c | 8 ++++++++ profile.c | 7 ++++++- 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/dive.c b/dive.c index 15fcbf51b..d20a64cc1 100644 --- a/dive.c +++ b/dive.c @@ -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; diff --git a/dives/Poseidon_MkVI_6-14_import.xml b/dives/Poseidon_MkVI_6-14_import.xml index 559aa2eba..6c92a3449 100644 --- a/dives/Poseidon_MkVI_6-14_import.xml +++ b/dives/Poseidon_MkVI_6-14_import.xml @@ -1,9 +1,6 @@ - - - - + 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 --- + + + diff --git a/parse-xml.c b/parse-xml.c index 02cf9f771..6e74e8aaf 100644 --- a/parse-xml.c +++ b/parse-xml.c @@ -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)) diff --git a/profile.c b/profile.c index 3e557252b..9bd33b83e 100644 --- a/profile.c +++ b/profile.c @@ -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. */ }