]> git.basschouten.com Git - openhab-addons.git/blob
94e5531436dc1dd39ad52470a7e30949085bcff4
[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.connection;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceCommand;
17
18 /**
19  * Class to implement the BlueGiga command <b>update</b>.
20  * <p>
21  * This command updates the connection parameters of a given connection. The parameters have
22  * the same meaning and follow the same rules as for the GAP class command: Connect Direct. If
23  * this command is issued at a master device, it will send parameter update request to the link
24  * layer. Bluetooth On the other hand if this command is issued at a slave device, it will send
25  * L2CAP connection parameter update request to the master, which may either accept or reject
26  * it. It will take an amount of time corresponding to at least six times the current connection
27  * interval before the new connection parameters will become active.
28  * <p>
29  * This class provides methods for processing BlueGiga API commands.
30  * <p>
31  * Note that this code is autogenerated. Manual changes may be overwritten.
32  *
33  * @author Chris Jackson - Initial contribution of Java code generator
34  */
35 @NonNullByDefault
36 public class BlueGigaUpdateCommand extends BlueGigaDeviceCommand {
37     public static final int COMMAND_CLASS = 0x03;
38     public static final int COMMAND_METHOD = 0x02;
39
40     /**
41      * Minimum connection interval (units of 1.25ms)
42      * <p>
43      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
44      */
45     private int intervalMin;
46
47     /**
48      * Maximum connection interval (units of 1.25ms)
49      * <p>
50      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
51      */
52     private int intervalMax;
53
54     /**
55      * Slave latency which defines how many connections intervals a slave may skip.
56      * <p>
57      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
58      */
59     private int latency;
60
61     /**
62      * Supervision timeout (units of 10ms)
63      * <p>
64      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
65      */
66     private int timeout;
67
68     /**
69      * Minimum connection interval (units of 1.25ms)
70      *
71      * @param intervalMin the intervalMin to set as {@link int}
72      */
73     public void setIntervalMin(int intervalMin) {
74         this.intervalMin = intervalMin;
75     }
76
77     /**
78      * Maximum connection interval (units of 1.25ms)
79      *
80      * @param intervalMax the intervalMax to set as {@link int}
81      */
82     public void setIntervalMax(int intervalMax) {
83         this.intervalMax = intervalMax;
84     }
85
86     /**
87      * Slave latency which defines how many connections intervals a slave may skip.
88      *
89      * @param latency the latency to set as {@link int}
90      */
91     public void setLatency(int latency) {
92         this.latency = latency;
93     }
94
95     /**
96      * Supervision timeout (units of 10ms)
97      *
98      * @param timeout the timeout to set as {@link int}
99      */
100     public void setTimeout(int timeout) {
101         this.timeout = timeout;
102     }
103
104     @Override
105     public int[] serialize() {
106         // Serialize the header
107         serializeHeader(COMMAND_CLASS, COMMAND_METHOD);
108
109         // Serialize the fields
110         serializeUInt8(connection);
111         serializeUInt16(intervalMin);
112         serializeUInt16(intervalMax);
113         serializeUInt16(latency);
114         serializeUInt16(timeout);
115
116         return getPayload();
117     }
118
119     @Override
120     public String toString() {
121         final StringBuilder builder = new StringBuilder();
122         builder.append("BlueGigaUpdateCommand [connection=");
123         builder.append(connection);
124         builder.append(", intervalMin=");
125         builder.append(intervalMin);
126         builder.append(", intervalMax=");
127         builder.append(intervalMax);
128         builder.append(", latency=");
129         builder.append(latency);
130         builder.append(", timeout=");
131         builder.append(timeout);
132         builder.append(']');
133         return builder.toString();
134     }
135 }