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