mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Planner: more fixes for gas tracking
Gas switches are now for the current segment, not for the next. We can only track gas for cylinders for which we have size / working pressure information. Print a warning for others. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
81e3f77447
commit
f44a7509b3
1 changed files with 22 additions and 20 deletions
42
planner.c
42
planner.c
|
@ -537,24 +537,21 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
|
||||||
snprintf(buffer, sizeof(buffer),
|
snprintf(buffer, sizeof(buffer),
|
||||||
translate("gettextFromC", "%s\nSubsurface dive plan\nbased on GFlow = %d and GFhigh = %d\n\n"),
|
translate("gettextFromC", "%s\nSubsurface dive plan\nbased on GFlow = %d and GFhigh = %d\n\n"),
|
||||||
disclaimer, diveplan->gflow, diveplan->gfhigh);
|
disclaimer, diveplan->gflow, diveplan->gfhigh);
|
||||||
/* we start with gas 0, then check if that was changed */
|
|
||||||
o2 = get_o2(&dive->cylinder[0].gasmix);
|
|
||||||
he = get_he(&dive->cylinder[0].gasmix);
|
|
||||||
do {
|
do {
|
||||||
const char *depth_unit;
|
const char *depth_unit;
|
||||||
char gas[64];
|
char gas[64];
|
||||||
double depthvalue;
|
double depthvalue;
|
||||||
int decimals;
|
int decimals;
|
||||||
double used;
|
double used;
|
||||||
int newo2 = o2, newhe = he;
|
int newo2 = -1, newhe = -1;
|
||||||
struct divedatapoint *nextdp;
|
struct divedatapoint *nextdp;
|
||||||
|
|
||||||
if (dp->time == 0)
|
if (dp->time == 0)
|
||||||
continue;
|
continue;
|
||||||
|
o2 = dp->o2;
|
||||||
|
he = dp->he;
|
||||||
depthvalue = get_depth_units(dp->depth, &decimals, &depth_unit);
|
depthvalue = get_depth_units(dp->depth, &decimals, &depth_unit);
|
||||||
/* do we change gas after this segment? We need to look at the gas
|
/* analyze the dive points ahead */
|
||||||
* for the next segment (that isn't just a record of available gas !!)
|
|
||||||
* to find out */
|
|
||||||
nextdp = dp->next;
|
nextdp = dp->next;
|
||||||
while (nextdp && nextdp->time == 0)
|
while (nextdp && nextdp->time == 0)
|
||||||
nextdp = nextdp->next;
|
nextdp = nextdp->next;
|
||||||
|
@ -585,13 +582,14 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
|
||||||
FRACTION(dp->time - lasttime, 60),
|
FRACTION(dp->time - lasttime, 60),
|
||||||
FRACTION(dp->time, 60),
|
FRACTION(dp->time, 60),
|
||||||
gas);
|
gas);
|
||||||
get_gas_string(newo2, newhe, gas, sizeof(gas));
|
if (nextdp && (o2 != newo2 || he != newhe) ) {
|
||||||
if (o2 != newo2 || he != newhe) {
|
// gas switch at this waypoint
|
||||||
|
get_gas_string(newo2, newhe, gas, sizeof(gas));
|
||||||
len = strlen(buffer);
|
len = strlen(buffer);
|
||||||
snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "Switch gas to %s\n"), gas);
|
snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "Switch gas to %s\n"), gas);
|
||||||
|
o2 = newo2;
|
||||||
|
he = newhe;
|
||||||
}
|
}
|
||||||
o2 = newo2;
|
|
||||||
he = newhe;
|
|
||||||
lasttime = dp->time;
|
lasttime = dp->time;
|
||||||
lastdepth = dp->depth;
|
lastdepth = dp->depth;
|
||||||
} while ((dp = dp->next) != NULL);
|
} while ((dp = dp->next) != NULL);
|
||||||
|
@ -605,17 +603,21 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
|
||||||
cylinder_t *cyl = &dive->cylinder[gasidx];
|
cylinder_t *cyl = &dive->cylinder[gasidx];
|
||||||
if (cylinder_none(cyl))
|
if (cylinder_none(cyl))
|
||||||
break;
|
break;
|
||||||
int consumed = mbar_to_atm(cyl->start.mbar - cyl->end.mbar) * cyl->type.size.mliter;
|
|
||||||
/* Warn if the plan uses more gas than is available in a cylinder
|
|
||||||
* This only works if we have working pressure for the cylinder
|
|
||||||
* 10bar is a made up number - but it seemed silly to pretend you could breathe cylinder down to 0 */
|
|
||||||
if (cyl->type.workingpressure.mbar && cyl->end.mbar < 10000)
|
|
||||||
warning = translate("gettextFromC", "WARNING: this is more gas than available in the specified cylinder!");
|
|
||||||
|
|
||||||
len = strlen(buffer);
|
len = strlen(buffer);
|
||||||
volume = get_volume_units(consumed, NULL, &unit);
|
|
||||||
get_gas_string(get_o2(&cyl->gasmix), get_he(&cyl->gasmix), gas, sizeof(gas));
|
get_gas_string(get_o2(&cyl->gasmix), get_he(&cyl->gasmix), gas, sizeof(gas));
|
||||||
snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "%.0f%s of %s%s\n"), volume, unit, gas, warning);
|
if (cyl->type.workingpressure.mbar) {
|
||||||
|
int consumed = mbar_to_atm(cyl->start.mbar - cyl->end.mbar) * cyl->type.size.mliter;
|
||||||
|
volume = get_volume_units(consumed, NULL, &unit);
|
||||||
|
/* Warn if the plan uses more gas than is available in a cylinder
|
||||||
|
* This only works if we have working pressure for the cylinder
|
||||||
|
* 10bar is a made up number - but it seemed silly to pretend you could breathe cylinder down to 0 */
|
||||||
|
if (cyl->end.mbar < 10000)
|
||||||
|
warning = translate("gettextFromC", "WARNING: this is more gas than available in the specified cylinder!");
|
||||||
|
snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "%.0f%s of %s%s\n"), volume, unit, gas, warning);
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "we really should calculate the consumption even without cylinder data\n");
|
||||||
|
snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "did not track volume for %s"), gas);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dive->notes = strdup(buffer);
|
dive->notes = strdup(buffer);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue