Fix the Mares Bluelink Pro communication

Sending the two byte command header and then waiting for the ack byte
before sending the remainder of the command payload causes problems for
some (but not all) users. Most likely the extra roundtrip time due to
waiting for the ack byte results in a delay that sometimes exceeds a
timeout in the dive computer while it's waiting for the payload data.

On the other hand, sending both the command header and the payload data
in one single packet is also not an option, because it causes problems
for some models, like the Mares Matrix. See commit
59bfb0f3189b14ae858650b851539d59e3fefe86 for details.

As an alternative solution, send the packet payload immediately after
the header, without waiting for the ack byte. This eliminates the extra
roundtrip time, while still sending out two separate bluetooth packets.
This commit is contained in:
Jef Driesen 2023-08-25 18:39:55 +02:00
parent a7e7439cab
commit e83732e200

View File

@ -197,6 +197,15 @@ mares_iconhd_packet (mares_iconhd_device_t *device,
return status; return status;
} }
// Send the command payload to the dive computer.
if (size) {
status = dc_iostream_write (device->iostream, data, size, NULL);
if (status != DC_STATUS_SUCCESS) {
ERROR (abstract->context, "Failed to send the command.");
return status;
}
}
// Receive the header byte. // Receive the header byte.
unsigned char header[1] = {0}; unsigned char header[1] = {0};
status = dc_iostream_read (device->iostream, header, sizeof (header), NULL); status = dc_iostream_read (device->iostream, header, sizeof (header), NULL);
@ -211,15 +220,6 @@ mares_iconhd_packet (mares_iconhd_device_t *device,
return DC_STATUS_PROTOCOL; return DC_STATUS_PROTOCOL;
} }
// Send the command payload to the dive computer.
if (size) {
status = dc_iostream_write (device->iostream, data, size, NULL);
if (status != DC_STATUS_SUCCESS) {
ERROR (abstract->context, "Failed to send the command.");
return status;
}
}
// Read the packet. // Read the packet.
status = dc_iostream_read (device->iostream, answer, asize, NULL); status = dc_iostream_read (device->iostream, answer, asize, NULL);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {