Skip to content

Commit 8c08209

Browse files
committed
UDP JSON switch|
1 parent 7a6a162 commit 8c08209

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

app/src/main/java/com/jvdegithub/aiscatcher/AisCatcherJava.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public interface AisCallback {
5353

5454
static native int applySetting(String dev, String Setting, String Param);
5555

56-
static native int createUDP(String h, String p);
56+
static native int createUDP(String h, String p, boolean JSON);
5757

5858
static native int createWebViewer(String p);
5959

app/src/main/java/com/jvdegithub/aiscatcher/Settings.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,22 @@ static void setDefault(Context context) {
8989
preferences.edit().putBoolean("u1SWITCH", true).commit();
9090
preferences.edit().putString("u1HOST", "127.0.0.1").commit();
9191
preferences.edit().putString("u1PORT", "10110").commit();
92+
preferences.edit().putBoolean("u1JSON", false).commit();
9293

9394
preferences.edit().putBoolean("u2SWITCH", false).commit();
9495
preferences.edit().putString("u2HOST", "127.0.0.1").commit();
9596
preferences.edit().putString("u2PORT", "10111").commit();
97+
preferences.edit().putBoolean("u2JSON", false).commit();
9698

9799
preferences.edit().putBoolean("u3SWITCH", false).commit();
98100
preferences.edit().putString("u3HOST", "127.0.0.1").commit();
99101
preferences.edit().putString("u3PORT", "10111").commit();
102+
preferences.edit().putBoolean("u3JSON", false).commit();
100103

101104
preferences.edit().putBoolean("u4SWITCH", false).commit();
102105
preferences.edit().putString("u4HOST", "127.0.0.1").commit();
103106
preferences.edit().putString("u4PORT", "10111").commit();
104-
107+
preferences.edit().putBoolean("u4JSON", false).commit();
105108

106109
preferences.edit().putInt("mLINEARITY", 17).commit();
107110
preferences.edit().putString("mRATE", "2500K").commit();
@@ -368,7 +371,9 @@ static private boolean SetUDPoutput(String s, Context context) {
368371
if (b) {
369372
String host = preferences.getString(s + "HOST", "");
370373
String port = preferences.getString(s + "PORT", "");
371-
return AisCatcherJava.createUDP(host, port) == 0;
374+
boolean JSON = preferences.getBoolean(s + "JSON", false);
375+
376+
return AisCatcherJava.createUDP(host, port, JSON) == 0;
372377

373378
}
374379
return true;

app/src/main/jni/JNI/AIScatcherNDK.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ std::vector<IO::UDPStreamer > UDP_connections;
248248
std::vector<IO::TCPClientStreamer > TCP_connections;
249249
std::vector<std::string> UDPhost;
250250
std::vector<std::string> UDPport;
251+
std::vector<bool> UDPJSON;
252+
251253
bool sharing = false;
252254
std::string sharingKey = "";
253255

@@ -352,7 +354,7 @@ Java_com_jvdegithub_aiscatcher_AisCatcherJava_Run(JNIEnv *env, jclass) {
352354
UDP_connections.resize(UDPhost.size());
353355

354356
for (int i = 0; i < UDPhost.size(); i++) {
355-
UDP_connections[i].Set("host",UDPhost[i]).Set("port",UDPport[i]);
357+
UDP_connections[i].Set("host",UDPhost[i]).Set("port",UDPport[i]).Set("JSON",UDPJSON[i]?"on":"off");
356358
UDP_connections[i].Start();
357359
model->Output() >> UDP_connections[i];
358360
}
@@ -411,6 +413,7 @@ Java_com_jvdegithub_aiscatcher_AisCatcherJava_Run(JNIEnv *env, jclass) {
411413

412414
UDPport.clear();
413415
UDPhost.clear();
416+
UDPJSON.clear();
414417

415418
if(webviewer) {
416419
webviewer->close();
@@ -576,19 +579,22 @@ Java_com_jvdegithub_aiscatcher_AisCatcherJava_createReceiver(JNIEnv *env, jclass
576579
extern "C"
577580
JNIEXPORT jint JNICALL
578581
Java_com_jvdegithub_aiscatcher_AisCatcherJava_createUDP(JNIEnv *env, jclass clazz, jstring h,
579-
jstring p) {
582+
jstring p, jboolean J) {
580583
try {
581584
UDPport.resize(UDPport.size() + 1);
582585
UDPhost.resize(UDPhost.size() + 1);
586+
UDPJSON.resize(UDPJSON.size() + 1);
583587

584588
jboolean b;
585589
std::string host = toString(env,h); //(env)->GetStringUTFChars(h, &b);
586590
std::string port = toString(env, p); //(env)->GetStringUTFChars(p, &b);
591+
bool JSON = J;
587592

588593
UDPport[UDPport.size() - 1] = port;
589594
UDPhost[UDPhost.size() - 1] = host;
595+
UDPJSON[UDPJSON.size()-1] = JSON;
590596

591-
Info() << "UDP: " << host << ":" << port;
597+
Info() << "UDP: " << host << ":" << port << (J ? std::string(" (JSON)") : std::string(" (NMEA)"));
592598
} catch (std::exception& e) {
593599
callbackError(env, e.what());
594600
device = nullptr;

app/src/main/res/xml/preferences.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@
241241
android:dependency="u1SWITCH"
242242
android:title="Port"/>
243243

244+
<SwitchPreferenceCompat
245+
android:key="u1JSON"
246+
android:defaultValue="False"
247+
android:dependency="u1SWITCH"
248+
android:title="JSON"/>
249+
244250
<SwitchPreferenceCompat
245251
android:key="u2SWITCH"
246252
android:defaultValue="False"
@@ -258,6 +264,12 @@
258264
android:defaultValue="4002"
259265
android:title="Port"/>
260266

267+
<SwitchPreferenceCompat
268+
android:key="u2JSON"
269+
android:defaultValue="False"
270+
android:dependency="u2SWITCH"
271+
android:title="JSON"/>
272+
261273
<SwitchPreferenceCompat
262274
android:key="u3SWITCH"
263275
android:dependency="sSHARING"
@@ -276,6 +288,12 @@
276288
android:defaultValue="4002"
277289
android:title="Port"/>
278290

291+
<SwitchPreferenceCompat
292+
android:key="31JSON"
293+
android:defaultValue="False"
294+
android:dependency="u3SWITCH"
295+
android:title="JSON"/>
296+
279297
<SwitchPreferenceCompat
280298
android:key="u4SWITCH"
281299
android:dependency="sSHARING"
@@ -294,6 +312,11 @@
294312
android:defaultValue="4002"
295313
android:title="Port"/>
296314

315+
<SwitchPreferenceCompat
316+
android:key="u4JSON"
317+
android:defaultValue="False"
318+
android:dependency="u4SWITCH"
319+
android:title="JSON"/>
297320

298321
</PreferenceCategory>
299322

0 commit comments

Comments
 (0)