mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
OSTC over BLE: read a long as needed
See alsob409e9fc91
and709c1df2af
. The OSTC parser cannot handle reads of single 20 byte BLE packages in serial mode. Instead of doing a deeper down agressive read, we can read on the serial level more subtile. As the parser is requesting a specific number of bytes, we just read that number of bytes and return them. As the 20 byte BLE packets do (obviously) not align with the reading requirement of the libdc parser, a little housekeeing needs to be done in between individual reads. CAVEAT 1: In contradiction to709c1df2af
, this is supposed to work for all parsers that properly specify the needed bytes to fetch. CAVEAT 2: All above tested on Linux Desktop with bluez stack. Subsurface mobile is step 2. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
This commit is contained in:
parent
b409e9fc91
commit
8911281593
1 changed files with 21 additions and 6 deletions
|
@ -126,19 +126,34 @@ static dc_status_t ble_serial_read(dc_custom_io_t *io, void* data, size_t size,
|
|||
{
|
||||
Q_UNUSED(io)
|
||||
size_t len;
|
||||
size_t received = 0;
|
||||
|
||||
if (buffer.in_pos >= buffer.in_bytes) {
|
||||
dc_status_t rc;
|
||||
size_t received;
|
||||
|
||||
ble_serial_flush_write();
|
||||
rc = ble_serial_ops.packet_read(&ble_serial_ops, buffer.in, sizeof(buffer.in), &received);
|
||||
}
|
||||
|
||||
/* There is still unused/unread data in the input steam.
|
||||
* So preseve it at the start of a new read.
|
||||
*/
|
||||
if (buffer.in_pos > 0) {
|
||||
len = buffer.in_bytes - buffer.in_pos;
|
||||
memcpy(buffer.in, buffer.in + buffer.in_pos, len);
|
||||
buffer.in_pos = 0;
|
||||
buffer.in_bytes = len;
|
||||
}
|
||||
|
||||
/* Read a long as requested in the size parameter */
|
||||
while ((buffer.in_bytes - buffer.in_pos) < size) {
|
||||
dc_status_t rc;
|
||||
|
||||
rc = ble_serial_ops.packet_read(&ble_serial_ops, buffer.in + buffer.in_bytes,
|
||||
sizeof(buffer.in) - buffer.in_bytes, &received);
|
||||
if (rc != DC_STATUS_SUCCESS)
|
||||
return rc;
|
||||
if (!received)
|
||||
return DC_STATUS_IO;
|
||||
buffer.in_pos = 0;
|
||||
buffer.in_bytes = received;
|
||||
|
||||
buffer.in_bytes += received;
|
||||
}
|
||||
|
||||
len = buffer.in_bytes - buffer.in_pos;
|
||||
|
|
Loading…
Add table
Reference in a new issue