diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-10-19 19:44:59 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-10-24 09:51:37 -0700 |
commit | 74d84a959a430e231db95c7dae9304927360fb7f (patch) | |
tree | 0a2611c2fe2d1fb04477b377150421e123135055 | |
parent | 2bcb3d88a090582d6d3dcda8810f011beb22caa6 (diff) | |
download | subsurface-74d84a959a430e231db95c7dae9304927360fb7f.tar.gz |
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 <bstoeger@mail.tuwien.ac.at>
-rw-r--r-- | core/libdivecomputer.c | 11 |
1 files changed, 7 insertions, 4 deletions
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; } |