2017-04-27 18:24:53 +00:00
|
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2011-09-20 19:40:34 +00:00
|
|
|
|
/* profile.c */
|
2012-08-26 21:41:05 +00:00
|
|
|
|
/* creates all the necessary data for drawing the dive profile
|
2011-09-20 19:40:34 +00:00
|
|
|
|
*/
|
2013-10-06 15:55:58 +00:00
|
|
|
|
#include "gettext.h"
|
2013-09-25 00:07:07 +00:00
|
|
|
|
#include <limits.h>
|
2013-10-05 07:29:09 +00:00
|
|
|
|
#include <string.h>
|
2014-10-14 08:46:40 +00:00
|
|
|
|
#include <assert.h>
|
2011-08-31 17:20:46 +00:00
|
|
|
|
|
|
|
|
|
#include "dive.h"
|
|
|
|
|
#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"
|
2017-01-07 02:01:14 +00:00
|
|
|
|
#include "qthelperfromc.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
|
|
|
|
|
|
|
|
|
|
|
2013-05-16 16:09:06 +00:00
|
|
|
|
int selected_dive = -1; /* careful: 0 is a valid value */
|
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-30 15:46:47 +00:00
|
|
|
|
void populate_pressure_information(struct dive *, struct divecomputer *, struct plot_info *, int);
|
2014-08-24 18:48:22 +00:00
|
|
|
|
|
2015-10-25 00:26:15 +00:00
|
|
|
|
extern bool in_planner();
|
|
|
|
|
extern pressure_t first_ceiling_pressure;
|
|
|
|
|
|
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",
|
|
|
|
|
i, entry->cylinderindex, entry->sec,
|
|
|
|
|
entry->pressure[0], entry->pressure[1],
|
|
|
|
|
entry->sec / 60, entry->sec % 60,
|
|
|
|
|
entry->temperature, entry->depth, entry->stopdepth, entry->stoptime, entry->ndl, entry->smoothed,
|
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 */
|
2014-10-11 11:25:52 +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
|
|
|
|
{
|
2016-03-10 15:37:18 +00:00
|
|
|
|
int index = entry1->cylinderindex;
|
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
|
|
|
|
|
|
|
|
|
if (entry2->cylinderindex != index)
|
|
|
|
|
return 0;
|
2013-02-25 23:23:16 +00:00
|
|
|
|
if (duration <= 0)
|
2013-02-21 02:57:50 +00:00
|
|
|
|
return 0;
|
2013-02-25 23:23:16 +00:00
|
|
|
|
a.mbar = GET_PRESSURE(entry1);
|
|
|
|
|
b.mbar = GET_PRESSURE(entry2);
|
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.
|
|
|
|
|
*/
|
2013-11-20 18:52:17 +00:00
|
|
|
|
int get_cylinder_index(struct dive *dive, struct event *ev)
|
2011-10-23 14:52:45 +00:00
|
|
|
|
{
|
2016-04-02 20:06:54 +00:00
|
|
|
|
int best;
|
|
|
|
|
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);
|
|
|
|
|
best = find_best_gasmix_match(mix, dive->cylinder, 0);
|
|
|
|
|
return best < 0 ? 0 : best;
|
2011-10-23 14:52:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-11 18:15:03 +00:00
|
|
|
|
struct event *get_next_event(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;
|
|
|
|
|
}
|
|
|
|
|
|
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_cylinder_index(struct plot_info *pi, int i, int cylinderindex, int end)
|
2011-10-23 14:52:45 +00:00
|
|
|
|
{
|
|
|
|
|
while (i < pi->nr) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
struct plot_data *entry = pi->entry + i;
|
2011-10-23 14:52:45 +00:00
|
|
|
|
if (entry->sec > end)
|
|
|
|
|
break;
|
|
|
|
|
if (entry->cylinderindex != cylinderindex) {
|
|
|
|
|
entry->cylinderindex = cylinderindex;
|
|
|
|
|
entry->pressure[0] = 0;
|
|
|
|
|
}
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-28 20:48:15 +00:00
|
|
|
|
/* normally the first cylinder has index 0... if not, we need to fix this up here */
|
2016-03-23 17:04:30 +00:00
|
|
|
|
static int set_first_cylinder_index(struct plot_info *pi, int i, int cylinderindex, int end)
|
2014-10-28 20:48:15 +00:00
|
|
|
|
{
|
|
|
|
|
while (i < pi->nr) {
|
|
|
|
|
struct plot_data *entry = pi->entry + i;
|
|
|
|
|
if (entry->sec > end)
|
|
|
|
|
break;
|
|
|
|
|
entry->cylinderindex = cylinderindex;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-24 02:51:27 +00:00
|
|
|
|
static void check_gas_change_events(struct dive *dive, struct divecomputer *dc, struct plot_info *pi)
|
2011-10-23 14:52:45 +00:00
|
|
|
|
{
|
|
|
|
|
int i = 0, cylinderindex = 0;
|
2012-11-24 02:51:27 +00:00
|
|
|
|
struct event *ev = get_next_event(dc->events, "gaschange");
|
2011-10-23 14:52:45 +00:00
|
|
|
|
|
2014-10-28 20:48:15 +00:00
|
|
|
|
// for dive computers that tell us their first gas as an event on the first sample
|
|
|
|
|
// we need to make sure things are setup correctly
|
2014-11-17 11:25:00 +00:00
|
|
|
|
cylinderindex = explicit_first_cylinder(dive, dc);
|
2016-03-23 17:04:30 +00:00
|
|
|
|
set_first_cylinder_index(pi, 0, cylinderindex, INT_MAX);
|
2014-11-17 11:25:00 +00:00
|
|
|
|
|
|
|
|
|
if (!ev)
|
|
|
|
|
return;
|
2014-10-28 20:48:15 +00:00
|
|
|
|
|
2011-10-23 14:52:45 +00:00
|
|
|
|
do {
|
|
|
|
|
i = set_cylinder_index(pi, i, cylinderindex, ev->time.seconds);
|
|
|
|
|
cylinderindex = get_cylinder_index(dive, ev);
|
2012-11-09 20:38:00 +00:00
|
|
|
|
ev = get_next_event(ev->next, "gaschange");
|
2011-10-23 14:52:45 +00:00
|
|
|
|
} while (ev);
|
2016-03-23 17:04:30 +00:00
|
|
|
|
set_cylinder_index(pi, i, cylinderindex, INT_MAX);
|
2011-10-23 14:52:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-26 13:22:41 +00:00
|
|
|
|
static void check_setpoint_events(struct dive *dive, struct divecomputer *dc, struct plot_info *pi)
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
pressure_t setpoint;
|
2016-03-07 00:39:19 +00:00
|
|
|
|
(void) dive;
|
2014-11-26 13:22:41 +00:00
|
|
|
|
setpoint.mbar = 0;
|
|
|
|
|
struct event *ev = get_next_event(dc->events, "SP change");
|
|
|
|
|
|
|
|
|
|
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;
|
2016-03-23 17:04:30 +00:00
|
|
|
|
unsigned 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;
|
|
|
|
|
int pressure = s->cylinderpressure.mbar;
|
|
|
|
|
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;
|
|
|
|
|
if (heartbeat < minhr)
|
|
|
|
|
minhr = heartbeat;
|
2014-01-15 15:34:55 +00:00
|
|
|
|
|
|
|
|
|
if (depth > maxdepth)
|
|
|
|
|
maxdepth = s->depth.mm;
|
|
|
|
|
if ((depth > SURFACE_THRESHOLD || lastdepth > SURFACE_THRESHOLD) &&
|
|
|
|
|
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)
|
|
|
|
|
minhr = 0;
|
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; \
|
2014-02-28 04:09:57 +00:00
|
|
|
|
SENSOR_PRESSURE(entry) = 0; \
|
2015-01-16 12:49:12 +00:00
|
|
|
|
entry->sac = _sac; \
|
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
|
|
|
|
{
|
2016-03-07 00:39:19 +00:00
|
|
|
|
|
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;
|
2016-03-07 00:39:19 +00:00
|
|
|
|
(void) dive;
|
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
|
|
|
|
pi->has_ndl |= sample->ndl.seconds;
|
|
|
|
|
entry->in_deco = sample->in_deco;
|
|
|
|
|
entry->cns = sample->cns;
|
2015-01-10 23:01:15 +00:00
|
|
|
|
if (dc->divemode == CCR) {
|
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
|
|
|
|
}
|
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
|
|
|
|
/* FIXME! sensor index -> cylinder index translation! */
|
2014-12-29 04:56:58 +00:00
|
|
|
|
// entry->cylinderindex = sample->sensor;
|
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
|
|
|
|
SENSOR_PRESSURE(entry) = sample->cylinderpressure.mbar;
|
2014-11-17 11:25:00 +00:00
|
|
|
|
O2CYLINDER_PRESSURE(entry) = sample->o2cylinderpressure.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
|
|
|
|
|
|
2016-03-10 15:37:18 +00:00
|
|
|
|
static void populate_cylinder_pressure_data(int idx, int start, int end, struct plot_info *pi, bool o2flag)
|
2011-09-08 15:33:02 +00:00
|
|
|
|
{
|
2013-01-07 00:09:48 +00:00
|
|
|
|
int i;
|
2011-09-08 15:33:02 +00:00
|
|
|
|
|
2013-01-07 00:09:48 +00:00
|
|
|
|
/* First: check that none of the entries has sensor pressure for this cylinder index */
|
|
|
|
|
for (i = 0; i < pi->nr; i++) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
struct plot_data *entry = pi->entry + i;
|
2014-11-17 16:39:40 +00:00
|
|
|
|
if (entry->cylinderindex != idx && !o2flag)
|
2013-01-07 00:09:48 +00:00
|
|
|
|
continue;
|
2014-11-17 16:39:40 +00:00
|
|
|
|
if (CYLINDER_PRESSURE(o2flag, entry))
|
2013-01-07 00:09:48 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2012-12-06 18:01:16 +00:00
|
|
|
|
|
2013-01-07 00:09:48 +00:00
|
|
|
|
/* Then: populate the first entry with the beginning cylinder pressure */
|
|
|
|
|
for (i = 0; i < pi->nr; i++) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
struct plot_data *entry = pi->entry + i;
|
2014-11-17 16:39:40 +00:00
|
|
|
|
if (entry->cylinderindex != idx && !o2flag)
|
2013-01-07 00:09:48 +00:00
|
|
|
|
continue;
|
2014-11-17 16:39:40 +00:00
|
|
|
|
if (o2flag)
|
|
|
|
|
O2CYLINDER_PRESSURE(entry) = start;
|
|
|
|
|
else
|
|
|
|
|
SENSOR_PRESSURE(entry) = start;
|
2013-01-07 00:09:48 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2013-01-04 04:45:20 +00:00
|
|
|
|
|
2013-01-07 00:09:48 +00:00
|
|
|
|
/* .. and the last entry with the ending cylinder pressure */
|
2013-01-29 21:10:46 +00:00
|
|
|
|
for (i = pi->nr; --i >= 0; /* nothing */) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
struct plot_data *entry = pi->entry + i;
|
2014-11-17 16:39:40 +00:00
|
|
|
|
if (entry->cylinderindex != idx && !o2flag)
|
2013-01-07 00:09:48 +00:00
|
|
|
|
continue;
|
2014-11-17 16:39:40 +00:00
|
|
|
|
if (o2flag)
|
|
|
|
|
O2CYLINDER_PRESSURE(entry) = end;
|
|
|
|
|
else
|
|
|
|
|
SENSOR_PRESSURE(entry) = end;
|
2013-01-07 00:09:48 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-10-23 14:18:30 +00:00
|
|
|
|
|
2015-10-22 19:47:39 +00:00
|
|
|
|
/*
|
|
|
|
|
* Calculate the sac rate between the two plot entries 'first' and 'last'.
|
|
|
|
|
*
|
|
|
|
|
* Everything in between has a cylinder pressure, and it's all the same
|
|
|
|
|
* cylinder.
|
|
|
|
|
*/
|
|
|
|
|
static int sac_between(struct dive *dive, struct plot_data *first, struct plot_data *last)
|
|
|
|
|
{
|
|
|
|
|
int airuse;
|
|
|
|
|
double pressuretime;
|
|
|
|
|
pressure_t a, b;
|
|
|
|
|
cylinder_t *cyl;
|
|
|
|
|
|
|
|
|
|
if (first == last)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
/* Calculate air use - trivial */
|
|
|
|
|
a.mbar = GET_PRESSURE(first);
|
|
|
|
|
b.mbar = GET_PRESSURE(last);
|
|
|
|
|
cyl = dive->cylinder + first->cylinderindex;
|
|
|
|
|
airuse = gas_volume(cyl, a) - gas_volume(cyl, b);
|
|
|
|
|
if (airuse <= 0)
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Try to do the momentary sac rate for this entry, averaging over one
|
|
|
|
|
* minute.
|
|
|
|
|
*/
|
|
|
|
|
static void fill_sac(struct dive *dive, struct plot_info *pi, int idx)
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
if (!GET_PRESSURE(entry))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Try to go back 30 seconds to get 'first'.
|
|
|
|
|
* Stop if the sensor changed, or if we went back too far.
|
|
|
|
|
*/
|
|
|
|
|
first = entry;
|
|
|
|
|
time = entry->sec - 30;
|
|
|
|
|
while (idx > 0) {
|
|
|
|
|
struct plot_data *prev = first-1;
|
|
|
|
|
if (prev->cylinderindex != first->cylinderindex)
|
|
|
|
|
break;
|
|
|
|
|
if (prev->depth < SURFACE_THRESHOLD && first->depth < SURFACE_THRESHOLD)
|
|
|
|
|
break;
|
|
|
|
|
if (prev->sec < time)
|
|
|
|
|
break;
|
|
|
|
|
if (!GET_PRESSURE(prev))
|
|
|
|
|
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->cylinderindex != last->cylinderindex)
|
|
|
|
|
break;
|
|
|
|
|
if (next->depth < SURFACE_THRESHOLD && last->depth < SURFACE_THRESHOLD)
|
|
|
|
|
break;
|
|
|
|
|
if (next->sec > time)
|
|
|
|
|
break;
|
|
|
|
|
if (!GET_PRESSURE(next))
|
|
|
|
|
break;
|
|
|
|
|
last = next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Ok, now calculate the SAC between 'first' and 'last' */
|
|
|
|
|
entry->sac = sac_between(dive, first, last);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-14 21:48:43 +00:00
|
|
|
|
static void calculate_sac(struct dive *dive, struct plot_info *pi)
|
|
|
|
|
{
|
2015-11-07 21:15:49 +00:00
|
|
|
|
for (int i = 0; i < pi->nr; i++)
|
2015-10-22 19:47:39 +00:00
|
|
|
|
fill_sac(dive, pi, i);
|
2013-10-14 21:48:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-01-07 00:09:48 +00:00
|
|
|
|
static void populate_secondary_sensor_data(struct divecomputer *dc, struct plot_info *pi)
|
|
|
|
|
{
|
2016-03-07 00:39:19 +00:00
|
|
|
|
(void) dc;
|
|
|
|
|
(void) 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
|
|
|
|
|
2013-01-07 00:09:48 +00:00
|
|
|
|
static void setup_gas_sensor_pressure(struct dive *dive, struct divecomputer *dc, struct plot_info *pi)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
struct divecomputer *secondary;
|
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 00:09:48 +00:00
|
|
|
|
/* First, populate the pressures with the manual cylinder data.. */
|
|
|
|
|
for (i = 0; i < MAX_CYLINDERS; i++) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
cylinder_t *cyl = dive->cylinder + i;
|
|
|
|
|
int start = cyl->start.mbar ?: cyl->sample_start.mbar;
|
|
|
|
|
int end = cyl->end.mbar ?: cyl->sample_end.mbar;
|
2013-01-07 00:09:48 +00:00
|
|
|
|
|
|
|
|
|
if (!start || !end)
|
|
|
|
|
continue;
|
|
|
|
|
|
2014-11-17 16:39:40 +00:00
|
|
|
|
populate_cylinder_pressure_data(i, start, end, pi, dive->cylinder[i].cylinder_use == OXYGEN);
|
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 */
|
2015-08-31 21:25:28 +00:00
|
|
|
|
static void calculate_ndl_tts(struct plot_data *entry, struct dive *dive, double surface_pressure)
|
2014-02-28 04:09:57 +00:00
|
|
|
|
{
|
2013-11-12 22:09:59 +00:00
|
|
|
|
/* FIXME: This should be configurable */
|
|
|
|
|
/* ascent speed up to first deco stop */
|
|
|
|
|
const int ascent_s_per_step = 1;
|
|
|
|
|
const int ascent_mm_per_step = 200; /* 12 m/min */
|
|
|
|
|
/* ascent speed between deco stops */
|
|
|
|
|
const int ascent_s_per_deco_step = 1;
|
|
|
|
|
const int ascent_mm_per_deco_step = 16; /* 1 m/min */
|
|
|
|
|
/* 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? */
|
2015-08-31 21:39:43 +00:00
|
|
|
|
int next_stop = ROUND_UP(deco_allowed_depth(tissue_tolerance_calc(dive, depth_to_bar(entry->depth, dive)),
|
2015-08-31 21:25:28 +00:00
|
|
|
|
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? */
|
|
|
|
|
int cylinderindex = entry->cylinderindex;
|
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 */
|
2015-10-12 20:34:15 +00:00
|
|
|
|
while (entry->ndl_calc < MAX_PROFILE_DECO && deco_allowed_depth(tissue_tolerance_calc(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;
|
2015-08-31 21:39:43 +00:00
|
|
|
|
add_segment(depth_to_bar(entry->depth, dive),
|
2014-12-29 04:56:58 +00:00
|
|
|
|
&dive->cylinder[cylinderindex].gasmix, time_stepsize, entry->o2pressure.mbar, dive, 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 */
|
2013-11-13 18:20:09 +00:00
|
|
|
|
for (; ascent_depth > next_stop; ascent_depth -= ascent_mm_per_step, entry->tts_calc += ascent_s_per_step) {
|
2015-08-31 21:39:43 +00:00
|
|
|
|
add_segment(depth_to_bar(ascent_depth, dive),
|
2015-08-31 21:25:28 +00:00
|
|
|
|
&dive->cylinder[cylinderindex].gasmix, ascent_s_per_step, entry->o2pressure.mbar, dive, prefs.decosac);
|
2015-08-31 21:39:43 +00:00
|
|
|
|
next_stop = ROUND_UP(deco_allowed_depth(tissue_tolerance_calc(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;
|
2015-08-31 21:39:43 +00:00
|
|
|
|
add_segment(depth_to_bar(ascent_depth, dive),
|
2015-08-31 21:25:28 +00:00
|
|
|
|
&dive->cylinder[cylinderindex].gasmix, time_stepsize, entry->o2pressure.mbar, dive, prefs.decosac);
|
2013-11-12 22:09:59 +00:00
|
|
|
|
|
2016-03-10 15:37:18 +00:00
|
|
|
|
if (deco_allowed_depth(tissue_tolerance_calc(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 */
|
2014-02-28 04:09:57 +00:00
|
|
|
|
for (; ascent_depth > next_stop; ascent_depth -= ascent_mm_per_deco_step, entry->tts_calc += ascent_s_per_deco_step)
|
2015-08-31 21:39:43 +00:00
|
|
|
|
add_segment(depth_to_bar(ascent_depth, dive),
|
2014-11-18 09:30:24 +00:00
|
|
|
|
&dive->cylinder[cylinderindex].gasmix, ascent_s_per_deco_step, entry->o2pressure.mbar, dive, 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.
|
|
|
|
|
*/
|
2014-02-04 19:34:16 +00:00
|
|
|
|
void calculate_deco_information(struct dive *dive, struct divecomputer *dc, struct plot_info *pi, bool print_mode)
|
2013-01-07 00:09:48 +00:00
|
|
|
|
{
|
2015-10-25 00:26:15 +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;
|
2016-04-08 23:22:46 +00:00
|
|
|
|
int deco_time = 0, prev_deco_time = 10000000;
|
2017-05-25 22:45:53 +00:00
|
|
|
|
struct deco_state *cache_data_initial = NULL;
|
2015-10-25 00:26:15 +00:00
|
|
|
|
/* For VPM-B outside the planner, cache the initial deco state for CVA iterations */
|
2017-01-07 02:01:14 +00:00
|
|
|
|
if (decoMode() == VPMB && !in_planner())
|
2015-10-25 00:26:15 +00:00
|
|
|
|
cache_deco_state(&cache_data_initial);
|
|
|
|
|
/* 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 */
|
|
|
|
|
while ((abs(prev_deco_time - deco_time) >= 30) && (count_iteration < 10)) {
|
2016-04-08 23:22:46 +00:00
|
|
|
|
int last_ndl_tts_calc_time = 0, first_ceiling = 0, current_ceiling, final_tts = 0 , time_clear_ceiling = 0, time_deep_ceiling = 0;
|
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;
|
|
|
|
|
|
|
|
|
|
entry->ambpressure = depth_to_bar(entry->depth, dive);
|
2016-10-26 05:21:47 +00:00
|
|
|
|
entry->gfline = get_gf(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);
|
|
|
|
|
add_segment(depth_to_bar(depth, dive),
|
|
|
|
|
&dive->cylinder[entry->cylinderindex].gasmix, time_stepsize, entry->o2pressure.mbar, dive, entry->sac);
|
|
|
|
|
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-01-07 02:01:14 +00:00
|
|
|
|
if (decoMode() == VPMB && !in_planner() && (entry - 1)->ceiling >= first_ceiling && first_iteration == true) {
|
2015-10-25 00:26:15 +00:00
|
|
|
|
nuclear_regeneration(t1);
|
|
|
|
|
vpmb_start_gradient();
|
|
|
|
|
/* For CVA calculations, start by guessing deco time = dive time remaining */
|
|
|
|
|
deco_time = pi->maxtime - t1;
|
|
|
|
|
vpmb_next_gradient(deco_time, surface_pressure / 1000.0);
|
|
|
|
|
}
|
|
|
|
|
entry->ceiling = deco_allowed_depth(tissue_tolerance_calc(dive, depth_to_bar(entry->depth, dive)), surface_pressure, dive, !prefs.calcceiling3m);
|
2016-04-07 13:06:44 +00:00
|
|
|
|
if (prefs.calcceiling3m)
|
|
|
|
|
current_ceiling = deco_allowed_depth(tissue_tolerance_calc(dive, depth_to_bar(entry->depth, dive)), surface_pressure, dive, true);
|
|
|
|
|
else
|
|
|
|
|
current_ceiling = entry->ceiling;
|
2015-10-25 00:26:15 +00:00
|
|
|
|
/* If using VPM-B outside the planner, take first_ceiling_pressure as the deepest ceiling */
|
2017-01-07 02:01:14 +00:00
|
|
|
|
if (decoMode() == VPMB && !in_planner()) {
|
2016-04-07 13:06:44 +00:00
|
|
|
|
if (current_ceiling > first_ceiling) {
|
|
|
|
|
time_deep_ceiling = t1;
|
|
|
|
|
first_ceiling = current_ceiling;
|
|
|
|
|
first_ceiling_pressure.mbar = depth_to_mbar(first_ceiling, dive);
|
|
|
|
|
if (first_iteration) {
|
|
|
|
|
nuclear_regeneration(t1);
|
|
|
|
|
vpmb_start_gradient();
|
|
|
|
|
/* For CVA calculations, start by guessing deco time = dive time remaining */
|
|
|
|
|
deco_time = pi->maxtime - t1;
|
|
|
|
|
vpmb_next_gradient(deco_time, surface_pressure / 1000.0);
|
|
|
|
|
}
|
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;
|
|
|
|
|
else if (time_clear_ceiling == 0)
|
|
|
|
|
time_clear_ceiling = t1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (j = 0; j < 16; j++) {
|
2017-05-25 20:29:25 +00:00
|
|
|
|
double m_value = deco_state->buehlmann_inertgas_a[j] + entry->ambpressure / deco_state->buehlmann_inertgas_b[j];
|
|
|
|
|
entry->ceilings[j] = deco_allowed_depth(deco_state->tolerated_by_tissue[j], surface_pressure, dive, 1);
|
|
|
|
|
entry->percentages[j] = deco_state->tissue_inertgas_saturation[j] < entry->ambpressure ?
|
|
|
|
|
lrint(deco_state->tissue_inertgas_saturation[j] / entry->ambpressure * AMB_PERCENTAGE) :
|
|
|
|
|
lrint(AMB_PERCENTAGE + (deco_state->tissue_inertgas_saturation[j] - entry->ambpressure) / (m_value - entry->ambpressure) * (100.0 - AMB_PERCENTAGE));
|
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;
|
2015-10-25 00:26:15 +00:00
|
|
|
|
cache_deco_state(&cache_data);
|
|
|
|
|
calculate_ndl_tts(entry, dive, surface_pressure);
|
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-05-25 22:45:53 +00:00
|
|
|
|
restore_deco_state(cache_data, false);
|
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()) {
|
2015-10-25 00:26:15 +00:00
|
|
|
|
prev_deco_time = deco_time;
|
|
|
|
|
// Do we need to update deco_time?
|
|
|
|
|
if (final_tts > 0)
|
|
|
|
|
deco_time = pi->maxtime + final_tts - time_deep_ceiling;
|
|
|
|
|
else if (time_clear_ceiling > 0)
|
|
|
|
|
deco_time = time_clear_ceiling - time_deep_ceiling;
|
|
|
|
|
vpmb_next_gradient(deco_time, surface_pressure / 1000.0);
|
|
|
|
|
final_tts = 0;
|
|
|
|
|
last_ndl_tts_calc_time = 0;
|
|
|
|
|
first_ceiling = 0;
|
|
|
|
|
first_iteration = false;
|
|
|
|
|
count_iteration ++;
|
2017-05-25 22:45:53 +00:00
|
|
|
|
restore_deco_state(cache_data_initial, false);
|
2015-10-25 00:26:15 +00:00
|
|
|
|
} else {
|
|
|
|
|
// With Buhlmann, or not in planner, iterating isn't needed. This makes the while condition false.
|
|
|
|
|
prev_deco_time = deco_time = 0;
|
2013-11-12 22:09:59 +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
|
|
|
|
|
dump_tissues();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
static void calculate_gas_information_new(struct dive *dive, struct plot_info *pi)
|
2014-01-27 17:14:42 +00:00
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
double amb_pressure;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
int cylinderindex = entry->cylinderindex;
|
|
|
|
|
|
2015-08-31 21:39:43 +00:00
|
|
|
|
amb_pressure = depth_to_bar(entry->depth, dive);
|
2014-01-27 17:14:42 +00:00
|
|
|
|
|
2015-01-19 10:32:27 +00:00
|
|
|
|
fill_pressures(&entry->pressures, amb_pressure, &dive->cylinder[cylinderindex].gasmix, entry->o2pressure.mbar / 1000.0, dive->dc.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);
|
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) };
|
2015-07-05 22:07:39 +00:00
|
|
|
|
entry->mod = (double)gas_mod(&dive->cylinder[cylinderindex].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;
|
2017-05-12 13:36:24 +00:00
|
|
|
|
entry->density = gas_density(&dive->cylinder[cylinderindex].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
|
|
|
|
|
2014-10-13 19:19:21 +00:00
|
|
|
|
void fill_o2_values(struct divecomputer *dc, struct plot_info *pi, struct dive *dive)
|
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
|
|
|
|
|
|
|
|
|
if (dc->divemode == CCR) {
|
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.
|
|
|
|
|
*/
|
2014-12-04 15:42:00 +00:00
|
|
|
|
void create_plot_info_new(struct dive *dive, struct divecomputer *dc, struct plot_info *pi, bool fast)
|
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
|
2014-01-28 23:11:14 +00:00
|
|
|
|
init_decompression(dive);
|
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_gas_change_events(dive, dc, pi); /* Populate the gas index from the gas change events */
|
|
|
|
|
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) {
|
|
|
|
|
populate_pressure_information(dive, dc, pi, false); /* .. calculate missing pressure entries for all gasses except o2 */
|
2015-01-10 23:01:15 +00:00
|
|
|
|
if (dc->divemode == CCR) /* For CCR dives.. */
|
2014-12-04 15:42:00 +00:00
|
|
|
|
populate_pressure_information(dive, dc, pi, true); /* .. calculate missing o2 gas pressure entries */
|
|
|
|
|
}
|
2014-12-29 04:56:58 +00:00
|
|
|
|
fill_o2_values(dc, pi, dive); /* .. and insert the O2 sensor data having 0 values. */
|
|
|
|
|
calculate_sac(dive, pi); /* Calculate sac */
|
2016-02-06 04:45:18 +00:00
|
|
|
|
#ifndef SUBSURFACE_MOBILE
|
2014-10-13 19:19:21 +00:00
|
|
|
|
calculate_deco_information(dive, dc, pi, false); /* and ceiling information, using gradient factor values in Preferences) */
|
2016-02-06 04:45:18 +00:00
|
|
|
|
#endif
|
2014-12-29 04:56:58 +00:00
|
|
|
|
calculate_gas_information_new(dive, 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
|
|
|
|
}
|
|
|
|
|
|
2014-03-31 10:48:22 +00:00
|
|
|
|
static void plot_string(struct plot_info *pi, struct plot_data *entry, struct membuffer *b, bool has_ndl)
|
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;
|
2014-06-09 03:51:13 +00:00
|
|
|
|
int decimals;
|
|
|
|
|
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);
|
2014-02-28 04:09:57 +00:00
|
|
|
|
put_format(b, translate("gettextFromC", "@: %d:%02d\nD: %.1f%s\n"), FRACTION(entry->sec, 60), depthvalue, depth_unit);
|
2013-10-11 16:53:29 +00:00
|
|
|
|
if (GET_PRESSURE(entry)) {
|
|
|
|
|
pressurevalue = get_pressure_units(GET_PRESSURE(entry), &pressure_unit);
|
2014-02-28 04:09:57 +00:00
|
|
|
|
put_format(b, translate("gettextFromC", "P: %d%s\n"), pressurevalue, pressure_unit);
|
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);
|
2014-02-28 04:09:57 +00:00
|
|
|
|
put_format(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;
|
2014-02-28 04:09:57 +00:00
|
|
|
|
put_format(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)
|
2014-06-09 18:23:05 +00:00
|
|
|
|
put_format(b, translate("gettextFromC", "SAC: %.*f%s/min\n"), decimals, sacvalue, unit);
|
2014-01-19 00:21:13 +00:00
|
|
|
|
if (entry->cns)
|
2014-02-28 04:09:57 +00:00
|
|
|
|
put_format(b, translate("gettextFromC", "CNS: %u%%\n"), entry->cns);
|
2014-01-19 00:21:13 +00:00
|
|
|
|
if (prefs.pp_graphs.po2)
|
2014-09-15 12:55:20 +00:00
|
|
|
|
put_format(b, translate("gettextFromC", "pO%s: %.2fbar\n"), UTF8_SUBSCRIPT_2, entry->pressures.o2);
|
2014-01-19 00:21:13 +00:00
|
|
|
|
if (prefs.pp_graphs.pn2)
|
2014-09-15 12:55:20 +00:00
|
|
|
|
put_format(b, translate("gettextFromC", "pN%s: %.2fbar\n"), UTF8_SUBSCRIPT_2, entry->pressures.n2);
|
2014-01-19 00:21:13 +00:00
|
|
|
|
if (prefs.pp_graphs.phe)
|
2014-09-15 12:55:20 +00:00
|
|
|
|
put_format(b, translate("gettextFromC", "pHe: %.2fbar\n"), entry->pressures.he);
|
2013-11-12 22:10:01 +00:00
|
|
|
|
if (prefs.mod) {
|
2017-03-09 16:07:30 +00:00
|
|
|
|
mod = lrint(get_depth_units(lrint(entry->mod), NULL, &depth_unit));
|
2014-02-28 04:09:57 +00:00
|
|
|
|
put_format(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-03-09 16:07:30 +00:00
|
|
|
|
ead = lrint(get_depth_units(lrint(entry->ead), NULL, &depth_unit));
|
2017-05-16 19:24:39 +00:00
|
|
|
|
put_format(b, translate("gettextFromC", "EAD: %d%s\nEADD: %d%s / %.1fg/ℓ\n"), ead, depth_unit, eadd, depth_unit, entry->density);
|
2014-03-31 10:52:46 +00:00
|
|
|
|
break;
|
|
|
|
|
case TRIMIX:
|
2017-03-09 16:07:30 +00:00
|
|
|
|
end = lrint(get_depth_units(lrint(entry->end), NULL, &depth_unit));
|
2017-05-16 19:24:39 +00:00
|
|
|
|
put_format(b, translate("gettextFromC", "END: %d%s\nEADD: %d%s / %.1fg/ℓ\n"), end, depth_unit, eadd, depth_unit, entry->density);
|
2014-03-31 10:48:22 +00:00
|
|
|
|
break;
|
2014-03-31 10:52:46 +00:00
|
|
|
|
case AIR:
|
2017-05-16 19:24:39 +00:00
|
|
|
|
put_format(b, translate("gettectFromC", "Density: %.1fg/ℓ\n"), entry->density);
|
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);
|
|
|
|
|
if (entry->ndl) {
|
|
|
|
|
/* this is a safety stop as we still have ndl */
|
|
|
|
|
if (entry->stoptime)
|
2017-03-13 05:49:44 +00:00
|
|
|
|
put_format(b, translate("gettextFromC", "Safety stop: %umin @ %.0f%s\n"), DIV_UP(entry->stoptime, 60),
|
2014-02-28 04:09:57 +00:00
|
|
|
|
depthvalue, depth_unit);
|
2012-12-01 21:02:30 +00:00
|
|
|
|
else
|
2017-03-13 05:49:44 +00:00
|
|
|
|
put_format(b, translate("gettextFromC", "Safety stop: unknown time @ %.0f%s\n"),
|
2014-02-28 04:09:57 +00:00
|
|
|
|
depthvalue, depth_unit);
|
2012-12-01 21:02:30 +00:00
|
|
|
|
} else {
|
|
|
|
|
/* actual deco stop */
|
|
|
|
|
if (entry->stoptime)
|
2014-02-28 04:09:57 +00:00
|
|
|
|
put_format(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
|
2017-02-20 07:54:21 +00:00
|
|
|
|
put_format(b, translate("gettextFromC", "Deco: unknown time @ %.0f%s\n"),
|
2014-02-28 04:09:57 +00:00
|
|
|
|
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"));
|
2012-12-01 21:02:30 +00:00
|
|
|
|
} else if (has_ndl) {
|
2014-02-28 04:09:57 +00:00
|
|
|
|
put_format(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)
|
|
|
|
|
put_format(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);
|
2014-02-28 04:09:57 +00:00
|
|
|
|
put_format(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)
|
|
|
|
|
put_format(b, translate("gettextFromC", "NDL: %umin (calc)\n"), DIV_UP(entry->ndl_calc, 60));
|
|
|
|
|
else
|
2015-10-13 16:58:10 +00:00
|
|
|
|
put_format(b, "%s", 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)
|
|
|
|
|
put_format(b, translate("gettextFromC", "TTS: %umin (calc)\n"), DIV_UP(entry->tts_calc, 60));
|
|
|
|
|
else
|
2015-10-13 16:58:10 +00:00
|
|
|
|
put_format(b, "%s", 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)
|
|
|
|
|
put_format(b, translate("gettextFromC", "RBT: %umin\n"), DIV_UP(entry->rbt, 60));
|
2013-11-12 22:10:01 +00:00
|
|
|
|
if (entry->ceiling) {
|
|
|
|
|
depthvalue = get_depth_units(entry->ceiling, NULL, &depth_unit);
|
2014-02-28 04:09:57 +00:00
|
|
|
|
put_format(b, translate("gettextFromC", "Calculated ceiling %.0f%s\n"), depthvalue, depth_unit);
|
2014-04-16 20:03:44 +00:00
|
|
|
|
if (prefs.calcalltissues) {
|
2013-11-12 22:10:01 +00:00
|
|
|
|
int k;
|
2014-02-28 04:09:57 +00:00
|
|
|
|
for (k = 0; k < 16; k++) {
|
2014-01-16 04:50:56 +00:00
|
|
|
|
if (entry->ceilings[k]) {
|
2013-11-12 22:10:01 +00:00
|
|
|
|
depthvalue = get_depth_units(entry->ceilings[k], NULL, &depth_unit);
|
2015-08-23 13:58:50 +00:00
|
|
|
|
put_format(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
|
|
|
|
}
|
2014-04-16 20:03:44 +00:00
|
|
|
|
if (entry->heartbeat && prefs.hrgraph)
|
2017-02-20 08:29:20 +00:00
|
|
|
|
put_format(b, translate("gettextFromC", "heart rate: %d\n"), entry->heartbeat);
|
2014-01-19 00:21:13 +00:00
|
|
|
|
if (entry->bearing)
|
2014-02-28 04:09:57 +00:00
|
|
|
|
put_format(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);
|
2014-12-31 19:34:11 +00:00
|
|
|
|
put_format(b, translate("gettextFromC", "mean depth to here %.1f%s\n"), depthvalue, depth_unit);
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < pi->nr; i++) {
|
|
|
|
|
entry = pi->entry + i;
|
|
|
|
|
if (entry->sec >= time)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (entry)
|
2014-03-31 10:48:22 +00:00
|
|
|
|
plot_string(pi, entry, mb, pi->has_ndl);
|
2014-09-19 06:48:19 +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;
|
2016-07-18 07:27:38 +00:00
|
|
|
|
int bar_used, last_pressure, pressurevalue, last_cylidx;
|
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;
|
|
|
|
|
last_pressure = GET_PRESSURE(start);
|
2016-07-18 07:27:38 +00:00
|
|
|
|
last_cylidx = start->cylinderindex;
|
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? */
|
2014-02-28 04:09:57 +00:00
|
|
|
|
if (GET_PRESSURE(data) < last_pressure + 2000)
|
|
|
|
|
bar_used += last_pressure - GET_PRESSURE(data);
|
2013-09-25 00:07:07 +00:00
|
|
|
|
|
2016-07-18 07:27:38 +00:00
|
|
|
|
if (data->cylinderindex != last_cylidx)
|
|
|
|
|
/* if we change tanks, don't try to do SAC rate later */
|
|
|
|
|
crossed_tankchange = true;
|
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
count += 1;
|
2013-09-25 00:07:07 +00:00
|
|
|
|
last_sec = data->sec;
|
|
|
|
|
last_pressure = GET_PRESSURE(data);
|
|
|
|
|
}
|
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
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
|
snprintf(buf, bufsize, translate("gettextFromC", "%sT: %d:%02d min"), UTF8_DELTA, 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);
|
2014-02-28 04:09:57 +00:00
|
|
|
|
snprintf(buf, bufsize, translate("gettextFromC", "%s %sD:%.1f%s"), buf2, UTF8_DELTA, depthvalue, depth_unit);
|
2013-09-25 00:07:07 +00:00
|
|
|
|
memcpy(buf2, buf, bufsize);
|
|
|
|
|
|
|
|
|
|
depthvalue = get_depth_units(min_depth, NULL, &depth_unit);
|
2014-02-28 04:09:57 +00:00
|
|
|
|
snprintf(buf, bufsize, translate("gettextFromC", "%s %sD:%.1f%s"), buf2, UTF8_DOWNWARDS_ARROW, depthvalue, depth_unit);
|
2013-09-25 00:07:07 +00:00
|
|
|
|
memcpy(buf2, buf, bufsize);
|
|
|
|
|
|
|
|
|
|
depthvalue = get_depth_units(max_depth, NULL, &depth_unit);
|
2014-02-28 04:09:57 +00:00
|
|
|
|
snprintf(buf, bufsize, translate("gettextFromC", "%s %sD:%.1f%s"), buf2, UTF8_UPWARDS_ARROW, depthvalue, depth_unit);
|
2013-09-25 00:07:07 +00:00
|
|
|
|
memcpy(buf2, buf, bufsize);
|
|
|
|
|
|
|
|
|
|
depthvalue = get_depth_units(avg_depth, NULL, &depth_unit);
|
2014-02-28 04:09:57 +00:00
|
|
|
|
snprintf(buf, bufsize, translate("gettextFromC", "%s %sD:%.1f%s\n"), buf2, UTF8_AVERAGE, 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);
|
2014-02-28 04:09:57 +00:00
|
|
|
|
snprintf(buf, bufsize, translate("gettextFromC", "%s%sV:%.2f%s"), buf2, UTF8_DOWNWARDS_ARROW, 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);
|
2014-02-28 04:09:57 +00:00
|
|
|
|
snprintf(buf, bufsize, translate("gettextFromC", "%s %sV:%.2f%s"), buf2, UTF8_UPWARDS_ARROW, 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);
|
2014-02-28 04:09:57 +00:00
|
|
|
|
snprintf(buf, bufsize, translate("gettextFromC", "%s %sV:%.2f%s"), buf2, UTF8_AVERAGE, 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);
|
2014-02-28 04:09:57 +00:00
|
|
|
|
snprintf(buf, bufsize, translate("gettextFromC", "%s %sP:%d %s"), buf2, UTF8_DELTA, pressurevalue, pressure_unit);
|
2016-07-18 07:27:38 +00:00
|
|
|
|
cylinder_t *cyl = displayed_dive.cylinder + start->cylinderindex;
|
|
|
|
|
/* 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;
|
|
|
|
|
while (first < stop && GET_PRESSURE(first) == 0)
|
|
|
|
|
first++;
|
|
|
|
|
while (last > first && GET_PRESSURE(last) == 0)
|
|
|
|
|
last--;
|
|
|
|
|
|
|
|
|
|
pressure_t first_pressure = { GET_PRESSURE(first) };
|
|
|
|
|
pressure_t stop_pressure = { GET_PRESSURE(last) };
|
|
|
|
|
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);
|
2017-02-20 09:39:54 +00:00
|
|
|
|
snprintf(buf, bufsize, translate("gettextFromC", "%s SAC: %.*f%s"), 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);
|
|
|
|
|
}
|