mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Switch verify_gas_exists to take gasmix argument
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
fece3f321f
commit
bd142bbee2
2 changed files with 23 additions and 27 deletions
8
dive.h
8
dive.h
|
@ -118,6 +118,14 @@ static inline bool gasmix_is_air(const struct gasmix *gasmix)
|
||||||
return is_air(gasmix->o2.permille, gasmix->he.permille);
|
return is_air(gasmix->o2.permille, gasmix->he.permille);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* in the planner we use a null gasmix to indicate that we keep using the gas as before
|
||||||
|
* this is BAD as a null gasmix can also be interpreted as air.
|
||||||
|
* DANGER DANGER DANGER */
|
||||||
|
static inline bool gasmix_is_null(const struct gasmix *gasmix)
|
||||||
|
{
|
||||||
|
return gasmix->he.permille == 0 && gasmix->o2.permille == 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Linear interpolation between 'a' and 'b', when we are 'part'way into the 'whole' distance from a to b */
|
/* Linear interpolation between 'a' and 'b', when we are 'part'way into the 'whole' distance from a to b */
|
||||||
static inline int interpolate(int a, int b, int part, int whole)
|
static inline int interpolate(int a, int b, int part, int whole)
|
||||||
{
|
{
|
||||||
|
|
42
planner.c
42
planner.c
|
@ -188,24 +188,21 @@ void fill_default_cylinder(cylinder_t *cyl)
|
||||||
|
|
||||||
/* make sure that the gas we are switching to is represented in our
|
/* make sure that the gas we are switching to is represented in our
|
||||||
* list of cylinders */
|
* list of cylinders */
|
||||||
static int verify_gas_exists(struct dive *dive, int o2, int he)
|
static int verify_gas_exists(struct dive *dive, struct gasmix mix_in)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct gasmix *mix;
|
|
||||||
struct gasmix mix_in;
|
|
||||||
cylinder_t *cyl;
|
cylinder_t *cyl;
|
||||||
|
|
||||||
mix_in.o2.permille = o2;
|
|
||||||
mix_in.he.permille = he;
|
|
||||||
for (i = 0; i < MAX_CYLINDERS; i++) {
|
for (i = 0; i < MAX_CYLINDERS; i++) {
|
||||||
cyl = dive->cylinder + i;
|
cyl = dive->cylinder + i;
|
||||||
mix = &cyl->gasmix;
|
|
||||||
if (cylinder_nodata(cyl))
|
if (cylinder_nodata(cyl))
|
||||||
continue;
|
continue;
|
||||||
if (gasmix_distance(mix, &mix_in) < 200)
|
if (gasmix_distance(&cyl->gasmix, &mix_in) < 200)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
fprintf(stderr, "this gas (%d/%d) should have been on the cylinder list\nThings will fail now\n", o2, he);
|
char gas[50];
|
||||||
|
get_gas_string(&mix_in, gas, sizeof(gas));
|
||||||
|
fprintf(stderr, "this gas %s should have been on the cylinder list\nThings will fail now\n", gas);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,8 +231,8 @@ static struct dive *create_dive_from_plan(struct diveplan *diveplan, struct dive
|
||||||
struct divedatapoint *dp;
|
struct divedatapoint *dp;
|
||||||
struct divecomputer *dc;
|
struct divecomputer *dc;
|
||||||
struct sample *sample;
|
struct sample *sample;
|
||||||
|
struct gasmix oldgasmix;
|
||||||
cylinder_t *cyl;
|
cylinder_t *cyl;
|
||||||
int oldo2, oldhe;
|
|
||||||
int oldpo2 = 0;
|
int oldpo2 = 0;
|
||||||
int lasttime = 0;
|
int lasttime = 0;
|
||||||
int lastdepth = 0;
|
int lastdepth = 0;
|
||||||
|
@ -257,14 +254,12 @@ static struct dive *create_dive_from_plan(struct diveplan *diveplan, struct dive
|
||||||
/* reset the end pressure values and start with the gas on the first cylinder */
|
/* reset the end pressure values and start with the gas on the first cylinder */
|
||||||
reset_cylinders(master_dive);
|
reset_cylinders(master_dive);
|
||||||
cyl = &master_dive->cylinder[0];
|
cyl = &master_dive->cylinder[0];
|
||||||
oldhe = cyl->gasmix.he.permille;
|
oldgasmix = cyl->gasmix;
|
||||||
oldo2 = cyl->gasmix.o2.permille;
|
|
||||||
sample = prepare_sample(dc);
|
sample = prepare_sample(dc);
|
||||||
sample->po2 = dp->po2;
|
sample->po2 = dp->po2;
|
||||||
finish_sample(dc);
|
finish_sample(dc);
|
||||||
while (dp) {
|
while (dp) {
|
||||||
int o2 = get_o2(&dp->gasmix);
|
struct gasmix gasmix = dp->gasmix;
|
||||||
int he = get_he(&dp->gasmix);
|
|
||||||
int po2 = dp->po2;
|
int po2 = dp->po2;
|
||||||
int time = dp->time;
|
int time = dp->time;
|
||||||
int depth = dp->depth;
|
int depth = dp->depth;
|
||||||
|
@ -272,15 +267,13 @@ static struct dive *create_dive_from_plan(struct diveplan *diveplan, struct dive
|
||||||
if (time == 0) {
|
if (time == 0) {
|
||||||
/* special entries that just inform the algorithm about
|
/* special entries that just inform the algorithm about
|
||||||
* additional gases that are available */
|
* additional gases that are available */
|
||||||
if (verify_gas_exists(dive, o2, he) < 0)
|
if (verify_gas_exists(dive, gasmix) < 0)
|
||||||
goto gas_error_exit;
|
goto gas_error_exit;
|
||||||
dp = dp->next;
|
dp = dp->next;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!o2 && !he) {
|
if (gasmix_is_null(&gasmix))
|
||||||
o2 = oldo2;
|
gasmix = oldgasmix;
|
||||||
he = oldhe;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check for SetPoint change */
|
/* Check for SetPoint change */
|
||||||
if (oldpo2 != po2) {
|
if (oldpo2 != po2) {
|
||||||
|
@ -292,14 +285,10 @@ static struct dive *create_dive_from_plan(struct diveplan *diveplan, struct dive
|
||||||
oldpo2 = po2;
|
oldpo2 = po2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create new gas, and gas change event if necessary;
|
/* Make sure we have the new gas, and create a gas change event */
|
||||||
* Sadly, we inherited our gaschange event from libdivecomputer which only
|
if (gasmix_distance(&gasmix, &oldgasmix) > 0) {
|
||||||
* support percentage values, so round the entries */
|
|
||||||
if (o2 != oldo2 || he != oldhe) {
|
|
||||||
int plano2 = (o2 + 5) / 10 * 10;
|
|
||||||
int planhe = (he + 5) / 10 * 10;
|
|
||||||
int idx;
|
int idx;
|
||||||
if ((idx = verify_gas_exists(dive, plano2, planhe)) < 0)
|
if ((idx = verify_gas_exists(dive, gasmix)) < 0)
|
||||||
goto gas_error_exit;
|
goto gas_error_exit;
|
||||||
/* need to insert a first sample for the new gas */
|
/* need to insert a first sample for the new gas */
|
||||||
add_gas_switch_event(dive, dc, lasttime + 1, idx);
|
add_gas_switch_event(dive, dc, lasttime + 1, idx);
|
||||||
|
@ -309,8 +298,7 @@ static struct dive *create_dive_from_plan(struct diveplan *diveplan, struct dive
|
||||||
sample->depth.mm = lastdepth;
|
sample->depth.mm = lastdepth;
|
||||||
finish_sample(dc);
|
finish_sample(dc);
|
||||||
cyl = &dive->cylinder[idx];
|
cyl = &dive->cylinder[idx];
|
||||||
oldo2 = o2;
|
oldgasmix = gasmix;
|
||||||
oldhe = he;
|
|
||||||
}
|
}
|
||||||
/* Create sample */
|
/* Create sample */
|
||||||
sample = prepare_sample(dc);
|
sample = prepare_sample(dc);
|
||||||
|
|
Loading…
Add table
Reference in a new issue