generated from Grigo/AndroidTemplate
Ковырял декодер строк
This commit is contained in:
@@ -1081,8 +1081,8 @@ public class NMEAParser {
|
||||
double length = dimRefA + dimRefB;
|
||||
double width = dimRefC + dimRefD;
|
||||
|
||||
// Draft (8 бит) - осадка - бит 296
|
||||
String draftBits = decodeAISField(payload, 296, 8);
|
||||
// Draft (8 бит) - осадка - бит 294
|
||||
String draftBits = decodeAISField(payload, 294, 8);
|
||||
double draft = Integer.parseInt(draftBits, 2) / 10.0;
|
||||
|
||||
Log.d(TAG, "Static Data - используем Dimension Reference поля (9, 9, 6, 6 бит):");
|
||||
@@ -1094,8 +1094,8 @@ public class NMEAParser {
|
||||
Log.d(TAG, " Total Width (C+D): " + width + " м");
|
||||
Log.d(TAG, " Draft: " + draftBits + " = " + draft + " м");
|
||||
|
||||
// ETA (20 бит) - бит 294
|
||||
String etaBits = decodeAISField(payload, 294, 20);
|
||||
// ETA (20 бит) - бит 274
|
||||
String etaBits = decodeAISField(payload, 274, 20);
|
||||
int eta = Integer.parseInt(etaBits, 2);
|
||||
Log.d(TAG, "ETA bits: " + etaBits + " = " + eta);
|
||||
|
||||
@@ -1109,7 +1109,7 @@ public class NMEAParser {
|
||||
|
||||
// Вычисляем доступную длину для оставшихся полей
|
||||
int totalBits = payload.length() * 6;
|
||||
int remainingBits = totalBits - 314; // Остается после ETA
|
||||
int remainingBits = totalBits - 294; // Остается после ETA
|
||||
Log.d(TAG, "Remaining bits after ETA: " + remainingBits + " (total: " + totalBits + ")");
|
||||
|
||||
String destination = "";
|
||||
@@ -1117,81 +1117,18 @@ public class NMEAParser {
|
||||
String epfdDescription = "Unknown";
|
||||
boolean dteReady = false;
|
||||
|
||||
// Для коротких сообщений (426 бит) используем упрощенную структуру
|
||||
if (totalBits <= 426) {
|
||||
// В коротких сообщениях может не быть всех полей
|
||||
// Пробуем разные позиции для Destination
|
||||
int[] possibleDestStarts = {302, 314, 320, 328};
|
||||
for (int destStartBit : possibleDestStarts) {
|
||||
if (destStartBit + 120 <= totalBits) {
|
||||
String destBits = decodeAISField(payload, destStartBit, 120);
|
||||
String testDest = decodeAISString(destBits);
|
||||
Log.d(TAG, "Пробуем Destination с бита " + destStartBit + ": " + testDest);
|
||||
if (testDest.contains("DEFAULT") || testDest.contains("FAULT")) {
|
||||
destination = testDest;
|
||||
Log.d(TAG, "Найден Destination с бита " + destStartBit + ": '" + destination + "'");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Если не нашли, используем стандартную позицию
|
||||
if (destination.isEmpty() && remainingBits > 0) {
|
||||
int destStartBit = 314;
|
||||
int destLength = Math.min(remainingBits, 120);
|
||||
String destBits = decodeAISField(payload, destStartBit, destLength);
|
||||
destination = decodeAISString(destBits);
|
||||
Log.d(TAG, "Destination bits (fallback): " + destBits + " = '" + destination + "' (length: " + destLength + ")");
|
||||
}
|
||||
} else {
|
||||
// Для полных сообщений используем стандартную структуру
|
||||
if (remainingBits >= 8) {
|
||||
// Maximum present static draught (8 бит) - бит 314
|
||||
String draughtBits = decodeAISField(payload, 314, 8);
|
||||
int draughtValue = Integer.parseInt(draughtBits, 2);
|
||||
maxDraught = (draughtValue == 0) ? 0.0 : (draughtValue == 255) ? 25.5 : draughtValue / 10.0;
|
||||
Log.d(TAG, "Max Draught bits: " + draughtBits + " = " + maxDraught + "m");
|
||||
remainingBits -= 8;
|
||||
}
|
||||
|
||||
if (remainingBits >= 4) {
|
||||
// Type of electronic position fixing device (4 бита)
|
||||
int epfdStartBit = 314 + 8;
|
||||
String epfdBits = decodeAISField(payload, epfdStartBit, 4);
|
||||
int epfdType = Integer.parseInt(epfdBits, 2);
|
||||
epfdDescription = getEPFDType(epfdType);
|
||||
Log.d(TAG, "EPFD Type bits: " + epfdBits + " = " + epfdType + " (" + epfdDescription + ")");
|
||||
remainingBits -= 4;
|
||||
}
|
||||
|
||||
if (remainingBits >= 1) {
|
||||
// DTE (1 бит)
|
||||
int dteStartBit = 314 + 8 + 4;
|
||||
String dteBits = decodeAISField(payload, dteStartBit, 1);
|
||||
dteReady = Integer.parseInt(dteBits, 2) == 0;
|
||||
Log.d(TAG, "DTE bits: " + dteBits + " = " + dteReady + " (ready: " + dteReady + ")");
|
||||
remainingBits -= 1;
|
||||
}
|
||||
|
||||
if (remainingBits >= 1) {
|
||||
// Spare (1 бит)
|
||||
int spareStartBit = 314 + 8 + 4 + 1;
|
||||
String spareBits = decodeAISField(payload, spareStartBit, 1);
|
||||
int spare = Integer.parseInt(spareBits, 2);
|
||||
Log.d(TAG, "Spare bits: " + spareBits + " = " + spare);
|
||||
remainingBits -= 1;
|
||||
}
|
||||
|
||||
if (remainingBits > 0) {
|
||||
// Destination (оставшиеся биты)
|
||||
int destStartBit = 314 + 8 + 4 + 1 + 1;
|
||||
int destLength = Math.min(remainingBits, 120); // Максимум 120 бит
|
||||
String destBits = decodeAISField(payload, destStartBit, destLength);
|
||||
destination = decodeAISString(destBits);
|
||||
Log.d(TAG, "Destination bits (full): " + destBits + " = '" + destination + "' (length: " + destLength + ")");
|
||||
} else {
|
||||
Log.w(TAG, "Destination поле недоступно - недостаточно битов");
|
||||
}
|
||||
// Destination (120 бит) - бит 302
|
||||
if (totalBits >= 302 + 120) {
|
||||
String destBits = decodeAISField(payload, 302, 120);
|
||||
destination = decodeAISString(destBits);
|
||||
Log.d(TAG, "Destination bits: " + destBits + " = '" + destination + "'");
|
||||
} else if (remainingBits > 0) {
|
||||
// Если сообщение короткое, читаем доступные биты
|
||||
int destStartBit = 302;
|
||||
int destLength = Math.min(remainingBits, 120);
|
||||
String destBits = decodeAISField(payload, destStartBit, destLength);
|
||||
destination = decodeAISString(destBits);
|
||||
Log.d(TAG, "Destination bits (short): " + destBits + " = '" + destination + "' (length: " + destLength + ")");
|
||||
}
|
||||
|
||||
Log.d(TAG, String.format("AIS Static: MMSI=%d, IMO=%d, name='%s', callSign='%s', type=%d, L=%.1f, W=%.1f, D=%.1f, maxD=%.1f, ETA=%s, EPFD=%s, DTE=%s, dest='%s'",
|
||||
@@ -1300,52 +1237,29 @@ public class NMEAParser {
|
||||
/**
|
||||
* Декодирует AIS строку
|
||||
*/
|
||||
//TODO: Исправить на нормальный декодер строк
|
||||
private String decodeAISString(String bits) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
Log.d(TAG, "Декодируем AIS строку из битов: " + bits + " (длина: " + bits.length() + ")");
|
||||
|
||||
for (int i = 0; i < bits.length(); i += 6) {
|
||||
if (i + 6 <= bits.length()) {
|
||||
String charBits = bits.substring(i, i + 6);
|
||||
int value = Integer.parseInt(charBits, 2);
|
||||
|
||||
char decodedChar;
|
||||
Log.d(TAG, "Обрабатываем значение: " + value + " (биты: " + charBits + ")");
|
||||
|
||||
// Приоритет специальных случаев (пробелы)
|
||||
if (value == 32 || value == 63) {
|
||||
decodedChar = ' '; // Пробел
|
||||
Log.d(TAG, "Найден пробел (" + value + ")");
|
||||
} else if (value >= 1 && value <= 26) {
|
||||
// Заглавные буквы A-Z
|
||||
decodedChar = (char)('A' + value - 1);
|
||||
Log.d(TAG, "Диапазон A-Z: " + value + " -> " + decodedChar);
|
||||
} else if (value >= 49 && value <= 58) {
|
||||
// Цифры 1-9 (кастомное сопоставление на основе AIS1)
|
||||
decodedChar = (char)('1' + (value - 49));
|
||||
Log.d(TAG, "Диапазон 1-9: " + value + " -> " + decodedChar);
|
||||
} else if (value == 59) {
|
||||
// Цифра 0 (кастомное сопоставление)
|
||||
decodedChar = '0';
|
||||
Log.d(TAG, "Декодирован символ (59) -> '0'");
|
||||
} else if (value == 0) {
|
||||
// Нулевое значение - конец строки, но не останавливаемся сразу
|
||||
decodedChar = ' '; // Заменяем на пробел для продолжения
|
||||
Log.d(TAG, "Найден ноль, заменяем на пробел");
|
||||
} else {
|
||||
// Неизвестный или зарезервированный символ
|
||||
decodedChar = '?';
|
||||
Log.w(TAG, "Неизвестное или зарезервированное значение AIS символа: " + value + " (биты: " + charBits + ")");
|
||||
}
|
||||
|
||||
result.append(decodedChar);
|
||||
Log.d(TAG, "Декодирован символ: " + charBits + " (" + value + ") -> '" + decodedChar + "'");
|
||||
|
||||
for (int i = 0; i + 6 <= bits.length(); i += 6) {
|
||||
String charBits = bits.substring(i, i + 6);
|
||||
int value = Integer.parseInt(charBits, 2);
|
||||
|
||||
char decodedChar;
|
||||
if (value == 0) {
|
||||
decodedChar = ' '; // 0 = пробел
|
||||
} else if (value >= 1 && value <= 26) {
|
||||
decodedChar = (char) ('A' + value - 1); // 1..26 = A..Z
|
||||
} else if (value >= 27 && value <= 36) {
|
||||
decodedChar = (char) ('0' + (value - 27)); // 27..36 = 0..9
|
||||
} else {
|
||||
decodedChar = ' '; // всё остальное = пробел
|
||||
}
|
||||
|
||||
result.append(decodedChar);
|
||||
}
|
||||
|
||||
String resultStr = result.toString().trim();
|
||||
Log.d(TAG, "Результат декодирования строки: '" + resultStr + "'");
|
||||
return resultStr;
|
||||
|
||||
return result.toString().trim();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user