Use SI units internally
Prefer SI units for internal constants (e.g. density) and calculations. This results in more consistent conversion formulas across the different backends. For the Uwatec backend, this changes makes it also much more visible that the unit for the depth is either 1 millibar (maximum depth) or 2 millibar (sample depth).
This commit is contained in:
parent
b186846a9e
commit
cffda88ae8
@ -22,6 +22,8 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <libdivecomputer/units.h>
|
||||
|
||||
#include "mclean_extreme.h"
|
||||
#include "context-private.h"
|
||||
#include "parser-private.h"
|
||||
@ -152,19 +154,19 @@ mclean_extreme_parser_get_field(dc_parser_t *abstract, dc_field_type_t type, uns
|
||||
dc_gasmix_t *gasmix = (dc_gasmix_t *)value;
|
||||
dc_salinity_t *salinity = (dc_salinity_t *)value;
|
||||
|
||||
const unsigned int psurf = array_uint16_le(abstract->data + 0x001E);
|
||||
const unsigned int atmospheric = array_uint16_le(abstract->data + 0x001E);
|
||||
const unsigned int density_index = abstract->data[0x0023];
|
||||
double density = 0;
|
||||
|
||||
switch (density_index) {
|
||||
case 0:
|
||||
density = 1.000;
|
||||
density = 1000.0;
|
||||
break;
|
||||
case 1:
|
||||
density = 1.020;
|
||||
density = 1020.0;
|
||||
break;
|
||||
case 2:
|
||||
density = 1.030;
|
||||
density = 1030.0;
|
||||
break;
|
||||
default:
|
||||
ERROR(abstract->context, "Corrupt density index in dive data");
|
||||
@ -177,17 +179,17 @@ mclean_extreme_parser_get_field(dc_parser_t *abstract, dc_field_type_t type, uns
|
||||
*((unsigned int *)value) = array_uint32_le(abstract->data + SZ_CFG + 0x000C) - array_uint32_le(abstract->data + SZ_CFG + 0x0000);
|
||||
break;
|
||||
case DC_FIELD_MAXDEPTH:
|
||||
*((double *)value) = 0.01 * (signed int)(array_uint16_le(abstract->data + SZ_CFG + 0x0016) - psurf) / density;
|
||||
*((double *)value) = (signed int)(array_uint16_le(abstract->data + SZ_CFG + 0x0016) - atmospheric) * (BAR / 1000.0) / (density * 10.0);
|
||||
break;
|
||||
case DC_FIELD_AVGDEPTH:
|
||||
*((double *)value) = 0.01 * (signed int)(array_uint16_le(abstract->data + SZ_CFG + 0x0018) - psurf) / density;
|
||||
*((double *)value) = (signed int)(array_uint16_le(abstract->data + SZ_CFG + 0x0018) - atmospheric) * (BAR / 1000.0) / (density * 10.0);
|
||||
break;
|
||||
case DC_FIELD_SALINITY:
|
||||
salinity->density = density * 1000.0;
|
||||
salinity->density = density;
|
||||
salinity->type = density_index == 0 ? DC_WATER_FRESH : DC_WATER_SALT;
|
||||
break;
|
||||
case DC_FIELD_ATMOSPHERIC:
|
||||
*((double *)value) = 0.001 * array_uint16_le(abstract->data + 0x001E);
|
||||
*((double *)value) = atmospheric / 1000.0;
|
||||
break;
|
||||
case DC_FIELD_TEMPERATURE_MINIMUM:
|
||||
*((double *)value) = (double)abstract->data[SZ_CFG + 0x0010];
|
||||
|
||||
@ -62,8 +62,8 @@
|
||||
#define HEADER 1
|
||||
#define PROFILE 2
|
||||
|
||||
#define FRESH 1.000
|
||||
#define SALT 1.025
|
||||
#define FRESH 1000.0
|
||||
#define SALT 1025.0
|
||||
|
||||
#define FREEDIVE 0x00000080
|
||||
#define GAUGE 0x00001000
|
||||
@ -789,7 +789,7 @@ uwatec_smart_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsi
|
||||
const uwatec_smart_header_info_t *table = parser->header;
|
||||
const unsigned char *data = abstract->data;
|
||||
|
||||
double salinity = (parser->watertype == DC_WATER_SALT ? SALT : FRESH);
|
||||
double density = (parser->watertype == DC_WATER_SALT ? SALT : FRESH);
|
||||
|
||||
dc_gasmix_t *gasmix = (dc_gasmix_t *) value;
|
||||
dc_tank_t *tank = (dc_tank_t *) value;
|
||||
@ -801,7 +801,7 @@ uwatec_smart_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsi
|
||||
*((unsigned int *) value) = array_uint16_le (data + table->divetime) * 60;
|
||||
break;
|
||||
case DC_FIELD_MAXDEPTH:
|
||||
*((double *) value) = array_uint16_le (data + table->maxdepth) / 100.0 / salinity;
|
||||
*((double *) value) = array_uint16_le (data + table->maxdepth) * (BAR / 1000.0) / (density * 10.0);
|
||||
break;
|
||||
case DC_FIELD_GASMIX_COUNT:
|
||||
*((unsigned int *) value) = parser->ngasmixes;
|
||||
@ -844,7 +844,7 @@ uwatec_smart_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsi
|
||||
if (table->settings == UNSUPPORTED)
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
water->type = parser->watertype;
|
||||
water->density = salinity * 1000.0;
|
||||
water->density = density;
|
||||
break;
|
||||
default:
|
||||
return DC_STATUS_UNSUPPORTED;
|
||||
@ -950,7 +950,7 @@ uwatec_smart_parse (uwatec_smart_parser_t *parser, dc_sample_callback_t callback
|
||||
// Previous gas mix - initialize with impossible value
|
||||
unsigned int gasmix_previous = 0xFFFFFFFF;
|
||||
|
||||
double salinity = (parser->watertype == DC_WATER_SALT ? SALT : FRESH);
|
||||
double density = (parser->watertype == DC_WATER_SALT ? SALT : FRESH);
|
||||
|
||||
unsigned int interval = 4;
|
||||
if (parser->divemode == DC_DIVEMODE_FREEDIVE) {
|
||||
@ -1233,7 +1233,7 @@ uwatec_smart_parse (uwatec_smart_parser_t *parser, dc_sample_callback_t callback
|
||||
}
|
||||
|
||||
if (have_depth) {
|
||||
sample.depth = (signed int)(depth - depth_calibration) / 50.0 / salinity;
|
||||
sample.depth = (signed int)(depth - depth_calibration) * (2.0 * BAR / 1000.0) / (density * 10.0);
|
||||
if (callback) callback (DC_SAMPLE_DEPTH, sample, userdata);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user