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