mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
CCR code: Change to sample structure
1) All the variables in the sample structures are strongly typed 2) Two additional types were declared in units.h: o2pressure_t bearing_t 3) The following variables were added: diluentpressure o2setpoint o2sensor[3] 4) Changes to a number of files were made to chanf sample->po2 to sample->po2.mbar bearing to bearring.degrees Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
1fec6453a2
commit
eaf6d56487
11 changed files with 64 additions and 51 deletions
2
dive.c
2
dive.c
|
@ -1105,7 +1105,7 @@ static void merge_samples(struct divecomputer *res, struct divecomputer *a, stru
|
||||||
sample.sensor = as->sensor;
|
sample.sensor = as->sensor;
|
||||||
if (as->cns)
|
if (as->cns)
|
||||||
sample.cns = as->cns;
|
sample.cns = as->cns;
|
||||||
if (as->po2)
|
if (as->po2.mbar)
|
||||||
sample.po2 = as->po2;
|
sample.po2 = as->po2;
|
||||||
if (as->ndl.seconds)
|
if (as->ndl.seconds)
|
||||||
sample.ndl = as->ndl;
|
sample.ndl = as->ndl;
|
||||||
|
|
34
dive.h
34
dive.h
|
@ -141,21 +141,25 @@ static inline depth_t gas_mod(struct gasmix *mix, pressure_t po2_limit) {
|
||||||
void get_gas_string(const struct gasmix *gasmix, char *text, int len);
|
void get_gas_string(const struct gasmix *gasmix, char *text, int len);
|
||||||
const char *gasname(const struct gasmix *gasmix);
|
const char *gasname(const struct gasmix *gasmix);
|
||||||
|
|
||||||
struct sample {
|
struct sample // BASE TYPE BYTES UNITS RANGE DESCRIPTION
|
||||||
duration_t time;
|
{ // --------- ----- ----- ----- -----------
|
||||||
depth_t depth;
|
duration_t time; // uint32_t 4 seconds (0-68 yrs) elapsed dive time up to this sample
|
||||||
temperature_t temperature;
|
duration_t stoptime; // uint32_t 4 seconds (0-18 h) time duration of next deco stop
|
||||||
pressure_t cylinderpressure;
|
duration_t ndl; // uint32_t 4 seconds (0-18 h) time duration before no-deco limit
|
||||||
int sensor; /* Cylinder pressure sensor index */
|
depth_t depth; // int32_t 4 mm (0-2000 km) dive depth of this sample
|
||||||
duration_t ndl;
|
depth_t stopdepth; // int32_t 4 mm (0-2000 km) depth of next deco stop
|
||||||
duration_t stoptime;
|
temperature_t temperature; // int32_t 4 mdegrK (0-2 MdegK) ambient temperature
|
||||||
depth_t stopdepth;
|
pressure_t cylinderpressure; // int32_t 4 mbar (0-2 Mbar) main cylinder pressure
|
||||||
bool in_deco;
|
pressure_t diluentpressure; // int32_t 4 mbar (0-2 Mbar) CCR diluent pressure (rebreather)
|
||||||
int cns;
|
o2pressure_t po2; // uint16_t 2 mbar (0-65 bar) O2 partial pressure
|
||||||
int po2;
|
o2pressure_t o2setpoint; // uint16_t 2 mbar (0-65 bar) CCR O2 setpoint (rebreather)
|
||||||
int heartbeat;
|
o2pressure_t o2sensor[3]; // uint16_t 6 mbar (0-65 bar) Up to 3 PO2 sensor values (rebreather)
|
||||||
int bearing;
|
bearing_t bearing; // int16_t 2 degrees (-32k to 32k deg) compass bearing
|
||||||
};
|
uint8_t sensor; // uint8_t 1 sensorID (0-255) ID of cylinder pressure sensor
|
||||||
|
uint8_t cns; // uint8_t 1 % (0-255 %) cns% accumulated
|
||||||
|
uint8_t heartbeat; // uint8_t 1 beats/m (0-255) heart rate measurement
|
||||||
|
bool in_deco; // bool 1 y/n y/n this sample is part of deco
|
||||||
|
}; // Total size of structure: 48 bytes, excluding padding at end
|
||||||
|
|
||||||
struct divetag {
|
struct divetag {
|
||||||
/*
|
/*
|
||||||
|
|
10
divelist.c
10
divelist.c
|
@ -178,8 +178,8 @@ static int calculate_otu(struct dive *dive)
|
||||||
struct sample *sample = dc->sample + i;
|
struct sample *sample = dc->sample + i;
|
||||||
struct sample *psample = sample - 1;
|
struct sample *psample = sample - 1;
|
||||||
t = sample->time.seconds - psample->time.seconds;
|
t = sample->time.seconds - psample->time.seconds;
|
||||||
if (sample->po2) {
|
if (sample->po2.mbar) {
|
||||||
po2 = sample->po2;
|
po2 = sample->po2.mbar;
|
||||||
} else {
|
} else {
|
||||||
int o2 = active_o2(dive, dc, sample->time);
|
int o2 = active_o2(dive, dc, sample->time);
|
||||||
po2 = o2 * depth_to_atm(sample->depth.mm, dive);
|
po2 = o2 * depth_to_atm(sample->depth.mm, dive);
|
||||||
|
@ -242,8 +242,8 @@ static int calculate_cns(struct dive *dive)
|
||||||
struct sample *sample = dc->sample + i;
|
struct sample *sample = dc->sample + i;
|
||||||
struct sample *psample = sample - 1;
|
struct sample *psample = sample - 1;
|
||||||
t = sample->time.seconds - psample->time.seconds;
|
t = sample->time.seconds - psample->time.seconds;
|
||||||
if (sample->po2) {
|
if (sample->po2.mbar) {
|
||||||
po2 = sample->po2;
|
po2 = sample->po2.mbar;
|
||||||
} else {
|
} else {
|
||||||
int o2 = active_o2(dive, dc, sample->time);
|
int o2 = active_o2(dive, dc, sample->time);
|
||||||
po2 = o2 / depth_to_atm(sample->depth.mm, dive);
|
po2 = o2 / depth_to_atm(sample->depth.mm, dive);
|
||||||
|
@ -326,7 +326,7 @@ static void add_dive_to_deco(struct dive *dive)
|
||||||
for (j = t0; j < t1; j++) {
|
for (j = t0; j < t1; j++) {
|
||||||
int depth = interpolate(psample->depth.mm, sample->depth.mm, j - t0, t1 - t0);
|
int depth = interpolate(psample->depth.mm, sample->depth.mm, j - t0, t1 - t0);
|
||||||
(void)add_segment(depth_to_mbar(depth, dive) / 1000.0,
|
(void)add_segment(depth_to_mbar(depth, dive) / 1000.0,
|
||||||
&dive->cylinder[sample->sensor].gasmix, 1, sample->po2, dive);
|
&dive->cylinder[sample->sensor].gasmix, 1, sample->po2.mbar, dive);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,7 +198,7 @@ sample_cb(dc_sample_type_t type, dc_sample_value_t value, void *userdata)
|
||||||
sample->ndl.seconds = ndl;
|
sample->ndl.seconds = ndl;
|
||||||
sample->stoptime.seconds = stoptime;
|
sample->stoptime.seconds = stoptime;
|
||||||
sample->stopdepth.mm = stopdepth;
|
sample->stopdepth.mm = stopdepth;
|
||||||
sample->po2 = po2;
|
sample->po2.mbar = po2;
|
||||||
sample->cns = cns;
|
sample->cns = cns;
|
||||||
}
|
}
|
||||||
sample = prepare_sample(dc);
|
sample = prepare_sample(dc);
|
||||||
|
@ -225,7 +225,7 @@ sample_cb(dc_sample_type_t type, dc_sample_value_t value, void *userdata)
|
||||||
sample->heartbeat = value.heartbeat;
|
sample->heartbeat = value.heartbeat;
|
||||||
break;
|
break;
|
||||||
case DC_SAMPLE_BEARING:
|
case DC_SAMPLE_BEARING:
|
||||||
sample->bearing = value.bearing;
|
sample->bearing.degrees = value.bearing;
|
||||||
break;
|
break;
|
||||||
case DC_SAMPLE_VENDOR:
|
case DC_SAMPLE_VENDOR:
|
||||||
printf(" <vendor time='%u:%02u' type=\"%u\" size=\"%u\">", FRACTION(sample->time.seconds, 60),
|
printf(" <vendor time='%u:%02u' type=\"%u\" size=\"%u\">", FRACTION(sample->time.seconds, 60),
|
||||||
|
@ -237,10 +237,10 @@ sample_cb(dc_sample_type_t type, dc_sample_value_t value, void *userdata)
|
||||||
#if DC_VERSION_CHECK(0, 3, 0)
|
#if DC_VERSION_CHECK(0, 3, 0)
|
||||||
case DC_SAMPLE_SETPOINT:
|
case DC_SAMPLE_SETPOINT:
|
||||||
/* for us a setpoint means constant pO2 from here */
|
/* for us a setpoint means constant pO2 from here */
|
||||||
sample->po2 = po2 = rint(value.setpoint * 1000);
|
sample->po2.mbar = po2 = rint(value.setpoint * 1000);
|
||||||
break;
|
break;
|
||||||
case DC_SAMPLE_PPO2:
|
case DC_SAMPLE_PPO2:
|
||||||
sample->po2 = po2 = rint(value.ppo2 * 1000);
|
sample->po2.mbar = po2 = rint(value.ppo2 * 1000);
|
||||||
break;
|
break;
|
||||||
case DC_SAMPLE_CNS:
|
case DC_SAMPLE_CNS:
|
||||||
sample->cns = cns = rint(value.cns * 100);
|
sample->cns = cns = rint(value.cns * 100);
|
||||||
|
|
|
@ -375,8 +375,7 @@ static void parse_sample_keyvalue(void *_sample, const char *key, const char *va
|
||||||
}
|
}
|
||||||
if (!strcmp(key, "po2")) {
|
if (!strcmp(key, "po2")) {
|
||||||
pressure_t p = get_pressure(value);
|
pressure_t p = get_pressure(value);
|
||||||
// Ugh, typeless.
|
sample->po2.mbar = p.mbar;
|
||||||
sample->po2 = p.mbar;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!strcmp(key, "heartbeat")) {
|
if (!strcmp(key, "heartbeat")) {
|
||||||
|
@ -384,7 +383,7 @@ static void parse_sample_keyvalue(void *_sample, const char *key, const char *va
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!strcmp(key, "bearing")) {
|
if (!strcmp(key, "bearing")) {
|
||||||
sample->bearing = atoi(value);
|
sample->bearing.degrees = atoi(value);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
report_error("Unexpected sample key/value pair (%s/%s)", key, value);
|
report_error("Unexpected sample key/value pair (%s/%s)", key, value);
|
||||||
|
|
|
@ -1327,7 +1327,7 @@ static void sample_start(void)
|
||||||
cur_sample->stoptime.seconds = laststoptime;
|
cur_sample->stoptime.seconds = laststoptime;
|
||||||
cur_sample->stopdepth.mm = laststopdepth;
|
cur_sample->stopdepth.mm = laststopdepth;
|
||||||
cur_sample->cns = lastcns;
|
cur_sample->cns = lastcns;
|
||||||
cur_sample->po2 = lastpo2;
|
cur_sample->po2.mbar = lastpo2;
|
||||||
cur_sample->sensor = lastsensor;
|
cur_sample->sensor = lastsensor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1342,7 +1342,7 @@ static void sample_end(void)
|
||||||
laststoptime = cur_sample->stoptime.seconds;
|
laststoptime = cur_sample->stoptime.seconds;
|
||||||
laststopdepth = cur_sample->stopdepth.mm;
|
laststopdepth = cur_sample->stopdepth.mm;
|
||||||
lastcns = cur_sample->cns;
|
lastcns = cur_sample->cns;
|
||||||
lastpo2 = cur_sample->po2;
|
lastpo2 = cur_sample->po2.mbar;
|
||||||
cur_sample = NULL;
|
cur_sample = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1929,7 +1929,7 @@ extern int shearwater_profile_sample(void *handle, int columns, char **data, cha
|
||||||
if (data[2])
|
if (data[2])
|
||||||
cur_sample->temperature.mkelvin = metric ? C_to_mkelvin(atof(data[2])) : F_to_mkelvin(atof(data[2]));
|
cur_sample->temperature.mkelvin = metric ? C_to_mkelvin(atof(data[2])) : F_to_mkelvin(atof(data[2]));
|
||||||
if (data[3])
|
if (data[3])
|
||||||
cur_sample->po2 = atof(data[3]) * 1000;
|
cur_sample->po2.mbar = atof(data[3]) * 1000;
|
||||||
if (data[4])
|
if (data[4])
|
||||||
cur_sample->ndl.seconds = atoi(data[4]) * 60;
|
cur_sample->ndl.seconds = atoi(data[4]) * 60;
|
||||||
if (data[5])
|
if (data[5])
|
||||||
|
|
12
planner.c
12
planner.c
|
@ -159,7 +159,7 @@ double tissue_at_end(struct dive *dive, char **cached_datap)
|
||||||
}
|
}
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
lastdepth = psample->depth.mm;
|
lastdepth = psample->depth.mm;
|
||||||
tissue_tolerance = interpolate_transition(dive, t0, t1, lastdepth, sample->depth.mm, &dive->cylinder[gasidx].gasmix, sample->po2);
|
tissue_tolerance = interpolate_transition(dive, t0, t1, lastdepth, sample->depth.mm, &dive->cylinder[gasidx].gasmix, sample->po2.mbar);
|
||||||
psample = sample;
|
psample = sample;
|
||||||
t0 = t1;
|
t0 = t1;
|
||||||
}
|
}
|
||||||
|
@ -263,7 +263,7 @@ static struct dive *create_dive_from_plan(struct diveplan *diveplan, struct dive
|
||||||
cyl = &master_dive->cylinder[0];
|
cyl = &master_dive->cylinder[0];
|
||||||
oldgasmix = cyl->gasmix;
|
oldgasmix = cyl->gasmix;
|
||||||
sample = prepare_sample(dc);
|
sample = prepare_sample(dc);
|
||||||
sample->po2 = dp->po2;
|
sample->po2.mbar = dp->po2;
|
||||||
finish_sample(dc);
|
finish_sample(dc);
|
||||||
while (dp) {
|
while (dp) {
|
||||||
struct gasmix gasmix = dp->gasmix;
|
struct gasmix gasmix = dp->gasmix;
|
||||||
|
@ -300,7 +300,7 @@ static struct dive *create_dive_from_plan(struct diveplan *diveplan, struct dive
|
||||||
/* need to insert a first sample for the new gas */
|
/* need to insert a first sample for the new gas */
|
||||||
add_gas_switch_event(dive, dc, lasttime + 1, idx);
|
add_gas_switch_event(dive, dc, lasttime + 1, idx);
|
||||||
sample = prepare_sample(dc);
|
sample = prepare_sample(dc);
|
||||||
sample[-1].po2 = po2;
|
sample[-1].po2.mbar = po2;
|
||||||
sample->time.seconds = lasttime + 1;
|
sample->time.seconds = lasttime + 1;
|
||||||
sample->depth.mm = lastdepth;
|
sample->depth.mm = lastdepth;
|
||||||
finish_sample(dc);
|
finish_sample(dc);
|
||||||
|
@ -311,8 +311,8 @@ static struct dive *create_dive_from_plan(struct diveplan *diveplan, struct dive
|
||||||
sample = prepare_sample(dc);
|
sample = prepare_sample(dc);
|
||||||
/* set po2 at beginning of this segment */
|
/* set po2 at beginning of this segment */
|
||||||
/* and keep it valid for last sample - where it likely doesn't matter */
|
/* and keep it valid for last sample - where it likely doesn't matter */
|
||||||
sample[-1].po2 = po2;
|
sample[-1].po2.mbar = po2;
|
||||||
sample->po2 = po2;
|
sample->po2.mbar = po2;
|
||||||
sample->time.seconds = lasttime = time;
|
sample->time.seconds = lasttime = time;
|
||||||
sample->depth.mm = lastdepth = depth;
|
sample->depth.mm = lastdepth = depth;
|
||||||
update_cylinder_pressure(dive, sample[-1].depth.mm, depth, time - sample[-1].time.seconds,
|
update_cylinder_pressure(dive, sample[-1].depth.mm, depth, time - sample[-1].time.seconds,
|
||||||
|
@ -703,7 +703,7 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, s
|
||||||
/* we start with gas 0, then check if that was changed */
|
/* we start with gas 0, then check if that was changed */
|
||||||
gas = dive->cylinder[0].gasmix;
|
gas = dive->cylinder[0].gasmix;
|
||||||
get_gas_from_events(&dive->dc, sample->time.seconds, &gas);
|
get_gas_from_events(&dive->dc, sample->time.seconds, &gas);
|
||||||
po2 = dive->dc.sample[dive->dc.samples - 1].po2;
|
po2 = dive->dc.sample[dive->dc.samples - 1].po2.mbar;
|
||||||
if ((current_cylinder = get_gasidx(dive, &gas)) == -1) {
|
if ((current_cylinder = get_gasidx(dive, &gas)) == -1) {
|
||||||
report_error(translate("gettextFromC", "Can't find gas %s"), gasname(&gas));
|
report_error(translate("gettextFromC", "Can't find gas %s"), gasname(&gas));
|
||||||
current_cylinder = 0;
|
current_cylinder = 0;
|
||||||
|
|
|
@ -834,7 +834,7 @@ struct plot_data *populate_plot_entries(struct dive *dive, struct divecomputer *
|
||||||
pi->has_ndl |= sample->ndl.seconds;
|
pi->has_ndl |= sample->ndl.seconds;
|
||||||
entry->in_deco = sample->in_deco;
|
entry->in_deco = sample->in_deco;
|
||||||
entry->cns = sample->cns;
|
entry->cns = sample->cns;
|
||||||
entry->po2 = sample->po2 / 1000.0;
|
entry->po2 = sample->po2.mbar / 1000.0;
|
||||||
/* FIXME! sensor index -> cylinder index translation! */
|
/* FIXME! sensor index -> cylinder index translation! */
|
||||||
entry->cylinderindex = sample->sensor;
|
entry->cylinderindex = sample->sensor;
|
||||||
SENSOR_PRESSURE(entry) = sample->cylinderpressure.mbar;
|
SENSOR_PRESSURE(entry) = sample->cylinderpressure.mbar;
|
||||||
|
@ -843,7 +843,7 @@ struct plot_data *populate_plot_entries(struct dive *dive, struct divecomputer *
|
||||||
else
|
else
|
||||||
entry->temperature = lasttemp;
|
entry->temperature = lasttemp;
|
||||||
entry->heartbeat = sample->heartbeat;
|
entry->heartbeat = sample->heartbeat;
|
||||||
entry->bearing = sample->bearing;
|
entry->bearing = sample->bearing.degrees;
|
||||||
|
|
||||||
/* skip events that happened at this time */
|
/* skip events that happened at this time */
|
||||||
while (ev && ev->time.seconds == time)
|
while (ev && ev->time.seconds == time)
|
||||||
|
|
|
@ -262,12 +262,12 @@ static void save_sample(struct membuffer *b, struct sample *sample, struct sampl
|
||||||
old->cns = sample->cns;
|
old->cns = sample->cns;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sample->po2 != old->po2) {
|
if (sample->po2.mbar != old->po2.mbar) {
|
||||||
put_milli(b, " po2=", sample->po2, "bar");
|
put_milli(b, " po2=", sample->po2.mbar, "bar");
|
||||||
old->po2 = sample->po2;
|
old->po2 = sample->po2;
|
||||||
}
|
}
|
||||||
show_index(b, sample->heartbeat, "heartbeat=", "");
|
show_index(b, sample->heartbeat, "heartbeat=", "");
|
||||||
show_index(b, sample->bearing, "bearing=", "°");
|
show_index(b, sample->bearing.degrees, "bearing=", "°");
|
||||||
put_format(b, "\n");
|
put_format(b, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -279,12 +279,12 @@ static void save_sample(struct membuffer *b, struct sample *sample, struct sampl
|
||||||
old->cns = sample->cns;
|
old->cns = sample->cns;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sample->po2 != old->po2) {
|
if (sample->po2.mbar != old->po2.mbar) {
|
||||||
put_milli(b, " po2='", sample->po2, " bar'");
|
put_milli(b, " po2='", sample->po2.mbar, " bar'");
|
||||||
old->po2 = sample->po2;
|
old->po2 = sample->po2;
|
||||||
}
|
}
|
||||||
show_index(b, sample->heartbeat, "heartbeat='", "'");
|
show_index(b, sample->heartbeat, "heartbeat='", "'");
|
||||||
show_index(b, sample->bearing, "bearing='", "'");
|
show_index(b, sample->bearing.degrees, "bearing='", "'");
|
||||||
put_format(b, " />\n");
|
put_format(b, " />\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
22
units.h
22
units.h
|
@ -59,22 +59,32 @@ typedef int64_t timestamp_t;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int seconds;
|
uint32_t seconds; // durations up to 68 yrs
|
||||||
} duration_t;
|
} duration_t;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int mm;
|
int32_t mm;
|
||||||
} depth_t;
|
} depth_t; // depth to 2000 km
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int mbar;
|
int32_t mbar; // pressure up to 2000 bar
|
||||||
} pressure_t;
|
} pressure_t;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int mkelvin;
|
uint16_t mbar;
|
||||||
|
} o2pressure_t; // pressure up to 65 bar
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int16_t degrees;
|
||||||
|
} bearing_t; // compass bearing
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int32_t mkelvin; // up to 1750 degrees K
|
||||||
} temperature_t;
|
} temperature_t;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
@ -242,4 +252,4 @@ struct units {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue