Skip to content
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
5 changes: 5 additions & 0 deletions gattc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package bluetooth

import "errors"

var ErrCannotSendWriteWithoutResponse = errors.New("cannot send write without response")
18 changes: 15 additions & 3 deletions gattc_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,13 @@ func (c DeviceCharacteristic) 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. A limited number of such
// writes can be in flight at any given time. This call is also known as a
// "write command" (as opposed to a write request).
func (c DeviceCharacteristic) WriteWithoutResponse(p []byte) (n int, err error) {
// writes can be in flight at any given time.
// If the client is not ready to send write without response requests at this time, ErrCannotSendWriteWithoutResponse is returned.
func (c DeviceCharacteristic) WriteWithoutResponse(p []byte) (int, error) {
if !c.service.device.prph.CanSendWriteWithoutResponse() {
return 0, ErrCannotSendWriteWithoutResponse
}

c.service.device.prph.WriteCharacteristic(p, c.characteristic, false)

return len(p), nil
Expand All @@ -227,6 +231,14 @@ func (c DeviceCharacteristic) GetMTU() (uint16, error) {
return uint16(c.service.device.prph.MaximumWriteValueLength(false)), nil
}

// CanSendWriteWithoutResponse returns whether a WriteWithoutResponse can be sent
// at this time. If this returns false, you must wait for some time before
// sending another WriteWithoutResponse. This is typically because the internal
// buffer is full.
func (c DeviceCharacteristic) CanSendWriteWithoutResponse() bool {
return c.service.device.prph.CanSendWriteWithoutResponse()
}

// Read reads the current characteristic value.
func (c *deviceCharacteristic) Read(data []byte) (n int, err error) {
c.readChan = make(chan error)
Expand Down
Loading