From d9c230820ffdeff6a6a6cb829b4c50f5d9fe95ae Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Tue, 26 Mar 2024 22:32:48 +0100 Subject: [PATCH] Fix the Mares usb-serial communication The BLE changes in commit e83732e200620882b13804f1ca54c1ab90a38188 are causing major problems for some of the usb-serial enabled models, like the Puck Pro and Quad Air. These models appear to require a small delay of a few milliseconds between sending the two command bytes and the remainder of the command payload. I suspect the device is still busy processing those first two bytes, and thus not ready in time to receive the remaining data. Instead of manually adding a fixed delay, restore the previous behaviour and wait for the ack byte again. This has the advantage that the delay is automatically proportional to the response time of the dive computer. For the BLE communication nothing changes. --- src/mares_iconhd.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/mares_iconhd.c b/src/mares_iconhd.c index b86ff0d4..b19f5bff 100644 --- a/src/mares_iconhd.c +++ b/src/mares_iconhd.c @@ -183,6 +183,7 @@ mares_iconhd_packet (mares_iconhd_device_t *device, { dc_status_t status = DC_STATUS_SUCCESS; dc_device_t *abstract = (dc_device_t *) device; + dc_transport_t transport = dc_iostream_get_transport (device->iostream); if (device_is_cancelled (abstract)) return DC_STATUS_CANCELLED; @@ -198,7 +199,7 @@ mares_iconhd_packet (mares_iconhd_device_t *device, } // Send the command payload to the dive computer. - if (size) { + if (size && transport == DC_TRANSPORT_BLE) { status = dc_iostream_write (device->iostream, data, size, NULL); if (status != DC_STATUS_SUCCESS) { ERROR (abstract->context, "Failed to send the command."); @@ -220,6 +221,15 @@ mares_iconhd_packet (mares_iconhd_device_t *device, return DC_STATUS_PROTOCOL; } + // Send the command payload to the dive computer. + if (size && transport != DC_TRANSPORT_BLE) { + status = dc_iostream_write (device->iostream, data, size, NULL); + if (status != DC_STATUS_SUCCESS) { + ERROR (abstract->context, "Failed to send the command data."); + return status; + } + } + // Read the packet. status = dc_iostream_read (device->iostream, answer, asize, NULL); if (status != DC_STATUS_SUCCESS) {