Add the devinfo event.

The devinfo event with the device serial number is required for the
fingerprint feature. Without this event, applications won't be able to
load (or save) the correct fingerprint. All necessary information is
already available in the initial handshake packet.
This commit is contained in:
Jef Driesen 2016-04-24 19:14:52 +02:00
parent 76c52b582a
commit d40cdb4755
3 changed files with 27 additions and 1 deletions

View File

@ -146,6 +146,20 @@ array_convert_hex2bin (const unsigned char input[], unsigned int isize, unsigned
return 0;
}
unsigned int
array_convert_str2num (const unsigned char data[], unsigned int size)
{
unsigned int value = 0;
for (unsigned int i = 0; i < size; ++i) {
if (data[i] < '0' || data[i] > '9')
break;
value *= 10;
value += data[i] - '0';
}
return value;
}
unsigned int
array_uint_be (const unsigned char data[], unsigned int n)
{

View File

@ -49,6 +49,9 @@ array_convert_bin2hex (const unsigned char input[], unsigned int isize, unsigned
int
array_convert_hex2bin (const unsigned char input[], unsigned int isize, unsigned char output[], unsigned int osize);
unsigned int
array_convert_str2num (const unsigned char data[], unsigned int size);
unsigned int
array_uint_be (const unsigned char data[], unsigned int n);

View File

@ -52,6 +52,7 @@ typedef struct suunto_eonsteel_device_t {
libusb_device_handle *handle;
unsigned int magic;
unsigned short seq;
unsigned char version[0x30];
unsigned char fingerprint[4];
} suunto_eonsteel_device_t;
@ -544,7 +545,7 @@ static int initialize_eonsteel(suunto_eonsteel_device_t *eon)
ERROR(eon->base.context, "Failed to send initialization command");
return -1;
}
if (receive_header(eon, &hdr, buf, sizeof(buf)) < 0) {
if (receive_header(eon, &hdr, eon->version, sizeof(eon->version)) < 0) {
ERROR(eon->base.context, "Failed to receive initial reply");
return -1;
}
@ -572,6 +573,7 @@ suunto_eonsteel_device_open(dc_device_t **out, dc_context_t *context, const char
// Set up the magic handshake fields
eon->magic = INIT_MAGIC;
eon->seq = INIT_SEQ;
memset (eon->version, 0, sizeof (eon->version));
memset (eon->fingerprint, 0, sizeof (eon->fingerprint));
if (libusb_init(&eon->ctx)) {
@ -652,6 +654,13 @@ suunto_eonsteel_device_foreach(dc_device_t *abstract, dc_dive_callback_t callbac
if (get_file_list(eon, &de) < 0)
return DC_STATUS_IO;
// Emit a device info event.
dc_event_devinfo_t devinfo;
devinfo.model = 0;
devinfo.firmware = array_uint32_be (eon->version + 0x20);
devinfo.serial = array_convert_str2num(eon->version + 0x10, 16);
device_event_emit (abstract, DC_EVENT_DEVINFO, &devinfo);
file = dc_buffer_new(0);
progress.maximum = count_dir_entries(de);
progress.current = 0;