]> git.basschouten.com Git - openhab-addons.git/blob
c4dbeab43e6f614435c87bbce52834da6cc82803
[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 java.util.HashSet;
16 import java.util.Set;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.binding.bluetooth.bluegiga.internal.BlueGigaDeviceResponse;
20 import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BluetoothAddressType;
21 import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.ConnectionStatusFlag;
22
23 /**
24  * Class to implement the BlueGiga command <b>connectionStatusEvent</b>.
25  * <p>
26  * This event indicates the connection status and parameters.
27  * <p>
28  * This class provides methods for processing BlueGiga API commands.
29  * <p>
30  * Note that this code is autogenerated. Manual changes may be overwritten.
31  *
32  * @author Chris Jackson - Initial contribution of Java code generator
33  */
34 @NonNullByDefault
35 public class BlueGigaConnectionStatusEvent extends BlueGigaDeviceResponse {
36     public static final int COMMAND_CLASS = 0x03;
37     public static final int COMMAND_METHOD = 0x00;
38
39     /**
40      * Connection status flags use connstatus-enumerator
41      * <p>
42      * BlueGiga API type is <i>ConnectionStatusFlag</i> - Java type is {@link ConnectionStatusFlag}
43      * Parameter allows multiple options so implemented as a {@link Set}.
44      */
45     private Set<ConnectionStatusFlag> flags = new HashSet<>();
46
47     /**
48      * Remote devices Bluetooth address
49      * <p>
50      * BlueGiga API type is <i>bd_addr</i> - Java type is {@link String}
51      */
52     private String address;
53
54     /**
55      * Remote address type see: Bluetooth Address Types--gap
56      * <p>
57      * BlueGiga API type is <i>BluetoothAddressType</i> - Java type is {@link BluetoothAddressType}
58      */
59     private BluetoothAddressType addressType;
60
61     /**
62      * Current connection interval (units of 1.25ms)
63      * <p>
64      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
65      */
66     private int connInterval;
67
68     /**
69      * Current supervision timeout (units of 10ms)
70      * <p>
71      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
72      */
73     private int timeout;
74
75     /**
76      * Slave latency which tells how many connection intervals the slave may skip.
77      * <p>
78      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
79      */
80     private int latency;
81
82     /**
83      * Bonding handle if the device has been bonded with. Otherwise: 0xFF
84      * <p>
85      * BlueGiga API type is <i>uint8</i> - Java type is {@link int}
86      */
87     private int bonding;
88
89     /**
90      * Event constructor
91      */
92     public BlueGigaConnectionStatusEvent(int[] inputBuffer) {
93         // Super creates deserializer and reads header fields
94         super(inputBuffer);
95
96         event = (inputBuffer[0] & 0x80) != 0;
97
98         // Deserialize the fields
99         connection = deserializeUInt8();
100         flags = deserializeConnectionStatusFlag();
101         address = deserializeAddress();
102         addressType = deserializeBluetoothAddressType();
103         connInterval = deserializeUInt16();
104         timeout = deserializeUInt16();
105         latency = deserializeUInt16();
106         bonding = deserializeUInt8();
107     }
108
109     /**
110      * Connection status flags use connstatus-enumerator
111      * <p>
112      * BlueGiga API type is <i>ConnectionStatusFlag</i> - Java type is {@link ConnectionStatusFlag}
113      *
114      * @return the current flags as {@link Set} of {@link ConnectionStatusFlag}
115      */
116     public Set<ConnectionStatusFlag> getFlags() {
117         return flags;
118     }
119
120     /**
121      * Remote devices Bluetooth address
122      * <p>
123      * BlueGiga API type is <i>bd_addr</i> - Java type is {@link String}
124      *
125      * @return the current address as {@link String}
126      */
127     public String getAddress() {
128         return address;
129     }
130
131     /**
132      * Remote address type see: Bluetooth Address Types--gap
133      * <p>
134      * BlueGiga API type is <i>BluetoothAddressType</i> - Java type is {@link BluetoothAddressType}
135      *
136      * @return the current address_type as {@link BluetoothAddressType}
137      */
138     public BluetoothAddressType getAddressType() {
139         return addressType;
140     }
141
142     /**
143      * Current connection interval (units of 1.25ms)
144      * <p>
145      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
146      *
147      * @return the current conn_interval as {@link int}
148      */
149     public int getConnInterval() {
150         return connInterval;
151     }
152
153     /**
154      * Current supervision timeout (units of 10ms)
155      * <p>
156      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
157      *
158      * @return the current timeout as {@link int}
159      */
160     public int getTimeout() {
161         return timeout;
162     }
163
164     /**
165      * Slave latency which tells how many connection intervals the slave may skip.
166      * <p>
167      * BlueGiga API type is <i>uint16</i> - Java type is {@link int}
168      *
169      * @return the current latency as {@link int}
170      */
171     public int getLatency() {
172         return latency;
173     }
174
175     /**
176      * Bonding handle if the device has been bonded with. Otherwise: 0xFF
177      * <p>
178      * BlueGiga API type is <i>uint8</i> - Java type is {@link int}
179      *
180      * @return the current bonding as {@link int}
181      */
182     public int getBonding() {
183         return bonding;
184     }
185
186     @Override
187     public String toString() {
188         final StringBuilder builder = new StringBuilder();
189         builder.append("BlueGigaConnectionStatusEvent [connection=");
190         builder.append(connection);
191         builder.append(", flags=");
192         builder.append(flags);
193         builder.append(", address=");
194         builder.append(address);
195         builder.append(", addressType=");
196         builder.append(addressType);
197         builder.append(", connInterval=");
198         builder.append(connInterval);
199         builder.append(", timeout=");
200         builder.append(timeout);
201         builder.append(", latency=");
202         builder.append(latency);
203         builder.append(", bonding=");
204         builder.append(bonding);
205         builder.append(']');
206         return builder.toString();
207     }
208 }