]> git.basschouten.com Git - openhab-addons.git/blob
2041989e9dbe5b2c0013c1f3e836bb52b13f9213
[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
20 /**
21  * Definition of the EIR Flags field
22  *
23  * @author Chris Jackson - Initial contribution
24  *
25  */
26 @NonNullByDefault
27 public enum EirFlags {
28     UNKNOWN(-1),
29     LE_LIMITED_DISCOVERABLE_MODE(0),
30     LE_GENERAL_DISCOVERABLE_MODE(1),
31     BR_EDR_NOT_SUPPORTED(2),
32     SIMULTANEOUS_LE_BDR_CONTROLLER(3),
33     SIMULTANEOUS_LE_BDR_HOST(4),
34     BIT5(5),
35     BIT6(6),
36     BIT7(7),
37     BIT8(8),
38     BIT9(9),
39     BIT10(10),
40     BIT11(11),
41     BIT12(12),
42     BIT13(13),
43     BIT14(14),
44     BIT15(15);
45
46     /**
47      * A mapping between the integer code and its corresponding type to
48      * facilitate lookup by code.
49      */
50     private static Map<Integer, EirFlags> codeMapping = new HashMap<>();
51
52     private int key;
53
54     private EirFlags(int key) {
55         this.key = key;
56     }
57
58     private static void initMapping() {
59         codeMapping = new HashMap<>();
60         for (EirFlags s : values()) {
61             codeMapping.put(s.key, s);
62         }
63     }
64
65     /**
66      * Lookup function based on the type code. Returns null if the code does not exist.
67      *
68      * @param bluetoothAddressType
69      *            the code to lookup
70      * @return enumeration value.
71      */
72     @SuppressWarnings({ "null", "unused" })
73     public static EirFlags getEirFlag(int eirFlag) {
74         if (codeMapping.isEmpty()) {
75             initMapping();
76         }
77
78         return codeMapping.getOrDefault(eirFlag, UNKNOWN);
79     }
80
81     /**
82      * Returns the Bluetooth protocol defined value for this enum
83      *
84      * @return the EIR Data type key
85      */
86     public int getKey() {
87         return key;
88     }
89 }