On Sat, 17 Aug 2024 at 23:29, Ben Linders <
benli...@gmail.com> wrote:
>
> I've made another attempt and tried 3 times to download dives. The led on the Bluelink went green but nothing downloaded. It shows the message "connect ..." but the word behind connect falls off the screen of my Samsung phone.
>
> Does this help?
Well, the logs are helpful in the sense that yes, they show that
bluetooth communication actually happens.
But something goes seriously wrong with the communication.
In your "subsurface log 2", I see this (edited down to remove the
uninteresting characteristic UUID etc):
Write "c267"
write confirmation 10 "c267" QLowEnergyService::NoError
notification 7 "aa00000000000000000000000000000000000000"
notification 7 "0000000000000000000000000000000000000000"
notification 7 "00000000"
notification 7 "0000000000000000000000000000000000000000"
notification 7 "0000000000000051756164000000000000000000"
notification 7 "00000030322e30312e30300201000032332d3033"
notification 7 "2d313859ad53564e343030000000000000000000"
notification 7 "000000000000000000000000"
notification 7 "0000000000ea"
Write "b316"
write confirmation 10 "b316"
notification 7 "aa00001000ea"
which actually looks fine: we've written a command, and get reasonable
data back, and then we write the next command etc.
In fact, it looks like it all works fine with what looks like good
data until we start sending the "read command" commands, and at that
point we see
Write "e742"
write confirmation 10 "e742"
notification 7 "aa019b0000ea"
and this is horribly wrong. The "e742" is just the CMD_READ byte: E7
and the 42 byte is the XOR of that with A5. And we haven't actually
written the _address_ we read from - there's 8 more bytes that specify
the address and the length of the read, and they never got sent.
So the end result is broken chaos.
Jef and Michael - the problem is that we have merged with the
libdivecomputer upstream code, because we thought Jef knew better. And
it appears that Jef doesn't actually know better at all.
See my libdivecomputer commit 704ed3f1 ("Add back Mares BlueLink Pro
bluetooth support tweaks"), and the whole "splitcommand" logic. In
particular, in that commit message I say
In particular, it turns out that we really can't send the command bytes,
then wait for the ACK byte, and then send the command argument data as a
separate packet. Because of the delays that the dongle adds, the dive
computer will have given up on the command arguments by the time it sees
them.
and it seems that is still true. The BlueLink dongle does *not* want
the first two bytes to be split out and sent independently.
But that code got removed by the upstream merge in commit d37cb917
("Merge remote-tracking branch 'libdivecomputer/master' into
update_libdivecomputer_202402"), because Jef did
e83732e2 ("Fix the Mares Bluelink Pro communication")
a7e7439c ("Setup the 2 byte command header internally")
and it now sends the first two command bytes as a separate packets
from the the rest.
But from the logs it's pretty clear that the split-command thing is
broken. We never send the address and length at all, just repeating
the "e742" write over and over again.
Which is strange is that the code should at least send the extra 8
command bytes right after the 2-byte packet:
status = dc_iostream_write (device->iostream, command,
sizeof(command), NULL);
if (status != DC_STATUS_SUCCESS) {
ERROR (abstract->context, "Failed to send the command header.");
return status;
}
// Send the command payload to the dive computer.
if (size && transport == DC_TRANSPORT_BLE) {
status = dc_iostream_write (device->iostream, data, size, NULL);
if (status != DC_STATUS_SUCCESS) {
ERROR (abstract->context, "Failed to send the
command data.");
return status;
}
}
but in the subsurface logs, that never happens.
So something is very very wrong with the libdivecomputer iconhd code,
or with the write buffering.
I don't know why the second write seems to just get entirely lost. All
the actual IO and the logging comes from the Qt BLE side (because
subsurface will log the write requests itself only if
if (verbose > 2 || debugCounter < DEBUG_THRESHOLD)
and so the subsurface side is being silent and that log is only about
actually sent and received packets from Qt.
And your libdivecomputer log-file doesn't show this, because it seems
to be from a later - completely failed - download, where it doesn't
even get past the initial "hello" command (that first "c267" thing:
CMD_VERSION). It's reading random stale data that the BlueLink is
sending that is left-over from previous very very confused things.
It might be interesting to get the output from "subsurface -vv", but
it actually looks like *none* of the subsurface.log data comes from
subsurface's own logging. Absolutely everything seems to be just Qt
logging.
I wonder if report_info() and friends are just broken, and don't show
up in subsurface.log at all.
Very annoying.
Linus