]> git.basschouten.com Git - openhab-addons.git/blob
0d39203a9e73251eaf351e689b3eab6122213cb5
[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.BlueGigaResponse;
17 import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.BluetoothAddressType;
18 import org.openhab.binding.bluetooth.bluegiga.internal.enumeration.ScanResponseType;
19
20 /**
21  * Class to implement the BlueGiga command <b>scanResponseEvent</b>.
22  * <p>
23  * This is a scan response event. This event is normally received by a Master which is scanning
24  * for advertisement and scan response packets from Slaves.
25  * <p>
26  * This class provides methods for processing BlueGiga API commands.
27  * <p>
28  * Note that this code is autogenerated. Manual changes may be overwritten.
29  *
30  * @author Chris Jackson - Initial contribution of Java code generator
31  */
32 @NonNullByDefault
33 public class BlueGigaScanResponseEvent extends BlueGigaResponse {
34     public static int COMMAND_CLASS = 0x06;
35     public static int COMMAND_METHOD = 0x00;
36
37     /**
38      * RSSI value (dBm). Range: -103 to -38
39      * <p>
40      * BlueGiga API type is <i>int8</i> - Java type is {@link int}
41      */
42     private int rssi;
43
44     /**
45      * Scan response header. 0: Connectable Advertisement packet. 2: Non Connectable
46      * Advertisement packet. 4: Scan response packet. 6: Discoverable advertisement packet
47      * <p>
48      * BlueGiga API type is <i>ScanResponseType</i> - Java type is {@link ScanResponseType}
49      */
50     private ScanResponseType packetType;
51
52     /**
53      * Advertisers address
54      * <p>
55      * BlueGiga API type is <i>bd_addr</i> - Java type is {@link String}
56      */
57     private String sender;
58
59     /**
60      * Advertiser address type. 1: random address. 0: public address
61      * <p>
62      * BlueGiga API type is <i>BluetoothAddressType</i> - Java type is {@link BluetoothAddressType}
63      */
64     private BluetoothAddressType addressType;
65
66     /**
67      * Bond handle if there is known bond for this device, 0xff otherwise
68      * <p>
69      * BlueGiga API type is <i>uint8</i> - Java type is {@link int}
70      */
71     private int bond;
72
73     /**
74      * Scan response data
75      * <p>
76      * BlueGiga API type is <i>uint8array</i> - Java type is {@link int[]}
77      */
78     private int[] data;
79
80     /**
81      * Event constructor
82      */
83     public BlueGigaScanResponseEvent(int[] inputBuffer) {
84         // Super creates deserializer and reads header fields
85         super(inputBuffer);
86
87         event = (inputBuffer[0] & 0x80) != 0;
88
89         // Deserialize the fields
90         rssi = deserializeInt8();
91         packetType = deserializeScanResponseType();
92         sender = deserializeAddress();
93         addressType = deserializeBluetoothAddressType();
94         bond = deserializeUInt8();
95         data = deserializeUInt8Array();
96     }
97
98     /**
99      * RSSI value (dBm). Range: -103 to -38
100      * <p>
101      * BlueGiga API type is <i>int8</i> - Java type is {@link int}
102      *
103      * @return the current rssi as {@link int}
104      */
105     public int getRssi() {
106         return rssi;
107     }
108
109     /**
110      * Scan response header. 0: Connectable Advertisement packet. 2: Non Connectable
111      * Advertisement packet. 4: Scan response packet. 6: Discoverable advertisement packet
112      * <p>
113      * BlueGiga API type is <i>ScanResponseType</i> - Java type is {@link ScanResponseType}
114      *
115      * @return the current packet_type as {@link ScanResponseType}
116      */
117     public ScanResponseType getPacketType() {
118         return packetType;
119     }
120
121     /**
122      * Advertisers address
123      * <p>
124      * BlueGiga API type is <i>bd_addr</i> - Java type is {@link String}
125      *
126      * @return the current sender as {@link String}
127      */
128     public String getSender() {
129         return sender;
130     }
131
132     /**
133      * Advertiser address type. 1: random address. 0: public address
134      * <p>
135      * BlueGiga API type is <i>BluetoothAddressType</i> - Java type is {@link BluetoothAddressType}
136      *
137      * @return the current address_type as {@link BluetoothAddressType}
138      */
139     public BluetoothAddressType getAddressType() {
140         return addressType;
141     }
142
143     /**
144      * Bond handle if there is known bond for this device, 0xff otherwise
145      * <p>
146      * BlueGiga API type is <i>uint8</i> - Java type is {@link int}
147      *
148      * @return the current bond as {@link int}
149      */
150     public int getBond() {
151         return bond;
152     }
153
154     /**
155      * Scan response data
156      * <p>
157      * BlueGiga API type is <i>uint8array</i> - Java type is {@link int[]}
158      *
159      * @return the current data as {@link int[]}
160      */
161     public int[] getData() {
162         return data;
163     }
164
165     @Override
166     public String toString() {
167         final StringBuilder builder = new StringBuilder();
168         builder.append("BlueGigaScanResponseEvent [rssi=");
169         builder.append(rssi);
170         builder.append(", packetType=");
171         builder.append(packetType);
172         builder.append(", sender=");
173         builder.append(sender);
174         builder.append(", addressType=");
175         builder.append(addressType);
176         builder.append(", bond=");
177         builder.append(bond);
178         builder.append(", data=");
179         for (int c = 0; c < data.length; c++) {
180             if (c > 0) {
181                 builder.append(' ');
182             }
183             builder.append(String.format("%02X", data[c]));
184         }
185         builder.append(']');
186         return builder.toString();
187     }
188 }