Skip to content

Commit d9c2308

Browse files
jefdriesenmikeller
authored andcommitted
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.
1 parent 5d321de commit d9c2308

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/mares_iconhd.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ mares_iconhd_packet (mares_iconhd_device_t *device,
183183
{
184184
dc_status_t status = DC_STATUS_SUCCESS;
185185
dc_device_t *abstract = (dc_device_t *) device;
186+
dc_transport_t transport = dc_iostream_get_transport (device->iostream);
186187

187188
if (device_is_cancelled (abstract))
188189
return DC_STATUS_CANCELLED;
@@ -198,7 +199,7 @@ mares_iconhd_packet (mares_iconhd_device_t *device,
198199
}
199200

200201
// Send the command payload to the dive computer.
201-
if (size) {
202+
if (size && transport == DC_TRANSPORT_BLE) {
202203
status = dc_iostream_write (device->iostream, data, size, NULL);
203204
if (status != DC_STATUS_SUCCESS) {
204205
ERROR (abstract->context, "Failed to send the command.");
@@ -220,6 +221,15 @@ mares_iconhd_packet (mares_iconhd_device_t *device,
220221
return DC_STATUS_PROTOCOL;
221222
}
222223

224+
// Send the command payload to the dive computer.
225+
if (size && transport != DC_TRANSPORT_BLE) {
226+
status = dc_iostream_write (device->iostream, data, size, NULL);
227+
if (status != DC_STATUS_SUCCESS) {
228+
ERROR (abstract->context, "Failed to send the command data.");
229+
return status;
230+
}
231+
}
232+
223233
// Read the packet.
224234
status = dc_iostream_read (device->iostream, answer, asize, NULL);
225235
if (status != DC_STATUS_SUCCESS) {

0 commit comments

Comments
 (0)