core: compile planner source files with C++

Another relatively easily converted part of the code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-03-07 11:09:40 +01:00 committed by bstoeger
parent bd31efa821
commit 77e8c3655e
8 changed files with 152 additions and 150 deletions

View file

@ -25,7 +25,7 @@ SOURCES += subsurface-mobile-main.cpp \
core/devicedetails.cpp \ core/devicedetails.cpp \
core/downloadfromdcthread.cpp \ core/downloadfromdcthread.cpp \
core/qtserialbluetooth.cpp \ core/qtserialbluetooth.cpp \
core/plannernotes.c \ core/plannernotes.cpp \
core/uemis-downloader.cpp \ core/uemis-downloader.cpp \
core/qthelper.cpp \ core/qthelper.cpp \
core/checkcloudconnection.cpp \ core/checkcloudconnection.cpp \
@ -45,7 +45,7 @@ SOURCES += subsurface-mobile-main.cpp \
core/fulltext.cpp \ core/fulltext.cpp \
core/subsurfacestartup.cpp \ core/subsurfacestartup.cpp \
core/pref.c \ core/pref.c \
core/profile.c \ core/profile.cpp \
core/device.cpp \ core/device.cpp \
core/dive.cpp \ core/dive.cpp \
core/divecomputer.c \ core/divecomputer.c \
@ -81,10 +81,10 @@ SOURCES += subsurface-mobile-main.cpp \
core/save-git.cpp \ core/save-git.cpp \
core/datatrak.cpp \ core/datatrak.cpp \
core/ostctools.c \ core/ostctools.c \
core/planner.c \ core/planner.cpp \
core/save-xml.cpp \ core/save-xml.cpp \
core/cochran.cpp \ core/cochran.cpp \
core/deco.c \ core/deco.cpp \
core/divesite.c \ core/divesite.c \
core/equipment.c \ core/equipment.c \
core/gas.c \ core/gas.c \

View file

