From 7c0f8f9b9d92c1e0e7b1c6a5fe77eeca2b1d97f1 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Tue, 10 Jan 2017 21:30:17 +0100 Subject: [PATCH] Output samples only once all raw data is available Originally, the time and vendor sample values are emitted immediately after the previous sample is complete. This is now postponed until all raw samples are available. This will be required for the Aqualung i450t. That model appears to ignore the fixed sample rate and instead store a timestamp in each sample. That means the timestamp is only available once the last raw sample data has been reached. --- src/oceanic_atom2_parser.c | 40 ++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/src/oceanic_atom2_parser.c b/src/oceanic_atom2_parser.c index 3e67bdb..3c63a5d 100644 --- a/src/oceanic_atom2_parser.c +++ b/src/oceanic_atom2_parser.c @@ -673,6 +673,7 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_ unsigned int count = 0; unsigned int complete = 1; + unsigned int previous = 0; unsigned int offset = parser->headersize; while (offset + samplesize <= size - parser->footersize) { dc_sample_value_t sample = {0}; @@ -685,12 +686,8 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_ continue; } - // Time. if (complete) { - time += interval; - sample.time = time; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); - + previous = offset; complete = 0; } @@ -710,12 +707,6 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_ } } - // Vendor specific data - sample.vendor.type = SAMPLE_VENDOR_OCEANIC_ATOM2; - sample.vendor.size = length; - sample.vendor.data = data + offset; - if (callback) callback (DC_SAMPLE_VENDOR, sample, userdata); - // Check for a tank switch sample. if (sampletype == 0xAA) { if (parser->model == DATAMASK || parser->model == COMPUMASK) { @@ -743,12 +734,20 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_ unsigned int nsamples = surftime / interval; for (unsigned int i = 0; i < nsamples; ++i) { - if (complete) { - time += interval; - sample.time = time; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + // Time + time += interval; + sample.time = time; + if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + + // Vendor specific data + if (i == 0) { + sample.vendor.type = SAMPLE_VENDOR_OCEANIC_ATOM2; + sample.vendor.size = (offset - previous) + length; + sample.vendor.data = data + previous; + if (callback) callback (DC_SAMPLE_VENDOR, sample, userdata); } + // Depth sample.depth = 0.0; if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); complete = 1; @@ -761,6 +760,17 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_ continue; } + // Time. + time += interval; + sample.time = time; + if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + + // Vendor specific data + sample.vendor.type = SAMPLE_VENDOR_OCEANIC_ATOM2; + sample.vendor.size = (offset - previous) + length; + sample.vendor.data = data + previous; + if (callback) callback (DC_SAMPLE_VENDOR, sample, userdata); + // Temperature (°F) if (have_temperature) { if (parser->model == GEO || parser->model == ATOM1 ||