PTT optimizations

legacy
sh123 2022-08-06 19:23:24 +03:00
rodzic 0ebb8b07a7
commit f8e617c9ca
2 zmienionych plików z 46 dodań i 37 usunięć

Wyświetl plik

@ -16,23 +16,15 @@ import java.util.TimerTask;
public class Ft817 implements RigCtl {
private static final String TAG = Ft817.class.getSimpleName();
private static final int PTT_OFF_DELAY_MS = 1000;
private Transport _transport;
private Timer _pttOffTimer;
private boolean _isPttOn = false;
@Override
public void initialize(Transport transport, Context context, RigCtlCallback protocolCallback) throws IOException {
_transport = transport;
_isPttOn = false;
}
@Override
public void pttOn() throws IOException {
if (_isPttOn) return;
// 0x00, 0x00, 0x00, 0x00, 0x08
// returns 0x00 (was un-keyed), 0xf0 (already keyed)
Log.i(TAG, "PTT ON");
@ -44,32 +36,10 @@ public class Ft817 implements RigCtl {
byte[] response = new byte[1];
int bytesRead = _transport.read(response);
Log.i(TAG, "PTT ON response: " + bytesRead + " " + response[0]);
_isPttOn = true;
}
@Override
public void pttOff() {
if (!_isPttOn) return;
if (_pttOffTimer != null) {
_pttOffTimer.cancel();
_pttOffTimer.purge();
_pttOffTimer = null;
}
_pttOffTimer = new Timer();
_pttOffTimer.schedule(new TimerTask() {
@Override
public void run() {
try {
sendPttOff();
} catch (IOException e) {
e.printStackTrace();
}
}
}, PTT_OFF_DELAY_MS);
}
public void sendPttOff() throws IOException {
public void pttOff() throws IOException {
// 0x00, 0x00, 0x00, 0x00, 0x88
// returns 0x00 (was keyed), 0xf0 (already un-keyed)
Log.i(TAG, "PTT OFF");
@ -81,7 +51,5 @@ public class Ft817 implements RigCtl {
byte[] response = new byte[1];
int bytesRead = _transport.read(response);
Log.i(TAG, "PTT OFF response: " + bytesRead + " " + response[0]);
_isPttOn = false;
}
}

Wyświetl plik

@ -24,14 +24,18 @@ import java.io.IOException;
import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Timer;
import java.util.TimerTask;
public class SoundModem implements Transport, Runnable {
private static final String TAG = SoundModem.class.getSimpleName();
private static final int PTT_OFF_DELAY_MS = 1000;
// NOTE, codec2 library requires that sample_rate % bit_rate == 0
//public static final int SAMPLE_RATE = 19200;
public static final int SAMPLE_RATE = 48000;
public static final int SAMPLE_RATE = 19200;
//public static final int SAMPLE_RATE = 48000;
private final String _name;
@ -56,6 +60,8 @@ public class SoundModem implements Transport, Runnable {
private final long _fskModem;
private final RigCtl _rigCtl;
private Timer _pttOffTimer;
private boolean _isPttOn = false;
public SoundModem(Context context) {
_context = context;
@ -94,6 +100,8 @@ public class SoundModem implements Transport, Runnable {
e.printStackTrace();
}
_isPttOn = false;
if (!disableRx)
new Thread(this).start();
}
@ -159,11 +167,12 @@ public class SoundModem implements Transport, Runnable {
@Override
public int write(byte[] srcDataBytesAsBits) throws IOException {
pttOn();
//Log.v(TAG, "write " + DebugTools.byteBitsToFlatString(srcDataBytesAsBits));
byte[] dataBytesAsBits = BitTools.convertToNRZI(srcDataBytesAsBits);
//Log.v(TAG, "write NRZ " + DebugTools.byteBitsToFlatString(dataBytesAsBits));
//Log.v(TAG, "write NRZ " + DebugTools.byteBitsToString(dataBytesAsBits));
_rigCtl.pttOn();
int j = 0;
for (int i = 0; i < dataBytesAsBits.length; i++, j++) {
@ -197,7 +206,7 @@ public class SoundModem implements Transport, Runnable {
} else {
_systemAudioPlayer.write(_playbackAudioBuffer, 0, bitBufferTail.length * _samplesPerSymbol);
}
_rigCtl.pttOff();
pttOff();
return 0;
}
@ -264,4 +273,36 @@ public class SoundModem implements Transport, Runnable {
}
}
}
private void pttOn() {
if (_isPttOn) return;
try {
_rigCtl.pttOn();
_isPttOn = true;
} catch (IOException e) {
e.printStackTrace();
}
}
private void pttOff() {
if (!_isPttOn) return;
if (_pttOffTimer != null) {
_pttOffTimer.cancel();
_pttOffTimer.purge();
_pttOffTimer = null;
}
_pttOffTimer = new Timer();
_pttOffTimer.schedule(new TimerTask() {
@Override
public void run() {
try {
_rigCtl.pttOff();
_isPttOn = false;
} catch (IOException e) {
e.printStackTrace();
}
}
}, PTT_OFF_DELAY_MS);
}
}