]> git.basschouten.com Git - openhab-addons.git/blob
028792b9c619edb5b3cb5087d0f546715d1dfeca
[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.command.gap;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaCommand;
17 import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.GapConnectableMode;
18 import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.GapDiscoverableMode;
19
20 /**
21  * Class to implement the BlueGiga command <b>setMode</b>.
22  * <p>
23  * This command configures the current GAP discoverability and connectability modes. It can
24  * be used to enable advertisements and/or allow connection. The command is also meant to fully
25  * stop advertising, when using gap_non_discoverable and gap_non_connectable.
26  * <p>
27  * This class provides methods for processing BlueGiga API commands.
28  * <p>
29  * Note that this code is autogenerated. Manual changes may be overwritten.
30  *
31  * @author Chris Jackson - Initial contribution of Java code generator
32  * @author Pauli Anttila - Added message builder
33  */
34 @NonNullByDefault
35 public class BlueGigaSetModeCommand extends BlueGigaCommand {
36     public static final int COMMAND_CLASS = 0x06;
37     public static final int COMMAND_METHOD = 0x01;
38
39     private BlueGigaSetModeCommand(CommandBuilder builder) {
40         this.discover = builder.discover;
41         this.connect = builder.connect;
42     }
43
44     /**
45      * see:GAP Discoverable Mode
46      * <p>
47      * BlueGiga API type is <i>GapDiscoverableMode</i> - Java type is {@link GapDiscoverableMode}
48      */
49     private GapDiscoverableMode discover;
50
51     /**
52      * see:GAP Connectable Mode
53      * <p>
54      * BlueGiga API type is <i>GapConnectableMode</i> - Java type is {@link GapConnectableMode}
55      */
56     private GapConnectableMode connect;
57
58     @Override
59     public int[] serialize() {
60         // Serialize the header
61         serializeHeader(COMMAND_CLASS, COMMAND_METHOD);
62
63         // Serialize the fields
64         serializeGapDiscoverableMode(discover);
65         serializeGapConnectableMode(connect);
66
67         return getPayload();
68     }
69
70     @Override
71     public String toString() {
72         final StringBuilder builder = new StringBuilder();
73         builder.append("BlueGigaSetModeCommand [discover=");
74         builder.append(discover);
75         builder.append(", connect=");
76         builder.append(connect);
77         builder.append(']');
78         return builder.toString();
79     }
80
81     public static class CommandBuilder {
82         private GapDiscoverableMode discover = GapDiscoverableMode.UNKNOWN;
83         private GapConnectableMode connect = GapConnectableMode.UNKNOWN;
84
85         /**
86          * see:GAP Discoverable Mode
87          *
88          * @param discover the discover to set as {@link GapDiscoverableMode}
89          */
90         public CommandBuilder withDiscover(GapDiscoverableMode discover) {
91             this.discover = discover;
92             return this;
93         }
94
95         /**
96          * see:GAP Connectable Mode
97          *
98          * @param connect the connect to set as {@link GapConnectableMode}
99          */
100         public CommandBuilder withConnect(GapConnectableMode connect) {
101             this.connect = connect;
102             return this;
103         }
104
105         public BlueGigaSetModeCommand build() {
106             return new BlueGigaSetModeCommand(this);
107         }
108     }
109 }