From 060c0b72151d40873169b9e724c2c4e96ff1f175 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Sun, 4 Jul 2021 11:25:22 +0200 Subject: [PATCH] Fix the sample rate parsing The byte at offset 0x1A appears to be some settings byte, containing not only the sample rate index, but also some other values in the higher bits. Except for the 4th bit, which contains the salinity setting, the meaning of those higher bits remains unknown. Since the sample rate is limited to only 4 possible values, 2 bits are sufficient for encoding the sample rate index. The 3th bit might contain some other setting, or be reserved for future sample rates. --- src/sporasub_sp2_parser.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sporasub_sp2_parser.c b/src/sporasub_sp2_parser.c index f2208a1..0479d59 100644 --- a/src/sporasub_sp2_parser.c +++ b/src/sporasub_sp2_parser.c @@ -151,9 +151,10 @@ sporasub_sp2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t return DC_STATUS_DATAFORMAT; unsigned int nsamples = array_uint16_le(data); + unsigned int settings = data[0x1A]; // Get the sample interval. - unsigned int interval_idx = data[0x1A]; + unsigned int interval_idx = settings & 0x03; const unsigned int intervals[] = {1, 2, 5, 10}; if (interval_idx >= C_ARRAY_SIZE(intervals)) { ERROR (abstract->context, "Invalid sample interval index %u", interval_idx);