summaryrefslogtreecommitdiffstats
path: root/core/profile.c
diff options
context:
space:
mode:
Diffstat (limited to 'core/profile.c')
-rw-r--r--core/profile.c60
1 files changed, 33 insertions, 27 deletions
diff --git a/core/profile.c b/core/profile.c
index 113f62845..47fc97723 100644
--- a/core/profile.c
+++ b/core/profile.c
@@ -316,10 +316,10 @@ struct plot_info *analyze_plot_info(struct plot_info *pi)
* Some dive computers give cylinder indexes, some
* give just the gas mix.
*/
-int get_cylinder_index(struct dive *dive, struct event *ev)
+int get_cylinder_index(const struct dive *dive, const struct event *ev)
{
int best;
- struct gasmix *mix;
+ struct gasmix mix;
if (ev->gas.index >= 0)
return ev->gas.index;
@@ -337,7 +337,7 @@ int get_cylinder_index(struct dive *dive, struct event *ev)
return best < 0 ? 0 : best;
}
-struct event *get_next_event(struct event *event, const char *name)
+struct event *get_next_event_mutable(struct event *event, const char *name)
{
if (!name || !*name)
return NULL;
@@ -349,6 +349,11 @@ struct event *get_next_event(struct event *event, const char *name)
return event;
}
+const struct event *get_next_event(const struct event *event, const char *name)
+{
+ return get_next_event_mutable((struct event *)event, name);
+}
+
static int count_events(struct divecomputer *dc)
{
int result = 0;
@@ -372,13 +377,13 @@ static int set_setpoint(struct plot_info *pi, int i, int setpoint, int end)
return i;
}
-static void check_setpoint_events(struct dive *dive, struct divecomputer *dc, struct plot_info *pi)
+static void check_setpoint_events(const struct dive *dive, struct divecomputer *dc, struct plot_info *pi)
{
UNUSED(dive);
int i = 0;
pressure_t setpoint;
setpoint.mbar = 0;
- struct event *ev = get_next_event(dc->events, "SP change");
+ const struct event *ev = get_next_event(dc->events, "SP change");
if (!ev)
return;
@@ -760,14 +765,14 @@ static void fill_sac(struct dive *dive, struct plot_info *pi, int idx, unsigned
/*
* Create a bitmap of cylinders that match our current gasmix
*/
-static unsigned int matching_gases(struct dive *dive, struct gasmix *gasmix)
+static unsigned int matching_gases(struct dive *dive, struct gasmix gasmix)
{
int i;
unsigned int gases = 0;
for (i = 0; i < MAX_CYLINDERS; i++) {
cylinder_t *cyl = dive->cylinder + i;
- if (same_gasmix(gasmix, &cyl->gasmix))
+ if (same_gasmix(gasmix, cyl->gasmix))
gases |= 1 << i;
}
return gases;
@@ -775,14 +780,14 @@ static unsigned int matching_gases(struct dive *dive, struct gasmix *gasmix)
static void calculate_sac(struct dive *dive, struct divecomputer *dc, struct plot_info *pi)
{
- struct gasmix *gasmix = NULL;
- struct event *ev = NULL;
+ struct gasmix gasmix = { 0 };
+ const struct event *ev = NULL;
unsigned int gases = 0;
for (int i = 0; i < pi->nr; i++) {
struct plot_data *entry = pi->entry + i;
- struct gasmix *newmix = get_gasmix(dive, dc, entry->sec, &ev, gasmix);
- if (newmix != gasmix) {
+ struct gasmix newmix = get_gasmix(dive, dc, entry->sec, &ev, gasmix);
+ if (!same_gasmix(newmix, gasmix)) {
gasmix = newmix;
gases = matching_gases(dive, newmix);
}
@@ -791,7 +796,7 @@ static void calculate_sac(struct dive *dive, struct divecomputer *dc, struct plo
}
}
-static void populate_secondary_sensor_data(struct divecomputer *dc, struct plot_info *pi)
+static void populate_secondary_sensor_data(const struct divecomputer *dc, struct plot_info *pi)
{
UNUSED(dc);
UNUSED(pi);
@@ -818,14 +823,14 @@ static void add_plot_pressure(struct plot_info *pi, int time, int cyl, pressure_
SENSOR_PRESSURE(entry, cyl) = p.mbar;
}
-static void setup_gas_sensor_pressure(struct dive *dive, struct divecomputer *dc, struct plot_info *pi)
+static void setup_gas_sensor_pressure(const struct dive *dive, const struct divecomputer *dc, struct plot_info *pi)
{
int prev, i;
- struct event *ev;
+ const struct event *ev;
int seen[MAX_CYLINDERS] = { 0, };
unsigned int first[MAX_CYLINDERS] = { 0, };
unsigned int last[MAX_CYLINDERS] = { 0, };
- struct divecomputer *secondary;
+ const struct divecomputer *secondary;
prev = explicit_first_cylinder(dive, dc);
seen[prev] = 1;
@@ -854,7 +859,7 @@ static void setup_gas_sensor_pressure(struct dive *dive, struct divecomputer *dc
// Fill in "seen[]" array - mark cylinders we're not interested
// in as negative.
for (i = 0; i < MAX_CYLINDERS; i++) {
- cylinder_t *cyl = dive->cylinder + i;
+ const cylinder_t *cyl = dive->cylinder + i;
int start = cyl->start.mbar;
int end = cyl->end.mbar;
@@ -885,7 +890,7 @@ static void setup_gas_sensor_pressure(struct dive *dive, struct divecomputer *dc
for (i = 0; i < MAX_CYLINDERS; i++) {
if (seen[i] >= 0) {
- cylinder_t *cyl = dive->cylinder + i;
+ const cylinder_t *cyl = dive->cylinder + i;
add_plot_pressure(pi, first[i], i, cyl->start);
add_plot_pressure(pi, last[i], i, cyl->end);
@@ -907,7 +912,7 @@ static void setup_gas_sensor_pressure(struct dive *dive, struct divecomputer *dc
#ifndef SUBSURFACE_MOBILE
/* calculate DECO STOP / TTS / NDL */
-static void calculate_ndl_tts(struct deco_state *ds, struct dive *dive, struct plot_data *entry, struct gasmix *gasmix, double surface_pressure,enum divemode_t divemode)
+static void calculate_ndl_tts(struct deco_state *ds, const struct dive *dive, struct plot_data *entry, struct gasmix gasmix, double surface_pressure,enum divemode_t divemode)
{
/* FIXME: This should be configurable */
/* ascent speed up to first deco stop */
@@ -990,7 +995,7 @@ static void calculate_ndl_tts(struct deco_state *ds, struct dive *dive, struct p
/* Let's try to do some deco calculations.
*/
-void calculate_deco_information(struct deco_state *ds, struct deco_state *planner_ds, struct dive *dive, struct divecomputer *dc, struct plot_info *pi, bool print_mode)
+void calculate_deco_information(struct deco_state *ds, const struct deco_state *planner_ds, const struct dive *dive, const struct divecomputer *dc, struct plot_info *pi, bool print_mode)
{
int i, count_iteration = 0;
double surface_pressure = (dc->surface_pressure.mbar ? dc->surface_pressure.mbar : get_surface_pressure_in_mbar(dive, true)) / 1000.0;
@@ -1016,8 +1021,8 @@ void calculate_deco_information(struct deco_state *ds, struct deco_state *planne
int last_ndl_tts_calc_time = 0, first_ceiling = 0, current_ceiling, last_ceiling = 0, final_tts = 0 , time_clear_ceiling = 0;
if (decoMode() == VPMB)
ds->first_ceiling_pressure.mbar = depth_to_mbar(first_ceiling, dive);
- struct gasmix *gasmix = NULL;
- struct event *ev = NULL, *evd = NULL;
+ struct gasmix gasmix = { 0 };
+ const struct event *ev = NULL, *evd = NULL;
enum divemode_t current_divemode = UNDEF_COMP_TYPE;
for (i = 1; i < pi->nr; i++) {
@@ -1205,8 +1210,8 @@ static void calculate_gas_information_new(struct dive *dive, struct divecomputer
{
int i;
double amb_pressure;
- struct gasmix *gasmix = NULL;
- struct event *evg = NULL, *evd = NULL;
+ struct gasmix gasmix = { 0 };
+ const struct event *evg = NULL, *evd = NULL;
enum divemode_t current_divemode = UNDEF_COMP_TYPE;
for (i = 1; i < pi->nr; i++) {
@@ -1219,8 +1224,10 @@ static void calculate_gas_information_new(struct dive *dive, struct divecomputer
fill_pressures(&entry->pressures, amb_pressure, gasmix, (current_divemode == OC) ? 0.0 : entry->o2pressure.mbar / 1000.0, current_divemode);
fn2 = (int)(1000.0 * entry->pressures.n2 / amb_pressure);
fhe = (int)(1000.0 * entry->pressures.he / amb_pressure);
- if (dc->divemode == PSCR) // OC pO2 is calulated for PSCR with or without external PO2 monitoring.
- entry->scr_OC_pO2.mbar = (int) depth_to_mbar(entry->depth, dive) * get_o2(get_gasmix(dive, dc, entry->sec, &evg, gasmix)) / 1000;
+ if (dc->divemode == PSCR) { // OC pO2 is calulated for PSCR with or without external PO2 monitoring.
+ struct gasmix gasmix2 = get_gasmix(dive, dc, entry->sec, &evg, gasmix);
+ entry->scr_OC_pO2.mbar = (int) depth_to_mbar(entry->depth, dive) * get_o2(gasmix2) / 1000;
+ }
/* Calculate MOD, EAD, END and EADD based on partial pressures calculated before
* so there is no difference in calculating between OC and CC
@@ -1385,11 +1392,10 @@ static void plot_string(struct plot_info *pi, struct plot_data *entry, struct me
depthvalue = get_depth_units(entry->depth, NULL, &depth_unit);
put_format_loc(b, translate("gettextFromC", "@: %d:%02d\nD: %.1f%s\n"), FRACTION(entry->sec, 60), depthvalue, depth_unit);
for (cyl = 0; cyl < MAX_CYLINDERS; cyl++) {
- struct gasmix *mix;
int mbar = GET_PRESSURE(entry, cyl);
if (!mbar)
continue;
- mix = &displayed_dive.cylinder[cyl].gasmix;
+ struct gasmix mix = displayed_dive.cylinder[cyl].gasmix;
pressurevalue = get_pressure_units(mbar, &pressure_unit);
put_format_loc(b, translate("gettextFromC", "P: %d%s (%s)\n"), pressurevalue, pressure_unit, gasname(mix));
}