diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2012-11-12 21:17:52 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2012-11-12 21:17:52 +0100 |
commit | 05b55542c82fc6842afd68c972b18e86a6c1d004 (patch) | |
tree | e2191043e663de9d9817fcb0e52d1b4ff4318a07 | |
parent | 56f62cc4ab46f811b4340aa36ad1df42bb08832c (diff) | |
download | subsurface-05b55542c82fc6842afd68c972b18e86a6c1d004.tar.gz |
Extract salinity for Uemis SDA and improve depth calculation
THe Uemis SDA allows the user to set it up for salt water and fresh water
use. We should take this into consideration for the water pressure to
depth conversion.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | dive.h | 15 | ||||
-rw-r--r-- | uemis.c | 28 |
2 files changed, 22 insertions, 21 deletions
@@ -298,6 +298,21 @@ static inline int depth_to_mbar(int depth, struct dive *dive) return depth / 10.0 * specific_weight + surface_pressure + 0.5; } +/* for the inverse calculation we use just the relative pressure + * (that's the one that some dive computers like the Uemis Zurich + * provide - for the other models that do this libdivecomputer has to + * take care of this, but the Uemis we support natively */ +static inline int rel_mbar_to_depth(int mbar, struct dive *dive) +{ + int cm; + double specific_weight = 1.03 * 0.981; + if (dive->salinity) + specific_weight = dive->salinity / 10000.0 * 0.981; + /* whole mbar gives us cm precision */ + cm = mbar / specific_weight + 0.5; + return cm * 10; +} + #define SURFACE_THRESHOLD 750 /* somewhat arbitrary: only below 75cm is it really diving */ /* this is a global spot for a temporary dive structure that we use to @@ -75,25 +75,6 @@ void decode( uint8_t *inbuf, uint8_t *outbuf, int inbuf_len ) { /* end code from Bob Trower */ /* - * pressure_to_depth: In centibar. And when converting to - * depth, I'm just going to always use saltwater, because I - * think "true depth" is just stupid. From a diving standpoint, - * "true depth" is pretty much completely pointless, unless - * you're doing some kind of underwater surveying work. - * - * So I give water depths in "pressure depth", always assuming - * salt water. So one atmosphere per 10m. - */ -static int pressure_to_depth(uint16_t value) -{ - double atm, cm; - - atm = bar_to_atm(value / 100.0); - cm = 100 * atm + 0.5; - return (cm > 0) ? 10 * (long)cm : 0; -} - -/* * convert the base64 data blog */ int uemis_convert_base64(char *base64, uint8_t **data) { @@ -212,7 +193,12 @@ void uemis_parse_divelog_binary(char *base64, void *datap) { datalen = uemis_convert_base64(base64, &data); dive->airtemp.mkelvin = *(uint16_t *)(data + 45) * 100 + 273150; - dive->surface_pressure.mbar = *(uint16_t *)(data +43); + dive->surface_pressure.mbar = *(uint16_t *)(data + 43); + if (*(uint8_t *)(data + 19)) + dive->salinity = 10300; /* avg grams per 10l sea water */ + else + dive->salinity = 10000; /* grams per 10l fresh water */ + /* dive template in use: 0 = air 1 = nitrox (B) @@ -253,7 +239,7 @@ void uemis_parse_divelog_binary(char *base64, void *datap) { sample = prepare_sample(divep); dive = *divep; /* prepare_sample might realloc the dive */ sample->time.seconds = u_sample->dive_time; - sample->depth.mm = pressure_to_depth(u_sample->water_pressure); + sample->depth.mm = rel_mbar_to_depth(u_sample->water_pressure, dive); sample->temperature.mkelvin = (u_sample->dive_temperature * 100) + 273150; sample->cylinderindex = u_sample->active_tank; sample->cylinderpressure.mbar = |