Skip to content

Commit a9ee325

Browse files
committed
Lora aprs text packets compatible mode
1 parent 970ca74 commit a9ee325

File tree

8 files changed

+59
-3
lines changed

8 files changed

+59
-3
lines changed

codec2talkie/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ android {
1010
applicationId "com.radio.codec2talkie"
1111
minSdkVersion 23
1212
targetSdkVersion 30
13-
versionCode 152
14-
versionName "1.52"
13+
versionCode 153
14+
versionName "1.53"
1515

1616
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1717
}

codec2talkie/src/main/java/com/radio/codec2talkie/MainActivity.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,12 +491,18 @@ private void updateStatusText(ProtocolFactory.ProtocolType protocolType) {
491491
status += getString(R.string.voax25_label);
492492
}
493493

494+
// Lora aprs text packets
495+
boolean textPacketsEnabled = SettingsWrapper.isTextPacketsEnabled(_sharedPreferences);
496+
if (textPacketsEnabled) {
497+
status += getString(R.string.text_packets_label);
498+
}
494499
// Digirepeater
495500
boolean isDigirepeaterEnabled = _sharedPreferences.getBoolean(PreferenceKeys.AX25_DIGIREPEATER_ENABLED, false);
496501
if (isDigirepeaterEnabled) {
497502
status += getString(R.string.digirepeater_label);
498503
}
499504

