aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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;