From 63090299716cb458b34ea19e08bee6528d04ed18 Mon Sep 17 00:00:00 2001 From: Jack Hsieh <97704544+chengweih001@users.noreply.github.com> Date: Fri, 21 Feb 2025 22:05:24 -0800 Subject: [PATCH] Update bluetooth.simulateAdapter command (#646) * Update bluetooth.simulateAdapter command Update bluetooth.simulateAdapter command to support creating, updating, and removing adapter. --- index.bs | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 6 deletions(-) diff --git a/index.bs b/index.bs index 8866a1a..6d2f5dc 100644 --- a/index.bs +++ b/index.bs @@ -2027,6 +2027,9 @@ steps in parallel: 1. If |simulatedBluetoothAdapter|'s [=adapter state=] is "absent", [=queue a global task=] on the [=Bluetooth task source=] given |global| to [=resolve=] |promise| with `false`. + 1. If |simulatedBluetoothAdapter|'s [=LE supported state=] is `false`, [=queue + a global task=] on the [=Bluetooth task source=] given |global| to + [=resolve=] |promise| with `false`. 1. Otherwise, [=queue a global task=] on the [=Bluetooth task source=] given |global| to [=resolve=] |promise| with `true`. 1. Abort these steps. @@ -4972,6 +4975,8 @@ Each simulated Bluetooth adapter has an adapter state that is * "powered-off" * "absent" +Each simulated Bluetooth adapter has a low-energy supported state that is a boolean describing if the adapter supports Bluetooth Low Energy. + A simulated Bluetooth device is a software defined [=Bluetooth device=] that behaves like a physical device, and may be attached to a simulated Bluetooth adapter, and may have associated properties like Manufacturer Specific Data and Service UUIDs. Issue: CDDL snippetes use the "text" type instead of @@ -5191,7 +5196,9 @@ bluetooth.simulateAdapter = ( bluetooth.SimulateAdapterParameters = { context: text, - state: "absent" / "powered-off" / "powered-on" + type: "create" / "update" / "remove", + ? leSupported: bool, + ? state: "absent" / "powered-off" / "powered-on" } @@ -5201,27 +5208,74 @@ The [=remote end steps=] with command parameters |params| are: 1. Let |contextId| be params["context"]. 1. Let |navigable| be the result of [=trying=] to [=get a navigable=] with |contextId|. 1. If |navigable| is not a [=navigable/top-level traversable=], return [=error=] with [=error code=] [=invalid argument=]. -1. Let |simulatedBluetoothAdapter| be a new [=simulated Bluetooth adapter=]. -1. Set |simulatedBluetoothAdapter|'s adapter state to |params|[`"state"`]. -1. Set |navigable|'s simulated Bluetooth adapter to |simulatedBluetoothAdapter|. -1. Return [=success=] with data `null`. +1. If |params|[`"type"`] is `create`, run the following steps: + 1. If |params|[`"leSupported"`] does not [=map/exist=], return [=error=] with [=error code=] [=invalid argument=]. + 1. If |params|[`"state"`] does not [=map/exist=], return [=error=] with [=error code=] [=invalid argument=]. + 1. Let |simulatedBluetoothAdapter| be a new [=simulated Bluetooth adapter=]. + 1. Set |simulatedBluetoothAdapter|'s LE supported state to |params|[`"leSupported"`]. + 1. Set |simulatedBluetoothAdapter|'s adapter state to |params|[`"state"`]. + 1. Set |navigable|'s simulated Bluetooth adapter to |simulatedBluetoothAdapter|. + 1. Return [=success=] with data `null`. +1. If |params|[`"type"`] is `update`, run the following steps: + 1. If |params|[`"leSupported"`] [=map/exists=], return [=error=] with [=error code=] [=invalid argument=]. + 1. If |params|[`"state"`] does not [=map/exist=], return [=error=] with [=error code=] [=invalid argument=]. + 1. Let |simulatedBluetoothAdapter| be |navigable|'s simulated Bluetooth adapter. + 1. If |simulatedBluetoothAdapter| is empty, return [=error=] with [=error code=] [=invalid argument=]. + 1. Set |simulatedBluetoothAdapter|'s adapter state to |params|[`"state"`]. + 1. Return [=success=] with data `null`. +1. If |params|[`"type"`] is `remove`, run the following steps: + 1. If |params|[`"leSupported"`] [=map/exists=], return [=error=] with [=error code=] [=invalid argument=]. + 1. If |params|[`"state"`] [=map/exists=], return [=error=] with [=error code=] [=invalid argument=]. + 1. Set |navigable|'s simulated Bluetooth adapter to empty. + 1. Return [=success=] with data `null`.
-A [=local end=] could simulate an adapter by sending the following message: +A [=local end=] could simulate an adapter that supports Bluetooth Low Energy by sending the following message:
 {
   "method": "bluetooth.simulateAdapter",
   "params": {
     "context": "cxt-d03fdd81",
+    "type": "create",
+    "leSupported": true,
     "state": "powered-on",
   }
 }
 
+
+A [=local end=] could update the adapter state of an existing adapter by sending the following message: + +
+{
+  "method": "bluetooth.simulateAdapter",
+  "params": {
+    "context": "cxt-d03fdd81",
+    "type": "update",
+    "state": "powered-off",
+  }
+}
+
+
+ +
+A [=local end=] could remove an existing adapter by sending the following message: + +
+{
+  "method": "bluetooth.simulateAdapter",
+  "params": {
+    "context": "cxt-d03fdd81",
+    "type": "remove",
+  }
+}
+
+
+ #### The bluetooth.simulatePreconnectedPeripheral Command #### {#bluetooth-simulateconnectedperipheral-command}