]> git.basschouten.com Git - openhab-addons.git/blob
6cea2aa0aa2ef0c73184091ffef5174f430efbb1
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.GapDiscoverMode;
18
19 /**
20  * Class to implement the BlueGiga command <b>discover</b>.
21  * <p>
22  * This command starts the GAP discovery procedure to scan for advertising devices i.e. to
23  * perform a device discovery. Scanning parameters can be configured with the Set Scan
24  * Parameters command before issuing this command. To cancel on an ongoing discovery process
25  * use the End Procedure command.
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  */
33 @NonNullByDefault
34 public class BlueGigaDiscoverCommand extends BlueGigaCommand {
35     public static int COMMAND_CLASS = 0x06;
36     public static int COMMAND_METHOD = 0x02;
37
38     private BlueGigaDiscoverCommand(CommandBuilder builder) {
39         this.mode = builder.mode;
40     }
41
42     /**
43      * see:GAP Discover Mode.
44      * <p>
45      * BlueGiga API type is <i>GapDiscoverMode</i> - Java type is {@link GapDiscoverMode}
46      */
47     private GapDiscoverMode mode;
48
49     @Override
50     public int[] serialize() {
51         // Serialize the header
52         serializeHeader(COMMAND_CLASS, COMMAND_METHOD);
53
54         // Serialize the fields
55         serializeGapDiscoverMode(mode);
56
57         return getPayload();
58     }
59
60     @Override
61     public String toString() {
62         final StringBuilder builder = new StringBuilder();
63         builder.append("BlueGigaDiscoverCommand [mode=");
64         builder.append(mode);
65         builder.append(']');
66         return builder.toString();
67     }
68
69     public static class CommandBuilder {
70         private GapDiscoverMode mode = GapDiscoverMode.UNKNOWN;
71
72         /**
73          * see:GAP Discover Mode.
74          *
75          * @param mode the mode to set as {@link GapDiscoverMode}
76          */
77         public CommandBuilder withMode(GapDiscoverMode mode) {
78             this.mode = mode;
79             return this;
80         }
81
82         public BlueGigaDiscoverCommand build() {
83             return new BlueGigaDiscoverCommand(this);
84         }
85     }
86 }