This is a second version of a similar patch submitted a few days ago.

This version preserves the present convention of storing the CCR setpoint
information in xml using a PO2 attribute. It also reads the setpoint info from
a xml PO2 attribute.

Three lines are marked as belonging to patches that were formulated by
Rober Helling and by Miika Turkia, respectively. So their equivalent patches
need to be pushed before this one. But this patch is buggy without those
two patches.

--
Willem Ferguson
Director: Centre for Environmental Studies,
University of Pretoria
Tel: 012-4202017 / 012-4204048
e-mail: [email protected]

>From 88aef22ce97ff48f5071c490cbcbab4c1fb2b39b Mon Sep 17 00:00:00 2001
From: willem ferguson <[email protected]>
Date: Sat, 15 Nov 2014 18:29:08 +0200
Subject: [PATCH 2/2] Version 2: Export Poseidon CCR dive log to XML

This patch improves on the previous similar patch. It preserves
the present convention of storing the CCR setpoint data to xml
using the attribute PO2. It also reads the setpoint data from
xml using the PO2 attribute.

Signed-off-by: willem ferguson <[email protected]>
---
 dive.c      | 48 ++++++++----------------------------------------
 parse-xml.c | 19 +++++++++++++++++++
 save-xml.c  | 37 ++++++++++++++++++++++++++++++++-----
 3 files changed, 59 insertions(+), 45 deletions(-)

diff --git a/dive.c b/dive.c
index 0c0e649..ae99951 100644
--- a/dive.c
+++ b/dive.c
@@ -434,10 +434,6 @@ void clear_dive(struct dive *d)
 	taglist_free(d->tag_list);
 	STRUCTURED_LIST_FREE(struct divecomputer, d->dc.next, free_dc);
 	STRUCTURED_LIST_FREE(struct picture, d->picture_list, free_pic);
-	for (int i = 0; i < MAX_CYLINDERS; i++)
-		free((void *)d->cylinder[i].type.description);
-	for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++)
-		free((void *)d->weightsystem[i].description);
 	memset(d, 0, sizeof(struct dive));
 }
 
@@ -456,10 +452,6 @@ void copy_dive(struct dive *s, struct dive *d)
 	d->location = copy_string(s->location);
 	d->notes = copy_string(s->notes);
 	d->suit = copy_string(s->suit);
-	for (int i = 0; i < MAX_CYLINDERS; i++)
-		d->cylinder[i].type.description = copy_string(s->cylinder[i].type.description);
-	for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++)
-		d->weightsystem[i].description = copy_string(s->weightsystem[i].description);
 	STRUCTURED_LIST_COPY(struct picture, s->picture_list, d->picture_list, copy_pl);
 	STRUCTURED_LIST_COPY(struct tag_entry, s->tag_list, d->tag_list, copy_tl);
 	STRUCTURED_LIST_COPY(struct divecomputer, s->dc.next, d->dc.next, copy_dc);
@@ -741,7 +733,10 @@ static void fixup_pressure(struct dive *dive, struct sample *sample)
 	int pressure, index;
 	cylinder_t *cyl;
 
-	pressure = sample->cylinderpressure.mbar;
+	if (dive->dc.dctype == CCR)
+		pressure = sample->diluentpressure.mbar;
+	else
+		pressure = sample->cylinderpressure.mbar;
 	if (!pressure)
 		return;
 	index = sample->sensor;
@@ -814,7 +809,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;	// Robert Heling's patch
 }
 
 void sanitize_gasmix(struct gasmix *mix)
@@ -1159,9 +1154,7 @@ static void fixup_dive_dc(struct dive *dive, struct divecomputer *dc)
 		/* if we have an explicit first cylinder */
 		if (sample->sensor == 0 && first_cylinder != 0)
 			sample->sensor = first_cylinder;
-
 		index = sample->sensor;
-
 		if (index == lastindex) {
 			/* Remove duplicate redundant pressure information */
 			if (pressure == lastpressure)
@@ -1207,7 +1200,6 @@ static void fixup_dive_dc(struct dive *dive, struct divecomputer *dc)
 		if (sample->cns > dive->maxcns)
 			dive->maxcns = sample->cns;
 	}
-
 	/* if all the samples for a cylinder have pressure data that
 	 * is basically equidistant throw out the sample cylinder pressure
 	 * information but make sure we still have a valid start and end
@@ -1222,8 +1214,8 @@ static void fixup_dive_dc(struct dive *dive, struct divecomputer *dc)
 	 * --- divinglog does there - but the code right now is only tested
 	 * --- for the single tank case */
 	for (j = 0; j < MAX_CYLINDERS; j++) {
+		cylinder_t *cyl = dive->cylinder + j;
 		if (abs(pressure_delta[j]) != INT_MAX) {
-			cylinder_t *cyl = dive->cylinder + j;
 			for (i = 0; i < dc->samples; i++)
 				if (dc->sample[i].sensor == j)
 					dc->sample[i].cylinderpressure.mbar = 0;
@@ -2515,13 +2507,8 @@ int count_dives_with_tag(const char *tag)
 	struct dive *d;
 
 	for_each_dive (i, d) {
-		if (same_string(tag, "")) {
-			// count dives with no tags
-			if (d->tag_list == NULL)
-				counter++;
-		} else if (taglist_contains(d->tag_list, tag)) {
+		if (taglist_contains(d->tag_list, tag))
 			counter++;
-		}
 	}
 	return counter;
 }
@@ -2535,13 +2522,8 @@ int count_dives_with_person(const char *person)
 	struct dive *d;
 
 	for_each_dive (i, d) {
-		if (same_string(person, "")) {
-			// solo dive
-			if (same_string(d->buddy, "") && same_string(d->divemaster, ""))
-				counter++;
-		} else if (string_sequence_contains(d->buddy, person) || string_sequence_contains(d->divemaster, person)) {
+		if (string_sequence_contains(d->buddy, person) || string_sequence_contains(d->divemaster, person))
 			counter++;
-		}
 	}
 	return counter;
 }
