1
1
package aero .t2s .modes .decoder .df .df17 ;
2
2
3
3
import aero .t2s .modes .CprPosition ;
4
+ import org .slf4j .LoggerFactory ;
5
+
4
6
import java .util .*;
5
7
6
8
public class PositionUpdate {
7
- private static double originLat ; // Origin is passed-in as a command-line argument as an indication of where the receiver is located
9
+ private static double originLat ; // Origin is passed-in as a command-line argument as an indication of where the receiver is located
8
10
private static double originLon ;
9
11
10
- private static double receiverLat ; // Receiver position is calculated based on data received
12
+ private static final double updateThreshold = 0.5d ; // Positions which move between updates by more than this (in degrees) should be rejected
13
+ private static final double receiverRange = 4.0d ; // Positions further away from the receiver than this (in degrees) should be rejected
14
+ private static double receiverLat ; // Receiver position is calculated based on data received
11
15
private static double receiverLon ;
12
- private static double receiverSumLat ; // Running-total of valid positions that can be used to calculate the average receiver position
16
+ private static double receiverSumLat ; // Running-total of valid positions that can be used to calculate the average receiver position
13
17
private static double receiverSumLon ;
14
- private static double receiverSumCount = 0 ; // number of valid positions received that are used to calculate the average
18
+ private static double receiverSumCount = 0 ; // number of valid positions received that are used to calculate the average
15
19
16
20
private static Map <String , PositionUpdate > cache = new HashMap <>();
17
21
private static Timer cacheCleanup ;
@@ -70,7 +74,14 @@ private CprPosition calculate(boolean isCprEven, CprPosition newCpr) {
70
74
}
71
75
72
76
if (current != null && current .isValid ()) {
73
- previous = current ;
77
+ // Sanity Check: Is the position just received too far away from the receiver position?
78
+ if ((Math .abs (current .getLat () - receiverLat ) > receiverRange ) || (Math .abs (current .getLon () - receiverLon ) > receiverRange )) {
79
+ LoggerFactory .getLogger (getClass ()).info ("Position Update discarded due to outside receiver range." );
80
+ current = null ;
81
+ }
82
+ else {
83
+ previous = current ;
84
+ }
74
85
}
75
86
76
87
return current ;
@@ -95,29 +106,20 @@ private void calculateLocal(boolean isOdd) {
95
106
double newLon = dLon * (m + cpr .getLon ());
96
107
97
108
cpr .setZones (j , m );
98
- if ((j != otherCpr .getLatZone ()) || (m != otherCpr .getLonZone ())) {
99
- // The new frame is in a different CPR zone
100
- if (isOdd ) {
101
- //even = null; // Keep the current odd frame but discard the previous even frame
102
- } else {
103
- //odd = null;
104
- }
105
- //previous = null;
106
- //current = null;
107
- //return;
108
- }
109
109
110
110
current = new CprPosition (newLat , newLon , cpr .getSurface ());
111
111
if (current .getSurface ()) {
112
112
validateSurface (current );
113
113
}
114
114
115
- // TODO Should be a sanity-check here to make sure the calculated position isn't outside receiver origin range
116
- // TODO Should be a sanity-check here to see if the calculated movement since the last update is too far
115
+ if ((Math .abs (current .getLat () - previous .getLat ()) > updateThreshold ) || (Math .abs (current .getLon () - previous .getLon ()) > updateThreshold )) {
116
+ LoggerFactory .getLogger (getClass ()).info ("Position Update discarded due to unreasonable distance between updates." );
117
+ current = null ;
118
+ }
117
119
}
118
120
119
121
private void calculateGlobal () {
120
- double j = Math .floor (59.0 * even .getLat () - 60.0 * odd .getLat () + 0.5 );
122
+ double j = Math .floor (dLatOdd * even .getLat () - dLatEven * odd .getLat () + 0.5 );
121
123
double degrees = even .getSurface () ? 90.0 : 360.0 ; // Doesn't matter whether we check odd or even as they must both match by now
122
124
123
125
double latEven = (degrees / dLatEven ) * (cprMod (j , dLatEven ) + even .getLat ());
@@ -161,7 +163,6 @@ private void calculateGlobal() {
161
163
if (current .getSurface ()) {
162
164
validateSurface (current );
163
165
}
164
- //TODO Should be a sanity-check here to make sure the calculated position isn't outside receiver origin range
165
166
}
166
167
167
168
static private double cprMod (double a , double b ) {
0 commit comments