These are two patches with CCR code updates, discussed on this forum
during the past 10 days.
They are hereby resubmitted.
The first patch deals with code modification.
The second patch does whitespace cleanup of the first path.
From 4954cffec322c54f21b122c5c26e42cb1c099c41 Mon Sep 17 00:00:00 2001
From: willem ferguson <[email protected]>
Date: Sat, 30 Aug 2014 17:46:47 +0200
Subject: [PATCH] CCR patch: adapt code for diluent cylinder pressures (3
of 4)
This patch implements the cylinder pressure calculations for diluent
gas in CCR dive computers. This is the third patch for achieving this.
The following were performed:
1) Add two lines to try_to_fill_sample() in parse-xml.c so that
diluent cylinder pressures are stored from XML dive log file
into structures of sample.
2) Add one line to populate_plot_entries() in profile.c so that
the diluent cylinder pressures are copied from structures of
sample to structures of plot_info.
3) add three constant #defines in profile.h
4) change populate_pressure_information() in gaspressures.c in
order to take into account pressure calculations for the
diluent cylinder, calling subordinate functions in the
appropriate way.
5) change create_plot_info_new() in profile.c in order to initiate
the pressure calculations for the diluent cylinder.
6) Implement two debugging functions (one in profile.c, another
in gaspressures.c). These debugging functions are activated
by means of #defines.
Two function calls dealing with oxygen pressure are currently commented out.
They will be activated in the following patch that
attends to CCR oxygen partial pressure calculation.
Signed-off-by: willem ferguson <[email protected]>
From 3e9260c09bb5e09946b5edaf2a2c68960fbd5e13 Mon Sep 17 00:00:00 2001
From: willem ferguson <[email protected]>
Date: Fri, 5 Sep 2014 18:30:56 +0200
Subject: [PATCH 2/2] Subject: [PATCH] CCR patch: adapt code for diluent
cylinder pressures (3)
Subject: [PATCH 4/4] Subject: [PATCH] CCR patch: adapt code for diluent
cylinder pressures (4 of 4)
This is the fourth patch in a series of four, dealing with the
calculation of cylinder pressures of diluent gas in CCR dives.
1) Do whitespace cleanup on CCR PATCH commit
3e9260c09bb5e09946b5edaf2a2c68960fbd5e13
Signed-off-by: willem ferguson <[email protected]>
Diluent gas calculation is now complete and activated for Poseidon CCR dive
logs.
The following two patches will deal with O2 partial pressures.
Kind regards,
willem
>From 4954cffec322c54f21b122c5c26e42cb1c099c41 Mon Sep 17 00:00:00 2001
From: willem ferguson <[email protected]>
Date: Sat, 30 Aug 2014 17:46:47 +0200
Subject: [PATCH] CCR patch: adapt code for diluent cylinder pressures (3)
This patch implements the cylinder pressure calculations for diluent
gas in CCR dive computers. This is the third patch for achieving this.
The following were performed:
1) Add two lines to try_to_fill_sample() in parse-xml so that
diluent cylinder pressures are stored from XML dive log file
into structures of sample.
2) Add one line to populate_plot_entries() in profile.c so that
the diluent cylinder pressures are copied from structures of
sample to structures of plot_info.
3) add three constant #defines in profile.h
4) change populate_pressure_information() in gaspressures.c in
order to take into account pressure calculations for the
diluent cylinder, calling subordinate functions in the
appropriate way.
5) change create_plot_info_new() in profile.c in order to initiate
the pressure calculations for the diluent cylinder.
6) Implement two debugging functions (one in profile.c, another
in gaspressures.c). These debugging functions are activated
by means of #defines.
Two function calls dealing with oxygen pressure are currently commented out.
They will be activated in the following patch that
attends to CCR oxygen partial pressure calculation.
Signed-off-by: willem ferguson <[email protected]>
---
gaspressures.c | 66 +++++++++++++++++++++++++++++++++++++++++++++-------------
parse-xml.c | 2 ++
profile.c | 52 +++++++++++++++++++++++++++++++++++++++------
profile.h | 2 ++
4 files changed, 102 insertions(+), 20 deletions(-)
diff --git a/gaspressures.c b/gaspressures.c
index be63f87..dfd6b6a 100644
--- a/gaspressures.c
+++ b/gaspressures.c
@@ -316,19 +316,46 @@ static inline int calc_pressure_time(struct dive *dive, struct divecomputer *dc,
return depth_to_mbar(depth, dive) * time;
}
-void populate_pressure_information(struct dive *dive, struct divecomputer *dc, struct plot_info *pi)
+#ifdef PRINT_PRESSURES_DEBUG
+// A CCR debugging tool that prints the gas pressures in cylinder 0 and in the diluent cylinder, used in populate_pressure_information():
+static void debug_print_pressures(struct plot_info *pi)
{
- int i, cylinderindex;
+ int i;
+ for (i = 0; i < pi->nr; i++) {
+ struct plot_data *entry = pi->entry + i;
+ printf("%5d |%9d | %9d || %9d | %9d |\n",i,SENSOR_PRESSURE(entry),INTERPOLATED_PRESSURE(entry),DILUENT_PRESSURE(entry),INTERPOLATED_DILUENT_PRESSURE(entry));
+ }
+}
+#endif
+
+/* This function goes through the list of tank pressures, either SENSOR_PRESSURE(entry) or DILUENT_PRESSURE(entry),
+ * of structure plot_info for the dive profile where each item in the list corresponds to one point (node) of the
+ * profile. It finds values for which there are no tank pressures (pressure==0). For each missing item (node) of
+ * tank pressure it creates a pr_track_alloc structure that represents a segment on the dive profile and that
+ * contains tank pressures. There is a linked list of pr_track_alloc structures for each cylinder. These pr_track_alloc
+ * structures ultimately allow for filling the missing tank pressure values on the dive profile using the depth_pressure
+ * of the dive. To do this, it calculates the summed pressure-time value for the duration of the dive and stores these
+ * in the pr_track_alloc structures. If diluent_flag = 1, then DILUENT_PRESSURE(entry) is used instead of SENSOR_PRESSURE.
+ * This function is called by create_plot_info_new() in profile.c
+ */
+void populate_pressure_information(struct dive *dive, struct divecomputer *dc, struct plot_info *pi, int diluent_flag)
+{
+ int i, cylinderid, cylinderindex = -1;
pr_track_t *track_pr[MAX_CYLINDERS] = { NULL, };
- pr_track_t *current;
+ pr_track_t *current = NULL;
bool missing_pr = false;
- cylinderindex = -1;
- current = NULL;
for (i = 0; i < pi->nr; i++) {
struct plot_data *entry = pi->entry + i;
- int pressure = SENSOR_PRESSURE(entry);
-
+ unsigned pressure;
+ if (diluent_flag) { // if this is a diluent cylinder:
+ pressure = DILUENT_PRESSURE(entry);
+ cylinderid = DILUENT_CYLINDER;
+ } else {
+ pressure = SENSOR_PRESSURE(entry);
+ cylinderid = entry->cylinderindex;
+ }
+ /* If track_pr structure already exists, then update it: */
/* discrete integration of pressure over time to get the SAC rate equivalent */
if (current) {
entry->pressure_time = calc_pressure_time(dive, dc, entry - 1, entry);
@@ -336,33 +363,44 @@ void populate_pressure_information(struct dive *dive, struct divecomputer *dc, s
current->t_end = entry->sec;
}
+ /* If 1st record or different cylinder: Create a new track_pr structure: */
/* track the segments per cylinder and their pressure/time integral */
- if (entry->cylinderindex != cylinderindex) {
- cylinderindex = entry->cylinderindex;
+ if (cylinderid != cylinderindex) {
+ if (diluent_flag) // For CCR dives:
+ cylinderindex = DILUENT_CYLINDER; // indicate diluent cylinder
+ else
+ cylinderindex = entry->cylinderindex;
current = pr_track_alloc(pressure, entry->sec);
track_pr[cylinderindex] = list_add(track_pr[cylinderindex], current);
continue;
}
if (!pressure) {
- missing_pr = 1;
+ missing_pr = 1;
continue;
}
-
current->end = pressure;
/* Was it continuous? */
- if (SENSOR_PRESSURE(entry - 1))
+ if ((diluent_flag) && (DILUENT_PRESSURE(entry-1))) // in the case of CCR diluent pressure
+ continue;
+ else if (SENSOR_PRESSURE(entry - 1)) // for all other cylinders
continue;
- /* transmitter changed its working status */
+ /* transmitter stopped transmitting cylinder pressure data */
current = pr_track_alloc(pressure, entry->sec);
track_pr[cylinderindex] = list_add(track_pr[cylinderindex], current);
}
if (missing_pr) {
- fill_missing_tank_pressures(dive, pi, track_pr, 0);
+ fill_missing_tank_pressures(dive, pi, track_pr, diluent_flag);
}
+
+#ifdef PRINT_PRESSURES_DEBUG
+ debug_print_pressures(pi);
+#endif
+
for (i = 0; i < MAX_CYLINDERS; i++)
list_free(track_pr[i]);
}
+
diff --git a/parse-xml.c b/parse-xml.c
index 8e0099d..b1b40fc 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -835,6 +835,8 @@ static void try_to_fill_sample(struct sample *sample, const char *name, char *bu
return;
if (MATCH("cylpress.sample", pressure, &sample->cylinderpressure))
return;
+ if (MATCH("pdiluent.sample", pressure, &sample->diluentpressure))
+ return;
if (MATCH("cylinderindex.sample", get_cylinderindex, &sample->sensor))
return;
if (MATCH("sensor.sample", get_sensor, &sample->sensor))
diff --git a/profile.c b/profile.c
index 044da0e..0d8b5b6 100644
--- a/profile.c
+++ b/profile.c
@@ -23,8 +23,8 @@ static struct plot_data *last_pi_entry_new = NULL;
void fill_missing_segment_pressures(pr_track_t*);
struct pr_interpolate_struct get_pr_interpolate_data(pr_track_t*, struct plot_info*, int);
-void fill_missing_tank_pressures(struct dive*, struct plot_info*, pr_track_t**);
-void populate_pressure_information(struct dive*, struct divecomputer*, struct plot_info*);
+void fill_missing_tank_pressures(struct dive*, struct plot_info*, pr_track_t**, int);
+void populate_pressure_information(struct dive*, struct divecomputer*, struct plot_info*, int);
#ifdef DEBUG_PI
/* debugging tool - not normally used */
@@ -554,6 +554,7 @@ struct plot_data *populate_plot_entries(struct dive *dive, struct divecomputer *
/* FIXME! sensor index -> cylinder index translation! */
entry->cylinderindex = sample->sensor;
SENSOR_PRESSURE(entry) = sample->cylinderpressure.mbar;
+ DILUENT_PRESSURE(entry) = sample->diluentpressure.mbar;
if (sample->temperature.mkelvin)
entry->temperature = lasttemp = sample->temperature.mkelvin;
else
@@ -858,6 +859,30 @@ static void calculate_gas_information_new(struct dive *dive, struct plot_info *p
entry->eadd = 0;
}
}
+
+#ifdef DEBUG_GAS
+/* A CCR debug function that writes the cylinder pressure and the oxygen values to the file debug_print_profiledata.dat:
+ * Called in create_plot_info_new()
+ */
+static void debug_print_profiledata(struct plot_info *pi)
+{
+ FILE *f1;
+ struct plot_data *entry;
+ int i;
+ if(!(f1 = fopen("debug_print_profiledata.dat","w"))) printf("File open error for: debug_print_profiledata.dat\n");
+ else {
+ fprintf(f1,"id t1 gas gasint t2 t3 dil dilint t4 t5 setpoint sensor1 sensor2 sensor3 t6 po2 fo2\n");
+ for(i=0; i< pi->nr; i++) {
+ entry = pi->entry + i;
+ fprintf(f1,"%d gas=%8d %8d ; dil=%8d %8d ; o2_sp= %f %f %f %f PO2= %f\n",i,SENSOR_PRESSURE(entry),
+ INTERPOLATED_PRESSURE(entry),DILUENT_PRESSURE(entry),INTERPOLATED_DILUENT_PRESSURE(entry),
+ entry->o2setpoint,entry->o2sensor[0],entry->o2sensor[1],entry->o2sensor[2],entry->po2);
+ }
+ fclose(f1);
+ }
+}
+#endif
+
/*
* Create a plot-info with smoothing and ranged min/max
*
@@ -867,10 +892,13 @@ static void calculate_gas_information_new(struct dive *dive, struct plot_info *p
*/
void create_plot_info_new(struct dive *dive, struct divecomputer *dc, struct plot_info *pi)
{
- int o2, he, o2low;
+ FILE *f1;
+ int i,o2, he, o2low;
+ struct plot_data *entry;
init_decompression(dive);
/* Create the new plot data */
free((void *)last_pi_entry_new);
+
get_dive_gas(dive, &o2, &he, &o2low);
if (he > 0) {
pi->dive_type = TRIMIX;
@@ -881,12 +909,24 @@ void create_plot_info_new(struct dive *dive, struct divecomputer *dc, struct plo
pi->dive_type = AIR;
}
last_pi_entry_new = populate_plot_entries(dive, dc, pi);
- check_gas_change_events(dive, dc, pi); /* Populate the gas index from the gas change events */
- setup_gas_sensor_pressure(dive, dc, pi); /* Try to populate our gas pressure knowledge */
- populate_pressure_information(dive, dc, pi); /* .. calculate missing pressure entries */
+
+ check_gas_change_events(dive, dc, pi); /* Populate the gas index from the gas change events */
+ 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);
+ 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);
+// calculate_gas_information_new(dive, dc, pi); /* And finaly calculate gas partial pressures */
calculate_gas_information_new(dive, pi); /* And finaly calculate gas partial pressures */
+
+#ifdef DEBUG_GAS
+ debug_print_profiledata(pi);
+#endif
+
pi->meandepth = dive->dc.meandepth.mm;
analyze_plot_info(pi);
}
diff --git a/profile.h b/profile.h
index d6f3f9c..0a7abf5 100644
--- a/profile.h
+++ b/profile.h
@@ -86,6 +86,8 @@ int get_maxtime(struct plot_info *pi);
int get_maxdepth(struct plot_info *pi);
#define DILUENT_CYLINDER 1
+#define DILUENT 1
+#define NONDILUENT 0
#define SENSOR_PR 0
#define INTERPOLATED_PR 1
#define SENSOR_PRESSURE(_entry) (_entry)->pressure[SENSOR_PR]
--
1.9.1
>From 3e9260c09bb5e09946b5edaf2a2c68960fbd5e13 Mon Sep 17 00:00:00 2001
From: willem ferguson <[email protected]>
Date: Fri, 5 Sep 2014 18:30:56 +0200
Subject: [PATCH 2/2] Subject: [PATCH] CCR patch: adapt code for diluent
cylinder pressures (3)
Perform whitespace cleanup on the previous patch with the same heading.
This is patch four of a series of four dealing with the calculation of
diluent gas pressures in CCR dive logs.
These calculations are now finalised and activated.
Following patches will deal with oxygen partial pressure calculation.
Signed-off-by: willem ferguson <[email protected]>
---
gaspressures.c | 2 +-
parse-xml.c | 2 +-
profile.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/gaspressures.c b/gaspressures.c
index dfd6b6a..c653f08 100644
--- a/gaspressures.c
+++ b/gaspressures.c
@@ -376,7 +376,7 @@ void populate_pressure_information(struct dive *dive, struct divecomputer *dc, s
}
if (!pressure) {
- missing_pr = 1;
+ missing_pr = 1;
continue;
}
current->end = pressure;
diff --git a/parse-xml.c b/parse-xml.c
index b1b40fc..02cf9f7 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -836,7 +836,7 @@ static void try_to_fill_sample(struct sample *sample, const char *name, char *bu
if (MATCH("cylpress.sample", pressure, &sample->cylinderpressure))
return;
if (MATCH("pdiluent.sample", pressure, &sample->diluentpressure))
- return;
+ return;
if (MATCH("cylinderindex.sample", get_cylinderindex, &sample->sensor))
return;
if (MATCH("sensor.sample", get_sensor, &sample->sensor))
diff --git a/profile.c b/profile.c
index 0d8b5b6..32b914b 100644
--- a/profile.c
+++ b/profile.c
@@ -867,7 +867,7 @@ static void calculate_gas_information_new(struct dive *dive, struct plot_info *p
static void debug_print_profiledata(struct plot_info *pi)
{
FILE *f1;
- struct plot_data *entry;
+ struct plot_data *entry;
int i;
if(!(f1 = fopen("debug_print_profiledata.dat","w"))) printf("File open error for: debug_print_profiledata.dat\n");
else {
--
1.9.1
_______________________________________________
subsurface mailing list
[email protected]
http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface