Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit ntrip path directly #35

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 32 additions & 25 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<string name="navdraw_item_processing_options">Processing options</string>
<string name="navdraw_item_solution_options">Solution options</string>
<string name="navdraw_item_ntripcaster_options">Caster options</string>

<string-array name="rtk_server_receiver">
<item>Rover</item>
<item>Base</item>
Expand Down Expand Up @@ -130,7 +130,7 @@
<item>b:</item>
<item>height:</item>
</string-array>

<!-- PMODE_XXX positioning mode -->
<string name="pmode_single">Single</string>
<string name="pmode_dgps">DGPS/DGNSS</string>
Expand Down Expand Up @@ -168,7 +168,7 @@
<string name="solq_ppp">PPP</string>
<string name="solq_dr">Dead reckoning</string>
<string name="solq_internal">Internal</string>

<!-- SOLF_XXX Solution Format -->
<string name="solf_llh">Lat/Long/Height</string>
<string name="solf_xyz">X/Y/Z — ECEF</string>
Expand Down Expand Up @@ -261,7 +261,7 @@
<string name="stapos_rinex_hdr">Rinex header</string>
<string name="stapos_rtcm_pos">RTCM Antenna position</string>


<!-- Procession options -->
<string name="procopt_category_processing_options_1">Processing options 1</string>
<string name="procopt_category_solution_options">Solution options</string>
Expand Down Expand Up @@ -327,7 +327,7 @@
<item>35</item>
<item>40</item>
</string-array>

<string name="procopt_ambiguity_resolution_title">GPS Integer ambiguity resolution</string>
<string name="procopt_ambiguity_resolution_dialog_title">GPS Integer ambiguity resolution</string>
<string-array name="procopt_ambiguity_resolution_entries">
Expand Down Expand Up @@ -532,11 +532,11 @@
<item>30</item>
<item>60</item>
</string-array>

<!-- Output header -->
<string name="solopt_output_header_title">Output header</string>
<string name="solopt_output_header_summary">Set whether the header is output or not</string>

<!-- Output mocklocation -->
<string name="solopt_output_mocklocation_title">Output GPS mock locations</string>
<string name="solopt_output_mocklocation_summary">Set if solution is sent to other applications like the internal GPS</string>
Expand All @@ -553,7 +553,7 @@
<string name="earth_tide_correction_off">OFF</string>
<string name="earth_tide_correction_solid">Solid</string>
<string name="earth_tide_correction_solid_otl_pole">Solid, ocean, pole</string>

<string-array name="solopt_lat_lon_format_entries">
<item>ddd.dddddddd : Degree</item>
<item>ddd mm ss.sss : Degree minute second</item>
Expand Down Expand Up @@ -627,7 +627,7 @@
<string name="solopt_output_customproj4_default">+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs</string>
<string name="solopt_output_testmode_title">Enable test mode</string>
<string name="solopt_output_testmode_summary">If this is enabled and Rover/Base/Correction are off, it runs in a special test mode with positions coming from internal GPS. Obviously no algorithm from RTKLIB can work</string>

<!-- Input streams settings -->
<string name="streams_settings_type_title">Type</string>
<string name="streams_settings_format_title">Format</string>
Expand All @@ -644,10 +644,10 @@
<string name="input_streams_settings_receiver_option_title">Receiver option</string>
<string name="input_streams_settings_transmit_gpgga_to_base_title">Transmit GPGGA to Base Station</string>
<string name="input_streams_settings_transmit_gpgga_lat_title">Latitude</string>
<string name="input_streams_settings_transmit_gpgga_lon_title">Longitude</string>
<string name="input_streams_settings_transmit_gpgga_lon_title">Longitude</string>
<string name="input_streams_setting_antenna_title">Antenna</string>
<string name="input_streams_setting_antenna_summary">Antenna official IGS name (for phase center variation)</string>

<string-array name="input_streams_settings_transmit_gpgga_entries">
<item>OFF</item>
<item>Latitude/Longitude</item>
Expand All @@ -658,8 +658,8 @@
<item>1</item>
<item>2</item>
</string-array>


<!-- Output stream settings -->
<string name="output_streams_settings_enable_solution1_title">Enable Solution 1</string>
<string name="output_streams_settings_enable_solution2_title">Enable Solution 2</string>
Expand All @@ -668,22 +668,29 @@
<string name="output_streams_settings_solution2_tab_title">Solution 2</string>
<string name="output_streams_settings_gpxtrace_tab_title">GPX Trace</string>


<!-- Log stream settings -->
<string name="log_streams_settings_enable_rover_title">Log rover</string>
<string name="log_streams_settings_enable_base_title">Log base </string>
<string name="log_streams_settings_enable_correction_title">Log correction</string>
<string name="log_stream_settings_rover_tab_title">Log Rover</string>
<string name="log_stream_settings_base_tab_title">Log Base</string>
<string name="log_stream_settings_correction_tab_title">Log Correction</string>

<!-- NTRIP client stream preferences -->
<string name="ntrip_client_dialog_title">NTRIP client settings</string>
<string name="ntrip_client_host_title">Host</string>
<string name="ntrip_client_port_title">Port</string>
<string name="ntrip_client_mountpoint_title">NTRIP Mountpoint</string>
<string name="ntrip_client_user_title">NTRIP user</string>
<string name="ntrip_client_password_title">NTRIP password</string>

<string name="ntrip_client_category_individual">Individual fields</string>
<string name="ntrip_client_category_path">Single path</string>

<string name="ntrip_client_path_title">NTRIP path...</string>
<string name="ntrip_client_path_hint">Change all settings as a single string.</string>

<string name="ntrip_server_dialog_title">NTRIP server settings</string>
<string name="file_filename_title">Filename</string>
<string name="file_filename_summary">can included %Y (year) %m (month) %d (day) %h (hour) %M (minutes) %S (seconds) for dynamic naming</string>
Expand All @@ -703,15 +710,15 @@

<!-- File stream preferences -->
<string name="file_dialog_title">File settings</string>

<!-- Bluetooth stream preferences -->
<string name="bluetooth_dialog_title">Bluetooth receiver settings</string>
<string name="bluetooth_device_not_selected">device not selected</string>
<string name="bluetooth_disabled_summary">Turn on Bluetooth and select the receiver</string>
<string name="bluetooth_device_address_title">Bluetooth device</string>
<string name="bluetooth_system_settings_title">Bluetooth system settings</string>
<string name="bluetooth_system_settings_summary">Display system Bluetooth settings screen</string>

<string name="bluetooth_connected">Bluetooth connected</string>
<string name="bluetooth_connection_lost">Bluetooth connection lost</string>

Expand Down Expand Up @@ -744,10 +751,10 @@
</string-array>

<!-- USB stream preferences -->

<string name="usb_connected">USB connected</string>
<string name="usb_connection_lost">USB connection lost</string>

<string name="usb_dialog_title">USB receiver settings</string>
<string name="usb_device_baudrate_title">Baudrate</string>
<string-array name="usb_device_baudrate_entries">
Expand Down Expand Up @@ -794,30 +801,30 @@
<item>1</item>
<item>2</item>
</string-array>

<!-- Startup/shutdown commands preference widget -->
<string name="send_commands_at_startup">Send commands at startup</string>
<string name="send_commands_at_shutdown">Send commands at shutdown</string>
<string name="commands_at_startup">Commands at startup</string>
<string name="commands_at_shutdown">Commands at shutdown</string>
<string name="load_startup_shutdown_commands">Load</string>
<string name="load_startup_shutdown_dialog_title">Select file</string>

<!-- Rover/base position -->
<string name="station_position_format_llh">Lat/Lon/Height (deg/m)</string>
<string name="station_position_format_llh_dms">Lat/Lon/Height (dms/m)</string>
<string name="station_position_format_ecef">X/Y/Z — ECEF</string>
<string name="station_position_for_fixed_mode">For fixed mode</string>
<string name="station_position_for_relative_mode">For relative mode</string>

<!-- StatusView -->
<string name="status_view_snr">SNR Rover/Base</string>
<string name="status_view_snr_l1">SNR Rover/Base L1</string>
<string name="status_view_snr_l2">SNR Rover/Base L2</string>
<string name="status_view_snr_l5">SNR Rover/Base L5</string>
<string name="status_view_skyplot_rover_l1">Skyplot Rover L1</string>
<string name="status_view_skyplot_rover_l2">Skyplot Rover L2</string>
<string name="status_view_skyplot_rover_l5">Skyplot Rover L5</string>
<string name="status_view_skyplot_rover_l5">Skyplot Rover L5</string>
<string name="status_view_skyplot_base_l1">Skyplot Base L1</string>
<string name="status_view_skyplot_base_l2">Skyplot Base L2</string>
<string name="status_view_skyplot_base_l5">Skyplot Base L5</string>
Expand All @@ -830,12 +837,12 @@
<string name="tools_download_egm2008_m25_geoid">Install EGM 2008 2.5\' Geoid (135MB)</string>
<string name="tools_download_egm2008_m10_geoid">Install EGM 2008 1.0\' Geoid (825MB)</string>
<string name="tools_download_egm96_m150_geoid">Install EGM 96 15\' Geoid (2MB)</string>

<string name="changelog_full_title">Change Log</string>
<string name="changelog_title">What\'s New</string>
<string name="changelog_ok_button">OK</string>
<string name="changelog_show_full">more…</string>

<string name="ntripcaster_options_enabled_summary">Enable experimental NTRIP Caster</string>
<string name="ntripcaster_options_enabled_title">NTRIP Caster</string>
<string name="ntripcaster_options_brutal_ending_summary">Ending NTRIP Caster will also shutown RTKGPS+, it is safer for being sure all connections are closed.</string>
Expand Down
69 changes: 43 additions & 26 deletions res/xml/stream_ntrip_client_settings.xml
Original file line number Diff line number Diff line change
@@ -1,28 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >

<EditTextPreference
android:key="stream_ntrip_client_host"
android:title="@string/ntrip_client_host_title"
android:inputType="textUri" />

