B2G/Bluetooth/WebBluetooth-v2/BluetoothGattCharacteristic: Difference between revisions
< B2G | Bluetooth | WebBluetooth-v2
Jump to navigation
Jump to search
(edit write characteristic value for both server and client) |
(add a value parameter into addDescriptor) |
||
Line 26: | Line 26: | ||
[NewObject] Promise<void> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattCharacteristic#startNotifications.28.29|startNotifications()]]; | [NewObject] Promise<void> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattCharacteristic#startNotifications.28.29|startNotifications()]]; | ||
[NewObject] Promise<void> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattCharacteristic#stopNotifications.28.29|stopNotifications()]]; | [NewObject] Promise<void> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattCharacteristic#stopNotifications.28.29|stopNotifications()]]; | ||
[NewObject] Promise<[[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattDescriptor#BluetoothGattDescriptor|BluetoothGattDescriptor]]> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattCharacteristic#addDescriptor.28DOMString_uuid.2C_Permissions_permissions.29|addDescriptor(DOMString uuid, Permissions permissions)]]; | [NewObject] Promise<[[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattDescriptor#BluetoothGattDescriptor|BluetoothGattDescriptor]]> [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattCharacteristic#addDescriptor.28DOMString_uuid.2C_Permissions_permissions.2C_ArrayBuffer_value.29|addDescriptor(DOMString uuid, Permissions permissions, ArrayBuffer value)]]; | ||
}; | }; | ||
Line 166: | Line 166: | ||
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattCharacteristic#startNotifications.28.29|BluetoothGattCharacteristic.startNotifications()]] | * [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattCharacteristic#startNotifications.28.29|BluetoothGattCharacteristic.startNotifications()]] | ||
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattCharacteristic#stopNotifications.28.29|BluetoothGattCharacteristic.stopNotifications()]] | * [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattCharacteristic#stopNotifications.28.29|BluetoothGattCharacteristic.stopNotifications()]] | ||
* [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattCharacteristic#addDescriptor.28DOMString_uuid.2C_Permissions_permissions.29|addDescriptor(DOMString uuid, Permissions permissions)]] | * [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattCharacteristic#addDescriptor.28DOMString_uuid.2C_Permissions_permissions.2C_ArrayBuffer_value.29|addDescriptor(DOMString uuid, Permissions permissions, ArrayBuffer value)]] | ||
=== readValue() === | === readValue() === | ||
Line 204: | Line 204: | ||
: A Promise to indicate whether the operation is resolved or rejected. The Promise is rejected if there is no Client Characteristic Configuration descriptor (CCCD) for this characteristic. | : A Promise to indicate whether the operation is resolved or rejected. The Promise is rejected if there is no Client Characteristic Configuration descriptor (CCCD) for this characteristic. | ||
=== addDescriptor(DOMString uuid, Permissions permissions) === | === addDescriptor(DOMString uuid, Permissions permissions, ArrayBuffer value) === | ||
; Description | ; Description | ||
Line 214: | Line 214: | ||
: ''permissions'' | : ''permissions'' | ||
:: [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattCharacteristic#Permissions|Permissions]] of the descriptor to add. | :: [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattCharacteristic#Permissions|Permissions]] of the descriptor to add. | ||
: ''value'' | |||
:: The initial value of this descriptor. | |||
; Return | ; Return | ||
: A Promise to indicate whether the operation is resolved or rejected. If the Promise is resolved, it returns the added [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattDescriptor#BluetoothGattDescriptor|BluetoothGattDescriptor]] object, and property [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattCharacteristic#descriptors|descriptors]] is also updated with the added descriptor. | : A Promise to indicate whether the operation is resolved or rejected. If the Promise is resolved, it returns the added [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattDescriptor#BluetoothGattDescriptor|BluetoothGattDescriptor]] object, and property [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattCharacteristic#descriptors|descriptors]] is also updated with the added descriptor. |
Revision as of 07:36, 6 May 2015
Overview
BluetoothGattCharacteristic represents the characteristic of services. BluetoothGattCharacteristic consists of the characteristic definition, a characteristic value along with properties and configurations which indicate how to access the value, and a list of descriptors which provides related information of this characteristic value.
Interfaces
BluetoothGattCharacteristic
[CheckPermissions="bluetooth"] interface BluetoothGattCharacteristic { readonly attribute BluetoothGattService service; [Cached, Pure] readonly attribute sequence<BluetoothGattDescriptor> descriptors; readonly attribute DOMString uuid; readonly attribute unsigned short instanceId; readonly attribute ArrayBuffer? value; [Cached, Constant] readonly attribute Permissions permissions; [Cached, Constant] readonly attribute GattCharacteristicProperties properties; [Cached, Pure] attribute WriteType writeType; [NewObject] Promise<ArrayBuffer> readValue(); [NewObject] Promise<void> writeValue(ArrayBuffer value); [NewObject] Promise<void> startNotifications(); [NewObject] Promise<void> stopNotifications(); [NewObject] Promise<BluetoothGattDescriptor> addDescriptor(DOMString uuid, Permissions permissions, ArrayBuffer value); };
Permissions
dictionary Permissions { boolean read = false; boolean readEncrypted = false; boolean readEncryptedMITM = false; boolean write = false; boolean writeEncrypted = false; boolean writeEncryptedMITM = false; boolean writeSigned = false; boolean writeSignedMITM = false; };
GattCharacteristicProperties
dictionary GattCharacteristicProperties { boolean broadcast = false; boolean read = false; boolean writeNoResponse = false; boolean write = false; boolean notify = false; boolean indicate = false; boolean signedWrite = false; boolean extendedProps = false; };
WriteType
dictionary WriteType { required boolean noResponse; required boolean default; required boolean signed; };
GattCharacteristicProperties
- BluetoothGattCharacteristic.service
- BluetoothGattCharacteristic.descriptors
- BluetoothGattCharacteristic.uuid
- BluetoothGattCharacteristic.instanceId
- BluetoothGattCharacteristic.value
- BluetoothGattCharacteristic.permissions
- BluetoothGattCharacteristic.properties
- BluetoothGattCharacteristic.writeType
service
- Description
- The service which this characteristic belongs to.
- Value Type
- BluetoothGattService
- Default Value
- null pointer
descriptors
- Description
- A cached descriptor array of this characteristic.
- Value Type
- sequence<BluetoothGattDescriptor>
- Default Value
- Empty array (array with length = 0)
uuid
- Description
- This property stores the UUID of this characteristic.
- Value Type
- DOMString
- Default Value
- Empty string ("")
instanceId
- Description
- This property stores the instance id of this characteristic.
- Value Type
- unsigned short
- Default Value
- 0
value
- Description
- The cached value of this characteristic. This value can be updated via readValue() method or via characteristic notification or indication from the remote device.
- Value Type
- ArrayBuffer or null
- Default Value
- null pointer
permissions
- Description
- A bit mask which describes allowed operations on the characteristic.
- Value Type
- dictionary Permissions
- Default Value
- 0
properties
- Description
- A bit mask which describes how to use the characteristic value.
- Value Type
- dictionary GattCharacteristicProperties
- Default Value
- 0
writeType
- Description
- The type of write operation.
- Value Type
- dictionary WriteType
- Default Value
- 0
Methods
- BluetoothGattCharacteristic.readValue()
- BluetoothGattCharacteristic.writeValue(ArrayBuffer value)
- BluetoothGattCharacteristic.startNotifications()
- BluetoothGattCharacteristic.stopNotifications()
- addDescriptor(DOMString uuid, Permissions permissions, ArrayBuffer value)
readValue()
- Description
- Read the characteristic value from the remote device. The cached value property will also be updated after retrieving the value.
- Return
- A Promise to indicate whether the operation is resolved or rejected. The Promise is resolved along with the value retrieved from the remote device.
writeValue(ArrayBuffer value)
- Description
- Write the characteristic value to the GATT server. If the local device is the GATT client, the value will be written to the remote GATT server. On the other hand, if the local device is the GATT server, the value will be written to value.
- Parameter
- value
- Desired value to be written to the GATT server.
- Return
- A Promise to indicate whether the operation is resolved or rejected.
startNotifications()
- Description
- Register notification/indication of this characteristic.
- Return
- A Promise to indicate whether the operation is resolved or rejected. The Promise is rejected if there is no Client Characteristic Configuration descriptor (CCCD) for this characteristic.
stopNotifications()
- Description
- Unregister notification/indication of this characteristic.
- Return
- A Promise to indicate whether the operation is resolved or rejected. The Promise is rejected if there is no Client Characteristic Configuration descriptor (CCCD) for this characteristic.
addDescriptor(DOMString uuid, Permissions permissions, ArrayBuffer value)
- Description
- Adds a descriptor to this characteristic.
- Parameter
- uuid
- UUID of the descriptor to add.
- permissions
- Permissions of the descriptor to add.
- value
- The initial value of this descriptor.
- Return
- A Promise to indicate whether the operation is resolved or rejected. If the Promise is resolved, it returns the added BluetoothGattDescriptor object, and property descriptors is also updated with the added descriptor.