2 * Copyright (c) 2010-2023 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;
19 * Class to implement the BlueGiga command <b>setScanParameters</b>.
21 * This command sets the scan parameters which affect how other Smart devices are discovered.
23 * This class provides methods for processing BlueGiga API commands.
25 * Note that this code is autogenerated. Manual changes may be overwritten.
27 * @author Chris Jackson - Initial contribution of Java code generator
28 * @author Pauli Anttila - Added message builder
31 public class BlueGigaSetScanParametersCommand extends BlueGigaCommand {
32 public static final int COMMAND_CLASS = 0x06;
33 public static final int COMMAND_METHOD = 0x07;
35 private BlueGigaSetScanParametersCommand(CommandBuilder builder) {
36 this.scanInterval = builder.scanInterval;
37 this.scanWindow = builder.scanWindow;
38 this.activeScanning = builder.activeScanning;
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
48 * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
50 private int scanInterval;
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.
60 * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
62 private int scanWindow;
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.
69 * BlueGiga API type is <i>boolean</i> - Java type is {@link boolean}
71 private boolean activeScanning;
74 public int[] serialize() {
75 // Serialize the header
76 serializeHeader(COMMAND_CLASS, COMMAND_METHOD);
78 // Serialize the fields
79 serializeUInt16(scanInterval);
80 serializeUInt16(scanWindow);
81 serializeBoolean(activeScanning);
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);
96 return builder.toString();
99 public static class CommandBuilder {
100 private int scanInterval;
101 private int scanWindow;
102 private boolean activeScanning;
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
111 * @param scanInterval the scanInterval to set as {@link int}
113 public CommandBuilder withScanInterval(int scanInterval) {
114 this.scanInterval = scanInterval;
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.
126 * @param scanWindow the scanWindow to set as {@link int}
128 public CommandBuilder withScanWindow(int scanWindow) {
129 this.scanWindow = scanWindow;
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.
138 * @param activeScanning the activeScanning to set as {@link boolean}
140 public CommandBuilder withActiveScanning(boolean activeScanning) {
141 this.activeScanning = activeScanning;
145 public BlueGigaSetScanParametersCommand build() {
146 return new BlueGigaSetScanParametersCommand(this);