kopia lustrzana https://github.com/sh123/codec2_talkie
Refactoring
rodzic
27ee7e4e3f
commit
09bc353600
|
@ -16,11 +16,12 @@ public enum AppMessage {
|
|||
EV_STARTED_TRACKING(11),
|
||||
EV_STOPPED_TRACKING(12),
|
||||
// commands
|
||||
CMD_SEND_LOCATION(13),
|
||||
CMD_SEND_LOCATION_TO_TNC(13),
|
||||
CMD_PROCESS(14),
|
||||
CMD_QUIT(15),
|
||||
CMD_START_TRACKING(16),
|
||||
CMD_STOP_TRACKING(17);
|
||||
CMD_STOP_TRACKING(17),
|
||||
CMD_SEND_SINGLE_TRACKING(18);
|
||||
|
||||
private final int _value;
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ public class AppService extends Service {
|
|||
|
||||
public void sendPosition() {
|
||||
Message msg = Message.obtain();
|
||||
msg.what = AppMessage.CMD_SEND_LOCATION.toInt();
|
||||
msg.what = AppMessage.CMD_SEND_SINGLE_TRACKING.toInt();
|
||||
_onProcess.sendMessage(msg);
|
||||
}
|
||||
|
||||
|
@ -146,7 +146,7 @@ public class AppService extends Service {
|
|||
|
||||
String trackerName = _sharedPreferences.getString(PreferenceKeys.APRS_LOCATION_SOURCE, "manual");
|
||||
_tracker = TrackerFactory.create(trackerName);
|
||||
_tracker.initialize(getApplicationContext(), position -> { if (_appWorker != null) _appWorker.sendPosition(position); });
|
||||
_tracker.initialize(getApplicationContext(), position -> { if (_appWorker != null) _appWorker.sendPositionToTnc(position); });
|
||||
|
||||
transportType = (TransportFactory.TransportType) extras.get("transportType");
|
||||
startAppWorker(transportType);
|
||||
|
@ -206,7 +206,7 @@ public class AppService extends Service {
|
|||
case EV_LISTENING:
|
||||
hideVoiceNotification();
|
||||
break;
|
||||
case CMD_SEND_LOCATION:
|
||||
case CMD_SEND_SINGLE_TRACKING:
|
||||
_tracker.sendPosition();
|
||||
break;
|
||||
case CMD_START_TRACKING:
|
||||
|
|
|
@ -21,16 +21,13 @@ import java.util.TimerTask;
|
|||
|
||||
import com.radio.codec2talkie.R;
|
||||
import com.radio.codec2talkie.log.LogItem;
|
||||
import com.radio.codec2talkie.log.LogItemDatabase;
|
||||
import com.radio.codec2talkie.log.LogItemRepository;
|
||||
import com.radio.codec2talkie.protocol.ProtocolCallback;
|
||||
import com.radio.codec2talkie.protocol.Protocol;
|
||||
import com.radio.codec2talkie.protocol.ProtocolFactory;
|
||||
import com.radio.codec2talkie.protocol.aprs.AprsCallsign;
|
||||
import com.radio.codec2talkie.protocol.position.Position;
|
||||
import com.radio.codec2talkie.settings.PreferenceKeys;
|
||||
import com.radio.codec2talkie.tools.AudioTools;
|
||||
import com.radio.codec2talkie.tools.DebugTools;
|
||||
import com.radio.codec2talkie.transport.Transport;
|
||||
import com.radio.codec2talkie.transport.TransportFactory;
|
||||
|
||||
|
@ -40,12 +37,12 @@ public class AppWorker extends Thread {
|
|||
|
||||
private static final int AUDIO_MIN_LEVEL = -70;
|
||||
private static final int AUDIO_MAX_LEVEL = 0;
|
||||
private final int AUDIO_SAMPLE_SIZE = 8000;
|
||||
private static final int AUDIO_SAMPLE_SIZE = 8000;
|
||||
|
||||
private final int PROCESS_INTERVAL_MS = 20;
|
||||
private final int LISTEN_AFTER_MS = 1500;
|
||||
private static final int PROCESS_INTERVAL_MS = 20;
|
||||
private static final int LISTEN_AFTER_MS = 1500;
|
||||
|
||||
private boolean _needsRecording = false;
|
||||
private boolean _needTransmission = false;
|
||||
private AppMessage _currentStatus = AppMessage.EV_DISCONNECTED;
|
||||
|
||||
private final Protocol _protocol;
|
||||
|
@ -150,11 +147,11 @@ public class AppWorker extends Thread {
|
|||
}
|
||||
|
||||
public void startReceive() {
|
||||
_needsRecording = false;
|
||||
_needTransmission = false;
|
||||
}
|
||||
|
||||
public void startTransmit() {
|
||||
_needsRecording = true;
|
||||
_needTransmission = true;
|
||||
}
|
||||
|
||||
public void stopRunning() {
|
||||
|
@ -165,10 +162,10 @@ public class AppWorker extends Thread {
|
|||
_onMessageReceived.sendMessage(msg);
|
||||
}
|
||||
|
||||
public void sendPosition(Position position) {
|
||||
public void sendPositionToTnc(Position position) {
|
||||
if (_currentStatus == AppMessage.EV_DISCONNECTED) return;
|
||||
Message msg = new Message();
|
||||
msg.what = AppMessage.CMD_SEND_LOCATION.toInt();
|
||||
msg.what = AppMessage.CMD_SEND_LOCATION_TO_TNC.toInt();
|
||||
msg.obj = position;
|
||||
_onMessageReceived.sendMessage(msg);
|
||||
}
|
||||
|
@ -341,13 +338,13 @@ public class AppWorker extends Thread {
|
|||
|
||||
private void processRecordPlaybackToggle() throws IOException {
|
||||
// playback -> recording
|
||||
if (_needsRecording && _systemAudioRecorder.getRecordingState() != AudioRecord.RECORDSTATE_RECORDING) {
|
||||
if (_needTransmission && _systemAudioRecorder.getRecordingState() != AudioRecord.RECORDSTATE_RECORDING) {
|
||||
_systemAudioPlayer.stop();
|
||||
_systemAudioRecorder.startRecording();
|
||||
sendRxAudioLevelUpdate(null);
|
||||
}
|
||||
// recording -> playback
|
||||
if (!_needsRecording && _systemAudioRecorder.getRecordingState() == AudioRecord.RECORDSTATE_RECORDING) {
|
||||
if (!_needTransmission && _systemAudioRecorder.getRecordingState() == AudioRecord.RECORDSTATE_RECORDING) {
|
||||
_protocol.flush();
|
||||
_systemAudioRecorder.stop();
|
||||
_systemAudioPlayer.play();
|
||||
|
@ -398,7 +395,7 @@ public class AppWorker extends Thread {
|
|||
Looper.myLooper().quitSafely();
|
||||
}
|
||||
|
||||
private void onProcessorIncomingMessage(Message msg) {
|
||||
private void onWorkerIncomingMessage(Message msg) {
|
||||
switch (AppMessage.values()[msg.what]) {
|
||||
case CMD_PROCESS:
|
||||
try {
|
||||
|
@ -411,7 +408,7 @@ public class AppWorker extends Thread {
|
|||
case CMD_QUIT:
|
||||
quitProcessing();
|
||||
break;
|
||||
case CMD_SEND_LOCATION:
|
||||
case CMD_SEND_LOCATION_TO_TNC:
|
||||
try {
|
||||
_protocol.sendPosition((Position)msg.obj);
|
||||
} catch (IOException e) {
|
||||
|
@ -424,11 +421,11 @@ public class AppWorker extends Thread {
|
|||
}
|
||||
}
|
||||
|
||||
private void startProcessorMessageHandler() {
|
||||
private void startWorkerMessageHandler() {
|
||||
_onMessageReceived = new Handler(Looper.myLooper()) {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
onProcessorIncomingMessage(msg);
|
||||
onWorkerIncomingMessage(msg);
|
||||
}
|
||||
};
|
||||
_processPeriodicTimer.schedule(new TimerTask() {
|
||||
|
@ -452,7 +449,7 @@ public class AppWorker extends Thread {
|
|||
|
||||
try {
|
||||
_protocol.initialize(_transport, _context, _protocolCallback);
|
||||
startProcessorMessageHandler();
|
||||
startWorkerMessageHandler();
|
||||
Looper.loop();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -24,35 +24,35 @@ public class Kiss implements Protocol {
|
|||
|
||||
private static final String TAG = Kiss.class.getSimpleName();
|
||||
|
||||
private final int TRANSPORT_OUTPUT_BUFFER_SIZE = 1024;
|
||||
private final int TRANSPORT_INPUT_BUFFER_SIZE = 1024;
|
||||
private final int FRAME_OUTPUT_BUFFER_SIZE = 1024;
|
||||
private final int KISS_CMD_BUFFER_SIZE = 128;
|
||||
private static final int TRANSPORT_OUTPUT_BUFFER_SIZE = 1024;
|
||||
private static final int TRANSPORT_INPUT_BUFFER_SIZE = 1024;
|
||||
private static final int FRAME_OUTPUT_BUFFER_SIZE = 1024;
|
||||
private static final int KISS_CMD_BUFFER_SIZE = 128;
|
||||
|
||||
private final int KISS_RADIO_CONTROL_COMMAND_SIZE = 17;
|
||||
private static final int KISS_RADIO_CONTROL_COMMAND_SIZE = 17;
|
||||
|
||||
private final byte KISS_FEND = (byte)0xc0;
|
||||
private final byte KISS_FESC = (byte)0xdb;
|
||||
private final byte KISS_TFEND = (byte)0xdc;
|
||||
private final byte KISS_TFESC = (byte)0xdd;
|
||||
private static final byte KISS_FEND = (byte)0xc0;
|
||||
private static final byte KISS_FESC = (byte)0xdb;
|
||||
private static final byte KISS_TFEND = (byte)0xdc;
|
||||
private static final byte KISS_TFESC = (byte)0xdd;
|
||||
|
||||
// only port 0 is supported
|
||||
private final byte KISS_CMD_DATA = (byte)0x00;
|
||||
private final byte KISS_CMD_TX_DELAY = (byte)0x01;
|
||||
private final byte KISS_CMD_P = (byte)0x02;
|
||||
private final byte KISS_CMD_SLOT_TIME = (byte)0x03;
|
||||
private final byte KISS_CMD_TX_TAIL = (byte)0x04;
|
||||
private final byte KISS_CMD_SET_HARDWARE = (byte)0x06;
|
||||
private final byte KISS_CMD_SIGNAL_REPORT = (byte)0x07;
|
||||
private final byte KISS_CMD_REBOOT = (byte)0x08;
|
||||
private final byte KISS_CMD_NOCMD = (byte)0x80;
|
||||
private static final byte KISS_CMD_DATA = (byte)0x00;
|
||||
private static final byte KISS_CMD_TX_DELAY = (byte)0x01;
|
||||
private static final byte KISS_CMD_P = (byte)0x02;
|
||||
private static final byte KISS_CMD_SLOT_TIME = (byte)0x03;
|
||||
private static final byte KISS_CMD_TX_TAIL = (byte)0x04;
|
||||
private static final byte KISS_CMD_SET_HARDWARE = (byte)0x06;
|
||||
private static final byte KISS_CMD_SIGNAL_REPORT = (byte)0x07;
|
||||
private static final byte KISS_CMD_REBOOT = (byte)0x08;
|
||||
private static final byte KISS_CMD_NOCMD = (byte)0x80;
|
||||
|
||||
private final byte CSMA_PERSISTENCE = (byte)0xff;
|
||||
private final byte CSMA_SLOT_TIME = (byte)0x00;
|
||||
private final byte TX_DELAY_10MS_UNITS = (byte)(250 / 10);
|
||||
private final byte TX_TAIL_10MS_UNITS = (byte)(500 / 10);
|
||||
private static final byte CSMA_PERSISTENCE = (byte)0xff;
|
||||
private static final byte CSMA_SLOT_TIME = (byte)0x00;
|
||||
private static final byte TX_DELAY_10MS_UNITS = (byte)(250 / 10);
|
||||
private static final byte TX_TAIL_10MS_UNITS = (byte)(500 / 10);
|
||||
|
||||
private final int SIGNAL_LEVEL_EVENT_SIZE = 4;
|
||||
private static final int SIGNAL_LEVEL_EVENT_SIZE = 4;
|
||||
|
||||
private enum State {
|
||||
GET_START,
|
||||
|
|
|
@ -8,8 +8,8 @@ import java.util.TimerTask;
|
|||
|
||||
public class KissBuffered extends Kiss {
|
||||
|
||||
private final int BUFFER_SIZE = 3200 * 60 * 10; // 10 min at 3200 bps
|
||||
private final int GAP_TO_PLAY_MS = 1000;
|
||||
private static final int BUFFER_SIZE = 3200 * 60 * 10; // 10 min at 3200 bps
|
||||
private static final int GAP_TO_PLAY_MS = 1000;
|
||||
|
||||
private final ByteBuffer _buffer;
|
||||
|
||||
|
|
|
@ -9,9 +9,8 @@ import java.util.TimerTask;
|
|||
|
||||
public class KissParrot extends Kiss {
|
||||
|
||||
private final int BUFFER_SIZE = 3200 * 60 * 5; // 5 min at 3200 bps
|
||||
|
||||
private final int PLAYBACK_DELAY_MS = 1000;
|
||||
private static final int BUFFER_SIZE = 3200 * 60 * 5; // 5 min at 3200 bps
|
||||
private static final int PLAYBACK_DELAY_MS = 1000;
|
||||
|
||||
private final ByteBuffer _buffer;
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import java.util.Arrays;
|
|||
|
||||
public class Raw implements Protocol {
|
||||
|
||||
private final int RX_BUFFER_SIZE = 8192;
|
||||
private static final int RX_BUFFER_SIZE = 8192;
|
||||
|
||||
protected Transport _transport;
|
||||
protected final byte[] _rxDataBuffer;
|
||||
|
|
|
@ -23,7 +23,7 @@ public class Recorder implements Protocol {
|
|||
|
||||
private static final String TAG = MainActivity.class.getSimpleName();
|
||||
|
||||
private final int ROTATION_DELAY_MS = 5000;
|
||||
private static final int ROTATION_DELAY_MS = 5000;
|
||||
|
||||
private File _storage;
|
||||
private FileOutputStream _activeStream;
|
||||
|
|
Ładowanie…
Reference in New Issue