From 3465c63058b4d28b370d0453edfad9ac99768d01 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Wed, 28 Dec 2016 00:19:37 +0100 Subject: wip --- NOTES | 6 ++++++ cmd/experimental/main.go | 47 ++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/NOTES b/NOTES index b02f901..c495e7e 100644 --- a/NOTES +++ b/NOTES @@ -23,3 +23,9 @@ notified: 05 3F 00 00 00 00 | "\x05?\x00\x00\x00\x00" notified: 0B 86 56 00 25 08 00 00 D4 0E 00 00 | "\v\x86V\x00%\b\x00\x00\xd4\x0e\x00\x00" Disconnected Done + +Link to APK +=========== + +https://support.anki.com/hc/en-us/articles/211651457-Anki-OVERDRIVE-Android-app-apk-for-unsupported-devices +https://rink.hockeyapp.net/apps/8eb7ad5380fe46ffbff241900c998cf6/app_versions/17 diff --git a/cmd/experimental/main.go b/cmd/experimental/main.go index 31181af..c9a55f2 100644 --- a/cmd/experimental/main.go +++ b/cmd/experimental/main.go @@ -8,44 +8,81 @@ import ( ) func onStateChange(d gatt.Device, s gatt.State) { + sid := gatt.MustParseUUID(anki.ServiceUUID) log.Println("State", s) switch s { case gatt.StatePoweredOn: log.Println("Scan...") - d.Scan([]gatt.UUID{}, false) + d.Scan([]gatt.UUID{sid}, false) default: d.StopScanning() } } func onDiscover(p gatt.Peripheral, a *gatt.Advertisement, rssi int) { + //defer p.Device().StopScanning() sid := gatt.MustParseUUID(anki.ServiceUUID) for _, s := range a.Services { + log.Println("Found", p.ID()) if s.Equal(sid) { - log.Println("Found", p.ID()) + log.Println("Connect", p.ID()) p.Device().Connect(p) } } } func onConnect(p gatt.Peripheral, err error) { - defer p.Device().CancelConnection(p) ss, err := p.DiscoverServices(nil) if err != nil { log.Println(err) return } for _, s := range ss { - log.Println(s) + log.Println("Service", s.UUID()) + cs, err := p.DiscoverCharacteristics(nil, s) + if err != nil { + log.Println("Discover Service", err) + return + } + for _, c := range cs { + log.Println("Characteristic", c.UUID()) + ds, err := p.DiscoverDescriptors(nil, c) + if err != nil { + log.Println("Discover Descriptors", err) + return + } + for _, d := range ds { + log.Println("Descriptor", d.UUID()) + } + if (c.Properties() & (gatt.CharNotify | gatt.CharIndicate)) != 0 { + if err := p.SetNotifyValue(c, onNotify); err != nil { + log.Println("Set notify", err) + return + } + } + } } } +func onNotify(c *gatt.Characteristic, b []byte, err error) { + log.Printf("notify: % X | %q\n", b, b) +} + +func onDisconnect(p gatt.Peripheral, err error) { + log.Println("Disconnect", p.ID()) + p.Device().CancelConnection(p) +} + func main() { d, err := gatt.NewDevice() if err != nil { log.Fatal(err) } - d.Handle(gatt.PeripheralDiscovered(onDiscover)) + d.Handle( + gatt.PeripheralDiscovered(onDiscover), + gatt.PeripheralConnected(onConnect), + gatt.PeripheralDisconnected(onDisconnect), + ) d.Init(onStateChange) select {} } -- cgit v1.2.3