From f53788e5e4066f0ef36041031de6bc2726274fc9 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 10 Nov 2012 19:18:10 +0100 Subject: Add support for obtaining salinity from libdivecomputer This requires a patched libdivecomputer that can return salinity of the water the dive was conducted in. Experimental patches exist that implement this for the OSTC. The code is designed so that it simply defaults to salt water if libdivecomputer doesn't include the feature. The patch also fixes the dive merge code to merge two other recent additions to the dive structure (surface_pressure and visibility). Signed-off-by: Dirk Hohndel --- dive.c | 3 +++ dive.h | 1 + libdivecomputer.c | 12 ++++++++++++ 3 files changed, 16 insertions(+) diff --git a/dive.c b/dive.c index d9193e398..19d3cc5b0 100644 --- a/dive.c +++ b/dive.c @@ -1082,6 +1082,9 @@ struct dive *try_to_merge(struct dive *a, struct dive *b, struct dive *next) MERGE_MAX(res, a, b, number); MERGE_MAX(res, a, b, maxdepth.mm); res->meandepth.mm = 0; + MERGE_NONZERO(res, a, b, salinity); + MERGE_NONZERO(res, a, b, visibility); + MERGE_NONZERO(res, a, b, surface_pressure.mbar); MERGE_MAX(res, a, b, duration.seconds); MERGE_MAX(res, a, b, surfacetime.seconds); MERGE_MAX(res, a, b, airtemp.mkelvin); diff --git a/dive.h b/dive.h index d303c81b7..1e54e1273 100644 --- a/dive.h +++ b/dive.h @@ -267,6 +267,7 @@ struct dive { int rating; double latitude, longitude; depth_t maxdepth, meandepth; + int salinity; // kg per 10000 l duration_t duration, surfacetime; int visibility; /* 0 - 5 star rating */ temperature_t airtemp, watertemp; diff --git a/libdivecomputer.c b/libdivecomputer.c index e3153572a..6a9b07f80 100644 --- a/libdivecomputer.c +++ b/libdivecomputer.c @@ -281,6 +281,18 @@ static int dive_cb(const unsigned char *data, unsigned int size, return rc; } + // Check if the libdivecomputer version already supports salinity + double salinity = 1.03; +#ifdef DC_FIELD_SALINITY + rc = dc_parser_get_field(parser, DC_FIELD_SALINITY, 0, &salinity); + if (rc != DC_STATUS_SUCCESS && rc != DC_STATUS_UNSUPPORTED) { + dev_info(devdata, _("Error obtaining water salinity")); + dc_parser_destroy(parser); + return rc; + } +#endif + dive->salinity = salinity * 10000.0 + 0.5; + rc = parse_gasmixes(devdata, dive, parser, ngases); if (rc != DC_STATUS_SUCCESS) { dev_info(devdata, _("Error parsing the gas mix")); -- cgit v1.2.3-70-g09d2