diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-10-25 13:28:55 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-10-25 13:59:52 -0700 |
commit | 0e196310f9cda2ccca27e9cf96186639b5658249 (patch) | |
tree | f53ee1f276774aa85b6bbe7015a302aa33339eb6 /core/divecomputer.h | |
parent | 4aa571d5a09e7c114633dc046bb8a61044a05d63 (diff) | |
download | subsurface-0e196310f9cda2ccca27e9cf96186639b5658249.tar.gz |
cleanup: split out divecomputer functions from dive.c
Since dive.c is so huge, split out divecomputer-related functions
into divecomputer.[c|h], sample.[c|h] and extradata.[c|h].
This does not give huge compile time improvements, since
struct dive contains a struct divecomputer and therefore
dive.h has to include divecomputer.h. However, it make things
distinctly more clear.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/divecomputer.h')
-rw-r--r-- | core/divecomputer.h | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/core/divecomputer.h b/core/divecomputer.h new file mode 100644 index 000000000..eb48e9b86 --- /dev/null +++ b/core/divecomputer.h @@ -0,0 +1,79 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef DIVECOMPUTER_H +#define DIVECOMPUTER_H + +#include "divemode.h" +#include "units.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct extra_data; +struct sample; + +/* Is this header the correct place? */ +#define SURFACE_THRESHOLD 750 /* somewhat arbitrary: only below 75cm is it really diving */ + +/* + * NOTE! The deviceid and diveid are model-specific *hashes* of + * whatever device identification that model may have. Different + * dive computers will have different identifying data, it could + * be a firmware number or a serial ID (in either string or in + * numeric format), and we do not care. + * + * The only thing we care about is that subsurface will hash + * that information the same way. So then you can check the ID + * of a dive computer by comparing the hashes for equality. + * + * A deviceid or diveid of zero is assumed to be "no ID". + */ +struct divecomputer { + timestamp_t when; + duration_t duration, surfacetime, last_manual_time; + depth_t maxdepth, meandepth; + temperature_t airtemp, watertemp; + pressure_t surface_pressure; + enum divemode_t divemode; // dive computer type: OC(default) or CCR + uint8_t no_o2sensors; // rebreathers: number of O2 sensors used + int salinity; // kg per 10000 l + const char *model, *serial, *fw_version; + uint32_t deviceid, diveid; + int samples, alloc_samples; + struct sample *sample; + struct event *events; + struct extra_data *extra_data; + struct divecomputer *next; +}; + +extern void fake_dc(struct divecomputer *dc); +extern void free_dc(struct divecomputer *dc); +extern void free_dc_contents(struct divecomputer *dc); +extern enum divemode_t get_current_divemode(const struct divecomputer *dc, int time, const struct event **evp, enum divemode_t *divemode); +extern int get_depth_at_time(const struct divecomputer *dc, unsigned int time); +extern void free_dive_dcs(struct divecomputer *dc); +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 fixup_dc_duration(struct divecomputer *dc); +extern unsigned int dc_airtemp(const struct divecomputer *dc); +extern unsigned int dc_watertemp(const struct divecomputer *dc); +extern void copy_events(const struct divecomputer *s, struct divecomputer *d); +extern void swap_event(struct divecomputer *dc, struct event *from, struct event *to); +extern void copy_samples(const struct divecomputer *s, struct divecomputer *d); +extern void add_event_to_dc(struct divecomputer *dc, struct event *ev); +extern struct event *add_event(struct divecomputer *dc, unsigned int time, int type, int flags, int value, const char *name); +extern void remove_event_from_dc(struct divecomputer *dc, struct event *event); +extern void add_extra_data(struct divecomputer *dc, const char *key, const char *value); +extern bool is_dc_planner(const struct divecomputer *dc); + +/* Check if two dive computer entries are the exact same dive (-1=no/0=maybe/1=yes) */ +extern int match_one_dc(const struct divecomputer *a, const struct divecomputer *b); + +#ifdef __cplusplus +} +#endif + +#endif |