macos: starting point for adding macOS support
Signed-off-by: Ron Evans <ron@hybridgroup.com>
This commit is contained in:
parent
40e14a41fc
commit
51b2b4c2b2
4
Makefile
4
Makefile
@ -35,3 +35,7 @@ smoketest-linux:
|
||||
smoketest-windows:
|
||||
# Test on Windows.
|
||||
GOOS=windows CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc go build -o /tmp/go-build-discard ./examples/scanner
|
||||
|
||||
smoketest-macos:
|
||||
# Test on macos.
|
||||
GOOS=darwin CGO_ENABLED=1 go build -o /tmp/go-build-discard ./examples/scanner
|
||||
|
22
README.md
22
README.md
@ -5,17 +5,17 @@
|
||||
|
||||
This package attempts to build a cross-platform Bluetooth Low Energy module for Go. It currently supports the following systems:
|
||||
|
||||
| | Windows | Linux | Nordic chips |
|
||||
| -------------------------------- | ------------------ | ------------------ | ------------------ |
|
||||
| API used | WinRT | BlueZ (over D-Bus) | SoftDevice |
|
||||
| Scanning | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Connect to peripheral | :x: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Write peripheral characteristics | :x: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Receive notifications | :x: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Advertisement | :x: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Local services | :x: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Local characteristics | :x: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Send notifications | :x: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| | Windows | Linux | Nordic chips | macOS |
|
||||
| -------------------------------- | ------------------ | ------------------ | ------------------ | ------------------ |
|
||||
| API used | WinRT | BlueZ (over D-Bus) | SoftDevice | CoreBluetooth |
|
||||
| Scanning | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: |
|
||||
| Connect to peripheral | :x: | :heavy_check_mark: | :heavy_check_mark: | :x: |
|
||||
| Write peripheral characteristics | :x: | :heavy_check_mark: | :heavy_check_mark: | :x: |
|
||||
| Receive notifications | :x: | :heavy_check_mark: | :heavy_check_mark: | :x: |
|
||||
| Advertisement | :x: | :heavy_check_mark: | :heavy_check_mark: | :x: |
|
||||
| Local services | :x: | :heavy_check_mark: | :heavy_check_mark: | :x: |
|
||||
| Local characteristics | :x: | :heavy_check_mark: | :heavy_check_mark: | :x: |
|
||||
| Send notifications | :x: | :heavy_check_mark: | :heavy_check_mark: | :x: |
|
||||
|
||||
## Baremetal support
|
||||
|
||||
|
23
adapter_darwin.go
Normal file
23
adapter_darwin.go
Normal file
@ -0,0 +1,23 @@
|
||||
package bluetooth
|
||||
|
||||
import (
|
||||
"github.com/JuulLabs-OSS/cbgo"
|
||||
"github.com/tinygo-org/bluetooth/macbt"
|
||||
)
|
||||
|
||||
type Adapter struct {
|
||||
cm cbgo.CentralManager
|
||||
cmd macbt.CMDelegate
|
||||
}
|
||||
|
||||
// DefaultAdapter is the default adapter on the system.
|
||||
//
|
||||
// Make sure to call Enable() before using it to initialize the adapter.
|
||||
var DefaultAdapter = &Adapter{}
|
||||
|
||||
// Enable configures the BLE stack. It must be called before any
|
||||
// Bluetooth-related calls (unless otherwise indicated).
|
||||
func (a *Adapter) Enable() error {
|
||||
a.cm = cbgo.NewCentralManager(nil)
|
||||
return nil
|
||||
}
|
14
gap_darwin.go
Normal file
14
gap_darwin.go
Normal file
@ -0,0 +1,14 @@
|
||||
package bluetooth
|
||||
|
||||
// Scan starts a BLE scan. It is stopped by a call to StopScan. A common pattern
|
||||
// is to cancel the scan when a particular device has been found.
|
||||
func (a *Adapter) Scan(callback func(*Adapter, ScanResult)) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// StopScan stops any in-progress scan. It can be called from within a Scan
|
||||
// callback to stop the current scan. If no scan is in progress, an error will
|
||||
// be returned.
|
||||
func (a *Adapter) StopScan() error {
|
||||
return nil
|
||||
}
|
3
go.mod
3
go.mod
@ -3,8 +3,11 @@ module github.com/tinygo-org/bluetooth
|
||||
go 1.14
|
||||
|
||||
require (
|
||||
github.com/JuulLabs-OSS/cbgo v0.0.2
|
||||
github.com/go-ole/go-ole v1.2.4
|
||||
github.com/godbus/dbus/v5 v5.0.3
|
||||
github.com/muka/go-bluetooth v0.0.0-20200619025933-f6113f7141c5
|
||||
github.com/sirupsen/logrus v1.6.0 // indirect
|
||||
golang.org/x/crypto v0.0.0-20200602180216-279210d13fed
|
||||
golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6 // indirect
|
||||
)
|
||||
|
9
go.sum
9
go.sum
@ -1,3 +1,5 @@
|
||||
github.com/JuulLabs-OSS/cbgo v0.0.2 h1:gCDyT0+EPuI8GOFyvAksFcVD2vF4CXBAVwT6uVnD9oo=
|
||||
github.com/JuulLabs-OSS/cbgo v0.0.2/go.mod h1:L4YtGP+gnyD84w7+jN66ncspFRfOYB5aj9QSXaFHmBA=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
|
||||
@ -8,7 +10,10 @@ github.com/godbus/dbus/v5 v5.0.3 h1:ZqHaoEF7TBzh4jzPmqVhE/5A1z9of6orkAe5uHoAeME=
|
||||
github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
@ -19,6 +24,8 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/sirupsen/logrus v1.5.0 h1:1N5EYkVAPEywqZRJd7cwnRtCb6xJx7NH3T3WUTF980Q=
|
||||
github.com/sirupsen/logrus v1.5.0/go.mod h1:+F7Ogzej0PZc/94MaYx/nvG9jOFMD2osvC3s+Squfpo=
|
||||
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
|
||||
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
@ -32,6 +39,8 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200331124033-c3d80250170d h1:nc5K6ox/4lTFbMVSL9WRR81ixkcwXThoiF6yf+R9scA=
|
||||
golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6 h1:DvY3Zkh7KabQE/kfzMvYvKirSiguP9Q/veMtkYyf0o8=
|
||||
golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
27
macbt/cmdelegate.go
Normal file
27
macbt/cmdelegate.go
Normal file
@ -0,0 +1,27 @@
|
||||
// Implements the CentralManagerDelegate interface. CoreBluetooth
|
||||
// communicates events asynchronously via callbacks. This file implements a
|
||||
// synchronous interface by translating these callbacks into channel
|
||||
// operations.
|
||||
|
||||
package macbt
|
||||
|
||||
import (
|
||||
"github.com/JuulLabs-OSS/cbgo"
|
||||
)
|
||||
|
||||
// CMDelegate to handle callbacks from CoreBluetooth.
|
||||
type CMDelegate struct {
|
||||
}
|
||||
|
||||
func (d *CMDelegate) CentralManagerDidUpdateState(cmgr cbgo.CentralManager) {
|
||||
}
|
||||
|
||||
func (d *CMDelegate) DidDiscoverPeripheral(cmgr cbgo.CentralManager, prph cbgo.Peripheral,
|
||||
advFields cbgo.AdvFields, rssi int) {
|
||||
}
|
||||
|
||||
func (d *CMDelegate) DidConnectPeripheral(cmgr cbgo.CentralManager, prph cbgo.Peripheral) {
|
||||
}
|
||||
|
||||
func (d *CMDelegate) DidDisconnectPeripheral(cmgr cbgo.CentralManager, prph cbgo.Peripheral, err error) {
|
||||
}
|
2
macbt/macbt.go
Normal file
2
macbt/macbt.go
Normal file
@ -0,0 +1,2 @@
|
||||
// Package macbt is wrapper to CoreBluetooth.
|
||||
package macbt
|
35
macbt/pmdelegate.go
Normal file
35
macbt/pmdelegate.go
Normal file
@ -0,0 +1,35 @@
|
||||
// Implements the PeripheralManagerDelegate interface.
|
||||
// CoreBluetooth communicates events asynchronously via callbacks. This file
|
||||
// implements a synchronous interface by translating these callbacks into
|
||||
// channel operations.
|
||||
|
||||
package macbt
|
||||
|
||||
import (
|
||||
"github.com/JuulLabs-OSS/cbgo"
|
||||
)
|
||||
|
||||
// PMDelegate to handle callbacks from CoreBluetooth.
|
||||
type PMDelegate struct {
|
||||
}
|
||||
|
||||
func (d *PMDelegate) PeripheralManagerDidUpdateState(pmgr cbgo.PeripheralManager) {
|
||||
}
|
||||
|
||||
func (d *PMDelegate) DidAddService(pmgr cbgo.PeripheralManager, svc cbgo.Service, err error) {
|
||||
}
|
||||
|
||||
func (d *PMDelegate) DidStartAdvertising(pmgr cbgo.PeripheralManager, err error) {
|
||||
}
|
||||
|
||||
func (d *PMDelegate) DidReceiveReadRequest(pmgr cbgo.PeripheralManager, cbreq cbgo.ATTRequest) {
|
||||
}
|
||||
|
||||
func (d *PMDelegate) DidReceiveWriteRequests(pmgr cbgo.PeripheralManager, cbreqs []cbgo.ATTRequest) {
|
||||
}
|
||||
|
||||
func (d *PMDelegate) CentralDidSubscribe(pmgr cbgo.PeripheralManager, cent cbgo.Central, cbchr cbgo.Characteristic) {
|
||||
}
|
||||
|
||||
func (d *PMDelegate) CentralDidUnsubscribe(pmgr cbgo.PeripheralManager, cent cbgo.Central, chr cbgo.Characteristic) {
|
||||
}
|
Loading…
Reference in New Issue
Block a user