aprs
sh123 2022-08-13 20:48:45 +03:00
rodzic 8ab5f3cf94
commit f6480ac927
12 zmienionych plików z 86 dodań i 83 usunięć

Wyświetl plik

@ -10,7 +10,6 @@ import android.media.AudioManager;
import android.media.AudioRecord; import android.media.AudioRecord;
import android.media.AudioTrack; import android.media.AudioTrack;
import android.media.MediaRecorder; import android.media.MediaRecorder;
import android.os.Build;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.os.Message; import android.os.Message;
@ -540,7 +539,7 @@ public class AppWorker extends Thread {
try { try {
_protocol.initialize(_transport, _context, _protocolCallback); _protocol.initialize(_transport, _context, _protocolCallback);
_recordAudioBuffer = new short[_protocol.getPcmAudioBufferSize()]; _recordAudioBuffer = new short[_protocol.getPcmAudioRecordBufferSize()];
startWorkerMessageHandler(); startWorkerMessageHandler();
Looper.loop(); Looper.loop();
} catch (IOException e) { } catch (IOException e) {

Wyświetl plik

@ -72,13 +72,13 @@ public class Aprs implements Protocol {
} }
@Override @Override
public int getPcmAudioBufferSize() { public int getPcmAudioRecordBufferSize() {
return _childProtocol.getPcmAudioBufferSize(); return _childProtocol.getPcmAudioRecordBufferSize();
} }
@Override @Override
public void sendCompressedAudio(String src, String dst, int codec2Mode, byte[] frame) { public void sendCompressedAudio(String src, String dst, int codec2Mode, byte[] frame) throws IOException {
throw new UnsupportedOperationException(); _childProtocol.sendCompressedAudio(src, dst, codec2Mode, frame);
} }
@Override @Override
@ -119,7 +119,7 @@ public class Aprs implements Protocol {
ProtocolCallback _protocolCallback = new ProtocolCallback() { ProtocolCallback _protocolCallback = new ProtocolCallback() {
@Override @Override
protected void onReceivePosition(Position position) { protected void onReceivePosition(Position position) {
throw new UnsupportedOperationException(); _parentProtocolCallback.onReceivePosition(position);
} }
@Override @Override
@ -130,7 +130,7 @@ public class Aprs implements Protocol {
@Override @Override
protected void onReceiveCompressedAudio(String src, String dst, int codec2Mode, byte[] audioFrame) { protected void onReceiveCompressedAudio(String src, String dst, int codec2Mode, byte[] audioFrame) {
throw new UnsupportedOperationException(); _parentProtocolCallback.onReceiveCompressedAudio(src, dst, codec2Mode, audioFrame);
} }
@Override @Override
@ -187,7 +187,7 @@ public class Aprs implements Protocol {
@Override @Override
protected void onTransmitPosition(Position position) { protected void onTransmitPosition(Position position) {
throw new UnsupportedOperationException(); _parentProtocolCallback.onTransmitPosition(position);
} }
@Override @Override

Wyświetl plik

@ -14,7 +14,6 @@ public class AudioCodec2 implements Protocol {
private final Protocol _childProtocol; private final Protocol _childProtocol;
private long _codec2Con; private long _codec2Con;
private int _codec2Mode;
private int _audioBufferSize; private int _audioBufferSize;
private char[] _recordAudioEncodedBuffer; private char[] _recordAudioEncodedBuffer;
@ -35,18 +34,18 @@ public class AudioCodec2 implements Protocol {
} }
@Override @Override
public int getPcmAudioBufferSize() { public int getPcmAudioRecordBufferSize() {
return _audioBufferSize; return _audioBufferSize;
} }
@Override @Override
public void sendCompressedAudio(String src, String dst, int codec2Mode, byte[] frame) { public void sendCompressedAudio(String src, String dst, int codec2Mode, byte[] frame) throws IOException {
throw new UnsupportedOperationException(); _childProtocol.sendCompressedAudio(src, dst, codec2Mode, frame);
} }
@Override @Override
public void sendTextMessage(TextMessage textMessage) { public void sendTextMessage(TextMessage textMessage) throws IOException {
throw new UnsupportedOperationException(); _childProtocol.sendTextMessage(textMessage);
} }
@Override @Override
@ -76,12 +75,12 @@ public class AudioCodec2 implements Protocol {
ProtocolCallback _protocolCallback = new ProtocolCallback() { ProtocolCallback _protocolCallback = new ProtocolCallback() {
@Override @Override
protected void onReceivePosition(Position position) { protected void onReceivePosition(Position position) {
throw new UnsupportedOperationException(); _parentProtocolCallback.onReceivePosition(position);
} }
@Override @Override
protected void onReceivePcmAudio(String src, String dst, int codec, short[] pcmFrame) { protected void onReceivePcmAudio(String src, String dst, int codec, short[] pcmFrame) {
throw new UnsupportedOperationException(); _parentProtocolCallback.onReceivePcmAudio(src, dst, codec, pcmFrame);
} }
@Override @Override
@ -112,7 +111,7 @@ public class AudioCodec2 implements Protocol {
@Override @Override
protected void onTransmitPcmAudio(String src, String dst, int codec, short[] frame) { protected void onTransmitPcmAudio(String src, String dst, int codec, short[] frame) {
throw new UnsupportedOperationException(); _parentProtocolCallback.onTransmitPcmAudio(src, dst, codec, frame);
} }
@Override @Override
@ -127,7 +126,7 @@ public class AudioCodec2 implements Protocol {
@Override @Override
protected void onTransmitPosition(Position position) { protected void onTransmitPosition(Position position) {
throw new UnsupportedOperationException(); _parentProtocolCallback.onTransmitPosition(position);
} }
@Override @Override
@ -152,8 +151,8 @@ public class AudioCodec2 implements Protocol {
}; };
@Override @Override
public void sendPosition(Position position) { public void sendPosition(Position position) throws IOException {
throw new UnsupportedOperationException(); _childProtocol.sendPosition(position);
} }
@Override @Override
@ -171,7 +170,6 @@ public class AudioCodec2 implements Protocol {
if (_codec2Con != 0) { if (_codec2Con != 0) {
Codec2.destroy(_codec2Con); Codec2.destroy(_codec2Con);
} }
_codec2Mode = codecMode;
_codec2Con = Codec2.create(codecMode); _codec2Con = Codec2.create(codecMode);
_audioBufferSize = Codec2.getSamplesPerFrame(_codec2Con); _audioBufferSize = Codec2.getSamplesPerFrame(_codec2Con);

Wyświetl plik

@ -51,8 +51,8 @@ public class AudioFrameAggregator implements Protocol {
} }
@Override @Override
public int getPcmAudioBufferSize() { public int getPcmAudioRecordBufferSize() {
throw new UnsupportedOperationException(); return _childProtocol.getPcmAudioRecordBufferSize();
} }
public int getPcmAudioBufferSize(int codec2ModeId) { public int getPcmAudioBufferSize(int codec2ModeId) {
@ -77,12 +77,12 @@ public class AudioFrameAggregator implements Protocol {
@Override @Override
public void sendTextMessage(TextMessage textMessage) throws IOException { public void sendTextMessage(TextMessage textMessage) throws IOException {
throw new UnsupportedOperationException(); _childProtocol.sendTextMessage(textMessage);
} }
@Override @Override
public void sendPcmAudio(String src, String dst, int codec, short[] pcmFrame) { public void sendPcmAudio(String src, String dst, int codec, short[] pcmFrame) throws IOException {
throw new UnsupportedOperationException(); _childProtocol.sendPcmAudio(src, dst, codec, pcmFrame);
} }
@Override @Override
@ -98,12 +98,12 @@ public class AudioFrameAggregator implements Protocol {
ProtocolCallback _protocolCallback = new ProtocolCallback() { ProtocolCallback _protocolCallback = new ProtocolCallback() {
@Override @Override
protected void onReceivePosition(Position position) { protected void onReceivePosition(Position position) {
throw new UnsupportedOperationException(); _parentProtocolCallback.onReceivePosition(position);
} }
@Override @Override
protected void onReceivePcmAudio(String src, String dst, int codec, short[] pcmFrame) { protected void onReceivePcmAudio(String src, String dst, int codec, short[] pcmFrame) {
throw new UnsupportedOperationException(); _parentProtocolCallback.onReceivePcmAudio(src, dst, codec, pcmFrame);
} }
@Override @Override
@ -160,7 +160,7 @@ public class AudioFrameAggregator implements Protocol {
@Override @Override
protected void onTransmitPosition(Position position) { protected void onTransmitPosition(Position position) {
throw new UnsupportedOperationException(); _parentProtocolCallback.onTransmitPosition(position);
} }
@Override @Override

Wyświetl plik

@ -47,8 +47,8 @@ public class Ax25 implements Protocol {
} }
@Override @Override
public int getPcmAudioBufferSize() { public int getPcmAudioRecordBufferSize() {
throw new UnsupportedOperationException(); return _childProtocol.getPcmAudioRecordBufferSize();
} }
@Override @Override
@ -75,12 +75,12 @@ public class Ax25 implements Protocol {
@Override @Override
public void sendTextMessage(TextMessage textMessage) throws IOException { public void sendTextMessage(TextMessage textMessage) throws IOException {
throw new UnsupportedOperationException(); _childProtocol.sendTextMessage(textMessage);
} }
@Override @Override
public void sendPcmAudio(String src, String dst, int codec, short[] pcmFrame) { public void sendPcmAudio(String src, String dst, int codec, short[] pcmFrame) throws IOException {
throw new UnsupportedOperationException(); _childProtocol.sendPcmAudio(src, dst, codec, pcmFrame);
} }
@Override @Override
@ -110,12 +110,12 @@ public class Ax25 implements Protocol {
ProtocolCallback _protocolCallback = new ProtocolCallback() { ProtocolCallback _protocolCallback = new ProtocolCallback() {
@Override @Override
protected void onReceivePosition(Position position) { protected void onReceivePosition(Position position) {
throw new UnsupportedOperationException(); _parentProtocolCallback.onReceivePosition(position);
} }
@Override @Override
protected void onReceivePcmAudio(String src, String dst, int codec, short[] pcmFrame) { protected void onReceivePcmAudio(String src, String dst, int codec, short[] pcmFrame) {
throw new UnsupportedOperationException(); _parentProtocolCallback.onReceivePcmAudio(src, dst, codec, pcmFrame);
} }
@Override @Override
@ -173,7 +173,7 @@ public class Ax25 implements Protocol {
@Override @Override
protected void onTransmitPosition(Position position) { protected void onTransmitPosition(Position position) {
throw new UnsupportedOperationException(); _parentProtocolCallback.onTransmitPosition(position);
} }
@Override @Override
@ -198,8 +198,8 @@ public class Ax25 implements Protocol {
}; };
@Override @Override
public void sendPosition(Position position) { public void sendPosition(Position position) throws IOException {
throw new UnsupportedOperationException(); _childProtocol.sendPosition(position);
} }
@Override @Override

Wyświetl plik

@ -51,7 +51,7 @@ public class Freedv implements Protocol {
} }
@Override @Override
public int getPcmAudioBufferSize() { public int getPcmAudioRecordBufferSize() {
return Codec2.freedvGetNSpeechSamples(_freedv); return Codec2.freedvGetNSpeechSamples(_freedv);
} }
@ -65,18 +65,22 @@ public class Freedv implements Protocol {
@Override @Override
public void sendCompressedAudio(String src, String dst, int codec, byte[] frame) throws IOException { public void sendCompressedAudio(String src, String dst, int codec, byte[] frame) throws IOException {
Log.w(TAG, "sendCompressedAudio() is not supported");
} }
@Override @Override
public void sendTextMessage(TextMessage textMessage) throws IOException { public void sendTextMessage(TextMessage textMessage) throws IOException {
Log.w(TAG, "sendTextMessage() is not supported");
} }
@Override @Override
public void sendData(String src, String dst, byte[] dataPacket) throws IOException { public void sendData(String src, String dst, byte[] dataPacket) throws IOException {
// TODO, send as data
} }
@Override @Override
public boolean receive() throws IOException { public boolean receive() throws IOException {
// TODO, distinguish between audio and data and call onReceiveData on parent callback
int nin = Codec2.freedvNin(_freedv); int nin = Codec2.freedvNin(_freedv);
short[] buf = new short[nin]; short[] buf = new short[nin];
int bytesRead = _transport.read(buf); int bytesRead = _transport.read(buf);
@ -96,6 +100,7 @@ public class Freedv implements Protocol {
@Override @Override
public void sendPosition(Position position) throws IOException { public void sendPosition(Position position) throws IOException {
Log.w(TAG, "sendPosition() is not supported");
} }
@Override @Override

Wyświetl plik

@ -32,7 +32,6 @@ public class Hdlc implements Protocol {
private final int _prefixSymCount; private final int _prefixSymCount;
private int _readByte = 0; private int _readByte = 0;
private int _prevHdlc = 0;
public Hdlc(SharedPreferences sharedPreferences) { public Hdlc(SharedPreferences sharedPreferences) {
double preambleLenSec = Integer.parseInt(sharedPreferences.getString(PreferenceKeys.PORTS_SOUND_MODEM_PREAMBLE, "200")) / 1000.0; double preambleLenSec = Integer.parseInt(sharedPreferences.getString(PreferenceKeys.PORTS_SOUND_MODEM_PREAMBLE, "200")) / 1000.0;
@ -50,13 +49,14 @@ public class Hdlc implements Protocol {
} }
@Override @Override
public int getPcmAudioBufferSize() { public int getPcmAudioRecordBufferSize() {
throw new UnsupportedOperationException(); Log.w(TAG, "getPcmAudioBufferSize() is not supported");
return -1;
} }
@Override @Override
public void sendPcmAudio(String src, String dst, int codec, short[] pcmFrame) throws IOException { public void sendPcmAudio(String src, String dst, int codec, short[] pcmFrame) throws IOException {
throw new UnsupportedOperationException(); Log.w(TAG, "sendPcmAudio() is not supported");
} }
@Override @Override
@ -66,7 +66,7 @@ public class Hdlc implements Protocol {
@Override @Override
public void sendTextMessage(TextMessage textMessage) throws IOException { public void sendTextMessage(TextMessage textMessage) throws IOException {
throw new UnsupportedOperationException(); Log.w(TAG, "sendTextMessage() is not supported");
} }
@Override @Override
@ -117,7 +117,6 @@ public class Hdlc implements Protocol {
} }
_currentFrameBuffer.clear(); _currentFrameBuffer.clear();
_readByte = 0; _readByte = 0;
_prevHdlc = 0;
} else { } else {
try { try {
_currentFrameBuffer.put(bit); _currentFrameBuffer.put(bit);
@ -125,7 +124,6 @@ public class Hdlc implements Protocol {
e.printStackTrace(); e.printStackTrace();
_currentFrameBuffer.clear(); _currentFrameBuffer.clear();
} }
_prevHdlc++;
} }
} }
} }
@ -134,7 +132,7 @@ public class Hdlc implements Protocol {
@Override @Override
public void sendPosition(Position position) { public void sendPosition(Position position) {
throw new UnsupportedOperationException(); Log.w(TAG, "sendPosition() is not supported");
} }
@Override @Override

Wyświetl plik

@ -14,7 +14,6 @@ import com.radio.codec2talkie.R;
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.settings.PreferenceKeys; import com.radio.codec2talkie.settings.PreferenceKeys;
import com.radio.codec2talkie.tools.DebugTools;
import com.radio.codec2talkie.transport.Transport; import com.radio.codec2talkie.transport.Transport;
import java.io.IOException; import java.io.IOException;
@ -61,12 +60,12 @@ public class Kiss implements Protocol {
GET_CMD, GET_CMD,
GET_DATA, GET_DATA,
ESCAPE ESCAPE
}; }
private enum DataType { private enum DataType {
RAW, RAW,
SIGNAL_REPORT SIGNAL_REPORT
}; }
private DataType _kissDataType = DataType.RAW; private DataType _kissDataType = DataType.RAW;
private State _kissState = State.GET_START; private State _kissState = State.GET_START;
@ -145,8 +144,9 @@ public class Kiss implements Protocol {
} }
@Override @Override
public int getPcmAudioBufferSize() { public int getPcmAudioRecordBufferSize() {
throw new UnsupportedOperationException(); Log.w(TAG, "getPcmAudioBufferSize() is not supported");
return -1;
} }
private void initializeExtended() throws IOException { private void initializeExtended() throws IOException {
@ -211,12 +211,12 @@ public class Kiss implements Protocol {
@Override @Override
public void sendTextMessage(TextMessage textMessage) throws IOException { public void sendTextMessage(TextMessage textMessage) throws IOException {
throw new UnsupportedOperationException(); Log.w(TAG, "sendTextMessage() is not supported");
} }
@Override @Override
public void sendPcmAudio(String src, String dst, int codec, short[] pcmFrame) { public void sendPcmAudio(String src, String dst, int codec, short[] pcmFrame) {
throw new UnsupportedOperationException(); Log.w(TAG, "sendPcmAudio() is not supported");
} }
@Override @Override
@ -237,7 +237,7 @@ public class Kiss implements Protocol {
@Override @Override
public void sendPosition(Position position) { public void sendPosition(Position position) {
throw new UnsupportedOperationException(); Log.w(TAG, "sendPosition() is not supported");
} }
@Override @Override

Wyświetl plik

@ -12,7 +12,7 @@ public interface Protocol {
// init // init
void initialize(Transport transport, Context context, ProtocolCallback protocolCallback) throws IOException; void initialize(Transport transport, Context context, ProtocolCallback protocolCallback) throws IOException;
// audio // audio
int getPcmAudioBufferSize(); int getPcmAudioRecordBufferSize();
void sendPcmAudio(String src, String dst, int codec, short[] pcmFrame) throws IOException; void sendPcmAudio(String src, String dst, int codec, short[] pcmFrame) throws IOException;
void sendCompressedAudio(String src, String dst, int codec, byte[] frame) throws IOException; void sendCompressedAudio(String src, String dst, int codec, byte[] frame) throws IOException;
// messaging // messaging

Wyświetl plik

@ -1,6 +1,7 @@
package com.radio.codec2talkie.protocol; package com.radio.codec2talkie.protocol;
import android.content.Context; import android.content.Context;
import android.util.Log;
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;
@ -10,6 +11,7 @@ import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
public class Raw implements Protocol { public class Raw implements Protocol {
private static final String TAG = Raw.class.getSimpleName();
private static final int RX_BUFFER_SIZE = 8192; private static final int RX_BUFFER_SIZE = 8192;
@ -29,8 +31,9 @@ public class Raw implements Protocol {
} }
@Override @Override
public int getPcmAudioBufferSize() { public int getPcmAudioRecordBufferSize() {
throw new UnsupportedOperationException(); Log.w(TAG, "getPcmAudioBufferSize() is not supported");
return -1;
} }
@Override @Override
@ -40,12 +43,12 @@ public class Raw implements Protocol {
@Override @Override
public void sendTextMessage(TextMessage textMessage) throws IOException { public void sendTextMessage(TextMessage textMessage) throws IOException {
throw new UnsupportedOperationException(); Log.w(TAG, "sendTextMessage() is not supported");
} }
@Override @Override
public void sendPcmAudio(String src, String dst, int codec, short[] pcmFrame) { public void sendPcmAudio(String src, String dst, int codec, short[] pcmFrame) {
throw new UnsupportedOperationException(); Log.w(TAG, "sendPcmAudio() is not supported");
} }
@Override @Override
@ -65,7 +68,7 @@ public class Raw implements Protocol {
@Override @Override
public void sendPosition(Position position) { public void sendPosition(Position position) {
throw new UnsupportedOperationException(); Log.w(TAG, "sendPosition() is not supported");
} }
@Override @Override

Wyświetl plik

@ -54,8 +54,8 @@ public class Recorder implements Protocol {
} }
@Override @Override
public int getPcmAudioBufferSize() { public int getPcmAudioRecordBufferSize() {
throw new UnsupportedOperationException(); return _childProtocol.getPcmAudioRecordBufferSize();
} }
@Override @Override
@ -67,12 +67,12 @@ public class Recorder implements Protocol {
@Override @Override
public void sendTextMessage(TextMessage textMessage) throws IOException { public void sendTextMessage(TextMessage textMessage) throws IOException {
throw new UnsupportedOperationException(); _childProtocol.sendTextMessage(textMessage);
} }
@Override @Override
public void sendPcmAudio(String src, String dst, int codec, short[] pcmFrame) { public void sendPcmAudio(String src, String dst, int codec, short[] pcmFrame) throws IOException {
throw new UnsupportedOperationException(); _childProtocol.sendPcmAudio(src, dst, codec, pcmFrame);
} }
@Override @Override
@ -88,12 +88,12 @@ public class Recorder implements Protocol {
ProtocolCallback _protocolCallback = new ProtocolCallback() { ProtocolCallback _protocolCallback = new ProtocolCallback() {
@Override @Override
protected void onReceivePosition(Position position) { protected void onReceivePosition(Position position) {
throw new UnsupportedOperationException(); _parentProtocolCallback.onReceivePosition(position);
} }
@Override @Override
protected void onReceivePcmAudio(String src, String dst, int codec, short[] pcmFrame) { protected void onReceivePcmAudio(String src, String dst, int codec, short[] pcmFrame) {
throw new UnsupportedOperationException(); _parentProtocolCallback.onReceivePcmAudio(src, dst, codec, pcmFrame);
} }
@Override @Override
@ -140,7 +140,7 @@ public class Recorder implements Protocol {
@Override @Override
protected void onTransmitPosition(Position position) { protected void onTransmitPosition(Position position) {
throw new UnsupportedOperationException(); _parentProtocolCallback.onTransmitPosition(position);
} }
@Override @Override
@ -165,8 +165,8 @@ public class Recorder implements Protocol {
}; };
@Override @Override
public void sendPosition(Position position) { public void sendPosition(Position position) throws IOException {
throw new UnsupportedOperationException(); _childProtocol.sendPosition(position);
} }
@Override @Override

Wyświetl plik

@ -46,8 +46,8 @@ public class Scrambler implements Protocol {
} }
@Override @Override
public int getPcmAudioBufferSize() { public int getPcmAudioRecordBufferSize() {
throw new UnsupportedOperationException(); return _childProtocol.getPcmAudioRecordBufferSize();
} }
@Override @Override
@ -62,12 +62,12 @@ public class Scrambler implements Protocol {
@Override @Override
public void sendTextMessage(TextMessage textMessage) throws IOException { public void sendTextMessage(TextMessage textMessage) throws IOException {
throw new UnsupportedOperationException(); _childProtocol.sendTextMessage(textMessage);
} }
@Override @Override
public void sendPcmAudio(String src, String dst, int codec, short[] pcmFrame) { public void sendPcmAudio(String src, String dst, int codec, short[] pcmFrame) throws IOException {
throw new UnsupportedOperationException(); _childProtocol.sendPcmAudio(src, dst, codec, pcmFrame);
} }
@Override @Override
@ -88,12 +88,12 @@ public class Scrambler implements Protocol {
ProtocolCallback _protocolCallback = new ProtocolCallback() { ProtocolCallback _protocolCallback = new ProtocolCallback() {
@Override @Override
protected void onReceivePosition(Position position) { protected void onReceivePosition(Position position) {
throw new UnsupportedOperationException(); _parentProtocolCallback.onReceivePosition(position);
} }
@Override @Override
protected void onReceivePcmAudio(String src, String dst, int codec, short[] pcmFrame) { protected void onReceivePcmAudio(String src, String dst, int codec, short[] pcmFrame) {
throw new UnsupportedOperationException(); _parentProtocolCallback.onReceivePcmAudio(src, dst, codec, pcmFrame);
} }
@Override @Override
@ -149,7 +149,7 @@ public class Scrambler implements Protocol {
@Override @Override
protected void onTransmitPosition(Position position) { protected void onTransmitPosition(Position position) {
throw new UnsupportedOperationException(); _parentProtocolCallback.onTransmitPosition(position);
} }
@Override @Override
@ -174,8 +174,8 @@ public class Scrambler implements Protocol {
}; };
@Override @Override
public void sendPosition(Position position) { public void sendPosition(Position position) throws IOException {
throw new UnsupportedOperationException(); _childProtocol.sendPosition(position);
} }
@Override @Override