@ -53,7 +53,7 @@ set(SUBSURFACE_CORE_LIB_SRCS
connectionlistmodel.h connectionlistmodel.h
datatrak.cpp datatrak.cpp
datatrak.h datatrak.h
deco.c deco.cpp
deco.h deco.h
device.cpp device.cpp
device.h device.h
@ -141,12 +141,12 @@ set(SUBSURFACE_CORE_LIB_SRCS
picture.h picture.h
pictureobj.cpp pictureobj.cpp
pictureobj.h pictureobj.h
planner.c planner.cpp
planner.h planner.h
plannernotes.c plannernotes.cpp
pref.h pref.h
pref.c pref.c
profile.c profile.cpp
profile.h profile.h
qt-gui.h qt-gui.h
qt-init.cpp qt-init.cpp

View file

@ -218,7 +218,7 @@ static double vpmb_tolerated_ambient_pressure(struct deco_state *ds, double refe
return ds->tissue_n2_sat[ci] + ds->tissue_he_sat[ci] + vpmb_config.other_gases_pressure - total_gradient; return ds->tissue_n2_sat[ci] + ds->tissue_he_sat[ci] + vpmb_config.other_gases_pressure - total_gradient;
} }
double tissue_tolerance_calc(struct deco_state *ds, const struct dive *dive, double pressure, bool in_planner) extern "C" double tissue_tolerance_calc(struct deco_state *ds, const struct dive *dive, double pressure, bool in_planner)
{ {
int ci = -1; int ci = -1;
double ret_tolerance_limit_ambient_pressure = 0.0; double ret_tolerance_limit_ambient_pressure = 0.0;
@ -325,7 +325,7 @@ static double calc_surface_phase(double surface_pressure, double he_pressure, do
return 0; return 0;
} }
void vpmb_start_gradient(struct deco_state *ds) extern "C" void vpmb_start_gradient(struct deco_state *ds)
{ {
int ci; int ci;
@ -335,7 +335,7 @@ void vpmb_start_gradient(struct deco_state *ds)
} }
} }
void vpmb_next_gradient(struct deco_state *ds, double deco_time, double surface_pressure, bool in_planner) extern "C" void vpmb_next_gradient(struct deco_state *ds, double deco_time, double surface_pressure, bool in_planner)
{ {
int ci; int ci;
double n2_b, n2_c; double n2_b, n2_c;
@ -381,7 +381,7 @@ static double solve_cubic(double A, double B, double C)
} }
void nuclear_regeneration(struct deco_state *ds, double time) extern "C" void nuclear_regeneration(struct deco_state *ds, double time)
{ {
time /= 60.0; time /= 60.0;
int ci; int ci;
@ -413,7 +413,7 @@ static double calc_inner_pressure(double crit_radius, double onset_tension, doub
} }
// Calculates the crushing pressure in the given moment. Updates crushing_onset_tension and critical radius if needed // Calculates the crushing pressure in the given moment. Updates crushing_onset_tension and critical radius if needed
void calc_crushing_pressure(struct deco_state *ds, double pressure) extern "C" void calc_crushing_pressure(struct deco_state *ds, double pressure)
{ {
int ci; int ci;
double gradient; double gradient;
@ -445,9 +445,8 @@ void calc_crushing_pressure(struct deco_state *ds, double pressure)
} }
/* add period_in_seconds at the given pressure and gas to the deco calculation */ /* add period_in_seconds at the given pressure and gas to the deco calculation */
void add_segment(struct deco_state *ds, double pressure, struct gasmix gasmix, int period_in_seconds, int ccpo2, enum divemode_t divemode, int sac, bool in_planner) extern "C" void add_segment(struct deco_state *ds, double pressure, struct gasmix gasmix, int period_in_seconds, int ccpo2, enum divemode_t divemode, int, bool in_planner)
{ {
UNUSED(sac);
int ci; int ci;
struct gas_pressures pressures; struct gas_pressures pressures;
bool icd = false; bool icd = false;
@ -479,7 +478,7 @@ void add_segment(struct deco_state *ds, double pressure, struct gasmix gasmix, i
} }
#if DECO_CALC_DEBUG #if DECO_CALC_DEBUG
void dump_tissues(struct deco_state *ds) extern "C" void dump_tissues(struct deco_state *ds)
{ {
int ci; int ci;
printf("N2 tissues:"); printf("N2 tissues:");
@ -492,7 +491,7 @@ void dump_tissues(struct deco_state *ds)
} }
#endif #endif
void clear_vpmb_state(struct deco_state *ds) extern "C" void clear_vpmb_state(struct deco_state *ds)
{ {
int ci; int ci;
for (ci = 0; ci < 16; ci++) { for (ci = 0; ci < 16; ci++) {
@ -504,7 +503,7 @@ void clear_vpmb_state(struct deco_state *ds)
ds->max_bottom_ceiling_pressure.mbar = 0; ds->max_bottom_ceiling_pressure.mbar = 0;
} }
void clear_deco(struct deco_state *ds, double surface_pressure, bool in_planner) extern "C" void clear_deco(struct deco_state *ds, double surface_pressure, bool in_planner)
{ {
int ci; int ci;
@ -523,18 +522,18 @@ void clear_deco(struct deco_state *ds, double surface_pressure, bool in_planner)
ds->ci_pointing_to_guiding_tissue = -1; ds->ci_pointing_to_guiding_tissue = -1;
} }
void cache_deco_state(struct deco_state *src, struct deco_state **cached_datap) extern "C" void cache_deco_state(struct deco_state *src, struct deco_state **cached_datap)
{ {
struct deco_state *data = *cached_datap; struct deco_state *data = *cached_datap;
if (!data) { if (!data) {
data = malloc(sizeof(struct deco_state)); data = (deco_state *)malloc(sizeof(struct deco_state));
*cached_datap = data; *cached_datap = data;
} }
*data = *src; *data = *src;
} }
void restore_deco_state(struct deco_state *data, struct deco_state *target, bool keep_vpmb_state) extern "C" void restore_deco_state(struct deco_state *data, struct deco_state *target, bool keep_vpmb_state)
{ {
if (keep_vpmb_state) { if (keep_vpmb_state) {
int ci; int ci;
@ -551,7 +550,7 @@ void restore_deco_state(struct deco_state *data, struct deco_state *target, bool
} }
int deco_allowed_depth(double tissues_tolerance, double surface_pressure, const struct dive *dive, bool smooth) extern "C" int deco_allowed_depth(double tissues_tolerance, double surface_pressure, const struct dive *dive, bool smooth)
{ {
int depth; int depth;
double pressure_delta; double pressure_delta;
@ -570,7 +569,7 @@ int deco_allowed_depth(double tissues_tolerance, double surface_pressure, const
return depth; return depth;
} }
void set_gf(short gflow, short gfhigh) extern "C" void set_gf(short gflow, short gfhigh)
{ {
if (gflow != -1) if (gflow != -1)
buehlmann_config.gf_low = (double)gflow / 100.0; buehlmann_config.gf_low = (double)gflow / 100.0;
@ -578,7 +577,7 @@ void set_gf(short gflow, short gfhigh)
buehlmann_config.gf_high = (double)gfhigh / 100.0; buehlmann_config.gf_high = (double)gfhigh / 100.0;
} }
void set_vpmb_conservatism(short conservatism) extern "C" void set_vpmb_conservatism(short conservatism)
{ {
if (conservatism < 0) if (conservatism < 0)
vpmb_config.conservatism = 0; vpmb_config.conservatism = 0;
@ -588,7 +587,7 @@ void set_vpmb_conservatism(short conservatism)
vpmb_config.conservatism = conservatism; vpmb_config.conservatism = conservatism;
} }
double get_gf(struct deco_state *ds, double ambpressure_bar, const struct dive *dive) extern "C" double get_gf(struct deco_state *ds, double ambpressure_bar, const struct dive *dive)
{ {
double surface_pressure_bar = get_surface_pressure_in_mbar(dive, true) / 1000.0; double surface_pressure_bar = get_surface_pressure_in_mbar(dive, true) / 1000.0;
double gf_low = buehlmann_config.gf_low; double gf_low = buehlmann_config.gf_low;
@ -602,7 +601,7 @@ double get_gf(struct deco_state *ds, double ambpressure_bar, const struct dive *
return gf; return gf;
} }
double regressiona(const struct deco_state *ds) extern "C" double regressiona(const struct deco_state *ds)
{ {
if (ds->sum1 > 1) { if (ds->sum1 > 1) {
double avxy = ds->sumxy / ds->sum1; double avxy = ds->sumxy / ds->sum1;
@ -615,7 +614,7 @@ double regressiona(const struct deco_state *ds)
return 0.0; return 0.0;
} }
double regressionb(const struct deco_state *ds) extern "C" double regressionb(const struct deco_state *ds)
{ {
if (ds->sum1) if (ds->sum1)
return ds->sumy / ds->sum1 - ds->sumx * regressiona(ds) / ds->sum1; return ds->sumy / ds->sum1 - ds->sumx * regressiona(ds) / ds->sum1;
@ -623,14 +622,14 @@ double regressionb(const struct deco_state *ds)
return 0.0; return 0.0;
} }
void reset_regression(struct deco_state *ds) extern "C" void reset_regression(struct deco_state *ds)
{ {
ds->sum1 = 0; ds->sum1 = 0;
ds->sumxx = ds->sumx = 0L; ds->sumxx = ds->sumx = 0L;
ds->sumy = ds->sumxy = 0.0; ds->sumy = ds->sumxy = 0.0;
} }
void update_regression(struct deco_state *ds, const struct dive *dive) extern "C" void update_regression(struct deco_state *ds, const struct dive *dive)
{ {
if (!ds->plot_depth) if (!ds->plot_depth)
return; return;

View file

@ -117,7 +117,7 @@ int pscr_o2(const double amb_pressure, struct gasmix mix)
* *pressures = structure for communicating o2 sensor values from and gas pressures to the calling function. * *pressures = structure for communicating o2 sensor values from and gas pressures to the calling function.
* *mix = structure containing cylinder gas mixture information. * *mix = structure containing cylinder gas mixture information.
* divemode = the dive mode pertaining to this point in the dive profile. * divemode = the dive mode pertaining to this point in the dive profile.
* This function called by: calculate_gas_information_new() in profile.c; add_segment() in deco.c. * This function called by: calculate_gas_information_new() in profile.cpp; add_segment() in deco.cpp.
*/ */
void fill_pressures(struct gas_pressures *pressures, const double amb_pressure, struct gasmix mix, double po2, enum divemode_t divemode) void fill_pressures(struct gas_pressures *pressures, const double amb_pressure, struct gasmix mix, double po2, enum divemode_t divemode)
{ {

View file

@ -2,9 +2,9 @@
/* gaspressures.c /* gaspressures.c
* --------------- * ---------------
* This file contains the routines to calculate the gas pressures in the cylinders. * This file contains the routines to calculate the gas pressures in the cylinders.
* The functions below support the code in profile.c. * The functions below support the code in profile.cpp.
* The high-level function is populate_pressure_information(), called by function * The high-level function is populate_pressure_information(), called by function
* create_plot_info_new() in profile.c. The other functions below are, in turn, * create_plot_info_new() in profile.cpp. The other functions below are, in turn,
* called by populate_pressure_information(). The calling sequence is as follows: * called by populate_pressure_information(). The calling sequence is as follows:
* *
* populate_pressure_information() -> calc_pressure_time() * populate_pressure_information() -> calc_pressure_time()
@ -362,7 +362,7 @@ static void debug_print_pressures(struct plot_info *pi)
* pr_track_alloc structures for each cylinder. These pr_track_alloc structures ultimately allow for filling * pr_track_alloc structures for each cylinder. These pr_track_alloc structures ultimately allow for filling
* the missing tank pressure values on the dive profile using the depth_pressure of the dive. To do this, it * the missing tank pressure values on the dive profile using the depth_pressure of the dive. To do this, it
* calculates the summed pressure-time value for the duration of the dive and stores these * in the pr_track_alloc * calculates the summed pressure-time value for the duration of the dive and stores these * in the pr_track_alloc
* structures. This function is called by create_plot_info_new() in profile.c * structures. This function is called by create_plot_info_new() in profile.cpp
*/ */
void populate_pressure_information(const struct dive *dive, const struct divecomputer *dc, struct plot_info *pi, int sensor) void populate_pressure_information(const struct dive *dive, const struct divecomputer *dc, struct plot_info *pi, int sensor)
{ {

View file

@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
/* planner.c /* planner.cpp
* *
* code that allows us to plan future dives * code that allows us to plan future dives
* *
@ -42,7 +42,7 @@ static int decostoplevels_imperial[] = { 0, 3048, 6096, 9144, 12192, 15240, 1828
325120, 345440, 365760, 386080 }; 325120, 345440, 365760, 386080 };
#if DEBUG_PLAN #if DEBUG_PLAN
void dump_plan(struct diveplan *diveplan) extern "C" void dump_plan(struct diveplan *diveplan)
{ {
struct divedatapoint *dp; struct divedatapoint *dp;
struct tm tm; struct tm tm;
@ -65,7 +65,7 @@ void dump_plan(struct diveplan *diveplan)
} }
#endif #endif
bool diveplan_empty(struct diveplan *diveplan) extern "C" bool diveplan_empty(struct diveplan *diveplan)
{ {
struct divedatapoint *dp; struct divedatapoint *dp;
if (!diveplan || !diveplan->dp) if (!diveplan || !diveplan->dp)
@ -80,7 +80,7 @@ bool diveplan_empty(struct diveplan *diveplan)
} }
/* get the cylinder index at a certain time during the dive */ /* get the cylinder index at a certain time during the dive */
int get_cylinderid_at_time(struct dive *dive, struct divecomputer *dc, duration_t time) extern "C" int get_cylinderid_at_time(struct dive *dive, struct divecomputer *dc, duration_t time)
{ {
// we start with the first cylinder unless an event tells us otherwise // we start with the first cylinder unless an event tells us otherwise
int cylinder_idx = 0; int cylinder_idx = 0;
@ -327,7 +327,7 @@ static void create_dive_from_plan(struct diveplan *diveplan, struct dive *dive,
return; return;
} }
void free_dps(struct diveplan *diveplan) extern "C" void free_dps(struct diveplan *diveplan)
{ {
if (!diveplan) if (!diveplan)
return; return;
@ -344,7 +344,7 @@ static struct divedatapoint *create_dp(int time_incr, int depth, int cylinderid,
{ {
struct divedatapoint *dp; struct divedatapoint *dp;
dp = malloc(sizeof(struct divedatapoint)); dp = (divedatapoint *)malloc(sizeof(struct divedatapoint));
dp->time = time_incr; dp->time = time_incr;
dp->depth.mm = depth; dp->depth.mm = depth;
dp->cylinderid = cylinderid; dp->cylinderid = cylinderid;
@ -371,7 +371,7 @@ static void add_to_end_of_diveplan(struct diveplan *diveplan, struct divedatapoi
dp->time += lasttime; dp->time += lasttime;
} }
struct divedatapoint *plan_add_segment(struct diveplan *diveplan, int duration, int depth, int cylinderid, int po2, bool entered, enum divemode_t divemode) extern "C" struct divedatapoint *plan_add_segment(struct diveplan *diveplan, int duration, int depth, int cylinderid, int po2, bool entered, enum divemode_t divemode)
{ {
struct divedatapoint *dp = create_dp(duration, depth, cylinderid, divemode == CCR ? po2 : 0); struct divedatapoint *dp = create_dp(duration, depth, cylinderid, divemode == CCR ? po2 : 0);
dp->entered = entered; dp->entered = entered;
@ -413,7 +413,7 @@ static struct gaschanges *analyze_gaslist(struct diveplan *diveplan, struct dive
if (dp->depth.mm <= depth) { if (dp->depth.mm <= depth) {
int i = 0; int i = 0;
nr++; nr++;
gaschanges = realloc(gaschanges, nr * sizeof(struct gaschanges)); gaschanges = (struct gaschanges *)realloc(gaschanges, nr * sizeof(struct gaschanges));
while (i < nr - 1) { while (i < nr - 1) {
if (dp->depth.mm < gaschanges[i].depth) { if (dp->depth.mm < gaschanges[i].depth) {
memmove(gaschanges + i + 1, gaschanges + i, (nr - i - 1) * sizeof(struct gaschanges)); memmove(gaschanges + i + 1, gaschanges + i, (nr - i - 1) * sizeof(struct gaschanges));
@ -454,7 +454,7 @@ static int *sort_stops(int *dstops, int dnr, struct gaschanges *gstops, int gnr)
{ {
int i, gi, di; int i, gi, di;
int total = dnr + gnr; int total = dnr + gnr;
int *stoplevels = malloc(total * sizeof(int)); int *stoplevels = (int *)malloc(total * sizeof(int));
/* no gaschanges */ /* no gaschanges */
if (gnr == 0) { if (gnr == 0) {
@ -502,9 +502,8 @@ static int *sort_stops(int *dstops, int dnr, struct gaschanges *gstops, int gnr)
return stoplevels; return stoplevels;
} }
int ascent_velocity(int depth, int avg_depth, int bottom_time) extern "C" int ascent_velocity(int depth, int avg_depth, int)
{ {
UNUSED(bottom_time);
/* We need to make this configurable */ /* We need to make this configurable */
/* As an example (and possibly reasonable default) this is the Tech 1 provedure according /* As an example (and possibly reasonable default) this is the Tech 1 provedure according
@ -655,7 +654,7 @@ static void average_max_depth(struct diveplan *dive, int *avg_depth, int *max_de
*avg_depth = *max_depth = 0; *avg_depth = *max_depth = 0;
} }
bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, int timestep, struct decostop *decostoptable, struct deco_state **cached_datap, bool is_planner, bool show_disclaimer) extern "C" bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, int timestep, struct decostop *decostoptable, struct deco_state **cached_datap, bool is_planner, bool show_disclaimer)
{ {
int bottom_depth; int bottom_depth;
@ -715,7 +714,7 @@ bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, i
create_dive_from_plan(diveplan, dive, is_planner); create_dive_from_plan(diveplan, dive, is_planner);
// Do we want deco stop array in metres or feet? // Do we want deco stop array in metres or feet?
if (prefs.units.length == METERS ) { if (prefs.units.length == units::METERS ) {
decostoplevels = decostoplevels_metric; decostoplevels = decostoplevels_metric;
decostoplevelcount = sizeof(decostoplevels_metric) / sizeof(int); decostoplevelcount = sizeof(decostoplevels_metric) / sizeof(int);
} else { } else {
@ -929,7 +928,7 @@ bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, i
last_segment_min_switch = false; last_segment_min_switch = false;
clock += TIMESTEP; clock += TIMESTEP;
depth -= deltad; depth -= deltad;
/* Print VPM-Gradient as gradient factor, this has to be done from within deco.c */ /* Print VPM-Gradient as gradient factor, this has to be done from within deco.cpp */
if (decodive) if (decodive)
ds->plot_depth = depth; ds->plot_depth = depth;
} while (depth > 0 && depth > stoplevels[stopidx]); } while (depth > 0 && depth > stoplevels[stopidx]);
@ -1179,7 +1178,7 @@ static int get_permille(const char *begin, const char **end)
return value; return value;
} }
int validate_gas(const char *text, struct gasmix *gas) extern "C" int validate_gas(const char *text, struct gasmix *gas)
{ {
int o2, he; int o2, he;
@ -1226,7 +1225,7 @@ int validate_gas(const char *text, struct gasmix *gas)
return 1; return 1;
} }
int validate_po2(const char *text, int *mbar_po2) extern "C" int validate_po2(const char *text, int *mbar_po2)
{ {
int po2; int po2;

View file

@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
/* planner.c /* plannernotes.cpp
* *
* code that allows us to plan future dives * code that allows us to plan future dives
* *
@ -75,7 +75,7 @@ static void add_icd_entry(struct membuffer *b, struct icd_data *icdvalues, bool
ambientpressure_mbar * -icdvalues->dHe / 5e6f, translate("gettextFromC", "bar")); ambientpressure_mbar * -icdvalues->dHe / 5e6f, translate("gettextFromC", "bar"));
} }
const char *get_planner_disclaimer() extern "C" const char *get_planner_disclaimer()
{ {
return translate("gettextFromC", "DISCLAIMER / WARNING: THIS IMPLEMENTATION OF THE %s " return translate("gettextFromC", "DISCLAIMER / WARNING: THIS IMPLEMENTATION OF THE %s "
"ALGORITHM AND A DIVE PLANNER IMPLEMENTATION BASED ON THAT HAS " "ALGORITHM AND A DIVE PLANNER IMPLEMENTATION BASED ON THAT HAS "
@ -84,7 +84,7 @@ const char *get_planner_disclaimer()
} }
/* Returns newly allocated buffer. Must be freed by caller */ /* Returns newly allocated buffer. Must be freed by caller */
char *get_planner_disclaimer_formatted() extern "C" char *get_planner_disclaimer_formatted()
{ {
struct membuffer buf = { 0 }; struct membuffer buf = { 0 };
const char *deco = decoMode(true) == VPMB ? translate("gettextFromC", "VPM-B") const char *deco = decoMode(true) == VPMB ? translate("gettextFromC", "VPM-B")
@ -93,7 +93,7 @@ char *get_planner_disclaimer_formatted()
return detach_cstring(&buf); return detach_cstring(&buf);
} }
void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_disclaimer, int error) extern "C" void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_disclaimer, int error)
{ {
struct membuffer buf = { 0 }; struct membuffer buf = { 0 };
struct membuffer icdbuf = { 0 }; struct membuffer icdbuf = { 0 };
@ -436,30 +436,34 @@ void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_d
} }
put_string(&buf, "<br/>\n"); put_string(&buf, "<br/>\n");
const char *depth_unit; {
int altitude = (int) get_depth_units((int) (pressure_to_altitude(diveplan->surface_pressure)), NULL, &depth_unit); const char *depth_unit;
int altitude = (int) get_depth_units((int) (pressure_to_altitude(diveplan->surface_pressure)), NULL, &depth_unit);
put_format_loc(&buf, translate("gettextFromC", "ATM pressure: %dmbar (%d%s)<br/>\n</div>\n"), diveplan->surface_pressure, altitude, depth_unit); put_format_loc(&buf, translate("gettextFromC", "ATM pressure: %dmbar (%d%s)<br/>\n</div>\n"), diveplan->surface_pressure, altitude, depth_unit);
}
/* Get SAC values and units for printing it in gas consumption */ /* Get SAC values and units for printing it in gas consumption */
double bottomsacvalue, decosacvalue; {
int sacdecimals; double bottomsacvalue, decosacvalue;
const char* sacunit; int sacdecimals;
const char* sacunit;
bottomsacvalue = get_volume_units(prefs.bottomsac, &sacdecimals, &sacunit); bottomsacvalue = get_volume_units(prefs.bottomsac, &sacdecimals, &sacunit);
decosacvalue = get_volume_units(prefs.decosac, NULL, NULL); decosacvalue = get_volume_units(prefs.decosac, NULL, NULL);
/* Reduce number of decimals from 1 to 0 for bar/min, keep 2 for cuft/min */ /* Reduce number of decimals from 1 to 0 for bar/min, keep 2 for cuft/min */
if (sacdecimals==1) sacdecimals--; if (sacdecimals==1) sacdecimals--;
/* Print the gas consumption next.*/ /* Print the gas consumption next.*/
if (dive->dc.divemode == CCR) if (dive->dc.divemode == CCR)
temp = strdup(translate("gettextFromC", "Gas consumption (CCR legs excluded):")); temp = strdup(translate("gettextFromC", "Gas consumption (CCR legs excluded):"));
else else
asprintf_loc(&temp, "%s %.*f|%.*f%s/min):", translate("gettextFromC", "Gas consumption (based on SAC"), asprintf_loc(&temp, "%s %.*f|%.*f%s/min):", translate("gettextFromC", "Gas consumption (based on SAC"),
sacdecimals, bottomsacvalue, sacdecimals, decosacvalue, sacunit); sacdecimals, bottomsacvalue, sacdecimals, decosacvalue, sacunit);
put_format(&buf, "<div>\n%s<br/>\n", temp); put_format(&buf, "<div>\n%s<br/>\n", temp);
free(temp); free(temp);
}
/* Print gas consumption: This loop covers all cylinders */ /* Print gas consumption: This loop covers all cylinders */
for (int gasidx = 0; gasidx < dive->cylinders.nr; gasidx++) { for (int gasidx = 0; gasidx < dive->cylinders.nr; gasidx++) {
@ -570,53 +574,55 @@ void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_d
} }
free_buffer(&icdbuf); free_buffer(&icdbuf);
/* Print warnings for pO2 */ /* Print warnings for pO2 (move into separate function?) */
dp = diveplan->dp; {
bool o2warning_exist = false; dp = diveplan->dp;
enum divemode_t current_divemode; bool o2warning_exist = false;
double amb; enum divemode_t current_divemode;
const struct event *evd = NULL; double amb;
current_divemode = UNDEF_COMP_TYPE; const struct event *evd = NULL;
current_divemode = UNDEF_COMP_TYPE;
if (dive->dc.divemode != CCR) { if (dive->dc.divemode != CCR) {
while (dp) { while (dp) {
if (dp->time != 0) { if (dp->time != 0) {
struct gas_pressures pressures; struct gas_pressures pressures;
struct gasmix gasmix = get_cylinder(dive, dp->cylinderid)->gasmix; struct gasmix gasmix = get_cylinder(dive, dp->cylinderid)->gasmix;
current_divemode = get_current_divemode(&dive->dc, dp->time, &evd, &current_divemode); current_divemode = get_current_divemode(&dive->dc, dp->time, &evd, &current_divemode);
amb = depth_to_atm(dp->depth.mm, dive); amb = depth_to_atm(dp->depth.mm, dive);
fill_pressures(&pressures, amb, gasmix, (current_divemode == OC) ? 0.0 : amb * gasmix.o2.permille / 1000.0, current_divemode); fill_pressures(&pressures, amb, gasmix, (current_divemode == OC) ? 0.0 : amb * gasmix.o2.permille / 1000.0, current_divemode);
if (pressures.o2 > (dp->entered ? prefs.bottompo2 : prefs.decopo2) / 1000.0) { if (pressures.o2 > (dp->entered ? prefs.bottompo2 : prefs.decopo2) / 1000.0) {
const char *depth_unit; const char *depth_unit;
int decimals; int decimals;
double depth_value = get_depth_units(dp->depth.mm, &decimals, &depth_unit); double depth_value = get_depth_units(dp->depth.mm, &decimals, &depth_unit);
if (!o2warning_exist) if (!o2warning_exist)
put_string(&buf, "<div>\n"); put_string(&buf, "<div>\n");
o2warning_exist = true; o2warning_exist = true;
asprintf_loc(&temp, translate("gettextFromC", "high pO₂ value %.2f at %d:%02u with gas %s at depth %.*f %s"), asprintf_loc(&temp, translate("gettextFromC", "high pO₂ value %.2f at %d:%02u with gas %s at depth %.*f %s"),
pressures.o2, FRACTION(dp->time, 60), gasname(gasmix), decimals, depth_value, depth_unit); pressures.o2, FRACTION(dp->time, 60), gasname(gasmix), decimals, depth_value, depth_unit);
put_format(&buf, "<span style='color: red;'>%s </span> %s<br/>\n", translate("gettextFromC", "Warning:"), temp); put_format(&buf, "<span style='color: red;'>%s </span> %s<br/>\n", translate("gettextFromC", "Warning:"), temp);
free(temp); free(temp);
} else if (pressures.o2 < 0.16) { } else if (pressures.o2 < 0.16) {
const char *depth_unit; const char *depth_unit;
int decimals; int decimals;
double depth_value = get_depth_units(dp->depth.mm, &decimals, &depth_unit); double depth_value = get_depth_units(dp->depth.mm, &decimals, &depth_unit);
if (!o2warning_exist) if (!o2warning_exist)
put_string(&buf, "<div>"); put_string(&buf, "<div>");
o2warning_exist = true; o2warning_exist = true;
asprintf_loc(&temp, translate("gettextFromC", "low pO₂ value %.2f at %d:%02u with gas %s at depth %.*f %s"), asprintf_loc(&temp, translate("gettextFromC", "low pO₂ value %.2f at %d:%02u with gas %s at depth %.*f %s"),
pressures.o2, FRACTION(dp->time, 60), gasname(gasmix), decimals, depth_value, depth_unit); pressures.o2, FRACTION(dp->time, 60), gasname(gasmix), decimals, depth_value, depth_unit);
put_format(&buf, "<span style='color: red;'>%s </span> %s<br/>\n", translate("gettextFromC", "Warning:"), temp); put_format(&buf, "<span style='color: red;'>%s </span> %s<br/>\n", translate("gettextFromC", "Warning:"), temp);
free(temp); free(temp);
}
} }
dp = dp->next;
} }
dp = dp->next;
} }
if (o2warning_exist)
put_string(&buf, "</div>\n");
} }
if (o2warning_exist)
put_string(&buf, "</div>\n");
finished: finished:
free(dive->notes); free(dive->notes);
dive->notes = detach_cstring(&buf); dive->notes = detach_cstring(&buf);

View file

@ -30,7 +30,7 @@
#define MAX_PROFILE_DECO 7200 #define MAX_PROFILE_DECO 7200
extern int ascent_velocity(int depth, int avg_depth, int bottom_time); extern "C" int ascent_velocity(int depth, int avg_depth, int bottom_time);
#ifdef DEBUG_PI #ifdef DEBUG_PI
/* debugging tool - not normally used */ /* debugging tool - not normally used */
@ -66,7 +66,7 @@ static void dump_pi(struct plot_info *pi)
* 30 minutes or 90 ft, just so that small dives show * 30 minutes or 90 ft, just so that small dives show
* up as such unless zoom is enabled. * up as such unless zoom is enabled.
*/ */
int get_maxtime(const struct plot_info *pi) extern "C" int get_maxtime(const struct plot_info *pi)
{ {
int seconds = pi->maxtime; int seconds = pi->maxtime;
int min = prefs.zoomed_plot ? 30 : 30 * 60; int min = prefs.zoomed_plot ? 30 : 30 * 60;
@ -74,7 +74,7 @@ int get_maxtime(const struct plot_info *pi)
} }
/* get the maximum depth to which we want to plot */ /* get the maximum depth to which we want to plot */
int get_maxdepth(const struct plot_info *pi) extern "C" int get_maxdepth(const struct plot_info *pi)
{ {
/* 3m to spare */ /* 3m to spare */
int mm = pi->maxdepth + 3000; int mm = pi->maxdepth + 3000;
@ -185,7 +185,7 @@ static void analyze_plot_info(struct plot_info *pi)
* Some dive computers give cylinder indices, some * Some dive computers give cylinder indices, some
* give just the gas mix. * give just the gas mix.
*/ */
int get_cylinder_index(const struct dive *dive, const struct event *ev) extern "C" int get_cylinder_index(const struct dive *dive, const struct event *ev)
{ {
int best; int best;
struct gasmix mix; struct gasmix mix;
@ -206,7 +206,7 @@ int get_cylinder_index(const struct dive *dive, const struct event *ev)
return best < 0 ? 0 : best; return best < 0 ? 0 : best;
} }
struct event *get_next_event_mutable(struct event *event, const char *name) extern "C" struct event *get_next_event_mutable(struct event *event, const char *name)
{ {
if (!name || !*name) if (!name || !*name)
return NULL; return NULL;
@ -218,7 +218,7 @@ struct event *get_next_event_mutable(struct event *event, const char *name)
return event; return event;
} }
const struct event *get_next_event(const struct event *event, const char *name) extern "C" const struct event *get_next_event(const struct event *event, const char *name)
{ {
return get_next_event_mutable((struct event *)event, name); return get_next_event_mutable((struct event *)event, name);
} }
@ -246,9 +246,8 @@ static int set_setpoint(struct plot_info *pi, int i, int setpoint, int end)
return i; return i;
} }
static void check_setpoint_events(const struct dive *dive, const struct divecomputer *dc, struct plot_info *pi) static void check_setpoint_events(const struct dive *, const struct divecomputer *dc, struct plot_info *pi)
{ {
UNUSED(dive);
int i = 0; int i = 0;
pressure_t setpoint; pressure_t setpoint;
setpoint.mbar = 0; setpoint.mbar = 0;
@ -381,7 +380,7 @@ static void insert_entry(struct plot_info *pi, int idx, int time, int depth, int
entry->bearing = -1; entry->bearing = -1;
} }
void free_plot_info_data(struct plot_info *pi) extern "C" void free_plot_info_data(struct plot_info *pi)
{ {
free(pi->entry); free(pi->entry);
free(pi->pressures); free(pi->pressures);
@ -390,7 +389,6 @@ void free_plot_info_data(struct plot_info *pi)
static void populate_plot_entries(const struct dive *dive, const struct divecomputer *dc, struct plot_info *pi) static void populate_plot_entries(const struct dive *dive, const struct divecomputer *dc, struct plot_info *pi)
{ {
UNUSED(dive);
int idx, maxtime, nr, i; int idx, maxtime, nr, i;
int lastdepth, lasttime, lasttemp = 0; int lastdepth, lasttime, lasttemp = 0;
struct plot_data *plot_data; struct plot_data *plot_data;
@ -407,10 +405,10 @@ static void populate_plot_entries(const struct dive *dive, const struct divecomp
* past "maxtime" in the original sample data) * past "maxtime" in the original sample data)
*/ */
nr = dc->samples + 6 + maxtime / 10 + count_events(dc); nr = dc->samples + 6 + maxtime / 10 + count_events(dc);
plot_data = calloc(nr, sizeof(struct plot_data)); plot_data = (struct plot_data *)calloc(nr, sizeof(struct plot_data));
pi->entry = plot_data; pi->entry = plot_data;
pi->nr_cylinders = dive->cylinders.nr; pi->nr_cylinders = dive->cylinders.nr;
pi->pressures = calloc(nr * (size_t)pi->nr_cylinders, sizeof(struct plot_pressure_data)); pi->pressures = (struct plot_pressure_data *)calloc(nr * (size_t)pi->nr_cylinders, sizeof(struct plot_pressure_data));
if (!plot_data) if (!plot_data)
return; return;
pi->nr = nr; pi->nr = nr;
@ -684,11 +682,11 @@ static void calculate_sac(const struct dive *dive, const struct divecomputer *dc
const struct event *ev = NULL; const struct event *ev = NULL;
bool *gases, *gases_scratch; bool *gases, *gases_scratch;
gases = calloc(pi->nr_cylinders, sizeof(*gases)); gases = (bool *)calloc(pi->nr_cylinders, sizeof(*gases));
/* This might be premature optimization, but let's allocate the gas array for /* This might be premature optimization, but let's allocate the gas array for
* the fill_sac function only once an not once per sample */ * the fill_sac function only once an not once per sample */
gases_scratch = malloc(pi->nr_cylinders * sizeof(*gases)); gases_scratch = (bool *)malloc(pi->nr_cylinders * sizeof(*gases));
for (int i = 0; i < pi->nr; i++) { for (int i = 0; i < pi->nr; i++) {
struct plot_data *entry = pi->entry + i; struct plot_data *entry = pi->entry + i;
@ -707,7 +705,7 @@ static void calculate_sac(const struct dive *dive, const struct divecomputer *dc
static void populate_secondary_sensor_data(const struct divecomputer *dc, struct plot_info *pi) static void populate_secondary_sensor_data(const struct divecomputer *dc, struct plot_info *pi)
{ {
int *seen = calloc(pi->nr_cylinders, sizeof(*seen)); int *seen = (int *)calloc(pi->nr_cylinders, sizeof(*seen));
for (int idx = 0; idx < pi->nr; ++idx) for (int idx = 0; idx < pi->nr; ++idx)
for (int c = 0; c < pi->nr_cylinders; ++c) for (int c = 0; c < pi->nr_cylinders; ++c)
if (get_plot_pressure_data(pi, idx, SENSOR_PR, c)) if (get_plot_pressure_data(pi, idx, SENSOR_PR, c))
@ -754,9 +752,9 @@ static void setup_gas_sensor_pressure(const struct dive *dive, const struct dive
/* FIXME: The planner uses a dummy one-past-end cylinder for surface air! */ /* FIXME: The planner uses a dummy one-past-end cylinder for surface air! */
int num_cyl = pi->nr_cylinders + 1; int num_cyl = pi->nr_cylinders + 1;
int *seen = malloc(num_cyl * sizeof(*seen)); int *seen = (int *)malloc(num_cyl * sizeof(*seen));
int *first = malloc(num_cyl * sizeof(*first)); int *first = (int *)malloc(num_cyl * sizeof(*first));
int *last = malloc(num_cyl * sizeof(*last)); int *last = (int *)malloc(num_cyl * sizeof(*last));
const struct divecomputer *secondary; const struct divecomputer *secondary;
for (i = 0; i < num_cyl; i++) { for (i = 0; i < num_cyl; i++) {
@ -1127,7 +1125,7 @@ static void calculate_deco_information(struct deco_state *ds, const struct deco_
/* Sort the o2 pressure values. There are so few that a simple bubble sort /* Sort the o2 pressure values. There are so few that a simple bubble sort
* will do */ * will do */
void sort_o2_pressures(int *sensorn, int np, struct plot_data *entry) extern "C" void sort_o2_pressures(int *sensorn, int np, struct plot_data *entry)
{ {
int smallest, position, old; int smallest, position, old;
@ -1308,7 +1306,7 @@ static void debug_print_profiledata(struct plot_info *pi)
/* /*
* Initialize a plot_info structure to all-zeroes * Initialize a plot_info structure to all-zeroes
*/ */
void init_plot_info(struct plot_info *pi) extern "C" void init_plot_info(struct plot_info *pi)
{ {
memset(pi, 0, sizeof(*pi)); memset(pi, 0, sizeof(*pi));
} }
@ -1323,7 +1321,7 @@ void init_plot_info(struct plot_info *pi)
* The old data will be freed. Before the first call, the plot * The old data will be freed. Before the first call, the plot
* info must be initialized with init_plot_info(). * info must be initialized with init_plot_info().
*/ */
void create_plot_info_new(const struct dive *dive, const struct divecomputer *dc, struct plot_info *pi, const struct deco_state *planner_ds) extern "C" void create_plot_info_new(const struct dive *dive, const struct divecomputer *dc, struct plot_info *pi, const struct deco_state *planner_ds)
{ {
int o2, he, o2max; int o2, he, o2max;
struct deco_state plot_deco_state; struct deco_state plot_deco_state;
@ -1333,14 +1331,14 @@ void create_plot_info_new(const struct dive *dive, const struct divecomputer *dc
calculate_max_limits_new(dive, dc, pi, in_planner); calculate_max_limits_new(dive, dc, pi, in_planner);
get_dive_gas(dive, &o2, &he, &o2max); get_dive_gas(dive, &o2, &he, &o2max);
if (dc->divemode == FREEDIVE) { if (dc->divemode == FREEDIVE) {
pi->dive_type = FREEDIVING; pi->dive_type = plot_info::FREEDIVING;
} else if (he > 0) { } else if (he > 0) {
pi->dive_type = TRIMIX; pi->dive_type = plot_info::TRIMIX;
} else { } else {
if (o2) if (o2)
pi->dive_type = NITROX; pi->dive_type = plot_info::NITROX;
else else
pi->dive_type = AIR; pi->dive_type = plot_info::AIR;
} }
populate_plot_entries(dive, dc, pi); populate_plot_entries(dive, dc, pi);
@ -1414,23 +1412,23 @@ static void plot_string(const struct dive *d, const struct plot_info *pi, int id
if (prefs.ead) { if (prefs.ead) {
switch (pi->dive_type) { switch (pi->dive_type) {
case NITROX: case plot_info::NITROX:
if (entry->ead > 0) { if (entry->ead > 0) {
ead = lrint(get_depth_units(entry->ead, NULL, &depth_unit)); ead = lrint(get_depth_units(entry->ead, NULL, &depth_unit));
put_format_loc(b, translate("gettextFromC", "EAD: %d%s\nEADD: %d%s / %.1fg/\n"), ead, depth_unit, eadd, depth_unit, entry->density); put_format_loc(b, translate("gettextFromC", "EAD: %d%s\nEADD: %d%s / %.1fg/\n"), ead, depth_unit, eadd, depth_unit, entry->density);
break; break;
} }
case TRIMIX: case plot_info::TRIMIX:
if (entry->end > 0) { if (entry->end > 0) {
end = lrint(get_depth_units(entry->end, NULL, &depth_unit)); end = lrint(get_depth_units(entry->end, NULL, &depth_unit));
put_format_loc(b, translate("gettextFromC", "END: %d%s\nEADD: %d%s / %.1fg/\n"), end, depth_unit, eadd, depth_unit, entry->density); put_format_loc(b, translate("gettextFromC", "END: %d%s\nEADD: %d%s / %.1fg/\n"), end, depth_unit, eadd, depth_unit, entry->density);
break; break;
} }
case AIR: case plot_info::AIR:
if (entry->density > 0) { if (entry->density > 0) {
put_format_loc(b, translate("gettextFromC", "Density: %.1fg/\n"), entry->density); put_format_loc(b, translate("gettextFromC", "Density: %.1fg/\n"), entry->density);
} }
case FREEDIVING: case plot_info::FREEDIVING:
/* nothing */ /* nothing */
break; break;
} }
@ -1519,7 +1517,7 @@ static void plot_string(const struct dive *d, const struct plot_info *pi, int id
strip_mb(b); strip_mb(b);
} }
int get_plot_details_new(const struct dive *d, const struct plot_info *pi, int time, struct membuffer *mb) extern "C" int get_plot_details_new(const struct dive *d, const struct plot_info *pi, int time, struct membuffer *mb)
{ {
int i; int i;
@ -1535,11 +1533,11 @@ int get_plot_details_new(const struct dive *d, const struct plot_info *pi, int t
} }
/* Compare two plot_data entries and writes the results into a string */ /* Compare two plot_data entries and writes the results into a string */
void compare_samples(const struct dive *d, const struct plot_info *pi, int idx1, int idx2, char *buf, int bufsize, bool sum) extern "C" void compare_samples(const struct dive *d, const struct plot_info *pi, int idx1, int idx2, char *buf, int bufsize, bool sum)
{ {
struct plot_data *start, *stop, *data; struct plot_data *start, *stop, *data;
const char *depth_unit, *pressure_unit, *vertical_speed_unit; const char *depth_unit, *pressure_unit, *vertical_speed_unit;
char *buf2 = malloc(bufsize); char *buf2 = (char *)malloc(bufsize);
int avg_speed, max_asc_speed, max_desc_speed; int avg_speed, max_asc_speed, max_desc_speed;
int delta_depth, avg_depth, max_depth, min_depth; int delta_depth, avg_depth, max_depth, min_depth;
int pressurevalue; int pressurevalue;
@ -1578,11 +1576,11 @@ void compare_samples(const struct dive *d, const struct plot_info *pi, int idx1,
last_sec = start->sec; last_sec = start->sec;
volume_t cylinder_volume = { .mliter = 0, }; volume_t cylinder_volume = { .mliter = 0, };
int *start_pressures = calloc((size_t)pi->nr_cylinders, sizeof(int)); int *start_pressures = (int *)calloc((size_t)pi->nr_cylinders, sizeof(int));
int *last_pressures = calloc((size_t)pi->nr_cylinders, sizeof(int)); int *last_pressures = (int *)calloc((size_t)pi->nr_cylinders, sizeof(int));
int *bar_used = calloc((size_t)pi->nr_cylinders, sizeof(int)); int *bar_used = (int *)calloc((size_t)pi->nr_cylinders, sizeof(int));
int *volumes_used = calloc((size_t)pi->nr_cylinders, sizeof(int)); int *volumes_used = (int *)calloc((size_t)pi->nr_cylinders, sizeof(int));
bool *cylinder_is_used = calloc((size_t)pi->nr_cylinders, sizeof(bool)); bool *cylinder_is_used = (bool *)calloc((size_t)pi->nr_cylinders, sizeof(bool));
data = start; data = start;
for (int i = idx1; i < idx2; ++i) { for (int i = idx1; i < idx2; ++i) {
@ -1603,7 +1601,7 @@ void compare_samples(const struct dive *d, const struct plot_info *pi, int idx1,
if (data->depth > max_depth) if (data->depth > max_depth)
max_depth = data->depth; max_depth = data->depth;
for (unsigned cylinder_index = 0; cylinder_index < pi->nr_cylinders; cylinder_index++) { for (int cylinder_index = 0; cylinder_index < pi->nr_cylinders; cylinder_index++) {
int next_pressure = get_plot_pressure(pi, i, cylinder_index); int next_pressure = get_plot_pressure(pi, i, cylinder_index);
if (next_pressure && !start_pressures[cylinder_index]) if (next_pressure && !start_pressures[cylinder_index])
start_pressures[cylinder_index] = next_pressure; start_pressures[cylinder_index] = next_pressure;
@ -1669,7 +1667,7 @@ void compare_samples(const struct dive *d, const struct plot_info *pi, int idx1,
int total_volume_used = 0; int total_volume_used = 0;
bool cylindersizes_are_identical = true; bool cylindersizes_are_identical = true;
bool sac_is_determinable = true; bool sac_is_determinable = true;
for (unsigned cylinder_index = 0; cylinder_index < pi->nr_cylinders; cylinder_index++) for (int cylinder_index = 0; cylinder_index < pi->nr_cylinders; cylinder_index++)
if (cylinder_is_used[cylinder_index]) { if (cylinder_is_used[cylinder_index]) {
total_bar_used += bar_used[cylinder_index]; total_bar_used += bar_used[cylinder_index];
total_volume_used += volumes_used[cylinder_index]; total_volume_used += volumes_used[cylinder_index];