-
Notifications
You must be signed in to change notification settings - Fork 85
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -277,7 +277,7 @@ class BLESession: Session, SwiftCBCentralManagerDelegate, SwiftCBPeripheralDeleg | |
|
||
func write(withParams params: [String: Any], completion: @escaping JSONRPCCompletionHandler) throws { | ||
let buffer = try EncodingHelpers.decodeBuffer(fromJSON: params) | ||
let withResponse = params["withResponse"] as? Bool ?? false | ||
let withResponse = params["withResponse"] as? Bool | ||
|
||
getEndpoint(for: "write request", withParams: params, blockedBy: .ExcludeWrites) { endpoint, error in | ||
if let error = error { | ||
|
@@ -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. | ||
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. Add this comment to c# as well |
||
// Otherwise, if the characteristic claims to support writing without response, do that. | ||
// Otherwise, write with response. | ||
let writeType = (withResponse ?? !endpoint.properties.contains(.writeWithoutResponse)) ? | ||
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. withResponse = withResponse ?? !endpoint.properties.contains(.writeWithoutResponse)); let writeType = withResponse ? x : y might be more clear? |
||
CBCharacteristicWriteType.withResponse : CBCharacteristicWriteType.withoutResponse | ||
peripheral.writeValue(buffer, for: endpoint, type: writeType) | ||
completion(buffer.count, nil) | ||
|
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.
Set to a variable "the characteristic thinks we MUST write WITH response"
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 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)