From 3dcf93e26e349d01f518871f3a394cf7e30da7be Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Mon, 12 Feb 2018 12:07:33 +0100 Subject: [PATCH] Add BLE support for the Scubapro G2 devices The main difference with the USB HID communication is that the BLE data packets have a variable size and are no longer padded to the full 32 (Tx) or 64 (Rx) bytes. --- src/descriptor.c | 4 ++-- src/uwatec_g2.c | 23 ++++++++++++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/descriptor.c b/src/descriptor.c index 4ba943e..b756cf3 100644 --- a/src/descriptor.c +++ b/src/descriptor.c @@ -135,9 +135,9 @@ static const dc_descriptor_t g_descriptors[] = { {"Scubapro", "Chromis", DC_FAMILY_UWATEC_MERIDIAN, 0x24, DC_TRANSPORT_SERIAL, NULL}, {"Scubapro", "Mantis 2", DC_FAMILY_UWATEC_MERIDIAN, 0x26, DC_TRANSPORT_SERIAL, NULL}, /* Scubapro G2 */ - {"Scubapro", "Aladin Sport Matrix", DC_FAMILY_UWATEC_G2, 0x17, DC_TRANSPORT_NONE, dc_filter_uwatec}, + {"Scubapro", "Aladin Sport Matrix", DC_FAMILY_UWATEC_G2, 0x17, DC_TRANSPORT_BLE, dc_filter_uwatec}, {"Scubapro", "Aladin Square", DC_FAMILY_UWATEC_G2, 0x22, DC_TRANSPORT_USBHID, dc_filter_uwatec}, - {"Scubapro", "G2", DC_FAMILY_UWATEC_G2, 0x32, DC_TRANSPORT_USBHID, dc_filter_uwatec}, + {"Scubapro", "G2", DC_FAMILY_UWATEC_G2, 0x32, DC_TRANSPORT_USBHID | DC_TRANSPORT_BLE, dc_filter_uwatec}, /* Reefnet */ {"Reefnet", "Sensus", DC_FAMILY_REEFNET_SENSUS, 1, DC_TRANSPORT_SERIAL, NULL}, {"Reefnet", "Sensus Pro", DC_FAMILY_REEFNET_SENSUSPRO, 2, DC_TRANSPORT_SERIAL, NULL}, diff --git a/src/uwatec_g2.c b/src/uwatec_g2.c index ea2d324..798cc9a 100644 --- a/src/uwatec_g2.c +++ b/src/uwatec_g2.c @@ -74,21 +74,25 @@ receive_data (uwatec_g2_device_t *device, dc_event_progress_t *progress, unsigne rc = dc_iostream_read (device->iostream, buf, sizeof(buf), &transferred); if (rc != DC_STATUS_SUCCESS) { - ERROR (device->base.context, "read interrupt transfer failed"); + ERROR (device->base.context, "Failed to receive the packet."); return rc; } - if (transferred != sizeof(buf)) { - ERROR (device->base.context, "incomplete read interrupt transfer (got " DC_PRINTF_SIZE ", expected " DC_PRINTF_SIZE ")", transferred, sizeof(buf)); + + if (transferred < 1) { + ERROR (device->base.context, "Invalid packet length (" DC_PRINTF_SIZE ").", transferred); return DC_STATUS_PROTOCOL; } + len = buf[0]; - if (len >= sizeof(buf)) { - ERROR (device->base.context, "read interrupt transfer returns impossible packet size (%d)", len); + if (len + 1 > transferred) { + ERROR (device->base.context, "Invalid payload length (%u).", len); return DC_STATUS_PROTOCOL; } + HEXDUMP (device->base.context, DC_LOGLEVEL_DEBUG, "rcv", buf + 1, len); + if (len > size) { - ERROR (device->base.context, "receive result buffer too small"); + ERROR (device->base.context, "Insufficient buffer space available."); return DC_STATUS_PROTOCOL; } @@ -124,7 +128,12 @@ uwatec_g2_transfer (uwatec_g2_device_t *device, const unsigned char command[], u buf[1] = csize; memcpy(buf + 2, command, csize); memset(buf + 2 + csize, 0, sizeof(buf) - (csize + 2)); - status = dc_iostream_write (device->iostream, buf, sizeof(buf), &transferred); + + if (dc_iostream_get_transport(device->iostream) == DC_TRANSPORT_BLE) { + status = dc_iostream_write(device->iostream, buf + 1, csize + 1, &transferred); + } else { + status = dc_iostream_write(device->iostream, buf, sizeof(buf), &transferred); + } if (status != DC_STATUS_SUCCESS) { ERROR (device->base.context, "Failed to send the command."); return status;