505+
// APRSIS
500506
boolean aprsisEnabled = SettingsWrapper.isAprsIsEnabled(_sharedPreferences);
501507
if (aprsisEnabled) {
502508
status += getString(R.string.aprsis_label);

codec2talkie/src/main/java/com/radio/codec2talkie/protocol/Ax25.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import com.radio.codec2talkie.transport.Transport;
1616

1717
import java.io.IOException;
18+
import java.nio.ByteBuffer;
19+
import java.nio.charset.StandardCharsets;
1820

1921
public class Ax25 implements Protocol {
2022

@@ -26,6 +28,7 @@ public class Ax25 implements Protocol {
2628
private String _digipath;
2729
private boolean _isVoax25Enabled;
2830
private boolean _isDigiRepeaterEnabled;
31+
private boolean _useTextPackets;
2932

3033
private ProtocolCallback _parentProtocolCallback;
3134

@@ -44,6 +47,7 @@ public void initialize(Transport transport, Context context, ProtocolCallback pr
4447
// NOTE, may need to pass through sendData/sendAudio
4548
_digipath = sharedPreferences.getString(PreferenceKeys.AX25_DIGIPATH, "").toUpperCase();
4649
_isVoax25Enabled = SettingsWrapper.isVoax25Enabled(sharedPreferences);
50+
_useTextPackets = SettingsWrapper.isTextPacketsEnabled(sharedPreferences);
4751
_isDigiRepeaterEnabled = sharedPreferences.getBoolean(PreferenceKeys.AX25_DIGIREPEATER_ENABLED, false);
4852
}
4953

@@ -93,7 +97,7 @@ public void sendData(String src, String dst, String path, byte[] dataPacket) thr
9397
ax25Packet.digipath = path == null ? _digipath : path;
9498
ax25Packet.isAudio = false;
9599
ax25Packet.rawData = dataPacket;
96-
byte[] ax25Frame = ax25Packet.toBinary();
100+
byte[] ax25Frame = _useTextPackets ? ax25Packet.toTextBinary() : ax25Packet.toBinary();
97101
if (ax25Frame == null) {
98102
Log.e(TAG, "Cannot convert AX.25 data packet to binary");
99103
_parentProtocolCallback.onProtocolTxError();

codec2talkie/src/main/java/com/radio/codec2talkie/protocol/ax25/AX25Packet.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
import androidx.annotation.NonNull;
44

5+
import com.radio.codec2talkie.protocol.aprs.tools.AprsIsData;
56
import com.radio.codec2talkie.tools.DebugTools;
67
import com.radio.codec2talkie.tools.TextTools;
78

89
import java.nio.BufferUnderflowException;
910
import java.nio.ByteBuffer;
11+
import java.nio.charset.StandardCharsets;
12+
import java.util.Arrays;
1013

1114
public class AX25Packet {
1215

@@ -28,6 +31,21 @@ public class AX25Packet {
2831
public void fromBinary(byte[] data) {
2932
isValid = false;
3033
if (data == null) return;
34+
// lora text packet with 0x3c,0xff,0x01 prefix
35+
if (data.length > 3 && data[0] == (byte)0x3c && data[1] == (byte)0xff && data[2] == (byte)0x01) {
36+
String rawText = new String(Arrays.copyOfRange(data, 3, data.length), StandardCharsets.US_ASCII);
37+
AprsIsData textPacket = AprsIsData.fromString(rawText);
38+
if (textPacket != null) {
39+
src = textPacket.src;
40+
dst = textPacket.dst;
41+
digipath = textPacket.rawDigipath;
42+
rawData = textPacket.data.getBytes(StandardCharsets.US_ASCII);
43+
isAudio = false;
44+
isValid = true;
45+
return;
46+
}
47+
}
48+
// binary packet
3149
ByteBuffer buffer = ByteBuffer.wrap(data);
3250
try {
3351
// dst
@@ -81,6 +99,18 @@ public void fromBinary(byte[] data) {
8199
}
82100
}
83101

102+
public byte[] toTextBinary() {
103+
byte[] packetContent = toString().getBytes(StandardCharsets.US_ASCII);
104+
// lora aprs prefix 0x3c,0xff,0x01
105+
ByteBuffer textPacketBuffer = ByteBuffer.allocateDirect(packetContent.length + 3);
106+
textPacketBuffer.put((byte)0x3c).put((byte)0xff).put((byte)0x01);
107+
textPacketBuffer.put(packetContent);
108+
textPacketBuffer.flip();
109+
byte[] ax25Frame = new byte[textPacketBuffer.remaining()];
110+
textPacketBuffer.get(ax25Frame);
111+
return ax25Frame;
112+
}
113+
84114
public byte[] toBinary() {
85115
ByteBuffer buffer = ByteBuffer.allocate(MaximumSize);
86116
String[] rptCallsigns = new String[] {};

codec2talkie/src/main/java/com/radio/codec2talkie/settings/PreferenceKeys.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public final class PreferenceKeys {
6767
public static String APP_AUDIO_DESTINATION = "app_audio_destination";
6868

6969
public static String AX25_VOAX25_ENABLE = "aprs_voax25_enable";
70+
public static String AX25_TEXT_PACKETS_ENABLE = "aprs_text_packets_enable";
7071
public static String AX25_CALLSIGN = "aprs_callsign";
7172
public static String AX25_SSID = "aprs_ssid";
7273
public static String AX25_DIGIPATH = "aprs_digipath";

codec2talkie/src/main/java/com/radio/codec2talkie/settings/SettingsWrapper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ public static boolean isVoax25Enabled(SharedPreferences sharedPreferences) {
9393
!isFreeDvSoundModemModulation(sharedPreferences); // no voax25 in freedv
9494
}
9595

96+
public static boolean isTextPacketsEnabled(SharedPreferences sharedPreferences) {
97+
return sharedPreferences.getBoolean(PreferenceKeys.AX25_TEXT_PACKETS_ENABLE, false);
98+
}
99+
96100
public static boolean isAprsIsEnabled(SharedPreferences sharedPreferences) {
97101
return sharedPreferences.getBoolean(PreferenceKeys.APRS_IS_ENABLE, false);
98102
}

codec2talkie/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@
232232
<string name="menu_send_position">Send position</string>
233233

234234
<string name="voax25_label">&#9742;</string>
235+
<string name="text_packets_label">&#128276;</string>
235236

236237
<string name="menu_aprs_log">View log</string>
237238

@@ -366,4 +367,6 @@
366367
<string name="map_menu_rotate_map">Rotate map with compass</string>
367368
<string name="map_menu_show_range">Show range circles</string>
368369
<string name="map_menu_show_moving">Show moving stations</string>
370+
<string name="aprs_text_packets_enable_title">Enable text packets</string>
371+
<string name="aprs_text_packets_enable_summary">Send lora aprs compatible text packets (0x3c,0xff,0x01 prefix)</string>
369372
</resources>

codec2talkie/src/main/res/xml/preferences.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,14 @@
215215
app:defaultValue="true">
216216
</SwitchPreference>
217217

218+
<SwitchPreference
219+
app:key="aprs_text_packets_enable"
220+
app:title="@string/aprs_text_packets_enable_title"
221+
app:summary="@string/aprs_text_packets_enable_summary"
222+
app:dependency="aprs_enable"
223+
app:defaultValue="false">
224+
</SwitchPreference>
225+
218226
<EditTextPreference
219227
app:key="aprs_callsign"
220228
app:title="@string/aprs_callsign_title"

0 commit comments

Comments
 (0)