Hi.

2015-06-15 20:51 GMT+02:00, Linus Torvalds <torva...@linux-foundation.org>:
>
> I can add it trivially to libdivecomputer, although right now
> subsurface just ignores DC_SAMPLE_RBT. So we'd have to add it to our
> sample structure etc, like the heartbeat and bearing thing we already
> do save. I'd argue that airtime reporting from the dive computer is no
> less important, even if it's just a heuristic based on pressure and we
> could just make up our own calculations if we wanted to..
>

I made this sometime ago while playing with the smarttrak files
import, just to get rid of the annoying messages reported from
sample_cb().   Then forgot about it.

If Linus hasn't done yet as part of his EON Steel import, this should
do the work.

Regards.

Salva.
From 3c7d6cff2f98fd7fc33e8cb03572d4dab5763b18 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Salvador=20Cu=C3=B1at?= <salvador.cu...@gmail.com>
Date: Wed, 22 Jul 2015 17:02:33 +0200
Subject: [PATCH 1/3] Add support for RBT reported sample value
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

RBT (Remaining Bottom Time) is a value calculated on the fly by some air
integrated divecomputers, tipically Uwatec devices. This value is an
estimation based in some heuristic around time function pressure
gradients. This way, RBT would be the time a diver can spend at actual
depth without running out of gas (taking account of ascent, deco, if
required, and rock bottom gas reserve, if set).
Older Uwatec devices just made the calculus and only stored alarm events
if this time value reached zero, but modern devices store the value each
sample, in minutes.
It seems that Suunto Eon Steel is storing RBT values too, in seconds.

Libdivecomputer has supported RBT for a while, but Subsurface just
printed it to stdout and dropped it.

This adds support for RBT value on subsurface sample structure and shows
it in the profile's info box, right under TTS(calc), if selected, where
these two values can be easily compared by humans.

Signed-off-by: Salvador Cuñat <salvador.cu...@gmail.com>
---
 dive.h            | 3 ++-
 libdivecomputer.c | 2 +-
 profile.c         | 5 ++++-
 profile.h         | 1 +
 4 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/dive.h b/dive.h
index f53d46f..edd4224 100644
--- a/dive.h
+++ b/dive.h
@@ -176,6 +176,7 @@ struct sample                         // BASE TYPE BYTES  UNITS    RANGE      DE
 	duration_t stoptime;           // uint32_t   4  seconds  (0-18 h)     time duration of next deco stop
 	duration_t ndl;                // uint32_t   4  seconds  (0-18 h)     time duration before no-deco limit
 	duration_t tts;                // uint32_t   4  seconds  (0-18 h)     time duration to reach the surface
+	duration_t rbt;                // uint32_t   4  seconds  (0-18 h)     remaining bottom time
 	depth_t depth;                 // int32_t    4    mm     (0-2000 km)  dive depth of this sample
 	depth_t stopdepth;             // int32_t    4    mm     (0-2000 km)  depth of next deco stop
 	temperature_t temperature;     // int32_t    4  mdegrK   (0-2 MdegK)  ambient temperature
@@ -191,7 +192,7 @@ struct sample                         // BASE TYPE BYTES  UNITS    RANGE      DE
 	bool in_deco;                  // bool       1    y/n      y/n        this sample is part of deco
 	bool manually_entered;         // bool       1    y/n      y/n        this sample was entered by the user,
 				       //                                     not calculated when planning a dive
