Commit 9611b58d authored by Franco Fichtner's avatar Franco Fichtner

network time: fix several issues with gps settings

o Page did not work with translations.
o Selected serial device wasn't shown.
o Very old gpsport migration code zapped.
o set_gps_default() must trigger on load.

(cherry picked from commit bb55f6c0)
parent 8bdd236a
...@@ -1462,9 +1462,9 @@ function system_ntp_setup_gps($serialport) ...@@ -1462,9 +1462,9 @@ function system_ntp_setup_gps($serialport)
symlink($serialport, $gps_device); symlink($serialport, $gps_device);
/* Send the following to the GPS port to initialize the GPS */ /* Send the following to the GPS port to initialize the GPS */
if (is_array($config['ntpd']) && is_array($config['ntpd']['gps']) && !empty($config['ntpd']['gps']['type'])) { if (isset($config['ntpd']['gps'])) {
$gps_init = base64_decode($config['ntpd']['gps']['initcmd']); $gps_init = base64_decode($config['ntpd']['gps']['initcmd']);
}else{ } else {
$gps_init = base64_decode('JFBVQlgsNDAsR1NWLDAsMCwwLDAqNTkNCiRQVUJYLDQwLEdMTCwwLDAsMCwwKjVDDQokUFVCWCw0MCxaREEsMCwwLDAsMCo0NA0KJFBVQlgsNDAsVlRHLDAsMCwwLDAqNUUNCiRQVUJYLDQwLEdTViwwLDAsMCwwKjU5DQokUFVCWCw0MCxHU0EsMCwwLDAsMCo0RQ0KJFBVQlgsNDAsR0dBLDAsMCwwLDANCiRQVUJYLDQwLFRYVCwwLDAsMCwwDQokUFVCWCw0MCxSTUMsMCwwLDAsMCo0Ng0KJFBVQlgsNDEsMSwwMDA3LDAwMDMsNDgwMCwwDQokUFVCWCw0MCxaREEsMSwxLDEsMQ=='); $gps_init = base64_decode('JFBVQlgsNDAsR1NWLDAsMCwwLDAqNTkNCiRQVUJYLDQwLEdMTCwwLDAsMCwwKjVDDQokUFVCWCw0MCxaREEsMCwwLDAsMCo0NA0KJFBVQlgsNDAsVlRHLDAsMCwwLDAqNUUNCiRQVUJYLDQwLEdTViwwLDAsMCwwKjU5DQokUFVCWCw0MCxHU0EsMCwwLDAsMCo0RQ0KJFBVQlgsNDAsR0dBLDAsMCwwLDANCiRQVUJYLDQwLFRYVCwwLDAsMCwwDQokUFVCWCw0MCxSTUMsMCwwLDAsMCo0Ng0KJFBVQlgsNDEsMSwwMDA3LDAwMDMsNDgwMCwwDQokUFVCWCw0MCxaREEsMSwxLDEsMQ==');
} }
...@@ -1643,16 +1643,6 @@ function system_ntp_configure($start_ntpd = true) ...@@ -1643,16 +1643,6 @@ function system_ntp_configure($start_ntpd = true)
$ntpcfg .= $config['ntpd']['gps']['refid']; $ntpcfg .= $config['ntpd']['gps']['refid'];
} }
$ntpcfg .= "\n"; $ntpcfg .= "\n";
}elseif (!empty($config['ntpd']['gpsport'])
&& file_exists('/dev/'.$config['ntpd']['gpsport'])
&& system_ntp_setup_gps($config['ntpd']['gpsport'])) {
/* This handles a 2.1 and earlier config */
$ntpcfg .= "# GPS Setup\n";
$ntpcfg .= "server 127.127.20.0 mode 0 minpoll 4 maxpoll 4 prefer\n";
$ntpcfg .= "fudge 127.127.20.0 time1 0.155 time2 0.000 flag1 1 flag2 0 flag3 1\n";
// Fall back to local clock if GPS is out of sync?
$ntpcfg .= "server 127.127.1.0\n";
$ntpcfg .= "fudge 127.127.1.0 stratum 12\n";
} }
/* End GPS configuration */ /* End GPS configuration */
......
...@@ -51,11 +51,6 @@ if ($_POST) { ...@@ -51,11 +51,6 @@ if ($_POST) {
elseif (isset($config['ntpd']['interface'])) elseif (isset($config['ntpd']['interface']))
unset($config['ntpd']['interface']); unset($config['ntpd']['interface']);
if (!empty($_POST['gpsport']) && file_exists('/dev/'.$_POST['gpsport']))
$config['ntpd']['gpsport'] = $_POST['gpsport'];
elseif (isset($config['ntpd']['gpsport']))
unset($config['ntpd']['gpsport']);
unset($config['ntpd']['prefer']); unset($config['ntpd']['prefer']);
unset($config['ntpd']['noselect']); unset($config['ntpd']['noselect']);
$timeservers = ''; $timeservers = '';
......
...@@ -32,38 +32,24 @@ require_once("services.inc"); ...@@ -32,38 +32,24 @@ require_once("services.inc");
require_once("system.inc"); require_once("system.inc");
require_once("interfaces.inc"); require_once("interfaces.inc");
function set_default_gps() { if (!isset($config['ntpd']['gps'])) {
global $config;
if (!isset($config['ntpd']) || !is_array($config['ntpd']))
$config['ntpd'] = array();
$config['ntpd']['gps'] = array(); $config['ntpd']['gps'] = array();
$config['ntpd']['gps']['type'] = 'Generic';
/* copy an existing configured GPS port if it exists, the unset may be uncommented post production */
if (!empty($config['ntpd']['gpsport']) && empty($config['ntpd']['gps']['port'])) {
$config['ntpd']['gps']['port'] = $config['ntpd']['gpsport'];
unset($config['ntpd']['gpsport']); /* this removes the original port config from config.xml */
$config['ntpd']['gps']['speed'] = 0;
$config['ntpd']['gps']['nmea'] = 0;
}
write_config("Setting default NTPd settings");
} }
if ($_POST) { if ($_POST) {
unset($input_errors); unset($input_errors);
if (!empty($_POST['gpsport']) && file_exists('/dev/'.$_POST['gpsport'])) if (!empty($_POST['gpsport']) && file_exists('/dev/'.$_POST['gpsport'])) {
$config['ntpd']['gps']['port'] = $_POST['gpsport']; $config['ntpd']['gps']['port'] = $_POST['gpsport'];
/* if port is not set, remove all the gps config */ } else if (isset($config['ntpd']['gps']['port'])) {
else unset($config['ntpd']['gps']); unset($config['ntpd']['gps']['port']);
}
if (!empty($_POST['gpstype'])) if (!empty($_POST['gpstype'])) {
$config['ntpd']['gps']['type'] = $_POST['gpstype']; $config['ntpd']['gps']['type'] = $_POST['gpstype'];
elseif (isset($config['ntpd']['gps']['type'])) } elseif (isset($config['ntpd']['gps']['type'])) {
unset($config['ntpd']['gps']['type']); unset($config['ntpd']['gps']['type']);
}
if (!empty($_POST['gpsspeed'])) if (!empty($_POST['gpsspeed']))
$config['ntpd']['gps']['speed'] = $_POST['gpsspeed']; $config['ntpd']['gps']['speed'] = $_POST['gpsspeed'];
...@@ -140,16 +126,13 @@ if ($_POST) { ...@@ -140,16 +126,13 @@ if ($_POST) {
$retval = system_ntp_configure(); $retval = system_ntp_configure();
$savemsg = get_std_save_message(); $savemsg = get_std_save_message();
} else {
/* set defaults if they do not already exist */
if (empty($config['ntpd']['gps']['type'])) {
set_default_gps();
}
} }
$closehead = false; $closehead = false;
$pconfig = &$config['ntpd']['gps']; $pconfig = &$config['ntpd']['gps'];
$pgtitle = array(gettext("Services"),gettext("NTP GPS")); $pgtitle = array(gettext("Services"),gettext("NTP GPS"));
$shortcut_section = "ntp"; $shortcut_section = "ntp";
include("head.inc"); include("head.inc");
?> ?>
...@@ -249,7 +232,7 @@ SureGPS = #Sure Electronics SKG16B ...@@ -249,7 +232,7 @@ SureGPS = #Sure Electronics SKG16B
var gpsdef = new Object(); var gpsdef = new Object();
//get the text description of the selected type //get the text description of the selected type
var e = document.getElementById("gpstype"); var e = document.getElementById("gpstype");
var type = e.options[e.selectedIndex].text; var type = e.options[e.selectedIndex].value;
//stuff the JS object as needed for each type //stuff the JS object as needed for each type
switch(type) { switch(type) {
...@@ -387,14 +370,14 @@ SureGPS = #Sure Electronics SKG16B ...@@ -387,14 +370,14 @@ SureGPS = #Sure Electronics SKG16B
<td width="78%" valign="top" class="vtable"> <td width="78%" valign="top" class="vtable">
<!-- Start with the original "Default", list a "Generic" and then specific configs alphabetically --> <!-- Start with the original "Default", list a "Generic" and then specific configs alphabetically -->
<select id="gpstype" name="gpstype" class="formselect" onchange="set_gps_default(this.form)"> <select id="gpstype" name="gpstype" class="formselect" onchange="set_gps_default(this.form)">
<option value="Custom"<?php if($pconfig['type'] == 'Custom') echo " selected=\"selected\""; ?>><?=gettext('Custom') ?></option> <option value="Generic" title="Generic"<?php if (empty($pconfig['type']) || $pconfig['type'] == 'Generic' ) echo " selected=\"selected\"";?>><?=gettext('Generic') ?></option>
<option value="Default"<?php if($pconfig['type'] == 'Default') echo " selected=\"selected\""; ?>><?=gettext('Default') ?></option> <option value="Default"<?php if($pconfig['type'] == 'Default') echo " selected=\"selected\""; ?>><?=gettext('Default') ?></option>
<option value="Generic" title="Generic"<?php if($pconfig['type'] == 'Generic' ) echo " selected=\"selected\"";?>><?=gettext('Generic') ?></option>
<option value="Garmin" title="$PGRM... Most Garmin"<?php if($pconfig['type'] == 'Garmin') echo " selected=\"selected\"";?>><?=gettext('Garmin') ?></option> <option value="Garmin" title="$PGRM... Most Garmin"<?php if($pconfig['type'] == 'Garmin') echo " selected=\"selected\"";?>><?=gettext('Garmin') ?></option>
<option value="MediaTek" title="$PMTK... Adafruit, Fastrax, some Garmin and others"<?php if($pconfig['type'] == 'MediaTek') echo " selected=\"selected\"";?>>MediaTek</option> <option value="MediaTek" title="$PMTK... Adafruit, Fastrax, some Garmin and others"<?php if($pconfig['type'] == 'MediaTek') echo " selected=\"selected\"";?>>MediaTek</option>
<option value="SiRF" title="$PSRF... Used by many devices"<?php if($pconfig['type'] == 'sirf') echo " selected=\"selected\"";?>><?=gettext('SiRF') ?></option> <option value="SiRF" title="$PSRF... Used by many devices"<?php if($pconfig['type'] == 'sirf') echo " selected=\"selected\"";?>><?=gettext('SiRF') ?></option>
<option value="U-Blox" title="$PUBX... U-Blox 5, 6 and probably 7"<?php if($pconfig['type'] == 'U-Blox') echo " selected=\"selected\"";?>><?=gettext('U-Blox') ?></option> <option value="U-Blox" title="$PUBX... U-Blox 5, 6 and probably 7"<?php if($pconfig['type'] == 'U-Blox') echo " selected=\"selected\"";?>><?=gettext('U-Blox') ?></option>
<option value="SureGPS" title="$PMTK... Sure Electronics SKG16B"<?php if($pconfig['type'] == 'SureGPS') echo " selected=\"selected\"";?>><?=gettext('SureGPS') ?></option> <option value="SureGPS" title="$PMTK... Sure Electronics SKG16B"<?php if($pconfig['type'] == 'SureGPS') echo " selected=\"selected\"";?>><?=gettext('SureGPS') ?></option>
<option value="Custom"<?php if($pconfig['type'] == 'Custom') echo " selected=\"selected\""; ?>><?=gettext('Custom') ?></option>
</select> <?php echo gettext("This option allows you to select a predefined configuration.");?> </select> <?php echo gettext("This option allows you to select a predefined configuration.");?>
<br /> <br />
<br /> <br />
...@@ -416,12 +399,13 @@ SureGPS = #Sure Electronics SKG16B ...@@ -416,12 +399,13 @@ SureGPS = #Sure Electronics SKG16B
<?php <?php
foreach ($serialports as $port): foreach ($serialports as $port):
$shortport = substr($port,5); $shortport = substr($port,5);
$selected = ($shortport == isset($pconfig['port'])?$pconfig['port']:null) ? " selected=\"selected\"" : ""; $selected = '';
if (isset($pconfig['port']) && $shortport === $pconfig['port']) {
$selected = 'selected="selected"';
}
?> ?>
<option value="<?php echo $shortport;?>"<?php echo $selected;?>><?php echo $shortport;?></option> <option value="<?php echo $shortport;?>"<?php echo $selected;?>><?php echo $shortport;?></option>
<?php <?php endforeach; ?>
endforeach;
?>
</select>&nbsp; </select>&nbsp;
<?php echo gettext("All serial ports are listed, be sure to pick the port with the GPS attached."); ?> <?php echo gettext("All serial ports are listed, be sure to pick the port with the GPS attached."); ?>
<br /><br /> <br /><br />
...@@ -583,5 +567,10 @@ SureGPS = #Sure Electronics SKG16B ...@@ -583,5 +567,10 @@ SureGPS = #Sure Electronics SKG16B
</div> </div>
</section> </section>
<script type="text/javascript">
//<![CDATA[
set_gps_default(document.getElementById('iform'));
//]]>
</script>
<?php include("foot.inc"); ?> <?php include("foot.inc"); ?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment