Changeset 8911281 in subsurface


Ignore:
Timestamp:
Jul 11, 2017, 4:41:21 AM (4 months ago)
Author:
Jan Mulder <jlmulder@…>
Branches:
master
Children:
fbaaa64
Parents:
b409e9f
Message:

OSTC over BLE: read a long as needed

See also b409e9fc91d87bbd5 and 709c1df2af4b87. 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 to 709c1df2af4b87, 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@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • core/qtserialbluetooth.cpp

    rea8e300 r8911281  
    127127        Q_UNUSED(io)
    128128        size_t len;
     129        size_t received = 0;
    129130
    130131        if (buffer.in_pos >= buffer.in_bytes) {
     132                ble_serial_flush_write();
     133        }
     134
     135        /* There is still unused/unread data in the input steam.
     136         * So preseve it at the start of a new read.
     137         */
     138        if (buffer.in_pos > 0) {
     139                len = buffer.in_bytes - buffer.in_pos;
     140                memcpy(buffer.in, buffer.in + buffer.in_pos, len);
     141                buffer.in_pos = 0;
     142                buffer.in_bytes = len;
     143        }
     144
     145        /* Read a long as requested in the size parameter */
     146        while ((buffer.in_bytes - buffer.in_pos) < size) {
    131147                dc_status_t rc;
    132                 size_t received;
    133 
    134                 ble_serial_flush_write();
    135                 rc = ble_serial_ops.packet_read(&ble_serial_ops, buffer.in, sizeof(buffer.in), &received);
     148
     149                rc = ble_serial_ops.packet_read(&ble_serial_ops, buffer.in + buffer.in_bytes,
     150                                                sizeof(buffer.in) - buffer.in_bytes, &received);
    136151                if (rc != DC_STATUS_SUCCESS)
    137152                        return rc;
    138153                if (!received)
    139154                        return DC_STATUS_IO;
    140                 buffer.in_pos = 0;
    141                 buffer.in_bytes = received;
     155
     156                buffer.in_bytes += received;
    142157        }
    143158
Note: See TracChangeset for help on using the changeset viewer.