diff --git a/central_darwin.go b/central_darwin.go index 3f18bcc..c861420 100644 --- a/central_darwin.go +++ b/central_darwin.go @@ -3,7 +3,7 @@ package gatt import ( "sync" - "github.com/paypal/gatt/xpc" + "github.com/cfreeman/gatt/xpc" ) type central struct { diff --git a/device_darwin.go b/device_darwin.go index 9504b4b..85156e8 100644 --- a/device_darwin.go +++ b/device_darwin.go @@ -9,7 +9,7 @@ import ( "sync" "time" - "github.com/paypal/gatt/xpc" + "github.com/cfreeman/gatt/xpc" ) const ( diff --git a/device_linux.go b/device_linux.go index f6f9fb1..c3a5118 100644 --- a/device_linux.go +++ b/device_linux.go @@ -4,8 +4,8 @@ import ( "encoding/binary" "net" - "github.com/paypal/gatt/linux" - "github.com/paypal/gatt/linux/cmd" + "github.com/cfreeman/gatt/linux" + "github.com/cfreeman/gatt/linux/cmd" ) type device struct { diff --git a/examples/discoverer.go b/examples/discoverer.go index 2757856..712e9a9 100644 --- a/examples/discoverer.go +++ b/examples/discoverer.go @@ -6,8 +6,8 @@ import ( "fmt" "log" - "github.com/paypal/gatt" - "github.com/paypal/gatt/examples/option" + "github.com/cfreeman/gatt" + "github.com/cfreeman/gatt/examples/option" ) func onStateChanged(d gatt.Device, s gatt.State) { diff --git a/examples/explorer.go b/examples/explorer.go index c7c0834..40718a0 100644 --- a/examples/explorer.go +++ b/examples/explorer.go @@ -10,8 +10,8 @@ import ( "strings" "time" - "github.com/paypal/gatt" - "github.com/paypal/gatt/examples/option" + "github.com/cfreeman/gatt" + "github.com/cfreeman/gatt/examples/option" ) var done = make(chan struct{}) diff --git a/examples/option/option_darwin.go b/examples/option/option_darwin.go index 0c31390..3bc6c78 100644 --- a/examples/option/option_darwin.go +++ b/examples/option/option_darwin.go @@ -1,6 +1,6 @@ package option -import "github.com/paypal/gatt" +import "github.com/cfreeman/gatt" var DefaultClientOptions = []gatt.Option{ gatt.MacDeviceRole(gatt.CentralManager), diff --git a/examples/option/option_linux.go b/examples/option/option_linux.go index de08783..a45796e 100644 --- a/examples/option/option_linux.go +++ b/examples/option/option_linux.go @@ -1,8 +1,8 @@ package option import ( - "github.com/paypal/gatt" - "github.com/paypal/gatt/linux/cmd" + "github.com/cfreeman/gatt" + "github.com/cfreeman/gatt/linux/cmd" ) var DefaultClientOptions = []gatt.Option{ diff --git a/examples/server.go b/examples/server.go index 1ee5fe4..d17a41c 100644 --- a/examples/server.go +++ b/examples/server.go @@ -6,9 +6,9 @@ import ( "fmt" "log" - "github.com/paypal/gatt" - "github.com/paypal/gatt/examples/option" - "github.com/paypal/gatt/examples/service" + "github.com/cfreeman/gatt" + "github.com/cfreeman/gatt/examples/option" + "github.com/cfreeman/gatt/examples/service" ) func main() { diff --git a/examples/server_lnx.go b/examples/server_lnx.go index 88d4943..7346bc2 100644 --- a/examples/server_lnx.go +++ b/examples/server_lnx.go @@ -9,9 +9,9 @@ import ( "log" "time" - "github.com/paypal/gatt" - "github.com/paypal/gatt/examples/service" - "github.com/paypal/gatt/linux/cmd" + "github.com/cfreeman/gatt" + "github.com/cfreeman/gatt/examples/service" + "github.com/cfreeman/gatt/linux/cmd" ) // server_lnx implements a GATT server. diff --git a/examples/service/battery.go b/examples/service/battery.go index ee5a9ab..8732897 100644 --- a/examples/service/battery.go +++ b/examples/service/battery.go @@ -1,6 +1,6 @@ package service -import "github.com/paypal/gatt" +import "github.com/cfreeman/gatt" func NewBatteryService() *gatt.Service { lv := byte(100) diff --git a/examples/service/count.go b/examples/service/count.go index fd88430..e2ec43b 100644 --- a/examples/service/count.go +++ b/examples/service/count.go @@ -5,7 +5,7 @@ import ( "log" "time" - "github.com/paypal/gatt" + "github.com/cfreeman/gatt" ) func NewCountService() *gatt.Service { diff --git a/examples/service/gap.go b/examples/service/gap.go index 4c2a4b2..2adeb39 100644 --- a/examples/service/gap.go +++ b/examples/service/gap.go @@ -1,6 +1,6 @@ package service -import "github.com/paypal/gatt" +import "github.com/cfreeman/gatt" var ( attrGAPUUID = gatt.UUID16(0x1800) diff --git a/examples/service/gatt.go b/examples/service/gatt.go index 8ca29c3..2dfdba6 100644 --- a/examples/service/gatt.go +++ b/examples/service/gatt.go @@ -3,7 +3,7 @@ package service import ( "log" - "github.com/paypal/gatt" + "github.com/cfreeman/gatt" ) var ( diff --git a/linux/cmd/cmd.go b/linux/cmd/cmd.go index b3ea7b4..0f64de3 100644 --- a/linux/cmd/cmd.go +++ b/linux/cmd/cmd.go @@ -7,8 +7,8 @@ import ( "io" "log" - "github.com/paypal/gatt/linux/evt" - "github.com/paypal/gatt/linux/util" + "github.com/cfreeman/gatt/linux/evt" + "github.com/cfreeman/gatt/linux/util" ) type CmdParam interface { diff --git a/linux/device.go b/linux/device.go index 9c18732..14a3e5e 100644 --- a/linux/device.go +++ b/linux/device.go @@ -7,8 +7,8 @@ import ( "syscall" "unsafe" - "github.com/paypal/gatt/linux/gioctl" - "github.com/paypal/gatt/linux/socket" + "github.com/cfreeman/gatt/linux/gioctl" + "github.com/cfreeman/gatt/linux/socket" ) type device struct { diff --git a/linux/devices.go b/linux/devices.go index c0d3c97..929529a 100644 --- a/linux/devices.go +++ b/linux/devices.go @@ -1,6 +1,6 @@ package linux -import "github.com/paypal/gatt/linux/gioctl" +import "github.com/cfreeman/gatt/linux/gioctl" const ( ioctlSize = uintptr(4) diff --git a/linux/evt/evt.go b/linux/evt/evt.go index 74f8aa3..8342cb1 100644 --- a/linux/evt/evt.go +++ b/linux/evt/evt.go @@ -5,7 +5,7 @@ import ( "encoding/binary" "errors" - "github.com/paypal/gatt/linux/util" + "github.com/cfreeman/gatt/linux/util" ) type EventHandler interface { diff --git a/linux/hci.go b/linux/hci.go index ceaf97a..e57a768 100644 --- a/linux/hci.go +++ b/linux/hci.go @@ -6,8 +6,8 @@ import ( "log" "sync" - "github.com/paypal/gatt/linux/cmd" - "github.com/paypal/gatt/linux/evt" + "github.com/cfreeman/gatt/linux/cmd" + "github.com/cfreeman/gatt/linux/evt" ) type HCI struct { diff --git a/linux/l2cap.go b/linux/l2cap.go index 1a03465..8c1a53d 100644 --- a/linux/l2cap.go +++ b/linux/l2cap.go @@ -5,7 +5,7 @@ import ( "io" "log" - "github.com/paypal/gatt/linux/cmd" + "github.com/cfreeman/gatt/linux/cmd" ) type aclData struct { diff --git a/option_linux.go b/option_linux.go index 8bc6c46..1a0bf73 100644 --- a/option_linux.go +++ b/option_linux.go @@ -4,7 +4,7 @@ import ( "errors" "io" - "github.com/paypal/gatt/linux/cmd" + "github.com/cfreeman/gatt/linux/cmd" ) // LnxDeviceID specifies which HCI device to use. diff --git a/option_linux_test.go b/option_linux_test.go index 1eeca7a..4822f69 100644 --- a/option_linux_test.go +++ b/option_linux_test.go @@ -3,7 +3,7 @@ package gatt import ( "bytes" - "github.com/paypal/gatt/linux/cmd" + "github.com/cfreeman/gatt/linux/cmd" ) func ExampleLnxDeviceID() { diff --git a/peripheral_darwin.go b/peripheral_darwin.go index bbe4dca..d64b907 100644 --- a/peripheral_darwin.go +++ b/peripheral_darwin.go @@ -4,7 +4,7 @@ import ( "errors" "log" - "github.com/paypal/gatt/xpc" + "github.com/cfreeman/gatt/xpc" ) type peripheral struct { diff --git a/peripheral_linux.go b/peripheral_linux.go index ce256fa..39d49b4 100644 --- a/peripheral_linux.go +++ b/peripheral_linux.go @@ -10,7 +10,7 @@ import ( "net" "strings" - "github.com/paypal/gatt/linux" + "github.com/cfreeman/gatt/linux" ) type peripheral struct { @@ -50,8 +50,7 @@ func finish(op byte, h uint16, b []byte) bool { return done } -func (p *peripheral) DiscoverServices(s []UUID) ([]*Service, error) { - // TODO: implement the UUID filters +func (p *peripheral) DiscoverServices(ds []UUID) ([]*Service, error) { // p.pd.Conn.Write([]byte{0x02, 0x87, 0x00}) // MTU done := false start := uint16(0x0001) @@ -77,14 +76,18 @@ func (p *peripheral) DiscoverServices(s []UUID) ([]*Service, error) { } for len(b) != 0 { - h := binary.LittleEndian.Uint16(b[:2]) endh := binary.LittleEndian.Uint16(b[2:4]) - s := &Service{ - uuid: UUID{b[4:l]}, - h: h, - endh: endh, + u := UUID{b[4:l]} + + if UUIDContains(ds, u) { + s := &Service{ + uuid: u, + h: binary.LittleEndian.Uint16(b[:2]), + endh: endh, + } + p.svcs = append(p.svcs, s) } - p.svcs = append(p.svcs, s) + b = b[l:] done = endh == 0xFFFF start = endh + 1 @@ -99,7 +102,6 @@ func (p *peripheral) DiscoverIncludedServices(ss []UUID, s *Service) ([]*Service } func (p *peripheral) DiscoverCharacteristics(cs []UUID, s *Service) ([]*Characteristic, error) { - // TODO: implement the UUID filters done := false start := s.h var prev *Characteristic @@ -142,7 +144,9 @@ func (p *peripheral) DiscoverCharacteristics(cs []UUID, s *Service) ([]*Characte h: h, vh: vh, } - s.chars = append(s.chars, c) + if UUIDContains(cs, u) { + s.chars = append(s.chars, c) + } b = b[l:] done = vh == s.endh start = vh + 1 @@ -159,7 +163,6 @@ func (p *peripheral) DiscoverCharacteristics(cs []UUID, s *Service) ([]*Characte } func (p *peripheral) DiscoverDescriptors(ds []UUID, c *Characteristic) ([]*Descriptor, error) { - // TODO: implement the UUID filters done := false start := c.vh + 1 for !done { @@ -193,7 +196,9 @@ func (p *peripheral) DiscoverDescriptors(ds []UUID, c *Characteristic) ([]*Descr h := binary.LittleEndian.Uint16(b[:2]) u := UUID{b[2:l]} d := &Descriptor{uuid: u, h: h, char: c} - c.descs = append(c.descs, d) + if UUIDContains(ds, u) { + c.descs = append(c.descs, d) + } if u.Equal(attrClientCharacteristicConfigUUID) { c.cccd = d } diff --git a/readme.md b/readme.md index ea3a957..2c2f549 100644 --- a/readme.md +++ b/readme.md @@ -96,7 +96,7 @@ OS X central, see http://stackoverflow.com/questions/20553957. ## Known Issues -Currently OS X vesion does not support subscribing to indications. +Currently OS X vesion does not support subscribing to indications. Please check [#32](https://github.com/paypal/gatt/issues/32) for the status of this issue. ## REFERENCES diff --git a/uuid.go b/uuid.go index 393e548..2df8f2c 100644 --- a/uuid.go +++ b/uuid.go @@ -71,6 +71,21 @@ func (u UUID) Equal(v UUID) bool { return bytes.Equal(u.b, v.b) } +// UUIDContains returns a boolean reporting whether u is in the slice s. +func UUIDContains(s []UUID, u UUID) bool { + if s == nil { + return true + } + + for _, a := range s { + if a.Equal(u) { + return true + } + } + + return false +} + // reverse returns a reversed copy of u. func reverse(u []byte) []byte { // Special-case 16 bit UUIDS for speed.