OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // The <code>chrome.bluetoothLowEnergy</code> API is used to communicate with | 5 // The <code>chrome.bluetoothLowEnergy</code> API is used to communicate with |
6 // Bluetooth Smart (Low Energy) devices using the | 6 // Bluetooth Smart (Low Energy) devices using the |
7 // <a href="https://developer.bluetooth.org/TechnologyOverview/Pages/GATT.aspx"> | 7 // <a href="https://developer.bluetooth.org/TechnologyOverview/Pages/GATT.aspx"> |
8 // Generic Attribute Profile (GATT)</a>. | 8 // Generic Attribute Profile (GATT)</a>. |
9 namespace bluetoothLowEnergy { | 9 namespace bluetoothLowEnergy { |
10 // Values representing the possible properties of a characteristic. | 10 // Values representing the possible properties of a characteristic. |
11 enum CharacteristicProperty {broadcast, read, writeWithoutResponse, write, | 11 enum CharacteristicProperty {broadcast, read, writeWithoutResponse, write, |
12 notify, indicate, authenticatedSignedWrites, | 12 notify, indicate, authenticatedSignedWrites, |
13 extendedProperties, reliableWrite, | 13 extendedProperties, reliableWrite, |
14 writableAuxiliaries}; | 14 writableAuxiliaries}; |
15 | 15 |
16 // Represents a peripheral's Bluetooth GATT Service, a collection of | 16 // Represents a peripheral's Bluetooth GATT Service, a collection of |
17 // characteristics and relationships to other services that encapsulate | 17 // characteristics and relationships to other services that encapsulate |
18 // the behavior of part of a device. | 18 // the behavior of part of a device. |
19 dictionary Service { | 19 dictionary Service { |
20 // The UUID of the service, e.g. 0000180d-0000-1000-8000-00805f9b34fb. | 20 // The UUID of the service, e.g. 0000180d-0000-1000-8000-00805f9b34fb. |
21 DOMString uuid; | 21 DOMString uuid; |
22 | 22 |
23 // Indicates whether the type of this service is primary or secondary. | 23 // Indicates whether the type of this service is primary or secondary. |
24 boolean isPrimary; | 24 boolean isPrimary; |
25 | 25 |
26 // Indicates whether this service represents a local service hosted by the | 26 // Indicates whether this service represents a local service hosted by the |
27 // application and available to other peripherals, or a remote service | 27 // application and available to other peripherals, or a remote service |
28 // hosted and received from a remote peripheral. | 28 // hosted and received from a remote peripheral. |
29 boolean isLocal; | 29 [nodoc] boolean isLocal; |
30 | 30 |
31 // Returns the identifier assigned to this service. Use the instance ID to | 31 // Returns the identifier assigned to this service. Use the instance ID to |
32 // distinguish between services from a peripheral with the same UUID and | 32 // distinguish between services from a peripheral with the same UUID and |
33 // to make function calls that take in a service identifier. Present, if | 33 // to make function calls that take in a service identifier. Present, if |
34 // this instance represents a remote service. | 34 // this instance represents a remote service. |
35 DOMString? instanceId; | 35 DOMString? instanceId; |
36 | 36 |
37 // The device address of the remote peripheral that the GATT service belongs | 37 // The device address of the remote peripheral that the GATT service belongs |
38 // to. Present, if this instance represents a remote service. | 38 // to. Present, if this instance represents a remote service. |
39 DOMString? deviceAddress; | 39 DOMString? deviceAddress; |
40 }; | 40 }; |
41 | 41 |
42 // Represents a GATT characteristic, which is a basic data element that | 42 // Represents a GATT characteristic, which is a basic data element that |
43 // provides further information about a peripheral's service. | 43 // provides further information about a peripheral's service. |
44 dictionary Characteristic { | 44 dictionary Characteristic { |
45 // The UUID of the characteristic, e.g. | 45 // The UUID of the characteristic, e.g. |
46 // 00002a37-0000-1000-8000-00805f9b34fb. | 46 // 00002a37-0000-1000-8000-00805f9b34fb. |
47 DOMString uuid; | 47 DOMString uuid; |
48 | 48 |
49 // Indicates whether this characteristic represents a local characteristic | 49 // Indicates whether this characteristic represents a local characteristic |
50 // hosted by the application and available to other peripherals, or a remote | 50 // hosted by the application and available to other peripherals, or a remote |
51 // characteristic hosted and received from a remote peripheral. | 51 // characteristic hosted and received from a remote peripheral. |
52 boolean isLocal; | 52 [nodoc] boolean isLocal; |
53 | 53 |
54 // The GATT service this characteristic belongs to. | 54 // The GATT service this characteristic belongs to. |
55 Service service; | 55 Service service; |
56 | 56 |
57 // The properties of this characteristic. | 57 // The properties of this characteristic. |
58 CharacteristicProperty[] properties; | 58 CharacteristicProperty[] properties; |
59 | 59 |
60 // Returns the identifier assigned to this characteristic. Use the instance | 60 // Returns the identifier assigned to this characteristic. Use the instance |
61 // ID to distinguish between characteristics from a peripheral with the same | 61 // ID to distinguish between characteristics from a peripheral with the same |
62 // UUID and to make function calls that take in a characteristic identifier. | 62 // UUID and to make function calls that take in a characteristic identifier. |
(...skipping 10 matching lines...) Expand all Loading... |
73 // Represents a GATT characteristic descriptor, which provides further | 73 // Represents a GATT characteristic descriptor, which provides further |
74 // information about a characteristic's value. | 74 // information about a characteristic's value. |
75 dictionary Descriptor { | 75 dictionary Descriptor { |
76 // The UUID of the characteristic descriptor, e.g. | 76 // The UUID of the characteristic descriptor, e.g. |
77 // 00002902-0000-1000-8000-00805f9b34fb. | 77 // 00002902-0000-1000-8000-00805f9b34fb. |
78 DOMString uuid; | 78 DOMString uuid; |
79 | 79 |
80 // Indicates whether this descriptor represents a local descriptor | 80 // Indicates whether this descriptor represents a local descriptor |
81 // hosted by the application and available to other peripherals, or a remote | 81 // hosted by the application and available to other peripherals, or a remote |
82 // descriptor hosted and received from a remote peripheral. | 82 // descriptor hosted and received from a remote peripheral. |
83 boolean isLocal; | 83 [nodoc] boolean isLocal; |
84 | 84 |
85 // The GATT characteristic this descriptor belongs to. | 85 // The GATT characteristic this descriptor belongs to. |
86 Characteristic characteristic; | 86 Characteristic characteristic; |
87 | 87 |
88 // Returns the identifier assigned to this descriptor. Use the instance ID | 88 // Returns the identifier assigned to this descriptor. Use the instance ID |
89 // to distinguish between descriptors from a peripheral with the same UUID | 89 // to distinguish between descriptors from a peripheral with the same UUID |
90 // and to make function calls that take in a descriptor identifier. Present, | 90 // and to make function calls that take in a descriptor identifier. Present, |
91 // if this instance represents a remote characteristic. | 91 // if this instance represents a remote characteristic. |
92 DOMString? instanceId; | 92 DOMString? instanceId; |
93 | 93 |
94 // The currently cached descriptor value. This value gets updated when | 94 // The currently cached descriptor value. This value gets updated when |
95 // the value of the descriptor is read or written. For local descriptors, | 95 // the value of the descriptor is read or written. For local descriptors, |
96 // this is the value that will be returned upon requests from remote | 96 // this is the value that will be returned upon requests from remote |
97 // peripherals by default. | 97 // peripherals by default. |
98 ArrayBuffer? value; | 98 ArrayBuffer? value; |
99 }; | 99 }; |
100 | 100 |
| 101 // The connection properties specified during a call to $ref:connect. |
| 102 dictionary ConnectProperties { |
| 103 // Flag indicating whether a connection to the device is left open when the |
| 104 // event page of the application is unloaded (see <a |
| 105 // href="http://developer.chrome.com/apps/app_lifecycle.html">Manage App |
| 106 // Lifecycle</a>). The default value is <code>false.</code> |
| 107 boolean persistent; |
| 108 }; |
| 109 |
101 callback CharacteristicCallback = void(Characteristic result); | 110 callback CharacteristicCallback = void(Characteristic result); |
102 callback CharacteristicsCallback = void(Characteristic[] result); | 111 callback CharacteristicsCallback = void(Characteristic[] result); |
103 callback DescriptorCallback = void(Descriptor result); | 112 callback DescriptorCallback = void(Descriptor result); |
104 callback DescriptorsCallback = void(Descriptor[] result); | 113 callback DescriptorsCallback = void(Descriptor[] result); |
105 callback ResultCallback = void(); | 114 callback ResultCallback = void(); |
106 callback ServiceCallback = void(Service result); | 115 callback ServiceCallback = void(Service result); |
107 callback ServicesCallback = void(Service[] result); | 116 callback ServicesCallback = void(Service[] result); |
108 | 117 |
109 // These functions all report failures via chrome.runtime.lastError. | 118 // These functions all report failures via chrome.runtime.lastError. |
110 interface Functions { | 119 interface Functions { |
| 120 // Establishes a connection between the application and the device with the |
| 121 // given address. A device may be already connected and its GATT services |
| 122 // available without calling <code>connect</code>, however, an app that |
| 123 // wants to access GATT services of a device should call this function to |
| 124 // make sure that a connection to the device is maintained. If the device |
| 125 // is not connected, all GATT services of the device will be discovered |
| 126 // after a successful call to <code>connect</code>. |
| 127 // |deviceAddress| : The Bluetooth address of the remote device to which a |
| 128 // GATT connection should be opened. |
| 129 // |properties| : Connection properties (optional). |
| 130 // |callback| : Called when the connect request has completed. |
| 131 static void connect(DOMString deviceAddress, |
| 132 optional ConnectProperties properties, |
| 133 ResultCallback callback); |
| 134 |
| 135 // Closes the app's connection to the device with the given address. Note |
| 136 // that this will not always destroy the physical link itself, since there |
| 137 // may be other apps with open connections. |
| 138 // |deviceAddress| : The Bluetooth address of the remote device. |
| 139 // |callback| : Called when the disconnect request has completed. |
| 140 static void disconnect(DOMString deviceAddress, |
| 141 optional ResultCallback callback); |
| 142 |
111 // Get the GATT service with the given instance ID. | 143 // Get the GATT service with the given instance ID. |
112 // |serviceId| : The instance ID of the requested GATT service. | 144 // |serviceId| : The instance ID of the requested GATT service. |
113 // |callback| : Called with the requested Service object. | 145 // |callback| : Called with the requested Service object. |
114 static void getService(DOMString serviceId, ServiceCallback callback); | 146 static void getService(DOMString serviceId, ServiceCallback callback); |
115 | 147 |
116 // Get all the GATT services that were discovered on the remote device with | 148 // Get all the GATT services that were discovered on the remote device with |
117 // the given device address. | 149 // the given device address. |
118 // |deviceAddress| : The Bluetooth Address of the remote device whose GATT | 150 // |deviceAddress| : The Bluetooth address of the remote device whose GATT |
119 // services should be returned. | 151 // services should be returned. |
120 // |callback| : Called with the list of requested Service objects. | 152 // |callback| : Called with the list of requested Service objects. |
121 static void getServices(DOMString deviceAddress, ServicesCallback callback); | 153 static void getServices(DOMString deviceAddress, ServicesCallback callback); |
122 | 154 |
123 // Get the GATT characteristic with the given instance ID that belongs to | 155 // Get the GATT characteristic with the given instance ID that belongs to |
124 // the given GATT service, if the characteristic exists. | 156 // the given GATT service, if the characteristic exists. |
125 // |characteristicId| : The instance ID of the requested GATT | 157 // |characteristicId| : The instance ID of the requested GATT |
126 // characteristic. | 158 // characteristic. |
127 // |callback| : Called with the requested Characteristic object. | 159 // |callback| : Called with the requested Characteristic object. |
128 static void getCharacteristic(DOMString characteristicId, | 160 static void getCharacteristic(DOMString characteristicId, |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 // |characteristic| : The GATT characteristic whose value has changed. | 259 // |characteristic| : The GATT characteristic whose value has changed. |
228 static void onCharacteristicValueChanged(Characteristic characteristic); | 260 static void onCharacteristicValueChanged(Characteristic characteristic); |
229 | 261 |
230 // Fired when the value of a remote GATT characteristic descriptor changes, | 262 // Fired when the value of a remote GATT characteristic descriptor changes, |
231 // usually as a result of a read or write request. | 263 // usually as a result of a read or write request. |
232 // |descriptor| : The GATT characteristic descriptor whose value has | 264 // |descriptor| : The GATT characteristic descriptor whose value has |
233 // changed. | 265 // changed. |
234 static void onDescriptorValueChanged(Descriptor descriptor); | 266 static void onDescriptorValueChanged(Descriptor descriptor); |
235 }; | 267 }; |
236 }; | 268 }; |
OLD | NEW |