From 070de23b8356aaca5bffbf0139947eccfffebf2a Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Thu, 11 May 2023 18:56:37 +0200 Subject: [PATCH 01/51] Post release version bump to 0.9.0 --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 062b566..44a120d 100644 --- a/configure.ac +++ b/configure.ac @@ -1,8 +1,8 @@ # Versioning. m4_define([dc_version_major],[0]) -m4_define([dc_version_minor],[8]) +m4_define([dc_version_minor],[9]) m4_define([dc_version_micro],[0]) -m4_define([dc_version_suffix],[]) +m4_define([dc_version_suffix],[devel]) m4_define([dc_version],dc_version_major.dc_version_minor.dc_version_micro[]m4_ifset([dc_version_suffix],-[dc_version_suffix])) # Libtool versioning. From a34e909a84dce0c36d5fa149ebb6757d792303c6 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Tue, 16 Oct 2018 09:10:52 +0200 Subject: [PATCH 02/51] Change the units for the sample time to milliseconds Some dive computers, especially freediving computers, supports multiple samples per second. Since our smallest unit of time is one second, we can't represent this, and the extra samples are dropped. Therefore, the units are changed to milliseconds to prepare supporting this extra resolution. --- doc/man/dc_parser_samples_foreach.3 | 2 +- examples/output_xml.c | 10 +++++++++- include/libdivecomputer/parser.h | 2 +- src/atomics_cobalt_parser.c | 2 +- src/citizen_aqualand_parser.c | 2 +- src/cochran_commander_parser.c | 8 ++++---- src/cressi_edy_parser.c | 2 +- src/cressi_goa_parser.c | 2 +- src/cressi_leonardo_parser.c | 4 ++-- src/deepblu_cosmiq_parser.c | 2 +- src/deepsix_excursion_parser.c | 4 ++-- src/diverite_nitekq_parser.c | 2 +- src/divesoft_freedom_parser.c | 2 +- src/divesystem_idive_parser.c | 2 +- src/hw_ostc_parser.c | 2 +- src/liquivision_lynx_parser.c | 2 +- src/mares_darwin_parser.c | 2 +- src/mares_iconhd_parser.c | 10 +++++----- src/mares_nemo_parser.c | 8 ++++---- src/mclean_extreme_parser.c | 2 +- src/oceanic_atom2_parser.c | 4 ++-- src/oceanic_veo250_parser.c | 2 +- src/oceanic_vtpro_parser.c | 2 +- src/oceans_s1_parser.c | 6 +++--- src/parser.c | 2 +- src/reefnet_sensus_parser.c | 2 +- src/reefnet_sensuspro_parser.c | 2 +- src/reefnet_sensusultra_parser.c | 2 +- src/seac_screen_parser.c | 2 +- src/shearwater_predator_parser.c | 4 ++-- src/sporasub_sp2_parser.c | 2 +- src/suunto_d9_parser.c | 2 +- src/suunto_eon_parser.c | 4 ++-- src/suunto_eonsteel_parser.c | 2 +- src/suunto_solution_parser.c | 2 +- src/suunto_vyper_parser.c | 4 ++-- src/tecdiving_divecomputereu_parser.c | 2 +- src/uwatec_memomouse_parser.c | 2 +- src/uwatec_smart_parser.c | 2 +- 39 files changed, 65 insertions(+), 57 deletions(-) diff --git a/doc/man/dc_parser_samples_foreach.3 b/doc/man/dc_parser_samples_foreach.3 index 5ac5554..1b8be82 100644 --- a/doc/man/dc_parser_samples_foreach.3 +++ b/doc/man/dc_parser_samples_foreach.3 @@ -63,7 +63,7 @@ closed. The following sample types may be raised: .Bl -tag -width Ds .It Dv DC_SAMPLE_TIME -The time of the sample taken in seconds after the dive began. +The time of the sample taken in milliseconds after the dive began. Set in the .Fa time field. diff --git a/examples/output_xml.c b/examples/output_xml.c index 7d76cb1..882680a 100644 --- a/examples/output_xml.c +++ b/examples/output_xml.c @@ -104,12 +104,20 @@ sample_cb (dc_sample_type_t type, dc_sample_value_t value, void *userdata) sample_data_t *sampledata = (sample_data_t *) userdata; + unsigned int seconds = 0, milliseconds = 0; + switch (type) { case DC_SAMPLE_TIME: + seconds = value.time / 1000; + milliseconds = value.time % 1000; if (sampledata->nsamples++) fprintf (sampledata->ostream, "\n"); fprintf (sampledata->ostream, "\n"); - fprintf (sampledata->ostream, " \n", value.time / 60, value.time % 60); + if (milliseconds) { + fprintf (sampledata->ostream, " \n", seconds / 60, seconds % 60, milliseconds); + } else { + fprintf (sampledata->ostream, " \n", seconds / 60, seconds % 60); + } break; case DC_SAMPLE_DEPTH: fprintf (sampledata->ostream, " %.2f\n", diff --git a/include/libdivecomputer/parser.h b/include/libdivecomputer/parser.h index 6c49d0b..de1bbc1 100644 --- a/include/libdivecomputer/parser.h +++ b/include/libdivecomputer/parser.h @@ -225,7 +225,7 @@ typedef struct dc_decomodel_t { } dc_decomodel_t; typedef union dc_sample_value_t { - unsigned int time; + unsigned int time; /* Milliseconds */ double depth; struct { unsigned int tank; diff --git a/src/atomics_cobalt_parser.c b/src/atomics_cobalt_parser.c index 905b730..194296e 100644 --- a/src/atomics_cobalt_parser.c +++ b/src/atomics_cobalt_parser.c @@ -276,7 +276,7 @@ atomics_cobalt_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback // Time (seconds). time += interval; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Depth (1/1000 bar). diff --git a/src/citizen_aqualand_parser.c b/src/citizen_aqualand_parser.c index 5b95555..41a8edc 100644 --- a/src/citizen_aqualand_parser.c +++ b/src/citizen_aqualand_parser.c @@ -241,7 +241,7 @@ citizen_aqualand_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba // Time time += interval; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Depth diff --git a/src/cochran_commander_parser.c b/src/cochran_commander_parser.c index a4515ea..271dc62 100644 --- a/src/cochran_commander_parser.c +++ b/src/cochran_commander_parser.c @@ -578,7 +578,7 @@ cochran_commander_parser_samples_foreach_tm (dc_parser_t *abstract, dc_sample_ca unsigned int temp = samples[0]; // Half degrees F unsigned int depth = samples[1]; // Half feet - last_sample_time = sample.time = time; + last_sample_time = sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); sample.depth = (depth / 2.0) * FEET; @@ -593,7 +593,7 @@ cochran_commander_parser_samples_foreach_tm (dc_parser_t *abstract, dc_sample_ca while (offset < size) { const unsigned char *s = samples + offset; - sample.time = time; + sample.time = time * 1000; if (last_sample_time != sample.time) { // We haven't issued this time yet. last_sample_time = sample.time; @@ -714,7 +714,7 @@ cochran_commander_parser_samples_foreach_emc (dc_parser_t *abstract, dc_sample_c start_depth = array_uint16_le (data + layout->start_depth) / 256.0; } - last_sample_time = sample.time = time; + last_sample_time = sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); sample.depth = start_depth * FEET; @@ -730,7 +730,7 @@ cochran_commander_parser_samples_foreach_emc (dc_parser_t *abstract, dc_sample_c while (offset < size) { const unsigned char *s = samples + offset; - sample.time = time; + sample.time = time * 1000; if (last_sample_time != sample.time) { // We haven't issued this time yet. last_sample_time = sample.time; diff --git a/src/cressi_edy_parser.c b/src/cressi_edy_parser.c index 3817fc7..4dd3a18 100644 --- a/src/cressi_edy_parser.c +++ b/src/cressi_edy_parser.c @@ -201,7 +201,7 @@ cressi_edy_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t c // Time (seconds). time += interval; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Depth (1/10 m). diff --git a/src/cressi_goa_parser.c b/src/cressi_goa_parser.c index f5d4a4c..80055fc 100644 --- a/src/cressi_goa_parser.c +++ b/src/cressi_goa_parser.c @@ -329,7 +329,7 @@ cressi_goa_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t c if (complete) { // Time (seconds). - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Temperature (1/10 °C). diff --git a/src/cressi_leonardo_parser.c b/src/cressi_leonardo_parser.c index eefebdf..55624b1 100644 --- a/src/cressi_leonardo_parser.c +++ b/src/cressi_leonardo_parser.c @@ -196,7 +196,7 @@ cressi_leonardo_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callbac // Time (seconds). time += surftime; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Depth (1/10 m). @@ -211,7 +211,7 @@ cressi_leonardo_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callbac // Time (seconds). time += interval; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Depth (1/10 m). diff --git a/src/deepblu_cosmiq_parser.c b/src/deepblu_cosmiq_parser.c index 508bc5d..a6efafd 100644 --- a/src/deepblu_cosmiq_parser.c +++ b/src/deepblu_cosmiq_parser.c @@ -204,7 +204,7 @@ deepblu_cosmiq_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback offset += SZ_SAMPLE; time += interval; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); sample.depth = (signed int) (depth - atmospheric) * (BAR / 1000.0) / parser->hydrostatic; diff --git a/src/deepsix_excursion_parser.c b/src/deepsix_excursion_parser.c index 2fc8c2c..f6eb05f 100644 --- a/src/deepsix_excursion_parser.c +++ b/src/deepsix_excursion_parser.c @@ -423,7 +423,7 @@ deepsix_excursion_parser_samples_foreach_v0 (dc_parser_t *abstract, dc_sample_ca if (type == TEMPERATURE) { time += interval; - sample.time = time; + sample.time = time * 1000; if (callback) callback(DC_SAMPLE_TIME, sample, userdata); sample.depth = pressure_to_depth(depth, atmospheric, DENSITY); @@ -591,7 +591,7 @@ deepsix_excursion_parser_samples_foreach_v1 (dc_parser_t *abstract, dc_sample_ca // Time (seconds). time += samplerate; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); unsigned int depth = array_uint16_le (data + offset); diff --git a/src/diverite_nitekq_parser.c b/src/diverite_nitekq_parser.c index 5623769..dec8204 100644 --- a/src/diverite_nitekq_parser.c +++ b/src/diverite_nitekq_parser.c @@ -264,7 +264,7 @@ diverite_nitekq_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callbac // Time (seconds). time += interval; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Gas change diff --git a/src/divesoft_freedom_parser.c b/src/divesoft_freedom_parser.c index b595e63..6280dbf 100644 --- a/src/divesoft_freedom_parser.c +++ b/src/divesoft_freedom_parser.c @@ -924,7 +924,7 @@ divesoft_freedom_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba continue; } time = timestamp; - sample.time = time; + sample.time = time * 1000; if (callback) callback(DC_SAMPLE_TIME, sample, userdata); } diff --git a/src/divesystem_idive_parser.c b/src/divesystem_idive_parser.c index 3270c55..b9dfb08 100644 --- a/src/divesystem_idive_parser.c +++ b/src/divesystem_idive_parser.c @@ -474,7 +474,7 @@ divesystem_idive_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba return DC_STATUS_DATAFORMAT; } time = timestamp; - sample.time = timestamp; + sample.time = timestamp * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Depth (1/10 m). diff --git a/src/hw_ostc_parser.c b/src/hw_ostc_parser.c index 2d93fcd..de354df 100644 --- a/src/hw_ostc_parser.c +++ b/src/hw_ostc_parser.c @@ -833,7 +833,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call // Time (seconds). time += samplerate; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Initial gas mix. diff --git a/src/liquivision_lynx_parser.c b/src/liquivision_lynx_parser.c index 764d20e..9958327 100644 --- a/src/liquivision_lynx_parser.c +++ b/src/liquivision_lynx_parser.c @@ -545,7 +545,7 @@ liquivision_lynx_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba // Time (seconds). time += interval; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Depth (1/100 m). diff --git a/src/mares_darwin_parser.c b/src/mares_darwin_parser.c index 88e831c..6a87e46 100644 --- a/src/mares_darwin_parser.c +++ b/src/mares_darwin_parser.c @@ -242,7 +242,7 @@ mares_darwin_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t // Surface Time (seconds). time += 20; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Depth (1/10 m). diff --git a/src/mares_iconhd_parser.c b/src/mares_iconhd_parser.c index 600eaa9..9ac6dd6 100644 --- a/src/mares_iconhd_parser.c +++ b/src/mares_iconhd_parser.c @@ -1022,7 +1022,7 @@ mares_iconhd_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t // Surface Time (seconds). time += surftime; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Surface Depth (0 m). @@ -1035,7 +1035,7 @@ mares_iconhd_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t for (unsigned int i = 0; i < divetime; ++i) { // Time (seconds). time += parser->interval; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Depth (1/10 m). @@ -1052,7 +1052,7 @@ mares_iconhd_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t // Surface Time (seconds). time += surftime; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Surface Depth (0 m). @@ -1061,7 +1061,7 @@ mares_iconhd_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t // Dive Time (seconds). time += divetime; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Maximum Depth (1/10 m). @@ -1123,7 +1123,7 @@ mares_iconhd_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t // Time (seconds). time += parser->interval; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Depth (1/10 m). diff --git a/src/mares_nemo_parser.c b/src/mares_nemo_parser.c index 2f26605..9e906ac 100644 --- a/src/mares_nemo_parser.c +++ b/src/mares_nemo_parser.c @@ -382,7 +382,7 @@ mares_nemo_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t c // Time (seconds). time += 20; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Depth (1/10 m). @@ -459,7 +459,7 @@ mares_nemo_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t c // Surface Time (seconds). time += surftime; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Surface Depth (0 m). @@ -500,7 +500,7 @@ mares_nemo_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t c time += interval; if (time > maxtime) time = maxtime; // Adjust the last sample. - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Depth (1/10 m). @@ -519,7 +519,7 @@ mares_nemo_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t c } else { // Dive Time (seconds). time += divetime; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Maximum Depth (1/10 m). diff --git a/src/mclean_extreme_parser.c b/src/mclean_extreme_parser.c index 694bf60..260c56b 100644 --- a/src/mclean_extreme_parser.c +++ b/src/mclean_extreme_parser.c @@ -269,7 +269,7 @@ mclean_extreme_parser_samples_foreach(dc_parser_t *abstract, dc_sample_callback_ const unsigned int setpoint = abstract->data[0x0013 + sp_index]; time += interval; - sample.time = time; + sample.time = time * 1000; if (callback) callback(DC_SAMPLE_TIME, sample, userdata); sample.depth = 0.1 * depth; diff --git a/src/oceanic_atom2_parser.c b/src/oceanic_atom2_parser.c index f6b1f71..ed4edd4 100644 --- a/src/oceanic_atom2_parser.c +++ b/src/oceanic_atom2_parser.c @@ -758,7 +758,7 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_ for (unsigned int i = 0; i < nsamples; ++i) { // Time time += interval; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Vendor specific data @@ -802,7 +802,7 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_ } else { time += interval; } - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Vendor specific data diff --git a/src/oceanic_veo250_parser.c b/src/oceanic_veo250_parser.c index 90d3383..2eead46 100644 --- a/src/oceanic_veo250_parser.c +++ b/src/oceanic_veo250_parser.c @@ -230,7 +230,7 @@ oceanic_veo250_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback // Time. time += interval; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Vendor specific data diff --git a/src/oceanic_vtpro_parser.c b/src/oceanic_vtpro_parser.c index 9650c49..75b3fc5 100644 --- a/src/oceanic_vtpro_parser.c +++ b/src/oceanic_vtpro_parser.c @@ -331,7 +331,7 @@ oceanic_vtpro_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_ time = timestamp * 60 + (i + 1) * interval; else time = timestamp * 60 + (i + 1) * 60.0 / count + 0.5; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Vendor specific data diff --git a/src/oceans_s1_parser.c b/src/oceans_s1_parser.c index 8b4cfbd..63c123f 100644 --- a/src/oceans_s1_parser.c +++ b/src/oceans_s1_parser.c @@ -249,7 +249,7 @@ oceans_s1_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t ca unsigned int nsamples = seconds / interval; for (unsigned int i = 0; i < nsamples; ++i) { time += interval; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); sample.depth = 0; @@ -257,7 +257,7 @@ oceans_s1_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t ca } time += interval; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); sample.depth = depth / 100.0; @@ -280,7 +280,7 @@ oceans_s1_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t ca } time += interval; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); sample.depth = depth / 100.0; diff --git a/src/parser.c b/src/parser.c index 63485d2..77dcb84 100644 --- a/src/parser.c +++ b/src/parser.c @@ -399,7 +399,7 @@ sample_statistics_cb (dc_sample_type_t type, dc_sample_value_t value, void *user switch (type) { case DC_SAMPLE_TIME: - statistics->divetime = value.time; + statistics->divetime = value.time / 1000; break; case DC_SAMPLE_DEPTH: if (statistics->maxdepth < value.depth) diff --git a/src/reefnet_sensus_parser.c b/src/reefnet_sensus_parser.c index 00c3b47..2797651 100644 --- a/src/reefnet_sensus_parser.c +++ b/src/reefnet_sensus_parser.c @@ -279,7 +279,7 @@ reefnet_sensus_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback // Time (seconds) time += interval; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Depth (adjusted feet of seawater). diff --git a/src/reefnet_sensuspro_parser.c b/src/reefnet_sensuspro_parser.c index ad371d7..422a161 100644 --- a/src/reefnet_sensuspro_parser.c +++ b/src/reefnet_sensuspro_parser.c @@ -278,7 +278,7 @@ reefnet_sensuspro_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callb // Time (seconds) time += interval; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Temperature (°F) diff --git a/src/reefnet_sensusultra_parser.c b/src/reefnet_sensusultra_parser.c index bc52f1f..90ead6f 100644 --- a/src/reefnet_sensusultra_parser.c +++ b/src/reefnet_sensusultra_parser.c @@ -275,7 +275,7 @@ reefnet_sensusultra_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal // Time (seconds) time += interval; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Temperature (0.01 °K) diff --git a/src/seac_screen_parser.c b/src/seac_screen_parser.c index c4a855c..dc2e781 100644 --- a/src/seac_screen_parser.c +++ b/src/seac_screen_parser.c @@ -331,7 +331,7 @@ seac_screen_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t return DC_STATUS_DATAFORMAT; } time = timestamp; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Depth (1/100 m). diff --git a/src/shearwater_predator_parser.c b/src/shearwater_predator_parser.c index 06a0882..cd98e76 100644 --- a/src/shearwater_predator_parser.c +++ b/src/shearwater_predator_parser.c @@ -899,7 +899,7 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal if (type == LOG_RECORD_DIVE_SAMPLE) { // Time (seconds). time += interval; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Depth (1/10 m or ft). @@ -1076,7 +1076,7 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal // Time (seconds). time += interval; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Depth (absolute pressure in millibar) diff --git a/src/sporasub_sp2_parser.c b/src/sporasub_sp2_parser.c index 5ac44b8..6c308d4 100644 --- a/src/sporasub_sp2_parser.c +++ b/src/sporasub_sp2_parser.c @@ -184,7 +184,7 @@ sporasub_sp2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t // Time (seconds) time += interval; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Depth (1/100 m) diff --git a/src/suunto_d9_parser.c b/src/suunto_d9_parser.c index 0abb079..4de49c1 100644 --- a/src/suunto_d9_parser.c +++ b/src/suunto_d9_parser.c @@ -521,7 +521,7 @@ suunto_d9_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t ca dc_sample_value_t sample = {0}; // Time (seconds). - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Sample data. diff --git a/src/suunto_eon_parser.c b/src/suunto_eon_parser.c index 8e80aca..8a048b2 100644 --- a/src/suunto_eon_parser.c +++ b/src/suunto_eon_parser.c @@ -294,7 +294,7 @@ suunto_eon_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t c if (complete) { // Time (seconds). time += interval; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); complete = 0; } @@ -341,7 +341,7 @@ suunto_eon_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t c // Time if (complete) { time += interval; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); } diff --git a/src/suunto_eonsteel_parser.c b/src/suunto_eonsteel_parser.c index 907eca7..31f67b9 100644 --- a/src/suunto_eonsteel_parser.c +++ b/src/suunto_eonsteel_parser.c @@ -474,7 +474,7 @@ static void sample_time(struct sample_data *info, unsigned short time_delta) dc_sample_value_t sample = {0}; info->time += time_delta; - sample.time = info->time / 1000; + sample.time = info->time / 1000 * 1000; if (info->callback) info->callback(DC_SAMPLE_TIME, sample, info->userdata); } diff --git a/src/suunto_solution_parser.c b/src/suunto_solution_parser.c index 59648d5..1713a73 100644 --- a/src/suunto_solution_parser.c +++ b/src/suunto_solution_parser.c @@ -183,7 +183,7 @@ suunto_solution_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callbac if (value < 0x7e || value > 0x82) { // Time (minutes). time += 3 * 60; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Depth (ft). diff --git a/src/suunto_vyper_parser.c b/src/suunto_vyper_parser.c index 4970b86..356f64c 100644 --- a/src/suunto_vyper_parser.c +++ b/src/suunto_vyper_parser.c @@ -353,7 +353,7 @@ suunto_vyper_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t if (complete) { // Time (seconds). time += interval; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); complete = 0; } @@ -425,7 +425,7 @@ suunto_vyper_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t // Time if (complete) { time += interval; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); } diff --git a/src/tecdiving_divecomputereu_parser.c b/src/tecdiving_divecomputereu_parser.c index d060996..bf134eb 100644 --- a/src/tecdiving_divecomputereu_parser.c +++ b/src/tecdiving_divecomputereu_parser.c @@ -159,7 +159,7 @@ tecdiving_divecomputereu_parser_samples_foreach (dc_parser_t *abstract, dc_sampl // Time (seconds). time += interval; - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Depth (1/10 m). diff --git a/src/uwatec_memomouse_parser.c b/src/uwatec_memomouse_parser.c index 3c818fa..2c3d506 100644 --- a/src/uwatec_memomouse_parser.c +++ b/src/uwatec_memomouse_parser.c @@ -250,7 +250,7 @@ uwatec_memomouse_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba offset += 2; // Time (seconds) - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Depth (meters) diff --git a/src/uwatec_smart_parser.c b/src/uwatec_smart_parser.c index bd849a8..83304a5 100644 --- a/src/uwatec_smart_parser.c +++ b/src/uwatec_smart_parser.c @@ -1162,7 +1162,7 @@ uwatec_smart_parse (uwatec_smart_parser_t *parser, dc_sample_callback_t callback } while (complete) { - sample.time = time; + sample.time = time * 1000; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); if (parser->ngasmixes && gasmix != gasmix_previous) { From bca8f9e2d2b55d308f38e4413353d6aac60153b4 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Thu, 22 Apr 2021 19:24:37 +0200 Subject: [PATCH 03/51] Enable the millisecond resolution sample time After the previous commit changed the resolution of the sample time to milliseconds, the dive computers which actually support a higher resoltion can now enable this feature and report all samples. --- src/mares_iconhd_parser.c | 37 +++++++++++++------------------- src/oceanic_atom2_parser.c | 30 ++++++-------------------- src/shearwater_predator_parser.c | 11 +++------- src/suunto_eonsteel_parser.c | 2 +- 4 files changed, 26 insertions(+), 54 deletions(-) diff --git a/src/mares_iconhd_parser.c b/src/mares_iconhd_parser.c index 9ac6dd6..cb67504 100644 --- a/src/mares_iconhd_parser.c +++ b/src/mares_iconhd_parser.c @@ -401,12 +401,12 @@ mares_iconhd_cache (mares_iconhd_parser_t *parser) unsigned int samplerate = 0; if (parser->model == SMARTAPNEA) { unsigned int idx = (settings & 0x0600) >> 9; - interval = 1; samplerate = 1 << idx; + interval = 1000 / samplerate; } else { const unsigned int intervals[] = {1, 5, 10, 20}; unsigned int idx = (settings & 0x0C00) >> 10; - interval = intervals[idx]; + interval = intervals[idx] * 1000; samplerate = 1; } @@ -625,7 +625,7 @@ mares_genius_cache (mares_iconhd_parser_t *parser) parser->headersize = headersize; parser->settings = settings; parser->surftime = surftime * 60; - parser->interval = 5; + parser->interval = 5000; parser->samplerate = 1; parser->ntanks = ntanks; parser->ngasmixes = ngasmixes; @@ -820,7 +820,7 @@ mares_iconhd_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsi if (parser->layout->divetime != UNSUPPORTED) { *((unsigned int *) value) = array_uint16_le (p + parser->layout->divetime); } else { - *((unsigned int *) value) = parser->nsamples * parser->interval - parser->surftime; + *((unsigned int *) value) = parser->nsamples * parser->interval / 1000 - parser->surftime; } break; case DC_FIELD_MAXDEPTH: @@ -963,14 +963,6 @@ mares_iconhd_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t const unsigned char *data = abstract->data; - if (parser->samplerate > 1) { - // The Smart Apnea supports multiple samples per second - // (e.g. 2, 4 or 8). Since our smallest unit of time is one - // second, we can't represent this, and the extra samples - // will get dropped. - WARNING(abstract->context, "Multiple samples per second are not supported!"); - } - // Previous gas mix - initialize with impossible value unsigned int gasmix_previous = 0xFFFFFFFF; @@ -1021,8 +1013,8 @@ mares_iconhd_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t unsigned int surftime = array_uint16_le (data + offset + 4); // Surface Time (seconds). - time += surftime; - sample.time = time * 1000; + time += surftime * 1000; + sample.time = time; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Surface Depth (0 m). @@ -1032,10 +1024,11 @@ mares_iconhd_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t offset += parser->samplesize; nsamples++; - for (unsigned int i = 0; i < divetime; ++i) { + unsigned int count = divetime * parser->samplerate; + for (unsigned int i = 0; i < count; ++i) { // Time (seconds). time += parser->interval; - sample.time = time * 1000; + sample.time = time; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Depth (1/10 m). @@ -1043,7 +1036,7 @@ mares_iconhd_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t sample.depth = depth / 10.0; if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); - offset += 2 * parser->samplerate; + offset += 2; } } else if (parser->model != GENIUS && parser->model != HORIZON && parser->mode == ICONHD_FREEDIVE) { unsigned int maxdepth = array_uint16_le (data + offset + 0); @@ -1051,8 +1044,8 @@ mares_iconhd_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t unsigned int surftime = array_uint16_le (data + offset + 4); // Surface Time (seconds). - time += surftime; - sample.time = time * 1000; + time += surftime * 1000; + sample.time = time; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Surface Depth (0 m). @@ -1060,8 +1053,8 @@ mares_iconhd_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); // Dive Time (seconds). - time += divetime; - sample.time = time * 1000; + time += divetime * 1000; + sample.time = time; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Maximum Depth (1/10 m). @@ -1123,7 +1116,7 @@ mares_iconhd_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t // Time (seconds). time += parser->interval; - sample.time = time * 1000; + sample.time = time; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Depth (1/10 m). diff --git a/src/oceanic_atom2_parser.c b/src/oceanic_atom2_parser.c index ed4edd4..526a10f 100644 --- a/src/oceanic_atom2_parser.c +++ b/src/oceanic_atom2_parser.c @@ -608,8 +608,7 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_ unsigned int extratime = 0; unsigned int time = 0; - unsigned int interval = 1; - unsigned int samplerate = 1; + unsigned int interval = 1000; if (parser->mode != FREEDIVE) { unsigned int offset = 0x17; if (parser->model == A300CS || parser->model == VTX || @@ -617,21 +616,13 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_ parser->model == PROPLUSX || parser->model == I770R || parser->model == SAGE || parser->model == BEACON) offset = 0x1f; - const unsigned int intervals[] = {2, 15, 30, 60}; + const unsigned int intervals[] = {2000, 15000, 30000, 60000}; unsigned int idx = data[offset] & 0x03; interval = intervals[idx]; } else if (parser->model == F11A || parser->model == F11B) { - const unsigned int intervals[] = {1, 1, 1, 2}; - const unsigned int samplerates[] = {4, 2, 1, 1}; + const unsigned int intervals[] = {250, 500, 1000, 2000}; unsigned int idx = data[0x29] & 0x03; interval = intervals[idx]; - samplerate = samplerates[idx]; - if (samplerate > 1) { - // Some models supports multiple samples per second. - // Since our smallest unit of time is one second, we can't - // represent this, and the extra samples will get dropped. - WARNING(abstract->context, "Multiple samples per second are not supported!"); - } } unsigned int samplesize = PAGESIZE / 2; @@ -752,13 +743,13 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_ // 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 surftime = (60 * bcd2dec (data[offset + 1]) + bcd2dec (data[offset + 2])) * 1000; unsigned int nsamples = surftime / interval; for (unsigned int i = 0; i < nsamples; ++i) { // Time time += interval; - sample.time = time * 1000; + sample.time = time; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Vendor specific data @@ -777,19 +768,12 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_ extratime += surftime; } else { - // Skip the extra samples. - if ((count % samplerate) != 0) { - offset += samplesize; - count++; - continue; - } - // Time. if (parser->model == I450T || parser->model == I470TC) { unsigned int minute = bcd2dec(data[offset + 0]); unsigned int hour = bcd2dec(data[offset + 1] & 0x0F); unsigned int second = bcd2dec(data[offset + 2]); - unsigned int timestamp = (hour * 3600) + (minute * 60 ) + second + extratime; + unsigned int timestamp = ((hour * 3600) + (minute * 60 ) + second) * 1000 + extratime; if (timestamp < time) { ERROR (abstract->context, "Timestamp moved backwards."); return DC_STATUS_DATAFORMAT; @@ -802,7 +786,7 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_ } else { time += interval; } - sample.time = time * 1000; + sample.time = time; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Vendor specific data diff --git a/src/shearwater_predator_parser.c b/src/shearwater_predator_parser.c index cd98e76..0975ff9 100644 --- a/src/shearwater_predator_parser.c +++ b/src/shearwater_predator_parser.c @@ -871,14 +871,9 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal // Sample interval. unsigned int time = 0; - unsigned int interval = 10; + unsigned int interval = 10000; if (parser->pnf && parser->logversion >= 9 && parser->opening[5] != UNDEFINED) { interval = array_uint16_be (data + parser->opening[5] + 23); - if (interval % 1000 != 0) { - ERROR (abstract->context, "Unsupported sample interval (%u ms).", interval); - return DC_STATUS_DATAFORMAT; - } - interval /= 1000; } unsigned int pnf = parser->pnf; @@ -899,7 +894,7 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal if (type == LOG_RECORD_DIVE_SAMPLE) { // Time (seconds). time += interval; - sample.time = time * 1000; + sample.time = time; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Depth (1/10 m or ft). @@ -1076,7 +1071,7 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal // Time (seconds). time += interval; - sample.time = time * 1000; + sample.time = time; if (callback) callback (DC_SAMPLE_TIME, sample, userdata); // Depth (absolute pressure in millibar) diff --git a/src/suunto_eonsteel_parser.c b/src/suunto_eonsteel_parser.c index 31f67b9..c7276fb 100644 --- a/src/suunto_eonsteel_parser.c +++ b/src/suunto_eonsteel_parser.c @@ -474,7 +474,7 @@ static void sample_time(struct sample_data *info, unsigned short time_delta) dc_sample_value_t sample = {0}; info->time += time_delta; - sample.time = info->time / 1000 * 1000; + sample.time = info->time; if (info->callback) info->callback(DC_SAMPLE_TIME, sample, info->userdata); } From b1ff2c6a8ed903229a1381eb45027ac1b2f382b9 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Thu, 22 Apr 2021 20:33:54 +0200 Subject: [PATCH 04/51] Add the sensor index to the ppO2 sample Rebreathers typically support multiple ppO2 sensors as a safety measure in case a sensor fails during the dive. The current api can already report multiple ppO2 values per sample, but it does not provide any information about which sensor the measurement is from. The new sensor index provides this info, and can also be used to distinguish between the average/voted ppO2 value using the special value DC_SENSOR_NONE. --- examples/output_xml.c | 6 +++++- include/libdivecomputer/parser.h | 6 +++++- src/diverite_nitekq_parser.c | 3 ++- src/divesoft_freedom_parser.c | 9 ++++++--- src/hw_ostc_parser.c | 3 ++- src/shearwater_predator_parser.c | 16 +++++++++------- src/tecdiving_divecomputereu_parser.c | 3 ++- 7 files changed, 31 insertions(+), 15 deletions(-) diff --git a/examples/output_xml.c b/examples/output_xml.c index 882680a..f4c312d 100644 --- a/examples/output_xml.c +++ b/examples/output_xml.c @@ -157,7 +157,11 @@ sample_cb (dc_sample_type_t type, dc_sample_value_t value, void *userdata) fprintf (sampledata->ostream, " %.2f\n", value.setpoint); break; case DC_SAMPLE_PPO2: - fprintf (sampledata->ostream, " %.2f\n", value.ppo2); + if (value.ppo2.sensor != DC_SENSOR_NONE) { + fprintf (sampledata->ostream, " %.2f\n", value.ppo2.sensor, value.ppo2.value); + } else { + fprintf (sampledata->ostream, " %.2f\n", value.ppo2.value); + } break; case DC_SAMPLE_CNS: fprintf (sampledata->ostream, " %.1f\n", value.cns * 100.0); diff --git a/include/libdivecomputer/parser.h b/include/libdivecomputer/parser.h index de1bbc1..c4d0a72 100644 --- a/include/libdivecomputer/parser.h +++ b/include/libdivecomputer/parser.h @@ -147,6 +147,7 @@ typedef struct dc_gasmix_t { double nitrogen; } dc_gasmix_t; +#define DC_SENSOR_NONE 0xFFFFFFFF #define DC_GASMIX_UNKNOWN 0xFFFFFFFF typedef enum dc_tankvolume_t { @@ -247,7 +248,10 @@ typedef union dc_sample_value_t { const void *data; } vendor; double setpoint; - double ppo2; + struct { + unsigned int sensor; + double value; + } ppo2; double cns; struct { unsigned int type; diff --git a/src/diverite_nitekq_parser.c b/src/diverite_nitekq_parser.c index dec8204..6cfd9bc 100644 --- a/src/diverite_nitekq_parser.c +++ b/src/diverite_nitekq_parser.c @@ -293,7 +293,8 @@ diverite_nitekq_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callbac if (offset + 1 > size) return DC_STATUS_DATAFORMAT; unsigned int ppo2 = data[offset]; - sample.ppo2 = ppo2 / 100.0; + sample.ppo2.sensor = DC_SENSOR_NONE; + sample.ppo2.value = ppo2 / 100.0; if (callback) callback (DC_SAMPLE_PPO2, sample, userdata); offset++; } diff --git a/src/divesoft_freedom_parser.c b/src/divesoft_freedom_parser.c index 6280dbf..1f0b7b3 100644 --- a/src/divesoft_freedom_parser.c +++ b/src/divesoft_freedom_parser.c @@ -946,7 +946,8 @@ divesoft_freedom_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba if (callback) callback(DC_SAMPLE_DEPTH, sample, userdata); if (ppo2) { - sample.ppo2 = ppo2 * 10.0 / BAR; + sample.ppo2.sensor = DC_SENSOR_NONE; + sample.ppo2.value = ppo2 * 10.0 / BAR; if (callback) callback(DC_SAMPLE_PPO2, sample, userdata); } @@ -1045,7 +1046,8 @@ divesoft_freedom_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba unsigned int ppo2 = array_uint16_le (data + offset + 4 + i * 2); if (ppo2 == 0 || ppo2 == 0xFFFF) continue; - sample.ppo2 = ppo2 * 10.0 / BAR; + sample.ppo2.sensor = i; + sample.ppo2.value = ppo2 * 10.0 / BAR; if (callback) callback(DC_SAMPLE_PPO2, sample, userdata); } } else if (id == MEASURE_ID_OXYGEN_MV) { @@ -1055,7 +1057,8 @@ divesoft_freedom_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba if (!parser->calibrated || state == SENSTAT_UNCALIBRATED || state == SENSTAT_NOT_EXIST) continue; - sample.ppo2 = value / 100.0 * parser->calibration[i] / BAR; + sample.ppo2.sensor = i; + sample.ppo2.value = value / 100.0 * parser->calibration[i] / BAR; if (callback) callback(DC_SAMPLE_PPO2, sample, userdata); } } diff --git a/src/hw_ostc_parser.c b/src/hw_ostc_parser.c index de354df..0ee02ac 100644 --- a/src/hw_ostc_parser.c +++ b/src/hw_ostc_parser.c @@ -1067,7 +1067,8 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call } if (count) { for (unsigned int j = 0; j < 3; ++j) { - sample.ppo2 = ppo2[j] / 100.0; + sample.ppo2.sensor = i; + sample.ppo2.value = ppo2[j] / 100.0; if (callback) callback (DC_SAMPLE_PPO2, sample, userdata); } } diff --git a/src/shearwater_predator_parser.c b/src/shearwater_predator_parser.c index 0975ff9..ab7752f 100644 --- a/src/shearwater_predator_parser.c +++ b/src/shearwater_predator_parser.c @@ -927,19 +927,21 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal if (ccr) { // PPO2 if ((status & PPO2_EXTERNAL) == 0) { -#ifdef SENSOR_AVERAGE - sample.ppo2 = data[offset + pnf + 6] / 100.0; + sample.ppo2.sensor = DC_SENSOR_NONE; + sample.ppo2.value = data[offset + pnf + 6] / 100.0; if (callback) callback (DC_SAMPLE_PPO2, sample, userdata); -#else - sample.ppo2 = data[offset + pnf + 12] * parser->calibration[0]; + + sample.ppo2.sensor = 0; + sample.ppo2.value = data[offset + pnf + 12] * parser->calibration[0]; if (callback && (parser->calibrated & 0x01)) callback (DC_SAMPLE_PPO2, sample, userdata); - sample.ppo2 = data[offset + pnf + 14] * parser->calibration[1]; + sample.ppo2.sensor = 1; + sample.ppo2.value = data[offset + pnf + 14] * parser->calibration[1]; if (callback && (parser->calibrated & 0x02)) callback (DC_SAMPLE_PPO2, sample, userdata); - sample.ppo2 = data[offset + pnf + 15] * parser->calibration[2]; + sample.ppo2.sensor = 2; + sample.ppo2.value = data[offset + pnf + 15] * parser->calibration[2]; if (callback && (parser->calibrated & 0x04)) callback (DC_SAMPLE_PPO2, sample, userdata); -#endif } // Setpoint diff --git a/src/tecdiving_divecomputereu_parser.c b/src/tecdiving_divecomputereu_parser.c index bf134eb..ccfbb05 100644 --- a/src/tecdiving_divecomputereu_parser.c +++ b/src/tecdiving_divecomputereu_parser.c @@ -174,7 +174,8 @@ tecdiving_divecomputereu_parser_samples_foreach (dc_parser_t *abstract, dc_sampl // ppO2 unsigned int ppo2 = data[offset + 1]; - sample.ppo2 = ppo2 / 10.0; + sample.ppo2.sensor = DC_SENSOR_NONE; + sample.ppo2.value = ppo2 / 10.0; if (callback) callback (DC_SAMPLE_PPO2, sample, userdata); // Setpoint From 4b383a778e194d5cd0b3239a31d03dda681560e4 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Thu, 22 Apr 2021 20:56:25 +0200 Subject: [PATCH 05/51] Add a TTS field to the deco sample Some dive computers report the time of the next decompression stop, while others report the Time To Surface (TTS). Some models can even report both. Add a TTS field to the deco sample to support both values. --- examples/output_xml.c | 4 ++++ include/libdivecomputer/parser.h | 1 + src/atomics_cobalt_parser.c | 1 + src/cochran_commander_parser.c | 6 ++++++ src/divesoft_freedom_parser.c | 1 + src/divesystem_idive_parser.c | 4 +++- src/hw_ostc_parser.c | 1 + src/liquivision_lynx_parser.c | 1 + src/mares_darwin_parser.c | 1 + src/mares_iconhd_parser.c | 1 + src/mares_nemo_parser.c | 1 + src/oceanic_atom2_parser.c | 1 + src/oceanic_veo250_parser.c | 1 + src/oceanic_vtpro_parser.c | 1 + src/oceans_s1_parser.c | 1 + src/seac_screen_parser.c | 1 + src/shearwater_predator_parser.c | 1 + src/suunto_d9_parser.c | 1 + src/suunto_eonsteel_parser.c | 4 +++- src/uwatec_memomouse_parser.c | 1 + 20 files changed, 32 insertions(+), 2 deletions(-) diff --git a/examples/output_xml.c b/examples/output_xml.c index f4c312d..1b66056 100644 --- a/examples/output_xml.c +++ b/examples/output_xml.c @@ -171,6 +171,10 @@ sample_cb (dc_sample_type_t type, dc_sample_value_t value, void *userdata) value.deco.time, convert_depth(value.deco.depth, sampledata->units), decostop[value.deco.type]); + if (value.deco.tts) { + fprintf (sampledata->ostream, " %u\n", + value.deco.tts); + } break; case DC_SAMPLE_GASMIX: fprintf (sampledata->ostream, " %u\n", value.gasmix); diff --git a/include/libdivecomputer/parser.h b/include/libdivecomputer/parser.h index c4d0a72..4a727e7 100644 --- a/include/libdivecomputer/parser.h +++ b/include/libdivecomputer/parser.h @@ -257,6 +257,7 @@ typedef union dc_sample_value_t { unsigned int type; unsigned int time; double depth; + unsigned int tts; } deco; unsigned int gasmix; /* Gas mix index */ } dc_sample_value_t; diff --git a/src/atomics_cobalt_parser.c b/src/atomics_cobalt_parser.c index 194296e..2fab3b3 100644 --- a/src/atomics_cobalt_parser.c +++ b/src/atomics_cobalt_parser.c @@ -344,6 +344,7 @@ atomics_cobalt_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback sample.deco.type = DC_DECO_NDL; sample.deco.time = ndl; sample.deco.depth = 0.0; + sample.deco.tts = 0; if (callback) callback (DC_SAMPLE_DECO, sample, userdata); offset += SZ_SEGMENT; diff --git a/src/cochran_commander_parser.c b/src/cochran_commander_parser.c index 271dc62..72151df 100644 --- a/src/cochran_commander_parser.c +++ b/src/cochran_commander_parser.c @@ -615,6 +615,7 @@ cochran_commander_parser_samples_foreach_tm (dc_parser_t *abstract, dc_sample_ca sample.deco.type = DC_DECO_DECOSTOP; sample.deco.time = 60; // We don't know the duration sample.deco.depth = deco_ceiling * FEET; + sample.deco.tts = 0; if (callback) callback(DC_SAMPLE_DECO, sample, userdata); break; case 0xAD: // Increment ceiling (shallower) @@ -623,6 +624,7 @@ cochran_commander_parser_samples_foreach_tm (dc_parser_t *abstract, dc_sample_ca sample.deco.type = DC_DECO_DECOSTOP; sample.deco.depth = deco_ceiling * FEET; sample.deco.time = 60; // We don't know the duration + sample.deco.tts = 0; if (callback) callback(DC_SAMPLE_DECO, sample, userdata); break; default: @@ -774,6 +776,7 @@ cochran_commander_parser_samples_foreach_emc (dc_parser_t *abstract, dc_sample_c sample.deco.type = DC_DECO_DECOSTOP; sample.deco.time = (array_uint16_le(s + 3) + 1) * 60; sample.deco.depth = deco_ceiling * FEET; + sample.deco.tts = 0; if (callback) callback(DC_SAMPLE_DECO, sample, userdata); break; case 0xAD: // Increment ceiling (shallower) @@ -782,6 +785,7 @@ cochran_commander_parser_samples_foreach_emc (dc_parser_t *abstract, dc_sample_c sample.deco.type = DC_DECO_DECOSTOP; sample.deco.depth = deco_ceiling * FEET; sample.deco.time = (array_uint16_le(s + 3) + 1) * 60; + sample.deco.tts = 0; if (callback) callback(DC_SAMPLE_DECO, sample, userdata); break; case 0xC0: // Switched to FO2 21% mode (surface) @@ -855,6 +859,7 @@ cochran_commander_parser_samples_foreach_emc (dc_parser_t *abstract, dc_sample_c sample.deco.type = DC_DECO_NDL; sample.deco.time = deco_time * 60; sample.deco.depth = 0; + sample.deco.tts = 0; if (callback) callback (DC_SAMPLE_DECO, sample, userdata); } break; @@ -865,6 +870,7 @@ cochran_commander_parser_samples_foreach_emc (dc_parser_t *abstract, dc_sample_c sample.deco.type = DC_DECO_DECOSTOP; sample.deco.depth = deco_ceiling * FEET; sample.deco.time = deco_time * 60; + sample.deco.tts = 0; if (callback) callback (DC_SAMPLE_DECO, sample, userdata); } break; diff --git a/src/divesoft_freedom_parser.c b/src/divesoft_freedom_parser.c index 1f0b7b3..74ac136 100644 --- a/src/divesoft_freedom_parser.c +++ b/src/divesoft_freedom_parser.c @@ -978,6 +978,7 @@ divesoft_freedom_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba sample.deco.time = ndl * 60; sample.deco.depth = 0.0; } + sample.deco.tts = tts * 60; if (callback) callback(DC_SAMPLE_DECO, sample, userdata); // Setpoint diff --git a/src/divesystem_idive_parser.c b/src/divesystem_idive_parser.c index b9dfb08..892cda1 100644 --- a/src/divesystem_idive_parser.c +++ b/src/divesystem_idive_parser.c @@ -566,11 +566,13 @@ divesystem_idive_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba if (decostop) { sample.deco.type = DC_DECO_DECOSTOP; sample.deco.depth = decostop / 10.0; - sample.deco.time = apos4 ? decotime : tts; + sample.deco.time = decotime; + sample.deco.tts = tts; } else { sample.deco.type = DC_DECO_NDL; sample.deco.depth = 0.0; sample.deco.time = tts; + sample.deco.tts = 0; } if (callback) callback (DC_SAMPLE_DECO, sample, userdata); diff --git a/src/hw_ostc_parser.c b/src/hw_ostc_parser.c index 0ee02ac..1421a08 100644 --- a/src/hw_ostc_parser.c +++ b/src/hw_ostc_parser.c @@ -1053,6 +1053,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call sample.deco.depth = 0.0; } sample.deco.time = data[offset + 1] * 60; + sample.deco.tts = 0; if (callback) callback (DC_SAMPLE_DECO, sample, userdata); break; case PPO2: diff --git a/src/liquivision_lynx_parser.c b/src/liquivision_lynx_parser.c index 9958327..14c86ed 100644 --- a/src/liquivision_lynx_parser.c +++ b/src/liquivision_lynx_parser.c @@ -593,6 +593,7 @@ liquivision_lynx_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba sample.deco.depth = 0.0; } sample.deco.time = 0; + sample.deco.tts = 0; if (callback) callback (DC_SAMPLE_DECO, sample, userdata); have_deco = 0; } diff --git a/src/mares_darwin_parser.c b/src/mares_darwin_parser.c index 6a87e46..56b68d3 100644 --- a/src/mares_darwin_parser.c +++ b/src/mares_darwin_parser.c @@ -282,6 +282,7 @@ mares_darwin_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t } sample.deco.time = 0; sample.deco.depth = 0.0; + sample.deco.tts = 0; if (callback) callback (DC_SAMPLE_DECO, sample, userdata); if (parser->samplesize == 3) { diff --git a/src/mares_iconhd_parser.c b/src/mares_iconhd_parser.c index cb67504..9ffb1e6 100644 --- a/src/mares_iconhd_parser.c +++ b/src/mares_iconhd_parser.c @@ -1159,6 +1159,7 @@ mares_iconhd_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t sample.deco.depth = 0.0; } sample.deco.time = decotime * 60; + sample.deco.tts = tts; if (callback) callback (DC_SAMPLE_DECO, sample, userdata); // Alarms diff --git a/src/mares_nemo_parser.c b/src/mares_nemo_parser.c index 9e906ac..a4c2d4b 100644 --- a/src/mares_nemo_parser.c +++ b/src/mares_nemo_parser.c @@ -422,6 +422,7 @@ mares_nemo_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t c } sample.deco.time = 0; sample.deco.depth = 0.0; + sample.deco.tts = 0; if (callback) callback (DC_SAMPLE_DECO, sample, userdata); // Pressure (1 bar). diff --git a/src/oceanic_atom2_parser.c b/src/oceanic_atom2_parser.c index 526a10f..272cfa2 100644 --- a/src/oceanic_atom2_parser.c +++ b/src/oceanic_atom2_parser.c @@ -964,6 +964,7 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_ sample.deco.depth = 0.0; } sample.deco.time = decotime * 60; + sample.deco.tts = 0; if (callback) callback (DC_SAMPLE_DECO, sample, userdata); } diff --git a/src/oceanic_veo250_parser.c b/src/oceanic_veo250_parser.c index 2eead46..5f1cac1 100644 --- a/src/oceanic_veo250_parser.c +++ b/src/oceanic_veo250_parser.c @@ -277,6 +277,7 @@ oceanic_veo250_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback sample.deco.depth = 0.0; } sample.deco.time = decotime * 60; + sample.deco.tts = 0; if (callback) callback (DC_SAMPLE_DECO, sample, userdata); } diff --git a/src/oceanic_vtpro_parser.c b/src/oceanic_vtpro_parser.c index 75b3fc5..636f572 100644 --- a/src/oceanic_vtpro_parser.c +++ b/src/oceanic_vtpro_parser.c @@ -372,6 +372,7 @@ oceanic_vtpro_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_ sample.deco.depth = 0.0; } sample.deco.time = decotime * 60; + sample.deco.tts = 0; if (callback) callback (DC_SAMPLE_DECO, sample, userdata); } diff --git a/src/oceans_s1_parser.c b/src/oceans_s1_parser.c index 63c123f..ff034a2 100644 --- a/src/oceans_s1_parser.c +++ b/src/oceans_s1_parser.c @@ -298,6 +298,7 @@ oceans_s1_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t ca } sample.deco.depth = 0.0; sample.deco.time = 0; + sample.deco.tts = 0; if (callback) callback (DC_SAMPLE_DECO, sample, userdata); } } diff --git a/src/seac_screen_parser.c b/src/seac_screen_parser.c index dc2e781..dfe0cc3 100644 --- a/src/seac_screen_parser.c +++ b/src/seac_screen_parser.c @@ -377,6 +377,7 @@ seac_screen_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t sample.deco.time = ndl_tts; sample.deco.depth = 0; } + sample.deco.tts = 0; if (callback) callback (DC_SAMPLE_DECO, sample, userdata); // CNS diff --git a/src/shearwater_predator_parser.c b/src/shearwater_predator_parser.c index ab7752f..e8f9055 100644 --- a/src/shearwater_predator_parser.c +++ b/src/shearwater_predator_parser.c @@ -995,6 +995,7 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal sample.deco.depth = 0.0; } sample.deco.time = data[offset + pnf + 9] * 60; + sample.deco.tts = array_uint16_be (data + offset + pnf + 4) * 60; if (callback) callback (DC_SAMPLE_DECO, sample, userdata); // for logversion 7 and newer (introduced for Perdix AI) diff --git a/src/suunto_d9_parser.c b/src/suunto_d9_parser.c index 4de49c1..b61e994 100644 --- a/src/suunto_d9_parser.c +++ b/src/suunto_d9_parser.c @@ -811,6 +811,7 @@ suunto_d9_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t ca } sample.deco.time = 0; sample.deco.depth = 0.0; + sample.deco.tts = 0; if (callback) callback (DC_SAMPLE_DECO, sample, userdata); time += interval_sample; diff --git a/src/suunto_eonsteel_parser.c b/src/suunto_eonsteel_parser.c index c7276fb..5edd8f6 100644 --- a/src/suunto_eonsteel_parser.c +++ b/src/suunto_eonsteel_parser.c @@ -510,6 +510,7 @@ static void sample_ndl(struct sample_data *info, short ndl) sample.deco.type = DC_DECO_NDL; sample.deco.time = ndl; + sample.deco.tts = 0; if (info->callback) info->callback(DC_SAMPLE_DECO, sample, info->userdata); } @@ -996,8 +997,9 @@ static int traverse_samples(unsigned short type, const struct type_desc *desc, c dc_sample_value_t sample = {0}; sample.deco.type = DC_DECO_DECOSTOP; - sample.deco.time = info->tts; + sample.deco.time = 0; sample.deco.depth = info->ceiling; + sample.deco.tts = info->tts; if (info->callback) info->callback(DC_SAMPLE_DECO, sample, info->userdata); } diff --git a/src/uwatec_memomouse_parser.c b/src/uwatec_memomouse_parser.c index 2c3d506..80c13d5 100644 --- a/src/uwatec_memomouse_parser.c +++ b/src/uwatec_memomouse_parser.c @@ -272,6 +272,7 @@ uwatec_memomouse_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba } sample.deco.time = 0; sample.deco.depth = 0.0; + sample.deco.tts = 0; if (callback) callback (DC_SAMPLE_DECO, sample, userdata); // Warnings From becb8bd36e595b7efec39266b1e590e4f8dc703e Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Mon, 14 Jun 2021 20:58:14 +0200 Subject: [PATCH 06/51] Add a usage field to the tank and gas mix For gas consumption calculations it's very convenient to know whether a tank is used for example in a sidemount configuration, or as oxygen/diluent tank on a rebreather. For rebreather dives, it's convenient to know whether a gas mix is used as a closed-circuit mix (oxygen/diluent) or as an open circuit mix (bailout). --- examples/output_xml.c | 18 ++++++++++++++++-- include/libdivecomputer/parser.h | 9 +++++++++ src/atomics_cobalt_parser.c | 2 ++ src/cochran_commander_parser.c | 1 + src/cressi_edy_parser.c | 1 + src/cressi_goa_parser.c | 1 + src/cressi_leonardo_parser.c | 1 + src/deepblu_cosmiq_parser.c | 1 + src/deepsix_excursion_parser.c | 1 + src/diverite_nitekq_parser.c | 1 + src/divesoft_freedom_parser.c | 8 ++++++++ src/divesystem_idive_parser.c | 2 ++ src/hw_ostc_parser.c | 2 ++ src/liquivision_lynx_parser.c | 2 ++ src/mares_darwin_parser.c | 2 ++ src/mares_iconhd_parser.c | 2 ++ src/mares_nemo_parser.c | 2 ++ src/mclean_extreme_parser.c | 1 + src/oceanic_atom2_parser.c | 1 + src/oceanic_veo250_parser.c | 1 + src/oceanic_vtpro_parser.c | 2 ++ src/oceans_s1_parser.c | 1 + src/seac_screen_parser.c | 1 + src/shearwater_predator_parser.c | 17 +++++++++++++++++ src/suunto_d9_parser.c | 1 + src/suunto_eon_parser.c | 2 ++ src/suunto_eonsteel_parser.c | 9 +++++++-- src/suunto_solution_parser.c | 1 + src/suunto_vyper_parser.c | 2 ++ src/uwatec_memomouse_parser.c | 2 ++ src/uwatec_smart_parser.c | 2 ++ 31 files changed, 95 insertions(+), 4 deletions(-) diff --git a/examples/output_xml.c b/examples/output_xml.c index 1b66056..3801383 100644 --- a/examples/output_xml.c +++ b/examples/output_xml.c @@ -338,11 +338,19 @@ dctool_xml_output_write (dctool_output_t *abstract, dc_parser_t *parser, const u "\n" " %.1f\n" " %.1f\n" - " %.1f\n" - "\n", + " %.1f\n", gasmix.helium * 100.0, gasmix.oxygen * 100.0, gasmix.nitrogen * 100.0); + if (gasmix.usage) { + const char *usage[] = {"none", "oxygen", "diluent", "sidemount"}; + fprintf (output->ostream, + " %s\n", + usage[gasmix.usage]); + } + fprintf (output->ostream, + "\n"); + } // Parse the tanks. @@ -370,6 +378,12 @@ dctool_xml_output_write (dctool_output_t *abstract, dc_parser_t *parser, const u " %u\n", tank.gasmix); } + if (tank.usage) { + const char *usage[] = {"none", "oxygen", "diluent", "sidemount"}; + fprintf (output->ostream, + " %s\n", + usage[tank.usage]); + } if (tank.type != DC_TANKVOLUME_NONE) { fprintf (output->ostream, " %s\n" diff --git a/include/libdivecomputer/parser.h b/include/libdivecomputer/parser.h index 4a727e7..8a067b6 100644 --- a/include/libdivecomputer/parser.h +++ b/include/libdivecomputer/parser.h @@ -141,10 +141,18 @@ typedef struct dc_salinity_t { double density; } dc_salinity_t; +typedef enum dc_usage_t { + DC_USAGE_NONE, + DC_USAGE_OXYGEN, + DC_USAGE_DILUENT, + DC_USAGE_SIDEMOUNT, +} dc_usage_t; + typedef struct dc_gasmix_t { double helium; double oxygen; double nitrogen; + dc_usage_t usage; } dc_gasmix_t; #define DC_SENSOR_NONE 0xFFFFFFFF @@ -186,6 +194,7 @@ typedef struct dc_tank_t { double workpressure; /* Work pressure (bar) */ double beginpressure; /* Begin pressure (bar) */ double endpressure; /* End pressure (bar) */ + dc_usage_t usage; } dc_tank_t; typedef enum dc_decomodel_type_t { diff --git a/src/atomics_cobalt_parser.c b/src/atomics_cobalt_parser.c index 2fab3b3..6c42020 100644 --- a/src/atomics_cobalt_parser.c +++ b/src/atomics_cobalt_parser.c @@ -171,6 +171,7 @@ atomics_cobalt_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, un *((unsigned int *) value) = p[0x2a]; break; case DC_FIELD_GASMIX: + gasmix->usage = DC_USAGE_NONE; gasmix->helium = p[SZ_HEADER + SZ_GASMIX * flags + 5] / 100.0; gasmix->oxygen = p[SZ_HEADER + SZ_GASMIX * flags + 4] / 100.0; gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium; @@ -202,6 +203,7 @@ atomics_cobalt_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, un tank->gasmix = flags; tank->beginpressure = array_uint16_le(p + 6) * PSI / BAR; tank->endpressure = array_uint16_le(p + 14) * PSI / BAR; + tank->usage = DC_USAGE_NONE; break; case DC_FIELD_DIVEMODE: switch(p[0x24]) { diff --git a/src/cochran_commander_parser.c b/src/cochran_commander_parser.c index 72151df..5609948 100644 --- a/src/cochran_commander_parser.c +++ b/src/cochran_commander_parser.c @@ -514,6 +514,7 @@ cochran_commander_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, // Gas percentages are decimal and encoded as // highbyte = integer portion // lowbyte = decimal portion, divide by 256 to get decimal value + gasmix->usage = DC_USAGE_NONE; gasmix->oxygen = array_uint16_le (data + layout->oxygen + 2 * flags) / 256.0 / 100; if (layout->helium == UNSUPPORTED) { gasmix->helium = 0; diff --git a/src/cressi_edy_parser.c b/src/cressi_edy_parser.c index 4dd3a18..2ce1a9a 100644 --- a/src/cressi_edy_parser.c +++ b/src/cressi_edy_parser.c @@ -152,6 +152,7 @@ cressi_edy_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsign *((unsigned int *) value) = cressi_edy_parser_count_gasmixes(p); break; case DC_FIELD_GASMIX: + gasmix->usage = DC_USAGE_NONE; gasmix->helium = 0.0; gasmix->oxygen = bcd2dec (p[0x17 - flags]) / 100.0; gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium; diff --git a/src/cressi_goa_parser.c b/src/cressi_goa_parser.c index 80055fc..507e327 100644 --- a/src/cressi_goa_parser.c +++ b/src/cressi_goa_parser.c @@ -250,6 +250,7 @@ cressi_goa_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsign *((unsigned int *) value) = ngasmixes; break; case DC_FIELD_GASMIX: + gasmix->usage = DC_USAGE_NONE; gasmix->helium = 0.0; gasmix->oxygen = data[layout->gasmix + 2 * flags + 1] / 100.0; gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium; diff --git a/src/cressi_leonardo_parser.c b/src/cressi_leonardo_parser.c index 55624b1..849aa87 100644 --- a/src/cressi_leonardo_parser.c +++ b/src/cressi_leonardo_parser.c @@ -146,6 +146,7 @@ cressi_leonardo_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, u } break; case DC_FIELD_GASMIX: + gasmix->usage = DC_USAGE_NONE; gasmix->helium = 0.0; gasmix->oxygen = data[0x19] / 100.0; gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium; diff --git a/src/deepblu_cosmiq_parser.c b/src/deepblu_cosmiq_parser.c index a6efafd..c6f647b 100644 --- a/src/deepblu_cosmiq_parser.c +++ b/src/deepblu_cosmiq_parser.c @@ -151,6 +151,7 @@ deepblu_cosmiq_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, un *((unsigned int *) value) = mode == SCUBA; break; case DC_FIELD_GASMIX: + gasmix->usage = DC_USAGE_NONE; gasmix->oxygen = data[3] / 100.0; gasmix->helium = 0.0; gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium; diff --git a/src/deepsix_excursion_parser.c b/src/deepsix_excursion_parser.c index f6eb05f..13e4453 100644 --- a/src/deepsix_excursion_parser.c +++ b/src/deepsix_excursion_parser.c @@ -322,6 +322,7 @@ deepsix_excursion_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, *((unsigned int *) value) = parser->ngasmixes; break; case DC_FIELD_GASMIX: + gasmix->usage = DC_USAGE_NONE; gasmix->oxygen = parser->gasmix[flags].oxygen / 100.0; gasmix->helium = parser->gasmix[flags].helium / 100.0; gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium; diff --git a/src/diverite_nitekq_parser.c b/src/diverite_nitekq_parser.c index 6cfd9bc..ef67e1b 100644 --- a/src/diverite_nitekq_parser.c +++ b/src/diverite_nitekq_parser.c @@ -161,6 +161,7 @@ diverite_nitekq_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, u *((unsigned int *) value) = parser->ngasmixes; break; case DC_FIELD_GASMIX: + gasmix->usage = DC_USAGE_NONE; gasmix->helium = parser->he[flags] / 100.0; gasmix->oxygen = parser->o2[flags] / 100.0; gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium; diff --git a/src/divesoft_freedom_parser.c b/src/divesoft_freedom_parser.c index 74ac136..6ddad76 100644 --- a/src/divesoft_freedom_parser.c +++ b/src/divesoft_freedom_parser.c @@ -838,6 +838,13 @@ divesoft_freedom_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, *((unsigned int *) value) = parser->ngasmixes; break; case DC_FIELD_GASMIX: + if (parser->gasmix[flags].type == OXYGEN) { + gasmix->usage = DC_USAGE_OXYGEN; + } else if (parser->gasmix[flags].type == DILUENT) { + gasmix->usage = DC_USAGE_DILUENT; + } else { + gasmix->usage = DC_USAGE_NONE; + } gasmix->helium = parser->gasmix[flags].helium / 100.0; gasmix->oxygen = parser->gasmix[flags].oxygen / 100.0; gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium; @@ -859,6 +866,7 @@ divesoft_freedom_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, tank->beginpressure = parser->tank[flags].beginpressure * 2.0; tank->endpressure = parser->tank[flags].endpressure * 2.0; tank->gasmix = flags; + tank->usage = DC_USAGE_NONE; break; case DC_FIELD_DECOMODEL: if (parser->vpm) { diff --git a/src/divesystem_idive_parser.c b/src/divesystem_idive_parser.c index 892cda1..6d89a09 100644 --- a/src/divesystem_idive_parser.c +++ b/src/divesystem_idive_parser.c @@ -317,6 +317,7 @@ divesystem_idive_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, *((unsigned int *) value) = parser->ngasmixes; break; case DC_FIELD_GASMIX: + gasmix->usage = DC_USAGE_NONE; gasmix->helium = parser->gasmix[flags].helium / 100.0; gasmix->oxygen = parser->gasmix[flags].oxygen / 100.0; gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium; @@ -331,6 +332,7 @@ divesystem_idive_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, tank->beginpressure = parser->tank[flags].beginpressure; tank->endpressure = parser->tank[flags].endpressure; tank->gasmix = DC_GASMIX_UNKNOWN; + tank->usage = DC_USAGE_NONE; break; case DC_FIELD_ATMOSPHERIC: if (ISIX3M(parser->model)) { diff --git a/src/hw_ostc_parser.c b/src/hw_ostc_parser.c index 1421a08..f41d747 100644 --- a/src/hw_ostc_parser.c +++ b/src/hw_ostc_parser.c @@ -552,6 +552,8 @@ hw_ostc_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned *((unsigned int *) value) = parser->ngasmixes; break; case DC_FIELD_GASMIX: + gasmix->usage = parser->gasmix[flags].diluent ? + DC_USAGE_DILUENT : DC_USAGE_NONE; gasmix->oxygen = parser->gasmix[flags].oxygen / 100.0; gasmix->helium = parser->gasmix[flags].helium / 100.0; gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium; diff --git a/src/liquivision_lynx_parser.c b/src/liquivision_lynx_parser.c index 14c86ed..19c1d14 100644 --- a/src/liquivision_lynx_parser.c +++ b/src/liquivision_lynx_parser.c @@ -315,6 +315,7 @@ liquivision_lynx_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, *((unsigned int *) value) = parser->ngasmixes; break; case DC_FIELD_GASMIX: + gasmix->usage = DC_USAGE_NONE; gasmix->helium = parser->gasmix[flags].helium / 100.0; gasmix->oxygen = parser->gasmix[flags].oxygen / 100.0; gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium; @@ -329,6 +330,7 @@ liquivision_lynx_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, tank->beginpressure = parser->tank[flags].beginpressure / 100.0; tank->endpressure = parser->tank[flags].endpressure / 100.0; tank->gasmix = DC_GASMIX_UNKNOWN; + tank->usage = DC_USAGE_NONE; break; default: return DC_STATUS_UNSUPPORTED; diff --git a/src/mares_darwin_parser.c b/src/mares_darwin_parser.c index 56b68d3..ecc5a03 100644 --- a/src/mares_darwin_parser.c +++ b/src/mares_darwin_parser.c @@ -159,6 +159,7 @@ mares_darwin_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsi } break; case DC_FIELD_GASMIX: + gasmix->usage = DC_USAGE_NONE; gasmix->helium = 0.0; if (mode == NITROX) { gasmix->oxygen = p[0x0E] / 100.0; @@ -185,6 +186,7 @@ mares_darwin_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsi tank->gasmix = 0; tank->beginpressure = array_uint16_be (p + 0x17); tank->endpressure = array_uint16_be (p + 0x19); + tank->usage = DC_USAGE_NONE; } else { return DC_STATUS_UNSUPPORTED; } diff --git a/src/mares_iconhd_parser.c b/src/mares_iconhd_parser.c index 9ffb1e6..7ec513e 100644 --- a/src/mares_iconhd_parser.c +++ b/src/mares_iconhd_parser.c @@ -830,6 +830,7 @@ mares_iconhd_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsi *((unsigned int *) value) = parser->ngasmixes; break; case DC_FIELD_GASMIX: + gasmix->usage = DC_USAGE_NONE; gasmix->oxygen = parser->gasmix[flags].oxygen / 100.0; gasmix->helium = parser->gasmix[flags].helium / 100.0; gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium; @@ -857,6 +858,7 @@ mares_iconhd_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsi } else { tank->gasmix = DC_GASMIX_UNKNOWN; } + tank->usage = DC_USAGE_NONE; break; case DC_FIELD_ATMOSPHERIC: *((double *) value) = array_uint16_le (p + parser->layout->atmospheric) / (1000.0 * parser->layout->atmospheric_divisor); diff --git a/src/mares_nemo_parser.c b/src/mares_nemo_parser.c index a4c2d4b..828fcb3 100644 --- a/src/mares_nemo_parser.c +++ b/src/mares_nemo_parser.c @@ -251,6 +251,7 @@ mares_nemo_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsign } gasmix->helium = 0.0; gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium; + gasmix->usage = DC_USAGE_NONE; break; case DC_FIELD_TANK_COUNT: if (parser->extra) @@ -290,6 +291,7 @@ mares_nemo_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsign } else { tank->gasmix = DC_GASMIX_UNKNOWN; } + tank->usage = DC_USAGE_NONE; break; case DC_FIELD_TEMPERATURE_MINIMUM: *((double *) value) = (signed char) p[53 - 11]; diff --git a/src/mclean_extreme_parser.c b/src/mclean_extreme_parser.c index 260c56b..0cf0c5f 100644 --- a/src/mclean_extreme_parser.c +++ b/src/mclean_extreme_parser.c @@ -221,6 +221,7 @@ mclean_extreme_parser_get_field(dc_parser_t *abstract, dc_field_type_t type, uns *((unsigned int *)value) = parser->ngasmixes; break; case DC_FIELD_GASMIX: + gasmix->usage = DC_USAGE_NONE; gasmix->helium = 0.01 * abstract->data[0x0001 + 1 + 2 * parser->gasmix[flags]]; gasmix->oxygen = 0.01 * abstract->data[0x0001 + 0 + 2 * parser->gasmix[flags]]; gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium; diff --git a/src/oceanic_atom2_parser.c b/src/oceanic_atom2_parser.c index 272cfa2..8d87174 100644 --- a/src/oceanic_atom2_parser.c +++ b/src/oceanic_atom2_parser.c @@ -516,6 +516,7 @@ oceanic_atom2_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, uns *((unsigned int *) value) = parser->ngasmixes; break; case DC_FIELD_GASMIX: + gasmix->usage = DC_USAGE_NONE; gasmix->oxygen = parser->oxygen[flags] / 100.0; gasmix->helium = parser->helium[flags] / 100.0; gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium; diff --git a/src/oceanic_veo250_parser.c b/src/oceanic_veo250_parser.c index 5f1cac1..d3d9e6e 100644 --- a/src/oceanic_veo250_parser.c +++ b/src/oceanic_veo250_parser.c @@ -170,6 +170,7 @@ oceanic_veo250_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, un *((unsigned int *) value) = 1; break; case DC_FIELD_GASMIX: + gasmix->usage = DC_USAGE_NONE; gasmix->helium = 0.0; if (data[footer + 6]) gasmix->oxygen = data[footer + 6] / 100.0; diff --git a/src/oceanic_vtpro_parser.c b/src/oceanic_vtpro_parser.c index 636f572..49d5937 100644 --- a/src/oceanic_vtpro_parser.c +++ b/src/oceanic_vtpro_parser.c @@ -200,6 +200,7 @@ oceanic_vtpro_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, uns *((unsigned int *) value) = 1; break; case DC_FIELD_GASMIX: + gasmix->usage = DC_USAGE_NONE; gasmix->helium = 0.0; if (oxygen) gasmix->oxygen = oxygen / 100.0; @@ -220,6 +221,7 @@ oceanic_vtpro_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, uns tank->gasmix = flags; tank->beginpressure = beginpressure * 2 * PSI / BAR; tank->endpressure = endpressure * 2 * PSI / BAR; + tank->usage = DC_USAGE_NONE; break; default: return DC_STATUS_UNSUPPORTED; diff --git a/src/oceans_s1_parser.c b/src/oceans_s1_parser.c index ff034a2..23d4903 100644 --- a/src/oceans_s1_parser.c +++ b/src/oceans_s1_parser.c @@ -166,6 +166,7 @@ oceans_s1_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigne *((unsigned int *) value) = parser->divemode == SCUBA; break; case DC_FIELD_GASMIX: + gasmix->usage = DC_USAGE_NONE; gasmix->helium = 0.0; gasmix->oxygen = parser->oxygen / 100.0; gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium; diff --git a/src/seac_screen_parser.c b/src/seac_screen_parser.c index dfe0cc3..a0f7f3d 100644 --- a/src/seac_screen_parser.c +++ b/src/seac_screen_parser.c @@ -239,6 +239,7 @@ seac_screen_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsig *((unsigned int *)value) = parser->ngasmixes; break; case DC_FIELD_GASMIX: + gasmix->usage = DC_USAGE_NONE; gasmix->helium = 0.0; gasmix->oxygen = parser->oxygen[flags] / 100.0; gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium; diff --git a/src/shearwater_predator_parser.c b/src/shearwater_predator_parser.c index e8f9055..d8512db 100644 --- a/src/shearwater_predator_parser.c +++ b/src/shearwater_predator_parser.c @@ -774,6 +774,7 @@ shearwater_predator_parser_get_field (dc_parser_t *abstract, dc_field_type_t typ *((unsigned int *) value) = parser->ngasmixes; break; case DC_FIELD_GASMIX: + gasmix->usage = parser->gasmix[flags].diluent ? DC_USAGE_DILUENT : DC_USAGE_NONE; gasmix->oxygen = parser->gasmix[flags].oxygen / 100.0; gasmix->helium = parser->gasmix[flags].helium / 100.0; gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium; @@ -788,6 +789,22 @@ shearwater_predator_parser_get_field (dc_parser_t *abstract, dc_field_type_t typ tank->beginpressure = parser->tank[flags].beginpressure * 2 * PSI / BAR; tank->endpressure = parser->tank[flags].endpressure * 2 * PSI / BAR; tank->gasmix = DC_GASMIX_UNKNOWN; + switch (parser->tank[flags].name[0]) { + case 'S': + tank->usage = DC_USAGE_SIDEMOUNT; + break; + case 'O': + tank->usage = DC_USAGE_OXYGEN; + break; + case 'D': + tank->usage = DC_USAGE_DILUENT; + break; + case 'T': + case 'B': + default: + tank->usage = DC_USAGE_NONE; + break; + } break; case DC_FIELD_SALINITY: if (parser->density == 1000) diff --git a/src/suunto_d9_parser.c b/src/suunto_d9_parser.c index b61e994..dba1338 100644 --- a/src/suunto_d9_parser.c +++ b/src/suunto_d9_parser.c @@ -388,6 +388,7 @@ suunto_d9_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigne *((unsigned int *) value) = parser->ngasmixes; break; case DC_FIELD_GASMIX: + gasmix->usage = DC_USAGE_NONE; gasmix->helium = parser->helium[flags] / 100.0; gasmix->oxygen = parser->oxygen[flags] / 100.0; gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium; diff --git a/src/suunto_eon_parser.c b/src/suunto_eon_parser.c index 8a048b2..77879d1 100644 --- a/src/suunto_eon_parser.c +++ b/src/suunto_eon_parser.c @@ -225,6 +225,7 @@ suunto_eon_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsign *((unsigned int *) value) = 1; break; case DC_FIELD_GASMIX: + gasmix->usage = DC_USAGE_NONE; gasmix->helium = 0.0; gasmix->oxygen = oxygen / 100.0; gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium; @@ -242,6 +243,7 @@ suunto_eon_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsign tank->gasmix = 0; tank->beginpressure = beginpressure; tank->endpressure = endpressure; + tank->usage = DC_USAGE_NONE; break; case DC_FIELD_TEMPERATURE_MINIMUM: if (parser->spyder) diff --git a/src/suunto_eonsteel_parser.c b/src/suunto_eonsteel_parser.c index 5edd8f6..d7ab999 100644 --- a/src/suunto_eonsteel_parser.c +++ b/src/suunto_eonsteel_parser.c @@ -88,6 +88,7 @@ typedef struct suunto_eonsteel_parser_t { double highsetpoint; double customsetpoint; dc_tankvolume_t tankinfo[MAXGASES]; + dc_usage_t tankusage[MAXGASES]; double tanksize[MAXGASES]; double tankworkingpressure[MAXGASES]; dc_decomodel_t decomodel; @@ -1097,6 +1098,7 @@ suunto_eonsteel_parser_get_field(dc_parser_t *parser, dc_field_type_t type, unsi if (fabs(tank->volume - rint(tank->volume)) > 0.001) tank->type = DC_TANKVOLUME_IMPERIAL; } + tank->usage = eon->cache.tankusage[flags]; break; case DC_FIELD_DECOMODEL: field_value(value, eon->cache.decomodel); @@ -1160,6 +1162,7 @@ static int add_gas_type(suunto_eonsteel_parser_t *eon, const struct type_desc *d { int idx = eon->cache.ngases; dc_tankvolume_t tankinfo = DC_TANKVOLUME_METRIC; + dc_usage_t usage = DC_USAGE_NONE; char *name; if (idx >= MAXGASES) @@ -1170,15 +1173,17 @@ static int add_gas_type(suunto_eonsteel_parser_t *eon, const struct type_desc *d if (!name) DEBUG(eon->base.context, "Unable to look up gas type %u in %s", type, desc->format); else if (!strcasecmp(name, "Diluent")) - ; + usage = DC_USAGE_DILUENT; else if (!strcasecmp(name, "Oxygen")) - ; + usage = DC_USAGE_OXYGEN; else if (!strcasecmp(name, "None")) tankinfo = DC_TANKVOLUME_NONE; else if (strcasecmp(name, "Primary")) DEBUG(eon->base.context, "Unknown gas type %u (%s)", type, name); eon->cache.tankinfo[idx] = tankinfo; + eon->cache.tankusage[idx] = usage; + eon->cache.gasmix[idx].usage = usage; eon->cache.initialized |= 1 << DC_FIELD_GASMIX_COUNT; eon->cache.initialized |= 1 << DC_FIELD_TANK_COUNT; diff --git a/src/suunto_solution_parser.c b/src/suunto_solution_parser.c index 1713a73..1ec82f3 100644 --- a/src/suunto_solution_parser.c +++ b/src/suunto_solution_parser.c @@ -151,6 +151,7 @@ suunto_solution_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, u *((unsigned int *) value) = 1; break; case DC_FIELD_GASMIX: + gasmix->usage = DC_USAGE_NONE; gasmix->helium = 0.0; gasmix->oxygen = 0.21; gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium; diff --git a/src/suunto_vyper_parser.c b/src/suunto_vyper_parser.c index 356f64c..8fab31b 100644 --- a/src/suunto_vyper_parser.c +++ b/src/suunto_vyper_parser.c @@ -267,6 +267,7 @@ suunto_vyper_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsi *((unsigned int *) value) = parser->ngasmixes; break; case DC_FIELD_GASMIX: + gas->usage = DC_USAGE_NONE; gas->helium = 0.0; gas->oxygen = parser->oxygen[flags] / 100.0; gas->nitrogen = 1.0 - gas->oxygen - gas->helium; @@ -287,6 +288,7 @@ suunto_vyper_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsi tank->gasmix = 0; tank->beginpressure = beginpressure; tank->endpressure = endpressure; + tank->usage = DC_USAGE_NONE; break; case DC_FIELD_TEMPERATURE_SURFACE: *((double *) value) = (signed char) data[8]; diff --git a/src/uwatec_memomouse_parser.c b/src/uwatec_memomouse_parser.c index 80c13d5..0e55b4d 100644 --- a/src/uwatec_memomouse_parser.c +++ b/src/uwatec_memomouse_parser.c @@ -166,6 +166,7 @@ uwatec_memomouse_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, *((unsigned int *) value) = 1; break; case DC_FIELD_GASMIX: + gasmix->usage = DC_USAGE_NONE; gasmix->helium = 0.0; if (size >= header + 18) { if (is_oxygen) @@ -197,6 +198,7 @@ uwatec_memomouse_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, } tank->endpressure = 0.0; tank->gasmix = 0; + tank->usage = DC_USAGE_NONE; break; case DC_FIELD_TEMPERATURE_MINIMUM: *((double *) value) = (signed char) data[15] / 4.0; diff --git a/src/uwatec_smart_parser.c b/src/uwatec_smart_parser.c index 83304a5..017c10b 100644 --- a/src/uwatec_smart_parser.c +++ b/src/uwatec_smart_parser.c @@ -807,6 +807,7 @@ uwatec_smart_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsi *((unsigned int *) value) = parser->ngasmixes; break; case DC_FIELD_GASMIX: + gasmix->usage = DC_USAGE_NONE; gasmix->helium = parser->gasmix[flags].helium / 100.0; gasmix->oxygen = parser->gasmix[flags].oxygen / 100.0; gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium; @@ -821,6 +822,7 @@ uwatec_smart_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsi tank->beginpressure = parser->tank[flags].beginpressure / 128.0; tank->endpressure = parser->tank[flags].endpressure / 128.0; tank->gasmix = parser->tank[flags].gasmix; + tank->usage = DC_USAGE_NONE; break; case DC_FIELD_TEMPERATURE_MINIMUM: *((double *) value) = (signed short) array_uint16_le (data + table->temp_minimum) / 10.0; From 4e24b3a277ced12e02ebc7f7c5fa67dd6a12a20c Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Wed, 27 Jul 2022 19:37:22 +0200 Subject: [PATCH 07/51] Pass the sample struct by reference Because the sample struct is passed by value, the size of the structure can't be changed without also changing the function signature and breaking backwards compatibility. This prevents adding new fields in the future, to support some new features. When passing the sample struct by reference using a pointer, the size of the pointer does always remains the same. --- doc/man/dc_parser_samples_foreach.3 | 2 +- examples/output_xml.c | 52 +++++++++++++-------------- include/libdivecomputer/parser.h | 2 +- src/atomics_cobalt_parser.c | 18 +++++----- src/citizen_aqualand_parser.c | 6 ++-- src/cochran_commander_parser.c | 46 ++++++++++++------------ src/cressi_edy_parser.c | 6 ++-- src/cressi_goa_parser.c | 8 ++--- src/cressi_leonardo_parser.c | 12 +++---- src/deepblu_cosmiq_parser.c | 6 ++-- src/deepsix_excursion_parser.c | 24 ++++++------- src/diverite_nitekq_parser.c | 8 ++--- src/divesoft_freedom_parser.c | 30 ++++++++-------- src/divesystem_idive_parser.c | 18 +++++----- src/hw_ostc_parser.c | 34 +++++++++--------- src/liquivision_lynx_parser.c | 14 ++++---- src/mares_darwin_parser.c | 14 ++++---- src/mares_iconhd_parser.c | 32 ++++++++--------- src/mares_nemo_parser.c | 28 +++++++-------- src/mclean_extreme_parser.c | 10 +++--- src/oceanic_atom2_parser.c | 22 ++++++------ src/oceanic_veo250_parser.c | 10 +++--- src/oceanic_vtpro_parser.c | 10 +++--- src/oceans_s1_parser.c | 16 ++++----- src/parser-private.h | 2 +- src/parser.c | 8 ++--- src/reefnet_sensus_parser.c | 6 ++-- src/reefnet_sensuspro_parser.c | 6 ++-- src/reefnet_sensusultra_parser.c | 6 ++-- src/seac_screen_parser.c | 12 +++---- src/shearwater_predator_parser.c | 40 ++++++++++----------- src/sporasub_sp2_parser.c | 8 ++--- src/suunto_d9_parser.c | 24 ++++++------- src/suunto_eon_parser.c | 16 ++++----- src/suunto_eonsteel_parser.c | 30 ++++++++-------- src/suunto_solution_parser.c | 8 ++--- src/suunto_vyper_parser.c | 18 +++++----- src/tecdiving_divecomputereu_parser.c | 10 +++--- src/uwatec_memomouse_parser.c | 12 +++---- src/uwatec_smart_parser.c | 18 +++++----- 40 files changed, 326 insertions(+), 326 deletions(-) diff --git a/doc/man/dc_parser_samples_foreach.3 b/doc/man/dc_parser_samples_foreach.3 index 1b8be82..d741a43 100644 --- a/doc/man/dc_parser_samples_foreach.3 +++ b/doc/man/dc_parser_samples_foreach.3 @@ -31,7 +31,7 @@ .Ft "typedef void" .Fo "(*dc_sample_callback_t)" .Fa "dc_sample_type_t type" -.Fa "dc_sample_value_t value" +.Fa "const dc_sample_value_t *value" .Fa "void *userdata" .Fc .Ft dc_status_t diff --git a/examples/output_xml.c b/examples/output_xml.c index 3801383..7489af6 100644 --- a/examples/output_xml.c +++ b/examples/output_xml.c @@ -90,7 +90,7 @@ convert_volume (double value, dctool_units_t units) } static void -sample_cb (dc_sample_type_t type, dc_sample_value_t value, void *userdata) +sample_cb (dc_sample_type_t type, const dc_sample_value_t *value, void *userdata) { static const char *events[] = { "none", "deco", "rbt", "ascent", "ceiling", "workload", "transmitter", @@ -108,8 +108,8 @@ sample_cb (dc_sample_type_t type, dc_sample_value_t value, void *userdata) switch (type) { case DC_SAMPLE_TIME: - seconds = value.time / 1000; - milliseconds = value.time % 1000; + seconds = value->time / 1000; + milliseconds = value->time % 1000; if (sampledata->nsamples++) fprintf (sampledata->ostream, "\n"); fprintf (sampledata->ostream, "\n"); @@ -121,63 +121,63 @@ sample_cb (dc_sample_type_t type, dc_sample_value_t value, void *userdata) break; case DC_SAMPLE_DEPTH: fprintf (sampledata->ostream, " %.2f\n", - convert_depth(value.depth, sampledata->units)); + convert_depth(value->depth, sampledata->units)); break; case DC_SAMPLE_PRESSURE: fprintf (sampledata->ostream, " %.2f\n", - value.pressure.tank, - convert_pressure(value.pressure.value, sampledata->units)); + value->pressure.tank, + convert_pressure(value->pressure.value, sampledata->units)); break; case DC_SAMPLE_TEMPERATURE: fprintf (sampledata->ostream, " %.2f\n", - convert_temperature(value.temperature, sampledata->units)); + convert_temperature(value->temperature, sampledata->units)); break; case DC_SAMPLE_EVENT: - if (value.event.type != SAMPLE_EVENT_GASCHANGE && value.event.type != SAMPLE_EVENT_GASCHANGE2) { + if (value->event.type != SAMPLE_EVENT_GASCHANGE && value->event.type != SAMPLE_EVENT_GASCHANGE2) { fprintf (sampledata->ostream, " %s\n", - value.event.type, value.event.time, value.event.flags, value.event.value, events[value.event.type]); + value->event.type, value->event.time, value->event.flags, value->event.value, events[value->event.type]); } break; case DC_SAMPLE_RBT: - fprintf (sampledata->ostream, " %u\n", value.rbt); + fprintf (sampledata->ostream, " %u\n", value->rbt); break; case DC_SAMPLE_HEARTBEAT: - fprintf (sampledata->ostream, " %u\n", value.heartbeat); + fprintf (sampledata->ostream, " %u\n", value->heartbeat); break; case DC_SAMPLE_BEARING: - fprintf (sampledata->ostream, " %u\n", value.bearing); + fprintf (sampledata->ostream, " %u\n", value->bearing); break; case DC_SAMPLE_VENDOR: - fprintf (sampledata->ostream, " ", value.vendor.type, value.vendor.size); - for (unsigned int i = 0; i < value.vendor.size; ++i) - fprintf (sampledata->ostream, "%02X", ((const unsigned char *) value.vendor.data)[i]); + fprintf (sampledata->ostream, " ", value->vendor.type, value->vendor.size); + for (unsigned int i = 0; i < value->vendor.size; ++i) + fprintf (sampledata->ostream, "%02X", ((const unsigned char *) value->vendor.data)[i]); fprintf (sampledata->ostream, "\n"); break; case DC_SAMPLE_SETPOINT: - fprintf (sampledata->ostream, " %.2f\n", value.setpoint); + fprintf (sampledata->ostream, " %.2f\n", value->setpoint); break; case DC_SAMPLE_PPO2: - if (value.ppo2.sensor != DC_SENSOR_NONE) { - fprintf (sampledata->ostream, " %.2f\n", value.ppo2.sensor, value.ppo2.value); + if (value->ppo2.sensor != DC_SENSOR_NONE) { + fprintf (sampledata->ostream, " %.2f\n", value->ppo2.sensor, value->ppo2.value); } else { - fprintf (sampledata->ostream, " %.2f\n", value.ppo2.value); + fprintf (sampledata->ostream, " %.2f\n", value->ppo2.value); } break; case DC_SAMPLE_CNS: - fprintf (sampledata->ostream, " %.1f\n", value.cns * 100.0); + fprintf (sampledata->ostream, " %.1f\n", value->cns * 100.0); break; case DC_SAMPLE_DECO: fprintf (sampledata->ostream, " %s\n", - value.deco.time, - convert_depth(value.deco.depth, sampledata->units), - decostop[value.deco.type]); - if (value.deco.tts) { + value->deco.time, + convert_depth(value->deco.depth, sampledata->units), + decostop[value->deco.type]); + if (value->deco.tts) { fprintf (sampledata->ostream, " %u\n", - value.deco.tts); + value->deco.tts); } break; case DC_SAMPLE_GASMIX: - fprintf (sampledata->ostream, " %u\n", value.gasmix); + fprintf (sampledata->ostream, " %u\n", value->gasmix); break; default: break; diff --git a/include/libdivecomputer/parser.h b/include/libdivecomputer/parser.h index 8a067b6..fbc67c0 100644 --- a/include/libdivecomputer/parser.h +++ b/include/libdivecomputer/parser.h @@ -273,7 +273,7 @@ typedef union dc_sample_value_t { typedef struct dc_parser_t dc_parser_t; -typedef void (*dc_sample_callback_t) (dc_sample_type_t type, dc_sample_value_t value, void *userdata); +typedef void (*dc_sample_callback_t) (dc_sample_type_t type, const dc_sample_value_t *value, void *userdata); dc_status_t dc_parser_new (dc_parser_t **parser, dc_device_t *device); diff --git a/src/atomics_cobalt_parser.c b/src/atomics_cobalt_parser.c index 6c42020..da5264a 100644 --- a/src/atomics_cobalt_parser.c +++ b/src/atomics_cobalt_parser.c @@ -279,18 +279,18 @@ atomics_cobalt_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback // Time (seconds). time += interval; sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Depth (1/1000 bar). unsigned int depth = array_uint16_le (data + offset + 0); sample.depth = (signed int)(depth - atmospheric) * (BAR / 1000.0) / parser->hydrostatic; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); // Pressure (1 psi). unsigned int pressure = array_uint16_le (data + offset + 2); sample.pressure.tank = tank; sample.pressure.value = pressure * PSI / BAR; - if (callback) callback (DC_SAMPLE_PRESSURE, sample, userdata); + if (callback) callback (DC_SAMPLE_PRESSURE, &sample, userdata); // Current gas mix unsigned int gasmix = data[offset + 4]; @@ -306,14 +306,14 @@ atomics_cobalt_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback return DC_STATUS_DATAFORMAT; } sample.gasmix = idx; - if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback (DC_SAMPLE_GASMIX, &sample, userdata); gasmix_previous = gasmix; } // Temperature (1 °F). unsigned int temperature = data[offset + 8]; sample.temperature = (temperature - 32.0) * (5.0 / 9.0); - if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata); + if (callback) callback (DC_SAMPLE_TEMPERATURE, &sample, userdata); // violation status sample.event.type = 0; @@ -323,15 +323,15 @@ atomics_cobalt_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback unsigned int violation = data[offset + 11]; if (violation & 0x01) { sample.event.type = SAMPLE_EVENT_ASCENT; - if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + if (callback) callback (DC_SAMPLE_EVENT, &sample, userdata); } if (violation & 0x04) { sample.event.type = SAMPLE_EVENT_CEILING; - if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + if (callback) callback (DC_SAMPLE_EVENT, &sample, userdata); } if (violation & 0x08) { sample.event.type = SAMPLE_EVENT_PO2; - if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + if (callback) callback (DC_SAMPLE_EVENT, &sample, userdata); } // NDL & deco @@ -347,7 +347,7 @@ atomics_cobalt_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback sample.deco.time = ndl; sample.deco.depth = 0.0; sample.deco.tts = 0; - if (callback) callback (DC_SAMPLE_DECO, sample, userdata); + if (callback) callback (DC_SAMPLE_DECO, &sample, userdata); offset += SZ_SEGMENT; } diff --git a/src/citizen_aqualand_parser.c b/src/citizen_aqualand_parser.c index 41a8edc..32816b4 100644 --- a/src/citizen_aqualand_parser.c +++ b/src/citizen_aqualand_parser.c @@ -242,14 +242,14 @@ citizen_aqualand_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba // Time time += interval; sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Depth if (metric) sample.depth = depth / 10.0; else sample.depth = depth * FEET; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); // Temperature if (time % 300 == 0) { @@ -260,7 +260,7 @@ citizen_aqualand_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba sample.temperature = temperature / 10.0; else sample.temperature = (temperature - 32.0) * (5.0 / 9.0); - if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata); + if (callback) callback (DC_SAMPLE_TEMPERATURE, &sample, userdata); } } } diff --git a/src/cochran_commander_parser.c b/src/cochran_commander_parser.c index 5609948..5d2d9b7 100644 --- a/src/cochran_commander_parser.c +++ b/src/cochran_commander_parser.c @@ -315,7 +315,7 @@ cochran_commander_handle_event (cochran_commander_parser_t *parser, unsigned cha sample.event.time = 0; sample.event.value = 0; sample.event.flags = event->flag; - if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + if (callback) callback (DC_SAMPLE_EVENT, &sample, userdata); } } @@ -580,16 +580,16 @@ cochran_commander_parser_samples_foreach_tm (dc_parser_t *abstract, dc_sample_ca unsigned int depth = samples[1]; // Half feet last_sample_time = sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); sample.depth = (depth / 2.0) * FEET; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); sample.temperature = (temp / 2.0 - 32.0) / 1.8; - if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata); + if (callback) callback (DC_SAMPLE_TEMPERATURE, &sample, userdata); sample.gasmix = 0; - if (callback) callback(DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback(DC_SAMPLE_GASMIX, &sample, userdata); while (offset < size) { const unsigned char *s = samples + offset; @@ -598,7 +598,7 @@ cochran_commander_parser_samples_foreach_tm (dc_parser_t *abstract, dc_sample_ca if (last_sample_time != sample.time) { // We haven't issued this time yet. last_sample_time = sample.time; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); } if (*s & 0x80) { @@ -617,7 +617,7 @@ cochran_commander_parser_samples_foreach_tm (dc_parser_t *abstract, dc_sample_ca sample.deco.time = 60; // We don't know the duration sample.deco.depth = deco_ceiling * FEET; sample.deco.tts = 0; - if (callback) callback(DC_SAMPLE_DECO, sample, userdata); + if (callback) callback(DC_SAMPLE_DECO, &sample, userdata); break; case 0xAD: // Increment ceiling (shallower) deco_ceiling -= 10; // feet @@ -626,7 +626,7 @@ cochran_commander_parser_samples_foreach_tm (dc_parser_t *abstract, dc_sample_ca sample.deco.depth = deco_ceiling * FEET; sample.deco.time = 60; // We don't know the duration sample.deco.tts = 0; - if (callback) callback(DC_SAMPLE_DECO, sample, userdata); + if (callback) callback(DC_SAMPLE_DECO, &sample, userdata); break; default: cochran_commander_handle_event(parser, s[0], callback, userdata); @@ -639,7 +639,7 @@ cochran_commander_parser_samples_foreach_tm (dc_parser_t *abstract, dc_sample_ca else temp += (*s & 0x0f); sample.temperature = (temp / 2.0 - 32.0) / 1.8; - if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata); + if (callback) callback (DC_SAMPLE_TEMPERATURE, &sample, userdata); } offset++; @@ -653,7 +653,7 @@ cochran_commander_parser_samples_foreach_tm (dc_parser_t *abstract, dc_sample_ca depth += s[0] & 0x3f; sample.depth = (depth / 2.0) * FEET; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); offset++; time += sample_interval; @@ -718,16 +718,16 @@ cochran_commander_parser_samples_foreach_emc (dc_parser_t *abstract, dc_sample_c } last_sample_time = sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); sample.depth = start_depth * FEET; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); sample.temperature = (data[layout->start_temp] - 32.0) / 1.8; - if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata); + if (callback) callback (DC_SAMPLE_TEMPERATURE, &sample, userdata); sample.gasmix = 0; - if (callback) callback(DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback(DC_SAMPLE_GASMIX, &sample, userdata); unsigned int last_gasmix = sample.gasmix; while (offset < size) { @@ -737,7 +737,7 @@ cochran_commander_parser_samples_foreach_emc (dc_parser_t *abstract, dc_sample_c if (last_sample_time != sample.time) { // We haven't issued this time yet. last_sample_time = sample.time; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); } // If corrupt_dive end before offset @@ -778,7 +778,7 @@ cochran_commander_parser_samples_foreach_emc (dc_parser_t *abstract, dc_sample_c sample.deco.time = (array_uint16_le(s + 3) + 1) * 60; sample.deco.depth = deco_ceiling * FEET; sample.deco.tts = 0; - if (callback) callback(DC_SAMPLE_DECO, sample, userdata); + if (callback) callback(DC_SAMPLE_DECO, &sample, userdata); break; case 0xAD: // Increment ceiling (shallower) deco_ceiling -= 10; // feet @@ -787,7 +787,7 @@ cochran_commander_parser_samples_foreach_emc (dc_parser_t *abstract, dc_sample_c sample.deco.depth = deco_ceiling * FEET; sample.deco.time = (array_uint16_le(s + 3) + 1) * 60; sample.deco.tts = 0; - if (callback) callback(DC_SAMPLE_DECO, sample, userdata); + if (callback) callback(DC_SAMPLE_DECO, &sample, userdata); break; case 0xC0: // Switched to FO2 21% mode (surface) // Event seen upon surfacing @@ -796,14 +796,14 @@ cochran_commander_parser_samples_foreach_emc (dc_parser_t *abstract, dc_sample_c case 0xEF: // Switched to gas blend 2 if (last_gasmix != 1) { sample.gasmix = 1; - if (callback) callback(DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback(DC_SAMPLE_GASMIX, &sample, userdata); last_gasmix = sample.gasmix; } break; case 0xF3: // Switched to gas blend 1 if (last_gasmix != 0) { sample.gasmix = 0; - if (callback) callback(DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback(DC_SAMPLE_GASMIX, &sample, userdata); last_gasmix = sample.gasmix; } break; @@ -823,7 +823,7 @@ cochran_commander_parser_samples_foreach_emc (dc_parser_t *abstract, dc_sample_c depth += (s[0] & 0x3f); sample.depth = (start_depth + depth / 4.0) * FEET; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); // Ascent rate is logged in the 0th sample, temp in the 1st, repeat. if (time % 2 == 0) { @@ -839,7 +839,7 @@ cochran_commander_parser_samples_foreach_emc (dc_parser_t *abstract, dc_sample_c double temperature = s[1] / 2.0 + 20.0; sample.temperature = (temperature - 32.0) / 1.8; - if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata); + if (callback) callback (DC_SAMPLE_TEMPERATURE, &sample, userdata); } // Cochran EMC models store NDL and deco stop time @@ -861,7 +861,7 @@ cochran_commander_parser_samples_foreach_emc (dc_parser_t *abstract, dc_sample_c sample.deco.time = deco_time * 60; sample.deco.depth = 0; sample.deco.tts = 0; - if (callback) callback (DC_SAMPLE_DECO, sample, userdata); + if (callback) callback (DC_SAMPLE_DECO, &sample, userdata); } break; case 23: @@ -872,7 +872,7 @@ cochran_commander_parser_samples_foreach_emc (dc_parser_t *abstract, dc_sample_c sample.deco.depth = deco_ceiling * FEET; sample.deco.time = deco_time * 60; sample.deco.tts = 0; - if (callback) callback (DC_SAMPLE_DECO, sample, userdata); + if (callback) callback (DC_SAMPLE_DECO, &sample, userdata); } break; } diff --git a/src/cressi_edy_parser.c b/src/cressi_edy_parser.c index 2ce1a9a..182fd11 100644 --- a/src/cressi_edy_parser.c +++ b/src/cressi_edy_parser.c @@ -203,12 +203,12 @@ cressi_edy_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t c // Time (seconds). time += interval; sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Depth (1/10 m). unsigned int depth = bcd2dec (data[offset + 0] & 0x0F) * 100 + bcd2dec (data[offset + 1]); sample.depth = depth / 10.0; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); // Current gasmix if (ngasmixes) { @@ -221,7 +221,7 @@ cressi_edy_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t c } if (idx != gasmix) { sample.gasmix = idx; - if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback (DC_SAMPLE_GASMIX, &sample, userdata); gasmix = idx; } } diff --git a/src/cressi_goa_parser.c b/src/cressi_goa_parser.c index 507e327..d5a9a34 100644 --- a/src/cressi_goa_parser.c +++ b/src/cressi_goa_parser.c @@ -331,24 +331,24 @@ cressi_goa_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t c if (complete) { // Time (seconds). sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Temperature (1/10 °C). if (have_temperature) { sample.temperature = temperature / 10.0; - if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata); + if (callback) callback (DC_SAMPLE_TEMPERATURE, &sample, userdata); have_temperature = 0; } // Depth (1/10 m). sample.depth = depth / 10.0; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); // Gas change if (divemode == SCUBA || divemode == NITROX) { if (gasmix != gasmix_previous) { sample.gasmix = gasmix; - if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback (DC_SAMPLE_GASMIX, &sample, userdata); gasmix_previous = gasmix; } } diff --git a/src/cressi_leonardo_parser.c b/src/cressi_leonardo_parser.c index 849aa87..3a6824e 100644 --- a/src/cressi_leonardo_parser.c +++ b/src/cressi_leonardo_parser.c @@ -198,11 +198,11 @@ cressi_leonardo_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callbac // Time (seconds). time += surftime; sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Depth (1/10 m). sample.depth = 0.0; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); offset += 4; } else { @@ -213,16 +213,16 @@ cressi_leonardo_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callbac // Time (seconds). time += interval; sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Depth (1/10 m). sample.depth = depth / 10.0; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); // Gas change. if (gasmix != gasmix_previous) { sample.gasmix = gasmix; - if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback (DC_SAMPLE_GASMIX, &sample, userdata); gasmix_previous = gasmix; } @@ -232,7 +232,7 @@ cressi_leonardo_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callbac sample.event.time = 0; sample.event.flags = 0; sample.event.value = ascent; - if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + if (callback) callback (DC_SAMPLE_EVENT, &sample, userdata); } offset += 2; diff --git a/src/deepblu_cosmiq_parser.c b/src/deepblu_cosmiq_parser.c index c6f647b..d744698 100644 --- a/src/deepblu_cosmiq_parser.c +++ b/src/deepblu_cosmiq_parser.c @@ -206,13 +206,13 @@ deepblu_cosmiq_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback time += interval; sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); sample.depth = (signed int) (depth - atmospheric) * (BAR / 1000.0) / parser->hydrostatic; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); sample.temperature = temperature / 10.0; - if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata); + if (callback) callback (DC_SAMPLE_TEMPERATURE, &sample, userdata); } return DC_STATUS_SUCCESS; diff --git a/src/deepsix_excursion_parser.c b/src/deepsix_excursion_parser.c index 13e4453..919fb6a 100644 --- a/src/deepsix_excursion_parser.c +++ b/src/deepsix_excursion_parser.c @@ -425,10 +425,10 @@ deepsix_excursion_parser_samples_foreach_v0 (dc_parser_t *abstract, dc_sample_ca if (type == TEMPERATURE) { time += interval; sample.time = time * 1000; - if (callback) callback(DC_SAMPLE_TIME, sample, userdata); + if (callback) callback(DC_SAMPLE_TIME, &sample, userdata); sample.depth = pressure_to_depth(depth, atmospheric, DENSITY); - if (callback) callback(DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback(DC_SAMPLE_DEPTH, &sample, userdata); } if (type == ALARM) { @@ -441,11 +441,11 @@ deepsix_excursion_parser_samples_foreach_v0 (dc_parser_t *abstract, dc_sample_ca length = 8; } else if (temperature >= 10) { sample.temperature = temperature / 10.0; - if (callback) callback(DC_SAMPLE_TEMPERATURE, sample, userdata); + if (callback) callback(DC_SAMPLE_TEMPERATURE, &sample, userdata); } } else { sample.temperature = temperature / 10.0; - if (callback) callback(DC_SAMPLE_TEMPERATURE, sample, userdata); + if (callback) callback(DC_SAMPLE_TEMPERATURE, &sample, userdata); } } else if (type == DECO) { unsigned int deco = array_uint16_le(data + offset + 4); @@ -455,7 +455,7 @@ deepsix_excursion_parser_samples_foreach_v0 (dc_parser_t *abstract, dc_sample_ca } else if (type == CNS) { unsigned int cns = array_uint16_le(data + offset + 4); sample.cns = cns / 100.0; - if (callback) callback(DC_SAMPLE_CNS, sample, userdata); + if (callback) callback(DC_SAMPLE_CNS, &sample, userdata); } offset += length; @@ -593,11 +593,11 @@ deepsix_excursion_parser_samples_foreach_v1 (dc_parser_t *abstract, dc_sample_ca // Time (seconds). time += samplerate; sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); unsigned int depth = array_uint16_le (data + offset); sample.depth = pressure_to_depth(depth, atmospheric, density); - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); offset += 2; // event info @@ -665,7 +665,7 @@ deepsix_excursion_parser_samples_foreach_v1 (dc_parser_t *abstract, dc_sample_ca break; } if (sample.event.type != SAMPLE_EVENT_NONE) { - if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + if (callback) callback (DC_SAMPLE_EVENT, &sample, userdata); } } break; @@ -687,7 +687,7 @@ deepsix_excursion_parser_samples_foreach_v1 (dc_parser_t *abstract, dc_sample_ca } sample.gasmix = mix_idx; - if (callback) callback(DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback(DC_SAMPLE_GASMIX, &sample, userdata); break; case EVENT_SAMPLES_MISSED: count = array_uint16_le(data + offset + event_offset); @@ -728,12 +728,12 @@ deepsix_excursion_parser_samples_foreach_v1 (dc_parser_t *abstract, dc_sample_ca case SAMPLE_TEMPERATURE: value = array_uint16_le(data + offset); sample.temperature = value / 10.0; - if (callback) callback(DC_SAMPLE_TEMPERATURE, sample, userdata); + if (callback) callback(DC_SAMPLE_TEMPERATURE, &sample, userdata); break; case SAMPLE_CNS: value = array_uint16_le(data + offset); sample.cns = value / 10000.0; - if (callback) callback (DC_SAMPLE_CNS, sample, userdata); + if (callback) callback (DC_SAMPLE_CNS, &sample, userdata); break; case SAMPLE_DECO_NDL: deco_flags = data[offset]; @@ -753,7 +753,7 @@ deepsix_excursion_parser_samples_foreach_v1 (dc_parser_t *abstract, dc_sample_ca sample.deco.depth = 0; sample.deco.time = deco_ndl_tts; } - if (callback) callback (DC_SAMPLE_DECO, sample, userdata); + if (callback) callback (DC_SAMPLE_DECO, &sample, userdata); break; default: break; diff --git a/src/diverite_nitekq_parser.c b/src/diverite_nitekq_parser.c index ef67e1b..bb13446 100644 --- a/src/diverite_nitekq_parser.c +++ b/src/diverite_nitekq_parser.c @@ -266,12 +266,12 @@ diverite_nitekq_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callbac // Time (seconds). time += interval; sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Gas change if (gasmix != gasmix_previous) { sample.gasmix = gasmix; - if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback (DC_SAMPLE_GASMIX, &sample, userdata); gasmix_previous = gasmix; } @@ -283,7 +283,7 @@ diverite_nitekq_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callbac sample.depth = depth / 10.0; else sample.depth = depth * FEET / 10.0; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); offset += 2; if (type == 3) { @@ -296,7 +296,7 @@ diverite_nitekq_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callbac unsigned int ppo2 = data[offset]; sample.ppo2.sensor = DC_SENSOR_NONE; sample.ppo2.value = ppo2 / 100.0; - if (callback) callback (DC_SAMPLE_PPO2, sample, userdata); + if (callback) callback (DC_SAMPLE_PPO2, &sample, userdata); offset++; } } else { diff --git a/src/divesoft_freedom_parser.c b/src/divesoft_freedom_parser.c index 6ddad76..51a229a 100644 --- a/src/divesoft_freedom_parser.c +++ b/src/divesoft_freedom_parser.c @@ -933,14 +933,14 @@ divesoft_freedom_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba } time = timestamp; sample.time = time * 1000; - if (callback) callback(DC_SAMPLE_TIME, sample, userdata); + if (callback) callback(DC_SAMPLE_TIME, &sample, userdata); } // Initial diluent. if (!initial) { if (parser->diluent != UNDEFINED) { sample.gasmix = parser->diluent; - if (callback) callback(DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback(DC_SAMPLE_GASMIX, &sample, userdata); } initial = 1; } @@ -951,19 +951,19 @@ divesoft_freedom_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba unsigned int ppo2 = array_uint16_le (data + offset + 6); sample.depth = depth / 100.0; - if (callback) callback(DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback(DC_SAMPLE_DEPTH, &sample, userdata); if (ppo2) { sample.ppo2.sensor = DC_SENSOR_NONE; sample.ppo2.value = ppo2 * 10.0 / BAR; - if (callback) callback(DC_SAMPLE_PPO2, sample, userdata); + if (callback) callback(DC_SAMPLE_PPO2, &sample, userdata); } if (id == POINT_2) { unsigned int orientation = array_uint32_le (data + offset + 8); unsigned int heading = orientation & 0x1FF; sample.bearing = heading; - if (callback) callback (DC_SAMPLE_BEARING, sample, userdata); + if (callback) callback (DC_SAMPLE_BEARING, &sample, userdata); } else if (id == POINT_1 || id == POINT_1_OLD) { unsigned int misc = array_uint32_le (data + offset + 8); unsigned int ceiling = array_uint16_le (data + offset + 12); @@ -974,7 +974,7 @@ divesoft_freedom_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba // Temperature sample.temperature = (signed int) signextend (temp, 10) / 10.0; - if (callback) callback(DC_SAMPLE_TEMPERATURE, sample, userdata); + if (callback) callback(DC_SAMPLE_TEMPERATURE, &sample, userdata); // Deco / NDL if (ceiling) { @@ -987,12 +987,12 @@ divesoft_freedom_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba sample.deco.depth = 0.0; } sample.deco.tts = tts * 60; - if (callback) callback(DC_SAMPLE_DECO, sample, userdata); + if (callback) callback(DC_SAMPLE_DECO, &sample, userdata); // Setpoint if (setpoint) { sample.setpoint = setpoint / 100.0; - if (callback) callback(DC_SAMPLE_SETPOINT, sample, userdata); + if (callback) callback(DC_SAMPLE_SETPOINT, &sample, userdata); } } } else if ((type >= LREC_MANIPULATION && type <= LREC_ACTIVITY) || type == LREC_INFO) { @@ -1004,7 +1004,7 @@ divesoft_freedom_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba sample.event.time = 0; sample.event.flags = 0; sample.event.value = 0; - if (callback) callback(DC_SAMPLE_EVENT, sample, userdata); + if (callback) callback(DC_SAMPLE_EVENT, &sample, userdata); } else if (event == EVENT_MIX_CHANGED || event == EVENT_DILUENT || event == EVENT_CHANGE_MODE) { unsigned int o2 = data[offset + 6]; unsigned int he = data[offset + 7]; @@ -1024,13 +1024,13 @@ divesoft_freedom_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba return DC_STATUS_DATAFORMAT; } sample.gasmix = idx; - if (callback) callback(DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback(DC_SAMPLE_GASMIX, &sample, userdata); } else if (event == EVENT_CNS) { sample.cns = array_uint16_le (data + offset + 6) / 100.0; - if (callback) callback(DC_SAMPLE_CNS, sample, userdata); + if (callback) callback(DC_SAMPLE_CNS, &sample, userdata); } else if (event == EVENT_SETPOINT_MANUAL || event == EVENT_SETPOINT_AUTO) { sample.setpoint = data[6] / 100.0; - if (callback) callback(DC_SAMPLE_SETPOINT, sample, userdata); + if (callback) callback(DC_SAMPLE_SETPOINT, &sample, userdata); } } else if (type == LREC_MEASURE) { // Measurement record. @@ -1048,7 +1048,7 @@ divesoft_freedom_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba sample.pressure.tank = idx; sample.pressure.value = pressure * 2.0; - if (callback) callback(DC_SAMPLE_PRESSURE, sample, userdata); + if (callback) callback(DC_SAMPLE_PRESSURE, &sample, userdata); } } else if (id == MEASURE_ID_OXYGEN) { for (unsigned int i = 0; i < NSENSORS; ++i) { @@ -1057,7 +1057,7 @@ divesoft_freedom_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba continue; sample.ppo2.sensor = i; sample.ppo2.value = ppo2 * 10.0 / BAR; - if (callback) callback(DC_SAMPLE_PPO2, sample, userdata); + if (callback) callback(DC_SAMPLE_PPO2, &sample, userdata); } } else if (id == MEASURE_ID_OXYGEN_MV) { for (unsigned int i = 0; i < NSENSORS; ++i) { @@ -1068,7 +1068,7 @@ divesoft_freedom_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba continue; sample.ppo2.sensor = i; sample.ppo2.value = value / 100.0 * parser->calibration[i] / BAR; - if (callback) callback(DC_SAMPLE_PPO2, sample, userdata); + if (callback) callback(DC_SAMPLE_PPO2, &sample, userdata); } } } else if (type == LREC_STATE) { diff --git a/src/divesystem_idive_parser.c b/src/divesystem_idive_parser.c index 6d89a09..28326a6 100644 --- a/src/divesystem_idive_parser.c +++ b/src/divesystem_idive_parser.c @@ -477,19 +477,19 @@ divesystem_idive_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba } time = timestamp; sample.time = timestamp * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Depth (1/10 m). unsigned int depth = array_uint16_le (data + offset + 6); if (maxdepth < depth) maxdepth = depth; sample.depth = depth / 10.0; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); // Temperature (Celsius). signed int temperature = (signed short) array_uint16_le (data + offset + 8); sample.temperature = temperature / 10.0; - if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata); + if (callback) callback (DC_SAMPLE_TEMPERATURE, &sample, userdata); // Dive mode unsigned int mode = data[offset + 18]; @@ -523,7 +523,7 @@ divesystem_idive_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba if (mode == SCR || mode == CCR) { unsigned int setpoint = array_uint16_le (data + offset + 19); sample.setpoint = setpoint / 1000.0; - if (callback) callback (DC_SAMPLE_SETPOINT, sample, userdata); + if (callback) callback (DC_SAMPLE_SETPOINT, &sample, userdata); } // Gaschange. @@ -550,7 +550,7 @@ divesystem_idive_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba } sample.gasmix = i; - if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback (DC_SAMPLE_GASMIX, &sample, userdata); o2_previous = o2; he_previous = he; } @@ -576,12 +576,12 @@ divesystem_idive_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba sample.deco.time = tts; sample.deco.tts = 0; } - if (callback) callback (DC_SAMPLE_DECO, sample, userdata); + if (callback) callback (DC_SAMPLE_DECO, &sample, userdata); // CNS unsigned int cns = array_uint16_le (data + offset + 29); sample.cns = cns / 100.0; - if (callback) callback (DC_SAMPLE_CNS, sample, userdata); + if (callback) callback (DC_SAMPLE_CNS, &sample, userdata); // Tank Pressure if (samplesize == SZ_SAMPLE_IX3M_APOS4) { @@ -602,7 +602,7 @@ divesystem_idive_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba sample.event.time = 0; sample.event.flags = 0; sample.event.value = 0; - if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + if (callback) callback (DC_SAMPLE_EVENT, &sample, userdata); } else { // Get the index of the tank. if (id != tank_previous) { @@ -632,7 +632,7 @@ divesystem_idive_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba if (tank_idx < ntanks) { sample.pressure.tank = tank_idx; sample.pressure.value = pressure; - if (callback) callback (DC_SAMPLE_PRESSURE, sample, userdata); + if (callback) callback (DC_SAMPLE_PRESSURE, &sample, userdata); tank[tank_idx].endpressure = pressure; } } diff --git a/src/hw_ostc_parser.c b/src/hw_ostc_parser.c index f41d747..ca19458 100644 --- a/src/hw_ostc_parser.c +++ b/src/hw_ostc_parser.c @@ -836,30 +836,30 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call // Time (seconds). time += samplerate; sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Initial gas mix. if (time == samplerate && parser->initial != UNDEFINED) { sample.gasmix = parser->initial; - if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback (DC_SAMPLE_GASMIX, &sample, userdata); } // Initial setpoint (mbar). if (time == samplerate && parser->initial_setpoint != UNDEFINED) { sample.setpoint = parser->initial_setpoint / 100.0; - if (callback) callback (DC_SAMPLE_SETPOINT, sample, userdata); + if (callback) callback (DC_SAMPLE_SETPOINT, &sample, userdata); } // Initial CNS (%). if (time == samplerate && parser->initial_cns != UNDEFINED) { sample.cns = parser->initial_cns / 100.0; - if (callback) callback (DC_SAMPLE_CNS, sample, userdata); + if (callback) callback (DC_SAMPLE_CNS, &sample, userdata); } // Depth (1/100 m). unsigned int depth = array_uint16_le (data + offset); sample.depth = depth / 100.0; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); offset += 2; // Extended sample info. @@ -918,7 +918,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call break; } if (sample.event.type && callback) - callback (DC_SAMPLE_EVENT, sample, userdata); + callback (DC_SAMPLE_EVENT, &sample, userdata); // Manual Gas Set & Change if (events & 0x10) { @@ -943,7 +943,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call } sample.gasmix = idx; - if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback (DC_SAMPLE_GASMIX, &sample, userdata); offset += 2; length -= 2; } @@ -965,7 +965,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call } idx--; /* Convert to a zero based index. */ sample.gasmix = idx; - if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback (DC_SAMPLE_GASMIX, &sample, userdata); tank = idx; offset++; length--; @@ -979,7 +979,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call return DC_STATUS_DATAFORMAT; } sample.setpoint = data[offset] / 100.0; - if (callback) callback (DC_SAMPLE_SETPOINT, sample, userdata); + if (callback) callback (DC_SAMPLE_SETPOINT, &sample, userdata); offset++; length--; } @@ -1008,7 +1008,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call } sample.gasmix = idx; - if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback (DC_SAMPLE_GASMIX, &sample, userdata); offset += 2; length -= 2; } @@ -1040,7 +1040,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call case TEMPERATURE: value = array_uint16_le (data + offset); sample.temperature = value / 10.0; - if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata); + if (callback) callback (DC_SAMPLE_TEMPERATURE, &sample, userdata); break; case DECO: // Due to a firmware bug, the deco/ndl info is incorrect for @@ -1056,7 +1056,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call } sample.deco.time = data[offset + 1] * 60; sample.deco.tts = 0; - if (callback) callback (DC_SAMPLE_DECO, sample, userdata); + if (callback) callback (DC_SAMPLE_DECO, &sample, userdata); break; case PPO2: for (unsigned int j = 0; j < 3; ++j) { @@ -1072,7 +1072,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call for (unsigned int j = 0; j < 3; ++j) { sample.ppo2.sensor = i; sample.ppo2.value = ppo2[j] / 100.0; - if (callback) callback (DC_SAMPLE_PPO2, sample, userdata); + if (callback) callback (DC_SAMPLE_PPO2, &sample, userdata); } } break; @@ -1081,7 +1081,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call sample.cns = array_uint16_le (data + offset) / 100.0; else sample.cns = data[offset] / 100.0; - if (callback) callback (DC_SAMPLE_CNS, sample, userdata); + if (callback) callback (DC_SAMPLE_CNS, &sample, userdata); break; case TANK: value = array_uint16_le (data + offset); @@ -1094,7 +1094,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call (firmware >= OSTC3FW(10,40) && firmware <= OSTC3FW(10,50))) { sample.pressure.value /= 10.0; } - if (callback) callback (DC_SAMPLE_PRESSURE, sample, userdata); + if (callback) callback (DC_SAMPLE_PRESSURE, &sample, userdata); } break; default: // Not yet used. @@ -1114,7 +1114,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call return DC_STATUS_DATAFORMAT; } sample.setpoint = data[offset] / 100.0; - if (callback) callback (DC_SAMPLE_SETPOINT, sample, userdata); + if (callback) callback (DC_SAMPLE_SETPOINT, &sample, userdata); offset++; length--; } @@ -1143,7 +1143,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call } sample.gasmix = idx; - if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback (DC_SAMPLE_GASMIX, &sample, userdata); offset += 2; length -= 2; } diff --git a/src/liquivision_lynx_parser.c b/src/liquivision_lynx_parser.c index 19c1d14..0ddb69e 100644 --- a/src/liquivision_lynx_parser.c +++ b/src/liquivision_lynx_parser.c @@ -548,28 +548,28 @@ liquivision_lynx_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba // Time (seconds). time += interval; sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Depth (1/100 m). sample.depth = value / 100.0; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); // Temperature (1/10 °C). int temperature = (signed short) array_uint16_le (data + offset); sample.temperature = temperature / 10.0; - if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata); + if (callback) callback (DC_SAMPLE_TEMPERATURE, &sample, userdata); // Gas mix if (have_gasmix) { sample.gasmix = gasmix_idx; - if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback (DC_SAMPLE_GASMIX, &sample, userdata); have_gasmix = 0; } // Setpoint (1/10 bar). if (have_setpoint) { sample.setpoint = setpoint / 10.0; - if (callback) callback (DC_SAMPLE_SETPOINT, sample, userdata); + if (callback) callback (DC_SAMPLE_SETPOINT, &sample, userdata); have_setpoint = 0; } @@ -579,7 +579,7 @@ liquivision_lynx_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba if (have_pressure & (1 << i)) { sample.pressure.tank = i; sample.pressure.value = pressure[i] / 100.0; - if (callback) callback (DC_SAMPLE_PRESSURE, sample, userdata); + if (callback) callback (DC_SAMPLE_PRESSURE, &sample, userdata); } } have_pressure = 0; @@ -596,7 +596,7 @@ liquivision_lynx_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba } sample.deco.time = 0; sample.deco.tts = 0; - if (callback) callback (DC_SAMPLE_DECO, sample, userdata); + if (callback) callback (DC_SAMPLE_DECO, &sample, userdata); have_deco = 0; } diff --git a/src/mares_darwin_parser.c b/src/mares_darwin_parser.c index ecc5a03..699fbc7 100644 --- a/src/mares_darwin_parser.c +++ b/src/mares_darwin_parser.c @@ -245,16 +245,16 @@ mares_darwin_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t // Surface Time (seconds). time += 20; sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Depth (1/10 m). sample.depth = depth / 10.0; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); // Gas change. if (gasmix != gasmix_previous) { sample.gasmix = gasmix; - if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback (DC_SAMPLE_GASMIX, &sample, userdata); gasmix_previous = gasmix; } @@ -264,7 +264,7 @@ mares_darwin_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t sample.event.time = 0; sample.event.flags = 0; sample.event.value = ascent; - if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + if (callback) callback (DC_SAMPLE_EVENT, &sample, userdata); } // Deco violation @@ -273,7 +273,7 @@ mares_darwin_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t sample.event.time = 0; sample.event.flags = 0; sample.event.value = 0; - if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + if (callback) callback (DC_SAMPLE_EVENT, &sample, userdata); } // Deco stop @@ -285,7 +285,7 @@ mares_darwin_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t sample.deco.time = 0; sample.deco.depth = 0.0; sample.deco.tts = 0; - if (callback) callback (DC_SAMPLE_DECO, sample, userdata); + if (callback) callback (DC_SAMPLE_DECO, &sample, userdata); if (parser->samplesize == 3) { unsigned int type = (time / 20 + 2) % 3; @@ -294,7 +294,7 @@ mares_darwin_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t pressure -= abstract->data[offset + 2]; sample.pressure.tank = 0; sample.pressure.value = pressure; - if (callback) callback (DC_SAMPLE_PRESSURE, sample, userdata); + if (callback) callback (DC_SAMPLE_PRESSURE, &sample, userdata); } } diff --git a/src/mares_iconhd_parser.c b/src/mares_iconhd_parser.c index 7ec513e..63a4021 100644 --- a/src/mares_iconhd_parser.c +++ b/src/mares_iconhd_parser.c @@ -1017,11 +1017,11 @@ mares_iconhd_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t // Surface Time (seconds). time += surftime * 1000; sample.time = time; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Surface Depth (0 m). sample.depth = 0.0; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); offset += parser->samplesize; nsamples++; @@ -1031,12 +1031,12 @@ mares_iconhd_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t // Time (seconds). time += parser->interval; sample.time = time; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Depth (1/10 m). unsigned int depth = array_uint16_le (data + offset); sample.depth = depth / 10.0; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); offset += 2; } @@ -1048,20 +1048,20 @@ mares_iconhd_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t // Surface Time (seconds). time += surftime * 1000; sample.time = time; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Surface Depth (0 m). sample.depth = 0.0; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); // Dive Time (seconds). time += divetime * 1000; sample.time = time; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Maximum Depth (1/10 m). sample.depth = maxdepth / 10.0; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); offset += parser->samplesize; nsamples++; @@ -1119,15 +1119,15 @@ mares_iconhd_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t // Time (seconds). time += parser->interval; sample.time = time; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Depth (1/10 m). sample.depth = depth / 10.0; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); // Temperature (1/10 °C). sample.temperature = temperature / 10.0; - if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata); + if (callback) callback (DC_SAMPLE_TEMPERATURE, &sample, userdata); // Current gas mix if (parser->ngasmixes > 0) { @@ -1137,7 +1137,7 @@ mares_iconhd_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t } if (gasmix != gasmix_previous) { sample.gasmix = gasmix; - if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback (DC_SAMPLE_GASMIX, &sample, userdata); gasmix_previous = gasmix; } } @@ -1148,7 +1148,7 @@ mares_iconhd_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t sample.event.time = 0; sample.event.flags = 0; sample.event.value = bookmark; - if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + if (callback) callback (DC_SAMPLE_EVENT, &sample, userdata); } if (parser->model == GENIUS || parser->model == HORIZON) { @@ -1162,7 +1162,7 @@ mares_iconhd_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t } sample.deco.time = decotime * 60; sample.deco.tts = tts; - if (callback) callback (DC_SAMPLE_DECO, sample, userdata); + if (callback) callback (DC_SAMPLE_DECO, &sample, userdata); // Alarms for (unsigned int v = alarms, i = 0; v; v >>= 1, ++i) { @@ -1188,7 +1188,7 @@ mares_iconhd_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t sample.event.time = 0; sample.event.flags = 0; sample.event.value = 0; - if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + if (callback) callback (DC_SAMPLE_EVENT, &sample, userdata); } } } @@ -1209,7 +1209,7 @@ mares_iconhd_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t if (gasmix < parser->ntanks) { sample.pressure.tank = gasmix; sample.pressure.value = pressure / 100.0; - if (callback) callback (DC_SAMPLE_PRESSURE, sample, userdata); + if (callback) callback (DC_SAMPLE_PRESSURE, &sample, userdata); } else if (pressure != 0) { WARNING (abstract->context, "Invalid tank with non-zero pressure."); } diff --git a/src/mares_nemo_parser.c b/src/mares_nemo_parser.c index 828fcb3..4b962ff 100644 --- a/src/mares_nemo_parser.c +++ b/src/mares_nemo_parser.c @@ -385,16 +385,16 @@ mares_nemo_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t c // Time (seconds). time += 20; sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Depth (1/10 m). sample.depth = depth / 10.0; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); // Gas change. if (gasmix != gasmix_previous) { sample.gasmix = gasmix; - if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback (DC_SAMPLE_GASMIX, &sample, userdata); gasmix_previous = gasmix; } @@ -404,7 +404,7 @@ mares_nemo_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t c sample.event.time = 0; sample.event.flags = 0; sample.event.value = ascent; - if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + if (callback) callback (DC_SAMPLE_EVENT, &sample, userdata); } // Deco violation @@ -413,7 +413,7 @@ mares_nemo_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t c sample.event.time = 0; sample.event.flags = 0; sample.event.value = 0; - if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + if (callback) callback (DC_SAMPLE_EVENT, &sample, userdata); } // Deco stop @@ -425,20 +425,20 @@ mares_nemo_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t c sample.deco.time = 0; sample.deco.depth = 0.0; sample.deco.tts = 0; - if (callback) callback (DC_SAMPLE_DECO, sample, userdata); + if (callback) callback (DC_SAMPLE_DECO, &sample, userdata); // Pressure (1 bar). if (parser->sample_size == 3) { sample.pressure.tank = 0; sample.pressure.value = data[idx + 2]; - if (callback) callback (DC_SAMPLE_PRESSURE, sample, userdata); + if (callback) callback (DC_SAMPLE_PRESSURE, &sample, userdata); } else if (parser->sample_size == 5) { unsigned int type = (time / 20) % 3; if (type == 0) { pressure -= data[idx + 2] * 100; sample.pressure.tank = 0; sample.pressure.value = pressure / 100.0; - if (callback) callback (DC_SAMPLE_PRESSURE, sample, userdata); + if (callback) callback (DC_SAMPLE_PRESSURE, &sample, userdata); } } } @@ -463,11 +463,11 @@ mares_nemo_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t c // Surface Time (seconds). time += surftime; sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Surface Depth (0 m). sample.depth = 0.0; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); if (profiles) { // Get the freedive sample interval for this model. @@ -504,11 +504,11 @@ mares_nemo_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t c if (time > maxtime) time = maxtime; // Adjust the last sample. sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Depth (1/10 m). sample.depth = depth / 10.0; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); } // Verify that the number of samples in the profile data @@ -523,11 +523,11 @@ mares_nemo_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t c // Dive Time (seconds). time += divetime; sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Maximum Depth (1/10 m). sample.depth = maxdepth / 10.0; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); } } } diff --git a/src/mclean_extreme_parser.c b/src/mclean_extreme_parser.c index 0cf0c5f..645a909 100644 --- a/src/mclean_extreme_parser.c +++ b/src/mclean_extreme_parser.c @@ -271,13 +271,13 @@ mclean_extreme_parser_samples_foreach(dc_parser_t *abstract, dc_sample_callback_ time += interval; sample.time = time * 1000; - if (callback) callback(DC_SAMPLE_TIME, sample, userdata); + if (callback) callback(DC_SAMPLE_TIME, &sample, userdata); sample.depth = 0.1 * depth; - if (callback) callback(DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback(DC_SAMPLE_DEPTH, &sample, userdata); sample.temperature = temperature; - if (callback) callback(DC_SAMPLE_TEMPERATURE, sample, userdata); + if (callback) callback(DC_SAMPLE_TEMPERATURE, &sample, userdata); if (gasmix_id != gasmix_previous) { // Find the gasmix in the list. @@ -299,13 +299,13 @@ mclean_extreme_parser_samples_foreach(dc_parser_t *abstract, dc_sample_callback_ } sample.gasmix = idx; - if (callback) callback(DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback(DC_SAMPLE_GASMIX, &sample, userdata); gasmix_previous = gasmix_id; } if (ccr) { sample.setpoint = 0.01 * setpoint; - if (callback) callback(DC_SAMPLE_SETPOINT, sample, userdata); + if (callback) callback(DC_SAMPLE_SETPOINT, &sample, userdata); } offset += SZ_SAMPLE; diff --git a/src/oceanic_atom2_parser.c b/src/oceanic_atom2_parser.c index 8d87174..cb98366 100644 --- a/src/oceanic_atom2_parser.c +++ b/src/oceanic_atom2_parser.c @@ -587,7 +587,7 @@ oceanic_atom2_parser_vendor (oceanic_atom2_parser_t *parser, const unsigned char sample.vendor.type = SAMPLE_VENDOR_OCEANIC_ATOM2; sample.vendor.size = length; sample.vendor.data = data + offset; - if (callback) callback (DC_SAMPLE_VENDOR, sample, userdata); + if (callback) callback (DC_SAMPLE_VENDOR, &sample, userdata); offset += length; } @@ -751,7 +751,7 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_ // Time time += interval; sample.time = time; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Vendor specific data if (i == 0) { @@ -763,7 +763,7 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_ // Depth sample.depth = 0.0; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); complete = 1; } @@ -788,7 +788,7 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_ time += interval; } sample.time = time; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Vendor specific data oceanic_atom2_parser_vendor (parser, @@ -850,7 +850,7 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_ temperature += (data[offset + 7] & 0x0C) >> 2; } sample.temperature = (temperature - 32.0) * (5.0 / 9.0); - if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata); + if (callback) callback (DC_SAMPLE_TEMPERATURE, &sample, userdata); } // Tank Pressure (psi) @@ -878,7 +878,7 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_ pressure -= data[offset + 1]; sample.pressure.tank = tank; sample.pressure.value = pressure * PSI / BAR; - if (callback) callback (DC_SAMPLE_PRESSURE, sample, userdata); + if (callback) callback (DC_SAMPLE_PRESSURE, &sample, userdata); } // Depth (1/16 ft) @@ -901,7 +901,7 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_ else depth = (data[offset + 2] + (data[offset + 3] << 8)) & 0x0FFF; sample.depth = depth / 16.0 * FEET; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); // Gas mix unsigned int have_gasmix = 0; @@ -916,7 +916,7 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_ return DC_STATUS_DATAFORMAT; } sample.gasmix = gasmix - 1; - if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback (DC_SAMPLE_GASMIX, &sample, userdata); gasmix_previous = gasmix; } @@ -966,7 +966,7 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_ } sample.deco.time = decotime * 60; sample.deco.tts = 0; - if (callback) callback (DC_SAMPLE_DECO, sample, userdata); + if (callback) callback (DC_SAMPLE_DECO, &sample, userdata); } unsigned int have_rbt = 0; @@ -989,7 +989,7 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_ } if (have_rbt) { sample.rbt = rbt; - if (callback) callback (DC_SAMPLE_RBT, sample, userdata); + if (callback) callback (DC_SAMPLE_RBT, &sample, userdata); } // Bookmarks @@ -1004,7 +1004,7 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_ sample.event.time = 0; sample.event.flags = 0; sample.event.value = 0; - if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + if (callback) callback (DC_SAMPLE_EVENT, &sample, userdata); } count++; diff --git a/src/oceanic_veo250_parser.c b/src/oceanic_veo250_parser.c index d3d9e6e..ee14061 100644 --- a/src/oceanic_veo250_parser.c +++ b/src/oceanic_veo250_parser.c @@ -232,18 +232,18 @@ oceanic_veo250_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback // Time. time += interval; sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Vendor specific data sample.vendor.type = SAMPLE_VENDOR_OCEANIC_VEO250; sample.vendor.size = PAGESIZE / 2; sample.vendor.data = data + offset; - if (callback) callback (DC_SAMPLE_VENDOR, sample, userdata); + if (callback) callback (DC_SAMPLE_VENDOR, &sample, userdata); // Depth (ft) unsigned int depth = data[offset + 2]; sample.depth = depth * FEET; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); // Temperature (°F) unsigned int temperature; @@ -254,7 +254,7 @@ oceanic_veo250_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback temperature = data[offset + 7]; } sample.temperature = (temperature - 32.0) * (5.0 / 9.0); - if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata); + if (callback) callback (DC_SAMPLE_TEMPERATURE, &sample, userdata); // NDL / Deco unsigned int have_deco = 0; @@ -279,7 +279,7 @@ oceanic_veo250_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback } sample.deco.time = decotime * 60; sample.deco.tts = 0; - if (callback) callback (DC_SAMPLE_DECO, sample, userdata); + if (callback) callback (DC_SAMPLE_DECO, &sample, userdata); } offset += PAGESIZE / 2; diff --git a/src/oceanic_vtpro_parser.c b/src/oceanic_vtpro_parser.c index 49d5937..4902033 100644 --- a/src/oceanic_vtpro_parser.c +++ b/src/oceanic_vtpro_parser.c @@ -334,13 +334,13 @@ oceanic_vtpro_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_ else time = timestamp * 60 + (i + 1) * 60.0 / count + 0.5; sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Vendor specific data sample.vendor.type = SAMPLE_VENDOR_OCEANIC_VTPRO; sample.vendor.size = PAGESIZE / 2; sample.vendor.data = data + offset; - if (callback) callback (DC_SAMPLE_VENDOR, sample, userdata); + if (callback) callback (DC_SAMPLE_VENDOR, &sample, userdata); // Depth (ft) unsigned int depth = 0; @@ -350,7 +350,7 @@ oceanic_vtpro_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_ depth = data[offset + 3]; } sample.depth = depth * FEET; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); // Temperature (°F) unsigned int temperature = 0; @@ -360,7 +360,7 @@ oceanic_vtpro_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_ temperature = data[offset + 6]; } sample.temperature = (temperature - 32.0) * (5.0 / 9.0); - if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata); + if (callback) callback (DC_SAMPLE_TEMPERATURE, &sample, userdata); // NDL / Deco if (parser->model != AERIS500AI) { @@ -375,7 +375,7 @@ oceanic_vtpro_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_ } sample.deco.time = decotime * 60; sample.deco.tts = 0; - if (callback) callback (DC_SAMPLE_DECO, sample, userdata); + if (callback) callback (DC_SAMPLE_DECO, &sample, userdata); } offset += PAGESIZE / 2; diff --git a/src/oceans_s1_parser.c b/src/oceans_s1_parser.c index 23d4903..c31bfe1 100644 --- a/src/oceans_s1_parser.c +++ b/src/oceans_s1_parser.c @@ -251,18 +251,18 @@ oceans_s1_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t ca for (unsigned int i = 0; i < nsamples; ++i) { time += interval; sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); sample.depth = 0; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); } time += interval; sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); sample.depth = depth / 100.0; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); } else if (strncmp(line, "enddive", 7) == 0) { if (sscanf(line, "enddive %u,%u", &maxdepth, &divetime) != 2) { ERROR (parser->base.context, "Failed to parse the line '%s'.", line); @@ -282,13 +282,13 @@ oceans_s1_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t ca time += interval; sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); sample.depth = depth / 100.0; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); sample.temperature = temperature; - if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata); + if (callback) callback (DC_SAMPLE_TEMPERATURE, &sample, userdata); if (events & EVENT_DECO_STOP) { sample.deco.type = DC_DECO_DECOSTOP; @@ -300,7 +300,7 @@ oceans_s1_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t ca sample.deco.depth = 0.0; sample.deco.time = 0; sample.deco.tts = 0; - if (callback) callback (DC_SAMPLE_DECO, sample, userdata); + if (callback) callback (DC_SAMPLE_DECO, &sample, userdata); } } diff --git a/src/parser-private.h b/src/parser-private.h index af1a76e..9b8ed7c 100644 --- a/src/parser-private.h +++ b/src/parser-private.h @@ -84,7 +84,7 @@ typedef struct sample_statistics_t { #define SAMPLE_STATISTICS_INITIALIZER {0, 0.0} void -sample_statistics_cb (dc_sample_type_t type, dc_sample_value_t value, void *userdata); +sample_statistics_cb (dc_sample_type_t type, const dc_sample_value_t *value, void *userdata); #ifdef __cplusplus } diff --git a/src/parser.c b/src/parser.c index 77dcb84..8a74cb1 100644 --- a/src/parser.c +++ b/src/parser.c @@ -393,17 +393,17 @@ dc_parser_destroy (dc_parser_t *parser) void -sample_statistics_cb (dc_sample_type_t type, dc_sample_value_t value, void *userdata) +sample_statistics_cb (dc_sample_type_t type, const dc_sample_value_t *value, void *userdata) { sample_statistics_t *statistics = (sample_statistics_t *) userdata; switch (type) { case DC_SAMPLE_TIME: - statistics->divetime = value.time / 1000; + statistics->divetime = value->time / 1000; break; case DC_SAMPLE_DEPTH: - if (statistics->maxdepth < value.depth) - statistics->maxdepth = value.depth; + if (statistics->maxdepth < value->depth) + statistics->maxdepth = value->depth; break; default: break; diff --git a/src/reefnet_sensus_parser.c b/src/reefnet_sensus_parser.c index 2797651..eb860ef 100644 --- a/src/reefnet_sensus_parser.c +++ b/src/reefnet_sensus_parser.c @@ -280,12 +280,12 @@ reefnet_sensus_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback // Time (seconds) time += interval; sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Depth (adjusted feet of seawater). unsigned int depth = data[offset++]; sample.depth = ((depth + 33.0 - (double) SAMPLE_DEPTH_ADJUST) * FSW - parser->atmospheric) / parser->hydrostatic; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); // Temperature (degrees Fahrenheit) if ((nsamples % 6) == 0) { @@ -293,7 +293,7 @@ reefnet_sensus_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback return DC_STATUS_DATAFORMAT; unsigned int temperature = data[offset++]; sample.temperature = (temperature - 32.0) * (5.0 / 9.0); - if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata); + if (callback) callback (DC_SAMPLE_TEMPERATURE, &sample, userdata); } // Current sample is complete. diff --git a/src/reefnet_sensuspro_parser.c b/src/reefnet_sensuspro_parser.c index 422a161..0100c28 100644 --- a/src/reefnet_sensuspro_parser.c +++ b/src/reefnet_sensuspro_parser.c @@ -279,15 +279,15 @@ reefnet_sensuspro_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callb // Time (seconds) time += interval; sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Temperature (°F) sample.temperature = (temperature - 32.0) * (5.0 / 9.0); - if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata); + if (callback) callback (DC_SAMPLE_TEMPERATURE, &sample, userdata); // Depth (absolute pressure in fsw) sample.depth = (depth * FSW - parser->atmospheric) / parser->hydrostatic; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); offset += 2; } diff --git a/src/reefnet_sensusultra_parser.c b/src/reefnet_sensusultra_parser.c index 90ead6f..9e43873 100644 --- a/src/reefnet_sensusultra_parser.c +++ b/src/reefnet_sensusultra_parser.c @@ -276,17 +276,17 @@ reefnet_sensusultra_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal // Time (seconds) time += interval; sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Temperature (0.01 °K) unsigned int temperature = array_uint16_le (data + offset); sample.temperature = temperature / 100.0 - 273.15; - if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata); + if (callback) callback (DC_SAMPLE_TEMPERATURE, &sample, userdata); // Depth (absolute pressure in millibar) unsigned int depth = array_uint16_le (data + offset + 2); sample.depth = (depth * BAR / 1000.0 - parser->atmospheric) / parser->hydrostatic; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); offset += 4; } diff --git a/src/seac_screen_parser.c b/src/seac_screen_parser.c index a0f7f3d..c50eaee 100644 --- a/src/seac_screen_parser.c +++ b/src/seac_screen_parser.c @@ -333,15 +333,15 @@ seac_screen_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t } time = timestamp; sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Depth (1/100 m). sample.depth = depth / 100.0; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); // Temperature (1/100 °C). sample.temperature = temperature / 100.0; - if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata); + if (callback) callback (DC_SAMPLE_TEMPERATURE, &sample, userdata); // Gas mix if (o2 != o2_previous) { @@ -364,7 +364,7 @@ seac_screen_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t } sample.gasmix = idx; - if (callback) callback(DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback(DC_SAMPLE_GASMIX, &sample, userdata); o2_previous = o2; } @@ -379,11 +379,11 @@ seac_screen_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t sample.deco.depth = 0; } sample.deco.tts = 0; - if (callback) callback (DC_SAMPLE_DECO, sample, userdata); + if (callback) callback (DC_SAMPLE_DECO, &sample, userdata); // CNS sample.cns = cns / 100.0; - if (callback) callback (DC_SAMPLE_CNS, sample, userdata); + if (callback) callback (DC_SAMPLE_CNS, &sample, userdata); // Deco model if (gf_low == 0 && gf_high == 0) { diff --git a/src/shearwater_predator_parser.c b/src/shearwater_predator_parser.c index d8512db..fe0a6db 100644 --- a/src/shearwater_predator_parser.c +++ b/src/shearwater_predator_parser.c @@ -912,7 +912,7 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal // Time (seconds). time += interval; sample.time = time; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Depth (1/10 m or ft). unsigned int depth = array_uint16_be (data + pnf + offset); @@ -920,7 +920,7 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal sample.depth = depth * FEET / 10.0; else sample.depth = depth / 10.0; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); // Temperature (°C or °F). int temperature = (signed char) data[offset + pnf + 13]; @@ -935,7 +935,7 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal sample.temperature = (temperature - 32.0) * (5.0 / 9.0); else sample.temperature = temperature; - if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata); + if (callback) callback (DC_SAMPLE_TEMPERATURE, &sample, userdata); // Status flags. unsigned int status = data[offset + pnf + 11]; @@ -946,19 +946,19 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal if ((status & PPO2_EXTERNAL) == 0) { sample.ppo2.sensor = DC_SENSOR_NONE; sample.ppo2.value = data[offset + pnf + 6] / 100.0; - if (callback) callback (DC_SAMPLE_PPO2, sample, userdata); + if (callback) callback (DC_SAMPLE_PPO2, &sample, userdata); sample.ppo2.sensor = 0; sample.ppo2.value = data[offset + pnf + 12] * parser->calibration[0]; - if (callback && (parser->calibrated & 0x01)) callback (DC_SAMPLE_PPO2, sample, userdata); + if (callback && (parser->calibrated & 0x01)) callback (DC_SAMPLE_PPO2, &sample, userdata); sample.ppo2.sensor = 1; sample.ppo2.value = data[offset + pnf + 14] * parser->calibration[1]; - if (callback && (parser->calibrated & 0x02)) callback (DC_SAMPLE_PPO2, sample, userdata); + if (callback && (parser->calibrated & 0x02)) callback (DC_SAMPLE_PPO2, &sample, userdata); sample.ppo2.sensor = 2; sample.ppo2.value = data[offset + pnf + 15] * parser->calibration[2]; - if (callback && (parser->calibrated & 0x04)) callback (DC_SAMPLE_PPO2, sample, userdata); + if (callback && (parser->calibrated & 0x04)) callback (DC_SAMPLE_PPO2, &sample, userdata); } // Setpoint @@ -972,13 +972,13 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal sample.setpoint = data[17] / 100.0; } } - if (callback) callback (DC_SAMPLE_SETPOINT, sample, userdata); + if (callback) callback (DC_SAMPLE_SETPOINT, &sample, userdata); } // CNS if (parser->petrel) { sample.cns = data[offset + pnf + 22] / 100.0; - if (callback) callback (DC_SAMPLE_CNS, sample, userdata); + if (callback) callback (DC_SAMPLE_CNS, &sample, userdata); } // Gaschange. @@ -993,7 +993,7 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal } sample.gasmix = idx; - if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback (DC_SAMPLE_GASMIX, &sample, userdata); o2_previous = o2; he_previous = he; dil_previous = ccr; @@ -1013,7 +1013,7 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal } sample.deco.time = data[offset + pnf + 9] * 60; sample.deco.tts = array_uint16_be (data + offset + pnf + 4) * 60; - if (callback) callback (DC_SAMPLE_DECO, sample, userdata); + if (callback) callback (DC_SAMPLE_DECO, &sample, userdata); // for logversion 7 and newer (introduced for Perdix AI) // detect tank pressure @@ -1035,7 +1035,7 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal pressure &= 0x0FFF; sample.pressure.tank = parser->tankidx[id]; sample.pressure.value = pressure * 2 * PSI / BAR; - if (callback) callback (DC_SAMPLE_PRESSURE, sample, userdata); + if (callback) callback (DC_SAMPLE_PRESSURE, &sample, userdata); } } @@ -1048,7 +1048,7 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal // 0xFB Tank size or max pressure haven’t been set up if (data[offset + pnf + 21] < 0xF0) { sample.rbt = data[offset + pnf + 21]; - if (callback) callback (DC_SAMPLE_RBT, sample, userdata); + if (callback) callback (DC_SAMPLE_RBT, &sample, userdata); } } } else if (type == LOG_RECORD_DIVE_SAMPLE_EXT) { @@ -1061,7 +1061,7 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal pressure &= 0x0FFF; sample.pressure.tank = parser->tankidx[id]; sample.pressure.value = pressure * 2 * PSI / BAR; - if (callback) callback (DC_SAMPLE_PRESSURE, sample, userdata); + if (callback) callback (DC_SAMPLE_PRESSURE, &sample, userdata); } } } @@ -1073,7 +1073,7 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal if (pressure) { sample.pressure.tank = parser->tankidx[id]; sample.pressure.value = pressure * 2 * PSI / BAR; - if (callback) callback (DC_SAMPLE_PRESSURE, sample, userdata); + if (callback) callback (DC_SAMPLE_PRESSURE, &sample, userdata); } } } @@ -1092,17 +1092,17 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal // Time (seconds). time += interval; sample.time = time; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Depth (absolute pressure in millibar) unsigned int depth = array_uint16_be (data + idx + 1); sample.depth = (signed int)(depth - parser->atmospheric) * (BAR / 1000.0) / (parser->density * GRAVITY); - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); // Temperature (1/10 °C). int temperature = (signed short) array_uint16_be (data + idx + 3); sample.temperature = temperature / 10.0; - if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata); + if (callback) callback (DC_SAMPLE_TEMPERATURE, &sample, userdata); } } else if (type == LOG_RECORD_INFO_EVENT) { unsigned int event = data[offset + 1]; @@ -1114,7 +1114,7 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal // Compass heading if (w1 != 0xFFFFFFFF) { sample.bearing = w1; - if (callback) callback (DC_SAMPLE_BEARING, sample, userdata); + if (callback) callback (DC_SAMPLE_BEARING, &sample, userdata); } // Tag @@ -1122,7 +1122,7 @@ shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal sample.event.time = 0; sample.event.flags = 0; sample.event.value = w2; - if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + if (callback) callback (DC_SAMPLE_EVENT, &sample, userdata); } } diff --git a/src/sporasub_sp2_parser.c b/src/sporasub_sp2_parser.c index 6c308d4..c84a35c 100644 --- a/src/sporasub_sp2_parser.c +++ b/src/sporasub_sp2_parser.c @@ -185,20 +185,20 @@ sporasub_sp2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t // Time (seconds) time += interval; sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Depth (1/100 m) sample.depth = depth / 100.0; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); // Temperature (1/10 °C) sample.temperature = temperature / 10.0 - 20.0; - if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata); + if (callback) callback (DC_SAMPLE_TEMPERATURE, &sample, userdata); // Heartrate if (heartrate) { sample.heartbeat = heartrate; - if (callback) callback (DC_SAMPLE_HEARTBEAT, sample, userdata); + if (callback) callback (DC_SAMPLE_HEARTBEAT, &sample, userdata); } offset += SZ_SAMPLE; diff --git a/src/suunto_d9_parser.c b/src/suunto_d9_parser.c index dba1338..43e9ccc 100644 --- a/src/suunto_d9_parser.c +++ b/src/suunto_d9_parser.c @@ -523,7 +523,7 @@ suunto_d9_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t ca // Time (seconds). sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Sample data. for (unsigned int i = 0; i < nparams; ++i) { @@ -538,19 +538,19 @@ suunto_d9_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t ca case 0x64: // Depth value = array_uint16_le (data + offset); sample.depth = value / (double) info[i].divisor; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); break; case 0x68: // Pressure value = array_uint16_le (data + offset); if (value != 0xFFFF) { sample.pressure.tank = 0; sample.pressure.value = value / (double) info[i].divisor; - if (callback) callback (DC_SAMPLE_PRESSURE, sample, userdata); + if (callback) callback (DC_SAMPLE_PRESSURE, &sample, userdata); } break; case 0x74: // Temperature sample.temperature = (signed char) data[offset] / (double) info[i].divisor; - if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata); + if (callback) callback (DC_SAMPLE_TEMPERATURE, &sample, userdata); break; default: // Unknown sample type ERROR (abstract->context, "Unknown sample type 0x%02x.", info[i].type); @@ -568,7 +568,7 @@ suunto_d9_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t ca return DC_STATUS_DATAFORMAT; } sample.gasmix = parser->gasmix; - if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback (DC_SAMPLE_GASMIX, &sample, userdata); } // Events @@ -608,7 +608,7 @@ suunto_d9_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t ca seconds = data[offset + 1]; sample.event.type = SAMPLE_EVENT_SURFACE; sample.event.time = seconds; - if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + if (callback) callback (DC_SAMPLE_EVENT, &sample, userdata); offset += 2; break; case 0x03: // Event @@ -714,7 +714,7 @@ suunto_d9_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t ca sample.event.flags = SAMPLE_FLAGS_BEGIN; sample.event.time = seconds; if (sample.event.type != SAMPLE_EVENT_NONE) { - if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + if (callback) callback (DC_SAMPLE_EVENT, &sample, userdata); } offset += 2; break; @@ -734,7 +734,7 @@ suunto_d9_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t ca sample.event.value = heading / 2; } sample.event.time = seconds; - if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + if (callback) callback (DC_SAMPLE_EVENT, &sample, userdata); offset += 4; break; case 0x05: // Gas Change @@ -750,7 +750,7 @@ suunto_d9_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t ca return DC_STATUS_DATAFORMAT; } sample.gasmix = idx; - if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback (DC_SAMPLE_GASMIX, &sample, userdata); offset += 2; break; case 0x06: // Gas Change @@ -784,10 +784,10 @@ suunto_d9_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t ca return DC_STATUS_DATAFORMAT; } sample.gasmix = idx; - if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback (DC_SAMPLE_GASMIX, &sample, userdata); if (type & 0x80) { sample.setpoint = ppo2 / 10.0; - if (callback) callback (DC_SAMPLE_SETPOINT, sample, userdata); + if (callback) callback (DC_SAMPLE_SETPOINT, &sample, userdata); } offset += length; break; @@ -813,7 +813,7 @@ suunto_d9_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t ca sample.deco.time = 0; sample.deco.depth = 0.0; sample.deco.tts = 0; - if (callback) callback (DC_SAMPLE_DECO, sample, userdata); + if (callback) callback (DC_SAMPLE_DECO, &sample, userdata); time += interval_sample; nsamples++; diff --git a/src/suunto_eon_parser.c b/src/suunto_eon_parser.c index 77879d1..9bfadda 100644 --- a/src/suunto_eon_parser.c +++ b/src/suunto_eon_parser.c @@ -275,15 +275,15 @@ suunto_eon_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t c // Time sample.time = 0; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Depth (0 ft) sample.depth = 0; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); // Initial gas mix. sample.gasmix = 0; - if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback (DC_SAMPLE_GASMIX, &sample, userdata); unsigned int depth = 0; unsigned int time = 0; @@ -297,7 +297,7 @@ suunto_eon_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t c // Time (seconds). time += interval; sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); complete = 0; } @@ -307,7 +307,7 @@ suunto_eon_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t c // Depth (ft). sample.depth = depth * FEET; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); complete = 1; } else { @@ -335,7 +335,7 @@ suunto_eon_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t c } if (sample.event.type != SAMPLE_EVENT_NONE) { - if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + if (callback) callback (DC_SAMPLE_EVENT, &sample, userdata); } } } @@ -344,12 +344,12 @@ suunto_eon_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t c if (complete) { time += interval; sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); } // Depth (0 ft) sample.depth = 0; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); return DC_STATUS_SUCCESS; } diff --git a/src/suunto_eonsteel_parser.c b/src/suunto_eonsteel_parser.c index d7ab999..5c5c328 100644 --- a/src/suunto_eonsteel_parser.c +++ b/src/suunto_eonsteel_parser.c @@ -476,7 +476,7 @@ static void sample_time(struct sample_data *info, unsigned short time_delta) info->time += time_delta; sample.time = info->time; - if (info->callback) info->callback(DC_SAMPLE_TIME, sample, info->userdata); + if (info->callback) info->callback(DC_SAMPLE_TIME, &sample, info->userdata); } static void sample_depth(struct sample_data *info, unsigned short depth) @@ -487,7 +487,7 @@ static void sample_depth(struct sample_data *info, unsigned short depth) return; sample.depth = depth / 100.0; - if (info->callback) info->callback(DC_SAMPLE_DEPTH, sample, info->userdata); + if (info->callback) info->callback(DC_SAMPLE_DEPTH, &sample, info->userdata); } static void sample_temp(struct sample_data *info, short temp) @@ -498,7 +498,7 @@ static void sample_temp(struct sample_data *info, short temp) return; sample.temperature = temp / 10.0; - if (info->callback) info->callback(DC_SAMPLE_TEMPERATURE, sample, info->userdata); + if (info->callback) info->callback(DC_SAMPLE_TEMPERATURE, &sample, info->userdata); } static void sample_ndl(struct sample_data *info, short ndl) @@ -512,7 +512,7 @@ static void sample_ndl(struct sample_data *info, short ndl) sample.deco.type = DC_DECO_NDL; sample.deco.time = ndl; sample.deco.tts = 0; - if (info->callback) info->callback(DC_SAMPLE_DECO, sample, info->userdata); + if (info->callback) info->callback(DC_SAMPLE_DECO, &sample, info->userdata); } static void sample_tts(struct sample_data *info, unsigned short tts) @@ -536,7 +536,7 @@ static void sample_heading(struct sample_data *info, unsigned short heading) sample.event.type = SAMPLE_EVENT_HEADING; sample.event.value = heading; - if (info->callback) info->callback(DC_SAMPLE_EVENT, sample, info->userdata); + if (info->callback) info->callback(DC_SAMPLE_EVENT, &sample, info->userdata); } static void sample_abspressure(struct sample_data *info, unsigned short pressure) @@ -551,7 +551,7 @@ static void sample_gastime(struct sample_data *info, short gastime) return; sample.rbt = gastime / 60; - if (info->callback) info->callback (DC_SAMPLE_RBT, sample, info->userdata); + if (info->callback) info->callback (DC_SAMPLE_RBT, &sample, info->userdata); } /* @@ -579,7 +579,7 @@ static void sample_pressure(struct sample_data *info, unsigned short pressure) sample.pressure.tank = info->gasnr-1; sample.pressure.value = pressure / 100.0; - if (info->callback) info->callback(DC_SAMPLE_PRESSURE, sample, info->userdata); + if (info->callback) info->callback(DC_SAMPLE_PRESSURE, &sample, info->userdata); } static void sample_bookmark_event(struct sample_data *info, unsigned short idx) @@ -589,7 +589,7 @@ static void sample_bookmark_event(struct sample_data *info, unsigned short idx) sample.event.type = SAMPLE_EVENT_BOOKMARK; sample.event.value = idx; - if (info->callback) info->callback(DC_SAMPLE_EVENT, sample, info->userdata); + if (info->callback) info->callback(DC_SAMPLE_EVENT, &sample, info->userdata); } static void sample_gas_switch_event(struct sample_data *info, unsigned short idx) @@ -601,7 +601,7 @@ static void sample_gas_switch_event(struct sample_data *info, unsigned short idx return; sample.gasmix = idx - 1; - if (info->callback) info->callback(DC_SAMPLE_GASMIX, sample, info->userdata); + if (info->callback) info->callback(DC_SAMPLE_GASMIX, &sample, info->userdata); } /* @@ -701,7 +701,7 @@ static void sample_event_state_value(const struct type_desc *desc, struct sample return; sample.event.flags = value ? SAMPLE_FLAGS_BEGIN : SAMPLE_FLAGS_END; - if (info->callback) info->callback(DC_SAMPLE_EVENT, sample, info->userdata); + if (info->callback) info->callback(DC_SAMPLE_EVENT, &sample, info->userdata); } static void sample_event_notify_type(const struct type_desc *desc, struct sample_data *info, unsigned char type) @@ -743,7 +743,7 @@ static void sample_event_notify_value(const struct type_desc *desc, struct sampl return; sample.event.flags = value ? SAMPLE_FLAGS_BEGIN : SAMPLE_FLAGS_END; - if (info->callback) info->callback(DC_SAMPLE_EVENT, sample, info->userdata); + if (info->callback) info->callback(DC_SAMPLE_EVENT, &sample, info->userdata); } @@ -783,7 +783,7 @@ static void sample_event_warning_value(const struct type_desc *desc, struct samp return; sample.event.flags = value ? SAMPLE_FLAGS_BEGIN : SAMPLE_FLAGS_END; - if (info->callback) info->callback(DC_SAMPLE_EVENT, sample, info->userdata); + if (info->callback) info->callback(DC_SAMPLE_EVENT, &sample, info->userdata); } static void sample_event_alarm_type(const struct type_desc *desc, struct sample_data *info, unsigned char type) @@ -816,7 +816,7 @@ static void sample_event_alarm_value(const struct type_desc *desc, struct sample return; sample.event.flags = value ? SAMPLE_FLAGS_BEGIN : SAMPLE_FLAGS_END; - if (info->callback) info->callback(DC_SAMPLE_EVENT, sample, info->userdata); + if (info->callback) info->callback(DC_SAMPLE_EVENT, &sample, info->userdata); } // enum:0=Low,1=High,2=Custom @@ -842,7 +842,7 @@ static void sample_setpoint_type(const struct type_desc *desc, struct sample_dat return; } - if (info->callback) info->callback(DC_SAMPLE_SETPOINT, sample, info->userdata); + if (info->callback) info->callback(DC_SAMPLE_SETPOINT, &sample, info->userdata); free(type); } @@ -1001,7 +1001,7 @@ static int traverse_samples(unsigned short type, const struct type_desc *desc, c sample.deco.time = 0; sample.deco.depth = info->ceiling; sample.deco.tts = info->tts; - if (info->callback) info->callback(DC_SAMPLE_DECO, sample, info->userdata); + if (info->callback) info->callback(DC_SAMPLE_DECO, &sample, info->userdata); } // Warn if there are left-over bytes for something we did use part of diff --git a/src/suunto_solution_parser.c b/src/suunto_solution_parser.c index 1ec82f3..f8320aa 100644 --- a/src/suunto_solution_parser.c +++ b/src/suunto_solution_parser.c @@ -185,7 +185,7 @@ suunto_solution_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callbac // Time (minutes). time += 3 * 60; sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Depth (ft). depth += (signed char) value; @@ -198,12 +198,12 @@ suunto_solution_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callbac depth += (signed char) data[offset++]; } sample.depth = depth * FEET; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); // Gas change. if (gasmix != gasmix_previous) { sample.gasmix = gasmix; - if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback (DC_SAMPLE_GASMIX, &sample, userdata); gasmix_previous = gasmix; } } else { @@ -228,7 +228,7 @@ suunto_solution_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callbac } if (sample.event.type != SAMPLE_EVENT_NONE) { - if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + if (callback) callback (DC_SAMPLE_EVENT, &sample, userdata); } } } diff --git a/src/suunto_vyper_parser.c b/src/suunto_vyper_parser.c index 8fab31b..fe9bfe2 100644 --- a/src/suunto_vyper_parser.c +++ b/src/suunto_vyper_parser.c @@ -332,16 +332,16 @@ suunto_vyper_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t // Time sample.time = 0; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Depth (0 ft) sample.depth = 0; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); // Initial gas mix if (!gauge) { sample.gasmix = 0; - if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback (DC_SAMPLE_GASMIX, &sample, userdata); } unsigned int depth = 0; @@ -356,7 +356,7 @@ suunto_vyper_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t // Time (seconds). time += interval; sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); complete = 0; } @@ -366,7 +366,7 @@ suunto_vyper_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t // Depth (ft). sample.depth = depth * FEET; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); complete = 1; } else { @@ -410,7 +410,7 @@ suunto_vyper_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t } sample.gasmix = idx; - if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback (DC_SAMPLE_GASMIX, &sample, userdata); sample.event.type = SAMPLE_EVENT_NONE; break; default: // Unknown @@ -419,7 +419,7 @@ suunto_vyper_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t } if (sample.event.type != SAMPLE_EVENT_NONE) { - if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + if (callback) callback (DC_SAMPLE_EVENT, &sample, userdata); } } } @@ -428,12 +428,12 @@ suunto_vyper_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t if (complete) { time += interval; sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); } // Depth (0 ft) sample.depth = 0; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); return DC_STATUS_SUCCESS; } diff --git a/src/tecdiving_divecomputereu_parser.c b/src/tecdiving_divecomputereu_parser.c index ccfbb05..b0f1552 100644 --- a/src/tecdiving_divecomputereu_parser.c +++ b/src/tecdiving_divecomputereu_parser.c @@ -160,28 +160,28 @@ tecdiving_divecomputereu_parser_samples_foreach (dc_parser_t *abstract, dc_sampl // Time (seconds). time += interval; sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Depth (1/10 m). unsigned int depth = array_uint16_be (data + offset + 2); sample.depth = depth / 10.0; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); // Temperature (Celsius). signed int temperature = (signed char) data[offset]; sample.temperature = temperature; - if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata); + if (callback) callback (DC_SAMPLE_TEMPERATURE, &sample, userdata); // ppO2 unsigned int ppo2 = data[offset + 1]; sample.ppo2.sensor = DC_SENSOR_NONE; sample.ppo2.value = ppo2 / 10.0; - if (callback) callback (DC_SAMPLE_PPO2, sample, userdata); + if (callback) callback (DC_SAMPLE_PPO2, &sample, userdata); // Setpoint unsigned int setpoint = data[offset + 4]; sample.setpoint = setpoint / 10.0; - if (callback) callback (DC_SAMPLE_SETPOINT, sample, userdata); + if (callback) callback (DC_SAMPLE_SETPOINT, &sample, userdata); offset += 8; } diff --git a/src/uwatec_memomouse_parser.c b/src/uwatec_memomouse_parser.c index 0e55b4d..7b28396 100644 --- a/src/uwatec_memomouse_parser.c +++ b/src/uwatec_memomouse_parser.c @@ -253,16 +253,16 @@ uwatec_memomouse_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba // Time (seconds) sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); // Depth (meters) sample.depth = depth * 10.0 / 64.0; - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); // Gas change. if (gasmix != gasmix_previous) { sample.gasmix = gasmix; - if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback (DC_SAMPLE_GASMIX, &sample, userdata); gasmix_previous = gasmix; } @@ -275,7 +275,7 @@ uwatec_memomouse_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba sample.deco.time = 0; sample.deco.depth = 0.0; sample.deco.tts = 0; - if (callback) callback (DC_SAMPLE_DECO, sample, userdata); + if (callback) callback (DC_SAMPLE_DECO, &sample, userdata); // Warnings for (unsigned int i = 0; i < 6; ++i) { @@ -304,7 +304,7 @@ uwatec_memomouse_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba break; } if (sample.event.type != SAMPLE_EVENT_NONE) { - if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + if (callback) callback (DC_SAMPLE_EVENT, &sample, userdata); } } } @@ -328,7 +328,7 @@ uwatec_memomouse_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba offset++; } - if (callback) callback (DC_SAMPLE_VENDOR, sample, userdata); + if (callback) callback (DC_SAMPLE_VENDOR, &sample, userdata); } time += 20; diff --git a/src/uwatec_smart_parser.c b/src/uwatec_smart_parser.c index 017c10b..d98801b 100644 --- a/src/uwatec_smart_parser.c +++ b/src/uwatec_smart_parser.c @@ -1165,7 +1165,7 @@ uwatec_smart_parse (uwatec_smart_parser_t *parser, dc_sample_callback_t callback while (complete) { sample.time = time * 1000; - if (callback) callback (DC_SAMPLE_TIME, sample, userdata); + if (callback) callback (DC_SAMPLE_TIME, &sample, userdata); if (parser->ngasmixes && gasmix != gasmix_previous) { idx = uwatec_smart_find_gasmix (parser, gasmix); @@ -1174,13 +1174,13 @@ uwatec_smart_parse (uwatec_smart_parser_t *parser, dc_sample_callback_t callback return DC_STATUS_DATAFORMAT; } sample.gasmix = idx; - if (callback) callback (DC_SAMPLE_GASMIX, sample, userdata); + if (callback) callback (DC_SAMPLE_GASMIX, &sample, userdata); gasmix_previous = gasmix; } if (have_temperature) { sample.temperature = temperature / 2.5; - if (callback) callback (DC_SAMPLE_TEMPERATURE, sample, userdata); + if (callback) callback (DC_SAMPLE_TEMPERATURE, &sample, userdata); } if (bookmark) { @@ -1188,12 +1188,12 @@ uwatec_smart_parse (uwatec_smart_parser_t *parser, dc_sample_callback_t callback sample.event.time = 0; sample.event.flags = 0; sample.event.value = 0; - if (callback) callback (DC_SAMPLE_EVENT, sample, userdata); + if (callback) callback (DC_SAMPLE_EVENT, &sample, userdata); } if (have_rbt || have_pressure) { sample.rbt = rbt; - if (callback) callback (DC_SAMPLE_RBT, sample, userdata); + if (callback) callback (DC_SAMPLE_RBT, &sample, userdata); } if (have_pressure) { @@ -1201,24 +1201,24 @@ uwatec_smart_parse (uwatec_smart_parser_t *parser, dc_sample_callback_t callback if (idx < parser->ntanks) { sample.pressure.tank = idx; sample.pressure.value = pressure / 4.0; - if (callback) callback (DC_SAMPLE_PRESSURE, sample, userdata); + if (callback) callback (DC_SAMPLE_PRESSURE, &sample, userdata); } } if (have_heartrate) { sample.heartbeat = heartrate; - if (callback) callback (DC_SAMPLE_HEARTBEAT, sample, userdata); + if (callback) callback (DC_SAMPLE_HEARTBEAT, &sample, userdata); } if (have_bearing) { sample.bearing = bearing; - if (callback) callback (DC_SAMPLE_BEARING, sample, userdata); + if (callback) callback (DC_SAMPLE_BEARING, &sample, userdata); have_bearing = 0; } if (have_depth) { sample.depth = (signed int)(depth - depth_calibration) * (2.0 * BAR / 1000.0) / (density * 10.0); - if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata); + if (callback) callback (DC_SAMPLE_DEPTH, &sample, userdata); } time += interval; From 0a4f37770f18d326a6039b928c83697b615975fd Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Fri, 23 Apr 2021 21:19:41 +0200 Subject: [PATCH 08/51] Remove the backend specific calibration functions The backend specific calibration function are deprecated. Applications should use the new replacement functions introduced in commit 6ab140461a3a85fba3803283070427f3be413c79. --- include/libdivecomputer/atomics_cobalt.h | 3 --- include/libdivecomputer/reefnet_sensus.h | 3 --- include/libdivecomputer/reefnet_sensuspro.h | 3 --- include/libdivecomputer/reefnet_sensusultra.h | 3 --- src/atomics_cobalt_parser.c | 14 -------------- src/libdivecomputer.symbols | 5 ----- src/reefnet_sensus_parser.c | 15 --------------- src/reefnet_sensuspro_parser.c | 15 --------------- src/reefnet_sensusultra_parser.c | 15 --------------- 9 files changed, 76 deletions(-) diff --git a/include/libdivecomputer/atomics_cobalt.h b/include/libdivecomputer/atomics_cobalt.h index 5afb1c1..c2dfd66 100644 --- a/include/libdivecomputer/atomics_cobalt.h +++ b/include/libdivecomputer/atomics_cobalt.h @@ -36,9 +36,6 @@ atomics_cobalt_device_version (dc_device_t *device, unsigned char data[], unsign dc_status_t atomics_cobalt_device_set_simulation (dc_device_t *device, unsigned int simulation); -dc_status_t -atomics_cobalt_parser_set_calibration (dc_parser_t *parser, double atmospheric, double hydrostatic); - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/include/libdivecomputer/reefnet_sensus.h b/include/libdivecomputer/reefnet_sensus.h index 583d9af..b0fe271 100644 --- a/include/libdivecomputer/reefnet_sensus.h +++ b/include/libdivecomputer/reefnet_sensus.h @@ -35,9 +35,6 @@ extern "C" { dc_status_t reefnet_sensus_device_get_handshake (dc_device_t *device, unsigned char data[], unsigned int size); -dc_status_t -reefnet_sensus_parser_set_calibration (dc_parser_t *parser, double atmospheric, double hydrostatic); - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/include/libdivecomputer/reefnet_sensuspro.h b/include/libdivecomputer/reefnet_sensuspro.h index a92966f..b879a50 100644 --- a/include/libdivecomputer/reefnet_sensuspro.h +++ b/include/libdivecomputer/reefnet_sensuspro.h @@ -38,9 +38,6 @@ reefnet_sensuspro_device_get_handshake (dc_device_t *device, unsigned char data[ dc_status_t reefnet_sensuspro_device_write_interval (dc_device_t *device, unsigned char interval); -dc_status_t -reefnet_sensuspro_parser_set_calibration (dc_parser_t *parser, double atmospheric, double hydrostatic); - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/include/libdivecomputer/reefnet_sensusultra.h b/include/libdivecomputer/reefnet_sensusultra.h index c5a8944..fc1b4f7 100644 --- a/include/libdivecomputer/reefnet_sensusultra.h +++ b/include/libdivecomputer/reefnet_sensusultra.h @@ -56,9 +56,6 @@ reefnet_sensusultra_device_write_parameter (dc_device_t *device, reefnet_sensusu dc_status_t reefnet_sensusultra_device_sense (dc_device_t *device, unsigned char data[], unsigned int size); -dc_status_t -reefnet_sensusultra_parser_set_calibration (dc_parser_t *parser, double atmospheric, double hydrostatic); - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/atomics_cobalt_parser.c b/src/atomics_cobalt_parser.c index da5264a..f559b7b 100644 --- a/src/atomics_cobalt_parser.c +++ b/src/atomics_cobalt_parser.c @@ -94,20 +94,6 @@ atomics_cobalt_parser_set_data (dc_parser_t *abstract, const unsigned char *data } -dc_status_t -atomics_cobalt_parser_set_calibration (dc_parser_t *abstract, double atmospheric, double hydrostatic) -{ - atomics_cobalt_parser_t *parser = (atomics_cobalt_parser_t*) abstract; - - if (!ISINSTANCE (abstract)) - return DC_STATUS_INVALIDARGS; - - parser->hydrostatic = hydrostatic; - - return DC_STATUS_SUCCESS; -} - - static dc_status_t atomics_cobalt_parser_set_density (dc_parser_t *abstract, double density) { diff --git a/src/libdivecomputer.symbols b/src/libdivecomputer.symbols index a9d2d39..e47a5e6 100644 --- a/src/libdivecomputer.symbols +++ b/src/libdivecomputer.symbols @@ -97,11 +97,6 @@ dc_parser_get_field dc_parser_samples_foreach dc_parser_destroy -reefnet_sensus_parser_set_calibration -reefnet_sensuspro_parser_set_calibration -reefnet_sensusultra_parser_set_calibration -atomics_cobalt_parser_set_calibration - dc_device_open dc_device_close dc_device_dump diff --git a/src/reefnet_sensus_parser.c b/src/reefnet_sensus_parser.c index eb860ef..b63a11a 100644 --- a/src/reefnet_sensus_parser.c +++ b/src/reefnet_sensus_parser.c @@ -114,21 +114,6 @@ reefnet_sensus_parser_set_data (dc_parser_t *abstract, const unsigned char *data } -dc_status_t -reefnet_sensus_parser_set_calibration (dc_parser_t *abstract, double atmospheric, double hydrostatic) -{ - reefnet_sensus_parser_t *parser = (reefnet_sensus_parser_t*) abstract; - - if (!ISINSTANCE (abstract)) - return DC_STATUS_INVALIDARGS; - - parser->atmospheric = atmospheric; - parser->hydrostatic = hydrostatic; - - return DC_STATUS_SUCCESS; -} - - static dc_status_t reefnet_sensus_parser_set_clock (dc_parser_t *abstract, unsigned int devtime, dc_ticks_t systime) { diff --git a/src/reefnet_sensuspro_parser.c b/src/reefnet_sensuspro_parser.c index 0100c28..fa4308c 100644 --- a/src/reefnet_sensuspro_parser.c +++ b/src/reefnet_sensuspro_parser.c @@ -113,21 +113,6 @@ reefnet_sensuspro_parser_set_data (dc_parser_t *abstract, const unsigned char *d } -dc_status_t -reefnet_sensuspro_parser_set_calibration (dc_parser_t *abstract, double atmospheric, double hydrostatic) -{ - reefnet_sensuspro_parser_t *parser = (reefnet_sensuspro_parser_t*) abstract; - - if (!ISINSTANCE (abstract)) - return DC_STATUS_INVALIDARGS; - - parser->atmospheric = atmospheric; - parser->hydrostatic = hydrostatic; - - return DC_STATUS_SUCCESS; -} - - static dc_status_t reefnet_sensuspro_parser_set_clock (dc_parser_t *abstract, unsigned int devtime, dc_ticks_t systime) { diff --git a/src/reefnet_sensusultra_parser.c b/src/reefnet_sensusultra_parser.c index 9e43873..63530c0 100644 --- a/src/reefnet_sensusultra_parser.c +++ b/src/reefnet_sensusultra_parser.c @@ -113,21 +113,6 @@ reefnet_sensusultra_parser_set_data (dc_parser_t *abstract, const unsigned char } -dc_status_t -reefnet_sensusultra_parser_set_calibration (dc_parser_t *abstract, double atmospheric, double hydrostatic) -{ - reefnet_sensusultra_parser_t *parser = (reefnet_sensusultra_parser_t*) abstract; - - if (!ISINSTANCE (abstract)) - return DC_STATUS_INVALIDARGS; - - parser->atmospheric = atmospheric; - parser->hydrostatic = hydrostatic; - - return DC_STATUS_SUCCESS; -} - - static dc_status_t reefnet_sensusultra_parser_set_clock (dc_parser_t *abstract, unsigned int devtime, dc_ticks_t systime) { From 679db0bae6b94cb51762ec93e1312d7ff97001ef Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Fri, 23 Apr 2021 21:27:12 +0200 Subject: [PATCH 09/51] Remove the clock parameters from the constructor Only a few dive computer backends (reefnet, aladin and memomouse) require the clock parameters for parsing the date/time. Therefore, those parameters are removed from the constructor function and applications should set the clock parameters with the dc_parser_set_clock() function instead. --- doc/man/dc_parser_new.3 | 2 -- examples/dctool_parse.c | 10 ++++++++- include/libdivecomputer/parser.h | 2 +- src/parser.c | 38 +++++++++++++++++++++++--------- src/reefnet_sensus.h | 2 +- src/reefnet_sensus_parser.c | 6 ++--- src/reefnet_sensuspro.h | 2 +- src/reefnet_sensuspro_parser.c | 6 ++--- src/reefnet_sensusultra.h | 2 +- src/reefnet_sensusultra_parser.c | 6 ++--- src/uwatec_memomouse.h | 2 +- src/uwatec_memomouse_parser.c | 6 ++--- 12 files changed, 53 insertions(+), 31 deletions(-) diff --git a/doc/man/dc_parser_new.3 b/doc/man/dc_parser_new.3 index 9f879cd..4bfe451 100644 --- a/doc/man/dc_parser_new.3 +++ b/doc/man/dc_parser_new.3 @@ -39,8 +39,6 @@ .Fa "dc_parser_t **parser" .Fa "dc_context_t *context" .Fa "dc_descriptor_t *descriptor" -.Fa "unsigned int devtime" -.Fa "dc_ticks_t systime" .Fc .Sh DESCRIPTION Creates a parser for a single dive extracted from the dive computer with diff --git a/examples/dctool_parse.c b/examples/dctool_parse.c index b898b5c..5908d62 100644 --- a/examples/dctool_parse.c +++ b/examples/dctool_parse.c @@ -54,12 +54,20 @@ parse (dc_buffer_t *buffer, dc_context_t *context, dc_descriptor_t *descriptor, // Create the parser. message ("Creating the parser.\n"); - rc = dc_parser_new2 (&parser, context, descriptor, devtime, systime); + rc = dc_parser_new2 (&parser, context, descriptor); if (rc != DC_STATUS_SUCCESS) { ERROR ("Error creating the parser."); goto cleanup; } + // Set the clock. + message ("Setting the clock.\n"); + rc = dc_parser_set_clock (parser, devtime, systime); + if (rc != DC_STATUS_SUCCESS && rc != DC_STATUS_UNSUPPORTED) { + ERROR ("Error setting the clock."); + goto cleanup; + } + // Register the data. message ("Registering the data.\n"); rc = dc_parser_set_data (parser, data, size); diff --git a/include/libdivecomputer/parser.h b/include/libdivecomputer/parser.h index fbc67c0..8662499 100644 --- a/include/libdivecomputer/parser.h +++ b/include/libdivecomputer/parser.h @@ -279,7 +279,7 @@ dc_status_t dc_parser_new (dc_parser_t **parser, dc_device_t *device); dc_status_t -dc_parser_new2 (dc_parser_t **parser, dc_context_t *context, dc_descriptor_t *descriptor, unsigned int devtime, dc_ticks_t systime); +dc_parser_new2 (dc_parser_t **parser, dc_context_t *context, dc_descriptor_t *descriptor); dc_family_t dc_parser_get_type (dc_parser_t *parser); diff --git a/src/parser.c b/src/parser.c index 8a74cb1..5138e54 100644 --- a/src/parser.c +++ b/src/parser.c @@ -72,7 +72,7 @@ #define REACTPROWHITE 0x4354 static dc_status_t -dc_parser_new_internal (dc_parser_t **out, dc_context_t *context, dc_family_t family, unsigned int model, unsigned int devtime, dc_ticks_t systime) +dc_parser_new_internal (dc_parser_t **out, dc_context_t *context, dc_family_t family, unsigned int model) { dc_status_t rc = DC_STATUS_SUCCESS; dc_parser_t *parser = NULL; @@ -102,19 +102,19 @@ dc_parser_new_internal (dc_parser_t **out, dc_context_t *context, dc_family_t fa break; case DC_FAMILY_UWATEC_ALADIN: case DC_FAMILY_UWATEC_MEMOMOUSE: - rc = uwatec_memomouse_parser_create (&parser, context, devtime, systime); + rc = uwatec_memomouse_parser_create (&parser, context); break; case DC_FAMILY_UWATEC_SMART: rc = uwatec_smart_parser_create (&parser, context, model); break; case DC_FAMILY_REEFNET_SENSUS: - rc = reefnet_sensus_parser_create (&parser, context, devtime, systime); + rc = reefnet_sensus_parser_create (&parser, context); break; case DC_FAMILY_REEFNET_SENSUSPRO: - rc = reefnet_sensuspro_parser_create (&parser, context, devtime, systime); + rc = reefnet_sensuspro_parser_create (&parser, context); break; case DC_FAMILY_REEFNET_SENSUSULTRA: - rc = reefnet_sensusultra_parser_create (&parser, context, devtime, systime); + rc = reefnet_sensusultra_parser_create (&parser, context); break; case DC_FAMILY_OCEANIC_VTPRO: rc = oceanic_vtpro_parser_create (&parser, context, model); @@ -215,20 +215,36 @@ dc_parser_new_internal (dc_parser_t **out, dc_context_t *context, dc_family_t fa dc_status_t dc_parser_new (dc_parser_t **out, dc_device_t *device) { + dc_status_t status = DC_STATUS_SUCCESS; + dc_parser_t *parser = NULL; + if (device == NULL) return DC_STATUS_INVALIDARGS; - return dc_parser_new_internal (out, device->context, - dc_device_get_type (device), device->devinfo.model, - device->clock.devtime, device->clock.systime); + status = dc_parser_new_internal (&parser, device->context, + dc_device_get_type (device), device->devinfo.model); + if (status != DC_STATUS_SUCCESS) + goto error_exit; + + status = dc_parser_set_clock (parser, device->clock.devtime, device->clock.systime); + if (status != DC_STATUS_SUCCESS && status != DC_STATUS_UNSUPPORTED) + goto error_free; + + *out = parser; + + return DC_STATUS_SUCCESS; + +error_free: + dc_parser_deallocate (parser); +error_exit: + return status; } dc_status_t -dc_parser_new2 (dc_parser_t **out, dc_context_t *context, dc_descriptor_t *descriptor, unsigned int devtime, dc_ticks_t systime) +dc_parser_new2 (dc_parser_t **out, dc_context_t *context, dc_descriptor_t *descriptor) { return dc_parser_new_internal (out, context, - dc_descriptor_get_type (descriptor), dc_descriptor_get_model (descriptor), - devtime, systime); + dc_descriptor_get_type (descriptor), dc_descriptor_get_model (descriptor)); } dc_parser_t * diff --git a/src/reefnet_sensus.h b/src/reefnet_sensus.h index a021b86..2ed5cbe 100644 --- a/src/reefnet_sensus.h +++ b/src/reefnet_sensus.h @@ -36,7 +36,7 @@ dc_status_t reefnet_sensus_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -reefnet_sensus_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int devtime, dc_ticks_t systime); +reefnet_sensus_parser_create (dc_parser_t **parser, dc_context_t *context); #ifdef __cplusplus } diff --git a/src/reefnet_sensus_parser.c b/src/reefnet_sensus_parser.c index b63a11a..9882778 100644 --- a/src/reefnet_sensus_parser.c +++ b/src/reefnet_sensus_parser.c @@ -71,7 +71,7 @@ static const dc_parser_vtable_t reefnet_sensus_parser_vtable = { dc_status_t -reefnet_sensus_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int devtime, dc_ticks_t systime) +reefnet_sensus_parser_create (dc_parser_t **out, dc_context_t *context) { reefnet_sensus_parser_t *parser = NULL; @@ -88,8 +88,8 @@ reefnet_sensus_parser_create (dc_parser_t **out, dc_context_t *context, unsigned // Set the default values. parser->atmospheric = DEF_ATMOSPHERIC; parser->hydrostatic = DEF_DENSITY_SALT * GRAVITY; - parser->devtime = devtime; - parser->systime = systime; + parser->devtime = 0; + parser->systime = 0; parser->cached = 0; parser->divetime = 0; parser->maxdepth = 0; diff --git a/src/reefnet_sensuspro.h b/src/reefnet_sensuspro.h index 9932515..fd21d99 100644 --- a/src/reefnet_sensuspro.h +++ b/src/reefnet_sensuspro.h @@ -36,7 +36,7 @@ dc_status_t reefnet_sensuspro_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -reefnet_sensuspro_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int devtime, dc_ticks_t systime); +reefnet_sensuspro_parser_create (dc_parser_t **parser, dc_context_t *context); #ifdef __cplusplus } diff --git a/src/reefnet_sensuspro_parser.c b/src/reefnet_sensuspro_parser.c index fa4308c..6dc0613 100644 --- a/src/reefnet_sensuspro_parser.c +++ b/src/reefnet_sensuspro_parser.c @@ -70,7 +70,7 @@ static const dc_parser_vtable_t reefnet_sensuspro_parser_vtable = { dc_status_t -reefnet_sensuspro_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int devtime, dc_ticks_t systime) +reefnet_sensuspro_parser_create (dc_parser_t **out, dc_context_t *context) { reefnet_sensuspro_parser_t *parser = NULL; @@ -87,8 +87,8 @@ reefnet_sensuspro_parser_create (dc_parser_t **out, dc_context_t *context, unsig // Set the default values. parser->atmospheric = DEF_ATMOSPHERIC; parser->hydrostatic = DEF_DENSITY_SALT * GRAVITY; - parser->devtime = devtime; - parser->systime = systime; + parser->devtime = 0; + parser->systime = 0; parser->cached = 0; parser->divetime = 0; parser->maxdepth = 0; diff --git a/src/reefnet_sensusultra.h b/src/reefnet_sensusultra.h index af73c8a..054745a 100644 --- a/src/reefnet_sensusultra.h +++ b/src/reefnet_sensusultra.h @@ -36,7 +36,7 @@ dc_status_t reefnet_sensusultra_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -reefnet_sensusultra_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int devtime, dc_ticks_t systime); +reefnet_sensusultra_parser_create (dc_parser_t **parser, dc_context_t *context); #ifdef __cplusplus } diff --git a/src/reefnet_sensusultra_parser.c b/src/reefnet_sensusultra_parser.c index 63530c0..5564019 100644 --- a/src/reefnet_sensusultra_parser.c +++ b/src/reefnet_sensusultra_parser.c @@ -70,7 +70,7 @@ static const dc_parser_vtable_t reefnet_sensusultra_parser_vtable = { dc_status_t -reefnet_sensusultra_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int devtime, dc_ticks_t systime) +reefnet_sensusultra_parser_create (dc_parser_t **out, dc_context_t *context) { reefnet_sensusultra_parser_t *parser = NULL; @@ -87,8 +87,8 @@ reefnet_sensusultra_parser_create (dc_parser_t **out, dc_context_t *context, uns // Set the default values. parser->atmospheric = DEF_ATMOSPHERIC; parser->hydrostatic = DEF_DENSITY_SALT * GRAVITY; - parser->devtime = devtime; - parser->systime = systime; + parser->devtime = 0; + parser->systime = 0; parser->cached = 0; parser->divetime = 0; parser->maxdepth = 0; diff --git a/src/uwatec_memomouse.h b/src/uwatec_memomouse.h index 49ecf9e..34ca2d3 100644 --- a/src/uwatec_memomouse.h +++ b/src/uwatec_memomouse.h @@ -35,7 +35,7 @@ dc_status_t uwatec_memomouse_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -uwatec_memomouse_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int devtime, dc_ticks_t systime); +uwatec_memomouse_parser_create (dc_parser_t **parser, dc_context_t *context); #ifdef __cplusplus } diff --git a/src/uwatec_memomouse_parser.c b/src/uwatec_memomouse_parser.c index 7b28396..1019c6a 100644 --- a/src/uwatec_memomouse_parser.c +++ b/src/uwatec_memomouse_parser.c @@ -59,7 +59,7 @@ static const dc_parser_vtable_t uwatec_memomouse_parser_vtable = { dc_status_t -uwatec_memomouse_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int devtime, dc_ticks_t systime) +uwatec_memomouse_parser_create (dc_parser_t **out, dc_context_t *context) { uwatec_memomouse_parser_t *parser = NULL; @@ -74,8 +74,8 @@ uwatec_memomouse_parser_create (dc_parser_t **out, dc_context_t *context, unsign } // Set the default values. - parser->devtime = devtime; - parser->systime = systime; + parser->devtime = 0; + parser->systime = 0; *out = (dc_parser_t*) parser; From 63f5a4d652f9dcb96fbec6f5bf74ecc6b8b388ba Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Fri, 23 Apr 2021 22:02:25 +0200 Subject: [PATCH 10/51] Remove the dc_parser_set_data function The dc_parser_set_data() function allows to re-use a parser object for multiple dives. The advantages of this feature are actually very limited in practice. The reduction in memory consumption is almost negligible, because the amount of internal state in the parser is typically very small. But the implementation requires some additional complexity because each backend needs code to reset its internal state. Therefore, the function is removed and the data and size needs to be passed directly to the dc_parser_new() and dc_parser_new2() functions instead. Because keeping a reference to the data has also caused issues in the past, especially for applications implemented in a garbage collected language, the data will now also get copied internally. --- doc/man/Makefile.am | 1 - doc/man/dc_device_foreach.3 | 4 +- doc/man/dc_parser_get_datetime.3 | 4 +- doc/man/dc_parser_get_field.3 | 4 +- doc/man/dc_parser_new.3 | 4 - doc/man/dc_parser_samples_foreach.3 | 4 +- doc/man/dc_parser_set_data.3 | 65 ------------- doc/man/libdivecomputer.3 | 4 +- examples/dctool_download.c | 10 +- examples/dctool_parse.c | 10 +- include/libdivecomputer/parser.h | 7 +- src/atomics_cobalt.h | 2 +- src/atomics_cobalt_parser.c | 13 +-- src/citizen_aqualand.h | 2 +- src/citizen_aqualand_parser.c | 13 +-- src/cochran_commander.h | 2 +- src/cochran_commander_parser.c | 13 +-- src/cressi_edy.h | 2 +- src/cressi_edy_parser.c | 13 +-- src/cressi_goa.h | 2 +- src/cressi_goa_parser.c | 12 +-- src/cressi_leonardo.h | 2 +- src/cressi_leonardo_parser.c | 13 +-- src/deepblu_cosmiq.h | 2 +- src/deepblu_cosmiq_parser.c | 12 +-- src/deepsix_excursion.h | 2 +- src/deepsix_excursion_parser.c | 23 +---- src/diverite_nitekq.h | 2 +- src/diverite_nitekq_parser.c | 13 +-- src/divesoft_freedom.h | 2 +- src/divesoft_freedom_parser.c | 50 +--------- src/divesystem_idive.h | 2 +- src/divesystem_idive_parser.c | 35 +------ src/hw_ostc.h | 2 +- src/hw_ostc3.h | 2 +- src/hw_ostc_parser.c | 41 ++------ src/libdivecomputer.symbols | 1 - src/liquivision_lynx.h | 2 +- src/liquivision_lynx_parser.c | 29 +----- src/mares_darwin.h | 2 +- src/mares_darwin_parser.c | 13 +-- src/mares_iconhd.h | 2 +- src/mares_iconhd_parser.c | 41 +------- src/mares_nemo.h | 2 +- src/mares_nemo_parser.c | 83 ++++++---------- src/mclean_extreme.h | 2 +- src/mclean_extreme_parser.c | 21 +---- src/oceanic_atom2.h | 2 +- src/oceanic_atom2_parser.c | 28 +----- src/oceanic_veo250.h | 2 +- src/oceanic_veo250_parser.c | 20 +--- src/oceanic_vtpro.h | 2 +- src/oceanic_vtpro_parser.c | 20 +--- src/oceans_s1.h | 2 +- src/oceans_s1_parser.c | 23 +---- src/parser-private.h | 6 +- src/parser.c | 130 +++++++++++++------------- src/reefnet_sensus.h | 2 +- src/reefnet_sensus_parser.c | 20 +--- src/reefnet_sensuspro.h | 2 +- src/reefnet_sensuspro_parser.c | 20 +--- src/reefnet_sensusultra.h | 2 +- src/reefnet_sensusultra_parser.c | 20 +--- src/seac_screen.h | 2 +- src/seac_screen_parser.c | 23 +---- src/shearwater_petrel.h | 2 +- src/shearwater_predator.h | 2 +- src/shearwater_predator_parser.c | 63 ++----------- src/sporasub_sp2.h | 2 +- src/sporasub_sp2_parser.c | 13 +-- src/suunto_d9.h | 2 +- src/suunto_d9_parser.c | 28 +----- src/suunto_eon.h | 2 +- src/suunto_eon_parser.c | 22 +---- src/suunto_eonsteel.h | 2 +- src/suunto_eonsteel_parser.c | 20 +--- src/suunto_solution.h | 2 +- src/suunto_solution_parser.c | 20 +--- src/suunto_vyper.h | 2 +- src/suunto_vyper_parser.c | 25 +---- src/tecdiving_divecomputereu.h | 2 +- src/tecdiving_divecomputereu_parser.c | 13 +-- src/uwatec_memomouse.h | 2 +- src/uwatec_memomouse_parser.c | 13 +-- src/uwatec_smart.h | 2 +- src/uwatec_smart_parser.c | 31 +----- 86 files changed, 229 insertions(+), 959 deletions(-) delete mode 100644 doc/man/dc_parser_set_data.3 diff --git a/doc/man/Makefile.am b/doc/man/Makefile.am index 63f9e85..4ea44de 100644 --- a/doc/man/Makefile.am +++ b/doc/man/Makefile.am @@ -32,7 +32,6 @@ MANPAGES = \ dc_parser_get_field.3 \ dc_parser_new.3 \ dc_parser_samples_foreach.3 \ - dc_parser_set_data.3 \ dc_bluetooth_open.3 \ dc_bluetooth_iterator_new.3 \ dc_bluetooth_device_get_address.3 \ diff --git a/doc/man/dc_device_foreach.3 b/doc/man/dc_device_foreach.3 index a349a72..86782f8 100644 --- a/doc/man/dc_device_foreach.3 +++ b/doc/man/dc_device_foreach.3 @@ -53,7 +53,7 @@ with Each dive invokes .Fa callback with the dive data, which should be parsed with -.Xr dc_parser_set_data 3 , +.Xr dc_parser_new 3 , and the binary fingerprint of the dive. The fingerprint can be used to record the newest dive and stop processing (on subsequent invocations) when the same dive fingerprint is @@ -72,7 +72,7 @@ If returns zero, this will not be reflected in the return value (usually .Dv DC_STATUS_SUCCESS ) . .Sh SEE ALSO -.Xr dc_parser_set_data 3 +.Xr dc_parser_new 3 .Sh AUTHORS The .Lb libdivecomputer diff --git a/doc/man/dc_parser_get_datetime.3 b/doc/man/dc_parser_get_datetime.3 index ba1f365..0b7b707 100644 --- a/doc/man/dc_parser_get_datetime.3 +++ b/doc/man/dc_parser_get_datetime.3 @@ -37,7 +37,7 @@ Extract the date and time of a dive, .Fa parser , previously initialised with -.Xr dc_parser_set_data 3 . +.Xr dc_parser_new 3 . This returns the broken-down time-stamp of the dive in the local time of the dive. .Pp @@ -57,7 +57,7 @@ messages on further failure. .Sh SEE ALSO .Xr dc_datetime_gmtime 3 , .Xr dc_datetime_localtime 3 , -.Xr dc_parser_set_data 3 +.Xr dc_parser_new 3 .Sh AUTHORS The .Lb libdivecomputer diff --git a/doc/man/dc_parser_get_field.3 b/doc/man/dc_parser_get_field.3 index a4c33f2..0f6455d 100644 --- a/doc/man/dc_parser_get_field.3 +++ b/doc/man/dc_parser_get_field.3 @@ -39,7 +39,7 @@ Extract a field from a dive, .Fa parser , previously initialised with -.Xr dc_parser_set_data 3 . +.Xr dc_parser_new 3 . The .Fa value field type depends upon the @@ -187,7 +187,7 @@ if the field was retrieved, if the field is not supported by the device, or other error messages on further failure. .Sh SEE ALSO -.Xr dc_parser_set_data 3 +.Xr dc_parser_new 3 .Sh AUTHORS The .Lb libdivecomputer diff --git a/doc/man/dc_parser_new.3 b/doc/man/dc_parser_new.3 index 4bfe451..e5340f0 100644 --- a/doc/man/dc_parser_new.3 +++ b/doc/man/dc_parser_new.3 @@ -53,10 +53,6 @@ parameter; and .Nm dc_parser_new2 , which is given device values (model, etc.) directly. .Pp -After filling in the -.Fa parser -parameter, one usually sets parser data with -.Xr dc_parser_set_data 3 . The pointer must later be freed with .Xr dc_parser_destroy 3 . .Sh RETURN VALUES diff --git a/doc/man/dc_parser_samples_foreach.3 b/doc/man/dc_parser_samples_foreach.3 index d741a43..69a637f 100644 --- a/doc/man/dc_parser_samples_foreach.3 +++ b/doc/man/dc_parser_samples_foreach.3 @@ -42,7 +42,7 @@ .Fc .Sh DESCRIPTION Extract the samples taken during a dive as previously initialised with -.Xr dc_parser_set_data 3 . +.Xr dc_parser_new 3 . Each sample is passed to .Fa callback with the @@ -184,7 +184,7 @@ Returns .Dv DC_STATUS_OK on success and another code on failure. .Sh SEE ALSO -.Xr dc_parser_set_data 3 +.Xr dc_parser_new 3 .Sh AUTHORS The .Lb libdivecomputer diff --git a/doc/man/dc_parser_set_data.3 b/doc/man/dc_parser_set_data.3 deleted file mode 100644 index 39af43b..0000000 --- a/doc/man/dc_parser_set_data.3 +++ /dev/null @@ -1,65 +0,0 @@ -.\" -.\" libdivecomputer -.\" -.\" Copyright (C) 2017 Kristaps Dzonsons -.\" -.\" This library is free software; you can redistribute it and/or -.\" modify it under the terms of the GNU Lesser General Public -.\" License as published by the Free Software Foundation; either -.\" version 2.1 of the License, or (at your option) any later version. -.\" -.\" This library is distributed in the hope that it will be useful, -.\" but WITHOUT ANY WARRANTY; without even the implied warranty of -.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -.\" Lesser General Public License for more details. -.\" -.\" You should have received a copy of the GNU Lesser General Public -.\" License along with this library; if not, write to the Free Software -.\" Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, -.\" MA 02110-1301 USA -.\" -.Dd January 5, 2017 -.Dt DC_PARSER_SET_DATA 3 -.Os -.Sh NAME -.Nm dc_parser_set_data -.Nd assigns parse data to a dive parser -.Sh LIBRARY -.Lb libdivecomputer -.Sh SYNOPSIS -.In libdivecomputer/parser.h -.Ft dc_status_t -.Fo dc_parser_set_data -.Fa "dc_parser_t *parser" -.Fa "const unsigned char *data" -.Fa "unsigned int size" -.Fc -.Sh DESCRIPTION -Assigns the binary sequence -.Fa data -of length -.Fa size -bytes to -.Fa parser , -which was created with -.Xr dc_parser_new 3 . -How the data is parsed depends upon the values provided to -.Xr dc_parser_new 3 . -The data usually comes from the callback assigned to -.Xr dc_device_foreach 3 . -.Sh RETURN VALUES -Returns -.Dv DC_STATUS_OK -on success and another code on failure. -.Sh SEE ALSO -.Xr dc_device_foreach 3 , -.Xr dc_parser_new 3 -.Sh AUTHORS -The -.Lb libdivecomputer -library was written by -.An Jef Driesen , -.Mt jef@libdivecomputer.org . -The manpages were written by -.An Kristaps Dzonsons , -.Mt kristaps@bsd.lv . diff --git a/doc/man/libdivecomputer.3 b/doc/man/libdivecomputer.3 index 4e1f601..cbe22eb 100644 --- a/doc/man/libdivecomputer.3 +++ b/doc/man/libdivecomputer.3 @@ -82,9 +82,7 @@ Iterate over all dives with .Xr dc_device_foreach 3 . .It For each iterated dive, create a new parser with -.Xr dc_parser_new 3 -and set the parsed data with -.Xr dc_parser_set_data 3 . +.Xr dc_parser_new 3 . .It Get attributes of the parsed dive with .Xr dc_parser_get_field 3 . diff --git a/examples/dctool_download.c b/examples/dctool_download.c index 04aedcf..29742e0 100644 --- a/examples/dctool_download.c +++ b/examples/dctool_download.c @@ -80,20 +80,12 @@ dive_cb (const unsigned char *data, unsigned int size, const unsigned char *fing // Create the parser. message ("Creating the parser.\n"); - rc = dc_parser_new (&parser, divedata->device); + rc = dc_parser_new (&parser, divedata->device, data, size); if (rc != DC_STATUS_SUCCESS) { ERROR ("Error creating the parser."); goto cleanup; } - // Register the data. - message ("Registering the data.\n"); - rc = dc_parser_set_data (parser, data, size); - if (rc != DC_STATUS_SUCCESS) { - ERROR ("Error registering the data."); - goto cleanup; - } - // Parse the dive data. message ("Parsing the dive data.\n"); rc = dctool_output_write (divedata->output, parser, data, size, fingerprint, fsize); diff --git a/examples/dctool_parse.c b/examples/dctool_parse.c index 5908d62..4ecf30e 100644 --- a/examples/dctool_parse.c +++ b/examples/dctool_parse.c @@ -54,7 +54,7 @@ parse (dc_buffer_t *buffer, dc_context_t *context, dc_descriptor_t *descriptor, // Create the parser. message ("Creating the parser.\n"); - rc = dc_parser_new2 (&parser, context, descriptor); + rc = dc_parser_new2 (&parser, context, descriptor, data, size); if (rc != DC_STATUS_SUCCESS) { ERROR ("Error creating the parser."); goto cleanup; @@ -68,14 +68,6 @@ parse (dc_buffer_t *buffer, dc_context_t *context, dc_descriptor_t *descriptor, goto cleanup; } - // Register the data. - message ("Registering the data.\n"); - rc = dc_parser_set_data (parser, data, size); - if (rc != DC_STATUS_SUCCESS) { - ERROR ("Error registering the data."); - goto cleanup; - } - // Parse the dive data. message ("Parsing the dive data.\n"); rc = dctool_output_write (output, parser, data, size, NULL, 0); diff --git a/include/libdivecomputer/parser.h b/include/libdivecomputer/parser.h index 8662499..ee69e42 100644 --- a/include/libdivecomputer/parser.h +++ b/include/libdivecomputer/parser.h @@ -276,10 +276,10 @@ typedef struct dc_parser_t dc_parser_t; typedef void (*dc_sample_callback_t) (dc_sample_type_t type, const dc_sample_value_t *value, void *userdata); dc_status_t -dc_parser_new (dc_parser_t **parser, dc_device_t *device); +dc_parser_new (dc_parser_t **parser, dc_device_t *device, const unsigned char data[], size_t size); dc_status_t -dc_parser_new2 (dc_parser_t **parser, dc_context_t *context, dc_descriptor_t *descriptor); +dc_parser_new2 (dc_parser_t **parser, dc_context_t *context, dc_descriptor_t *descriptor, const unsigned char data[], size_t size); dc_family_t dc_parser_get_type (dc_parser_t *parser); @@ -293,9 +293,6 @@ dc_parser_set_atmospheric (dc_parser_t *parser, double atmospheric); dc_status_t dc_parser_set_density (dc_parser_t *parser, double density); -dc_status_t -dc_parser_set_data (dc_parser_t *parser, const unsigned char *data, unsigned int size); - dc_status_t dc_parser_get_datetime (dc_parser_t *parser, dc_datetime_t *datetime); diff --git a/src/atomics_cobalt.h b/src/atomics_cobalt.h index 09f0226..8c70641 100644 --- a/src/atomics_cobalt.h +++ b/src/atomics_cobalt.h @@ -36,7 +36,7 @@ dc_status_t atomics_cobalt_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -atomics_cobalt_parser_create (dc_parser_t **parser, dc_context_t *context); +atomics_cobalt_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size); #ifdef __cplusplus } diff --git a/src/atomics_cobalt_parser.c b/src/atomics_cobalt_parser.c index f559b7b..7dc407a 100644 --- a/src/atomics_cobalt_parser.c +++ b/src/atomics_cobalt_parser.c @@ -43,7 +43,6 @@ struct atomics_cobalt_parser_t { double hydrostatic; }; -static dc_status_t atomics_cobalt_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t atomics_cobalt_parser_set_density (dc_parser_t *abstract, double density); static dc_status_t atomics_cobalt_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime); static dc_status_t atomics_cobalt_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); @@ -52,7 +51,6 @@ static dc_status_t atomics_cobalt_parser_samples_foreach (dc_parser_t *abstract, static const dc_parser_vtable_t atomics_cobalt_parser_vtable = { sizeof(atomics_cobalt_parser_t), DC_FAMILY_ATOMICS_COBALT, - atomics_cobalt_parser_set_data, /* set_data */ NULL, /* set_clock */ NULL, /* set_atmospheric */ atomics_cobalt_parser_set_density, /* set_density */ @@ -64,7 +62,7 @@ static const dc_parser_vtable_t atomics_cobalt_parser_vtable = { dc_status_t -atomics_cobalt_parser_create (dc_parser_t **out, dc_context_t *context) +atomics_cobalt_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size) { atomics_cobalt_parser_t *parser = NULL; @@ -72,7 +70,7 @@ atomics_cobalt_parser_create (dc_parser_t **out, dc_context_t *context) return DC_STATUS_INVALIDARGS; // Allocate memory. - parser = (atomics_cobalt_parser_t *) dc_parser_allocate (context, &atomics_cobalt_parser_vtable); + parser = (atomics_cobalt_parser_t *) dc_parser_allocate (context, &atomics_cobalt_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -87,13 +85,6 @@ atomics_cobalt_parser_create (dc_parser_t **out, dc_context_t *context) } -static dc_status_t -atomics_cobalt_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - return DC_STATUS_SUCCESS; -} - - static dc_status_t atomics_cobalt_parser_set_density (dc_parser_t *abstract, double density) { diff --git a/src/citizen_aqualand.h b/src/citizen_aqualand.h index ac47cb6..bc23311 100644 --- a/src/citizen_aqualand.h +++ b/src/citizen_aqualand.h @@ -35,7 +35,7 @@ dc_status_t citizen_aqualand_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -citizen_aqualand_parser_create (dc_parser_t **parser, dc_context_t *context); +citizen_aqualand_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size); #ifdef __cplusplus } diff --git a/src/citizen_aqualand_parser.c b/src/citizen_aqualand_parser.c index 32816b4..ff1ea9e 100644 --- a/src/citizen_aqualand_parser.c +++ b/src/citizen_aqualand_parser.c @@ -36,7 +36,6 @@ typedef struct citizen_aqualand_parser_t { dc_parser_t base; } citizen_aqualand_parser_t; -static dc_status_t citizen_aqualand_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t citizen_aqualand_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime); static dc_status_t citizen_aqualand_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); static dc_status_t citizen_aqualand_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata); @@ -44,7 +43,6 @@ static dc_status_t citizen_aqualand_parser_samples_foreach (dc_parser_t *abstrac static const dc_parser_vtable_t citizen_aqualand_parser_vtable = { sizeof(citizen_aqualand_parser_t), DC_FAMILY_CITIZEN_AQUALAND, - citizen_aqualand_parser_set_data, /* set_data */ NULL, /* set_clock */ NULL, /* set_atmospheric */ NULL, /* set_density */ @@ -56,7 +54,7 @@ static const dc_parser_vtable_t citizen_aqualand_parser_vtable = { dc_status_t -citizen_aqualand_parser_create (dc_parser_t **out, dc_context_t *context) +citizen_aqualand_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size) { citizen_aqualand_parser_t *parser = NULL; @@ -64,7 +62,7 @@ citizen_aqualand_parser_create (dc_parser_t **out, dc_context_t *context) return DC_STATUS_INVALIDARGS; // Allocate memory. - parser = (citizen_aqualand_parser_t *) dc_parser_allocate (context, &citizen_aqualand_parser_vtable); + parser = (citizen_aqualand_parser_t *) dc_parser_allocate (context, &citizen_aqualand_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -76,13 +74,6 @@ citizen_aqualand_parser_create (dc_parser_t **out, dc_context_t *context) } -static dc_status_t -citizen_aqualand_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - return DC_STATUS_SUCCESS; -} - - static dc_status_t citizen_aqualand_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime) { diff --git a/src/cochran_commander.h b/src/cochran_commander.h index 84a521e..1a36676 100644 --- a/src/cochran_commander.h +++ b/src/cochran_commander.h @@ -35,7 +35,7 @@ dc_status_t cochran_commander_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -cochran_commander_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); +cochran_commander_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model); #ifdef __cplusplus } diff --git a/src/cochran_commander_parser.c b/src/cochran_commander_parser.c index 5d2d9b7..aeaf25c 100644 --- a/src/cochran_commander_parser.c +++ b/src/cochran_commander_parser.c @@ -99,7 +99,6 @@ typedef struct cochran_commander_parser_t { unsigned int nevents; } cochran_commander_parser_t ; -static dc_status_t cochran_commander_parser_set_data (dc_parser_t *parser, const unsigned char *data, unsigned int size); static dc_status_t cochran_commander_parser_get_datetime (dc_parser_t *parser, dc_datetime_t *datetime); static dc_status_t cochran_commander_parser_get_field (dc_parser_t *parser, dc_field_type_t type, unsigned int flags, void *value); static dc_status_t cochran_commander_parser_samples_foreach (dc_parser_t *parser, dc_sample_callback_t callback, void *userdata); @@ -107,7 +106,6 @@ static dc_status_t cochran_commander_parser_samples_foreach (dc_parser_t *parser static const dc_parser_vtable_t cochran_commander_parser_vtable = { sizeof(cochran_commander_parser_t), DC_FAMILY_COCHRAN_COMMANDER, - cochran_commander_parser_set_data, /* set_data */ NULL, /* set_clock */ NULL, /* set_atmospheric */ NULL, /* set_density */ @@ -352,7 +350,7 @@ cochran_commander_backparse(cochran_commander_parser_t *parser, const unsigned c dc_status_t -cochran_commander_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model) +cochran_commander_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model) { cochran_commander_parser_t *parser = NULL; dc_status_t status = DC_STATUS_SUCCESS; @@ -361,7 +359,7 @@ cochran_commander_parser_create (dc_parser_t **out, dc_context_t *context, unsig return DC_STATUS_INVALIDARGS; // Allocate memory. - parser = (cochran_commander_parser_t *) dc_parser_allocate (context, &cochran_commander_parser_vtable); + parser = (cochran_commander_parser_t *) dc_parser_allocate (context, &cochran_commander_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -407,13 +405,6 @@ error_free: } -static dc_status_t -cochran_commander_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - return DC_STATUS_SUCCESS; -} - - static dc_status_t cochran_commander_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime) { diff --git a/src/cressi_edy.h b/src/cressi_edy.h index 7aa5a34..238e5df 100644 --- a/src/cressi_edy.h +++ b/src/cressi_edy.h @@ -35,7 +35,7 @@ dc_status_t cressi_edy_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -cressi_edy_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); +cressi_edy_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model); #ifdef __cplusplus } diff --git a/src/cressi_edy_parser.c b/src/cressi_edy_parser.c index 182fd11..6d46f63 100644 --- a/src/cressi_edy_parser.c +++ b/src/cressi_edy_parser.c @@ -38,7 +38,6 @@ struct cressi_edy_parser_t { unsigned int model; }; -static dc_status_t cressi_edy_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t cressi_edy_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime); static dc_status_t cressi_edy_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); static dc_status_t cressi_edy_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata); @@ -46,7 +45,6 @@ static dc_status_t cressi_edy_parser_samples_foreach (dc_parser_t *abstract, dc_ static const dc_parser_vtable_t cressi_edy_parser_vtable = { sizeof(cressi_edy_parser_t), DC_FAMILY_CRESSI_EDY, - cressi_edy_parser_set_data, /* set_data */ NULL, /* set_clock */ NULL, /* set_atmospheric */ NULL, /* set_density */ @@ -73,7 +71,7 @@ cressi_edy_parser_count_gasmixes (const unsigned char *data) } dc_status_t -cressi_edy_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model) +cressi_edy_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model) { cressi_edy_parser_t *parser = NULL; @@ -81,7 +79,7 @@ cressi_edy_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int return DC_STATUS_INVALIDARGS; // Allocate memory. - parser = (cressi_edy_parser_t *) dc_parser_allocate (context, &cressi_edy_parser_vtable); + parser = (cressi_edy_parser_t *) dc_parser_allocate (context, &cressi_edy_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -96,13 +94,6 @@ cressi_edy_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int } -static dc_status_t -cressi_edy_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - return DC_STATUS_SUCCESS; -} - - static dc_status_t cressi_edy_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime) { diff --git a/src/cressi_goa.h b/src/cressi_goa.h index 0a92512..63283a0 100644 --- a/src/cressi_goa.h +++ b/src/cressi_goa.h @@ -35,7 +35,7 @@ dc_status_t cressi_goa_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -cressi_goa_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); +cressi_goa_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model); #ifdef __cplusplus } diff --git a/src/cressi_goa_parser.c b/src/cressi_goa_parser.c index d5a9a34..2898662 100644 --- a/src/cressi_goa_parser.c +++ b/src/cressi_goa_parser.c @@ -62,7 +62,6 @@ typedef struct cressi_goa_layout_t { unsigned int temperature; } cressi_goa_layout_t; -static dc_status_t cressi_goa_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t cressi_goa_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime); static dc_status_t cressi_goa_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); static dc_status_t cressi_goa_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata); @@ -70,7 +69,6 @@ static dc_status_t cressi_goa_parser_samples_foreach (dc_parser_t *abstract, dc_ static const dc_parser_vtable_t cressi_goa_parser_vtable = { sizeof(cressi_goa_parser_t), DC_FAMILY_CRESSI_GOA, - cressi_goa_parser_set_data, /* set_data */ NULL, /* set_clock */ NULL, /* set_atmospheric */ NULL, /* set_density */ @@ -128,7 +126,7 @@ static const cressi_goa_layout_t layouts[] = { }; dc_status_t -cressi_goa_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model) +cressi_goa_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model) { cressi_goa_parser_t *parser = NULL; @@ -136,7 +134,7 @@ cressi_goa_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int return DC_STATUS_INVALIDARGS; // Allocate memory. - parser = (cressi_goa_parser_t *) dc_parser_allocate (context, &cressi_goa_parser_vtable); + parser = (cressi_goa_parser_t *) dc_parser_allocate (context, &cressi_goa_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -149,12 +147,6 @@ cressi_goa_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int return DC_STATUS_SUCCESS; } -static dc_status_t -cressi_goa_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - return DC_STATUS_SUCCESS; -} - static dc_status_t cressi_goa_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime) { diff --git a/src/cressi_leonardo.h b/src/cressi_leonardo.h index 982bb01..2efc4d8 100644 --- a/src/cressi_leonardo.h +++ b/src/cressi_leonardo.h @@ -35,7 +35,7 @@ dc_status_t cressi_leonardo_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -cressi_leonardo_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); +cressi_leonardo_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model); #ifdef __cplusplus } diff --git a/src/cressi_leonardo_parser.c b/src/cressi_leonardo_parser.c index 3a6824e..df382c5 100644 --- a/src/cressi_leonardo_parser.c +++ b/src/cressi_leonardo_parser.c @@ -39,7 +39,6 @@ struct cressi_leonardo_parser_t { unsigned int model; }; -static dc_status_t cressi_leonardo_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t cressi_leonardo_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime); static dc_status_t cressi_leonardo_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); static dc_status_t cressi_leonardo_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata); @@ -47,7 +46,6 @@ static dc_status_t cressi_leonardo_parser_samples_foreach (dc_parser_t *abstract static const dc_parser_vtable_t cressi_leonardo_parser_vtable = { sizeof(cressi_leonardo_parser_t), DC_FAMILY_CRESSI_LEONARDO, - cressi_leonardo_parser_set_data, /* set_data */ NULL, /* set_clock */ NULL, /* set_atmospheric */ NULL, /* set_density */ @@ -59,7 +57,7 @@ static const dc_parser_vtable_t cressi_leonardo_parser_vtable = { dc_status_t -cressi_leonardo_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model) +cressi_leonardo_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model) { cressi_leonardo_parser_t *parser = NULL; @@ -67,7 +65,7 @@ cressi_leonardo_parser_create (dc_parser_t **out, dc_context_t *context, unsigne return DC_STATUS_INVALIDARGS; // Allocate memory. - parser = (cressi_leonardo_parser_t *) dc_parser_allocate (context, &cressi_leonardo_parser_vtable); + parser = (cressi_leonardo_parser_t *) dc_parser_allocate (context, &cressi_leonardo_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -81,13 +79,6 @@ cressi_leonardo_parser_create (dc_parser_t **out, dc_context_t *context, unsigne } -static dc_status_t -cressi_leonardo_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - return DC_STATUS_SUCCESS; -} - - static dc_status_t cressi_leonardo_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime) { diff --git a/src/deepblu_cosmiq.h b/src/deepblu_cosmiq.h index 3587812..0d0c29a 100644 --- a/src/deepblu_cosmiq.h +++ b/src/deepblu_cosmiq.h @@ -36,7 +36,7 @@ dc_status_t deepblu_cosmiq_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -deepblu_cosmiq_parser_create (dc_parser_t **parser, dc_context_t *context); +deepblu_cosmiq_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size); #ifdef __cplusplus } diff --git a/src/deepblu_cosmiq_parser.c b/src/deepblu_cosmiq_parser.c index d744698..95b5ae7 100644 --- a/src/deepblu_cosmiq_parser.c +++ b/src/deepblu_cosmiq_parser.c @@ -41,7 +41,6 @@ typedef struct deepblu_cosmiq_parser_t { double hydrostatic; } deepblu_cosmiq_parser_t; -static dc_status_t deepblu_cosmiq_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t deepblu_cosmiq_parser_set_density (dc_parser_t *abstract, double density); static dc_status_t deepblu_cosmiq_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime); static dc_status_t deepblu_cosmiq_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); @@ -50,7 +49,6 @@ static dc_status_t deepblu_cosmiq_parser_samples_foreach (dc_parser_t *abstract, static const dc_parser_vtable_t deepblu_cosmiq_parser_vtable = { sizeof(deepblu_cosmiq_parser_t), DC_FAMILY_DEEPBLU_COSMIQ, - deepblu_cosmiq_parser_set_data, /* set_data */ NULL, /* set_clock */ NULL, /* set_atmospheric */ deepblu_cosmiq_parser_set_density, /* set_density */ @@ -61,7 +59,7 @@ static const dc_parser_vtable_t deepblu_cosmiq_parser_vtable = { }; dc_status_t -deepblu_cosmiq_parser_create (dc_parser_t **out, dc_context_t *context) +deepblu_cosmiq_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size) { deepblu_cosmiq_parser_t *parser = NULL; @@ -69,7 +67,7 @@ deepblu_cosmiq_parser_create (dc_parser_t **out, dc_context_t *context) return DC_STATUS_INVALIDARGS; // Allocate memory. - parser = (deepblu_cosmiq_parser_t *) dc_parser_allocate (context, &deepblu_cosmiq_parser_vtable); + parser = (deepblu_cosmiq_parser_t *) dc_parser_allocate (context, &deepblu_cosmiq_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -83,12 +81,6 @@ deepblu_cosmiq_parser_create (dc_parser_t **out, dc_context_t *context) return DC_STATUS_SUCCESS; } -static dc_status_t -deepblu_cosmiq_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - return DC_STATUS_SUCCESS; -} - static dc_status_t deepblu_cosmiq_parser_set_density (dc_parser_t *abstract, double density) { diff --git a/src/deepsix_excursion.h b/src/deepsix_excursion.h index 42ecffc..839511f 100644 --- a/src/deepsix_excursion.h +++ b/src/deepsix_excursion.h @@ -35,7 +35,7 @@ dc_status_t deepsix_excursion_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -deepsix_excursion_parser_create (dc_parser_t **parser, dc_context_t *context); +deepsix_excursion_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size); #ifdef __cplusplus } diff --git a/src/deepsix_excursion_parser.c b/src/deepsix_excursion_parser.c index 919fb6a..52d06af 100644 --- a/src/deepsix_excursion_parser.c +++ b/src/deepsix_excursion_parser.c @@ -112,7 +112,6 @@ typedef struct deepsix_excursion_parser_t { deepsix_excursion_gasmix_t gasmix[MAX_GASMIXES]; } deepsix_excursion_parser_t; -static dc_status_t deepsix_excursion_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t deepsix_excursion_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime); static dc_status_t deepsix_excursion_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); static dc_status_t deepsix_excursion_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata); @@ -122,7 +121,6 @@ static dc_status_t deepsix_excursion_parser_samples_foreach_v1 (dc_parser_t *abs static const dc_parser_vtable_t deepsix_parser_vtable = { sizeof(deepsix_excursion_parser_t), DC_FAMILY_DEEPSIX_EXCURSION, - deepsix_excursion_parser_set_data, /* set_data */ NULL, /* set_clock */ NULL, /* set_atmospheric */ NULL, /* set_density */ @@ -185,7 +183,7 @@ deepsix_excursion_find_gasmix(deepsix_excursion_parser_t *parser, unsigned int o } dc_status_t -deepsix_excursion_parser_create (dc_parser_t **out, dc_context_t *context) +deepsix_excursion_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size) { deepsix_excursion_parser_t *parser = NULL; @@ -193,7 +191,7 @@ deepsix_excursion_parser_create (dc_parser_t **out, dc_context_t *context) return DC_STATUS_INVALIDARGS; // Allocate memory. - parser = (deepsix_excursion_parser_t *) dc_parser_allocate (context, &deepsix_parser_vtable); + parser = (deepsix_excursion_parser_t *) dc_parser_allocate (context, &deepsix_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -213,23 +211,6 @@ deepsix_excursion_parser_create (dc_parser_t **out, dc_context_t *context) return DC_STATUS_SUCCESS; } -static dc_status_t -deepsix_excursion_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - deepsix_excursion_parser_t *parser = (deepsix_excursion_parser_t *) abstract; - - // Reset the cache. - parser->cached = 0; - parser->ngasmixes = 0; - for (unsigned int i = 0; i < MAX_GASMIXES; ++i) { - parser->gasmix[i].id = 0; - parser->gasmix[i].oxygen = 0; - parser->gasmix[i].helium = 0; - } - - return DC_STATUS_SUCCESS; -} - static dc_status_t deepsix_excursion_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime) { diff --git a/src/diverite_nitekq.h b/src/diverite_nitekq.h index e016cab..9bbf728 100644 --- a/src/diverite_nitekq.h +++ b/src/diverite_nitekq.h @@ -35,7 +35,7 @@ dc_status_t diverite_nitekq_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -diverite_nitekq_parser_create (dc_parser_t **parser, dc_context_t *context); +diverite_nitekq_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size); #ifdef __cplusplus } diff --git a/src/diverite_nitekq_parser.c b/src/diverite_nitekq_parser.c index bb13446..d9f6dcc 100644 --- a/src/diverite_nitekq_parser.c +++ b/src/diverite_nitekq_parser.c @@ -49,7 +49,6 @@ struct diverite_nitekq_parser_t { double maxdepth; }; -static dc_status_t diverite_nitekq_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t diverite_nitekq_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime); static dc_status_t diverite_nitekq_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); static dc_status_t diverite_nitekq_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata); @@ -57,7 +56,6 @@ static dc_status_t diverite_nitekq_parser_samples_foreach (dc_parser_t *abstract static const dc_parser_vtable_t diverite_nitekq_parser_vtable = { sizeof(diverite_nitekq_parser_t), DC_FAMILY_DIVERITE_NITEKQ, - diverite_nitekq_parser_set_data, /* set_data */ NULL, /* set_clock */ NULL, /* set_atmospheric */ NULL, /* set_density */ @@ -69,7 +67,7 @@ static const dc_parser_vtable_t diverite_nitekq_parser_vtable = { dc_status_t -diverite_nitekq_parser_create (dc_parser_t **out, dc_context_t *context) +diverite_nitekq_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size) { diverite_nitekq_parser_t *parser = NULL; @@ -77,7 +75,7 @@ diverite_nitekq_parser_create (dc_parser_t **out, dc_context_t *context) return DC_STATUS_INVALIDARGS; // Allocate memory. - parser = (diverite_nitekq_parser_t *) dc_parser_allocate (context, &diverite_nitekq_parser_vtable); + parser = (diverite_nitekq_parser_t *) dc_parser_allocate (context, &diverite_nitekq_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -101,13 +99,6 @@ diverite_nitekq_parser_create (dc_parser_t **out, dc_context_t *context) } -static dc_status_t -diverite_nitekq_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - return DC_STATUS_SUCCESS; -} - - static dc_status_t diverite_nitekq_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime) { diff --git a/src/divesoft_freedom.h b/src/divesoft_freedom.h index db04edb..bca87b7 100644 --- a/src/divesoft_freedom.h +++ b/src/divesoft_freedom.h @@ -35,7 +35,7 @@ dc_status_t divesoft_freedom_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -divesoft_freedom_parser_create (dc_parser_t **parser, dc_context_t *context); +divesoft_freedom_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size); #ifdef __cplusplus } diff --git a/src/divesoft_freedom_parser.c b/src/divesoft_freedom_parser.c index 51a229a..49c0f0f 100644 --- a/src/divesoft_freedom_parser.c +++ b/src/divesoft_freedom_parser.c @@ -254,7 +254,6 @@ typedef struct divesoft_freedom_parser_t { unsigned int calibrated; } divesoft_freedom_parser_t; -static dc_status_t divesoft_freedom_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t divesoft_freedom_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime); static dc_status_t divesoft_freedom_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); static dc_status_t divesoft_freedom_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata); @@ -262,7 +261,6 @@ static dc_status_t divesoft_freedom_parser_samples_foreach (dc_parser_t *abstrac static const dc_parser_vtable_t divesoft_freedom_parser_vtable = { sizeof(divesoft_freedom_parser_t), DC_FAMILY_DIVESOFT_FREEDOM, - divesoft_freedom_parser_set_data, /* set_data */ NULL, /* set_clock */ NULL, /* set_atmospheric */ NULL, /* set_density */ @@ -643,7 +641,7 @@ divesoft_freedom_cache (divesoft_freedom_parser_t *parser) } dc_status_t -divesoft_freedom_parser_create (dc_parser_t **out, dc_context_t *context) +divesoft_freedom_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size) { divesoft_freedom_parser_t *parser = NULL; @@ -651,7 +649,7 @@ divesoft_freedom_parser_create (dc_parser_t **out, dc_context_t *context) return DC_STATUS_INVALIDARGS; // Allocate memory. - parser = (divesoft_freedom_parser_t *) dc_parser_allocate (context, &divesoft_freedom_parser_vtable); + parser = (divesoft_freedom_parser_t *) dc_parser_allocate (context, &divesoft_freedom_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -698,50 +696,6 @@ divesoft_freedom_parser_create (dc_parser_t **out, dc_context_t *context) return DC_STATUS_SUCCESS; } -static dc_status_t -divesoft_freedom_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - divesoft_freedom_parser_t *parser = (divesoft_freedom_parser_t *) abstract; - - // Reset the cache. - parser->cached = 0; - parser->version = 0; - parser->headersize = 0; - parser->divetime = 0; - parser->divemode = 0; - parser->temperature_min = 0; - parser->maxdepth = 0; - parser->atmospheric = 0; - parser->avgdepth = 0; - parser->ngasmixes = 0; - for (unsigned int i = 0; i < NGASMIXES; ++i) { - parser->gasmix[i].oxygen = 0; - parser->gasmix[i].helium = 0; - parser->gasmix[i].type = 0; - parser->gasmix[i].id = 0; - } - parser->diluent = UNDEFINED; - parser->ntanks = 0; - for (unsigned int i = 0; i < NTANKS; ++i) { - parser->tank[i].volume = 0; - parser->tank[i].workpressure = 0; - parser->tank[i].beginpressure = 0; - parser->tank[i].endpressure = 0; - parser->tank[i].transmitter = 0; - parser->tank[i].active = 0; - } - parser->vpm = 0; - parser->gf_lo = 0; - parser->gf_hi = 0; - parser->seawater = 0; - for (unsigned int i = 0; i < NSENSORS; ++i) { - parser->calibration[i] = 0; - } - parser->calibrated = 0; - - return DC_STATUS_SUCCESS; -} - static dc_status_t divesoft_freedom_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime) { diff --git a/src/divesystem_idive.h b/src/divesystem_idive.h index 1da80a0..91e1ea9 100644 --- a/src/divesystem_idive.h +++ b/src/divesystem_idive.h @@ -36,7 +36,7 @@ dc_status_t divesystem_idive_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream, unsigned int model); dc_status_t -divesystem_idive_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); +divesystem_idive_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model); #ifdef __cplusplus } diff --git a/src/divesystem_idive_parser.c b/src/divesystem_idive_parser.c index 28326a6..c7f5fb4 100644 --- a/src/divesystem_idive_parser.c +++ b/src/divesystem_idive_parser.c @@ -89,7 +89,6 @@ struct divesystem_idive_parser_t { unsigned int gf_high; }; -static dc_status_t divesystem_idive_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t divesystem_idive_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime); static dc_status_t divesystem_idive_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); static dc_status_t divesystem_idive_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata); @@ -97,7 +96,6 @@ static dc_status_t divesystem_idive_parser_samples_foreach (dc_parser_t *abstrac static const dc_parser_vtable_t divesystem_idive_parser_vtable = { sizeof(divesystem_idive_parser_t), DC_FAMILY_DIVESYSTEM_IDIVE, - divesystem_idive_parser_set_data, /* set_data */ NULL, /* set_clock */ NULL, /* set_atmospheric */ NULL, /* set_density */ @@ -109,7 +107,7 @@ static const dc_parser_vtable_t divesystem_idive_parser_vtable = { dc_status_t -divesystem_idive_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model) +divesystem_idive_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model) { divesystem_idive_parser_t *parser = NULL; @@ -117,7 +115,7 @@ divesystem_idive_parser_create (dc_parser_t **out, dc_context_t *context, unsign return DC_STATUS_INVALIDARGS; // Allocate memory. - parser = (divesystem_idive_parser_t *) dc_parser_allocate (context, &divesystem_idive_parser_vtable); + parser = (divesystem_idive_parser_t *) dc_parser_allocate (context, &divesystem_idive_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -156,35 +154,6 @@ divesystem_idive_parser_create (dc_parser_t **out, dc_context_t *context, unsign } -static dc_status_t -divesystem_idive_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - divesystem_idive_parser_t *parser = (divesystem_idive_parser_t *) abstract; - - // Reset the cache. - parser->cached = 0; - parser->divemode = INVALID; - parser->divetime = 0; - parser->maxdepth = 0; - parser->ngasmixes = 0; - parser->ntanks = 0; - for (unsigned int i = 0; i < NGASMIXES; ++i) { - parser->gasmix[i].oxygen = 0; - parser->gasmix[i].helium = 0; - } - for (unsigned int i = 0; i < NTANKS; ++i) { - parser->tank[i].id = 0; - parser->tank[i].beginpressure = 0; - parser->tank[i].endpressure = 0; - } - parser->algorithm = INVALID; - parser->gf_low = INVALID; - parser->gf_high = INVALID; - - return DC_STATUS_SUCCESS; -} - - static dc_status_t divesystem_idive_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime) { diff --git a/src/hw_ostc.h b/src/hw_ostc.h index fc45182..55abda9 100644 --- a/src/hw_ostc.h +++ b/src/hw_ostc.h @@ -36,7 +36,7 @@ dc_status_t hw_ostc_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -hw_ostc_parser_create (dc_parser_t **parser, dc_context_t *context); +hw_ostc_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size); #ifdef __cplusplus } diff --git a/src/hw_ostc3.h b/src/hw_ostc3.h index 92cf277..0fddc96 100644 --- a/src/hw_ostc3.h +++ b/src/hw_ostc3.h @@ -36,7 +36,7 @@ dc_status_t hw_ostc3_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -hw_ostc3_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model); +hw_ostc3_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model); #ifdef __cplusplus } diff --git a/src/hw_ostc_parser.c b/src/hw_ostc_parser.c index ca19458..288d28a 100644 --- a/src/hw_ostc_parser.c +++ b/src/hw_ostc_parser.c @@ -132,7 +132,6 @@ typedef struct hw_ostc_parser_t { hw_ostc_gasmix_t gasmix[NGASMIXES]; } hw_ostc_parser_t; -static dc_status_t hw_ostc_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t hw_ostc_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime); static dc_status_t hw_ostc_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); static dc_status_t hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata); @@ -140,7 +139,6 @@ static dc_status_t hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sam static const dc_parser_vtable_t hw_ostc_parser_vtable = { sizeof(hw_ostc_parser_t), DC_FAMILY_HW_OSTC, - hw_ostc_parser_set_data, /* set_data */ NULL, /* set_clock */ NULL, /* set_atmospheric */ NULL, /* set_density */ @@ -367,7 +365,7 @@ hw_ostc_parser_cache (hw_ostc_parser_t *parser) } static dc_status_t -hw_ostc_parser_create_internal (dc_parser_t **out, dc_context_t *context, unsigned int hwos, unsigned int model) +hw_ostc_parser_create_internal (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size, unsigned int hwos, unsigned int model) { hw_ostc_parser_t *parser = NULL; @@ -375,7 +373,7 @@ hw_ostc_parser_create_internal (dc_parser_t **out, dc_context_t *context, unsign return DC_STATUS_INVALIDARGS; // Allocate memory. - parser = (hw_ostc_parser_t *) dc_parser_allocate (context, &hw_ostc_parser_vtable); + parser = (hw_ostc_parser_t *) dc_parser_allocate (context, &hw_ostc_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -408,44 +406,17 @@ hw_ostc_parser_create_internal (dc_parser_t **out, dc_context_t *context, unsign dc_status_t -hw_ostc_parser_create (dc_parser_t **out, dc_context_t *context) +hw_ostc_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size) { - return hw_ostc_parser_create_internal (out, context, 0, 0); + return hw_ostc_parser_create_internal (out, context, data, size, 0, 0); } dc_status_t -hw_ostc3_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model) +hw_ostc3_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model) { - return hw_ostc_parser_create_internal (out, context, 1, model); + return hw_ostc_parser_create_internal (out, context, data, size, 1, model); } -static dc_status_t -hw_ostc_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - hw_ostc_parser_t *parser = (hw_ostc_parser_t *) abstract; - - // Reset the cache. - parser->cached = 0; - parser->version = 0; - parser->header = 0; - parser->layout = NULL; - parser->ngasmixes = 0; - parser->nfixed = 0; - parser->initial = 0; - parser->initial_setpoint = 0; - parser->initial_cns = 0; - for (unsigned int i = 0; i < NGASMIXES; ++i) { - parser->gasmix[i].oxygen = 0; - parser->gasmix[i].helium = 0; - parser->gasmix[i].type = 0; - parser->gasmix[i].enabled = 0; - parser->gasmix[i].diluent = 0; - } - - return DC_STATUS_SUCCESS; -} - - static dc_status_t hw_ostc_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime) { diff --git a/src/libdivecomputer.symbols b/src/libdivecomputer.symbols index e47a5e6..477f1ec 100644 --- a/src/libdivecomputer.symbols +++ b/src/libdivecomputer.symbols @@ -91,7 +91,6 @@ dc_parser_set_clock dc_parser_set_atmospheric dc_parser_set_density dc_parser_get_type -dc_parser_set_data dc_parser_get_datetime dc_parser_get_field dc_parser_samples_foreach diff --git a/src/liquivision_lynx.h b/src/liquivision_lynx.h index 52e7294..dd278b4 100644 --- a/src/liquivision_lynx.h +++ b/src/liquivision_lynx.h @@ -35,7 +35,7 @@ dc_status_t liquivision_lynx_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -liquivision_lynx_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); +liquivision_lynx_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model); #ifdef __cplusplus } diff --git a/src/liquivision_lynx_parser.c b/src/liquivision_lynx_parser.c index 0ddb69e..c336b6a 100644 --- a/src/liquivision_lynx_parser.c +++ b/src/liquivision_lynx_parser.c @@ -117,7 +117,6 @@ struct liquivision_lynx_parser_t { liquivision_lynx_tank_t tank[NTANKS]; }; -static dc_status_t liquivision_lynx_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t liquivision_lynx_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime); static dc_status_t liquivision_lynx_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); static dc_status_t liquivision_lynx_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata); @@ -125,7 +124,6 @@ static dc_status_t liquivision_lynx_parser_samples_foreach (dc_parser_t *abstrac static const dc_parser_vtable_t liquivision_lynx_parser_vtable = { sizeof(liquivision_lynx_parser_t), DC_FAMILY_LIQUIVISION_LYNX, - liquivision_lynx_parser_set_data, /* set_data */ NULL, /* set_clock */ NULL, /* set_atmospheric */ NULL, /* set_density */ @@ -137,7 +135,7 @@ static const dc_parser_vtable_t liquivision_lynx_parser_vtable = { dc_status_t -liquivision_lynx_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model) +liquivision_lynx_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model) { liquivision_lynx_parser_t *parser = NULL; @@ -145,7 +143,7 @@ liquivision_lynx_parser_create (dc_parser_t **out, dc_context_t *context, unsign return DC_STATUS_INVALIDARGS; // Allocate memory. - parser = (liquivision_lynx_parser_t *) dc_parser_allocate (context, &liquivision_lynx_parser_vtable); + parser = (liquivision_lynx_parser_t *) dc_parser_allocate (context, &liquivision_lynx_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -173,29 +171,6 @@ liquivision_lynx_parser_create (dc_parser_t **out, dc_context_t *context, unsign } -static dc_status_t -liquivision_lynx_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - liquivision_lynx_parser_t *parser = (liquivision_lynx_parser_t *) abstract; - - // Reset the cache. - parser->cached = 0; - parser->ngasmixes = 0; - parser->ntanks = 0; - for (unsigned int i = 0; i < NGASMIXES; ++i) { - parser->gasmix[i].oxygen = 0; - parser->gasmix[i].helium = 0; - } - for (unsigned int i = 0; i < NTANKS; ++i) { - parser->tank[i].id = 0; - parser->tank[i].beginpressure = 0; - parser->tank[i].endpressure = 0; - } - - return DC_STATUS_SUCCESS; -} - - static dc_status_t liquivision_lynx_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime) { diff --git a/src/mares_darwin.h b/src/mares_darwin.h index a902014..35efbcb 100644 --- a/src/mares_darwin.h +++ b/src/mares_darwin.h @@ -35,7 +35,7 @@ dc_status_t mares_darwin_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream, unsigned int model); dc_status_t -mares_darwin_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); +mares_darwin_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model); #ifdef __cplusplus } diff --git a/src/mares_darwin_parser.c b/src/mares_darwin_parser.c index 699fbc7..bebd89c 100644 --- a/src/mares_darwin_parser.c +++ b/src/mares_darwin_parser.c @@ -47,7 +47,6 @@ struct mares_darwin_parser_t { unsigned int samplesize; }; -static dc_status_t mares_darwin_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t mares_darwin_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime); static dc_status_t mares_darwin_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); static dc_status_t mares_darwin_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata); @@ -55,7 +54,6 @@ static dc_status_t mares_darwin_parser_samples_foreach (dc_parser_t *abstract, d static const dc_parser_vtable_t mares_darwin_parser_vtable = { sizeof(mares_darwin_parser_t), DC_FAMILY_MARES_DARWIN, - mares_darwin_parser_set_data, /* set_data */ NULL, /* set_clock */ NULL, /* set_atmospheric */ NULL, /* set_density */ @@ -67,7 +65,7 @@ static const dc_parser_vtable_t mares_darwin_parser_vtable = { dc_status_t -mares_darwin_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model) +mares_darwin_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model) { mares_darwin_parser_t *parser = NULL; @@ -75,7 +73,7 @@ mares_darwin_parser_create (dc_parser_t **out, dc_context_t *context, unsigned i return DC_STATUS_INVALIDARGS; // Allocate memory. - parser = (mares_darwin_parser_t *) dc_parser_allocate (context, &mares_darwin_parser_vtable); + parser = (mares_darwin_parser_t *) dc_parser_allocate (context, &mares_darwin_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -97,13 +95,6 @@ mares_darwin_parser_create (dc_parser_t **out, dc_context_t *context, unsigned i } -static dc_status_t -mares_darwin_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - return DC_STATUS_SUCCESS; -} - - static dc_status_t mares_darwin_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime) { diff --git a/src/mares_iconhd.h b/src/mares_iconhd.h index 55a50d0..1b00c54 100644 --- a/src/mares_iconhd.h +++ b/src/mares_iconhd.h @@ -35,7 +35,7 @@ dc_status_t mares_iconhd_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -mares_iconhd_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); +mares_iconhd_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model); #ifdef __cplusplus } diff --git a/src/mares_iconhd_parser.c b/src/mares_iconhd_parser.c index 63a4021..73f32d9 100644 --- a/src/mares_iconhd_parser.c +++ b/src/mares_iconhd_parser.c @@ -264,7 +264,6 @@ static const mares_iconhd_layout_t horizon = { 0x54 + 8, /* tanks */ }; -static dc_status_t mares_iconhd_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t mares_iconhd_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime); static dc_status_t mares_iconhd_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); static dc_status_t mares_iconhd_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata); @@ -272,7 +271,6 @@ static dc_status_t mares_iconhd_parser_samples_foreach (dc_parser_t *abstract, d static const dc_parser_vtable_t mares_iconhd_parser_vtable = { sizeof(mares_iconhd_parser_t), DC_FAMILY_MARES_ICONHD, - mares_iconhd_parser_set_data, /* set_data */ NULL, /* set_clock */ NULL, /* set_atmospheric */ NULL, /* set_density */ @@ -656,7 +654,7 @@ mares_iconhd_parser_cache (mares_iconhd_parser_t *parser) } dc_status_t -mares_iconhd_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model) +mares_iconhd_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model) { mares_iconhd_parser_t *parser = NULL; @@ -664,7 +662,7 @@ mares_iconhd_parser_create (dc_parser_t **out, dc_context_t *context, unsigned i return DC_STATUS_INVALIDARGS; // Allocate memory. - parser = (mares_iconhd_parser_t *) dc_parser_allocate (context, &mares_iconhd_parser_vtable); + parser = (mares_iconhd_parser_t *) dc_parser_allocate (context, &mares_iconhd_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -701,41 +699,6 @@ mares_iconhd_parser_create (dc_parser_t **out, dc_context_t *context, unsigned i return DC_STATUS_SUCCESS; } - -static dc_status_t -mares_iconhd_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - mares_iconhd_parser_t *parser = (mares_iconhd_parser_t *) abstract; - - // Reset the cache. - parser->cached = 0; - parser->logformat = 0; - parser->mode = (parser->model == GENIUS || parser->model == HORIZON) ? GENIUS_AIR : ICONHD_AIR; - parser->nsamples = 0; - parser->samplesize = 0; - parser->headersize = 0; - parser->settings = 0; - parser->surftime = 0; - parser->interval = 0; - parser->samplerate = 0; - parser->ntanks = 0; - parser->ngasmixes = 0; - for (unsigned int i = 0; i < NGASMIXES; ++i) { - parser->gasmix[i].oxygen = 0; - parser->gasmix[i].helium = 0; - } - for (unsigned int i = 0; i < NTANKS; ++i) { - parser->tank[i].volume = 0; - parser->tank[i].workpressure = 0; - parser->tank[i].beginpressure = 0; - parser->tank[i].endpressure = 0; - } - parser->layout = NULL; - - return DC_STATUS_SUCCESS; -} - - static dc_status_t mares_iconhd_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime) { diff --git a/src/mares_nemo.h b/src/mares_nemo.h index c7a162b..1847d0f 100644 --- a/src/mares_nemo.h +++ b/src/mares_nemo.h @@ -35,7 +35,7 @@ dc_status_t mares_nemo_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -mares_nemo_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); +mares_nemo_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model); #ifdef __cplusplus } diff --git a/src/mares_nemo_parser.c b/src/mares_nemo_parser.c index 4b962ff..cb3e3bf 100644 --- a/src/mares_nemo_parser.c +++ b/src/mares_nemo_parser.c @@ -59,7 +59,6 @@ struct mares_nemo_parser_t { unsigned int extra; }; -static dc_status_t mares_nemo_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t mares_nemo_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime); static dc_status_t mares_nemo_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); static dc_status_t mares_nemo_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata); @@ -67,7 +66,6 @@ static dc_status_t mares_nemo_parser_samples_foreach (dc_parser_t *abstract, dc_ static const dc_parser_vtable_t mares_nemo_parser_vtable = { sizeof(mares_nemo_parser_t), DC_FAMILY_MARES_NEMO, - mares_nemo_parser_set_data, /* set_data */ NULL, /* set_clock */ NULL, /* set_atmospheric */ NULL, /* set_density */ @@ -79,15 +77,16 @@ static const dc_parser_vtable_t mares_nemo_parser_vtable = { dc_status_t -mares_nemo_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model) +mares_nemo_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model) { + dc_status_t status = DC_STATUS_SUCCESS; mares_nemo_parser_t *parser = NULL; if (out == NULL) return DC_STATUS_INVALIDARGS; // Allocate memory. - parser = (mares_nemo_parser_t *) dc_parser_allocate (context, &mares_nemo_parser_vtable); + parser = (mares_nemo_parser_t *) dc_parser_allocate (context, &mares_nemo_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -98,70 +97,42 @@ mares_nemo_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int if (model == NEMOWIDE || model == NEMOAIR || model == PUCK || model == PUCKAIR) freedive = GAUGE; - // Set the default values. - parser->model = model; - parser->freedive = freedive; - parser->mode = AIR; - parser->length = 0; - parser->sample_count = 0; - parser->sample_size = 0; - parser->header = 0; - parser->extra = 0; - - *out = (dc_parser_t*) parser; - - return DC_STATUS_SUCCESS; -} - - -static dc_status_t -mares_nemo_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - mares_nemo_parser_t *parser = (mares_nemo_parser_t *) abstract; - - // Clear the previous state. - parser->base.data = NULL; - parser->base.size = 0; - parser->mode = AIR; - parser->length = 0; - parser->sample_count = 0; - parser->sample_size = 0; - parser->header = 0; - parser->extra = 0; - - if (size == 0) - return DC_STATUS_SUCCESS; - - if (size < 2 + 3) - return DC_STATUS_DATAFORMAT; + if (size < 2 + 3) { + status = DC_STATUS_DATAFORMAT; + goto error_free; + } unsigned int length = array_uint16_le (data); - if (length > size) - return DC_STATUS_DATAFORMAT; + if (length > size) { + status = DC_STATUS_DATAFORMAT; + goto error_free; + } unsigned int extra = 0; const unsigned char marker[3] = {0xAA, 0xBB, 0xCC}; if (memcmp (data + length - 3, marker, sizeof (marker)) == 0) { - if (parser->model == PUCKAIR) + if (model == PUCKAIR) extra = 7; else extra = 12; } - if (length < 2 + extra + 3) - return DC_STATUS_DATAFORMAT; + if (length < 2 + extra + 3) { + status = DC_STATUS_DATAFORMAT; + goto error_free; + } unsigned int mode = data[length - extra - 1]; unsigned int header_size = 53; unsigned int sample_size = 2; if (extra) { - if (parser->model == PUCKAIR) + if (model == PUCKAIR) sample_size = 3; else sample_size = 5; } - if (mode == parser->freedive) { + if (mode == freedive) { header_size = 28; sample_size = 6; } @@ -169,12 +140,14 @@ mares_nemo_parser_set_data (dc_parser_t *abstract, const unsigned char *data, un unsigned int nsamples = array_uint16_le (data + length - extra - 3); unsigned int nbytes = 2 + nsamples * sample_size + header_size + extra; - if (length != nbytes) - return DC_STATUS_DATAFORMAT; + if (length != nbytes) { + status = DC_STATUS_DATAFORMAT; + goto error_free; + } - // Store the new state. - parser->base.data = data; - parser->base.size = size; + // Set the default values. + parser->model = model; + parser->freedive = freedive; parser->mode = mode; parser->length = length; parser->sample_count = nsamples; @@ -182,7 +155,13 @@ mares_nemo_parser_set_data (dc_parser_t *abstract, const unsigned char *data, un parser->header = header_size; parser->extra = extra; + *out = (dc_parser_t*) parser; + return DC_STATUS_SUCCESS; + +error_free: + dc_parser_deallocate ((dc_parser_t *) parser); + return status; } diff --git a/src/mclean_extreme.h b/src/mclean_extreme.h index c388bd4..fd7c6bc 100644 --- a/src/mclean_extreme.h +++ b/src/mclean_extreme.h @@ -35,7 +35,7 @@ dc_status_t mclean_extreme_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -mclean_extreme_parser_create (dc_parser_t **parser, dc_context_t *context); +mclean_extreme_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size); #ifdef __cplusplus } diff --git a/src/mclean_extreme_parser.c b/src/mclean_extreme_parser.c index 645a909..b9de495 100644 --- a/src/mclean_extreme_parser.c +++ b/src/mclean_extreme_parser.c @@ -58,7 +58,6 @@ struct mclean_extreme_parser_t { unsigned int gasmix[NGASMIXES]; }; -static dc_status_t mclean_extreme_parser_set_data(dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t mclean_extreme_parser_get_datetime(dc_parser_t *abstract, dc_datetime_t *datetime); static dc_status_t mclean_extreme_parser_get_field(dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); static dc_status_t mclean_extreme_parser_samples_foreach(dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata); @@ -66,7 +65,6 @@ static dc_status_t mclean_extreme_parser_samples_foreach(dc_parser_t *abstract, static const dc_parser_vtable_t mclean_extreme_parser_vtable = { sizeof(mclean_extreme_parser_t), DC_FAMILY_MCLEAN_EXTREME, - mclean_extreme_parser_set_data, /* set_data */ NULL, /* set_clock */ NULL, /* set_atmospheric */ NULL, /* set_density */ @@ -77,7 +75,7 @@ static const dc_parser_vtable_t mclean_extreme_parser_vtable = { }; dc_status_t -mclean_extreme_parser_create(dc_parser_t **out, dc_context_t *context) +mclean_extreme_parser_create(dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size) { mclean_extreme_parser_t *parser = NULL; @@ -86,7 +84,7 @@ mclean_extreme_parser_create(dc_parser_t **out, dc_context_t *context) } // Allocate memory. - parser = (mclean_extreme_parser_t *)dc_parser_allocate(context, &mclean_extreme_parser_vtable); + parser = (mclean_extreme_parser_t *)dc_parser_allocate(context, &mclean_extreme_parser_vtable, data, size); if (parser == NULL) { ERROR(context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -104,21 +102,6 @@ mclean_extreme_parser_create(dc_parser_t **out, dc_context_t *context) return DC_STATUS_SUCCESS; } -static dc_status_t -mclean_extreme_parser_set_data(dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - mclean_extreme_parser_t *parser = (mclean_extreme_parser_t *)abstract; - - // Reset the cache. - parser->cached = 0; - parser->ngasmixes = 0; - for (unsigned int i = 0; i < NGASMIXES; ++i) { - parser->gasmix[i] = INVALID; - } - - return DC_STATUS_SUCCESS; -} - static dc_status_t mclean_extreme_parser_get_datetime(dc_parser_t *abstract, dc_datetime_t *datetime) { diff --git a/src/oceanic_atom2.h b/src/oceanic_atom2.h index 25da953..152c439 100644 --- a/src/oceanic_atom2.h +++ b/src/oceanic_atom2.h @@ -37,7 +37,7 @@ dc_status_t oceanic_atom2_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream, unsigned int model); dc_status_t -oceanic_atom2_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); +oceanic_atom2_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model); #ifdef __cplusplus } diff --git a/src/oceanic_atom2_parser.c b/src/oceanic_atom2_parser.c index cb98366..49b2c0c 100644 --- a/src/oceanic_atom2_parser.c +++ b/src/oceanic_atom2_parser.c @@ -59,7 +59,6 @@ struct oceanic_atom2_parser_t { double maxdepth; }; -static dc_status_t oceanic_atom2_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t oceanic_atom2_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime); static dc_status_t oceanic_atom2_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); static dc_status_t oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata); @@ -67,7 +66,6 @@ static dc_status_t oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, static const dc_parser_vtable_t oceanic_atom2_parser_vtable = { sizeof(oceanic_atom2_parser_t), DC_FAMILY_OCEANIC_ATOM2, - oceanic_atom2_parser_set_data, /* set_data */ NULL, /* set_clock */ NULL, /* set_atmospheric */ NULL, /* set_density */ @@ -79,7 +77,7 @@ static const dc_parser_vtable_t oceanic_atom2_parser_vtable = { dc_status_t -oceanic_atom2_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model) +oceanic_atom2_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model) { oceanic_atom2_parser_t *parser = NULL; @@ -87,7 +85,7 @@ oceanic_atom2_parser_create (dc_parser_t **out, dc_context_t *context, unsigned return DC_STATUS_INVALIDARGS; // Allocate memory. - parser = (oceanic_atom2_parser_t *) dc_parser_allocate (context, &oceanic_atom2_parser_vtable); + parser = (oceanic_atom2_parser_t *) dc_parser_allocate (context, &oceanic_atom2_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -153,28 +151,6 @@ oceanic_atom2_parser_create (dc_parser_t **out, dc_context_t *context, unsigned } -static dc_status_t -oceanic_atom2_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - oceanic_atom2_parser_t *parser = (oceanic_atom2_parser_t *) abstract; - - // Reset the cache. - parser->cached = 0; - parser->header = 0; - parser->footer = 0; - parser->mode = NORMAL; - parser->ngasmixes = 0; - for (unsigned int i = 0; i < NGASMIXES; ++i) { - parser->oxygen[i] = 0; - parser->helium[i] = 0; - } - parser->divetime = 0; - parser->maxdepth = 0.0; - - return DC_STATUS_SUCCESS; -} - - static dc_status_t oceanic_atom2_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime) { diff --git a/src/oceanic_veo250.h b/src/oceanic_veo250.h index fc79375..5d24f74 100644 --- a/src/oceanic_veo250.h +++ b/src/oceanic_veo250.h @@ -37,7 +37,7 @@ dc_status_t oceanic_veo250_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -oceanic_veo250_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); +oceanic_veo250_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model); #ifdef __cplusplus } diff --git a/src/oceanic_veo250_parser.c b/src/oceanic_veo250_parser.c index ee14061..096e47c 100644 --- a/src/oceanic_veo250_parser.c +++ b/src/oceanic_veo250_parser.c @@ -42,7 +42,6 @@ struct oceanic_veo250_parser_t { double maxdepth; }; -static dc_status_t oceanic_veo250_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t oceanic_veo250_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime); static dc_status_t oceanic_veo250_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); static dc_status_t oceanic_veo250_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata); @@ -50,7 +49,6 @@ static dc_status_t oceanic_veo250_parser_samples_foreach (dc_parser_t *abstract, static const dc_parser_vtable_t oceanic_veo250_parser_vtable = { sizeof(oceanic_veo250_parser_t), DC_FAMILY_OCEANIC_VEO250, - oceanic_veo250_parser_set_data, /* set_data */ NULL, /* set_clock */ NULL, /* set_atmospheric */ NULL, /* set_density */ @@ -62,7 +60,7 @@ static const dc_parser_vtable_t oceanic_veo250_parser_vtable = { dc_status_t -oceanic_veo250_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model) +oceanic_veo250_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model) { oceanic_veo250_parser_t *parser = NULL; @@ -70,7 +68,7 @@ oceanic_veo250_parser_create (dc_parser_t **out, dc_context_t *context, unsigned return DC_STATUS_INVALIDARGS; // Allocate memory. - parser = (oceanic_veo250_parser_t *) dc_parser_allocate (context, &oceanic_veo250_parser_vtable); + parser = (oceanic_veo250_parser_t *) dc_parser_allocate (context, &oceanic_veo250_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -88,20 +86,6 @@ oceanic_veo250_parser_create (dc_parser_t **out, dc_context_t *context, unsigned } -static dc_status_t -oceanic_veo250_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - oceanic_veo250_parser_t *parser = (oceanic_veo250_parser_t *) abstract; - - // Reset the cache. - parser->cached = 0; - parser->divetime = 0; - parser->maxdepth = 0.0; - - return DC_STATUS_SUCCESS; -} - - static dc_status_t oceanic_veo250_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime) { diff --git a/src/oceanic_vtpro.h b/src/oceanic_vtpro.h index 6a3c2cd..3928adf 100644 --- a/src/oceanic_vtpro.h +++ b/src/oceanic_vtpro.h @@ -37,7 +37,7 @@ dc_status_t oceanic_vtpro_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream, unsigned int model); dc_status_t -oceanic_vtpro_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); +oceanic_vtpro_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model); #ifdef __cplusplus } diff --git a/src/oceanic_vtpro_parser.c b/src/oceanic_vtpro_parser.c index 4902033..ec380b3 100644 --- a/src/oceanic_vtpro_parser.c +++ b/src/oceanic_vtpro_parser.c @@ -42,7 +42,6 @@ struct oceanic_vtpro_parser_t { double maxdepth; }; -static dc_status_t oceanic_vtpro_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t oceanic_vtpro_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime); static dc_status_t oceanic_vtpro_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); static dc_status_t oceanic_vtpro_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata); @@ -50,7 +49,6 @@ static dc_status_t oceanic_vtpro_parser_samples_foreach (dc_parser_t *abstract, static const dc_parser_vtable_t oceanic_vtpro_parser_vtable = { sizeof(oceanic_vtpro_parser_t), DC_FAMILY_OCEANIC_VTPRO, - oceanic_vtpro_parser_set_data, /* set_data */ NULL, /* set_clock */ NULL, /* set_atmospheric */ NULL, /* set_density */ @@ -62,7 +60,7 @@ static const dc_parser_vtable_t oceanic_vtpro_parser_vtable = { dc_status_t -oceanic_vtpro_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model) +oceanic_vtpro_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model) { oceanic_vtpro_parser_t *parser = NULL; @@ -70,7 +68,7 @@ oceanic_vtpro_parser_create (dc_parser_t **out, dc_context_t *context, unsigned return DC_STATUS_INVALIDARGS; // Allocate memory. - parser = (oceanic_vtpro_parser_t *) dc_parser_allocate (context, &oceanic_vtpro_parser_vtable); + parser = (oceanic_vtpro_parser_t *) dc_parser_allocate (context, &oceanic_vtpro_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -88,20 +86,6 @@ oceanic_vtpro_parser_create (dc_parser_t **out, dc_context_t *context, unsigned } -static dc_status_t -oceanic_vtpro_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - oceanic_vtpro_parser_t *parser = (oceanic_vtpro_parser_t *) abstract; - - // Reset the cache. - parser->cached = 0; - parser->divetime = 0; - parser->maxdepth = 0.0; - - return DC_STATUS_SUCCESS; -} - - static dc_status_t oceanic_vtpro_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime) { diff --git a/src/oceans_s1.h b/src/oceans_s1.h index 825d309..e5e43f8 100644 --- a/src/oceans_s1.h +++ b/src/oceans_s1.h @@ -36,7 +36,7 @@ dc_status_t oceans_s1_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -oceans_s1_parser_create (dc_parser_t **parser, dc_context_t *context); +oceans_s1_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size); #ifdef __cplusplus } diff --git a/src/oceans_s1_parser.c b/src/oceans_s1_parser.c index c31bfe1..cce5031 100644 --- a/src/oceans_s1_parser.c +++ b/src/oceans_s1_parser.c @@ -58,7 +58,6 @@ struct oceans_s1_parser_t { unsigned int divetime; }; -static dc_status_t oceans_s1_parser_set_data(dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t oceans_s1_parser_get_datetime(dc_parser_t *abstract, dc_datetime_t *datetime); static dc_status_t oceans_s1_parser_get_field(dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); static dc_status_t oceans_s1_parser_samples_foreach(dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata); @@ -66,7 +65,6 @@ static dc_status_t oceans_s1_parser_samples_foreach(dc_parser_t *abstract, dc_sa static const dc_parser_vtable_t oceans_s1_parser_vtable = { sizeof(oceans_s1_parser_t), DC_FAMILY_OCEANS_S1, - oceans_s1_parser_set_data, /* set_data */ NULL, /* set_clock */ NULL, /* set_atmospheric */ NULL, /* set_density */ @@ -77,7 +75,7 @@ static const dc_parser_vtable_t oceans_s1_parser_vtable = { }; dc_status_t -oceans_s1_parser_create (dc_parser_t **out, dc_context_t *context) +oceans_s1_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size) { oceans_s1_parser_t *parser = NULL; @@ -85,7 +83,7 @@ oceans_s1_parser_create (dc_parser_t **out, dc_context_t *context) return DC_STATUS_INVALIDARGS; // Allocate memory. - parser = (oceans_s1_parser_t *) dc_parser_allocate (context, &oceans_s1_parser_vtable); + parser = (oceans_s1_parser_t *) dc_parser_allocate (context, &oceans_s1_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -105,23 +103,6 @@ oceans_s1_parser_create (dc_parser_t **out, dc_context_t *context) return DC_STATUS_SUCCESS; } -static dc_status_t -oceans_s1_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - oceans_s1_parser_t *parser = (oceans_s1_parser_t *) abstract; - - // Reset the cache. - parser->cached = 0; - parser->timestamp = 0; - parser->number = 0; - parser->divemode = 0; - parser->oxygen = 0; - parser->maxdepth = 0; - parser->divetime = 0; - - return DC_STATUS_SUCCESS; -} - static dc_status_t oceans_s1_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime) { diff --git a/src/parser-private.h b/src/parser-private.h index 9b8ed7c..73e2e59 100644 --- a/src/parser-private.h +++ b/src/parser-private.h @@ -41,7 +41,7 @@ typedef struct dc_parser_vtable_t dc_parser_vtable_t; struct dc_parser_t { const dc_parser_vtable_t *vtable; dc_context_t *context; - const unsigned char *data; + unsigned char *data; unsigned int size; }; @@ -50,8 +50,6 @@ struct dc_parser_vtable_t { dc_family_t type; - dc_status_t (*set_data) (dc_parser_t *parser, const unsigned char *data, unsigned int size); - dc_status_t (*set_clock) (dc_parser_t *parser, unsigned int devtime, dc_ticks_t systime); dc_status_t (*set_atmospheric) (dc_parser_t *parser, double atmospheric); @@ -68,7 +66,7 @@ struct dc_parser_vtable_t { }; dc_parser_t * -dc_parser_allocate (dc_context_t *context, const dc_parser_vtable_t *vtable); +dc_parser_allocate (dc_context_t *context, const dc_parser_vtable_t *vtable, const unsigned char data[], size_t size); void dc_parser_deallocate (dc_parser_t *parser); diff --git a/src/parser.c b/src/parser.c index 5138e54..011115d 100644 --- a/src/parser.c +++ b/src/parser.c @@ -20,6 +20,7 @@ */ #include +#include #include #include "suunto_d9.h" @@ -72,7 +73,7 @@ #define REACTPROWHITE 0x4354 static dc_status_t -dc_parser_new_internal (dc_parser_t **out, dc_context_t *context, dc_family_t family, unsigned int model) +dc_parser_new_internal (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size, dc_family_t family, unsigned int model) { dc_status_t rc = DC_STATUS_SUCCESS; dc_parser_t *parser = NULL; @@ -82,126 +83,126 @@ dc_parser_new_internal (dc_parser_t **out, dc_context_t *context, dc_family_t fa switch (family) { case DC_FAMILY_SUUNTO_SOLUTION: - rc = suunto_solution_parser_create (&parser, context); + rc = suunto_solution_parser_create (&parser, context, data, size); break; case DC_FAMILY_SUUNTO_EON: - rc = suunto_eon_parser_create (&parser, context, 0); + rc = suunto_eon_parser_create (&parser, context, data, size, 0); break; case DC_FAMILY_SUUNTO_VYPER: if (model == 0x01) - rc = suunto_eon_parser_create (&parser, context, 1); + rc = suunto_eon_parser_create (&parser, context, data, size, 1); else - rc = suunto_vyper_parser_create (&parser, context); + rc = suunto_vyper_parser_create (&parser, context, data, size); break; case DC_FAMILY_SUUNTO_VYPER2: case DC_FAMILY_SUUNTO_D9: - rc = suunto_d9_parser_create (&parser, context, model); + rc = suunto_d9_parser_create (&parser, context, data, size, model); break; case DC_FAMILY_SUUNTO_EONSTEEL: - rc = suunto_eonsteel_parser_create(&parser, context, model); + rc = suunto_eonsteel_parser_create(&parser, context, data, size, model); break; case DC_FAMILY_UWATEC_ALADIN: case DC_FAMILY_UWATEC_MEMOMOUSE: - rc = uwatec_memomouse_parser_create (&parser, context); + rc = uwatec_memomouse_parser_create (&parser, context, data, size); break; case DC_FAMILY_UWATEC_SMART: - rc = uwatec_smart_parser_create (&parser, context, model); + rc = uwatec_smart_parser_create (&parser, context, data, size, model); break; case DC_FAMILY_REEFNET_SENSUS: - rc = reefnet_sensus_parser_create (&parser, context); + rc = reefnet_sensus_parser_create (&parser, context, data, size); break; case DC_FAMILY_REEFNET_SENSUSPRO: - rc = reefnet_sensuspro_parser_create (&parser, context); + rc = reefnet_sensuspro_parser_create (&parser, context, data, size); break; case DC_FAMILY_REEFNET_SENSUSULTRA: - rc = reefnet_sensusultra_parser_create (&parser, context); + rc = reefnet_sensusultra_parser_create (&parser, context, data, size); break; case DC_FAMILY_OCEANIC_VTPRO: - rc = oceanic_vtpro_parser_create (&parser, context, model); + rc = oceanic_vtpro_parser_create (&parser, context, data, size, model); break; case DC_FAMILY_OCEANIC_VEO250: - rc = oceanic_veo250_parser_create (&parser, context, model); + rc = oceanic_veo250_parser_create (&parser, context, data, size, model); break; case DC_FAMILY_OCEANIC_ATOM2: if (model == REACTPROWHITE) - rc = oceanic_veo250_parser_create (&parser, context, model); + rc = oceanic_veo250_parser_create (&parser, context, data, size, model); else - rc = oceanic_atom2_parser_create (&parser, context, model); + rc = oceanic_atom2_parser_create (&parser, context, data, size, model); break; case DC_FAMILY_MARES_NEMO: case DC_FAMILY_MARES_PUCK: - rc = mares_nemo_parser_create (&parser, context, model); + rc = mares_nemo_parser_create (&parser, context, data, size, model); break; case DC_FAMILY_MARES_DARWIN: - rc = mares_darwin_parser_create (&parser, context, model); + rc = mares_darwin_parser_create (&parser, context, data, size, model); break; case DC_FAMILY_MARES_ICONHD: - rc = mares_iconhd_parser_create (&parser, context, model); + rc = mares_iconhd_parser_create (&parser, context, data, size, model); break; case DC_FAMILY_HW_OSTC: - rc = hw_ostc_parser_create (&parser, context); + rc = hw_ostc_parser_create (&parser, context, data, size); break; case DC_FAMILY_HW_FROG: case DC_FAMILY_HW_OSTC3: - rc = hw_ostc3_parser_create (&parser, context, model); + rc = hw_ostc3_parser_create (&parser, context, data, size, model); break; case DC_FAMILY_CRESSI_EDY: case DC_FAMILY_ZEAGLE_N2ITION3: - rc = cressi_edy_parser_create (&parser, context, model); + rc = cressi_edy_parser_create (&parser, context, data, size, model); break; case DC_FAMILY_CRESSI_LEONARDO: - rc = cressi_leonardo_parser_create (&parser, context, model); + rc = cressi_leonardo_parser_create (&parser, context, data, size, model); break; case DC_FAMILY_CRESSI_GOA: - rc = cressi_goa_parser_create (&parser, context, model); + rc = cressi_goa_parser_create (&parser, context, data, size, model); break; case DC_FAMILY_ATOMICS_COBALT: - rc = atomics_cobalt_parser_create (&parser, context); + rc = atomics_cobalt_parser_create (&parser, context, data, size); break; case DC_FAMILY_SHEARWATER_PREDATOR: - rc = shearwater_predator_parser_create (&parser, context, model); + rc = shearwater_predator_parser_create (&parser, context, data, size, model); break; case DC_FAMILY_SHEARWATER_PETREL: - rc = shearwater_petrel_parser_create (&parser, context, model); + rc = shearwater_petrel_parser_create (&parser, context, data, size, model); break; case DC_FAMILY_DIVERITE_NITEKQ: - rc = diverite_nitekq_parser_create (&parser, context); + rc = diverite_nitekq_parser_create (&parser, context, data, size); break; case DC_FAMILY_CITIZEN_AQUALAND: - rc = citizen_aqualand_parser_create (&parser, context); + rc = citizen_aqualand_parser_create (&parser, context, data, size); break; case DC_FAMILY_DIVESYSTEM_IDIVE: - rc = divesystem_idive_parser_create (&parser, context, model); + rc = divesystem_idive_parser_create (&parser, context, data, size, model); break; case DC_FAMILY_COCHRAN_COMMANDER: - rc = cochran_commander_parser_create (&parser, context, model); + rc = cochran_commander_parser_create (&parser, context, data, size, model); break; case DC_FAMILY_TECDIVING_DIVECOMPUTEREU: - rc = tecdiving_divecomputereu_parser_create (&parser, context); + rc = tecdiving_divecomputereu_parser_create (&parser, context, data, size); break; case DC_FAMILY_MCLEAN_EXTREME: - rc = mclean_extreme_parser_create (&parser, context); + rc = mclean_extreme_parser_create (&parser, context, data, size); break; case DC_FAMILY_LIQUIVISION_LYNX: - rc = liquivision_lynx_parser_create (&parser, context, model); + rc = liquivision_lynx_parser_create (&parser, context, data, size, model); break; case DC_FAMILY_SPORASUB_SP2: - rc = sporasub_sp2_parser_create (&parser, context); + rc = sporasub_sp2_parser_create (&parser, context, data, size); break; case DC_FAMILY_DEEPSIX_EXCURSION: - rc = deepsix_excursion_parser_create (&parser, context); + rc = deepsix_excursion_parser_create (&parser, context, data, size); break; case DC_FAMILY_SEAC_SCREEN: - rc = seac_screen_parser_create (&parser, context); + rc = seac_screen_parser_create (&parser, context, data, size); break; case DC_FAMILY_DEEPBLU_COSMIQ: - rc = deepblu_cosmiq_parser_create (&parser, context); + rc = deepblu_cosmiq_parser_create (&parser, context, data, size); break; case DC_FAMILY_OCEANS_S1: - rc = oceans_s1_parser_create (&parser, context); + rc = oceans_s1_parser_create (&parser, context, data, size); break; case DC_FAMILY_DIVESOFT_FREEDOM: - rc = divesoft_freedom_parser_create (&parser, context); + rc = divesoft_freedom_parser_create (&parser, context, data, size); break; default: return DC_STATUS_INVALIDARGS; @@ -213,7 +214,7 @@ dc_parser_new_internal (dc_parser_t **out, dc_context_t *context, dc_family_t fa } dc_status_t -dc_parser_new (dc_parser_t **out, dc_device_t *device) +dc_parser_new (dc_parser_t **out, dc_device_t *device, const unsigned char data[], size_t size) { dc_status_t status = DC_STATUS_SUCCESS; dc_parser_t *parser = NULL; @@ -221,7 +222,7 @@ dc_parser_new (dc_parser_t **out, dc_device_t *device) if (device == NULL) return DC_STATUS_INVALIDARGS; - status = dc_parser_new_internal (&parser, device->context, + status = dc_parser_new_internal (&parser, device->context, data, size, dc_device_get_type (device), device->devinfo.model); if (status != DC_STATUS_SUCCESS) goto error_exit; @@ -241,14 +242,14 @@ error_exit: } dc_status_t -dc_parser_new2 (dc_parser_t **out, dc_context_t *context, dc_descriptor_t *descriptor) +dc_parser_new2 (dc_parser_t **out, dc_context_t *context, dc_descriptor_t *descriptor, const unsigned char data[], size_t size) { - return dc_parser_new_internal (out, context, + return dc_parser_new_internal (out, context, data, size, dc_descriptor_get_type (descriptor), dc_descriptor_get_model (descriptor)); } dc_parser_t * -dc_parser_allocate (dc_context_t *context, const dc_parser_vtable_t *vtable) +dc_parser_allocate (dc_context_t *context, const dc_parser_vtable_t *vtable, const unsigned char data[], size_t size) { dc_parser_t *parser = NULL; @@ -265,15 +266,34 @@ dc_parser_allocate (dc_context_t *context, const dc_parser_vtable_t *vtable) // Initialize the base class. parser->vtable = vtable; parser->context = context; - parser->data = NULL; - parser->size = 0; + if (size) { + // Allocate memory for the data. + parser->data = malloc (size); + if (parser->data == NULL) { + ERROR (context, "Failed to allocate memory."); + free (parser); + return NULL; + } + + // Copy the data. + memcpy (parser->data, data, size); + parser->size = size; + } else { + parser->data = NULL; + parser->size = 0; + + } return parser; } void dc_parser_deallocate (dc_parser_t *parser) { + if (parser == NULL) + return; + + free (parser->data); free (parser); } @@ -336,22 +356,6 @@ dc_parser_set_density (dc_parser_t *parser, double density) } -dc_status_t -dc_parser_set_data (dc_parser_t *parser, const unsigned char *data, unsigned int size) -{ - if (parser == NULL) - return DC_STATUS_UNSUPPORTED; - - if (parser->vtable->set_data == NULL) - return DC_STATUS_UNSUPPORTED; - - parser->data = data; - parser->size = size; - - return parser->vtable->set_data (parser, data, size); -} - - dc_status_t dc_parser_get_datetime (dc_parser_t *parser, dc_datetime_t *datetime) { diff --git a/src/reefnet_sensus.h b/src/reefnet_sensus.h index 2ed5cbe..38157dc 100644 --- a/src/reefnet_sensus.h +++ b/src/reefnet_sensus.h @@ -36,7 +36,7 @@ dc_status_t reefnet_sensus_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -reefnet_sensus_parser_create (dc_parser_t **parser, dc_context_t *context); +reefnet_sensus_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size); #ifdef __cplusplus } diff --git a/src/reefnet_sensus_parser.c b/src/reefnet_sensus_parser.c index 9882778..29e7f46 100644 --- a/src/reefnet_sensus_parser.c +++ b/src/reefnet_sensus_parser.c @@ -48,7 +48,6 @@ struct reefnet_sensus_parser_t { unsigned int maxdepth; }; -static dc_status_t reefnet_sensus_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t reefnet_sensus_parser_set_clock (dc_parser_t *abstract, unsigned int devtime, dc_ticks_t systime); static dc_status_t reefnet_sensus_parser_set_atmospheric (dc_parser_t *abstract, double atmospheric); static dc_status_t reefnet_sensus_parser_set_density (dc_parser_t *abstract, double density); @@ -59,7 +58,6 @@ static dc_status_t reefnet_sensus_parser_samples_foreach (dc_parser_t *abstract, static const dc_parser_vtable_t reefnet_sensus_parser_vtable = { sizeof(reefnet_sensus_parser_t), DC_FAMILY_REEFNET_SENSUS, - reefnet_sensus_parser_set_data, /* set_data */ reefnet_sensus_parser_set_clock, /* set_clock */ reefnet_sensus_parser_set_atmospheric, /* set_atmospheric */ reefnet_sensus_parser_set_density, /* set_density */ @@ -71,7 +69,7 @@ static const dc_parser_vtable_t reefnet_sensus_parser_vtable = { dc_status_t -reefnet_sensus_parser_create (dc_parser_t **out, dc_context_t *context) +reefnet_sensus_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size) { reefnet_sensus_parser_t *parser = NULL; @@ -79,7 +77,7 @@ reefnet_sensus_parser_create (dc_parser_t **out, dc_context_t *context) return DC_STATUS_INVALIDARGS; // Allocate memory. - parser = (reefnet_sensus_parser_t *) dc_parser_allocate (context, &reefnet_sensus_parser_vtable); + parser = (reefnet_sensus_parser_t *) dc_parser_allocate (context, &reefnet_sensus_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -100,20 +98,6 @@ reefnet_sensus_parser_create (dc_parser_t **out, dc_context_t *context) } -static dc_status_t -reefnet_sensus_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - reefnet_sensus_parser_t *parser = (reefnet_sensus_parser_t*) abstract; - - // Reset the cache. - parser->cached = 0; - parser->divetime = 0; - parser->maxdepth = 0; - - return DC_STATUS_SUCCESS; -} - - static dc_status_t reefnet_sensus_parser_set_clock (dc_parser_t *abstract, unsigned int devtime, dc_ticks_t systime) { diff --git a/src/reefnet_sensuspro.h b/src/reefnet_sensuspro.h index fd21d99..f187f93 100644 --- a/src/reefnet_sensuspro.h +++ b/src/reefnet_sensuspro.h @@ -36,7 +36,7 @@ dc_status_t reefnet_sensuspro_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -reefnet_sensuspro_parser_create (dc_parser_t **parser, dc_context_t *context); +reefnet_sensuspro_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size); #ifdef __cplusplus } diff --git a/src/reefnet_sensuspro_parser.c b/src/reefnet_sensuspro_parser.c index 6dc0613..5d6fd5e 100644 --- a/src/reefnet_sensuspro_parser.c +++ b/src/reefnet_sensuspro_parser.c @@ -47,7 +47,6 @@ struct reefnet_sensuspro_parser_t { unsigned int maxdepth; }; -static dc_status_t reefnet_sensuspro_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t reefnet_sensuspro_parser_set_clock (dc_parser_t *abstract, unsigned int devtime, dc_ticks_t systime); static dc_status_t reefnet_sensuspro_parser_set_atmospheric (dc_parser_t *abstract, double atmospheric); static dc_status_t reefnet_sensuspro_parser_set_density (dc_parser_t *abstract, double density); @@ -58,7 +57,6 @@ static dc_status_t reefnet_sensuspro_parser_samples_foreach (dc_parser_t *abstra static const dc_parser_vtable_t reefnet_sensuspro_parser_vtable = { sizeof(reefnet_sensuspro_parser_t), DC_FAMILY_REEFNET_SENSUSPRO, - reefnet_sensuspro_parser_set_data, /* set_data */ reefnet_sensuspro_parser_set_clock, /* set_clock */ reefnet_sensuspro_parser_set_atmospheric, /* set_atmospheric */ reefnet_sensuspro_parser_set_density, /* set_density */ @@ -70,7 +68,7 @@ static const dc_parser_vtable_t reefnet_sensuspro_parser_vtable = { dc_status_t -reefnet_sensuspro_parser_create (dc_parser_t **out, dc_context_t *context) +reefnet_sensuspro_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size) { reefnet_sensuspro_parser_t *parser = NULL; @@ -78,7 +76,7 @@ reefnet_sensuspro_parser_create (dc_parser_t **out, dc_context_t *context) return DC_STATUS_INVALIDARGS; // Allocate memory. - parser = (reefnet_sensuspro_parser_t *) dc_parser_allocate (context, &reefnet_sensuspro_parser_vtable); + parser = (reefnet_sensuspro_parser_t *) dc_parser_allocate (context, &reefnet_sensuspro_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -99,20 +97,6 @@ reefnet_sensuspro_parser_create (dc_parser_t **out, dc_context_t *context) } -static dc_status_t -reefnet_sensuspro_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - reefnet_sensuspro_parser_t *parser = (reefnet_sensuspro_parser_t*) abstract; - - // Reset the cache. - parser->cached = 0; - parser->divetime = 0; - parser->maxdepth = 0; - - return DC_STATUS_SUCCESS; -} - - static dc_status_t reefnet_sensuspro_parser_set_clock (dc_parser_t *abstract, unsigned int devtime, dc_ticks_t systime) { diff --git a/src/reefnet_sensusultra.h b/src/reefnet_sensusultra.h index 054745a..1cefc9c 100644 --- a/src/reefnet_sensusultra.h +++ b/src/reefnet_sensusultra.h @@ -36,7 +36,7 @@ dc_status_t reefnet_sensusultra_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -reefnet_sensusultra_parser_create (dc_parser_t **parser, dc_context_t *context); +reefnet_sensusultra_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size); #ifdef __cplusplus } diff --git a/src/reefnet_sensusultra_parser.c b/src/reefnet_sensusultra_parser.c index 5564019..670a0c3 100644 --- a/src/reefnet_sensusultra_parser.c +++ b/src/reefnet_sensusultra_parser.c @@ -47,7 +47,6 @@ struct reefnet_sensusultra_parser_t { unsigned int maxdepth; }; -static dc_status_t reefnet_sensusultra_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t reefnet_sensusultra_parser_set_clock (dc_parser_t *abstract, unsigned int devtime, dc_ticks_t systime); static dc_status_t reefnet_sensusultra_parser_set_atmospheric (dc_parser_t *abstract, double atmospheric); static dc_status_t reefnet_sensusultra_parser_set_density (dc_parser_t *abstract, double density); @@ -58,7 +57,6 @@ static dc_status_t reefnet_sensusultra_parser_samples_foreach (dc_parser_t *abst static const dc_parser_vtable_t reefnet_sensusultra_parser_vtable = { sizeof(reefnet_sensusultra_parser_t), DC_FAMILY_REEFNET_SENSUSULTRA, - reefnet_sensusultra_parser_set_data, /* set_data */ reefnet_sensusultra_parser_set_clock, /* set_clock */ reefnet_sensusultra_parser_set_atmospheric, /* set_atmospheric */ reefnet_sensusultra_parser_set_density, /* set_density */ @@ -70,7 +68,7 @@ static const dc_parser_vtable_t reefnet_sensusultra_parser_vtable = { dc_status_t -reefnet_sensusultra_parser_create (dc_parser_t **out, dc_context_t *context) +reefnet_sensusultra_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size) { reefnet_sensusultra_parser_t *parser = NULL; @@ -78,7 +76,7 @@ reefnet_sensusultra_parser_create (dc_parser_t **out, dc_context_t *context) return DC_STATUS_INVALIDARGS; // Allocate memory. - parser = (reefnet_sensusultra_parser_t *) dc_parser_allocate (context, &reefnet_sensusultra_parser_vtable); + parser = (reefnet_sensusultra_parser_t *) dc_parser_allocate (context, &reefnet_sensusultra_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -99,20 +97,6 @@ reefnet_sensusultra_parser_create (dc_parser_t **out, dc_context_t *context) } -static dc_status_t -reefnet_sensusultra_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - reefnet_sensusultra_parser_t *parser = (reefnet_sensusultra_parser_t*) abstract; - - // Reset the cache. - parser->cached = 0; - parser->divetime = 0; - parser->maxdepth = 0; - - return DC_STATUS_SUCCESS; -} - - static dc_status_t reefnet_sensusultra_parser_set_clock (dc_parser_t *abstract, unsigned int devtime, dc_ticks_t systime) { diff --git a/src/seac_screen.h b/src/seac_screen.h index 64c15b6..4ff05ea 100644 --- a/src/seac_screen.h +++ b/src/seac_screen.h @@ -35,7 +35,7 @@ dc_status_t seac_screen_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -seac_screen_parser_create (dc_parser_t **parser, dc_context_t *context); +seac_screen_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size); #ifdef __cplusplus } diff --git a/src/seac_screen_parser.c b/src/seac_screen_parser.c index c50eaee..07553d6 100644 --- a/src/seac_screen_parser.c +++ b/src/seac_screen_parser.c @@ -48,7 +48,6 @@ struct seac_screen_parser_t { unsigned int gf_high; }; -static dc_status_t seac_screen_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t seac_screen_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime); static dc_status_t seac_screen_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); static dc_status_t seac_screen_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata); @@ -56,7 +55,6 @@ static dc_status_t seac_screen_parser_samples_foreach (dc_parser_t *abstract, dc static const dc_parser_vtable_t seac_screen_parser_vtable = { sizeof(seac_screen_parser_t), DC_FAMILY_SEAC_SCREEN, - seac_screen_parser_set_data, /* set_data */ NULL, /* set_clock */ NULL, /* set_atmospheric */ NULL, /* set_density */ @@ -67,7 +65,7 @@ static const dc_parser_vtable_t seac_screen_parser_vtable = { }; dc_status_t -seac_screen_parser_create (dc_parser_t **out, dc_context_t *context) +seac_screen_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size) { seac_screen_parser_t *parser = NULL; @@ -75,7 +73,7 @@ seac_screen_parser_create (dc_parser_t **out, dc_context_t *context) return DC_STATUS_INVALIDARGS; // Allocate memory. - parser = (seac_screen_parser_t *) dc_parser_allocate (context, &seac_screen_parser_vtable); + parser = (seac_screen_parser_t *) dc_parser_allocate (context, &seac_screen_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -95,23 +93,6 @@ seac_screen_parser_create (dc_parser_t **out, dc_context_t *context) return DC_STATUS_SUCCESS; } -static dc_status_t -seac_screen_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - seac_screen_parser_t *parser = (seac_screen_parser_t *)abstract; - - // Reset the cache. - parser->cached = 0; - parser->ngasmixes = 0; - for (unsigned int i = 0; i < NGASMIXES; ++i) { - parser->oxygen[i] = 0; - } - parser->gf_low = 0; - parser->gf_high = 0; - - return DC_STATUS_SUCCESS; -} - static dc_status_t seac_screen_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime) { diff --git a/src/shearwater_petrel.h b/src/shearwater_petrel.h index 0a4e756..166007e 100644 --- a/src/shearwater_petrel.h +++ b/src/shearwater_petrel.h @@ -35,7 +35,7 @@ dc_status_t shearwater_petrel_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -shearwater_petrel_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); +shearwater_petrel_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model); #ifdef __cplusplus } diff --git a/src/shearwater_predator.h b/src/shearwater_predator.h index 5d1fccb..5d8ef9d 100644 --- a/src/shearwater_predator.h +++ b/src/shearwater_predator.h @@ -35,7 +35,7 @@ dc_status_t shearwater_predator_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -shearwater_predator_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); +shearwater_predator_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model); #ifdef __cplusplus } diff --git a/src/shearwater_predator_parser.c b/src/shearwater_predator_parser.c index fe0a6db..749fe3c 100644 --- a/src/shearwater_predator_parser.c +++ b/src/shearwater_predator_parser.c @@ -148,7 +148,6 @@ struct shearwater_predator_parser_t { unsigned int density; }; -static dc_status_t shearwater_predator_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t shearwater_predator_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime); static dc_status_t shearwater_predator_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); static dc_status_t shearwater_predator_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata); @@ -158,7 +157,6 @@ static dc_status_t shearwater_predator_parser_cache (shearwater_predator_parser_ static const dc_parser_vtable_t shearwater_predator_parser_vtable = { sizeof(shearwater_predator_parser_t), DC_FAMILY_SHEARWATER_PREDATOR, - shearwater_predator_parser_set_data, /* set_data */ NULL, /* set_clock */ NULL, /* set_atmospheric */ NULL, /* set_density */ @@ -171,7 +169,6 @@ static const dc_parser_vtable_t shearwater_predator_parser_vtable = { static const dc_parser_vtable_t shearwater_petrel_parser_vtable = { sizeof(shearwater_predator_parser_t), DC_FAMILY_SHEARWATER_PETREL, - shearwater_predator_parser_set_data, /* set_data */ NULL, /* set_clock */ NULL, /* set_atmospheric */ NULL, /* set_density */ @@ -197,7 +194,7 @@ shearwater_predator_find_gasmix (shearwater_predator_parser_t *parser, unsigned static dc_status_t -shearwater_common_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model, unsigned int petrel) +shearwater_common_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model, unsigned int petrel) { shearwater_predator_parser_t *parser = NULL; const dc_parser_vtable_t *vtable = NULL; @@ -215,7 +212,7 @@ shearwater_common_parser_create (dc_parser_t **out, dc_context_t *context, unsig } // Allocate memory. - parser = (shearwater_predator_parser_t *) dc_parser_allocate (context, vtable); + parser = (shearwater_predator_parser_t *) dc_parser_allocate (context, vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -270,64 +267,16 @@ shearwater_common_parser_create (dc_parser_t **out, dc_context_t *context, unsig dc_status_t -shearwater_predator_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model) +shearwater_predator_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model) { - return shearwater_common_parser_create (out, context, model, 0); + return shearwater_common_parser_create (out, context, data, size, model, 0); } dc_status_t -shearwater_petrel_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model) +shearwater_petrel_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model) { - return shearwater_common_parser_create (out, context, model, 1); -} - - -static dc_status_t -shearwater_predator_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - shearwater_predator_parser_t *parser = (shearwater_predator_parser_t *) abstract; - - // Reset the cache. - parser->cached = 0; - parser->pnf = 0; - parser->logversion = 0; - parser->headersize = 0; - parser->footersize = 0; - for (unsigned int i = 0; i < NRECORDS; ++i) { - parser->opening[i] = UNDEFINED; - parser->closing[i] = UNDEFINED; - } - parser->final = UNDEFINED; - parser->ngasmixes = 0; - for (unsigned int i = 0; i < NGASMIXES; ++i) { - parser->gasmix[i].oxygen = 0; - parser->gasmix[i].helium = 0; - parser->gasmix[i].diluent = 0; - } - parser->ntanks = 0; - for (unsigned int i = 0; i < NTANKS; ++i) { - parser->tank[i].enabled = 0; - parser->tank[i].active = 0; - parser->tank[i].beginpressure = 0; - parser->tank[i].endpressure = 0; - parser->tank[i].pressure_max = 0; - parser->tank[i].pressure_reserve = 0; - parser->tank[i].serial = 0; - memset (parser->tank[i].name, 0, sizeof (parser->tank[i].name)); - parser->tankidx[i] = i; - } - parser->aimode = AI_OFF; - parser->calibrated = 0; - for (unsigned int i = 0; i < 3; ++i) { - parser->calibration[i] = 0.0; - } - parser->divemode = M_OC_TEC; - parser->units = METRIC; - parser->density = DEF_DENSITY_SALT; - parser->atmospheric = DEF_ATMOSPHERIC / (BAR / 1000); - - return DC_STATUS_SUCCESS; + return shearwater_common_parser_create (out, context, data, size, model, 1); } diff --git a/src/sporasub_sp2.h b/src/sporasub_sp2.h index de2ca42..6b21c45 100644 --- a/src/sporasub_sp2.h +++ b/src/sporasub_sp2.h @@ -35,7 +35,7 @@ dc_status_t sporasub_sp2_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -sporasub_sp2_parser_create (dc_parser_t **parser, dc_context_t *context); +sporasub_sp2_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size); #ifdef __cplusplus } diff --git a/src/sporasub_sp2_parser.c b/src/sporasub_sp2_parser.c index c84a35c..37f0211 100644 --- a/src/sporasub_sp2_parser.c +++ b/src/sporasub_sp2_parser.c @@ -37,7 +37,6 @@ struct sporasub_sp2_parser_t { dc_parser_t base; }; -static dc_status_t sporasub_sp2_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t sporasub_sp2_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime); static dc_status_t sporasub_sp2_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); static dc_status_t sporasub_sp2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata); @@ -45,7 +44,6 @@ static dc_status_t sporasub_sp2_parser_samples_foreach (dc_parser_t *abstract, d static const dc_parser_vtable_t sporasub_sp2_parser_vtable = { sizeof(sporasub_sp2_parser_t), DC_FAMILY_SPORASUB_SP2, - sporasub_sp2_parser_set_data, /* set_data */ NULL, /* set_clock */ NULL, /* set_atmospheric */ NULL, /* set_density */ @@ -57,7 +55,7 @@ static const dc_parser_vtable_t sporasub_sp2_parser_vtable = { dc_status_t -sporasub_sp2_parser_create (dc_parser_t **out, dc_context_t *context) +sporasub_sp2_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size) { sporasub_sp2_parser_t *parser = NULL; @@ -65,7 +63,7 @@ sporasub_sp2_parser_create (dc_parser_t **out, dc_context_t *context) return DC_STATUS_INVALIDARGS; // Allocate memory. - parser = (sporasub_sp2_parser_t *) dc_parser_allocate (context, &sporasub_sp2_parser_vtable); + parser = (sporasub_sp2_parser_t *) dc_parser_allocate (context, &sporasub_sp2_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -77,13 +75,6 @@ sporasub_sp2_parser_create (dc_parser_t **out, dc_context_t *context) } -static dc_status_t -sporasub_sp2_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - return DC_STATUS_SUCCESS; -} - - static dc_status_t sporasub_sp2_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime) { diff --git a/src/suunto_d9.h b/src/suunto_d9.h index 94a782f..e6ae5bd 100644 --- a/src/suunto_d9.h +++ b/src/suunto_d9.h @@ -36,7 +36,7 @@ dc_status_t suunto_d9_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream, unsigned int model); dc_status_t -suunto_d9_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); +suunto_d9_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model); #ifdef __cplusplus } diff --git a/src/suunto_d9_parser.c b/src/suunto_d9_parser.c index 43e9ccc..8445d11 100644 --- a/src/suunto_d9_parser.c +++ b/src/suunto_d9_parser.c @@ -92,7 +92,6 @@ typedef struct sample_info_t { unsigned int divisor; } sample_info_t; -static dc_status_t suunto_d9_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t suunto_d9_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime); static dc_status_t suunto_d9_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); static dc_status_t suunto_d9_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata); @@ -100,7 +99,6 @@ static dc_status_t suunto_d9_parser_samples_foreach (dc_parser_t *abstract, dc_s static const dc_parser_vtable_t suunto_d9_parser_vtable = { sizeof(suunto_d9_parser_t), DC_FAMILY_SUUNTO_D9, - suunto_d9_parser_set_data, /* set_data */ NULL, /* set_clock */ NULL, /* set_atmospheric */ NULL, /* set_density */ @@ -251,7 +249,7 @@ suunto_d9_parser_cache (suunto_d9_parser_t *parser) } dc_status_t -suunto_d9_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model) +suunto_d9_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model) { suunto_d9_parser_t *parser = NULL; @@ -259,7 +257,7 @@ suunto_d9_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int return DC_STATUS_INVALIDARGS; // Allocate memory. - parser = (suunto_d9_parser_t *) dc_parser_allocate (context, &suunto_d9_parser_vtable); + parser = (suunto_d9_parser_t *) dc_parser_allocate (context, &suunto_d9_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -285,28 +283,6 @@ suunto_d9_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int } -static dc_status_t -suunto_d9_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - suunto_d9_parser_t *parser = (suunto_d9_parser_t *) abstract; - - // Reset the cache. - parser->cached = 0; - parser->id = 0; - parser->mode = AIR; - parser->ngasmixes = 0; - parser->nccr = 0; - for (unsigned int i = 0; i < NGASMIXES; ++i) { - parser->oxygen[i] = 0; - parser->helium[i] = 0; - } - parser->gasmix = 0; - parser->config = 0; - - return DC_STATUS_SUCCESS; -} - - static dc_status_t suunto_d9_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime) { diff --git a/src/suunto_eon.h b/src/suunto_eon.h index 5e99a69..9c605eb 100644 --- a/src/suunto_eon.h +++ b/src/suunto_eon.h @@ -36,7 +36,7 @@ dc_status_t suunto_eon_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -suunto_eon_parser_create (dc_parser_t **parser, dc_context_t *context, int spyder); +suunto_eon_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size, int spyder); #ifdef __cplusplus } diff --git a/src/suunto_eon_parser.c b/src/suunto_eon_parser.c index 9bfadda..94370a3 100644 --- a/src/suunto_eon_parser.c +++ b/src/suunto_eon_parser.c @@ -43,7 +43,6 @@ struct suunto_eon_parser_t { unsigned int nitrox; }; -static dc_status_t suunto_eon_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t suunto_eon_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime); static dc_status_t suunto_eon_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); static dc_status_t suunto_eon_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata); @@ -51,7 +50,6 @@ static dc_status_t suunto_eon_parser_samples_foreach (dc_parser_t *abstract, dc_ static const dc_parser_vtable_t suunto_eon_parser_vtable = { sizeof(suunto_eon_parser_t), DC_FAMILY_SUUNTO_EON, - suunto_eon_parser_set_data, /* set_data */ NULL, /* set_clock */ NULL, /* set_atmospheric */ NULL, /* set_density */ @@ -112,7 +110,7 @@ suunto_eon_parser_cache (suunto_eon_parser_t *parser) } dc_status_t -suunto_eon_parser_create (dc_parser_t **out, dc_context_t *context, int spyder) +suunto_eon_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size, int spyder) { suunto_eon_parser_t *parser = NULL; @@ -120,7 +118,7 @@ suunto_eon_parser_create (dc_parser_t **out, dc_context_t *context, int spyder) return DC_STATUS_INVALIDARGS; // Allocate memory. - parser = (suunto_eon_parser_t *) dc_parser_allocate (context, &suunto_eon_parser_vtable); + parser = (suunto_eon_parser_t *) dc_parser_allocate (context, &suunto_eon_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -140,22 +138,6 @@ suunto_eon_parser_create (dc_parser_t **out, dc_context_t *context, int spyder) } -static dc_status_t -suunto_eon_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - suunto_eon_parser_t *parser = (suunto_eon_parser_t *) abstract; - - // Reset the cache. - parser->cached = 0; - parser->divetime = 0; - parser->maxdepth = 0; - parser->marker = 0; - parser->nitrox = 0; - - return DC_STATUS_SUCCESS; -} - - static dc_status_t suunto_eon_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime) { diff --git a/src/suunto_eonsteel.h b/src/suunto_eonsteel.h index 2800107..cb18296 100644 --- a/src/suunto_eonsteel.h +++ b/src/suunto_eonsteel.h @@ -35,7 +35,7 @@ dc_status_t suunto_eonsteel_device_open(dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream, unsigned int model); dc_status_t -suunto_eonsteel_parser_create(dc_parser_t **parser, dc_context_t *context, unsigned int model); +suunto_eonsteel_parser_create(dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model); #ifdef __cplusplus } diff --git a/src/suunto_eonsteel_parser.c b/src/suunto_eonsteel_parser.c index 5c5c328..d6fd027 100644 --- a/src/suunto_eonsteel_parser.c +++ b/src/suunto_eonsteel_parser.c @@ -1509,18 +1509,6 @@ static void show_all_descriptors(suunto_eonsteel_parser_t *eon) show_descriptor(eon, i, eon->type_desc+i); } -static dc_status_t -suunto_eonsteel_parser_set_data(dc_parser_t *parser, const unsigned char *data, unsigned int size) -{ - suunto_eonsteel_parser_t *eon = (suunto_eonsteel_parser_t *) parser; - - desc_free(eon->type_desc, MAXTYPE); - memset(eon->type_desc, 0, sizeof(eon->type_desc)); - initialize_field_caches(eon); - show_all_descriptors(eon); - return DC_STATUS_SUCCESS; -} - static dc_status_t suunto_eonsteel_parser_destroy(dc_parser_t *parser) { @@ -1534,7 +1522,6 @@ suunto_eonsteel_parser_destroy(dc_parser_t *parser) static const dc_parser_vtable_t suunto_eonsteel_parser_vtable = { sizeof(suunto_eonsteel_parser_t), DC_FAMILY_SUUNTO_EONSTEEL, - suunto_eonsteel_parser_set_data, /* set_data */ NULL, /* set_clock */ NULL, /* set_atmospheric */ NULL, /* set_density */ @@ -1545,14 +1532,14 @@ static const dc_parser_vtable_t suunto_eonsteel_parser_vtable = { }; dc_status_t -suunto_eonsteel_parser_create(dc_parser_t **out, dc_context_t *context, unsigned int model) +suunto_eonsteel_parser_create(dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model) { suunto_eonsteel_parser_t *parser = NULL; if (out == NULL) return DC_STATUS_INVALIDARGS; - parser = (suunto_eonsteel_parser_t *) dc_parser_allocate (context, &suunto_eonsteel_parser_vtable); + parser = (suunto_eonsteel_parser_t *) dc_parser_allocate (context, &suunto_eonsteel_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -1561,6 +1548,9 @@ suunto_eonsteel_parser_create(dc_parser_t **out, dc_context_t *context, unsigned memset(&parser->type_desc, 0, sizeof(parser->type_desc)); memset(&parser->cache, 0, sizeof(parser->cache)); + initialize_field_caches(parser); + show_all_descriptors(parser); + *out = (dc_parser_t *) parser; return DC_STATUS_SUCCESS; diff --git a/src/suunto_solution.h b/src/suunto_solution.h index 9d9e632..0556ad7 100644 --- a/src/suunto_solution.h +++ b/src/suunto_solution.h @@ -35,7 +35,7 @@ dc_status_t suunto_solution_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -suunto_solution_parser_create (dc_parser_t **parser, dc_context_t *context); +suunto_solution_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size); #ifdef __cplusplus } diff --git a/src/suunto_solution_parser.c b/src/suunto_solution_parser.c index f8320aa..69c6977 100644 --- a/src/suunto_solution_parser.c +++ b/src/suunto_solution_parser.c @@ -39,14 +39,12 @@ struct suunto_solution_parser_t { unsigned int maxdepth; }; -static dc_status_t suunto_solution_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t suunto_solution_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); static dc_status_t suunto_solution_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata); static const dc_parser_vtable_t suunto_solution_parser_vtable = { sizeof(suunto_solution_parser_t), DC_FAMILY_SUUNTO_SOLUTION, - suunto_solution_parser_set_data, /* set_data */ NULL, /* set_clock */ NULL, /* set_atmospheric */ NULL, /* set_density */ @@ -58,7 +56,7 @@ static const dc_parser_vtable_t suunto_solution_parser_vtable = { dc_status_t -suunto_solution_parser_create (dc_parser_t **out, dc_context_t *context) +suunto_solution_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size) { suunto_solution_parser_t *parser = NULL; @@ -66,7 +64,7 @@ suunto_solution_parser_create (dc_parser_t **out, dc_context_t *context) return DC_STATUS_INVALIDARGS; // Allocate memory. - parser = (suunto_solution_parser_t *) dc_parser_allocate (context, &suunto_solution_parser_vtable); + parser = (suunto_solution_parser_t *) dc_parser_allocate (context, &suunto_solution_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -83,20 +81,6 @@ suunto_solution_parser_create (dc_parser_t **out, dc_context_t *context) } -static dc_status_t -suunto_solution_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - suunto_solution_parser_t *parser = (suunto_solution_parser_t *) abstract; - - // Reset the cache. - parser->cached = 0; - parser->divetime = 0; - parser->maxdepth = 0; - - return DC_STATUS_SUCCESS; -} - - static dc_status_t suunto_solution_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value) { diff --git a/src/suunto_vyper.h b/src/suunto_vyper.h index 858520f..616c094 100644 --- a/src/suunto_vyper.h +++ b/src/suunto_vyper.h @@ -35,7 +35,7 @@ dc_status_t suunto_vyper_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -suunto_vyper_parser_create (dc_parser_t **parser, dc_context_t *context); +suunto_vyper_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size); #ifdef __cplusplus } diff --git a/src/suunto_vyper_parser.c b/src/suunto_vyper_parser.c index fe9bfe2..8311363 100644 --- a/src/suunto_vyper_parser.c +++ b/src/suunto_vyper_parser.c @@ -44,7 +44,6 @@ struct suunto_vyper_parser_t { unsigned int oxygen[NGASMIXES]; }; -static dc_status_t suunto_vyper_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t suunto_vyper_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime); static dc_status_t suunto_vyper_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); static dc_status_t suunto_vyper_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata); @@ -52,7 +51,6 @@ static dc_status_t suunto_vyper_parser_samples_foreach (dc_parser_t *abstract, d static const dc_parser_vtable_t suunto_vyper_parser_vtable = { sizeof(suunto_vyper_parser_t), DC_FAMILY_SUUNTO_VYPER, - suunto_vyper_parser_set_data, /* set_data */ NULL, /* set_clock */ NULL, /* set_atmospheric */ NULL, /* set_density */ @@ -162,7 +160,7 @@ suunto_vyper_parser_cache (suunto_vyper_parser_t *parser) dc_status_t -suunto_vyper_parser_create (dc_parser_t **out, dc_context_t *context) +suunto_vyper_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size) { suunto_vyper_parser_t *parser = NULL; @@ -170,7 +168,7 @@ suunto_vyper_parser_create (dc_parser_t **out, dc_context_t *context) return DC_STATUS_INVALIDARGS; // Allocate memory. - parser = (suunto_vyper_parser_t *) dc_parser_allocate (context, &suunto_vyper_parser_vtable); + parser = (suunto_vyper_parser_t *) dc_parser_allocate (context, &suunto_vyper_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -192,25 +190,6 @@ suunto_vyper_parser_create (dc_parser_t **out, dc_context_t *context) } -static dc_status_t -suunto_vyper_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - suunto_vyper_parser_t *parser = (suunto_vyper_parser_t *) abstract; - - // Reset the cache. - parser->cached = 0; - parser->divetime = 0; - parser->maxdepth = 0; - parser->marker = 0; - parser->ngasmixes = 0; - for (unsigned int i = 0; i < NGASMIXES; ++i) { - parser->oxygen[i] = 0; - } - - return DC_STATUS_SUCCESS; -} - - static dc_status_t suunto_vyper_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime) { diff --git a/src/tecdiving_divecomputereu.h b/src/tecdiving_divecomputereu.h index 714ae43..8eafb4e 100644 --- a/src/tecdiving_divecomputereu.h +++ b/src/tecdiving_divecomputereu.h @@ -35,7 +35,7 @@ dc_status_t tecdiving_divecomputereu_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -tecdiving_divecomputereu_parser_create (dc_parser_t **parser, dc_context_t *context); +tecdiving_divecomputereu_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size); #ifdef __cplusplus } diff --git a/src/tecdiving_divecomputereu_parser.c b/src/tecdiving_divecomputereu_parser.c index b0f1552..4f3f514 100644 --- a/src/tecdiving_divecomputereu_parser.c +++ b/src/tecdiving_divecomputereu_parser.c @@ -36,7 +36,6 @@ struct tecdiving_divecomputereu_parser_t { dc_parser_t base; }; -static dc_status_t tecdiving_divecomputereu_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t tecdiving_divecomputereu_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime); static dc_status_t tecdiving_divecomputereu_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); static dc_status_t tecdiving_divecomputereu_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata); @@ -44,7 +43,6 @@ static dc_status_t tecdiving_divecomputereu_parser_samples_foreach (dc_parser_t static const dc_parser_vtable_t tecdiving_divecomputereu_parser_vtable = { sizeof(tecdiving_divecomputereu_parser_t), DC_FAMILY_TECDIVING_DIVECOMPUTEREU, - tecdiving_divecomputereu_parser_set_data, /* set_data */ NULL, /* set_clock */ NULL, /* set_atmospheric */ NULL, /* set_density */ @@ -56,7 +54,7 @@ static const dc_parser_vtable_t tecdiving_divecomputereu_parser_vtable = { dc_status_t -tecdiving_divecomputereu_parser_create (dc_parser_t **out, dc_context_t *context) +tecdiving_divecomputereu_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size) { tecdiving_divecomputereu_parser_t *parser = NULL; @@ -64,7 +62,7 @@ tecdiving_divecomputereu_parser_create (dc_parser_t **out, dc_context_t *context return DC_STATUS_INVALIDARGS; // Allocate memory. - parser = (tecdiving_divecomputereu_parser_t *) dc_parser_allocate (context, &tecdiving_divecomputereu_parser_vtable); + parser = (tecdiving_divecomputereu_parser_t *) dc_parser_allocate (context, &tecdiving_divecomputereu_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -76,13 +74,6 @@ tecdiving_divecomputereu_parser_create (dc_parser_t **out, dc_context_t *context } -static dc_status_t -tecdiving_divecomputereu_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - return DC_STATUS_SUCCESS; -} - - static dc_status_t tecdiving_divecomputereu_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime) { diff --git a/src/uwatec_memomouse.h b/src/uwatec_memomouse.h index 34ca2d3..e038cf9 100644 --- a/src/uwatec_memomouse.h +++ b/src/uwatec_memomouse.h @@ -35,7 +35,7 @@ dc_status_t uwatec_memomouse_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -uwatec_memomouse_parser_create (dc_parser_t **parser, dc_context_t *context); +uwatec_memomouse_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size); #ifdef __cplusplus } diff --git a/src/uwatec_memomouse_parser.c b/src/uwatec_memomouse_parser.c index 1019c6a..0849a3c 100644 --- a/src/uwatec_memomouse_parser.c +++ b/src/uwatec_memomouse_parser.c @@ -38,7 +38,6 @@ struct uwatec_memomouse_parser_t { dc_ticks_t systime; }; -static dc_status_t uwatec_memomouse_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t uwatec_memomouse_parser_set_clock (dc_parser_t *abstract, unsigned int devtime, dc_ticks_t systime); static dc_status_t uwatec_memomouse_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime); static dc_status_t uwatec_memomouse_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); @@ -47,7 +46,6 @@ static dc_status_t uwatec_memomouse_parser_samples_foreach (dc_parser_t *abstrac static const dc_parser_vtable_t uwatec_memomouse_parser_vtable = { sizeof(uwatec_memomouse_parser_t), DC_FAMILY_UWATEC_MEMOMOUSE, - uwatec_memomouse_parser_set_data, /* set_data */ uwatec_memomouse_parser_set_clock, /* set_clock */ NULL, /* set_atmospheric */ NULL, /* set_density */ @@ -59,7 +57,7 @@ static const dc_parser_vtable_t uwatec_memomouse_parser_vtable = { dc_status_t -uwatec_memomouse_parser_create (dc_parser_t **out, dc_context_t *context) +uwatec_memomouse_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size) { uwatec_memomouse_parser_t *parser = NULL; @@ -67,7 +65,7 @@ uwatec_memomouse_parser_create (dc_parser_t **out, dc_context_t *context) return DC_STATUS_INVALIDARGS; // Allocate memory. - parser = (uwatec_memomouse_parser_t *) dc_parser_allocate (context, &uwatec_memomouse_parser_vtable); + parser = (uwatec_memomouse_parser_t *) dc_parser_allocate (context, &uwatec_memomouse_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -83,13 +81,6 @@ uwatec_memomouse_parser_create (dc_parser_t **out, dc_context_t *context) } -static dc_status_t -uwatec_memomouse_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - return DC_STATUS_SUCCESS; -} - - static dc_status_t uwatec_memomouse_parser_set_clock (dc_parser_t *abstract, unsigned int devtime, dc_ticks_t systime) { diff --git a/src/uwatec_smart.h b/src/uwatec_smart.h index 49013c5..646cc97 100644 --- a/src/uwatec_smart.h +++ b/src/uwatec_smart.h @@ -35,7 +35,7 @@ dc_status_t uwatec_smart_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t -uwatec_smart_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); +uwatec_smart_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model); #ifdef __cplusplus } diff --git a/src/uwatec_smart_parser.c b/src/uwatec_smart_parser.c index d98801b..c6c356d 100644 --- a/src/uwatec_smart_parser.c +++ b/src/uwatec_smart_parser.c @@ -157,7 +157,6 @@ struct uwatec_smart_parser_t { dc_divemode_t divemode; }; -static dc_status_t uwatec_smart_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); static dc_status_t uwatec_smart_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime); static dc_status_t uwatec_smart_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); static dc_status_t uwatec_smart_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata); @@ -167,7 +166,6 @@ static dc_status_t uwatec_smart_parse (uwatec_smart_parser_t *parser, dc_sample_ static const dc_parser_vtable_t uwatec_smart_parser_vtable = { sizeof(uwatec_smart_parser_t), DC_FAMILY_UWATEC_SMART, - uwatec_smart_parser_set_data, /* set_data */ NULL, /* set_clock */ NULL, /* set_atmospheric */ NULL, /* set_density */ @@ -573,7 +571,7 @@ uwatec_smart_parser_cache (uwatec_smart_parser_t *parser) dc_status_t -uwatec_smart_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model) +uwatec_smart_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size, unsigned int model) { dc_status_t status = DC_STATUS_SUCCESS; uwatec_smart_parser_t *parser = NULL; @@ -582,7 +580,7 @@ uwatec_smart_parser_create (dc_parser_t **out, dc_context_t *context, unsigned i return DC_STATUS_INVALIDARGS; // Allocate memory. - parser = (uwatec_smart_parser_t *) dc_parser_allocate (context, &uwatec_smart_parser_vtable); + parser = (uwatec_smart_parser_t *) dc_parser_allocate (context, &uwatec_smart_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; @@ -707,31 +705,6 @@ error_free: } -static dc_status_t -uwatec_smart_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) -{ - uwatec_smart_parser_t *parser = (uwatec_smart_parser_t *) abstract; - - // Reset the cache. - parser->cached = 0; - parser->ngasmixes = 0; - parser->ntanks = 0; - for (unsigned int i = 0; i < NGASMIXES; ++i) { - parser->gasmix[i].id = 0; - parser->gasmix[i].oxygen = 0; - parser->gasmix[i].helium = 0; - parser->tank[i].id = 0; - parser->tank[i].beginpressure = 0; - parser->tank[i].endpressure = 0; - parser->tank[i].gasmix = 0; - } - parser->watertype = DC_WATER_FRESH; - parser->divemode = DC_DIVEMODE_OC; - - return DC_STATUS_SUCCESS; -} - - static dc_status_t uwatec_smart_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime) { From 9b7aa813e0a9291b10e370847c139d19bb4c57b0 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Mon, 15 May 2023 19:48:11 +0200 Subject: [PATCH 11/51] Change the salinity format in the xml output Replace the numeric type with a name (fresh or salt) and change the density value into an xml attribute. The type is the primary information here, while the density value is optional. --- examples/output_xml.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/output_xml.c b/examples/output_xml.c index 7489af6..7d06aae 100644 --- a/examples/output_xml.c +++ b/examples/output_xml.c @@ -450,8 +450,14 @@ dctool_xml_output_write (dctool_output_t *abstract, dc_parser_t *parser, const u } if (status != DC_STATUS_UNSUPPORTED) { - fprintf (output->ostream, "%.1f\n", - salinity.type, salinity.density); + const char *names[] = {"fresh", "salt"}; + if (salinity.density) { + fprintf (output->ostream, "%s\n", + salinity.density, names[salinity.type]); + } else { + fprintf (output->ostream, "%s\n", + names[salinity.type]); + } } // Parse the atmospheric pressure. From ee147afcebb8cb3ff643df52ed65ed36a61a1fa2 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Thu, 22 Jun 2023 20:18:26 +0200 Subject: [PATCH 12/51] Move the model number mapping to a function --- src/shearwater_common.c | 61 +++++++++++++++++++++++++++++++++++++++++ src/shearwater_common.h | 3 ++ src/shearwater_petrel.c | 54 +----------------------------------- 3 files changed, 65 insertions(+), 53 deletions(-) diff --git a/src/shearwater_common.c b/src/shearwater_common.c index a7f67f6..2dfb34a 100644 --- a/src/shearwater_common.c +++ b/src/shearwater_common.c @@ -548,3 +548,64 @@ shearwater_common_identifier (shearwater_common_device_t *device, dc_buffer_t *b return rc; } + +unsigned int +shearwater_common_get_model (shearwater_common_device_t *device, unsigned int hardware) +{ + unsigned int model = 0; + + switch (hardware) { + case 0x0101: + case 0x0202: + model = PREDATOR; + break; + case 0x0404: + case 0x0909: + model = PETREL; + break; + case 0x0505: + case 0x0808: + case 0x0838: + case 0x08A5: + case 0x0B0B: + case 0x7828: + case 0x7B2C: + case 0x8838: + model = PETREL2; + break; + case 0xB407: + model = PETREL3; + break; + case 0x0606: + case 0x0A0A: + model = NERD; + break; + case 0x0E0D: + case 0x7E2D: + model = NERD2; + break; + case 0x0707: + model = PERDIX; + break; + case 0x0C0D: + case 0x7C2D: + case 0x8D6C: + model = PERDIXAI; + break; + case 0xC407: + model = PERDIX2; + break; + case 0x0F0F: + case 0x1F0A: + case 0x1F0F: + model = TERIC; + break; + case 0x1512: + model = PEREGRINE; + break; + default: + WARNING (device->base.context, "Unknown hardware type 0x%04x.", hardware); + } + + return model; +} diff --git a/src/shearwater_common.h b/src/shearwater_common.h index b1f8c3b..dd6b180 100644 --- a/src/shearwater_common.h +++ b/src/shearwater_common.h @@ -67,6 +67,9 @@ shearwater_common_download (shearwater_common_device_t *device, dc_buffer_t *buf dc_status_t shearwater_common_identifier (shearwater_common_device_t *device, dc_buffer_t *buffer, unsigned int id); +unsigned int +shearwater_common_get_model (shearwater_common_device_t *device, unsigned int hardware); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/shearwater_petrel.c b/src/shearwater_petrel.c index c047cca..1e32c17 100644 --- a/src/shearwater_petrel.c +++ b/src/shearwater_petrel.c @@ -210,59 +210,7 @@ shearwater_petrel_device_foreach (dc_device_t *abstract, dc_dive_callback_t call // Convert and map to the model number. unsigned int hardware = array_uint_be (dc_buffer_get_data (buffer), dc_buffer_get_size (buffer)); - unsigned int model = 0; - switch (hardware) { - case 0x0101: - case 0x0202: - model = PREDATOR; - break; - case 0x0404: - case 0x0909: - model = PETREL; - break; - case 0x0505: - case 0x0808: - case 0x0838: - case 0x08A5: - case 0x0B0B: - case 0x7828: - case 0x7B2C: - case 0x8838: - model = PETREL2; - break; - case 0xB407: - model = PETREL3; - break; - case 0x0606: - case 0x0A0A: - model = NERD; - break; - case 0x0E0D: - case 0x7E2D: - model = NERD2; - break; - case 0x0707: - model = PERDIX; - break; - case 0x0C0D: - case 0x7C2D: - case 0x8D6C: - model = PERDIXAI; - break; - case 0xC407: - model = PERDIX2; - break; - case 0x0F0F: - case 0x1F0A: - case 0x1F0F: - model = TERIC; - break; - case 0x1512: - model = PEREGRINE; - break; - default: - WARNING (abstract->context, "Unknown hardware type %04x.", hardware); - } + unsigned int model = shearwater_common_get_model (&device->base, hardware); // Emit a device info event. dc_event_devinfo_t devinfo; From 13705f2b2d62b8e0e126c85ba6d8f6bff5ac6aa2 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Thu, 22 Jun 2023 20:35:47 +0200 Subject: [PATCH 13/51] Use a static buffer for the RDBI function The RDBI (Read Data by Identifier) responses always have a fixed length. Using a resizable buffer for the API only makes the memory management more complex than necessary. Also add some symbolic constants to improve readability. --- src/shearwater_common.c | 39 ++++++++++++++------------- src/shearwater_common.h | 2 +- src/shearwater_petrel.c | 59 +++++++++++++++-------------------------- 3 files changed, 43 insertions(+), 57 deletions(-) diff --git a/src/shearwater_common.c b/src/shearwater_common.c index 2dfb34a..c184bb3 100644 --- a/src/shearwater_common.c +++ b/src/shearwater_common.c @@ -36,6 +36,9 @@ #define ESC_END 0xDC #define ESC_ESC 0xDD +#define RDBI_REQUEST 0x22 +#define RDBI_RESPONSE 0x62 + dc_status_t shearwater_common_setup (shearwater_common_device_t *device, dc_context_t *context, dc_iostream_t *iostream) { @@ -512,41 +515,41 @@ shearwater_common_download (shearwater_common_device_t *device, dc_buffer_t *buf dc_status_t -shearwater_common_identifier (shearwater_common_device_t *device, dc_buffer_t *buffer, unsigned int id) +shearwater_common_rdbi (shearwater_common_device_t *device, unsigned int id, unsigned char data[], unsigned int size) { + dc_status_t status = DC_STATUS_SUCCESS; dc_device_t *abstract = (dc_device_t *) device; - dc_status_t rc = DC_STATUS_SUCCESS; - - // Erase the buffer. - if (!dc_buffer_clear (buffer)) { - ERROR (abstract->context, "Insufficient buffer space available."); - return DC_STATUS_NOMEMORY; - } // Transfer the request. unsigned int n = 0; - unsigned char request[] = {0x22, + unsigned char request[] = { + RDBI_REQUEST, (id >> 8) & 0xFF, (id ) & 0xFF}; unsigned char response[SZ_PACKET]; - rc = shearwater_common_transfer (device, request, sizeof (request), response, sizeof (response), &n); - if (rc != DC_STATUS_SUCCESS) { - return rc; + status = shearwater_common_transfer (device, request, sizeof (request), response, sizeof (response), &n); + if (status != DC_STATUS_SUCCESS) { + return status; } // Verify the response. - if (n < 3 || response[0] != 0x62 || response[1] != request[1] || response[2] != request[2]) { + if (n < 3 || response[0] != RDBI_RESPONSE || response[1] != request[1] || response[2] != request[2]) { ERROR (abstract->context, "Unexpected response packet."); return DC_STATUS_PROTOCOL; } - // Append the packet to the output buffer. - if (!dc_buffer_append (buffer, response + 3, n - 3)) { - ERROR (abstract->context, "Insufficient buffer space available."); - return DC_STATUS_NOMEMORY; + unsigned int length = n - 3; + + if (length != size) { + ERROR (abstract->context, "Unexpected packet size (%u bytes).", length); + return DC_STATUS_PROTOCOL; } - return rc; + if (length) { + memcpy (data, response + 3, length); + } + + return status; } unsigned int diff --git a/src/shearwater_common.h b/src/shearwater_common.h index dd6b180..8f8e356 100644 --- a/src/shearwater_common.h +++ b/src/shearwater_common.h @@ -65,7 +65,7 @@ dc_status_t shearwater_common_download (shearwater_common_device_t *device, dc_buffer_t *buffer, unsigned int address, unsigned int size, unsigned int compression, dc_event_progress_t *progress); dc_status_t -shearwater_common_identifier (shearwater_common_device_t *device, dc_buffer_t *buffer, unsigned int id); +shearwater_common_rdbi (shearwater_common_device_t *device, unsigned int id, unsigned char data[], unsigned int size); unsigned int shearwater_common_get_model (shearwater_common_device_t *device, unsigned int hardware); diff --git a/src/shearwater_petrel.c b/src/shearwater_petrel.c index 1e32c17..0d91c03 100644 --- a/src/shearwater_petrel.c +++ b/src/shearwater_petrel.c @@ -152,64 +152,47 @@ shearwater_petrel_device_foreach (dc_device_t *abstract, dc_dive_callback_t call shearwater_petrel_device_t *device = (shearwater_petrel_device_t *) abstract; dc_status_t rc = DC_STATUS_SUCCESS; - // Allocate memory buffers for the manifests. - dc_buffer_t *buffer = dc_buffer_new (MANIFEST_SIZE); - dc_buffer_t *manifests = dc_buffer_new (MANIFEST_SIZE); - if (buffer == NULL || manifests == NULL) { - ERROR (abstract->context, "Insufficient buffer space available."); - dc_buffer_free (buffer); - dc_buffer_free (manifests); - return DC_STATUS_NOMEMORY; - } - // Enable progress notifications. unsigned int current = 0, maximum = 0; dc_event_progress_t progress = EVENT_PROGRESS_INITIALIZER; device_event_emit (abstract, DC_EVENT_PROGRESS, &progress); // Read the serial number. - rc = shearwater_common_identifier (&device->base, buffer, ID_SERIAL); + unsigned char rsp_serial[8] = {0}; + rc = shearwater_common_rdbi (&device->base, ID_SERIAL, rsp_serial, sizeof(rsp_serial)); if (rc != DC_STATUS_SUCCESS) { ERROR (abstract->context, "Failed to read the serial number."); - dc_buffer_free (buffer); - dc_buffer_free (manifests); return rc; } // Convert to a number. unsigned char serial[4] = {0}; - if (array_convert_hex2bin (dc_buffer_get_data (buffer), dc_buffer_get_size (buffer), - serial, sizeof (serial)) != 0 ) { + if (array_convert_hex2bin (rsp_serial, sizeof(rsp_serial), serial, sizeof (serial)) != 0 ) { ERROR (abstract->context, "Failed to convert the serial number."); - dc_buffer_free (buffer); - dc_buffer_free (manifests); return DC_STATUS_DATAFORMAT; - } // Read the firmware version. - rc = shearwater_common_identifier (&device->base, buffer, ID_FIRMWARE); + unsigned char rsp_firmware[11] = {0}; + rc = shearwater_common_rdbi (&device->base, ID_FIRMWARE, rsp_firmware, sizeof(rsp_firmware)); if (rc != DC_STATUS_SUCCESS) { ERROR (abstract->context, "Failed to read the firmware version."); - dc_buffer_free (buffer); - dc_buffer_free (manifests); return rc; } // Convert to a number. - unsigned int firmware = str2num (dc_buffer_get_data (buffer), dc_buffer_get_size (buffer), 1); + unsigned int firmware = str2num (rsp_firmware, sizeof(rsp_firmware), 1); // Read the hardware type. - rc = shearwater_common_identifier (&device->base, buffer, ID_HARDWARE); + unsigned char rsp_hardware[2] = {0}; + rc = shearwater_common_rdbi (&device->base, ID_HARDWARE, rsp_hardware, sizeof(rsp_hardware)); if (rc != DC_STATUS_SUCCESS) { ERROR (abstract->context, "Failed to read the hardware type."); - dc_buffer_free (buffer); - dc_buffer_free (manifests); return rc; } // Convert and map to the model number. - unsigned int hardware = array_uint_be (dc_buffer_get_data (buffer), dc_buffer_get_size (buffer)); + unsigned int hardware = array_uint16_be (rsp_hardware); unsigned int model = shearwater_common_get_model (&device->base, hardware); // Emit a device info event. @@ -220,22 +203,14 @@ shearwater_petrel_device_foreach (dc_device_t *abstract, dc_dive_callback_t call device_event_emit (abstract, DC_EVENT_DEVINFO, &devinfo); // Read the logbook type - rc = shearwater_common_identifier (&device->base, buffer, ID_LOGUPLOAD); + unsigned char rsp_logupload[9] = {0}; + rc = shearwater_common_rdbi (&device->base, ID_LOGUPLOAD, rsp_logupload, sizeof(rsp_logupload)); if (rc != DC_STATUS_SUCCESS) { ERROR (abstract->context, "Failed to read the logbook type."); - dc_buffer_free (buffer); - dc_buffer_free (manifests); return rc; } - if (dc_buffer_get_size (buffer) != 9) { - ERROR (abstract->context, "Unexpected packet size (" DC_PRINTF_SIZE " bytes).", dc_buffer_get_size(buffer)); - dc_buffer_free (buffer); - dc_buffer_free (manifests); - return DC_STATUS_DATAFORMAT; - } - - unsigned int base_addr = array_uint32_be (dc_buffer_get_data (buffer) + 1); + unsigned int base_addr = array_uint32_be (rsp_logupload + 1); switch (base_addr) { case 0xDD000000: // Predator - we shouldn't get here, we could give up or we can try 0xC0000000 case 0xC0000000: // Predator-Like Format (what we used to call the Petrel format) @@ -248,9 +223,17 @@ shearwater_petrel_device_foreach (dc_device_t *abstract, dc_dive_callback_t call break; default: // unknown format ERROR (abstract->context, "Unknown logbook format %08x", base_addr); + return DC_STATUS_DATAFORMAT; + } + + // Allocate memory buffers for the manifests. + dc_buffer_t *buffer = dc_buffer_new (MANIFEST_SIZE); + dc_buffer_t *manifests = dc_buffer_new (MANIFEST_SIZE); + if (buffer == NULL || manifests == NULL) { + ERROR (abstract->context, "Insufficient buffer space available."); dc_buffer_free (buffer); dc_buffer_free (manifests); - return DC_STATUS_DATAFORMAT; + return DC_STATUS_NOMEMORY; } // Read the manifest pages From d4402aa29606866476f982c6667f3deba94b9593 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Thu, 22 Jun 2023 20:42:12 +0200 Subject: [PATCH 14/51] Add support for the WDBI function The RDBI (Read Data by Identifier) has a WDBI (Write Data by Identifier) counterpart, which supports changing settings on the dive computer. --- src/shearwater_common.c | 37 +++++++++++++++++++++++++++++++++++++ src/shearwater_common.h | 3 +++ 2 files changed, 40 insertions(+) diff --git a/src/shearwater_common.c b/src/shearwater_common.c index c184bb3..7a47f58 100644 --- a/src/shearwater_common.c +++ b/src/shearwater_common.c @@ -39,6 +39,9 @@ #define RDBI_REQUEST 0x22 #define RDBI_RESPONSE 0x62 +#define WDBI_REQUEST 0x2E +#define WDBI_RESPONSE 0x6E + dc_status_t shearwater_common_setup (shearwater_common_device_t *device, dc_context_t *context, dc_iostream_t *iostream) { @@ -552,6 +555,40 @@ shearwater_common_rdbi (shearwater_common_device_t *device, unsigned int id, uns return status; } +dc_status_t +shearwater_common_wdbi (shearwater_common_device_t *device, unsigned int id, const unsigned char data[], unsigned int size) +{ + dc_status_t status = DC_STATUS_SUCCESS; + dc_device_t *abstract = (dc_device_t *) device; + + if (size + 3 > SZ_PACKET) { + return DC_STATUS_INVALIDARGS; + } + + // Transfer the request. + unsigned int n = 0; + unsigned char request[SZ_PACKET] = { + WDBI_REQUEST, + (id >> 8) & 0xFF, + (id ) & 0xFF}; + if (size) { + memcpy (request + 3, data, size); + } + unsigned char response[SZ_PACKET]; + status = shearwater_common_transfer (device, request, size + 3, response, sizeof (response), &n); + if (status != DC_STATUS_SUCCESS) { + return status; + } + + // Verify the response. + if (n < 3 || response[0] != WDBI_RESPONSE || response[1] != request[1] || response[2] != request[2]) { + ERROR (abstract->context, "Unexpected response packet."); + return DC_STATUS_PROTOCOL; + } + + return status; +} + unsigned int shearwater_common_get_model (shearwater_common_device_t *device, unsigned int hardware) { diff --git a/src/shearwater_common.h b/src/shearwater_common.h index 8f8e356..1c25b75 100644 --- a/src/shearwater_common.h +++ b/src/shearwater_common.h @@ -67,6 +67,9 @@ shearwater_common_download (shearwater_common_device_t *device, dc_buffer_t *buf dc_status_t shearwater_common_rdbi (shearwater_common_device_t *device, unsigned int id, unsigned char data[], unsigned int size); +dc_status_t +shearwater_common_wdbi (shearwater_common_device_t *device, unsigned int id, const unsigned char data[], unsigned int size); + unsigned int shearwater_common_get_model (shearwater_common_device_t *device, unsigned int hardware); From c16530b8ab34f73e5506a1be25c3e521c819f7ed Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Thu, 22 Jun 2023 21:16:08 +0200 Subject: [PATCH 15/51] Detect negative response packets When the dive computer receives an RDBI or WDBI command it doesn't support, it sends a 3 byte NAK packet containing an error code. Detect these NAK packets and use it to return a more appropriate error. --- src/shearwater_common.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/shearwater_common.c b/src/shearwater_common.c index 7a47f58..1e2a65b 100644 --- a/src/shearwater_common.c +++ b/src/shearwater_common.c @@ -42,6 +42,8 @@ #define WDBI_REQUEST 0x2E #define WDBI_RESPONSE 0x6E +#define NAK 0x7F + dc_status_t shearwater_common_setup (shearwater_common_device_t *device, dc_context_t *context, dc_iostream_t *iostream) { @@ -537,6 +539,10 @@ shearwater_common_rdbi (shearwater_common_device_t *device, unsigned int id, uns // Verify the response. if (n < 3 || response[0] != RDBI_RESPONSE || response[1] != request[1] || response[2] != request[2]) { + if (n == 3 && response[0] == NAK && response[1] == RDBI_REQUEST) { + ERROR (abstract->context, "Received NAK packet with error code 0x%02x.", response[2]); + return DC_STATUS_UNSUPPORTED; + } ERROR (abstract->context, "Unexpected response packet."); return DC_STATUS_PROTOCOL; } @@ -582,6 +588,10 @@ shearwater_common_wdbi (shearwater_common_device_t *device, unsigned int id, con // Verify the response. if (n < 3 || response[0] != WDBI_RESPONSE || response[1] != request[1] || response[2] != request[2]) { + if (n == 3 && response[0] == NAK && response[1] == WDBI_REQUEST) { + ERROR (abstract->context, "Received NAK packet with error code 0x%02x.", response[2]); + return DC_STATUS_UNSUPPORTED; + } ERROR (abstract->context, "Unexpected response packet."); return DC_STATUS_PROTOCOL; } From 25bd1f98536f16e71c32e91d7c879957d07063c0 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Thu, 22 Jun 2023 21:23:28 +0200 Subject: [PATCH 16/51] Add support for time synchronization Add time synchronisation for the Shearwater dive computers. All models support setting the local time. Only the Teric has basic support for time zones, and can set UTC time with a timezone offset. Co-authored-by: Michael Keller --- src/shearwater_common.c | 85 +++++++++++++++++++++++++++++++++++++++ src/shearwater_common.h | 11 +++++ src/shearwater_petrel.c | 28 ++++++++++++- src/shearwater_predator.c | 9 ++++- 4 files changed, 131 insertions(+), 2 deletions(-) diff --git a/src/shearwater_common.c b/src/shearwater_common.c index 1e2a65b..ca3f237 100644 --- a/src/shearwater_common.c +++ b/src/shearwater_common.c @@ -599,6 +599,91 @@ shearwater_common_wdbi (shearwater_common_device_t *device, unsigned int id, con return status; } +dc_status_t +shearwater_common_timesync_local (shearwater_common_device_t *device, const dc_datetime_t *datetime) +{ + dc_status_t status = DC_STATUS_SUCCESS; + dc_device_t *abstract = (dc_device_t *) device; + + // Convert to local time. + dc_datetime_t local = *datetime; + local.timezone = DC_TIMEZONE_NONE; + + dc_ticks_t ticks = dc_datetime_mktime (&local); + if (ticks == -1) { + ERROR (abstract->context, "Invalid date/time value specified."); + return DC_STATUS_INVALIDARGS; + } + + const unsigned char timestamp[] = { + (ticks >> 24) & 0xFF, + (ticks >> 16) & 0xFF, + (ticks >> 8) & 0xFF, + (ticks ) & 0xFF, + }; + + status = shearwater_common_wdbi (device, ID_TIME_LOCAL, timestamp, sizeof(timestamp)); + if (status != DC_STATUS_SUCCESS) { + ERROR (abstract->context, "Failed to write the dive computer local time."); + return status; + } + + return status; +} + +dc_status_t +shearwater_common_timesync_utc (shearwater_common_device_t *device, const dc_datetime_t *datetime) +{ + dc_status_t status = DC_STATUS_SUCCESS; + dc_device_t *abstract = (dc_device_t *) device; + + // Convert to UTC time. + dc_ticks_t ticks = dc_datetime_mktime (datetime); + if (ticks == -1) { + ERROR (abstract->context, "Invalid date/time value specified."); + return DC_STATUS_INVALIDARGS; + } + + const unsigned char timestamp[] = { + (ticks >> 24) & 0xFF, + (ticks >> 16) & 0xFF, + (ticks >> 8) & 0xFF, + (ticks ) & 0xFF, + }; + + status = shearwater_common_wdbi (device, ID_TIME_UTC, timestamp, sizeof(timestamp)); + if (status != DC_STATUS_SUCCESS) { + ERROR (abstract->context, "Failed to write the dive computer UTC time."); + return status; + } + + int timezone = datetime->timezone / 60; + const unsigned char offset[] = { + (timezone >> 24) & 0xFF, + (timezone >> 16) & 0xFF, + (timezone >> 8) & 0xFF, + (timezone ) & 0xFF, + }; + + status = shearwater_common_wdbi (device, ID_TIME_OFFSET, offset, sizeof (offset)); + if (status != DC_STATUS_SUCCESS) { + ERROR (abstract->context, "Failed to write the dive computer timezone offset."); + return status; + } + + // We don't have a way to determine the daylight savings time setting, + // but the required offset is already factored into the timezone offset. + const unsigned char dst[] = {0, 0, 0, 0}; + + status = shearwater_common_wdbi (device, ID_TIME_DST, dst, sizeof (dst)); + if (status != DC_STATUS_SUCCESS) { + ERROR (abstract->context, "Failed to write the dive computer DST setting."); + return status; + } + + return status; +} + unsigned int shearwater_common_get_model (shearwater_common_device_t *device, unsigned int hardware) { diff --git a/src/shearwater_common.h b/src/shearwater_common.h index 1c25b75..4c7f186 100644 --- a/src/shearwater_common.h +++ b/src/shearwater_common.h @@ -35,6 +35,11 @@ extern "C" { #define ID_LOGUPLOAD 0x8021 #define ID_HARDWARE 0x8050 +#define ID_TIME_LOCAL 0x9030 +#define ID_TIME_UTC 0x9031 +#define ID_TIME_OFFSET 0x9032 +#define ID_TIME_DST 0x9033 + #define PREDATOR 2 #define PETREL 3 #define PETREL2 PETREL @@ -70,6 +75,12 @@ shearwater_common_rdbi (shearwater_common_device_t *device, unsigned int id, uns dc_status_t shearwater_common_wdbi (shearwater_common_device_t *device, unsigned int id, const unsigned char data[], unsigned int size); +dc_status_t +shearwater_common_timesync_local (shearwater_common_device_t *device, const dc_datetime_t *datetime); + +dc_status_t +shearwater_common_timesync_utc (shearwater_common_device_t *device, const dc_datetime_t *datetime); + unsigned int shearwater_common_get_model (shearwater_common_device_t *device, unsigned int hardware); diff --git a/src/shearwater_petrel.c b/src/shearwater_petrel.c index 0d91c03..7ec18ff 100644 --- a/src/shearwater_petrel.c +++ b/src/shearwater_petrel.c @@ -46,6 +46,7 @@ typedef struct shearwater_petrel_device_t { static dc_status_t shearwater_petrel_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size); static dc_status_t shearwater_petrel_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata); +static dc_status_t shearwater_petrel_device_timesync (dc_device_t *abstract, const dc_datetime_t *datetime); static dc_status_t shearwater_petrel_device_close (dc_device_t *abstract); static const dc_device_vtable_t shearwater_petrel_device_vtable = { @@ -56,7 +57,7 @@ static const dc_device_vtable_t shearwater_petrel_device_vtable = { NULL, /* write */ NULL, /* dump */ shearwater_petrel_device_foreach, /* foreach */ - NULL, /* timesync */ + shearwater_petrel_device_timesync, shearwater_petrel_device_close /* close */ }; @@ -350,3 +351,28 @@ shearwater_petrel_device_foreach (dc_device_t *abstract, dc_dive_callback_t call return rc; } + +static dc_status_t +shearwater_petrel_device_timesync (dc_device_t *abstract, const dc_datetime_t *datetime) +{ + dc_status_t status = DC_STATUS_SUCCESS; + shearwater_common_device_t *device = (shearwater_common_device_t *) abstract; + + // Read the hardware type. + unsigned char rsp_hardware[2] = {0}; + status = shearwater_common_rdbi (device, ID_HARDWARE, rsp_hardware, sizeof(rsp_hardware)); + if (status != DC_STATUS_SUCCESS) { + ERROR (abstract->context, "Failed to read the hardware type."); + return status; + } + + // Convert and map to the model number. + unsigned int hardware = array_uint16_be (rsp_hardware); + unsigned int model = shearwater_common_get_model (device, hardware); + + if (model == TERIC) { + return shearwater_common_timesync_utc (device, datetime); + } else { + return shearwater_common_timesync_local (device, datetime); + } +} diff --git a/src/shearwater_predator.c b/src/shearwater_predator.c index d4c97b4..fffd511 100644 --- a/src/shearwater_predator.c +++ b/src/shearwater_predator.c @@ -44,6 +44,7 @@ typedef struct shearwater_predator_device_t { static dc_status_t shearwater_predator_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size); static dc_status_t shearwater_predator_device_dump (dc_device_t *abstract, dc_buffer_t *buffer); static dc_status_t shearwater_predator_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata); +static dc_status_t shearwater_predator_device_timesync (dc_device_t *abstract, const dc_datetime_t *datetime); static const dc_device_vtable_t shearwater_predator_device_vtable = { sizeof(shearwater_predator_device_t), @@ -53,7 +54,7 @@ static const dc_device_vtable_t shearwater_predator_device_vtable = { NULL, /* write */ shearwater_predator_device_dump, /* dump */ shearwater_predator_device_foreach, /* foreach */ - NULL, /* timesync */ + shearwater_predator_device_timesync, NULL /* close */ }; @@ -357,3 +358,9 @@ shearwater_predator_extract_dives (dc_device_t *abstract, const unsigned char da return shearwater_predator_extract_predator (abstract, data, size, callback, userdata); } } + +static dc_status_t +shearwater_predator_device_timesync (dc_device_t *abstract, const dc_datetime_t *datetime) +{ + return shearwater_common_timesync_local ((shearwater_common_device_t *) abstract, datetime); +} From ff0328537ec18ee92bd4f0538f629b1795a52772 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Wed, 5 Jul 2023 23:54:16 +0200 Subject: [PATCH 17/51] Ignore the diluents for open-circuit dives For open-circuit dives it makes no sense to also include the configured diluents. Usually those diluents are only present because the diver uses the same dive computer for both open and closed circuit dives. --- src/shearwater_predator_parser.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/shearwater_predator_parser.c b/src/shearwater_predator_parser.c index 749fe3c..b6aa7e2 100644 --- a/src/shearwater_predator_parser.c +++ b/src/shearwater_predator_parser.c @@ -659,6 +659,9 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser) for (unsigned int i = 0; i < ngasmixes; ++i) { if (gasmix[i].oxygen == 0 && gasmix[i].helium == 0) continue; + if (gasmix[i].diluent && + (divemode != M_CC && divemode != M_CC2 && divemode != M_SC)) + continue; parser->gasmix[parser->ngasmixes] = gasmix[i]; parser->ngasmixes++; } From 3a68af418eb40979029ca00b401c7ecffea96b5f Mon Sep 17 00:00:00 2001 From: Michael Keller Date: Thu, 6 Jul 2023 23:07:31 +0200 Subject: [PATCH 18/51] Fix the OSTC4 firmware upgrade In commit 1c8cd096b57a876c4fb0afc5113aac05d75d924e the block size was changed from 64 to 1024 bytes. For bluetooth classic communication, this shouldn't matter, but for some reason it does cause the OSTC4 firmware upgrade to fail. Maybe some buffering problem in the OSTC4 firmware or bluetooth stack? Change the block size back to 64 bytes. --- src/hw_ostc3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hw_ostc3.c b/src/hw_ostc3.c index f4bac54..170aa30 100644 --- a/src/hw_ostc3.c +++ b/src/hw_ostc3.c @@ -240,7 +240,7 @@ hw_ostc3_write (hw_ostc3_device_t *device, dc_event_progress_t *progress, const size_t nbytes = 0; while (nbytes < size) { // Set the maximum packet size. - size_t length = 1024; + size_t length = (device->hardware == OSTC4) ? 64 : 1024; // Limit the packet size to the total size. if (nbytes + length > size) From 0afd62d7af629671bff6f453811d10af975d2b2f Mon Sep 17 00:00:00 2001 From: Michael Keller Date: Thu, 6 Jul 2023 23:16:12 +0200 Subject: [PATCH 19/51] Return an error for the OSTC4 memory dump The OSTC4 does not support downloading memory dumps. --- src/hw_ostc3.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/hw_ostc3.c b/src/hw_ostc3.c index 170aa30..4ec278d 100644 --- a/src/hw_ostc3.c +++ b/src/hw_ostc3.c @@ -1715,6 +1715,10 @@ hw_ostc3_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) return rc; } + if (device->hardware == OSTC4) { + return DC_STATUS_UNSUPPORTED; + } + // Emit a device info event. dc_event_devinfo_t devinfo; devinfo.firmware = device->firmware; From ceaaba3e778677237f9f8a4a26d9f47a63483303 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Mon, 10 Jul 2023 18:26:38 +0200 Subject: [PATCH 20/51] Add support for the new Ratio iX3M 2 models Except for the new prefix in the bluetooth name, the new models are backwards compatible with the previous models. --- src/descriptor.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/descriptor.c b/src/descriptor.c index c62baa3..ead1a8a 100644 --- a/src/descriptor.c +++ b/src/descriptor.c @@ -414,6 +414,20 @@ static const dc_descriptor_t g_descriptors[] = { {"Ratio", "iX3M 2021 Pro Deep", DC_FAMILY_DIVESYSTEM_IDIVE, 0x73, DC_TRANSPORT_SERIAL, NULL}, {"Ratio", "iX3M 2021 Pro Tech+", DC_FAMILY_DIVESYSTEM_IDIVE, 0x74, DC_TRANSPORT_SERIAL, NULL}, {"Ratio", "iX3M 2021 Pro Reb", DC_FAMILY_DIVESYSTEM_IDIVE, 0x75, DC_TRANSPORT_SERIAL, NULL}, + {"Ratio", "iDive 2 Free", DC_FAMILY_DIVESYSTEM_IDIVE, 0x80, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLE, dc_filter_divesystem}, + {"Ratio", "iDive 2 Fancy", DC_FAMILY_DIVESYSTEM_IDIVE, 0x81, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLE, dc_filter_divesystem}, + {"Ratio", "iDive 2 Easy", DC_FAMILY_DIVESYSTEM_IDIVE, 0x82, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLE, dc_filter_divesystem}, + {"Ratio", "iDive 2 Pro", DC_FAMILY_DIVESYSTEM_IDIVE, 0x83, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLE, dc_filter_divesystem}, + {"Ratio", "iDive 2 Deep", DC_FAMILY_DIVESYSTEM_IDIVE, 0x84, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLE, dc_filter_divesystem}, + {"Ratio", "iDive 2 Tech", DC_FAMILY_DIVESYSTEM_IDIVE, 0x85, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLE, dc_filter_divesystem}, + {"Ratio", "iDive 2 Reb", DC_FAMILY_DIVESYSTEM_IDIVE, 0x86, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLE, dc_filter_divesystem}, + {"Ratio", "iX3M 2 GPS Gauge", DC_FAMILY_DIVESYSTEM_IDIVE, 0x90, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLE, dc_filter_divesystem}, + {"Ratio", "iX3M 2 GPS Easy", DC_FAMILY_DIVESYSTEM_IDIVE, 0x91, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLE, dc_filter_divesystem}, + {"Ratio", "iX3M 2 GPS Pro", DC_FAMILY_DIVESYSTEM_IDIVE, 0x92, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLE, dc_filter_divesystem}, + {"Ratio", "iX3M 2 GPS Deep", DC_FAMILY_DIVESYSTEM_IDIVE, 0x93, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLE, dc_filter_divesystem}, + {"Ratio", "iX3M 2 GPS Tech", DC_FAMILY_DIVESYSTEM_IDIVE, 0x94, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLE, dc_filter_divesystem}, + {"Ratio", "iX3M 2 GPS Reb", DC_FAMILY_DIVESYSTEM_IDIVE, 0x95, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLE, dc_filter_divesystem}, + {"Ratio", "ATOM", DC_FAMILY_DIVESYSTEM_IDIVE, 0x96, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLE, dc_filter_divesystem}, {"Ratio", "iX3M 2 Gauge", DC_FAMILY_DIVESYSTEM_IDIVE, 0x100, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLE, dc_filter_divesystem}, {"Ratio", "iX3M 2 Easy", DC_FAMILY_DIVESYSTEM_IDIVE, 0x101, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLE, dc_filter_divesystem}, {"Ratio", "iX3M 2 Pro", DC_FAMILY_DIVESYSTEM_IDIVE, 0x102, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLE, dc_filter_divesystem}, @@ -691,6 +705,7 @@ static int dc_filter_divesystem (dc_transport_t transport, const void *userdata, static const char * const bluetooth[] = { "DS", "IX5M", + "RATIO-", }; if (transport == DC_TRANSPORT_BLUETOOTH || transport == DC_TRANSPORT_BLE) { From f818a5a92a08e147be5252864f6f8a1868e0fbcc Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Mon, 10 Jul 2023 17:52:23 +0200 Subject: [PATCH 21/51] Add a function for detecting CCR dives --- src/shearwater_predator_parser.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/shearwater_predator_parser.c b/src/shearwater_predator_parser.c index b6aa7e2..534d8e0 100644 --- a/src/shearwater_predator_parser.c +++ b/src/shearwater_predator_parser.c @@ -179,6 +179,12 @@ static const dc_parser_vtable_t shearwater_petrel_parser_vtable = { }; +static unsigned int +shearwater_predator_is_ccr (unsigned int divemode) +{ + return divemode == M_CC || divemode == M_CC2 || divemode == M_SC; +} + static unsigned int shearwater_predator_find_gasmix (shearwater_predator_parser_t *parser, unsigned int o2, unsigned int he, unsigned int dil) { @@ -659,8 +665,7 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser) for (unsigned int i = 0; i < ngasmixes; ++i) { if (gasmix[i].oxygen == 0 && gasmix[i].helium == 0) continue; - if (gasmix[i].diluent && - (divemode != M_CC && divemode != M_CC2 && divemode != M_SC)) + if (gasmix[i].diluent && !shearwater_predator_is_ccr (divemode)) continue; parser->gasmix[parser->ngasmixes] = gasmix[i]; parser->ngasmixes++; From f77e9c03fc1e46f4c6e7e4172ae9507faea8fb40 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Mon, 10 Jul 2023 17:53:13 +0200 Subject: [PATCH 22/51] Restrict the oxygen/diluent usage to CCR dives For open-circuit dives, the oxygen and diluent usage doesn't make any sense at all. But when an open-circuit diver uses the letter 'D' to indicate a tank for decompression use, it will get incorrectly labeled as a diluent tank. Fixed by restricting the oxygen/diluent usage to CCR dives only. --- src/shearwater_predator_parser.c | 33 +++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/shearwater_predator_parser.c b/src/shearwater_predator_parser.c index 534d8e0..d1a1cd6 100644 --- a/src/shearwater_predator_parser.c +++ b/src/shearwater_predator_parser.c @@ -746,21 +746,24 @@ shearwater_predator_parser_get_field (dc_parser_t *abstract, dc_field_type_t typ tank->beginpressure = parser->tank[flags].beginpressure * 2 * PSI / BAR; tank->endpressure = parser->tank[flags].endpressure * 2 * PSI / BAR; tank->gasmix = DC_GASMIX_UNKNOWN; - switch (parser->tank[flags].name[0]) { - case 'S': - tank->usage = DC_USAGE_SIDEMOUNT; - break; - case 'O': - tank->usage = DC_USAGE_OXYGEN; - break; - case 'D': - tank->usage = DC_USAGE_DILUENT; - break; - case 'T': - case 'B': - default: - tank->usage = DC_USAGE_NONE; - break; + if (shearwater_predator_is_ccr (parser->divemode)) { + switch (parser->tank[flags].name[0]) { + case 'O': + tank->usage = DC_USAGE_OXYGEN; + break; + case 'D': + tank->usage = DC_USAGE_DILUENT; + break; + default: + tank->usage = DC_USAGE_NONE; + break; + } + } else { + if (parser->tank[flags].name[0] == 'S') { + tank->usage = DC_USAGE_SIDEMOUNT; + } else { + tank->usage = DC_USAGE_NONE; + } } break; case DC_FIELD_SALINITY: From a4cd21b811bf2cf025bdfc79bd877bedbae1578d Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Thu, 6 Jul 2023 22:27:05 +0200 Subject: [PATCH 23/51] 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. --- src/array.c | 11 +++++++++++ src/array.h | 3 +++ src/shearwater_predator_parser.c | 16 +++++++++++----- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/array.c b/src/array.c index 29f5faf..f47c3eb 100644 --- a/src/array.c +++ b/src/array.c @@ -404,3 +404,14 @@ signextend (unsigned int value, unsigned int nbits) else return value & mask; } + +unsigned int +popcount (unsigned int value) +{ + unsigned int count = 0; + while (value) { + value &= value - 1; + count++; + } + return count; +} diff --git a/src/array.h b/src/array.h index a6ef21e..fab1475 100644 --- a/src/array.h +++ b/src/array.h @@ -126,6 +126,9 @@ dec2bcd (unsigned char value); unsigned int signextend (unsigned int value, unsigned int nbits); +unsigned int +popcount (unsigned int value); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/shearwater_predator_parser.c b/src/shearwater_predator_parser.c index d1a1cd6..2bf4e3a 100644 --- a/src/shearwater_predator_parser.c +++ b/src/shearwater_predator_parser.c @@ -118,6 +118,7 @@ typedef struct shearwater_predator_tank_t { unsigned int pressure_reserve; unsigned int serial; char name[2]; + dc_usage_t usage; } shearwater_predator_tank_t; struct shearwater_predator_parser_t { @@ -254,6 +255,7 @@ shearwater_common_parser_create (dc_parser_t **out, dc_context_t *context, const parser->tank[i].pressure_reserve = 0; parser->tank[i].serial = 0; memset (parser->tank[i].name, 0, sizeof (parser->tank[i].name)); + parser->tank[i].usage = DC_USAGE_NONE; parser->tankidx[i] = i; } parser->aimode = AI_OFF; @@ -547,6 +549,14 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser) } } } + unsigned int gtrmode = data[offset + 29]; + if (popcount(gtrmode) >= 2) { + for (unsigned int i = 0; i < 4; ++i) { + if (gtrmode & (1 << i)) { + tank[i].usage = DC_USAGE_SIDEMOUNT; + } + } + } } else if (type == LOG_RECORD_OPENING_5) { if (logversion >= 9) { 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 break; } } else { - if (parser->tank[flags].name[0] == 'S') { - tank->usage = DC_USAGE_SIDEMOUNT; - } else { - tank->usage = DC_USAGE_NONE; - } + tank->usage = parser->tank[flags].usage; } break; case DC_FIELD_SALINITY: From 9bc742d3acdb456f6d3aad9669cdf8896e8e9793 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Sun, 16 Jul 2023 23:59:15 +0200 Subject: [PATCH 24/51] Use the HP CCR data for the oxygen/diluent usage For dives in HP CCR mode, the oxygen and diluent tanks are stored at a fixed index. This information is more reliable than using the tank name, and also prevents the incorrect labeling of one of the other tanks as an oxygen or diluent tank. --- src/shearwater_predator_parser.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/shearwater_predator_parser.c b/src/shearwater_predator_parser.c index 2bf4e3a..fc06b66 100644 --- a/src/shearwater_predator_parser.c +++ b/src/shearwater_predator_parser.c @@ -141,6 +141,7 @@ struct shearwater_predator_parser_t { shearwater_predator_tank_t tank[NTANKS]; unsigned int tankidx[NTANKS]; unsigned int aimode; + unsigned int hpccr; unsigned int calibrated; double calibration[3]; unsigned int divemode; @@ -259,6 +260,7 @@ shearwater_common_parser_create (dc_parser_t **out, dc_context_t *context, const parser->tankidx[i] = i; } parser->aimode = AI_OFF; + parser->hpccr = 0; parser->calibrated = 0; for (unsigned int i = 0; i < 3; ++i) { parser->calibration[i] = 0.0; @@ -387,6 +389,7 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser) shearwater_predator_tank_t tank[NTANKS] = {0}; unsigned int o2_previous = UNDEFINED, he_previous = UNDEFINED, dil_previous = UNDEFINED; unsigned int aimode = AI_OFF; + unsigned int hpccr = 0; if (!pnf) { for (unsigned int i = 0; i < NFIXED; ++i) { gasmix[i].oxygen = data[20 + i]; @@ -498,8 +501,8 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser) tank[id].enabled = 1; tank[id].beginpressure = pressure; tank[id].endpressure = pressure; - tank[id].name[0] = i == 0 ? 'D': 'O'; - tank[id].name[1] = 0; + tank[id].usage = i == 0 ? DC_USAGE_DILUENT : DC_USAGE_OXYGEN; + hpccr = 1; } tank[id].endpressure = pressure; } @@ -543,9 +546,9 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser) if (aimode == AI_HPCCR) { for (unsigned int i = 0; i < 2; ++i) { tank[4 + i].enabled = 1; - tank[4 + i].name[0] = i == 0 ? 'D': 'O'; - tank[4 + i].name[1] = 0; + tank[4 + i].usage = i == 0 ? DC_USAGE_DILUENT : DC_USAGE_OXYGEN; } + hpccr = 1; } } } @@ -692,6 +695,7 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser) } } parser->aimode = aimode; + parser->hpccr = hpccr; parser->divemode = divemode; parser->units = data[parser->opening[0] + 8]; parser->atmospheric = array_uint16_be (data + parser->opening[1] + (parser->pnf ? 16 : 47)); @@ -756,7 +760,7 @@ shearwater_predator_parser_get_field (dc_parser_t *abstract, dc_field_type_t typ tank->beginpressure = parser->tank[flags].beginpressure * 2 * PSI / BAR; tank->endpressure = parser->tank[flags].endpressure * 2 * PSI / BAR; tank->gasmix = DC_GASMIX_UNKNOWN; - if (shearwater_predator_is_ccr (parser->divemode)) { + if (shearwater_predator_is_ccr (parser->divemode) && !parser->hpccr) { switch (parser->tank[flags].name[0]) { case 'O': tank->usage = DC_USAGE_OXYGEN; From 8bfbb94087462a16dd13429945e0f405cb9d34e6 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Thu, 20 Jul 2023 23:35:23 +0200 Subject: [PATCH 25/51] Include the command byte in the hexdump The hexdump only includes the command parameters, but not the main command byte. Since there are many commands without parameters, that's not very useful. --- src/uwatec_smart.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/uwatec_smart.c b/src/uwatec_smart.c index e7be4fc..e124c7b 100644 --- a/src/uwatec_smart.c +++ b/src/uwatec_smart.c @@ -286,8 +286,6 @@ uwatec_smart_usbhid_send (uwatec_smart_device_t *device, unsigned char cmd, cons return DC_STATUS_INVALIDARGS; } - HEXDUMP (abstract->context, DC_LOGLEVEL_DEBUG, "cmd", data, size); - buf[0] = 0; buf[1] = size + 1; buf[2] = cmd; @@ -296,6 +294,8 @@ uwatec_smart_usbhid_send (uwatec_smart_device_t *device, unsigned char cmd, cons } memset(buf + 3 + size, 0, sizeof(buf) - (size + 3)); + HEXDUMP (abstract->context, DC_LOGLEVEL_DEBUG, "cmd", buf + 2, size + 1); + if (dc_iostream_get_transport(device->iostream) == DC_TRANSPORT_BLE) { rc = dc_iostream_write(device->iostream, buf + 1, size + 2, NULL); } else { From ecc9e0b09bc18604acc6974cd58eebd9d92e3ff0 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Mon, 31 Jul 2023 19:42:13 +0200 Subject: [PATCH 26/51] Limit the lookup function to the manual gas mixes Looking up the gasmix by oxygen and helium content is only needed for the manual gas mixes. For gas switches to a fixed gas mix, the index is stored directly in the data. --- src/hw_ostc_parser.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/hw_ostc_parser.c b/src/hw_ostc_parser.c index 288d28a..8798216 100644 --- a/src/hw_ostc_parser.c +++ b/src/hw_ostc_parser.c @@ -37,10 +37,6 @@ #define UNDEFINED 0xFFFFFFFF -#define ALL 0 -#define FIXED 1 -#define MANUAL 2 - #define HEADER 1 #define PROFILE 2 @@ -194,15 +190,10 @@ static const hw_ostc_layout_t hw_ostc_layout_ostc3 = { }; static unsigned int -hw_ostc_find_gasmix (hw_ostc_parser_t *parser, unsigned int o2, unsigned int he, unsigned int dil, unsigned int type) +hw_ostc_find_gasmix_manual (hw_ostc_parser_t *parser, unsigned int o2, unsigned int he, unsigned int dil) { - unsigned int offset = 0; + unsigned int offset = parser->nfixed; unsigned int count = parser->ngasmixes; - if (type == FIXED) { - count = parser->nfixed; - } else if (type == MANUAL) { - offset = parser->nfixed; - } unsigned int i = offset; while (i < count) { @@ -899,7 +890,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call } unsigned int o2 = data[offset]; unsigned int he = data[offset + 1]; - unsigned int idx = hw_ostc_find_gasmix (parser, o2, he, ccr, MANUAL); + unsigned int idx = hw_ostc_find_gasmix_manual (parser, o2, he, ccr); if (idx >= parser->ngasmixes) { if (idx >= NGASMIXES) { ERROR (abstract->context, "Maximum number of gas mixes reached."); @@ -964,7 +955,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call unsigned int o2 = data[offset]; unsigned int he = data[offset + 1]; - unsigned int idx = hw_ostc_find_gasmix (parser, o2, he, 0, MANUAL); + unsigned int idx = hw_ostc_find_gasmix_manual (parser, o2, he, 0); if (idx >= parser->ngasmixes) { if (idx >= NGASMIXES) { ERROR (abstract->context, "Maximum number of gas mixes reached."); @@ -1099,7 +1090,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call unsigned int o2 = data[offset]; unsigned int he = data[offset + 1]; - unsigned int idx = hw_ostc_find_gasmix (parser, o2, he, 0, MANUAL); + unsigned int idx = hw_ostc_find_gasmix_manual (parser, o2, he, 0); if (idx >= parser->ngasmixes) { if (idx >= NGASMIXES) { ERROR (abstract->context, "Maximum number of gas mixes reached."); From 323804d5e68d1f5e075be29f479ef50bc72bc326 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Mon, 31 Jul 2023 20:17:06 +0200 Subject: [PATCH 27/51] Keep track of the actively used gas mixes The hwOS models support switching to a disabled gas mix. Therefore, the disabled state is not always a good indication whether a gas mix is used or not. Look for gas switches during the parsing step instead to keep track of the actively used gas mixes. --- src/hw_ostc_parser.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/hw_ostc_parser.c b/src/hw_ostc_parser.c index 8798216..7d23964 100644 --- a/src/hw_ostc_parser.c +++ b/src/hw_ostc_parser.c @@ -108,6 +108,7 @@ typedef struct hw_ostc_gasmix_t { unsigned int helium; unsigned int type; unsigned int enabled; + unsigned int active; unsigned int diluent; } hw_ostc_gasmix_t; @@ -290,6 +291,7 @@ hw_ostc_parser_cache (hw_ostc_parser_t *parser) gasmix[i].helium = 0; gasmix[i].type = 0; gasmix[i].enabled = 1; + gasmix[i].active = 0; gasmix[i].diluent = 0; } } else if (version == 0x23 || version == 0x24) { @@ -299,6 +301,7 @@ hw_ostc_parser_cache (hw_ostc_parser_t *parser) gasmix[i].helium = data[28 + 4 * i + 1]; gasmix[i].type = data[28 + 4 * i + 3]; gasmix[i].enabled = gasmix[i].type != 0; + gasmix[i].active = 0; gasmix[i].diluent = ccr; // Find the first gas marked as the initial gas. if (initial == UNDEFINED && data[28 + 4 * i + 3] == 1) { @@ -325,6 +328,7 @@ hw_ostc_parser_cache (hw_ostc_parser_t *parser) } else { gasmix[i].enabled = 1; } + gasmix[i].active = 0; gasmix[i].diluent = ccr; } } @@ -387,6 +391,7 @@ hw_ostc_parser_create_internal (dc_parser_t **out, dc_context_t *context, const parser->gasmix[i].helium = 0; parser->gasmix[i].type = 0; parser->gasmix[i].enabled = 0; + parser->gasmix[i].active = 0; parser->gasmix[i].diluent = 0; } @@ -802,6 +807,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call // Initial gas mix. if (time == samplerate && parser->initial != UNDEFINED) { + parser->gasmix[parser->initial].active = 1; sample.gasmix = parser->initial; if (callback) callback (DC_SAMPLE_GASMIX, &sample, userdata); } @@ -900,6 +906,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call parser->gasmix[idx].helium = he; parser->gasmix[idx].type = 0; parser->gasmix[idx].enabled = 1; + parser->gasmix[idx].active = 1; parser->gasmix[idx].diluent = ccr; parser->ngasmixes = idx + 1; } @@ -926,6 +933,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call return DC_STATUS_DATAFORMAT; } idx--; /* Convert to a zero based index. */ + parser->gasmix[idx].active = 1; sample.gasmix = idx; if (callback) callback (DC_SAMPLE_GASMIX, &sample, userdata); tank = idx; @@ -965,6 +973,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call parser->gasmix[idx].helium = he; parser->gasmix[idx].type = 0; parser->gasmix[idx].enabled = 1; + parser->gasmix[idx].active = 1; parser->gasmix[idx].diluent = 0; parser->ngasmixes = idx + 1; } @@ -1100,6 +1109,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call parser->gasmix[idx].helium = he; parser->gasmix[idx].type = 0; parser->gasmix[idx].enabled = 1; + parser->gasmix[idx].active = 1; parser->gasmix[idx].diluent = 0; parser->ngasmixes = idx + 1; } From 993283d1c8c36f20249b2065c3af3afd1b1f3f28 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Mon, 31 Jul 2023 21:08:50 +0200 Subject: [PATCH 28/51] Store the original one based gas mix index --- src/hw_ostc_parser.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/hw_ostc_parser.c b/src/hw_ostc_parser.c index 7d23964..59e06ae 100644 --- a/src/hw_ostc_parser.c +++ b/src/hw_ostc_parser.c @@ -104,6 +104,7 @@ typedef struct hw_ostc_layout_t { } hw_ostc_layout_t; typedef struct hw_ostc_gasmix_t { + unsigned int id; unsigned int oxygen; unsigned int helium; unsigned int type; @@ -287,6 +288,7 @@ hw_ostc_parser_cache (hw_ostc_parser_t *parser) initial = data[31]; } for (unsigned int i = 0; i < ngasmixes; ++i) { + gasmix[i].id = i + 1; gasmix[i].oxygen = data[25 + 2 * i]; gasmix[i].helium = 0; gasmix[i].type = 0; @@ -297,6 +299,7 @@ hw_ostc_parser_cache (hw_ostc_parser_t *parser) } else if (version == 0x23 || version == 0x24) { ngasmixes = 5; for (unsigned int i = 0; i < ngasmixes; ++i) { + gasmix[i].id = i + 1; gasmix[i].oxygen = data[28 + 4 * i + 0]; gasmix[i].helium = data[28 + 4 * i + 1]; gasmix[i].type = data[28 + 4 * i + 3]; @@ -320,6 +323,7 @@ hw_ostc_parser_cache (hw_ostc_parser_t *parser) initial = data[31]; } for (unsigned int i = 0; i < ngasmixes; ++i) { + gasmix[i].id = i + 1; gasmix[i].oxygen = data[19 + 2 * i + 0]; gasmix[i].helium = data[19 + 2 * i + 1]; gasmix[i].type = 0; @@ -387,6 +391,7 @@ hw_ostc_parser_create_internal (dc_parser_t **out, dc_context_t *context, const parser->initial_setpoint = 0; parser->initial_cns = 0; for (unsigned int i = 0; i < NGASMIXES; ++i) { + parser->gasmix[i].id = 0; parser->gasmix[i].oxygen = 0; parser->gasmix[i].helium = 0; parser->gasmix[i].type = 0; @@ -902,6 +907,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call ERROR (abstract->context, "Maximum number of gas mixes reached."); return DC_STATUS_NOMEMORY; } + parser->gasmix[idx].id = 0; parser->gasmix[idx].oxygen = o2; parser->gasmix[idx].helium = he; parser->gasmix[idx].type = 0; @@ -969,6 +975,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call ERROR (abstract->context, "Maximum number of gas mixes reached."); return DC_STATUS_NOMEMORY; } + parser->gasmix[idx].id = 0; parser->gasmix[idx].oxygen = o2; parser->gasmix[idx].helium = he; parser->gasmix[idx].type = 0; @@ -1105,6 +1112,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call ERROR (abstract->context, "Maximum number of gas mixes reached."); return DC_STATUS_NOMEMORY; } + parser->gasmix[idx].id = 0; parser->gasmix[idx].oxygen = o2; parser->gasmix[idx].helium = he; parser->gasmix[idx].type = 0; From 5d36cc079878672d3669db91c44f05fa2905e1dd Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Mon, 31 Jul 2023 21:08:50 +0200 Subject: [PATCH 29/51] Remove disabled gas mixes Returning disabled gas mixes to the application mainly results in lots of unnecessary information. Therefore, remove all disabled gas mixes, unless they are actively used. Many other dive computers do not even include disabled gas mixes in the data. The removal of the disabled gas mixes requires a two pass approach for parsing the profile data. The first pass is only used to discover which gas mixes are actively used during the dive. Next, all disabled and not actively used gas mixes are removed from the list. Since removing one or more gas mixes also invalidates the index of the remaining gas mixes, the profile needs to be parsed again to report the new index in the gas switch samples. The original one based index is used as the stable gas mix id, used for looking up the new gas mix index. --- src/hw_ostc_parser.c | 99 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 79 insertions(+), 20 deletions(-) diff --git a/src/hw_ostc_parser.c b/src/hw_ostc_parser.c index 59e06ae..f1e306d 100644 --- a/src/hw_ostc_parser.c +++ b/src/hw_ostc_parser.c @@ -124,6 +124,7 @@ typedef struct hw_ostc_parser_t { const hw_ostc_layout_t *layout; unsigned int ngasmixes; unsigned int nfixed; + unsigned int ndisabled; unsigned int initial; unsigned int initial_setpoint; unsigned int initial_cns; @@ -134,6 +135,8 @@ static dc_status_t hw_ostc_parser_get_datetime (dc_parser_t *abstract, dc_dateti static dc_status_t hw_ostc_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); static dc_status_t hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata); +static dc_status_t hw_ostc_parser_internal_foreach (hw_ostc_parser_t *parser, dc_sample_callback_t callback, void *userdata); + static const dc_parser_vtable_t hw_ostc_parser_vtable = { sizeof(hw_ostc_parser_t), DC_FAMILY_HW_OSTC, @@ -194,7 +197,7 @@ static const hw_ostc_layout_t hw_ostc_layout_ostc3 = { static unsigned int hw_ostc_find_gasmix_manual (hw_ostc_parser_t *parser, unsigned int o2, unsigned int he, unsigned int dil) { - unsigned int offset = parser->nfixed; + unsigned int offset = parser->nfixed - parser->ndisabled; unsigned int count = parser->ngasmixes; unsigned int i = offset; @@ -207,6 +210,22 @@ hw_ostc_find_gasmix_manual (hw_ostc_parser_t *parser, unsigned int o2, unsigned return i; } +static unsigned int +hw_ostc_find_gasmix_fixed (hw_ostc_parser_t *parser, unsigned int id) +{ + unsigned int offset = 0; + unsigned int count = parser->nfixed - parser->ndisabled; + + unsigned int i = offset; + while (i < count) { + if (id == parser->gasmix[i].id) + break; + i++; + } + + return i; +} + static unsigned int hw_ostc_is_ccr (unsigned int divemode, unsigned int version) { @@ -341,7 +360,6 @@ hw_ostc_parser_cache (hw_ostc_parser_t *parser) ERROR(abstract->context, "Invalid initial gas mix."); return DC_STATUS_DATAFORMAT; } - initial--; /* Convert to a zero based index. */ } else { WARNING(abstract->context, "No initial gas mix available."); } @@ -352,6 +370,7 @@ hw_ostc_parser_cache (hw_ostc_parser_t *parser) parser->layout = layout; parser->ngasmixes = ngasmixes; parser->nfixed = ngasmixes; + parser->ndisabled = 0; parser->initial = initial; parser->initial_setpoint = initial_setpoint; parser->initial_cns = initial_cns; @@ -387,6 +406,7 @@ hw_ostc_parser_create_internal (dc_parser_t **out, dc_context_t *context, const parser->layout = NULL; parser->ngasmixes = 0; parser->nfixed = 0; + parser->ndisabled = 0; parser->initial = 0; parser->initial_setpoint = 0; parser->initial_cns = 0; @@ -491,7 +511,7 @@ hw_ostc_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned // Cache the profile data. if (parser->cached < PROFILE) { - rc = hw_ostc_parser_samples_foreach (abstract, NULL, NULL); + rc = hw_ostc_parser_internal_foreach (parser, NULL, NULL); if (rc != DC_STATUS_SUCCESS) return rc; } @@ -679,17 +699,12 @@ hw_ostc_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned static dc_status_t -hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata) +hw_ostc_parser_internal_foreach (hw_ostc_parser_t *parser, dc_sample_callback_t callback, void *userdata) { - hw_ostc_parser_t *parser = (hw_ostc_parser_t *) abstract; + dc_parser_t *abstract = (dc_parser_t *) parser; const unsigned char *data = abstract->data; unsigned int size = abstract->size; - // Cache the parser data. - dc_status_t rc = hw_ostc_parser_cache (parser); - if (rc != DC_STATUS_SUCCESS) - return rc; - unsigned int version = parser->version; unsigned int header = parser->header; const hw_ostc_layout_t *layout = parser->layout; @@ -795,7 +810,7 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call unsigned int time = 0; unsigned int nsamples = 0; - unsigned int tank = parser->initial != UNDEFINED ? parser->initial : 0; + unsigned int tank = parser->initial != UNDEFINED ? parser->initial - 1 : 0; unsigned int offset = header; if (version == 0x23 || version == 0x24) @@ -812,8 +827,9 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call // Initial gas mix. if (time == samplerate && parser->initial != UNDEFINED) { - parser->gasmix[parser->initial].active = 1; - sample.gasmix = parser->initial; + unsigned int idx = hw_ostc_find_gasmix_fixed (parser, parser->initial); + parser->gasmix[idx].active = 1; + sample.gasmix = idx; if (callback) callback (DC_SAMPLE_GASMIX, &sample, userdata); } @@ -929,20 +945,20 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call ERROR (abstract->context, "Buffer overflow detected!"); return DC_STATUS_DATAFORMAT; } - unsigned int idx = data[offset]; - if (parser->model == OSTC4 && ccr && idx > parser->nfixed) { + unsigned int id = data[offset]; + if (parser->model == OSTC4 && ccr && id > parser->nfixed) { // Fix the OSTC4 diluent index. - idx -= parser->nfixed; + id -= parser->nfixed; } - if (idx < 1 || idx > parser->nfixed) { - ERROR(abstract->context, "Invalid gas mix (%u).", idx); + if (id < 1 || id > parser->nfixed) { + ERROR(abstract->context, "Invalid gas mix (%u).", id); return DC_STATUS_DATAFORMAT; } - idx--; /* Convert to a zero based index. */ + unsigned int idx = hw_ostc_find_gasmix_fixed (parser, id); parser->gasmix[idx].active = 1; sample.gasmix = idx; if (callback) callback (DC_SAMPLE_GASMIX, &sample, userdata); - tank = idx; + tank = id - 1; offset++; length--; } @@ -1141,7 +1157,50 @@ hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t call return DC_STATUS_DATAFORMAT; } + // Remove the disabled gas mixes from the fixed gas mixes. + unsigned int ndisabled = 0, nenabled = 0; + unsigned int count = parser->nfixed - parser->ndisabled; + for (unsigned int i = 0; i < count; ++i) { + if (parser->gasmix[i].enabled || parser->gasmix[i].active) { + // Move the fixed gas mix. + parser->gasmix[nenabled] = parser->gasmix[i]; + nenabled++; + } else { + ndisabled++; + } + } + + // Move all the manual gas mixes. + memmove (parser->gasmix + nenabled, parser->gasmix + count, + (parser->ngasmixes - count) * sizeof (hw_ostc_gasmix_t)); + memset (parser->gasmix + parser->ngasmixes - ndisabled, 0, + ndisabled * sizeof (hw_ostc_gasmix_t)); + + // Adjust the counts. + parser->ngasmixes -= ndisabled; + parser->ndisabled += ndisabled; + parser->cached = PROFILE; return DC_STATUS_SUCCESS; } + +static dc_status_t +hw_ostc_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata) +{ + hw_ostc_parser_t *parser = (hw_ostc_parser_t *) abstract; + + // Cache the header data. + dc_status_t rc = hw_ostc_parser_cache (parser); + if (rc != DC_STATUS_SUCCESS) + return rc; + + // Cache the profile data. + if (parser->cached < PROFILE) { + rc = hw_ostc_parser_internal_foreach (parser, NULL, NULL); + if (rc != DC_STATUS_SUCCESS) + return rc; + } + + return hw_ostc_parser_internal_foreach (parser, callback, userdata); +} From 301fdbe3640c89326ebb34b31de3d78f49f0adb9 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Tue, 18 Jul 2023 00:40:56 +0200 Subject: [PATCH 30/51] Remove support for the Tusa TC1 Apparantly the Tusa TC1 does not support downloading dives at all. The bluetooth communication is probably disabled in the firmware. --- src/descriptor.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/descriptor.c b/src/descriptor.c index ead1a8a..794fd1d 100644 --- a/src/descriptor.c +++ b/src/descriptor.c @@ -457,7 +457,6 @@ static const dc_descriptor_t g_descriptors[] = { {"Deep Six", "Excursion", DC_FAMILY_DEEPSIX_EXCURSION, 0, DC_TRANSPORT_BLE, dc_filter_deepsix}, {"Crest", "CR-4", DC_FAMILY_DEEPSIX_EXCURSION, 0, DC_TRANSPORT_BLE, dc_filter_deepsix}, {"Genesis", "Centauri", DC_FAMILY_DEEPSIX_EXCURSION, 0, DC_TRANSPORT_BLE, dc_filter_deepsix}, - {"Tusa", "TC1", DC_FAMILY_DEEPSIX_EXCURSION, 0, DC_TRANSPORT_BLE, dc_filter_deepsix}, {"Scorpena", "Alpha", DC_FAMILY_DEEPSIX_EXCURSION, 0, DC_TRANSPORT_BLE, dc_filter_deepsix}, /* Seac Screen */ {"Seac", "Screen", DC_FAMILY_SEAC_SCREEN, 0, DC_TRANSPORT_SERIAL, NULL}, @@ -780,7 +779,6 @@ static int dc_filter_deepsix (dc_transport_t transport, const void *userdata, vo "EXCURSION", "Crest-CR4", "CENTAURI", - "TC1", "ALPHA", }; From b2310e62d64cc2c51722bbe0289b5930f7f62140 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Mon, 25 Jan 2021 21:35:38 +0100 Subject: [PATCH 31/51] Pass the descriptor to the filter function Passing the descriptor for which the filter function is being called is a good practice and will also allow to implement some more specific filtering in the future. --- src/descriptor.c | 74 ++++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/src/descriptor.c b/src/descriptor.c index 794fd1d..d287393 100644 --- a/src/descriptor.c +++ b/src/descriptor.c @@ -50,22 +50,22 @@ typedef int (*dc_match_t)(const void *, const void *); -typedef int (*dc_filter_t) (dc_transport_t transport, const void *userdata, void *params); +typedef int (*dc_filter_t) (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params); -static int dc_filter_uwatec (dc_transport_t transport, const void *userdata, void *params); -static int dc_filter_suunto (dc_transport_t transport, const void *userdata, void *params); -static int dc_filter_shearwater (dc_transport_t transport, const void *userdata, void *params); -static int dc_filter_hw (dc_transport_t transport, const void *userdata, void *params); -static int dc_filter_tecdiving (dc_transport_t transport, const void *userdata, void *params); -static int dc_filter_mares (dc_transport_t transport, const void *userdata, void *params); -static int dc_filter_divesystem (dc_transport_t transport, const void *userdata, void *params); -static int dc_filter_oceanic (dc_transport_t transport, const void *userdata, void *params); -static int dc_filter_mclean (dc_transport_t transport, const void *userdata, void *params); -static int dc_filter_atomic (dc_transport_t transport, const void *userdata, void *params); -static int dc_filter_deepsix (dc_transport_t transport, const void *userdata, void *params); -static int dc_filter_deepblu (dc_transport_t transport, const void *userdata, void *params); -static int dc_filter_oceans (dc_transport_t transport, const void *userdata, void *params); -static int dc_filter_divesoft (dc_transport_t transport, const void *userdata, void *params); +static int dc_filter_uwatec (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params); +static int dc_filter_suunto (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params); +static int dc_filter_shearwater (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params); +static int dc_filter_hw (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params); +static int dc_filter_tecdiving (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params); +static int dc_filter_mares (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params); +static int dc_filter_divesystem (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params); +static int dc_filter_oceanic (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params); +static int dc_filter_mclean (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params); +static int dc_filter_atomic (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params); +static int dc_filter_deepsix (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params); +static int dc_filter_deepblu (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params); +static int dc_filter_oceans (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params); +static int dc_filter_divesoft (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params); static dc_status_t dc_descriptor_iterator_next (dc_iterator_t *iterator, void *item); @@ -570,7 +570,8 @@ static const char * const rfcomm[] = { NULL }; -static int dc_filter_uwatec (dc_transport_t transport, const void *userdata, void *params) +static int +dc_filter_uwatec (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params) { static const char * const irda[] = { "Aladin Smart Com", @@ -607,7 +608,8 @@ static int dc_filter_uwatec (dc_transport_t transport, const void *userdata, voi return 1; } -static int dc_filter_suunto (dc_transport_t transport, const void *userdata, void *params) +static int +dc_filter_suunto (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params) { static const dc_usb_desc_t usbhid[] = { {0x1493, 0x0030}, // Eon Steel @@ -631,7 +633,8 @@ static int dc_filter_suunto (dc_transport_t transport, const void *userdata, voi return 1; } -static int dc_filter_hw (dc_transport_t transport, const void *userdata, void *params) +static int +dc_filter_hw (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params) { static const char * const bluetooth[] = { "OSTC", @@ -647,7 +650,8 @@ static int dc_filter_hw (dc_transport_t transport, const void *userdata, void *p return 1; } -static int dc_filter_shearwater (dc_transport_t transport, const void *userdata, void *params) +static int +dc_filter_shearwater (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params) { static const char * const bluetooth[] = { "Predator", @@ -670,7 +674,8 @@ static int dc_filter_shearwater (dc_transport_t transport, const void *userdata, return 1; } -static int dc_filter_tecdiving (dc_transport_t transport, const void *userdata, void *params) +static int +dc_filter_tecdiving (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params) { static const char * const bluetooth[] = { "DiveComputer", @@ -685,7 +690,8 @@ static int dc_filter_tecdiving (dc_transport_t transport, const void *userdata, return 1; } -static int dc_filter_mares (dc_transport_t transport, const void *userdata, void *params) +static int +dc_filter_mares (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params) { static const char * const bluetooth[] = { "Mares bluelink pro", @@ -699,7 +705,8 @@ static int dc_filter_mares (dc_transport_t transport, const void *userdata, void return 1; } -static int dc_filter_divesystem (dc_transport_t transport, const void *userdata, void *params) +static int +dc_filter_divesystem (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params) { static const char * const bluetooth[] = { "DS", @@ -714,7 +721,8 @@ static int dc_filter_divesystem (dc_transport_t transport, const void *userdata, return 1; } -static int dc_filter_oceanic (dc_transport_t transport, const void *userdata, void *params) +static int +dc_filter_oceanic (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params) { static const unsigned int model[] = { 0x4552, // Oceanic Pro Plus X @@ -741,7 +749,8 @@ static int dc_filter_oceanic (dc_transport_t transport, const void *userdata, vo return 1; } -static int dc_filter_mclean(dc_transport_t transport, const void *userdata, void *params) +static int +dc_filter_mclean(dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params) { static const char * const bluetooth[] = { "McLean Extreme", @@ -756,7 +765,8 @@ static int dc_filter_mclean(dc_transport_t transport, const void *userdata, void return 1; } -static int dc_filter_atomic (dc_transport_t transport, const void *userdata, void *params) +static int +dc_filter_atomic (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params) { static const dc_usb_desc_t usb[] = { {0x0471, 0x0888}, // Atomic Aquatics Cobalt @@ -773,7 +783,8 @@ static int dc_filter_atomic (dc_transport_t transport, const void *userdata, voi return 1; } -static int dc_filter_deepsix (dc_transport_t transport, const void *userdata, void *params) +static int +dc_filter_deepsix (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params) { static const char * const bluetooth[] = { "EXCURSION", @@ -789,7 +800,8 @@ static int dc_filter_deepsix (dc_transport_t transport, const void *userdata, vo return 1; } -static int dc_filter_deepblu (dc_transport_t transport, const void *userdata, void *params) +static int +dc_filter_deepblu (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params) { static const char * const bluetooth[] = { "COSMIQ", @@ -802,7 +814,8 @@ static int dc_filter_deepblu (dc_transport_t transport, const void *userdata, vo return 1; } -static int dc_filter_oceans (dc_transport_t transport, const void *userdata, void *params) +static int +dc_filter_oceans (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params) { static const char * const bluetooth[] = { "S1", @@ -815,7 +828,8 @@ static int dc_filter_oceans (dc_transport_t transport, const void *userdata, voi return 1; } -static int dc_filter_divesoft (dc_transport_t transport, const void *userdata, void *params) +static int +dc_filter_divesoft (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params) { static const char * const bluetooth[] = { "Freedom", @@ -926,5 +940,5 @@ dc_descriptor_filter (dc_descriptor_t *descriptor, dc_transport_t transport, con if (descriptor == NULL || descriptor->filter == NULL || userdata == NULL) return 1; - return descriptor->filter (transport, userdata, params); + return descriptor->filter (descriptor, transport, userdata, params); } From a985b1185970c44e26d787ffd5a3e1390591a641 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Wed, 5 Jul 2023 20:32:41 +0200 Subject: [PATCH 32/51] Replace the filter parameters with an alternative The USB I/O backend needs some additional information (e.g. interface number and in/out endpoints) to setup the USB connection. This info is currently maintained inside the descriptor filter function and gets passed to the USB backend by means of the filter parameters. This approach is not only unnecessary complex, but also makes it very difficult to expose the filter function in the public api because the data structures for those parameters are private. Therefore, this data exchange is replaced with a direct mapping between the USB VID/PID and the configuration info in the USB backend itself. --- src/bluetooth.c | 2 +- src/descriptor-private.h | 8 +--- src/descriptor.c | 85 ++++++++++++++++------------------------ src/irda.c | 2 +- src/serial_posix.c | 2 +- src/serial_win32.c | 2 +- src/usb.c | 45 ++++++++++++++++++--- src/usbhid.c | 4 +- 8 files changed, 81 insertions(+), 69 deletions(-) diff --git a/src/bluetooth.c b/src/bluetooth.c index aa5f05a..cc143b7 100644 --- a/src/bluetooth.c +++ b/src/bluetooth.c @@ -455,7 +455,7 @@ dc_bluetooth_iterator_next (dc_iterator_t *abstract, void *out) INFO (abstract->context, "Discover: address=" DC_ADDRESS_FORMAT ", name=%s", address, name ? name : ""); - if (!dc_descriptor_filter (iterator->descriptor, DC_TRANSPORT_BLUETOOTH, name, NULL)) { + if (!dc_descriptor_filter (iterator->descriptor, DC_TRANSPORT_BLUETOOTH, name)) { continue; } diff --git a/src/descriptor-private.h b/src/descriptor-private.h index d829422..06c2980 100644 --- a/src/descriptor-private.h +++ b/src/descriptor-private.h @@ -33,14 +33,8 @@ typedef struct dc_usb_desc_t { unsigned short pid; } dc_usb_desc_t; -typedef struct dc_usb_params_t { - unsigned int interface; - unsigned char endpoint_in; - unsigned char endpoint_out; -} dc_usb_params_t; - int -dc_descriptor_filter (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params); +dc_descriptor_filter (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata); #ifdef __cplusplus } diff --git a/src/descriptor.c b/src/descriptor.c index d287393..d90b54e 100644 --- a/src/descriptor.c +++ b/src/descriptor.c @@ -36,36 +36,26 @@ values, \ C_ARRAY_SIZE(values) - isnullterminated, \ C_ARRAY_ITEMSIZE(values), \ - match, \ - NULL, NULL, 0) - -#define DC_FILTER_INTERNAL_WITH_PARAMS(key, values, isnullterminated, match, params_dst, params_src) \ - dc_filter_internal( \ - key, \ - values, \ - C_ARRAY_SIZE(values) - isnullterminated, \ - C_ARRAY_ITEMSIZE(values), \ - match, \ - params_dst, params_src, sizeof *(params_src)) + match) typedef int (*dc_match_t)(const void *, const void *); -typedef int (*dc_filter_t) (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params); +typedef int (*dc_filter_t) (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata); -static int dc_filter_uwatec (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params); -static int dc_filter_suunto (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params); -static int dc_filter_shearwater (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params); -static int dc_filter_hw (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params); -static int dc_filter_tecdiving (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params); -static int dc_filter_mares (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params); -static int dc_filter_divesystem (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params); -static int dc_filter_oceanic (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params); -static int dc_filter_mclean (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params); -static int dc_filter_atomic (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params); -static int dc_filter_deepsix (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params); -static int dc_filter_deepblu (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params); -static int dc_filter_oceans (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params); -static int dc_filter_divesoft (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params); +static int dc_filter_uwatec (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata); +static int dc_filter_suunto (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata); +static int dc_filter_shearwater (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata); +static int dc_filter_hw (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata); +static int dc_filter_tecdiving (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata); +static int dc_filter_mares (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata); +static int dc_filter_divesystem (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata); +static int dc_filter_oceanic (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata); +static int dc_filter_mclean (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata); +static int dc_filter_atomic (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata); +static int dc_filter_deepsix (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata); +static int dc_filter_deepblu (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata); +static int dc_filter_oceans (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata); +static int dc_filter_divesoft (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata); static dc_status_t dc_descriptor_iterator_next (dc_iterator_t *iterator, void *item); @@ -546,16 +536,13 @@ dc_match_oceanic (const void *key, const void *value) } static int -dc_filter_internal (const void *key, const void *values, size_t count, size_t size, dc_match_t match, void *params_dst, const void *params_src, size_t params_size) +dc_filter_internal (const void *key, const void *values, size_t count, size_t size, dc_match_t match) { if (key == NULL) return 1; for (size_t i = 0; i < count; ++i) { if (match (key, (const unsigned char *) values + i * size)) { - if (params_src && params_dst) { - memcpy (params_dst, params_src, params_size); - } return 1; } } @@ -571,7 +558,7 @@ static const char * const rfcomm[] = { }; static int -dc_filter_uwatec (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params) +dc_filter_uwatec (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata) { static const char * const irda[] = { "Aladin Smart Com", @@ -609,7 +596,7 @@ dc_filter_uwatec (dc_descriptor_t *descriptor, dc_transport_t transport, const v } static int -dc_filter_suunto (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params) +dc_filter_suunto (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata) { static const dc_usb_desc_t usbhid[] = { {0x1493, 0x0030}, // Eon Steel @@ -634,7 +621,7 @@ dc_filter_suunto (dc_descriptor_t *descriptor, dc_transport_t transport, const v } static int -dc_filter_hw (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params) +dc_filter_hw (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata) { static const char * const bluetooth[] = { "OSTC", @@ -651,7 +638,7 @@ dc_filter_hw (dc_descriptor_t *descriptor, dc_transport_t transport, const void } static int -dc_filter_shearwater (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params) +dc_filter_shearwater (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata) { static const char * const bluetooth[] = { "Predator", @@ -675,7 +662,7 @@ dc_filter_shearwater (dc_descriptor_t *descriptor, dc_transport_t transport, con } static int -dc_filter_tecdiving (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params) +dc_filter_tecdiving (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata) { static const char * const bluetooth[] = { "DiveComputer", @@ -691,7 +678,7 @@ dc_filter_tecdiving (dc_descriptor_t *descriptor, dc_transport_t transport, cons } static int -dc_filter_mares (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params) +dc_filter_mares (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata) { static const char * const bluetooth[] = { "Mares bluelink pro", @@ -706,7 +693,7 @@ dc_filter_mares (dc_descriptor_t *descriptor, dc_transport_t transport, const vo } static int -dc_filter_divesystem (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params) +dc_filter_divesystem (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata) { static const char * const bluetooth[] = { "DS", @@ -722,7 +709,7 @@ dc_filter_divesystem (dc_descriptor_t *descriptor, dc_transport_t transport, con } static int -dc_filter_oceanic (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params) +dc_filter_oceanic (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata) { static const unsigned int model[] = { 0x4552, // Oceanic Pro Plus X @@ -750,7 +737,7 @@ dc_filter_oceanic (dc_descriptor_t *descriptor, dc_transport_t transport, const } static int -dc_filter_mclean(dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params) +dc_filter_mclean(dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata) { static const char * const bluetooth[] = { "McLean Extreme", @@ -766,25 +753,21 @@ dc_filter_mclean(dc_descriptor_t *descriptor, dc_transport_t transport, const vo } static int -dc_filter_atomic (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params) +dc_filter_atomic (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata) { static const dc_usb_desc_t usb[] = { {0x0471, 0x0888}, // Atomic Aquatics Cobalt }; - static const dc_usb_params_t usb_params = { - 0, 0x82, 0x02 - }; - if (transport == DC_TRANSPORT_USB) { - return DC_FILTER_INTERNAL_WITH_PARAMS (userdata, usb, 0, dc_match_usb, params, &usb_params); + return DC_FILTER_INTERNAL (userdata, usb, 0, dc_match_usb); } return 1; } static int -dc_filter_deepsix (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params) +dc_filter_deepsix (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata) { static const char * const bluetooth[] = { "EXCURSION", @@ -801,7 +784,7 @@ dc_filter_deepsix (dc_descriptor_t *descriptor, dc_transport_t transport, const } static int -dc_filter_deepblu (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params) +dc_filter_deepblu (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata) { static const char * const bluetooth[] = { "COSMIQ", @@ -815,7 +798,7 @@ dc_filter_deepblu (dc_descriptor_t *descriptor, dc_transport_t transport, const } static int -dc_filter_oceans (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params) +dc_filter_oceans (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata) { static const char * const bluetooth[] = { "S1", @@ -829,7 +812,7 @@ dc_filter_oceans (dc_descriptor_t *descriptor, dc_transport_t transport, const v } static int -dc_filter_divesoft (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params) +dc_filter_divesoft (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata) { static const char * const bluetooth[] = { "Freedom", @@ -935,10 +918,10 @@ dc_descriptor_get_transports (dc_descriptor_t *descriptor) } int -dc_descriptor_filter (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata, void *params) +dc_descriptor_filter (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata) { if (descriptor == NULL || descriptor->filter == NULL || userdata == NULL) return 1; - return descriptor->filter (descriptor, transport, userdata, params); + return descriptor->filter (descriptor, transport, userdata); } diff --git a/src/irda.c b/src/irda.c index a5bb8e4..6bd927c 100644 --- a/src/irda.c +++ b/src/irda.c @@ -226,7 +226,7 @@ dc_irda_iterator_new (dc_iterator_t **out, dc_context_t *context, dc_descriptor_ INFO (context, "Discover: address=%08x, name=%s, charset=%02x, hints=%04x", address, name, charset, hints); - if (!dc_descriptor_filter (descriptor, DC_TRANSPORT_IRDA, name, NULL)) { + if (!dc_descriptor_filter (descriptor, DC_TRANSPORT_IRDA, name)) { continue; } diff --git a/src/serial_posix.c b/src/serial_posix.c index a189e15..51b1037 100644 --- a/src/serial_posix.c +++ b/src/serial_posix.c @@ -230,7 +230,7 @@ dc_serial_iterator_next (dc_iterator_t *abstract, void *out) return DC_STATUS_NOMEMORY; } - if (!dc_descriptor_filter (iterator->descriptor, DC_TRANSPORT_SERIAL, filename, NULL)) { + if (!dc_descriptor_filter (iterator->descriptor, DC_TRANSPORT_SERIAL, filename)) { continue; } diff --git a/src/serial_win32.c b/src/serial_win32.c index aeeeb83..30fe0e9 100644 --- a/src/serial_win32.c +++ b/src/serial_win32.c @@ -228,7 +228,7 @@ dc_serial_iterator_next (dc_iterator_t *abstract, void *out) // Null terminate the string. data[data_len] = 0; - if (!dc_descriptor_filter (iterator->descriptor, DC_TRANSPORT_SERIAL, data, NULL)) { + if (!dc_descriptor_filter (iterator->descriptor, DC_TRANSPORT_SERIAL, data)) { continue; } diff --git a/src/usb.c b/src/usb.c index 758c604..80083f6 100644 --- a/src/usb.c +++ b/src/usb.c @@ -42,9 +42,21 @@ #include "descriptor-private.h" #include "iterator-private.h" #include "platform.h" +#include "array.h" #define ISINSTANCE(device) dc_iostream_isinstance((device), &dc_usb_vtable) +typedef struct dc_usb_params_t { + unsigned int interface; + unsigned char endpoint_in; + unsigned char endpoint_out; +} dc_usb_params_t; + +typedef struct dc_usb_config_t { + dc_usb_desc_t desc; + dc_usb_params_t params; +} dc_usb_config_t; + typedef struct dc_usb_session_t { size_t refcount; #ifdef HAVE_LIBUSB @@ -120,6 +132,26 @@ static const dc_iostream_vtable_t dc_usb_vtable = { dc_usb_close, /* close */ }; +static const dc_usb_config_t g_usb_config[] = { + // Atomic Aquatics Cobalt + {{0x0471, 0x0888}, {0, 0x82, 0x02}}, +}; + +static const dc_usb_params_t * +dc_usb_params_find (const dc_usb_desc_t *desc) +{ + if (desc == NULL) + return NULL; + + for (size_t i = 0; i < C_ARRAY_SIZE(g_usb_config); ++i) { + if (g_usb_config[i].desc.vid == desc->vid && + g_usb_config[i].desc.pid == desc->pid) + return &g_usb_config[i].params; + } + + return NULL; +} + static dc_status_t syserror(int errcode) { @@ -305,11 +337,13 @@ dc_usb_iterator_next (dc_iterator_t *abstract, void *out) } dc_usb_desc_t usb = {dev.idVendor, dev.idProduct}; - dc_usb_params_t params = {0, 0, 0}; - if (!dc_descriptor_filter (iterator->descriptor, DC_TRANSPORT_USB, &usb, ¶ms)) { + if (!dc_descriptor_filter (iterator->descriptor, DC_TRANSPORT_USB, &usb)) { continue; } + // Check for known USB parameters. + const dc_usb_params_t *params = dc_usb_params_find (&usb); + // Get the active configuration descriptor. struct libusb_config_descriptor *config = NULL; rc = libusb_get_active_config_descriptor (current, &config); @@ -325,7 +359,8 @@ dc_usb_iterator_next (dc_iterator_t *abstract, void *out) const struct libusb_interface *iface = &config->interface[i]; for (int j = 0; j < iface->num_altsetting; j++) { const struct libusb_interface_descriptor *desc = &iface->altsetting[j]; - if (interface == NULL && desc->bInterfaceNumber == params.interface) { + if (interface == NULL && + (params == NULL || params->interface == desc->bInterfaceNumber)) { interface = desc; } } @@ -349,12 +384,12 @@ dc_usb_iterator_next (dc_iterator_t *abstract, void *out) } if (ep_in == NULL && direction == LIBUSB_ENDPOINT_IN && - (params.endpoint_in == 0 || params.endpoint_in == desc->bEndpointAddress)) { + (params == NULL || params->endpoint_in == desc->bEndpointAddress)) { ep_in = desc; } if (ep_out == NULL && direction == LIBUSB_ENDPOINT_OUT && - (params.endpoint_out == 0 || params.endpoint_out == desc->bEndpointAddress)) { + (params == NULL || params->endpoint_out == desc->bEndpointAddress)) { ep_out = desc; } } diff --git a/src/usbhid.c b/src/usbhid.c index acd20ef..3ed94d7 100644 --- a/src/usbhid.c +++ b/src/usbhid.c @@ -439,7 +439,7 @@ dc_usbhid_iterator_next (dc_iterator_t *abstract, void *out) } dc_usb_desc_t usb = {dev.idVendor, dev.idProduct}; - if (!dc_descriptor_filter (iterator->descriptor, DC_TRANSPORT_USBHID, &usb, NULL)) { + if (!dc_descriptor_filter (iterator->descriptor, DC_TRANSPORT_USBHID, &usb)) { continue; } @@ -523,7 +523,7 @@ dc_usbhid_iterator_next (dc_iterator_t *abstract, void *out) iterator->current = current->next; dc_usb_desc_t usb = {current->vendor_id, current->product_id}; - if (!dc_descriptor_filter (iterator->descriptor, DC_TRANSPORT_USBHID, &usb, NULL)) { + if (!dc_descriptor_filter (iterator->descriptor, DC_TRANSPORT_USBHID, &usb)) { continue; } From 4a9be44afde08ff61f2c19869e8c9bb94169ff34 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Sun, 20 Aug 2023 21:50:59 +0200 Subject: [PATCH 33/51] Use separate data structures for USB and USB HID Using separate data structures for the filtering allows to keep the USB and USB HID backends completely independent from each other. --- include/libdivecomputer/usb.h | 8 ++++++++ include/libdivecomputer/usbhid.h | 8 ++++++++ src/descriptor-private.h | 5 ----- src/descriptor.c | 20 ++++++++++++++++---- src/usbhid.c | 4 ++-- 5 files changed, 34 insertions(+), 11 deletions(-) diff --git a/include/libdivecomputer/usb.h b/include/libdivecomputer/usb.h index 6d13813..82e5881 100644 --- a/include/libdivecomputer/usb.h +++ b/include/libdivecomputer/usb.h @@ -86,6 +86,14 @@ typedef enum dc_usb_recipient_t { DC_USB_RECIPIENT_OTHER = 0x03, } dc_usb_recipient_t; +/** + * USB device descriptor. + */ +typedef struct dc_usb_desc_t { + unsigned short vid; + unsigned short pid; +} dc_usb_desc_t; + /** * Opaque object representing a USB device. */ diff --git a/include/libdivecomputer/usbhid.h b/include/libdivecomputer/usbhid.h index f1c542a..245adf0 100644 --- a/include/libdivecomputer/usbhid.h +++ b/include/libdivecomputer/usbhid.h @@ -32,6 +32,14 @@ extern "C" { #endif /* __cplusplus */ +/** + * USB HID device descriptor. + */ +typedef struct dc_usbhid_desc_t { + unsigned short vid; + unsigned short pid; +} dc_usbhid_desc_t; + /** * Opaque object representing a USB HID device. */ diff --git a/src/descriptor-private.h b/src/descriptor-private.h index 06c2980..77bdbb6 100644 --- a/src/descriptor-private.h +++ b/src/descriptor-private.h @@ -28,11 +28,6 @@ extern "C" { #endif /* __cplusplus */ -typedef struct dc_usb_desc_t { - unsigned short vid; - unsigned short pid; -} dc_usb_desc_t; - int dc_descriptor_filter (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata); diff --git a/src/descriptor.c b/src/descriptor.c index d90b54e..79c2d7c 100644 --- a/src/descriptor.c +++ b/src/descriptor.c @@ -23,6 +23,9 @@ #include #include +#include +#include + #include "descriptor-private.h" #include "iterator-private.h" #include "platform.h" @@ -496,6 +499,15 @@ dc_match_usb (const void *key, const void *value) return k->vid == v->vid && k->pid == v->pid; } +static int +dc_match_usbhid (const void *key, const void *value) +{ + const dc_usbhid_desc_t *k = (const dc_usbhid_desc_t *) key; + const dc_usbhid_desc_t *v = (const dc_usbhid_desc_t *) value; + + return k->vid == v->vid && k->pid == v->pid; +} + static int dc_match_number_with_prefix (const void *key, const void *value) { @@ -569,7 +581,7 @@ dc_filter_uwatec (dc_descriptor_t *descriptor, dc_transport_t transport, const v "UWATEC Galileo", "UWATEC Galileo Sol", }; - static const dc_usb_desc_t usbhid[] = { + static const dc_usbhid_desc_t usbhid[] = { {0x2e6c, 0x3201}, // G2, G2 TEK {0x2e6c, 0x3211}, // G2 Console {0x2e6c, 0x4201}, // G2 HUD @@ -587,7 +599,7 @@ dc_filter_uwatec (dc_descriptor_t *descriptor, dc_transport_t transport, const v if (transport == DC_TRANSPORT_IRDA) { return DC_FILTER_INTERNAL (userdata, irda, 0, dc_match_name); } else if (transport == DC_TRANSPORT_USBHID) { - return DC_FILTER_INTERNAL (userdata, usbhid, 0, dc_match_usb); + return DC_FILTER_INTERNAL (userdata, usbhid, 0, dc_match_usbhid); } else if (transport == DC_TRANSPORT_BLE) { return DC_FILTER_INTERNAL (userdata, bluetooth, 0, dc_match_name); } @@ -598,7 +610,7 @@ dc_filter_uwatec (dc_descriptor_t *descriptor, dc_transport_t transport, const v static int dc_filter_suunto (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata) { - static const dc_usb_desc_t usbhid[] = { + static const dc_usbhid_desc_t usbhid[] = { {0x1493, 0x0030}, // Eon Steel {0x1493, 0x0033}, // Eon Core {0x1493, 0x0035}, // D5 @@ -612,7 +624,7 @@ dc_filter_suunto (dc_descriptor_t *descriptor, dc_transport_t transport, const v }; if (transport == DC_TRANSPORT_USBHID) { - return DC_FILTER_INTERNAL (userdata, usbhid, 0, dc_match_usb); + return DC_FILTER_INTERNAL (userdata, usbhid, 0, dc_match_usbhid); } else if (transport == DC_TRANSPORT_BLE) { return DC_FILTER_INTERNAL (userdata, bluetooth, 0, dc_match_prefix); } diff --git a/src/usbhid.c b/src/usbhid.c index 3ed94d7..04e35d9 100644 --- a/src/usbhid.c +++ b/src/usbhid.c @@ -438,7 +438,7 @@ dc_usbhid_iterator_next (dc_iterator_t *abstract, void *out) return syserror (rc); } - dc_usb_desc_t usb = {dev.idVendor, dev.idProduct}; + dc_usbhid_desc_t usb = {dev.idVendor, dev.idProduct}; if (!dc_descriptor_filter (iterator->descriptor, DC_TRANSPORT_USBHID, &usb)) { continue; } @@ -522,7 +522,7 @@ dc_usbhid_iterator_next (dc_iterator_t *abstract, void *out) struct hid_device_info *current = iterator->current; iterator->current = current->next; - dc_usb_desc_t usb = {current->vendor_id, current->product_id}; + dc_usbhid_desc_t usb = {current->vendor_id, current->product_id}; if (!dc_descriptor_filter (iterator->descriptor, DC_TRANSPORT_USBHID, &usb)) { continue; } From ed871137b1f9d9a9d54c28951288eb44475e7e99 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Sun, 20 Aug 2023 22:13:45 +0200 Subject: [PATCH 34/51] Export the filter function in the public api The functionality provided by the filter function is not only useful for the built-in transports, but also for the applications. For example in combination with a custom transport. --- contrib/msvc/libdivecomputer.vcxproj | 1 - include/libdivecomputer/descriptor.h | 3 +++ src/Makefile.am | 2 +- src/bluetooth.c | 1 - src/descriptor-private.h | 37 ---------------------------- src/descriptor.c | 2 +- src/irda.c | 1 - src/libdivecomputer.symbols | 1 + src/serial_posix.c | 1 - src/serial_win32.c | 1 - src/usb.c | 1 - src/usbhid.c | 1 - 12 files changed, 6 insertions(+), 46 deletions(-) delete mode 100644 src/descriptor-private.h diff --git a/contrib/msvc/libdivecomputer.vcxproj b/contrib/msvc/libdivecomputer.vcxproj index 7f1335c..704ef8b 100644 --- a/contrib/msvc/libdivecomputer.vcxproj +++ b/contrib/msvc/libdivecomputer.vcxproj @@ -331,7 +331,6 @@ - diff --git a/include/libdivecomputer/descriptor.h b/include/libdivecomputer/descriptor.h index a2b4495..ec6a6c6 100644 --- a/include/libdivecomputer/descriptor.h +++ b/include/libdivecomputer/descriptor.h @@ -52,6 +52,9 @@ dc_descriptor_get_model (dc_descriptor_t *descriptor); unsigned int dc_descriptor_get_transports (dc_descriptor_t *descriptor); +int +dc_descriptor_filter (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/Makefile.am b/src/Makefile.am index de59dd6..be3f2e3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -16,7 +16,7 @@ endif libdivecomputer_la_SOURCES = \ version.c \ - descriptor-private.h descriptor.c \ + descriptor.c \ iostream-private.h iostream.c \ iterator-private.h iterator.c \ common-private.h common.c \ diff --git a/src/bluetooth.c b/src/bluetooth.c index cc143b7..309953c 100644 --- a/src/bluetooth.c +++ b/src/bluetooth.c @@ -51,7 +51,6 @@ #include "context-private.h" #include "iostream-private.h" #include "iterator-private.h" -#include "descriptor-private.h" #include "platform.h" #ifdef _WIN32 diff --git a/src/descriptor-private.h b/src/descriptor-private.h deleted file mode 100644 index 77bdbb6..0000000 --- a/src/descriptor-private.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * libdivecomputer - * - * Copyright (C) 2017 Jef Driesen - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -#ifndef DC_DESCRIPTOR_PRIVATE_H -#define DC_DESCRIPTOR_PRIVATE_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -int -dc_descriptor_filter (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* DC_DESCRIPTOR_PRIVATE_H */ diff --git a/src/descriptor.c b/src/descriptor.c index 79c2d7c..77d55f6 100644 --- a/src/descriptor.c +++ b/src/descriptor.c @@ -23,10 +23,10 @@ #include #include +#include #include #include -#include "descriptor-private.h" #include "iterator-private.h" #include "platform.h" diff --git a/src/irda.c b/src/irda.c index 6bd927c..dd5397b 100644 --- a/src/irda.c +++ b/src/irda.c @@ -47,7 +47,6 @@ #include "context-private.h" #include "iostream-private.h" #include "iterator-private.h" -#include "descriptor-private.h" #include "array.h" #include "platform.h" diff --git a/src/libdivecomputer.symbols b/src/libdivecomputer.symbols index 477f1ec..c829852 100644 --- a/src/libdivecomputer.symbols +++ b/src/libdivecomputer.symbols @@ -34,6 +34,7 @@ dc_descriptor_get_product dc_descriptor_get_type dc_descriptor_get_model dc_descriptor_get_transports +dc_descriptor_filter dc_iostream_get_transport dc_iostream_set_timeout diff --git a/src/serial_posix.c b/src/serial_posix.c index 51b1037..792a1c9 100644 --- a/src/serial_posix.c +++ b/src/serial_posix.c @@ -57,7 +57,6 @@ #include "context-private.h" #include "iostream-private.h" #include "iterator-private.h" -#include "descriptor-private.h" #include "platform.h" #include "timer.h" diff --git a/src/serial_win32.c b/src/serial_win32.c index 30fe0e9..e506cbd 100644 --- a/src/serial_win32.c +++ b/src/serial_win32.c @@ -31,7 +31,6 @@ #include "context-private.h" #include "iostream-private.h" #include "iterator-private.h" -#include "descriptor-private.h" #include "platform.h" static dc_status_t dc_serial_iterator_next (dc_iterator_t *iterator, void *item); diff --git a/src/usb.c b/src/usb.c index 80083f6..d7074cb 100644 --- a/src/usb.c +++ b/src/usb.c @@ -39,7 +39,6 @@ #include "common-private.h" #include "context-private.h" #include "iostream-private.h" -#include "descriptor-private.h" #include "iterator-private.h" #include "platform.h" #include "array.h" diff --git a/src/usbhid.c b/src/usbhid.c index 04e35d9..b7818e0 100644 --- a/src/usbhid.c +++ b/src/usbhid.c @@ -57,7 +57,6 @@ #include "common-private.h" #include "context-private.h" #include "iostream-private.h" -#include "descriptor-private.h" #include "iterator-private.h" #include "platform.h" From fe9b47f4bd8e2f23b7f3267a6bcac27fa6f0100e Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Tue, 22 Aug 2023 23:05:54 +0200 Subject: [PATCH 35/51] Document the device descriptor functions --- include/libdivecomputer/descriptor.h | 64 ++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/include/libdivecomputer/descriptor.h b/include/libdivecomputer/descriptor.h index ec6a6c6..bdd8c73 100644 --- a/include/libdivecomputer/descriptor.h +++ b/include/libdivecomputer/descriptor.h @@ -29,29 +29,93 @@ extern "C" { #endif /* __cplusplus */ +/** + * Opaque object representing a supported dive computer. + */ typedef struct dc_descriptor_t dc_descriptor_t; +/** + * Create an iterator to enumerate the supported dive computers. + * + * @param[out] iterator A location to store the iterator. + * @returns #DC_STATUS_SUCCESS on success, or another #dc_status_t code + * on failure. + */ dc_status_t dc_descriptor_iterator (dc_iterator_t **iterator); +/** + * Free the device descriptor. + * + * @param[in] descriptor A valid device descriptor. + */ void dc_descriptor_free (dc_descriptor_t *descriptor); +/** + * Get the vendor name of the dive computer. + * + * @param[in] descriptor A valid device descriptor. + * @returns The vendor name of the dive computer on success, or NULL on failure. + */ const char * dc_descriptor_get_vendor (dc_descriptor_t *descriptor); +/** + * Get the product name of the dive computer. + * + * @param[in] descriptor A valid device descriptor. + * @returns The product name of the dive computer on success, or NULL on + * failure. + */ const char * dc_descriptor_get_product (dc_descriptor_t *descriptor); +/** + * Get the family type of the dive computer. + * + * @param[in] descriptor A valid device descriptor. + * @returns The family type of the dive computer on success, or DC_FAMILY_NULL + * on failure. + */ dc_family_t dc_descriptor_get_type (dc_descriptor_t *descriptor); +/** + * Get the model number of the dive computer. + * + * @param[in] descriptor A valid device descriptor. + * @returns The model number of the dive computer on success, or zero on + * failure. + */ unsigned int dc_descriptor_get_model (dc_descriptor_t *descriptor); +/** + * Get all transports supported by the dive computer. + * + * @param[in] descriptor A valid device descriptor. + * @returns A bitmask with all the transports supported by the dive computer on + * success, or DC_TRANSPORT_NONE on failure. + */ unsigned int dc_descriptor_get_transports (dc_descriptor_t *descriptor); +/** + * Check if a low-level I/O device matches a supported dive computer. + * + * @param[in] descriptor A valid device descriptor. + * @param[in] transport The transport type of the I/O device. + * @param[in] userdata A pointer to a transport specific data structure: + * - DC_TRANSPORT_SERIAL: Name of the device node (string) + * - DC_TRANSPORT_USB: USB VID/PID (#dc_usb_desc_t) + * - DC_TRANSPORT_USBHID: USB VID/PID (#dc_usbhid_desc_t) + * - DC_TRANSPORT_IRDA: IrDA device name (string) + * - DC_TRANSPORT_BLUETOOTH: Bluetooth device name (string) + * - DC_TRANSPORT_BLE: Bluetooth device name (string) + * @returns Non-zero if the device matches a supported dive computer, or zero if + * there is no match. + */ int dc_descriptor_filter (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata); From 330cb889525ef878dcf844e308e30c6227c57eff Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Fri, 7 Apr 2023 13:29:41 +0200 Subject: [PATCH 36/51] Use plain ascii text in the code comments --- src/shearwater_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shearwater_common.c b/src/shearwater_common.c index ca3f237..f27bc9a 100644 --- a/src/shearwater_common.c +++ b/src/shearwater_common.c @@ -93,7 +93,7 @@ shearwater_common_decompress_lre (unsigned char *data, unsigned int size, dc_buf // The 9th bit indicates whether the remaining 8 bits represent // a run of zero bytes or not. If the bit is set, the value is - // not a run and doesn’t need expansion. If the bit is not set, + // not a run and doesn't need expansion. If the bit is not set, // the value contains the number of zero bytes in the run. A // zero-length run indicates the end of the compressed stream. if (value & 0x100) { From baa1c494c14b3874b499a7a1f50fb9e97866ab7e Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Thu, 7 Sep 2023 20:02:36 +0200 Subject: [PATCH 37/51] Use a symbolic constant for the header size --- src/cressi_edy_parser.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cressi_edy_parser.c b/src/cressi_edy_parser.c index 6d46f63..951c032 100644 --- a/src/cressi_edy_parser.c +++ b/src/cressi_edy_parser.c @@ -31,6 +31,8 @@ #define IQ700 0x05 #define EDY 0x08 +#define SZ_HEADER 32 + typedef struct cressi_edy_parser_t cressi_edy_parser_t; struct cressi_edy_parser_t { @@ -97,7 +99,7 @@ cressi_edy_parser_create (dc_parser_t **out, dc_context_t *context, const unsign static dc_status_t cressi_edy_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime) { - if (abstract->size < 32) + if (abstract->size < SZ_HEADER) return DC_STATUS_DATAFORMAT; const unsigned char *p = abstract->data; @@ -121,7 +123,7 @@ cressi_edy_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsign { cressi_edy_parser_t *parser = (cressi_edy_parser_t *) abstract; - if (abstract->size < 32) + if (abstract->size < SZ_HEADER) return DC_STATUS_DATAFORMAT; const unsigned char *p = abstract->data; @@ -180,7 +182,7 @@ cressi_edy_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t c unsigned int ngasmixes = cressi_edy_parser_count_gasmixes(data); unsigned int gasmix = 0xFFFFFFFF; - unsigned int offset = 32; + unsigned int offset = SZ_HEADER; while (offset + 2 <= size) { dc_sample_value_t sample = {0}; From 072f0d4242736dc4ed807491921160d0acd8007e Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Thu, 7 Sep 2023 20:13:12 +0200 Subject: [PATCH 38/51] Fix a potential buffer overflow --- src/atomics_cobalt.c | 8 ++++++++ src/citizen_aqualand.c | 8 ++++++++ src/cressi_edy.c | 9 +++++++++ 3 files changed, 25 insertions(+) diff --git a/src/atomics_cobalt.c b/src/atomics_cobalt.c index 1c2e3a5..8c38696 100644 --- a/src/atomics_cobalt.c +++ b/src/atomics_cobalt.c @@ -41,6 +41,8 @@ #define FP_OFFSET 20 +#define SZ_HEADER 228 + #define SZ_MEMORY1 (29 * 64 * 1024) // Cobalt 1 #define SZ_MEMORY2 (41 * 64 * 1024) // Cobalt 2 #define SZ_VERSION 14 @@ -347,6 +349,12 @@ atomics_cobalt_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac return DC_STATUS_SUCCESS; } + if (size < SZ_HEADER) { + ERROR (abstract->context, "Dive header is too small (%u).", size); + dc_buffer_free (buffer); + return DC_STATUS_DATAFORMAT; + } + if (memcmp (data + FP_OFFSET, device->fingerprint, sizeof (device->fingerprint)) == 0) { dc_buffer_free (buffer); return DC_STATUS_SUCCESS; diff --git a/src/citizen_aqualand.c b/src/citizen_aqualand.c index 63760ac..66455f4 100644 --- a/src/citizen_aqualand.c +++ b/src/citizen_aqualand.c @@ -31,6 +31,8 @@ #define ISINSTANCE(device) dc_device_isinstance((device), &citizen_aqualand_device_vtable) +#define SZ_HEADER 32 + typedef struct citizen_aqualand_device_t { dc_device_t base; dc_iostream_t *iostream; @@ -200,6 +202,12 @@ citizen_aqualand_device_foreach (dc_device_t *abstract, dc_dive_callback_t callb unsigned char *data = dc_buffer_get_data (buffer); unsigned int size = dc_buffer_get_size (buffer); + if (size < SZ_HEADER) { + ERROR (abstract->context, "Dive header is too small (%u).", size); + dc_buffer_free (buffer); + return DC_STATUS_DATAFORMAT; + } + if (callback && memcmp (data + 0x05, device->fingerprint, sizeof (device->fingerprint)) != 0) { callback (data, size, data + 0x05, sizeof (device->fingerprint), userdata); } diff --git a/src/cressi_edy.c b/src/cressi_edy.c index 86ed76e..d61b84e 100644 --- a/src/cressi_edy.c +++ b/src/cressi_edy.c @@ -38,6 +38,8 @@ #define SZ_PACKET 0x80 #define SZ_PAGE (SZ_PACKET / 4) +#define SZ_HEADER 32 + #define IQ700 0x05 #define EDY 0x08 @@ -522,6 +524,13 @@ cressi_edy_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, v return rc; } + if (length < SZ_HEADER) { + ERROR (abstract->context, "Dive header is too small (%u).", length); + dc_rbstream_free (rbstream); + free (buffer); + return DC_STATUS_DATAFORMAT; + } + unsigned char *p = buffer + offset; if (memcmp (p, device->fingerprint, sizeof (device->fingerprint)) == 0) From a7e7439cabbaca7702e40aca088afccb951a4d8a Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Fri, 25 Aug 2023 18:31:11 +0200 Subject: [PATCH 39/51] Setup the 2 byte command header internally Instead of setting up the two byte command header in every function, move this logic to a central place. --- src/mares_iconhd.c | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/src/mares_iconhd.c b/src/mares_iconhd.c index 2f5bd28..d1189c7 100644 --- a/src/mares_iconhd.c +++ b/src/mares_iconhd.c @@ -21,7 +21,6 @@ #include // memcpy, memcmp #include // malloc, free -#include // assert #include "mares_iconhd.h" #include "context-private.h" @@ -178,19 +177,21 @@ mares_iconhd_get_model (mares_iconhd_device_t *device) static dc_status_t mares_iconhd_packet (mares_iconhd_device_t *device, - const unsigned char command[], unsigned int csize, + unsigned char cmd, + const unsigned char data[], unsigned int size, unsigned char answer[], unsigned int asize) { dc_status_t status = DC_STATUS_SUCCESS; dc_device_t *abstract = (dc_device_t *) device; - assert (csize >= 2); - if (device_is_cancelled (abstract)) return DC_STATUS_CANCELLED; // Send the command header to the dive computer. - status = dc_iostream_write (device->iostream, command, 2, NULL); + const unsigned char command[2] = { + cmd, cmd ^ XOR, + }; + status = dc_iostream_write (device->iostream, command, sizeof(command), NULL); if (status != DC_STATUS_SUCCESS) { ERROR (abstract->context, "Failed to send the command."); return status; @@ -211,8 +212,8 @@ mares_iconhd_packet (mares_iconhd_device_t *device, } // Send the command payload to the dive computer. - if (csize > 2) { - status = dc_iostream_write (device->iostream, command + 2, csize - 2, NULL); + if (size) { + status = dc_iostream_write (device->iostream, data, size, NULL); if (status != DC_STATUS_SUCCESS) { ERROR (abstract->context, "Failed to send the command."); return status; @@ -244,11 +245,11 @@ mares_iconhd_packet (mares_iconhd_device_t *device, } static dc_status_t -mares_iconhd_transfer (mares_iconhd_device_t *device, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize) +mares_iconhd_transfer (mares_iconhd_device_t *device, unsigned char cmd, const unsigned char data[], unsigned int size, unsigned char answer[], unsigned int asize) { unsigned int nretries = 0; dc_status_t rc = DC_STATUS_SUCCESS; - while ((rc = mares_iconhd_packet (device, command, csize, answer, asize)) != DC_STATUS_SUCCESS) { + while ((rc = mares_iconhd_packet (device, cmd, data, size, answer, asize)) != DC_STATUS_SUCCESS) { // Automatically discard a corrupted packet, // and request a new one. if (rc != DC_STATUS_PROTOCOL && rc != DC_STATUS_TIMEOUT) @@ -283,23 +284,21 @@ mares_iconhd_read_object(mares_iconhd_device_t *device, dc_event_progress_t *pro // Transfer the init packet. unsigned char rsp_init[16]; - unsigned char cmd_init[18] = { - CMD_OBJ_INIT, - CMD_OBJ_INIT ^ XOR, + unsigned char cmd_init[16] = { 0x40, (index >> 0) & 0xFF, (index >> 8) & 0xFF, subindex & 0xFF }; memset (cmd_init + 6, 0x00, sizeof(cmd_init) - 6); - status = mares_iconhd_transfer (device, cmd_init, sizeof (cmd_init), rsp_init, sizeof (rsp_init)); + status = mares_iconhd_transfer (device, CMD_OBJ_INIT, cmd_init, sizeof (cmd_init), rsp_init, sizeof (rsp_init)); if (status != DC_STATUS_SUCCESS) { ERROR (abstract->context, "Failed to transfer the init packet."); return status; } // Verify the packet header. - if (memcmp (cmd_init + 3, rsp_init + 1, 3) != 0) { + if (memcmp (cmd_init + 1, rsp_init + 1, 3) != 0) { ERROR (abstract->context, "Unexpected packet header."); return DC_STATUS_PROTOCOL; } @@ -347,8 +346,7 @@ mares_iconhd_read_object(mares_iconhd_device_t *device, dc_event_progress_t *pro // Transfer the segment packet. unsigned char rsp_segment[1 + 504]; - unsigned char cmd_segment[] = {cmd, cmd ^ XOR}; - status = mares_iconhd_transfer (device, cmd_segment, sizeof (cmd_segment), rsp_segment, len + 1); + status = mares_iconhd_transfer (device, cmd, NULL, 0, rsp_segment, len + 1); if (status != DC_STATUS_SUCCESS) { ERROR (abstract->context, "Failed to transfer the segment packet."); return status; @@ -447,8 +445,7 @@ mares_iconhd_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_ dc_iostream_purge (device->iostream, DC_DIRECTION_ALL); // Send the version command. - unsigned char command[] = {CMD_VERSION, CMD_VERSION ^ XOR}; - status = mares_iconhd_transfer (device, command, sizeof (command), + status = mares_iconhd_transfer (device, CMD_VERSION, NULL, 0, device->version, sizeof (device->version)); if (status != DC_STATUS_SUCCESS) { goto error_free_iostream; @@ -460,9 +457,8 @@ mares_iconhd_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_ // Read the size of the flash memory. unsigned int memsize = 0; if (device->model == QUAD) { - unsigned char cmd_flash[] = {CMD_FLASHSIZE, CMD_FLASHSIZE ^ XOR}; unsigned char rsp_flash[4] = {0}; - status = mares_iconhd_transfer (device, cmd_flash, sizeof (cmd_flash), rsp_flash, sizeof (rsp_flash)); + status = mares_iconhd_transfer (device, CMD_FLASHSIZE, NULL, 0, rsp_flash, sizeof (rsp_flash)); if (status != DC_STATUS_SUCCESS) { WARNING (context, "Failed to read the flash memory size."); } else { @@ -575,7 +571,7 @@ mares_iconhd_device_read (dc_device_t *abstract, unsigned int address, unsigned len = device->packetsize; // Read the packet. - unsigned char command[] = {CMD_READ, CMD_READ ^ XOR, + unsigned char command[] = { (address ) & 0xFF, (address >> 8) & 0xFF, (address >> 16) & 0xFF, @@ -584,7 +580,7 @@ mares_iconhd_device_read (dc_device_t *abstract, unsigned int address, unsigned (len >> 8) & 0xFF, (len >> 16) & 0xFF, (len >> 24) & 0xFF}; - rc = mares_iconhd_transfer (device, command, sizeof (command), data, len); + rc = mares_iconhd_transfer (device, CMD_READ, command, sizeof (command), data, len); if (rc != DC_STATUS_SUCCESS) return rc; From e83732e200620882b13804f1ca54c1ab90a38188 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Fri, 25 Aug 2023 18:39:55 +0200 Subject: [PATCH 40/51] Fix the Mares Bluelink Pro communication Sending the two byte command header and then waiting for the ack byte before sending the remainder of the command payload causes problems for some (but not all) users. Most likely the extra roundtrip time due to waiting for the ack byte results in a delay that sometimes exceeds a timeout in the dive computer while it's waiting for the payload data. On the other hand, sending both the command header and the payload data in one single packet is also not an option, because it causes problems for some models, like the Mares Matrix. See commit 59bfb0f3189b14ae858650b851539d59e3fefe86 for details. As an alternative solution, send the packet payload immediately after the header, without waiting for the ack byte. This eliminates the extra roundtrip time, while still sending out two separate bluetooth packets. --- src/mares_iconhd.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/mares_iconhd.c b/src/mares_iconhd.c index d1189c7..ede2658 100644 --- a/src/mares_iconhd.c +++ b/src/mares_iconhd.c @@ -197,6 +197,15 @@ mares_iconhd_packet (mares_iconhd_device_t *device, return status; } + // Send the command payload to the dive computer. + if (size) { + status = dc_iostream_write (device->iostream, data, size, NULL); + if (status != DC_STATUS_SUCCESS) { + ERROR (abstract->context, "Failed to send the command."); + return status; + } + } + // Receive the header byte. unsigned char header[1] = {0}; status = dc_iostream_read (device->iostream, header, sizeof (header), NULL); @@ -211,15 +220,6 @@ mares_iconhd_packet (mares_iconhd_device_t *device, return DC_STATUS_PROTOCOL; } - // Send the command payload to the dive computer. - if (size) { - status = dc_iostream_write (device->iostream, data, size, NULL); - if (status != DC_STATUS_SUCCESS) { - ERROR (abstract->context, "Failed to send the command."); - return status; - } - } - // Read the packet. status = dc_iostream_read (device->iostream, answer, asize, NULL); if (status != DC_STATUS_SUCCESS) { From 3c50e91a1096332df66b2d33d64e5a8dc9136ab9 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Sun, 29 Oct 2023 19:56:40 +0100 Subject: [PATCH 41/51] Allow a zero timestamp for the first sample Previously the timestamp of the first sample was always a non-zero value, but the IX3M 2 with the APOS5 firmware now appears to record a timestamp of zero. This was incorrectly detected as a backwards time jump because the time is also initialized to zero. --- src/divesystem_idive_parser.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/divesystem_idive_parser.c b/src/divesystem_idive_parser.c index c7f5fb4..6b286c0 100644 --- a/src/divesystem_idive_parser.c +++ b/src/divesystem_idive_parser.c @@ -440,8 +440,8 @@ divesystem_idive_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba // Time (seconds). unsigned int timestamp = array_uint32_le (data + offset + 2); - if (timestamp <= time) { - ERROR (abstract->context, "Timestamp moved backwards."); + if (timestamp <= time && time != 0) { + ERROR (abstract->context, "Timestamp moved backwards (%u %u).", timestamp, time); return DC_STATUS_DATAFORMAT; } time = timestamp; From e1762fc8bddf9d742387617f87b990729c0e482f Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Wed, 1 Nov 2023 21:12:49 +0100 Subject: [PATCH 42/51] Skip all non-sample records The IX3M 2 with the APOS5 firmware supports a new info record containing the GPS coordinates. To be able to identify this new record type, the previously reserved field at byte offset 52 is now used to store the record type: zero for the existing sample record and one for the new info record. This also fixes the underlying problem of the zero timestamp in commit 3c50e91a1096332df66b2d33d64e5a8dc9136ab9, because the zero timestamp was the result of incorrectly interpreting the first info record as a sample record. --- src/divesystem_idive_parser.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/divesystem_idive_parser.c b/src/divesystem_idive_parser.c index 6b286c0..c2c934e 100644 --- a/src/divesystem_idive_parser.c +++ b/src/divesystem_idive_parser.c @@ -58,6 +58,9 @@ #define IX3M2_ZHL16C 2 #define IX3M2_VPM 3 +#define REC_SAMPLE 0 +#define REC_INFO 1 + typedef struct divesystem_idive_parser_t divesystem_idive_parser_t; typedef struct divesystem_idive_gasmix_t { @@ -438,6 +441,16 @@ divesystem_idive_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba while (offset + samplesize <= size) { dc_sample_value_t sample = {0}; + // Get the record type. + unsigned int type = ISIX3M(parser->model) ? + array_uint16_le (data + offset + 52) : + REC_SAMPLE; + if (type != REC_SAMPLE) { + // Skip non-sample records. + offset += samplesize; + continue; + } + // Time (seconds). unsigned int timestamp = array_uint32_le (data + offset + 2); if (timestamp <= time && time != 0) { From 2d9008aff703721ac71bbc00bbf3a9f57fd029ce Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Sun, 12 Nov 2023 21:01:57 +0100 Subject: [PATCH 43/51] Remove disabled gas mixes Returning disabled gas mixes to the application mainly results in lots of unnecessary information. Therefore, remove all disabled gas mixes, unless they are actively used. Many other dive computers do not even include disabled gas mixes in the data. Unlike previously assumed, the on/off state of each gas mix is actually available in the PNF data format (opening record 4). For the older Predator data format, this info isn't available and all gas mixes are manually marked as enabled. --- src/shearwater_predator_parser.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/shearwater_predator_parser.c b/src/shearwater_predator_parser.c index fc06b66..167f585 100644 --- a/src/shearwater_predator_parser.c +++ b/src/shearwater_predator_parser.c @@ -107,6 +107,8 @@ typedef struct shearwater_predator_gasmix_t { unsigned int oxygen; unsigned int helium; unsigned int diluent; + unsigned int enabled; + unsigned int active; } shearwater_predator_gasmix_t; typedef struct shearwater_predator_tank_t { @@ -245,6 +247,8 @@ shearwater_common_parser_create (dc_parser_t **out, dc_context_t *context, const parser->gasmix[i].oxygen = 0; parser->gasmix[i].helium = 0; parser->gasmix[i].diluent = 0; + parser->gasmix[i].enabled = 0; + parser->gasmix[i].active = 0; } parser->ntanks = 0; for (unsigned int i = 0; i < NTANKS; ++i) { @@ -395,6 +399,7 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser) gasmix[i].oxygen = data[20 + i]; gasmix[i].helium = data[30 + i]; gasmix[i].diluent = i >= 5; + gasmix[i].enabled = 1; } } @@ -443,6 +448,8 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser) ngasmixes = idx + 1; } + gasmix[idx].active = 1; + o2_previous = o2; he_previous = he; dil_previous = ccr; @@ -552,6 +559,13 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser) } } } + + // Gas mix on/off state. + unsigned int state = array_uint16_be (data + offset + 17); + for (unsigned int i = 0; i < NFIXED; ++i) { + gasmix[i].enabled = (state & (1 << i)) != 0; + } + unsigned int gtrmode = data[offset + 29]; if (popcount(gtrmode) >= 2) { for (unsigned int i = 0; i < 4; ++i) { @@ -678,6 +692,8 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser) for (unsigned int i = 0; i < ngasmixes; ++i) { if (gasmix[i].oxygen == 0 && gasmix[i].helium == 0) continue; + if (!gasmix[i].enabled && !gasmix[i].active) + continue; if (gasmix[i].diluent && !shearwater_predator_is_ccr (divemode)) continue; parser->gasmix[parser->ngasmixes] = gasmix[i]; From 08d8c3e13272bc4c33f62cfdc57a34702cff7191 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Wed, 1 Nov 2023 21:25:18 +0100 Subject: [PATCH 44/51] Add support for parsing the compass bearings When no compass bearing is set on the dive computer, the stored value is initialized to zero. Since this can also be a valid value, those zero values are only ignored untill another non-zero value is present. In later firmware versions, the value will get initialized to 0xFFFF instead. --- src/divesystem_idive_parser.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/divesystem_idive_parser.c b/src/divesystem_idive_parser.c index c2c934e..c13a804 100644 --- a/src/divesystem_idive_parser.c +++ b/src/divesystem_idive_parser.c @@ -413,6 +413,7 @@ divesystem_idive_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba unsigned int algorithm_previous = INVALID; unsigned int gf_low = INVALID; unsigned int gf_high = INVALID; + unsigned int have_bearing = 0; unsigned int firmware = 0; unsigned int apos4 = 0; @@ -618,6 +619,16 @@ divesystem_idive_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba tank[tank_idx].endpressure = pressure; } } + + // Compass bearing + unsigned int bearing = array_uint16_le (data + offset + 50); + if (bearing != 0) { + have_bearing = 1; // Stop ignoring zero values. + } + if (have_bearing && bearing != 0xFFFF) { + sample.bearing = bearing; + if (callback) callback (DC_SAMPLE_BEARING, &sample, userdata); + } } offset += samplesize; From d47e1ce02b1cc4af1eddeca4215521132a5c927c Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Fri, 5 Jan 2024 00:01:24 +0100 Subject: [PATCH 45/51] Add support for the Scubapro G3 and Luna 2.0 The new models appear to be compatible with the previous G2, but with new model numbers and bluetooth names. The USB VID/PID for the G3 is still unknown. Reported-by: Greg McLaughlin --- src/descriptor.c | 6 ++++++ src/uwatec_smart_parser.c | 12 ++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/descriptor.c b/src/descriptor.c index 77d55f6..cc03549 100644 --- a/src/descriptor.c +++ b/src/descriptor.c @@ -170,7 +170,10 @@ static const dc_descriptor_t g_descriptors[] = { {"Scubapro", "G2 TEK", DC_FAMILY_UWATEC_SMART, 0x31, DC_TRANSPORT_USBHID | DC_TRANSPORT_BLE, dc_filter_uwatec}, {"Scubapro", "G2", DC_FAMILY_UWATEC_SMART, 0x32, DC_TRANSPORT_USBHID | DC_TRANSPORT_BLE, dc_filter_uwatec}, {"Scubapro", "G2 Console", DC_FAMILY_UWATEC_SMART, 0x32, DC_TRANSPORT_USBHID | DC_TRANSPORT_BLE, dc_filter_uwatec}, + {"Scubapro", "G3", DC_FAMILY_UWATEC_SMART, 0x34, DC_TRANSPORT_USBHID | DC_TRANSPORT_BLE, dc_filter_uwatec}, {"Scubapro", "G2 HUD", DC_FAMILY_UWATEC_SMART, 0x42, DC_TRANSPORT_USBHID | DC_TRANSPORT_BLE, dc_filter_uwatec}, + {"Scubapro", "Luna 2.0 AI", DC_FAMILY_UWATEC_SMART, 0x50, DC_TRANSPORT_BLE, dc_filter_uwatec}, + {"Scubapro", "Luna 2.0", DC_FAMILY_UWATEC_SMART, 0x51, DC_TRANSPORT_BLE, dc_filter_uwatec}, /* Reefnet */ {"Reefnet", "Sensus", DC_FAMILY_REEFNET_SENSUS, 1, DC_TRANSPORT_SERIAL, NULL}, {"Reefnet", "Sensus Pro", DC_FAMILY_REEFNET_SENSUSPRO, 2, DC_TRANSPORT_SERIAL, NULL}, @@ -594,6 +597,9 @@ dc_filter_uwatec (dc_descriptor_t *descriptor, dc_transport_t transport, const v "A1", "A2", "G2 TEK", + "Galileo 3", + "Luna 2.0 AI", + "Luna 2.0", }; if (transport == DC_TRANSPORT_IRDA) { diff --git a/src/uwatec_smart_parser.c b/src/uwatec_smart_parser.c index c6c356d..8e455a7 100644 --- a/src/uwatec_smart_parser.c +++ b/src/uwatec_smart_parser.c @@ -51,7 +51,10 @@ #define ALADINA2 0x28 #define G2TEK 0x31 #define G2 0x32 +#define G3 0x34 #define G2HUD 0x42 +#define LUNA2AI 0x50 +#define LUNA2 0x51 #define UNSUPPORTED 0xFFFFFFFF @@ -532,7 +535,8 @@ uwatec_smart_parser_cache (uwatec_smart_parser_t *parser) parser->model == G2 || parser->model == ALADINSPORTMATRIX || parser->model == ALADINSQUARE || parser->model == G2HUD || parser->model == ALADINA1 || parser->model == ALADINA2 || - parser->model == G2TEK) { + parser->model == G2TEK || parser->model == G3 || + parser->model == LUNA2AI || parser->model == LUNA2) { unsigned int offset = header->tankpressure + 2 * i; endpressure = array_uint16_le(data + offset); beginpressure = array_uint16_le(data + offset + 2 * header->ngases); @@ -623,9 +627,12 @@ uwatec_smart_parser_create (dc_parser_t **out, dc_context_t *context, const unsi case G2: case G2HUD: case G2TEK: + case G3: case ALADINSPORTMATRIX: case ALADINA1: case ALADINA2: + case LUNA2AI: + case LUNA2: parser->headersize = 84; parser->header = &uwatec_smart_trimix_header; parser->samples = uwatec_smart_galileo_samples; @@ -928,7 +935,8 @@ uwatec_smart_parse (uwatec_smart_parser_t *parser, dc_sample_callback_t callback parser->model == G2 || parser->model == ALADINSPORTMATRIX || parser->model == ALADINSQUARE || parser->model == G2HUD || parser->model == ALADINA1 || parser->model == ALADINA2 || - parser->model == G2TEK) { + parser->model == G2TEK || parser->model == G3 || + parser->model == LUNA2AI || parser->model == LUNA2) { // Uwatec Galileo id = uwatec_galileo_identify (data[offset]); } else { From cfe345aa8e19391a6fa369e376be5dc17e9d6fd3 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Thu, 11 Jan 2024 23:09:11 +0100 Subject: [PATCH 46/51] Exclude O2 sensors without calibration data O2 sensor for which no calibration data is available will always result in a ppO2 value of zero for all samples, which isn't very useful. --- src/divesoft_freedom_parser.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/divesoft_freedom_parser.c b/src/divesoft_freedom_parser.c index 49c0f0f..9647511 100644 --- a/src/divesoft_freedom_parser.c +++ b/src/divesoft_freedom_parser.c @@ -1017,8 +1017,8 @@ divesoft_freedom_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callba for (unsigned int i = 0; i < NSENSORS; ++i) { unsigned int value = array_uint16_le (data + offset + 4 + i * 2); unsigned int state = data[offset + 12 + i]; - if (!parser->calibrated || state == SENSTAT_UNCALIBRATED || - state == SENSTAT_NOT_EXIST) + if (!parser->calibrated || parser->calibration[i] == 0 || + state == SENSTAT_UNCALIBRATED || state == SENSTAT_NOT_EXIST) continue; sample.ppo2.sensor = i; sample.ppo2.value = value / 100.0 * parser->calibration[i] / BAR; From de6696bc7fb4d129ba9be6175a684c53a2b8c659 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Mon, 15 Jan 2024 07:09:27 +0100 Subject: [PATCH 47/51] Add support for the Shearwater Tern --- src/descriptor.c | 2 ++ src/shearwater_common.c | 3 +++ src/shearwater_common.h | 1 + 3 files changed, 6 insertions(+) diff --git a/src/descriptor.c b/src/descriptor.c index cc03549..66555e7 100644 --- a/src/descriptor.c +++ b/src/descriptor.c @@ -357,6 +357,7 @@ static const dc_descriptor_t g_descriptors[] = { {"Shearwater", "Peregrine", DC_FAMILY_SHEARWATER_PETREL, 9, DC_TRANSPORT_BLE, dc_filter_shearwater}, {"Shearwater", "Petrel 3", DC_FAMILY_SHEARWATER_PETREL, 10, DC_TRANSPORT_BLE, dc_filter_shearwater}, {"Shearwater", "Perdix 2", DC_FAMILY_SHEARWATER_PETREL, 11, DC_TRANSPORT_BLE, dc_filter_shearwater}, + {"Shearwater", "Tern", DC_FAMILY_SHEARWATER_PETREL, 12, DC_TRANSPORT_BLE, dc_filter_shearwater}, /* Dive Rite NiTek Q */ {"Dive Rite", "NiTek Q", DC_FAMILY_DIVERITE_NITEKQ, 0, DC_TRANSPORT_SERIAL, NULL}, /* Citizen Hyper Aqualand */ @@ -668,6 +669,7 @@ dc_filter_shearwater (dc_descriptor_t *descriptor, dc_transport_t transport, con "Perdix 2", "Teric", "Peregrine", + "Tern" }; if (transport == DC_TRANSPORT_BLUETOOTH || transport == DC_TRANSPORT_BLE) { diff --git a/src/shearwater_common.c b/src/shearwater_common.c index f27bc9a..43da455 100644 --- a/src/shearwater_common.c +++ b/src/shearwater_common.c @@ -738,6 +738,9 @@ shearwater_common_get_model (shearwater_common_device_t *device, unsigned int ha case 0x1512: model = PEREGRINE; break; + case 0xC0E0: + model = TERN; + break; default: WARNING (device->base.context, "Unknown hardware type 0x%04x.", hardware); } diff --git a/src/shearwater_common.h b/src/shearwater_common.h index 4c7f186..8078141 100644 --- a/src/shearwater_common.h +++ b/src/shearwater_common.h @@ -51,6 +51,7 @@ extern "C" { #define PEREGRINE 9 #define PETREL3 10 #define PERDIX2 11 +#define TERN 12 #define NSTEPS 10000 #define STEP(i,n) ((NSTEPS * (i) + (n) / 2) / (n)) From 1d0aeecf65834d21b310e189a903eaa84d0e0caf Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Thu, 18 Jan 2024 06:58:42 +0100 Subject: [PATCH 48/51] Fix the React Pro White memory layout --- src/oceanic_atom2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/oceanic_atom2.c b/src/oceanic_atom2.c index cc1e3c3..0c63e16 100644 --- a/src/oceanic_atom2.c +++ b/src/oceanic_atom2.c @@ -339,7 +339,7 @@ static const oceanic_common_layout_t oceanic_reactpro_layout = { 0x0600, /* rb_logbook_end */ 8, /* rb_logbook_entry_size */ 0x0600, /* rb_profile_begin */ - 0xFFF0, /* rb_profile_end */ + 0xFE00, /* rb_profile_end */ 1, /* pt_mode_global */ 1, /* pt_mode_logbook */ 0, /* pt_mode_serial */ From edfb1a9c6722fac9f5f41c6187dc1c03e6988e4f Mon Sep 17 00:00:00 2001 From: Michael Keller Date: Fri, 2 Feb 2024 22:21:03 +1300 Subject: [PATCH 49/51] Import: Update Garmin Descent Import for libdivecomputer Update. Update the importer for Garmin Descent to work with the latest upstream version of libdivecomputer. Signed-off-by: Michael Keller --- .github/workflows/build.yml | 60 ++++++++++++++++++------------------- contrib/android/Android.mk | 6 +++- src/descriptor.c | 5 ++-- src/garmin.c | 19 +++++++----- src/garmin.h | 4 +-- src/garmin_parser.c | 45 +++++++++++++--------------- src/parser.c | 2 +- 7 files changed, 73 insertions(+), 68 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 00ff527..86ef116 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -123,36 +123,36 @@ jobs: name: ${{ github.job }}-${{ matrix.arch }} path: ${{ github.job }}-${{ matrix.arch }}.tar.gz - msvc: - - name: Visual Studio - - runs-on: windows-latest - - strategy: - fail-fast: false - matrix: - platform: [x86, x64] - - env: - CONFIGURATION: Release - - steps: - - uses: actions/checkout@v3 - - uses: msys2/setup-msys2@v2 - with: - install: autoconf automake libtool pkg-config make gcc - - run: | - autoreconf --install --force - ./configure --prefix=/usr - make -C src revision.h - shell: msys2 {0} - - uses: microsoft/setup-msbuild@v1 - - run: msbuild -m -p:Platform=${{ matrix.platform }} -p:Configuration=${{ env.CONFIGURATION }} contrib/msvc/libdivecomputer.vcxproj - - uses: actions/upload-artifact@v3 - with: - name: ${{ github.job }}-${{ matrix.platform }} - path: contrib/msvc/${{ matrix.platform }}/${{ env.CONFIGURATION }}/bin +# msvc: +# +# name: Visual Studio +# +# runs-on: windows-latest +# +# strategy: +# fail-fast: false +# matrix: +# platform: [x86, x64] +# +# env: +# CONFIGURATION: Release +# +# steps: +# - uses: actions/checkout@v3 +# - uses: msys2/setup-msys2@v2 +# with: +# install: autoconf automake libtool pkg-config make gcc +# - run: | +# autoreconf --install --force +# ./configure --prefix=/usr +# make -C src revision.h +# shell: msys2 {0} +# - uses: microsoft/setup-msbuild@v1 +# - run: msbuild -m -p:Platform=${{ matrix.platform }} -p:Configuration=${{ env.CONFIGURATION }} contrib/msvc/libdivecomputer.vcxproj +# - uses: actions/upload-artifact@v3 +# with: +# name: ${{ github.job }}-${{ matrix.platform }} +# path: contrib/msvc/${{ matrix.platform }}/${{ env.CONFIGURATION }}/bin android: diff --git a/contrib/android/Android.mk b/contrib/android/Android.mk index fcceb81..43f5473 100644 --- a/contrib/android/Android.mk +++ b/contrib/android/Android.mk @@ -114,7 +114,11 @@ LOCAL_SRC_FILES := \ src/uwatec_smart.c \ src/uwatec_smart_parser.c \ src/version.c \ - src/zeagle_n2ition3.c + src/zeagle_n2ition3.c \ + src/field-cache.c \ + src/usb_storage.c \ + src/garmin.c \ + src/garmin_parser.c include $(BUILD_SHARED_LIBRARY) include $(CLEAR_VARS) diff --git a/src/descriptor.c b/src/descriptor.c index ac679d1..7a824dc 100644 --- a/src/descriptor.c +++ b/src/descriptor.c @@ -61,7 +61,7 @@ static int dc_filter_oceans (dc_descriptor_t *descriptor, dc_transport_t transpo static int dc_filter_divesoft (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata); // Not merged upstream yet -static int dc_filter_garmin (dc_transport_t transport, const void *userdata, void *params); +static int dc_filter_garmin (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata); static dc_status_t dc_descriptor_iterator_next (dc_iterator_t *iterator, void *item); @@ -858,7 +858,8 @@ dc_filter_divesoft (dc_descriptor_t *descriptor, dc_transport_t transport, const } // Not merged upstream yet -static int dc_filter_garmin (dc_transport_t transport, const void *userdata, void *params) +static int +dc_filter_garmin (dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata) { static const dc_usb_desc_t usbhid[] = { {0x091e, 0x2b2b}, // Garmin Descent Mk1 diff --git a/src/garmin.c b/src/garmin.c index c156097..f51e19a 100644 --- a/src/garmin.c +++ b/src/garmin.c @@ -448,7 +448,6 @@ garmin_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void { dc_status_t status = DC_STATUS_SUCCESS; garmin_device_t *device = (garmin_device_t *) abstract; - dc_parser_t *parser; char pathname[PATH_MAX]; char pathname_input[PATH_MAX]; size_t pathlen; @@ -539,16 +538,12 @@ garmin_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void free(files.array); return DC_STATUS_NOMEMORY; } - if ((rc = garmin_parser_create(&parser, abstract->context) != DC_STATUS_SUCCESS)) { - ERROR (abstract->context, "Failed to create parser for dive verification."); - free(files.array); - return rc; - } dc_event_devinfo_t devinfo; dc_event_devinfo_t *devinfo_p = &devinfo; for (int i = 0; i < files.nr; i++) { const char *name = files.array[i].name; + dc_parser_t *parser; const unsigned char *data; unsigned int size; short is_dive = 0; @@ -574,7 +569,14 @@ garmin_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void data = dc_buffer_get_data(file); size = dc_buffer_get_size(file); - is_dive = !device->model || garmin_parser_is_dive(parser, data, size, devinfo_p); + status = garmin_parser_create(&parser, abstract->context, data, size); + if (status != DC_STATUS_SUCCESS) { + ERROR (abstract->context, "Failed to create parser for dive verification."); + free(files.array); + return rc; + } + + is_dive = !device->model || garmin_parser_is_dive(parser, devinfo_p); if (devinfo_p) { // first time we came through here, let's emit the // devinfo and vendor events @@ -583,6 +585,7 @@ garmin_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void } if (!is_dive) { DEBUG(abstract->context, "decided %s isn't a dive.", name); + dc_parser_destroy(parser); continue; } @@ -591,10 +594,10 @@ garmin_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void progress.current++; device_event_emit(abstract, DC_EVENT_PROGRESS, &progress); + dc_parser_destroy(parser); } free(files.array); - dc_parser_destroy(parser); dc_buffer_free(file); return status; } diff --git a/src/garmin.h b/src/garmin.h index ade3d6c..88bb652 100644 --- a/src/garmin.h +++ b/src/garmin.h @@ -35,12 +35,12 @@ dc_status_t garmin_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream, unsigned int model); dc_status_t -garmin_parser_create (dc_parser_t **parser, dc_context_t *context); +garmin_parser_create (dc_parser_t **parser, dc_context_t *context, const unsigned char data[], size_t size); // we need to be able to call into the parser to check if the // files that we find are actual dives int -garmin_parser_is_dive (dc_parser_t *abstract, const unsigned char *data, unsigned int size, dc_event_devinfo_t *devinfo_p); +garmin_parser_is_dive (dc_parser_t *abstract, dc_event_devinfo_t *devinfo_p); // The dive names are of the form "2018-08-20-10-23-30.fit" // With the terminating zero, that's 24 bytes. diff --git a/src/garmin_parser.c b/src/garmin_parser.c index 466c6d2..106bace 100644 --- a/src/garmin_parser.c +++ b/src/garmin_parser.c @@ -232,12 +232,12 @@ static void garmin_event(struct garmin_parser_t *garmin, if (!sample.event.name) return; - garmin->callback(DC_SAMPLE_EVENT, sample, garmin->userdata); + garmin->callback(DC_SAMPLE_EVENT, &sample, garmin->userdata); return; case 57: sample.gasmix = data; - garmin->callback(DC_SAMPLE_GASMIX, sample, garmin->userdata); + garmin->callback(DC_SAMPLE_GASMIX, &sample, garmin->userdata); dc_tankinfo_t *tankinfo = &garmin->cache.tankinfo[data]; if (!garmin->dive.current_tankinfo || (*tankinfo & DC_TANKINFO_CC_DILUENT) != (*garmin->dive.current_tankinfo & DC_TANKINFO_CC_DILUENT)) { @@ -250,7 +250,7 @@ static void garmin_event(struct garmin_parser_t *garmin, } sample2.event.flags = 2 << SAMPLE_FLAGS_SEVERITY_SHIFT; - garmin->callback(DC_SAMPLE_EVENT, sample2, garmin->userdata); + garmin->callback(DC_SAMPLE_EVENT, &sample2, garmin->userdata); garmin->dive.current_tankinfo = tankinfo; } @@ -324,7 +324,7 @@ static void flush_pending_record(struct garmin_parser_t *garmin) sample.deco.type = DC_DECO_DECOSTOP; sample.deco.time = record->stop_time; sample.deco.depth = record->ceiling; - garmin->callback(DC_SAMPLE_DECO, sample, garmin->userdata); + garmin->callback(DC_SAMPLE_DECO, &sample, garmin->userdata); } if (pending & RECORD_EVENT) { @@ -337,19 +337,19 @@ static void flush_pending_record(struct garmin_parser_t *garmin) sample.pressure.tank = find_tank_index(garmin, record->sensor); sample.pressure.value = record->pressure / 100.0; - garmin->callback(DC_SAMPLE_PRESSURE, sample, garmin->userdata); + garmin->callback(DC_SAMPLE_PRESSURE, &sample, garmin->userdata); } if (pending & RECORD_SETPOINT_CHANGE) { dc_sample_value_t sample = {0}; sample.setpoint = record->setpoint_actual_cbar / 100.0; - garmin->callback(DC_SAMPLE_SETPOINT, sample, garmin->userdata); + garmin->callback(DC_SAMPLE_SETPOINT, &sample, garmin->userdata); } } -static dc_status_t garmin_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size); +static dc_status_t garmin_parser_set_data (garmin_parser_t *garmin, const unsigned char *data, unsigned int size); static dc_status_t garmin_parser_get_datetime (dc_parser_t *abstract, dc_datetime_t *datetime); static dc_status_t garmin_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned int flags, void *value); static dc_status_t garmin_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata); @@ -357,7 +357,6 @@ static dc_status_t garmin_parser_samples_foreach (dc_parser_t *abstract, dc_samp static const dc_parser_vtable_t garmin_parser_vtable = { sizeof(garmin_parser_t), DC_FAMILY_GARMIN, - garmin_parser_set_data, /* set_data */ NULL, /* set_clock */ NULL, /* set_atmospheric */ NULL, /* set_density */ @@ -368,7 +367,7 @@ static const dc_parser_vtable_t garmin_parser_vtable = { }; dc_status_t -garmin_parser_create (dc_parser_t **out, dc_context_t *context) +garmin_parser_create (dc_parser_t **out, dc_context_t *context, const unsigned char data[], size_t size) { garmin_parser_t *parser = NULL; @@ -376,12 +375,14 @@ garmin_parser_create (dc_parser_t **out, dc_context_t *context) return DC_STATUS_INVALIDARGS; // Allocate memory. - parser = (garmin_parser_t *) dc_parser_allocate (context, &garmin_parser_vtable); + parser = (garmin_parser_t *) dc_parser_allocate (context, &garmin_parser_vtable, data, size); if (parser == NULL) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; } + garmin_parser_set_data(parser, data, size); + *out = (dc_parser_t *) parser; return DC_STATUS_SUCCESS; @@ -508,8 +509,8 @@ DECLARE_FIELD(ANY, timestamp, UINT32) // Now we're ready to actually update the sample times garmin->record_data.time = data+1; - sample.time = data; - garmin->callback(DC_SAMPLE_TIME, sample, garmin->userdata); + sample.time = data * 1000; + garmin->callback(DC_SAMPLE_TIME, &sample, garmin->userdata); } } DECLARE_FIELD(ANY, message_index, UINT16) { garmin->record_data.index = data; } @@ -556,7 +557,7 @@ DECLARE_FIELD(RECORD, heart_rate, UINT8) // bpm if (garmin->callback) { dc_sample_value_t sample = {0}; sample.heartbeat = data; - garmin->callback(DC_SAMPLE_HEARTBEAT, sample, garmin->userdata); + garmin->callback(DC_SAMPLE_HEARTBEAT, &sample, garmin->userdata); } } DECLARE_FIELD(RECORD, cadence, UINT8) { } // cadence @@ -568,7 +569,7 @@ DECLARE_FIELD(RECORD, temperature, SINT8) // degrees C if (garmin->callback) { dc_sample_value_t sample = {0}; sample.temperature = data; - garmin->callback(DC_SAMPLE_TEMPERATURE, sample, garmin->userdata); + garmin->callback(DC_SAMPLE_TEMPERATURE, &sample, garmin->userdata); } } DECLARE_FIELD(RECORD, abs_pressure, UINT32) {} // Pascal @@ -577,7 +578,7 @@ DECLARE_FIELD(RECORD, depth, UINT32) // mm if (garmin->callback) { dc_sample_value_t sample = {0}; sample.depth = data / 1000.0; - garmin->callback(DC_SAMPLE_DEPTH, sample, garmin->userdata); + garmin->callback(DC_SAMPLE_DEPTH, &sample, garmin->userdata); } } DECLARE_FIELD(RECORD, next_stop_depth, UINT32) // mm @@ -595,7 +596,7 @@ DECLARE_FIELD(RECORD, tts, UINT32) if (garmin->callback) { dc_sample_value_t sample = {0}; sample.time = data; - garmin->callback(DC_SAMPLE_TTS, sample, garmin->userdata); + garmin->callback(DC_SAMPLE_TTS, &sample, garmin->userdata); } } DECLARE_FIELD(RECORD, ndl, UINT32) // s @@ -604,7 +605,7 @@ DECLARE_FIELD(RECORD, ndl, UINT32) // s dc_sample_value_t sample = {0}; sample.deco.type = DC_DECO_NDL; sample.deco.time = data; - garmin->callback(DC_SAMPLE_DECO, sample, garmin->userdata); + garmin->callback(DC_SAMPLE_DECO, &sample, garmin->userdata); } } DECLARE_FIELD(RECORD, cns_load, UINT8) @@ -612,7 +613,7 @@ DECLARE_FIELD(RECORD, cns_load, UINT8) if (garmin->callback) { dc_sample_value_t sample = {0}; sample.cns = data / 100.0; - garmin->callback(DC_SAMPLE_CNS, sample, garmin->userdata); + garmin->callback(DC_SAMPLE_CNS, &sample, garmin->userdata); } } DECLARE_FIELD(RECORD, n2_load, UINT16) { } // percent @@ -1586,10 +1587,8 @@ static void add_gps_string(garmin_parser_t *garmin, const char *desc, struct pos } int -garmin_parser_is_dive (dc_parser_t *abstract, const unsigned char *data, unsigned int size, dc_event_devinfo_t *devinfo_p) +garmin_parser_is_dive (dc_parser_t *abstract, dc_event_devinfo_t *devinfo_p) { - // set up the parser and extract data - dc_parser_set_data(abstract, data, size); garmin_parser_t *garmin = (garmin_parser_t *) abstract; if (devinfo_p) { @@ -1621,10 +1620,8 @@ static void add_sensor_string(garmin_parser_t *garmin, const char *desc, const s } static dc_status_t -garmin_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size) +garmin_parser_set_data (garmin_parser_t *garmin, const unsigned char *data, unsigned int size) { - garmin_parser_t *garmin = (garmin_parser_t *) abstract; - /* Walk the data once without a callback to set up the core fields */ garmin->callback = NULL; garmin->userdata = NULL; diff --git a/src/parser.c b/src/parser.c index f3c7584..840c919 100644 --- a/src/parser.c +++ b/src/parser.c @@ -212,7 +212,7 @@ dc_parser_new_internal (dc_parser_t **out, dc_context_t *context, const unsigned // Not merged upstream yet case DC_FAMILY_GARMIN: - rc = garmin_parser_create (&parser, context); + rc = garmin_parser_create (&parser, context, data, size); break; } From 39bc2fe05c9c230dfa4a94865bbff9dd33952be8 Mon Sep 17 00:00:00 2001 From: Michael Keller Date: Sat, 3 Feb 2024 00:20:34 +1300 Subject: [PATCH 50/51] Import: Clean up gasmix / tank usage. Separate the usage enums and remove the unneeded values from each. Signed-off-by: Michael Keller --- configure.ac | 2 ++ include/libdivecomputer/parser.h | 13 ++++++++----- src/atomics_cobalt_parser.c | 2 +- src/divesoft_freedom_parser.c | 4 ++-- src/divesystem_idive_parser.c | 2 +- src/field-cache.h | 2 +- src/garmin_parser.c | 33 ++++++++++++-------------------- src/hw_ostc_parser.c | 8 ++------ src/liquivision_lynx_parser.c | 2 +- src/mares_darwin_parser.c | 2 +- src/mares_iconhd_parser.c | 2 +- src/mares_nemo_parser.c | 2 +- src/oceanic_vtpro_parser.c | 2 +- src/shearwater_predator_parser.c | 28 +++++++-------------------- src/suunto_eon_parser.c | 2 +- src/suunto_eonsteel_parser.c | 13 +++---------- src/suunto_vyper_parser.c | 2 +- src/uwatec_memomouse_parser.c | 2 +- src/uwatec_smart_parser.c | 2 +- 19 files changed, 48 insertions(+), 77 deletions(-) diff --git a/configure.ac b/configure.ac index fbb2073..41fa303 100644 --- a/configure.ac +++ b/configure.ac @@ -207,6 +207,8 @@ AX_APPEND_COMPILE_FLAGS([ \ -Wno-unused-but-set-variable \ -Wno-pointer-sign \ -Wno-shadow \ + -Wenum-conversion \ + -Werror=enum-conversion \ -fmacro-prefix-map='$(top_srcdir)/'= \ ],,[$ERROR_CFLAGS]) diff --git a/include/libdivecomputer/parser.h b/include/libdivecomputer/parser.h index 71797ba..0d286c8 100644 --- a/include/libdivecomputer/parser.h +++ b/include/libdivecomputer/parser.h @@ -174,10 +174,10 @@ typedef struct dc_salinity_t { } dc_salinity_t; typedef enum dc_usage_t { - DC_USAGE_NONE, + DC_USAGE_NONE, // Usage not specified DC_USAGE_OXYGEN, DC_USAGE_DILUENT, - DC_USAGE_SIDEMOUNT, + DC_USAGE_OPEN_CIRCUIT, } dc_usage_t; typedef struct dc_gasmix_t { @@ -193,8 +193,6 @@ typedef struct dc_gasmix_t { typedef unsigned int dc_tankinfo_t; #define DC_TANKINFO_METRIC 1 #define DC_TANKINFO_IMPERIAL 2 -#define DC_TANKINFO_CC_DILUENT 4 -#define DC_TANKINFO_CC_O2 8 // For backwards compatibility #define DC_TANKVOLUME_NONE 0 @@ -224,6 +222,11 @@ typedef unsigned int dc_tankinfo_t; * divide by 1 ATM (Vair = Vwater * Pwork / Patm). */ +typedef enum dc_tank_usage_t { + DC_TANK_USAGE_NONE, + DC_TANK_USAGE_SIDEMOUNT, +} dc_tank_usage_t; + typedef struct dc_tank_t { unsigned int gasmix; /* Gas mix index, or DC_GASMIX_UNKNOWN */ dc_tankinfo_t type; /* Tank type - metric/imperial and oc/cc */ @@ -231,7 +234,7 @@ typedef struct dc_tank_t { double workpressure; /* Work pressure (bar) */ double beginpressure; /* Begin pressure (bar) */ double endpressure; /* End pressure (bar) */ - dc_usage_t usage; + dc_tank_usage_t usage; } dc_tank_t; typedef enum dc_decomodel_type_t { diff --git a/src/atomics_cobalt_parser.c b/src/atomics_cobalt_parser.c index 1121234..ef54579 100644 --- a/src/atomics_cobalt_parser.c +++ b/src/atomics_cobalt_parser.c @@ -191,7 +191,7 @@ atomics_cobalt_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, un tank->gasmix = flags; tank->beginpressure = array_uint16_le(p + 6) * PSI / BAR; tank->endpressure = array_uint16_le(p + 14) * PSI / BAR; - tank->usage = DC_USAGE_NONE; + tank->usage = DC_TANK_USAGE_NONE; break; case DC_FIELD_DIVEMODE: switch(p[0x24]) { diff --git a/src/divesoft_freedom_parser.c b/src/divesoft_freedom_parser.c index 9647511..efad408 100644 --- a/src/divesoft_freedom_parser.c +++ b/src/divesoft_freedom_parser.c @@ -797,7 +797,7 @@ divesoft_freedom_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, } else if (parser->gasmix[flags].type == DILUENT) { gasmix->usage = DC_USAGE_DILUENT; } else { - gasmix->usage = DC_USAGE_NONE; + gasmix->usage = DC_USAGE_OPEN_CIRCUIT; } gasmix->helium = parser->gasmix[flags].helium / 100.0; gasmix->oxygen = parser->gasmix[flags].oxygen / 100.0; @@ -820,7 +820,7 @@ divesoft_freedom_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, tank->beginpressure = parser->tank[flags].beginpressure * 2.0; tank->endpressure = parser->tank[flags].endpressure * 2.0; tank->gasmix = flags; - tank->usage = DC_USAGE_NONE; + tank->usage = DC_TANK_USAGE_NONE; break; case DC_FIELD_DECOMODEL: if (parser->vpm) { diff --git a/src/divesystem_idive_parser.c b/src/divesystem_idive_parser.c index c13a804..3c80590 100644 --- a/src/divesystem_idive_parser.c +++ b/src/divesystem_idive_parser.c @@ -304,7 +304,7 @@ divesystem_idive_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, tank->beginpressure = parser->tank[flags].beginpressure; tank->endpressure = parser->tank[flags].endpressure; tank->gasmix = DC_GASMIX_UNKNOWN; - tank->usage = DC_USAGE_NONE; + tank->usage = DC_TANK_USAGE_NONE; break; case DC_FIELD_ATMOSPHERIC: if (ISIX3M(parser->model)) { diff --git a/src/field-cache.h b/src/field-cache.h index 09c06e0..dd847e6 100644 --- a/src/field-cache.h +++ b/src/field-cache.h @@ -26,7 +26,7 @@ typedef struct dc_field_cache { // dc_tank_t TANK[MAXGASES] // but that's for later dc_tankinfo_t tankinfo[MAXGASES]; - dc_usage_t tankusage[MAXGASES]; + dc_tank_usage_t tankusage[MAXGASES]; double tanksize[MAXGASES]; double tankworkingpressure[MAXGASES]; diff --git a/src/garmin_parser.c b/src/garmin_parser.c index 106bace..c2be625 100644 --- a/src/garmin_parser.c +++ b/src/garmin_parser.c @@ -72,7 +72,7 @@ struct record_data { double ceiling; // RECORD_GASMIX - int index, gas_status, gas_type; + int index, gas_status; dc_gasmix_t gasmix; // RECORD_EVENT @@ -129,7 +129,7 @@ typedef struct garmin_parser_t { unsigned int setpoint_low_cbar, setpoint_high_cbar; unsigned int setpoint_low_switch_depth_mm, setpoint_high_switch_depth_mm; unsigned int setpoint_low_switch_mode, setpoint_high_switch_mode; - dc_tankinfo_t *current_tankinfo; + dc_gasmix_t *current_gasmix; } dive; // I count nine (!) different GPS fields Hmm. @@ -239,11 +239,11 @@ static void garmin_event(struct garmin_parser_t *garmin, sample.gasmix = data; garmin->callback(DC_SAMPLE_GASMIX, &sample, garmin->userdata); - dc_tankinfo_t *tankinfo = &garmin->cache.tankinfo[data]; - if (!garmin->dive.current_tankinfo || (*tankinfo & DC_TANKINFO_CC_DILUENT) != (*garmin->dive.current_tankinfo & DC_TANKINFO_CC_DILUENT)) { + dc_gasmix_t *gasmix = &garmin->cache.GASMIX[data]; + if (!garmin->dive.current_gasmix || gasmix->usage != garmin->dive.current_gasmix->usage) { dc_sample_value_t sample2 = {0}; sample2.event.type = SAMPLE_EVENT_STRING; - if (*tankinfo & DC_TANKINFO_CC_DILUENT) { + if (gasmix->usage == DC_USAGE_DILUENT) { sample2.event.name = "Switched to closed circuit"; } else { sample2.event.name = "Switched to open circuit bailout"; @@ -252,7 +252,7 @@ static void garmin_event(struct garmin_parser_t *garmin, garmin->callback(DC_SAMPLE_EVENT, &sample2, garmin->userdata); - garmin->dive.current_tankinfo = tankinfo; + garmin->dive.current_gasmix = gasmix; } return; @@ -279,17 +279,7 @@ static void flush_pending_record(struct garmin_parser_t *garmin) int index = record->index; if (enabled && index < MAXGASES) { DC_ASSIGN_IDX(garmin->cache, GASMIX, index, record->gasmix); - if (index + 1 > garmin->cache.GASMIX_COUNT) { - DC_ASSIGN_FIELD(garmin->cache, GASMIX_COUNT, index + 1); - garmin->cache.initialized |= 1 << DC_FIELD_TANK_COUNT; - } - - dc_tankinfo_t tankinfo = DC_TANKINFO_METRIC; - if (record->gas_type == 1) { - tankinfo |= DC_TANKINFO_CC_DILUENT; - } - garmin->cache.tankinfo[index] = tankinfo; - garmin->cache.initialized |= 1 << DC_FIELD_TANK; + DC_ASSIGN_FIELD(garmin->cache, GASMIX_COUNT, index + 1); } } if (pending & RECORD_DEVICE_INFO && record->device_index == 0) { @@ -699,7 +689,10 @@ DECLARE_FIELD(DIVE_GAS, status, ENUM) DECLARE_FIELD(DIVE_GAS, type, ENUM) { // 0 - open circuit, 1 - CCR diluent - garmin->record_data.gas_type = data; + if (data == 1) + garmin->record_data.gasmix.usage = DC_USAGE_DILUENT; + else + garmin->record_data.gasmix.usage = DC_USAGE_OPEN_CIRCUIT; garmin->record_data.pending |= RECORD_GASMIX; } @@ -1663,10 +1656,8 @@ garmin_parser_set_data (garmin_parser_t *garmin, const unsigned char *data, unsi // // There's no way to match them up unless they are an identity // mapping, so having two different ones doesn't actually work. - if (garmin->dive.nr_sensor > garmin->cache.GASMIX_COUNT) { + if (garmin->dive.nr_sensor > garmin->cache.GASMIX_COUNT) DC_ASSIGN_FIELD(garmin->cache, GASMIX_COUNT, garmin->dive.nr_sensor); - garmin->cache.initialized |= 1 << DC_FIELD_TANK_COUNT; - } for (int i = 0; i < garmin->dive.nr_sensor; i++) { static const char *name[] = { "Sensor 1", "Sensor 2", "Sensor 3", "Sensor 4", "Sensor 5" }; diff --git a/src/hw_ostc_parser.c b/src/hw_ostc_parser.c index d343793..e3b9500 100644 --- a/src/hw_ostc_parser.c +++ b/src/hw_ostc_parser.c @@ -575,14 +575,10 @@ hw_ostc_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned } gasmix->usage = parser->gasmix[flags].diluent ? - DC_USAGE_DILUENT : DC_USAGE_NONE; + DC_USAGE_DILUENT : DC_USAGE_OPEN_CIRCUIT; gasmix->oxygen = parser->gasmix[flags].oxygen / 100.0; gasmix->helium = parser->gasmix[flags].helium / 100.0; gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium; - if (!parser->gasmix[flags].enabled) { - // Indicate that this gasmix is not active - return DC_STATUS_UNSUPPORTED; - } break; case DC_FIELD_TANK: @@ -595,7 +591,7 @@ hw_ostc_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigned tank->volume = 0.0; tank->gasmix = flags; tank->workpressure = 0.0; - tank->type = DC_TANKINFO_METRIC | (parser->gasmix[flags].diluent ? DC_TANKINFO_CC_DILUENT : 0); + tank->type = DC_TANKINFO_METRIC; break; case DC_FIELD_SALINITY: diff --git a/src/liquivision_lynx_parser.c b/src/liquivision_lynx_parser.c index c336b6a..d34e828 100644 --- a/src/liquivision_lynx_parser.c +++ b/src/liquivision_lynx_parser.c @@ -305,7 +305,7 @@ liquivision_lynx_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, tank->beginpressure = parser->tank[flags].beginpressure / 100.0; tank->endpressure = parser->tank[flags].endpressure / 100.0; tank->gasmix = DC_GASMIX_UNKNOWN; - tank->usage = DC_USAGE_NONE; + tank->usage = DC_TANK_USAGE_NONE; break; default: return DC_STATUS_UNSUPPORTED; diff --git a/src/mares_darwin_parser.c b/src/mares_darwin_parser.c index bebd89c..e80adaa 100644 --- a/src/mares_darwin_parser.c +++ b/src/mares_darwin_parser.c @@ -177,7 +177,7 @@ mares_darwin_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsi tank->gasmix = 0; tank->beginpressure = array_uint16_be (p + 0x17); tank->endpressure = array_uint16_be (p + 0x19); - tank->usage = DC_USAGE_NONE; + tank->usage = DC_TANK_USAGE_NONE; } else { return DC_STATUS_UNSUPPORTED; } diff --git a/src/mares_iconhd_parser.c b/src/mares_iconhd_parser.c index 08dbea5..c845e65 100644 --- a/src/mares_iconhd_parser.c +++ b/src/mares_iconhd_parser.c @@ -828,7 +828,7 @@ mares_iconhd_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsi } else { tank->gasmix = DC_GASMIX_UNKNOWN; } - tank->usage = DC_USAGE_NONE; + tank->usage = DC_TANK_USAGE_NONE; break; case DC_FIELD_ATMOSPHERIC: *((double *) value) = array_uint16_le (p + parser->layout->atmospheric) / (1000.0 * parser->layout->atmospheric_divisor); diff --git a/src/mares_nemo_parser.c b/src/mares_nemo_parser.c index cb3e3bf..fb2b643 100644 --- a/src/mares_nemo_parser.c +++ b/src/mares_nemo_parser.c @@ -270,7 +270,7 @@ mares_nemo_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsign } else { tank->gasmix = DC_GASMIX_UNKNOWN; } - tank->usage = DC_USAGE_NONE; + tank->usage = DC_TANK_USAGE_NONE; break; case DC_FIELD_TEMPERATURE_MINIMUM: *((double *) value) = (signed char) p[53 - 11]; diff --git a/src/oceanic_vtpro_parser.c b/src/oceanic_vtpro_parser.c index ec380b3..888f77f 100644 --- a/src/oceanic_vtpro_parser.c +++ b/src/oceanic_vtpro_parser.c @@ -205,7 +205,7 @@ oceanic_vtpro_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, uns tank->gasmix = flags; tank->beginpressure = beginpressure * 2 * PSI / BAR; tank->endpressure = endpressure * 2 * PSI / BAR; - tank->usage = DC_USAGE_NONE; + tank->usage = DC_TANK_USAGE_NONE; break; default: return DC_STATUS_UNSUPPORTED; diff --git a/src/shearwater_predator_parser.c b/src/shearwater_predator_parser.c index fa0b849..1b184a4 100644 --- a/src/shearwater_predator_parser.c +++ b/src/shearwater_predator_parser.c @@ -123,7 +123,7 @@ typedef struct shearwater_predator_tank_t { unsigned int serial; char name[2]; unsigned int battery; - dc_usage_t usage; + dc_tank_usage_t usage; } shearwater_predator_tank_t; struct shearwater_predator_parser_t { @@ -271,7 +271,7 @@ shearwater_common_parser_create (dc_parser_t **out, dc_context_t *context, const parser->tank[i].serial = 0; memset (parser->tank[i].name, 0, sizeof (parser->tank[i].name)); parser->tank[i].battery = 0; - parser->tank[i].usage = DC_USAGE_NONE; + parser->tank[i].usage = DC_TANK_USAGE_NONE; parser->tankidx[i] = i; } parser->aimode = AI_OFF; @@ -603,7 +603,7 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser) tank[id].enabled = 1; tank[id].beginpressure = pressure; tank[id].endpressure = pressure; - tank[id].usage = i == 0 ? DC_USAGE_DILUENT : DC_USAGE_OXYGEN; + //tank[id].usage = i == 0 ? DC_USAGE_DILUENT : DC_USAGE_OXYGEN; //TODO: Link this tank to the correct gasmix hpccr = 1; } tank[id].endpressure = pressure; @@ -648,7 +648,7 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser) if (aimode == AI_HPCCR) { for (unsigned int i = 0; i < 2; ++i) { tank[4 + i].enabled = 1; - tank[4 + i].usage = i == 0 ? DC_USAGE_DILUENT : DC_USAGE_OXYGEN; + //tank[4 + i].usage = i == 0 ? DC_USAGE_DILUENT : DC_USAGE_OXYGEN; //TODO: Link this tank to the correct gasmix } hpccr = 1; } @@ -665,7 +665,7 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser) if (popcount(gtrmode) >= 2) { for (unsigned int i = 0; i < 4; ++i) { if (gtrmode & (1 << i)) { - tank[i].usage = DC_USAGE_SIDEMOUNT; + tank[i].usage = DC_TANK_USAGE_SIDEMOUNT; } } } @@ -895,7 +895,7 @@ shearwater_predator_parser_get_field (dc_parser_t *abstract, dc_field_type_t typ *((unsigned int *) value) = parser->ngasmixes; break; case DC_FIELD_GASMIX: - gasmix->usage = parser->gasmix[flags].diluent ? DC_USAGE_DILUENT : DC_USAGE_NONE; + gasmix->usage = parser->gasmix[flags].diluent ? DC_USAGE_DILUENT : DC_USAGE_OPEN_CIRCUIT; gasmix->oxygen = parser->gasmix[flags].oxygen / 100.0; gasmix->helium = parser->gasmix[flags].helium / 100.0; gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium; @@ -910,21 +910,7 @@ shearwater_predator_parser_get_field (dc_parser_t *abstract, dc_field_type_t typ tank->beginpressure = parser->tank[flags].beginpressure * 2 * PSI / BAR; tank->endpressure = parser->tank[flags].endpressure * 2 * PSI / BAR; tank->gasmix = DC_GASMIX_UNKNOWN; - if (shearwater_predator_is_ccr (parser->divemode) && !parser->hpccr) { - switch (parser->tank[flags].name[0]) { - case 'O': - tank->usage = DC_USAGE_OXYGEN; - break; - case 'D': - tank->usage = DC_USAGE_DILUENT; - break; - default: - tank->usage = DC_USAGE_NONE; - break; - } - } else { - tank->usage = parser->tank[flags].usage; - } + tank->usage = parser->tank[flags].usage; break; case DC_FIELD_SALINITY: if (parser->density == 1000) diff --git a/src/suunto_eon_parser.c b/src/suunto_eon_parser.c index 94370a3..deca27d 100644 --- a/src/suunto_eon_parser.c +++ b/src/suunto_eon_parser.c @@ -225,7 +225,7 @@ suunto_eon_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsign tank->gasmix = 0; tank->beginpressure = beginpressure; tank->endpressure = endpressure; - tank->usage = DC_USAGE_NONE; + tank->usage = DC_TANK_USAGE_NONE; break; case DC_FIELD_TEMPERATURE_MINIMUM: if (parser->spyder) diff --git a/src/suunto_eonsteel_parser.c b/src/suunto_eonsteel_parser.c index b7a5f01..e2b2a26 100644 --- a/src/suunto_eonsteel_parser.c +++ b/src/suunto_eonsteel_parser.c @@ -985,15 +985,6 @@ static int traverse_samples(unsigned short type, const struct type_desc *desc, c used += bytes; } - if (info->ndl < 0 && info->ceiling) { - dc_sample_value_t sample = {0}; - - sample.deco.type = DC_DECO_DECOSTOP; - sample.deco.time = 0; - sample.deco.depth = info->ceiling; - if (info->callback) info->callback(DC_SAMPLE_DECO, &sample, info->userdata); - } - // Warn if there are left-over bytes for something we did use part of if (used && len) ERROR(eon->base.context, "Entry for '%s' had %d bytes, only used %d", desc->desc, len+used, used); @@ -1136,9 +1127,11 @@ static dc_status_t add_gas_type(suunto_eonsteel_parser_t *eon, const struct type tankinfo = DC_TANKVOLUME_NONE; else if (strcasecmp(name, "Primary")) DEBUG(eon->base.context, "Unknown gas type %u (%s)", type, name); + if (name && strcasecmp(name, "Diluent") && strcasecmp(name, "Oxygen")) + usage = DC_USAGE_OPEN_CIRCUIT; eon->cache.tankinfo[idx] = tankinfo; - eon->cache.tankusage[idx] = usage; + eon->cache.tankusage[idx] = DC_TANK_USAGE_NONE; eon->cache.GASMIX[idx].usage = usage; eon->cache.initialized |= 1 << DC_FIELD_GASMIX_COUNT; diff --git a/src/suunto_vyper_parser.c b/src/suunto_vyper_parser.c index 3d4317a..9252b2c 100644 --- a/src/suunto_vyper_parser.c +++ b/src/suunto_vyper_parser.c @@ -274,7 +274,7 @@ suunto_vyper_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsi tank->gasmix = 0; tank->beginpressure = beginpressure; tank->endpressure = endpressure; - tank->usage = DC_USAGE_NONE; + tank->usage = DC_TANK_USAGE_NONE; break; case DC_FIELD_TEMPERATURE_SURFACE: *((double *) value) = (signed char) data[8]; diff --git a/src/uwatec_memomouse_parser.c b/src/uwatec_memomouse_parser.c index 0849a3c..3b11f27 100644 --- a/src/uwatec_memomouse_parser.c +++ b/src/uwatec_memomouse_parser.c @@ -189,7 +189,7 @@ uwatec_memomouse_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, } tank->endpressure = 0.0; tank->gasmix = 0; - tank->usage = DC_USAGE_NONE; + tank->usage = DC_TANK_USAGE_NONE; break; case DC_FIELD_TEMPERATURE_MINIMUM: *((double *) value) = (signed char) data[15] / 4.0; diff --git a/src/uwatec_smart_parser.c b/src/uwatec_smart_parser.c index 8e455a7..588221f 100644 --- a/src/uwatec_smart_parser.c +++ b/src/uwatec_smart_parser.c @@ -802,7 +802,7 @@ uwatec_smart_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsi tank->beginpressure = parser->tank[flags].beginpressure / 128.0; tank->endpressure = parser->tank[flags].endpressure / 128.0; tank->gasmix = parser->tank[flags].gasmix; - tank->usage = DC_USAGE_NONE; + tank->usage = DC_TANK_USAGE_NONE; break; case DC_FIELD_TEMPERATURE_MINIMUM: *((double *) value) = (signed short) array_uint16_le (data + table->temp_minimum) / 10.0; From 4bbfe1659e0750b7eb896eead6178253fd2f8c53 Mon Sep 17 00:00:00 2001 From: Michael Keller Date: Wed, 14 Feb 2024 11:57:39 +1300 Subject: [PATCH 51/51] Shearwater: Fix Up Timesynch Changes. A few fixes for bugs introduced during merge conflict resolution. Signed-off-by: Michael Keller --- src/shearwater_common.c | 30 +++++++++++++++--------------- src/shearwater_common.h | 3 +-- src/shearwater_petrel.c | 2 +- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/shearwater_common.c b/src/shearwater_common.c index 6cf77c2..211be4f 100644 --- a/src/shearwater_common.c +++ b/src/shearwater_common.c @@ -688,9 +688,9 @@ dc_status_t shearwater_common_get_model(shearwater_common_device_t *device, unsi { // Read the hardware type. unsigned char rsp_hardware[2] = {0}; - status = shearwater_common_rdbi (device, ID_HARDWARE, rsp_hardware, sizeof(rsp_hardware)); + dc_status_t status = shearwater_common_rdbi (device, ID_HARDWARE, rsp_hardware, sizeof(rsp_hardware)); if (status != DC_STATUS_SUCCESS) { - ERROR (abstract->context, "Failed to read the hardware type."); + ERROR (device->base.context, "Failed to read the hardware type."); return status; } @@ -699,11 +699,11 @@ dc_status_t shearwater_common_get_model(shearwater_common_device_t *device, unsi switch (hardware) { case 0x0101: case 0x0202: - model = PREDATOR; + *model = PREDATOR; break; case 0x0404: case 0x0909: - model = PETREL; + *model = PETREL; break; case 0x0505: case 0x0808: @@ -713,44 +713,44 @@ dc_status_t shearwater_common_get_model(shearwater_common_device_t *device, unsi case 0x7828: case 0x7B2C: case 0x8838: - model = PETREL2; + *model = PETREL2; break; case 0xB407: - model = PETREL3; + *model = PETREL3; break; case 0x0606: case 0x0A0A: - model = NERD; + *model = NERD; break; case 0x0E0D: case 0x7E2D: - model = NERD2; + *model = NERD2; break; case 0x0707: - model = PERDIX; + *model = PERDIX; break; case 0x0C0D: case 0x7C2D: case 0x8D6C: - model = PERDIXAI; + *model = PERDIXAI; break; case 0xC407: - model = PERDIX2; + *model = PERDIX2; break; case 0x0F0F: case 0x1F0A: case 0x1F0F: - model = TERIC; + *model = TERIC; break; case 0x1512: - model = PEREGRINE; + *model = PEREGRINE; break; case 0xC0E0: - model = TERN; + *model = TERN; break; default: WARNING (device->base.context, "Unknown hardware type 0x%04x.", hardware); } - return model; + return status; } diff --git a/src/shearwater_common.h b/src/shearwater_common.h index 377c8df..de9e250 100644 --- a/src/shearwater_common.h +++ b/src/shearwater_common.h @@ -88,8 +88,7 @@ shearwater_common_timesync_local (shearwater_common_device_t *device, const dc_d dc_status_t shearwater_common_timesync_utc (shearwater_common_device_t *device, const dc_datetime_t *datetime); -unsigned int -shearwater_common_get_model (shearwater_common_device_t *device, unsigned int hardware); +dc_status_t shearwater_common_get_model(shearwater_common_device_t *device, unsigned int *model); dc_status_t shearwater_common_can_wdbi (shearwater_common_device_t *device, dc_buffer_t *buffer, unsigned int id); diff --git a/src/shearwater_petrel.c b/src/shearwater_petrel.c index 9f3cc11..671ef92 100644 --- a/src/shearwater_petrel.c +++ b/src/shearwater_petrel.c @@ -355,7 +355,7 @@ shearwater_petrel_device_timesync (dc_device_t *abstract, const dc_datetime_t *d shearwater_common_device_t *device = (shearwater_common_device_t *) abstract; unsigned int model = 0; - status = shearwater_common_get_model (&device->base, &model); + status = shearwater_common_get_model (device, &model); if (status != DC_STATUS_SUCCESS) { ERROR (abstract->context, "Failed to read the hardware type."); return status;