Skip to content
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

BLE: allow client to override write with/without response #159

Merged

Conversation

cwillisf
Copy link
Contributor

@cwillisf cwillisf commented Nov 14, 2019

Resolves

Resolves #150
Closes #154

Proposed Changes

In #154, @terado0618 implemented a fix for #150 on Windows. This PR includes #154 along with a similar change for macOS and documentation of the new behavior.

Reason for Changes

This offers a significant performance boost on Windows: see this comment. Performance on macOS seems to be acceptable without this change, but I think it's important for the hardware communication to be similar on both platforms so that extensions don't need to worry about platform differences.

This PR should be merged with scratchfoundation/scratch-vm#2298.

@terado0618, please let me know if you have concerns about this PR. Thanks!

@cwillisf cwillisf added this to the November 2019 milestone Nov 14, 2019
@cwillisf cwillisf assigned paulkaplan, kchadha and fsih and unassigned paulkaplan and kchadha Nov 14, 2019
@cwillisf cwillisf requested review from fsih and removed request for paulkaplan and kchadha November 14, 2019 19:30
@cwillisf cwillisf changed the title Ble write without response BLE: allow client to override write with/without response Nov 14, 2019
@terado0618
Copy link
Contributor

LGTM.
Thanks!

@@ -338,7 +338,7 @@ private async Task<JToken> Write(JObject parameters)
{
var buffer = EncodingHelpers.DecodeBuffer(parameters);
var endpoint = await GetEndpoint("write request", parameters, GattHelpers.BlockListStatus.ExcludeWrites);
var withResponse = (parameters["withResponse"]?.ToObject<bool>() ?? false) ||
var withResponse = parameters["withResponse"]?.ToObject<bool>() ??
!endpoint.CharacteristicProperties.HasFlag(GattCharacteristicProperties.WriteWithoutResponse);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set to a variable "the characteristic thinks we MUST write WITH response"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to say that we explicitly expect an error if the gatt characteristic does not have property write with response (because then we're trying to write and we're not allowed to write at all)

@@ -297,7 +297,10 @@ class BLESession: Session, SwiftCBCentralManagerDelegate, SwiftCBPeripheralDeleg
return
}

let writeType = (withResponse || !endpoint.properties.contains(.writeWithoutResponse)) ?
// If the client specified a write type, honor that.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this comment to c# as well

// If the client specified a write type, honor that.
// Otherwise, if the characteristic claims to support writing without response, do that.
// Otherwise, write with response.
let writeType = (withResponse ?? !endpoint.properties.contains(.writeWithoutResponse)) ?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

withResponse = withResponse ?? !endpoint.properties.contains(.writeWithoutResponse));

let writeType = withResponse ? x : y

might be more clear?

@cwillisf
Copy link
Contributor Author

I'm going to merge this as-is for now but I've filed #161 to follow up on the review comments later.

@cwillisf cwillisf merged commit bd80631 into scratchfoundation:develop Nov 19, 2019
@cwillisf cwillisf deleted the ble-write-without-response branch November 19, 2019 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BLE: the withResponse parameter should override write behavior
5 participants