aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2021-08-16 20:52:00 -1000
committerGravatar Dirk Hohndel <dirk@hohndel.org>2021-08-18 13:22:02 -0700
commitd141bbf38fab99ea31ba45a79a95046ce152b982 (patch)
tree8948cbd768958b0457ad76a7dcb087c14084db81
parent35adf2d72910d0cb287396b08717067d70c8ceb3 (diff)
downloadsubsurface-d141bbf38fab99ea31ba45a79a95046ce152b982.tar.gz
Update the serial number and deviceid in sync when loading
When we save the divecomputer data, we never actually save the serial value as a field. We used to rely on saving the very dodgy 'deviceid', and then look up the serial number from there. And that never really worked reliably, but we didn't really notice, because we never really _used_ the serial number anywhere. The only place the serial number is actually reliably displayed is in the "Extra data" tab, which contains the key value pairs, and that's where the original dive download code got the serial number from. So just parse that at load time too, the same way we parsed it at dive download time. In fact, do the firmware version the same way, and remove the code from the downloader, since it too can rely on 'add_extra_data()' just picking up the information directly. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--core/divecomputer.c10
-rw-r--r--core/libdivecomputer.c25
2 files changed, 11 insertions, 24 deletions
diff --git a/core/divecomputer.c b/core/divecomputer.c
index 200094588..289f9efa2 100644
--- a/core/divecomputer.c
+++ b/core/divecomputer.c
@@ -474,16 +474,22 @@ void remove_event_from_dc(struct divecomputer *dc, struct event *event)
void add_extra_data(struct divecomputer *dc, const char *key, const char *value)
{
struct extra_data **ed = &dc->extra_data;
+ const char *newval = strdup(value);
- if (!strcasecmp(key, "Serial"))
+ if (!strcasecmp(key, "Serial")) {
dc->deviceid = calculate_string_hash(value);
+ dc->serial = newval;
+ }
+ if (!strcmp(key, "FW Version")) {
+ dc->fw_version = newval;
+ }
while (*ed)
ed = &(*ed)->next;
*ed = malloc(sizeof(struct extra_data));
if (*ed) {
(*ed)->key = strdup(key);
- (*ed)->value = strdup(value);
+ (*ed)->value = newval;
(*ed)->next = NULL;
}
}
diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c
index d2d25306d..c750efdd6 100644
--- a/core/libdivecomputer.c
+++ b/core/libdivecomputer.c
@@ -553,20 +553,6 @@ uint32_t calculate_string_hash(const char *str)
return calculate_diveid((const unsigned char *)str, strlen(str));
}
-/*
- * Set the serial number.
- *
- * This also sets the device ID by hashing the serial
- * number string.
- */
-static void set_dc_serial(struct divecomputer *dc, const char *serial, const device_data_t *devdata)
-{
- const struct device *device;
-
- dc->serial = strdup(serial);
- dc->deviceid = calculate_string_hash(serial);
-}
-
static void parse_string_field(device_data_t *devdata, struct dive *dive, dc_field_string_t *str)
{
// Our dive ID is the string hash of the "Dive ID" string
@@ -575,15 +561,10 @@ static void parse_string_field(device_data_t *devdata, struct dive *dive, dc_fie
dive->dc.diveid = calculate_string_hash(str->value);
return;
}
+
+ // This will pick up serial number and firmware data
add_extra_data(&dive->dc, str->desc, str->value);
- if (!strcmp(str->desc, "Serial")) {
- set_dc_serial(&dive->dc, str->value, devdata);
- return;
- }
- if (!strcmp(str->desc, "FW Version")) {
- dive->dc.fw_version = strdup(str->value);
- return;
- }
+
/* GPS data? */
if (!strncmp(str->desc, "GPS", 3)) {
char *line = (char *) str->value;