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 import com.irurueta.algebra.Matrix;
19 import com.irurueta.geometry.Point;
20
21 /**
22 * Contains a located signal strength reading associated to a given radio source
23 * (e.g. Wi-Fi access point or bluetooth beacon).
24 *
25 * @param <S> a {@link RadioSource} type.
26 * @param <P> a {@link Point} type.
27 */
28 public class RssiReadingLocated<S extends RadioSource, P extends Point<?>> extends RssiReading<S> implements
29 ReadingLocated<P> {
30
31 /**
32 * Position where radio source reading was made.
33 */
34 private P position;
35
36 /**
37 * Covariance of inhomogeneous coordinates of current position
38 * (if available).
39 */
40 private Matrix positionCovariance;
41
42 /**
43 * Constructor.
44 *
45 * @param source radio source associated to this reading.
46 * @param rssi received signal strength indicator in dBm.
47 * @param position position where reading was made.
48 * @throws IllegalArgumentException if either radio source data or position
49 * are null.
50 */
51 public RssiReadingLocated(final S source, final double rssi, final P position) {
52 super(source, rssi);
53
54 if (position == null) {
55 throw new IllegalArgumentException();
56 }
57
58 this.position = position;
59 }
60
61 /**
62 * Constructor.
63 *
64 * @param source radio source associated to this reading.
65 * @param rssi received signal strength indicator in dBm.
66 * @param position position where reading was made.
67 * @param rssiStandardDeviation standard deviation of RSSI, if available.
68 * @throws IllegalArgumentException if either radio source data or position
69 * are null.
70 */
71 public RssiReadingLocated(final S source, final double rssi, final P position, final Double rssiStandardDeviation) {
72 super(source, rssi, rssiStandardDeviation);
73
74 if (position == null) {
75 throw new IllegalArgumentException();
76 }
77
78 this.position = position;
79 }
80
81 /**
82 * Constructor.
83 *
84 * @param source radio source associated to this reading.
85 * @param rssi received signal strength indicator in dBm.
86 * @param position position where reading was made.
87 * @param positionCovariance covariance of inhomogeneous coordinates of
88 * current position (if available).
89 * @throws IllegalArgumentException if either radio source or position are
90 * null, or covariance has invalid size.
91 */
92 public RssiReadingLocated(final S source, final double rssi, final P position, final Matrix positionCovariance) {
93 this(source, rssi, position);
94
95 if (positionCovariance != null) {
96 final var dims = position.getDimensions();
97 if (positionCovariance.getRows() != dims || positionCovariance.getColumns() != dims) {
98 throw new IllegalArgumentException();
99 }
100 }
101 this.positionCovariance = positionCovariance;
102 }
103
104 /**
105 * Constructor.
106 *
107 * @param source radio source associated to this reading.
108 * @param rssi received signal strength indicator in dBm.
109 * @param position position where reading was made.
110 * @param rssiStandardDeviation standard deviation of RSSI, if available.
111 * @param positionCovariance covariance of inhomogeneous coordinates of
112 * current position (if available).
113 * @throws IllegalArgumentException if either radio source or position are
114 * null, or covariance has invalid size.
115 */
116 public RssiReadingLocated(
117 final S source, final double rssi, final P position, final Double rssiStandardDeviation,
118 final Matrix positionCovariance) {
119 this(source, rssi, position, rssiStandardDeviation);
120
121 if (positionCovariance != null) {
122 var dims = position.getDimensions();
123 if (positionCovariance.getRows() != dims || positionCovariance.getColumns() != dims) {
124 throw new IllegalArgumentException();
125 }
126 }
127 this.positionCovariance = positionCovariance;
128 }
129
130 /**
131 * Empty constructor.
132 */
133 protected RssiReadingLocated() {
134 super();
135 }
136
137 /**
138 * Gets position where reading was made.
139 *
140 * @return position where reading was made.
141 */
142 @Override
143 public P getPosition() {
144 return position;
145 }
146
147 /**
148 * Gets covariance of inhomogeneous coordinates of current position (if available).
149 *
150 * @return covariance of position or null.
151 */
152 @Override
153 public Matrix getPositionCovariance() {
154 return positionCovariance;
155 }
156 }