Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the Mares usb-serial communication #63

Merged
merged 1 commit into from
May 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix the Mares usb-serial communication
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.
jefdriesen authored and mikeller committed May 19, 2024
commit d9c230820ffdeff6a6a6cb829b4c50f5d9fe95ae
12 changes: 11 additions & 1 deletion src/mares_iconhd.c
Original file line number Diff line number Diff line change
@@ -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) {