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 org.eclipse.jdt.annotation.NonNullByDefault;
18 * Represents a Bluetooth class, which describes the general characteristics and capabilities of a device.
20 * @author Chris Jackson - Initial Contribution
24 public class BluetoothClass {
25 private final int clazz;
27 public static final class Service {
28 private static final int BITMASK = 0xFFE000;
30 public static final int LIMITED_DISCOVERABILITY = 0x002000;
31 public static final int POSITIONING = 0x010000;
32 public static final int NETWORKING = 0x020000;
33 public static final int RENDER = 0x040000;
34 public static final int CAPTURE = 0x080000;
35 public static final int OBJECT_TRANSFER = 0x100000;
36 public static final int AUDIO = 0x200000;
37 public static final int TELEPHONY = 0x400000;
38 public static final int INFORMATION = 0x800000;
41 public static class Device {
42 private static final int BITMASK = 0x1FFC;
45 * Defines the major device class constants.
48 public static class Major {
49 private static final int BITMASK = 0x1F00;
51 public static final int MISC = 0x0000;
52 public static final int COMPUTER = 0x0100;
53 public static final int PHONE = 0x0200;
54 public static final int NETWORKING = 0x0300;
55 public static final int AUDIO_VIDEO = 0x0400;
56 public static final int PERIPHERAL = 0x0500;
57 public static final int IMAGING = 0x0600;
58 public static final int WEARABLE = 0x0700;
59 public static final int TOY = 0x0800;
60 public static final int HEALTH = 0x0900;
61 public static final int UNCATEGORIZED = 0x1F00;
64 // Devices in the COMPUTER major class
65 public static final int COMPUTER_UNCATEGORIZED = 0x0100;
66 public static final int COMPUTER_DESKTOP = 0x0104;
67 public static final int COMPUTER_SERVER = 0x0108;
68 public static final int COMPUTER_LAPTOP = 0x010C;
69 public static final int COMPUTER_HANDHELD_PC_PDA = 0x0110;
70 public static final int COMPUTER_PALM_SIZE_PC_PDA = 0x0114;
71 public static final int COMPUTER_WEARABLE = 0x0118;
73 // Devices in the PHONE major class
74 public static final int PHONE_UNCATEGORIZED = 0x0200;
75 public static final int PHONE_CELLULAR = 0x0204;
76 public static final int PHONE_CORDLESS = 0x0208;
77 public static final int PHONE_SMART = 0x020C;
78 public static final int PHONE_MODEM_OR_GATEWAY = 0x0210;
79 public static final int PHONE_ISDN = 0x0214;
81 // Minor classes for the AUDIO_VIDEO major class
82 public static final int AUDIO_VIDEO_UNCATEGORIZED = 0x0400;
83 public static final int AUDIO_VIDEO_WEARABLE_HEADSET = 0x0404;
84 public static final int AUDIO_VIDEO_HANDSFREE = 0x0408;
85 public static final int AUDIO_VIDEO_MICROPHONE = 0x0410;
86 public static final int AUDIO_VIDEO_LOUDSPEAKER = 0x0414;
87 public static final int AUDIO_VIDEO_HEADPHONES = 0x0418;
88 public static final int AUDIO_VIDEO_PORTABLE_AUDIO = 0x041C;
89 public static final int AUDIO_VIDEO_CAR_AUDIO = 0x0420;
90 public static final int AUDIO_VIDEO_SET_TOP_BOX = 0x0424;
91 public static final int AUDIO_VIDEO_HIFI_AUDIO = 0x0428;
92 public static final int AUDIO_VIDEO_VCR = 0x042C;
93 public static final int AUDIO_VIDEO_VIDEO_CAMERA = 0x0430;
94 public static final int AUDIO_VIDEO_CAMCORDER = 0x0434;
95 public static final int AUDIO_VIDEO_VIDEO_MONITOR = 0x0438;
96 public static final int AUDIO_VIDEO_VIDEO_DISPLAY_AND_LOUDSPEAKER = 0x043C;
97 public static final int AUDIO_VIDEO_VIDEO_CONFERENCING = 0x0440;
98 public static final int AUDIO_VIDEO_VIDEO_GAMING_TOY = 0x0448;
100 // Devices in the WEARABLE major class
101 public static final int WEARABLE_UNCATEGORIZED = 0x0700;
102 public static final int WEARABLE_WRIST_WATCH = 0x0704;
103 public static final int WEARABLE_PAGER = 0x0708;
104 public static final int WEARABLE_JACKET = 0x070C;
105 public static final int WEARABLE_HELMET = 0x0710;
106 public static final int WEARABLE_GLASSES = 0x0714;
108 // Devices in the TOY major class
109 public static final int TOY_UNCATEGORIZED = 0x0800;
110 public static final int TOY_ROBOT = 0x0804;
111 public static final int TOY_VEHICLE = 0x0808;
112 public static final int TOY_DOLL_ACTION_FIGURE = 0x080C;
113 public static final int TOY_CONTROLLER = 0x0810;
114 public static final int TOY_GAME = 0x0814;
116 // Devices in the HEALTH major class
117 public static final int HEALTH_UNCATEGORIZED = 0x0900;
118 public static final int HEALTH_BLOOD_PRESSURE = 0x0904;
119 public static final int HEALTH_THERMOMETER = 0x0908;
120 public static final int HEALTH_WEIGHING = 0x090C;
121 public static final int HEALTH_GLUCOSE = 0x0910;
122 public static final int HEALTH_PULSE_OXIMETER = 0x0914;
123 public static final int HEALTH_PULSE_RATE = 0x0918;
124 public static final int HEALTH_DATA_DISPLAY = 0x091C;
126 // Devices in PERIPHERAL major class
127 public static final int PERIPHERAL_NON_KEYBOARD_NON_POINTING = 0x0500;
128 public static final int PERIPHERAL_KEYBOARD = 0x0540;
129 public static final int PERIPHERAL_POINTING = 0x0580;
130 public static final int PERIPHERAL_KEYBOARD_POINTING = 0x05C0;
136 * @param clazz the device class provided in the bluetooth descriptor
138 public BluetoothClass(int clazz) {
143 * Return the major and minor device class
145 * @return major and minor device class
147 public int getDeviceClass() {
148 return (clazz & Device.BITMASK);
152 * Return the major device class
154 * @return the major device class
156 public int getMajorDeviceClass() {
157 return (clazz & Device.Major.BITMASK);
161 * Return true if the specified service class is supported
163 * @param service the service id
164 * @return true, if the class supports the service
166 public boolean hasService(int service) {
167 return ((clazz & Service.BITMASK & service) != 0);