From 0753f10661d76cbe1848d5ac079d511c36e1addd Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Wed, 30 Mar 2022 20:52:07 +0200 Subject: [PATCH] Fix changing the OSTC settings The command to change the OSTC settings has a variable length payload (1 to 4 bytes). Therefore, the expected number of bytes is only know after evaluating the first option index byte. Due to the limited UART buffer in the OSTC, sending the remainder of the packet immediately after the first byte, can cause the OSTC to get out of sync. Introduce a small delay between sending the option index and the remaining parameters to avoid this problem. --- src/hw_ostc3.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/hw_ostc3.c b/src/hw_ostc3.c index ff821c6..550662f 100644 --- a/src/hw_ostc3.c +++ b/src/hw_ostc3.c @@ -318,11 +318,29 @@ hw_ostc3_transfer (hw_ostc3_device_t *device, } if (input) { - // Send the input data packet. - status = hw_ostc3_write (device, progress, input, isize); - if (status != DC_STATUS_SUCCESS) { - ERROR (abstract->context, "Failed to send the data packet."); - return status; + if (cmd == WRITE) { + // Send the first byte of the input data packet. + status = hw_ostc3_write (device, progress, input, 1); + if (status != DC_STATUS_SUCCESS) { + ERROR (abstract->context, "Failed to send the data packet."); + return status; + } + + dc_iostream_sleep (device->iostream, 10); + + // Send the reamainder of the input data packet. + status = hw_ostc3_write (device, progress, input + 1, isize - 1); + if (status != DC_STATUS_SUCCESS) { + ERROR (abstract->context, "Failed to send the data packet."); + return status; + } + } else { + // Send the input data packet. + status = hw_ostc3_write (device, progress, input, isize); + if (status != DC_STATUS_SUCCESS) { + ERROR (abstract->context, "Failed to send the data packet."); + return status; + } } }