From ca126e9af682d010777c84991821a3ce8c89805d Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Sat, 23 Oct 2010 23:02:50 +0200 Subject: [PATCH] Add support for the new surface samples. --- src/oceanic_atom2_parser.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/oceanic_atom2_parser.c b/src/oceanic_atom2_parser.c index 6f93f60..83828cc 100644 --- a/src/oceanic_atom2_parser.c +++ b/src/oceanic_atom2_parser.c @@ -257,9 +257,18 @@ oceanic_atom2_parser_samples_foreach (parser_t *abstract, sample_callback_t call complete = 0; } + // The sample size is usually fixed, but some sample types have a + // larger size. Check whether we have that many bytes available. + unsigned int length = PAGESIZE / 2; + if (data[offset + 0] == 0xBB) { + length += PAGESIZE / 2; + if (offset + length > size - PAGESIZE) + return PARSER_STATUS_ERROR; + } + // Vendor specific data sample.vendor.type = SAMPLE_VENDOR_OCEANIC_ATOM2; - sample.vendor.size = PAGESIZE / 2; + sample.vendor.size = length; sample.vendor.data = data + offset; if (callback) callback (SAMPLE_TYPE_VENDOR, sample, userdata); @@ -277,6 +286,24 @@ oceanic_atom2_parser_samples_foreach (parser_t *abstract, sample_callback_t call else pressure = (((data[offset + 4] << 8) + data[offset + 5]) & 0x0FFF) * 2; } + } else if (data[offset + 0] == 0xBB) { + // The surface time is not always a nice multiple of the samplerate. + // The number of inserted surface samples is therefore rounded down + // to keep the timestamps aligned at multiples of the samplerate. + unsigned int surftime = 60 * bcd2dec (data[offset + 1]) + bcd2dec (data[offset + 2]); + unsigned int nsamples = surftime / interval; + + for (unsigned int i = 0; i < nsamples; ++i) { + if (complete) { + time += interval; + sample.time = time; + if (callback) callback (SAMPLE_TYPE_TIME, sample, userdata); + } + + sample.depth = 0.0; + if (callback) callback (SAMPLE_TYPE_DEPTH, sample, userdata); + complete = 1; + } } else { // Temperature (°F) if (parser->model == 0x4344) { @@ -317,7 +344,7 @@ oceanic_atom2_parser_samples_foreach (parser_t *abstract, sample_callback_t call complete = 1; } - offset += PAGESIZE / 2; + offset += length; } return PARSER_STATUS_SUCCESS;