diff --git a/src/cressi_edy.c b/src/cressi_edy.c index 89c4b48..e23eee7 100644 --- a/src/cressi_edy.c +++ b/src/cressi_edy.c @@ -379,6 +379,13 @@ cressi_edy_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) return DC_STATUS_NOMEMORY; } + // Emit a device info event. + dc_event_devinfo_t devinfo; + devinfo.model = device->model; + devinfo.firmware = 0; + devinfo.serial = 0; + device_event_emit (abstract, DC_EVENT_DEVINFO, &devinfo); + return device_dump_read (abstract, dc_buffer_get_data (buffer), dc_buffer_get_size (buffer), SZ_PACKET); } diff --git a/src/cressi_leonardo.c b/src/cressi_leonardo.c index 244b887..f331537 100644 --- a/src/cressi_leonardo.c +++ b/src/cressi_leonardo.c @@ -378,6 +378,13 @@ cressi_leonardo_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) return DC_STATUS_PROTOCOL; } + // Emit a device info event. + dc_event_devinfo_t devinfo; + devinfo.model = data[0]; + devinfo.firmware = 0; + devinfo.serial = array_uint24_le (data + 1); + device_event_emit (abstract, DC_EVENT_DEVINFO, &devinfo); + return DC_STATUS_SUCCESS; } @@ -394,13 +401,6 @@ cressi_leonardo_device_foreach (dc_device_t *abstract, dc_dive_callback_t callba return rc; } - unsigned char *data = dc_buffer_get_data (buffer); - dc_event_devinfo_t devinfo; - devinfo.model = data[0]; - devinfo.firmware = 0; - devinfo.serial = array_uint24_le (data + 1); - device_event_emit (abstract, DC_EVENT_DEVINFO, &devinfo); - rc = cressi_leonardo_extract_dives (abstract, dc_buffer_get_data (buffer), dc_buffer_get_size (buffer), callback, userdata); diff --git a/src/hw_ostc.c b/src/hw_ostc.c index cb64818..cbb97bb 100644 --- a/src/hw_ostc.c +++ b/src/hw_ostc.c @@ -274,6 +274,20 @@ hw_ostc_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) nbytes += len; } + // Emit a device info event. + dc_event_devinfo_t devinfo; + devinfo.firmware = array_uint16_be (data + 264); + devinfo.serial = array_uint16_le (data + 6); + if (devinfo.serial > 7000) + devinfo.model = 3; // OSTC 2C + else if (devinfo.serial > 2048) + devinfo.model = 2; // OSTC 2N + else if (devinfo.serial > 300) + devinfo.model = 1; // OSTC Mk2 + else + devinfo.model = 0; // OSTC + device_event_emit (abstract, DC_EVENT_DEVINFO, &devinfo); + return DC_STATUS_SUCCESS; } @@ -291,21 +305,6 @@ hw_ostc_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void return rc; } - // Emit a device info event. - unsigned char *data = dc_buffer_get_data (buffer); - dc_event_devinfo_t devinfo; - devinfo.firmware = array_uint16_be (data + 264); - devinfo.serial = array_uint16_le (data + 6); - if (devinfo.serial > 7000) - devinfo.model = 3; // OSTC 2C - else if (devinfo.serial > 2048) - devinfo.model = 2; // OSTC 2N - else if (devinfo.serial > 300) - devinfo.model = 1; // OSTC Mk2 - else - devinfo.model = 0; // OSTC - device_event_emit (abstract, DC_EVENT_DEVINFO, &devinfo); - rc = hw_ostc_extract_dives (abstract, dc_buffer_get_data (buffer), dc_buffer_get_size (buffer), callback, userdata); diff --git a/src/hw_ostc3.c b/src/hw_ostc3.c index 550662f..e8dc223 100644 --- a/src/hw_ostc3.c +++ b/src/hw_ostc3.c @@ -1662,6 +1662,21 @@ hw_ostc3_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) return rc; } + // Emit a device info event. + dc_event_devinfo_t devinfo; + devinfo.firmware = device->firmware; + devinfo.serial = device->serial; + if (device->hardware != UNKNOWN) { + devinfo.model = device->hardware; + } else { + // Fallback to the serial number. + if (devinfo.serial > 10000) + devinfo.model = SPORT; + else + devinfo.model = OSTC3; + } + device_event_emit (abstract, DC_EVENT_DEVINFO, &devinfo); + // Allocate the required amount of memory. if (!dc_buffer_resize (buffer, SZ_MEMORY)) { ERROR (abstract->context, "Insufficient buffer space available."); diff --git a/src/liquivision_lynx.c b/src/liquivision_lynx.c index b461248..56abb37 100644 --- a/src/liquivision_lynx.c +++ b/src/liquivision_lynx.c @@ -366,12 +366,22 @@ liquivision_lynx_device_read (dc_device_t *abstract, unsigned int address, unsig static dc_status_t liquivision_lynx_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) { + liquivision_lynx_device_t *device = (liquivision_lynx_device_t *) abstract; + + // Emit a device info event. + dc_event_devinfo_t devinfo; + devinfo.model = array_uint16_le (device->info + 0); + devinfo.firmware = 0; + devinfo.serial = array_uint32_le (device->more + 0); + device_event_emit (abstract, DC_EVENT_DEVINFO, &devinfo); + // Allocate the required amount of memory. if (!dc_buffer_resize (buffer, MEMSIZE)) { ERROR (abstract->context, "Insufficient buffer space available."); return DC_STATUS_NOMEMORY; } + // Download the memory dump. return device_dump_read (abstract, dc_buffer_get_data (buffer), dc_buffer_get_size (buffer), SEGMENTSIZE); } diff --git a/src/mares_darwin.c b/src/mares_darwin.c index 92172f2..cefa717 100644 --- a/src/mares_darwin.c +++ b/src/mares_darwin.c @@ -189,6 +189,7 @@ mares_darwin_device_set_fingerprint (dc_device_t *abstract, const unsigned char static dc_status_t mares_darwin_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) { + dc_status_t status = DC_STATUS_SUCCESS; mares_darwin_device_t *device = (mares_darwin_device_t *) abstract; assert (device->layout != NULL); @@ -199,8 +200,22 @@ mares_darwin_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) return DC_STATUS_NOMEMORY; } - return device_dump_read (abstract, dc_buffer_get_data (buffer), + // Download the memory dump. + status = device_dump_read (abstract, dc_buffer_get_data (buffer), dc_buffer_get_size (buffer), PACKETSIZE); + if (status != DC_STATUS_SUCCESS) { + return status; + } + + // Emit a device info event. + unsigned char *data = dc_buffer_get_data (buffer); + dc_event_devinfo_t devinfo; + devinfo.model = device->model; + devinfo.firmware = 0; + devinfo.serial = array_uint16_be (data + 8); + device_event_emit (abstract, DC_EVENT_DEVINFO, &devinfo); + + return status; } @@ -221,14 +236,6 @@ mares_darwin_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, return rc; } - // Emit a device info event. - unsigned char *data = dc_buffer_get_data (buffer); - dc_event_devinfo_t devinfo; - devinfo.model = device->model; - devinfo.firmware = 0; - devinfo.serial = array_uint16_be (data + 8); - device_event_emit (abstract, DC_EVENT_DEVINFO, &devinfo); - rc = mares_darwin_extract_dives (abstract, dc_buffer_get_data (buffer), dc_buffer_get_size (buffer), callback, userdata); diff --git a/src/mares_iconhd.c b/src/mares_iconhd.c index 21f88fa..0c39b86 100644 --- a/src/mares_iconhd.c +++ b/src/mares_iconhd.c @@ -650,6 +650,7 @@ mares_iconhd_device_read (dc_device_t *abstract, unsigned int address, unsigned static dc_status_t mares_iconhd_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) { + dc_status_t status = DC_STATUS_SUCCESS; mares_iconhd_device_t *device = (mares_iconhd_device_t *) abstract; // Allocate the required amount of memory. @@ -664,8 +665,22 @@ mares_iconhd_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) vendor.size = sizeof (device->version); device_event_emit (abstract, DC_EVENT_VENDOR, &vendor); - return device_dump_read (abstract, dc_buffer_get_data (buffer), + // Download the memory dump. + status = device_dump_read (abstract, dc_buffer_get_data (buffer), dc_buffer_get_size (buffer), device->packetsize); + if (status != DC_STATUS_SUCCESS) { + return status; + } + + // Emit a device info event. + unsigned char *data = dc_buffer_get_data (buffer); + dc_event_devinfo_t devinfo; + devinfo.model = device->model; + devinfo.firmware = 0; + devinfo.serial = array_uint32_le (data + 0x0C); + device_event_emit (abstract, DC_EVENT_DEVINFO, &devinfo); + + return status; } static dc_status_t diff --git a/src/mares_nemo.c b/src/mares_nemo.c index f5e22a3..4b6929b 100644 --- a/src/mares_nemo.c +++ b/src/mares_nemo.c @@ -245,6 +245,14 @@ mares_nemo_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) nbytes += PACKETSIZE; } + // Emit a device info event. + unsigned char *data = dc_buffer_get_data (buffer); + dc_event_devinfo_t devinfo; + devinfo.model = data[1]; + devinfo.firmware = 0; + devinfo.serial = array_uint16_be (data + 8); + device_event_emit (abstract, DC_EVENT_DEVINFO, &devinfo); + return DC_STATUS_SUCCESS; } @@ -264,13 +272,7 @@ mares_nemo_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, v return rc; } - // Emit a device info event. unsigned char *data = dc_buffer_get_data (buffer); - dc_event_devinfo_t devinfo; - devinfo.model = data[1]; - devinfo.firmware = 0; - devinfo.serial = array_uint16_be (data + 8); - device_event_emit (abstract, DC_EVENT_DEVINFO, &devinfo); const mares_common_layout_t *layout = NULL; switch (data[1]) { diff --git a/src/mares_puck.c b/src/mares_puck.c index 614d886..aaf1c41 100644 --- a/src/mares_puck.c +++ b/src/mares_puck.c @@ -192,6 +192,7 @@ mares_puck_device_set_fingerprint (dc_device_t *abstract, const unsigned char da static dc_status_t mares_puck_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) { + dc_status_t status = DC_STATUS_SUCCESS; mares_puck_device_t *device = (mares_puck_device_t *) abstract; assert (device->layout != NULL); @@ -202,8 +203,22 @@ mares_puck_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) return DC_STATUS_NOMEMORY; } - return device_dump_read (abstract, dc_buffer_get_data (buffer), + // Download the memory dump. + status = device_dump_read (abstract, dc_buffer_get_data (buffer), dc_buffer_get_size (buffer), PACKETSIZE); + if (status != DC_STATUS_SUCCESS) { + return status; + } + + // Emit a device info event. + unsigned char *data = dc_buffer_get_data (buffer); + dc_event_devinfo_t devinfo; + devinfo.model = data[1]; + devinfo.firmware = 0; + devinfo.serial = array_uint16_be (data + 8); + device_event_emit (abstract, DC_EVENT_DEVINFO, &devinfo); + + return status; } @@ -224,15 +239,8 @@ mares_puck_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, v return rc; } - // Emit a device info event. - unsigned char *data = dc_buffer_get_data (buffer); - dc_event_devinfo_t devinfo; - devinfo.model = data[1]; - devinfo.firmware = 0; - devinfo.serial = array_uint16_be (data + 8); - device_event_emit (abstract, DC_EVENT_DEVINFO, &devinfo); - - rc = mares_common_extract_dives (abstract->context, device->layout, device->fingerprint, data, callback, userdata); + rc = mares_common_extract_dives (abstract->context, device->layout, device->fingerprint, + dc_buffer_get_data (buffer), callback, userdata); dc_buffer_free (buffer); diff --git a/src/oceanic_common.c b/src/oceanic_common.c index 77f4dc7..d2a4818 100644 --- a/src/oceanic_common.c +++ b/src/oceanic_common.c @@ -188,13 +188,16 @@ oceanic_common_device_set_fingerprint (dc_device_t *abstract, const unsigned cha dc_status_t oceanic_common_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) { + dc_status_t status = DC_STATUS_SUCCESS; oceanic_common_device_t *device = (oceanic_common_device_t *) abstract; assert (device != NULL); assert (device->layout != NULL); + const oceanic_common_layout_t *layout = device->layout; + // Allocate the required amount of memory. - if (!dc_buffer_resize (buffer, device->layout->memsize)) { + if (!dc_buffer_resize (buffer, layout->memsize)) { ERROR (abstract->context, "Insufficient buffer space available."); return DC_STATUS_NOMEMORY; } @@ -205,8 +208,30 @@ oceanic_common_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) vendor.size = sizeof (device->version); device_event_emit (abstract, DC_EVENT_VENDOR, &vendor); - return device_dump_read (abstract, dc_buffer_get_data (buffer), + // Download the memory dump. + status = device_dump_read (abstract, dc_buffer_get_data (buffer), dc_buffer_get_size (buffer), PAGESIZE * device->multipage); + if (status != DC_STATUS_SUCCESS) { + return status; + } + + // Emit a device info event. + unsigned char *id = dc_buffer_get_data (buffer) + layout->cf_devinfo; + dc_event_devinfo_t devinfo; + devinfo.model = array_uint16_be (id + 8); + devinfo.firmware = device->firmware; + if (layout->pt_mode_serial == 0) + devinfo.serial = array_convert_bcd2dec (id + 10, 3); + else if (layout->pt_mode_serial == 1) + devinfo.serial = array_convert_bin2dec (id + 11, 3); + else + devinfo.serial = + (id[11] & 0x0F) * 100000 + ((id[11] & 0xF0) >> 4) * 10000 + + (id[12] & 0x0F) * 1000 + ((id[12] & 0xF0) >> 4) * 100 + + (id[13] & 0x0F) * 10 + ((id[13] & 0xF0) >> 4) * 1; + device_event_emit (abstract, DC_EVENT_DEVINFO, &devinfo); + + return status; } diff --git a/src/shearwater_predator.c b/src/shearwater_predator.c index e861c37..d4c97b4 100644 --- a/src/shearwater_predator.c +++ b/src/shearwater_predator.c @@ -115,6 +115,7 @@ shearwater_predator_device_set_fingerprint (dc_device_t *abstract, const unsigne static dc_status_t shearwater_predator_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) { + dc_status_t status = DC_STATUS_SUCCESS; shearwater_common_device_t *device = (shearwater_common_device_t *) abstract; // Pre-allocate the required amount of memory. @@ -128,7 +129,21 @@ shearwater_predator_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) progress.current = 0; progress.maximum = NSTEPS; - return shearwater_common_download (device, buffer, 0xDD000000, SZ_MEMORY, 0, &progress); + // Download the memory dump. + status = shearwater_common_download (device, buffer, 0xDD000000, SZ_MEMORY, 0, &progress); + if (status != DC_STATUS_SUCCESS) { + return status; + } + + // Emit a device info event. + unsigned char *data = dc_buffer_get_data (buffer); + dc_event_devinfo_t devinfo; + devinfo.model = data[0x2000D]; + devinfo.firmware = bcd2dec (data[0x2000A]); + devinfo.serial = array_uint32_be (data + 0x20002); + device_event_emit (abstract, DC_EVENT_DEVINFO, &devinfo); + + return status; } @@ -145,15 +160,8 @@ shearwater_predator_device_foreach (dc_device_t *abstract, dc_dive_callback_t ca return rc; } - // Emit a device info event. - unsigned char *data = dc_buffer_get_data (buffer); - dc_event_devinfo_t devinfo; - devinfo.model = data[0x2000D]; - devinfo.firmware = bcd2dec (data[0x2000A]); - devinfo.serial = array_uint32_be (data + 0x20002); - device_event_emit (abstract, DC_EVENT_DEVINFO, &devinfo); - - rc = shearwater_predator_extract_dives (abstract, data, SZ_MEMORY, callback, userdata); + rc = shearwater_predator_extract_dives (abstract, dc_buffer_get_data (buffer), + dc_buffer_get_size (buffer), callback, userdata); dc_buffer_free (buffer); diff --git a/src/suunto_eon.c b/src/suunto_eon.c index cc0ea5d..a7f09dd 100644 --- a/src/suunto_eon.c +++ b/src/suunto_eon.c @@ -181,6 +181,13 @@ suunto_eon_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) dc_buffer_append (buffer, answer, SZ_MEMORY); + // Emit a device info event. + dc_event_devinfo_t devinfo; + devinfo.model = 0; + devinfo.firmware = 0; + devinfo.serial = array_convert_bcd2dec (answer + 244, 3); + device_event_emit (abstract, DC_EVENT_DEVINFO, &devinfo); + return DC_STATUS_SUCCESS; } @@ -200,15 +207,8 @@ suunto_eon_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, v return rc; } - // Emit a device info event. - unsigned char *data = dc_buffer_get_data (buffer); - dc_event_devinfo_t devinfo; - devinfo.model = 0; - devinfo.firmware = 0; - devinfo.serial = array_convert_bcd2dec (data + 244, 3); - device_event_emit (abstract, DC_EVENT_DEVINFO, &devinfo); - - rc = suunto_common_extract_dives (device, &suunto_eon_layout, data, callback, userdata); + rc = suunto_common_extract_dives (device, &suunto_eon_layout, dc_buffer_get_data (buffer), + callback, userdata); dc_buffer_free (buffer); diff --git a/src/suunto_solution.c b/src/suunto_solution.c index 99ac331..e72fe94 100644 --- a/src/suunto_solution.c +++ b/src/suunto_solution.c @@ -221,6 +221,13 @@ suunto_solution_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) progress.current += 1; device_event_emit (abstract, DC_EVENT_PROGRESS, &progress); + // Emit a device info event. + dc_event_devinfo_t devinfo; + devinfo.model = 0; + devinfo.firmware = 0; + devinfo.serial = array_convert_bcd2dec (data + 0x1D, 3); + device_event_emit (abstract, DC_EVENT_DEVINFO, &devinfo); + return DC_STATUS_SUCCESS; } @@ -238,14 +245,6 @@ suunto_solution_device_foreach (dc_device_t *abstract, dc_dive_callback_t callba return rc; } - // Emit a device info event. - unsigned char *data = dc_buffer_get_data (buffer); - dc_event_devinfo_t devinfo; - devinfo.model = 0; - devinfo.firmware = 0; - devinfo.serial = array_convert_bcd2dec (data + 0x1D, 3); - device_event_emit (abstract, DC_EVENT_DEVINFO, &devinfo); - rc = suunto_solution_extract_dives (abstract, dc_buffer_get_data (buffer), dc_buffer_get_size (buffer), callback, userdata); diff --git a/src/suunto_vyper.c b/src/suunto_vyper.c index 8465b9c..02bd42f 100644 --- a/src/suunto_vyper.c +++ b/src/suunto_vyper.c @@ -426,14 +426,39 @@ suunto_vyper_read_dive (dc_device_t *abstract, dc_buffer_t *buffer, int init, dc static dc_status_t suunto_vyper_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) { + dc_status_t status = DC_STATUS_SUCCESS; + // Allocate the required amount of memory. if (!dc_buffer_resize (buffer, SZ_MEMORY)) { ERROR (abstract->context, "Insufficient buffer space available."); return DC_STATUS_NOMEMORY; } - return device_dump_read (abstract, dc_buffer_get_data (buffer), + // Download the memory dump. + status = device_dump_read (abstract, dc_buffer_get_data (buffer), dc_buffer_get_size (buffer), SZ_PACKET); + if (status != DC_STATUS_SUCCESS) { + return status; + } + + // Identify the connected device as a Vyper or a Spyder, by inspecting + // the Vyper model code. For a Spyder, this value will contain the + // sample interval (20, 30 or 60s) instead of the model code. + unsigned char *data = dc_buffer_get_data (buffer); + unsigned int hoffset = HDR_DEVINFO_VYPER; + if (data[hoffset] == 20 || data[hoffset] == 30 || data[hoffset] == 60) { + hoffset = HDR_DEVINFO_SPYDER; + } + + // Emit a device info event. + dc_event_devinfo_t devinfo; + devinfo.model = data[hoffset + 0]; + devinfo.firmware = data[hoffset + 1]; + devinfo.serial = 0; + devinfo.serial = array_convert_bin2dec (data + hoffset + 2, 4); + device_event_emit (abstract, DC_EVENT_DEVINFO, &devinfo); + + return status; }