]> git.basschouten.com Git - openhab-addons.git/blob
38895ec009c516aad60e8f012ada947f2161e663
[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.enumeration;
14
15 import java.util.HashMap;
16 import java.util.Map;
17
18 /**
19  * Class to implement the BlueGiga Enumeration <b>ScanResponseType</b>.
20  * <p>
21  * Defines the packet types received during a scan response
22  * <p>
23  * Note that this code is autogenerated. Manual changes may be overwritten.
24  *
25  * @author Chris Jackson - Initial contribution of Java code generator
26  */
27 public enum ScanResponseType {
28     /**
29      * Default unknown value
30      */
31     UNKNOWN(-1),
32
33     /**
34      * [0] Connectable Advertisement packet
35      */
36     CONNECTABLE_ADVERTISEMENT(0x0000),
37
38     /**
39      * [2] Non Connectable Advertisement packet
40      */
41     NON_CONNECTABLE_ADVERTISEMENT(0x0002),
42
43     /**
44      * [4] Scan response packet
45      */
46     SCAN_RESPONSE(0x0004),
47
48     /**
49      * [6] Discoverable advertisement packet
50      */
51     DISCOVERABLE_ADVERTISEMENT(0x0006);
52
53     /**
54      * A mapping between the integer code and its corresponding type to
55      * facilitate lookup by code.
56      */
57     private static Map<Integer, ScanResponseType> codeMapping;
58
59     private int key;
60
61     private ScanResponseType(int key) {
62         this.key = key;
63     }
64
65     private static void initMapping() {
66         codeMapping = new HashMap<>();
67         for (ScanResponseType s : values()) {
68             codeMapping.put(s.key, s);
69         }
70     }
71
72     /**
73      * Lookup function based on the type code. Returns null if the code does not exist.
74      *
75      * @param scanResponseType
76      *            the code to lookup
77      * @return enumeration value.
78      */
79     public static ScanResponseType getScanResponseType(int scanResponseType) {
80         if (codeMapping == null) {
81             initMapping();
82         }
83
84         if (codeMapping.get(scanResponseType) == null) {
85             return UNKNOWN;
86         }
87
88         return codeMapping.get(scanResponseType);
89     }
90
91     /**
92      * Returns the BlueGiga protocol defined value for this enum
93      *
94      * @return the BGAPI enumeration key
95      */
96     public int getKey() {
97         return key;
98     }
99 }