diff --git a/.gitignore b/.gitignore index 7ab0687..bebc889 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ c.out c/*-ble sample +.idea \ No newline at end of file diff --git a/adv.go b/adv.go index 787ff33..9a3539f 100644 --- a/adv.go +++ b/adv.go @@ -2,7 +2,8 @@ package gatt import ( "errors" - "log" + "fmt" + log "github.com/sirupsen/logrus" ) // MaxEIRPacketLength is the maximum allowed AdvertisingPacket @@ -93,9 +94,16 @@ func (a *Advertisement) unmarshall(b []byte) error { return errors.New("invalid advertise data") } l, t := b[0], b[1] + fmt.Println(len(b), b) if len(b) < int(1+l) { - return errors.New("invalid advertise data") + return errors.New("invalid advertise data, not enough data") + } + if l == 0 { + fmt.Println("Detected zero length data") } + //else if l == 0 { + // return errors.New(fmt.Sprintf("invalid advertise data: %d", l)) + //} d := b[2 : 1+l] switch t { case typeFlags: @@ -131,7 +139,7 @@ func (a *Advertisement) unmarshall(b []byte) error { // case typeServiceData32, // case typeServiceData128: default: - log.Printf("DATA: [ % X ]", d) + log.Info("DATA: [ % X ]", d) } b = b[1+l:] } diff --git a/attr.go b/attr.go index d1ae09d..e1a9609 100644 --- a/attr.go +++ b/attr.go @@ -1,6 +1,6 @@ package gatt -import "log" +import log "github.com/sirupsen/logrus" // attr is a BLE attribute. It is not exported; // managing attributes is an implementation detail. diff --git a/central_darwin.go b/central_darwin.go index 3f18bcc..1a60de4 100644 --- a/central_darwin.go +++ b/central_darwin.go @@ -3,7 +3,7 @@ package gatt import ( "sync" - "github.com/paypal/gatt/xpc" + "github.com/XC-/gatt/xpc" ) type central struct { diff --git a/device_darwin.go b/device_darwin.go index 9504b4b..c7280b3 100644 --- a/device_darwin.go +++ b/device_darwin.go @@ -5,11 +5,11 @@ import ( "encoding/binary" "errors" "fmt" - "log" + log "github.com/sirupsen/logrus" "sync" "time" - "github.com/paypal/gatt/xpc" + "github.com/XC-/gatt/xpc" ) const ( diff --git a/device_linux.go b/device_linux.go index f6f9fb1..73e9f1a 100644 --- a/device_linux.go +++ b/device_linux.go @@ -2,10 +2,12 @@ package gatt import ( "encoding/binary" + "encoding/hex" + "fmt" "net" - "github.com/paypal/gatt/linux" - "github.com/paypal/gatt/linux/cmd" + "github.com/XC-/gatt/linux" + "github.com/XC-/gatt/linux/cmd" ) type device struct { @@ -94,6 +96,10 @@ func (d *device) Init(f func(Device, State)) error { } d.hci.AdvertisementHandler = func(pd *linux.PlatData) { a := &Advertisement{} + if hex.EncodeToString(pd.Address[:]) != "d8c672d8cf87" { + return + } + fmt.Println(pd.Name+": "+string(pd.AddressType)+" "+hex.EncodeToString(pd.Address[:])) a.unmarshall(pd.Data) a.Connectable = pd.Connectable p := &peripheral{pd: pd, d: d} diff --git a/examples/discoverer.go b/examples/discoverer.go index 2757856..e1e4291 100644 --- a/examples/discoverer.go +++ b/examples/discoverer.go @@ -4,10 +4,10 @@ package main import ( "fmt" - "log" + log "github.com/sirupsen/logrus" - "github.com/paypal/gatt" - "github.com/paypal/gatt/examples/option" + "github.com/XC-/gatt" + "github.com/XC-/gatt/examples/option" ) func onStateChanged(d gatt.Device, s gatt.State) { diff --git a/examples/explorer.go b/examples/explorer.go index c7c0834..0c0a083 100644 --- a/examples/explorer.go +++ b/examples/explorer.go @@ -5,13 +5,13 @@ package main import ( "flag" "fmt" - "log" + log "github.com/sirupsen/logrus" "os" "strings" "time" - "github.com/paypal/gatt" - "github.com/paypal/gatt/examples/option" + "github.com/XC-/gatt" + "github.com/XC-/gatt/examples/option" ) var done = make(chan struct{}) diff --git a/examples/option/option_darwin.go b/examples/option/option_darwin.go index 0c31390..f308a59 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/XC-/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..c24d2d4 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/XC-/gatt" + "github.com/XC-/gatt/linux/cmd" ) var DefaultClientOptions = []gatt.Option{ diff --git a/examples/server.go b/examples/server.go index 1ee5fe4..726737b 100644 --- a/examples/server.go +++ b/examples/server.go @@ -4,11 +4,11 @@ package main import ( "fmt" - "log" + log "github.com/sirupsen/logrus" - "github.com/paypal/gatt" - "github.com/paypal/gatt/examples/option" - "github.com/paypal/gatt/examples/service" + "github.com/XC-/gatt" + "github.com/XC-/gatt/examples/option" + "github.com/XC-/gatt/examples/service" ) func main() { diff --git a/examples/server_lnx.go b/examples/server_lnx.go index 88d4943..cd39718 100644 --- a/examples/server_lnx.go +++ b/examples/server_lnx.go @@ -6,12 +6,12 @@ import ( "bytes" "flag" "fmt" - "log" + log "github.com/sirupsen/logrus" "time" - "github.com/paypal/gatt" - "github.com/paypal/gatt/examples/service" - "github.com/paypal/gatt/linux/cmd" + "github.com/XC-/gatt" + "github.com/XC-/gatt/examples/service" + "github.com/XC-/gatt/linux/cmd" ) // server_lnx implements a GATT server. diff --git a/examples/service/battery.go b/examples/service/battery.go index ee5a9ab..8ea870e 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/XC-/gatt" func NewBatteryService() *gatt.Service { lv := byte(100) diff --git a/examples/service/count.go b/examples/service/count.go index fd88430..962146d 100644 --- a/examples/service/count.go +++ b/examples/service/count.go @@ -2,10 +2,10 @@ package service import ( "fmt" - "log" + log "github.com/sirupsen/logrus" "time" - "github.com/paypal/gatt" + "github.com/XC-/gatt" ) func NewCountService() *gatt.Service { diff --git a/examples/service/gap.go b/examples/service/gap.go index 4c2a4b2..c56b230 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/XC-/gatt" var ( attrGAPUUID = gatt.UUID16(0x1800) diff --git a/examples/service/gatt.go b/examples/service/gatt.go index 8ca29c3..54a8606 100644 --- a/examples/service/gatt.go +++ b/examples/service/gatt.go @@ -1,9 +1,9 @@ package service import ( - "log" + log "github.com/sirupsen/logrus" - "github.com/paypal/gatt" + "github.com/XC-/gatt" ) var ( diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..d2a5c11 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/XC-/gatt + +go 1.13 + +require github.com/sirupsen/logrus v1.4.2 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..2377f40 --- /dev/null +++ b/go.sum @@ -0,0 +1,10 @@ +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= +github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/linux/cmd/cmd.go b/linux/cmd/cmd.go index b3ea7b4..7cf12bd 100644 --- a/linux/cmd/cmd.go +++ b/linux/cmd/cmd.go @@ -5,10 +5,10 @@ import ( "errors" "fmt" "io" - "log" + log "github.com/sirupsen/logrus" - "github.com/paypal/gatt/linux/evt" - "github.com/paypal/gatt/linux/util" + "github.com/XC-/gatt/linux/evt" + "github.com/XC-/gatt/linux/util" ) type CmdParam interface { @@ -140,9 +140,9 @@ const ( hostCtl = 0x03 infoParam = 0x04 statusParam = 0x05 - testingCmd = 0X3E + testingCmd = 0x3E leCtl = 0x08 - vendorCmd = 0X3F + vendorCmd = 0x3F ) const ( diff --git a/linux/const.go b/linux/const.go index 8c0a140..00d40ae 100644 --- a/linux/const.go +++ b/linux/const.go @@ -4,11 +4,11 @@ type packetType uint8 // HCI Packet types const ( - typCommandPkt packetType = 0X01 - typACLDataPkt = 0X02 - typSCODataPkt = 0X03 - typEventPkt = 0X04 - typVendorPkt = 0XFF + typCommandPkt packetType = 0x01 + typACLDataPkt = 0x02 + typSCODataPkt = 0x03 + typEventPkt = 0x04 + typVendorPkt = 0xFF ) // Event Type diff --git a/linux/device.go b/linux/device.go index 9c18732..6ff8f50 100644 --- a/linux/device.go +++ b/linux/device.go @@ -2,13 +2,13 @@ package linux import ( "errors" - "log" + log "github.com/sirupsen/logrus" "sync" "syscall" "unsafe" - "github.com/paypal/gatt/linux/gioctl" - "github.com/paypal/gatt/linux/socket" + "github.com/XC-/gatt/linux/gioctl" + "github.com/XC-/gatt/linux/socket" ) type device struct { diff --git a/linux/devices.go b/linux/devices.go index c0d3c97..3db3888 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/XC-/gatt/linux/gioctl" const ( ioctlSize = uintptr(4) diff --git a/linux/evt/evt.go b/linux/evt/evt.go index 74f8aa3..28532ab 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/XC-/gatt/linux/util" ) type EventHandler interface { diff --git a/linux/hci.go b/linux/hci.go index ceaf97a..2bc9c33 100644 --- a/linux/hci.go +++ b/linux/hci.go @@ -3,11 +3,11 @@ package linux import ( "fmt" "io" - "log" + log "github.com/sirupsen/logrus" "sync" - "github.com/paypal/gatt/linux/cmd" - "github.com/paypal/gatt/linux/evt" + "github.com/XC-/gatt/linux/cmd" + "github.com/XC-/gatt/linux/evt" ) type HCI struct { diff --git a/linux/l2cap.go b/linux/l2cap.go index 1a03465..ea5e1e6 100644 --- a/linux/l2cap.go +++ b/linux/l2cap.go @@ -3,9 +3,9 @@ package linux import ( "fmt" "io" - "log" + log "github.com/sirupsen/logrus" - "github.com/paypal/gatt/linux/cmd" + "github.com/XC-/gatt/linux/cmd" ) type aclData struct { diff --git a/option_linux.go b/option_linux.go index 8bc6c46..ac74c6d 100644 --- a/option_linux.go +++ b/option_linux.go @@ -4,7 +4,7 @@ import ( "errors" "io" - "github.com/paypal/gatt/linux/cmd" + "github.com/XC-/gatt/linux/cmd" ) // LnxDeviceID specifies which HCI device to use. diff --git a/option_linux_test.go b/option_linux_test.go index 1eeca7a..8c9c875 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/XC-/gatt/linux/cmd" ) func ExampleLnxDeviceID() { diff --git a/peripheral_darwin.go b/peripheral_darwin.go index bbe4dca..f337a5e 100644 --- a/peripheral_darwin.go +++ b/peripheral_darwin.go @@ -2,9 +2,9 @@ package gatt import ( "errors" - "log" + log "github.com/sirupsen/logrus" - "github.com/paypal/gatt/xpc" + "github.com/XC-/gatt/xpc" ) type peripheral struct { diff --git a/peripheral_linux.go b/peripheral_linux.go index ce256fa..0525f38 100644 --- a/peripheral_linux.go +++ b/peripheral_linux.go @@ -6,11 +6,11 @@ import ( "errors" "fmt" "io" - "log" + log "github.com/sirupsen/logrus" "net" "strings" - "github.com/paypal/gatt/linux" + "github.com/XC-/gatt/linux" ) type peripheral struct { diff --git a/xpc/xpc_darwin.go b/xpc/xpc_darwin.go index 2a85a99..b36e937 100644 --- a/xpc/xpc_darwin.go +++ b/xpc/xpc_darwin.go @@ -9,7 +9,7 @@ import "C" import ( "errors" "fmt" - "log" + log "github.com/sirupsen/logrus" r "reflect" "unsafe" )