-
Notifications
You must be signed in to change notification settings - Fork 174
fix(darwin): WriteWithoutResponse checks CanSendWriteWithoutResponse before request #386
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
Open
acouvreur
wants to merge
5
commits into
tinygo-org:dev
Choose a base branch
from
acouvreur:add-CanSendWriteWithoutResponse-darwin
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fe363b9
feat(gattc): add CanSendWriteWithoutResponse for darwin
acouvreur 6b21611
fix doc
acouvreur 319250f
WriteWithoutResponse checks if it can send write without response req…
acouvreur 0e87cf5
remove mutex
acouvreur 281cb3f
remove unused named return params
acouvreur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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 { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this function does not exist in any of the other platforms, I am hesitant to include it. Can just checking in the |
||
| 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) | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems all other implementations already have its error handling (e.g. gattc_hci.go), so we should move this variable to "gattc_darwin.go". We need it exposed to use it in user code for checks, like you already demonstrated in your small example. (IMO unexposed variants in the other implementations are not that powerful, but this is another story.)