Skip to content

Commit 4fecff5

Browse files
committed
PR feedback
1 parent 482a6ce commit 4fecff5

File tree

7 files changed

+172
-53
lines changed

7 files changed

+172
-53
lines changed

android-src/KV4PHT/app/src/main/java/com/vagell/kv4pht/data/AppSetting.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public class AppSetting {
4444
public static final String SETTING_APRS_POSITION_ACCURACY = "aprsPositionAccuracy";
4545
public static final String SETTING_APRS_BEACON_POSITION = "aprsBeaconPosition";
4646
public static final String SETTING_APRS_TX_ENCODER = "aprsTxEncoder";
47+
public static final String SETTING_AX25_ENCODER = "ax25Encoder";
48+
public static final String SETTING_AX25_DECODER = "ax25Decoder";
4749
public static final String SETTING_CALLSIGN = "callsign";
4850
public static final String SETTING_STICKY_PTT = "stickyPTT";
4951

android-src/KV4PHT/app/src/main/java/com/vagell/kv4pht/radio/RadioAudioService.java

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ public enum RadioModuleType {UNKNOWN, VHF, UHF}
242242
private MicGainBoost micGainBoost = MicGainBoost.NONE;
243243
@Setter
244244
private @NonNull String bandwidth = "25kHz";
245-
private @NonNull AprsTxEncoder aprsTxEncoder = AprsTxEncoder.ANDROID;
245+
private @NonNull AprsTxEncoder aprsTxEncoder = AprsTxEncoder.SOFTWARE;
246+
private Ax25Decoder ax25Decoder = Ax25Decoder.BOTH;
246247
private final Map<String, Long> packetActionSeenMs = new ConcurrentHashMap<>();
247248

248249
// === Android Components ===
@@ -267,14 +268,30 @@ public enum RadioModuleType {UNKNOWN, VHF, UHF}
267268
public static final int DECODER_SOURCE_ESP32 = 1 << 1;
268269

269270
public enum AprsTxEncoder {
270-
ANDROID,
271-
ESP32;
271+
SOFTWARE,
272+
FIRMWARE;
272273

273274
public static AprsTxEncoder fromSetting(String value) {
274-
if ("ESP32".equalsIgnoreCase(value)) {
275-
return ESP32;
275+
if ("Firmware".equalsIgnoreCase(value)) {
276+
return FIRMWARE;
276277
}
277-
return ANDROID;
278+
return SOFTWARE;
279+
}
280+
}
281+
282+
public enum Ax25Decoder {
283+
BOTH,
284+
SOFTWARE,
285+
FIRMWARE;
286+
287+
public static Ax25Decoder fromSetting(String value) {
288+
if ("Software".equalsIgnoreCase(value)) {
289+
return SOFTWARE;
290+
}
291+
if ("Firmware".equalsIgnoreCase(value)) {
292+
return FIRMWARE;
293+
}
294+
return BOTH;
278295
}
279296
}
280297

@@ -345,8 +362,12 @@ public void setAprsTxEncoder(@NonNull String encoder) {
345362
this.aprsTxEncoder = AprsTxEncoder.fromSetting(encoder);
346363
}
347364

365+
public void setAx25Decoder(@NonNull Ax25Decoder decoder) {
366+
this.ax25Decoder = decoder;
367+
}
368+
348369
public int getOutgoingAprsSourceIndicator() {
349-
return aprsTxEncoder == AprsTxEncoder.ESP32 ? DECODER_SOURCE_ESP32 : DECODER_SOURCE_ANDROID;
370+
return aprsTxEncoder == AprsTxEncoder.FIRMWARE ? DECODER_SOURCE_ESP32 : DECODER_SOURCE_ANDROID;
350371
}
351372

352373
public void setMinRadioFreq(float newMinFreq) {
@@ -1272,7 +1293,9 @@ private void handleEsp32Ax25Packet(final byte[] param, final Integer len) {
12721293
return;
12731294
}
12741295
byte[] packet = java.util.Arrays.copyOfRange(param, 1, len);
1275-
handleAx25Packet(packet, DECODER_SOURCE_ESP32);
1296+
if (shouldAcceptDecodedPacket(DECODER_SOURCE_ESP32, packet)) {
1297+
handleAx25Packet(packet, DECODER_SOURCE_ESP32);
1298+
}
12761299
}
12771300

12781301
private void handlePhysicalPttUp() {
@@ -1353,9 +1376,24 @@ private void ensureAudioPlaying() {
13531376

13541377
@Override
13551378
public void handlePacket(byte[] packet) {
1356-
handleAx25Packet(packet, DECODER_SOURCE_ANDROID);
1379+
if (shouldAcceptDecodedPacket(DECODER_SOURCE_ANDROID, packet)) {
1380+
handleAx25Packet(packet, DECODER_SOURCE_ANDROID);
1381+
}
1382+
}
1383+
1384+
private boolean shouldAcceptDecodedPacket(int source, byte[] packet) {
1385+
switch (ax25Decoder) {
1386+
case SOFTWARE:
1387+
return source == DECODER_SOURCE_ANDROID;
1388+
case FIRMWARE:
1389+
return source == DECODER_SOURCE_ESP32;
1390+
case BOTH:
1391+
default:
1392+
return true;
1393+
}
13571394
}
13581395

1396+
13591397
private void handleAx25Packet(byte[] packet, int decoderSource) {
13601398
try {
13611399
String hash = packetHash(packet);
@@ -1541,7 +1579,7 @@ private void txAX25Packet(Packet ax25Packet) {
15411579
return;
15421580
}
15431581
Log.d(TAG, "Sending AX25 packet: " + ax25Packet);
1544-
if (aprsTxEncoder == AprsTxEncoder.ESP32) {
1582+
if (aprsTxEncoder == AprsTxEncoder.FIRMWARE) {
15451583
hostToEsp32.txAx25(ax25Packet.bytesWithoutCRC());
15461584
} else {
15471585
startPtt();

android-src/KV4PHT/app/src/main/java/com/vagell/kv4pht/ui/MainActivity.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,8 @@ private void applyAccessibilitySettings(Map<String, String> settings) {
11221122
private void applyAprsSettings(Map<String, String> settings) {
11231123
String accuracy = settings.get(AppSetting.SETTING_APRS_POSITION_ACCURACY);
11241124
String beacon = settings.get(AppSetting.SETTING_APRS_BEACON_POSITION);
1125-
String txEncoder = settings.getOrDefault(AppSetting.SETTING_APRS_TX_ENCODER, "Android");
1125+
String txEncoder = getAx25EncoderSetting(settings);
1126+
String decoder = settings.getOrDefault(AppSetting.SETTING_AX25_DECODER, "Both");
11261127

11271128
if (accuracy != null && radioAudioService != null) {
11281129
threadPoolExecutor.execute(() -> radioAudioService.setAprsPositionAccuracy(
@@ -1145,9 +1146,18 @@ private void applyAprsSettings(Map<String, String> settings) {
11451146
}
11461147
if (radioAudioService != null) {
11471148
radioAudioService.setAprsTxEncoder(txEncoder);
1149+
radioAudioService.setAx25Decoder(RadioAudioService.Ax25Decoder.fromSetting(decoder));
11481150
}
11491151
}
11501152

1153+
private String getAx25EncoderSetting(Map<String, String> settings) {
1154+
String stored = settings.get(AppSetting.SETTING_AX25_ENCODER);
1155+
if (stored != null) {
1156+
return stored;
1157+
}
1158+
return settings.getOrDefault(AppSetting.SETTING_APRS_TX_ENCODER, "Software");
1159+
}
1160+
11511161
@SuppressLint("ClickableViewAccessibility")
11521162
private void attachListeners() {
11531163
ImageButton pttButton = findViewById(R.id.pttButton);

android-src/KV4PHT/app/src/main/java/com/vagell/kv4pht/ui/SettingsActivity.java

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ private void populateMicGainOptions() {
104104

105105
private void populateAprsOptions() {
106106
setDropdownOptions(R.id.aprsPositionAccuracyTextView, List.of("Exact", "Approx"));
107-
setDropdownOptions(R.id.aprsTxEncoderTextView, List.of("Android", "ESP32"));
107+
setDropdownOptions(R.id.ax25DecoderTextView, List.of("Both", "Software", "Firmware"));
108+
setDropdownOptions(R.id.ax25EncoderTextView, List.of("Software", "Firmware"));
108109
}
109110

110111
private void populateRadioOptions() {
@@ -169,6 +170,27 @@ private void setDropdownWithDefault(Map<String, String> settings, String key, in
169170
.setText(settings.getOrDefault(key, defaultValue), false);
170171
}
171172

173+
private void setAx25DecoderDropdown(Map<String, String> settings) {
174+
setDropdownWithDefault(settings, AppSetting.SETTING_AX25_DECODER, R.id.ax25DecoderTextView, "Both");
175+
}
176+
177+
private void setAx25EncoderDropdown(Map<String, String> settings) {
178+
String stored = settings.get(AppSetting.SETTING_AX25_ENCODER);
179+
if (stored == null && settings.containsKey(AppSetting.SETTING_APRS_TX_ENCODER)) {
180+
stored = mapLegacyEncoderSetting(settings.get(AppSetting.SETTING_APRS_TX_ENCODER));
181+
saveAppSettingAsync(AppSetting.SETTING_AX25_ENCODER, stored);
182+
}
183+
this.<AutoCompleteTextView>findViewById(R.id.ax25EncoderTextView)
184+
.setText(stored == null ? "Software" : stored, false);
185+
}
186+
187+
private String mapLegacyEncoderSetting(String stored) {
188+
if ("ESP32".equalsIgnoreCase(stored) || "Firmware".equalsIgnoreCase(stored) || "1".equals(stored)) {
189+
return "Firmware";
190+
}
191+
return "Software";
192+
}
193+
172194
private void populateOriginalValues(Runnable callback) {
173195
threadPoolExecutor.execute(() -> {
174196
final Map<String, String> settings = viewModel.getAppDb().appSettingDao().getAll().stream()
@@ -184,7 +206,8 @@ private void populateOriginalValues(Runnable callback) {
184206
setSwitchIfPresent(settings, AppSetting.SETTING_DISABLE_ANIMATIONS, R.id.noAnimationsSwitch);
185207
setSwitchIfPresent(settings, AppSetting.SETTING_APRS_BEACON_POSITION, R.id.aprsPositionSwitch);
186208
setDropdownIfPresent(settings, AppSetting.SETTING_APRS_POSITION_ACCURACY, R.id.aprsPositionAccuracyTextView);
187-
setDropdownWithDefault(settings, AppSetting.SETTING_APRS_TX_ENCODER, R.id.aprsTxEncoderTextView, "Android");
209+
setAx25DecoderDropdown(settings);
210+
setAx25EncoderDropdown(settings);
188211
setDropdownIfPresent(settings, AppSetting.SETTING_BANDWIDTH, R.id.bandwidthTextView);
189212
setDropdownIfPresent(settings, AppSetting.SETTING_MIN_2_M_TX_FREQ, R.id.min2mFreqTextView, mhz);
190213
setDropdownIfPresent(settings, AppSetting.SETTING_MAX_2_M_TX_FREQ, R.id.max2mFreqTextView, mhz);
@@ -254,7 +277,8 @@ private void attachSlider(int viewId, IntConsumer onValueChanged) {
254277
private void attachListeners() {
255278
attachTextView(R.id.callsignTextInputEditText, text -> setCallsign(text.toUpperCase()));
256279
attachTextView(R.id.aprsPositionAccuracyTextView, this::setAprsPositionAccuracy);
257-
attachTextView(R.id.aprsTxEncoderTextView, this::setAprsTxEncoder);
280+
attachTextView(R.id.ax25DecoderTextView, this::setAx25Decoder);
281+
attachTextView(R.id.ax25EncoderTextView, this::setAx25Encoder);
258282
attachTextView(R.id.bandwidthTextView, this::setBandwidth);
259283
attachTextView(R.id.min2mFreqTextView, text -> setMin2mTxFreq(extractPrefix(text)));
260284
attachTextView(R.id.max2mFreqTextView, text -> setMax2mTxFreq(extractPrefix(text)));
@@ -283,8 +307,12 @@ private void setAprsPositionAccuracy(String accuracy) {
283307
saveAppSettingAsync(AppSetting.SETTING_APRS_POSITION_ACCURACY, accuracy);
284308
}
285309

286-
private void setAprsTxEncoder(String encoder) {
287-
saveAppSettingAsync(AppSetting.SETTING_APRS_TX_ENCODER, encoder);
310+
private void setAx25Encoder(String encoder) {
311+
saveAppSettingAsync(AppSetting.SETTING_AX25_ENCODER, encoder);
312+
}
313+
314+
private void setAx25Decoder(String decoder) {
315+
saveAppSettingAsync(AppSetting.SETTING_AX25_DECODER, decoder);
288316
}
289317

290318
private void setBandwidth(String bandwidth) {

0 commit comments

Comments
 (0)