diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-08-05 20:43:06 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-08-08 16:26:31 -0700 |
commit | 52e5d9c605469b338075e22533a8f97a6f984b57 (patch) | |
tree | c8fd18dc85ee5afba09c6714353316efc8a8db68 /core | |
parent | 594d1d3514f91221884bdc31f29a09e8f325f1e8 (diff) | |
download | subsurface-52e5d9c605469b338075e22533a8f97a6f984b57.tar.gz |
Cleanup: move planner/deco related declarations planner/deco.h
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-rw-r--r-- | core/deco.c | 2 | ||||
-rw-r--r-- | core/deco.h | 36 | ||||
-rw-r--r-- | core/dive.c | 26 | ||||
-rw-r--r-- | core/dive.h | 72 | ||||
-rw-r--r-- | core/divelist.h | 2 | ||||
-rw-r--r-- | core/divemode.h | 7 | ||||
-rw-r--r-- | core/planner.c | 29 | ||||
-rw-r--r-- | core/planner.h | 40 | ||||
-rw-r--r-- | core/profile.h | 2 | ||||
-rw-r--r-- | core/qthelper.cpp | 1 |
10 files changed, 117 insertions, 100 deletions
diff --git a/core/deco.c b/core/deco.c index 46f57c9da..cb8273f41 100644 --- a/core/deco.c +++ b/core/deco.c @@ -21,8 +21,10 @@ #include <string.h> #include <assert.h> +#include "deco.h" #include "ssrf.h" #include "dive.h" +#include "gas.h" #include "subsurface-string.h" #include "errorhelper.h" #include "planner.h" diff --git a/core/deco.h b/core/deco.h index 4a10b7366..ed1135abb 100644 --- a/core/deco.h +++ b/core/deco.h @@ -2,14 +2,47 @@ #ifndef DECO_H #define DECO_H +#include "units.h" +#include "gas.h" +#include "divemode.h" + #ifdef __cplusplus extern "C" { #endif struct dive; -struct deco_state; +struct divecomputer; struct decostop; +struct deco_state { + double tissue_n2_sat[16]; + double tissue_he_sat[16]; + double tolerated_by_tissue[16]; + double tissue_inertgas_saturation[16]; + double buehlmann_inertgas_a[16]; + double buehlmann_inertgas_b[16]; + + double max_n2_crushing_pressure[16]; + double max_he_crushing_pressure[16]; + + double crushing_onset_tension[16]; // total inert gas tension in the t* moment + double n2_regen_radius[16]; // rs + double he_regen_radius[16]; + double max_ambient_pressure; // last moment we were descending + + double bottom_n2_gradient[16]; + double bottom_he_gradient[16]; + + double initial_n2_gradient[16]; + double initial_he_gradient[16]; + pressure_t first_ceiling_pressure; + pressure_t max_bottom_ceiling_pressure; + int ci_pointing_to_guiding_tissue; + double gf_low_pressure_this_dive; + int deco_time; + bool icd_warning; +}; + extern const double buehlmann_N2_t_halflife[]; extern int deco_allowed_depth(double tissues_tolerance, double surface_pressure, const struct dive *dive, bool smooth); @@ -29,6 +62,7 @@ extern void calc_crushing_pressure(struct deco_state *ds, double pressure); extern void vpmb_start_gradient(struct deco_state *ds); extern void clear_vpmb_state(struct deco_state *ds); extern void printdecotable(struct decostop *table); +extern void add_segment(struct deco_state *ds, double pressure, struct gasmix gasmix, int period_in_seconds, int setpoint, enum divemode_t divemode, int sac); extern double regressiona(); extern double regressionb(); diff --git a/core/dive.c b/core/dive.c index 9a5171c32..a86ca4f57 100644 --- a/core/dive.c +++ b/core/dive.c @@ -3435,32 +3435,6 @@ void set_git_prefs(const char *prefs) git_prefs.pp_graphs.po2 = 1; } -void average_max_depth(struct diveplan *dive, int *avg_depth, int *max_depth) -{ - int integral = 0; - int last_time = 0; - int last_depth = 0; - struct divedatapoint *dp = dive->dp; - - *max_depth = 0; - - while (dp) { - if (dp->time) { - /* Ignore gas indication samples */ - integral += (dp->depth.mm + last_depth) * (dp->time - last_time) / 2; - last_time = dp->time; - last_depth = dp->depth.mm; - if (dp->depth.mm > *max_depth) - *max_depth = dp->depth.mm; - } - dp = dp->next; - } - if (last_time) - *avg_depth = integral / last_time; - else - *avg_depth = *max_depth = 0; -} - struct picture *alloc_picture() { struct picture *pic = malloc(sizeof(struct picture)); diff --git a/core/dive.h b/core/dive.h index 57bb6e297..1509e51c2 100644 --- a/core/dive.h +++ b/core/dive.h @@ -12,6 +12,7 @@ #include <string.h> #include <stdio.h> +#include "divemode.h" #include "equipment.h" #ifdef __cplusplus @@ -20,8 +21,6 @@ extern "C" { extern int last_xml_version; -enum divemode_t {OC, CCR, PSCR, FREEDIVE, NUM_DIVEMODE, UNDEF_COMP_TYPE}; // Flags (Open-circuit and Closed-circuit-rebreather) for setting dive computer type - extern const char *cylinderuse_text[NUM_GAS_USE]; extern const char *divemode_text_ui[]; extern const char *divemode_text[]; @@ -405,76 +404,9 @@ extern void subsurface_command_line_exit(int *, char ***); #define DECOTIMESTEP 60 /* seconds. Unit of deco stop times */ -struct deco_state { - double tissue_n2_sat[16]; - double tissue_he_sat[16]; - double tolerated_by_tissue[16]; - double tissue_inertgas_saturation[16]; - double buehlmann_inertgas_a[16]; - double buehlmann_inertgas_b[16]; - - double max_n2_crushing_pressure[16]; - double max_he_crushing_pressure[16]; - - double crushing_onset_tension[16]; // total inert gas tension in the t* moment - double n2_regen_radius[16]; // rs - double he_regen_radius[16]; - double max_ambient_pressure; // last moment we were descending - - double bottom_n2_gradient[16]; - double bottom_he_gradient[16]; - - double initial_n2_gradient[16]; - double initial_he_gradient[16]; - pressure_t first_ceiling_pressure; - pressure_t max_bottom_ceiling_pressure; - int ci_pointing_to_guiding_tissue; - double gf_low_pressure_this_dive; - int deco_time; - bool icd_warning; -}; - -extern void add_segment(struct deco_state *ds, double pressure, struct gasmix gasmix, int period_in_seconds, int setpoint, enum divemode_t divemode, int sac); extern bool is_dc_planner(const struct divecomputer *dc); extern bool has_planned(const struct dive *dive, bool planned); -/* this should be converted to use our types */ -struct divedatapoint { - int time; - depth_t depth; - int cylinderid; - pressure_t minimum_gas; - int setpoint; - bool entered; - struct divedatapoint *next; - enum divemode_t divemode; -}; - -struct diveplan { - timestamp_t when; - int surface_pressure; /* mbar */ - int bottomsac; /* ml/min */ - int decosac; /* ml/min */ - int salinity; - short gflow; - short gfhigh; - short vpmb_conservatism; - struct divedatapoint *dp; - int eff_gflow, eff_gfhigh; - int surface_interval; -}; - -struct divedatapoint *plan_add_segment(struct diveplan *diveplan, int duration, int depth, int cylinderid, int po2, bool entered, enum divemode_t divemode); -struct divedatapoint *create_dp(int time_incr, int depth, int cylinderid, int po2); -#if DEBUG_PLAN -void dump_plan(struct diveplan *diveplan); -#endif -struct decostop { - int depth; - int time; -}; -extern 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); - /* Since C doesn't have parameter-based overloading, two versions of get_next_event. */ extern const struct event *get_next_event(const struct event *event, const char *name); extern struct event *get_next_event_mutable(struct event *event, const char *name); @@ -501,8 +433,6 @@ extern void set_git_prefs(const char *prefs); extern char *get_dive_date_c_string(timestamp_t when); extern void update_setpoint_events(const struct dive *dive, struct divecomputer *dc); -extern void average_max_depth(struct diveplan *dive, int *avg_depth, int *max_depth); - #ifdef __cplusplus } diff --git a/core/divelist.h b/core/divelist.h index 75f096feb..3c09d5400 100644 --- a/core/divelist.h +++ b/core/divelist.h @@ -8,6 +8,8 @@ extern "C" { #endif +struct deco_state; + /* this is used for both git and xml format */ #define DATAFORMAT_VERSION 3 diff --git a/core/divemode.h b/core/divemode.h new file mode 100644 index 000000000..3ea012fe6 --- /dev/null +++ b/core/divemode.h @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef DIVEMODE_H +#define DIVEMODE_H + +enum divemode_t {OC, CCR, PSCR, FREEDIVE, NUM_DIVEMODE, UNDEF_COMP_TYPE}; // Flags (Open-circuit and Closed-circuit-rebreather) for setting dive computer type + +#endif diff --git a/core/planner.c b/core/planner.c index fb53fb59d..b4400b91f 100644 --- a/core/planner.c +++ b/core/planner.c @@ -5,12 +5,11 @@ * * (c) Dirk Hohndel 2013 */ -#include "ssrf.h" #include <assert.h> #include <unistd.h> #include <ctype.h> #include <string.h> -#include "dive.h" +#include "ssrf.h" #include "divelist.h" #include "subsurface-string.h" #include "deco.h" @@ -638,6 +637,32 @@ void printdecotable(struct decostop *table) } } +static void average_max_depth(struct diveplan *dive, int *avg_depth, int *max_depth) +{ + int integral = 0; + int last_time = 0; + int last_depth = 0; + struct divedatapoint *dp = dive->dp; + + *max_depth = 0; + + while (dp) { + if (dp->time) { + /* Ignore gas indication samples */ + integral += (dp->depth.mm + last_depth) * (dp->time - last_time) / 2; + last_time = dp->time; + last_depth = dp->depth.mm; + if (dp->depth.mm > *max_depth) + *max_depth = dp->depth.mm; + } + dp = dp->next; + } + if (last_time) + *avg_depth = integral / last_time; + else + *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) { diff --git a/core/planner.h b/core/planner.h index b7e3c7241..404fbe3fc 100644 --- a/core/planner.h +++ b/core/planner.h @@ -5,6 +5,35 @@ #define LONGDECO 1 #define NOT_RECREATIONAL 2 +#include "units.h" +#include "divemode.h" + +/* this should be converted to use our types */ +struct divedatapoint { + int time; + depth_t depth; + int cylinderid; + pressure_t minimum_gas; + int setpoint; + bool entered; + struct divedatapoint *next; + enum divemode_t divemode; +}; + +struct diveplan { + timestamp_t when; + int surface_pressure; /* mbar */ + int bottomsac; /* ml/min */ + int decosac; /* ml/min */ + int salinity; + short gflow; + short gfhigh; + short vpmb_conservatism; + struct divedatapoint *dp; + int eff_gflow, eff_gfhigh; + int surface_interval; +}; + #ifdef __cplusplus extern "C" { #endif @@ -27,6 +56,17 @@ extern struct dive *planned_dive; extern char *cache_data; extern char *disclaimer; +struct divedatapoint *plan_add_segment(struct diveplan *diveplan, int duration, int depth, int cylinderid, int po2, bool entered, enum divemode_t divemode); +struct divedatapoint *create_dp(int time_incr, int depth, int cylinderid, int po2); +#if DEBUG_PLAN +void dump_plan(struct diveplan *diveplan); +#endif +struct decostop { + int depth; + int time; +}; +extern 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); + #ifdef __cplusplus } #endif diff --git a/core/profile.h b/core/profile.h index b7bf75664..2c4a632d5 100644 --- a/core/profile.h +++ b/core/profile.h @@ -23,8 +23,10 @@ enum plot_pressure { }; struct membuffer; +struct deco_state; struct divecomputer; struct plot_info; + struct plot_data { unsigned int in_deco : 1; int sec; diff --git a/core/qthelper.cpp b/core/qthelper.cpp index bc4c7fb74..cd9fc7b90 100644 --- a/core/qthelper.cpp +++ b/core/qthelper.cpp @@ -11,6 +11,7 @@ #include "version.h" #include "divecomputer.h" #include "errorhelper.h" +#include "planner.h" #include "time.h" #include "gettextfromc.h" #include "applicationstate.h" |