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 // Type of advertisement. If 'broadcast' is chosen, the sent advertisement | 16 // Type of advertisement. If 'broadcast' is chosen, the sent advertisement |
17 // type will be ADV_NONCONN_IND and the device will broadcast with a random | 17 // type will be ADV_NONCONN_IND and the device will broadcast with a random |
18 // MAC Address. If set to 'peripheral', the advertisement type will be | 18 // MAC Address. If set to 'peripheral', the advertisement type will be |
19 // ADV_IND or ADV_SCAN_IND and the device will broadcast with real Bluetooth | 19 // ADV_IND or ADV_SCAN_IND and the device will broadcast with real Bluetooth |
20 // Adapter's MAC Address. | 20 // Adapter's MAC Address. |
21 enum AdvertisementType {broadcast, peripheral}; | 21 enum AdvertisementType {broadcast, peripheral}; |
22 | 22 |
23 // Result of a register or unregister service call. | |
24 enum ServiceResult { | |
25 // The service operation was successful. | |
26 success, | |
27 // The service that is being registered is already regsitered. | |
28 alreadyRegistered, | |
29 // The service that is being unregistered is not regsitered. | |
30 notRegistered | |
31 }; | |
32 | |
33 // Represents a bluetooth central device that is connected to the local GATT | |
34 // server. | |
35 dictionary Device { | |
36 // The address of the device, in the format 'XX:XX:XX:XX:XX:XX'. | |
37 DOMString address; | |
38 | |
39 // The human-readable name of the device. | |
40 DOMString? name; | |
41 | |
42 // The class of the device, a bit-field defined by | |
43 // http://www.bluetooth.org/en-us/specification/assigned-numbers/baseband. | |
44 long? deviceClass; | |
45 }; | |
46 | |
23 // Represents a peripheral's Bluetooth GATT Service, a collection of | 47 // Represents a peripheral's Bluetooth GATT Service, a collection of |
24 // characteristics and relationships to other services that encapsulate | 48 // characteristics and relationships to other services that encapsulate |
25 // the behavior of part of a device. | 49 // the behavior of part of a device. |
26 dictionary Service { | 50 dictionary Service { |
27 // The UUID of the service, e.g. 0000180d-0000-1000-8000-00805f9b34fb. | 51 // The UUID of the service, e.g. 0000180d-0000-1000-8000-00805f9b34fb. |
28 DOMString uuid; | 52 DOMString uuid; |
29 | 53 |
30 // Indicates whether the type of this service is primary or secondary. | 54 // Indicates whether the type of this service is primary or secondary. |
31 boolean isPrimary; | 55 boolean isPrimary; |
32 | 56 |
33 // Indicates whether this service represents a local service hosted by the | |
34 // application and available to other peripherals, or a remote service | |
35 // hosted and received from a remote peripheral. | |
36 [nodoc] boolean isLocal; | |
37 | |
38 // Returns the identifier assigned to this service. Use the instance ID to | 57 // Returns the identifier assigned to this service. Use the instance ID to |
39 // distinguish between services from a peripheral with the same UUID and | 58 // distinguish between services from a peripheral with the same UUID and |
40 // to make function calls that take in a service identifier. Present, if | 59 // to make function calls that take in a service identifier. Present, if |
41 // this instance represents a remote service. | 60 // this instance represents a remote service. |
42 DOMString? instanceId; | 61 DOMString? instanceId; |
43 | 62 |
44 // The device address of the remote peripheral that the GATT service belongs | 63 // The device address of the remote peripheral that the GATT service belongs |
45 // to. Present, if this instance represents a remote service. | 64 // to. Present, if this instance represents a remote service. |
46 DOMString? deviceAddress; | 65 DOMString? deviceAddress; |
47 }; | 66 }; |
48 | 67 |
49 // Represents a GATT characteristic, which is a basic data element that | 68 // Represents a GATT characteristic, which is a basic data element that |
50 // provides further information about a peripheral's service. | 69 // provides further information about a peripheral's service. |
51 dictionary Characteristic { | 70 dictionary Characteristic { |
52 // The UUID of the characteristic, e.g. | 71 // The UUID of the characteristic, e.g. |
53 // 00002a37-0000-1000-8000-00805f9b34fb. | 72 // 00002a37-0000-1000-8000-00805f9b34fb. |
54 DOMString uuid; | 73 DOMString uuid; |
55 | 74 |
56 // Indicates whether this characteristic represents a local characteristic | |
57 // hosted by the application and available to other peripherals, or a remote | |
58 // characteristic hosted and received from a remote peripheral. | |
59 [nodoc] boolean isLocal; | |
60 | |
61 // The GATT service this characteristic belongs to. | 75 // The GATT service this characteristic belongs to. |
62 Service service; | 76 Service? service; |
63 | 77 |
64 // The properties of this characteristic. | 78 // The properties of this characteristic. |
65 CharacteristicProperty[] properties; | 79 CharacteristicProperty[] properties; |
66 | 80 |
67 // Returns the identifier assigned to this characteristic. Use the instance | 81 // Returns the identifier assigned to this characteristic. Use the instance |
68 // ID to distinguish between characteristics from a peripheral with the same | 82 // ID to distinguish between characteristics from a peripheral with the same |
69 // UUID and to make function calls that take in a characteristic identifier. | 83 // UUID and to make function calls that take in a characteristic identifier. |
70 // Present, if this instance represents a remote characteristic. | 84 // Present, if this instance represents a remote characteristic. |
71 DOMString? instanceId; | 85 DOMString? instanceId; |
72 | 86 |
73 // The currently cached characteristic value. This value gets updated when | 87 // The currently cached characteristic value. This value gets updated when |
74 // the value of the characteristic is read or updated via a notification | 88 // the value of the characteristic is read or updated via a notification |
75 // or indication. | 89 // or indication. |
76 ArrayBuffer? value; | 90 ArrayBuffer? value; |
77 }; | 91 }; |
78 | 92 |
79 // Represents a GATT characteristic descriptor, which provides further | 93 // Represents a GATT characteristic descriptor, which provides further |
80 // information about a characteristic's value. | 94 // information about a characteristic's value. |
81 dictionary Descriptor { | 95 dictionary Descriptor { |
82 // The UUID of the characteristic descriptor, e.g. | 96 // The UUID of the characteristic descriptor, e.g. |
83 // 00002902-0000-1000-8000-00805f9b34fb. | 97 // 00002902-0000-1000-8000-00805f9b34fb. |
84 DOMString uuid; | 98 DOMString uuid; |
85 | 99 |
86 // Indicates whether this descriptor represents a local descriptor | |
87 // hosted by the application and available to other peripherals, or a remote | |
88 // descriptor hosted and received from a remote peripheral. | |
89 [nodoc] boolean isLocal; | |
90 | |
91 // The GATT characteristic this descriptor belongs to. | 100 // The GATT characteristic this descriptor belongs to. |
92 Characteristic characteristic; | 101 Characteristic? characteristic; |
93 | 102 |
94 // Returns the identifier assigned to this descriptor. Use the instance ID | 103 // Returns the identifier assigned to this descriptor. Use the instance ID |
95 // to distinguish between descriptors from a peripheral with the same UUID | 104 // to distinguish between descriptors from a peripheral with the same UUID |
96 // and to make function calls that take in a descriptor identifier. Present, | 105 // and to make function calls that take in a descriptor identifier. Present, |
97 // if this instance represents a remote characteristic. | 106 // if this instance represents a remote characteristic. |
98 DOMString? instanceId; | 107 DOMString? instanceId; |
99 | 108 |
100 // The currently cached descriptor value. This value gets updated when | 109 // The currently cached descriptor value. This value gets updated when |
101 // the value of the descriptor is read. | 110 // the value of the descriptor is read. |
102 ArrayBuffer? value; | 111 ArrayBuffer? value; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 | 159 |
151 // List of UUIDs to include in the "Solicit UUIDs" field of the Advertising | 160 // List of UUIDs to include in the "Solicit UUIDs" field of the Advertising |
152 // Data. These UUIDs can be of the 16bit, 32bit or 128 formats. | 161 // Data. These UUIDs can be of the 16bit, 32bit or 128 formats. |
153 DOMString[]? solicitUuids; | 162 DOMString[]? solicitUuids; |
154 | 163 |
155 // List of service data to be included in "Service Data" fields of the adver tising | 164 // List of service data to be included in "Service Data" fields of the adver tising |
156 // data. | 165 // data. |
157 ServiceData[]? serviceData; | 166 ServiceData[]? serviceData; |
158 }; | 167 }; |
159 | 168 |
169 // Represents a response to a attribute read/write request. | |
170 dictionary Response { | |
171 // Id of the request this is a response to. | |
172 long requestId; | |
173 // If this is an error response, this should be true. | |
174 boolean isError; | |
175 // Response value. Write requests and error responses will ignore this | |
176 // parameter. | |
177 ArrayBuffer? value; | |
178 }; | |
179 | |
160 callback CharacteristicCallback = void(Characteristic result); | 180 callback CharacteristicCallback = void(Characteristic result); |
181 callback CreateCharacteristicCallback = void(DOMString characteristicId); | |
161 callback CharacteristicsCallback = void(Characteristic[] result); | 182 callback CharacteristicsCallback = void(Characteristic[] result); |
162 callback DescriptorCallback = void(Descriptor result); | 183 callback DescriptorCallback = void(Descriptor result); |
184 callback CreateDescriptorCallback = void(DOMString descriptorId); | |
163 callback DescriptorsCallback = void(Descriptor[] result); | 185 callback DescriptorsCallback = void(Descriptor[] result); |
164 callback ResultCallback = void(); | 186 callback ResultCallback = void(); |
165 callback ServiceCallback = void(Service result); | 187 callback ServiceCallback = void(Service result); |
188 callback CreateServiceCallback = void(DOMString serviceId); | |
166 callback ServicesCallback = void(Service[] result); | 189 callback ServicesCallback = void(Service[] result); |
190 callback ServiceResultCallback = void(ServiceResult result); | |
167 callback RegisterAdvertisementCallback = void (long advertisementId); | 191 callback RegisterAdvertisementCallback = void (long advertisementId); |
168 | 192 |
169 // These functions all report failures via chrome.runtime.lastError. | 193 // These functions all report failures via chrome.runtime.lastError. |
170 interface Functions { | 194 interface Functions { |
171 // Establishes a connection between the application and the device with the | 195 // Establishes a connection between the application and the device with the |
172 // given address. A device may be already connected and its GATT services | 196 // given address. A device may be already connected and its GATT services |
173 // available without calling <code>connect</code>, however, an app that | 197 // available without calling <code>connect</code>, however, an app that |
174 // wants to access GATT services of a device should call this function to | 198 // wants to access GATT services of a device should call this function to |
175 // make sure that a connection to the device is maintained. If the device | 199 // make sure that a connection to the device is maintained. If the device |
176 // is not connected, all GATT services of the device will be discovered | 200 // is not connected, all GATT services of the device will be discovered |
177 // after a successful call to <code>connect</code>. | 201 // after a successful call to <code>connect</code>. |
178 // |deviceAddress| : The Bluetooth address of the remote device to which a | 202 // |deviceAddress|: The Bluetooth address of the remote device to which a |
179 // GATT connection should be opened. | 203 // GATT connection should be opened. |
180 // |properties| : Connection properties (optional). | 204 // |properties|: Connection properties (optional). |
181 // |callback| : Called when the connect request has completed. | 205 // |callback|: Called when the connect request has completed. |
182 static void connect(DOMString deviceAddress, | 206 static void connect(DOMString deviceAddress, |
183 optional ConnectProperties properties, | 207 optional ConnectProperties properties, |
184 ResultCallback callback); | 208 ResultCallback callback); |
185 | 209 |
186 // Closes the app's connection to the device with the given address. Note | 210 // Closes the app's connection to the device with the given address. Note |
187 // that this will not always destroy the physical link itself, since there | 211 // that this will not always destroy the physical link itself, since there |
188 // may be other apps with open connections. | 212 // may be other apps with open connections. |
189 // |deviceAddress| : The Bluetooth address of the remote device. | 213 // |deviceAddress|: The Bluetooth address of the remote device. |
190 // |callback| : Called when the disconnect request has completed. | 214 // |callback|: Called when the disconnect request has completed. |
191 static void disconnect(DOMString deviceAddress, | 215 static void disconnect(DOMString deviceAddress, |
192 optional ResultCallback callback); | 216 optional ResultCallback callback); |
193 | 217 |
194 // Get the GATT service with the given instance ID. | 218 // Get the GATT service with the given instance ID. |
195 // |serviceId| : The instance ID of the requested GATT service. | 219 // |serviceId|: The instance ID of the requested GATT service. |
196 // |callback| : Called with the requested Service object. | 220 // |callback|: Called with the requested Service object. |
197 static void getService(DOMString serviceId, ServiceCallback callback); | 221 static void getService(DOMString serviceId, ServiceCallback callback); |
198 | 222 |
223 // Create a locally hosted GATT service. This service can be registered | |
224 // to be available on a local GATT server. | |
225 // |service|: The service to create. | |
226 // |callback|: Called with the created services's unique ID. | |
227 static void createService(Service service, CreateServiceCallback callback); | |
228 | |
199 // Get all the GATT services that were discovered on the remote device with | 229 // Get all the GATT services that were discovered on the remote device with |
200 // the given device address. | 230 // the given device address. |
201 // |deviceAddress| : The Bluetooth address of the remote device whose GATT | 231 // |deviceAddress|: The Bluetooth address of the remote device whose GATT |
202 // services should be returned. | 232 // services should be returned. |
203 // |callback| : Called with the list of requested Service objects. | 233 // |callback|: Called with the list of requested Service objects. |
204 static void getServices(DOMString deviceAddress, ServicesCallback callback); | 234 static void getServices(DOMString deviceAddress, ServicesCallback callback); |
205 | 235 |
206 // Get the GATT characteristic with the given instance ID that belongs to | 236 // Get the GATT characteristic with the given instance ID that belongs to |
207 // the given GATT service, if the characteristic exists. | 237 // the given GATT service, if the characteristic exists. |
208 // |characteristicId| : The instance ID of the requested GATT | 238 // |characteristicId|: The instance ID of the requested GATT |
209 // characteristic. | 239 // characteristic. |
210 // |callback| : Called with the requested Characteristic object. | 240 // |callback|: Called with the requested Characteristic object. |
211 static void getCharacteristic(DOMString characteristicId, | 241 static void getCharacteristic(DOMString characteristicId, |
212 CharacteristicCallback callback); | 242 CharacteristicCallback callback); |
213 | 243 |
244 // Create a locally hosted GATT characteristic. This characteristic must | |
245 // be hosted under a valid service. If the service ID is not valid, the | |
246 // lastError will be set. | |
247 // |characteristic|: The characteristic to create. | |
248 // |serviceId|: ID of the service to create this characteristic for. | |
249 // |callback|: Called with the created characteristic's unique ID. | |
250 static void createCharacteristic(Characteristic characteristic, | |
251 DOMString serviceId, | |
252 CreateCharacteristicCallback callback); | |
253 | |
214 // Get a list of all discovered GATT characteristics that belong to the | 254 // Get a list of all discovered GATT characteristics that belong to the |
215 // given service. | 255 // given service. |
216 // |serviceId| : The instance ID of the GATT service whose characteristics | 256 // |serviceId|: The instance ID of the GATT service whose characteristics |
217 // should be returned. | 257 // should be returned. |
218 // |callback| : Called with the list of characteristics that belong to the | 258 // |callback|: Called with the list of characteristics that belong to the |
219 // given service. | 259 // given service. |
220 static void getCharacteristics(DOMString serviceId, | 260 static void getCharacteristics(DOMString serviceId, |
221 CharacteristicsCallback callback); | 261 CharacteristicsCallback callback); |
222 | 262 |
223 // Get a list of GATT services that are included by the given service. | 263 // Get a list of GATT services that are included by the given service. |
224 // |serviceId| : The instance ID of the GATT service whose included | 264 // |serviceId|: The instance ID of the GATT service whose included |
225 // services should be returned. | 265 // services should be returned. |
226 // |callback| : Called with the list of GATT services included from the | 266 // |callback|: Called with the list of GATT services included from the |
227 // given service. | 267 // given service. |
228 static void getIncludedServices(DOMString serviceId, | 268 static void getIncludedServices(DOMString serviceId, |
229 ServicesCallback callback); | 269 ServicesCallback callback); |
230 | 270 |
231 // Get the GATT characteristic descriptor with the given instance ID. | 271 // Get the GATT characteristic descriptor with the given instance ID. |
232 // |descriptorId| : The instance ID of the requested GATT characteristic | 272 // |descriptorId|: The instance ID of the requested GATT characteristic |
233 // descriptor. | 273 // descriptor. |
234 // |callback| : Called with the requested Descriptor object. | 274 // |callback|: Called with the requested Descriptor object. |
235 static void getDescriptor(DOMString descriptorId, | 275 static void getDescriptor(DOMString descriptorId, |
236 DescriptorCallback callback); | 276 DescriptorCallback callback); |
237 | 277 |
278 // Create a locally hosted GATT descriptor. This descriptor must | |
279 // be hosted under a valid characteristic. If the characteristic ID is not | |
280 // valid, the lastError will be set. | |
281 // |descriptor|: The descriptor to create. | |
282 // |characteristicId|: ID of the characteristic to create this descriptor | |
283 // for. | |
284 // |callback|: Called with the created descriptor's unique ID. | |
285 static void createDescriptor(Descriptor descriptor, | |
286 DOMString characteristicId, | |
287 CreateDescriptorCallback callback); | |
288 | |
238 // Get a list of GATT characteristic descriptors that belong to the given | 289 // Get a list of GATT characteristic descriptors that belong to the given |
239 // characteristic. | 290 // characteristic. |
240 // |characteristicId| : The instance ID of the GATT characteristic whose | 291 // |characteristicId|: The instance ID of the GATT characteristic whose |
241 // descriptors should be returned. | 292 // descriptors should be returned. |
242 // |callback| : Called with the list of descriptors that belong to the given | 293 // |callback|: Called with the list of descriptors that belong to the given |
243 // characteristic. | 294 // characteristic. |
244 static void getDescriptors(DOMString characteristicId, | 295 static void getDescriptors(DOMString characteristicId, |
245 DescriptorsCallback callback); | 296 DescriptorsCallback callback); |
246 | 297 |
247 // Retrieve the value of a specified characteristic from a remote | 298 // Retrieve the value of a specified characteristic from a remote |
248 // peripheral. | 299 // peripheral. |
249 // |characteristicId| : The instance ID of the GATT characteristic whose | 300 // |characteristicId|: The instance ID of the GATT characteristic whose |
250 // value should be read from the remote device. | 301 // value should be read from the remote device. |
251 // |callback| : Called with the Characteristic object whose value was | 302 // |callback|: Called with the Characteristic object whose value was |
252 // requested. The <code>value</code> field of the returned Characteristic | 303 // requested. The <code>value</code> field of the returned Characteristic |
253 // object contains the result of the read request. | 304 // object contains the result of the read request. |
254 static void readCharacteristicValue(DOMString characteristicId, | 305 static void readCharacteristicValue(DOMString characteristicId, |
255 CharacteristicCallback callback); | 306 CharacteristicCallback callback); |
256 | 307 |
257 // Write the value of a specified characteristic from a remote peripheral. | 308 // Write the value of a specified characteristic from a remote peripheral. |
258 // |characteristicId| : The instance ID of the GATT characteristic whose | 309 // |characteristicId|: The instance ID of the GATT characteristic whose |
259 // value should be written to. | 310 // value should be written to. |
260 // |value| : The value that should be sent to the remote characteristic as | 311 // |value|: The value that should be sent to the remote characteristic as |
261 // part of the write request. | 312 // part of the write request. |
262 // |callback| : Called when the write request has completed. | 313 // |callback|: Called when the write request has completed. |
263 static void writeCharacteristicValue(DOMString characteristicId, | 314 static void writeCharacteristicValue(DOMString characteristicId, |
264 ArrayBuffer value, | 315 ArrayBuffer value, |
265 ResultCallback callback); | 316 ResultCallback callback); |
266 | 317 |
267 // Enable value notifications/indications from the specified characteristic. | 318 // Enable value notifications/indications from the specified characteristic. |
268 // Once enabled, an application can listen to notifications using the | 319 // Once enabled, an application can listen to notifications using the |
269 // $(ref:onCharacteristicValueChanged) event. | 320 // $(ref:onCharacteristicValueChanged) event. |
270 // |characteristicId| : The instance ID of the GATT characteristic that | 321 // |characteristicId|: The instance ID of the GATT characteristic that |
271 // notifications should be enabled on. | 322 // notifications should be enabled on. |
272 // |properties| : Notification session properties (optional). | 323 // |properties|: Notification session properties (optional). |
273 // |callback| : Called when the request has completed. | 324 // |callback|: Called when the request has completed. |
274 static void startCharacteristicNotifications( | 325 static void startCharacteristicNotifications( |
275 DOMString characteristicId, | 326 DOMString characteristicId, |
276 optional NotificationProperties properties, | 327 optional NotificationProperties properties, |
277 ResultCallback callback); | 328 ResultCallback callback); |
278 | 329 |
279 // Disable value notifications/indications from the specified | 330 // Disable value notifications/indications from the specified |
280 // characteristic. After a successful call, the application will stop | 331 // characteristic. After a successful call, the application will stop |
281 // receiving notifications/indications from this characteristic. | 332 // receiving notifications/indications from this characteristic. |
282 // |characteristicId| : The instance ID of the GATT characteristic on which | 333 // |characteristicId|: The instance ID of the GATT characteristic on which |
283 // this app's notification session should be stopped. | 334 // this app's notification session should be stopped. |
284 // |callback| : Called when the request has completed (optional). | 335 // |callback|: Called when the request has completed (optional). |
285 static void stopCharacteristicNotifications( | 336 static void stopCharacteristicNotifications( |
286 DOMString characteristicId, | 337 DOMString characteristicId, |
287 optional ResultCallback callback); | 338 optional ResultCallback callback); |
288 | 339 |
289 // Retrieve the value of a specified characteristic descriptor from a remote | 340 // Retrieve the value of a specified characteristic descriptor from a remote |
290 // peripheral. | 341 // peripheral. |
291 // |descriptorId| : The instance ID of the GATT characteristic descriptor | 342 // |descriptorId|: The instance ID of the GATT characteristic descriptor |
292 // whose value should be read from the remote device. | 343 // whose value should be read from the remote device. |
293 // |callback| : Called with the Descriptor object whose value was requested. | 344 // |callback|: Called with the Descriptor object whose value was requested. |
294 // The <code>value</code> field of the returned Descriptor object contains | 345 // The <code>value</code> field of the returned Descriptor object contains |
295 // the result of the read request. | 346 // the result of the read request. |
296 static void readDescriptorValue(DOMString descriptorId, | 347 static void readDescriptorValue(DOMString descriptorId, |
297 DescriptorCallback callback); | 348 DescriptorCallback callback); |
298 | 349 |
299 // Write the value of a specified characteristic descriptor from a remote | 350 // Write the value of a specified characteristic descriptor from a remote |
300 // peripheral. | 351 // peripheral. |
301 // |descriptorId| : The instance ID of the GATT characteristic descriptor | 352 // |descriptorId|: The instance ID of the GATT characteristic descriptor |
302 // whose value should be written to. | 353 // whose value should be written to. |
303 // |value| : The value that should be sent to the remote descriptor as part | 354 // |value|: The value that should be sent to the remote descriptor as part |
304 // of the write request. | 355 // of the write request. |
305 // |callback| : Called when the write request has completed. | 356 // |callback|: Called when the write request has completed. |
306 static void writeDescriptorValue(DOMString descriptorId, | 357 static void writeDescriptorValue(DOMString descriptorId, |
307 ArrayBuffer value, | 358 ArrayBuffer value, |
308 ResultCallback callback); | 359 ResultCallback callback); |
309 | 360 |
361 // Register the given service with the local GATT server. If the service | |
362 // ID is invalid, the lastError will be set. | |
363 // |serviceId|: Unique ID of a created service. | |
364 // |callback|: Callback with the result of the register operation. | |
365 static void registerService( | |
366 DOMString serviceId, ServiceResultCallback callback); | |
367 | |
368 // Unregister the given service with the local GATT server. If the service | |
369 // ID is invalid, the lastError will be set. | |
370 // |serviceId|: Unique ID of a current registered service. | |
371 // |callback|: Callback with the result of the register operation. | |
372 static void unregisterService( | |
373 DOMString serviceId, ServiceResultCallback callback); | |
374 | |
310 // Create an advertisement and register it for advertising. To call this | 375 // Create an advertisement and register it for advertising. To call this |
311 // function, the app must have the bluetooth:low_energy and | 376 // function, the app must have the bluetooth:low_energy and |
312 // bluetooth:peripheral permissions set to true. Additionally this API | 377 // bluetooth:peripheral permissions set to true. Additionally this API |
313 // is only available to auto launched apps in Kiosk Mode of by setting | 378 // is only available to auto launched apps in Kiosk Mode of by setting |
314 // the 'enable-ble-advertising-in-apps' flag. | 379 // the 'enable-ble-advertising-in-apps' flag. |
315 // See https://developer.chrome.com/apps/manifest/bluetooth | 380 // See https://developer.chrome.com/apps/manifest/bluetooth |
316 // Note: On some hardware, central and peripheral modes at the same time is | 381 // Note: On some hardware, central and peripheral modes at the same time is |
317 // supported but on hardware that doesn't support this, making this call | 382 // supported but on hardware that doesn't support this, making this call |
318 // will switch the device to peripheral mode. In the case of hardware which | 383 // will switch the device to peripheral mode. In the case of hardware which |
319 // does not support both central and peripheral mode, attempting to use the | 384 // does not support both central and peripheral mode, attempting to use the |
320 // device in both modes will lead to undefined behavior or prevent other | 385 // device in both modes will lead to undefined behavior or prevent other |
321 // central-role applications from behaving correctly (including the | 386 // central-role applications from behaving correctly (including the |
322 // discovery of Bluetooth Low Energy devices). | 387 // discovery of Bluetooth Low Energy devices). |
323 // |advertisement| : The advertisement to advertise. | 388 // |advertisement|: The advertisement to advertise. |
324 // |callback| : Called once the registeration is done and we've started | 389 // |callback|: Called once the registeration is done and we've started |
325 // advertising. Returns the id of the created advertisement. | 390 // advertising. Returns the id of the created advertisement. |
326 static void registerAdvertisement( | 391 static void registerAdvertisement( |
327 Advertisement advertisement, RegisterAdvertisementCallback callback); | 392 Advertisement advertisement, RegisterAdvertisementCallback callback); |
328 | 393 |
329 // Unregisters an advertisement and stops its advertising. If the | 394 // Unregisters an advertisement and stops its advertising. If the |
330 // advertisement fails to unregister the only way to stop advertising | 395 // advertisement fails to unregister the only way to stop advertising |
331 // might be to restart the device. | 396 // might be to restart the device. |
332 // |advertisementId| : Id of the advertisement to unregister. | 397 // |advertisementId|: Id of the advertisement to unregister. |
333 // |callback| : Called once the advertisement is unregistered and is no | 398 // |callback|: Called once the advertisement is unregistered and is no |
334 // longer being advertised. | 399 // longer being advertised. |
335 static void unregisterAdvertisement(long advertisementId, | 400 static void unregisterAdvertisement(long advertisementId, |
336 ResultCallback callback); | 401 ResultCallback callback); |
402 | |
403 // Sends a response for a characteristic or descriptor read/write | |
404 // request. | |
405 // |response|: The response to the request. | |
406 static void sendRequestResponse(Response response); | |
337 }; | 407 }; |
338 | 408 |
339 interface Events { | 409 interface Events { |
340 // Fired whan a new GATT service has been discovered on a remote device. | 410 // Fired whan a new GATT service has been discovered on a remote device. |
341 // |service| : The GATT service that was added. | 411 // |service|: The GATT service that was added. |
342 static void onServiceAdded(Service service); | 412 static void onServiceAdded(Service service); |
343 | 413 |
344 // Fired when the state of a remote GATT service changes. This involves any | 414 // Fired when the state of a remote GATT service changes. This involves any |
345 // characteristics and/or descriptors that get added or removed from the | 415 // characteristics and/or descriptors that get added or removed from the |
346 // service, as well as "ServiceChanged" notifications from the remote | 416 // service, as well as "ServiceChanged" notifications from the remote |
347 // device. | 417 // device. |
348 // |service| : The GATT service whose state has changed. | 418 // |service|: The GATT service whose state has changed. |
349 static void onServiceChanged(Service service); | 419 static void onServiceChanged(Service service); |
350 | 420 |
351 // Fired when a GATT service that was previously discovered on a remote | 421 // Fired when a GATT service that was previously discovered on a remote |
352 // device has been removed. | 422 // device has been removed. |
353 // |service| : The GATT service that was removed. | 423 // |service|: The GATT service that was removed. |
354 static void onServiceRemoved(Service service); | 424 static void onServiceRemoved(Service service); |
355 | 425 |
356 // Fired when the value of a remote GATT characteristic changes, either as | 426 // Fired when the value of a remote GATT characteristic changes, either as |
357 // a result of a read request, or a value change notification/indication | 427 // a result of a read request, or a value change notification/indication |
358 // This event will only be sent if the app has enabled notifications by | 428 // This event will only be sent if the app has enabled notifications by |
359 // calling $(ref:startCharacteristicNotifications). | 429 // calling $(ref:startCharacteristicNotifications). |
360 // |characteristic| : The GATT characteristic whose value has changed. | 430 // |characteristic|: The GATT characteristic whose value has changed. |
361 static void onCharacteristicValueChanged(Characteristic characteristic); | 431 static void onCharacteristicValueChanged(Characteristic characteristic); |
362 | 432 |
363 // Fired when the value of a remote GATT characteristic descriptor changes, | 433 // Fired when the value of a remote GATT characteristic descriptor changes, |
364 // usually as a result of a read request. This event exists | 434 // usually as a result of a read request. This event exists |
365 // mostly for convenience and will always be sent after a successful | 435 // mostly for convenience and will always be sent after a successful |
366 // call to $(ref:readDescriptorValue). | 436 // call to $(ref:readDescriptorValue). |
367 // |descriptor| : The GATT characteristic descriptor whose value has | 437 // |descriptor|: The GATT characteristic descriptor whose value has |
368 // changed. | 438 // changed. |
369 static void onDescriptorValueChanged(Descriptor descriptor); | 439 static void onDescriptorValueChanged(Descriptor descriptor); |
440 | |
441 // Fired when a connected central device requests to read the value of a | |
442 // characteristic registered on the local GATT server. Not responding | |
443 // to this request for a long time may lead to a disconnection. | |
444 // |requestId|: Unique ID for this request. Use this ID when responding | |
445 // to this request via the sendRequestResponse function. | |
446 // |device|: The bluetooth device that is requesting this read. | |
447 // |characteristic|: The GATT characteristic whose value is requested. | |
448 static void onCharacteristicReadRequest( | |
449 long requestId, Device device, Characteristic characteristic); | |
Devlin
2016/04/29 17:13:13
I'd consider making these dictionaries, too, so th
rkc
2016/04/29 20:15:58
Done.
| |
450 | |
451 // Fired when a connected central device requests to write the value of a | |
452 // characteristic registered on the local GATT server. Not responding | |
453 // to this request for a long time may lead to a disconnection. | |
454 // |requestId|: Unique ID for this request. Use this ID when responding | |
455 // to this request via the sendRequestResponse function. | |
456 // |device|: The bluetooth device that is requesting this write. | |
457 // |characteristic|: The GATT characteristic whose value is being written. | |
458 static void onCharacteristicWriteRequest( | |
459 long requestId, Device device, Characteristic characteristic, | |
460 ArrayBuffer value); | |
461 | |
462 // Fired when a connected central device requests to read the value of a | |
463 // descriptor registered on the local GATT server. Not responding to | |
464 // this request for a long time may lead to a disconnection. | |
465 // |requestId|: Unique ID for this request. Use this ID when responding | |
466 // to this request via the sendRequestResponse function. | |
467 // |device|: The bluetooth device that is requesting this read. | |
468 // |descriptor|: The GATT descriptor whose value is requested. | |
469 static void onDescriptorReadRequest( | |
470 long requestId, Device device, Descriptor descriptor); | |
471 | |
472 // Fired when a connected central device requests to write the value of a | |
473 // descriptor registered on the local GATT server. Not responding to | |
474 // this request for a long time may lead to a disconnection. | |
475 // |requestId|: Unique ID for this request. Use this ID when responding | |
476 // to this request via the sendRequestResponse function. | |
477 // |device|: The bluetooth device that is requesting this write. | |
478 // |descriptor|: The GATT descriptor whose value is being written. | |
479 static void onDescriptorWriteRequest( | |
480 long requestId, Device device, Descriptor descriptor, | |
481 ArrayBuffer value); | |
370 }; | 482 }; |
371 }; | 483 }; |
OLD | NEW |