2 * Copyright (c) 2010-2022 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.bluetooth.bluegiga.internal.command.gap;
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;
21 * Class to implement the BlueGiga command <b>setMode</b>.
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.
27 * This class provides methods for processing BlueGiga API commands.
29 * Note that this code is autogenerated. Manual changes may be overwritten.
31 * @author Chris Jackson - Initial contribution of Java code generator
32 * @author Pauli Anttila - Added message builder
35 public class BlueGigaSetModeCommand extends BlueGigaCommand {
36 public static int COMMAND_CLASS = 0x06;
37 public static int COMMAND_METHOD = 0x01;
39 private BlueGigaSetModeCommand(CommandBuilder builder) {
40 this.discover = builder.discover;
41 this.connect = builder.connect;
45 * see:GAP Discoverable Mode
47 * BlueGiga API type is <i>GapDiscoverableMode</i> - Java type is {@link GapDiscoverableMode}
49 private GapDiscoverableMode discover;
52 * see:GAP Connectable Mode
54 * BlueGiga API type is <i>GapConnectableMode</i> - Java type is {@link GapConnectableMode}
56 private GapConnectableMode connect;
59 public int[] serialize() {
60 // Serialize the header
61 serializeHeader(COMMAND_CLASS, COMMAND_METHOD);
63 // Serialize the fields
64 serializeGapDiscoverableMode(discover);
65 serializeGapConnectableMode(connect);
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);
78 return builder.toString();
81 public static class CommandBuilder {
82 private GapDiscoverableMode discover = GapDiscoverableMode.UNKNOWN;
83 private GapConnectableMode connect = GapConnectableMode.UNKNOWN;
86 * see:GAP Discoverable Mode
88 * @param discover the discover to set as {@link GapDiscoverableMode}
90 public CommandBuilder withDiscover(GapDiscoverableMode discover) {
91 this.discover = discover;
96 * see:GAP Connectable Mode
98 * @param connect the connect to set as {@link GapConnectableMode}
100 public CommandBuilder withConnect(GapConnectableMode connect) {
101 this.connect = connect;
105 public BlueGigaSetModeCommand build() {
106 return new BlueGigaSetModeCommand(this);