@@ -180,8 +180,9 @@ private boolean fromCompressedBinary(byte[] infoData) {
180
180
_position .latitude = getUncompressedCoordinate (latitude .getBytes (), true );
181
181
if (longitude == null ) return false ;
182
182
_position .longitude = getUncompressedCoordinate (longitude .getBytes (), false );
183
- if (comment != null )
183
+ if (comment != null ) {
184
184
_position .comment = TextTools .stripNulls (comment );
185
+ }
185
186
186
187
_position .hasSpeed = false ;
187
188
_position .hasBearing = false ;
@@ -222,6 +223,9 @@ else if (cByte == '{') {
222
223
// TODO, implement
223
224
double rangeMiles = 2 * Math .pow (1.08 , sByte );
224
225
}
226
+
227
+ // sometimes altitude is coming from comment event for compressed packets
228
+ _position .comment = parseAltitude (_position .comment );
225
229
return true ;
226
230
}
227
231
@@ -294,22 +298,8 @@ private boolean fromUncompressedBinary(byte[] infoData) {
294
298
}
295
299
if (strTail == null ) return true ;
296
300
297
- // read altitude (could be anywhere inside the comment)
298
- Pattern altitudePattern = Pattern .compile ("^.*(/A=\\ d{6}).*$" , Pattern .DOTALL );
299
- Matcher altitudeMatcher = altitudePattern .matcher (strTail );
300
- if (altitudeMatcher .matches ()) {
301
- String altitude = altitudeMatcher .group (1 );
302
- if (altitude != null ) {
303
- strTail = strTail .replaceAll (altitude , "" );
304
- altitude = altitude .split ("=" )[1 ];
305
- _position .altitudeMeters = UnitTools .feetToMeters (Long .parseLong (altitude ));
306
- _position .isAltitudeEnabled = true ;
307
- _position .hasAltitude = true ;
308
- }
309
- } else {
310
- _position .isAltitudeEnabled = false ;
311
- _position .hasAltitude = false ;
312
- }
301
+ // try parse altitude
302
+ strTail = parseAltitude (strTail );
313
303
314
304
// read PHG range
315
305
Pattern phgPattern = Pattern .compile ("^.*(PHG\\ d{4}).*$" , Pattern .DOTALL );
@@ -340,6 +330,27 @@ private boolean fromUncompressedBinary(byte[] infoData) {
340
330
return true ;
341
331
}
342
332
333
+ private String parseAltitude (String strData ) {
334
+ String strTail = strData ;
335
+ // read altitude (could be anywhere inside the comment)
336
+ Pattern altitudePattern = Pattern .compile ("^.*(/A=\\ d{6}).*$" , Pattern .DOTALL );
337
+ Matcher altitudeMatcher = altitudePattern .matcher (strTail );
338
+ if (altitudeMatcher .matches ()) {
339
+ String altitude = altitudeMatcher .group (1 );
340
+ if (altitude != null ) {
341
+ strTail = strTail .replaceAll (altitude , "" );
342
+ altitude = altitude .split ("=" )[1 ];
343
+ _position .altitudeMeters = UnitTools .feetToMeters (Long .parseLong (altitude ));
344
+ _position .isAltitudeEnabled = true ;
345
+ _position .hasAltitude = true ;
346
+ }
347
+ } else {
348
+ _position .isAltitudeEnabled = false ;
349
+ _position .hasAltitude = false ;
350
+ }
351
+ return strTail ;
352
+ }
353
+
343
354
private double getUncompressedCoordinate (byte [] data , boolean isLatitude ) {
344
355
double v = (data [0 ] - 33 ) * 91 * 91 * 91 +
345
356
(data [1 ] - 33 ) * 91 * 91 +
0 commit comments