]> git.basschouten.com Git - openhab-addons.git/blob
4a7f2ad8ac867a0cd09a5410d119c03e795812dd
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.bluetooth.bluegiga.internal.eir;
14
15 import java.util.HashMap;
16 import java.util.Map;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20
21 /**
22  * Definition of the EIR Flags field
23  *
24  * @author Chris Jackson - Initial contribution
25  *
26  */
27 @NonNullByDefault
28 public enum EirFlags {
29     UNKNOWN(-1),
30     LE_LIMITED_DISCOVERABLE_MODE(0),
31     LE_GENERAL_DISCOVERABLE_MODE(1),
32     BR_EDR_NOT_SUPPORTED(2),
33     SIMULTANEOUS_LE_BDR_CONTROLLER(3),
34     SIMULTANEOUS_LE_BDR_HOST(4),
35     BIT5(5),
36     BIT6(6),
37     BIT7(7),
38     BIT8(8),
39     BIT9(9),
40     BIT10(10),
41     BIT11(11),
42     BIT12(12),
43     BIT13(13),
44     BIT14(14),
45     BIT15(15);
46
47     /**
48      * A mapping between the integer code and its corresponding type to
49      * facilitate lookup by code.
50      */
51     private static @Nullable Map<Integer, EirFlags> codeMapping;
52
53     private int key;
54
55     private EirFlags(int key) {
56         this.key = key;
57     }
58
59     /**
60      * Lookup function based on the type code. Returns {@link UNKNOWN} if the code does not exist.
61      *
62      * @param bluetoothAddressType
63      *            the code to lookup
64      * @return enumeration value.
65      */
66     public static EirFlags getEirFlag(int eirFlag) {
67         Map<Integer, EirFlags> localCodeMapping = codeMapping;
68         if (localCodeMapping == null) {
69             localCodeMapping = new HashMap<>();
70             for (EirFlags s : values()) {
71                 localCodeMapping.put(s.key, s);
72             }
73             codeMapping = localCodeMapping;
74         }
75
76         return localCodeMapping.getOrDefault(eirFlag, UNKNOWN);
77     }
78
79     /**
80      * Returns the Bluetooth protocol defined value for this enum
81      *
82      * @return the EIR Data type key
83      */
84     public int getKey() {
85         return key;
86     }
87 }