1 /*
2 * Copyright (C) 2018 Alberto Irurueta Carro (alberto@irurueta.com)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package com.irurueta.navigation.indoor;
17
18 /**
19 * Contains a reading associated to a given radio source (e.e. Wi-Fi access point or
20 * bluetooth beacon) containing signal strength and distance to associated access
21 * point.
22 *
23 * @param <S> a {@link RadioSource} type.
24 */
25 public class RangingAndRssiReading<S extends RadioSource> extends Reading<S> {
26
27 /**
28 * Default number of measurements.
29 */
30 public static final int DEFAULT_NUM_MEASUREMENTS = 1;
31
32 /**
33 * Distance in meters to the radio source.
34 */
35 private double distance;
36
37 /**
38 * Standard deviation of distance, if available.
39 */
40 private Double distanceStandardDeviation;
41
42 /**
43 * Number of attempted measurements using in the RTT exchange.
44 */
45 private int numAttemptedMeasurements = DEFAULT_NUM_MEASUREMENTS;
46
47 /**
48 * Number of successful measurements used to calculate the distance and standard
49 * deviation.
50 */
51 private int numSuccessfulMeasurements = DEFAULT_NUM_MEASUREMENTS;
52
53 /**
54 * Received signal strength indicator (of this 802.11 network for a Wi-Fi access point or
55 * of this bluetooth beacon), in dBm.
56 */
57 private double rssi;
58
59 /**
60 * Standard deviation of RSSI, if available.
61 */
62 private Double rssiStandardDeviation;
63
64 /**
65 * Constructor.
66 *
67 * @param source radio source associated to this reading.
68 * @param distance distance in meters to the radio source.
69 * @param rssi received signal strength indicator in dBm.
70 * @throws IllegalArgumentException if radio source data is null or distance is negative.
71 */
72 public RangingAndRssiReading(final S source, final double distance, final double rssi) {
73 super(source);
74
75 if (distance < 0.0) {
76 throw new IllegalArgumentException();
77 }
78
79 this.distance = distance;
80 this.rssi = rssi;
81 }
82
83 /**
84 * Constructor.
85 *
86 * @param source radio source associated to this reading.
87 * @param distance distance in meters to the radio source.
88 * @param rssi received signal strength indicator in dBm.
89 * @param numAttemptedMeasurements number of attempted measurements used in the RTT exchange.
90 * @param numSuccessfulMeasurements number of successful measurements used to calculate the
91 * distance and standard deviation.
92 * @throws IllegalArgumentException if radio source data is null, distance is negative,
93 * number of attempted measures is less than 1 or number of successful measures is
94 * negative.
95 */
96 public RangingAndRssiReading(
97 final S source, final double distance, final double rssi, final int numAttemptedMeasurements,
98 final int numSuccessfulMeasurements) {
99 this(source, distance, rssi, null, null, numAttemptedMeasurements,
100 numSuccessfulMeasurements);
101 }
102
103 /**
104 * Constructor.
105 *
106 * @param source radio source associated to this reading.
107 * @param distance distance in meters to the radio source.
108 * @param rssi received signal strength indicator in dBm.
109 * @param distanceStandardDeviation standard deviation of distance, if available.
110 * @param rssiStandardDeviation standard deviation of RSSI, if available.
111 * @throws IllegalArgumentException if radio source data is null, distance is negative
112 * or any of the standard deviations is zero or negative.
113 */
114 public RangingAndRssiReading(
115 final S source, final double distance, final double rssi, final Double distanceStandardDeviation,
116 final Double rssiStandardDeviation) {
117 this(source, distance, rssi);
118
119 if (distanceStandardDeviation != null && distanceStandardDeviation <= 0.0) {
120 throw new IllegalArgumentException();
121 }
122 if (rssiStandardDeviation != null && rssiStandardDeviation <= 0.0) {
123 throw new IllegalArgumentException();
124 }
125
126 this.distanceStandardDeviation = distanceStandardDeviation;
127 this.rssiStandardDeviation = rssiStandardDeviation;
128 }
129
130 /**
131 * Constructor.
132 *
133 * @param source radio source associated to this reading.
134 * @param distance distance in meters to the radio source.
135 * @param rssi received signal strength indicator in dBm.
136 * @param distanceStandardDeviation standard deviation of distance, if available.
137 * @param rssiStandardDeviation standard deviation of RSSI, if available.
138 * @param numAttemptedMeasurements number of attempted measurements used in the RTT exchange.
139 * @param numSuccessfulMeasurements number of successful measurements used to calculate the
140 * distance and standard deviation.
141 * @throws IllegalArgumentException if radio source data is null, distance is negative,
142 * any of the standard deviations is zero or negative, number of attempted
143 * measures is less than 1 or number of successful measures is negative.
144 */
145 public RangingAndRssiReading(
146 final S source, final double distance, final double rssi, final Double distanceStandardDeviation,
147 final Double rssiStandardDeviation, final int numAttemptedMeasurements,
148 final int numSuccessfulMeasurements) {
149 this(source, distance, rssi, distanceStandardDeviation, rssiStandardDeviation);
150
151 if (numAttemptedMeasurements < DEFAULT_NUM_MEASUREMENTS || numSuccessfulMeasurements < 0) {
152 throw new IllegalArgumentException();
153 }
154
155 this.numAttemptedMeasurements = numAttemptedMeasurements;
156 this.numSuccessfulMeasurements = numSuccessfulMeasurements;
157 }
158
159 /**
160 * Empty constructor.
161 */
162 protected RangingAndRssiReading() {
163 super();
164 }
165
166 /**
167 * Contains radio source reading type.
168 *
169 * @return reading type.
170 */
171 @Override
172 public ReadingType getType() {
173 return ReadingType.RANGING_AND_RSSI_READING;
174 }
175
176 /**
177 * Gets distance in meters to the radio source.
178 *
179 * @return distance in meters to the radio source.
180 */
181 public double getDistance() {
182 return distance;
183 }
184
185 /**
186 * Gets standard deviation of distance, if available.
187 *
188 * @return standard deviation of distance or null.
189 */
190 public Double getDistanceStandardDeviation() {
191 return distanceStandardDeviation;
192 }
193
194 /**
195 * Gets number of attempted measurements used in the RTT exchange.
196 *
197 * @return number of attempted measurements used in the RTT exchange.
198 */
199 public int getNumAttemptedMeasurements() {
200 return numAttemptedMeasurements;
201 }
202
203 /**
204 * Gets number of successful measurements used to calculate the distance and
205 * standard deviation.
206 *
207 * @return number of successful measurements used to calculate the distance and
208 * standard deviation.
209 */
210 public int getNumSuccessfulMeasurements() {
211 return numSuccessfulMeasurements;
212 }
213
214 /**
215 * Gets received signal strength indicator of (of this 802.11 network for a Wi-Fi access point or
216 * of this bluetooth beacon), in dBm.
217 *
218 * @return received signal strength indicator.
219 */
220 public double getRssi() {
221 return rssi;
222 }
223
224 /**
225 * Gets standard deviation of RSSI, if available.
226 *
227 * @return standard deviation of RSSI, if available.
228 */
229 public Double getRssiStandardDeviation() {
230 return rssiStandardDeviation;
231 }
232 }