2021-01-28 10:03:30 +00:00
|
|
|
package com.radio.codec2talkie.protocol;
|
|
|
|
|
2021-10-12 13:53:01 +00:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
|
2023-07-02 08:12:53 +00:00
|
|
|
import androidx.annotation.NonNull;
|
2021-10-12 13:53:01 +00:00
|
|
|
import androidx.preference.PreferenceManager;
|
|
|
|
|
2022-08-11 13:40:06 +00:00
|
|
|
import com.radio.codec2talkie.settings.SettingsWrapper;
|
2021-10-12 13:53:01 +00:00
|
|
|
|
2021-01-28 10:03:30 +00:00
|
|
|
public class ProtocolFactory {
|
|
|
|
|
|
|
|
public enum ProtocolType {
|
2021-01-31 13:08:07 +00:00
|
|
|
RAW("RAW"),
|
2022-07-31 11:05:35 +00:00
|
|
|
HDLC("HDLC"),
|
2021-01-31 13:08:07 +00:00
|
|
|
KISS("KISS"),
|
2021-10-19 18:07:49 +00:00
|
|
|
KISS_BUFFERED("KISS BUF"),
|
2022-08-11 09:01:02 +00:00
|
|
|
KISS_PARROT("KISS RPT"),
|
|
|
|
FREEDV("FREEDV");
|
2021-01-31 13:08:07 +00:00
|
|
|
|
2021-10-06 18:11:59 +00:00
|
|
|
private final String _name;
|
2021-01-31 13:08:07 +00:00
|
|
|
|
2021-02-06 14:34:30 +00:00
|
|
|
ProtocolType(String name) {
|
2021-01-31 13:08:07 +00:00
|
|
|
_name = name;
|
|
|
|
}
|
|
|
|
|
2023-07-02 08:12:53 +00:00
|
|
|
@NonNull
|
2021-01-31 13:08:07 +00:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return _name;
|
|
|
|
}
|
2022-06-26 14:58:22 +00:00
|
|
|
}
|
2021-01-28 10:03:30 +00:00
|
|
|
|
2022-07-04 19:18:49 +00:00
|
|
|
public static ProtocolType getBaseProtocolType(Context context) {
|
|
|
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
|
|
|
|
ProtocolFactory.ProtocolType protocolType;
|
|
|
|
|
2022-08-10 17:46:13 +00:00
|
|
|
// Use HDLC instead of KISS for the sound modem as we are the modem
|
2022-08-11 13:40:06 +00:00
|
|
|
if (SettingsWrapper.isSoundModemEnabled(sharedPreferences)) {
|
|
|
|
if (SettingsWrapper.isFreeDvSoundModemModulation(sharedPreferences)) {
|
2022-08-11 09:01:02 +00:00
|
|
|
protocolType = ProtocolType.FREEDV;
|
|
|
|
} else {
|
|
|
|
protocolType = ProtocolFactory.ProtocolType.HDLC;
|
|
|
|
}
|
2022-08-11 13:40:06 +00:00
|
|
|
} else if (SettingsWrapper.isKissProtocolEnabled(sharedPreferences)) {
|
|
|
|
if (SettingsWrapper.isKissParrotEnabled(sharedPreferences)) {
|
2022-07-04 19:18:49 +00:00
|
|
|
protocolType = ProtocolFactory.ProtocolType.KISS_PARROT;
|
|
|
|
}
|
2022-08-11 13:40:06 +00:00
|
|
|
else if (SettingsWrapper.isKissBufferedModeEnabled(sharedPreferences)) {
|
2022-07-04 19:18:49 +00:00
|
|
|
protocolType = ProtocolFactory.ProtocolType.KISS_BUFFERED;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
protocolType = ProtocolFactory.ProtocolType.KISS;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
protocolType = ProtocolFactory.ProtocolType.RAW;
|
|
|
|
}
|
|
|
|
return protocolType;
|
|
|
|
}
|
|
|
|
|
2023-12-09 11:33:32 +00:00
|
|
|
public static Protocol create(Context context) {
|
2021-10-12 13:53:01 +00:00
|
|
|
|
|
|
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
|
2022-07-04 19:18:49 +00:00
|
|
|
ProtocolType protocolType = getBaseProtocolType(context);
|
|
|
|
|
2022-08-11 13:40:06 +00:00
|
|
|
boolean recordingEnabled = SettingsWrapper.isCodec2RecorderEnabled(sharedPreferences);
|
|
|
|
boolean scramblingEnabled = SettingsWrapper.isKissScramblerEnabled(sharedPreferences);
|
|
|
|
String scramblingKey = SettingsWrapper.getKissScramblerKey(sharedPreferences);
|
|
|
|
boolean aprsEnabled = SettingsWrapper.isAprsEnabled(sharedPreferences);
|
2022-08-19 17:34:39 +00:00
|
|
|
boolean aprsIsEnabled = SettingsWrapper.isAprsIsEnabled(sharedPreferences);
|
2022-08-14 12:57:05 +00:00
|
|
|
boolean freedvEnabled = SettingsWrapper.isFreeDvSoundModemModulation(sharedPreferences);
|
2023-12-09 17:43:55 +00:00
|
|
|
boolean codec2Enabled = SettingsWrapper.isCodec2Enabled(sharedPreferences);
|
2021-10-12 13:53:01 +00:00
|
|
|
|
2022-08-14 12:57:05 +00:00
|
|
|
// "root" protocol
|
2021-10-06 18:11:59 +00:00
|
|
|
Protocol proto;
|
2021-01-28 10:03:30 +00:00
|
|
|
switch (protocolType) {
|
|
|
|
case KISS:
|
2021-10-06 18:11:59 +00:00
|
|
|
proto = new Kiss();
|
|
|
|
break;
|
2021-01-30 19:32:25 +00:00
|
|
|
case KISS_BUFFERED:
|
2021-10-06 18:11:59 +00:00
|
|
|
proto = new KissBuffered();
|
|
|
|
break;
|
2021-01-28 10:03:30 +00:00
|
|
|
case KISS_PARROT:
|
2021-10-06 18:11:59 +00:00
|
|
|
proto = new KissParrot();
|
|
|
|
break;
|
2022-07-31 11:05:35 +00:00
|
|
|
case HDLC:
|
2022-07-31 12:01:27 +00:00
|
|
|
proto = new Hdlc(sharedPreferences);
|
2022-07-31 11:05:35 +00:00
|
|
|
break;
|
2022-08-11 09:01:02 +00:00
|
|
|
case FREEDV:
|
2022-08-14 12:57:05 +00:00
|
|
|
proto = new Freedv();
|
|
|
|
break;
|
2021-01-28 10:03:30 +00:00
|
|
|
case RAW:
|
|
|
|
default:
|
2021-10-06 18:11:59 +00:00
|
|
|
proto = new Raw();
|
|
|
|
break;
|
2021-01-28 10:03:30 +00:00
|
|
|
}
|
2021-10-06 18:11:59 +00:00
|
|
|
|
2022-07-29 14:54:24 +00:00
|
|
|
if (scramblingEnabled) {
|
|
|
|
proto = new Scrambler(proto, scramblingKey);
|
|
|
|
}
|
|
|
|
if (aprsEnabled) {
|
|
|
|
proto = new Ax25(proto);
|
|
|
|
}
|
2022-08-14 12:57:05 +00:00
|
|
|
if (!freedvEnabled) {
|
2023-12-09 17:43:55 +00:00
|
|
|
if (codec2Enabled) {
|
|
|
|
if (recordingEnabled) {
|
|
|
|
proto = new Recorder(proto, sharedPreferences);
|
|
|
|
}
|
2021-10-06 18:11:59 +00:00
|
|
|
|
2023-12-09 17:43:55 +00:00
|
|
|
proto = new AudioCodec2FrameAggregator(proto, sharedPreferences);
|
|
|
|
proto = new AudioCodec2(proto, sharedPreferences);
|
|
|
|
} else {
|
|
|
|
proto = new AudioOpus(proto);
|
|
|
|
}
|
2022-08-14 12:57:05 +00:00
|
|
|
}
|
2022-06-29 19:23:02 +00:00
|
|
|
|
2022-08-11 09:01:02 +00:00
|
|
|
if (aprsEnabled) {
|
2022-08-19 17:34:39 +00:00
|
|
|
if (aprsIsEnabled) {
|
|
|
|
proto = new AprsIs(proto);
|
|
|
|
}
|
2022-06-29 19:23:02 +00:00
|
|
|
proto = new Aprs(proto);
|
|
|
|
}
|
|
|
|
return proto;
|
2021-01-28 10:03:30 +00:00
|
|
|
}
|
|
|
|
}
|