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.
This commit is contained in:
parent
afff8b450f
commit
3dcf93e26e
@ -135,9 +135,9 @@ static const dc_descriptor_t g_descriptors[] = {
|
|||||||
{"Scubapro", "Chromis", DC_FAMILY_UWATEC_MERIDIAN, 0x24, DC_TRANSPORT_SERIAL, NULL},
|
{"Scubapro", "Chromis", DC_FAMILY_UWATEC_MERIDIAN, 0x24, DC_TRANSPORT_SERIAL, NULL},
|
||||||
{"Scubapro", "Mantis 2", DC_FAMILY_UWATEC_MERIDIAN, 0x26, DC_TRANSPORT_SERIAL, NULL},
|
{"Scubapro", "Mantis 2", DC_FAMILY_UWATEC_MERIDIAN, 0x26, DC_TRANSPORT_SERIAL, NULL},
|
||||||
/* Scubapro G2 */
|
/* 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", "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 */
|
||||||
{"Reefnet", "Sensus", DC_FAMILY_REEFNET_SENSUS, 1, DC_TRANSPORT_SERIAL, NULL},
|
{"Reefnet", "Sensus", DC_FAMILY_REEFNET_SENSUS, 1, DC_TRANSPORT_SERIAL, NULL},
|
||||||
{"Reefnet", "Sensus Pro", DC_FAMILY_REEFNET_SENSUSPRO, 2, DC_TRANSPORT_SERIAL, NULL},
|
{"Reefnet", "Sensus Pro", DC_FAMILY_REEFNET_SENSUSPRO, 2, DC_TRANSPORT_SERIAL, NULL},
|
||||||
|
|||||||
@ -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);
|
rc = dc_iostream_read (device->iostream, buf, sizeof(buf), &transferred);
|
||||||
if (rc != DC_STATUS_SUCCESS) {
|
if (rc != DC_STATUS_SUCCESS) {
|
||||||
ERROR (device->base.context, "read interrupt transfer failed");
|
ERROR (device->base.context, "Failed to receive the packet.");
|
||||||
return rc;
|
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;
|
return DC_STATUS_PROTOCOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = buf[0];
|
len = buf[0];
|
||||||
if (len >= sizeof(buf)) {
|
if (len + 1 > transferred) {
|
||||||
ERROR (device->base.context, "read interrupt transfer returns impossible packet size (%d)", len);
|
ERROR (device->base.context, "Invalid payload length (%u).", len);
|
||||||
return DC_STATUS_PROTOCOL;
|
return DC_STATUS_PROTOCOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
HEXDUMP (device->base.context, DC_LOGLEVEL_DEBUG, "rcv", buf + 1, len);
|
HEXDUMP (device->base.context, DC_LOGLEVEL_DEBUG, "rcv", buf + 1, len);
|
||||||
|
|
||||||
if (len > size) {
|
if (len > size) {
|
||||||
ERROR (device->base.context, "receive result buffer too small");
|
ERROR (device->base.context, "Insufficient buffer space available.");
|
||||||
return DC_STATUS_PROTOCOL;
|
return DC_STATUS_PROTOCOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,7 +128,12 @@ uwatec_g2_transfer (uwatec_g2_device_t *device, const unsigned char command[], u
|
|||||||
buf[1] = csize;
|
buf[1] = csize;
|
||||||
memcpy(buf + 2, command, csize);
|
memcpy(buf + 2, command, csize);
|
||||||
memset(buf + 2 + csize, 0, sizeof(buf) - (csize + 2));
|
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) {
|
if (status != DC_STATUS_SUCCESS) {
|
||||||
ERROR (device->base.context, "Failed to send the command.");
|
ERROR (device->base.context, "Failed to send the command.");
|
||||||
return status;
|
return status;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user