2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.bluetooth;
15 import java.util.HashMap;
17 import java.util.UUID;
20 * The {@link BluetoothDescriptor} class defines the Bluetooth descriptor.
22 * Descriptors are defined attributes that describe a characteristic value.
24 * https://www.bluetooth.com/specifications/gatt/descriptors
26 * @author Chris Jackson - Initial contribution
27 * @author Kai Kreuzer - added constructor and fixed setValue method
29 public class BluetoothDescriptor {
31 protected final BluetoothCharacteristic characteristic;
32 protected final UUID uuid;
34 protected final int handle;
37 * The main constructor
39 * @param characteristic the characteristic that this class describes
40 * @param uuid the uuid of the descriptor
42 public BluetoothDescriptor(BluetoothCharacteristic characteristic, UUID uuid, int handle) {
43 this.characteristic = characteristic;
49 * Returns the characteristic this descriptor belongs to.
53 BluetoothCharacteristic getCharacteristic() {
54 return characteristic;
58 * Returns the permissions for this descriptor.
60 * @return the permissions
62 public int getPermissions() {
67 * Returns the UUID of this descriptor.
71 public UUID getUuid() {
76 * Returns the handle for this descriptor
78 * @return the handle for the descriptor
80 public int getHandle() {
84 public GattDescriptor getDescriptor() {
85 return GattDescriptor.getDescriptor(uuid);
88 public enum GattDescriptor {
90 CHARACTERISTIC_EXTENDED_PROPERTIES(0x2900),
91 CHARACTERISTIC_USER_DESCRIPTION(0x2901),
92 CLIENT_CHARACTERISTIC_CONFIGURATION(0x2902),
93 SERVER_CHARACTERISTIC_CONFIGURATION(0x2903),
94 CHARACTERISTIC_PRESENTATION_FORMAT(0x2904),
95 CHARACTERISTIC_AGGREGATE_FORMAT(0x2905),
97 EXTERNAL_REPORT_REFERENCE(0x2907),
98 REPORT_REFERENCE(0x2908),
99 NUMBER_OF_DIGITALS(0x2909),
100 TRIGGER_SETTING(0x290A);
102 private static Map<UUID, GattDescriptor> uuidToServiceMapping;
104 private final UUID uuid;
106 private GattDescriptor(long key) {
107 this.uuid = BluetoothBindingConstants.createBluetoothUUID(key);
110 private static void initMapping() {
111 uuidToServiceMapping = new HashMap<>();
112 for (GattDescriptor s : values()) {
113 uuidToServiceMapping.put(s.uuid, s);
117 public static GattDescriptor getDescriptor(UUID uuid) {
118 if (uuidToServiceMapping == null) {
121 return uuidToServiceMapping.get(uuid);
127 public UUID getUUID() {