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