summaryrefslogtreecommitdiffstats
path: root/parse-xml.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2012-12-30 20:00:51 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-12-30 20:44:47 -0800
commitd720e133d84d6d468ffab48698d5105849f7d14c (patch)
tree78b531ab868c901f8077a49d5d8304422698f6a0 /parse-xml.c
parentdf0ea072920668de4517ad85c742c7169bd24f22 (diff)
downloadsubsurface-d720e133d84d6d468ffab48698d5105849f7d14c.tar.gz
First step in cleaning up cylinder pressure sensor logic
This clarifies/changes the meaning of our "cylinderindex" entry in our samples. It has been rather confused, because different dive computers have done things differently, and the naming really hasn't helped. There are two totally different - and independent - cylinder "indexes": - the pressure sensor index, which indicates which cylinder the sensor data is from. - the "active cylinder" index, which indicates which cylinder we actually breathe from. These two values really are totally independent, and have nothing what-so-ever to do with each other. The sensor index may well be fixed: many dive computers only support a single pressure sensor (whether wireless or wired), and the sensor index is thus always zero. Other dive computers may support multiple pressure sensors, and the gas switch event may - or may not - indicate that the sensor changed too. A dive computer might give the sensor data for *all* cylinders it can read, regardless of which one is the one we're actively breathing. In fact, some dive computers might give sensor data for not just *your* cylinder, but your buddies. This patch renames "cylinderindex" in the samples as "sensor", making it quite clear that it's about which sensor index the pressure data in the sample is about. The way we figure out which is the currently active gas is with an explicit has change event. If a computer (like the Uemis Zurich) joins the two concepts together, then a sensor change should also create a gas switch event. This patch also changes the Uemis importer to do that. Finally, it should be noted that the plot info works totally separately from the sample data, and is about what we actually *display*, not about the sample pressures etc. In the plot info, the "cylinderindex" does in fact mean the currently active cylinder, and while it is initially set to match the sensor information from the samples, we then walk the gas change events and fix it up - and if the active cylinder differs from the sensor cylinder, we clear the sensor data. [Dirk Hohndel: this conflicted with some of my recent changes - I think I merged things correctly...] Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'parse-xml.c')
-rw-r--r--parse-xml.c40
1 files changed, 39 insertions, 1 deletions
diff --git a/parse-xml.c b/parse-xml.c
index 8232fb041..a256990b3 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -155,6 +155,7 @@ static gboolean in_settings = FALSE;
static struct tm cur_tm;
static int cur_cylinder_index, cur_ws_index;
static int lastndl, laststoptime, laststopdepth, lastcns, lastpo2, lastindeco;
+static int lastcylinderindex, lastsensor;
static enum import_source {
UNKNOWN,
@@ -650,6 +651,39 @@ static void try_to_fill_dc(struct divecomputer *dc, const char *name, char *buf)
nonmatch("divecomputer", name, buf);
}
+void add_gas_switch_event(struct dive *dive, struct divecomputer *dc, int seconds, int idx)
+{
+ /* The gas switch event format is insane. It will be fixed, I think */
+ int o2 = dive->cylinder[idx].gasmix.o2.permille;
+ int he = dive->cylinder[idx].gasmix.he.permille;
+ int value;
+
+ if (!o2)
+ o2 = AIR_PERMILLE;
+ o2 = (o2+5) / 10;
+ he = (he+5) / 10;
+ value = o2 + (he << 16);
+
+ add_event(dc, seconds, 11, 0, value, "gaschange");
+}
+
+static void get_cylinderindex(char *buffer, void *_i)
+{
+ int *i = _i;
+ *i = atoi(buffer);
+ if (lastcylinderindex != *i) {
+ add_gas_switch_event(cur_dive, cur_dc, cur_sample->time.seconds, *i);
+ lastcylinderindex = *i;
+ }
+}
+
+static void get_sensor(char *buffer, void *_i)
+{
+ int *i = _i;
+ *i = atoi(buffer);
+ lastsensor = *i;
+}
+
/* We're in samples - try to convert the random xml value to something useful */
static void try_to_fill_sample(struct sample *sample, const char *name, char *buf)
{
@@ -661,7 +695,9 @@ static void try_to_fill_sample(struct sample *sample, const char *name, char *bu
return;
if (MATCH(".sample.cylpress", pressure, &sample->cylinderpressure))
return;
- if (MATCH(".sample.cylinderindex", get_index, &sample->cylinderindex))
+ if (MATCH(".sample.cylinderindex", get_cylinderindex, &sample->sensor))
+ return;
+ if (MATCH(".sample.sensor", get_sensor, &sample->sensor))
return;
if (MATCH(".sample.depth", depth, &sample->depth))
return;
@@ -1005,6 +1041,7 @@ static gboolean is_dive(void)
static void reset_dc_info(struct divecomputer *dc)
{
lastcns = lastpo2 = lastndl = laststoptime = laststopdepth = lastindeco = 0;
+ lastsensor = lastcylinderindex = 0;
}
static void reset_dc_settings(void)
@@ -1129,6 +1166,7 @@ static void sample_start(void)
cur_sample->stopdepth.mm = laststopdepth;
cur_sample->cns = lastcns;
cur_sample->po2 = lastpo2;
+ cur_sample->sensor = lastsensor;
}
static void sample_end(void)