[CCR PATCH] Import and store sensor and setpoint values from xml (1 of 3)

2014-10-11 Thread Willem Ferguson

CCR patch: Import and store oxygen sensor data

Patch 1 of 3.
This patch allows the importing of oxygen sensor and setpoint data
from Poseidon CCR dive logs. This is done as follows:
1) Change parse-xml.c to read up to three oxygen sensor values from xml
   and to store the information in structures of sample.
2) Change parse-xml.c to read o2 setpoint values fro xml and to store
   these in structures of sample.
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 structures
   of sample into structures of 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.

Signed-off-by: willem ferguson willemfergu...@zoology.up.ac.za

___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


[CCR PATCH] Import ad store sensor and setpoint values from xml [WITH attachment]

2014-10-11 Thread Willem Ferguson

CCR patch: Import and store oxygen sensor data

Patch 1 of 3.
This patch allows the importing of oxygen sensor and setpoint data
from Poseidon CCR dive logs. This is done as follows:
1) Change parse-xml.c to read up to three oxygen sensor values from xml
   and to store the information in structures of sample.
2) Change parse-xml.c to read o2 setpoint values fro xml and to store
   these in structures of sample.
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 structures
   of sample into structures of 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.

Signed-off-by: willem ferguson willemfergu...@zoology.up.ac.za

From 094388bf62e5765f150338e3c1fc161bcc695342 Mon Sep 17 00:00:00 2001
From: willem ferguson willemfergu...@zoology.up.ac.za
Date: Sat, 11 Oct 2014 09:49:48 +0200
Subject: [PATCH 2/2] CCR patch: Import and store oxygen sensor data

Patch 1 of 3.
This patch allows the importing of oxygen sensor and setpoint data
from Poseidon CCR dive logs. This is done as follows:
1) Change parse-xml.c to read up to three oxygen sensor values from xml.
   and to store the information in structures of sample.
2) Change parse-xml.c to read o2 setpoint values fro xml and to store
   these in structures of sample.
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 structures
   of sample into structures of 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.

Signed-off-by: willem ferguson willemfergu...@zoology.up.ac.za
---
 dive.c  | 29 +
 dives/Poseidon_MkVI_6-14_import.xml |  8 
 parse-xml.c | 12 ++--
 profile.c   | 15 ++-
 4 files changed, 49 insertions(+), 15 deletions(-)

diff --git a/dive.c b/dive.c
index 15fcbf5..a698d5a 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;
@@ -1062,7 +1062,7 @@ static void fixup_dive_dc(struct dive *dive, struct divecomputer *dc)
 		int diluent_pressure = sample-diluentpressure.mbar;
 		int index = sample-sensor;
 
-		if (index == lastindex) {
+		if (index == lastindex) { 
 			/* Remove duplicate redundant pressure information */
 			if (pressure == lastpressure)
 sample-cylinderpressure.mbar = 0;
@@ -1108,12 +1108,33 @@ 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] == sample-o2sensor[j].mbar)
+	sample-o2sensor[j].mbar = 0;
+else
+	lasto2val[j] = sample-o2sensor[j].mbar;
+			}
+		}
+
+		// 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;
 		lastdepth = depth;
 		lasttime = time;
-		if (sample-cns  dive-maxcns)
+			if (sample-cns  dive-maxcns)
 			dive-maxcns = sample-cns;
 	}
 
diff --git a/dives/Poseidon_MkVI_6-14_import.xml b/dives/Poseidon_MkVI_6-14_import.xml
index 559aa2e..6c92a34 100644
--- a/dives/Poseidon_MkVI_6-14_import.xml
+++ b/dives/Poseidon_MkVI_6-14_import.xml
@@ -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'/
-  

Re: [CCR PATCH] Import ad store sensor and setpoint values from xml [WITH attachment]

2014-10-11 Thread Dirk Hohndel
On Sat, Oct 11, 2014 at 10:05:33AM +0200, Willem Ferguson wrote:
 CCR patch: Import and store oxygen sensor data

Thanks for this one. Instead of sitting on it forever or a back and forth
about the minor changes that I want I simply applied the changes and
committed it. Here's my diff on top of yours... you'll see some small
algorithm cleanup (you put that value in o2val, so use o2val instead of
getting the structure member again), whitespace, debug printout...

/D


diff --git a/dive.c b/dive.c
index ea1ff03afbbc..d20a64cc1cc1 100644
--- a/dive.c
+++ b/dive.c
@@ -1113,10 +1113,10 @@ static void fixup_dive_dc(struct dive *dive, struct 
divecomputer *dc)
for (j = 0; j  dc-no_o2sensors; j++) {  // for CCR oxygen 
sensor data:
o2val = sample-o2sensor[j].mbar;
if (o2val) {
-   if (lasto2val[j] == sample-o2sensor[j].mbar)
+   if (lasto2val[j] == o2val)
sample-o2sensor[j].mbar = 0;
else
-   lasto2val[j] = sample-o2sensor[j].mbar;
+   lasto2val[j] = o2val;
}
}
 
@@ -1134,7 +1134,7 @@ static void fixup_dive_dc(struct dive *dive, struct
divecomputer *dc)
depthtime += (time - lasttime) * (lastdepth + depth) / 2;
lastdepth = depth;
lasttime = time;
-   if (sample-cns  dive-maxcns)
+   if (sample-cns  dive-maxcns)
dive-maxcns = sample-cns;
}
 
diff --git a/parse-xml.c b/parse-xml.c
index b07505c2d8f4..6e74e8aaf449 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -815,8 +815,8 @@ static void try_to_fill_dc(struct divecomputer *dc, const 
char *name, char *buf)
return;
if (MATCH(diveid, hex_value, dc-diveid))
return;
-   if (MATCH(dctype, get_dc_type, dc-dctype)) { printf(TYPE\n);
-   return; }
+   if (MATCH(dctype, get_dc_type, dc-dctype))
+   return;
if (MATCH(no_o2sensors, get_sensor, dc-no_o2sensors))
return;
if (match_dc_data_fields(dc, name, buf))
--- a/profile.c 2014-10-11 07:05:54.047560980 -0400
+++ b/profile.c 2014-10-11 07:09:59.319146178 -0400
@@ -551,7 +551,7 @@
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-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;
@@ -844,10 +846,10 @@
entry-end = (entry-depth + 1) * (1000 - fhe) / 1000.0 - 
1;
entry-ead = (entry-depth + 1) * (1000 - fo2 - fhe) / 
(double)N2_IN_AIR - 1;
entry-eadd = (entry-depth + 1) *
-   (entry-pressures.o2 / amb_pressure * 
O2_DENSITY +
-entry-pressures.n2 / amb_pressure * 
N2_DENSITY +
-entry-pressures.he / amb_pressure * 
HE_DENSITY) /
-   (O2_IN_AIR * O2_DENSITY + N2_IN_AIR * 
N2_DENSITY) * 1000 - 1;
+ (entry-pressures.o2 / amb_pressure * 
O2_DENSITY +
+  entry-pressures.n2 / amb_pressure * 
N2_DENSITY +
+  entry-pressures.he / amb_pressure * 
HE_DENSITY) /
+ (O2_IN_AIR * O2_DENSITY + N2_IN_AIR * 
N2_DENSITY) * 1000 - 1;
if (entry-mod  0)
entry-mod = 0;
if (entry-ead  0)
@@ -914,9 +916,9 @@
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(CCR DIVE: %s (%d O2 sensors)\n, 
dc-model,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. */
}
calculate_sac(dive, pi); /* Calculate sac */
calculate_deco_information(dive, dc, pi, false);