mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Cleanup: move planner/deco related declarations planner/deco.h
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
		
							parent
							
								
									594d1d3514
								
							
						
					
					
						commit
						52e5d9c605
					
				
					 13 changed files with 122 additions and 102 deletions
				
			
		| 
						 | 
				
			
			@ -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"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										36
									
								
								core/deco.h
									
										
									
									
									
								
							
							
						
						
									
										36
									
								
								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();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										26
									
								
								core/dive.c
									
										
									
									
									
								
							
							
						
						
									
										26
									
								
								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));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										72
									
								
								core/dive.h
									
										
									
									
									
								
							
							
						
						
									
										72
									
								
								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
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,6 +8,8 @@
 | 
			
		|||
extern "C" {
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
struct deco_state;
 | 
			
		||||
 | 
			
		||||
/* this is used for both git and xml format */
 | 
			
		||||
#define DATAFORMAT_VERSION 3
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										7
									
								
								core/divemode.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								core/divemode.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,7 +5,8 @@
 | 
			
		|||
#include <QAbstractTableModel>
 | 
			
		||||
#include <QDateTime>
 | 
			
		||||
 | 
			
		||||
#include "core/dive.h"
 | 
			
		||||
#include "core/deco.h"
 | 
			
		||||
#include "core/planner.h"
 | 
			
		||||
 | 
			
		||||
class DivePlannerPointsModel : public QAbstractTableModel {
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,7 +5,8 @@
 | 
			
		|||
#include <QAbstractTableModel>
 | 
			
		||||
 | 
			
		||||
#include "core/display.h"
 | 
			
		||||
#include "core/dive.h"
 | 
			
		||||
#include "core/deco.h"
 | 
			
		||||
#include "core/planner.h"
 | 
			
		||||
 | 
			
		||||
struct dive;
 | 
			
		||||
struct plot_data;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,6 @@
 | 
			
		|||
// SPDX-License-Identifier: GPL-2.0
 | 
			
		||||
#include "testplan.h"
 | 
			
		||||
#include "core/deco.h"
 | 
			
		||||
#include "core/dive.h"
 | 
			
		||||
#include "core/planner.h"
 | 
			
		||||
#include "core/qthelper.h"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue