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
|
|
|
|
*/
|
2018-05-22 07:07:42 +00:00
|
|
|
|
#include "ssrf.h"
|
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>
|
2011-08-31 17:20:46 +00:00
|
|
|
|
|
|
|
|
|
#include "dive.h"
|
2018-05-11 15:25:41 +00:00
|
|
|
|
#include "subsurface-string.h"
|
2011-08-31 17:20:46 +00:00
|
|
|
|
#include "display.h"
|
2011-09-05 19:12:58 +00:00
|
|
|
|
#include "divelist.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"
|
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"
|
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
|
|
|
|
|
|
2019-03-18 20:17:00 +00:00
|
|
|
|
extern int ascent_velocity(int depth, int avg_depth, int bottom_time);
|
2015-10-12 20:34:15 +00:00
|
|
|
|
|
Undo: select dives after add, remove, merge, split dive commands
Select the proper dives after the add, remove, split and merge
dives commands on undo *and* redo. Generally, select the added
dives. For undo of add, remember the pre-addition selection.
For redo of remove, select the closest dive to the first removed
dive.
The biggest part of the commit is the signal-interface between
the dive commands and the dive-list model and dive-list view.
This is done in two steps:
1) To the DiveTripModel in batches of trips. The dive trip model
transforms the dives into indices.
2) To the DiveListView. The DiveListView has to translate the
DiveTripModel indexes to actual indexes via its QSortFilterProxy-
model.
For code-reuse, derive all divelist-changing commands from a new base-class,
which has a flag that describes whether the divelist changed. The helper
functions which add and remove dives are made members of the base class and
set the flag is a selected dive is added or removed.
To properly detect when the current dive was deleted it
became necessary to turn the current dive from an index
to a pointer, because indices are not stable.
Unfortunately, in some cases an index was expected and these
places now have to transform the dive into an index. These
should be converted in due course.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-03 09:35:43 +00:00
|
|
|
|
struct dive *current_dive = NULL;
|
2014-03-17 15:19:09 +00:00
|
|
|
|
unsigned int dc_number = 0;
|
2011-08-31 18:07:31 +00:00
|
|
|
|
|
2014-03-07 16:31:47 +00:00
|
|
|
|
static struct plot_data *last_pi_entry_new = NULL;
|
2014-08-24 18:48:22 +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 */
|
2014-02-28 04:09:57 +00:00
|
|
|
|
static void dump_pi(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",
|
|
|
|
|
pi->nr, pi->maxtime, pi->meandepth, pi->maxdepth,
|
|
|
|
|
pi->maxpressure, pi->mintemp, pi->maxtemp);
|
2012-12-01 21:02:30 +00:00
|
|
|
|
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",
|
Start cleaning up sensor indexing for multiple sensors
This is a very timid start at making us actually use multiple sensors
without the magical special case for just CCR oxygen tracking.
It mainly does:
- turn the "sample->sensor" index into an array of two indexes, to
match the pressures themselves.
- get rid of dive->{oxygen_cylinder_index,diluent_cylinder_index},
since a CCR dive should now simply set the sample->sensor[] indices
correctly instead.
- in a couple of places, start actually looping over the sensors rather
than special-case the O2 case (although often the small "loops" are
just unrolled, since it's just two cases.
but in many cases we still end up only covering the zero sensor case,
because the CCR O2 sensor code coverage was fairly limited.
It's entirely possible (even likely) that this migth break some existing
case: it tries to be a fairly direct ("stupid") translation of the old
code, but unlike the preparatory patch this does actually does change
some semantics.
For example, right now the git loader code assumes that if the git save
data contains a o2pressure entry, it just hardcodes the O2 sensor index
to 1.
In fact, one issue is going to simply be that our file formats do not
have that multiple sensor format, but instead had very clearly encoded
things as being the CCR O2 pressure sensor.
But this is hopefully close to usable, and I will need feedback (and
maybe test cases) from people who have existing CCR dives with pressure
data.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-21 02:49:45 +00:00
|
|
|
|
i, entry->sensor[0], entry->sec,
|
2014-02-28 04:09:57 +00:00
|
|
|
|
entry->pressure[0], entry->pressure[1],
|
|
|
|
|
entry->sec / 60, entry->sec % 60,
|
|
|
|
|
entry->temperature, entry->depth, entry->stopdepth, entry->stoptime, entry->ndl, entry->smoothed,
|
2014-09-15 12:55:20 +00:00
|
|
|
|
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
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
#define ROUND_UP(x, y) ((((x) + (y) - 1) / (y)) * (y))
|
|
|
|
|
#define DIV_UP(x, y) (((x) + (y) - 1) / (y))
|
2013-05-03 18:04:51 +00:00
|
|
|
|
|
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.
|
|
|
|
|
* We also need to add 180 seconds at the end so the min/max
|
2011-09-16 23:22:00 +00:00
|
|
|
|
* plots correctly
|
2011-08-31 21:35:31 +00:00
|
|
|
|
*/
|
2013-05-03 21:16:09 +00:00
|
|
|
|
int get_maxtime(struct plot_info *pi)
|
2011-08-31 21:15:50 +00:00
|
|
|
|
{
|
2011-09-16 15:20:06 +00:00
|
|
|
|
int seconds = pi->maxtime;
|
2015-10-11 10:16:48 +00:00
|
|
|
|
|
|
|
|
|
int DURATION_THR = (pi->dive_type == FREEDIVING ? 60 : 600);
|
|
|
|
|
int CEILING = (pi->dive_type == FREEDIVING ? 30 : 60);
|
|
|
|
|
|
2014-02-27 15:31:00 +00:00
|
|
|
|
if (prefs.zoomed_plot) {
|
2012-06-11 00:45:36 +00:00
|
|
|
|
/* Rounded up to one minute, with at least 2.5 minutes to
|
|
|
|
|
* spare.
|
|
|
|
|
* For dive times shorter than 10 minutes, we use seconds/4 to
|
|
|
|
|
* calculate the space dynamically.
|
|
|
|
|
* This is seamless since 600/4 = 150.
|
|
|
|
|
*/
|
2015-10-11 10:16:48 +00:00
|
|
|
|
if (seconds < DURATION_THR)
|
|
|
|
|
return ROUND_UP(seconds + seconds / 4, CEILING);
|
2012-06-11 00:45:36 +00:00
|
|
|
|
else
|
2015-10-11 10:16:48 +00:00
|
|
|
|
return ROUND_UP(seconds + DURATION_THR/4, CEILING);
|
2012-06-09 20:40:12 +00:00
|
|
|
|
} else {
|
2016-01-14 00:47:52 +00:00
|
|
|
|
#ifndef SUBSURFACE_MOBILE
|
2012-06-09 20:40:12 +00:00
|
|
|
|
/* min 30 minutes, rounded up to 5 minutes, with at least 2.5 minutes to spare */
|
2015-10-11 10:16:48 +00:00
|
|
|
|
return MAX(30 * 60, ROUND_UP(seconds + DURATION_THR/4, CEILING * 5));
|
2016-01-14 00:47:52 +00:00
|
|
|
|
#else
|
|
|
|
|
/* just add 2.5 minutes so we have a consistant right margin */
|
|
|
|
|
return seconds + DURATION_THR / 4;
|
|
|
|
|
#endif
|
2012-06-09 20:40:12 +00:00
|
|
|
|
}
|
2011-08-31 21:15:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-11-01 18:44:18 +00:00
|
|
|
|
/* get the maximum depth to which we want to plot
|
2013-12-31 22:32:15 +00:00
|
|
|
|
* take into account the additional vertical space needed to plot
|
2012-11-01 18:44:18 +00:00
|
|
|
|
* partial pressure graphs */
|
2013-05-03 21:16:09 +00:00
|
|
|
|
int get_maxdepth(struct plot_info *pi)
|
2011-08-31 21:15:50 +00:00
|
|
|
|
{
|
2011-09-16 16:10:13 +00:00
|
|
|
|
unsigned mm = pi->maxdepth;
|
2012-11-01 18:44:18 +00:00
|
|
|
|
int md;
|
|
|
|
|
|
2014-02-27 15:31:00 +00:00
|
|
|
|
if (prefs.zoomed_plot) {
|
2012-06-11 00:45:36 +00:00
|
|
|
|
/* Rounded up to 10m, with at least 3m to spare */
|
2014-02-28 04:09:57 +00:00
|
|
|
|
md = ROUND_UP(mm + 3000, 10000);
|
2012-06-11 00:45:36 +00:00
|
|
|
|
} else {
|
|
|
|
|
/* Minimum 30m, rounded up to 10m, with at least 3m to spare */
|
2014-02-28 04:09:57 +00:00
|
|
|
|
md = MAX((unsigned)30000, ROUND_UP(mm + 3000, 10000));
|
2012-11-01 18:44:18 +00:00
|
|
|
|
}
|
2017-03-09 16:07:30 +00:00
|
|
|
|
md += lrint(pi->maxpp * 9000);
|
2012-11-01 18:44:18 +00:00
|
|
|
|
return md;
|
2011-08-31 21:15:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-11-09 20:38:00 +00:00
|
|
|
|
/* collect all event names and whether we display them */
|
2013-05-06 21:58:18 +00:00
|
|
|
|
struct ev_select *ev_namelist;
|
|
|
|
|
int evn_allocated;
|
|
|
|
|
int evn_used;
|
2011-10-25 07:29:19 +00:00
|
|
|
|
|
2013-10-09 07:14:39 +00:00
|
|
|
|
#if WE_DONT_USE_THIS /* we need to implement event filters in Qt */
|
2019-02-23 17:31:02 +00:00
|
|
|
|
int evn_foreach (void (*callback)(const char *, bool *, void *), void *data)
|
|
|
|
|
{
|
2011-10-25 09:51:16 +00:00
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < evn_used; i++) {
|
2012-10-21 18:34:11 +00:00
|
|
|
|
/* here we display an event name on screen - so translate */
|
2014-02-28 04:09:57 +00:00
|
|
|
|
callback(translate("gettextFromC", ev_namelist[i].ev_name), &ev_namelist[i].plot_ev, data);
|
2011-10-25 09:51:16 +00:00
|
|
|
|
}
|
2013-02-25 21:38:01 +00:00
|
|
|
|
return i;
|
2011-10-25 09:51:16 +00:00
|
|
|
|
}
|
2013-10-09 07:14:39 +00:00
|
|
|
|
#endif /* WE_DONT_USE_THIS */
|
2011-10-25 09:51:16 +00:00
|
|
|
|
|
2013-01-31 13:07:04 +00:00
|
|
|
|
void clear_events(void)
|
|
|
|
|
{
|
2014-12-18 07:47:56 +00:00
|
|
|
|
for (int i = 0; i < evn_used; i++)
|
|
|
|
|
free(ev_namelist[i].ev_name);
|
2013-01-31 13:07:04 +00:00
|
|
|
|
evn_used = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-25 07:29:19 +00:00
|
|
|
|
void remember_event(const char *eventname)
|
|
|
|
|
{
|
2012-11-09 20:38:00 +00:00
|
|
|
|
int i = 0, len;
|
2011-10-25 07:29:19 +00:00
|
|
|
|
|
|
|
|
|
if (!eventname || (len = strlen(eventname)) == 0)
|
|
|
|
|
return;
|
|
|
|
|
while (i < evn_used) {
|
2012-11-09 20:38:00 +00:00
|
|
|
|
if (!strncmp(eventname, ev_namelist[i].ev_name, len))
|
2011-10-25 07:29:19 +00:00
|
|
|
|
return;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
if (evn_used == evn_allocated) {
|
|
|
|
|
evn_allocated += 10;
|
|
|
|
|
ev_namelist = realloc(ev_namelist, evn_allocated * sizeof(struct ev_select));
|
2014-02-28 04:09:57 +00:00
|
|
|
|
if (!ev_namelist)
|
2011-10-25 07:29:19 +00:00
|
|
|
|
/* we are screwed, but let's just bail out */
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ev_namelist[evn_used].ev_name = strdup(eventname);
|
2014-01-15 18:54:41 +00:00
|
|
|
|
ev_namelist[evn_used].plot_ev = true;
|
2011-10-25 07:29:19 +00:00
|
|
|
|
evn_used++;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-07 21:13:30 +00:00
|
|
|
|
/* UNUSED! */
|
|
|
|
|
static int get_local_sac(struct plot_data *entry1, struct plot_data *entry2, struct dive *dive) __attribute__((unused));
|
|
|
|
|
|
2013-02-25 23:23:16 +00:00
|
|
|
|
/* Get local sac-rate (in ml/min) between entry1 and entry2 */
|
2013-10-14 21:48:43 +00:00
|
|
|
|
static int get_local_sac(struct plot_data *entry1, struct plot_data *entry2, 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;
|
|
|
|
|
int duration = entry2->sec - entry1->sec;
|
|
|
|
|
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;
|
Start cleaning up sensor indexing for multiple sensors
This is a very timid start at making us actually use multiple sensors
without the magical special case for just CCR oxygen tracking.
It mainly does:
- turn the "sample->sensor" index into an array of two indexes, to
match the pressures themselves.
- get rid of dive->{oxygen_cylinder_index,diluent_cylinder_index},
since a CCR dive should now simply set the sample->sensor[] indices
correctly instead.
- in a couple of places, start actually looping over the sensors rather
than special-case the O2 case (although often the small "loops" are
just unrolled, since it's just two cases.
but in many cases we still end up only covering the zero sensor case,
because the CCR O2 sensor code coverage was fairly limited.
It's entirely possible (even likely) that this migth break some existing
case: it tries to be a fairly direct ("stupid") translation of the old
code, but unlike the preparatory patch this does actually does change
some semantics.
For example, right now the git loader code assumes that if the git save
data contains a o2pressure entry, it just hardcodes the O2 sensor index
to 1.
In fact, one issue is going to simply be that our file formats do not
have that multiple sensor format, but instead had very clearly encoded
things as being the CCR O2 pressure sensor.
But this is hopefully close to usable, and I will need feedback (and
maybe test cases) from people who have existing CCR dives with pressure
data.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-21 02:49:45 +00:00
|
|
|
|
a.mbar = GET_PRESSURE(entry1, 0);
|
|
|
|
|
b.mbar = GET_PRESSURE(entry2, 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 */
|
|
|
|
|
depth = (entry1->depth + entry2->depth) / 2;
|
2014-02-11 21:08:29 +00:00
|
|
|
|
atm = depth_to_atm(depth, dive);
|
2013-02-21 02:57:50 +00:00
|
|
|
|
|
2013-02-25 23:23:16 +00:00
|
|
|
|
cyl = dive->cylinder + index;
|
|
|
|
|
|
|
|
|
|
airuse = gas_volume(cyl, a) - gas_volume(cyl, b);
|
|
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
}
|
|
|
|
|
|
2016-04-20 22:55:51 +00:00
|
|
|
|
#define HALF_INTERVAL 9 * 30
|
2016-04-20 22:12:53 +00:00
|
|
|
|
/*
|
2016-04-20 22:55:51 +00:00
|
|
|
|
* Run the min/max calculations: over a 9 minute interval
|
2016-04-20 22:12:53 +00:00
|
|
|
|
* around the entry point (indices 0, 1, 2 respectively).
|
|
|
|
|
*/
|
2016-04-20 22:55:51 +00:00
|
|
|
|
static void analyze_plot_info_minmax(struct plot_info *pi, int entry_index)
|
2011-09-08 15:33:02 +00:00
|
|
|
|
{
|
2016-04-20 22:55:51 +00:00
|
|
|
|
struct plot_data *plot_entry = pi->entry + entry_index; // fixed
|
2016-04-20 22:12:53 +00:00
|
|
|
|
struct plot_data *p = plot_entry; // moves with 'entry'
|
2016-04-20 22:55:51 +00:00
|
|
|
|
int start = p->sec - HALF_INTERVAL, end = p->sec + HALF_INTERVAL;
|
2016-04-20 22:12:53 +00:00
|
|
|
|
int min, max;
|
2011-09-08 15:33:02 +00:00
|
|
|
|
|
|
|
|
|
/* Go back 'seconds' in time */
|
2016-04-20 22:55:51 +00:00
|
|
|
|
while (entry_index > 0) {
|
2016-04-20 22:12:53 +00:00
|
|
|
|
if (p[-1].sec < start)
|
2011-09-08 15:33:02 +00:00
|
|
|
|
break;
|
2016-04-20 22:55:51 +00:00
|
|
|
|
entry_index--;
|
2011-09-08 15:33:02 +00:00
|
|
|
|
p--;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-20 22:12:53 +00:00
|
|
|
|
// indexes to the min/max entries
|
2016-04-20 22:55:51 +00:00
|
|
|
|
min = max = entry_index;
|
2016-04-20 22:12:53 +00:00
|
|
|
|
|
2011-09-08 15:33:02 +00:00
|
|
|
|
/* Then go forward until we hit an entry past the time */
|
2016-04-20 22:55:51 +00:00
|
|
|
|
while (entry_index < pi->nr) {
|
2016-04-20 22:12:53 +00:00
|
|
|
|
int time = p->sec;
|
2011-10-23 05:40:53 +00:00
|
|
|
|
int depth = p->depth;
|
2016-04-20 22:12:53 +00:00
|
|
|
|
|
|
|
|
|
if (time > end)
|
2011-09-08 15:33:02 +00:00
|
|
|
|
break;
|
2016-04-20 22:12:53 +00:00
|
|
|
|
|
|
|
|
|
if (depth < pi->entry[min].depth)
|
2016-04-20 22:55:51 +00:00
|
|
|
|
min = entry_index;
|
2016-04-20 22:12:53 +00:00
|
|
|
|
if (depth > pi->entry[max].depth)
|
2016-04-20 22:55:51 +00:00
|
|
|
|
max = entry_index;
|
2016-04-20 22:12:53 +00:00
|
|
|
|
|
|
|
|
|
p++;
|
2016-04-20 22:55:51 +00:00
|
|
|
|
entry_index++;
|
2011-09-08 15:33:02 +00:00
|
|
|
|
}
|
2016-04-20 22:12:53 +00:00
|
|
|
|
|
2016-04-20 22:55:51 +00:00
|
|
|
|
plot_entry->min = min;
|
|
|
|
|
plot_entry->max = max;
|
2011-09-08 15:33:02 +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
|
|
|
|
|
2014-01-14 18:43:58 +00:00
|
|
|
|
struct plot_info *analyze_plot_info(struct plot_info *pi)
|
2011-09-08 15:33:02 +00:00
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
int nr = pi->nr;
|
|
|
|
|
|
|
|
|
|
/* Smoothing function: 5-point triangular smooth */
|
2011-09-30 05:49:12 +00:00
|
|
|
|
for (i = 2; i < nr; i++) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
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
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
if (i < nr - 2) {
|
|
|
|
|
depth = entry[-2].depth + 2 * entry[-1].depth + 3 * entry[0].depth + 2 * entry[1].depth + entry[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 */
|
2011-09-16 23:22:00 +00:00
|
|
|
|
if (entry[0].sec - entry[-1].sec) {
|
2013-09-25 00:07:07 +00:00
|
|
|
|
entry->speed = (entry[0].depth - entry[-1].depth) / (entry[0].sec - entry[-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*/
|
2011-09-30 05:49:12 +00:00
|
|
|
|
if (entry[0].sec - entry[-1].sec < 15 && entry->velocity < FAST) {
|
2011-09-17 04:45:32 +00:00
|
|
|
|
int past = -2;
|
2014-02-28 04:09:57 +00:00
|
|
|
|
while (i + past > 0 && entry[0].sec - entry[past].sec < 15)
|
2011-09-17 04:45:32 +00:00
|
|
|
|
past--;
|
2012-08-26 21:41:05 +00:00
|
|
|
|
entry->velocity = velocity((entry[0].depth - entry[past].depth) /
|
2014-02-28 04:09:57 +00:00
|
|
|
|
(entry[0].sec - entry[past].sec));
|
2011-09-17 04:45:32 +00:00
|
|
|
|
}
|
2013-01-29 21:10:46 +00:00
|
|
|
|
} else {
|
2011-09-16 23:22:00 +00:00
|
|
|
|
entry->velocity = STABLE;
|
2013-09-25 00:07:07 +00:00
|
|
|
|
entry->speed = 0;
|
2013-01-29 21:10:46 +00:00
|
|
|
|
}
|
2011-09-08 15:33:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-20 22:55:51 +00:00
|
|
|
|
/* get minmax data */
|
2016-04-20 22:12:53 +00:00
|
|
|
|
for (i = 0; i < nr; i++)
|
|
|
|
|
analyze_plot_info_minmax(pi, i);
|
2012-08-26 21:41:05 +00:00
|
|
|
|
|
2011-09-08 15:33:02 +00:00
|
|
|
|
return pi;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-17 18:26:21 +00:00
|
|
|
|
/*
|
|
|
|
|
* If the event has an explicit cylinder index,
|
|
|
|
|
* we return that. If it doesn't, we return the best
|
|
|
|
|
* match based on the gasmix.
|
|
|
|
|
*
|
|
|
|
|
* Some dive computers give cylinder indexes, some
|
|
|
|
|
* give just the gas mix.
|
|
|
|
|
*/
|
2018-08-16 22:58:30 +00:00
|
|
|
|
int get_cylinder_index(const struct dive *dive, const struct event *ev)
|
2011-10-23 14:52:45 +00:00
|
|
|
|
{
|
2016-04-02 20:06:54 +00:00
|
|
|
|
int best;
|
2018-08-16 11:35:14 +00:00
|
|
|
|
struct gasmix mix;
|
2011-10-23 14:52:45 +00:00
|
|
|
|
|
2014-08-17 18:26:21 +00:00
|
|
|
|
if (ev->gas.index >= 0)
|
|
|
|
|
return ev->gas.index;
|
|
|
|
|
|
2013-03-28 16:56:32 +00:00
|
|
|
|
/*
|
2016-04-02 20:06:54 +00:00
|
|
|
|
* This should no longer happen!
|
|
|
|
|
*
|
|
|
|
|
* We now match up gas change events with their cylinders at dive
|
|
|
|
|
* event fixup time.
|
2011-10-23 14:52:45 +00:00
|
|
|
|
*/
|
2016-04-02 20:06:54 +00:00
|
|
|
|
fprintf(stderr, "Still looking up cylinder based on gas mix in get_cylinder_index()!\n");
|
|
|
|
|
|
|
|
|
|
mix = get_gasmix_from_event(dive, ev);
|
2019-06-05 18:31:35 +00:00
|
|
|
|
best = find_best_gasmix_match(mix, dive->cylinder);
|
2016-04-02 20:06:54 +00:00
|
|
|
|
return best < 0 ? 0 : best;
|
2011-10-23 14:52:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-16 22:58:30 +00:00
|
|
|
|
struct event *get_next_event_mutable(struct event *event, const char *name)
|
2011-10-23 14:52:45 +00:00
|
|
|
|
{
|
2012-11-09 20:38:00 +00:00
|
|
|
|
if (!name || !*name)
|
|
|
|
|
return NULL;
|
2011-10-23 14:52:45 +00:00
|
|
|
|
while (event) {
|
2012-11-09 20:38:00 +00:00
|
|
|
|
if (!strcmp(event->name, name))
|
2011-10-23 14:52:45 +00:00
|
|
|
|
return event;
|
|
|
|
|
event = event->next;
|
|
|
|
|
}
|
|
|
|
|
return event;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-16 22:58:30 +00:00
|
|
|
|
const struct event *get_next_event(const struct event *event, const char *name)
|
|
|
|
|
{
|
|
|
|
|
return get_next_event_mutable((struct event *)event, name);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-23 16:36:20 +00:00
|
|
|
|
static int count_events(struct divecomputer *dc)
|
|
|
|
|
{
|
|
|
|
|
int result = 0;
|
|
|
|
|
struct event *ev = dc->events;
|
|
|
|
|
while (ev != NULL) {
|
|
|
|
|
result++;
|
|
|
|
|
ev = ev->next;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-23 17:04:30 +00:00
|
|
|
|
static int set_setpoint(struct plot_info *pi, int i, int setpoint, int end)
|
2014-11-26 13:22:41 +00:00
|
|
|
|
{
|
|
|
|
|
while (i < pi->nr) {
|
|
|
|
|
struct plot_data *entry = pi->entry + i;
|
|
|
|
|
if (entry->sec > end)
|
|
|
|
|
break;
|
|
|
|
|
entry->o2pressure.mbar = setpoint;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-16 22:58:30 +00:00
|
|
|
|
static void check_setpoint_events(const struct dive *dive, struct divecomputer *dc, struct plot_info *pi)
|
2014-11-26 13:22:41 +00:00
|
|
|
|
{
|
2018-05-22 07:07:42 +00:00
|
|
|
|
UNUSED(dive);
|
2014-11-26 13:22:41 +00:00
|
|
|
|
int i = 0;
|
|
|
|
|
pressure_t setpoint;
|
|
|
|
|
setpoint.mbar = 0;
|
2018-08-16 22:58:30 +00:00
|
|
|
|
const struct event *ev = get_next_event(dc->events, "SP change");
|
2014-11-26 13:22:41 +00:00
|
|
|
|
|
|
|
|
|
if (!ev)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
i = set_setpoint(pi, i, setpoint.mbar, ev->time.seconds);
|
|
|
|
|
setpoint.mbar = ev->value;
|
2014-12-29 04:56:58 +00:00
|
|
|
|
if (setpoint.mbar)
|
2015-01-10 23:01:15 +00:00
|
|
|
|
dc->divemode = CCR;
|
2014-11-26 13:22:41 +00:00
|
|
|
|
ev = get_next_event(ev->next, "SP change");
|
|
|
|
|
} while (ev);
|
2016-03-23 17:04:30 +00:00
|
|
|
|
set_setpoint(pi, i, setpoint.mbar, INT_MAX);
|
2014-11-26 13:22:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-15 15:34:55 +00:00
|
|
|
|
|
2015-01-23 19:05:32 +00:00
|
|
|
|
struct plot_info calculate_max_limits_new(struct dive *dive, struct divecomputer *given_dc)
|
2014-01-15 15:34:55 +00:00
|
|
|
|
{
|
2015-01-19 18:24:03 +00:00
|
|
|
|
struct divecomputer *dc = &(dive->dc);
|
2015-01-23 19:05:32 +00:00
|
|
|
|
bool seen = false;
|
2014-02-18 03:10:04 +00:00
|
|
|
|
static struct plot_info pi;
|
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;
|
|
|
|
|
int cyl;
|
|
|
|
|
|
|
|
|
|
/* Get the per-cylinder maximum pressure if they are manual */
|
|
|
|
|
for (cyl = 0; cyl < MAX_CYLINDERS; cyl++) {
|
2014-05-29 20:13:11 +00:00
|
|
|
|
int mbar = dive->cylinder[cyl].start.mbar;
|
2014-01-15 15:34:55 +00:00
|
|
|
|
if (mbar > maxpressure)
|
|
|
|
|
maxpressure = mbar;
|
2014-04-28 19:47:56 +00:00
|
|
|
|
if (mbar < minpressure)
|
|
|
|
|
minpressure = mbar;
|
2014-01-15 15:34:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Then do all the samples from all the dive computers */
|
|
|
|
|
do {
|
2015-01-23 19:05:32 +00:00
|
|
|
|
if (dc == given_dc)
|
|
|
|
|
seen = true;
|
2014-01-15 15:34:55 +00:00
|
|
|
|
int i = dc->samples;
|
|
|
|
|
int lastdepth = 0;
|
|
|
|
|
struct sample *s = dc->sample;
|
2016-06-01 19:49:32 +00:00
|
|
|
|
struct event *ev;
|
2014-01-15 15:34:55 +00:00
|
|
|
|
|
|
|
|
|
while (--i >= 0) {
|
|
|
|
|
int depth = s->depth.mm;
|
2017-07-20 21:39:02 +00:00
|
|
|
|
int pressure = s->pressure[0].mbar;
|
2014-01-15 15:34:55 +00:00
|
|
|
|
int temperature = s->temperature.mkelvin;
|
2014-02-23 22:32:25 +00:00
|
|
|
|
int heartbeat = s->heartbeat;
|
2014-01-15 15:34:55 +00:00
|
|
|
|
|
|
|
|
|
if (!mintemp && temperature < mintemp)
|
|
|
|
|
mintemp = temperature;
|
|
|
|
|
if (temperature > maxtemp)
|
|
|
|
|
maxtemp = temperature;
|
|
|
|
|
|
|
|
|
|
if (pressure && pressure < minpressure)
|
|
|
|
|
minpressure = pressure;
|
|
|
|
|
if (pressure > maxpressure)
|
|
|
|
|
maxpressure = pressure;
|
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)
|
|
|
|
|
maxdepth = s->depth.mm;
|
2019-03-20 15:29:27 +00:00
|
|
|
|
if ((depth > SURFACE_THRESHOLD || lastdepth > SURFACE_THRESHOLD || in_planner()) &&
|
2014-01-15 15:34:55 +00:00
|
|
|
|
s->time.seconds > maxtime)
|
|
|
|
|
maxtime = s->time.seconds;
|
|
|
|
|
lastdepth = depth;
|
|
|
|
|
s++;
|
|
|
|
|
}
|
2016-06-01 19:49:32 +00:00
|
|
|
|
|
|
|
|
|
/* Make sure we can fit all events */
|
|
|
|
|
ev = dc->events;
|
|
|
|
|
while (ev) {
|
|
|
|
|
if (ev->time.seconds > maxtime)
|
|
|
|
|
maxtime = ev->time.seconds;
|
|
|
|
|
ev = ev->next;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-23 19:05:32 +00:00
|
|
|
|
dc = dc->next;
|
|
|
|
|
if (dc == NULL && !seen) {
|
|
|
|
|
dc = given_dc;
|
|
|
|
|
seen = true;
|
|
|
|
|
}
|
|
|
|
|
} while (dc != NULL);
|
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
|
|
|
|
|
2014-02-10 14:50:45 +00:00
|
|
|
|
memset(&pi, 0, sizeof(pi));
|
2014-01-15 15:34:55 +00:00
|
|
|
|
pi.maxdepth = maxdepth;
|
|
|
|
|
pi.maxtime = maxtime;
|
|
|
|
|
pi.maxpressure = maxpressure;
|
|
|
|
|
pi.minpressure = minpressure;
|
2014-02-23 22:32:25 +00:00
|
|
|
|
pi.minhr = minhr;
|
|
|
|
|
pi.maxhr = maxhr;
|
2014-01-15 15:34:55 +00:00
|
|
|
|
pi.mintemp = mintemp;
|
|
|
|
|
pi.maxtemp = maxtemp;
|
|
|
|
|
return pi;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-23 16:36:20 +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. */
|
2015-01-16 12:49:12 +00:00
|
|
|
|
#define INSERT_ENTRY(_time, _depth, _sac) \
|
2014-02-28 04:09:57 +00:00
|
|
|
|
*entry = entry[-1]; \
|
|
|
|
|
entry->sec = _time; \
|
|
|
|
|
entry->depth = _depth; \
|
2015-01-03 07:36:41 +00:00
|
|
|
|
entry->running_sum = (entry - 1)->running_sum + (_time - (entry - 1)->sec) * (_depth + (entry - 1)->depth) / 2; \
|
2017-09-14 19:14:33 +00:00
|
|
|
|
memset(entry->pressure, 0, sizeof(entry->pressure)); \
|
2015-01-16 12:49:12 +00:00
|
|
|
|
entry->sac = _sac; \
|
2017-11-05 14:56:35 +00:00
|
|
|
|
entry->ndl = -1; \
|
|
|
|
|
entry->bearing = -1; \
|
2014-02-28 04:09:57 +00:00
|
|
|
|
entry++; \
|
2014-02-23 16:36:20 +00:00
|
|
|
|
idx++
|
|
|
|
|
|
2014-01-14 18:43:58 +00:00
|
|
|
|
struct plot_data *populate_plot_entries(struct dive *dive, 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
|
|
|
|
{
|
2018-05-22 07:07:42 +00:00
|
|
|
|
UNUSED(dive);
|
2016-03-10 15:37:18 +00:00
|
|
|
|
int idx, maxtime, nr, i;
|
|
|
|
|
int lastdepth, lasttime, lasttemp = 0;
|
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
|
|
|
|
struct plot_data *plot_data;
|
2014-02-23 16:36:20 +00:00
|
|
|
|
struct event *ev = dc->events;
|
2013-02-04 05:21:33 +00:00
|
|
|
|
maxtime = 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
|
|
|
|
|
|
|
|
|
/*
|
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
|
|
|
|
*/
|
2015-09-20 22:10:31 +00:00
|
|
|
|
nr = dc->samples + 6 + maxtime / 10 + count_events(dc);
|
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
|
|
|
|
plot_data = calloc(nr, sizeof(struct plot_data));
|
|
|
|
|
pi->entry = plot_data;
|
|
|
|
|
if (!plot_data)
|
|
|
|
|
return NULL;
|
|
|
|
|
pi->nr = nr;
|
|
|
|
|
idx = 2; /* the two extra events at the start */
|
|
|
|
|
|
|
|
|
|
lastdepth = 0;
|
|
|
|
|
lasttime = 0;
|
2014-02-23 16:36:20 +00:00
|
|
|
|
/* skip events at time = 0 */
|
|
|
|
|
while (ev && ev->time.seconds == 0)
|
|
|
|
|
ev = ev->next;
|
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
|
|
|
|
for (i = 0; i < dc->samples; i++) {
|
|
|
|
|
struct plot_data *entry = plot_data + idx;
|
2014-02-28 04:09:57 +00:00
|
|
|
|
struct sample *sample = dc->sample + i;
|
2016-03-10 15:37:18 +00:00
|
|
|
|
int time = sample->time.seconds;
|
|
|
|
|
int offset, delta;
|
2014-10-13 19:19:21 +00:00
|
|
|
|
int depth = sample->depth.mm;
|
2015-01-16 12:49:12 +00:00
|
|
|
|
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) {
|
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
|
|
|
|
if (lasttime + offset > maxtime)
|
|
|
|
|
break;
|
|
|
|
|
|
2014-02-23 16:36:20 +00:00
|
|
|
|
/* Add events if they are between plot entries */
|
2016-03-23 17:04:30 +00:00
|
|
|
|
while (ev && (int)ev->time.seconds < lasttime + offset) {
|
2015-01-16 12:49:12 +00:00
|
|
|
|
INSERT_ENTRY(ev->time.seconds, interpolate(lastdepth, depth, ev->time.seconds - lasttime, delta), sac);
|
2014-02-23 16:36:20 +00:00
|
|
|
|
ev = ev->next;
|
|
|
|
|
}
|
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 */
|
2015-01-16 12:49:12 +00:00
|
|
|
|
INSERT_ENTRY(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 */
|
2016-03-23 17:04:30 +00:00
|
|
|
|
while (ev && (int)ev->time.seconds == lasttime + offset)
|
2014-02-23 16:36:20 +00:00
|
|
|
|
ev = ev->next;
|
|
|
|
|
}
|
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 */
|
2016-03-23 17:04:30 +00:00
|
|
|
|
while (ev && (int)ev->time.seconds < time) {
|
2015-01-16 12:49:12 +00:00
|
|
|
|
INSERT_ENTRY(ev->time.seconds, interpolate(lastdepth, depth, ev->time.seconds - lasttime, delta), sac);
|
2014-02-23 16:36:20 +00:00
|
|
|
|
ev = ev->next;
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
entry->sec = time;
|
|
|
|
|
entry->depth = depth;
|
|
|
|
|
|
2015-01-03 07:36:41 +00:00
|
|
|
|
entry->running_sum = (entry - 1)->running_sum + (time - (entry - 1)->sec) * (depth + (entry - 1)->depth) / 2;
|
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
|
|
|
|
entry->stopdepth = sample->stopdepth.mm;
|
|
|
|
|
entry->stoptime = sample->stoptime.seconds;
|
|
|
|
|
entry->ndl = sample->ndl.seconds;
|
2014-12-28 22:38:40 +00:00
|
|
|
|
entry->tts = sample->tts.seconds;
|
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
|
|
|
|
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)) {
|
2015-01-05 07:20:26 +00:00
|
|
|
|
entry->o2pressure.mbar = entry->o2setpoint.mbar = sample->setpoint.mbar; // for rebreathers
|
2014-12-29 04:56:58 +00:00
|
|
|
|
entry->o2sensor[0].mbar = sample->o2sensor[0].mbar; // for up to three rebreather O2 sensors
|
2014-11-18 09:30:24 +00:00
|
|
|
|
entry->o2sensor[1].mbar = sample->o2sensor[1].mbar;
|
|
|
|
|
entry->o2sensor[2].mbar = sample->o2sensor[2].mbar;
|
2014-10-13 19:19:21 +00:00
|
|
|
|
} else {
|
2014-10-19 14:07:07 +00:00
|
|
|
|
entry->pressures.o2 = sample->setpoint.mbar / 1000.0;
|
2014-10-13 19:19:21 +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 (sample->pressure[0].mbar)
|
|
|
|
|
SENSOR_PRESSURE(entry, sample->sensor[0]) = sample->pressure[0].mbar;
|
|
|
|
|
if (sample->pressure[1].mbar)
|
|
|
|
|
SENSOR_PRESSURE(entry, sample->sensor[1]) = sample->pressure[1].mbar;
|
2013-11-12 22:00:55 +00:00
|
|
|
|
if (sample->temperature.mkelvin)
|
|
|
|
|
entry->temperature = lasttemp = sample->temperature.mkelvin;
|
|
|
|
|
else
|
|
|
|
|
entry->temperature = lasttemp;
|
2014-01-17 22:00:28 +00:00
|
|
|
|
entry->heartbeat = sample->heartbeat;
|
2014-06-03 17:21:41 +00:00
|
|
|
|
entry->bearing = sample->bearing.degrees;
|
2015-01-16 12:49:12 +00:00
|
|
|
|
entry->sac = sample->sac.mliter;
|
Add support for RBT reported sample value
RBT (Remaining Bottom Time) is a value calculated on the fly by some air
integrated divecomputers, for example Uwatec devices. This value is an
estimation based in some heuristic around time function pressure
gradients. This way, RBT would be the time a diver can spend at actual
depth without running out of gas (taking account of ascent, deco, if
required, and rock bottom gas reserve, if set).
Older Uwatec devices just made the calculus and only stored alarm events
if this time value reached zero, but modern devices store the value each
sample, in minutes.
It seems that Suunto Eon Steel is storing RBT values too, in seconds.
Libdivecomputer has supported RBT for a while, but Subsurface just
printed it to stdout and dropped it.
This adds support for RBT value on subsurface sample structure and shows
it in the profile's info box, right under TTS(calc), if selected, where
these two values can be easily compared by humans.
Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-22 15:02:33 +00:00
|
|
|
|
if (sample->rbt.seconds)
|
|
|
|
|
entry->rbt = sample->rbt.seconds;
|
2014-02-23 16:36:20 +00:00
|
|
|
|
/* skip events that happened at this time */
|
2016-03-23 17:04:30 +00:00
|
|
|
|
while (ev && (int)ev->time.seconds == time)
|
2014-02-23 16:36:20 +00:00
|
|
|
|
ev = ev->next;
|
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;
|
|
|
|
|
idx++;
|
2015-09-20 22:10:31 +00:00
|
|
|
|
|
|
|
|
|
if (time > maxtime)
|
|
|
|
|
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 */
|
|
|
|
|
while (ev) {
|
|
|
|
|
struct plot_data *entry = plot_data + idx;
|
|
|
|
|
int time = ev->time.seconds;
|
|
|
|
|
|
|
|
|
|
if (time > lasttime) {
|
|
|
|
|
INSERT_ENTRY(ev->time.seconds, 0, 0);
|
|
|
|
|
lasttime = time;
|
|
|
|
|
}
|
|
|
|
|
ev = ev->next;
|
|
|
|
|
}
|
|
|
|
|
|
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 */
|
2014-02-28 04:09:57 +00:00
|
|
|
|
plot_data[idx++].sec = lasttime + 1;
|
|
|
|
|
plot_data[idx++].sec = lasttime + 2;
|
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
|
|
|
|
pi->nr = idx;
|
|
|
|
|
|
|
|
|
|
return plot_data;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-23 16:36:20 +00:00
|
|
|
|
#undef INSERT_ENTRY
|
|
|
|
|
|
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
|
|
|
|
*/
|
2017-07-28 18:25:42 +00:00
|
|
|
|
static int sac_between(struct dive *dive, struct plot_data *first, struct plot_data *last, unsigned int gases)
|
2015-10-22 19:47:39 +00:00
|
|
|
|
{
|
2017-07-28 18:25:42 +00:00
|
|
|
|
int i, airuse;
|
2015-10-22 19:47:39 +00:00
|
|
|
|
double pressuretime;
|
|
|
|
|
|
|
|
|
|
if (first == last)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2017-07-28 18:25:42 +00:00
|
|
|
|
/* Get airuse for the set of cylinders over the range */
|
|
|
|
|
airuse = 0;
|
|
|
|
|
for (i = 0; i < MAX_CYLINDERS; i++) {
|
|
|
|
|
pressure_t a, b;
|
|
|
|
|
cylinder_t *cyl;
|
|
|
|
|
int cyluse;
|
|
|
|
|
|
|
|
|
|
if (!(gases & (1u << i)))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
a.mbar = GET_PRESSURE(first, i);
|
|
|
|
|
b.mbar = GET_PRESSURE(last, i);
|
|
|
|
|
cyl = dive->cylinder + i;
|
|
|
|
|
cyluse = gas_volume(cyl, a) - gas_volume(cyl, b);
|
|
|
|
|
if (cyluse > 0)
|
|
|
|
|
airuse += cyluse;
|
|
|
|
|
}
|
|
|
|
|
if (!airuse)
|
2015-10-22 19:47:39 +00:00
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
/* Calculate depthpressure integrated over time */
|
|
|
|
|
pressuretime = 0.0;
|
|
|
|
|
do {
|
|
|
|
|
int depth = (first[0].depth + first[1].depth) / 2;
|
|
|
|
|
int time = first[1].sec - first[0].sec;
|
|
|
|
|
double atm = depth_to_atm(depth, dive);
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2017-07-28 18:25:42 +00:00
|
|
|
|
/* Which of the set of gases have pressure data */
|
|
|
|
|
static unsigned int have_pressures(struct plot_data *entry, unsigned int gases)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_CYLINDERS; i++) {
|
|
|
|
|
unsigned int mask = 1 << i;
|
|
|
|
|
if (gases & mask) {
|
|
|
|
|
if (!GET_PRESSURE(entry, i))
|
|
|
|
|
gases &= ~mask;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return gases;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-22 19:47:39 +00:00
|
|
|
|
/*
|
|
|
|
|
* Try to do the momentary sac rate for this entry, averaging over one
|
|
|
|
|
* minute.
|
|
|
|
|
*/
|
2017-07-28 18:25:42 +00:00
|
|
|
|
static void fill_sac(struct dive *dive, struct plot_info *pi, int idx, unsigned int gases)
|
2015-10-22 19:47:39 +00:00
|
|
|
|
{
|
|
|
|
|
struct plot_data *entry = pi->entry + idx;
|
|
|
|
|
struct plot_data *first, *last;
|
2016-03-10 15:37:18 +00:00
|
|
|
|
int time;
|
2015-10-22 19:47:39 +00:00
|
|
|
|
|
|
|
|
|
if (entry->sac)
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
gases = have_pressures(entry, gases);
|
|
|
|
|
if (!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
|
|
|
|
*/
|
|
|
|
|
first = entry;
|
|
|
|
|
time = entry->sec - 30;
|
|
|
|
|
while (idx > 0) {
|
|
|
|
|
struct plot_data *prev = first-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
|
|
|
|
|
2015-10-22 19:47:39 +00:00
|
|
|
|
if (prev->depth < SURFACE_THRESHOLD && first->depth < SURFACE_THRESHOLD)
|
|
|
|
|
break;
|
|
|
|
|
if (prev->sec < time)
|
|
|
|
|
break;
|
2017-07-28 18:25:42 +00:00
|
|
|
|
if (have_pressures(prev, gases) != gases)
|
2015-10-22 19:47:39 +00:00
|
|
|
|
break;
|
|
|
|
|
idx--;
|
|
|
|
|
first = prev;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Now find an entry a minute after the first one */
|
|
|
|
|
last = first;
|
|
|
|
|
time = first->sec + 60;
|
|
|
|
|
while (++idx < pi->nr) {
|
|
|
|
|
struct plot_data *next = last+1;
|
|
|
|
|
if (next->depth < SURFACE_THRESHOLD && last->depth < SURFACE_THRESHOLD)
|
|
|
|
|
break;
|
|
|
|
|
if (next->sec > time)
|
|
|
|
|
break;
|
2017-07-28 18:25:42 +00:00
|
|
|
|
if (have_pressures(next, gases) != gases)
|
2015-10-22 19:47:39 +00:00
|
|
|
|
break;
|
|
|
|
|
last = next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Ok, now calculate the SAC between 'first' and 'last' */
|
2017-07-28 18:25:42 +00:00
|
|
|
|
entry->sac = sac_between(dive, 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
|
|
|
|
|
*/
|
2018-08-16 17:10:10 +00:00
|
|
|
|
static unsigned int matching_gases(struct dive *dive, struct gasmix gasmix)
|
2017-07-28 18:25:42 +00:00
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
unsigned int gases = 0;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_CYLINDERS; i++) {
|
|
|
|
|
cylinder_t *cyl = dive->cylinder + i;
|
2018-08-16 17:10:10 +00:00
|
|
|
|
if (same_gasmix(gasmix, cyl->gasmix))
|
2017-07-28 18:25:42 +00:00
|
|
|
|
gases |= 1 << i;
|
|
|
|
|
}
|
|
|
|
|
return gases;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void calculate_sac(struct dive *dive, struct divecomputer *dc, struct plot_info *pi)
|
2013-10-14 21:48:43 +00:00
|
|
|
|
{
|
2018-09-10 18:40:25 +00:00
|
|
|
|
struct gasmix gasmix = gasmix_invalid;
|
2018-08-16 22:58:30 +00:00
|
|
|
|
const struct event *ev = NULL;
|
2017-07-28 18:25:42 +00:00
|
|
|
|
unsigned int gases = 0;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < pi->nr; i++) {
|
|
|
|
|
struct plot_data *entry = pi->entry + i;
|
2018-08-16 17:10:10 +00:00
|
|
|
|
struct gasmix newmix = get_gasmix(dive, dc, entry->sec, &ev, gasmix);
|
|
|
|
|
if (!same_gasmix(newmix, gasmix)) {
|
2017-07-28 18:25:42 +00:00
|
|
|
|
gasmix = newmix;
|
2018-08-16 17:10:10 +00:00
|
|
|
|
gases = matching_gases(dive, newmix);
|
2017-07-28 18:25:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fill_sac(dive, pi, i, gases);
|
|
|
|
|
}
|
2013-10-14 21:48:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-16 22:58:30 +00:00
|
|
|
|
static void populate_secondary_sensor_data(const struct divecomputer *dc, struct plot_info *pi)
|
2013-01-07 00:09:48 +00:00
|
|
|
|
{
|
2018-05-22 07:07:42 +00:00
|
|
|
|
UNUSED(dc);
|
|
|
|
|
UNUSED(pi);
|
2013-01-07 00:09:48 +00:00
|
|
|
|
/* We should try to see if it has interesting pressure data here */
|
|
|
|
|
}
|
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.
|
|
|
|
|
*/
|
2017-11-17 01:57:37 +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
|
|
|
|
{
|
2017-07-30 17:41:20 +00:00
|
|
|
|
struct plot_data *entry;
|
2017-12-19 22:39:24 +00:00
|
|
|
|
if (pi->nr <= 0) {
|
|
|
|
|
fprintf(stderr, "add_plot_pressure(): called with pi->nr <= 0\n");
|
|
|
|
|
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
|
|
|
|
for (int i = 0; i < pi->nr; i++) {
|
2017-07-30 17:41:20 +00:00
|
|
|
|
entry = pi->entry + i;
|
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-07-30 17:41:20 +00:00
|
|
|
|
if (entry->sec >= time)
|
|
|
|
|
break;
|
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
|
|
|
|
SENSOR_PRESSURE(entry, cyl) = p.mbar;
|
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
|
|
|
|
}
|
|
|
|
|
|
2018-08-16 22:58:30 +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
|
|
|
|
{
|
2017-07-31 04:05:48 +00:00
|
|
|
|
int prev, i;
|
2018-08-16 22:58:30 +00:00
|
|
|
|
const struct event *ev;
|
2017-11-17 01:57:37 +00:00
|
|
|
|
int seen[MAX_CYLINDERS] = { 0, };
|
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
|
|
|
|
unsigned int first[MAX_CYLINDERS] = { 0, };
|
|
|
|
|
unsigned int last[MAX_CYLINDERS] = { 0, };
|
2018-08-16 22:58:30 +00:00
|
|
|
|
const struct divecomputer *secondary;
|
2017-07-28 18:49:03 +00:00
|
|
|
|
|
2017-07-31 04:05:48 +00:00
|
|
|
|
prev = explicit_first_cylinder(dive, dc);
|
|
|
|
|
seen[prev] = 1;
|
2017-07-28 18:49:03 +00:00
|
|
|
|
for (i = 0; i < MAX_CYLINDERS; i++)
|
2017-07-30 17:41:20 +00:00
|
|
|
|
last[i] = INT_MAX;
|
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
|
|
|
|
|
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
|
|
|
|
for (ev = get_next_event(dc->events, "gaschange"); ev != NULL; ev = get_next_event(ev->next, "gaschange")) {
|
|
|
|
|
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)
|
2013-01-07 00:09:48 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
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.
|
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
|
|
|
|
for (i = 0; i < MAX_CYLINDERS; i++) {
|
2018-08-16 22:58:30 +00:00
|
|
|
|
const cylinder_t *cyl = dive->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 */
|
|
|
|
|
for_each_dc(dive, secondary) {
|
|
|
|
|
if (has_gaschange_event(dive, secondary, i)) {
|
|
|
|
|
seen[i] = -1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_CYLINDERS; i++) {
|
|
|
|
|
if (seen[i] >= 0) {
|
2018-08-16 22:58:30 +00:00
|
|
|
|
const cylinder_t *cyl = dive->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
|
|
|
|
|
* primary dive computer (dc).
|
|
|
|
|
*/
|
|
|
|
|
secondary = &dive->dc;
|
|
|
|
|
do {
|
|
|
|
|
if (secondary == dc)
|
|
|
|
|
continue;
|
|
|
|
|
populate_secondary_sensor_data(dc, pi);
|
|
|
|
|
} while ((secondary = secondary->next) != NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-06 04:45:18 +00:00
|
|
|
|
#ifndef SUBSURFACE_MOBILE
|
2013-11-12 22:09:59 +00:00
|
|
|
|
/* calculate DECO STOP / TTS / NDL */
|
2018-08-16 22:58:30 +00:00
|
|
|
|
static void calculate_ndl_tts(struct deco_state *ds, const struct dive *dive, struct plot_data *entry, struct gasmix gasmix, double surface_pressure,enum divemode_t divemode)
|
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;
|
2013-11-12 22:09:59 +00:00
|
|
|
|
const int deco_stepsize = 3000;
|
|
|
|
|
/* at what depth is the current deco-step? */
|
2017-11-22 19:42:33 +00:00
|
|
|
|
int next_stop = ROUND_UP(deco_allowed_depth(
|
|
|
|
|
tissue_tolerance_calc(ds, dive, depth_to_bar(entry->depth, dive)),
|
|
|
|
|
surface_pressure, dive, 1), deco_stepsize);
|
2013-11-12 22:09:59 +00:00
|
|
|
|
int ascent_depth = entry->depth;
|
|
|
|
|
/* at what time should we give up and say that we got enuff NDL? */
|
2015-10-25 00:26:15 +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) {
|
2014-01-16 04:50:56 +00:00
|
|
|
|
if (entry->depth < 3000) {
|
2015-10-12 20:34:15 +00:00
|
|
|
|
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 */
|
2017-11-22 19:42:33 +00:00
|
|
|
|
while (entry->ndl_calc < MAX_PROFILE_DECO &&
|
|
|
|
|
deco_allowed_depth(tissue_tolerance_calc(ds, dive, depth_to_bar(entry->depth, dive)),
|
|
|
|
|
surface_pressure, dive, 1) <= 0
|
|
|
|
|
) {
|
2013-11-13 18:20:09 +00:00
|
|
|
|
entry->ndl_calc += time_stepsize;
|
2017-11-22 19:42:33 +00:00
|
|
|
|
add_segment(ds, depth_to_bar(entry->depth, dive),
|
2018-04-03 17:30:27 +00:00
|
|
|
|
gasmix, time_stepsize, entry->o2pressure.mbar, divemode, prefs.bottomsac);
|
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 */
|
2014-01-15 18:54:41 +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 */
|
2019-03-18 20:17:00 +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) {
|
2017-11-22 19:42:33 +00:00
|
|
|
|
add_segment(ds, depth_to_bar(ascent_depth, dive),
|
2018-04-03 17:30:27 +00:00
|
|
|
|
gasmix, ascent_s_per_step, entry->o2pressure.mbar, divemode, prefs.decosac);
|
2017-11-22 19:42:33 +00:00
|
|
|
|
next_stop = ROUND_UP(deco_allowed_depth(tissue_tolerance_calc(ds, dive, depth_to_bar(ascent_depth, dive)),
|
|
|
|
|
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? */
|
2013-11-13 18:20:09 +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 */
|
2013-11-13 18:20:09 +00:00
|
|
|
|
if (ascent_depth == entry->stopdepth_calc)
|
|
|
|
|
entry->stoptime_calc += time_stepsize;
|
2013-11-12 22:09:59 +00:00
|
|
|
|
|
2013-11-13 18:20:09 +00:00
|
|
|
|
entry->tts_calc += time_stepsize;
|
2015-10-12 20:34:15 +00:00
|
|
|
|
if (entry->tts_calc > MAX_PROFILE_DECO)
|
|
|
|
|
break;
|
2017-11-22 19:42:33 +00:00
|
|
|
|
add_segment(ds, depth_to_bar(ascent_depth, dive),
|
2018-04-03 17:30:27 +00:00
|
|
|
|
gasmix, time_stepsize, entry->o2pressure.mbar, divemode, prefs.decosac);
|
2013-11-12 22:09:59 +00:00
|
|
|
|
|
2017-11-22 19:42:33 +00:00
|
|
|
|
if (deco_allowed_depth(tissue_tolerance_calc(ds, dive, depth_to_bar(ascent_depth,dive)), 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 */
|
2019-03-18 20:17:00 +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)
|
2017-11-22 19:42:33 +00:00
|
|
|
|
add_segment(ds, depth_to_bar(ascent_depth, dive),
|
2018-04-03 17:30:27 +00:00
|
|
|
|
gasmix, ascent_s_per_deco_step, entry->o2pressure.mbar, divemode, prefs.decosac);
|
2013-11-12 22:09:59 +00:00
|
|
|
|
ascent_depth = next_stop;
|
|
|
|
|
next_stop -= deco_stepsize;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Let's try to do some deco calculations.
|
|
|
|
|
*/
|
2018-08-16 22:58:30 +00:00
|
|
|
|
void calculate_deco_information(struct deco_state *ds, const struct deco_state *planner_ds, const struct dive *dive, const struct divecomputer *dc, struct plot_info *pi, bool print_mode)
|
2013-01-07 00:09:48 +00:00
|
|
|
|
{
|
2017-11-02 20:32:28 +00:00
|
|
|
|
int i, count_iteration = 0;
|
2014-01-15 18:54:41 +00:00
|
|
|
|
double surface_pressure = (dc->surface_pressure.mbar ? dc->surface_pressure.mbar : get_surface_pressure_in_mbar(dive, true)) / 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;
|
2018-04-03 17:30:27 +00:00
|
|
|
|
|
2017-11-24 13:17:01 +00:00
|
|
|
|
if (!in_planner()) {
|
2017-11-22 19:42:33 +00:00
|
|
|
|
ds->deco_time = 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;
|
|
|
|
|
}
|
2017-05-25 22:45:53 +00:00
|
|
|
|
struct deco_state *cache_data_initial = NULL;
|
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 */
|
2017-10-26 23:06:11 +00:00
|
|
|
|
if (decoMode() == VPMB) {
|
2017-11-22 19:42:33 +00:00
|
|
|
|
cache_deco_state(ds, &cache_data_initial);
|
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;
|
2017-10-26 23:06:11 +00:00
|
|
|
|
if (decoMode() == VPMB)
|
2017-11-22 19:42:33 +00:00
|
|
|
|
ds->first_ceiling_pressure.mbar = depth_to_mbar(first_ceiling, dive);
|
2018-09-10 18:40:25 +00:00
|
|
|
|
struct gasmix gasmix = gasmix_invalid;
|
2018-08-16 22:58:30 +00:00
|
|
|
|
const struct event *ev = NULL, *evd = NULL;
|
2018-05-08 14:24:51 +00:00
|
|
|
|
enum divemode_t current_divemode = UNDEF_COMP_TYPE;
|
2017-07-28 17:35:25 +00:00
|
|
|
|
|
2015-10-25 00:26:15 +00:00
|
|
|
|
for (i = 1; i < pi->nr; i++) {
|
|
|
|
|
struct plot_data *entry = pi->entry + i;
|
|
|
|
|
int j, t0 = (entry - 1)->sec, t1 = entry->sec;
|
|
|
|
|
int time_stepsize = 20;
|
|
|
|
|
|
2018-04-07 15:52:16 +00:00
|
|
|
|
current_divemode = get_current_divemode(dc, entry->sec, &evd, ¤t_divemode);
|
2018-08-16 17:10:10 +00:00
|
|
|
|
gasmix = get_gasmix(dive, dc, t1, &ev, gasmix);
|
2015-10-25 00:26:15 +00:00
|
|
|
|
entry->ambpressure = depth_to_bar(entry->depth, dive);
|
2017-11-22 19:42:33 +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) {
|
|
|
|
|
fprintf(stderr, "non-monotonous dive stamps %d %d\n", t0, t1);
|
|
|
|
|
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) {
|
|
|
|
|
int depth = interpolate(entry[-1].depth, entry[0].depth, j - t0, t1 - t0);
|
2017-11-22 19:42:33 +00:00
|
|
|
|
add_segment(ds, depth_to_bar(depth, dive),
|
2018-08-16 17:10:10 +00:00
|
|
|
|
gasmix, time_stepsize, entry->o2pressure.mbar, current_divemode, entry->sac);
|
2018-04-10 19:20:38 +00:00
|
|
|
|
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) {
|
|
|
|
|
entry->ceiling = (entry - 1)->ceiling;
|
|
|
|
|
} else {
|
|
|
|
|
/* Keep updating the VPM-B gradients until the start of the ascent phase of the dive. */
|
2017-10-08 08:29:48 +00:00
|
|
|
|
if (decoMode() == 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 */
|
|
|
|
|
if (!first_iteration || in_planner())
|
2017-11-22 19:42:33 +00:00
|
|
|
|
vpmb_next_gradient(ds, ds->deco_time, surface_pressure / 1000.0);
|
2015-10-25 00:26:15 +00:00
|
|
|
|
}
|
2017-11-22 19:42:33 +00:00
|
|
|
|
entry->ceiling = deco_allowed_depth(tissue_tolerance_calc(ds, dive, depth_to_bar(entry->depth, dive)), surface_pressure, dive, !prefs.calcceiling3m);
|
2016-04-07 13:06:44 +00:00
|
|
|
|
if (prefs.calcceiling3m)
|
2017-11-22 19:42:33 +00:00
|
|
|
|
current_ceiling = deco_allowed_depth(tissue_tolerance_calc(ds, dive, depth_to_bar(entry->depth, dive)), surface_pressure, dive, true);
|
2016-04-07 13:06:44 +00:00
|
|
|
|
else
|
|
|
|
|
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 */
|
2017-10-08 08:29:48 +00:00
|
|
|
|
if (decoMode() == VPMB) {
|
2017-10-26 23:06:11 +00:00
|
|
|
|
if (current_ceiling >= first_ceiling ||
|
2017-11-13 15:12:45 +00:00
|
|
|
|
(time_deep_ceiling == t0 && entry->depth == (entry - 1)->depth)) {
|
2016-04-07 13:06:44 +00:00
|
|
|
|
time_deep_ceiling = t1;
|
|
|
|
|
first_ceiling = current_ceiling;
|
2017-11-22 19:42:33 +00:00
|
|
|
|
ds->first_ceiling_pressure.mbar = depth_to_mbar(first_ceiling, dive);
|
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*/
|
2017-10-26 23:06:11 +00:00
|
|
|
|
if (!in_planner())
|
2017-11-22 19:42:33 +00:00
|
|
|
|
ds->deco_time = pi->maxtime - t1 + 1800;
|
|
|
|
|
vpmb_next_gradient(ds, ds->deco_time, surface_pressure / 1000.0);
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-23 15:46:45 +00:00
|
|
|
|
entry->surface_gf = 0.0;
|
2015-10-25 00:26:15 +00:00
|
|
|
|
for (j = 0; j < 16; j++) {
|
2017-11-22 19:42:33 +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];
|
2017-11-22 19:42:33 +00:00
|
|
|
|
entry->ceilings[j] = deco_allowed_depth(ds->tolerated_by_tissue[j], surface_pressure, dive, 1);
|
|
|
|
|
entry->percentages[j] = ds->tissue_inertgas_saturation[j] < entry->ambpressure ?
|
|
|
|
|
lrint(ds->tissue_inertgas_saturation[j] / entry->ambpressure * AMB_PERCENTAGE) :
|
|
|
|
|
lrint(AMB_PERCENTAGE + (ds->tissue_inertgas_saturation[j] - entry->ambpressure) / (m_value - entry->ambpressure) * (100.0 - AMB_PERCENTAGE));
|
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);
|
|
|
|
|
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
|
|
|
|
|
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 */
|
2017-01-07 02:01:14 +00:00
|
|
|
|
if ((prefs.calcndltts && !print_mode && (decoMode() != VPMB || in_planner() || !first_iteration)) ||
|
|
|
|
|
(decoMode() == VPMB && !in_planner() && i == pi->nr - 1)) {
|
2015-10-25 00:26:15 +00:00
|
|
|
|
/* only calculate ndl/tts on every 30 seconds */
|
|
|
|
|
if ((entry->sec - last_ndl_tts_calc_time) < 30 && i != pi->nr - 1) {
|
|
|
|
|
struct plot_data *prev_entry = (entry - 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;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
last_ndl_tts_calc_time = entry->sec;
|
|
|
|
|
|
|
|
|
|
/* We are going to mess up deco state, so store it for later restore */
|
2017-05-25 22:45:53 +00:00
|
|
|
|
struct deco_state *cache_data = NULL;
|
2017-11-22 19:42:33 +00:00
|
|
|
|
cache_deco_state(ds, &cache_data);
|
2018-08-16 17:10:10 +00:00
|
|
|
|
calculate_ndl_tts(ds, dive, entry, gasmix, surface_pressure, current_divemode);
|
2017-01-07 02:01:14 +00:00
|
|
|
|
if (decoMode() == VPMB && !in_planner() && i == pi->nr - 1)
|
2015-10-25 00:26:15 +00:00
|
|
|
|
final_tts = entry->tts_calc;
|
|
|
|
|
/* Restore "real" deco state for next real time step */
|
2017-11-22 19:42:33 +00:00
|
|
|
|
restore_deco_state(cache_data, ds, decoMode() == VPMB);
|
2015-10-25 00:26:15 +00:00
|
|
|
|
free(cache_data);
|
2014-06-29 18:23:00 +00:00
|
|
|
|
}
|
2015-10-25 00:26:15 +00:00
|
|
|
|
}
|
2017-01-07 02:01:14 +00:00
|
|
|
|
if (decoMode() == 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. */
|
2017-11-22 19:42:33 +00:00
|
|
|
|
ds->deco_time = ROUND_UP(time_clear_ceiling - time_deep_ceiling + 20, 60) + 20;
|
|
|
|
|
vpmb_next_gradient(ds, ds->deco_time, surface_pressure / 1000.0);
|
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;
|
|
|
|
|
restore_deco_state(cache_data_initial, ds, true);
|
|
|
|
|
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
|
|
|
|
|
2015-10-25 00:26:15 +00:00
|
|
|
|
free(cache_data_initial);
|
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
|
|
|
|
}
|
2016-02-06 04:45:18 +00:00
|
|
|
|
#endif
|
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,
|
|
|
|
|
* calculates the po2 value from the sensor data. Several rules are applied, depending on how many o2 sensors
|
|
|
|
|
* there are and the differences among the readings from these sensors.
|
|
|
|
|
*/
|
2014-12-29 04:56:58 +00:00
|
|
|
|
static int calculate_ccr_po2(struct plot_data *entry, struct divecomputer *dc)
|
|
|
|
|
{
|
2014-11-18 09:30:24 +00:00
|
|
|
|
int sump = 0, minp = 999999, maxp = -999999;
|
|
|
|
|
int diff_limit = 100; // The limit beyond which O2 sensor differences are considered significant (default = 100 mbar)
|
2014-10-25 09:42:33 +00:00
|
|
|
|
int i, np = 0;
|
2014-10-14 08:46:40 +00:00
|
|
|
|
|
2014-12-29 04:56:58 +00:00
|
|
|
|
for (i = 0; i < dc->no_o2sensors; i++)
|
2014-11-18 09:30:24 +00:00
|
|
|
|
if (entry->o2sensor[i].mbar) { // Valid reading
|
2014-10-14 08:46:40 +00:00
|
|
|
|
++np;
|
2014-11-18 09:30:24 +00:00
|
|
|
|
sump += entry->o2sensor[i].mbar;
|
|
|
|
|
minp = MIN(minp, entry->o2sensor[i].mbar);
|
|
|
|
|
maxp = MAX(maxp, entry->o2sensor[i].mbar);
|
2014-10-13 19:19:21 +00:00
|
|
|
|
}
|
2014-10-14 08:46:40 +00:00
|
|
|
|
switch (np) {
|
|
|
|
|
case 0: // Uhoh
|
2014-11-20 14:55:11 +00:00
|
|
|
|
return entry->o2pressure.mbar;
|
2014-10-14 08:46:40 +00:00
|
|
|
|
case 1: // Return what we have
|
|
|
|
|
return sump;
|
|
|
|
|
case 2: // Take the average
|
|
|
|
|
return sump / 2;
|
2014-12-29 04:56:58 +00:00
|
|
|
|
case 3: // Voting logic
|
2014-10-14 08:46:40 +00:00
|
|
|
|
if (2 * maxp - sump + minp < diff_limit) { // Upper difference acceptable...
|
2014-12-29 04:56:58 +00:00
|
|
|
|
if (2 * minp - sump + maxp) // ...and lower difference acceptable
|
2014-10-14 08:46:40 +00:00
|
|
|
|
return sump / 3;
|
2014-10-13 19:19:21 +00:00
|
|
|
|
else
|
2014-10-14 08:46:40 +00:00
|
|
|
|
return (sump - minp) / 2;
|
|
|
|
|
} else {
|
2014-12-29 04:56:58 +00:00
|
|
|
|
if (2 * minp - sump + maxp) // ...but lower difference acceptable
|
2014-10-14 08:46:40 +00:00
|
|
|
|
return (sump - maxp) / 2;
|
|
|
|
|
else
|
|
|
|
|
return sump / 3;
|
2014-10-13 19:19:21 +00:00
|
|
|
|
}
|
2014-10-14 08:46:40 +00:00
|
|
|
|
default: // This should not happen
|
|
|
|
|
assert(np <= 3);
|
2014-11-18 09:30:24 +00:00
|
|
|
|
return 0;
|
2014-10-14 08:46:40 +00:00
|
|
|
|
}
|
2014-10-13 19:19:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-28 17:35:25 +00:00
|
|
|
|
static void calculate_gas_information_new(struct dive *dive, struct divecomputer *dc, struct plot_info *pi)
|
2014-01-27 17:14:42 +00:00
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
double amb_pressure;
|
2018-09-10 18:40:25 +00:00
|
|
|
|
struct gasmix gasmix = gasmix_invalid;
|
2018-08-16 22:58:30 +00:00
|
|
|
|
const struct event *evg = NULL, *evd = NULL;
|
2018-05-08 14:24:51 +00:00
|
|
|
|
enum divemode_t current_divemode = UNDEF_COMP_TYPE;
|
2014-01-27 17:14:42 +00:00
|
|
|
|
|
|
|
|
|
for (i = 1; i < pi->nr; i++) {
|
2014-11-04 18:50:23 +00:00
|
|
|
|
int fn2, fhe;
|
2014-01-27 17:14:42 +00:00
|
|
|
|
struct plot_data *entry = pi->entry + i;
|
2017-07-28 17:35:25 +00:00
|
|
|
|
|
2018-08-16 17:10:10 +00:00
|
|
|
|
gasmix = get_gasmix(dive, dc, entry->sec, &evg, gasmix);
|
2015-08-31 21:39:43 +00:00
|
|
|
|
amb_pressure = depth_to_bar(entry->depth, dive);
|
2018-04-07 15:52:16 +00:00
|
|
|
|
current_divemode = get_current_divemode(dc, entry->sec, &evd, ¤t_divemode);
|
2018-08-16 17:10:10 +00:00
|
|
|
|
fill_pressures(&entry->pressures, amb_pressure, gasmix, (current_divemode == OC) ? 0.0 : entry->o2pressure.mbar / 1000.0, current_divemode);
|
2014-12-29 04:56:58 +00:00
|
|
|
|
fn2 = (int)(1000.0 * entry->pressures.n2 / amb_pressure);
|
|
|
|
|
fhe = (int)(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.
|
2018-08-16 17:10:10 +00:00
|
|
|
|
struct gasmix gasmix2 = get_gasmix(dive, dc, entry->sec, &evg, gasmix);
|
|
|
|
|
entry->scr_OC_pO2.mbar = (int) depth_to_mbar(entry->depth, dive) * 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) };
|
2018-08-16 17:10:10 +00:00
|
|
|
|
entry->mod = (double)gas_mod(gasmix, modpO2, dive, 1).mm;
|
2014-03-31 10:52:46 +00:00
|
|
|
|
entry->end = (entry->depth + 10000) * (1000 - fhe) / 1000.0 - 10000;
|
2014-11-04 18:50:23 +00:00
|
|
|
|
entry->ead = (entry->depth + 10000) * fn2 / (double)N2_IN_AIR - 10000;
|
2014-01-27 17:14:42 +00:00
|
|
|
|
entry->eadd = (entry->depth + 10000) *
|
2014-09-15 12:55:20 +00:00
|
|
|
|
(entry->pressures.o2 / amb_pressure * O2_DENSITY +
|
|
|
|
|
entry->pressures.n2 / amb_pressure * N2_DENSITY +
|
|
|
|
|
entry->pressures.he / amb_pressure * HE_DENSITY) /
|
2014-08-30 15:46:47 +00:00
|
|
|
|
(O2_IN_AIR * O2_DENSITY + N2_IN_AIR * N2_DENSITY) * 1000 - 10000;
|
2018-08-16 17:10:10 +00:00
|
|
|
|
entry->density = gas_density(gasmix, depth_to_mbar(entry->depth, dive));
|
2014-01-27 17:14:42 +00:00
|
|
|
|
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-08-30 15:46:47 +00:00
|
|
|
|
|
2017-07-28 18:25:42 +00:00
|
|
|
|
void fill_o2_values(struct dive *dive, 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
|
|
|
|
|
|
|
|
|
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++)
|
2014-11-18 09:30:24 +00:00
|
|
|
|
last_sensor[j].mbar = pi->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++)
|
2014-11-18 09:30:24 +00:00
|
|
|
|
if (entry->o2sensor[j].mbar)
|
|
|
|
|
last_sensor[j].mbar = entry->o2sensor[j].mbar;
|
2014-10-13 19:19:21 +00:00
|
|
|
|
else
|
2014-11-18 09:30:24 +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,
|
2014-11-18 09:30:24 +00:00
|
|
|
|
amb_pressure.mbar = depth_to_mbar(entry->depth, dive);
|
2014-12-29 04:56:58 +00:00
|
|
|
|
o2pressure.mbar = calculate_ccr_po2(entry, dc); // ...calculate the po2 based on the sensor data
|
2014-11-18 09:30:24 +00:00
|
|
|
|
entry->o2pressure.mbar = MIN(o2pressure.mbar, amb_pressure.mbar);
|
2014-10-14 09:37:30 +00:00
|
|
|
|
} else {
|
2014-12-29 04:56:58 +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()
|
|
|
|
|
*/
|
|
|
|
|
static void debug_print_profiledata(struct plot_info *pi)
|
|
|
|
|
{
|
|
|
|
|
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");
|
|
|
|
|
for (i = 0; i < pi->nr; i++) {
|
|
|
|
|
entry = pi->entry + i;
|
2014-11-19 21:36:50 +00:00
|
|
|
|
fprintf(f1, "%d gas=%8d %8d ; dil=%8d %8d ; o2_sp= %d %d %d %d PO2= %f\n", i, SENSOR_PRESSURE(entry),
|
2014-11-17 11:25:00 +00:00
|
|
|
|
INTERPOLATED_PRESSURE(entry), O2CYLINDER_PRESSURE(entry), INTERPOLATED_O2CYLINDER_PRESSURE(entry),
|
2014-11-19 21:36:50 +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.
|
|
|
|
|
*/
|
2017-11-24 13:17:01 +00:00
|
|
|
|
void create_plot_info_new(struct dive *dive, struct divecomputer *dc, struct plot_info *pi, bool fast, struct deco_state *planner_ds)
|
2014-01-17 16:43:25 +00:00
|
|
|
|
{
|
2015-01-25 17:06:27 +00:00
|
|
|
|
int o2, he, o2max;
|
2016-02-06 04:45:18 +00:00
|
|
|
|
#ifndef SUBSURFACE_MOBILE
|
2017-11-22 19:42:33 +00:00
|
|
|
|
struct deco_state plot_deco_state;
|
|
|
|
|
init_decompression(&plot_deco_state, dive);
|
2017-11-29 05:44:11 +00:00
|
|
|
|
#else
|
2018-05-22 07:07:42 +00:00
|
|
|
|
UNUSED(planner_ds);
|
2016-02-06 04:45:18 +00:00
|
|
|
|
#endif
|
2014-05-12 17:58:15 +00:00
|
|
|
|
/* Create the new plot data */
|
|
|
|
|
free((void *)last_pi_entry_new);
|
2014-08-30 15:46:47 +00:00
|
|
|
|
|
2015-01-25 17:06:27 +00:00
|
|
|
|
get_dive_gas(dive, &o2, &he, &o2max);
|
2015-10-11 10:16:48 +00:00
|
|
|
|
if (dc->divemode == FREEDIVE){
|
|
|
|
|
pi->dive_type = FREEDIVE;
|
|
|
|
|
} else if (he > 0) {
|
2014-03-31 10:48:22 +00:00
|
|
|
|
pi->dive_type = TRIMIX;
|
|
|
|
|
} else {
|
|
|
|
|
if (o2)
|
|
|
|
|
pi->dive_type = NITROX;
|
|
|
|
|
else
|
|
|
|
|
pi->dive_type = AIR;
|
|
|
|
|
}
|
2015-10-11 10:16:48 +00:00
|
|
|
|
|
2014-02-18 03:50:19 +00:00
|
|
|
|
last_pi_entry_new = 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 */
|
2014-12-04 15:42:00 +00:00
|
|
|
|
if (!fast) {
|
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
|
|
|
|
for (int cyl = 0; cyl < MAX_CYLINDERS; cyl++)
|
|
|
|
|
populate_pressure_information(dive, dc, pi, cyl);
|
2014-12-04 15:42:00 +00:00
|
|
|
|
}
|
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 */
|
2016-02-06 04:45:18 +00:00
|
|
|
|
#ifndef SUBSURFACE_MOBILE
|
2017-11-24 13:17:01 +00:00
|
|
|
|
calculate_deco_information(&plot_deco_state, planner_ds, dive, dc, pi, false); /* and ceiling information, using gradient factor values in Preferences) */
|
2016-02-06 04:45:18 +00:00
|
|
|
|
#endif
|
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
|
|
|
|
|
|
2014-01-17 16:43:25 +00:00
|
|
|
|
pi->meandepth = dive->dc.meandepth.mm;
|
|
|
|
|
analyze_plot_info(pi);
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-17 15:19:09 +00:00
|
|
|
|
struct divecomputer *select_dc(struct dive *dive)
|
2013-01-01 18:20:22 +00:00
|
|
|
|
{
|
2014-03-17 15:19:09 +00:00
|
|
|
|
unsigned int max = number_of_computers(dive);
|
|
|
|
|
unsigned int i = dc_number;
|
2013-01-01 18:20:22 +00:00
|
|
|
|
|
2014-03-17 15:19:09 +00:00
|
|
|
|
/* Reset 'dc_number' if we've switched dives and it is now out of range */
|
|
|
|
|
if (i >= max)
|
|
|
|
|
dc_number = i = 0;
|
Add a "View next dive computer" menu item
This adds the capability to actually view all your dive computers, by
adding a menu item under "Log"->"View"->"Next DC" to show the next dive
computer.
Realistically, if you actually commonly use this, you'd use the
accelerator shortcut. Which right now is Ctrl-C ("C for Computer"),
which is probably a horrible choice.
I really would want to have nice "next/prev dive" accelerators too,
because the cursor keys don't work very well with the gtk focus issues.
Being able to switch between dives would also make the "just the dive
profile, maam" view (ctrl-2) much more useful.
The prev/next dive in the profile view should probably be done with a
keyboard action callback, which also avoids some of the limitations of
accelerators (ie you can make any key do the action). Some gtk person,
please?
Anyway, this commit only does the dive computer choice thing, and only
using the accelerators.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-17 17:37:07 +00:00
|
|
|
|
|
2014-03-17 15:19:09 +00:00
|
|
|
|
return get_dive_dc(dive, i);
|
Add a "View next dive computer" menu item
This adds the capability to actually view all your dive computers, by
adding a menu item under "Log"->"View"->"Next DC" to show the next dive
computer.
Realistically, if you actually commonly use this, you'd use the
accelerator shortcut. Which right now is Ctrl-C ("C for Computer"),
which is probably a horrible choice.
I really would want to have nice "next/prev dive" accelerators too,
because the cursor keys don't work very well with the gtk focus issues.
Being able to switch between dives would also make the "just the dive
profile, maam" view (ctrl-2) much more useful.
The prev/next dive in the profile view should probably be done with a
keyboard action callback, which also avoids some of the limitations of
accelerators (ie you can make any key do the action). Some gtk person,
please?
Anyway, this commit only does the dive computer choice thing, and only
using the accelerators.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-17 17:37:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-05 14:56:35 +00:00
|
|
|
|
static void plot_string(struct plot_info *pi, struct plot_data *entry, struct membuffer *b)
|
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;
|
2012-11-11 16:12:09 +00:00
|
|
|
|
|
2013-10-11 16:53:29 +00:00
|
|
|
|
depthvalue = get_depth_units(entry->depth, NULL, &depth_unit);
|
2018-02-24 11:06:27 +00:00
|
|
|
|
put_format_loc(b, translate("gettextFromC", "@: %d:%02d\nD: %.1f%s\n"), FRACTION(entry->sec, 60), depthvalue, depth_unit);
|
2017-09-13 20:18:31 +00:00
|
|
|
|
for (cyl = 0; cyl < MAX_CYLINDERS; cyl++) {
|
|
|
|
|
int mbar = GET_PRESSURE(entry, cyl);
|
|
|
|
|
if (!mbar)
|
|
|
|
|
continue;
|
2018-08-16 17:10:10 +00:00
|
|
|
|
struct gasmix mix = displayed_dive.cylinder[cyl].gasmix;
|
2017-09-13 20:18:31 +00:00
|
|
|
|
pressurevalue = get_pressure_units(mbar, &pressure_unit);
|
2018-02-24 11:06:27 +00:00
|
|
|
|
put_format_loc(b, translate("gettextFromC", "P: %d%s (%s)\n"), pressurevalue, pressure_unit, gasname(mix));
|
2012-11-11 16:12:09 +00:00
|
|
|
|
}
|
2013-10-11 16:53:29 +00:00
|
|
|
|
if (entry->temperature) {
|
|
|
|
|
tempvalue = get_temp_units(entry->temperature, &temp_unit);
|
2018-02-24 11:06:27 +00:00
|
|
|
|
put_format_loc(b, translate("gettextFromC", "T: %.1f%s\n"), tempvalue, temp_unit);
|
2012-11-11 16:12:09 +00:00
|
|
|
|
}
|
2013-10-04 05:57:48 +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 */
|
|
|
|
|
if (entry->speed > 0)
|
|
|
|
|
speedvalue *= -1;
|
2018-02-24 11:06:27 +00:00
|
|
|
|
put_format_loc(b, translate("gettextFromC", "V: %.1f%s\n"), speedvalue, vertical_speed_unit);
|
2014-06-09 03:51:13 +00:00
|
|
|
|
sacvalue = get_volume_units(entry->sac, &decimals, &unit);
|
2014-01-19 00:21:13 +00:00
|
|
|
|
if (entry->sac && prefs.show_sac)
|
2018-02-24 11:06:27 +00:00
|
|
|
|
put_format_loc(b, translate("gettextFromC", "SAC: %.*f%s/min\n"), decimals, sacvalue, unit);
|
2014-01-19 00:21:13 +00:00
|
|
|
|
if (entry->cns)
|
2018-02-24 11:06:27 +00:00
|
|
|
|
put_format_loc(b, translate("gettextFromC", "CNS: %u%%\n"), entry->cns);
|
2019-06-03 14:38:20 +00:00
|
|
|
|
if (prefs.pp_graphs.po2 && entry->pressures.o2 > 0) {
|
2019-05-11 20:45:49 +00:00
|
|
|
|
put_format_loc(b, translate("gettextFromC", "pO₂: %.2fbar\n"), entry->pressures.o2);
|
2019-06-03 14:38:20 +00:00
|
|
|
|
if (entry->scr_OC_pO2.mbar)
|
2019-06-07 07:36:15 +00:00
|
|
|
|
put_format_loc(b, translate("gettextFromC", "SCR ΔpO₂: %.2fbar\n"), entry->scr_OC_pO2.mbar/1000.0 - entry->pressures.o2);
|
2019-06-03 14:38:20 +00:00
|
|
|
|
}
|
2017-11-05 14:56:35 +00:00
|
|
|
|
if (prefs.pp_graphs.pn2 && entry->pressures.n2 > 0)
|
2019-05-11 20:45:49 +00:00
|
|
|
|
put_format_loc(b, translate("gettextFromC", "pN₂: %.2fbar\n"), entry->pressures.n2);
|
2017-11-05 14:56:35 +00:00
|
|
|
|
if (prefs.pp_graphs.phe && entry->pressures.he > 0)
|
2018-02-24 11:06:27 +00:00
|
|
|
|
put_format_loc(b, translate("gettextFromC", "pHe: %.2fbar\n"), entry->pressures.he);
|
2017-11-05 14:56:35 +00:00
|
|
|
|
if (prefs.mod && entry->mod > 0) {
|
2017-03-09 16:07:30 +00:00
|
|
|
|
mod = lrint(get_depth_units(lrint(entry->mod), NULL, &depth_unit));
|
2018-02-24 11:06:27 +00:00
|
|
|
|
put_format_loc(b, translate("gettextFromC", "MOD: %d%s\n"), mod, depth_unit);
|
2013-11-12 22:10:01 +00:00
|
|
|
|
}
|
2017-03-09 16:07:30 +00:00
|
|
|
|
eadd = lrint(get_depth_units(lrint(entry->eadd), NULL, &depth_unit));
|
2017-05-12 13:36:24 +00:00
|
|
|
|
|
2013-11-12 22:10:01 +00:00
|
|
|
|
if (prefs.ead) {
|
2014-03-31 10:48:22 +00:00
|
|
|
|
switch (pi->dive_type) {
|
|
|
|
|
case NITROX:
|
2017-11-05 14:56:35 +00:00
|
|
|
|
if (entry->ead > 0) {
|
|
|
|
|
ead = lrint(get_depth_units(lrint(entry->ead), NULL, &depth_unit));
|
2018-02-24 11:06:27 +00:00
|
|
|
|
put_format_loc(b, translate("gettextFromC", "EAD: %d%s\nEADD: %d%s / %.1fg/ℓ\n"), ead, depth_unit, eadd, depth_unit, entry->density);
|
2017-11-05 14:56:35 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2014-03-31 10:52:46 +00:00
|
|
|
|
case TRIMIX:
|
2017-11-05 14:56:35 +00:00
|
|
|
|
if (entry->end > 0) {
|
|
|
|
|
end = lrint(get_depth_units(lrint(entry->end), NULL, &depth_unit));
|
2018-02-24 11:06:27 +00:00
|
|
|
|
put_format_loc(b, translate("gettextFromC", "END: %d%s\nEADD: %d%s / %.1fg/ℓ\n"), end, depth_unit, eadd, depth_unit, entry->density);
|
2017-11-05 14:56:35 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2014-03-31 10:52:46 +00:00
|
|
|
|
case AIR:
|
2017-11-05 14:56:35 +00:00
|
|
|
|
if (entry->density > 0) {
|
2018-02-24 11:06:27 +00:00
|
|
|
|
put_format_loc(b, translate("gettextFromC", "Density: %.1fg/ℓ\n"), entry->density);
|
2017-11-05 14:56:35 +00:00
|
|
|
|
}
|
2015-10-21 21:35:41 +00:00
|
|
|
|
case 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
|
|
|
|
}
|
2012-12-01 21:02:30 +00:00
|
|
|
|
if (entry->stopdepth) {
|
|
|
|
|
depthvalue = get_depth_units(entry->stopdepth, NULL, &depth_unit);
|
2017-11-05 14:56:35 +00:00
|
|
|
|
if (entry->ndl > 0) {
|
2012-12-01 21:02:30 +00:00
|
|
|
|
/* this is a safety stop as we still have ndl */
|
|
|
|
|
if (entry->stoptime)
|
2018-02-24 11:06:27 +00:00
|
|
|
|
put_format_loc(b, translate("gettextFromC", "Safety stop: %umin @ %.0f%s\n"), DIV_UP(entry->stoptime, 60),
|
|
|
|
|
depthvalue, depth_unit);
|
2012-12-01 21:02:30 +00:00
|
|
|
|
else
|
2018-02-24 11:06:27 +00:00
|
|
|
|
put_format_loc(b, translate("gettextFromC", "Safety stop: unknown time @ %.0f%s\n"),
|
|
|
|
|
depthvalue, depth_unit);
|
2012-12-01 21:02:30 +00:00
|
|
|
|
} else {
|
|
|
|
|
/* actual deco stop */
|
|
|
|
|
if (entry->stoptime)
|
2018-02-24 11:06:27 +00:00
|
|
|
|
put_format_loc(b, translate("gettextFromC", "Deco: %umin @ %.0f%s\n"), DIV_UP(entry->stoptime, 60),
|
|
|
|
|
depthvalue, depth_unit);
|
2012-12-01 21:02:30 +00:00
|
|
|
|
else
|
2018-02-24 11:06:27 +00:00
|
|
|
|
put_format_loc(b, translate("gettextFromC", "Deco: unknown time @ %.0f%s\n"),
|
|
|
|
|
depthvalue, depth_unit);
|
2012-12-01 21:02:30 +00:00
|
|
|
|
}
|
2012-12-31 02:11:01 +00:00
|
|
|
|
} else if (entry->in_deco) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
put_string(b, translate("gettextFromC", "In deco\n"));
|
2017-11-05 14:56:35 +00:00
|
|
|
|
} else if (entry->ndl >= 0) {
|
2018-02-24 11:06:27 +00:00
|
|
|
|
put_format_loc(b, translate("gettextFromC", "NDL: %umin\n"), DIV_UP(entry->ndl, 60));
|
2013-07-05 13:19:41 +00:00
|
|
|
|
}
|
2014-07-09 20:13:36 +00:00
|
|
|
|
if (entry->tts)
|
2018-02-24 11:06:27 +00:00
|
|
|
|
put_format_loc(b, translate("gettextFromC", "TTS: %umin\n"), DIV_UP(entry->tts, 60));
|
2013-11-13 18:20:09 +00:00
|
|
|
|
if (entry->stopdepth_calc && entry->stoptime_calc) {
|
|
|
|
|
depthvalue = get_depth_units(entry->stopdepth_calc, NULL, &depth_unit);
|
2018-02-24 11:06:27 +00:00
|
|
|
|
put_format_loc(b, translate("gettextFromC", "Deco: %umin @ %.0f%s (calc)\n"), DIV_UP(entry->stoptime_calc, 60),
|
|
|
|
|
depthvalue, depth_unit);
|
2013-11-13 18:20:09 +00:00
|
|
|
|
} else if (entry->in_deco_calc) {
|
|
|
|
|
/* 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. */
|
2014-02-28 04:09:57 +00:00
|
|
|
|
put_string(b, translate("gettextFromC", "In deco (calc)\n"));
|
2014-04-16 20:03:44 +00:00
|
|
|
|
} else if (prefs.calcndltts && entry->ndl_calc != 0) {
|
2015-10-13 09:21:14 +00:00
|
|
|
|
if(entry->ndl_calc < MAX_PROFILE_DECO)
|
2018-02-24 11:06:27 +00:00
|
|
|
|
put_format_loc(b, translate("gettextFromC", "NDL: %umin (calc)\n"), DIV_UP(entry->ndl_calc, 60));
|
2015-10-13 09:21:14 +00:00
|
|
|
|
else
|
2018-02-24 11:06:27 +00:00
|
|
|
|
put_string(b, translate("gettextFromC", "NDL: >2h (calc)\n"));
|
2015-10-13 09:21:14 +00:00
|
|
|
|
}
|
|
|
|
|
if (entry->tts_calc) {
|
|
|
|
|
if (entry->tts_calc < MAX_PROFILE_DECO)
|
2018-02-24 11:06:27 +00:00
|
|
|
|
put_format_loc(b, translate("gettextFromC", "TTS: %umin (calc)\n"), DIV_UP(entry->tts_calc, 60));
|
2015-10-13 09:21:14 +00:00
|
|
|
|
else
|
2018-02-24 11:06:27 +00:00
|
|
|
|
put_string(b, translate("gettextFromC", "TTS: >2h (calc)\n"));
|
2012-12-01 21:02:30 +00:00
|
|
|
|
}
|
Add support for RBT reported sample value
RBT (Remaining Bottom Time) is a value calculated on the fly by some air
integrated divecomputers, for example Uwatec devices. This value is an
estimation based in some heuristic around time function pressure
gradients. This way, RBT would be the time a diver can spend at actual
depth without running out of gas (taking account of ascent, deco, if
required, and rock bottom gas reserve, if set).
Older Uwatec devices just made the calculus and only stored alarm events
if this time value reached zero, but modern devices store the value each
sample, in minutes.
It seems that Suunto Eon Steel is storing RBT values too, in seconds.
Libdivecomputer has supported RBT for a while, but Subsurface just
printed it to stdout and dropped it.
This adds support for RBT value on subsurface sample structure and shows
it in the profile's info box, right under TTS(calc), if selected, where
these two values can be easily compared by humans.
Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-22 15:02:33 +00:00
|
|
|
|
if (entry->rbt)
|
2018-02-24 11:06:27 +00:00
|
|
|
|
put_format_loc(b, translate("gettextFromC", "RBT: %umin\n"), DIV_UP(entry->rbt, 60));
|
2019-01-29 13:27:27 +00:00
|
|
|
|
if (prefs.decoinfo) {
|
|
|
|
|
if (entry->surface_gf > 0)
|
|
|
|
|
put_format(b, translate("gettextFromC", "Surface GF %.0f%%\n"), entry->surface_gf);
|
|
|
|
|
if (entry->ceiling) {
|
|
|
|
|
depthvalue = get_depth_units(entry->ceiling, NULL, &depth_unit);
|
|
|
|
|
put_format_loc(b, translate("gettextFromC", "Calculated ceiling %.0f%s\n"), depthvalue, depth_unit);
|
|
|
|
|
if (prefs.calcalltissues) {
|
|
|
|
|
int k;
|
|
|
|
|
for (k = 0; k < 16; k++) {
|
|
|
|
|
if (entry->ceilings[k]) {
|
|
|
|
|
depthvalue = get_depth_units(entry->ceilings[k], NULL, &depth_unit);
|
|
|
|
|
put_format_loc(b, translate("gettextFromC", "Tissue %.0fmin: %.1f%s\n"), buehlmann_N2_t_halflife[k], depthvalue, depth_unit);
|
|
|
|
|
}
|
2013-11-12 22:10:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-01-14 00:24:58 +00:00
|
|
|
|
}
|
2018-04-10 19:20:38 +00:00
|
|
|
|
if (entry->icd_warning)
|
|
|
|
|
put_format(b, "%s", translate("gettextFromC", "ICD in leading tissue\n"));
|
2014-04-16 20:03:44 +00:00
|
|
|
|
if (entry->heartbeat && prefs.hrgraph)
|
2018-02-24 11:06:27 +00:00
|
|
|
|
put_format_loc(b, translate("gettextFromC", "heart rate: %d\n"), entry->heartbeat);
|
2017-11-05 14:56:35 +00:00
|
|
|
|
if (entry->bearing >= 0)
|
2018-02-24 11:06:27 +00:00
|
|
|
|
put_format_loc(b, translate("gettextFromC", "bearing: %d\n"), entry->bearing);
|
2014-12-31 19:34:11 +00:00
|
|
|
|
if (entry->running_sum) {
|
2015-01-01 12:27:57 +00:00
|
|
|
|
depthvalue = get_depth_units(entry->running_sum / entry->sec, NULL, &depth_unit);
|
2018-02-24 11:06:27 +00:00
|
|
|
|
put_format_loc(b, translate("gettextFromC", "mean depth to here %.1f%s\n"), depthvalue, depth_unit);
|
2014-12-31 19:34:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-19 00:21:13 +00:00
|
|
|
|
strip_mb(b);
|
2012-11-11 12:20:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-10 15:37:18 +00:00
|
|
|
|
struct plot_data *get_plot_details_new(struct plot_info *pi, int time, struct membuffer *mb)
|
2014-02-05 16:53:57 +00:00
|
|
|
|
{
|
|
|
|
|
struct plot_data *entry = NULL;
|
|
|
|
|
int i;
|
|
|
|
|
|
2017-11-05 14:56:35 +00:00
|
|
|
|
/* The two first and the two last plot entries do not have useful data */
|
|
|
|
|
for (i = 2; i < pi->nr - 2; i++) {
|
2014-02-05 16:53:57 +00:00
|
|
|
|
entry = pi->entry + i;
|
|
|
|
|
if (entry->sec >= time)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (entry)
|
2017-11-05 14:56:35 +00:00
|
|
|
|
plot_string(pi, entry, mb);
|
2018-02-17 20:21:16 +00:00
|
|
|
|
return entry;
|
2014-02-05 16:53:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-25 00:07:07 +00:00
|
|
|
|
/* Compare two plot_data entries and writes the results into a string */
|
|
|
|
|
void compare_samples(struct plot_data *e1, struct plot_data *e2, char *buf, int bufsize, int sum)
|
|
|
|
|
{
|
|
|
|
|
struct plot_data *start, *stop, *data;
|
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
|
|
|
|
char *buf2 = malloc(bufsize);
|
2013-11-30 08:13:27 +00:00
|
|
|
|
int avg_speed, max_asc_speed, max_desc_speed;
|
2013-09-25 00:07:07 +00:00
|
|
|
|
int delta_depth, avg_depth, max_depth, min_depth;
|
2017-08-26 19:14:46 +00:00
|
|
|
|
int bar_used, last_pressure, pressurevalue;
|
2013-09-25 00:07:07 +00:00
|
|
|
|
int count, last_sec, delta_time;
|
2016-07-18 07:27:38 +00:00
|
|
|
|
bool crossed_tankchange = false;
|
2013-09-25 00:07:07 +00:00
|
|
|
|
|
|
|
|
|
double depthvalue, speedvalue;
|
|
|
|
|
|
|
|
|
|
if (bufsize > 0)
|
|
|
|
|
buf[0] = '\0';
|
2013-12-10 23:53:28 +00:00
|
|
|
|
if (e1 == NULL || e2 == NULL) {
|
|
|
|
|
free(buf2);
|
2013-09-25 00:07:07 +00:00
|
|
|
|
return;
|
2013-12-10 23:53:28 +00:00
|
|
|
|
}
|
2013-09-25 00:07:07 +00:00
|
|
|
|
|
|
|
|
|
if (e1->sec < e2->sec) {
|
|
|
|
|
start = e1;
|
|
|
|
|
stop = e2;
|
|
|
|
|
} else if (e1->sec > e2->sec) {
|
|
|
|
|
start = e2;
|
|
|
|
|
stop = e1;
|
|
|
|
|
} else {
|
2013-12-10 23:53:28 +00:00
|
|
|
|
free(buf2);
|
2013-09-25 00:07:07 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
count = 0;
|
2013-10-03 18:36:46 +00:00
|
|
|
|
avg_speed = 0;
|
2013-11-30 08:13:27 +00:00
|
|
|
|
max_asc_speed = 0;
|
|
|
|
|
max_desc_speed = 0;
|
2013-09-25 00:07:07 +00:00
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
delta_depth = abs(start->depth - stop->depth);
|
2016-03-10 15:37:18 +00:00
|
|
|
|
delta_time = abs(start->sec - stop->sec);
|
2013-09-25 00:07:07 +00:00
|
|
|
|
avg_depth = 0;
|
|
|
|
|
max_depth = 0;
|
|
|
|
|
min_depth = INT_MAX;
|
|
|
|
|
bar_used = 0;
|
|
|
|
|
|
|
|
|
|
last_sec = start->sec;
|
Start cleaning up sensor indexing for multiple sensors
This is a very timid start at making us actually use multiple sensors
without the magical special case for just CCR oxygen tracking.
It mainly does:
- turn the "sample->sensor" index into an array of two indexes, to
match the pressures themselves.
- get rid of dive->{oxygen_cylinder_index,diluent_cylinder_index},
since a CCR dive should now simply set the sample->sensor[] indices
correctly instead.
- in a couple of places, start actually looping over the sensors rather
than special-case the O2 case (although often the small "loops" are
just unrolled, since it's just two cases.
but in many cases we still end up only covering the zero sensor case,
because the CCR O2 sensor code coverage was fairly limited.
It's entirely possible (even likely) that this migth break some existing
case: it tries to be a fairly direct ("stupid") translation of the old
code, but unlike the preparatory patch this does actually does change
some semantics.
For example, right now the git loader code assumes that if the git save
data contains a o2pressure entry, it just hardcodes the O2 sensor index
to 1.
In fact, one issue is going to simply be that our file formats do not
have that multiple sensor format, but instead had very clearly encoded
things as being the CCR O2 pressure sensor.
But this is hopefully close to usable, and I will need feedback (and
maybe test cases) from people who have existing CCR dives with pressure
data.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-21 02:49:45 +00:00
|
|
|
|
last_pressure = GET_PRESSURE(start, 0);
|
2013-09-25 00:07:07 +00:00
|
|
|
|
|
2013-10-03 18:36:46 +00:00
|
|
|
|
data = start;
|
2013-09-25 00:07:07 +00:00
|
|
|
|
while (data != stop) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
data = start + count;
|
2013-09-25 00:07:07 +00:00
|
|
|
|
if (sum)
|
2014-02-28 04:09:57 +00:00
|
|
|
|
avg_speed += abs(data->speed) * (data->sec - last_sec);
|
2013-09-25 00:07:07 +00:00
|
|
|
|
else
|
2014-02-28 04:09:57 +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
|
|
|
|
|
2013-11-30 08:13:27 +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
|
|
|
|
|
|
|
|
|
if (data->depth < min_depth)
|
|
|
|
|
min_depth = data->depth;
|
|
|
|
|
if (data->depth > max_depth)
|
|
|
|
|
max_depth = data->depth;
|
2016-07-18 07:27:38 +00:00
|
|
|
|
/* Try to detect gas changes - this hack might work for some side mount scenarios? */
|
Start cleaning up sensor indexing for multiple sensors
This is a very timid start at making us actually use multiple sensors
without the magical special case for just CCR oxygen tracking.
It mainly does:
- turn the "sample->sensor" index into an array of two indexes, to
match the pressures themselves.
- get rid of dive->{oxygen_cylinder_index,diluent_cylinder_index},
since a CCR dive should now simply set the sample->sensor[] indices
correctly instead.
- in a couple of places, start actually looping over the sensors rather
than special-case the O2 case (although often the small "loops" are
just unrolled, since it's just two cases.
but in many cases we still end up only covering the zero sensor case,
because the CCR O2 sensor code coverage was fairly limited.
It's entirely possible (even likely) that this migth break some existing
case: it tries to be a fairly direct ("stupid") translation of the old
code, but unlike the preparatory patch this does actually does change
some semantics.
For example, right now the git loader code assumes that if the git save
data contains a o2pressure entry, it just hardcodes the O2 sensor index
to 1.
In fact, one issue is going to simply be that our file formats do not
have that multiple sensor format, but instead had very clearly encoded
things as being the CCR O2 pressure sensor.
But this is hopefully close to usable, and I will need feedback (and
maybe test cases) from people who have existing CCR dives with pressure
data.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-21 02:49:45 +00:00
|
|
|
|
if (GET_PRESSURE(data, 0) < last_pressure + 2000)
|
|
|
|
|
bar_used += last_pressure - GET_PRESSURE(data, 0);
|
2013-09-25 00:07:07 +00:00
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
count += 1;
|
2013-09-25 00:07:07 +00:00
|
|
|
|
last_sec = data->sec;
|
Start cleaning up sensor indexing for multiple sensors
This is a very timid start at making us actually use multiple sensors
without the magical special case for just CCR oxygen tracking.
It mainly does:
- turn the "sample->sensor" index into an array of two indexes, to
match the pressures themselves.
- get rid of dive->{oxygen_cylinder_index,diluent_cylinder_index},
since a CCR dive should now simply set the sample->sensor[] indices
correctly instead.
- in a couple of places, start actually looping over the sensors rather
than special-case the O2 case (although often the small "loops" are
just unrolled, since it's just two cases.
but in many cases we still end up only covering the zero sensor case,
because the CCR O2 sensor code coverage was fairly limited.
It's entirely possible (even likely) that this migth break some existing
case: it tries to be a fairly direct ("stupid") translation of the old
code, but unlike the preparatory patch this does actually does change
some semantics.
For example, right now the git loader code assumes that if the git save
data contains a o2pressure entry, it just hardcodes the O2 sensor index
to 1.
In fact, one issue is going to simply be that our file formats do not
have that multiple sensor format, but instead had very clearly encoded
things as being the CCR O2 pressure sensor.
But this is hopefully close to usable, and I will need feedback (and
maybe test cases) from people who have existing CCR dives with pressure
data.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-21 02:49:45 +00:00
|
|
|
|
last_pressure = GET_PRESSURE(data, 0);
|
2013-09-25 00:07:07 +00:00
|
|
|
|
}
|
2014-02-28 04:09:57 +00:00
|
|
|
|
avg_depth /= stop->sec - start->sec;
|
|
|
|
|
avg_speed /= stop->sec - start->sec;
|
2013-09-25 00:07:07 +00:00
|
|
|
|
|
2019-05-11 20:45:49 +00:00
|
|
|
|
snprintf_loc(buf, bufsize, translate("gettextFromC", "ΔT:%d:%02dmin"), delta_time / 60, delta_time % 60);
|
2013-09-25 00:07:07 +00:00
|
|
|
|
memcpy(buf2, buf, bufsize);
|
|
|
|
|
|
|
|
|
|
depthvalue = get_depth_units(delta_depth, NULL, &depth_unit);
|
2019-05-11 20:45:49 +00:00
|
|
|
|
snprintf_loc(buf, bufsize, translate("gettextFromC", "%s ΔD:%.1f%s"), buf2, depthvalue, depth_unit);
|
2013-09-25 00:07:07 +00:00
|
|
|
|
memcpy(buf2, buf, bufsize);
|
|
|
|
|
|
|
|
|
|
depthvalue = get_depth_units(min_depth, NULL, &depth_unit);
|
2019-05-11 20:45:49 +00:00
|
|
|
|
snprintf_loc(buf, bufsize, translate("gettextFromC", "%s ↓D:%.1f%s"), buf2, depthvalue, depth_unit);
|
2013-09-25 00:07:07 +00:00
|
|
|
|
memcpy(buf2, buf, bufsize);
|
|
|
|
|
|
|
|
|
|
depthvalue = get_depth_units(max_depth, NULL, &depth_unit);
|
2019-05-11 20:45:49 +00:00
|
|
|
|
snprintf_loc(buf, bufsize, translate("gettextFromC", "%s ↑D:%.1f%s"), buf2, depthvalue, depth_unit);
|
2013-09-25 00:07:07 +00:00
|
|
|
|
memcpy(buf2, buf, bufsize);
|
|
|
|
|
|
|
|
|
|
depthvalue = get_depth_units(avg_depth, NULL, &depth_unit);
|
2019-05-11 20:45:49 +00:00
|
|
|
|
snprintf_loc(buf, bufsize, translate("gettextFromC", "%s øD:%.1f%s\n"), buf2, depthvalue, depth_unit);
|
2013-09-25 00:07:07 +00:00
|
|
|
|
memcpy(buf2, buf, bufsize);
|
|
|
|
|
|
2013-11-30 08:13:27 +00:00
|
|
|
|
speedvalue = get_vertical_speed_units(abs(max_desc_speed), NULL, &vertical_speed_unit);
|
2019-05-11 20:45:49 +00:00
|
|
|
|
snprintf_loc(buf, bufsize, translate("gettextFromC", "%s ↓V:%.2f%s"), buf2, speedvalue, vertical_speed_unit);
|
2013-09-25 00:07:07 +00:00
|
|
|
|
memcpy(buf2, buf, bufsize);
|
|
|
|
|
|
2013-11-30 08:13:27 +00:00
|
|
|
|
speedvalue = get_vertical_speed_units(abs(max_asc_speed), NULL, &vertical_speed_unit);
|
2019-05-11 20:45:49 +00:00
|
|
|
|
snprintf_loc(buf, bufsize, translate("gettextFromC", "%s ↑V:%.2f%s"), buf2, speedvalue, vertical_speed_unit);
|
2013-09-25 00:07:07 +00:00
|
|
|
|
memcpy(buf2, buf, bufsize);
|
|
|
|
|
|
2013-10-18 17:30:51 +00:00
|
|
|
|
speedvalue = get_vertical_speed_units(abs(avg_speed), NULL, &vertical_speed_unit);
|
2019-05-11 20:45:49 +00:00
|
|
|
|
snprintf_loc(buf, bufsize, translate("gettextFromC", "%s øV:%.2f%s"), buf2, speedvalue, vertical_speed_unit);
|
2013-09-25 00:07:07 +00:00
|
|
|
|
memcpy(buf2, buf, bufsize);
|
|
|
|
|
|
|
|
|
|
/* Only print if gas has been used */
|
|
|
|
|
if (bar_used) {
|
|
|
|
|
pressurevalue = get_pressure_units(bar_used, &pressure_unit);
|
|
|
|
|
memcpy(buf2, buf, bufsize);
|
2019-05-11 20:45:49 +00:00
|
|
|
|
snprintf_loc(buf, bufsize, translate("gettextFromC", "%s ΔP:%d%s"), buf2, pressurevalue, pressure_unit);
|
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
|
|
|
|
cylinder_t *cyl = displayed_dive.cylinder + 0;
|
2016-07-18 07:27:38 +00:00
|
|
|
|
/* if we didn't cross a tank change and know the cylidner size as well, show SAC rate */
|
|
|
|
|
if (!crossed_tankchange && cyl->type.size.mliter) {
|
|
|
|
|
double volume_value;
|
|
|
|
|
int volume_precision;
|
|
|
|
|
const char *volume_unit;
|
|
|
|
|
struct plot_data *first = start;
|
|
|
|
|
struct plot_data *last = stop;
|
Start cleaning up sensor indexing for multiple sensors
This is a very timid start at making us actually use multiple sensors
without the magical special case for just CCR oxygen tracking.
It mainly does:
- turn the "sample->sensor" index into an array of two indexes, to
match the pressures themselves.
- get rid of dive->{oxygen_cylinder_index,diluent_cylinder_index},
since a CCR dive should now simply set the sample->sensor[] indices
correctly instead.
- in a couple of places, start actually looping over the sensors rather
than special-case the O2 case (although often the small "loops" are
just unrolled, since it's just two cases.
but in many cases we still end up only covering the zero sensor case,
because the CCR O2 sensor code coverage was fairly limited.
It's entirely possible (even likely) that this migth break some existing
case: it tries to be a fairly direct ("stupid") translation of the old
code, but unlike the preparatory patch this does actually does change
some semantics.
For example, right now the git loader code assumes that if the git save
data contains a o2pressure entry, it just hardcodes the O2 sensor index
to 1.
In fact, one issue is going to simply be that our file formats do not
have that multiple sensor format, but instead had very clearly encoded
things as being the CCR O2 pressure sensor.
But this is hopefully close to usable, and I will need feedback (and
maybe test cases) from people who have existing CCR dives with pressure
data.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-21 02:49:45 +00:00
|
|
|
|
while (first < stop && GET_PRESSURE(first, 0) == 0)
|
2016-07-18 07:27:38 +00:00
|
|
|
|
first++;
|
Start cleaning up sensor indexing for multiple sensors
This is a very timid start at making us actually use multiple sensors
without the magical special case for just CCR oxygen tracking.
It mainly does:
- turn the "sample->sensor" index into an array of two indexes, to
match the pressures themselves.
- get rid of dive->{oxygen_cylinder_index,diluent_cylinder_index},
since a CCR dive should now simply set the sample->sensor[] indices
correctly instead.
- in a couple of places, start actually looping over the sensors rather
than special-case the O2 case (although often the small "loops" are
just unrolled, since it's just two cases.
but in many cases we still end up only covering the zero sensor case,
because the CCR O2 sensor code coverage was fairly limited.
It's entirely possible (even likely) that this migth break some existing
case: it tries to be a fairly direct ("stupid") translation of the old
code, but unlike the preparatory patch this does actually does change
some semantics.
For example, right now the git loader code assumes that if the git save
data contains a o2pressure entry, it just hardcodes the O2 sensor index
to 1.
In fact, one issue is going to simply be that our file formats do not
have that multiple sensor format, but instead had very clearly encoded
things as being the CCR O2 pressure sensor.
But this is hopefully close to usable, and I will need feedback (and
maybe test cases) from people who have existing CCR dives with pressure
data.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-21 02:49:45 +00:00
|
|
|
|
while (last > first && GET_PRESSURE(last, 0) == 0)
|
2016-07-18 07:27:38 +00:00
|
|
|
|
last--;
|
|
|
|
|
|
Start cleaning up sensor indexing for multiple sensors
This is a very timid start at making us actually use multiple sensors
without the magical special case for just CCR oxygen tracking.
It mainly does:
- turn the "sample->sensor" index into an array of two indexes, to
match the pressures themselves.
- get rid of dive->{oxygen_cylinder_index,diluent_cylinder_index},
since a CCR dive should now simply set the sample->sensor[] indices
correctly instead.
- in a couple of places, start actually looping over the sensors rather
than special-case the O2 case (although often the small "loops" are
just unrolled, since it's just two cases.
but in many cases we still end up only covering the zero sensor case,
because the CCR O2 sensor code coverage was fairly limited.
It's entirely possible (even likely) that this migth break some existing
case: it tries to be a fairly direct ("stupid") translation of the old
code, but unlike the preparatory patch this does actually does change
some semantics.
For example, right now the git loader code assumes that if the git save
data contains a o2pressure entry, it just hardcodes the O2 sensor index
to 1.
In fact, one issue is going to simply be that our file formats do not
have that multiple sensor format, but instead had very clearly encoded
things as being the CCR O2 pressure sensor.
But this is hopefully close to usable, and I will need feedback (and
maybe test cases) from people who have existing CCR dives with pressure
data.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-21 02:49:45 +00:00
|
|
|
|
pressure_t first_pressure = { GET_PRESSURE(first, 0) };
|
|
|
|
|
pressure_t stop_pressure = { GET_PRESSURE(last, 0) };
|
2016-07-18 07:27:38 +00:00
|
|
|
|
int volume_used = gas_volume(cyl, first_pressure) - gas_volume(cyl, stop_pressure);
|
|
|
|
|
|
|
|
|
|
/* Mean pressure in ATM */
|
|
|
|
|
double atm = depth_to_atm(avg_depth, &displayed_dive);
|
|
|
|
|
|
|
|
|
|
/* milliliters per minute */
|
2017-03-09 16:07:30 +00:00
|
|
|
|
int sac = lrint(volume_used / atm * 60 / delta_time);
|
2016-07-18 07:27:38 +00:00
|
|
|
|
memcpy(buf2, buf, bufsize);
|
|
|
|
|
volume_value = get_volume_units(sac, &volume_precision, &volume_unit);
|
2018-02-24 18:44:49 +00:00
|
|
|
|
snprintf_loc(buf, bufsize, translate("gettextFromC", "%s SAC:%.*f%s/min"), buf2, volume_precision, volume_value, volume_unit);
|
2016-07-18 07:27:38 +00:00
|
|
|
|
}
|
2013-09-25 00:07:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free(buf2);
|
|
|
|
|
}
|