On Tue, Sep 25, 2018 at 11:07 PM Linus Torvalds
<[email protected]> wrote:
>
> So I need to make that BLEObject::read() function just handle the
> "user just wants a partial packet" case. Nobody has cared until now.
>
> And I guess I also need to make it loop over the packet until it gets
> the asked-for data.
Like this attached patch.
Dirk, I've verified that this builds, and still works with the EON
Core, but I can't actually test the case that the Mares hits. The code
_looks_ simple, but I'd rather not commit it upstream without testing.
Are your scripts able to make a test-build with this patch in, without
actually committing it to the master branch?
The patch *looks* obvious, but..
Linus
core/qt-ble.cpp | 32 +++++++++++++++++++++++++++++---
1 file changed, 29 insertions(+), 3 deletions(-)
diff --git a/core/qt-ble.cpp b/core/qt-ble.cpp
index 8d4003d0f..1dda570a7 100644
--- a/core/qt-ble.cpp
+++ b/core/qt-ble.cpp
@@ -191,8 +191,15 @@ dc_status_t BLEObject::read(void *data, size_t size, size_t *actual)
QByteArray packet = receivedPackets.takeFirst();
- if ((size_t)packet.size() > size)
- return DC_STATUS_NOMEMORY;
+ // Did we get more than asked for?
+ //
+ // Put back the left-over at the beginning of the
+ // received packet list, and truncate the packet
+ // we got to just the part asked for.
+ if ((size_t)packet.size() > size) {
+ receivedPackets.prepend(packet.mid(size));
+ packet.truncate(size);
+ }
memcpy((char *)data, packet.data(), packet.size());
if (actual)
@@ -501,11 +508,30 @@ static void checkThreshold()
}
}
+// If 'actual' is NULL, we need to get all or nothing
dc_status_t qt_ble_read(void *io, void* data, size_t size, size_t *actual)
{
checkThreshold();
+
BLEObject *ble = (BLEObject *) io;
- return ble->read(data, size, actual);
+ do {
+ dc_status_t rc;
+ size_t got = 0;
+
+ rc = ble->read(data, size, &got);
+ if (actual) {
+ *actual = got;
+ return rc;
+ }
+
+ if (rc != DC_STATUS_SUCCESS)
+ return rc;
+
+ data = (void *)(got + (char *)data);
+ size -= got;
+ } while (size);
+
+ return DC_STATUS_SUCCESS;
}
dc_status_t qt_ble_write(void *io, const void* data, size_t size, size_t *actual)
_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface