Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
41 changes: 41 additions & 0 deletions gattc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//go:build !baremetal || (softdevice && s132v6) || (softdevice && s140v6) || (softdevice && s140v7) || hci || ninafw || cyw43439
Comment thread
acouvreur marked this conversation as resolved.
Outdated

package bluetooth

// GATTCService is the common interface that all platform-specific
// DeviceService types must implement.
type GATTCService interface {
// UUID returns the UUID for this DeviceService.
UUID() UUID

// DiscoverCharacteristics discovers characteristics in this service.
// Pass a list of characteristic UUIDs you are interested in to this
// function. Either a list of all requested services is returned, or if
// some services could not be discovered an error is returned.
DiscoverCharacteristics(uuids []UUID) ([]DeviceCharacteristic, error)
}

// GATTCCharacteristic is the common interface that all platform-specific
// DeviceCharacteristic types must implement.
type GATTCCharacteristic interface {
// UUID returns the UUID for this DeviceCharacteristic.
UUID() UUID

// Read reads the current characteristic value.
Read(data []byte) (int, error)

// Write replaces the characteristic value with a new value.
Write(p []byte) (n int, err error)

// WriteWithoutResponse replaces the characteristic value with a new
// value. The call will return before all data has been written.
WriteWithoutResponse(p []byte) (n int, err error)

// EnableNotifications enables notifications for this characteristic,
// calling the provided callback with the new value when the
// characteristic value is changed by the remote peripheral.
EnableNotifications(callback func(buf []byte)) error

// GetMTU returns the MTU for this characteristic.
GetMTU() (uint16, error)
}
5 changes: 4 additions & 1 deletion gattc_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import (
"github.com/tinygo-org/cbgo"
)

var errCannotSendWriteWithoutResponse = errors.New("bluetooth: cannot send write without response (buffer full)")

var (
errCannotSendWriteWithoutResponse = errors.New("bluetooth: cannot send write without response (buffer full)")
_ GATTCService = DeviceService{}
Comment thread
acouvreur marked this conversation as resolved.
Outdated
_ GATTCCharacteristic = DeviceCharacteristic{}
)

// DiscoverServices starts a service discovery procedure. Pass a list of service
Expand Down
12 changes: 12 additions & 0 deletions gattc_hci.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ var (
errCharacteristicNotFound = errors.New("bluetooth: characteristic not found")
)

var (
_ GATTCService = DeviceService{}
_ GATTCCharacteristic = DeviceCharacteristic{}
)

const (
maxDefaultServicesToDiscover = 8
maxDefaultCharacteristicsToDiscover = 16
Expand Down Expand Up @@ -236,6 +241,13 @@ func (s DeviceService) DiscoverCharacteristics(uuids []UUID) ([]DeviceCharacteri
return characteristics, nil
}

// Write replaces the characteristic value with a new value.
//
// Not yet implemented on HCI.
func (c DeviceCharacteristic) Write(p []byte) (n int, err error) {
return 0, errNotYetImplemented
}

// WriteWithoutResponse replaces the characteristic value with a new value. The
// call will return before all data has been written. A limited number of such
// writes can be in flight at any given time. This call is also known as a
Expand Down
5 changes: 5 additions & 0 deletions gattc_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import (
"github.com/godbus/dbus/v5"
)

var (
_ GATTCService = DeviceService{}
_ GATTCCharacteristic = (*DeviceCharacteristic)(nil)
)

var (
errDupNotif = errors.New("unclosed notifications")
)
Expand Down
12 changes: 12 additions & 0 deletions gattc_sd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ const (
maxDefaultCharacteristicsToDiscover = 8
)

var (
_ GATTCService = DeviceService{}
_ GATTCCharacteristic = DeviceCharacteristic{}
)

var (
errAlreadyDiscovering = errors.New("bluetooth: already discovering a service or characteristic")
errNotFound = errors.New("bluetooth: not found")
Expand Down Expand Up @@ -312,6 +317,13 @@ func (s DeviceService) DiscoverCharacteristics(uuids []UUID) ([]DeviceCharacteri
return characteristics, nil
}

// Write replaces the characteristic value with a new value.
//
// Not yet implemented on SoftDevice.
func (c DeviceCharacteristic) Write(p []byte) (n int, err error) {
return 0, errNotFound
}

// WriteWithoutResponse replaces the characteristic value with a new value. The
// call will return before all data has been written. A limited number of such
// writes can be in flight at any given time. This call is also known as a
Expand Down
5 changes: 5 additions & 0 deletions gattc_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import (
"github.com/saltosystems/winrt-go/windows/storage/streams"
)

var (
_ GATTCService = DeviceService{}
_ GATTCCharacteristic = DeviceCharacteristic{}
)

var (
errNoWrite = errors.New("bluetooth: write not supported")
errNoWriteWithoutResponse = errors.New("bluetooth: write without response not supported")
Expand Down
Loading