Skip to content

Commit

Permalink
Fix the Mares usb-serial communication
Browse files Browse the repository at this point in the history
The BLE changes in commit e83732e 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.
  • Loading branch information
jefdriesen authored and mikeller committed May 19, 2024
1 parent 5d321de commit d9c2308
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/mares_iconhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.");
Expand All @@ -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) {
Expand Down

0 comments on commit d9c2308

Please sign in to comment.