]> git.basschouten.com Git - openhab-addons.git/blob
deab96b1c82eca6ebb3eb46c5ae6fe00c0c5fb4b
[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>GapDiscoverableMode</b>.
20  * <p>
21  * GAP discoverable modes
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 GapDiscoverableMode {
28     /**
29      * Default unknown value
30      */
31     UNKNOWN(-1),
32
33     /**
34      * [0] Non-discoverable mode: the LE Limited Discoverable Mode and the LE General
35      * Discoverable Mode bits are NOT set in the AD Flags type. A master can still connect to the
36      * advertising slave in this mode.
37      */
38     GAP_NON_DISCOVERABLE(0x0000),
39
40     /**
41      * [1] Discoverable using limited scanning mode: the advertisement packets will carry the LE
42      * Limited Discoverable Mode bit set in the Flags AD type.
43      */
44     GAP_LIMITED_DISCOVERABLE(0x0001),
45
46     /**
47      * [2] Discoverable using general scanning mode: the advertisement packets will carry the LE
48      * General Discoverable Mode bit set in the Flags AD type.
49      */
50     GAP_GENERAL_DISCOVERABLE(0x0002),
51
52     /**
53      * [3] Same as gap_non_discoverable.
54      */
55     GAP_BROADCAST(0x0003),
56
57     /**
58      * [4] In this advertisement the advertisement and scan response data defined by user will be
59      * used. The user is responsible of building the advertisement data so that it also contains the
60      * appropriate desired Flags AD type.
61      */
62     GAP_USER_DATA(0x0004),
63
64     /**
65      * [128] When turning the most highest bit on in GAP discoverable mode, the remote devices that
66      * send scan request packets to the advertiser are reported back to the application through
67      * Scan Response event. This is so called Enhanced Broadcasting mode.
68      */
69     GAP_ENHANCED_BROADCASTING(0x0080);
70
71     /**
72      * A mapping between the integer code and its corresponding type to
73      * facilitate lookup by code.
74      */
75     private static Map<Integer, GapDiscoverableMode> codeMapping;
76
77     private int key;
78
79     private GapDiscoverableMode(int key) {
80         this.key = key;
81     }
82
83     private static void initMapping() {
84         codeMapping = new HashMap<>();
85         for (GapDiscoverableMode s : values()) {
86             codeMapping.put(s.key, s);
87         }
88     }
89
90     /**
91      * Lookup function based on the type code. Returns null if the code does not exist.
92      *
93      * @param gapDiscoverableMode
94      *            the code to lookup
95      * @return enumeration value.
96      */
97     public static GapDiscoverableMode getGapDiscoverableMode(int gapDiscoverableMode) {
98         if (codeMapping == null) {
99             initMapping();
100         }
101
102         if (codeMapping.get(gapDiscoverableMode) == null) {
103             return UNKNOWN;
104         }
105
106         return codeMapping.get(gapDiscoverableMode);
107     }
108
109     /**
110      * Returns the BlueGiga protocol defined value for this enum
111      *
112      * @return the BGAPI enumeration key
113      */
114     public int getKey() {
115         return key;
116     }
117 }