Skip to content

Commit b751163

Browse files
committed
Support bluetooth.simulateService
1 parent d940d56 commit b751163

1 file changed

Lines changed: 91 additions & 1 deletion

File tree

index.bs

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5008,7 +5008,14 @@ Each <a>simulated Bluetooth adapter</a> has an <dfn>adapter state</dfn> that is
50085008

50095009
Each <a>simulated Bluetooth adapter</a> has a <dfn lt="LE supported state">low-energy supported state</dfn> that is a boolean describing if the adapter supports Bluetooth Low Energy.
50105010

5011-
A <dfn>simulated Bluetooth device</dfn> is a software defined [=Bluetooth device=] that behaves like a physical device, and may be attached to a <a>simulated Bluetooth adapter</a>, and may have associated properties like <a>Manufacturer Specific Data</a> and <a>Service UUIDs</a>.
5011+
A <dfn>simulated Bluetooth device</dfn> is a software defined [=Bluetooth device=] that
5012+
behaves like a physical device, may be attached to a <a>simulated Bluetooth adapter</a>,
5013+
may have associated properties like <a>Manufacturer Specific Data</a> and <a>Service UUIDs</a>,
5014+
and has a <dfn>simulated GATT service mapping</dfn>, which is an <a>ordered map</a> of Bluetooth
5015+
<a>UUID</a> {{strings}} to <a>simulated GATT services</a>.
5016+
5017+
A <dfn>simulated GATT service</dfn> is a software defined [=Service=] that belongs to a
5018+
<a>simulated Bluetooth device</a>, and has a property of <a>UUID</a>.
50125019

50135020
Issue: CDDL snippetes use the "text" type instead of
50145021
"browsingContext.BrowsingContext" to allow indepedent programmatic
@@ -5567,6 +5574,89 @@ A [=local end=] could simulate device GATT disconnection by sending the followin
55675574
</pre>
55685575
</div>
55695576

5577+
#### The bluetooth.simulateService Command #### {#bluetooth-simulateservice-command}
5578+
5579+
<pre highlight="cddl" class="cddl remote-cddl local-cddl">
5580+
bluetooth.SimulateService = (
5581+
method: "bluetooth.simulateService",
5582+
params: bluetooth.simulateServiceParameters,
5583+
)
5584+
5585+
bluetooth.simulateServiceParameters = {
5586+
context: text,
5587+
address: text,
5588+
uuid: bluetooth.BluetoothServiceUuid,
5589+
type: "add" / "remove",
5590+
}
5591+
5592+
</pre>
5593+
5594+
<div algorithm="remote end steps for bluetooth.simulateService">
5595+
The [=remote end steps=] with command parameters |params| are:
5596+
5597+
1. Let |contextId| be |params|[`"context"`].
5598+
1. Let |navigable| be the result of [=trying=] to [=get a navigable=] with |contextId|.
5599+
1. Let |deviceAddress| be |params|[`"address"`].
5600+
1. Let |simulatedBluetoothAdapter| be |navigable|'s <a>simulated Bluetooth adapter</a>.
5601+
1. If |simulatedBluetoothAdapter| is empty, return [=error=] with [=error code=] [=invalid argument=].
5602+
1. Let |deviceMapping| be |simulatedBluetoothAdapter|'s <a>simulated Bluetooth device mapping</a>.
5603+
1. If |deviceMapping|[|deviceAddress|] [=map/exists=], let |simulatedDevice| be |deviceMapping|[|deviceAddress|].
5604+
1. Otherwise, return [=error=] with [=error code=] [=invalid argument=].
5605+
1. Let |simulatedDeviceInstance| be the result of <a>get the <code>BluetoothDevice</code> representing</a>
5606+
|simulatedDevice| inside |navigable|'s <a>active window</a>'s <a spec=HTML>associated <code>Navigator</code></a>'s
5607+
[=associated Bluetooth=].
5608+
1. Let |serviceMapping| be |simulatedDevice|'s <a>simulated GATT service mapping</a>.
5609+
1. If |params|[`"type"`] is `"add"`:
5610+
1. If |serviceMapping|[|params|[`"uuid"`]] [=map/exists=], return [=error=] with [=error code=] [=invalid element state=].
5611+
1. Let |simulatedGattService| be a new <a>simulated GATT service</a>.
5612+
1. Set |simulatedGattService|'s <a>UUID</a> to |params|[`"uuid"`].
5613+
1. Set |serviceMapping|[|params|[`"uuid"`]] to |simulatedGattService|.
5614+
1. <a>Create a <code>BluetoothRemoteGATTService</code> representing</a> |simulatedGattService|
5615+
and add a mapping from |simulatedGattService| to the resulting {{Promise}} in
5616+
|simulatedDeviceInstance|.{{[[context]]}}.{{Bluetooth/[[attributeInstanceMap]]}}.
5617+
1. Return [=success=] with data `null`.
5618+
1. Else if |params|[`"type"`] is `"remove"`:
5619+
1. If |serviceMapping|[|params|[`"uuid"`]] [=map/exists=], let |simulatedGattService| be |serviceMapping|[|params|[`"uuid"`]].
5620+
1. Otherwise, return [=error=] with [=error code=] [=invalid element state=].
5621+
1. Remove |simulatedGattService| from |simulatedDeviceInstance|.{{[[context]]}}.{{Bluetooth/[[attributeInstanceMap]]}}.
5622+
1. Remove |params|[`"uuid"`] from |serviceMapping|.
5623+
1. Return [=success=] with data `null`.
5624+
1. Return [=error=] with [=error code=] [=invalid argument=].
5625+
5626+
</div>
5627+
5628+
<div class="example">
5629+
A [=local end=] could simulate adding a GATT service by sending the following message:
5630+
5631+
<pre highlight="json">
5632+
{
5633+
"method": "bluetooth.simulateService",
5634+
"params": {
5635+
"context": "cxt-d03fdd81",
5636+
"address": "09:09:09:09:09:09",
5637+
"uuid": "12345678-1234-5678-9abc-def123456789",
5638+
"type": "add"
5639+
}
5640+
}
5641+
</pre>
5642+
</div>
5643+
5644+
<div class="example">
5645+
A [=local end=] could simulate removing a GATT service by sending the following message:
5646+
5647+
<pre highlight="json">
5648+
{
5649+
"method": "bluetooth.simulateService",
5650+
"params": {
5651+
"context": "cxt-d03fdd81",
5652+
"address": "09:09:09:09:09:09",
5653+
"uuid": "12345678-1234-5678-9abc-def123456789",
5654+
"type": "remove"
5655+
}
5656+
}
5657+
</pre>
5658+
</div>
5659+
55705660
### Events ### {#bidi-events}
55715661

55725662
#### The bluetooth.requestDevicePromptUpdated Event #### {#bluetooth-requestdevicepromptupdated-event}

0 commit comments

Comments
 (0)