zhuguifei
2025-12-30 61eee1173c00a7ba9d9c748d28fe3acdb33b9441
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package com.blakequ.bluetooth_manager_lib.device.ibeacon;
 
import android.annotation.SuppressLint;
import android.bluetooth.BluetoothDevice;
import android.os.Parcel;
 
import com.blakequ.bluetooth_manager_lib.device.BeaconDevice;
import com.blakequ.bluetooth_manager_lib.device.BeaconType;
import com.blakequ.bluetooth_manager_lib.device.BluetoothLeDevice;
 
 
@SuppressLint("ParcelCreator")
public class IBeaconDevice extends BluetoothLeDevice implements BeaconDevice {
 
    /**
     * The m iBeacon data.
     */
    private final IBeaconManufacturerData mIBeaconData;
 
    /**
     * Instantiates a new iBeacon device.
     *
     * @param device     the device
     * @param rssi       the RSSI value
     * @param scanRecord the scanRecord
     * @throws IllegalArgumentException if the passed device is not an iBeacon
     */
    public IBeaconDevice(final BluetoothDevice device, final int rssi, final byte[] scanRecord) {
        super(device, rssi, scanRecord, 0);
        mIBeaconData = new IBeaconManufacturerData(this);
    }
 
    /**
     * Instantiates a new iBeacon device.
     *
     * @param device     the device
     * @param rssi       the RSSI value of the RSSI measurement
     * @param scanRecord the scan record
     * @param timestamp  the timestamp of the RSSI measurement
     * @throws IllegalArgumentException if the passed device is not an iBeacon
     */
    public IBeaconDevice(final BluetoothDevice device, final int rssi, final byte[] scanRecord, final long timestamp) {
        super(device, rssi, scanRecord, timestamp);
        mIBeaconData = new IBeaconManufacturerData(this);
    }
 
    /**
     * Will try to convert a {@link BluetoothLeDevice} into an
     * iBeacon Device.
     *
     * @param device the device
     * @throws IllegalArgumentException if the passed device is not an iBeacon
     */
    public IBeaconDevice(final BluetoothLeDevice device) {
        super(device);
        mIBeaconData = new IBeaconManufacturerData(this);
    }
 
    private IBeaconDevice(final Parcel in) {
        super(in);
        mIBeaconData = new IBeaconManufacturerData(this);
    }
 
    /**
     * Gets the estimated Accuracy of the reading in meters based on
     * a simple running average of the last {@link #MAX_RSSI_LOG_SIZE}
     * samples.
     *
     * @return the accuracy in meters
     */
    public double getAccuracy() {
        return IBeaconUtils.calculateAccuracy(
                getCalibratedTxPower(),
                getRunningAverageRssi());
    }
 
    @Override
    public BeaconType getBeaconType() {
        return BeaconType.IBEACON;
    }
 
    /**
     * Gets the calibrated TX power of the iBeacon device as reported.
     *
     * @return the calibrated TX power
     */
    public int getCalibratedTxPower() {
        return getIBeaconData().getCalibratedTxPower();
    }
 
    /**
     * Gets the iBeacon company identifier.
     *
     * @return the company identifier
     */
    public int getCompanyIdentifier() {
        return getIBeaconData().getCompanyIdentifier();
    }
 
    /**
     * Gets the estimated Distance descriptor.
     *
     * @return the distance descriptor
     */
    public IBeaconDistanceDescriptor getDistanceDescriptor() {
        return IBeaconUtils.getDistanceDescriptor(getAccuracy());
    }
 
    /**
     * Gets the iBeacon manufacturing data.
     *
     * @return the iBeacon data
     */
    public IBeaconManufacturerData getIBeaconData() {
        return mIBeaconData;
    }
 
    /**
     * Gets the iBeacon Major value.
     *
     * @return the Major value
     */
    public int getMajor() {
        return getIBeaconData().getMajor();
    }
 
    /**
     * Gets the iBeacon Minor value.
     *
     * @return the Minor value
     */
    public int getMinor() {
        return getIBeaconData().getMinor();
    }
 
    /**
     * Gets the iBeacon UUID.
     *
     * @return the UUID
     */
    public String getUUID() {
        return getIBeaconData().getUUID();
    }
}