summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2014-10-22 12:11:12 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-11-07 20:55:18 -0800
commit0a27978014162f88f1ac26695e7180f502e66498 (patch)
tree28d897a194d601f0d1410d751139da10a30a1d81
parentcff413f14d89b8239e676240aef4d73f8ea07559 (diff)
downloadsubsurface-0a27978014162f88f1ac26695e7180f502e66498.tar.gz
Use the new DC_FIELD_STRING callback if it exists
This recognizes recognize some strigns (serial number and firmware version), and the ones that it doesn't recognize it adds as extra data using Dirk's new interface. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--dive.c4
-rw-r--r--dive.h2
-rw-r--r--libdivecomputer.c47
3 files changed, 52 insertions, 1 deletions
diff --git a/dive.c b/dive.c
index 0216a75ac..ccd071ca4 100644
--- a/dive.c
+++ b/dive.c
@@ -1129,6 +1129,10 @@ static void fixup_dive_dc(struct dive *dive, struct divecomputer *dc)
int pressure_delta[MAX_CYLINDERS] = { INT_MAX, };
int first_cylinder;
+ /* Add device information to table */
+ if (dc->deviceid && (dc->serial || dc->fw_version))
+ create_device_node(dc->model, dc->deviceid, dc->serial, dc->fw_version, "");
+
/* Fixup duration and mean depth */
fixup_dc_duration(dc);
update_min_max_temperatures(dive, dc->watertemp);
diff --git a/dive.h b/dive.h
index dffdc4ebe..e3c4c74e7 100644
--- a/dive.h
+++ b/dive.h
@@ -261,7 +261,7 @@ struct divecomputer {
enum dive_comp_type dctype; // dive computer type: OC(default) or CCR
uint8_t no_o2sensors; // rebreathers: number of O2 sensors used
int salinity; // kg per 10000 l
- const char *model;
+ const char *model, *serial, *fw_version;
uint32_t deviceid, diveid;
int samples, alloc_samples;
struct sample *sample;
diff --git a/libdivecomputer.c b/libdivecomputer.c
index ff8d0eb93..c78d3b620 100644
--- a/libdivecomputer.c
+++ b/libdivecomputer.c
@@ -397,6 +397,39 @@ static uint32_t calculate_diveid(const unsigned char *fingerprint, unsigned int
return csum[0];
}
+static uint32_t calculate_string_hash(const char *str)
+{
+ return calculate_diveid(str, strlen(str));
+}
+
+#ifdef DC_FIELD_STRING
+static void parse_string_field(struct dive *dive, dc_field_string_t *str)
+{
+ // Our dive ID is the string hash of the "Dive ID" string
+ if (!strcmp(str->desc, "Dive ID")) {
+ if (!dive->dc.diveid)
+ dive->dc.diveid = calculate_string_hash(str->value);
+ return;
+ }
+
+ if (!strcmp(str->desc, "Serial")) {
+ if (!dive->dc.serial)
+ dive->dc.serial = strdup(str->value);
+ if (!dive->dc.deviceid)
+ dive->dc.deviceid = calculate_string_hash(str->value);
+ return;
+ }
+
+ if (!strcmp(str->desc, "FW Version")) {
+ if (!dive->dc.fw_version)
+ dive->dc.fw_version = strdup(str->value);
+ return;
+ }
+
+ add_extra_data(&dive->dc, str->desc, str->value);
+}
+#endif
+
/* returns true if we want libdivecomputer's dc_device_foreach() to continue,
* false otherwise */
static int dive_cb(const unsigned char *data, unsigned int size,
@@ -494,6 +527,20 @@ static int dive_cb(const unsigned char *data, unsigned int size,
dive->dc.surface_pressure.mbar = rint(surface_pressure * 1000.0);
#endif
+#ifdef DC_FIELD_STRING
+ // The dive parsing may give us more device information
+ int idx;
+ for (idx = 0; idx < 100; idx++) {
+ dc_field_string_t str = { NULL };
+ rc = dc_parser_get_field(parser, DC_FIELD_STRING, idx, &str);
+ if (rc != DC_STATUS_SUCCESS)
+ break;
+ if (!str.desc || !str.value)
+ break;
+ parse_string_field(dive, &str);
+ }
+#endif
+
rc = parse_gasmixes(devdata, dive, parser, ngases, data);
if (rc != DC_STATUS_SUCCESS) {
dev_info(devdata, translate("gettextFromC", "Error parsing the gas mix"));