Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5613a57
expose hci up down
Mar 14, 2018
1dd6d60
Fix cancel via context and respect context deadline (#14)
moogle19 Mar 16, 2018
1e3172f
scan full advertising packet for UUIDs (#16)
estutzenberger Mar 16, 2018
582be3b
fill in char and desc values on successful read (#15)
estutzenberger Apr 4, 2018
721d240
Rollback 619ee1f77e2de4a17af8786baa9c08b1c77e442e
moogle19 Apr 4, 2018
7370f1c
Refinement (#19)
moogle19 May 24, 2018
b4a677b
Add isConnected field to darwin.conn type (#25)
jlubawy Jul 18, 2018
11b1dad
Add lock for sent map (#22)
moogle19 Jul 18, 2018
731710e
Add Conn method to Client interface (#26)
jlubawy Aug 14, 2018
c9d4987
Fixes OSX unsupported key for MTU (#30)
xibz Aug 31, 2018
e78417b
Add option to pass HCI options when creating a device (#28)
Oct 2, 2018
c598225
added list
muka Feb 8, 2019
27e2a04
added deps
lc-spxl May 11, 2019
e4c7701
Update README.md
moogle19 May 13, 2019
147700f
Some fixes and QoL improvements (#45)
estutzenberger May 21, 2019
5328f95
linux.hci: fix stop advertise on new connection
rkjdid Aug 2, 2019
31b5b19
hci: add Connect/DisconnectHandler options
rkjdid Jul 28, 2019
27f6032
linux.hci: do not exit sktLoop on handlePacket error (#51)
rkjdid Jan 9, 2020
6e59c69
add go.mod/sum (#54)
cbrake Jan 9, 2020
5ba052e
remove log entry
rkjdid Jan 10, 2020
0105c68
Merge pull request #50 from rkjdid/conn-handlers
estutzenberger Jan 10, 2020
67ae735
Merge pull request #49 from rkjdid/fix-stop-advertise
estutzenberger Jan 10, 2020
15dbdb1
re-adding log
armaanhammer Jan 17, 2020
0a73a9d
Merge pull request #58 from armaanhammer/isolate-bugfix-from-tempfix
estutzenberger Jan 20, 2020
53527f8
Merge branch 'master' of https://github.com/go-ble/ble
muka Jan 26, 2020
21cb16e
rename go.mod
muka Mar 31, 2020
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
.tags1

/examples/bin/*
vendor
.idea
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ os:
- linux

go:
- 1.7
- 1.8
- 1.9
- tip
Expand Down
112 changes: 112 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Gopkg.toml example
#
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true


[[constraint]]
branch = "master"
name = "github.com/go-ble/ble"

[[constraint]]
name = "github.com/mgutz/logxi"
version = "1.0.0"

[[constraint]]
name = "github.com/pkg/errors"
version = "0.8.1"

[[constraint]]
branch = "master"
name = "github.com/raff/goble"

[[constraint]]
name = "github.com/urfave/cli"
version = "1.20.0"

[[constraint]]
branch = "master"
name = "golang.org/x/sys"

[prune]
go-tests = true
unused-packages = true
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
[![codebeat badge](https://codebeat.co/badges/ba9fae6e-77d2-4173-8587-36ac8756676b)](https://codebeat.co/projects/github-com-go-ble-ble-master)
[![Build Status](https://travis-ci.org/go-ble/ble.svg?branch=master)](https://travis-ci.org/go-ble/ble)

**ble** is a Golang [Bluetooth Low Energy](https://en.wikipedia.org/wiki/Bluetooth_Low_Energy) package for Linux and Mac OS.


**ble** is a [Bluetooth Low Energy](https://en.wikipedia.org/wiki/Bluetooth_Low_Energy) package for Linux and macOS.

**Note:** The Mac OS portion is not being actively maintained.
3 changes: 3 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,7 @@ type Client interface {

// Disconnected returns a receiving channel, which is closed when the client disconnects.
Disconnected() <-chan struct{}

// Conn returns the client's current connection.
Conn() Conn
}
7 changes: 7 additions & 0 deletions darwin/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ func (cln *Client) ReadCharacteristic(c *ble.Characteristic) ([]byte, error) {
if rsp.err() != nil {
return nil, rsp.err()
}
c.Value = rsp.data()
return rsp.data(), nil
}

Expand Down Expand Up @@ -215,6 +216,7 @@ func (cln *Client) ReadDescriptor(d *ble.Descriptor) ([]byte, error) {
if err := rsp.err(); err != nil {
return nil, err
}
d.Value = rsp.data()
return rsp.data(), nil
}

Expand Down Expand Up @@ -318,6 +320,11 @@ func (cln *Client) Disconnected() <-chan struct{} {
return cln.conn.Disconnected()
}

// Conn returns the client's current connection.
func (cln *Client) Conn() ble.Conn {
return cln.conn
}

type sub struct {
fn ble.NotificationHandler
char *ble.Characteristic
Expand Down
8 changes: 6 additions & 2 deletions darwin/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"github.com/raff/goble/xpc"
)

func newConn(d *Device, a ble.Addr) *conn {
func newConn(d *Device, a ble.Addr, rxMTU int) *conn {
return &conn{
dev: d,
rxMTU: 23,
rxMTU: rxMTU,
txMTU: 23,
addr: a,
done: make(chan struct{}),
Expand Down Expand Up @@ -43,6 +43,8 @@ type conn struct {
notifiers map[uint16]ble.Notifier // central connection only

subs map[uint16]*sub

isConnected bool
}

func (c *conn) Context() context.Context {
Expand Down Expand Up @@ -75,7 +77,9 @@ func (c *conn) TxMTU() int {
}

func (c *conn) SetTxMTU(mtu int) {
c.Lock()
c.txMTU = mtu
c.Unlock()
}

func (c *conn) Read(b []byte) (int, error) {
Expand Down
13 changes: 9 additions & 4 deletions darwin/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type Device struct {
}

// NewDevice returns a BLE device.
func NewDevice(opts ...Option) (*Device, error) {
func NewDevice(opts ...ble.Option) (*Device, error) {
err := initXpcIDs()
if err != nil {
return nil, err
Expand All @@ -61,7 +61,7 @@ func NewDevice(opts ...Option) (*Device, error) {
}

// Option sets the options specified.
func (d *Device) Option(opts ...Option) error {
func (d *Device) Option(opts ...ble.Option) error {
var err error
for _, opt := range opts {
err = opt(d)
Expand Down Expand Up @@ -489,10 +489,15 @@ func (d *Device) HandleXpcEvent(event xpc.Dict, err error) {
d.conn(args).unsubscribed(d.chars[args.attributeID()])

case evtPeripheralConnected:
d.chConn <- d.conn(args)
c := d.conn(args)
if !c.isConnected {
c.isConnected = true
d.chConn <- c
}

case evtPeripheralDisconnected:
c := d.conn(args)
c.isConnected = false
select {
case c.rspc <- m:
// Canceled by local central synchronously
Expand Down Expand Up @@ -541,7 +546,7 @@ func (d *Device) conn(m msg) *conn {
d.connLock.Lock()
c, ok := d.conns[a.String()]
if !ok {
c = newConn(d, a)
c = newConn(d, a, m.attMTU())
d.conns[a.String()] = c
}
d.connLock.Unlock()
Expand Down
7 changes: 6 additions & 1 deletion darwin/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ func (m msg) args() xpc.Dict { return xpc.Dict(m).MustGetDict("kCBMsgArgs") }
func (m msg) advertisementData() xpc.Dict {
return xpc.Dict(m).MustGetDict("kCBMsgArgAdvertisementData")
}
func (m msg) attMTU() int { return xpc.Dict(m).MustGetInt("kCBMsgArgATTMTU") }

const macOSXDefaultMTU = 23

// Uses GetInt as oppose to MustGetInt due to OSX not supporting 'kCBMsgArgATTMTU'.
// Issue #29
func (m msg) attMTU() int { return xpc.Dict(m).GetInt("kCBMsgArgATTMTU", macOSXDefaultMTU) }
func (m msg) attWrites() xpc.Array { return xpc.Dict(m).MustGetArray("kCBMsgArgATTWrites") }
func (m msg) attributeID() int { return xpc.Dict(m).MustGetInt("kCBMsgArgAttributeID") }
func (m msg) characteristicHandle() int {
Expand Down
64 changes: 47 additions & 17 deletions darwin/option.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,50 @@
package darwin

// An Option is a configuration function, which configures the device.
type Option func(*Device) error

// OptPeripheralRole configures the device to perform Peripheral tasks.
func OptPeripheralRole() Option {
return func(d *Device) error {
d.role = 1
return nil
}
}

// OptCentralRole configures the device to perform Central tasks.
func OptCentralRole() Option {
return func(d *Device) error {
d.role = 0
return nil
}
import (
"errors"
"time"

"github.com/go-ble/ble/linux/hci/cmd"
)

// SetPeripheralRole configures the device to perform Peripheral tasks.
func (d *Device) SetPeripheralRole() error {
d.role = 1
return nil
}

// SetCentralRole configures the device to perform Central tasks.
func (d *Device) SetCentralRole() error {
d.role = 0
return nil
}

// SetDeviceID sets HCI device ID.
func (d *Device) SetDeviceID(id int) error {
return errors.New("Not supported")
}

// SetDialerTimeout sets dialing timeout for Dialer.
func (d *Device) SetDialerTimeout(dur time.Duration) error {
return errors.New("Not supported")
}

// SetListenerTimeout sets dialing timeout for Listener.
func (d *Device) SetListenerTimeout(dur time.Duration) error {
return errors.New("Not supported")
}

// SetConnParams overrides default connection parameters.
func (d *Device) SetConnParams(param cmd.LECreateConnection) error {
return errors.New("Not supported")
}

// SetScanParams overrides default scanning parameters.
func (d *Device) SetScanParams(param cmd.LESetScanParameters) error {
return errors.New("Not supported")
}

// SetAdvParams overrides default advertising parameters.
func (d *Device) SetAdvParams(param cmd.LESetAdvertisingParameters) error {
return errors.New("Not supported")
}
Loading