Skip to content

Commit 48808c3

Browse files
committed
Parse /A=xxxxx altitude from comment even for compressed position reports
1 parent 84faf42 commit 48808c3

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

codec2talkie/src/main/java/com/radio/codec2talkie/protocol/aprs/AprsDataPositionReport.java

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,9 @@ private boolean fromCompressedBinary(byte[] infoData) {
180180
_position.latitude = getUncompressedCoordinate(latitude.getBytes(), true);
181181
if (longitude == null) return false;
182182
_position.longitude = getUncompressedCoordinate(longitude.getBytes(), false);
183-
if (comment != null)
183+
if (comment != null) {
184184
_position.comment = TextTools.stripNulls(comment);
185+
}
185186

186187
_position.hasSpeed = false;
187188
_position.hasBearing = false;
@@ -222,6 +223,9 @@ else if (cByte == '{') {
222223
// TODO, implement
223224
double rangeMiles = 2 * Math.pow(1.08, sByte);
224225
}
226+
227+
// sometimes altitude is coming from comment event for compressed packets
228+
_position.comment = parseAltitude(_position.comment);
225229
return true;
226230
}
227231

@@ -294,22 +298,8 @@ private boolean fromUncompressedBinary(byte[] infoData) {
294298
}
295299
if (strTail == null) return true;
296300

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);
313303

314304
// read PHG range
315305
Pattern phgPattern = Pattern.compile("^.*(PHG\\d{4}).*$", Pattern.DOTALL);
@@ -340,6 +330,27 @@ private boolean fromUncompressedBinary(byte[] infoData) {
340330
return true;
341331
}
342332

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+
343354
private double getUncompressedCoordinate(byte[] data, boolean isLatitude) {
344355
double v = (data[0] - 33) * 91 * 91 * 91 +
345356
(data[1] - 33) * 91 * 91 +

0 commit comments

Comments
 (0)