aboutsummaryrefslogtreecommitdiffstats
path: root/core/cochran.c
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-08-04 18:44:57 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-11-09 19:19:04 +0100
commit7c9f46acd202121e67557bb634961ef17a9f6c1f (patch)
treef21b6ff42a930cc97c31db9f20c03f1613e70291 /core/cochran.c
parentcd4f66014f7b5269dff9e088c9d7d38241c03156 (diff)
downloadsubsurface-7c9f46acd202121e67557bb634961ef17a9f6c1f.tar.gz
Core: remove MAX_CYLINDERS restriction
Instead of using fixed size arrays, use a new cylinder_table structure. The code copies the weightsystem code, but is significantly more complex because cylinders are such an integral part of the core. Two functions to access the cylinders were added: get_cylinder() and get_or_create_cylinder() The former does a simple array access and supposes that the cylinder exists. The latter is used by the parser(s) and if a cylinder with the given id does not exist, cylinders up to that id are generated. One point will make C programmers cringe: the cylinder structure is passed by value. This is due to the way the table-macros work. A refactoring of the table macros is planned. It has to be noted that the size of a cylinder_t is 64 bytes, i.e. 8 long words on a 64-bit architecture, so passing on the stack is probably not even significantly slower than passing as reference. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/cochran.c')
-rw-r--r--core/cochran.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/core/cochran.c b/core/cochran.c
index 9cbc51113..632ba5bff 100644
--- a/core/cochran.c
+++ b/core/cochran.c
@@ -675,20 +675,24 @@ static void cochran_parse_dive(const unsigned char *decode, unsigned mod,
case TYPE_GEMINI:
case TYPE_COMMANDER:
if (config.type == TYPE_GEMINI) {
+ cylinder_t cyl = { 0 };
dc->model = "Gemini";
dc->deviceid = buf[0x18c] * 256 + buf[0x18d]; // serial no
- fill_default_cylinder(dive, 0);
- dive->cylinder[0].gasmix.o2.permille = (log[CMD_O2_PERCENT] / 256
+ fill_default_cylinder(dive, &cyl);
+ cyl.gasmix.o2.permille = (log[CMD_O2_PERCENT] / 256
+ log[CMD_O2_PERCENT + 1]) * 10;
- dive->cylinder[0].gasmix.he.permille = 0;
+ cyl.gasmix.he.permille = 0;
+ add_to_cylinder_table(&dive->cylinders, 0, cyl);
} else {
dc->model = "Commander";
dc->deviceid = array_uint32_le(buf + 0x31e); // serial no
for (g = 0; g < 2; g++) {
- fill_default_cylinder(dive, g);
- dive->cylinder[g].gasmix.o2.permille = (log[CMD_O2_PERCENT + g * 2] / 256
+ cylinder_t cyl = { 0 };
+ fill_default_cylinder(dive, &cyl);
+ cyl.gasmix.o2.permille = (log[CMD_O2_PERCENT + g * 2] / 256
+ log[CMD_O2_PERCENT + g * 2 + 1]) * 10;
- dive->cylinder[g].gasmix.he.permille = 0;
+ cyl.gasmix.he.permille = 0;
+ add_to_cylinder_table(&dive->cylinders, g, cyl);
}
}
@@ -727,13 +731,15 @@ static void cochran_parse_dive(const unsigned char *decode, unsigned mod,
dc->model = "EMC";
dc->deviceid = array_uint32_le(buf + 0x31e); // serial no
for (g = 0; g < 4; g++) {
- fill_default_cylinder(dive , g);
- dive->cylinder[g].gasmix.o2.permille =
+ cylinder_t cyl = { 0 };
+ fill_default_cylinder(dive, &cyl);
+ cyl.gasmix.o2.permille =
(log[EMC_O2_PERCENT + g * 2] / 256
+ log[EMC_O2_PERCENT + g * 2 + 1]) * 10;
- dive->cylinder[g].gasmix.he.permille =
+ 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);
}
tm.tm_year = log[EMC_YEAR];