This patch ensures that the setpoint and the o2 sensor data,
as well as the dctype and no_o2sensor members of divecomputer
are all read properly from xml (parse-xml.c) and are written
to xml (save-xml) in a consistent way.

The variables being dealt with XML I/O here are:

Oxygen sensor data:
  sample.sensor[0]
  sample.sensor[1]
  sample.sensor[2]
  sample.setpoint

Divecomputer data:
  dc.dctype
  dc.no_o2sensors

After these changes a CCR dive can be read from CSV, saved as XML
and read back from XML in a consistent way.

Signed-off-by: willem ferguson <[email protected]>


Dirk, there are trivial changes to profile.c listed in this patch. Although
they will not have any effect whatsoever, I would prefer them not
being merged. I am struggling to remove profile.c from the commit
because it was not intended to be added.

>From aad14ed67de065c559ac07d59bd0374b1fa2f579 Mon Sep 17 00:00:00 2001
From: willem ferguson <[email protected]>
Date: Tue, 11 Nov 2014 22:17:01 +0200
Subject: [PATCH] Modify parse-xml.c and save-xml.c to read and to store CCR
 sample and dive computer data in a consistent way.

This patch ensures that the setpoint and the o2 sensor data,
as well as the dctype and no_o2sensor members of divecomputer
are all read properly from xml (parse-xml.c) and are written
to xml (save-xml) in a consistent way.

Signed-off-by: willem ferguson <[email protected]>
---
 dive.c      |  2 +-
 parse-xml.c |  4 +++-
 profile.c   |  5 ++++-
 save-xml.c  | 24 +++++++++++++++++++++++-
 4 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/dive.c b/dive.c
index d20c11b..b18a1a7 100644
--- a/dive.c
+++ b/dive.c
@@ -806,7 +806,7 @@ int explicit_first_cylinder(struct dive *dive, struct divecomputer *dc)
 	if (ev && dc && dc->sample && ev->time.seconds == dc->sample[0].time.seconds)
 		return get_cylinder_index(dive, ev);
 	else
-		return 0;
+		return dc->dctype == CCR ? get_cylinder_use(dive, diluent) : 0;
 }
 
 void sanitize_gasmix(struct gasmix *mix)
diff --git a/parse-xml.c b/parse-xml.c
index 3e8c55b..52fbb36 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -912,10 +912,12 @@ static void try_to_fill_sample(struct sample *sample, const char *name, char *bu
 		return;
 	if (MATCH("sensor3.sample", double_to_o2pressure, &sample->o2sensor[2])) // up to 3 CCR sensors
 		return;
-	if (MATCH("po2.sample", double_to_o2pressure, &sample->setpoint)) {
+	if (MATCH("setpoint.sample", double_to_o2pressure, &sample->setpoint)) {
 		cur_dive->dc.dctype = CCR;
 		return;
 	}
+	if (MATCH("po2.sample", double_to_o2pressure, &sample->o2sensor[0]))
+		return;
 	if (MATCH("heartbeat", get_uint8, &sample->heartbeat))
 		return;
 	if (MATCH("bearing", get_bearing, &sample->bearing))
diff --git a/profile.c b/profile.c
index d3c5ef8..965f861 100644
--- a/profile.c
+++ b/profile.c
@@ -575,13 +575,16 @@ struct plot_data *populate_plot_entries(struct dive *dive, struct divecomputer *
 		pi->has_ndl |= sample->ndl.seconds;
 		entry->in_deco = sample->in_deco;
 		entry->cns = sample->cns;
+//		if (dc->dctype == CCR) printf("DC TYPE = CCR\n");
+//		else printf("DC TYPE = OC\n");
+
 		if (dc->dctype == CCR) {
 			entry->o2setpoint = sample->setpoint.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;
 		} else {
-			entry->pressures.o2 = sample->setpoint.mbar / 1000.0;
+			entry->pressures.o2  = sample->setpoint.mbar / 1000.0;
 		}
 		/* FIXME! sensor index -> cylinder index translation! */
 		entry->cylinderindex = sample->sensor;
diff --git a/save-xml.c b/save-xml.c
index a128cf0..7e79fcc 100644
--- a/save-xml.c
+++ b/save-xml.c
@@ -251,8 +251,23 @@ static void save_sample(struct membuffer *b, struct sample *sample, struct sampl
 		old->cns = sample->cns;
 	}
 
+	if ((sample->o2sensor[0].mbar) && (sample->o2sensor[0].mbar != old->o2sensor[0].mbar)) {
+		put_milli(b, " sensor1='", sample->o2sensor[0].mbar, " bar'");
+		old->o2sensor[0] = sample->o2sensor[0];
+	}
+
+	if ((sample->o2sensor[1].mbar) && (sample->o2sensor[1].mbar != old->o2sensor[1].mbar)) {
+		put_milli(b, " sensor2='", sample->o2sensor[1].mbar, " bar'");
+		old->o2sensor[1] = sample->o2sensor[1];
+	}
+
+	if ((sample->o2sensor[2].mbar) && (sample->o2sensor[2].mbar != old->o2sensor[2].mbar)) {
+		put_milli(b, " sensor3='", sample->o2sensor[2].mbar, " bar'");
+		old->o2sensor[2] = sample->o2sensor[2];
+	}
+
 	if (sample->setpoint.mbar != old->setpoint.mbar) {
-		put_milli(b, " po2='", sample->setpoint.mbar, " bar'");
+		put_milli(b, " setpoint='", sample->setpoint.mbar, " bar'");
 		old->setpoint = sample->setpoint;
 	}
 	show_index(b, sample->heartbeat, "heartbeat='", "'");
@@ -348,6 +363,13 @@ static void save_dc(struct membuffer *b, struct dive *dive, struct divecomputer
 		show_date(b, dc->when);
 	if (dc->duration.seconds && dc->duration.seconds != dive->dc.duration.seconds)
 		put_duration(b, dc->duration, " duration='", " min'");
+	if (dc->dctype == OC)
+		put_string(b," dctype='OC'");
+	else {
+		put_string(b," dctype='CCR'");
+		if (dc->no_o2sensors)
+			put_format(b," no_o2sensors='%d'", dc->no_o2sensors);
+	}
 	put_format(b, ">\n");
 	save_depths(b, dc);
 	save_temperatures(b, dc);
-- 
1.9.1

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to