summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Willem Ferguson <willemferguson@zoology.up.ac.za>2014-06-03 19:21:41 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-06-03 17:05:25 -0700
commiteaf6d564874ac838dc4f3cca7a781034ae60ef7f (patch)
treed214c58bdc33f6dbd058afe715de357dd14d4114
parent1fec6453a2b7b6dcd34901a4e92dd11aae38879c (diff)
downloadsubsurface-eaf6d564874ac838dc4f3cca7a781034ae60ef7f.tar.gz
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>
-rw-r--r--dive.c2
-rw-r--r--dive.h34
-rw-r--r--divelist.c10
-rw-r--r--libdivecomputer.c8
-rw-r--r--load-git.c5
-rw-r--r--parse-xml.c6
-rw-r--r--planner.c12
-rw-r--r--profile.c4
-rw-r--r--save-git.c6
-rw-r--r--save-xml.c6
-rw-r--r--units.h22
11 files changed, 64 insertions, 51 deletions
diff --git a/dive.c b/dive.c
index 52a95ef80..fe2b408ea 100644
--- a/dive.c
+++ b/dive.c
@@ -1105,7 +1105,7 @@ static void merge_samples(struct divecomputer *res, struct divecomputer *a, stru
sample.sensor = as->sensor;
if (as->cns)
sample.cns = as->cns;
- if (as->po2)
+ if (as->po2.mbar)
sample.po2 = as->po2;
if (as->ndl.seconds)
sample.ndl = as->ndl;
diff --git a/dive.h b/dive.h
index cdef2cd40..7a1c26d13 100644
--- a/dive.h
+++ b/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);
const char *gasname(const struct gasmix *gasmix);
-struct sample {
- duration_t time;
- depth_t depth;
- temperature_t temperature;
- pressure_t cylinderpressure;
- int sensor; /* Cylinder pressure sensor index */
- duration_t ndl;
- duration_t stoptime;
- depth_t stopdepth;
- bool in_deco;
- int cns;
- int po2;
- int heartbeat;
- int bearing;
-};
+struct sample // BASE TYPE BYTES UNITS RANGE DESCRIPTION
+{ // --------- ----- ----- ----- -----------
+ duration_t time; // uint32_t 4 seconds (0-68 yrs) elapsed dive time up to this sample
+ duration_t stoptime; // uint32_t 4 seconds (0-18 h) time duration of next deco stop
+ duration_t ndl; // uint32_t 4 seconds (0-18 h) time duration before no-deco limit
+ depth_t depth; // int32_t 4 mm (0-2000 km) dive depth of this sample
+ depth_t stopdepth; // int32_t 4 mm (0-2000 km) depth of next deco stop
+ temperature_t temperature; // int32_t 4 mdegrK (0-2 MdegK) ambient temperature
+ pressure_t cylinderpressure; // int32_t 4 mbar (0-2 Mbar) main cylinder pressure
+ pressure_t diluentpressure; // int32_t 4 mbar (0-2 Mbar) CCR diluent pressure (rebreather)
+ o2pressure_t po2; // uint16_t 2 mbar (0-65 bar) O2 partial pressure
+ o2pressure_t o2setpoint; // uint16_t 2 mbar (0-65 bar) CCR O2 setpoint (rebreather)
+ o2pressure_t o2sensor[3]; // uint16_t 6 mbar (0-65 bar) Up to 3 PO2 sensor values (rebreather)
+ 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 {
/*
diff --git a/divelist.c b/divelist.c
index 489982465..c018bbdc7 100644
--- a/divelist.c
+++ b/divelist.c
@@ -178,8 +178,8 @@ static int calculate_otu(struct dive *dive)
struct sample *sample = dc->sample + i;
struct sample *psample = sample - 1;
t = sample->time.seconds - psample->time.seconds;
- if (sample->po2) {
- po2 = sample->po2;
+ if (sample->po2.mbar) {
+ po2 = sample->po2.mbar;
} else {
int o2 = active_o2(dive, dc, sample->time);
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 *psample = sample - 1;
t = sample->time.seconds - psample->time.seconds;
- if (sample->po2) {
- po2 = sample->po2;
+ if (sample->po2.mbar) {
+ po2 = sample->po2.mbar;
} else {
int o2 = active_o2(dive, dc, sample->time);
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++) {
int depth = interpolate(psample->depth.mm, sample->depth.mm, j - t0, t1 - t0);
(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);
}
}
}
diff --git a/libdivecomputer.c b/libdivecomputer.c
index d6f2d60b1..e8a033848 100644
--- a/libdivecomputer.c
+++ b/libdivecomputer.c
@@ -198,7 +198,7 @@ sample_cb(dc_sample_type_t type, dc_sample_value_t value, void *userdata)
sample->ndl.seconds = ndl;
sample->stoptime.seconds = stoptime;
sample->stopdepth.mm = stopdepth;
- sample->po2 = po2;
+ sample->po2.mbar = po2;
sample->cns = cns;
}
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;
break;
case DC_SAMPLE_BEARING:
- sample->bearing = value.bearing;
+ sample->bearing.degrees = value.bearing;
break;
case DC_SAMPLE_VENDOR:
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)
case DC_SAMPLE_SETPOINT:
/* 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;
case DC_SAMPLE_PPO2:
- sample->po2 = po2 = rint(value.ppo2 * 1000);
+ sample->po2.mbar = po2 = rint(value.ppo2 * 1000);
break;
case DC_SAMPLE_CNS:
sample->cns = cns = rint(value.cns * 100);
diff --git a/load-git.c b/load-git.c
index acfdd2527..f50b067cf 100644
--- a/load-git.c
+++ b/load-git.c
@@ -375,8 +375,7 @@ static void parse_sample_keyvalue(void *_sample, const char *key, const char *va
}
if (!strcmp(key, "po2")) {
pressure_t p = get_pressure(value);
- // Ugh, typeless.
- sample->po2 = p.mbar;
+ sample->po2.mbar = p.mbar;
return;
}
if (!strcmp(key, "heartbeat")) {
@@ -384,7 +383,7 @@ static void parse_sample_keyvalue(void *_sample, const char *key, const char *va
return;
}
if (!strcmp(key, "bearing")) {
- sample->bearing = atoi(value);
+ sample->bearing.degrees = atoi(value);
return;
}
report_error("Unexpected sample key/value pair (%s/%s)", key, value);
diff --git a/parse-xml.c b/parse-xml.c
index cef5221db..d1985657d 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -1327,7 +1327,7 @@ static void sample_start(void)
cur_sample->stoptime.seconds = laststoptime;
cur_sample->stopdepth.mm = laststopdepth;
cur_sample->cns = lastcns;
- cur_sample->po2 = lastpo2;
+ cur_sample->po2.mbar = lastpo2;
cur_sample->sensor = lastsensor;
}
@@ -1342,7 +1342,7 @@ static void sample_end(void)
laststoptime = cur_sample->stoptime.seconds;
laststopdepth = cur_sample->stopdepth.mm;
lastcns = cur_sample->cns;
- lastpo2 = cur_sample->po2;
+ lastpo2 = cur_sample->po2.mbar;
cur_sample = NULL;
}
@@ -1929,7 +1929,7 @@ extern int shearwater_profile_sample(void *handle, int columns, char **data, cha
if (data[2])
cur_sample->temperature.mkelvin = metric ? C_to_mkelvin(atof(data[2])) : F_to_mkelvin(atof(data[2]));
if (data[3])
- cur_sample->po2 = atof(data[3]) * 1000;
+ cur_sample->po2.mbar = atof(data[3]) * 1000;
if (data[4])
cur_sample->ndl.seconds = atoi(data[4]) * 60;
if (data[5])
diff --git a/planner.c b/planner.c
index 445d375c5..32411b950 100644
--- a/planner.c
+++ b/planner.c
@@ -159,7 +159,7 @@ double tissue_at_end(struct dive *dive, char **cached_datap)
}
if (i > 0)
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;
t0 = t1;
}
@@ -263,7 +263,7 @@ static struct dive *create_dive_from_plan(struct diveplan *diveplan, struct dive
cyl = &master_dive->cylinder[0];
oldgasmix = cyl->gasmix;
sample = prepare_sample(dc);
- sample->po2 = dp->po2;
+ sample->po2.mbar = dp->po2;
finish_sample(dc);
while (dp) {
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 */
add_gas_switch_event(dive, dc, lasttime + 1, idx);
sample = prepare_sample(dc);
- sample[-1].po2 = po2;
+ sample[-1].po2.mbar = po2;
sample->time.seconds = lasttime + 1;
sample->depth.mm = lastdepth;
finish_sample(dc);
@@ -311,8 +311,8 @@ static struct dive *create_dive_from_plan(struct diveplan *diveplan, struct dive
sample = prepare_sample(dc);
/* set po2 at beginning of this segment */
/* and keep it valid for last sample - where it likely doesn't matter */
- sample[-1].po2 = po2;
- sample->po2 = po2;
+ sample[-1].po2.mbar = po2;
+ sample->po2.mbar = po2;
sample->time.seconds = lasttime = time;
sample->depth.mm = lastdepth = depth;
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 */
gas = dive->cylinder[0].gasmix;
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) {
report_error(translate("gettextFromC", "Can't find gas %s"), gasname(&gas));
current_cylinder = 0;
diff --git a/profile.c b/profile.c
index d3934e308..67948f22b 100644
--- a/profile.c
+++ b/profile.c
@@ -834,7 +834,7 @@ struct plot_data *populate_plot_entries(struct dive *dive, struct divecomputer *
pi->has_ndl |= sample->ndl.seconds;
entry->in_deco = sample->in_deco;
entry->cns = sample->cns;
- entry->po2 = sample->po2 / 1000.0;
+ entry->po2 = sample->po2.mbar / 1000.0;
/* FIXME! sensor index -> cylinder index translation! */
entry->cylinderindex = sample->sensor;
SENSOR_PRESSURE(entry) = sample->cylinderpressure.mbar;
@@ -843,7 +843,7 @@ struct plot_data *populate_plot_entries(struct dive *dive, struct divecomputer *
else
entry->temperature = lasttemp;
entry->heartbeat = sample->heartbeat;
- entry->bearing = sample->bearing;
+ entry->bearing = sample->bearing.degrees;
/* skip events that happened at this time */
while (ev && ev->time.seconds == time)
diff --git a/save-git.c b/save-git.c
index 6abba601a..af682820d 100644
--- a/save-git.c
+++ b/save-git.c
@@ -262,12 +262,12 @@ static void save_sample(struct membuffer *b, struct sample *sample, struct sampl
old->cns = sample->cns;
}
- if (sample->po2 != old->po2) {
- put_milli(b, " po2=", sample->po2, "bar");
+ if (sample->po2.mbar != old->po2.mbar) {
+ put_milli(b, " po2=", sample->po2.mbar, "bar");
old->po2 = sample->po2;
}
show_index(b, sample->heartbeat, "heartbeat=", "");
- show_index(b, sample->bearing, "bearing=", "°");
+ show_index(b, sample->bearing.degrees, "bearing=", "°");
put_format(b, "\n");
}
diff --git a/save-xml.c b/save-xml.c
index 5f61af77f..d48d0ef08 100644
--- a/save-xml.c
+++ b/save-xml.c
@@ -279,12 +279,12 @@ static void save_sample(struct membuffer *b, struct sample *sample, struct sampl
old->cns = sample->cns;
}
- if (sample->po2 != old->po2) {
- put_milli(b, " po2='", sample->po2, " bar'");
+ if (sample->po2.mbar != old->po2.mbar) {
+ put_milli(b, " po2='", sample->po2.mbar, " bar'");
old->po2 = sample->po2;
}
show_index(b, sample->heartbeat, "heartbeat='", "'");
- show_index(b, sample->bearing, "bearing='", "'");
+ show_index(b, sample->bearing.degrees, "bearing='", "'");
put_format(b, " />\n");
}
diff --git a/units.h b/units.h
index 0a9e44b79..4b32d5237 100644
--- a/units.h
+++ b/units.h
@@ -59,22 +59,32 @@ typedef int64_t timestamp_t;
typedef struct
{
- int seconds;
+ uint32_t seconds; // durations up to 68 yrs
} duration_t;
typedef struct
{
- int mm;
-} depth_t;
+ int32_t mm;
+} depth_t; // depth to 2000 km
typedef struct
{
- int mbar;
+ int32_t mbar; // pressure up to 2000 bar
} pressure_t;
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;
typedef struct
@@ -242,4 +252,4 @@ struct units {
}
#endif
-#endif \ No newline at end of file
+#endif