From d2372c209ab86cffd672b0c6a4a8e0135a0788b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aki=20M=C3=A4kinen?= Date: Fri, 29 Nov 2019 00:41:18 +0200 Subject: [PATCH 1/4] feat: migrate to go modules, switch logging library --- .gitignore | 1 + adv.go | 2 +- attr.go | 2 +- central_darwin.go | 2 +- device_darwin.go | 4 ++-- device_linux.go | 4 ++-- examples/discoverer.go | 6 +++--- examples/explorer.go | 6 +++--- examples/option/option_darwin.go | 2 +- examples/option/option_linux.go | 4 ++-- examples/server.go | 8 ++++---- examples/server_lnx.go | 8 ++++---- examples/service/battery.go | 2 +- examples/service/count.go | 4 ++-- examples/service/gap.go | 2 +- examples/service/gatt.go | 4 ++-- go.mod | 5 +++++ go.sum | 7 +++++++ linux/cmd/cmd.go | 10 +++++----- linux/const.go | 10 +++++----- linux/device.go | 6 +++--- linux/devices.go | 2 +- linux/evt/evt.go | 2 +- linux/hci.go | 6 +++--- linux/l2cap.go | 4 ++-- option_linux.go | 2 +- option_linux_test.go | 2 +- peripheral_darwin.go | 4 ++-- peripheral_linux.go | 4 ++-- xpc/xpc_darwin.go | 2 +- 30 files changed, 70 insertions(+), 57 deletions(-) create mode 100644 go.mod create mode 100644 go.sum 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..2a9dbc4 100644 --- a/adv.go +++ b/adv.go @@ -2,7 +2,7 @@ package gatt import ( "errors" - "log" + log "github.com/sirupsen/logrus" ) // MaxEIRPacketLength is the maximum allowed AdvertisingPacket 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..668996a 100644 --- a/central_darwin.go +++ b/central_darwin.go @@ -3,7 +3,7 @@ package gatt import ( "sync" - "github.com/paypal/gatt/xpc" + "gatt/xpc" ) type central struct { diff --git a/device_darwin.go b/device_darwin.go index 9504b4b..cc66fe3 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" + "gatt/xpc" ) const ( diff --git a/device_linux.go b/device_linux.go index f6f9fb1..3110c76 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" + "gatt/linux" + "gatt/linux/cmd" ) type device struct { diff --git a/examples/discoverer.go b/examples/discoverer.go index 2757856..3843c74 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" + "gatt" + "gatt/examples/option" ) func onStateChanged(d gatt.Device, s gatt.State) { diff --git a/examples/explorer.go b/examples/explorer.go index c7c0834..641d15d 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" + "gatt" + "gatt/examples/option" ) var done = make(chan struct{}) diff --git a/examples/option/option_darwin.go b/examples/option/option_darwin.go index 0c31390..fa27541 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 "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..f3e3790 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" + "gatt" + "gatt/linux/cmd" ) var DefaultClientOptions = []gatt.Option{ diff --git a/examples/server.go b/examples/server.go index 1ee5fe4..1ac2067 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" + "gatt" + "gatt/examples/option" + "gatt/examples/service" ) func main() { diff --git a/examples/server_lnx.go b/examples/server_lnx.go index 88d4943..1df8c41 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" + "gatt" + "gatt/examples/service" + "gatt/linux/cmd" ) // server_lnx implements a GATT server. diff --git a/examples/service/battery.go b/examples/service/battery.go index ee5a9ab..965a8e0 100644 --- a/examples/service/battery.go +++ b/examples/service/battery.go @@ -1,6 +1,6 @@ package service -import "github.com/paypal/gatt" +import "gatt" func NewBatteryService() *gatt.Service { lv := byte(100) diff --git a/examples/service/count.go b/examples/service/count.go index fd88430..0783470 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" + "gatt" ) func NewCountService() *gatt.Service { diff --git a/examples/service/gap.go b/examples/service/gap.go index 4c2a4b2..2f3f3a5 100644 --- a/examples/service/gap.go +++ b/examples/service/gap.go @@ -1,6 +1,6 @@ package service -import "github.com/paypal/gatt" +import "gatt" var ( attrGAPUUID = gatt.UUID16(0x1800) diff --git a/examples/service/gatt.go b/examples/service/gatt.go index 8ca29c3..c1d281b 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" + "gatt" ) var ( diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..7a70f7f --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module 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..400b0b0 --- /dev/null +++ b/go.sum @@ -0,0 +1,7 @@ +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/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/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/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/linux/cmd/cmd.go b/linux/cmd/cmd.go index b3ea7b4..5c60ffc 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" + "gatt/linux/evt" + "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..d6afb03 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" + "gatt/linux/gioctl" + "gatt/linux/socket" ) type device struct { diff --git a/linux/devices.go b/linux/devices.go index c0d3c97..f65f0e3 100644 --- a/linux/devices.go +++ b/linux/devices.go @@ -1,6 +1,6 @@ package linux -import "github.com/paypal/gatt/linux/gioctl" +import "gatt/linux/gioctl" const ( ioctlSize = uintptr(4) diff --git a/linux/evt/evt.go b/linux/evt/evt.go index 74f8aa3..77f36bb 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" + "gatt/linux/util" ) type EventHandler interface { diff --git a/linux/hci.go b/linux/hci.go index ceaf97a..46daf70 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" + "gatt/linux/cmd" + "gatt/linux/evt" ) type HCI struct { diff --git a/linux/l2cap.go b/linux/l2cap.go index 1a03465..8d07a1d 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" + "gatt/linux/cmd" ) type aclData struct { diff --git a/option_linux.go b/option_linux.go index 8bc6c46..faf90bc 100644 --- a/option_linux.go +++ b/option_linux.go @@ -4,7 +4,7 @@ import ( "errors" "io" - "github.com/paypal/gatt/linux/cmd" + "gatt/linux/cmd" ) // LnxDeviceID specifies which HCI device to use. diff --git a/option_linux_test.go b/option_linux_test.go index 1eeca7a..1b25a48 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" + "gatt/linux/cmd" ) func ExampleLnxDeviceID() { diff --git a/peripheral_darwin.go b/peripheral_darwin.go index bbe4dca..ba7e990 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" + "gatt/xpc" ) type peripheral struct { diff --git a/peripheral_linux.go b/peripheral_linux.go index ce256fa..ecb41ff 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" + "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" ) From a61c96a2bd67b0cacf6874406d09babc8f2b0376 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aki=20M=C3=A4kinen?= Date: Fri, 29 Nov 2019 00:48:49 +0200 Subject: [PATCH 2/4] build: fix module name --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 7a70f7f..d2a5c11 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module gatt +module github.com/XC-/gatt go 1.13 From 2500d08c7d4daf38bf595bdc72c3be28d093a30c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aki=20M=C3=A4kinen?= Date: Fri, 29 Nov 2019 00:53:28 +0200 Subject: [PATCH 3/4] fix: fix imports --- central_darwin.go | 2 +- device_darwin.go | 2 +- device_linux.go | 4 ++-- examples/discoverer.go | 4 ++-- examples/explorer.go | 4 ++-- examples/option/option_darwin.go | 2 +- examples/option/option_linux.go | 4 ++-- examples/server.go | 6 +++--- examples/server_lnx.go | 6 +++--- examples/service/battery.go | 2 +- examples/service/count.go | 2 +- examples/service/gap.go | 2 +- examples/service/gatt.go | 2 +- linux/cmd/cmd.go | 4 ++-- linux/device.go | 4 ++-- linux/devices.go | 2 +- linux/evt/evt.go | 2 +- linux/hci.go | 4 ++-- linux/l2cap.go | 2 +- option_linux.go | 2 +- option_linux_test.go | 2 +- peripheral_darwin.go | 2 +- peripheral_linux.go | 2 +- 23 files changed, 34 insertions(+), 34 deletions(-) diff --git a/central_darwin.go b/central_darwin.go index 668996a..1a60de4 100644 --- a/central_darwin.go +++ b/central_darwin.go @@ -3,7 +3,7 @@ package gatt import ( "sync" - "gatt/xpc" + "github.com/XC-/gatt/xpc" ) type central struct { diff --git a/device_darwin.go b/device_darwin.go index cc66fe3..c7280b3 100644 --- a/device_darwin.go +++ b/device_darwin.go @@ -9,7 +9,7 @@ import ( "sync" "time" - "gatt/xpc" + "github.com/XC-/gatt/xpc" ) const ( diff --git a/device_linux.go b/device_linux.go index 3110c76..3f74704 100644 --- a/device_linux.go +++ b/device_linux.go @@ -4,8 +4,8 @@ import ( "encoding/binary" "net" - "gatt/linux" - "gatt/linux/cmd" + "github.com/XC-/gatt/linux" + "github.com/XC-/gatt/linux/cmd" ) type device struct { diff --git a/examples/discoverer.go b/examples/discoverer.go index 3843c74..e1e4291 100644 --- a/examples/discoverer.go +++ b/examples/discoverer.go @@ -6,8 +6,8 @@ import ( "fmt" log "github.com/sirupsen/logrus" - "gatt" - "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 641d15d..0c0a083 100644 --- a/examples/explorer.go +++ b/examples/explorer.go @@ -10,8 +10,8 @@ import ( "strings" "time" - "gatt" - "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 fa27541..f308a59 100644 --- a/examples/option/option_darwin.go +++ b/examples/option/option_darwin.go @@ -1,6 +1,6 @@ package option -import "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 f3e3790..c24d2d4 100644 --- a/examples/option/option_linux.go +++ b/examples/option/option_linux.go @@ -1,8 +1,8 @@ package option import ( - "gatt" - "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 1ac2067..726737b 100644 --- a/examples/server.go +++ b/examples/server.go @@ -6,9 +6,9 @@ import ( "fmt" log "github.com/sirupsen/logrus" - "gatt" - "gatt/examples/option" - "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 1df8c41..cd39718 100644 --- a/examples/server_lnx.go +++ b/examples/server_lnx.go @@ -9,9 +9,9 @@ import ( log "github.com/sirupsen/logrus" "time" - "gatt" - "gatt/examples/service" - "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 965a8e0..8ea870e 100644 --- a/examples/service/battery.go +++ b/examples/service/battery.go @@ -1,6 +1,6 @@ package service -import "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 0783470..962146d 100644 --- a/examples/service/count.go +++ b/examples/service/count.go @@ -5,7 +5,7 @@ import ( log "github.com/sirupsen/logrus" "time" - "gatt" + "github.com/XC-/gatt" ) func NewCountService() *gatt.Service { diff --git a/examples/service/gap.go b/examples/service/gap.go index 2f3f3a5..c56b230 100644 --- a/examples/service/gap.go +++ b/examples/service/gap.go @@ -1,6 +1,6 @@ package service -import "gatt" +import "github.com/XC-/gatt" var ( attrGAPUUID = gatt.UUID16(0x1800) diff --git a/examples/service/gatt.go b/examples/service/gatt.go index c1d281b..54a8606 100644 --- a/examples/service/gatt.go +++ b/examples/service/gatt.go @@ -3,7 +3,7 @@ package service import ( log "github.com/sirupsen/logrus" - "gatt" + "github.com/XC-/gatt" ) var ( diff --git a/linux/cmd/cmd.go b/linux/cmd/cmd.go index 5c60ffc..7cf12bd 100644 --- a/linux/cmd/cmd.go +++ b/linux/cmd/cmd.go @@ -7,8 +7,8 @@ import ( "io" log "github.com/sirupsen/logrus" - "gatt/linux/evt" - "gatt/linux/util" + "github.com/XC-/gatt/linux/evt" + "github.com/XC-/gatt/linux/util" ) type CmdParam interface { diff --git a/linux/device.go b/linux/device.go index d6afb03..6ff8f50 100644 --- a/linux/device.go +++ b/linux/device.go @@ -7,8 +7,8 @@ import ( "syscall" "unsafe" - "gatt/linux/gioctl" - "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 f65f0e3..3db3888 100644 --- a/linux/devices.go +++ b/linux/devices.go @@ -1,6 +1,6 @@ package linux -import "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 77f36bb..28532ab 100644 --- a/linux/evt/evt.go +++ b/linux/evt/evt.go @@ -5,7 +5,7 @@ import ( "encoding/binary" "errors" - "gatt/linux/util" + "github.com/XC-/gatt/linux/util" ) type EventHandler interface { diff --git a/linux/hci.go b/linux/hci.go index 46daf70..2bc9c33 100644 --- a/linux/hci.go +++ b/linux/hci.go @@ -6,8 +6,8 @@ import ( log "github.com/sirupsen/logrus" "sync" - "gatt/linux/cmd" - "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 8d07a1d..ea5e1e6 100644 --- a/linux/l2cap.go +++ b/linux/l2cap.go @@ -5,7 +5,7 @@ import ( "io" log "github.com/sirupsen/logrus" - "gatt/linux/cmd" + "github.com/XC-/gatt/linux/cmd" ) type aclData struct { diff --git a/option_linux.go b/option_linux.go index faf90bc..ac74c6d 100644 --- a/option_linux.go +++ b/option_linux.go @@ -4,7 +4,7 @@ import ( "errors" "io" - "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 1b25a48..8c9c875 100644 --- a/option_linux_test.go +++ b/option_linux_test.go @@ -3,7 +3,7 @@ package gatt import ( "bytes" - "gatt/linux/cmd" + "github.com/XC-/gatt/linux/cmd" ) func ExampleLnxDeviceID() { diff --git a/peripheral_darwin.go b/peripheral_darwin.go index ba7e990..f337a5e 100644 --- a/peripheral_darwin.go +++ b/peripheral_darwin.go @@ -4,7 +4,7 @@ import ( "errors" log "github.com/sirupsen/logrus" - "gatt/xpc" + "github.com/XC-/gatt/xpc" ) type peripheral struct { diff --git a/peripheral_linux.go b/peripheral_linux.go index ecb41ff..0525f38 100644 --- a/peripheral_linux.go +++ b/peripheral_linux.go @@ -10,7 +10,7 @@ import ( "net" "strings" - "gatt/linux" + "github.com/XC-/gatt/linux" ) type peripheral struct { From aae991cc9d0da570cd103a2feff1d3064fdb0b7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aki=20M=C3=A4kinen?= Date: Mon, 13 Apr 2020 18:02:21 +0300 Subject: [PATCH 4/4] fix: Log data at info level --- adv.go | 12 ++++++++++-- device_linux.go | 6 ++++++ go.sum | 3 +++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/adv.go b/adv.go index 2a9dbc4..9a3539f 100644 --- a/adv.go +++ b/adv.go @@ -2,6 +2,7 @@ package gatt import ( "errors" + "fmt" log "github.com/sirupsen/logrus" ) @@ -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/device_linux.go b/device_linux.go index 3f74704..73e9f1a 100644 --- a/device_linux.go +++ b/device_linux.go @@ -2,6 +2,8 @@ package gatt import ( "encoding/binary" + "encoding/hex" + "fmt" "net" "github.com/XC-/gatt/linux" @@ -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/go.sum b/go.sum index 400b0b0..2377f40 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +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=