B2G/Bluetooth/WebBluetooth-v2/BluetoothGattCharacteristic: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
Line 19: Line 19:
   readonly attribute ArrayBuffer?                          [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattCharacteristic#value|value]];
   readonly attribute ArrayBuffer?                          [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattCharacteristic#value|value]];
   [Cached, Constant]
   [Cached, Constant]
   readonly attribute CharacteristicPermissions permissions;
   readonly attribute Permission permissions;
   [Cached, Constant]
   [Cached, Constant]
   readonly attribute [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattCharacteristic#CharacteristicProperties|CharacteristicProperties]]              [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattCharacteristic#properties_2|properties]];
   readonly attribute [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattCharacteristic#CharacteristicProperties|CharacteristicProperties]]              [[B2G/Bluetooth/WebBluetooth-v2/BluetoothGattCharacteristic#properties_2|properties]];

Revision as of 09:38, 14 November 2014

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 Permission permissions;
  [Cached, Constant]
  readonly attribute CharacteristicProperties              properties;
  [Cached, Pure]         
           attribute CharacteristicWriteType               writeType;

  [NewObject, Throws] Promise<ArrayBuffer> readValue();
  [NewObject, Throws] Promise<ArrayBuffer> writeValue(ArrayBuffer value);
  [NewObject, Throws] Promise<void> startNotifications();
  [NewObject, Throws] Promise<void> stopNotifications();
  [NewObject, Throws] Promise<BluetoothGattDescriptor> addDescriptor(DOMString aUuid, DescriptorPermissions aPermissions);
};

Permission

dictionary Permission
{
  required boolean read;
  required boolean readEncrypted;
  required boolean readEncryptedMITM;
  required boolean write;
  required boolean writeEncrypted;
  required boolean writeEncryptedMITM;
  required boolean writeSigned;
  required boolean writeSignedMITM;
};

CharacteristicProperties

dictionary CharacteristicProperties
{
  required boolean broadcast;
  required boolean read;
  required boolean writeNoResponse;
  required boolean write;
  required boolean notify;
  required boolean indicate;
  required boolean signedWrite;
  required boolean extendedProps;
};

CharacteristicWriteType

dictionary CharacteristicWriteType
{
  required boolean noResponse;
  required boolean default;
  required boolean signed;
};

Properties

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

properties

Description
A bit mask which describes how the characteristic value can be used.
Value Type
dictionary CharacteristicProperties
Default Value
0

writeType

Description
The type of write operation.
Value Type
dictionary CharacteristicWriteType
Default Value
0

Methods

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 remote device.
Parameter
value
Desired value to be written to the remote device.
Return
A Promise to indicate whether the operation is resolved or rejected. The Promise is resolved along with the characteristic value after this write operation.

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.