Skip to content

Commit eba020c

Browse files
committed
Prefix OFDM HF AX25 APRS packets with packet length
1 parent ce069d9 commit eba020c

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

codec2talkie/src/main/java/com/radio/codec2talkie/protocol/Freedv.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
public class Freedv implements Protocol {
2323
private static final String TAG = Freedv.class.getSimpleName();
2424

25+
private static final int CRC_LENGTH = 2;
26+
private static final int PKT_SIZE_LENGTH = 2;
27+
2528
private ProtocolCallback _parentProtocolCallback;
2629
private Transport _transport;
2730

@@ -89,15 +92,18 @@ public void sendTextMessage(TextMessage textMessage) throws IOException {
8992

9093
@Override
9194
public void sendData(String src, String dst, String path, byte[] dataPacket) throws IOException {
92-
if (dataPacket.length > _dataBuffer.length - 2) {
95+
if (dataPacket.length > _dataBuffer.length - CRC_LENGTH - PKT_SIZE_LENGTH) {
9396
Log.e(TAG, "Too large packet " + dataPacket.length + " > " + _dataBuffer.length);
9497
return;
9598
}
9699
long cnt = Codec2.freedvRawDataPreambleTx(_freedvData, _dataSamplesBuffer);
97100
_transport.write(Arrays.copyOf(_dataSamplesBuffer, (int) cnt));
98101

99102
Arrays.fill(_dataBuffer, (byte) 0);
100-
System.arraycopy(dataPacket, 0, _dataBuffer, 0, dataPacket.length);
103+
// transmit packet size first
104+
_dataBuffer[0] = (byte)((dataPacket.length >> 8) & 0xff);
105+
_dataBuffer[1] = (byte)(dataPacket.length & 0xff);
106+
System.arraycopy(dataPacket, 0, _dataBuffer, 2, dataPacket.length);
101107
Codec2.freedvRawDataTx(_freedvData, _dataSamplesBuffer, _dataBuffer);
102108
_transport.write(_dataSamplesBuffer);
103109

@@ -151,8 +157,12 @@ public boolean receive() throws IOException {
151157
long cntRead = Codec2.freedvRawDataRx(_freedvData, _dataBuffer, samplesData);
152158
if (cntRead > 0) {
153159
Log.i(TAG, "receive " + cntRead);
160+
// extract packet length
161+
int pktLen = (((int)_dataBuffer[0] & 0xff) << 8) | ((int)_dataBuffer[1] & 0xff);
162+
byte [] pkt = new byte[pktLen];
163+
System.arraycopy(_dataBuffer, 2, pkt, 0, pktLen);
154164
// TODO, refactor, use onReceiveData
155-
_parentProtocolCallback.onReceiveCompressedAudio(null, null, -1, _dataBuffer);
165+
_parentProtocolCallback.onReceiveCompressedAudio(null, null, -1, pkt);
156166
float snr = Codec2.freedvGetModemStat(_freedvData);
157167
_parentProtocolCallback.onReceiveSignalLevel((short) 0, (short)(100 * snr));
158168
isRead = true;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void fromBinary(String srcCallsign, String dstCallsign, String digipath,
6060
// message
6161
byte[] message = new byte[buffer.remaining()];
6262
buffer.get(message);
63-
textMessage = new String(message);
63+
textMessage = new String(message, StandardCharsets.UTF_8);
6464
// TODO, message id: {xxxxx
6565
_isValid = true;
6666
}

0 commit comments

Comments
 (0)