-};                      // Total size of structure: 53 bytes, excluding padding at end
+};                      // Total size of structure: 57 bytes, excluding padding at end
 
 struct divetag {
 	/*
diff --git a/libdivecomputer.c b/libdivecomputer.c
index edefaab..64e76e3 100644
--- a/libdivecomputer.c
+++ b/libdivecomputer.c
@@ -246,7 +246,7 @@ sample_cb(dc_sample_type_t type, dc_sample_value_t value, void *userdata)
 		handle_event(dc, sample, value);
 		break;
 	case DC_SAMPLE_RBT:
-		printf("   <rbt>%u</rbt>\n", value.rbt);
+		sample->rbt.seconds = (!strncasecmp(dc->model, "suunto", 6)) ? value.rbt : value.rbt * 60;
 		break;
 	case DC_SAMPLE_HEARTBEAT:
 		sample->heartbeat = value.heartbeat;
diff --git a/profile.c b/profile.c
index 74382b0..51f322c 100644
--- a/profile.c
+++ b/profile.c
@@ -637,7 +637,8 @@ struct plot_data *populate_plot_entries(struct dive *dive, struct divecomputer *
 		entry->heartbeat = sample->heartbeat;
 		entry->bearing = sample->bearing.degrees;
 		entry->sac = sample->sac.mliter;
-
+		if (sample->rbt.seconds)
+			entry->rbt = sample->rbt.seconds;
 		/* skip events that happened at this time */
 		while (ev && ev->time.seconds == time)
 			ev = ev->next;
@@ -1197,6 +1198,8 @@ static void plot_string(struct plot_info *pi, struct plot_data *entry, struct me
 	}
 	if (entry->tts_calc)
 		put_format(b, translate("gettextFromC", "TTS: %umin (calc)\n"), DIV_UP(entry->tts_calc, 60));
+	if (entry->rbt)
+		put_format(b, translate("gettextFromC", "RBT: %umin\n"), DIV_UP(entry->rbt, 60));
 	if (entry->ceiling) {
 		depthvalue = get_depth_units(entry->ceiling, NULL, &depth_unit);
 		put_format(b, translate("gettextFromC", "Calculated ceiling %.0f%s\n"), depthvalue, depth_unit);
diff --git a/profile.h b/profile.h
index 36b8aa7..a6dbfcf 100644
--- a/profile.h
+++ b/profile.h
@@ -34,6 +34,7 @@ struct plot_data {
 	int percentages[16];
 	int ndl;
 	int tts;
+	int rbt;
 	int stoptime;
 	int stopdepth;
 	int cns;
-- 
2.1.4

From 5554d205cefe90418539d30761aabd920e8219a8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Salvador=20Cu=C3=B1at?= <salvador.cu...@gmail.com>
Date: Wed, 22 Jul 2015 17:20:39 +0200
Subject: [PATCH 2/3] RBT - Add save/load in xml file support
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Salvador Cuñat <salvador.cu...@gmail.com>
---
 parse-xml.c | 2 ++
 save-xml.c  | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/parse-xml.c b/parse-xml.c
index 3d0c6a1..a94fa0a 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -936,6 +936,8 @@ static void try_to_fill_sample(struct sample *sample, const char *name, char *bu
 		return;
 	if (MATCH("cns.sample", get_uint8, &sample->cns))
 		return;
+	if (MATCH("rbt.sample", sampletime, &sample->rbt))
+		return;
 	if (MATCH("sensor1.sample", double_to_o2pressure, &sample->o2sensor[0])) // CCR O2 sensor data
 		return;
 	if (MATCH("sensor2.sample", double_to_o2pressure, &sample->o2sensor[1]))
diff --git a/save-xml.c b/save-xml.c
index 160b5fc..00f4626 100644
--- a/save-xml.c
+++ b/save-xml.c
@@ -210,6 +210,8 @@ static void save_sample(struct membuffer *b, struct sample *sample, struct sampl
 		put_format(b, " tts='%u:%02u min'", FRACTION(sample->tts.seconds, 60));
 		old->tts = sample->tts;
 	}
+	if (sample->rbt.seconds)
+		put_format(b, " rbt='%u:%02u min'", FRACTION(sample->rbt.seconds, 60));
 	if (sample->in_deco != old->in_deco) {
 		put_format(b, " in_deco='%d'", sample->in_deco ? 1 : 0);
 		old->in_deco = sample->in_deco;
-- 
2.1.4

From 66a4765590cff31523eaf26818a3ff68cf5fbc2b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Salvador=20Cu=C3=B1at?= <salvador.cu...@gmail.com>
Date: Wed, 22 Jul 2015 17:23:20 +0200
Subject: [PATCH 3/3] RBT - Add load/save in git storage support
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Salvador Cuñat <salvador.cu...@gmail.com>
---
 load-git.c | 6 ++++++
 save-git.c | 3 +++
 2 files changed, 9 insertions(+)

diff --git a/load-git.c b/load-git.c
index 649663f..753ad41 100644
--- a/load-git.c
+++ b/load-git.c
@@ -497,6 +497,12 @@ static void parse_sample_keyvalue(void *_sample, const char *key, const char *va
 		sample->cns = atoi(value);
 		return;
 	}
+
+	if (!strcmp(key, "rbt")) {
+		sample->rbt = get_duration(value);
+		return;
+	}
+
 	if (!strcmp(key, "po2")) {
 		pressure_t p = get_pressure(value);
 		sample->setpoint.mbar = p.mbar;
diff --git a/save-git.c b/save-git.c
index c47d899..559666d 100644
--- a/save-git.c
+++ b/save-git.c
@@ -303,6 +303,9 @@ static void save_sample(struct membuffer *b, struct sample *sample, struct sampl
 		old->cns = sample->cns;
 	}
 
+	if (sample->rbt.seconds)
+		put_format(b, " rbt=%u:%02u", FRACTION(sample->rbt.seconds, 60));
+
 	if (sample->o2sensor[0].mbar != old->o2sensor[0].mbar) {
 		put_milli(b, " sensor1=", sample->o2sensor[0].mbar, "bar");
 		old->o2sensor[0] = sample->o2sensor[0];
-- 
2.1.4

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

Reply via email to