2017-04-27 18:18:03 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2014-02-11 18:14:46 +00:00
|
|
|
#ifndef DEVICE_H
|
|
|
|
#define DEVICE_H
|
2013-01-09 20:07:09 +00:00
|
|
|
|
2019-08-05 17:41:15 +00:00
|
|
|
#include <stdint.h>
|
2024-05-04 15:55:50 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2019-08-05 17:41:15 +00:00
|
|
|
|
|
|
|
struct divecomputer;
|
2020-10-05 18:55:57 +00:00
|
|
|
struct device;
|
|
|
|
struct device_table;
|
2020-10-06 19:36:51 +00:00
|
|
|
struct dive_table;
|
2020-10-05 18:55:57 +00:00
|
|
|
|
|
|
|
// global device table
|
2021-10-30 16:54:18 +00:00
|
|
|
extern struct fingerprint_table fingerprint_table;
|
2020-10-05 18:55:57 +00:00
|
|
|
|
2024-05-18 15:03:19 +00:00
|
|
|
extern int create_device_node(struct device_table *table, const std::string &model, const std::string &serial, const std::string &nickname);
|
2020-10-05 18:55:57 +00:00
|
|
|
extern int nr_devices(const struct device_table *table);
|
|
|
|
extern const struct device *get_device(const struct device_table *table, int i);
|
2020-10-25 06:53:40 +00:00
|
|
|
extern struct device *get_device_mutable(struct device_table *table, int i);
|
2020-10-17 11:28:05 +00:00
|
|
|
extern void clear_device_table(struct device_table *table);
|
2024-05-18 15:03:19 +00:00
|
|
|
std::string get_dc_nickname(const struct divecomputer *dc);
|
2020-10-06 19:36:51 +00:00
|
|
|
extern bool device_used_by_selected_dive(const struct device *dev);
|
2020-10-05 19:12:49 +00:00
|
|
|
|
|
|
|
extern const struct device *get_device_for_dc(const struct device_table *table, const struct divecomputer *dc);
|
2021-08-17 18:05:20 +00:00
|
|
|
extern int get_or_add_device_for_dc(struct device_table *table, const struct divecomputer *dc);
|
2020-10-17 12:01:52 +00:00
|
|
|
extern bool device_exists(const struct device_table *table, const struct device *dev);
|
2020-10-21 13:25:18 +00:00
|
|
|
extern int add_to_device_table(struct device_table *table, const struct device *dev); // returns index
|
|
|
|
extern int remove_device(struct device_table *table, const struct device *dev); // returns index or -1 if not found
|
2020-10-24 20:46:36 +00:00
|
|
|
extern void remove_from_device_table(struct device_table *table, int idx);
|
2013-01-09 20:07:09 +00:00
|
|
|
|
2020-10-05 18:55:57 +00:00
|
|
|
// struct device accessors for C-code. The returned strings are not stable!
|
2024-05-18 15:03:19 +00:00
|
|
|
std::string device_get_model(const struct device *dev);
|
|
|
|
std::string device_get_serial(const struct device *dev);
|
|
|
|
std::string device_get_nickname(const struct device *dev);
|
2020-10-05 18:55:57 +00:00
|
|
|
|
2020-10-17 14:07:39 +00:00
|
|
|
// for C code that needs to alloc/free a device table. (Let's try to get rid of those)
|
|
|
|
extern struct device_table *alloc_device_table();
|
|
|
|
extern void free_device_table(struct device_table *devices);
|
|
|
|
|
2021-10-30 16:54:18 +00:00
|
|
|
// create fingerprint entry - raw data remains owned by caller
|
|
|
|
extern void create_fingerprint_node(struct fingerprint_table *table, uint32_t model, uint32_t serial,
|
|
|
|
const unsigned char *raw_data, unsigned int fsize, uint32_t fdeviceid, uint32_t fdiveid);
|
2021-10-30 20:23:47 +00:00
|
|
|
extern void create_fingerprint_node_from_hex(struct fingerprint_table *table, uint32_t model, uint32_t serial,
|
|
|
|
const char *hex_data, uint32_t fdeviceid, uint32_t fdiveid);
|
2021-10-30 16:54:18 +00:00
|
|
|
// look up the fingerprint for model/serial - returns the number of bytes in the fingerprint; memory owned by the table
|
|
|
|
extern unsigned int get_fingerprint_data(const struct fingerprint_table *table, uint32_t model, uint32_t serial, const unsigned char **fp_out);
|
|
|
|
|
2021-10-30 20:23:47 +00:00
|
|
|
// access the fingerprint data from C
|
|
|
|
extern int nr_fingerprints(struct fingerprint_table *table);
|
|
|
|
extern uint32_t fp_get_model(struct fingerprint_table *table, unsigned int i);
|
|
|
|
extern uint32_t fp_get_serial(struct fingerprint_table *table, unsigned int i);
|
|
|
|
extern uint32_t fp_get_deviceid(struct fingerprint_table *table, unsigned int i);
|
|
|
|
extern uint32_t fp_get_diveid(struct fingerprint_table *table, unsigned int i);
|
|
|
|
|
2022-03-12 09:44:37 +00:00
|
|
|
extern int is_default_dive_computer_device(const char *);
|
|
|
|
|
|
|
|
typedef void (*device_callback_t)(const char *name, void *userdata);
|
|
|
|
|
|
|
|
extern int enumerate_devices(device_callback_t callback, void *userdata, unsigned int transport);
|
|
|
|
|
2020-09-13 17:08:41 +00:00
|
|
|
// Functions and global variables that are only available to C++ code
|
2020-10-03 09:18:42 +00:00
|
|
|
struct device {
|
|
|
|
bool operator<(const device &a) const;
|
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>
2021-08-16 22:50:11 +00:00
|
|
|
void showchanges(const std::string &n) const;
|
2020-10-05 07:56:21 +00:00
|
|
|
std::string model;
|
|
|
|
std::string serialNumber;
|
|
|
|
std::string nickName;
|
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>
2021-08-16 22:50:11 +00:00
|
|
|
uint32_t deviceId; // Always the string hash of the serialNumber
|
2020-09-13 17:08:41 +00:00
|
|
|
};
|
|
|
|
|
2021-10-30 16:54:18 +00:00
|
|
|
struct fingerprint_record {
|
|
|
|
bool operator<(const fingerprint_record &a) const;
|
|
|
|
uint32_t model; // model and libdivecomputer serial number to
|
|
|
|
uint32_t serial; // look up the fingerprint
|
|
|
|
unsigned char *raw_data; // fingerprint data as provided by libdivecomputer
|
|
|
|
unsigned int fsize; // size of raw fingerprint data
|
|
|
|
unsigned int fdeviceid; // corresponding deviceid
|
|
|
|
unsigned int fdiveid; // corresponding diveid
|
|
|
|
};
|
|
|
|
|
2020-10-03 09:18:42 +00:00
|
|
|
struct device_table {
|
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>
2021-08-16 22:50:11 +00:00
|
|
|
// Keep the dive computers in a vector sorted by (model, serial)
|
2020-10-05 08:12:12 +00:00
|
|
|
std::vector<device> devices;
|
2020-09-13 17:08:41 +00:00
|
|
|
};
|
|
|
|
|
2021-10-30 16:54:18 +00:00
|
|
|
struct fingerprint_table {
|
|
|
|
// Keep the fingerprint records in a vector sorted by (model, serial) - these are uint32_t here
|
|
|
|
std::vector<fingerprint_record> fingerprints;
|
|
|
|
};
|
|
|
|
|
2024-02-29 07:23:55 +00:00
|
|
|
std::string fp_get_data(struct fingerprint_table *table, unsigned int i);
|
|
|
|
|
2014-02-11 18:14:46 +00:00
|
|
|
#endif // DEVICE_H
|