2019-05-30 18:51:30 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#ifndef EQUIPMENT_H
|
|
|
|
#define EQUIPMENT_H
|
|
|
|
|
2019-06-04 11:52:48 +00:00
|
|
|
#include "gas.h"
|
2019-05-30 18:51:30 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct dive;
|
|
|
|
|
|
|
|
enum cylinderuse {OC_GAS, DILUENT, OXYGEN, NOT_USED, NUM_GAS_USE}; // The different uses for cylinders
|
2020-10-25 17:27:01 +00:00
|
|
|
extern const char *cylinderuse_text[NUM_GAS_USE];
|
2019-05-30 18:51:30 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
volume_t size;
|
|
|
|
pressure_t workingpressure;
|
|
|
|
const char *description; /* "LP85", "AL72", "AL80", "HP100+" or whatever */
|
|
|
|
} cylinder_type_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
cylinder_type_t type;
|
|
|
|
struct gasmix gasmix;
|
|
|
|
pressure_t start, end, sample_start, sample_end;
|
|
|
|
depth_t depth;
|
|
|
|
bool manually_added;
|
|
|
|
volume_t gas_used;
|
|
|
|
volume_t deco_gas_used;
|
|
|
|
enum cylinderuse cylinder_use;
|
|
|
|
bool bestmix_o2;
|
|
|
|
bool bestmix_he;
|
|
|
|
} cylinder_t;
|
|
|
|
|
2020-01-07 03:00:20 +00:00
|
|
|
static const cylinder_t empty_cylinder = { { { 0 }, { 0 }, (const char *)0}, { { 0 }, { 0 } } , { 0 }, { 0 }, { 0 }, { 0 }, { 0 }, false, { 0 }, { 0 }, OC_GAS, false, false };
|
|
|
|
|
2019-08-04 16:44:57 +00:00
|
|
|
/* Table of cylinders. Attention: this stores cylinders,
|
|
|
|
* *not* pointers to cylinders. This has two crucial consequences:
|
|
|
|
* 1) Pointers to cylinders are not stable. They may be
|
|
|
|
* invalidated if the table is reallocated.
|
2020-04-28 12:50:40 +00:00
|
|
|
* 2) add_cylinder(), etc. take ownership of the
|
2019-08-04 16:44:57 +00:00
|
|
|
* cylinder. Notably of the description string. */
|
|
|
|
struct cylinder_table {
|
|
|
|
int nr, allocated;
|
|
|
|
cylinder_t *cylinders;
|
|
|
|
};
|
|
|
|
|
2019-05-30 18:51:30 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
weight_t weight;
|
|
|
|
const char *description; /* "integrated", "belt", "ankle" */
|
2020-09-12 16:50:06 +00:00
|
|
|
bool auto_filled; /* weight was automatically derived from the type */
|
2019-05-30 18:51:30 +00:00
|
|
|
} weightsystem_t;
|
|
|
|
|
2020-09-12 16:50:06 +00:00
|
|
|
static const weightsystem_t empty_weightsystem = { { 0 }, 0, false };
|
2019-11-03 22:08:32 +00:00
|
|
|
|
2019-06-26 15:21:03 +00:00
|
|
|
/* Table of weightsystems. Attention: this stores weightsystems,
|
|
|
|
* *not* pointers * to weightsystems. This has two crucial
|
|
|
|
* consequences:
|
|
|
|
* 1) Pointers to weightsystems are not stable. They may be
|
|
|
|
* invalidated if the table is reallocated.
|
|
|
|
* 2) add_to_weightsystem_table(), etc. takes ownership of the
|
|
|
|
* weightsystem. Notably of the description string */
|
|
|
|
struct weightsystem_table {
|
|
|
|
int nr, allocated;
|
|
|
|
weightsystem_t *weightsystems;
|
|
|
|
};
|
|
|
|
|
2019-05-30 18:51:30 +00:00
|
|
|
#define MAX_WS_INFO (100)
|
|
|
|
|
2024-02-28 07:42:23 +00:00
|
|
|
extern enum cylinderuse cylinderuse_from_text(const char *text);
|
2019-06-26 15:21:03 +00:00
|
|
|
extern void copy_weights(const struct weightsystem_table *s, struct weightsystem_table *d);
|
2020-04-11 13:00:15 +00:00
|
|
|
extern void copy_cylinders(const struct cylinder_table *s, struct cylinder_table *d);
|
2019-11-03 14:04:48 +00:00
|
|
|
extern weightsystem_t clone_weightsystem(weightsystem_t ws);
|
2019-11-03 22:14:35 +00:00
|
|
|
extern void free_weightsystem(weightsystem_t ws);
|
2019-08-04 12:42:21 +00:00
|
|
|
extern void copy_cylinder_types(const struct dive *s, struct dive *d);
|
2019-06-26 15:21:03 +00:00
|
|
|
extern void add_cloned_weightsystem(struct weightsystem_table *t, weightsystem_t ws);
|
2020-02-23 10:05:19 +00:00
|
|
|
extern cylinder_t clone_cylinder(cylinder_t cyl);
|
2020-02-23 10:07:51 +00:00
|
|
|
extern void free_cylinder(cylinder_t cyl);
|
2019-08-04 17:17:11 +00:00
|
|
|
extern cylinder_t *add_empty_cylinder(struct cylinder_table *t);
|
2019-08-04 16:44:57 +00:00
|
|
|
extern void add_cloned_cylinder(struct cylinder_table *t, cylinder_t cyl);
|
|
|
|
extern cylinder_t *get_cylinder(const struct dive *d, int idx);
|
|
|
|
extern cylinder_t *get_or_create_cylinder(struct dive *d, int idx);
|
2019-06-05 18:26:51 +00:00
|
|
|
extern void add_cylinder_description(const cylinder_type_t *);
|
|
|
|
extern void add_weightsystem_description(const weightsystem_t *);
|
2019-06-25 19:26:51 +00:00
|
|
|
extern bool same_weightsystem(weightsystem_t w1, weightsystem_t w2);
|
2019-05-30 18:51:30 +00:00
|
|
|
extern void remove_cylinder(struct dive *dive, int idx);
|
|
|
|
extern void remove_weightsystem(struct dive *dive, int idx);
|
2019-11-08 21:47:38 +00:00
|
|
|
extern void set_weightsystem(struct dive *dive, int idx, weightsystem_t ws);
|
2019-05-30 18:51:30 +00:00
|
|
|
extern void reset_cylinders(struct dive *dive, bool track_gas);
|
2019-06-04 11:52:48 +00:00
|
|
|
extern int gas_volume(const cylinder_t *cyl, pressure_t p); /* Volume in mliter of a cylinder at pressure 'p' */
|
2019-08-04 16:44:57 +00:00
|
|
|
extern int find_best_gasmix_match(struct gasmix mix, const struct cylinder_table *cylinders);
|
2020-03-02 14:34:56 +00:00
|
|
|
extern void fill_default_cylinder(const struct dive *dive, cylinder_t *cyl); /* dive is needed to fill out MOD, which depends on salinity. */
|
2020-03-01 15:26:47 +00:00
|
|
|
extern cylinder_t create_new_cylinder(const struct dive *dive); /* dive is needed to fill out MOD, which depends on salinity. */
|
2021-11-21 10:39:02 +00:00
|
|
|
extern int first_hidden_cylinder(const struct dive *d);
|
2019-05-30 18:51:30 +00:00
|
|
|
#ifdef DEBUG_CYL
|
|
|
|
extern void dump_cylinders(struct dive *dive, bool verbose);
|
|
|
|
#endif
|
|
|
|
|
2019-06-26 15:21:03 +00:00
|
|
|
/* Weightsystem table functions */
|
|
|
|
extern void clear_weightsystem_table(struct weightsystem_table *);
|
|
|
|
extern void add_to_weightsystem_table(struct weightsystem_table *, int idx, weightsystem_t ws);
|
|
|
|
|
2019-08-04 16:44:57 +00:00
|
|
|
/* Cylinder table functions */
|
|
|
|
extern void clear_cylinder_table(struct cylinder_table *);
|
2020-04-28 12:50:40 +00:00
|
|
|
extern void add_cylinder(struct cylinder_table *, int idx, cylinder_t cyl);
|
2019-08-04 16:44:57 +00:00
|
|
|
|
2019-05-30 18:51:30 +00:00
|
|
|
void get_gas_string(struct gasmix gasmix, char *text, int len);
|
|
|
|
const char *gasname(struct gasmix gasmix);
|
|
|
|
|
2020-12-11 21:34:35 +00:00
|
|
|
typedef struct tank_info {
|
2019-05-30 18:51:30 +00:00
|
|
|
const char *name;
|
|
|
|
int cuft, ml, psi, bar;
|
2020-12-11 21:34:35 +00:00
|
|
|
} tank_info_t;
|
|
|
|
|
|
|
|
struct tank_info_table {
|
|
|
|
int nr, allocated;
|
|
|
|
struct tank_info *infos;
|
2019-05-30 18:51:30 +00:00
|
|
|
};
|
2020-12-11 21:34:35 +00:00
|
|
|
|
|
|
|
extern struct tank_info_table tank_info_table;
|
|
|
|
extern void reset_tank_info_table(struct tank_info_table *table);
|
|
|
|
extern void clear_tank_info_table(struct tank_info_table *table);
|
|
|
|
extern void add_tank_info_metric(struct tank_info_table *table, const char *name, int ml, int bar);
|
|
|
|
extern void add_tank_info_imperial(struct tank_info_table *table, const char *name, int cuft, int psi);
|
2024-03-30 12:40:00 +00:00
|
|
|
extern void set_tank_info_size(struct tank_info_table *table, const char *name, volume_t size);
|
|
|
|
extern void set_tank_info_workingpressure(struct tank_info_table *table, const char *name, pressure_t working_pressure);
|
|
|
|
extern struct tank_info *get_tank_info(struct tank_info_table *table, const char *name);
|
2019-05-30 18:51:30 +00:00
|
|
|
|
|
|
|
struct ws_info_t {
|
|
|
|
const char *name;
|
|
|
|
int grams;
|
|
|
|
};
|
|
|
|
extern struct ws_info_t ws_info[MAX_WS_INFO];
|
2024-03-30 12:40:00 +00:00
|
|
|
extern struct ws_info_t *get_weightsystem_description(const char *name);
|
2019-05-30 18:51:30 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // EQUIPMENT_H
|