aboutsummaryrefslogtreecommitdiffstats
path: root/dive.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-10-28 13:48:15 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-10-28 14:04:19 -0700
commite32ba4d6d8115176e1ce0f4960926985b52164ca (patch)
tree8b45963724d70eaf69d2af61b81c27c836a1213e /dive.c
parent874754e22b8678ab3d5314c56fda860ea844fc55 (diff)
downloadsubsurface-e32ba4d6d8115176e1ce0f4960926985b52164ca.tar.gz
Improve tank handling for Cobalt
This isn't Cobalt specific, this is specific to dive computers that indicate the first tank that's in use with a gaschange event that coincides with the first sample. We need to make sure that we suppress showing that gas change event (regardless which cylinder it goes to) and instead set the correct cylinder index from the very start of the dive. This works with the test data I have and doesn't seem to break thing with any of the files that I tried... but I'm worried that this is not the right way to do things. Fixes #742 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'dive.c')
-rw-r--r--dive.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/dive.c b/dive.c
index 9395c93f9..9f4df56dc 100644
--- a/dive.c
+++ b/dive.c
@@ -782,6 +782,19 @@ static int same_rounded_pressure(pressure_t a, pressure_t b)
return abs(a.mbar - b.mbar) <= 500;
}
+/* Some dive computers (Cobalt) don't start the dive with cylinder 0 but explicitly
+ * tell us what the first gas is with a gas change event in the first sample.
+ * Sneakily we'll use a return value of 0 (or FALSE) when there is no explicit
+ * first cylinder - in which case cylinder 0 is indeed the first cylinder */
+int explicit_first_cylinder(struct dive *dive, struct divecomputer *dc)
+{
+ struct event *ev = get_next_event(dc->events, "gaschange");
+ if (ev && ev->time.seconds == dc->sample[0].time.seconds)
+ return get_cylinder_index(dive, ev);
+ else
+ return 0;
+}
+
void sanitize_gasmix(struct gasmix *mix)
{
unsigned int o2, he;
@@ -1095,10 +1108,14 @@ static void fixup_dive_dc(struct dive *dive, struct divecomputer *dc)
int lasto2val[3] = { 0, 0, 0 };
int lasttemp = 0, lastpressure = 0, lastdiluentpressure = 0;
int pressure_delta[MAX_CYLINDERS] = { INT_MAX, };
+ int first_cylinder;
/* Fixup duration and mean depth */
fixup_dc_duration(dc);
update_min_max_temperatures(dive, dc->watertemp);
+
+ /* make sure we know for which tank the pressure values are intended */
+ first_cylinder = explicit_first_cylinder(dive, dc);
for (i = 0; i < dc->samples; i++) {
struct sample *sample = dc->sample + i;
int time = sample->time.seconds;
@@ -1106,7 +1123,13 @@ static void fixup_dive_dc(struct dive *dive, struct divecomputer *dc)
int temp = sample->temperature.mkelvin;
int pressure = sample->cylinderpressure.mbar;
int diluent_pressure = sample->diluentpressure.mbar;
- int index = sample->sensor;
+ int index;
+
+ /* 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 */