2017-04-27 18:24:53 +00:00
|
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2011-09-20 19:40:34 +00:00
|
|
|
|
/* profile.c */
|
2012-08-26 21:41:05 +00:00
|
|
|
|
/* creates all the necessary data for drawing the dive profile
|
2011-09-20 19:40:34 +00:00
|
|
|
|
*/
|
2013-10-06 15:55:58 +00:00
|
|
|
|
#include "gettext.h"
|
2013-09-25 00:07:07 +00:00
|
|
|
|
#include <limits.h>
|
2013-10-05 07:29:09 +00:00
|
|
|
|
#include <string.h>
|
2014-10-14 08:46:40 +00:00
|
|
|
|
#include <assert.h>
|
2023-12-03 21:59:21 +00:00
|
|
|
|
#include <stdlib.h>
|
2011-08-31 17:20:46 +00:00
|
|
|
|
|
|
|
|
|
#include "dive.h"
|
2011-09-05 19:12:58 +00:00
|
|
|
|
#include "divelist.h"
|
2024-06-18 20:23:57 +00:00
|
|
|
|
#include "divelog.h"
|
2024-03-24 20:03:08 +00:00
|
|
|
|
#include "errorhelper.h"
|
2020-10-25 08:14:16 +00:00
|
|
|
|
#include "event.h"
|
2020-10-25 17:14:23 +00:00
|
|
|
|
#include "interpolate.h"
|
2020-10-25 12:28:55 +00:00
|
|
|
|
#include "sample.h"
|
2020-10-25 08:14:16 +00:00
|
|
|
|
#include "subsurface-string.h"
|
2013-05-04 19:41:49 +00:00
|
|
|
|
|
2013-05-04 22:36:40 +00:00
|
|
|
|
#include "profile.h"
|
2014-08-24 18:48:22 +00:00
|
|
|
|
#include "gaspressures.h"
|
2013-05-30 18:56:00 +00:00
|
|
|
|
#include "deco.h"
|
2024-03-12 07:52:21 +00:00
|
|
|
|
#include "errorhelper.h"
|
2012-11-10 10:40:35 +00:00
|
|
|
|
#include "libdivecomputer/parser.h"
|
2012-11-29 04:13:21 +00:00
|
|
|
|
#include "libdivecomputer/version.h"
|
2014-01-19 00:21:13 +00:00
|
|
|
|
#include "membuffer.h"
|
2018-02-24 22:28:13 +00:00
|
|
|
|
#include "qthelper.h"
|
2024-05-28 19:31:11 +00:00
|
|
|
|
#include "range.h"
|
2018-03-14 19:37:19 +00:00
|
|
|
|
#include "format.h"
|
2011-08-31 17:20:46 +00:00
|
|
|
|
|
2014-10-13 19:19:21 +00:00
|
|
|
|
//#define DEBUG_GAS 1
|
|
|
|
|
|
2015-10-12 20:34:15 +00:00
|
|
|
|
#define MAX_PROFILE_DECO 7200
|
|
|
|
|
|
2024-05-04 16:45:55 +00:00
|
|
|
|
int ascent_velocity(int depth, int avg_depth, int bottom_time);
|
2015-10-12 20:34:15 +00:00
|
|
|
|
|
2013-12-19 21:11:43 +00:00
|
|
|
|
#ifdef DEBUG_PI
|
2011-11-04 21:32:15 +00:00
|
|
|
|
/* debugging tool - not normally used */
|
2024-05-03 16:51:03 +00:00
|
|
|
|
static void dump_pi(const struct plot_info &pi)
|
2011-11-04 21:32:15 +00:00
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
printf("pi:{nr:%d maxtime:%d meandepth:%d maxdepth:%d \n"
|
2014-02-28 04:09:57 +00:00
|
|
|
|
" maxpressure:%d mintemp:%d maxtemp:%d\n",
|
2024-05-03 16:51:03 +00:00
|
|
|
|
pi.nr, pi.maxtime, pi.meandepth, pi.maxdepth,
|
|
|
|
|
pi.maxpressure, pi.mintemp, pi.maxtemp);
|
|
|
|
|
for (i = 0; i < pi.nr; i++) {
|
|
|
|
|
struct plot_data &entry = pi.entry[i];
|
Fix overly complicated and fragile "same_cylinder" logic
The plot-info per-event 'same_cylinder' logic was fragile, and caused
us to not print the beginning pressure of the first cylinder.
In particular, there was a nasty interaction with not all plot entries
having pressures, and the whole logic that avoid some of the early
plot entries because they are fake entries that are just there to make
sure that we don't step off the edge of the world. When we then only
do certain things on the particular entries that don't have the same
cylinder as the last plot entry, things don't always happen like they
should.
Fix this by:
- get rid of the computed "same_cylinder" state entirely. All the
cases where we use it, we might as well just look at what the last
cylinder we used was, and thus "same_cylinder" is just about testing
the current cylinder index against that last index.
- get rid of some of the edge conditions by just writing the loops
more clearly, so that they simply don't have special cases. For
example, instead of setting some "last_pressure" for a cylinder at
cylinder changes, just set the damn thing on every single sample. The
last pressure will automatically be the pressure we set last! The code
is simpler and more straightforward.
So this simplifies the code and just makes it less fragile - it
doesn't matter if the cylinder change happens to happen at a sample
that doesn't have a pressure reading, for example, because we no
longer care so deeply about exactly which sample the cylinder change
happens at. As a result, the bug Mika noticed just goes away.
Reported-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-25 01:55:48 +00:00
|
|
|
|
printf(" entry[%d]:{cylinderindex:%d sec:%d pressure:{%d,%d}\n"
|
2014-02-28 04:09:57 +00:00
|
|
|
|
" time:%d:%02d temperature:%d depth:%d stopdepth:%d stoptime:%d ndl:%d smoothed:%d po2:%lf phe:%lf pn2:%lf sum-pp %lf}\n",
|
2024-05-03 16:51:03 +00:00
|
|
|
|
i, entry.sensor[0], entry.sec,
|
|
|
|
|
entry.pressure[0], entry.pressure[1],
|
|
|
|
|
entry.sec / 60, entry.sec % 60,
|
|
|
|
|
entry.temperature, entry.depth, entry.stopdepth, entry.stoptime, entry.ndl, entry.smoothed,
|
|
|
|
|
entry.pressures.o2, entry.pressures.he, entry.pressures.n2,
|
|
|
|
|
entry.pressures.o2 + entry.pressures.he + entry.pressures.n2);
|
2012-12-01 21:02:30 +00:00
|
|
|
|
}
|
2011-11-04 21:32:15 +00:00
|
|
|
|
printf(" }\n");
|
|
|
|
|
}
|
2013-12-19 21:11:43 +00:00
|
|
|
|
#endif
|
2011-11-04 21:32:15 +00:00
|
|
|
|
|
2024-03-10 22:11:23 +00:00
|
|
|
|
template<typename T>
|
|
|
|
|
static T round_up(T x, T y)
|
|
|
|
|
{
|
|
|
|
|
return ((x + y - 1) / y) * y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
static T div_up(T x, T y)
|
|
|
|
|
{
|
|
|
|
|
return (x + y - 1) / y;
|
|
|
|
|
}
|
2013-05-03 18:04:51 +00:00
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
plot_info::plot_info()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
plot_info::~plot_info()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-31 21:35:31 +00:00
|
|
|
|
/*
|
|
|
|
|
* When showing dive profiles, we scale things to the
|
|
|
|
|
* current dive. However, we don't scale past less than
|
|
|
|
|
* 30 minutes or 90 ft, just so that small dives show
|
2012-06-11 00:45:36 +00:00
|
|
|
|
* up as such unless zoom is enabled.
|
2011-08-31 21:35:31 +00:00
|
|
|
|
*/
|
2024-05-03 16:51:03 +00:00
|
|
|
|
int get_maxtime(const struct plot_info &pi)
|
2011-08-31 21:15:50 +00:00
|
|
|
|
{
|
2024-05-03 16:51:03 +00:00
|
|
|
|
int seconds = pi.maxtime;
|
2021-08-29 07:23:38 +00:00
|
|
|
|
int min = prefs.zoomed_plot ? 30 : 30 * 60;
|
2024-03-23 08:16:59 +00:00
|
|
|
|
return std::max(min, seconds);
|
2011-08-31 21:15:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-04 20:04:26 +00:00
|
|
|
|
/* get the maximum depth to which we want to plot */
|
2024-05-03 16:51:03 +00:00
|
|
|
|
int get_maxdepth(const struct plot_info &pi)
|
2011-08-31 21:15:50 +00:00
|
|
|
|
{
|
2021-12-04 20:04:26 +00:00
|
|
|
|
/* 3m to spare */
|
2024-05-03 16:51:03 +00:00
|
|
|
|
int mm = pi.maxdepth + 3000;
|
2024-03-23 08:16:59 +00:00
|
|
|
|
return prefs.zoomed_plot ? mm : std::max(30000, mm);
|
2011-08-31 21:15:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-07 21:13:30 +00:00
|
|
|
|
/* UNUSED! */
|
2024-05-03 16:51:03 +00:00
|
|
|
|
static int get_local_sac(struct plot_info &pi, int idx1, int idx2, struct dive *dive) __attribute__((unused));
|
2015-11-07 21:13:30 +00:00
|
|
|
|
|
2013-02-25 23:23:16 +00:00
|
|
|
|
/* Get local sac-rate (in ml/min) between entry1 and entry2 */
|
2024-05-03 16:51:03 +00:00
|
|
|
|
static int get_local_sac(struct plot_info &pi, int idx1, int idx2, struct dive *dive)
|
2013-02-21 02:57:50 +00:00
|
|
|
|
{
|
Profile support for multiple concurrent pressure sensors
This finally handles multiple cylinder pressures, both overlapping and
consecutive, and it seems to work on the nasty cases I've thrown at it.
Want to just track five different cylinders all at once, without any
pesky gas switch events? Sure, you can do that. It will show five
different gas pressures for your five cylinders, and they will go down
as you breathe down the cylinders.
I obviously don't have any real data for that case, but I do have a test
file with five actual cylinders that all have samples over the whole
course of the dive. The end result looks messy as hell, but what did
you expect?
HOWEVER.
The only way to do this sanely was
- actually make the "struct plot_info" have all the cylinder pressures
(so no "sensor index and pressure" - every cylinder has a pressure for
every plot info entry)
This obviously makes the plot_info much bigger. We used to have
MAX_CYLINDERS be a fairly generous 8, which seems sane. The planning
code made that 8 be 20. That seems questionable. But whatever.
The good news is that the plot-info should hopefully get freed, and
only be allocated one dive at a time, so the fact that it is big and
nasty shouldn't be a scaling issue, though.
- the "populate_pressure_information()" function had to be rewritten
quite a bit. The good news is that it's actually simpler now, although
I would not go so far as to really call it simple. It's still
complicated and suble, but now it explicitly just does one cylinder at
a time.
It *used* to have this insanely complicated "keep track of the pressure
ranges for every cylinder at once". I just couldn't stand that model
and keep my sanity, so it now just tracks one cylinder at a time, and
doesn't have an array of live data, instead the caller will just call
it for each cylinder.
- get rid of some of our hackier stuff, like the code that populates the
plot_info data code with the currently selected cylinder number, and
clears out any other pressures. That obviously does *not* work when you
may not have a single primary cylinder any more.
Now, the above sounds like all good things. Yeah, it mostly is.
BUT.
There's a few big downsides from the above:
- there's no sane way to do this as a series of small changes.
The change to make the plot_info take an array of cylinder pressures
rather than the sensor+pressure model really isn't amenable to "fix up
one use at a time". When you switch over to the new data structure
model, you have to switch over to the new way of populating the
pressure ranges. The two just go hand in hand.
- Some of our code *depended* on the "sensor+pressure" model. I fixed all
the ones I could sanely fix. There was one particular case that I just
couldn't sanely fix, and I didn't care enough about it to do something
insane.
So the only _known_ breakage is the "TankItem" profile widget. That's
the bar at the bottom of the profile that shows which cylinder is in
use right now. You'd think that would be trivial to fix up, and yes it
would be - I could just use the regular model of
firstcyl = explicit_first_cylinder(dive, dc)
.. then iterate over the gas change events to see the others ..
but the problem with the "TankItem" widget is that it does its own
model, and it has thrown away the dive and the dive computer
information. It just doesn't even know. It only knows what cylinders
there are, and the plot_info. And it just used to look at the sensor
number in the plot_info, and be done with that. That number no longer
exists.
- I have tested it, and I think the code is better, but hey, it's a
fairly large patch to some of the more complex code in our code base.
That "interpolate missing pressure fields" code really isn't pretty. It
may be prettier, but..
Anyway, without further ado, here's the patch. No sign-off yet, because I
do think people should look and comment. But I think the patch is fine,
and I'll fix anythign that anybody can find, *except* for that TankItem
thing that I will refuse to touch. That class is ugly. It needs to have
access to the actual dive.
Note how it actually does remove more lines than it adds, and that's
despite added comments etc. The code really is simpler, but there may be
cases in there that need more work.
Known missing pieces that don't currently take advantage of concurrent
cylinder pressure data:
- the momentary SAC rate coloring for dives will need more work
- dive merging (but we expect to generally normally not merge dive
computers, which is the main source of sensor data)
- actually taking advantage of different sensor data from different
dive computers
But most of all: Testing. Lots and lots of testing to find all the
corner cases.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-27 17:17:05 +00:00
|
|
|
|
int index = 0;
|
2013-02-25 23:23:16 +00:00
|
|
|
|
cylinder_t *cyl;
|
2024-05-03 16:51:03 +00:00
|
|
|
|
struct plot_data &entry1 = pi.entry[idx1];
|
|
|
|
|
struct plot_data &entry2 = pi.entry[idx2];
|
|
|
|
|
int duration = entry2.sec - entry1.sec;
|
2013-02-25 23:23:16 +00:00
|
|
|
|
int depth, airuse;
|
|
|
|
|
pressure_t a, b;
|
|
|
|
|
double atm;
|
2013-02-21 02:57:50 +00:00
|
|
|
|
|
2013-02-25 23:23:16 +00:00
|
|
|
|
if (duration <= 0)
|
2013-02-21 02:57:50 +00:00
|
|
|
|
return 0;
|
2019-07-06 09:58:27 +00:00
|
|
|
|
a.mbar = get_plot_pressure(pi, idx1, 0);
|
|
|
|
|
b.mbar = get_plot_pressure(pi, idx2, 0);
|
2014-04-26 17:55:17 +00:00
|
|
|
|
if (!b.mbar || a.mbar <= b.mbar)
|
2013-02-21 02:57:50 +00:00
|
|
|
|
return 0;
|
|
|
|
|
|
2013-02-25 23:23:16 +00:00
|
|
|
|
/* Mean pressure in ATM */
|
2024-05-03 16:51:03 +00:00
|
|
|
|
depth = (entry1.depth + entry2.depth) / 2;
|
2024-06-20 20:09:47 +00:00
|
|
|
|
atm = dive->depth_to_atm(depth);
|
2013-02-21 02:57:50 +00:00
|
|
|
|
|
2024-06-25 05:43:32 +00:00
|
|
|
|
cyl = dive->get_cylinder(index);
|
2013-02-25 23:23:16 +00:00
|
|
|
|
|
2024-07-02 09:12:27 +00:00
|
|
|
|
// TODO: Implement addition/subtraction on units.h types
|
|
|
|
|
airuse = cyl->gas_volume(a).mliter - cyl->gas_volume(b).mliter;
|
2013-02-25 23:23:16 +00:00
|
|
|
|
|
|
|
|
|
/* milliliters per minute */
|
2017-03-09 16:07:30 +00:00
|
|
|
|
return lrint(airuse / atm * 60 / duration);
|
2013-02-21 02:57:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-09-17 04:45:32 +00:00
|
|
|
|
static velocity_t velocity(int speed)
|
|
|
|
|
{
|
|
|
|
|
velocity_t v;
|
|
|
|
|
|
|
|
|
|
if (speed < -304) /* ascent faster than -60ft/min */
|
|
|
|
|
v = CRAZY;
|
|
|
|
|
else if (speed < -152) /* above -30ft/min */
|
|
|
|
|
v = FAST;
|
|
|
|
|
else if (speed < -76) /* -15ft/min */
|
|
|
|
|
v = MODERATE;
|
|
|
|
|
else if (speed < -25) /* -5ft/min */
|
|
|
|
|
v = SLOW;
|
|
|
|
|
else if (speed < 25) /* very hard to find data, but it appears that the recommendations
|
2012-08-26 21:41:05 +00:00
|
|
|
|
for descent are usually about 2x ascent rate; still, we want
|
2011-09-17 04:45:32 +00:00
|
|
|
|
stable to mean stable */
|
|
|
|
|
v = STABLE;
|
|
|
|
|
else if (speed < 152) /* between 5 and 30ft/min is considered slow */
|
|
|
|
|
v = SLOW;
|
|
|
|
|
else if (speed < 304) /* up to 60ft/min is moderate */
|
|
|
|
|
v = MODERATE;
|
|
|
|
|
else if (speed < 507) /* up to 100ft/min is fast */
|
|
|
|
|
v = FAST;
|
|
|
|
|
else /* more than that is just crazy - you'll blow your ears out */
|
|
|
|
|
v = CRAZY;
|
|
|
|
|
|
|
|
|
|
return v;
|
|
|
|
|
}
|
2013-05-03 18:04:51 +00:00
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
static void analyze_plot_info(struct plot_info &pi)
|
2011-09-08 15:33:02 +00:00
|
|
|
|
{
|
|
|
|
|
/* Smoothing function: 5-point triangular smooth */
|
2024-05-03 16:51:03 +00:00
|
|
|
|
for (size_t i = 2; i < pi.entry.size(); i++) {
|
|
|
|
|
struct plot_data &entry = pi.entry[i];
|
2011-10-23 05:40:53 +00:00
|
|
|
|
int depth;
|
2011-09-08 15:33:02 +00:00
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (i + 2 < pi.entry.size()) {
|
|
|
|
|
depth = pi.entry[i-2].depth + 2 * pi.entry[i-1].depth + 3 * pi.entry[i].depth + 2 * pi.entry[i+1].depth + pi.entry[i+2].depth;
|
|
|
|
|
entry.smoothed = (depth + 4) / 9;
|
2011-09-16 23:22:00 +00:00
|
|
|
|
}
|
|
|
|
|
/* vertical velocity in mm/sec */
|
2011-09-17 04:45:32 +00:00
|
|
|
|
/* Linus wants to smooth this - let's at least look at the samples that aren't FAST or CRAZY */
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (pi.entry[i].sec - pi.entry[i-1].sec) {
|
|
|
|
|
entry.speed = (pi.entry[i+0].depth - pi.entry[i-1].depth) / (pi.entry[i].sec - pi.entry[i-1].sec);
|
|
|
|
|
entry.velocity = velocity(entry.speed);
|
2013-05-31 06:21:39 +00:00
|
|
|
|
/* if our samples are short and we aren't too FAST*/
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (pi.entry[i].sec - pi.entry[i-1].sec < 15 && entry.velocity < FAST) {
|
2011-09-17 04:45:32 +00:00
|
|
|
|
int past = -2;
|
2024-05-03 16:51:03 +00:00
|
|
|
|
while (i + past > 0 && pi.entry[i].sec - pi.entry[i+past].sec < 15)
|
2011-09-17 04:45:32 +00:00
|
|
|
|
past--;
|
2024-05-03 16:51:03 +00:00
|
|
|
|
entry.velocity = velocity((pi.entry[i].depth - pi.entry[i+past].depth) /
|
|
|
|
|
(pi.entry[i].sec - pi.entry[i+past].sec));
|
2011-09-17 04:45:32 +00:00
|
|
|
|
}
|
2013-01-29 21:10:46 +00:00
|
|
|
|
} else {
|
2024-05-03 16:51:03 +00:00
|
|
|
|
entry.velocity = STABLE;
|
|
|
|
|
entry.speed = 0;
|
2013-01-29 21:10:46 +00:00
|
|
|
|
}
|
2011-09-08 15:33:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
static size_t set_setpoint(struct plot_info &pi, size_t i, int setpoint, int end)
|
2014-11-26 13:22:41 +00:00
|
|
|
|
{
|
2024-05-03 16:51:03 +00:00
|
|
|
|
while (i < pi.entry.size()) {
|
|
|
|
|
struct plot_data &entry = pi.entry[i];
|
|
|
|
|
if (entry.sec > end)
|
2014-11-26 13:22:41 +00:00
|
|
|
|
break;
|
2024-05-03 16:51:03 +00:00
|
|
|
|
entry.o2pressure.mbar = setpoint;
|
2014-11-26 13:22:41 +00:00
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
static void check_setpoint_events(const struct dive *, const struct divecomputer *dc, struct plot_info &pi)
|
2014-11-26 13:22:41 +00:00
|
|
|
|
{
|
2024-05-03 16:51:03 +00:00
|
|
|
|
size_t i = 0;
|
2014-11-26 13:22:41 +00:00
|
|
|
|
pressure_t setpoint;
|
|
|
|
|
setpoint.mbar = 0;
|
|
|
|
|
|
2024-05-25 06:16:57 +00:00
|
|
|
|
event_loop loop("SP change");
|
|
|
|
|
bool found = false;
|
|
|
|
|
while (auto ev = loop.next(*dc)) {
|
2014-11-26 13:22:41 +00:00
|
|
|
|
i = set_setpoint(pi, i, setpoint.mbar, ev->time.seconds);
|
|
|
|
|
setpoint.mbar = ev->value;
|
2024-05-25 06:16:57 +00:00
|
|
|
|
found = true;
|
|
|
|
|
}
|
|
|
|
|
if (found) // Fill the last setpoint until the end of the dive
|
|
|
|
|
set_setpoint(pi, i, setpoint.mbar, INT_MAX);
|
2014-11-26 13:22:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
static void calculate_max_limits_new(const struct dive *dive, const struct divecomputer *given_dc, struct plot_info &pi, bool in_planner)
|
2014-01-15 15:34:55 +00:00
|
|
|
|
{
|
2015-01-23 19:05:32 +00:00
|
|
|
|
bool seen = false;
|
2020-05-01 08:55:42 +00:00
|
|
|
|
bool found_sample_beyond_last_event = false;
|
2014-01-15 15:34:55 +00:00
|
|
|
|
int maxdepth = dive->maxdepth.mm;
|
2017-11-29 05:44:11 +00:00
|
|
|
|
int maxtime = 0;
|
2014-01-15 15:34:55 +00:00
|
|
|
|
int maxpressure = 0, minpressure = INT_MAX;
|
2014-02-23 22:32:25 +00:00
|
|
|
|
int maxhr = 0, minhr = INT_MAX;
|
2014-01-15 15:34:55 +00:00
|
|
|
|
int mintemp = dive->mintemp.mkelvin;
|
|
|
|
|
int maxtemp = dive->maxtemp.mkelvin;
|
|
|
|
|
|
|
|
|
|
/* Get the per-cylinder maximum pressure if they are manual */
|
2024-05-28 19:31:11 +00:00
|
|
|
|
for (auto &cyl: dive->cylinders) {
|
|
|
|
|
int mbar_start = cyl.start.mbar;
|
|
|
|
|
int mbar_end = cyl.end.mbar;
|
2019-11-11 13:28:49 +00:00
|
|
|
|
if (mbar_start > maxpressure)
|
|
|
|
|
maxpressure = mbar_start;
|
2023-05-22 20:34:01 +00:00
|
|
|
|
if (mbar_end && mbar_end < minpressure)
|
2019-11-11 13:28:49 +00:00
|
|
|
|
minpressure = mbar_end;
|
2014-01-15 15:34:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-27 15:09:48 +00:00
|
|
|
|
auto process_dc = [&] (const divecomputer &dc) {
|
2014-01-15 15:34:55 +00:00
|
|
|
|
int lastdepth = 0;
|
|
|
|
|
|
2020-05-01 08:55:42 +00:00
|
|
|
|
/* Make sure we can fit all events */
|
2024-05-27 15:09:48 +00:00
|
|
|
|
if (!dc.events.empty())
|
|
|
|
|
maxtime = std::max(maxtime, dc.events.back().time.seconds);
|
2020-05-01 08:55:42 +00:00
|
|
|
|
|
2024-05-27 15:09:48 +00:00
|
|
|
|
for (auto &s: dc.samples) {
|
2024-05-19 10:38:38 +00:00
|
|
|
|
int depth = s.depth.mm;
|
|
|
|
|
int temperature = s.temperature.mkelvin;
|
|
|
|
|
int heartbeat = s.heartbeat;
|
2014-01-15 15:34:55 +00:00
|
|
|
|
|
2023-05-22 20:05:43 +00:00
|
|
|
|
for (int sensor = 0; sensor < MAX_SENSORS; ++sensor) {
|
2024-05-19 10:38:38 +00:00
|
|
|
|
int pressure = s.pressure[sensor].mbar;
|
2023-05-22 20:05:43 +00:00
|
|
|
|
if (pressure && pressure < minpressure)
|
|
|
|
|
minpressure = pressure;
|
|
|
|
|
if (pressure > maxpressure)
|
|
|
|
|
maxpressure = pressure;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-15 15:34:55 +00:00
|
|
|
|
if (!mintemp && temperature < mintemp)
|
|
|
|
|
mintemp = temperature;
|
|
|
|
|
if (temperature > maxtemp)
|
|
|
|
|
maxtemp = temperature;
|
|
|
|
|
|
2014-02-23 22:32:25 +00:00
|
|
|
|
if (heartbeat > maxhr)
|
|
|
|
|
maxhr = heartbeat;
|
2018-03-15 22:12:45 +00:00
|
|
|
|
if (heartbeat && heartbeat < minhr)
|
2014-02-23 22:32:25 +00:00
|
|
|
|
minhr = heartbeat;
|
2014-01-15 15:34:55 +00:00
|
|
|
|
|
|
|
|
|
if (depth > maxdepth)
|
2024-05-19 10:38:38 +00:00
|
|
|
|
maxdepth = s.depth.mm;
|
2020-05-01 08:55:42 +00:00
|
|
|
|
/* Make sure that we get the first sample beyond the last event.
|
|
|
|
|
* If maxtime is somewhere in the middle of the last segment,
|
|
|
|
|
* populate_plot_entries() gets confused leading to display artifacts. */
|
2021-01-08 22:55:20 +00:00
|
|
|
|
if ((depth > SURFACE_THRESHOLD || lastdepth > SURFACE_THRESHOLD || in_planner || !found_sample_beyond_last_event) &&
|
2024-05-19 10:38:38 +00:00
|
|
|
|
s.time.seconds > maxtime) {
|
2020-05-01 08:55:42 +00:00
|
|
|
|
found_sample_beyond_last_event = true;
|
2024-05-19 10:38:38 +00:00
|
|
|
|
maxtime = s.time.seconds;
|
2020-05-01 08:55:42 +00:00
|
|
|
|
}
|
2014-01-15 15:34:55 +00:00
|
|
|
|
lastdepth = depth;
|
|
|
|
|
}
|
2024-05-27 15:09:48 +00:00
|
|
|
|
};
|
2016-06-01 19:49:32 +00:00
|
|
|
|
|
2024-05-27 15:09:48 +00:00
|
|
|
|
/* Then do all the samples from all the dive computers */
|
|
|
|
|
for (auto &dc: dive->dcs) {
|
|
|
|
|
if (&dc == given_dc)
|
2015-01-23 19:05:32 +00:00
|
|
|
|
seen = true;
|
2024-05-27 15:09:48 +00:00
|
|
|
|
process_dc(dc);
|
|
|
|
|
}
|
|
|
|
|
if (!seen)
|
|
|
|
|
process_dc(*given_dc);
|
2014-01-15 15:34:55 +00:00
|
|
|
|
|
|
|
|
|
if (minpressure > maxpressure)
|
|
|
|
|
minpressure = 0;
|
2014-02-23 22:32:25 +00:00
|
|
|
|
if (minhr > maxhr)
|
2018-03-15 22:12:45 +00:00
|
|
|
|
minhr = maxhr;
|
2014-01-15 15:34:55 +00:00
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
pi.maxdepth = maxdepth;
|
|
|
|
|
pi.maxtime = maxtime;
|
|
|
|
|
pi.maxpressure = maxpressure;
|
|
|
|
|
pi.minpressure = minpressure;
|
|
|
|
|
pi.minhr = minhr;
|
|
|
|
|
pi.maxhr = maxhr;
|
|
|
|
|
pi.mintemp = mintemp;
|
|
|
|
|
pi.maxtemp = maxtemp;
|
2014-01-15 15:34:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
static plot_data &add_entry(struct plot_info &pi)
|
2019-07-06 11:22:26 +00:00
|
|
|
|
{
|
2024-05-03 16:51:03 +00:00
|
|
|
|
pi.entry.emplace_back();
|
|
|
|
|
pi.pressures.resize(pi.pressures.size() + pi.nr_cylinders);
|
|
|
|
|
return pi.entry.back();
|
2019-07-06 11:22:26 +00:00
|
|
|
|
}
|
2014-02-23 16:36:20 +00:00
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
/* copy the previous entry (we know this exists), update time and depth
|
|
|
|
|
* and zero out the sensor pressure (since this is a synthetic entry)
|
|
|
|
|
* increment the entry pointer and the count of synthetic entries. */
|
|
|
|
|
static void insert_entry(struct plot_info &pi, int time, int depth, int sac)
|
2019-07-06 12:41:09 +00:00
|
|
|
|
{
|
2024-05-03 16:51:03 +00:00
|
|
|
|
struct plot_data &entry = add_entry(pi);
|
|
|
|
|
struct plot_data &prev = pi.entry[pi.entry.size() - 2];
|
|
|
|
|
entry = prev;
|
|
|
|
|
entry.sec = time;
|
|
|
|
|
entry.depth = depth;
|
|
|
|
|
entry.running_sum = prev.running_sum + (time - prev.sec) * (depth + prev.depth) / 2;
|
|
|
|
|
entry.sac = sac;
|
|
|
|
|
entry.ndl = -1;
|
|
|
|
|
entry.bearing = -1;
|
2019-07-06 12:41:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
static void populate_plot_entries(const struct dive *dive, const struct divecomputer *dc, struct plot_info &pi)
|
Do a better job at creating plot info entries
This simplifies - and improves - the code to generate the plot info
entries from the samples.
We used to generate exactly one plot info entry per sample, and then -
because the result doesn't have high enough granularity - we'd
generate additional plot info entries at gas change events etc.
Which resulted in all kinds of ugly special case logic. Not only for
the gas switch, btw: you can see the effects of this in the deco graph
(done at plot entry boundaries) and in the gas pressure curves.
So this throws that "do special plot entries for gas switch events"
code away entirely, and replaces it with a much more straightforward
model: we generate plot entries at a minimum of ten-second intervals.
If you have samples more often than that, you'll get more frequent
plot entries, but you'll never get less than that "every ten seconds".
As a result, the code is smaller and simpler (99 insertions, 161
deletions), and actually does a better job too.
You can see the difference especially in the test dives that only have
a few entries (or if you create a new dive without a dive computer,
using the "Add Dive" menu entry). Look at the deco graph of test-dive
20 before and after, for example. You can also see it very subtly in
the cylinder pressure curves going from line segments to curves on
that same dive.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-06 20:53:25 +00:00
|
|
|
|
{
|
2024-05-28 19:31:11 +00:00
|
|
|
|
pi.nr_cylinders = static_cast<int>(dive->cylinders.size());
|
Do a better job at creating plot info entries
This simplifies - and improves - the code to generate the plot info
entries from the samples.
We used to generate exactly one plot info entry per sample, and then -
because the result doesn't have high enough granularity - we'd
generate additional plot info entries at gas change events etc.
Which resulted in all kinds of ugly special case logic. Not only for
the gas switch, btw: you can see the effects of this in the deco graph
(done at plot entry boundaries) and in the gas pressure curves.
So this throws that "do special plot entries for gas switch events"
code away entirely, and replaces it with a much more straightforward
model: we generate plot entries at a minimum of ten-second intervals.
If you have samples more often than that, you'll get more frequent
plot entries, but you'll never get less than that "every ten seconds".
As a result, the code is smaller and simpler (99 insertions, 161
deletions), and actually does a better job too.
You can see the difference especially in the test dives that only have
a few entries (or if you create a new dive without a dive computer,
using the "Add Dive" menu entry). Look at the deco graph of test-dive
20 before and after, for example. You can also see it very subtly in
the cylinder pressure curves going from line segments to curves on
that same dive.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-06 20:53:25 +00:00
|
|
|
|
|
|
|
|
|
/*
|
2024-05-03 16:51:03 +00:00
|
|
|
|
* To avoid continuous reallocation, allocate the expected number of entries.
|
2013-01-07 02:20:12 +00:00
|
|
|
|
* We want to have a plot_info event at least every 10s (so "maxtime/10+1"),
|
2014-02-23 16:36:20 +00:00
|
|
|
|
* but samples could be more dense than that (so add in dc->samples). We also
|
|
|
|
|
* need to have one for every event (so count events and add that) and
|
Do a better job at creating plot info entries
This simplifies - and improves - the code to generate the plot info
entries from the samples.
We used to generate exactly one plot info entry per sample, and then -
because the result doesn't have high enough granularity - we'd
generate additional plot info entries at gas change events etc.
Which resulted in all kinds of ugly special case logic. Not only for
the gas switch, btw: you can see the effects of this in the deco graph
(done at plot entry boundaries) and in the gas pressure curves.
So this throws that "do special plot entries for gas switch events"
code away entirely, and replaces it with a much more straightforward
model: we generate plot entries at a minimum of ten-second intervals.
If you have samples more often than that, you'll get more frequent
plot entries, but you'll never get less than that "every ten seconds".
As a result, the code is smaller and simpler (99 insertions, 161
deletions), and actually does a better job too.
You can see the difference especially in the test dives that only have
a few entries (or if you create a new dive without a dive computer,
using the "Add Dive" menu entry). Look at the deco graph of test-dive
20 before and after, for example. You can also see it very subtly in
the cylinder pressure curves going from line segments to curves on
that same dive.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-06 20:53:25 +00:00
|
|
|
|
* additionally we want two surface events around the whole thing (thus the
|
2015-09-20 22:10:31 +00:00
|
|
|
|
* additional 4). There is also one extra space for a final entry
|
|
|
|
|
* that has time > maxtime (because there can be surface samples
|
|
|
|
|
* past "maxtime" in the original sample data)
|
Do a better job at creating plot info entries
This simplifies - and improves - the code to generate the plot info
entries from the samples.
We used to generate exactly one plot info entry per sample, and then -
because the result doesn't have high enough granularity - we'd
generate additional plot info entries at gas change events etc.
Which resulted in all kinds of ugly special case logic. Not only for
the gas switch, btw: you can see the effects of this in the deco graph
(done at plot entry boundaries) and in the gas pressure curves.
So this throws that "do special plot entries for gas switch events"
code away entirely, and replaces it with a much more straightforward
model: we generate plot entries at a minimum of ten-second intervals.
If you have samples more often than that, you'll get more frequent
plot entries, but you'll never get less than that "every ten seconds".
As a result, the code is smaller and simpler (99 insertions, 161
deletions), and actually does a better job too.
You can see the difference especially in the test dives that only have
a few entries (or if you create a new dive without a dive computer,
using the "Add Dive" menu entry). Look at the deco graph of test-dive
20 before and after, for example. You can also see it very subtly in
the cylinder pressure curves going from line segments to curves on
that same dive.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-06 20:53:25 +00:00
|
|
|
|
*/
|
2024-05-25 06:16:57 +00:00
|
|
|
|
size_t nr = dc->samples.size() + 6 + pi.maxtime / 10 + dc->events.size();
|
2024-05-03 16:51:03 +00:00
|
|
|
|
pi.entry.reserve(nr);
|
|
|
|
|
pi.pressures.reserve(nr * pi.nr_cylinders);
|
Do a better job at creating plot info entries
This simplifies - and improves - the code to generate the plot info
entries from the samples.
We used to generate exactly one plot info entry per sample, and then -
because the result doesn't have high enough granularity - we'd
generate additional plot info entries at gas change events etc.
Which resulted in all kinds of ugly special case logic. Not only for
the gas switch, btw: you can see the effects of this in the deco graph
(done at plot entry boundaries) and in the gas pressure curves.
So this throws that "do special plot entries for gas switch events"
code away entirely, and replaces it with a much more straightforward
model: we generate plot entries at a minimum of ten-second intervals.
If you have samples more often than that, you'll get more frequent
plot entries, but you'll never get less than that "every ten seconds".
As a result, the code is smaller and simpler (99 insertions, 161
deletions), and actually does a better job too.
You can see the difference especially in the test dives that only have
a few entries (or if you create a new dive without a dive computer,
using the "Add Dive" menu entry). Look at the deco graph of test-dive
20 before and after, for example. You can also see it very subtly in
the cylinder pressure curves going from line segments to curves on
that same dive.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-06 20:53:25 +00:00
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
// The two extra events at the start
|
|
|
|
|
pi.entry.resize(2);
|
|
|
|
|
pi.pressures.resize(pi.nr_cylinders * 2);
|
|
|
|
|
|
|
|
|
|
int lastdepth = 0;
|
|
|
|
|
int lasttime = 0;
|
|
|
|
|
int lasttemp = 0;
|
2014-02-23 16:36:20 +00:00
|
|
|
|
/* skip events at time = 0 */
|
2024-05-25 06:16:57 +00:00
|
|
|
|
auto evit = dc->events.begin();
|
|
|
|
|
while (evit != dc->events.end() && evit->time.seconds == 0)
|
|
|
|
|
++evit;
|
2024-05-19 10:38:38 +00:00
|
|
|
|
for (const auto &sample: dc->samples) {
|
2024-05-03 16:51:03 +00:00
|
|
|
|
int time = sample.time.seconds;
|
2016-03-10 15:37:18 +00:00
|
|
|
|
int offset, delta;
|
2024-05-03 16:51:03 +00:00
|
|
|
|
int depth = sample.depth.mm;
|
|
|
|
|
int sac = sample.sac.mliter;
|
Do a better job at creating plot info entries
This simplifies - and improves - the code to generate the plot info
entries from the samples.
We used to generate exactly one plot info entry per sample, and then -
because the result doesn't have high enough granularity - we'd
generate additional plot info entries at gas change events etc.
Which resulted in all kinds of ugly special case logic. Not only for
the gas switch, btw: you can see the effects of this in the deco graph
(done at plot entry boundaries) and in the gas pressure curves.
So this throws that "do special plot entries for gas switch events"
code away entirely, and replaces it with a much more straightforward
model: we generate plot entries at a minimum of ten-second intervals.
If you have samples more often than that, you'll get more frequent
plot entries, but you'll never get less than that "every ten seconds".
As a result, the code is smaller and simpler (99 insertions, 161
deletions), and actually does a better job too.
You can see the difference especially in the test dives that only have
a few entries (or if you create a new dive without a dive computer,
using the "Add Dive" menu entry). Look at the deco graph of test-dive
20 before and after, for example. You can also see it very subtly in
the cylinder pressure curves going from line segments to curves on
that same dive.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-06 20:53:25 +00:00
|
|
|
|
|
|
|
|
|
/* Add intermediate plot entries if required */
|
|
|
|
|
delta = time - lasttime;
|
2015-06-22 14:02:17 +00:00
|
|
|
|
if (delta <= 0) {
|
2013-01-07 23:14:13 +00:00
|
|
|
|
time = lasttime;
|
2015-06-22 14:02:17 +00:00
|
|
|
|
delta = 1; // avoid divide by 0
|
2013-01-07 23:14:13 +00:00
|
|
|
|
}
|
2016-03-10 15:37:18 +00:00
|
|
|
|
for (offset = 10; offset < delta; offset += 10) {
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (lasttime + offset > pi.maxtime)
|
Do a better job at creating plot info entries
This simplifies - and improves - the code to generate the plot info
entries from the samples.
We used to generate exactly one plot info entry per sample, and then -
because the result doesn't have high enough granularity - we'd
generate additional plot info entries at gas change events etc.
Which resulted in all kinds of ugly special case logic. Not only for
the gas switch, btw: you can see the effects of this in the deco graph
(done at plot entry boundaries) and in the gas pressure curves.
So this throws that "do special plot entries for gas switch events"
code away entirely, and replaces it with a much more straightforward
model: we generate plot entries at a minimum of ten-second intervals.
If you have samples more often than that, you'll get more frequent
plot entries, but you'll never get less than that "every ten seconds".
As a result, the code is smaller and simpler (99 insertions, 161
deletions), and actually does a better job too.
You can see the difference especially in the test dives that only have
a few entries (or if you create a new dive without a dive computer,
using the "Add Dive" menu entry). Look at the deco graph of test-dive
20 before and after, for example. You can also see it very subtly in
the cylinder pressure curves going from line segments to curves on
that same dive.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-06 20:53:25 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2014-02-23 16:36:20 +00:00
|
|
|
|
/* Add events if they are between plot entries */
|
2024-05-25 06:16:57 +00:00
|
|
|
|
while (evit != dc->events.end() && static_cast<int>(evit->time.seconds) < lasttime + offset) {
|
|
|
|
|
insert_entry(pi, evit->time.seconds, interpolate(lastdepth, depth, evit->time.seconds - lasttime, delta), sac);
|
|
|
|
|
++evit;
|
2014-02-23 16:36:20 +00:00
|
|
|
|
}
|
Do a better job at creating plot info entries
This simplifies - and improves - the code to generate the plot info
entries from the samples.
We used to generate exactly one plot info entry per sample, and then -
because the result doesn't have high enough granularity - we'd
generate additional plot info entries at gas change events etc.
Which resulted in all kinds of ugly special case logic. Not only for
the gas switch, btw: you can see the effects of this in the deco graph
(done at plot entry boundaries) and in the gas pressure curves.
So this throws that "do special plot entries for gas switch events"
code away entirely, and replaces it with a much more straightforward
model: we generate plot entries at a minimum of ten-second intervals.
If you have samples more often than that, you'll get more frequent
plot entries, but you'll never get less than that "every ten seconds".
As a result, the code is smaller and simpler (99 insertions, 161
deletions), and actually does a better job too.
You can see the difference especially in the test dives that only have
a few entries (or if you create a new dive without a dive computer,
using the "Add Dive" menu entry). Look at the deco graph of test-dive
20 before and after, for example. You can also see it very subtly in
the cylinder pressure curves going from line segments to curves on
that same dive.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-06 20:53:25 +00:00
|
|
|
|
|
2014-02-23 16:36:20 +00:00
|
|
|
|
/* now insert the time interpolated entry */
|
2024-05-03 16:51:03 +00:00
|
|
|
|
insert_entry(pi, lasttime + offset, interpolate(lastdepth, depth, offset, delta), sac);
|
Do a better job at creating plot info entries
This simplifies - and improves - the code to generate the plot info
entries from the samples.
We used to generate exactly one plot info entry per sample, and then -
because the result doesn't have high enough granularity - we'd
generate additional plot info entries at gas change events etc.
Which resulted in all kinds of ugly special case logic. Not only for
the gas switch, btw: you can see the effects of this in the deco graph
(done at plot entry boundaries) and in the gas pressure curves.
So this throws that "do special plot entries for gas switch events"
code away entirely, and replaces it with a much more straightforward
model: we generate plot entries at a minimum of ten-second intervals.
If you have samples more often than that, you'll get more frequent
plot entries, but you'll never get less than that "every ten seconds".
As a result, the code is smaller and simpler (99 insertions, 161
deletions), and actually does a better job too.
You can see the difference especially in the test dives that only have
a few entries (or if you create a new dive without a dive computer,
using the "Add Dive" menu entry). Look at the deco graph of test-dive
20 before and after, for example. You can also see it very subtly in
the cylinder pressure curves going from line segments to curves on
that same dive.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-06 20:53:25 +00:00
|
|
|
|
|
2014-02-23 16:36:20 +00:00
|
|
|
|
/* skip events that happened at this time */
|
2024-05-25 06:16:57 +00:00
|
|
|
|
while (evit != dc->events.end() && static_cast<int>(evit->time.seconds) == lasttime + offset)
|
|
|
|
|
++evit;
|
2014-02-23 16:36:20 +00:00
|
|
|
|
}
|
Do a better job at creating plot info entries
This simplifies - and improves - the code to generate the plot info
entries from the samples.
We used to generate exactly one plot info entry per sample, and then -
because the result doesn't have high enough granularity - we'd
generate additional plot info entries at gas change events etc.
Which resulted in all kinds of ugly special case logic. Not only for
the gas switch, btw: you can see the effects of this in the deco graph
(done at plot entry boundaries) and in the gas pressure curves.
So this throws that "do special plot entries for gas switch events"
code away entirely, and replaces it with a much more straightforward
model: we generate plot entries at a minimum of ten-second intervals.
If you have samples more often than that, you'll get more frequent
plot entries, but you'll never get less than that "every ten seconds".
As a result, the code is smaller and simpler (99 insertions, 161
deletions), and actually does a better job too.
You can see the difference especially in the test dives that only have
a few entries (or if you create a new dive without a dive computer,
using the "Add Dive" menu entry). Look at the deco graph of test-dive
20 before and after, for example. You can also see it very subtly in
the cylinder pressure curves going from line segments to curves on
that same dive.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-06 20:53:25 +00:00
|
|
|
|
|
2014-02-23 16:36:20 +00:00
|
|
|
|
/* Add events if they are between plot entries */
|
2024-05-25 06:16:57 +00:00
|
|
|
|
while (evit != dc->events.end() && static_cast<int>(evit->time.seconds) < time) {
|
|
|
|
|
insert_entry(pi, evit->time.seconds, interpolate(lastdepth, depth, evit->time.seconds - lasttime, delta), sac);
|
|
|
|
|
++evit;
|
Do a better job at creating plot info entries
This simplifies - and improves - the code to generate the plot info
entries from the samples.
We used to generate exactly one plot info entry per sample, and then -
because the result doesn't have high enough granularity - we'd
generate additional plot info entries at gas change events etc.
Which resulted in all kinds of ugly special case logic. Not only for
the gas switch, btw: you can see the effects of this in the deco graph
(done at plot entry boundaries) and in the gas pressure curves.
So this throws that "do special plot entries for gas switch events"
code away entirely, and replaces it with a much more straightforward
model: we generate plot entries at a minimum of ten-second intervals.
If you have samples more often than that, you'll get more frequent
plot entries, but you'll never get less than that "every ten seconds".
As a result, the code is smaller and simpler (99 insertions, 161
deletions), and actually does a better job too.
You can see the difference especially in the test dives that only have
a few entries (or if you create a new dive without a dive computer,
using the "Add Dive" menu entry). Look at the deco graph of test-dive
20 before and after, for example. You can also see it very subtly in
the cylinder pressure curves going from line segments to curves on
that same dive.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-06 20:53:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
plot_data &entry = add_entry(pi);
|
|
|
|
|
plot_data &prev = pi.entry[pi.entry.size() - 2];
|
|
|
|
|
entry.sec = time;
|
|
|
|
|
entry.depth = depth;
|
|
|
|
|
|
|
|
|
|
entry.running_sum = prev.running_sum + (time - prev.sec) * (depth + prev.depth) / 2;
|
|
|
|
|
entry.stopdepth = sample.stopdepth.mm;
|
|
|
|
|
entry.stoptime = sample.stoptime.seconds;
|
|
|
|
|
entry.ndl = sample.ndl.seconds;
|
|
|
|
|
entry.tts = sample.tts.seconds;
|
|
|
|
|
entry.in_deco = sample.in_deco;
|
|
|
|
|
entry.cns = sample.cns;
|
2018-03-05 20:23:23 +00:00
|
|
|
|
if (dc->divemode == CCR || (dc->divemode == PSCR && dc->no_o2sensors)) {
|
2024-05-03 16:51:03 +00:00
|
|
|
|
entry.o2pressure.mbar = entry.o2setpoint.mbar = sample.setpoint.mbar; // for rebreathers
|
2024-01-20 23:35:44 +00:00
|
|
|
|
int i;
|
|
|
|
|
for (i = 0; i < MAX_O2_SENSORS; i++)
|
2024-05-03 16:51:03 +00:00
|
|
|
|
entry.o2sensor[i].mbar = sample.o2sensor[i].mbar;
|
2014-10-13 19:19:21 +00:00
|
|
|
|
} else {
|
2024-05-03 16:51:03 +00:00
|
|
|
|
entry.pressures.o2 = sample.setpoint.mbar / 1000.0;
|
2014-10-13 19:19:21 +00:00
|
|
|
|
}
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (sample.pressure[0].mbar && sample.sensor[0] != NO_SENSOR)
|
|
|
|
|
set_plot_pressure_data(pi, pi.entry.size() - 1, SENSOR_PR, sample.sensor[0], sample.pressure[0].mbar);
|
|
|
|
|
if (sample.pressure[1].mbar && sample.sensor[1] != NO_SENSOR)
|
|
|
|
|
set_plot_pressure_data(pi, pi.entry.size() - 1, SENSOR_PR, sample.sensor[1], sample.pressure[1].mbar);
|
|
|
|
|
if (sample.temperature.mkelvin)
|
|
|
|
|
entry.temperature = lasttemp = sample.temperature.mkelvin;
|
2013-11-12 22:00:55 +00:00
|
|
|
|
else
|
2024-05-03 16:51:03 +00:00
|
|
|
|
entry.temperature = lasttemp;
|
|
|
|
|
entry.heartbeat = sample.heartbeat;
|
|
|
|
|
entry.bearing = sample.bearing.degrees;
|
|
|
|
|
entry.sac = sample.sac.mliter;
|
|
|
|
|
if (sample.rbt.seconds)
|
|
|
|
|
entry.rbt = sample.rbt.seconds;
|
2014-02-23 16:36:20 +00:00
|
|
|
|
/* skip events that happened at this time */
|
2024-05-25 06:16:57 +00:00
|
|
|
|
while (evit != dc->events.end() && static_cast<int>(evit->time.seconds) == time)
|
|
|
|
|
++evit;
|
Do a better job at creating plot info entries
This simplifies - and improves - the code to generate the plot info
entries from the samples.
We used to generate exactly one plot info entry per sample, and then -
because the result doesn't have high enough granularity - we'd
generate additional plot info entries at gas change events etc.
Which resulted in all kinds of ugly special case logic. Not only for
the gas switch, btw: you can see the effects of this in the deco graph
(done at plot entry boundaries) and in the gas pressure curves.
So this throws that "do special plot entries for gas switch events"
code away entirely, and replaces it with a much more straightforward
model: we generate plot entries at a minimum of ten-second intervals.
If you have samples more often than that, you'll get more frequent
plot entries, but you'll never get less than that "every ten seconds".
As a result, the code is smaller and simpler (99 insertions, 161
deletions), and actually does a better job too.
You can see the difference especially in the test dives that only have
a few entries (or if you create a new dive without a dive computer,
using the "Add Dive" menu entry). Look at the deco graph of test-dive
20 before and after, for example. You can also see it very subtly in
the cylinder pressure curves going from line segments to curves on
that same dive.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-06 20:53:25 +00:00
|
|
|
|
lasttime = time;
|
|
|
|
|
lastdepth = depth;
|
2015-09-20 22:10:31 +00:00
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (time > pi.maxtime)
|
2015-09-20 22:10:31 +00:00
|
|
|
|
break;
|
Do a better job at creating plot info entries
This simplifies - and improves - the code to generate the plot info
entries from the samples.
We used to generate exactly one plot info entry per sample, and then -
because the result doesn't have high enough granularity - we'd
generate additional plot info entries at gas change events etc.
Which resulted in all kinds of ugly special case logic. Not only for
the gas switch, btw: you can see the effects of this in the deco graph
(done at plot entry boundaries) and in the gas pressure curves.
So this throws that "do special plot entries for gas switch events"
code away entirely, and replaces it with a much more straightforward
model: we generate plot entries at a minimum of ten-second intervals.
If you have samples more often than that, you'll get more frequent
plot entries, but you'll never get less than that "every ten seconds".
As a result, the code is smaller and simpler (99 insertions, 161
deletions), and actually does a better job too.
You can see the difference especially in the test dives that only have
a few entries (or if you create a new dive without a dive computer,
using the "Add Dive" menu entry). Look at the deco graph of test-dive
20 before and after, for example. You can also see it very subtly in
the cylinder pressure curves going from line segments to curves on
that same dive.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-06 20:53:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-01 19:49:32 +00:00
|
|
|
|
/* Add any remaining events */
|
2024-05-25 06:16:57 +00:00
|
|
|
|
while (evit != dc->events.end()) {
|
|
|
|
|
int time = evit->time.seconds;
|
2016-06-01 19:49:32 +00:00
|
|
|
|
|
|
|
|
|
if (time > lasttime) {
|
2024-05-25 06:16:57 +00:00
|
|
|
|
insert_entry(pi, evit->time.seconds, 0, 0);
|
2016-06-01 19:49:32 +00:00
|
|
|
|
lasttime = time;
|
|
|
|
|
}
|
2024-05-25 06:16:57 +00:00
|
|
|
|
++evit;
|
2016-06-01 19:49:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
Do a better job at creating plot info entries
This simplifies - and improves - the code to generate the plot info
entries from the samples.
We used to generate exactly one plot info entry per sample, and then -
because the result doesn't have high enough granularity - we'd
generate additional plot info entries at gas change events etc.
Which resulted in all kinds of ugly special case logic. Not only for
the gas switch, btw: you can see the effects of this in the deco graph
(done at plot entry boundaries) and in the gas pressure curves.
So this throws that "do special plot entries for gas switch events"
code away entirely, and replaces it with a much more straightforward
model: we generate plot entries at a minimum of ten-second intervals.
If you have samples more often than that, you'll get more frequent
plot entries, but you'll never get less than that "every ten seconds".
As a result, the code is smaller and simpler (99 insertions, 161
deletions), and actually does a better job too.
You can see the difference especially in the test dives that only have
a few entries (or if you create a new dive without a dive computer,
using the "Add Dive" menu entry). Look at the deco graph of test-dive
20 before and after, for example. You can also see it very subtly in
the cylinder pressure curves going from line segments to curves on
that same dive.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-06 20:53:25 +00:00
|
|
|
|
/* Add two final surface events */
|
2024-05-03 16:51:03 +00:00
|
|
|
|
add_entry(pi).sec = lasttime + 1;
|
|
|
|
|
add_entry(pi).sec = lasttime + 2;
|
|
|
|
|
pi.nr = (int)pi.entry.size();
|
Do a better job at creating plot info entries
This simplifies - and improves - the code to generate the plot info
entries from the samples.
We used to generate exactly one plot info entry per sample, and then -
because the result doesn't have high enough granularity - we'd
generate additional plot info entries at gas change events etc.
Which resulted in all kinds of ugly special case logic. Not only for
the gas switch, btw: you can see the effects of this in the deco graph
(done at plot entry boundaries) and in the gas pressure curves.
So this throws that "do special plot entries for gas switch events"
code away entirely, and replaces it with a much more straightforward
model: we generate plot entries at a minimum of ten-second intervals.
If you have samples more often than that, you'll get more frequent
plot entries, but you'll never get less than that "every ten seconds".
As a result, the code is smaller and simpler (99 insertions, 161
deletions), and actually does a better job too.
You can see the difference especially in the test dives that only have
a few entries (or if you create a new dive without a dive computer,
using the "Add Dive" menu entry). Look at the deco graph of test-dive
20 before and after, for example. You can also see it very subtly in
the cylinder pressure curves going from line segments to curves on
that same dive.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-06 20:53:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-22 19:47:39 +00:00
|
|
|
|
/*
|
|
|
|
|
* Calculate the sac rate between the two plot entries 'first' and 'last'.
|
|
|
|
|
*
|
2017-07-28 18:25:42 +00:00
|
|
|
|
* Everything in between has a cylinder pressure for at least some of the cylinders.
|
2015-10-22 19:47:39 +00:00
|
|
|
|
*/
|
2024-05-03 16:51:03 +00:00
|
|
|
|
static int sac_between(const struct dive *dive, const struct plot_info &pi, int first, int last, const char gases[])
|
2015-10-22 19:47:39 +00:00
|
|
|
|
{
|
|
|
|
|
if (first == last)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2017-07-28 18:25:42 +00:00
|
|
|
|
/* Get airuse for the set of cylinders over the range */
|
2024-05-28 19:31:11 +00:00
|
|
|
|
int airuse = 0;
|
|
|
|
|
for (int i = 0; i < pi.nr_cylinders; i++) {
|
2017-07-28 18:25:42 +00:00
|
|
|
|
pressure_t a, b;
|
|
|
|
|
|
2019-07-12 22:12:47 +00:00
|
|
|
|
if (!gases[i])
|
2017-07-28 18:25:42 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
2019-07-06 09:58:27 +00:00
|
|
|
|
a.mbar = get_plot_pressure(pi, first, i);
|
|
|
|
|
b.mbar = get_plot_pressure(pi, last, i);
|
2024-06-25 05:43:32 +00:00
|
|
|
|
const cylinder_t *cyl = dive->get_cylinder(i);
|
2024-07-02 09:12:27 +00:00
|
|
|
|
// TODO: Implement addition/subtraction on units.h types
|
|
|
|
|
int cyluse = cyl->gas_volume(a).mliter - cyl->gas_volume(b).mliter;
|
2017-07-28 18:25:42 +00:00
|
|
|
|
if (cyluse > 0)
|
|
|
|
|
airuse += cyluse;
|
|
|
|
|
}
|
|
|
|
|
if (!airuse)
|
2015-10-22 19:47:39 +00:00
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
/* Calculate depthpressure integrated over time */
|
2024-05-28 19:31:11 +00:00
|
|
|
|
double pressuretime = 0.0;
|
2015-10-22 19:47:39 +00:00
|
|
|
|
do {
|
2024-05-03 16:51:03 +00:00
|
|
|
|
const struct plot_data &entry = pi.entry[first];
|
|
|
|
|
const struct plot_data &next = pi.entry[first + 1];
|
|
|
|
|
int depth = (entry.depth + next.depth) / 2;
|
|
|
|
|
int time = next.sec - entry.sec;
|
2024-06-20 20:09:47 +00:00
|
|
|
|
double atm = dive->depth_to_atm(depth);
|
2015-10-22 19:47:39 +00:00
|
|
|
|
|
|
|
|
|
pressuretime += atm * time;
|
|
|
|
|
} while (++first < last);
|
|
|
|
|
|
|
|
|
|
/* Turn "atmseconds" into "atmminutes" */
|
|
|
|
|
pressuretime /= 60;
|
|
|
|
|
|
|
|
|
|
/* SAC = mliter per minute */
|
2017-03-08 06:41:41 +00:00
|
|
|
|
return lrint(airuse / pressuretime);
|
2015-10-22 19:47:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-12 22:12:47 +00:00
|
|
|
|
/* Is there pressure data for all gases? */
|
2024-05-03 16:51:03 +00:00
|
|
|
|
static bool all_pressures(const struct plot_info &pi, int idx, const char gases[])
|
2017-07-28 18:25:42 +00:00
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
for (i = 0; i < pi.nr_cylinders; i++) {
|
2019-07-12 22:12:47 +00:00
|
|
|
|
if (gases[i] && !get_plot_pressure(pi, idx, i))
|
|
|
|
|
return false;
|
2017-07-28 18:25:42 +00:00
|
|
|
|
}
|
2019-07-12 22:12:47 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Which of the set of gases have pressure data? Returns false if none of them. */
|
2024-05-03 16:51:03 +00:00
|
|
|
|
static bool filter_pressures(const struct plot_info &pi, int idx, const char gases_in[], char gases_out[])
|
2019-07-12 22:12:47 +00:00
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
bool has_pressure = false;
|
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
for (i = 0; i < pi.nr_cylinders; i++) {
|
2019-07-12 22:12:47 +00:00
|
|
|
|
gases_out[i] = gases_in[i] && get_plot_pressure(pi, idx, i);
|
|
|
|
|
has_pressure |= gases_out[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return has_pressure;
|
2017-07-28 18:25:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-22 19:47:39 +00:00
|
|
|
|
/*
|
|
|
|
|
* Try to do the momentary sac rate for this entry, averaging over one
|
2019-07-12 22:12:47 +00:00
|
|
|
|
* minute. This is premature optimization, but instead of allocating
|
|
|
|
|
* an array of gases, the caller passes in scratch memory in the last
|
|
|
|
|
* argument.
|
2015-10-22 19:47:39 +00:00
|
|
|
|
*/
|
2024-05-03 16:51:03 +00:00
|
|
|
|
static void fill_sac(const struct dive *dive, struct plot_info &pi, int idx, const char gases_in[], char gases[])
|
2015-10-22 19:47:39 +00:00
|
|
|
|
{
|
2024-05-03 16:51:03 +00:00
|
|
|
|
struct plot_data &entry = pi.entry[idx];
|
2019-07-06 09:58:27 +00:00
|
|
|
|
int first, last;
|
2016-03-10 15:37:18 +00:00
|
|
|
|
int time;
|
2015-10-22 19:47:39 +00:00
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (entry.sac)
|
2015-10-22 19:47:39 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2017-07-28 18:25:42 +00:00
|
|
|
|
/*
|
|
|
|
|
* We may not have pressure data for all the cylinders,
|
|
|
|
|
* but we'll calculate the SAC for the ones we do have.
|
|
|
|
|
*/
|
2019-07-12 22:12:47 +00:00
|
|
|
|
if (!filter_pressures(pi, idx, gases_in, gases))
|
2015-10-22 19:47:39 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Try to go back 30 seconds to get 'first'.
|
2017-07-28 18:25:42 +00:00
|
|
|
|
* Stop if the cylinder pressure data set changes.
|
2015-10-22 19:47:39 +00:00
|
|
|
|
*/
|
2019-07-06 09:58:27 +00:00
|
|
|
|
first = idx;
|
2024-05-03 16:51:03 +00:00
|
|
|
|
time = entry.sec - 30;
|
2015-10-22 19:47:39 +00:00
|
|
|
|
while (idx > 0) {
|
2024-05-03 16:51:03 +00:00
|
|
|
|
const struct plot_data &entry = pi.entry[idx];
|
|
|
|
|
const struct plot_data &prev = pi.entry[idx - 1];
|
Profile support for multiple concurrent pressure sensors
This finally handles multiple cylinder pressures, both overlapping and
consecutive, and it seems to work on the nasty cases I've thrown at it.
Want to just track five different cylinders all at once, without any
pesky gas switch events? Sure, you can do that. It will show five
different gas pressures for your five cylinders, and they will go down
as you breathe down the cylinders.
I obviously don't have any real data for that case, but I do have a test
file with five actual cylinders that all have samples over the whole
course of the dive. The end result looks messy as hell, but what did
you expect?
HOWEVER.
The only way to do this sanely was
- actually make the "struct plot_info" have all the cylinder pressures
(so no "sensor index and pressure" - every cylinder has a pressure for
every plot info entry)
This obviously makes the plot_info much bigger. We used to have
MAX_CYLINDERS be a fairly generous 8, which seems sane. The planning
code made that 8 be 20. That seems questionable. But whatever.
The good news is that the plot-info should hopefully get freed, and
only be allocated one dive at a time, so the fact that it is big and
nasty shouldn't be a scaling issue, though.
- the "populate_pressure_information()" function had to be rewritten
quite a bit. The good news is that it's actually simpler now, although
I would not go so far as to really call it simple. It's still
complicated and suble, but now it explicitly just does one cylinder at
a time.
It *used* to have this insanely complicated "keep track of the pressure
ranges for every cylinder at once". I just couldn't stand that model
and keep my sanity, so it now just tracks one cylinder at a time, and
doesn't have an array of live data, instead the caller will just call
it for each cylinder.
- get rid of some of our hackier stuff, like the code that populates the
plot_info data code with the currently selected cylinder number, and
clears out any other pressures. That obviously does *not* work when you
may not have a single primary cylinder any more.
Now, the above sounds like all good things. Yeah, it mostly is.
BUT.
There's a few big downsides from the above:
- there's no sane way to do this as a series of small changes.
The change to make the plot_info take an array of cylinder pressures
rather than the sensor+pressure model really isn't amenable to "fix up
one use at a time". When you switch over to the new data structure
model, you have to switch over to the new way of populating the
pressure ranges. The two just go hand in hand.
- Some of our code *depended* on the "sensor+pressure" model. I fixed all
the ones I could sanely fix. There was one particular case that I just
couldn't sanely fix, and I didn't care enough about it to do something
insane.
So the only _known_ breakage is the "TankItem" profile widget. That's
the bar at the bottom of the profile that shows which cylinder is in
use right now. You'd think that would be trivial to fix up, and yes it
would be - I could just use the regular model of
firstcyl = explicit_first_cylinder(dive, dc)
.. then iterate over the gas change events to see the others ..
but the problem with the "TankItem" widget is that it does its own
model, and it has thrown away the dive and the dive computer
information. It just doesn't even know. It only knows what cylinders
there are, and the plot_info. And it just used to look at the sensor
number in the plot_info, and be done with that. That number no longer
exists.
- I have tested it, and I think the code is better, but hey, it's a
fairly large patch to some of the more complex code in our code base.
That "interpolate missing pressure fields" code really isn't pretty. It
may be prettier, but..
Anyway, without further ado, here's the patch. No sign-off yet, because I
do think people should look and comment. But I think the patch is fine,
and I'll fix anythign that anybody can find, *except* for that TankItem
thing that I will refuse to touch. That class is ugly. It needs to have
access to the actual dive.
Note how it actually does remove more lines than it adds, and that's
despite added comments etc. The code really is simpler, but there may be
cases in there that need more work.
Known missing pieces that don't currently take advantage of concurrent
cylinder pressure data:
- the momentary SAC rate coloring for dives will need more work
- dive merging (but we expect to generally normally not merge dive
computers, which is the main source of sensor data)
- actually taking advantage of different sensor data from different
dive computers
But most of all: Testing. Lots and lots of testing to find all the
corner cases.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-27 17:17:05 +00:00
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (prev.depth < SURFACE_THRESHOLD && entry.depth < SURFACE_THRESHOLD)
|
2015-10-22 19:47:39 +00:00
|
|
|
|
break;
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (prev.sec < time)
|
2015-10-22 19:47:39 +00:00
|
|
|
|
break;
|
2019-07-12 22:12:47 +00:00
|
|
|
|
if (!all_pressures(pi, idx - 1, gases))
|
2015-10-22 19:47:39 +00:00
|
|
|
|
break;
|
|
|
|
|
idx--;
|
2019-07-06 09:58:27 +00:00
|
|
|
|
first = idx;
|
2015-10-22 19:47:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Now find an entry a minute after the first one */
|
|
|
|
|
last = first;
|
2024-05-03 16:51:03 +00:00
|
|
|
|
time = pi.entry[first].sec + 60;
|
|
|
|
|
while (++idx < pi.nr) {
|
|
|
|
|
const struct plot_data &entry = pi.entry[last];
|
|
|
|
|
const struct plot_data &next = pi.entry[last + 1];
|
|
|
|
|
if (next.depth < SURFACE_THRESHOLD && entry.depth < SURFACE_THRESHOLD)
|
2015-10-22 19:47:39 +00:00
|
|
|
|
break;
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (next.sec > time)
|
2015-10-22 19:47:39 +00:00
|
|
|
|
break;
|
2019-07-12 22:12:47 +00:00
|
|
|
|
if (!all_pressures(pi, idx + 1, gases))
|
2015-10-22 19:47:39 +00:00
|
|
|
|
break;
|
2019-07-06 09:58:27 +00:00
|
|
|
|
last = idx;
|
2015-10-22 19:47:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Ok, now calculate the SAC between 'first' and 'last' */
|
2024-05-03 16:51:03 +00:00
|
|
|
|
entry.sac = sac_between(dive, pi, first, last, gases);
|
2015-10-22 19:47:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-28 18:25:42 +00:00
|
|
|
|
/*
|
|
|
|
|
* Create a bitmap of cylinders that match our current gasmix
|
|
|
|
|
*/
|
2024-03-10 22:11:23 +00:00
|
|
|
|
static void matching_gases(const struct dive *dive, struct gasmix gasmix, char gases[])
|
2017-07-28 18:25:42 +00:00
|
|
|
|
{
|
2024-05-28 19:31:11 +00:00
|
|
|
|
for (auto [i, cyl]: enumerated_range(dive->cylinders))
|
|
|
|
|
gases[i] = same_gasmix(gasmix, cyl.gasmix);
|
2017-07-28 18:25:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
static void calculate_sac(const struct dive *dive, const struct divecomputer *dc, struct plot_info &pi)
|
2013-10-14 21:48:43 +00:00
|
|
|
|
{
|
2024-05-03 16:51:03 +00:00
|
|
|
|
std::vector<char> gases(pi.nr_cylinders, false);
|
2019-07-12 22:12:47 +00:00
|
|
|
|
|
|
|
|
|
/* This might be premature optimization, but let's allocate the gas array for
|
|
|
|
|
* the fill_sac function only once an not once per sample */
|
2024-05-03 16:51:03 +00:00
|
|
|
|
std::vector<char> gases_scratch(pi.nr_cylinders);
|
2017-07-28 18:25:42 +00:00
|
|
|
|
|
2024-05-25 06:16:57 +00:00
|
|
|
|
struct gasmix gasmix = gasmix_invalid;
|
|
|
|
|
gasmix_loop loop(*dive, *dc);
|
2024-05-03 16:51:03 +00:00
|
|
|
|
for (int i = 0; i < pi.nr; i++) {
|
|
|
|
|
const struct plot_data &entry = pi.entry[i];
|
2024-05-25 06:16:57 +00:00
|
|
|
|
struct gasmix newmix = loop.next(entry.sec);
|
2018-08-16 17:10:10 +00:00
|
|
|
|
if (!same_gasmix(newmix, gasmix)) {
|
2017-07-28 18:25:42 +00:00
|
|
|
|
gasmix = newmix;
|
2024-03-10 22:11:23 +00:00
|
|
|
|
matching_gases(dive, newmix, gases.data());
|
2017-07-28 18:25:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-10 22:11:23 +00:00
|
|
|
|
fill_sac(dive, pi, i, gases.data(), gases_scratch.data());
|
2017-07-28 18:25:42 +00:00
|
|
|
|
}
|
2013-10-14 21:48:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-27 15:09:48 +00:00
|
|
|
|
static void populate_secondary_sensor_data(const struct divecomputer &dc, struct plot_info &pi)
|
2013-01-07 00:09:48 +00:00
|
|
|
|
{
|
2024-05-03 16:51:03 +00:00
|
|
|
|
std::vector<int> seen(pi.nr_cylinders, 0);
|
|
|
|
|
for (int idx = 0; idx < pi.nr; ++idx)
|
|
|
|
|
for (int c = 0; c < pi.nr_cylinders; ++c)
|
2022-03-20 15:54:15 +00:00
|
|
|
|
if (get_plot_pressure_data(pi, idx, SENSOR_PR, c))
|
|
|
|
|
++seen[c]; // Count instances so we can differentiate a real sensor from just start and end pressure
|
|
|
|
|
int idx = 0;
|
2013-01-07 00:09:48 +00:00
|
|
|
|
/* We should try to see if it has interesting pressure data here */
|
2024-05-27 15:09:48 +00:00
|
|
|
|
for (const auto &sample: dc.samples) {
|
2024-05-19 10:38:38 +00:00
|
|
|
|
if (idx >= pi.nr)
|
|
|
|
|
break;
|
2024-05-03 16:51:03 +00:00
|
|
|
|
for (; idx < pi.nr; ++idx) {
|
|
|
|
|
if (idx == pi.nr - 1 || pi.entry[idx].sec >= sample.time.seconds)
|
2022-03-20 15:54:15 +00:00
|
|
|
|
// We've either found the entry at or just after the sample's time,
|
|
|
|
|
// or this is the last entry so use for the last sensor readings if there are any.
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
for (int s = 0; s < MAX_SENSORS; ++s)
|
|
|
|
|
// Copy sensor data if available, but don't add if this dc already has sensor data
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (sample.sensor[s] != NO_SENSOR && seen[sample.sensor[s]] < 3 && sample.pressure[s].mbar)
|
|
|
|
|
set_plot_pressure_data(pi, idx, SENSOR_PR, sample.sensor[s], sample.pressure[s].mbar);
|
2022-03-20 15:54:15 +00:00
|
|
|
|
}
|
2013-01-07 00:09:48 +00:00
|
|
|
|
}
|
2011-10-23 14:52:45 +00:00
|
|
|
|
|
Profile support for multiple concurrent pressure sensors
This finally handles multiple cylinder pressures, both overlapping and
consecutive, and it seems to work on the nasty cases I've thrown at it.
Want to just track five different cylinders all at once, without any
pesky gas switch events? Sure, you can do that. It will show five
different gas pressures for your five cylinders, and they will go down
as you breathe down the cylinders.
I obviously don't have any real data for that case, but I do have a test
file with five actual cylinders that all have samples over the whole
course of the dive. The end result looks messy as hell, but what did
you expect?
HOWEVER.
The only way to do this sanely was
- actually make the "struct plot_info" have all the cylinder pressures
(so no "sensor index and pressure" - every cylinder has a pressure for
every plot info entry)
This obviously makes the plot_info much bigger. We used to have
MAX_CYLINDERS be a fairly generous 8, which seems sane. The planning
code made that 8 be 20. That seems questionable. But whatever.
The good news is that the plot-info should hopefully get freed, and
only be allocated one dive at a time, so the fact that it is big and
nasty shouldn't be a scaling issue, though.
- the "populate_pressure_information()" function had to be rewritten
quite a bit. The good news is that it's actually simpler now, although
I would not go so far as to really call it simple. It's still
complicated and suble, but now it explicitly just does one cylinder at
a time.
It *used* to have this insanely complicated "keep track of the pressure
ranges for every cylinder at once". I just couldn't stand that model
and keep my sanity, so it now just tracks one cylinder at a time, and
doesn't have an array of live data, instead the caller will just call
it for each cylinder.
- get rid of some of our hackier stuff, like the code that populates the
plot_info data code with the currently selected cylinder number, and
clears out any other pressures. That obviously does *not* work when you
may not have a single primary cylinder any more.
Now, the above sounds like all good things. Yeah, it mostly is.
BUT.
There's a few big downsides from the above:
- there's no sane way to do this as a series of small changes.
The change to make the plot_info take an array of cylinder pressures
rather than the sensor+pressure model really isn't amenable to "fix up
one use at a time". When you switch over to the new data structure
model, you have to switch over to the new way of populating the
pressure ranges. The two just go hand in hand.
- Some of our code *depended* on the "sensor+pressure" model. I fixed all
the ones I could sanely fix. There was one particular case that I just
couldn't sanely fix, and I didn't care enough about it to do something
insane.
So the only _known_ breakage is the "TankItem" profile widget. That's
the bar at the bottom of the profile that shows which cylinder is in
use right now. You'd think that would be trivial to fix up, and yes it
would be - I could just use the regular model of
firstcyl = explicit_first_cylinder(dive, dc)
.. then iterate over the gas change events to see the others ..
but the problem with the "TankItem" widget is that it does its own
model, and it has thrown away the dive and the dive computer
information. It just doesn't even know. It only knows what cylinders
there are, and the plot_info. And it just used to look at the sensor
number in the plot_info, and be done with that. That number no longer
exists.
- I have tested it, and I think the code is better, but hey, it's a
fairly large patch to some of the more complex code in our code base.
That "interpolate missing pressure fields" code really isn't pretty. It
may be prettier, but..
Anyway, without further ado, here's the patch. No sign-off yet, because I
do think people should look and comment. But I think the patch is fine,
and I'll fix anythign that anybody can find, *except* for that TankItem
thing that I will refuse to touch. That class is ugly. It needs to have
access to the actual dive.
Note how it actually does remove more lines than it adds, and that's
despite added comments etc. The code really is simpler, but there may be
cases in there that need more work.
Known missing pieces that don't currently take advantage of concurrent
cylinder pressure data:
- the momentary SAC rate coloring for dives will need more work
- dive merging (but we expect to generally normally not merge dive
computers, which is the main source of sensor data)
- actually taking advantage of different sensor data from different
dive computers
But most of all: Testing. Lots and lots of testing to find all the
corner cases.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-27 17:17:05 +00:00
|
|
|
|
/*
|
|
|
|
|
* This adds a pressure entry to the plot_info based on the gas change
|
|
|
|
|
* information and the manually filled in pressures.
|
|
|
|
|
*/
|
2024-05-03 16:51:03 +00:00
|
|
|
|
static void add_plot_pressure(struct plot_info &pi, int time, int cyl, pressure_t p)
|
Profile support for multiple concurrent pressure sensors
This finally handles multiple cylinder pressures, both overlapping and
consecutive, and it seems to work on the nasty cases I've thrown at it.
Want to just track five different cylinders all at once, without any
pesky gas switch events? Sure, you can do that. It will show five
different gas pressures for your five cylinders, and they will go down
as you breathe down the cylinders.
I obviously don't have any real data for that case, but I do have a test
file with five actual cylinders that all have samples over the whole
course of the dive. The end result looks messy as hell, but what did
you expect?
HOWEVER.
The only way to do this sanely was
- actually make the "struct plot_info" have all the cylinder pressures
(so no "sensor index and pressure" - every cylinder has a pressure for
every plot info entry)
This obviously makes the plot_info much bigger. We used to have
MAX_CYLINDERS be a fairly generous 8, which seems sane. The planning
code made that 8 be 20. That seems questionable. But whatever.
The good news is that the plot-info should hopefully get freed, and
only be allocated one dive at a time, so the fact that it is big and
nasty shouldn't be a scaling issue, though.
- the "populate_pressure_information()" function had to be rewritten
quite a bit. The good news is that it's actually simpler now, although
I would not go so far as to really call it simple. It's still
complicated and suble, but now it explicitly just does one cylinder at
a time.
It *used* to have this insanely complicated "keep track of the pressure
ranges for every cylinder at once". I just couldn't stand that model
and keep my sanity, so it now just tracks one cylinder at a time, and
doesn't have an array of live data, instead the caller will just call
it for each cylinder.
- get rid of some of our hackier stuff, like the code that populates the
plot_info data code with the currently selected cylinder number, and
clears out any other pressures. That obviously does *not* work when you
may not have a single primary cylinder any more.
Now, the above sounds like all good things. Yeah, it mostly is.
BUT.
There's a few big downsides from the above:
- there's no sane way to do this as a series of small changes.
The change to make the plot_info take an array of cylinder pressures
rather than the sensor+pressure model really isn't amenable to "fix up
one use at a time". When you switch over to the new data structure
model, you have to switch over to the new way of populating the
pressure ranges. The two just go hand in hand.
- Some of our code *depended* on the "sensor+pressure" model. I fixed all
the ones I could sanely fix. There was one particular case that I just
couldn't sanely fix, and I didn't care enough about it to do something
insane.
So the only _known_ breakage is the "TankItem" profile widget. That's
the bar at the bottom of the profile that shows which cylinder is in
use right now. You'd think that would be trivial to fix up, and yes it
would be - I could just use the regular model of
firstcyl = explicit_first_cylinder(dive, dc)
.. then iterate over the gas change events to see the others ..
but the problem with the "TankItem" widget is that it does its own
model, and it has thrown away the dive and the dive computer
information. It just doesn't even know. It only knows what cylinders
there are, and the plot_info. And it just used to look at the sensor
number in the plot_info, and be done with that. That number no longer
exists.
- I have tested it, and I think the code is better, but hey, it's a
fairly large patch to some of the more complex code in our code base.
That "interpolate missing pressure fields" code really isn't pretty. It
may be prettier, but..
Anyway, without further ado, here's the patch. No sign-off yet, because I
do think people should look and comment. But I think the patch is fine,
and I'll fix anythign that anybody can find, *except* for that TankItem
thing that I will refuse to touch. That class is ugly. It needs to have
access to the actual dive.
Note how it actually does remove more lines than it adds, and that's
despite added comments etc. The code really is simpler, but there may be
cases in there that need more work.
Known missing pieces that don't currently take advantage of concurrent
cylinder pressure data:
- the momentary SAC rate coloring for dives will need more work
- dive merging (but we expect to generally normally not merge dive
computers, which is the main source of sensor data)
- actually taking advantage of different sensor data from different
dive computers
But most of all: Testing. Lots and lots of testing to find all the
corner cases.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-27 17:17:05 +00:00
|
|
|
|
{
|
2024-05-03 16:51:03 +00:00
|
|
|
|
for (int i = 0; i < pi.nr; i++) {
|
|
|
|
|
if (i == pi.nr - 1 || pi.entry[i].sec >= time) {
|
2019-07-06 10:59:12 +00:00
|
|
|
|
set_plot_pressure_data(pi, i, SENSOR_PR, cyl, p.mbar);
|
|
|
|
|
return;
|
|
|
|
|
}
|
Profile support for multiple concurrent pressure sensors
This finally handles multiple cylinder pressures, both overlapping and
consecutive, and it seems to work on the nasty cases I've thrown at it.
Want to just track five different cylinders all at once, without any
pesky gas switch events? Sure, you can do that. It will show five
different gas pressures for your five cylinders, and they will go down
as you breathe down the cylinders.
I obviously don't have any real data for that case, but I do have a test
file with five actual cylinders that all have samples over the whole
course of the dive. The end result looks messy as hell, but what did
you expect?
HOWEVER.
The only way to do this sanely was
- actually make the "struct plot_info" have all the cylinder pressures
(so no "sensor index and pressure" - every cylinder has a pressure for
every plot info entry)
This obviously makes the plot_info much bigger. We used to have
MAX_CYLINDERS be a fairly generous 8, which seems sane. The planning
code made that 8 be 20. That seems questionable. But whatever.
The good news is that the plot-info should hopefully get freed, and
only be allocated one dive at a time, so the fact that it is big and
nasty shouldn't be a scaling issue, though.
- the "populate_pressure_information()" function had to be rewritten
quite a bit. The good news is that it's actually simpler now, although
I would not go so far as to really call it simple. It's still
complicated and suble, but now it explicitly just does one cylinder at
a time.
It *used* to have this insanely complicated "keep track of the pressure
ranges for every cylinder at once". I just couldn't stand that model
and keep my sanity, so it now just tracks one cylinder at a time, and
doesn't have an array of live data, instead the caller will just call
it for each cylinder.
- get rid of some of our hackier stuff, like the code that populates the
plot_info data code with the currently selected cylinder number, and
clears out any other pressures. That obviously does *not* work when you
may not have a single primary cylinder any more.
Now, the above sounds like all good things. Yeah, it mostly is.
BUT.
There's a few big downsides from the above:
- there's no sane way to do this as a series of small changes.
The change to make the plot_info take an array of cylinder pressures
rather than the sensor+pressure model really isn't amenable to "fix up
one use at a time". When you switch over to the new data structure
model, you have to switch over to the new way of populating the
pressure ranges. The two just go hand in hand.
- Some of our code *depended* on the "sensor+pressure" model. I fixed all
the ones I could sanely fix. There was one particular case that I just
couldn't sanely fix, and I didn't care enough about it to do something
insane.
So the only _known_ breakage is the "TankItem" profile widget. That's
the bar at the bottom of the profile that shows which cylinder is in
use right now. You'd think that would be trivial to fix up, and yes it
would be - I could just use the regular model of
firstcyl = explicit_first_cylinder(dive, dc)
.. then iterate over the gas change events to see the others ..
but the problem with the "TankItem" widget is that it does its own
model, and it has thrown away the dive and the dive computer
information. It just doesn't even know. It only knows what cylinders
there are, and the plot_info. And it just used to look at the sensor
number in the plot_info, and be done with that. That number no longer
exists.
- I have tested it, and I think the code is better, but hey, it's a
fairly large patch to some of the more complex code in our code base.
That "interpolate missing pressure fields" code really isn't pretty. It
may be prettier, but..
Anyway, without further ado, here's the patch. No sign-off yet, because I
do think people should look and comment. But I think the patch is fine,
and I'll fix anythign that anybody can find, *except* for that TankItem
thing that I will refuse to touch. That class is ugly. It needs to have
access to the actual dive.
Note how it actually does remove more lines than it adds, and that's
despite added comments etc. The code really is simpler, but there may be
cases in there that need more work.
Known missing pieces that don't currently take advantage of concurrent
cylinder pressure data:
- the momentary SAC rate coloring for dives will need more work
- dive merging (but we expect to generally normally not merge dive
computers, which is the main source of sensor data)
- actually taking advantage of different sensor data from different
dive computers
But most of all: Testing. Lots and lots of testing to find all the
corner cases.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-27 17:17:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
static void setup_gas_sensor_pressure(const struct dive *dive, const struct divecomputer *dc, struct plot_info &pi)
|
2013-01-07 00:09:48 +00:00
|
|
|
|
{
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (pi.nr_cylinders == 0)
|
2020-04-20 19:12:54 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2024-02-07 18:34:26 +00:00
|
|
|
|
/* FIXME: The planner uses a dummy one-past-end cylinder for surface air! */
|
2024-05-03 16:51:03 +00:00
|
|
|
|
int num_cyl = pi.nr_cylinders + 1;
|
2024-03-10 22:11:23 +00:00
|
|
|
|
std::vector<int> seen(num_cyl, 0);
|
|
|
|
|
std::vector<int> first(num_cyl, 0);
|
|
|
|
|
std::vector<int> last(num_cyl, INT_MAX);
|
2017-07-28 18:49:03 +00:00
|
|
|
|
|
2024-06-25 05:43:32 +00:00
|
|
|
|
int prev = dive->explicit_first_cylinder(dc);
|
2024-04-25 23:04:05 +00:00
|
|
|
|
prev = prev >= 0 ? prev : 0;
|
2017-07-31 04:05:48 +00:00
|
|
|
|
seen[prev] = 1;
|
Do a better job at creating plot info entries
This simplifies - and improves - the code to generate the plot info
entries from the samples.
We used to generate exactly one plot info entry per sample, and then -
because the result doesn't have high enough granularity - we'd
generate additional plot info entries at gas change events etc.
Which resulted in all kinds of ugly special case logic. Not only for
the gas switch, btw: you can see the effects of this in the deco graph
(done at plot entry boundaries) and in the gas pressure curves.
So this throws that "do special plot entries for gas switch events"
code away entirely, and replaces it with a much more straightforward
model: we generate plot entries at a minimum of ten-second intervals.
If you have samples more often than that, you'll get more frequent
plot entries, but you'll never get less than that "every ten seconds".
As a result, the code is smaller and simpler (99 insertions, 161
deletions), and actually does a better job too.
You can see the difference especially in the test dives that only have
a few entries (or if you create a new dive without a dive computer,
using the "Add Dive" menu entry). Look at the deco graph of test-dive
20 before and after, for example. You can also see it very subtly in
the cylinder pressure curves going from line segments to curves on
that same dive.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-06 20:53:25 +00:00
|
|
|
|
|
2024-05-25 06:16:57 +00:00
|
|
|
|
event_loop loop("gaschange");
|
|
|
|
|
while (auto ev = loop.next(*dc)) {
|
Profile support for multiple concurrent pressure sensors
This finally handles multiple cylinder pressures, both overlapping and
consecutive, and it seems to work on the nasty cases I've thrown at it.
Want to just track five different cylinders all at once, without any
pesky gas switch events? Sure, you can do that. It will show five
different gas pressures for your five cylinders, and they will go down
as you breathe down the cylinders.
I obviously don't have any real data for that case, but I do have a test
file with five actual cylinders that all have samples over the whole
course of the dive. The end result looks messy as hell, but what did
you expect?
HOWEVER.
The only way to do this sanely was
- actually make the "struct plot_info" have all the cylinder pressures
(so no "sensor index and pressure" - every cylinder has a pressure for
every plot info entry)
This obviously makes the plot_info much bigger. We used to have
MAX_CYLINDERS be a fairly generous 8, which seems sane. The planning
code made that 8 be 20. That seems questionable. But whatever.
The good news is that the plot-info should hopefully get freed, and
only be allocated one dive at a time, so the fact that it is big and
nasty shouldn't be a scaling issue, though.
- the "populate_pressure_information()" function had to be rewritten
quite a bit. The good news is that it's actually simpler now, although
I would not go so far as to really call it simple. It's still
complicated and suble, but now it explicitly just does one cylinder at
a time.
It *used* to have this insanely complicated "keep track of the pressure
ranges for every cylinder at once". I just couldn't stand that model
and keep my sanity, so it now just tracks one cylinder at a time, and
doesn't have an array of live data, instead the caller will just call
it for each cylinder.
- get rid of some of our hackier stuff, like the code that populates the
plot_info data code with the currently selected cylinder number, and
clears out any other pressures. That obviously does *not* work when you
may not have a single primary cylinder any more.
Now, the above sounds like all good things. Yeah, it mostly is.
BUT.
There's a few big downsides from the above:
- there's no sane way to do this as a series of small changes.
The change to make the plot_info take an array of cylinder pressures
rather than the sensor+pressure model really isn't amenable to "fix up
one use at a time". When you switch over to the new data structure
model, you have to switch over to the new way of populating the
pressure ranges. The two just go hand in hand.
- Some of our code *depended* on the "sensor+pressure" model. I fixed all
the ones I could sanely fix. There was one particular case that I just
couldn't sanely fix, and I didn't care enough about it to do something
insane.
So the only _known_ breakage is the "TankItem" profile widget. That's
the bar at the bottom of the profile that shows which cylinder is in
use right now. You'd think that would be trivial to fix up, and yes it
would be - I could just use the regular model of
firstcyl = explicit_first_cylinder(dive, dc)
.. then iterate over the gas change events to see the others ..
but the problem with the "TankItem" widget is that it does its own
model, and it has thrown away the dive and the dive computer
information. It just doesn't even know. It only knows what cylinders
there are, and the plot_info. And it just used to look at the sensor
number in the plot_info, and be done with that. That number no longer
exists.
- I have tested it, and I think the code is better, but hey, it's a
fairly large patch to some of the more complex code in our code base.
That "interpolate missing pressure fields" code really isn't pretty. It
may be prettier, but..
Anyway, without further ado, here's the patch. No sign-off yet, because I
do think people should look and comment. But I think the patch is fine,
and I'll fix anythign that anybody can find, *except* for that TankItem
thing that I will refuse to touch. That class is ugly. It needs to have
access to the actual dive.
Note how it actually does remove more lines than it adds, and that's
despite added comments etc. The code really is simpler, but there may be
cases in there that need more work.
Known missing pieces that don't currently take advantage of concurrent
cylinder pressure data:
- the momentary SAC rate coloring for dives will need more work
- dive merging (but we expect to generally normally not merge dive
computers, which is the main source of sensor data)
- actually taking advantage of different sensor data from different
dive computers
But most of all: Testing. Lots and lots of testing to find all the
corner cases.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-27 17:17:05 +00:00
|
|
|
|
int cyl = ev->gas.index;
|
|
|
|
|
int sec = ev->time.seconds;
|
2013-01-07 00:09:48 +00:00
|
|
|
|
|
Profile support for multiple concurrent pressure sensors
This finally handles multiple cylinder pressures, both overlapping and
consecutive, and it seems to work on the nasty cases I've thrown at it.
Want to just track five different cylinders all at once, without any
pesky gas switch events? Sure, you can do that. It will show five
different gas pressures for your five cylinders, and they will go down
as you breathe down the cylinders.
I obviously don't have any real data for that case, but I do have a test
file with five actual cylinders that all have samples over the whole
course of the dive. The end result looks messy as hell, but what did
you expect?
HOWEVER.
The only way to do this sanely was
- actually make the "struct plot_info" have all the cylinder pressures
(so no "sensor index and pressure" - every cylinder has a pressure for
every plot info entry)
This obviously makes the plot_info much bigger. We used to have
MAX_CYLINDERS be a fairly generous 8, which seems sane. The planning
code made that 8 be 20. That seems questionable. But whatever.
The good news is that the plot-info should hopefully get freed, and
only be allocated one dive at a time, so the fact that it is big and
nasty shouldn't be a scaling issue, though.
- the "populate_pressure_information()" function had to be rewritten
quite a bit. The good news is that it's actually simpler now, although
I would not go so far as to really call it simple. It's still
complicated and suble, but now it explicitly just does one cylinder at
a time.
It *used* to have this insanely complicated "keep track of the pressure
ranges for every cylinder at once". I just couldn't stand that model
and keep my sanity, so it now just tracks one cylinder at a time, and
doesn't have an array of live data, instead the caller will just call
it for each cylinder.
- get rid of some of our hackier stuff, like the code that populates the
plot_info data code with the currently selected cylinder number, and
clears out any other pressures. That obviously does *not* work when you
may not have a single primary cylinder any more.
Now, the above sounds like all good things. Yeah, it mostly is.
BUT.
There's a few big downsides from the above:
- there's no sane way to do this as a series of small changes.
The change to make the plot_info take an array of cylinder pressures
rather than the sensor+pressure model really isn't amenable to "fix up
one use at a time". When you switch over to the new data structure
model, you have to switch over to the new way of populating the
pressure ranges. The two just go hand in hand.
- Some of our code *depended* on the "sensor+pressure" model. I fixed all
the ones I could sanely fix. There was one particular case that I just
couldn't sanely fix, and I didn't care enough about it to do something
insane.
So the only _known_ breakage is the "TankItem" profile widget. That's
the bar at the bottom of the profile that shows which cylinder is in
use right now. You'd think that would be trivial to fix up, and yes it
would be - I could just use the regular model of
firstcyl = explicit_first_cylinder(dive, dc)
.. then iterate over the gas change events to see the others ..
but the problem with the "TankItem" widget is that it does its own
model, and it has thrown away the dive and the dive computer
information. It just doesn't even know. It only knows what cylinders
there are, and the plot_info. And it just used to look at the sensor
number in the plot_info, and be done with that. That number no longer
exists.
- I have tested it, and I think the code is better, but hey, it's a
fairly large patch to some of the more complex code in our code base.
That "interpolate missing pressure fields" code really isn't pretty. It
may be prettier, but..
Anyway, without further ado, here's the patch. No sign-off yet, because I
do think people should look and comment. But I think the patch is fine,
and I'll fix anythign that anybody can find, *except* for that TankItem
thing that I will refuse to touch. That class is ugly. It needs to have
access to the actual dive.
Note how it actually does remove more lines than it adds, and that's
despite added comments etc. The code really is simpler, but there may be
cases in there that need more work.
Known missing pieces that don't currently take advantage of concurrent
cylinder pressure data:
- the momentary SAC rate coloring for dives will need more work
- dive merging (but we expect to generally normally not merge dive
computers, which is the main source of sensor data)
- actually taking advantage of different sensor data from different
dive computers
But most of all: Testing. Lots and lots of testing to find all the
corner cases.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-27 17:17:05 +00:00
|
|
|
|
if (cyl < 0)
|
2024-02-07 18:34:26 +00:00
|
|
|
|
continue; // unknown cylinder
|
|
|
|
|
if (cyl >= num_cyl) {
|
2024-03-24 20:03:08 +00:00
|
|
|
|
report_info("setup_gas_sensor_pressure(): invalid cylinder idx %d", cyl);
|
2013-01-07 00:09:48 +00:00
|
|
|
|
continue;
|
2024-02-07 18:34:26 +00:00
|
|
|
|
}
|
2013-01-07 00:09:48 +00:00
|
|
|
|
|
2017-11-17 01:35:03 +00:00
|
|
|
|
last[prev] = sec;
|
Profile support for multiple concurrent pressure sensors
This finally handles multiple cylinder pressures, both overlapping and
consecutive, and it seems to work on the nasty cases I've thrown at it.
Want to just track five different cylinders all at once, without any
pesky gas switch events? Sure, you can do that. It will show five
different gas pressures for your five cylinders, and they will go down
as you breathe down the cylinders.
I obviously don't have any real data for that case, but I do have a test
file with five actual cylinders that all have samples over the whole
course of the dive. The end result looks messy as hell, but what did
you expect?
HOWEVER.
The only way to do this sanely was
- actually make the "struct plot_info" have all the cylinder pressures
(so no "sensor index and pressure" - every cylinder has a pressure for
every plot info entry)
This obviously makes the plot_info much bigger. We used to have
MAX_CYLINDERS be a fairly generous 8, which seems sane. The planning
code made that 8 be 20. That seems questionable. But whatever.
The good news is that the plot-info should hopefully get freed, and
only be allocated one dive at a time, so the fact that it is big and
nasty shouldn't be a scaling issue, though.
- the "populate_pressure_information()" function had to be rewritten
quite a bit. The good news is that it's actually simpler now, although
I would not go so far as to really call it simple. It's still
complicated and suble, but now it explicitly just does one cylinder at
a time.
It *used* to have this insanely complicated "keep track of the pressure
ranges for every cylinder at once". I just couldn't stand that model
and keep my sanity, so it now just tracks one cylinder at a time, and
doesn't have an array of live data, instead the caller will just call
it for each cylinder.
- get rid of some of our hackier stuff, like the code that populates the
plot_info data code with the currently selected cylinder number, and
clears out any other pressures. That obviously does *not* work when you
may not have a single primary cylinder any more.
Now, the above sounds like all good things. Yeah, it mostly is.
BUT.
There's a few big downsides from the above:
- there's no sane way to do this as a series of small changes.
The change to make the plot_info take an array of cylinder pressures
rather than the sensor+pressure model really isn't amenable to "fix up
one use at a time". When you switch over to the new data structure
model, you have to switch over to the new way of populating the
pressure ranges. The two just go hand in hand.
- Some of our code *depended* on the "sensor+pressure" model. I fixed all
the ones I could sanely fix. There was one particular case that I just
couldn't sanely fix, and I didn't care enough about it to do something
insane.
So the only _known_ breakage is the "TankItem" profile widget. That's
the bar at the bottom of the profile that shows which cylinder is in
use right now. You'd think that would be trivial to fix up, and yes it
would be - I could just use the regular model of
firstcyl = explicit_first_cylinder(dive, dc)
.. then iterate over the gas change events to see the others ..
but the problem with the "TankItem" widget is that it does its own
model, and it has thrown away the dive and the dive computer
information. It just doesn't even know. It only knows what cylinders
there are, and the plot_info. And it just used to look at the sensor
number in the plot_info, and be done with that. That number no longer
exists.
- I have tested it, and I think the code is better, but hey, it's a
fairly large patch to some of the more complex code in our code base.
That "interpolate missing pressure fields" code really isn't pretty. It
may be prettier, but..
Anyway, without further ado, here's the patch. No sign-off yet, because I
do think people should look and comment. But I think the patch is fine,
and I'll fix anythign that anybody can find, *except* for that TankItem
thing that I will refuse to touch. That class is ugly. It needs to have
access to the actual dive.
Note how it actually does remove more lines than it adds, and that's
despite added comments etc. The code really is simpler, but there may be
cases in there that need more work.
Known missing pieces that don't currently take advantage of concurrent
cylinder pressure data:
- the momentary SAC rate coloring for dives will need more work
- dive merging (but we expect to generally normally not merge dive
computers, which is the main source of sensor data)
- actually taking advantage of different sensor data from different
dive computers
But most of all: Testing. Lots and lots of testing to find all the
corner cases.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-27 17:17:05 +00:00
|
|
|
|
prev = cyl;
|
|
|
|
|
|
|
|
|
|
last[cyl] = sec;
|
|
|
|
|
if (!seen[cyl]) {
|
|
|
|
|
// The end time may be updated by a subsequent cylinder change
|
|
|
|
|
first[cyl] = sec;
|
|
|
|
|
seen[cyl] = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-17 01:35:03 +00:00
|
|
|
|
last[prev] = INT_MAX;
|
Profile support for multiple concurrent pressure sensors
This finally handles multiple cylinder pressures, both overlapping and
consecutive, and it seems to work on the nasty cases I've thrown at it.
Want to just track five different cylinders all at once, without any
pesky gas switch events? Sure, you can do that. It will show five
different gas pressures for your five cylinders, and they will go down
as you breathe down the cylinders.
I obviously don't have any real data for that case, but I do have a test
file with five actual cylinders that all have samples over the whole
course of the dive. The end result looks messy as hell, but what did
you expect?
HOWEVER.
The only way to do this sanely was
- actually make the "struct plot_info" have all the cylinder pressures
(so no "sensor index and pressure" - every cylinder has a pressure for
every plot info entry)
This obviously makes the plot_info much bigger. We used to have
MAX_CYLINDERS be a fairly generous 8, which seems sane. The planning
code made that 8 be 20. That seems questionable. But whatever.
The good news is that the plot-info should hopefully get freed, and
only be allocated one dive at a time, so the fact that it is big and
nasty shouldn't be a scaling issue, though.
- the "populate_pressure_information()" function had to be rewritten
quite a bit. The good news is that it's actually simpler now, although
I would not go so far as to really call it simple. It's still
complicated and suble, but now it explicitly just does one cylinder at
a time.
It *used* to have this insanely complicated "keep track of the pressure
ranges for every cylinder at once". I just couldn't stand that model
and keep my sanity, so it now just tracks one cylinder at a time, and
doesn't have an array of live data, instead the caller will just call
it for each cylinder.
- get rid of some of our hackier stuff, like the code that populates the
plot_info data code with the currently selected cylinder number, and
clears out any other pressures. That obviously does *not* work when you
may not have a single primary cylinder any more.
Now, the above sounds like all good things. Yeah, it mostly is.
BUT.
There's a few big downsides from the above:
- there's no sane way to do this as a series of small changes.
The change to make the plot_info take an array of cylinder pressures
rather than the sensor+pressure model really isn't amenable to "fix up
one use at a time". When you switch over to the new data structure
model, you have to switch over to the new way of populating the
pressure ranges. The two just go hand in hand.
- Some of our code *depended* on the "sensor+pressure" model. I fixed all
the ones I could sanely fix. There was one particular case that I just
couldn't sanely fix, and I didn't care enough about it to do something
insane.
So the only _known_ breakage is the "TankItem" profile widget. That's
the bar at the bottom of the profile that shows which cylinder is in
use right now. You'd think that would be trivial to fix up, and yes it
would be - I could just use the regular model of
firstcyl = explicit_first_cylinder(dive, dc)
.. then iterate over the gas change events to see the others ..
but the problem with the "TankItem" widget is that it does its own
model, and it has thrown away the dive and the dive computer
information. It just doesn't even know. It only knows what cylinders
there are, and the plot_info. And it just used to look at the sensor
number in the plot_info, and be done with that. That number no longer
exists.
- I have tested it, and I think the code is better, but hey, it's a
fairly large patch to some of the more complex code in our code base.
That "interpolate missing pressure fields" code really isn't pretty. It
may be prettier, but..
Anyway, without further ado, here's the patch. No sign-off yet, because I
do think people should look and comment. But I think the patch is fine,
and I'll fix anythign that anybody can find, *except* for that TankItem
thing that I will refuse to touch. That class is ugly. It needs to have
access to the actual dive.
Note how it actually does remove more lines than it adds, and that's
despite added comments etc. The code really is simpler, but there may be
cases in there that need more work.
Known missing pieces that don't currently take advantage of concurrent
cylinder pressure data:
- the momentary SAC rate coloring for dives will need more work
- dive merging (but we expect to generally normally not merge dive
computers, which is the main source of sensor data)
- actually taking advantage of different sensor data from different
dive computers
But most of all: Testing. Lots and lots of testing to find all the
corner cases.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-27 17:17:05 +00:00
|
|
|
|
|
2017-11-17 01:57:37 +00:00
|
|
|
|
// Fill in "seen[]" array - mark cylinders we're not interested
|
|
|
|
|
// in as negative.
|
2024-05-25 06:16:57 +00:00
|
|
|
|
for (int i = 0; i < pi.nr_cylinders; i++) {
|
2024-06-25 05:43:32 +00:00
|
|
|
|
const cylinder_t *cyl = dive->get_cylinder(i);
|
2017-07-28 18:49:03 +00:00
|
|
|
|
int start = cyl->start.mbar;
|
|
|
|
|
int end = cyl->end.mbar;
|
|
|
|
|
|
2017-11-17 01:57:37 +00:00
|
|
|
|
/*
|
|
|
|
|
* Fundamentally uninteresting?
|
|
|
|
|
*
|
|
|
|
|
* A dive computer with no pressure data isn't interesting
|
|
|
|
|
* to plot pressures for even if we've seen it..
|
|
|
|
|
*/
|
|
|
|
|
if (!start || !end || start == end) {
|
|
|
|
|
seen[i] = -1;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If we've seen it, we're definitely interested */
|
|
|
|
|
if (seen[i])
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* If it's only mentioned by other dc's, ignore it */
|
2024-05-27 15:09:48 +00:00
|
|
|
|
for (auto &secondary: dive->dcs) {
|
2024-06-25 05:43:32 +00:00
|
|
|
|
if (dive->has_gaschange_event(&secondary, i)) {
|
2017-11-17 01:57:37 +00:00
|
|
|
|
seen[i] = -1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 06:16:57 +00:00
|
|
|
|
for (int i = 0; i < pi.nr_cylinders; i++) {
|
2017-11-17 01:57:37 +00:00
|
|
|
|
if (seen[i] >= 0) {
|
2024-06-25 05:43:32 +00:00
|
|
|
|
const cylinder_t *cyl = dive->get_cylinder(i);
|
2017-11-17 01:57:37 +00:00
|
|
|
|
|
|
|
|
|
add_plot_pressure(pi, first[i], i, cyl->start);
|
|
|
|
|
add_plot_pressure(pi, last[i], i, cyl->end);
|
Profile support for multiple concurrent pressure sensors
This finally handles multiple cylinder pressures, both overlapping and
consecutive, and it seems to work on the nasty cases I've thrown at it.
Want to just track five different cylinders all at once, without any
pesky gas switch events? Sure, you can do that. It will show five
different gas pressures for your five cylinders, and they will go down
as you breathe down the cylinders.
I obviously don't have any real data for that case, but I do have a test
file with five actual cylinders that all have samples over the whole
course of the dive. The end result looks messy as hell, but what did
you expect?
HOWEVER.
The only way to do this sanely was
- actually make the "struct plot_info" have all the cylinder pressures
(so no "sensor index and pressure" - every cylinder has a pressure for
every plot info entry)
This obviously makes the plot_info much bigger. We used to have
MAX_CYLINDERS be a fairly generous 8, which seems sane. The planning
code made that 8 be 20. That seems questionable. But whatever.
The good news is that the plot-info should hopefully get freed, and
only be allocated one dive at a time, so the fact that it is big and
nasty shouldn't be a scaling issue, though.
- the "populate_pressure_information()" function had to be rewritten
quite a bit. The good news is that it's actually simpler now, although
I would not go so far as to really call it simple. It's still
complicated and suble, but now it explicitly just does one cylinder at
a time.
It *used* to have this insanely complicated "keep track of the pressure
ranges for every cylinder at once". I just couldn't stand that model
and keep my sanity, so it now just tracks one cylinder at a time, and
doesn't have an array of live data, instead the caller will just call
it for each cylinder.
- get rid of some of our hackier stuff, like the code that populates the
plot_info data code with the currently selected cylinder number, and
clears out any other pressures. That obviously does *not* work when you
may not have a single primary cylinder any more.
Now, the above sounds like all good things. Yeah, it mostly is.
BUT.
There's a few big downsides from the above:
- there's no sane way to do this as a series of small changes.
The change to make the plot_info take an array of cylinder pressures
rather than the sensor+pressure model really isn't amenable to "fix up
one use at a time". When you switch over to the new data structure
model, you have to switch over to the new way of populating the
pressure ranges. The two just go hand in hand.
- Some of our code *depended* on the "sensor+pressure" model. I fixed all
the ones I could sanely fix. There was one particular case that I just
couldn't sanely fix, and I didn't care enough about it to do something
insane.
So the only _known_ breakage is the "TankItem" profile widget. That's
the bar at the bottom of the profile that shows which cylinder is in
use right now. You'd think that would be trivial to fix up, and yes it
would be - I could just use the regular model of
firstcyl = explicit_first_cylinder(dive, dc)
.. then iterate over the gas change events to see the others ..
but the problem with the "TankItem" widget is that it does its own
model, and it has thrown away the dive and the dive computer
information. It just doesn't even know. It only knows what cylinders
there are, and the plot_info. And it just used to look at the sensor
number in the plot_info, and be done with that. That number no longer
exists.
- I have tested it, and I think the code is better, but hey, it's a
fairly large patch to some of the more complex code in our code base.
That "interpolate missing pressure fields" code really isn't pretty. It
may be prettier, but..
Anyway, without further ado, here's the patch. No sign-off yet, because I
do think people should look and comment. But I think the patch is fine,
and I'll fix anythign that anybody can find, *except* for that TankItem
thing that I will refuse to touch. That class is ugly. It needs to have
access to the actual dive.
Note how it actually does remove more lines than it adds, and that's
despite added comments etc. The code really is simpler, but there may be
cases in there that need more work.
Known missing pieces that don't currently take advantage of concurrent
cylinder pressure data:
- the momentary SAC rate coloring for dives will need more work
- dive merging (but we expect to generally normally not merge dive
computers, which is the main source of sensor data)
- actually taking advantage of different sensor data from different
dive computers
But most of all: Testing. Lots and lots of testing to find all the
corner cases.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-27 17:17:05 +00:00
|
|
|
|
}
|
2013-01-07 00:09:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Here, we should try to walk through all the dive computers,
|
|
|
|
|
* and try to see if they have sensor data different from the
|
2022-03-20 15:54:15 +00:00
|
|
|
|
* current dive computer (dc).
|
2013-01-07 00:09:48 +00:00
|
|
|
|
*/
|
2024-05-27 15:09:48 +00:00
|
|
|
|
for (auto &secondary: dive->dcs) {
|
|
|
|
|
if (&secondary == dc)
|
2013-01-07 00:09:48 +00:00
|
|
|
|
continue;
|
2022-03-20 15:54:15 +00:00
|
|
|
|
populate_secondary_sensor_data(secondary, pi);
|
2024-05-27 15:09:48 +00:00
|
|
|
|
}
|
2013-01-07 00:09:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-12 22:09:59 +00:00
|
|
|
|
/* calculate DECO STOP / TTS / NDL */
|
2024-05-03 16:51:03 +00:00
|
|
|
|
static void calculate_ndl_tts(struct deco_state *ds, const struct dive *dive, struct plot_data &entry, struct gasmix gasmix,
|
2021-02-12 16:39:46 +00:00
|
|
|
|
double surface_pressure, enum divemode_t divemode, bool in_planner)
|
2014-02-28 04:09:57 +00:00
|
|
|
|
{
|
2019-03-19 15:22:51 +00:00
|
|
|
|
/* should this be configurable? */
|
2013-11-12 22:09:59 +00:00
|
|
|
|
/* ascent speed up to first deco stop */
|
|
|
|
|
const int ascent_s_per_step = 1;
|
|
|
|
|
const int ascent_s_per_deco_step = 1;
|
|
|
|
|
/* how long time steps in deco calculations? */
|
2014-06-04 18:05:22 +00:00
|
|
|
|
const int time_stepsize = 60;
|
2022-05-06 20:33:57 +00:00
|
|
|
|
const int deco_stepsize = M_OR_FT(3, 10);
|
2013-11-12 22:09:59 +00:00
|
|
|
|
/* at what depth is the current deco-step? */
|
2024-03-10 22:11:23 +00:00
|
|
|
|
int next_stop = round_up(deco_allowed_depth(
|
2024-06-20 20:09:47 +00:00
|
|
|
|
tissue_tolerance_calc(ds, dive, dive->depth_to_bar(entry.depth), in_planner),
|
2017-11-22 19:42:33 +00:00
|
|
|
|
surface_pressure, dive, 1), deco_stepsize);
|
2024-05-03 16:51:03 +00:00
|
|
|
|
int ascent_depth = entry.depth;
|
2013-11-12 22:09:59 +00:00
|
|
|
|
/* at what time should we give up and say that we got enuff NDL? */
|
2024-05-03 16:51:03 +00:00
|
|
|
|
/* If iterating through a dive, entry.tts_calc needs to be reset */
|
|
|
|
|
entry.tts_calc = 0;
|
2013-11-12 22:09:59 +00:00
|
|
|
|
|
|
|
|
|
/* If we don't have a ceiling yet, calculate ndl. Don't try to calculate
|
|
|
|
|
* a ndl for lower values than 3m it would take forever */
|
|
|
|
|
if (next_stop == 0) {
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (entry.depth < 3000) {
|
|
|
|
|
entry.ndl = MAX_PROFILE_DECO;
|
2013-11-12 22:09:59 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
/* stop if the ndl is above max_ndl seconds, and call it plenty of time */
|
2024-05-03 16:51:03 +00:00
|
|
|
|
while (entry.ndl_calc < MAX_PROFILE_DECO &&
|
2024-06-20 20:09:47 +00:00
|
|
|
|
deco_allowed_depth(tissue_tolerance_calc(ds, dive, dive->depth_to_bar(entry.depth), in_planner),
|
2017-11-22 19:42:33 +00:00
|
|
|
|
surface_pressure, dive, 1) <= 0
|
|
|
|
|
) {
|
2024-05-03 16:51:03 +00:00
|
|
|
|
entry.ndl_calc += time_stepsize;
|
2024-06-20 20:09:47 +00:00
|
|
|
|
add_segment(ds, dive->depth_to_bar(entry.depth),
|
2024-05-03 16:51:03 +00:00
|
|
|
|
gasmix, time_stepsize, entry.o2pressure.mbar, divemode, prefs.bottomsac, in_planner);
|
2013-11-12 22:09:59 +00:00
|
|
|
|
}
|
|
|
|
|
/* we don't need to calculate anything else */
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-13 18:20:09 +00:00
|
|
|
|
/* We are in deco */
|
2024-05-03 16:51:03 +00:00
|
|
|
|
entry.in_deco_calc = true;
|
2013-11-13 18:20:09 +00:00
|
|
|
|
|
2013-11-12 22:09:59 +00:00
|
|
|
|
/* Add segments for movement to stopdepth */
|
2024-05-03 16:51:03 +00:00
|
|
|
|
for (; ascent_depth > next_stop; ascent_depth -= ascent_s_per_step * ascent_velocity(ascent_depth, entry.running_sum / entry.sec, 0), entry.tts_calc += ascent_s_per_step) {
|
2024-06-20 20:09:47 +00:00
|
|
|
|
add_segment(ds, dive->depth_to_bar(ascent_depth),
|
2024-05-03 16:51:03 +00:00
|
|
|
|
gasmix, ascent_s_per_step, entry.o2pressure.mbar, divemode, prefs.decosac, in_planner);
|
2024-06-20 20:09:47 +00:00
|
|
|
|
next_stop = round_up(deco_allowed_depth(tissue_tolerance_calc(ds, dive, dive->depth_to_bar(ascent_depth), in_planner),
|
2017-11-22 19:42:33 +00:00
|
|
|
|
surface_pressure, dive, 1), deco_stepsize);
|
2013-11-12 22:09:59 +00:00
|
|
|
|
}
|
|
|
|
|
ascent_depth = next_stop;
|
|
|
|
|
|
|
|
|
|
/* And how long is the current deco-step? */
|
2024-05-03 16:51:03 +00:00
|
|
|
|
entry.stoptime_calc = 0;
|
|
|
|
|
entry.stopdepth_calc = next_stop;
|
2013-11-12 22:09:59 +00:00
|
|
|
|
next_stop -= deco_stepsize;
|
|
|
|
|
|
|
|
|
|
/* And how long is the total TTS */
|
2014-02-28 04:09:57 +00:00
|
|
|
|
while (next_stop >= 0) {
|
2013-11-12 22:09:59 +00:00
|
|
|
|
/* save the time for the first stop to show in the graph */
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (ascent_depth == entry.stopdepth_calc)
|
|
|
|
|
entry.stoptime_calc += time_stepsize;
|
2013-11-12 22:09:59 +00:00
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
entry.tts_calc += time_stepsize;
|
|
|
|
|
if (entry.tts_calc > MAX_PROFILE_DECO)
|
2015-10-12 20:34:15 +00:00
|
|
|
|
break;
|
2024-06-20 20:09:47 +00:00
|
|
|
|
add_segment(ds, dive->depth_to_bar(ascent_depth),
|
2024-05-03 16:51:03 +00:00
|
|
|
|
gasmix, time_stepsize, entry.o2pressure.mbar, divemode, prefs.decosac, in_planner);
|
2013-11-12 22:09:59 +00:00
|
|
|
|
|
2024-06-20 20:09:47 +00:00
|
|
|
|
if (deco_allowed_depth(tissue_tolerance_calc(ds, dive, dive->depth_to_bar(ascent_depth), in_planner), surface_pressure, dive, 1) <= next_stop) {
|
2013-11-12 22:09:59 +00:00
|
|
|
|
/* move to the next stop and add the travel between stops */
|
2024-05-03 16:51:03 +00:00
|
|
|
|
for (; ascent_depth > next_stop; ascent_depth -= ascent_s_per_deco_step * ascent_velocity(ascent_depth, entry.running_sum / entry.sec, 0), entry.tts_calc += ascent_s_per_deco_step)
|
2024-06-20 20:09:47 +00:00
|
|
|
|
add_segment(ds, dive->depth_to_bar(ascent_depth),
|
2024-05-03 16:51:03 +00:00
|
|
|
|
gasmix, ascent_s_per_deco_step, entry.o2pressure.mbar, divemode, prefs.decosac, in_planner);
|
2013-11-12 22:09:59 +00:00
|
|
|
|
ascent_depth = next_stop;
|
|
|
|
|
next_stop -= deco_stepsize;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Let's try to do some deco calculations.
|
|
|
|
|
*/
|
2021-01-08 21:37:24 +00:00
|
|
|
|
static void calculate_deco_information(struct deco_state *ds, const struct deco_state *planner_ds, const struct dive *dive,
|
2024-05-03 16:51:03 +00:00
|
|
|
|
const struct divecomputer *dc, struct plot_info &pi)
|
2013-01-07 00:09:48 +00:00
|
|
|
|
{
|
2017-11-02 20:32:28 +00:00
|
|
|
|
int i, count_iteration = 0;
|
2024-06-30 15:26:12 +00:00
|
|
|
|
double surface_pressure = (dc->surface_pressure.mbar ? dc->surface_pressure.mbar : dive->get_surface_pressure().mbar) / 1000.0;
|
2015-10-25 00:26:15 +00:00
|
|
|
|
bool first_iteration = true;
|
2017-10-26 23:06:11 +00:00
|
|
|
|
int prev_deco_time = 10000000, time_deep_ceiling = 0;
|
2021-02-12 16:39:46 +00:00
|
|
|
|
bool in_planner = planner_ds != NULL;
|
2018-04-03 17:30:27 +00:00
|
|
|
|
|
2021-02-26 11:42:27 +00:00
|
|
|
|
if (!in_planner) {
|
2017-11-22 19:42:33 +00:00
|
|
|
|
ds->deco_time = 0;
|
2019-11-15 08:57:17 +00:00
|
|
|
|
ds->first_ceiling_pressure.mbar = 0;
|
2017-11-24 13:17:01 +00:00
|
|
|
|
} else {
|
|
|
|
|
ds->deco_time = planner_ds->deco_time;
|
|
|
|
|
ds->first_ceiling_pressure = planner_ds->first_ceiling_pressure;
|
|
|
|
|
}
|
2024-03-07 18:08:22 +00:00
|
|
|
|
deco_state_cache cache_data_initial;
|
2017-08-29 09:41:30 +00:00
|
|
|
|
lock_planner();
|
2015-10-25 00:26:15 +00:00
|
|
|
|
/* For VPM-B outside the planner, cache the initial deco state for CVA iterations */
|
2021-02-12 17:19:24 +00:00
|
|
|
|
if (decoMode(in_planner) == VPMB) {
|
2024-03-07 18:08:22 +00:00
|
|
|
|
cache_data_initial.cache(ds);
|
2017-10-26 23:06:11 +00:00
|
|
|
|
}
|
2015-10-25 00:26:15 +00:00
|
|
|
|
/* For VPM-B outside the planner, iterate until deco time converges (usually one or two iterations after the initial)
|
|
|
|
|
* Set maximum number of iterations to 10 just in case */
|
2018-04-03 17:30:27 +00:00
|
|
|
|
|
2017-11-22 19:42:33 +00:00
|
|
|
|
while ((abs(prev_deco_time - ds->deco_time) >= 30) && (count_iteration < 10)) {
|
2017-12-19 22:35:57 +00:00
|
|
|
|
int last_ndl_tts_calc_time = 0, first_ceiling = 0, current_ceiling, last_ceiling = 0, final_tts = 0 , time_clear_ceiling = 0;
|
2021-02-12 17:19:24 +00:00
|
|
|
|
if (decoMode(in_planner) == VPMB)
|
2024-06-20 20:09:47 +00:00
|
|
|
|
ds->first_ceiling_pressure.mbar = dive->depth_to_mbar(first_ceiling);
|
2017-07-28 17:35:25 +00:00
|
|
|
|
|
2024-05-25 06:16:57 +00:00
|
|
|
|
gasmix_loop loop(*dive, *dc);
|
|
|
|
|
divemode_loop loop_d(*dc);
|
2024-05-03 16:51:03 +00:00
|
|
|
|
for (i = 1; i < pi.nr; i++) {
|
|
|
|
|
struct plot_data &entry = pi.entry[i];
|
|
|
|
|
struct plot_data &prev = pi.entry[i - 1];
|
|
|
|
|
int j, t0 = prev.sec, t1 = entry.sec;
|
2021-01-09 16:28:23 +00:00
|
|
|
|
int time_stepsize = 20, max_ceiling = -1;
|
2015-10-25 00:26:15 +00:00
|
|
|
|
|
2024-05-25 06:16:57 +00:00
|
|
|
|
divemode_t current_divemode = loop_d.next(entry.sec);
|
|
|
|
|
struct gasmix gasmix = loop.next(t1);
|
2024-06-20 20:09:47 +00:00
|
|
|
|
entry.ambpressure = dive->depth_to_bar(entry.depth);
|
2024-05-03 16:51:03 +00:00
|
|
|
|
entry.gfline = get_gf(ds, entry.ambpressure, dive) * (100.0 - AMB_PERCENTAGE) + AMB_PERCENTAGE;
|
2015-10-25 00:26:15 +00:00
|
|
|
|
if (t0 > t1) {
|
2024-03-24 20:03:08 +00:00
|
|
|
|
report_info("non-monotonous dive stamps %d %d", t0, t1);
|
2015-10-25 00:26:15 +00:00
|
|
|
|
int xchg = t1;
|
|
|
|
|
t1 = t0;
|
|
|
|
|
t0 = xchg;
|
|
|
|
|
}
|
|
|
|
|
if (t0 != t1 && t1 - t0 < time_stepsize)
|
|
|
|
|
time_stepsize = t1 - t0;
|
|
|
|
|
for (j = t0 + time_stepsize; j <= t1; j += time_stepsize) {
|
2024-05-03 16:51:03 +00:00
|
|
|
|
int depth = interpolate(prev.depth, entry.depth, j - t0, t1 - t0);
|
2024-06-20 20:09:47 +00:00
|
|
|
|
add_segment(ds, dive->depth_to_bar(depth),
|
2024-05-03 16:51:03 +00:00
|
|
|
|
gasmix, time_stepsize, entry.o2pressure.mbar, current_divemode, entry.sac, in_planner);
|
|
|
|
|
entry.icd_warning = ds->icd_warning;
|
2015-10-25 00:26:15 +00:00
|
|
|
|
if ((t1 - j < time_stepsize) && (j < t1))
|
|
|
|
|
time_stepsize = t1 - j;
|
|
|
|
|
}
|
|
|
|
|
if (t0 == t1) {
|
2024-05-03 16:51:03 +00:00
|
|
|
|
entry.ceiling = prev.ceiling;
|
2015-10-25 00:26:15 +00:00
|
|
|
|
} else {
|
|
|
|
|
/* Keep updating the VPM-B gradients until the start of the ascent phase of the dive. */
|
2021-02-12 17:19:24 +00:00
|
|
|
|
if (decoMode(in_planner) == VPMB && last_ceiling >= first_ceiling && first_iteration == true) {
|
2017-11-22 19:42:33 +00:00
|
|
|
|
nuclear_regeneration(ds, t1);
|
|
|
|
|
vpmb_start_gradient(ds);
|
2017-10-26 23:06:11 +00:00
|
|
|
|
/* For CVA iterations, calculate next gradient */
|
2021-02-26 11:42:27 +00:00
|
|
|
|
if (!first_iteration || in_planner)
|
2021-02-12 16:47:52 +00:00
|
|
|
|
vpmb_next_gradient(ds, ds->deco_time, surface_pressure / 1000.0, in_planner);
|
2015-10-25 00:26:15 +00:00
|
|
|
|
}
|
2024-06-20 20:09:47 +00:00
|
|
|
|
entry.ceiling = deco_allowed_depth(tissue_tolerance_calc(ds, dive, dive->depth_to_bar(entry.depth), in_planner), surface_pressure, dive, !prefs.calcceiling3m);
|
2016-04-07 13:06:44 +00:00
|
|
|
|
if (prefs.calcceiling3m)
|
2024-06-20 20:09:47 +00:00
|
|
|
|
current_ceiling = deco_allowed_depth(tissue_tolerance_calc(ds, dive, dive->depth_to_bar(entry.depth), in_planner), surface_pressure, dive, true);
|
2016-04-07 13:06:44 +00:00
|
|
|
|
else
|
2024-05-03 16:51:03 +00:00
|
|
|
|
current_ceiling = entry.ceiling;
|
2017-10-03 20:57:14 +00:00
|
|
|
|
last_ceiling = current_ceiling;
|
2017-10-26 23:06:11 +00:00
|
|
|
|
/* If using VPM-B, take first_ceiling_pressure as the deepest ceiling */
|
2021-02-12 17:19:24 +00:00
|
|
|
|
if (decoMode(in_planner) == VPMB) {
|
2017-10-26 23:06:11 +00:00
|
|
|
|
if (current_ceiling >= first_ceiling ||
|
2024-05-03 16:51:03 +00:00
|
|
|
|
(time_deep_ceiling == t0 && entry.depth == prev.depth)) {
|
2016-04-07 13:06:44 +00:00
|
|
|
|
time_deep_ceiling = t1;
|
|
|
|
|
first_ceiling = current_ceiling;
|
2024-06-20 20:09:47 +00:00
|
|
|
|
ds->first_ceiling_pressure.mbar = dive->depth_to_mbar(first_ceiling);
|
2016-04-07 13:06:44 +00:00
|
|
|
|
if (first_iteration) {
|
2017-11-22 19:42:33 +00:00
|
|
|
|
nuclear_regeneration(ds, t1);
|
|
|
|
|
vpmb_start_gradient(ds);
|
2017-10-29 06:47:09 +00:00
|
|
|
|
/* For CVA calculations, deco time = dive time remaining is a good guess,
|
|
|
|
|
but we want to over-estimate deco_time for the first iteration so it
|
|
|
|
|
converges correctly, so add 30min*/
|
2021-02-26 11:42:27 +00:00
|
|
|
|
if (!in_planner)
|
2024-05-03 16:51:03 +00:00
|
|
|
|
ds->deco_time = pi.maxtime - t1 + 1800;
|
2021-02-12 16:47:52 +00:00
|
|
|
|
vpmb_next_gradient(ds, ds->deco_time, surface_pressure / 1000.0, in_planner);
|
2016-04-07 13:06:44 +00:00
|
|
|
|
}
|
2015-10-25 00:26:15 +00:00
|
|
|
|
}
|
|
|
|
|
// Use the point where the ceiling clears as the end of deco phase for CVA calculations
|
2016-04-07 13:06:44 +00:00
|
|
|
|
if (current_ceiling > 0)
|
2015-10-25 00:26:15 +00:00
|
|
|
|
time_clear_ceiling = 0;
|
2017-11-03 07:48:14 +00:00
|
|
|
|
else if (time_clear_ceiling == 0 && t1 > time_deep_ceiling)
|
2015-10-25 00:26:15 +00:00
|
|
|
|
time_clear_ceiling = t1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-03 16:51:03 +00:00
|
|
|
|
entry.surface_gf = 0.0;
|
|
|
|
|
entry.current_gf = 0.0;
|
2015-10-25 00:26:15 +00:00
|
|
|
|
for (j = 0; j < 16; j++) {
|
2024-05-03 16:51:03 +00:00
|
|
|
|
double m_value = ds->buehlmann_inertgas_a[j] + entry.ambpressure / ds->buehlmann_inertgas_b[j];
|
2019-01-23 15:46:45 +00:00
|
|
|
|
double surface_m_value = ds->buehlmann_inertgas_a[j] + surface_pressure / ds->buehlmann_inertgas_b[j];
|
2024-05-03 16:51:03 +00:00
|
|
|
|
entry.ceilings[j] = deco_allowed_depth(ds->tolerated_by_tissue[j], surface_pressure, dive, 1);
|
|
|
|
|
if (entry.ceilings[j] > max_ceiling)
|
|
|
|
|
max_ceiling = entry.ceilings[j];
|
|
|
|
|
double current_gf = (ds->tissue_inertgas_saturation[j] - entry.ambpressure) / (m_value - entry.ambpressure);
|
|
|
|
|
entry.percentages[j] = ds->tissue_inertgas_saturation[j] < entry.ambpressure ?
|
|
|
|
|
lrint(ds->tissue_inertgas_saturation[j] / entry.ambpressure * AMB_PERCENTAGE) :
|
2019-11-28 09:37:44 +00:00
|
|
|
|
lrint(AMB_PERCENTAGE + current_gf * (100.0 - AMB_PERCENTAGE));
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (current_gf > entry.current_gf)
|
|
|
|
|
entry.current_gf = current_gf;
|
2019-01-23 15:46:45 +00:00
|
|
|
|
double surface_gf = 100.0 * (ds->tissue_inertgas_saturation[j] - surface_pressure) / (surface_m_value - surface_pressure);
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (surface_gf > entry.surface_gf)
|
|
|
|
|
entry.surface_gf = surface_gf;
|
2015-10-25 00:26:15 +00:00
|
|
|
|
}
|
2013-11-12 22:09:59 +00:00
|
|
|
|
|
2021-01-09 16:28:23 +00:00
|
|
|
|
// In the planner, if the ceiling is violated, add an event.
|
|
|
|
|
// TODO: This *really* shouldn't be done here. This is a contract
|
|
|
|
|
// between the planner and the profile that the planner uses a dive
|
|
|
|
|
// that can be trampled upon. But ultimately, the ceiling-violation
|
|
|
|
|
// marker should be handled differently!
|
|
|
|
|
// Don't scream if we violate the ceiling by a few cm.
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (in_planner && !pi.waypoint_above_ceiling &&
|
|
|
|
|
entry.depth < max_ceiling - 100 && entry.sec > 0) {
|
2021-01-09 16:28:23 +00:00
|
|
|
|
struct dive *non_const_dive = (struct dive *)dive; // cast away const!
|
2024-05-27 15:09:48 +00:00
|
|
|
|
add_event(&non_const_dive->dcs[0], entry.sec, SAMPLE_EVENT_CEILING, -1, max_ceiling / 1000,
|
2021-01-09 16:28:23 +00:00
|
|
|
|
translate("gettextFromC", "planned waypoint above ceiling"));
|
2024-05-03 16:51:03 +00:00
|
|
|
|
pi.waypoint_above_ceiling = true;
|
2021-01-09 16:28:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-25 00:26:15 +00:00
|
|
|
|
/* should we do more calculations?
|
|
|
|
|
* We don't for print-mode because this info doesn't show up there
|
|
|
|
|
* If the ceiling hasn't cleared by the last data point, we need tts for VPM-B CVA calculation
|
|
|
|
|
* It is not necessary to do these calculation on the first VPMB iteration, except for the last data point */
|
2021-02-26 11:42:27 +00:00
|
|
|
|
if ((prefs.calcndltts && (decoMode(in_planner) != VPMB || in_planner || !first_iteration)) ||
|
2024-05-03 16:51:03 +00:00
|
|
|
|
(decoMode(in_planner) == VPMB && !in_planner && i == pi.nr - 1)) {
|
2015-10-25 00:26:15 +00:00
|
|
|
|
/* only calculate ndl/tts on every 30 seconds */
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if ((entry.sec - last_ndl_tts_calc_time) < 30 && i != pi.nr - 1) {
|
|
|
|
|
struct plot_data &prev_entry = pi.entry[i - 1];
|
|
|
|
|
entry.stoptime_calc = prev_entry.stoptime_calc;
|
|
|
|
|
entry.stopdepth_calc = prev_entry.stopdepth_calc;
|
|
|
|
|
entry.tts_calc = prev_entry.tts_calc;
|
|
|
|
|
entry.ndl_calc = prev_entry.ndl_calc;
|
2015-10-25 00:26:15 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2024-05-03 16:51:03 +00:00
|
|
|
|
last_ndl_tts_calc_time = entry.sec;
|
2015-10-25 00:26:15 +00:00
|
|
|
|
|
|
|
|
|
/* We are going to mess up deco state, so store it for later restore */
|
2024-03-07 18:08:22 +00:00
|
|
|
|
deco_state_cache cache_data;
|
|
|
|
|
cache_data.cache(ds);
|
2021-02-12 16:39:46 +00:00
|
|
|
|
calculate_ndl_tts(ds, dive, entry, gasmix, surface_pressure, current_divemode, in_planner);
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (decoMode(in_planner) == VPMB && !in_planner && i == pi.nr - 1)
|
|
|
|
|
final_tts = entry.tts_calc;
|
2015-10-25 00:26:15 +00:00
|
|
|
|
/* Restore "real" deco state for next real time step */
|
2024-03-07 18:08:22 +00:00
|
|
|
|
cache_data.restore(ds, decoMode(in_planner) == VPMB);
|
2014-06-29 18:23:00 +00:00
|
|
|
|
}
|
2015-10-25 00:26:15 +00:00
|
|
|
|
}
|
2021-02-26 11:42:27 +00:00
|
|
|
|
if (decoMode(in_planner) == VPMB && !in_planner) {
|
2017-11-02 21:01:52 +00:00
|
|
|
|
int this_deco_time;
|
2017-11-22 19:42:33 +00:00
|
|
|
|
prev_deco_time = ds->deco_time;
|
2015-10-25 00:26:15 +00:00
|
|
|
|
// Do we need to update deco_time?
|
|
|
|
|
if (final_tts > 0)
|
2017-11-22 19:42:33 +00:00
|
|
|
|
ds->deco_time = last_ndl_tts_calc_time + final_tts - time_deep_ceiling;
|
2015-10-25 00:26:15 +00:00
|
|
|
|
else if (time_clear_ceiling > 0)
|
2017-11-02 08:34:45 +00:00
|
|
|
|
/* Consistent with planner, deco_time ends after ascending (20s @9m/min from 3m)
|
2017-11-02 10:26:30 +00:00
|
|
|
|
* at end of whole minute after clearing ceiling. The deepest ceiling when planning a dive
|
|
|
|
|
* comes typically 10-60s after the end of the bottom time, so add 20s to the calculated
|
|
|
|
|
* deco time. */
|
2024-03-10 22:11:23 +00:00
|
|
|
|
ds->deco_time = round_up(time_clear_ceiling - time_deep_ceiling + 20, 60) + 20;
|
2021-02-12 16:47:52 +00:00
|
|
|
|
vpmb_next_gradient(ds, ds->deco_time, surface_pressure / 1000.0, in_planner);
|
2015-10-25 00:26:15 +00:00
|
|
|
|
final_tts = 0;
|
|
|
|
|
last_ndl_tts_calc_time = 0;
|
|
|
|
|
first_ceiling = 0;
|
|
|
|
|
first_iteration = false;
|
|
|
|
|
count_iteration ++;
|
2017-11-22 19:42:33 +00:00
|
|
|
|
this_deco_time = ds->deco_time;
|
2024-03-07 18:08:22 +00:00
|
|
|
|
cache_data_initial.restore(ds, true);
|
2017-11-22 19:42:33 +00:00
|
|
|
|
ds->deco_time = this_deco_time;
|
2015-10-25 00:26:15 +00:00
|
|
|
|
} else {
|
2017-10-26 23:06:11 +00:00
|
|
|
|
// With Buhlmann iterating isn't needed. This makes the while condition false.
|
2017-11-22 19:42:33 +00:00
|
|
|
|
prev_deco_time = ds->deco_time = 0;
|
2013-11-12 22:09:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-03 17:30:27 +00:00
|
|
|
|
|
2013-11-12 22:09:59 +00:00
|
|
|
|
#if DECO_CALC_DEBUG & 1
|
2018-02-11 21:23:59 +00:00
|
|
|
|
dump_tissues(ds);
|
2013-11-12 22:09:59 +00:00
|
|
|
|
#endif
|
2017-08-29 09:41:30 +00:00
|
|
|
|
unlock_planner();
|
2013-11-12 22:09:59 +00:00
|
|
|
|
}
|
2021-01-05 01:49:33 +00:00
|
|
|
|
|
2024-01-20 23:35:44 +00:00
|
|
|
|
/* Sort the o2 pressure values. There are so few that a simple bubble sort
|
|
|
|
|
* will do */
|
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
void sort_o2_pressures(int *sensorn, int np, const struct plot_data &entry)
|
2024-01-20 23:35:44 +00:00
|
|
|
|
{
|
|
|
|
|
int smallest, position, old;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < np - 1; i++) {
|
|
|
|
|
position = i;
|
2024-05-03 16:51:03 +00:00
|
|
|
|
smallest = entry.o2sensor[sensorn[i]].mbar;
|
2024-01-20 23:35:44 +00:00
|
|
|
|
for (int j = i+1; j < np; j++)
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (entry.o2sensor[sensorn[j]].mbar < smallest) {
|
2024-01-20 23:35:44 +00:00
|
|
|
|
position = j;
|
2024-05-03 16:51:03 +00:00
|
|
|
|
smallest = entry.o2sensor[sensorn[j]].mbar;
|
2024-01-20 23:35:44 +00:00
|
|
|
|
}
|
|
|
|
|
old = sensorn[i];
|
|
|
|
|
sensorn[i] = position;
|
|
|
|
|
sensorn[position] = old;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-10-13 19:19:21 +00:00
|
|
|
|
|
|
|
|
|
/* Function calculate_ccr_po2: This function takes information from one plot_data structure (i.e. one point on
|
|
|
|
|
* the dive profile), containing the oxygen sensor values of a CCR system and, for that plot_data structure,
|
2024-01-20 23:35:44 +00:00
|
|
|
|
* calculates the po2 value from the sensor data. If there are at least 3 sensors, sensors are voted out until
|
|
|
|
|
* their span is within diff_limit.
|
2014-10-13 19:19:21 +00:00
|
|
|
|
*/
|
2024-05-03 16:51:03 +00:00
|
|
|
|
static int calculate_ccr_po2(struct plot_data &entry, const struct divecomputer *dc)
|
2014-12-29 04:56:58 +00:00
|
|
|
|
{
|
2024-01-20 23:35:44 +00:00
|
|
|
|
int sump = 0, minp = 0, maxp = 0;
|
|
|
|
|
int sensorn[MAX_O2_SENSORS];
|
2014-10-25 09:42:33 +00:00
|
|
|
|
int i, np = 0;
|
2014-10-14 08:46:40 +00:00
|
|
|
|
|
2024-01-20 23:35:44 +00:00
|
|
|
|
for (i = 0; i < dc->no_o2sensors && i < MAX_O2_SENSORS; i++)
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (entry.o2sensor[i].mbar) { // Valid reading
|
2024-01-20 23:35:44 +00:00
|
|
|
|
sensorn[np++] = i;
|
2024-05-03 16:51:03 +00:00
|
|
|
|
sump += entry.o2sensor[i].mbar;
|
2014-10-13 19:19:21 +00:00
|
|
|
|
}
|
2024-01-20 23:35:44 +00:00
|
|
|
|
if (np == 0)
|
2024-05-03 16:51:03 +00:00
|
|
|
|
return entry.o2pressure.mbar;
|
2024-01-20 23:35:44 +00:00
|
|
|
|
else if (np == 1)
|
2024-05-03 16:51:03 +00:00
|
|
|
|
return entry.o2sensor[sensorn[0]].mbar;
|
2024-01-20 23:35:44 +00:00
|
|
|
|
|
|
|
|
|
maxp = np - 1;
|
|
|
|
|
sort_o2_pressures(sensorn, np, entry);
|
|
|
|
|
|
|
|
|
|
// This is the Shearwater voting logic: If there are still at least three sensors and one
|
|
|
|
|
// differs by more than 20% from the closest it is voted out.
|
|
|
|
|
while (maxp - minp > 1) {
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (entry.o2sensor[sensorn[minp + 1]].mbar - entry.o2sensor[sensorn[minp]].mbar >
|
2024-01-20 23:35:44 +00:00
|
|
|
|
sump / (maxp - minp + 1) / 5) {
|
2024-05-03 16:51:03 +00:00
|
|
|
|
sump -= entry.o2sensor[sensorn[minp]].mbar;
|
2024-01-20 23:35:44 +00:00
|
|
|
|
++minp;
|
|
|
|
|
continue;
|
2014-10-13 19:19:21 +00:00
|
|
|
|
}
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (entry.o2sensor[sensorn[maxp]].mbar - entry.o2sensor[sensorn[maxp - 1]].mbar >
|
2024-01-20 23:35:44 +00:00
|
|
|
|
sump / (maxp - minp +1) / 5) {
|
2024-05-03 16:51:03 +00:00
|
|
|
|
sump -= entry.o2sensor[sensorn[maxp]].mbar;
|
2024-01-20 23:35:44 +00:00
|
|
|
|
--maxp;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2014-10-14 08:46:40 +00:00
|
|
|
|
}
|
2024-01-20 23:35:44 +00:00
|
|
|
|
|
|
|
|
|
return sump / (maxp - minp + 1);
|
|
|
|
|
|
2014-10-13 19:19:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
static double gas_density(const struct gas_pressures &pressures)
|
2022-10-28 20:17:35 +00:00
|
|
|
|
{
|
2024-05-03 16:51:03 +00:00
|
|
|
|
return (pressures.o2 * O2_DENSITY + pressures.he * HE_DENSITY + pressures.n2 * N2_DENSITY) / 1000.0;
|
2022-10-28 20:17:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
static void calculate_gas_information_new(const struct dive *dive, const struct divecomputer *dc, struct plot_info &pi)
|
2014-01-27 17:14:42 +00:00
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
double amb_pressure;
|
|
|
|
|
|
2024-05-25 06:16:57 +00:00
|
|
|
|
gasmix_loop loop(*dive, *dc);
|
|
|
|
|
divemode_loop loop_d(*dc);
|
2024-05-03 16:51:03 +00:00
|
|
|
|
for (i = 1; i < pi.nr; i++) {
|
2021-12-03 13:59:36 +00:00
|
|
|
|
double fn2, fhe;
|
2024-05-03 16:51:03 +00:00
|
|
|
|
struct plot_data &entry = pi.entry[i];
|
|
|
|
|
|
2024-05-25 06:16:57 +00:00
|
|
|
|
auto gasmix = loop.next(entry.sec);
|
2024-06-20 20:09:47 +00:00
|
|
|
|
amb_pressure = dive->depth_to_bar(entry.depth);
|
2024-05-25 06:16:57 +00:00
|
|
|
|
divemode_t current_divemode = loop_d.next(entry.sec);
|
2024-05-05 04:54:30 +00:00
|
|
|
|
entry.pressures = fill_pressures(amb_pressure, gasmix, (current_divemode == OC) ? 0.0 : entry.o2pressure.mbar / 1000.0, current_divemode);
|
2024-05-03 16:51:03 +00:00
|
|
|
|
fn2 = 1000.0 * entry.pressures.n2 / amb_pressure;
|
|
|
|
|
fhe = 1000.0 * entry.pressures.he / amb_pressure;
|
2018-08-16 11:35:14 +00:00
|
|
|
|
if (dc->divemode == PSCR) { // OC pO2 is calulated for PSCR with or without external PO2 monitoring.
|
2024-05-25 06:16:57 +00:00
|
|
|
|
struct gasmix gasmix2 = loop.next(entry.sec);
|
2024-06-20 20:09:47 +00:00
|
|
|
|
entry.scr_OC_pO2.mbar = (int) dive->depth_to_mbar(entry.depth) * get_o2(gasmix2) / 1000;
|
2018-08-16 11:35:14 +00:00
|
|
|
|
}
|
2014-01-27 17:14:42 +00:00
|
|
|
|
|
|
|
|
|
/* Calculate MOD, EAD, END and EADD based on partial pressures calculated before
|
|
|
|
|
* so there is no difference in calculating between OC and CC
|
2014-06-22 14:41:44 +00:00
|
|
|
|
* END takes O₂ + N₂ (air) into account ("Narcotic" for trimix dives)
|
|
|
|
|
* EAD just uses N₂ ("Air" for nitrox dives) */
|
2014-08-30 15:46:47 +00:00
|
|
|
|
pressure_t modpO2 = { .mbar = (int)(prefs.modpO2 * 1000) };
|
2024-06-30 14:17:20 +00:00
|
|
|
|
entry.mod = dive->gas_mod(gasmix, modpO2, 1).mm;
|
2024-06-20 20:47:16 +00:00
|
|
|
|
entry.end = dive->mbar_to_depth(lrint(dive->depth_to_mbarf(entry.depth) * (1000 - fhe) / 1000.0));
|
|
|
|
|
entry.ead = dive->mbar_to_depth(lrint(dive->depth_to_mbarf(entry.depth) * fn2 / (double)N2_IN_AIR));
|
|
|
|
|
entry.eadd = dive->mbar_to_depth(lrint(dive->depth_to_mbarf(entry.depth) *
|
2024-05-03 16:51:03 +00:00
|
|
|
|
(entry.pressures.o2 / amb_pressure * O2_DENSITY +
|
|
|
|
|
entry.pressures.n2 / amb_pressure * N2_DENSITY +
|
|
|
|
|
entry.pressures.he / amb_pressure * HE_DENSITY) /
|
2024-06-20 20:47:16 +00:00
|
|
|
|
(O2_IN_AIR * O2_DENSITY + N2_IN_AIR * N2_DENSITY) * 1000));
|
2024-05-03 16:51:03 +00:00
|
|
|
|
entry.density = gas_density(entry.pressures);
|
|
|
|
|
if (entry.mod < 0)
|
|
|
|
|
entry.mod = 0;
|
|
|
|
|
if (entry.ead < 0)
|
|
|
|
|
entry.ead = 0;
|
|
|
|
|
if (entry.end < 0)
|
|
|
|
|
entry.end = 0;
|
|
|
|
|
if (entry.eadd < 0)
|
|
|
|
|
entry.eadd = 0;
|
2014-01-27 17:14:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-08-30 15:46:47 +00:00
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
static void fill_o2_values(const struct dive *dive, const struct divecomputer *dc, struct plot_info &pi)
|
2014-11-01 04:06:34 +00:00
|
|
|
|
/* In the samples from each dive computer, there may be uninitialised oxygen
|
|
|
|
|
* sensor or setpoint values, e.g. when events were inserted into the dive log
|
|
|
|
|
* or if the dive computer does not report o2 values with every sample. But
|
|
|
|
|
* for drawing the profile a complete series of valid o2 pressure values is
|
|
|
|
|
* required. This function takes the oxygen sensor data and setpoint values
|
|
|
|
|
* from the structures of plotinfo and replaces the zero values with their
|
|
|
|
|
* last known values so that the oxygen sensor data are complete and ready
|
|
|
|
|
* for plotting. This function called by: create_plot_info_new() */
|
2014-10-12 12:46:20 +00:00
|
|
|
|
{
|
|
|
|
|
int i, j;
|
2014-11-18 09:30:24 +00:00
|
|
|
|
pressure_t last_sensor[3], o2pressure;
|
|
|
|
|
pressure_t amb_pressure;
|
2014-10-12 12:46:20 +00:00
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
for (i = 0; i < pi.nr; i++) {
|
|
|
|
|
struct plot_data &entry = pi.entry[i];
|
2015-01-10 23:01:15 +00:00
|
|
|
|
|
2018-03-05 20:23:23 +00:00
|
|
|
|
if (dc->divemode == CCR || (dc->divemode == PSCR && dc->no_o2sensors)) {
|
2014-12-29 04:56:58 +00:00
|
|
|
|
if (i == 0) { // For 1st iteration, initialise the last_sensor values
|
2014-10-13 19:19:21 +00:00
|
|
|
|
for (j = 0; j < dc->no_o2sensors; j++)
|
2024-05-03 16:51:03 +00:00
|
|
|
|
last_sensor[j].mbar = entry.o2sensor[j].mbar;
|
2014-12-29 04:56:58 +00:00
|
|
|
|
} else { // Now re-insert the missing oxygen pressure values
|
2014-10-13 19:19:21 +00:00
|
|
|
|
for (j = 0; j < dc->no_o2sensors; j++)
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (entry.o2sensor[j].mbar)
|
|
|
|
|
last_sensor[j].mbar = entry.o2sensor[j].mbar;
|
2014-10-13 19:19:21 +00:00
|
|
|
|
else
|
2024-05-03 16:51:03 +00:00
|
|
|
|
entry.o2sensor[j].mbar = last_sensor[j].mbar;
|
2014-12-29 04:56:58 +00:00
|
|
|
|
} // having initialised the empty o2 sensor values for this point on the profile,
|
2024-06-20 20:09:47 +00:00
|
|
|
|
amb_pressure.mbar = dive->depth_to_mbar(entry.depth);
|
2014-12-29 04:56:58 +00:00
|
|
|
|
o2pressure.mbar = calculate_ccr_po2(entry, dc); // ...calculate the po2 based on the sensor data
|
2024-05-03 16:51:03 +00:00
|
|
|
|
entry.o2pressure.mbar = std::min(o2pressure.mbar, amb_pressure.mbar);
|
2014-10-14 09:37:30 +00:00
|
|
|
|
} else {
|
2024-05-03 16:51:03 +00:00
|
|
|
|
entry.o2pressure.mbar = 0; // initialise po2 to zero for dctype = OC
|
2014-10-12 12:46:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-30 15:46:47 +00:00
|
|
|
|
#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()
|
|
|
|
|
*/
|
2024-05-03 16:51:03 +00:00
|
|
|
|
static void debug_print_profiledata(struct plot_info &pi)
|
2014-08-30 15:46:47 +00:00
|
|
|
|
{
|
|
|
|
|
FILE *f1;
|
|
|
|
|
struct plot_data *entry;
|
|
|
|
|
int i;
|
2014-12-29 04:56:58 +00:00
|
|
|
|
if (!(f1 = fopen("debug_print_profiledata.dat", "w"))) {
|
2014-08-30 15:46:47 +00:00
|
|
|
|
printf("File open error for: debug_print_profiledata.dat\n");
|
2014-12-29 04:56:58 +00:00
|
|
|
|
} else {
|
2014-08-30 15:46:47 +00:00
|
|
|
|
fprintf(f1, "id t1 gas gasint t2 t3 dil dilint t4 t5 setpoint sensor1 sensor2 sensor3 t6 po2 fo2\n");
|
2024-05-03 16:51:03 +00:00
|
|
|
|
for (i = 0; i < pi.nr; i++) {
|
|
|
|
|
struct plot_data &entry = pi.entry[i];
|
2019-07-06 10:35:33 +00:00
|
|
|
|
fprintf(f1, "%d gas=%8d %8d ; dil=%8d %8d ; o2_sp= %d %d %d %d PO2= %f\n", i, get_plot_sensor_pressure(pi, i),
|
|
|
|
|
get_plot_interpolated_pressure(pi, i), O2CYLINDER_PRESSURE(entry), INTERPOLATED_O2CYLINDER_PRESSURE(entry),
|
2024-05-03 16:51:03 +00:00
|
|
|
|
entry.o2pressure.mbar, entry.o2sensor[0].mbar, entry.o2sensor[1].mbar, entry.o2sensor[2].mbar, entry.pressures.o2);
|
2014-08-30 15:46:47 +00:00
|
|
|
|
}
|
|
|
|
|
fclose(f1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2013-01-07 00:09:48 +00:00
|
|
|
|
/*
|
|
|
|
|
* Create a plot-info with smoothing and ranged min/max
|
|
|
|
|
*
|
|
|
|
|
* This also makes sure that we have extra empty events on both
|
|
|
|
|
* sides, so that you can do end-points without having to worry
|
|
|
|
|
* about it.
|
2019-08-25 10:56:41 +00:00
|
|
|
|
*
|
2024-05-03 16:51:03 +00:00
|
|
|
|
* The old data will be freed.
|
2013-01-07 00:09:48 +00:00
|
|
|
|
*/
|
2024-05-03 16:51:03 +00:00
|
|
|
|
struct plot_info create_plot_info_new(const struct dive *dive, const struct divecomputer *dc, const struct deco_state *planner_ds)
|
2014-01-17 16:43:25 +00:00
|
|
|
|
{
|
2017-11-22 19:42:33 +00:00
|
|
|
|
struct deco_state plot_deco_state;
|
2021-02-12 16:39:46 +00:00
|
|
|
|
bool in_planner = planner_ds != NULL;
|
2024-06-18 20:23:57 +00:00
|
|
|
|
divelog.dives.init_decompression(&plot_deco_state, dive, in_planner);
|
2024-05-03 16:51:03 +00:00
|
|
|
|
plot_info pi;
|
2021-02-12 16:39:46 +00:00
|
|
|
|
calculate_max_limits_new(dive, dc, pi, in_planner);
|
2024-06-24 19:04:31 +00:00
|
|
|
|
auto [o2, he, o2max ] = dive->get_maximal_gas();
|
2024-01-13 09:46:36 +00:00
|
|
|
|
if (dc->divemode == FREEDIVE) {
|
2024-05-03 16:51:03 +00:00
|
|
|
|
pi.dive_type = plot_info::FREEDIVING;
|
2024-01-13 09:46:36 +00:00
|
|
|
|
} else if (he > 0) {
|
2024-05-03 16:51:03 +00:00
|
|
|
|
pi.dive_type = plot_info::TRIMIX;
|
2014-03-31 10:48:22 +00:00
|
|
|
|
} else {
|
|
|
|
|
if (o2)
|
2024-05-03 16:51:03 +00:00
|
|
|
|
pi.dive_type = plot_info::NITROX;
|
2014-03-31 10:48:22 +00:00
|
|
|
|
else
|
2024-05-03 16:51:03 +00:00
|
|
|
|
pi.dive_type = plot_info::AIR;
|
2014-03-31 10:48:22 +00:00
|
|
|
|
}
|
2015-10-11 10:16:48 +00:00
|
|
|
|
|
2019-07-06 12:41:09 +00:00
|
|
|
|
populate_plot_entries(dive, dc, pi);
|
2014-08-30 15:46:47 +00:00
|
|
|
|
|
2014-12-29 04:56:58 +00:00
|
|
|
|
check_setpoint_events(dive, dc, pi); /* Populate setpoints */
|
|
|
|
|
setup_gas_sensor_pressure(dive, dc, pi); /* Try to populate our gas pressure knowledge */
|
2024-05-03 16:51:03 +00:00
|
|
|
|
for (int cyl = 0; cyl < pi.nr_cylinders; cyl++)
|
2021-12-10 16:44:37 +00:00
|
|
|
|
populate_pressure_information(dive, dc, pi, cyl);
|
2017-07-28 18:25:42 +00:00
|
|
|
|
fill_o2_values(dive, dc, pi); /* .. and insert the O2 sensor data having 0 values. */
|
|
|
|
|
calculate_sac(dive, dc, pi); /* Calculate sac */
|
2021-01-05 01:49:33 +00:00
|
|
|
|
|
2021-02-12 14:45:05 +00:00
|
|
|
|
calculate_deco_information(&plot_deco_state, planner_ds, dive, dc, pi); /* and ceiling information, using gradient factor values in Preferences) */
|
2021-01-05 01:49:33 +00:00
|
|
|
|
|
2017-07-28 17:35:25 +00:00
|
|
|
|
calculate_gas_information_new(dive, dc, pi); /* Calculate gas partial pressures */
|
2014-08-30 15:46:47 +00:00
|
|
|
|
|
|
|
|
|
#ifdef DEBUG_GAS
|
|
|
|
|
debug_print_profiledata(pi);
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-05-27 15:09:48 +00:00
|
|
|
|
pi.meandepth = dive->dcs[0].meandepth.mm;
|
2014-01-17 16:43:25 +00:00
|
|
|
|
analyze_plot_info(pi);
|
2024-05-03 16:51:03 +00:00
|
|
|
|
return pi;
|
2014-01-17 16:43:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
static std::vector<std::string> plot_string(const struct dive *d, const struct plot_info &pi, int idx)
|
2012-11-11 12:20:32 +00:00
|
|
|
|
{
|
2013-01-14 00:24:58 +00:00
|
|
|
|
int pressurevalue, mod, ead, end, eadd;
|
2013-10-04 05:57:48 +00:00
|
|
|
|
const char *depth_unit, *pressure_unit, *temp_unit, *vertical_speed_unit;
|
2017-05-27 14:21:37 +00:00
|
|
|
|
double depthvalue, tempvalue, speedvalue, sacvalue;
|
2017-09-13 20:18:31 +00:00
|
|
|
|
int decimals, cyl;
|
2014-06-09 03:51:13 +00:00
|
|
|
|
const char *unit;
|
2024-05-03 16:51:03 +00:00
|
|
|
|
const struct plot_data &entry = pi.entry[idx];
|
2024-03-10 22:11:23 +00:00
|
|
|
|
std::vector<std::string> res;
|
2012-11-11 16:12:09 +00:00
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
depthvalue = get_depth_units(entry.depth, NULL, &depth_unit);
|
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "@: %d:%02d"), FRACTION_TUPLE(entry.sec, 60)));
|
2024-05-01 06:14:02 +00:00
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "D: %.1f%s"), depthvalue, depth_unit));
|
2024-05-03 16:51:03 +00:00
|
|
|
|
for (cyl = 0; cyl < pi.nr_cylinders; cyl++) {
|
2019-07-06 09:58:27 +00:00
|
|
|
|
int mbar = get_plot_pressure(pi, idx, cyl);
|
2017-09-13 20:18:31 +00:00
|
|
|
|
if (!mbar)
|
|
|
|
|
continue;
|
2024-06-25 05:43:32 +00:00
|
|
|
|
struct gasmix mix = d->get_cylinder(cyl)->gasmix;
|
2017-09-13 20:18:31 +00:00
|
|
|
|
pressurevalue = get_pressure_units(mbar, &pressure_unit);
|
2024-07-02 10:38:36 +00:00
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "P: %d%s (%s)"), pressurevalue, pressure_unit, mix.name().c_str()));
|
2012-11-11 16:12:09 +00:00
|
|
|
|
}
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (entry.temperature) {
|
|
|
|
|
tempvalue = get_temp_units(entry.temperature, &temp_unit);
|
2024-03-10 22:11:23 +00:00
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "T: %.1f%s"), tempvalue, temp_unit));
|
2012-11-11 16:12:09 +00:00
|
|
|
|
}
|
2024-05-03 16:51:03 +00:00
|
|
|
|
speedvalue = get_vertical_speed_units(abs(entry.speed), NULL, &vertical_speed_unit);
|
2013-09-25 00:07:07 +00:00
|
|
|
|
/* Ascending speeds are positive, descending are negative */
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (entry.speed > 0)
|
2013-09-25 00:07:07 +00:00
|
|
|
|
speedvalue *= -1;
|
2024-03-10 22:11:23 +00:00
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "V: %.1f%s"), speedvalue, vertical_speed_unit));
|
2024-05-03 16:51:03 +00:00
|
|
|
|
sacvalue = get_volume_units(entry.sac, &decimals, &unit);
|
|
|
|
|
if (entry.sac && prefs.show_sac)
|
2024-03-10 22:11:23 +00:00
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "SAC: %.*f%s/min"), decimals, sacvalue, unit));
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (entry.cns)
|
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "CNS: %u%%"), entry.cns));
|
|
|
|
|
if (prefs.pp_graphs.po2 && entry.pressures.o2 > 0) {
|
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "pO₂: %.2fbar"), entry.pressures.o2));
|
|
|
|
|
if (entry.scr_OC_pO2.mbar)
|
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "SCR ΔpO₂: %.2fbar"), entry.scr_OC_pO2.mbar/1000.0 - entry.pressures.o2));
|
2019-06-03 14:38:20 +00:00
|
|
|
|
}
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (prefs.pp_graphs.pn2 && entry.pressures.n2 > 0)
|
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "pN₂: %.2fbar"), entry.pressures.n2));
|
|
|
|
|
if (prefs.pp_graphs.phe && entry.pressures.he > 0)
|
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "pHe: %.2fbar"), entry.pressures.he));
|
|
|
|
|
if (prefs.mod && entry.mod > 0) {
|
|
|
|
|
mod = lrint(get_depth_units(entry.mod, NULL, &depth_unit));
|
2024-03-10 22:11:23 +00:00
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "MOD: %d%s"), mod, depth_unit));
|
2013-11-12 22:10:01 +00:00
|
|
|
|
}
|
2024-05-03 16:51:03 +00:00
|
|
|
|
eadd = lrint(get_depth_units(entry.eadd, NULL, &depth_unit));
|
2017-05-12 13:36:24 +00:00
|
|
|
|
|
2013-11-12 22:10:01 +00:00
|
|
|
|
if (prefs.ead) {
|
2024-05-03 16:51:03 +00:00
|
|
|
|
switch (pi.dive_type) {
|
2024-03-07 10:09:40 +00:00
|
|
|
|
case plot_info::NITROX:
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (entry.ead > 0) {
|
|
|
|
|
ead = lrint(get_depth_units(entry.ead, NULL, &depth_unit));
|
2024-03-10 22:11:23 +00:00
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "EAD: %d%s"), ead, depth_unit));
|
2024-05-03 16:51:03 +00:00
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "EADD: %d%s / %.1fg/ℓ"), eadd, depth_unit, entry.density));
|
2017-11-05 14:56:35 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2024-03-07 10:09:40 +00:00
|
|
|
|
case plot_info::TRIMIX:
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (entry.end > 0) {
|
|
|
|
|
end = lrint(get_depth_units(entry.end, NULL, &depth_unit));
|
2024-03-10 22:11:23 +00:00
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "END: %d%s"), end, depth_unit));
|
2024-05-03 16:51:03 +00:00
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "EADD: %d%s / %.1fg/ℓ"), eadd, depth_unit, entry.density));
|
2017-11-05 14:56:35 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2024-03-07 10:09:40 +00:00
|
|
|
|
case plot_info::AIR:
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (entry.density > 0) {
|
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "Density: %.1fg/ℓ"), entry.density));
|
2017-11-05 14:56:35 +00:00
|
|
|
|
}
|
2024-03-07 10:09:40 +00:00
|
|
|
|
case plot_info::FREEDIVING:
|
2014-03-31 10:52:46 +00:00
|
|
|
|
/* nothing */
|
2014-03-31 10:48:22 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2013-01-03 05:21:36 +00:00
|
|
|
|
}
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (entry.stopdepth) {
|
|
|
|
|
depthvalue = get_depth_units(entry.stopdepth, NULL, &depth_unit);
|
|
|
|
|
if (entry.ndl > 0) {
|
2012-12-01 21:02:30 +00:00
|
|
|
|
/* this is a safety stop as we still have ndl */
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (entry.stoptime)
|
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "Safety stop: %umin @ %.0f%s"), div_up(entry.stoptime, 60),
|
2024-03-10 22:11:23 +00:00
|
|
|
|
depthvalue, depth_unit));
|
2012-12-01 21:02:30 +00:00
|
|
|
|
else
|
2024-03-10 22:11:23 +00:00
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "Safety stop: unknown time @ %.0f%s"),
|
|
|
|
|
depthvalue, depth_unit));
|
2012-12-01 21:02:30 +00:00
|
|
|
|
} else {
|
|
|
|
|
/* actual deco stop */
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (entry.stoptime)
|
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "Deco: %umin @ %.0f%s"), div_up(entry.stoptime, 60),
|
2024-03-10 22:11:23 +00:00
|
|
|
|
depthvalue, depth_unit));
|
2012-12-01 21:02:30 +00:00
|
|
|
|
else
|
2024-03-10 22:11:23 +00:00
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "Deco: unknown time @ %.0f%s"),
|
|
|
|
|
depthvalue, depth_unit));
|
2012-12-01 21:02:30 +00:00
|
|
|
|
}
|
2024-05-03 16:51:03 +00:00
|
|
|
|
} else if (entry.in_deco) {
|
2024-03-10 22:11:23 +00:00
|
|
|
|
res.push_back(translate("gettextFromC", "In deco"));
|
2024-05-03 16:51:03 +00:00
|
|
|
|
} else if (entry.ndl >= 0) {
|
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "NDL: %umin"), div_up(entry.ndl, 60)));
|
2013-07-05 13:19:41 +00:00
|
|
|
|
}
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (entry.tts)
|
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "TTS: %umin"), div_up(entry.tts, 60)));
|
|
|
|
|
if (entry.stopdepth_calc && entry.stoptime_calc) {
|
|
|
|
|
depthvalue = get_depth_units(entry.stopdepth_calc, NULL, &depth_unit);
|
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "Deco: %umin @ %.0f%s (calc)"), div_up(entry.stoptime_calc, 60),
|
2024-03-10 22:11:23 +00:00
|
|
|
|
depthvalue, depth_unit));
|
2024-05-03 16:51:03 +00:00
|
|
|
|
} else if (entry.in_deco_calc) {
|
2013-11-13 18:20:09 +00:00
|
|
|
|
/* This means that we have no NDL left,
|
|
|
|
|
* and we have no deco stop,
|
|
|
|
|
* so if we just accend to the surface slowly
|
|
|
|
|
* (ascent_mm_per_step / ascent_s_per_step)
|
|
|
|
|
* everything will be ok. */
|
2024-03-10 22:11:23 +00:00
|
|
|
|
res.push_back(translate("gettextFromC", "In deco (calc)"));
|
2024-05-03 16:51:03 +00:00
|
|
|
|
} else if (prefs.calcndltts && entry.ndl_calc != 0) {
|
|
|
|
|
if(entry.ndl_calc < MAX_PROFILE_DECO)
|
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "NDL: %umin (calc)"), div_up(entry.ndl_calc, 60)));
|
2015-10-13 09:21:14 +00:00
|
|
|
|
else
|
2024-03-10 22:11:23 +00:00
|
|
|
|
res.push_back(translate("gettextFromC", "NDL: >2h (calc)"));
|
2015-10-13 09:21:14 +00:00
|
|
|
|
}
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (entry.tts_calc) {
|
|
|
|
|
if (entry.tts_calc < MAX_PROFILE_DECO)
|
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "TTS: %umin (calc)"), div_up(entry.tts_calc, 60)));
|
2015-10-13 09:21:14 +00:00
|
|
|
|
else
|
2024-03-10 22:11:23 +00:00
|
|
|
|
res.push_back(translate("gettextFromC", "TTS: >2h (calc)"));
|
2012-12-01 21:02:30 +00:00
|
|
|
|
}
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (entry.rbt)
|
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "RBT: %umin"), div_up(entry.rbt, 60)));
|
2019-01-29 13:27:27 +00:00
|
|
|
|
if (prefs.decoinfo) {
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (entry.current_gf > 0.0)
|
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "GF %d%%"), (int)(100.0 * entry.current_gf)));
|
|
|
|
|
if (entry.surface_gf > 0.0)
|
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "Surface GF %.0f%%"), entry.surface_gf));
|
|
|
|
|
if (entry.ceiling) {
|
|
|
|
|
depthvalue = get_depth_units(entry.ceiling, NULL, &depth_unit);
|
2024-03-10 22:11:23 +00:00
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "Calculated ceiling %.1f%s"), depthvalue, depth_unit));
|
2019-01-29 13:27:27 +00:00
|
|
|
|
if (prefs.calcalltissues) {
|
|
|
|
|
int k;
|
|
|
|
|
for (k = 0; k < 16; k++) {
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (entry.ceilings[k]) {
|
|
|
|
|
depthvalue = get_depth_units(entry.ceilings[k], NULL, &depth_unit);
|
2024-03-10 22:11:23 +00:00
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "Tissue %.0fmin: %.1f%s"), buehlmann_N2_t_halflife[k], depthvalue, depth_unit));
|
2019-01-29 13:27:27 +00:00
|
|
|
|
}
|
2013-11-12 22:10:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-01-14 00:24:58 +00:00
|
|
|
|
}
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (entry.icd_warning)
|
2024-03-10 22:11:23 +00:00
|
|
|
|
res.push_back(translate("gettextFromC", "ICD in leading tissue"));
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (entry.heartbeat && prefs.hrgraph)
|
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "heart rate: %d"), entry.heartbeat));
|
|
|
|
|
if (entry.bearing >= 0)
|
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "bearing: %d"), entry.bearing));
|
|
|
|
|
if (entry.running_sum) {
|
|
|
|
|
depthvalue = get_depth_units(entry.running_sum / entry.sec, NULL, &depth_unit);
|
2024-03-10 22:11:23 +00:00
|
|
|
|
res.push_back(casprintf_loc(translate("gettextFromC", "mean depth to here %.1f%s"), depthvalue, depth_unit));
|
2014-12-31 19:34:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-10 22:11:23 +00:00
|
|
|
|
return res;
|
2012-11-11 12:20:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
std::pair<int, std::vector<std::string>> get_plot_details_new(const struct dive *d, const struct plot_info &pi, int time)
|
2014-02-05 16:53:57 +00:00
|
|
|
|
{
|
2017-11-05 14:56:35 +00:00
|
|
|
|
/* The two first and the two last plot entries do not have useful data */
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (pi.entry.size() <= 4)
|
2024-03-10 22:11:23 +00:00
|
|
|
|
return { 0, {} };
|
|
|
|
|
|
|
|
|
|
// binary search for sample index
|
2024-05-03 16:51:03 +00:00
|
|
|
|
auto it = std::lower_bound(pi.entry.begin() + 2, pi.entry.end() - 3, time,
|
2024-03-10 22:11:23 +00:00
|
|
|
|
[] (const plot_data &d, int time)
|
|
|
|
|
{ return d.sec < time; });
|
2024-05-03 16:51:03 +00:00
|
|
|
|
int idx = it - pi.entry.begin();
|
2024-03-10 22:11:23 +00:00
|
|
|
|
|
|
|
|
|
auto strings = plot_string(d, pi, idx);
|
|
|
|
|
return std::make_pair(idx, strings);
|
2014-02-05 16:53:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-10 22:11:23 +00:00
|
|
|
|
/* Compare two plot_data entries and writes the results into a set of strings */
|
2024-05-03 16:51:03 +00:00
|
|
|
|
std::vector<std::string> compare_samples(const struct dive *d, const struct plot_info &pi, int idx1, int idx2, bool sum)
|
2013-09-25 00:07:07 +00:00
|
|
|
|
{
|
2024-03-10 22:11:23 +00:00
|
|
|
|
std::string space(" ");
|
2013-10-18 17:30:51 +00:00
|
|
|
|
const char *depth_unit, *pressure_unit, *vertical_speed_unit;
|
2013-09-25 00:07:07 +00:00
|
|
|
|
double depthvalue, speedvalue;
|
|
|
|
|
|
2024-03-10 22:11:23 +00:00
|
|
|
|
std::vector<std::string> res;
|
|
|
|
|
if (idx1 < 0 || idx2 < 0)
|
|
|
|
|
return res;
|
2013-09-25 00:07:07 +00:00
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (pi.entry[idx1].sec > pi.entry[idx2].sec) {
|
2019-07-06 09:58:27 +00:00
|
|
|
|
int tmp = idx2;
|
|
|
|
|
idx2 = idx1;
|
|
|
|
|
idx1 = tmp;
|
2024-05-03 16:51:03 +00:00
|
|
|
|
} else if (pi.entry[idx1].sec == pi.entry[idx2].sec) {
|
2024-03-10 22:11:23 +00:00
|
|
|
|
return res;
|
2013-09-25 00:07:07 +00:00
|
|
|
|
}
|
2024-05-03 16:51:03 +00:00
|
|
|
|
const struct plot_data &start = pi.entry[idx1];
|
|
|
|
|
const struct plot_data &stop = pi.entry[idx2];
|
2019-07-06 09:58:27 +00:00
|
|
|
|
|
2024-03-10 22:11:23 +00:00
|
|
|
|
int avg_speed = 0;
|
|
|
|
|
int max_asc_speed = 0;
|
|
|
|
|
int max_desc_speed = 0;
|
2013-09-25 00:07:07 +00:00
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
int delta_depth = abs(start.depth - stop.depth);
|
|
|
|
|
int delta_time = abs(start.sec - stop.sec);
|
2024-03-10 22:11:23 +00:00
|
|
|
|
int avg_depth = 0;
|
|
|
|
|
int max_depth = 0;
|
|
|
|
|
int min_depth = INT_MAX;
|
2013-09-25 00:07:07 +00:00
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
int last_sec = start.sec;
|
2023-05-26 08:05:05 +00:00
|
|
|
|
|
|
|
|
|
volume_t cylinder_volume = { .mliter = 0, };
|
2024-05-03 16:51:03 +00:00
|
|
|
|
std::vector<int> start_pressures(pi.nr_cylinders, 0);
|
|
|
|
|
std::vector<int> last_pressures(pi.nr_cylinders, 0);
|
|
|
|
|
std::vector<int> bar_used(pi.nr_cylinders, 0);
|
|
|
|
|
std::vector<int> volumes_used(pi.nr_cylinders, 0);
|
|
|
|
|
std::vector<char> cylinder_is_used(pi.nr_cylinders, false);
|
2013-09-25 00:07:07 +00:00
|
|
|
|
|
2019-07-06 09:58:27 +00:00
|
|
|
|
for (int i = idx1; i < idx2; ++i) {
|
2024-05-03 16:51:03 +00:00
|
|
|
|
const struct plot_data &data = pi.entry[i];
|
2013-09-25 00:07:07 +00:00
|
|
|
|
if (sum)
|
2024-05-03 16:51:03 +00:00
|
|
|
|
avg_speed += abs(data.speed) * (data.sec - last_sec);
|
2013-09-25 00:07:07 +00:00
|
|
|
|
else
|
2024-05-03 16:51:03 +00:00
|
|
|
|
avg_speed += data.speed * (data.sec - last_sec);
|
|
|
|
|
avg_depth += data.depth * (data.sec - last_sec);
|
2013-09-25 00:07:07 +00:00
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (data.speed > max_desc_speed)
|
|
|
|
|
max_desc_speed = data.speed;
|
|
|
|
|
if (data.speed < max_asc_speed)
|
|
|
|
|
max_asc_speed = data.speed;
|
2013-09-25 00:07:07 +00:00
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
if (data.depth < min_depth)
|
|
|
|
|
min_depth = data.depth;
|
|
|
|
|
if (data.depth > max_depth)
|
|
|
|
|
max_depth = data.depth;
|
2023-05-26 08:05:05 +00:00
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
for (int cylinder_index = 0; cylinder_index < pi.nr_cylinders; cylinder_index++) {
|
2023-05-26 08:05:05 +00:00
|
|
|
|
int next_pressure = get_plot_pressure(pi, i, cylinder_index);
|
|
|
|
|
if (next_pressure && !start_pressures[cylinder_index])
|
|
|
|
|
start_pressures[cylinder_index] = next_pressure;
|
|
|
|
|
|
|
|
|
|
if (start_pressures[cylinder_index]) {
|
|
|
|
|
if (last_pressures[cylinder_index]) {
|
|
|
|
|
bar_used[cylinder_index] += last_pressures[cylinder_index] - next_pressure;
|
|
|
|
|
|
2024-06-25 05:43:32 +00:00
|
|
|
|
const cylinder_t *cyl = d->get_cylinder(cylinder_index);
|
2023-05-26 08:05:05 +00:00
|
|
|
|
|
2024-07-02 09:12:27 +00:00
|
|
|
|
// TODO: Implement addition/subtraction on units.h types
|
|
|
|
|
volumes_used[cylinder_index] += cyl->gas_volume((pressure_t){ last_pressures[cylinder_index] }).mliter -
|
|
|
|
|
cyl->gas_volume((pressure_t){ next_pressure }).mliter;
|
2023-05-26 08:05:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// check if the gas in this cylinder is being used
|
|
|
|
|
if (next_pressure < start_pressures[cylinder_index] - 1000 && !cylinder_is_used[cylinder_index]) {
|
|
|
|
|
cylinder_is_used[cylinder_index] = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
last_pressures[cylinder_index] = next_pressure;
|
|
|
|
|
}
|
2013-09-25 00:07:07 +00:00
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
last_sec = data.sec;
|
2013-09-25 00:07:07 +00:00
|
|
|
|
}
|
2023-05-26 08:05:05 +00:00
|
|
|
|
|
2024-05-03 16:51:03 +00:00
|
|
|
|
avg_depth /= stop.sec - start.sec;
|
|
|
|
|
avg_speed /= stop.sec - start.sec;
|
2013-09-25 00:07:07 +00:00
|
|
|
|
|
2024-03-10 22:11:23 +00:00
|
|
|
|
std::string l = casprintf_loc(translate("gettextFromC", "ΔT:%d:%02dmin"), delta_time / 60, delta_time % 60);
|
2013-09-25 00:07:07 +00:00
|
|
|
|
|
|
|
|
|
depthvalue = get_depth_units(delta_depth, NULL, &depth_unit);
|
2024-03-10 22:11:23 +00:00
|
|
|
|
l += space + casprintf_loc(translate("gettextFromC", "ΔD:%.1f%s"), depthvalue, depth_unit);
|
2013-09-25 00:07:07 +00:00
|
|
|
|
|
|
|
|
|
depthvalue = get_depth_units(min_depth, NULL, &depth_unit);
|
2024-03-10 22:11:23 +00:00
|
|
|
|
l += space + casprintf_loc(translate("gettextFromC", "↓D:%.1f%s"), depthvalue, depth_unit);
|
2013-09-25 00:07:07 +00:00
|
|
|
|
|
|
|
|
|
depthvalue = get_depth_units(max_depth, NULL, &depth_unit);
|
2024-03-10 22:11:23 +00:00
|
|
|
|
l += space + casprintf_loc(translate("gettextFromC", "↑D:%.1f%s"), depthvalue, depth_unit);
|
2013-09-25 00:07:07 +00:00
|
|
|
|
|
|
|
|
|
depthvalue = get_depth_units(avg_depth, NULL, &depth_unit);
|
2024-03-10 22:11:23 +00:00
|
|
|
|
l += space + casprintf_loc(translate("gettextFromC", "øD:%.1f%s"), depthvalue, depth_unit);
|
|
|
|
|
res.push_back(l);
|
2013-09-25 00:07:07 +00:00
|
|
|
|
|
2013-11-30 08:13:27 +00:00
|
|
|
|
speedvalue = get_vertical_speed_units(abs(max_desc_speed), NULL, &vertical_speed_unit);
|
2024-03-10 22:11:23 +00:00
|
|
|
|
l = casprintf_loc(translate("gettextFromC", "↓V:%.2f%s"), speedvalue, vertical_speed_unit);
|
2013-09-25 00:07:07 +00:00
|
|
|
|
|
2013-11-30 08:13:27 +00:00
|
|
|
|
speedvalue = get_vertical_speed_units(abs(max_asc_speed), NULL, &vertical_speed_unit);
|
2024-03-10 22:11:23 +00:00
|
|
|
|
l += space + casprintf_loc(translate("gettextFromC", "↑V:%.2f%s"), speedvalue, vertical_speed_unit);
|
2013-09-25 00:07:07 +00:00
|
|
|
|
|
2013-10-18 17:30:51 +00:00
|
|
|
|
speedvalue = get_vertical_speed_units(abs(avg_speed), NULL, &vertical_speed_unit);
|
2024-03-10 22:11:23 +00:00
|
|
|
|
l += space + casprintf_loc(translate("gettextFromC", "øV:%.2f%s"), speedvalue, vertical_speed_unit);
|
2013-09-25 00:07:07 +00:00
|
|
|
|
|
2023-05-26 08:05:05 +00:00
|
|
|
|
int total_bar_used = 0;
|
|
|
|
|
int total_volume_used = 0;
|
|
|
|
|
bool cylindersizes_are_identical = true;
|
|
|
|
|
bool sac_is_determinable = true;
|
2024-05-03 16:51:03 +00:00
|
|
|
|
for (int cylinder_index = 0; cylinder_index < pi.nr_cylinders; cylinder_index++) {
|
2023-05-26 08:05:05 +00:00
|
|
|
|
if (cylinder_is_used[cylinder_index]) {
|
|
|
|
|
total_bar_used += bar_used[cylinder_index];
|
|
|
|
|
total_volume_used += volumes_used[cylinder_index];
|
|
|
|
|
|
2024-06-25 05:43:32 +00:00
|
|
|
|
const cylinder_t *cyl = d->get_cylinder(cylinder_index);
|
2023-05-26 08:05:05 +00:00
|
|
|
|
if (cyl->type.size.mliter) {
|
|
|
|
|
if (cylinder_volume.mliter && cylinder_volume.mliter != cyl->type.size.mliter) {
|
|
|
|
|
cylindersizes_are_identical = false;
|
|
|
|
|
} else {
|
|
|
|
|
cylinder_volume.mliter = cyl->type.size.mliter;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
sac_is_determinable = false;
|
|
|
|
|
}
|
2016-07-18 07:27:38 +00:00
|
|
|
|
}
|
2024-03-10 22:11:23 +00:00
|
|
|
|
}
|
2023-05-26 08:05:05 +00:00
|
|
|
|
|
|
|
|
|
// No point printing 'bar used' if we know it's meaningless because cylinders of different size were used
|
|
|
|
|
if (cylindersizes_are_identical && total_bar_used) {
|
2024-03-10 22:11:23 +00:00
|
|
|
|
int pressurevalue = get_pressure_units(total_bar_used, &pressure_unit);
|
|
|
|
|
l += space + casprintf_loc(translate("gettextFromC", "ΔP:%d%s"), pressurevalue, pressure_unit);
|
2023-05-26 08:05:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We can't calculate the SAC if the volume for some of the cylinders used is unknown
|
|
|
|
|
if (sac_is_determinable && total_volume_used) {
|
|
|
|
|
int volume_precision;
|
|
|
|
|
const char *volume_unit;
|
|
|
|
|
|
|
|
|
|
/* Mean pressure in ATM */
|
2024-06-20 20:09:47 +00:00
|
|
|
|
double atm = d->depth_to_atm(avg_depth);
|
2023-05-26 08:05:05 +00:00
|
|
|
|
|
|
|
|
|
/* milliliters per minute */
|
|
|
|
|
int sac = lrint(total_volume_used / atm * 60 / delta_time);
|
2024-03-10 22:11:23 +00:00
|
|
|
|
double volume_value = get_volume_units(sac, &volume_precision, &volume_unit);
|
|
|
|
|
l += space + casprintf_loc(translate("gettextFromC", "SAC:%.*f%s/min"), volume_precision, volume_value, volume_unit);
|
2013-09-25 00:07:07 +00:00
|
|
|
|
}
|
2024-03-10 22:11:23 +00:00
|
|
|
|
res.push_back(l);
|
2013-09-25 00:07:07 +00:00
|
|
|
|
|
2024-03-10 22:11:23 +00:00
|
|
|
|
return res;
|
2013-09-25 00:07:07 +00:00
|
|
|
|
}
|