]> git.basschouten.com Git - openhab-addons.git/blob
d6369ca874cc0ca420c4e562039acaba43bad80d
[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>connectSelective</b>.
20  * <p>
21  * This command will start the GAP direct connection establishment procedure to a set of
22  * dedicated Bluetooth Smart devices. When this command is issued the the module will enter a
23  * state where it scans connectable Bluetooth advertisement packets from the remote devices
24  * which are registered in the local white list. Upon receiving an advertisement packet from
25  * one of the registered devices, the module will send a connection request to this device, and a
26  * successful connection will produce a connection status event. The connect selective
27  * command can be cancelled with End Procedure command. When in Initiating State there are no
28  * scan response events.
29  * <p>
30  * This class provides methods for processing BlueGiga API commands.
31  * <p>
32  * Note that this code is autogenerated. Manual changes may be overwritten.
33  *
34  * @author Chris Jackson - Initial contribution of Java code generator
35  */
36 @NonNullByDefault
37 public class BlueGigaConnectSelectiveCommand extends BlueGigaCommand {
38     public static final int COMMAND_CLASS = 0x06;
39     public static final int COMMAND_METHOD = 0x05;
40
41     /**
42      * Minimum Connection Interval (in units of 1.25ms). Range: 6 - 3200 The lowest possible
43      * Connection Interval is 7.50ms and the largest is 4000ms.
44      * <p>
45      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
46      */
47     private int connIntervalMin;
48
49     /**
50      * Maximum Connection Interval (in units of 1.25ms). Range: 6 - 3200 Must be equal or bigger than
51      * minimum Connection Interval.
52      * <p>
53      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
54      */
55     private int connIntervalMax;
56
57     /**
58      * Supervision Timeout (in units of 10ms). The Supervision Timeout defines how long the
59      * devices can be out of range before the connection is closed. Range: 10 - 3200 Minimum time for
60      * the Supervision Timeout is 100ms and maximum value is 32000ms. According to the
61      * specification, the Supervision Timeout in milliseconds shall be larger than (1 + latency) *
62      * conn_interval_max * 2, where conn_interval_max is given in milliseconds.
63      * <p>
64      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
65      */
66     private int timeout;
67
68     /**
69      * This parameter configures the slave latency. Slave latency defines how many connection
70      * intervals a slave device can skip. Increasing slave latency will decrease the energy
71      * consumption of the slave in scenarios where slave does not have data to send at every
72      * connection interval. Range: 0 - 500 0 : Slave latency is disabled. Example: Connection
73      * interval is 10ms and slave latency is 9: this means that the slave is allowed to communicate
74      * every 100ms, but it can communicate every 10ms if needed.
75      * <p>
76      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
77      */
78     private int latency;
79
80     /**
81      * Minimum Connection Interval (in units of 1.25ms). Range: 6 - 3200 The lowest possible
82      * Connection Interval is 7.50ms and the largest is 4000ms.
83      *
84      * @param connIntervalMin the connIntervalMin to set as {@link int}
85      */
86     public void setConnIntervalMin(int connIntervalMin) {
87         this.connIntervalMin = connIntervalMin;
88     }
89
90     /**
91      * Maximum Connection Interval (in units of 1.25ms). Range: 6 - 3200 Must be equal or bigger than
92      * minimum Connection Interval.
93      *
94      * @param connIntervalMax the connIntervalMax to set as {@link int}
95      */
96     public void setConnIntervalMax(int connIntervalMax) {
97         this.connIntervalMax = connIntervalMax;
98     }
99
100     /**
101      * Supervision Timeout (in units of 10ms). The Supervision Timeout defines how long the
102      * devices can be out of range before the connection is closed. Range: 10 - 3200 Minimum time for
103      * the Supervision Timeout is 100ms and maximum value is 32000ms. According to the
104      * specification, the Supervision Timeout in milliseconds shall be larger than (1 + latency) *
105      * conn_interval_max * 2, where conn_interval_max is given in milliseconds.
106      *
107      * @param timeout the timeout to set as {@link int}
108      */
109     public void setTimeout(int timeout) {
110         this.timeout = timeout;
111     }
112
113     /**
114      * This parameter configures the slave latency. Slave latency defines how many connection
115      * intervals a slave device can skip. Increasing slave latency will decrease the energy
116      * consumption of the slave in scenarios where slave does not have data to send at every
117      * connection interval. Range: 0 - 500 0 : Slave latency is disabled. Example: Connection
118      * interval is 10ms and slave latency is 9: this means that the slave is allowed to communicate
119      * every 100ms, but it can communicate every 10ms if needed.
120      *
121      * @param latency the latency to set as {@link int}
122      */
123     public void setLatency(int latency) {
124         this.latency = latency;
125     }
126
127     @Override
128     public int[] serialize() {
129         // Serialize the header
130         serializeHeader(COMMAND_CLASS, COMMAND_METHOD);
131
132         // Serialize the fields
133         serializeUInt16(connIntervalMin);
134         serializeUInt16(connIntervalMax);
135         serializeUInt16(timeout);
136         serializeUInt16(latency);
137
138         return getPayload();
139     }
140
141     @Override
142     public String toString() {
143         final StringBuilder builder = new StringBuilder();
144         builder.append("BlueGigaConnectSelectiveCommand [connIntervalMin=");
145         builder.append(connIntervalMin);
146         builder.append(", connIntervalMax=");
147         builder.append(connIntervalMax);
148         builder.append(", timeout=");
149         builder.append(timeout);
150         builder.append(", latency=");
151         builder.append(latency);
152         builder.append(']');
153         return builder.toString();
154     }
155 }