]> git.basschouten.com Git - openhab-addons.git/blob
0c0a5f29470cba23164055b03f4e82759a3e883a
[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
18 /**
19  * Class to implement the BlueGiga command <b>setScanParameters</b>.
20  * <p>
21  * This command sets the scan parameters which affect how other Smart devices are discovered.
22  * <p>
23  * This class provides methods for processing BlueGiga API commands.
24  * <p>
25  * Note that this code is autogenerated. Manual changes may be overwritten.
26  *
27  * @author Chris Jackson - Initial contribution of Java code generator
28  * @author Pauli Anttila - Added message builder
29  */
30 @NonNullByDefault
31 public class BlueGigaSetScanParametersCommand extends BlueGigaCommand {
32     public static int COMMAND_CLASS = 0x06;
33     public static int COMMAND_METHOD = 0x07;
34
35     private BlueGigaSetScanParametersCommand(CommandBuilder builder) {
36         this.scanInterval = builder.scanInterval;
37         this.scanWindow = builder.scanWindow;
38         this.activeScanning = builder.activeScanning;
39     }
40
41     /**
42      * Scan interval defines the interval when scanning is re-started in units of 625us. Range: 0x4
43      * - 0x4000. Default: (46,875ms) 0x4B After every scan interval the scanner will change the
44      * frequency it operates at at it will cycle through all the three advertisements channels in a
45      * round robin fashion. According to the specification all three channels must be Bluetooth
46      * used by a scanner.
47      * <p>
48      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
49      */
50     private int scanInterval;
51
52     /**
53      * Scan Window defines how long time the scanner will listen on a certain frequency and try to
54      * pick up advertisement packets. Scan window is defined as units of 625us. Range: 0x4 - 0x4000.
55      * Default: 0x32 (31,25 ms). Scan windows must be equal or smaller than scan interval If scan
56      * window is equal to the scan interval value, then the module Bluetooth will be scanning at a
57      * 100% duty cycle. If scan window is half of the scan interval value, then the module Bluetooth
58      * will be scanning at a 50% duty cycle.
59      * <p>
60      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
61      */
62     private int scanWindow;
63
64     /**
65      * 1: Active scanning is used. When an advertisement packet is received the Bluetooth stack
66      * will send a scan request packet to the advertiser to try and read the scan response data. 0:
67      * Passive scanning is used. No scan request is made.
68      * <p>
69      * BlueGiga API type is <i>boolean</i> - Java type is {@link boolean}
70      */
71     private boolean activeScanning;
72
73     @Override
74     public int[] serialize() {
75         // Serialize the header
76         serializeHeader(COMMAND_CLASS, COMMAND_METHOD);
77
78         // Serialize the fields
79         serializeUInt16(scanInterval);
80         serializeUInt16(scanWindow);
81         serializeBoolean(activeScanning);
82
83         return getPayload();
84     }
85
86     @Override
87     public String toString() {
88         final StringBuilder builder = new StringBuilder();
89         builder.append("BlueGigaSetScanParametersCommand [scanInterval=");
90         builder.append(scanInterval);
91         builder.append(", scanWindow=");
92         builder.append(scanWindow);
93         builder.append(", activeScanning=");
94         builder.append(activeScanning);
95         builder.append(']');
96         return builder.toString();
97     }
98
99     public static class CommandBuilder {
100         private int scanInterval;
101         private int scanWindow;
102         private boolean activeScanning;
103
104         /**
105          * Scan interval defines the interval when scanning is re-started in units of 625us. Range: 0x4
106          * - 0x4000. Default: (46,875ms) 0x4B After every scan interval the scanner will change the
107          * frequency it operates at at it will cycle through all the three advertisements channels in a
108          * round robin fashion. According to the specification all three channels must be Bluetooth
109          * used by a scanner.
110          *
111          * @param scanInterval the scanInterval to set as {@link int}
112          */
113         public CommandBuilder withScanInterval(int scanInterval) {
114             this.scanInterval = scanInterval;
115             return this;
116         }
117
118         /**
119          * Scan Window defines how long time the scanner will listen on a certain frequency and try to
120          * pick up advertisement packets. Scan window is defined as units of 625us. Range: 0x4 - 0x4000.
121          * Default: 0x32 (31,25 ms). Scan windows must be equal or smaller than scan interval If scan
122          * window is equal to the scan interval value, then the module Bluetooth will be scanning at a
123          * 100% duty cycle. If scan window is half of the scan interval value, then the module Bluetooth
124          * will be scanning at a 50% duty cycle.
125          *
126          * @param scanWindow the scanWindow to set as {@link int}
127          */
128         public CommandBuilder withScanWindow(int scanWindow) {
129             this.scanWindow = scanWindow;
130             return this;
131         }
132
133         /**
134          * 1: Active scanning is used. When an advertisement packet is received the Bluetooth stack
135          * will send a scan request packet to the advertiser to try and read the scan response data. 0:
136          * Passive scanning is used. No scan request is made.
137          *
138          * @param activeScanning the activeScanning to set as {@link boolean}
139          */
140         public CommandBuilder withActiveScanning(boolean activeScanning) {
141             this.activeScanning = activeScanning;
142             return this;
143         }
144
145         public BlueGigaSetScanParametersCommand build() {
146             return new BlueGigaSetScanParametersCommand(this);
147         }
148     }
149 }