<EditTextPreference
android:key="stream_ntrip_client_port"
android:title="@string/ntrip_client_port_title"
android:inputType="number" />

<EditTextPreference
android:key="stream_ntrip_client_mountpoint"
android:title="@string/ntrip_client_mountpoint_title" />

<EditTextPreference
android:key="stream_ntrip_client_user"
android:title="@string/ntrip_client_user_title"
android:inputType="textPersonName" />

<EditTextPreference
android:key="stream_ntrip_client_password"
android:title="@string/ntrip_client_password_title"
android:inputType="textVisiblePassword" />

</PreferenceScreen>

<PreferenceCategory
android:key="stream_ntrip_client_category_individual"
android:title="@string/ntrip_client_category_individual">

<EditTextPreference
android:key="stream_ntrip_client_host"
android:title="@string/ntrip_client_host_title"
android:inputType="textUri" />

<EditTextPreference
android:key="stream_ntrip_client_port"
android:title="@string/ntrip_client_port_title"
android:inputType="number" />

<EditTextPreference
android:key="stream_ntrip_client_mountpoint"
android:title="@string/ntrip_client_mountpoint_title" />

<EditTextPreference
android:key="stream_ntrip_client_user"
android:title="@string/ntrip_client_user_title"
android:inputType="textPersonName" />

<EditTextPreference
android:key="stream_ntrip_client_password"
android:title="@string/ntrip_client_password_title"
android:inputType="textVisiblePassword" />

</PreferenceCategory>

<PreferenceCategory
android:key="stream_ntrip_client_category_path"
android:title="@string/ntrip_client_category_path">

<gpsplus.rtkgps.settings.NtripPathEditTextPreference
android:key="stream_ntrip_path"
android:title="@string/ntrip_client_path_title"
android:inputType="textUri" />

</PreferenceCategory>

</PreferenceScreen>
61 changes: 61 additions & 0 deletions src/gpsplus/rtkgps/settings/NtripPathEditTextPreference.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package gpsplus.rtkgps.settings;

import android.content.Context;
import android.os.Bundle;
import android.preference.EditTextPreference;

import android.util.AttributeSet;
import android.text.Editable;
import android.text.TextWatcher;
import android.app.AlertDialog;
import android.app.Dialog;
import android.widget.Button;

public class NtripPathEditTextPreference extends EditTextPreference {

public NtripPathEditTextPreference(Context ctx, AttributeSet attrs, int defStyle) {
super(ctx, attrs, defStyle);
}

public NtripPathEditTextPreference(Context ctx, AttributeSet attrs) {
super(ctx, attrs);
}

private class EditTextWatcher implements TextWatcher {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}

@Override
public void beforeTextChanged(CharSequence s, int start, int before, int count) {}

@Override
public void afterTextChanged(Editable s) {
onEditTextChanged();
}
}

EditTextWatcher m_watcher = new EditTextWatcher();

protected boolean onCheckValue(String value) {
return null != SettingsHelper.decodeNtripTcpPath(value);
}

protected void onEditTextChanged() {
boolean enable = onCheckValue(getEditText().getText().toString());
Dialog dlg = getDialog();
if (dlg instanceof AlertDialog) {
AlertDialog alertDlg = (AlertDialog) dlg;
Button btn = alertDlg.getButton(AlertDialog.BUTTON_POSITIVE);
btn.setEnabled(enable);
}
}

@Override
protected void showDialog(Bundle state) {
super.showDialog(state);

getEditText().removeTextChangedListener(m_watcher);
getEditText().addTextChangedListener(m_watcher);
onEditTextChanged();
}
}
33 changes: 33 additions & 0 deletions src/gpsplus/rtkgps/settings/SettingsHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,21 @@
import gpsplus.rtklib.constants.StreamFormat;
import gpsplus.rtklib.constants.StreamType;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class SettingsHelper {

static final String NTRIP_REGEX = "^ntrip://(?:([^:]+)(?::([^@]+))?@)?([^:]+)(?::([0-9]+))?/(.+)$";

static final int USER = 1;
static final int PASSWORD = 2;
static final int HOST = 3;
static final int PORT = 4;
static final int MOUNTPOINT = 5;

static class StreamDefaultsBase {

Expand Down Expand Up @@ -471,5 +481,28 @@ static String encodeNtripTcpPath(
return path.toString();
}

static StreamNtripClientFragment.Value decodeNtripTcpPath(String path) {
StreamNtripClientFragment.Value value = new StreamNtripClientFragment.Value();
Pattern pattern = Pattern.compile(NTRIP_REGEX);
Matcher matcher = pattern.matcher(path);
if (!matcher.find()) {
return null;
}
value
.setUser(fixEmpty(matcher.group(USER)))
.setPassword(fixEmpty(matcher.group(PASSWORD)))
.setHost(matcher.group(HOST))
.setPort(
matcher.group(PORT) == null
? StreamNtripClientFragment.Value.DEFAULT_PORT
: Integer.parseInt(matcher.group(PORT))
)
.setMountpoint(matcher.group(MOUNTPOINT));
return value;
}

static String fixEmpty(String value) {
return value == null ? "" : value;
}

}
Loading