Skip to content

Commit a4cd21b

Browse files
committed
Use the GTR mode to detect sidemount tanks
Firmware v84 introduced support for sidemount diving. Users can now configure the two sidemount tanks as the source for the GTR (Gas Time Remaining) estimations. We can take advantage of this feature to detect the sidemount tanks. This is more reliable than using the tank name.
1 parent f77e9c0 commit a4cd21b

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

src/array.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,3 +404,14 @@ signextend (unsigned int value, unsigned int nbits)
404404
else
405405
return value & mask;
406406
}
407+
408+
unsigned int
409+
popcount (unsigned int value)
410+
{
411+
unsigned int count = 0;
412+
while (value) {
413+
value &= value - 1;
414+
count++;
415+
}
416+
return count;
417+
}

src/array.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ dec2bcd (unsigned char value);
126126
unsigned int
127127
signextend (unsigned int value, unsigned int nbits);
128128

129+
unsigned int
130+
popcount (unsigned int value);
131+
129132
#ifdef __cplusplus
130133
}
131134
#endif /* __cplusplus */

src/shearwater_predator_parser.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ typedef struct shearwater_predator_tank_t {
118118
unsigned int pressure_reserve;
119119
unsigned int serial;
120120
char name[2];
121+
dc_usage_t usage;
121122
} shearwater_predator_tank_t;
122123

123124
struct shearwater_predator_parser_t {
@@ -254,6 +255,7 @@ shearwater_common_parser_create (dc_parser_t **out, dc_context_t *context, const
254255
parser->tank[i].pressure_reserve = 0;
255256
parser->tank[i].serial = 0;
256257
memset (parser->tank[i].name, 0, sizeof (parser->tank[i].name));
258+
parser->tank[i].usage = DC_USAGE_NONE;
257259
parser->tankidx[i] = i;
258260
}
259261
parser->aimode = AI_OFF;
@@ -547,6 +549,14 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser)
547549
}
548550
}
549551
}
552+
unsigned int gtrmode = data[offset + 29];
553+
if (popcount(gtrmode) >= 2) {
554+
for (unsigned int i = 0; i < 4; ++i) {
555+
if (gtrmode & (1 << i)) {
556+
tank[i].usage = DC_USAGE_SIDEMOUNT;
557+
}
558+
}
559+
}
550560
} else if (type == LOG_RECORD_OPENING_5) {
551561
if (logversion >= 9) {
552562
tank[0].serial = array_convert_bcd2dec (data + offset + 1, 3);
@@ -759,11 +769,7 @@ shearwater_predator_parser_get_field (dc_parser_t *abstract, dc_field_type_t typ
759769
break;
760770
}
761771
} else {
762-
if (parser->tank[flags].name[0] == 'S') {
763-
tank->usage = DC_USAGE_SIDEMOUNT;
764-
} else {
765-
tank->usage = DC_USAGE_NONE;
766-
}
772+
tank->usage = parser->tank[flags].usage;
767773
}
768774
break;
769775
case DC_FIELD_SALINITY:

0 commit comments

Comments
 (0)