summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/cochran.c6
-rw-r--r--core/equipment.c18
-rw-r--r--core/equipment.h4
-rw-r--r--core/libdivecomputer.c2
-rw-r--r--core/liquivision.c2
-rw-r--r--core/load-git.c2
-rw-r--r--core/planner.c2
7 files changed, 24 insertions, 12 deletions
diff --git a/core/cochran.c b/core/cochran.c
index 5955ddb69..55460014a 100644
--- a/core/cochran.c
+++ b/core/cochran.c
@@ -682,7 +682,7 @@ static void cochran_parse_dive(const unsigned char *decode, unsigned mod,
cyl.gasmix.o2.permille = (log[CMD_O2_PERCENT] / 256
+ log[CMD_O2_PERCENT + 1]) * 10;
cyl.gasmix.he.permille = 0;
- add_to_cylinder_table(&dive->cylinders, 0, cyl);
+ add_cylinder(&dive->cylinders, 0, cyl);
} else {
dc->model = "Commander";
dc->deviceid = array_uint32_le(buf + 0x31e); // serial no
@@ -692,7 +692,7 @@ static void cochran_parse_dive(const unsigned char *decode, unsigned mod,
cyl.gasmix.o2.permille = (log[CMD_O2_PERCENT + g * 2] / 256
+ log[CMD_O2_PERCENT + g * 2 + 1]) * 10;
cyl.gasmix.he.permille = 0;
- add_to_cylinder_table(&dive->cylinders, g, cyl);
+ add_cylinder(&dive->cylinders, g, cyl);
}
}
@@ -739,7 +739,7 @@ static void cochran_parse_dive(const unsigned char *decode, unsigned mod,
cyl.gasmix.he.permille =
(log[EMC_HE_PERCENT + g * 2] / 256
+ log[EMC_HE_PERCENT + g * 2 + 1]) * 10;
- add_to_cylinder_table(&dive->cylinders, g, cyl);
+ add_cylinder(&dive->cylinders, g, cyl);
}
tm.tm_year = log[EMC_YEAR];
diff --git a/core/equipment.c b/core/equipment.c
index 4be46ed1e..8d169d8d2 100644
--- a/core/equipment.c
+++ b/core/equipment.c
@@ -56,7 +56,7 @@ MAKE_CLEAR_TABLE(weightsystem_table, weightsystems, weightsystem)
//static MAKE_GET_IDX(cylinder_table, cylinder_t, cylinders)
static MAKE_GROW_TABLE(cylinder_table, cylinder_t, cylinders)
//static MAKE_GET_INSERTION_INDEX(cylinder_table, cylinder_t, cylinders, cylinder_less_than)
-MAKE_ADD_TO(cylinder_table, cylinder_t, cylinders)
+static MAKE_ADD_TO(cylinder_table, cylinder_t, cylinders)
MAKE_REMOVE_FROM(cylinder_table, cylinders)
//MAKE_SORT(cylinder_table, cylinder_t, cylinders, comp_cylinders)
//MAKE_REMOVE(cylinder_table, cylinder_t, cylinder)
@@ -144,11 +144,23 @@ cylinder_t clone_cylinder(cylinder_t cyl)
return res;
}
+void add_cylinder(struct cylinder_table *t, int idx, cylinder_t cyl)
+{
+ add_to_cylinder_table(t, idx, cyl);
+ /* FIXME: This is a horrible hack: we make sure that at the end of
+ * every single cylinder table there is an empty cylinder that can
+ * be used by the planner as "surface air" cylinder. Fix this.
+ */
+ add_to_cylinder_table(t, t->nr, empty_cylinder);
+ t->nr--;
+ t->cylinders[t->nr].cylinder_use = NOT_USED;
+}
+
/* Add a clone of a cylinder to the end of a cylinder table.
* Cloned in means that the description-string is copied. */
void add_cloned_cylinder(struct cylinder_table *t, cylinder_t cyl)
{
- add_to_cylinder_table(t, t->nr, clone_cylinder(cyl));
+ add_cylinder(t, t->nr, clone_cylinder(cyl));
}
bool same_weightsystem(weightsystem_t w1, weightsystem_t w2)
@@ -342,7 +354,7 @@ cylinder_t *add_empty_cylinder(struct cylinder_table *t)
{
cylinder_t cyl = empty_cylinder;
cyl.type.description = strdup("");
- add_to_cylinder_table(t, t->nr, cyl);
+ add_cylinder(t, t->nr, cyl);
return &t->cylinders[t->nr - 1];
}
diff --git a/core/equipment.h b/core/equipment.h
index 081a13835..c5a0db6d6 100644
--- a/core/equipment.h
+++ b/core/equipment.h
@@ -39,7 +39,7 @@ static const cylinder_t empty_cylinder = { { { 0 }, { 0 }, (const char *)0}, { {
* *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.
- * 2) add_to_cylinder_table(), etc. take ownership of the
+ * 2) add_cylinder(), etc. take ownership of the
* cylinder. Notably of the description string. */
struct cylinder_table {
int nr, allocated;
@@ -102,7 +102,7 @@ extern void add_to_weightsystem_table(struct weightsystem_table *, int idx, weig
/* Cylinder table functions */
extern void clear_cylinder_table(struct cylinder_table *);
-extern void add_to_cylinder_table(struct cylinder_table *, int idx, cylinder_t cyl);
+extern void add_cylinder(struct cylinder_table *, int idx, cylinder_t cyl);
void get_gas_string(struct gasmix gasmix, char *text, int len);
const char *gasname(struct gasmix gasmix);
diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c
index bc0836c3c..f40c55c2e 100644
--- a/core/libdivecomputer.c
+++ b/core/libdivecomputer.c
@@ -228,7 +228,7 @@ static int parse_gasmixes(device_data_t *devdata, struct dive *dive, dc_parser_t
if (empty_string(cyl.type.description))
cyl.type.description = strdup(translate("gettextFromC", "unknown"));
- add_to_cylinder_table(&dive->cylinders, dive->cylinders.nr, cyl);
+ add_cylinder(&dive->cylinders, dive->cylinders.nr, cyl);
}
return DC_STATUS_SUCCESS;
}
diff --git a/core/liquivision.c b/core/liquivision.c
index 905091dd8..5a9caf603 100644
--- a/core/liquivision.c
+++ b/core/liquivision.c
@@ -151,7 +151,7 @@ static void parse_dives(int log_version, const unsigned char *buf, unsigned int
for (i = 0; i < 1; i++) {
cylinder_t cyl = empty_cylinder;
fill_default_cylinder(dive, &cyl);
- add_to_cylinder_table(&dive->cylinders, i, cyl);
+ add_cylinder(&dive->cylinders, i, cyl);
}
// Model 0=Xen, 1,2=Xeo, 4=Lynx, other=Liquivision
diff --git a/core/load-git.c b/core/load-git.c
index b7353763f..24f96a794 100644
--- a/core/load-git.c
+++ b/core/load-git.c
@@ -455,7 +455,7 @@ static void parse_dive_cylinder(char *line, struct membuffer *str, struct git_pa
if (cylinder.cylinder_use == OXYGEN)
state->o2pressure_sensor = state->active_dive->cylinders.nr;
- add_to_cylinder_table(&state->active_dive->cylinders, state->active_dive->cylinders.nr, cylinder);
+ add_cylinder(&state->active_dive->cylinders, state->active_dive->cylinders.nr, cylinder);
}
static void parse_weightsystem_keyvalue(void *_ws, const char *key, const char *value)
diff --git a/core/planner.c b/core/planner.c
index a5f0d36bc..8cadaca01 100644
--- a/core/planner.c
+++ b/core/planner.c
@@ -1074,7 +1074,7 @@ bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, i
// If no empty cylinder is found, keep using last deco gas
cylinder_t cyl = empty_cylinder;
cyl.cylinder_use = NOT_USED;
- add_to_cylinder_table(&dive->cylinders, dive->cylinders.nr, cyl);
+ add_cylinder(&dive->cylinders, dive->cylinders.nr, cyl);
current_cylinder = dive->cylinders.nr - 1;
plan_add_segment(diveplan, prefs.surface_segment, 0, current_cylinder, 0, false, OC);
}