Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migrate to go modules, switch logging library #109

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
c.out
c/*-ble
sample
.idea
14 changes: 11 additions & 3 deletions adv.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package gatt

import (
"errors"
"log"
"fmt"
log "github.com/sirupsen/logrus"
)

// MaxEIRPacketLength is the maximum allowed AdvertisingPacket
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:]
}
Expand Down
2 changes: 1 addition & 1 deletion attr.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion central_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package gatt
import (
"sync"

"github.com/paypal/gatt/xpc"
"github.com/XC-/gatt/xpc"
)

type central struct {
Expand Down
4 changes: 2 additions & 2 deletions device_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
10 changes: 8 additions & 2 deletions device_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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}
Expand Down
6 changes: 3 additions & 3 deletions examples/discoverer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions examples/explorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down
2 changes: 1 addition & 1 deletion examples/option/option_darwin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package option

import "github.com/paypal/gatt"
import "github.com/XC-/gatt"

var DefaultClientOptions = []gatt.Option{
gatt.MacDeviceRole(gatt.CentralManager),
Expand Down
4 changes: 2 additions & 2 deletions examples/option/option_linux.go
Original file line number Diff line number Diff line change
@@ -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{
Expand Down
8 changes: 4 additions & 4 deletions examples/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
8 changes: 4 additions & 4 deletions examples/server_lnx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion examples/service/battery.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package service

import "github.com/paypal/gatt"
import "github.com/XC-/gatt"

func NewBatteryService() *gatt.Service {
lv := byte(100)
Expand Down
4 changes: 2 additions & 2 deletions examples/service/count.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion examples/service/gap.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package service

import "github.com/paypal/gatt"
import "github.com/XC-/gatt"

var (
attrGAPUUID = gatt.UUID16(0x1800)
Expand Down
4 changes: 2 additions & 2 deletions examples/service/gatt.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package service

import (
"log"
log "github.com/sirupsen/logrus"

"github.com/paypal/gatt"
"github.com/XC-/gatt"
)

var (
Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/XC-/gatt

go 1.13

require github.com/sirupsen/logrus v1.4.2
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
10 changes: 5 additions & 5 deletions linux/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -140,9 +140,9 @@ const (
hostCtl = 0x03
infoParam = 0x04
statusParam = 0x05
testingCmd = 0X3E
testingCmd = 0x3E
leCtl = 0x08
vendorCmd = 0X3F
vendorCmd = 0x3F
)

const (
Expand Down
10 changes: 5 additions & 5 deletions linux/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions linux/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion linux/devices.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package linux

import "github.com/paypal/gatt/linux/gioctl"
import "github.com/XC-/gatt/linux/gioctl"

const (
ioctlSize = uintptr(4)
Expand Down
2 changes: 1 addition & 1 deletion linux/evt/evt.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/binary"
"errors"

"github.com/paypal/gatt/linux/util"
"github.com/XC-/gatt/linux/util"
)

type EventHandler interface {
Expand Down
6 changes: 3 additions & 3 deletions linux/hci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions linux/l2cap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion option_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion option_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package gatt
import (
"bytes"

"github.com/paypal/gatt/linux/cmd"
"github.com/XC-/gatt/linux/cmd"
)

func ExampleLnxDeviceID() {
Expand Down
4 changes: 2 additions & 2 deletions peripheral_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions peripheral_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion xpc/xpc_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import "C"
import (
"errors"
"fmt"
"log"
log "github.com/sirupsen/logrus"
r "reflect"
"unsafe"
)
Expand Down