Skip to content

Commit

Permalink
Display speed based on modulation
Browse files Browse the repository at this point in the history
  • Loading branch information
sh123 committed Nov 17, 2023
1 parent 3346003 commit 9886bcc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public static String getFreedvModeAsText(SharedPreferences sharedPreferences) {
return null;
}

public static String getModulationAsText(SharedPreferences sharedPreferences) {
int modulation = Integer.parseInt(sharedPreferences.getString(PreferenceKeys.KISS_EXTENSIONS_RADIO_MOD, "0"));
return modulation == RadioTools.ModulationTypeLora ? "LoRa" : "FSK";
}

public static String getSpeedStatusText(String codec2ModeName, SharedPreferences sharedPreferences) {

// use freedv mode text instead if it is active
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,37 @@
import com.radio.codec2talkie.settings.SettingsWrapper;

public class RadioTools {

public static final int ModulationTypeLora = 0;
public static final int ModulationTypeFsk = 1;

public static int calculateLoraSpeedBps(int bw, int sf, int cr) {
return (int)(sf * (4.0 / cr) / (Math.pow(2.0, sf) / bw));
}

public static int getRadioSpeed(SharedPreferences sharedPreferences) {
int resultBps = 0;
int maxSpeedBps = 128000;
try {
if (!SettingsWrapper.isSoundModemEnabled(sharedPreferences) && SettingsWrapper.isKissExtensionEnabled(sharedPreferences)) {
int bw = Integer.parseInt(sharedPreferences.getString(PreferenceKeys.KISS_EXTENSIONS_RADIO_BANDWIDTH, "125000"));
int sf = Integer.parseInt(sharedPreferences.getString(PreferenceKeys.KISS_EXTENSIONS_RADIO_SF, "7"));
int cr = Integer.parseInt(sharedPreferences.getString(PreferenceKeys.KISS_EXTENSIONS_RADIO_CR, "5"));
resultBps = RadioTools.calculateLoraSpeedBps(bw, sf, cr);
int modulation = Integer.parseInt(sharedPreferences.getString(PreferenceKeys.KISS_EXTENSIONS_RADIO_MOD, "0"));
if (SettingsWrapper.isSoundModemEnabled(sharedPreferences)) {
return SettingsWrapper.getFskSpeed(sharedPreferences);
}
if (modulation == ModulationTypeLora) {
int resultBps = 0;
int maxSpeedBps = 128000;
try {
if (!SettingsWrapper.isSoundModemEnabled(sharedPreferences) && SettingsWrapper.isKissExtensionEnabled(sharedPreferences)) {
int bw = Integer.parseInt(sharedPreferences.getString(PreferenceKeys.KISS_EXTENSIONS_RADIO_BANDWIDTH, "125000"));
int sf = Integer.parseInt(sharedPreferences.getString(PreferenceKeys.KISS_EXTENSIONS_RADIO_SF, "7"));
int cr = Integer.parseInt(sharedPreferences.getString(PreferenceKeys.KISS_EXTENSIONS_RADIO_CR, "5"));
resultBps = RadioTools.calculateLoraSpeedBps(bw, sf, cr);
}
} catch (NumberFormatException | ArithmeticException e) {
e.printStackTrace();
}
} catch (NumberFormatException|ArithmeticException e) {
e.printStackTrace();
return (resultBps > 0 && resultBps <= maxSpeedBps) ? resultBps : 0;
} else if (modulation == ModulationTypeFsk){
return Integer.parseInt(sharedPreferences.getString(PreferenceKeys.KISS_EXTENSIONS_RADIO_FSK_BIT_RATE, "4.8"));
}
return (resultBps > 0 && resultBps <= maxSpeedBps) ? resultBps : 0;
return 0;
}

public static double calculateLoraSensitivity(SharedPreferences sharedPreferences) {
Expand Down

0 comments on commit 9886bcc

Please sign in to comment.