diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2021-08-16 12:50:11 -1000 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2021-08-18 13:22:02 -0700 |
commit | 6c4e890960036b127eab513ca967e9454bc63d54 (patch) | |
tree | 48295d3854ba576f5d9c4cd2e6297d96bbaae66d /core/divelist.c | |
parent | 61524f9b2ddfda16688890d1a9cf05d050174a9b (diff) | |
download | subsurface-6c4e890960036b127eab513ca967e9454bc63d54.tar.gz |
Clean up divecomputer 'device' handling
We have this odd legacy notion of a divecomputer 'device', that was
originally just basically the libdivecomputer 'EVENT_DEVINFO' report
that was associated with each dive. So it had firmware version,
deviceid, and serial number.
It had also gotten extended to do 'nickname' handling, and it was all
confusing, ugly and bad. It was particularly bad because it wasn't
actually a 'per device' thing at all: due to the firmware field, a dive
computer that got a firmware update forced a new 'device'.
To make matters worse, the 'deviceid' was also almost random, because
we've calculated it a couple of different ways, and libdivecomputer
itself has changed how the legacy 32-bit 'serial number' is expressed.
Finally, because of all these issues, we didn't even try to make the
thing unique, so it really ended up being a random snapshot of the state
of the dive computer at the time of a dive, and sometimes we'd pick one,
and sometimes another, since they weren't really well-defined.
So get rid of all this confusion.
The new rules:
- the actual random dive computer state at the time of a dive is kept
in the dive data. So if you want to know the firmware version, it
should be in the 'extra data'
- the only serial number that matters is the string one in the extra
data, because that's the one that actually matches what the dive
computer reports, and isn't some random 32-bit integer with ambiguous
formatting.
- the 'device id' - the thing we match with (together with the model
name, eg "Suunto EON Steel") is purely a hash of the real serial
number.
The device ID that libdivecomputer reports in EVENT_DEVINFO is
ignored, as is the device ID we've saved in the XML or git files. If
we have a serial number, the device ID will be uniquely associated
with that serial number, and if we don't have one, the device ID will
be zero (for 'match anything').
So now 'deviceid' is literally just a shorthand for the serial number
string, and the two are joined at the hip.
- the 'device' managament is _only_ used to track devices that have
serial numbers _and_ nicknames. So no more different device
structures just because one had a nickname and the other didn't etc.
Without a serial number, the device is 'anonymous' and fundamentally
cannot be distinguished from other devices of the same model, so a
nickname is meaningless. And without a nickname, there is no point in
creating a device data structure, since all the data is in the dive
itself and the device structure wouldn't add any value..
These rules mean that we no longer have ambiguous 'device' structures,
and we can never have duplicates that can confuse us.
This does mean that you can't give a nickname to a device that cannot be
uniquely identified with a serial number, but those are happily fairly
rare (and mostly older ones). Dirk said he'd look at what it takes to
give more dive computers proper serial numbers, and I already did it for
the Garmin Descent family yesterday.
(Honesty in advertizing: right now you can't add a nickname to a dive
computer that doesn't already have one, because such a dive computer
will not have a device structure. But that's a UI issue, and I'll sort
that out separately)
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'core/divelist.c')
-rw-r--r-- | core/divelist.c | 18 |
1 files changed, 0 insertions, 18 deletions
diff --git a/core/divelist.c b/core/divelist.c index a1420e407..9beea4d7c 100644 --- a/core/divelist.c +++ b/core/divelist.c @@ -807,13 +807,6 @@ void delete_single_dive(int idx) void process_loaded_dives() { - int i; - struct dive *dive; - - /* Register dive computer nick names. */ - for_each_dive(i, dive) - add_devices_of_dive(dive, &device_table); - sort_dive_table(&dive_table); sort_trip_table(&trip_table); @@ -1172,17 +1165,6 @@ void process_imported_dives(struct dive_table *import_table, struct trip_table * add_to_device_table(devices_to_add, dev); } - /* check if we need a nickname for the divecomputer for newly downloaded dives; - * since we know they all came from the same divecomputer we just check for the - * first one */ - if (flags & IMPORT_IS_DOWNLOADED) { - add_devices_of_dive(import_table->dives[0], devices_to_add); - } else { - /* they aren't downloaded, so record / check all new ones */ - for (i = 0; i < import_table->nr; i++) - add_devices_of_dive(import_table->dives[i], devices_to_add); - } - /* Sort the table of dives to be imported and combine mergable dives */ sort_dive_table(import_table); merge_imported_dives(import_table); |