Skip to content

Conversation

@deadprogram
Copy link
Member

This PR adds a GetUUID() accessor to both DeviceService and DeviceCharacteristic to simplify use on bare metal with short UUIDs.

@deadprogram
Copy link
Member Author

This PR is intended to address the comments from #11

Copy link
Member

@aykevl aykevl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetUUID works, but Effective Go suggests leaving out the Get prefix: https://golang.org/doc/effective_go.html#Getters

To make that possible, perhaps you can unexport the UUID field (renaming it to uuid) or rename it to something else such as UnderlyingUUID?

@deadprogram
Copy link
Member Author

That was what I was trying originally but I did not immediately figure out how to handle the naming conflict you mentioned, which is why I took an "easier" way out.

I realized I can do what I wanted using a type alias, which I have just now changed and pushed to this branch.

@aykevl
Copy link
Member

aykevl commented Sep 6, 2020

This is the function to convert from C.ble_uuid_t to the UUID type: sd_ble_uuid_encode

@deadprogram
Copy link
Member Author

I think I have made all of the changes requested but am unable to test them due to #15

@aykevl
Copy link
Member

aykevl commented Sep 9, 2020

You could use any development from Nordic to test these changes. But I will also try to test it.

Copy link
Member

@aykevl aykevl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this doesn't work correctly on a SoftDevice:

$ tinygo gdb -target=pca10056-s140v7 ./examples/scanner/
[...]
(gdb) bt
#0  runtime.nilPanic () at /home/ayke/src/github.com/tinygo-org/tinygo/src/runtime/panic.go:32
#1  0x0002713e in (tinygo.org/x/bluetooth.Addresser).Set ()

It appears that the MAC address is being set on a nil Address.

@deadprogram
Copy link
Member Author

Unfortunately this doesn't work correctly on a SoftDevice:

$ tinygo gdb -target=pca10056-s140v7 ./examples/scanner/
[...]
(gdb) bt
#0  runtime.nilPanic () at /home/ayke/src/github.com/tinygo-org/tinygo/src/runtime/panic.go:32
#1  0x0002713e in (tinygo.org/x/bluetooth.Addresser).Set ()

It appears that the MAC address is being set on a nil Address.

Seems like this problem exists on dev branch even without this PR.

…t UUIDs

Signed-off-by: deadprogram <ron@hybridgroup.com>
Signed-off-by: Ron Evans <ron@hybridgroup.com>
Signed-off-by: Ron Evans <ron@hybridgroup.com>
…service and characteristic discovery

Signed-off-by: deadprogram <ron@hybridgroup.com>
…stics

Signed-off-by: deadprogram <ron@hybridgroup.com>
Signed-off-by: deadprogram <ron@hybridgroup.com>
@deadprogram
Copy link
Member Author

deadprogram commented Sep 11, 2020

Made a great deal of progress here. Now I am testing and discovering some differences between the results being returned by Linux vs. the SoftDevice.

$ go run ./examples/discover E4:B7:F4:11:8D:33
enabling
scanning...
found device: E4:B7:F4:11:8D:33 0 TinyGo
connected to  E4:B7:F4:11:8D:33
discovering services/characteristics
- service 0000180d-0000-1000-8000-00805f9b34fb
-- characteristic 00002a37-0000-1000-8000-00805f9b34fb
- service 00001801-0000-1000-8000-00805f9b34fb
-- characteristic 00002a05-0000-1000-8000-00805f9b34fb

vs. my current code on SD:

found device: E4:B7:F4:11:8D:33 -51 Go HRS
evt: connected in central role
connected to  E4:B7:F4:11:8D:33
discovering services/characteristics
evt: discovered primary service 3
evt: discovered primary service 2
evt: discovered primary service 1
- service 00180000-0000-0000-0000-000000000000
evt: discovered characteristics 3
evt: discovered characteristics 3
evt: discovered characteristics 2
evt: discovered characteristics 1
- service 01180000-0000-0000-0000-000000000000
evt: discovered characteristics 1
- service 0d180000-0000-0000-0000-000000000000
evt: discovered characteristics 1
evt: discovered characteristics 0

First thing I notice is that the short UUIDs on SD do not look like what I was expecting. Is that an error?

In any case, also why are more services being returned? And likewise with the number of characteristics per service? I think I am getting pretty close here.

Signed-off-by: deadprogram <ron@hybridgroup.com>
@deadprogram
Copy link
Member Author

Found the error in converting short UUID to UUID, and pushed a commit to correct that.

Now, here is my debug output:

found device: E4:B7:F4:11:8D:33 -51 Go HRS
evt: connected in central role
connected to  E4:B7:F4:11:8D:33
discovering services/characteristics
evt: discovered primary service 3
evt: discovered primary service 2
evt: discovered primary service 1
- service 00001800-0000-1000-8000-00805f9b34fb
evt: discovered characteristics 3
evt: discovered characteristics 3
evt: discovered characteristics 2
evt: discovered characteristics 1
- service 00001801-0000-1000-8000-00805f9b34fb
evt: discovered characteristics 1
- service 0000180d-0000-1000-8000-00805f9b34fb
evt: discovered characteristics 1
evt: discovered characteristics 0

Signed-off-by: deadprogram <ron@hybridgroup.com>
Signed-off-by: deadprogram <ron@hybridgroup.com>
@deadprogram
Copy link
Member Author

OK, now after testing, I am pretty confident that the SD version is working exactly as it is supposed to with my latest commits:

connected to  E4:B7:F4:11:8D:33
discovering services/characteristics
- service 00001800-0000-1000-8000-00805f9b34fb
-- characteristic 00002a00-0000-1000-8000-00805f9b34fb
-- characteristic 00002a01-0000-1000-8000-00805f9b34fb
-- characteristic 00002a04-0000-1000-8000-00805f9b34fb
-- characteristic 00002aa6-0000-1000-8000-00805f9b34fb
- service 00001801-0000-1000-8000-00805f9b34fb
-- characteristic 00002a05-0000-1000-8000-00805f9b34fb
- service 0000180d-0000-1000-8000-00805f9b34fb
-- characteristic 00002a37-0000-1000-8000-00805f9b34fb
Done.

Note this is the "heartbeat" example.

Copy link
Member

@aykevl aykevl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, except that I discovered some unsafe code. Other than that it looks good to me.

…ting short UUID

Signed-off-by: deadprogram <ron@hybridgroup.com>
@aykevl aykevl merged commit ef90e5d into dev Sep 13, 2020
@aykevl aykevl deleted the uuid-getter branch September 13, 2020 18:21
@aykevl
Copy link
Member

aykevl commented Sep 13, 2020

Great! Now we can discover services and characteristics from SoftDevice chips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants