Skip to content

Commit a696627

Browse files
jefdriesenmikeller
authored andcommitted
Add support for new record types
Log format version 1.6 introduces some new record types. The ID_TANK_TRANSMITTER record reports a tank pressure from a transmitter not linked to a gas mix. Unlike the previous ID_GAS_TRANSMITTER record, the tank id is no longer the transmitter serial number, but a transmitter index (0-3). To avoid conflicts and being able to distinguish the two types, one of the higher bit is set internally.
1 parent 18c3074 commit a696627

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

src/halcyon_symbios_parser.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
#define ID_LOG_VERSION 0x0F
4848
#define ID_TRIM 0x10
4949
#define ID_GAS_CONFIG 0x11
50+
#define ID_TANK_TRANSMITTER 0x12
51+
#define ID_GF_INFO 0x13
5052

5153
#define ISCONFIG(type) ( \
5254
(type) == ID_LOG_VERSION || \
@@ -65,6 +67,8 @@
6567
#define NGASMIXES 10
6668
#define NTANKS 10
6769

70+
#define TRANSMITTER_ID (1u << 16)
71+
6872
typedef struct halcyon_symbios_gasmix_t {
6973
unsigned int id;
7074
unsigned int oxygen;
@@ -305,6 +309,8 @@ halcyon_symbios_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callbac
305309
4, /* ID_LOG_VERSION */
306310
4, /* ID_TRIM */
307311
8, /* ID_GAS_CONFIG */
312+
8, /* ID_TANK_TRANSMITTER */
313+
6, /* ID_GF_INFO */
308314
};
309315

310316
unsigned int time_start = UNDEFINED, time_end = UNDEFINED;
@@ -632,6 +638,49 @@ halcyon_symbios_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callbac
632638
if (callback) callback(DC_SAMPLE_GASMIX, &sample, userdata);
633639
}
634640
}
641+
} else if (type == ID_TANK_TRANSMITTER) {
642+
unsigned int id = data[offset + 2] | TRANSMITTER_ID;
643+
unsigned int DC_ATTR_UNUSED battery = array_uint16_le (data + offset + 4);
644+
unsigned int pressure = array_uint16_le (data + offset + 6) / 10;
645+
dc_usage_t usage = DC_USAGE_NONE;
646+
647+
if (tank_id_previous != id ||
648+
tank_usage_previous != usage) {
649+
// Find the tank in the list.
650+
unsigned int idx = 0;
651+
while (idx < ntanks) {
652+
if (tank[idx].id == id &&
653+
tank[idx].usage == usage)
654+
break;
655+
idx++;
656+
}
657+
658+
// Add a new tank if necessary.
659+
if (idx >= ntanks) {
660+
if (ngasmixes >= NTANKS) {
661+
ERROR (abstract->context, "Maximum number of tanks reached.");
662+
return DC_STATUS_NOMEMORY;
663+
}
664+
tank[ntanks].id = id;
665+
tank[ntanks].beginpressure = pressure;
666+
tank[ntanks].endpressure = pressure;
667+
tank[ntanks].gasmix = DC_GASMIX_UNKNOWN;
668+
tank[ntanks].usage = usage;
669+
ntanks++;
670+
}
671+
672+
tank_id_previous = id;
673+
tank_usage_previous = usage;
674+
tank_idx = idx;
675+
}
676+
tank[tank_idx].endpressure = pressure;
677+
678+
sample.pressure.tank = tank_idx;
679+
sample.pressure.value = pressure / 10.0;
680+
if (callback) callback(DC_SAMPLE_PRESSURE, &sample, userdata);
681+
} else if (type == ID_GF_INFO) {
682+
unsigned int DC_ATTR_UNUSED gf_now = array_uint16_le (data + offset + 2);
683+
unsigned int DC_ATTR_UNUSED gf_surface = array_uint16_le (data + offset + 4);
635684
} else {
636685
WARNING (abstract->context, "Unknown record (type=%u, size=%u", type, length);
637686
}

0 commit comments

Comments
 (0)