Position parser improvements

legacy
sh123 2022-07-23 17:23:57 +03:00
rodzic 6f0029dd74
commit c7c3c66038
4 zmienionych plików z 34 dodań i 5 usunięć

Wyświetl plik

@ -4,6 +4,7 @@ import com.radio.codec2talkie.protocol.aprs.tools.AprsTools;
import com.radio.codec2talkie.protocol.message.TextMessage;
import com.radio.codec2talkie.protocol.position.Position;
import com.radio.codec2talkie.tools.MathTools;
import com.radio.codec2talkie.tools.TextTools;
import com.radio.codec2talkie.tools.UnitTools;
import java.nio.ByteBuffer;
@ -48,6 +49,7 @@ public class AprsDataPositionReport implements AprsData {
_position = new Position();
_position.srcCallsign = srcCallsign;
_position.dstCallsign = dstCallsign;
_position.privacyLevel = 0;
if ((infoData[0] == '/' || infoData[0] == '\\') && fromCompressedBinary(infoData)) {
_position.isCompressed = true;
_isValid = true;
@ -203,18 +205,23 @@ public class AprsDataPositionReport implements AprsData {
byte[] tail = new byte[buffer.remaining()];
buffer.get(tail);
String strTail = new String(tail);
Pattern latLonPattern = Pattern.compile("^(\\d{4}[.]\\d{2})(N|S)([/\\\\])(\\d{5}[.]\\d{2})(E|W)(\\S)(.+)$");
Pattern latLonPattern = Pattern.compile("^([\\d ]{4}[.][\\d ]{2})(N|S)([/\\\\])([\\d ]{5}[.][\\d ]{2})(E|W)(\\S)(.+)$");
Matcher latLonMatcher = latLonPattern.matcher(strTail);
if (!latLonMatcher.matches()) return false;
String lat = latLonMatcher.group(1);
String latSuffix = latLonMatcher.group(2);
if (lat == null || latSuffix == null) return false;
_position.privacyLevel = TextTools.countChars(lat, ' ');
// NOTE, ambiguity, replace with 0
lat = lat.replace(' ', '0');
_position.latitude = UnitTools.nmeaToDecimal(lat, latSuffix);
String table = latLonMatcher.group(3);
String lon = latLonMatcher.group(4);
String lonSuffix = latLonMatcher.group(5);
if (lon == null || lonSuffix == null) return false;
// NOTE, ambiguity, replace with 0
lon = lon.replace(' ', '0');
_position.longitude = UnitTools.nmeaToDecimal(lon, lonSuffix);
String symbol = latLonMatcher.group(6);
_position.symbolCode = String.format("%s%s", table, symbol);

Wyświetl plik

@ -115,6 +115,7 @@ public class AprsDataPositionReportMicE implements AprsData {
_dstCallsign = dstCallsign;
_position.srcCallsign = srcCallsign;
_position.dstCallsign = dstCallsign;
_position.privacyLevel = 0;
if (srcCallsign == null || dstCallsign == null) return;
if (dstCallsign.length() < 6 || infoData.length < 8) return;
@ -135,7 +136,12 @@ public class AprsDataPositionReportMicE implements AprsData {
isCustom = true;
if (c != 'L') messageId |= 1;
}
c = (c == 'K' || c == 'L') ? ' ' : (char) (c - 17);
if (c == 'K' || c == 'L') {
// NOTE, using 0 instead of ' ' for position ambiguity
c = '0';
_position.privacyLevel += 1;
} else
c = (char) (c - 17);
} else if (c >= 'P' && c <= 'Z') {
if (i < 3) {
messageId |= 1;
@ -146,7 +152,12 @@ public class AprsDataPositionReportMicE implements AprsData {
} else {
we = 'W';
}
c = (c == 'Z') ? ' ' : (char) (c - 32);
if (c == 'Z') {
// NOTE, using 0 instead of ' ' for position ambiguity
c = '0';
_position.privacyLevel += 1;
} else
c = (char) (c - 32);
}
if (i < 2) messageId <<= 1;
if (i == 4) latitude.append('.');

Wyświetl plik

@ -4,4 +4,15 @@ public class TextTools {
public static String addZeroWidthSpaces(String text) {
return text.replaceAll(".(?!$)", "$0\u200b");
}
public static int countChars(String text, char ch) {
int count = 0;
for (int i = 0; i < text.length(); i++) {
if (text.charAt(i) == ch) {
count++;
}
}
return count;
}
}

Wyświetl plik

@ -37,11 +37,11 @@ public class UnitTools {
}
public static long metersToFeet(double meters) {
return (long)(meters * 3.2808);
return (long)(meters * 3.28084);
}
public static double feetToMeters(long feet) {
return feet * 0.3048;
return feet / 3.28084;
}
public static long metersPerSecondToKnots(double metersPerSecond) {