@@ -2559,20 +2541,6 @@ int count_dives_with_location(const char *location)
 	return counter;
 }
 
-// count the dives with exactly the suit
-int count_dives_with_suit(const char *suit)
-{
-	int i, counter = 0;
-	struct dive *d;
-
-	for_each_dive (i, d) {
-		if (same_string(d->suit, suit))
-			counter++;
-	}
-	return counter;
-}
-
-
 struct dive *merge_dives(struct dive *a, struct dive *b, int offset, bool prefer_downloaded)
 {
 	struct dive *res = alloc_dive();
diff --git a/parse-xml.c b/parse-xml.c
index 3e8c55b..d022090 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -557,6 +557,19 @@ static void get_dc_type(char *buffer, enum dive_comp_type *i)
 		*i = CCR;	// if the xml string = "CCR", set dc-type to CCR
 }				// otherwise the default dc-type is used (OC)
 
+/* Extract the cylinder use type from the xml text buffer */
+static void get_cylinderuse(char *buffer, enum cylinderuse *i)
+{
+	if (trimspace(buffer)) {
+		if (strcmp(buffer,"bailout") == 0)
+			*i = bailout;
+		else if (strcmp(buffer,"oxygen") == 0)
+			*i = oxygen;
+		else if (strcmp(buffer,"diluent") == 0)
+			*i = diluent;
+	}
+}
+
 #define MATCH(pattern, fn, dest) ({ 			\
 	/* Silly type compatibility test */ 		\
 	if (0) (fn)("test", dest);			\
@@ -912,6 +925,10 @@ 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("setpoint.sample", double_to_o2pressure, &sample->setpoint)) {
+		cur_dive->dc.dctype = CCR;
+		return;
+	}
 	if (MATCH("po2.sample", double_to_o2pressure, &sample->setpoint)) {
 		cur_dive->dc.dctype = CCR;
 		return;
@@ -1226,6 +1243,8 @@ static void try_to_fill_dive(struct dive *dive, const char *name, char *buf)
 		return;
 	if (MATCH("end.cylinder", pressure, &dive->cylinder[cur_cylinder_index].end))
 		return;
+	if (MATCH("cylinder_use.cylinder", get_cylinderuse, &dive->cylinder[cur_cylinder_index].cylinder_use))
+		return;
 	if (MATCH("description.weightsystem", utf8_string, &dive->weightsystem[cur_ws_index].description))
 		return;
 	if (MATCH("weight.weightsystem", weight, &dive->weightsystem[cur_ws_index].weight))
diff --git a/save-xml.c b/save-xml.c
index 51d3054..14c9458 100644
--- a/save-xml.c
+++ b/save-xml.c
@@ -163,6 +163,7 @@ static void put_gasmix(struct membuffer *b, struct gasmix *mix)
 static void save_cylinder_info(struct membuffer *b, struct dive *dive)
 {
 	int i, nr;
+	pressure_t pstart, pend;
 
 	nr = nr_cylinders(dive);
 
@@ -170,15 +171,22 @@ static void save_cylinder_info(struct membuffer *b, struct dive *dive)
 		cylinder_t *cylinder = dive->cylinder + i;
 		int volume = cylinder->type.size.mliter;
 		const char *description = cylinder->type.description;
-
 		put_format(b, "  <cylinder");
 		if (volume)
 			put_milli(b, " size='", volume, " l'");
 		put_pressure(b, cylinder->type.workingpressure, " workpressure='", " bar'");
 		show_utf8(b, description, " description='", "'", 1);
 		put_gasmix(b, &cylinder->gasmix);
-		put_pressure(b, cylinder->start.mbar ? cylinder->start : cylinder->sample_start, " start='", " bar'");
-		put_pressure(b, cylinder->end.mbar ? cylinder->end : cylinder->sample_end, " end='", " bar'");
+		put_pressure(b, cylinder->start.mbar ? cylinder->start : cylinder->sample_start, " start='", " bar'");	// Miika Turkia's patch
+		put_pressure(b, cylinder->end.mbar ? cylinder->end : cylinder->sample_end, " end='", " bar'");		// Miika Turkia's patch
+		switch (cylinder->cylinder_use) {
+		case oxygen:	put_string(b," cylinder_use='oxygen'");
+				break;
+		case diluent:	put_string(b," cylinder_use='diluent'");
+				break;
+		default:	put_string(b," cylinder_use='bailout'");
+				break;
+		}
 		put_format(b, " />\n");
 	}
 }
@@ -213,8 +221,7 @@ static void save_sample(struct membuffer *b, struct sample *sample, struct sampl
 	put_milli(b, " depth='", sample->depth.mm, " m'");
 	put_temperature(b, sample->temperature, " temp='", " C'");
 	put_pressure(b, sample->cylinderpressure, " pressure='", " bar'");
-	put_pressure(b, sample->diluentpressure, " pdiluent='", " bar'");
-
+	put_pressure(b, sample->diluentpressure, " pdiluent='"," bar'");
 	/*
 	 * We only show sensor information for samples with pressure, and only if it
 	 * changed from the previous sensor we showed.
@@ -252,6 +259,21 @@ 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'");
 		old->setpoint = sample->setpoint;
@@ -349,6 +371,11 @@ 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 == CCR) {
+		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