From 74d84a959a430e231db95c7dae9304927360fb7f Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 19 Oct 2020 19:44:59 +0200 Subject: divecomputer: add device to provided table instead of global table In the specuial case of suunto, where we may add a device directly instead of via dive->dc, add the device to the provided table. The caller will then pass on the new device to the undo system. This makes downloading finally really undoable (at least I hope so). So far, the dives and dive sites were removed, but any new device remained. However, when setting the device-id via serial, we now have to check both, the global and the downloaded list of devices. Signed-off-by: Berthold Stoeger --- core/libdivecomputer.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'core/libdivecomputer.c') diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c index f78d23ee3..f9551decd 100644 --- a/core/libdivecomputer.c +++ b/core/libdivecomputer.c @@ -560,12 +560,15 @@ static uint32_t calculate_string_hash(const char *str) * If no existing device ID exists, create a new by hashing the serial * number string. */ -static void set_dc_serial(struct divecomputer *dc, const char *serial) +static void set_dc_serial(struct divecomputer *dc, const char *serial, const device_data_t *devdata) { const struct device *device; dc->serial = strdup(serial); - if ((device = get_device_for_dc(&device_table, dc)) != NULL) + if ((device = get_device_for_dc(&device_table, dc)) != NULL) // prefer already known ID over downloaded ID. + dc->deviceid = device_get_id(device); + + if (!dc->deviceid && (device = get_device_for_dc(devdata->devices, dc)) != NULL) dc->deviceid = device_get_id(device); if (!dc->deviceid) @@ -582,7 +585,7 @@ static void parse_string_field(device_data_t *devdata, struct dive *dive, dc_fie } add_extra_data(&dive->dc, str->desc, str->value); if (!strcmp(str->desc, "Serial")) { - set_dc_serial(&dive->dc, str->value); + set_dc_serial(&dive->dc, str->value, devdata); return; } if (!strcmp(str->desc, "FW Version")) { @@ -932,7 +935,7 @@ static unsigned int fixup_suunto_versions(device_data_t *devdata, const dc_event (devinfo->firmware >> 8) & 0xff, (devinfo->firmware >> 0) & 0xff); } - create_device_node(&device_table, devdata->model, devdata->deviceid, serial_nr, firmware, ""); + create_device_node(devdata->devices, devdata->model, devdata->deviceid, serial_nr, firmware, ""); return serial; } -- cgit v1.2.3-70-g09d2