Uncompressed position parsing

legacy
sh123 2022-07-22 17:16:31 +03:00
rodzic 9100eb4f0f
commit 8bb87173f7
4 zmienionych plików z 20 dodań i 10 usunięć

Wyświetl plik

@ -229,7 +229,10 @@ public class AppWorker extends Thread {
private final ProtocolCallback _protocolCallback = new ProtocolCallback() {
@Override
protected void onReceivePosition(Position position) {
throw new UnsupportedOperationException();
Log.i(TAG, String.format("Position: %f %f %f %f %f",
position.latitude, position.longitude,
position.bearingDegrees, position.speedMetersPerSecond, position.altitudeMeters));
// TODO, store to database
}
@Override

Wyświetl plik

@ -8,12 +8,12 @@ public class AprsDataFactory {
public static AprsData create(AprsDataType aprsDataType) {
switch (aprsDataType.getDataType()) {
case UNKNOWN:
case POSITION_WITH_TIMESTAMP_MSG:
case POSITION_WITH_TIMESTAMP_NO_MSG:
case POSITION_WITHOUT_TIMESTAMP_NO_MSG:
break;
case MIC_E:
return new AprsDataPositionReportMicE();
case POSITION_WITH_TIMESTAMP_MSG:
case POSITION_WITH_TIMESTAMP_NO_MSG:
case POSITION_WITHOUT_TIMESTAMP_NO_MSG:
case POSITION_WITHOUT_TIMESTAMP_MSG:
return new AprsDataPositionReport();
case MESSAGE:

Wyświetl plik

@ -67,7 +67,7 @@ public class AprsDataPositionReport implements AprsData {
private byte[] generateCompressedInfo(Position position) {
ByteBuffer buffer = ByteBuffer.allocate(256);
buffer.put((byte)'!');
buffer.put((byte)'=');
buffer.put(getCompressedNmeaCoordinate(position));
// compressed can hold either speed and bearing or altitude
if (position.isSpeedBearingEnabled) {
@ -93,7 +93,7 @@ public class AprsDataPositionReport implements AprsData {
private byte[] generateUncompressedInfo(Position position) {
ByteBuffer buffer = ByteBuffer.allocate(256);
buffer.put((byte)'!');
buffer.put((byte)'=');
buffer.put(getUncompressedNmeaCoordinate(position).getBytes());
// put course altitude
if (position.isSpeedBearingEnabled) {
@ -137,11 +137,11 @@ public class AprsDataPositionReport implements AprsData {
String lat = latLonMatcher.group(1);
String latSuffix = latLonMatcher.group(2);
_position.latitude = UnitTools.nmeaToDecimal(lat, latSuffix, true);
_position.latitude = UnitTools.nmeaToDecimal(lat, latSuffix);
String table = latLonMatcher.group(3);
String lon = latLonMatcher.group(4);
String lonSuffix = latLonMatcher.group(5);
_position.longitude = UnitTools.nmeaToDecimal(lon, lonSuffix, false);
_position.longitude = UnitTools.nmeaToDecimal(lon, lonSuffix);
String symbol = latLonMatcher.group(6);
_position.symbolCode = String.format("%s%s", table, symbol);
strTail = latLonMatcher.group(7);

Wyświetl plik

@ -17,8 +17,15 @@ public class UnitTools {
isLatitude ? (degrees > 0 ? 'N' : 'S') : (degrees > 0 ? 'E' : 'W'));
}
public static double nmeaToDecimal(String degrees, String dir, boolean isLatitude) {
return 0.0;
public static double nmeaToDecimal(String degrees, String dir) {
// ddmm.mm / dddmm.mm
int digitCount = degrees.charAt(4) == '.' ? 2 : 3;
String integerPart = degrees.substring(0, digitCount);
String fractionalPart = degrees.substring(digitCount);
double v = Double.parseDouble(integerPart) + Double.parseDouble(fractionalPart) / 60.0;
if (dir.equals("W") || dir.equals("S"))
v = -v;
return v;
}
public static String decimalToDecimalNmea(double degrees, boolean isLatitude) {