]> git.basschouten.com Git - openhab-addons.git/blob
04ae0f2b20db227b5ab36fde12050d332086b15d
[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.notification;
14
15 import java.util.Map;
16
17 /**
18  * The {@link BluetoothScanNotification} provides a notification of a received scan packet
19  *
20  * @author Chris Jackson - Initial contribution
21  * @author Peter Rosenberg - Add support for ServiceData
22  */
23 public class BluetoothScanNotification extends BluetoothNotification {
24     /**
25      * The receive signal strength for this beacon packet
26      */
27     private int rssi = Integer.MIN_VALUE;
28
29     /**
30      * The raw data
31      */
32     private byte[] data = null;
33
34     /**
35      * The manufacturer specific data
36      */
37     private byte[] manufacturerData = null;
38
39     /**
40      * The service data.
41      * Key: UUID of the service
42      * Value: Data of the characteristic
43      */
44     private Map<String, byte[]> serviceData = null;
45
46     /**
47      * The beacon type
48      */
49     private BluetoothBeaconType beaconType = BluetoothBeaconType.BEACON_UNKNOWN;
50
51     /**
52      * The device name
53      */
54     private String name = new String();
55
56     /**
57      * An enumeration of basic beacon types
58      */
59     public enum BluetoothBeaconType {
60         BEACON_UNKNOWN,
61         BEACON_ADVERTISEMENT,
62         BEACON_SCANRESPONSE
63     }
64
65     /**
66      * Sets the receive signal strength RSSI value for the scan
67      *
68      * param rssi the RSSI value for the scan packet in dBm
69      */
70     public void setRssi(int rssi) {
71         this.rssi = rssi;
72     }
73
74     /**
75      * Gets the receive signal strength RSSI value for the scan
76      *
77      * @return the RSSI value for the scan packet in dBm or Integer.MIN_VALUE if no RSSI is available.
78      */
79     public int getRssi() {
80         return rssi;
81     }
82
83     /**
84      * Sets the scan packet data
85      *
86      * @param data a byte array containing the raw packet data;
87      */
88     public void setData(byte[] data) {
89         this.data = data;
90     }
91
92     /**
93      * Gets the scan packet data
94      *
95      * @return a byte array containing the data or null if none is set
96      */
97     public byte[] getData() {
98         return data;
99     }
100
101     /**
102      * Sets the scan packet manufacturer specific data
103      *
104      * @param manufacturerData a byte array containing the manufacturer specific data
105      */
106     public void setManufacturerData(byte[] manufacturerData) {
107         this.manufacturerData = manufacturerData;
108     }
109
110     /**
111      * Gets the scan packet manufacturer specific data
112      *
113      * @return a byte array containing the manufacturer specific data or null if none is set
114      */
115     public byte[] getManufacturerData() {
116         return manufacturerData;
117     }
118
119     public void setServiceData(Map<String, byte[]> serviceData) {
120         this.serviceData = serviceData;
121     }
122
123     public Map<String, byte[]> getServiceData() {
124         return serviceData;
125     }
126
127     /**
128      * Sets the beacon type for this packet
129      *
130      * @beaconType the {@link BluetoothBeaconType} for this packet
131      */
132     public void setBeaconType(BluetoothBeaconType beaconType) {
133         this.beaconType = beaconType;
134     }
135
136     /**
137      * Gets the beacon type for this packet
138      *
139      * @return the {@link BluetoothBeaconType} for this packet
140      */
141     public BluetoothBeaconType getBeaconType() {
142         return beaconType;
143     }
144
145     /**
146      * Sets the device name
147      *
148      * @param name {@link String} containing the device name
149      */
150     public void setDeviceName(String name) {
151         this.name = name;
152     }
153
154     /**
155      * Gets the device name
156      *
157      * @return {@link String} containing the device name
158      */
159     public String getDeviceName() {
160         return name;
161     }
162 }