Improve logging

aprs
sh123 2022-08-14 19:52:42 +03:00
rodzic 42b306d21c
commit 60c62a2f82
7 zmienionych plików z 36 dodań i 9 usunięć

Wyświetl plik

@ -149,7 +149,8 @@ public class Freedv implements Protocol {
long cntRead = Codec2.freedvRawDataRx(_freedvData, _dataBuffer, samplesData); long cntRead = Codec2.freedvRawDataRx(_freedvData, _dataBuffer, samplesData);
if (cntRead > 0) { if (cntRead > 0) {
Log.i(TAG, "receive " + cntRead); Log.i(TAG, "receive " + cntRead);
//_parentProtocolCallback.onReceiveCompressedAudio(null, null, -1, _dataBuffer); // TODO, refactor, use onReceiveData
_parentProtocolCallback.onReceiveCompressedAudio(null, null, -1, _dataBuffer);
isRead = true; isRead = true;
} }
ninData = Codec2.freedvNin(_freedvData); ninData = Codec2.freedvNin(_freedvData);
@ -165,8 +166,7 @@ public class Freedv implements Protocol {
@Override @Override
public void flush() throws IOException { public void flush() throws IOException {
Log.i(TAG, "flush()"); // TODO, check if need to flush buffers
// TODO buffers
} }
@Override @Override

Wyświetl plik

@ -110,7 +110,7 @@ public class Hdlc implements Protocol {
//Log.i(TAG, "checksum: " + calculatedCrc + " " + packetCrc); //Log.i(TAG, "checksum: " + calculatedCrc + " " + packetCrc);
if (calculatedCrc == packetCrc) { if (calculatedCrc == packetCrc) {
//Log.v(TAG, DebugTools.byteBitsToString(packetBits)); //Log.v(TAG, DebugTools.byteBitsToString(packetBits));
Log.i(TAG, "RX: " + DebugTools.bytesToHex(packetBytes)); //Log.i(TAG, "RX: " + DebugTools.bytesToHex(packetBytes));
_parentProtocolCallback.onReceiveCompressedAudio(null, null, -1, contentBytes); _parentProtocolCallback.onReceiveCompressedAudio(null, null, -1, contentBytes);
} }
} }

Wyświetl plik

@ -296,6 +296,7 @@ public class Kiss implements Protocol {
case KISS_FEND: case KISS_FEND:
if (_kissDataType == DataType.RAW) { if (_kissDataType == DataType.RAW) {
// NOTE, KISS does not distinguish between audio and data packets, upper layer should decide // NOTE, KISS does not distinguish between audio and data packets, upper layer should decide
// TODO, refactor, use onReceiveData
protocolCallback.onReceiveCompressedAudio(null, null, -1, Arrays.copyOf(_frameOutputBuffer, _frameOutputBufferPos)); protocolCallback.onReceiveCompressedAudio(null, null, -1, Arrays.copyOf(_frameOutputBuffer, _frameOutputBufferPos));
} else if (_kissDataType == DataType.SIGNAL_REPORT && _isExtendedMode) { } else if (_kissDataType == DataType.SIGNAL_REPORT && _isExtendedMode) {
byte[] signalLevelRaw = Arrays.copyOf(_kissCmdBuffer, _kissCmdBufferPos); byte[] signalLevelRaw = Arrays.copyOf(_kissCmdBuffer, _kissCmdBufferPos);

Wyświetl plik

@ -164,7 +164,7 @@ public class AprsDataPositionReport implements AprsData {
if (longitude == null) return false; if (longitude == null) return false;
_position.longitude = getUncompressedCoordinate(longitude.getBytes(), false); _position.longitude = getUncompressedCoordinate(longitude.getBytes(), false);
if (comment != null) if (comment != null)
_position.comment = comment; _position.comment = TextTools.stripNulls(comment);
_position.hasSpeed = false; _position.hasSpeed = false;
_position.hasBearing = false; _position.hasBearing = false;
@ -283,7 +283,7 @@ public class AprsDataPositionReport implements AprsData {
_position.hasAltitude = false; _position.hasAltitude = false;
} }
// read comment until the end // read comment until the end
_position.comment = strTail; _position.comment = TextTools.stripNulls(strTail);
return true; return true;
} }

Wyświetl plik

@ -3,6 +3,7 @@ package com.radio.codec2talkie.protocol.aprs;
import com.radio.codec2talkie.protocol.aprs.tools.AprsTools; import com.radio.codec2talkie.protocol.aprs.tools.AprsTools;
import com.radio.codec2talkie.protocol.message.TextMessage; import com.radio.codec2talkie.protocol.message.TextMessage;
import com.radio.codec2talkie.protocol.position.Position; import com.radio.codec2talkie.protocol.position.Position;
import com.radio.codec2talkie.tools.TextTools;
import com.radio.codec2talkie.tools.UnitTools; import com.radio.codec2talkie.tools.UnitTools;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -220,9 +221,9 @@ public class AprsDataPositionReportMicE implements AprsData {
if (infoData.length > 11 && infoData[11] == '}') { if (infoData.length > 11 && infoData[11] == '}') {
_position.hasAltitude = true; _position.hasAltitude = true;
_position.altitudeMeters = ((infoData[8] - 33) * 91 * 91 + (infoData[9] - 33) * 91 + (infoData[10] - 33)) - 10000; _position.altitudeMeters = ((infoData[8] - 33) * 91 * 91 + (infoData[9] - 33) * 91 + (infoData[10] - 33)) - 10000;
_position.comment = new String(Arrays.copyOfRange(infoData, 12, infoData.length)); _position.comment = TextTools.stripNulls(new String(Arrays.copyOfRange(infoData, 12, infoData.length)));
} else { } else {
_position.comment = new String(Arrays.copyOfRange(infoData, 8, infoData.length)); _position.comment = TextTools.stripNulls(new String(Arrays.copyOfRange(infoData, 8, infoData.length)));
} }
_position.maidenHead = UnitTools.decimalToMaidenhead(_position.latitude, _position.longitude); _position.maidenHead = UnitTools.decimalToMaidenhead(_position.latitude, _position.longitude);

Wyświetl plik

@ -3,6 +3,7 @@ package com.radio.codec2talkie.protocol.ax25;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import com.radio.codec2talkie.tools.DebugTools; import com.radio.codec2talkie.tools.DebugTools;
import com.radio.codec2talkie.tools.TextTools;
import java.nio.BufferUnderflowException; import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -157,7 +158,11 @@ public class AX25Packet {
String path = digipath == null ? "" : digipath; String path = digipath == null ? "" : digipath;
if (!path.isEmpty()) if (!path.isEmpty())
path = "," + path; path = "," + path;
return String.format("%s>%s%s:%s", src, dst, path, DebugTools.bytesToDebugString(rawData)); String info = DebugTools.bytesToDebugString(rawData);
if (!isAudio) {
info = DebugTools.bytesToDebugString(TextTools.stripNulls(rawData));
}
return String.format("%s>%s%s:%s", src, dst, path, info);
} }
private boolean digiRepeatMicE() { private boolean digiRepeatMicE() {

Wyświetl plik

@ -1,5 +1,9 @@
package com.radio.codec2talkie.tools; package com.radio.codec2talkie.tools;
import android.util.Log;
import java.util.Arrays;
public class TextTools { public class TextTools {
public static String addZeroWidthSpaces(String text) { public static String addZeroWidthSpaces(String text) {
return text.replaceAll(".(?!$)", "$0\u200b"); return text.replaceAll(".(?!$)", "$0\u200b");
@ -15,4 +19,20 @@ public class TextTools {
} }
return count; return count;
} }
public static String stripNulls(String text) {
int pos = text.indexOf('\0');
if (pos == -1) return text;
return text.substring(0, pos);
}
public static byte[] stripNulls(byte[] data) {
int i = 0;
for (byte b : data) {
if (b == 0) break;
i++;
}
if (i == data.length) return data;
return Arrays.copyOf(data, i);
}
} }