RFC patch: store dive computer serial / firmware again

Dirk Hohndel dirk at hohndel.org
Thu Nov 20 12:33:19 PST 2014


Apparently we did this in the Gtk version of Subsurface, but lost this in
the Qt transition. Here's a quick patch that should fix this, but I'm not
quite ready to add this to master until I hear some feedback and a few
people have tested it.

/D


-------------- next part --------------
>From 0911e49aa5315165abf33cf6787dead35554aa27 Mon Sep 17 00:00:00 2001
From: Dirk Hohndel <dirk at hohndel.org>
Date: Thu, 20 Nov 2014 12:28:12 -0800
Subject: [PATCH] Remember serial and firmware for divecomputers

This should work for dive computers that report those data.
Before this can go into master we need to understand
- how this is supposed to interact with the string based interface that
  possibly returns the firmware on a per-dive basis
- if we want to have multiple distinct entries in the list of dive
  computers (that's what we get with the current code since the firmware
  is hashed into the deviceid for everything except the Uemis)
- if this breaks anything

Signed-off-by: Dirk Hohndel <dirk at hohndel.org>
---
 libdivecomputer.c | 12 +++++++++++-
 libdivecomputer.h |  2 +-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/libdivecomputer.c b/libdivecomputer.c
index 17bd01a0abce..301d2d82b404 100644
--- a/libdivecomputer.c
+++ b/libdivecomputer.c
@@ -437,6 +437,8 @@ static int dive_cb(const unsigned char *data, unsigned int size,
 	}
 	dive->dc.model = strdup(devdata->model);
 	dive->dc.deviceid = devdata->deviceid;
+	dive->dc.serial = strdup(devdata->serial);
+	dive->dc.fw_version = strdup(devdata->firmware);
 	dive->dc.diveid = calculate_diveid(fingerprint, fsize);
 
 	tm.tm_year = dt.year;
@@ -700,6 +702,7 @@ static void event_cb(dc_device_t *device, dc_event_type_t event, const void *dat
 	const dc_event_vendor_t *vendor = data;
 	device_data_t *devdata = userdata;
 	unsigned int serial;
+	char buffer[16];
 
 	switch (event) {
 	case DC_EVENT_WAITING:
@@ -729,7 +732,14 @@ static void event_cb(dc_device_t *device, dc_event_type_t event, const void *dat
 		if (!strcmp(devdata->vendor, "Suunto"))
 			serial = fixup_suunto_versions(devdata, devinfo);
 		devdata->deviceid = calculate_sha1(devinfo->model, devinfo->firmware, serial);
-
+		if (serial != 0) {
+			snprintf(buffer, sizeof(buffer), "0x%08x", serial);
+			devdata->serial = strdup(buffer);
+		}
+		if (devinfo->firmware != 0) {
+			snprintf(buffer, sizeof(buffer), "0x%08x", devinfo->firmware);
+			devdata->firmware = strdup(buffer);
+		}
 		break;
 	case DC_EVENT_CLOCK:
 		dev_info(devdata, translate("gettextFromC", "Event: systime=%" PRId64 ", devtime=%u\n"),
diff --git a/libdivecomputer.h b/libdivecomputer.h
index af51854a0d1f..795c4ae85db6 100644
--- a/libdivecomputer.h
+++ b/libdivecomputer.h
@@ -19,7 +19,7 @@ typedef struct device_data_t
 {
 	dc_descriptor_t *descriptor;
 	const char *vendor, *product, *devname;
-	const char *model;
+	const char *model, *serial, *firmware;
 	uint32_t deviceid, diveid;
 	dc_device_t *device;
 	dc_context_t *context;
-- 
1.8.0.rc0.18.gf84667d



More information about the subsurface mailing list