diff --git a/index.bs b/index.bs index 7ea9f6f..21338f0 100644 --- a/index.bs +++ b/index.bs @@ -5015,7 +5015,12 @@ and has a simulated GATT service mapping, which is an ordered map< UUID strings to simulated GATT services. A simulated GATT service is a software defined [=Service=] that belongs to a -simulated Bluetooth device, has a property of UUID, and is known-present in the +simulated Bluetooth device, has a property of UUID, is known-present in the +Bluetooth cache. and has a simulated GATT characteristic mapping, which +is an ordered map of Bluetooth UUID strings to simulated GATT characteristics. + +A simulated GATT characteristic is a software defined [=Characteristic=] that belongs to a +simulated GATT service, has a property of UUID, and is known-present in the Bluetooth cache. Issue: CDDL snippetes use the "text" type instead of @@ -5692,8 +5697,43 @@ bluetooth.SimulateCharacteristicParameters = {
+The [=remote end steps=] with command parameters |params| are: -Issue: TODO: Finish the algorithm of bluetooth.simulateCharacteristic. +1. Let |contextId| be |params|[`"context"`]. +1. Let |navigable| be the result of [=trying=] to [=get a navigable=] with |contextId|. +1. Let |deviceAddress| be |params|[`"address"`]. +1. Let |simulatedBluetoothAdapter| be |navigable|'s simulated Bluetooth adapter. +1. If |simulatedBluetoothAdapter| is empty, return [=error=] with [=error code=] [=invalid argument=]. +1. Let |deviceMapping| be |simulatedBluetoothAdapter|'s simulated Bluetooth device mapping. +1. If |deviceMapping|[|deviceAddress|] [=map/exists=], let |simulatedDevice| be |deviceMapping|[|deviceAddress|]. +1. Otherwise, return [=error=] with [=error code=] [=invalid argument=]. +1. Let |simulatedDeviceInstance| be the result of get the BluetoothDevice representing + |simulatedDevice| inside |navigable|'s active window's associated Navigator's + [=associated Bluetooth=]. +1. Let |serviceMapping| be |simulatedDevice|'s simulated GATT service mapping. +1. Let |serviceUuid| be |params|[`"serviceUuid"`]. +1. If |serviceMapping|[|serviceUuid|] [=map/exists=], let |simulatedService| be |serviceMapping|[|serviceUuid|]. +1. Otherwise, return [=error=] with [=error code=] [=invalid argument=]. +1. Let |characteristicMapping| be |simulatedService|'s simulated GATT characteristic mapping. +1. Let |characteristicUuid| be |params|[`"characteristicUuid"`]. +1. If |params|[`"type"`] is `"add"`: + 1. If |characteristicMapping|[|characteristicUuid|] [=map/exists=], return [=error=] with + [=error code=] [=invalid element state=]. + 1. Let |simulatedGattCharacteristic| be a new simulated GATT characteristic. + 1. Set |simulatedGattCharacteristic|'s UUID to |characteristicUuid|. + 1. Set |characteristicMapping|[|characteristicUuid|] to |simulatedGattCharacteristic|. + 1. Create a BluetoothRemoteGATTCharacteristic representing |simulatedGattCharacteristic| + and add a mapping from |simulatedGattCharacteristic| to the resulting {{Promise}} in + |simulatedDeviceInstance|.{{[[context]]}}.{{Bluetooth/[[attributeInstanceMap]]}}. + 1. Return [=success=] with data `null`. +1. Else if |params|[`"type"`] is `"remove"`: + 1. If |characteristicMapping|[|characteristicUuid|] [=map/exists=], let |simulatedGattCharacteristic| + be |characteristicMapping|[|characteristicUuid|]. + 1. Otherwise, return [=error=] with [=error code=] [=invalid element state=]. + 1. Remove |simulatedGattCharacteristic| from |simulatedDeviceInstance|.{{[[context]]}}.{{Bluetooth/[[attributeInstanceMap]]}}. + 1. Remove |characteristicUuid| from |characteristicMapping|. + 1. Return [=success=] with data `null`. +1. Return [=error=] with [=error code=] [=invalid argument=].