mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Assemble the actual Suunto serial number
It turns out that the serial number returned by libdivecomputer isn't really the serial number as interpreted by the vendor. Those tend to be strings, but libdivecomputer gives us a 32bit number. Some experimenting showed that for the Suunto devies tested the serial number is encoded in that 32bit number: It so happens that the Suunto serial number strings are strings that have all numbers, but they aren't *one* number. They are four bytes representing two numbers each, and the "23500027" string is actually the four bytes 23 50 00 27 (0x17 0x32 0x00 0x1b). And libdivecomputer has incorrectly parsed those four bytes as one number, not as the encoded serial number string it is. So the value 389152795 is actually hex 0x1732001b, which is 0x17 0x32 0x00 0x1b, which is - 23 50 00 27. This should be done by libdivecomputer, but hey, in the meantime this at least shows the concept. And helps test the XML save/restore code. It depends on the two patches that create the whole "device.c" infrastructure, of course. With this, my dive file ends up having the settings section look like this: <divecomputerid model='Suunto Vyper Air' deviceid='d4629110' serial='01201094' firmware='1.1.22'/> <divecomputerid model='Suunto HelO2' deviceid='995dd566' serial='23500027' firmware='1.0.4'/> where the format of the firmware version is something I guessed at, but it was the obvious choice (again, it's byte-based, I'm ignoring the high byte that is zero for both of my Suuntos). Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
ec38d3708d
commit
1aa3c0d514
5 changed files with 93 additions and 11 deletions
37
save-xml.c
37
save-xml.c
|
@ -485,23 +485,42 @@ static void save_trip(FILE *f, dive_trip_t *trip)
|
|||
|
||||
static void save_dc_if_needed(FILE *f, struct divecomputer *dc)
|
||||
{
|
||||
const char *nickname;
|
||||
struct device_info *info = get_device_info(dc->model, dc->deviceid);
|
||||
const char *nickname, *serial_nr, *firmware;
|
||||
|
||||
/* we have no dc or no model or no deviceid information... nothing to do here */
|
||||
if (!dc || !dc->model || !*dc->model || !dc->deviceid)
|
||||
if (!info || info->saved)
|
||||
return;
|
||||
info->saved = 1;
|
||||
|
||||
if (dc_was_saved(dc))
|
||||
return;
|
||||
/* Nicknames that are empty or the same as the device model are not interesting */
|
||||
nickname = info->nickname;
|
||||
if (nickname) {
|
||||
if (!*nickname || !strcmp(dc->model, nickname))
|
||||
nickname = NULL;
|
||||
}
|
||||
|
||||
mark_dc_saved(dc);
|
||||
nickname = get_dc_nickname(dc->model, dc->deviceid);
|
||||
/* We have no nickname, or it is the same as the model ID - nothing interesting */
|
||||
if (!nickname || !*nickname || !strcmp(dc->model, nickname))
|
||||
/* Serial numbers that are empty are not interesting */
|
||||
serial_nr = info->serial_nr;
|
||||
if (serial_nr && !*serial_nr)
|
||||
serial_nr = NULL;
|
||||
|
||||
/* Firmware strings that are empty are not interesting */
|
||||
firmware = info->firmware;
|
||||
if (firmware && !*firmware)
|
||||
firmware = NULL;
|
||||
|
||||
/* Do we have anything interesting about this dive computer to save? */
|
||||
if (!serial_nr && !nickname && !firmware)
|
||||
return;
|
||||
|
||||
fprintf(f, "<divecomputerid model='%s' deviceid='%08x'", dc->model, dc->deviceid);
|
||||
show_utf8(f, nickname, " nickname='", "'", 1);
|
||||
if (serial_nr)
|
||||
show_utf8(f, serial_nr, " serial='", "'", 1);
|
||||
if (firmware)
|
||||
show_utf8(f, firmware, " firmware='", "'", 1);
|
||||
if (nickname)
|
||||
show_utf8(f, nickname, " nickname='", "'", 1);
|
||||
fprintf(f, "/>\n");
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue