diff options
Diffstat (limited to 'core/dive.h')
-rw-r--r-- | core/dive.h | 141 |
1 files changed, 75 insertions, 66 deletions
diff --git a/core/dive.h b/core/dive.h index 01ec1fd3d..4c24dad74 100644 --- a/core/dive.h +++ b/core/dive.h @@ -71,7 +71,7 @@ struct icd_data { // This structure provides communication between function isob int dHe; // The change in fraction (permille) of helium during the change }; -extern bool isobaric_counterdiffusion(struct gasmix *oldgasmix, struct gasmix *newgasmix, struct icd_data *results); +extern bool isobaric_counterdiffusion(struct gasmix oldgasmix, struct gasmix newgasmix, struct icd_data *results); /* * Events are currently based straight on what libdivecomputer gives us. @@ -100,7 +100,7 @@ struct event { char name[]; }; -extern int event_is_gaschange(struct event *ev); +extern int event_is_gaschange(const struct event *ev); extern int get_pressure_units(int mb, const char **units); extern double get_depth_units(int mm, int *frac, const char **units); @@ -113,33 +113,33 @@ extern depth_t units_to_depth(double depth); extern int units_to_sac(double volume); /* Volume in mliter of a cylinder at pressure 'p' */ -extern int gas_volume(cylinder_t *cyl, pressure_t p); -extern double gas_compressibility_factor(struct gasmix *gas, double bar); -extern double isothermal_pressure(struct gasmix *gas, double p1, int volume1, int volume2); -extern double gas_density(struct gasmix *gas, int pressure); -extern int same_gasmix(struct gasmix *a, struct gasmix *b); +extern int gas_volume(const cylinder_t *cyl, pressure_t p); +extern double gas_compressibility_factor(struct gasmix gas, double bar); +extern double isothermal_pressure(struct gasmix gas, double p1, int volume1, int volume2); +extern double gas_density(struct gasmix gas, int pressure); +extern int same_gasmix(struct gasmix a, struct gasmix b); -static inline int get_o2(const struct gasmix *mix) +static inline int get_o2(struct gasmix mix) { - return mix->o2.permille ?: O2_IN_AIR; + return mix.o2.permille ?: O2_IN_AIR; } -static inline int get_he(const struct gasmix *mix) +static inline int get_he(struct gasmix mix) { - return mix->he.permille; + return mix.he.permille; } struct gas_pressures { double o2, n2, he; }; -extern void fill_pressures(struct gas_pressures *pressures, const double amb_pressure, const struct gasmix *mix, double po2, enum divemode_t dctype); +extern void fill_pressures(struct gas_pressures *pressures, const double amb_pressure, struct gasmix mix, double po2, enum divemode_t dctype); extern void sanitize_gasmix(struct gasmix *mix); -extern int gasmix_distance(const struct gasmix *a, const struct gasmix *b); -extern int find_best_gasmix_match(struct gasmix *mix, cylinder_t array[], unsigned int used); +extern int gasmix_distance(struct gasmix a, struct gasmix b); +extern int find_best_gasmix_match(struct gasmix mix, const cylinder_t array[], unsigned int used); -extern bool gasmix_is_air(const struct gasmix *gasmix); +extern bool gasmix_is_air(struct gasmix gasmix); /* Linear interpolation between 'a' and 'b', when we are 'part'way into the 'whole' distance from a to b */ static inline int interpolate(int a, int b, int part, int whole) @@ -152,8 +152,8 @@ static inline int interpolate(int a, int b, int part, int whole) return (a+b)/2; } -void get_gas_string(const struct gasmix *gasmix, char *text, int len); -const char *gasname(const struct gasmix *gasmix); +void get_gas_string(struct gasmix gasmix, char *text, int len); +const char *gasname(struct gasmix gasmix); #define MAX_SENSORS 2 struct sample // BASE TYPE BYTES UNITS RANGE DESCRIPTION @@ -334,7 +334,7 @@ struct dive { extern void invalidate_dive_cache(struct dive *dive); extern bool dive_cache_is_valid(const struct dive *dive); -extern int get_cylinder_idx_by_use(struct dive *dive, enum cylinderuse cylinder_use_type); +extern int get_cylinder_idx_by_use(const struct dive *dive, enum cylinderuse cylinder_use_type); extern void cylinder_renumber(struct dive *dive, int mapping[]); extern int same_gasmix_cylinder(cylinder_t *cyl, int cylid, struct dive *dive, bool check_unused); @@ -352,9 +352,9 @@ struct dive_components { unsigned int weights : 1; }; -extern enum divemode_t get_current_divemode(struct divecomputer *dc, int time, struct event **evp, enum divemode_t *divemode); -extern struct event *get_next_divemodechange(struct event **evd, bool update_pointer); -extern enum divemode_t get_divemode_at_time(struct divecomputer *dc, int dtime, struct event **ev_dmc); +extern enum divemode_t get_current_divemode(const struct divecomputer *dc, int time, const struct event **evp, enum divemode_t *divemode); +extern struct event *get_next_divemodechange(const struct event **evd, bool update_pointer); +extern enum divemode_t get_divemode_at_time(const struct divecomputer *dc, int dtime, const struct event **ev_dmc); /* picture list and methods related to dive picture handling */ struct picture { @@ -373,7 +373,7 @@ struct picture { for (struct picture *picture = (_divestruct).picture_list; picture; picture = picture->next) extern struct picture *alloc_picture(); -extern bool dive_check_picture_time(struct dive *d, int shift_time, timestamp_t timestamp); +extern bool dive_check_picture_time(const struct dive *d, int shift_time, timestamp_t timestamp); extern void dive_create_picture(struct dive *d, const char *filename, int shift_time, bool match_all); extern void dive_add_picture(struct dive *d, struct picture *newpic); extern bool dive_remove_picture(struct dive *d, const char *filename); @@ -382,22 +382,22 @@ extern bool picture_check_valid(const char *filename, int shift_time); extern void dive_set_geodata_from_picture(struct dive *d, struct picture *pic); extern void picture_free(struct picture *picture); -extern bool has_gaschange_event(struct dive *dive, struct divecomputer *dc, int idx); -extern int explicit_first_cylinder(struct dive *dive, struct divecomputer *dc); -extern int get_depth_at_time(struct divecomputer *dc, unsigned int time); +extern bool has_gaschange_event(const struct dive *dive, const struct divecomputer *dc, int idx); +extern int explicit_first_cylinder(const struct dive *dive, const struct divecomputer *dc); +extern int get_depth_at_time(const struct divecomputer *dc, unsigned int time); -extern fraction_t best_o2(depth_t depth, struct dive *dive); -extern fraction_t best_he(depth_t depth, struct dive *dive); +extern fraction_t best_o2(depth_t depth, const struct dive *dive); +extern fraction_t best_he(depth_t depth, const struct dive *dive); extern int get_surface_pressure_in_mbar(const struct dive *dive, bool non_null); extern int calculate_depth_to_mbar(int depth, pressure_t surface_pressure, int salinity); -extern int depth_to_mbar(int depth, struct dive *dive); -extern double depth_to_bar(int depth, struct dive *dive); -extern double depth_to_atm(int depth, struct dive *dive); -extern int rel_mbar_to_depth(int mbar, struct dive *dive); -extern int mbar_to_depth(int mbar, struct dive *dive); -extern depth_t gas_mod(struct gasmix *mix, pressure_t po2_limit, struct dive *dive, int roundto); -extern depth_t gas_mnd(struct gasmix *mix, depth_t end, struct dive *dive, int roundto); +extern int depth_to_mbar(int depth, const struct dive *dive); +extern double depth_to_bar(int depth, const struct dive *dive); +extern double depth_to_atm(int depth, const struct dive *dive); +extern int rel_mbar_to_depth(int mbar, const struct dive *dive); +extern int mbar_to_depth(int mbar, const struct dive *dive); +extern depth_t gas_mod(struct gasmix mix, pressure_t po2_limit, const struct dive *dive, int roundto); +extern depth_t gas_mnd(struct gasmix mix, depth_t end, const struct dive *dive, int roundto); #define SURFACE_THRESHOLD 750 /* somewhat arbitrary: only below 75cm is it really diving */ @@ -442,10 +442,10 @@ extern unsigned int dc_number; extern struct dive *get_dive(int nr); extern struct dive *get_dive_from_table(int nr, struct dive_table *dt); -extern struct dive_site *get_dive_site_for_dive(struct dive *dive); -extern const char *get_dive_country(struct dive *dive); +extern struct dive_site *get_dive_site_for_dive(const struct dive *dive); +extern const char *get_dive_country(const struct dive *dive); extern const char *get_dive_location(const struct dive *dive); -extern unsigned int number_of_computers(struct dive *dive); +extern unsigned int number_of_computers(const struct dive *dive); extern struct divecomputer *get_dive_dc(struct dive *dive, int nr); extern timestamp_t dive_endtime(const struct dive *dive); @@ -475,8 +475,8 @@ extern "C" { extern struct dive *get_dive_by_uniq_id(int id); extern int get_idx_by_uniq_id(int id); -extern bool dive_site_has_gps_location(struct dive_site *ds); -extern int dive_has_gps_location(struct dive *dive); +extern bool dive_site_has_gps_location(const struct dive_site *ds); +extern int dive_has_gps_location(const struct dive *dive); extern int report_error(const char *fmt, ...); extern void set_error_cb(void(*cb)(char *)); // Callback takes ownership of passed string @@ -487,7 +487,7 @@ extern bool time_during_dive_with_offset(struct dive *dive, timestamp_t when, ti struct dive *find_dive_n_near(timestamp_t when, int n, timestamp_t offset); /* Check if two dive computer entries are the exact same dive (-1=no/0=maybe/1=yes) */ -extern int match_one_dc(struct divecomputer *a, struct divecomputer *b); +extern int match_one_dc(const struct divecomputer *a, const struct divecomputer *b); extern void parse_xml_init(void); extern int parse_xml_buffer(const char *url, const char *buf, int size, struct dive_table *table, const char **params); @@ -499,9 +499,9 @@ extern int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buf, i extern int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table); extern int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table); extern int parse_divinglog_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table); -extern int parse_dlf_buffer(unsigned char *buffer, size_t size); +extern int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *table); -extern int parse_file(const char *filename); +extern int parse_file(const char *filename, struct dive_table *table); extern int parse_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate); extern int parse_seabear_log(const char *filename); extern int parse_txt_file(const char *filename, const char *csv); @@ -547,8 +547,8 @@ extern struct dive *alloc_dive(void); extern void record_dive_to_table(struct dive *dive, struct dive_table *table); extern void record_dive(struct dive *dive); extern void clear_dive(struct dive *dive); -extern void copy_dive(struct dive *s, struct dive *d); -extern void selective_copy_dive(struct dive *s, struct dive *d, struct dive_components what, bool clear); +extern void copy_dive(const struct dive *s, struct dive *d); +extern void selective_copy_dive(const struct dive *s, struct dive *d, struct dive_components what, bool clear); extern struct dive *clone_dive(struct dive *s); extern void clear_table(struct dive_table *table); @@ -557,37 +557,38 @@ extern void alloc_samples(struct divecomputer *dc, int num); extern void free_samples(struct divecomputer *dc); extern struct sample *prepare_sample(struct divecomputer *dc); extern void finish_sample(struct divecomputer *dc); +extern struct sample *add_sample(const struct sample *sample, int time, struct divecomputer *dc); extern void add_sample_pressure(struct sample *sample, int sensor, int mbar); -extern int legacy_format_o2pressures(struct dive *dive, struct divecomputer *dc); +extern int legacy_format_o2pressures(const struct dive *dive, const struct divecomputer *dc); extern void sort_table(struct dive_table *table); extern struct dive *fixup_dive(struct dive *dive); extern void fixup_dc_duration(struct divecomputer *dc); extern int dive_getUniqID(); -extern unsigned int dc_airtemp(struct divecomputer *dc); -extern unsigned int dc_watertemp(struct divecomputer *dc); +extern unsigned int dc_airtemp(const struct divecomputer *dc); +extern unsigned int dc_watertemp(const struct divecomputer *dc); extern int split_dive(struct dive *); extern void split_dive_at_time(struct dive *dive, duration_t time); extern struct dive *merge_dives(struct dive *a, struct dive *b, int offset, bool prefer_downloaded); extern struct dive *try_to_merge(struct dive *a, struct dive *b, bool prefer_downloaded); extern struct event *clone_event(const struct event *src_ev); -extern void copy_events(struct divecomputer *s, struct divecomputer *d); +extern void copy_events(const struct divecomputer *s, struct divecomputer *d); extern void free_events(struct event *ev); -extern void copy_cylinders(struct dive *s, struct dive *d, bool used_only); -extern void copy_samples(struct divecomputer *s, struct divecomputer *d); -extern bool is_cylinder_used(struct dive *dive, int idx); -extern bool is_cylinder_prot(struct dive *dive, int idx); +extern void copy_cylinders(const struct dive *s, struct dive *d, bool used_only); +extern void copy_samples(const struct divecomputer *s, struct divecomputer *d); +extern bool is_cylinder_used(const struct dive *dive, int idx); +extern bool is_cylinder_prot(const struct dive *dive, int idx); extern void fill_default_cylinder(cylinder_t *cyl); extern void add_gas_switch_event(struct dive *dive, struct divecomputer *dc, int time, int idx); extern struct event *add_event(struct divecomputer *dc, unsigned int time, int type, int flags, int value, const char *name); extern void remove_event(struct event *event); -extern void update_event_name(struct dive *d, struct event* event, const char *name); +extern void update_event_name(struct dive *d, struct event *event, const char *name); extern void add_extra_data(struct divecomputer *dc, const char *key, const char *value); -extern void per_cylinder_mean_depth(struct dive *dive, struct divecomputer *dc, int *mean, int *duration); -extern int get_cylinder_index(struct dive *dive, struct event *ev); -extern struct gasmix *get_gasmix_from_event(struct dive *, struct event *ev); -extern int nr_cylinders(struct dive *dive); -extern int nr_weightsystems(struct dive *dive); +extern void per_cylinder_mean_depth(const struct dive *dive, struct divecomputer *dc, int *mean, int *duration); +extern int get_cylinder_index(const struct dive *dive, const struct event *ev); +extern struct gasmix get_gasmix_from_event(const struct dive *, const struct event *ev); +extern int nr_cylinders(const struct dive *dive); +extern int nr_weightsystems(const struct dive *dive); /* UI related protopypes */ @@ -606,7 +607,7 @@ extern void clear_events(void); extern void set_dc_nickname(struct dive *dive); extern void set_autogroup(bool value); -extern int total_weight(struct dive *); +extern int total_weight(const struct dive *); #ifdef __cplusplus } @@ -663,7 +664,7 @@ struct deco_state { bool icd_warning; }; -extern void add_segment(struct deco_state *ds, double pressure, const struct gasmix *gasmix, int period_in_seconds, int setpoint, enum divemode_t divemode, int sac); +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 void clear_deco(struct deco_state *ds, double surface_pressure); extern void dump_tissues(struct deco_state *ds); extern void set_gf(short gflow, short gfhigh); @@ -716,9 +717,18 @@ 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 struct event *get_next_event(struct event *event, const char *name); +/* 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); -extern struct gasmix *get_gasmix(struct dive *dive, struct divecomputer *dc, int time, struct event **evp, struct gasmix *gasmix); +/* Get gasmixes at increasing timestamps. + * In "evp", pass a pointer to a "struct event *" which is NULL-initialized on first invocation. + * On subsequent calls, pass the same "evp" and the "gasmix" from previous calls. + */ +extern struct gasmix get_gasmix(const struct dive *dive, const struct divecomputer *dc, int time, const struct event **evp, struct gasmix gasmix); + +/* Get gasmix at a given time */ +extern struct gasmix get_gasmix_at_time(const struct dive *dive, const struct divecomputer *dc, duration_t time); /* these structs holds the information that * describes the cylinders / weight systems. @@ -740,9 +750,8 @@ struct ws_info_t { extern struct ws_info_t ws_info[MAX_WS_INFO]; extern bool cylinder_nodata(const cylinder_t *cyl); -extern bool cylinder_none(void *_data); -extern bool weightsystem_none(void *_data); -extern bool no_weightsystems(weightsystem_t *ws); +extern bool cylinder_none(const cylinder_t *cyl); +extern bool weightsystem_none(const weightsystem_t *ws); extern void remove_cylinder(struct dive *dive, int idx); extern void remove_weightsystem(struct dive *dive, int idx); extern void reset_cylinders(struct dive *dive, bool track_gas); @@ -755,7 +764,7 @@ extern void set_informational_units(const char *units); extern void set_git_prefs(const char *prefs); extern char *get_dive_date_c_string(timestamp_t when); -extern void update_setpoint_events(struct dive *dive, struct divecomputer *dc); +extern void update_setpoint_events(const struct dive *dive, struct divecomputer *dc); #ifdef __cplusplus } |