Assigning dc type to the dc structure
This patch lays the foundation for differentiating between
open-circuit(OC)
dives and rebreather dives (CCR). The following were done:
1) In dive.h add an enum type dive_computer_type
2) In dive.h add two more fields to the dc structure:
a) dctype (an enum field indicating dc type)
b) no_o2sensors (indicating number of o2 sensors for this dc)
3) In parse-xml.c add a function dctype_string. This parses the dc_type
string from xml and assigns an enum value which will later be
returned
to the function that parses the dc variables.
4) In dive.c in function fixup_dive_dc, the dc->dctype variable is set
to OC (open-circuit) if this value has not been initialised from the
xm log file.
Signed-off-by: Willem Ferguson <[email protected]>
>From c5ce9d1c66049670ead8e8aa058d1659bd62910a Mon Sep 17 00:00:00 2001
From: Willem Ferguson <[email protected]>
Date: Tue, 10 Jun 2014 15:42:54 +0200
Subject: [PATCH 2/2] Assigning dc type to the dc structure
This patch lays the foundation for differentiating between open-circuit(OC)
dives and rebreather dives (CCR). The following were done:
1) In dive.h add an enum type dive_computer_type
2) In dive.h add two more fields to the dc structure:
a) dctype (an enum field indicating dc type)
b) no_o2sensors (indicating number of o2 sensors for this dc)
3) In parse-xml.c add a function dctype_string. This parses the dc_type
string from xml and assigns an enum value which will later be returned
to the function that parses the dc variables.
4) In dive.c in function fixup_dive_dc, the dc->dctype variable is set
to OC (open-circuit) if this value has not been initialised from the
xm log file.
Signed-off-by: Willem Ferguson <[email protected]>
---
dive.c | 3 +++
dive.h | 5 +++++
parse-xml.c | 24 +++++++++++++++++++++++-
3 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/dive.c b/dive.c
index 1f1a597..b308027 100644
--- a/dive.c
+++ b/dive.c
@@ -851,6 +851,9 @@ static void fixup_dive_dc(struct dive *dive, struct divecomputer *dc)
fixup_dc_duration(dc);
update_min_max_temperatures(dive, dc->watertemp);
+
+ if (!dc->dctype) dc->dctype = OC; // If dc type is undefined, then make it open circuit (OC)
+ // This ensures dc->dctype always has a value.
for (i = 0; i < dc->samples; i++) {
struct sample *sample = dc->sample + i;
int time = sample->time.seconds;
diff --git a/dive.h b/dive.h
index b7a53d5..256336f 100644
--- a/dive.h
+++ b/dive.h
@@ -41,6 +41,9 @@ extern "C" {
#include <stdbool.h>
#endif
+enum dive_comp_type {OC, CCR}; // Flags (Open-circuit and Closed-circuit-rebreather) for setting dive computer type
+
+
struct gasmix {
fraction_t o2;
fraction_t he;
@@ -216,6 +219,8 @@ struct divecomputer {
depth_t maxdepth, meandepth;
temperature_t airtemp, watertemp;
pressure_t surface_pressure;
+ enum dive_comp_type dctype; // Type of dive computer: 'CCR' = rebreather
+ int no_o2sensors; // rebreathers: number of O2 sensors used
int salinity; // kg per 10000 l
const char *model;
uint32_t deviceid, diveid;
diff --git a/parse-xml.c b/parse-xml.c
index 1b5d88b..e89f90f 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -531,7 +531,7 @@ static void get_rating(char *buffer, void *_i)
static void double_to_permil(char *buffer, void *_i)
{
- int *i = _i;
+ uint16_t *i = _i;
*i = rint(ascii_strtod(buffer, NULL) * 1000.0);
}
@@ -745,6 +745,28 @@ static int match_dc_data_fields(struct divecomputer *dc, const char *name, char
return 0;
}
+/* Parse the dc_type string from xml and set the dc type.. */
+static void dctype_string(char *buffer, void *_d)
+{
+ int size;
+ char *res;
+ enum dive_comp_type *d = _d; // define a dive_computer_type
+ while (isspace(*buffer)) // Collect the string from xml buffer
+ buffer++;
+ size = strlen(buffer);
+ while (size && isspace(buffer[size - 1]))
+ size--;
+ if (!size)
+ return;
+ res = malloc(size + 1); // Store the string..
+ memcpy(res, buffer, size);
+ res[size] = 0; // ..and terminate it properly
+ if (strcmp(res,"CCR") == 0) // Based on this string..
+ *d = CCR; // .. set the dc type
+ else // If the string is not 'CCR'..
+ *d = OC; // then set it to OC (open-circuit)
+}
+
/* We're in the top-level dive xml. Try to convert whatever value to a dive value */
static void try_to_fill_dc(struct divecomputer *dc, const char *name, char *buf)
{
--
1.7.10.4
_______________________________________________
subsurface mailing list
[email protected]
http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface