Discussion:
Mares Bluetooth dongle
Linus Torvalds
2018-09-24 18:36:46 UTC
Permalink
Ok, so I've parsed the bluetooth logs that were provided by Allen Hall
(back in April) and by Fabio Capriati (recently), and I think I see
what is going wrong.

We actually do *almost* the right thing. We even pick the right GATT
service from the device.

It looks like (if I'm reading things correctly) that device has a service

544E326B-5B72-C6B0-1C46-41C1BC448118

which in turn has a few characteristics:

1d1aae28-d2a8-91a1-1242-9d2973fbe571
99a91ebd-b21f-1689-bb43-681f1f55e966

and that characteristic 1d1aae28 then has a "Client Characteristic
Configuration" descriptor to enable notifications and we'll get the
read data from that. And we just do a write to the 99a91ebd one.

That part is actually exactly what we expect: enable notifications on
one characteristic, and write to another. And the protocol is the
exact same normal Mares protocol that libdivecomputer already
supports.

So it should all just work, EXCEPT there is *third* characteristic on
that service too with uuid

d8b3ab7c-4101-ec80-c441-9b0914f6ebc3

and that's the thing that seems to mess us up.

We end up trying to enable notifications on that third characteristic,
because our logic to pick the read-vs-write ones is way way too
simplistic. We basically assume that the notifications come in on the
last characteristic, and that the writes go out on the first
characteristic. Both of which are wrong for this one.

But from everything I see, I think that the Mares code should just
magically start working if I fix that stupid choice of
characteristics.

I'm hoping to have hardware to test by Thursday, but I'm actually
hoping I could have a test-patch for people to try before that.

Because the Mares BLE case really looks like we should be able to get
it working fairly trivially.

Unlike the Garmin Descent, which still confuses the heck out of me,
despite me having the hardware to look at and traces to follow.

Linus
Dirk Hohndel
2018-09-24 18:46:26 UTC
Permalink
Post by Linus Torvalds
But from everything I see, I think that the Mares code should just
magically start working if I fix that stupid choice of
characteristics.
I'm hoping to have hardware to test by Thursday, but I'm actually
hoping I could have a test-patch for people to try before that.
You bought another dive computer?
Post by Linus Torvalds
Because the Mares BLE case really looks like we should be able to get
it working fairly trivially.
I am traveling Tue/Wed this week - but usually I can create a test APK on a very
quick turnaround. So the moment you have a patch you want me to try, getting
an APK out "only" requires me to be near my computer and have a few minutes
to start of a build and upload it.


/D
Linus Torvalds
2018-09-24 19:23:53 UTC
Permalink
Post by Dirk Hohndel
Post by Linus Torvalds
I'm hoping to have hardware to test by Thursday, but I'm actually
hoping I could have a test-patch for people to try before that.
You bought another dive computer?
No. I went into the local dive shop to ask if they can rent them, but
they don't. But the owner has seen me there enough that he just said
"take it for a few days".

So I have a Mares Quad Air to play with for a few days, and I decided
to just buy the bluetooth donge that they didn't have in the store. It
was prime, but sadly not "two day" prime, just "get it by Thursday".
Post by Dirk Hohndel
Post by Linus Torvalds
Because the Mares BLE case really looks like we should be able to get
it working fairly trivially.
I am traveling Tue/Wed this week - but usually I can create a test APK on a very
quick turnaround. So the moment you have a patch you want me to try, getting
an APK out "only" requires me to be near my computer and have a few minutes
to start of a build and upload it.
I should have a patch later today. Need to go grocery shopping and
mull over just how to select the endpoints so that I don't screw up
any of our existing cases.

Our code to pick a characteristic is basically almost entirely random
and just "this worked for the cases we had" with then the Heinrichs
Weicamp thing being a complete special case because of the whole "need
to do flow control in software" thing.

I suspect I just need to bite the bullet and have a per-divecomputer
set of uuid's etc, with the existing code as a fallback. Or something.

I'm not writing code yet, I've only got to the "I understand what's
wrong" phase.

Linus
Dirk Hohndel
2018-09-24 19:27:07 UTC
Permalink
Post by Linus Torvalds
Post by Dirk Hohndel
You bought another dive computer?
No. I went into the local dive shop to ask if they can rent them, but
they don't. But the owner has seen me there enough that he just said
"take it for a few days".
NICE.
Post by Linus Torvalds
So I have a Mares Quad Air to play with for a few days, and I decided
to just buy the bluetooth donge that they didn't have in the store. It
was prime, but sadly not "two day" prime, just "get it by Thursday".
I hate that.
Post by Linus Torvalds
Post by Dirk Hohndel
Post by Linus Torvalds
Because the Mares BLE case really looks like we should be able to get
it working fairly trivially.
I am traveling Tue/Wed this week - but usually I can create a test APK on a very
quick turnaround. So the moment you have a patch you want me to try, getting
an APK out "only" requires me to be near my computer and have a few minutes
to start of a build and upload it.
I should have a patch later today. Need to go grocery shopping and
mull over just how to select the endpoints so that I don't screw up
any of our existing cases.
I keep wondering if the HW is indeed the only one where we really are looking
for a fixed UUID... i.e., maybe that's the same on the Mares and we just hard
code things?
Have we ever compared notes on the Perdix AI?
Post by Linus Torvalds
Our code to pick a characteristic is basically almost entirely random
and just "this worked for the cases we had" with then the Heinrichs
Weicamp thing being a complete special case because of the whole "need
to do flow control in software" thing.
I suspect I just need to bite the bullet and have a per-divecomputer
set of uuid's etc, with the existing code as a fallback. Or something.
That seems much more sane...

/D
Linus Torvalds
2018-09-24 23:41:42 UTC
Permalink
On Mon, Sep 24, 2018 at 12:23 PM Linus Torvalds
Post by Linus Torvalds
Our code to pick a characteristic is basically almost entirely random
and just "this worked for the cases we had" with then the Heinrichs
Weicamp thing being a complete special case because of the whole "need
to do flow control in software" thing.
I suspect I just need to bite the bullet and have a per-divecomputer
set of uuid's etc, with the existing code as a fallback. Or something.
I didn't end up doing the uuid matching yet.

Instead, I tried to just fix up the fairly hardcoded "pick the first
characteristic for writing, the last for reading", and make that whole
logic be a lot more flexible.

So now it actually looks at which characteristics have which
properties, and tries to do the sane thing based on that.

It still works for me Shearwater and my Suunto, and it does seem to make sense.

So maybe it now works for the Mares BlueLink. And if not, I'd really
like to see the subsurface debug log from a trial..

Dirk, I've sent you a merge request on github.

Linus

Loading...