Commit f0b9bd07 authored by Ad Schellevis's avatar Ad Schellevis Committed by Franco Fichtner

(legacy) refactor services_ntpd_gps.php

(cherry picked from commit de12c9fa)
parent 3634dc09
<?php
/*
Copyright (C) 2014-2015 Deciso B.V.
Copyright (C) 2013 Dagorlad
Copyright (C) 2012 Jim Pingle
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2014-2016 Deciso B.V.
Copyright (C) 2013 Dagorlad
Copyright (C) 2012 Jim Pingle
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
require_once("guiconfig.inc");
......@@ -34,535 +34,498 @@ require_once("system.inc");
require_once("interfaces.inc");
if (!isset($config['ntpd']['gps'])) {
$config['ntpd']['gps'] = array();
$config['ntpd']['gps'] = array();
}
if ($_POST) {
unset($input_errors);
if (!empty($_POST['gpsport']) && file_exists('/dev/'.$_POST['gpsport'])) {
$config['ntpd']['gps']['port'] = $_POST['gpsport'];
} else if (isset($config['ntpd']['gps']['port'])) {
unset($config['ntpd']['gps']['port']);
}
if (!empty($_POST['gpstype'])) {
$config['ntpd']['gps']['type'] = $_POST['gpstype'];
} elseif (isset($config['ntpd']['gps']['type'])) {
unset($config['ntpd']['gps']['type']);
}
if (!empty($_POST['gpsspeed']))
$config['ntpd']['gps']['speed'] = $_POST['gpsspeed'];
elseif (isset($config['ntpd']['gps']['speed']))
unset($config['ntpd']['gps']['speed']);
if (!empty($_POST['gpsnmea']) && ($_POST['gpsnmea'][0] === "0"))
$config['ntpd']['gps']['nmea'] = "0";
else
$config['ntpd']['gps']['nmea'] = strval(array_sum($_POST['gpsnmea']));
if (!empty($_POST['gpsfudge1']))
$config['ntpd']['gps']['fudge1'] = $_POST['gpsfudge1'];
elseif (isset($config['ntpd']['gps']['fudge1']))
unset($config['ntpd']['gps']['fudge1']);
if (!empty($_POST['gpsfudge2']))
$config['ntpd']['gps']['fudge2'] = $_POST['gpsfudge2'];
elseif (isset($config['ntpd']['gps']['fudge2']))
unset($config['ntpd']['gps']['fudge2']);
if (!empty($_POST['gpsstratum']) && ($_POST['gpsstratum']) < 17 )
$config['ntpd']['gps']['stratum'] = $_POST['gpsstratum'];
elseif (isset($config['ntpd']['gps']['stratum']))
unset($config['ntpd']['gps']['stratum']);
if (empty($_POST['gpsprefer'])) {
$config['ntpd']['gps']['prefer'] = 'on';
} elseif (isset($config['ntpd']['gps']['prefer']))
unset($config['ntpd']['gps']['prefer']);
if (!empty($_POST['gpsselect']))
$config['ntpd']['gps']['noselect'] = $_POST['gpsselect'];
elseif (isset($config['ntpd']['gps']['noselect']))
unset($config['ntpd']['gps']['noselect']);
if (!empty($_POST['gpsflag1'])) {
$config['ntpd']['gps']['flag1'] = $_POST['gpsflag1'];
} elseif (isset($config['ntpd']['gps']['flag1'])) {
unset($config['ntpd']['gps']['flag1']);
$copy_fields = array('port', 'type', 'speed', 'nmea', 'fudge1', 'fudge2', 'stratum', 'prefer', 'noselect',
'flag1', 'flag2', 'flag3', 'flag4', 'subsec', 'refid', 'initcmd');
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$pconfig = array();
foreach ($copy_fields as $fieldname) {
if (isset($config['ntpd']['gps'][$fieldname])) {
$pconfig[$fieldname] = $config['ntpd']['gps'][$fieldname];
} else {
$pconfig[$fieldname] = null;
}
if (!empty($_POST['gpsflag2']))
$config['ntpd']['gps']['flag2'] = $_POST['gpsflag2'];
elseif (isset($config['ntpd']['gps']['flag2']))
unset($config['ntpd']['gps']['flag2']);
if (!empty($_POST['gpsflag3']))
$config['ntpd']['gps']['flag3'] = $_POST['gpsflag3'];
elseif (isset($config['ntpd']['gps']['flag3']))
unset($config['ntpd']['gps']['flag3']);
if (!empty($_POST['gpsflag4']))
$config['ntpd']['gps']['flag4'] = $_POST['gpsflag4'];
elseif (isset($config['ntpd']['gps']['flag4']))
unset($config['ntpd']['gps']['flag4']);
if (!empty($_POST['gpssubsec']))
$config['ntpd']['gps']['subsec'] = $_POST['gpssubsec'];
elseif (isset($config['ntpd']['gps']['subsec']))
unset($config['ntpd']['gps']['subsec']);
if (!empty($_POST['gpsrefid']))
$config['ntpd']['gps']['refid'] = $_POST['gpsrefid'];
elseif (isset($config['ntpd']['gps']['refid']))
unset($config['ntpd']['gps']['refid']);
if (!empty($_POST['gpsinitcmd']))
$config['ntpd']['gps']['initcmd'] = base64_encode($_POST['gpsinitcmd']);
elseif (isset($config['ntpd']['gps']['initcmd']))
unset($config['ntpd']['gps']['initcmd']);
write_config("Updated NTP GPS Settings");
$retval = system_ntp_configure();
$savemsg = get_std_save_message();
}
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
$pconfig = $_POST;
$input_errors = array();
if (!empty($pconfig['stratum']) && ($pconfig['stratum'] > 17 || $pconfig['stratum'] < 0 || (int)$pconfig['stratum'] == null)) {
$input_errors[] = gettext("Clock stratum must be a number in the range 0..16");
}
// swap prefer
$pconfig['prefer'] = empty($pconfig['prefer']) ? "on" : "";
if (count($input_errors) == 0) {
$gps = array();
foreach ($copy_fields as $fieldname) {
if (!empty($pconfig[$fieldname])) {
$gps[$fieldname] = $pconfig[$fieldname];
}
}
$gps['initcmd']= base64_encode($gps['initcmd']);
$config['ntpd']['gps'] = $gps;
write_config("Updated NTP GPS Settings");
system_ntp_configure();
header("Location: services_ntpd_gps.php");
exit;
}
}
$pconfig = &$config['ntpd']['gps'];
$service_hook = 'ntpd';
legacy_html_escape_form_data($pconfig);
include("head.inc");
?>
<body>
<script type="text/javascript">
//<![CDATA[
function show_advanced(showboxID, configvalueID) {
document.getElementById(showboxID).innerHTML='';
aodiv = document.getElementById(configvalueID);
aodiv.style.display = "block";
}
function ToggleOther(clicked, checkOff) {
if (document.getElementById(clicked).checked) {
document.getElementById(checkOff).checked=false;
}
}
function show_advanced(showboxID, configvalueID) {
document.getElementById(showboxID).innerHTML='';
aodiv = document.getElementById(configvalueID);
aodiv.style.display = "block";
}
function ToggleOther(clicked, checkOff) {
if (document.getElementById(clicked).checked) {
document.getElementById(checkOff).checked=false;
}
}
/*
init commands are Base64 encoded
Default = #Sponsored, probably a Ublox
$PUBX,40,GSV,0,0,0,0*59
$PUBX,40,GLL,0,0,0,0*5C
$PUBX,40,ZDA,0,0,0,0*44
$PUBX,40,VTG,0,0,0,0*5E
$PUBX,40,GSV,0,0,0,0*59
$PUBX,40,GSA,0,0,0,0*4E
$PUBX,40,GGA,0,0,0,0
$PUBX,40,TXT,0,0,0,0
$PUBX,40,RMC,0,0,0,0*46
$PUBX,41,1,0007,0003,4800,0
$PUBX,40,ZDA,1,1,1,1
Generic = #do nothing
Garmin = #most Garmin
$PGRMC,,,,,,,,,,3,,2,4*52 #enable PPS @ 100ms
$PGRMC1,,1,,,,,,W,,,,,,,*30 #enable WAAS
$PGRMO,,3*74 #turn off all sentences
$PGRMO,GPRMC,1*3D #enable RMC
$PGRMO,GPGGA,1*20 #enable GGA
$PGRMO,GPGLL,1*26 #enable GLL
MediaTek = #Adafruit, Fastrax, some Garmin and others
$PMTK225,0*2B #normal power mode
$PMTK314,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0*28 #enable GLL, RMC, GGA and ZDA
$PMTK301,2*2E #enable WAAS
$PMTK320,0*2F #power save off
$PMTK330,0*2E #set WGS84 datum
$PMTK386,0*23 #disable static navigation (MT333X)
$PMTK397,0*23 #disable static navigation (MT332X)
$PMTK251,4800*14 #4800 baud rate
SiRF = #used by many devices
$PSRF103,00,00,01,01*25 #turn on GGA
$PSRF103,01,00,01,01*24 #turn on GLL
$PSRF103,02,00,00,01*24 #turn off GSA
$PSRF103,03,00,00,01*24 #turn off GSV
$PSRF103,04,00,01,01*24 #turn on RMC
$PSRF103,05,00,00,01*24 #turn off VTG
$PSRF100,1,4800,8,1,0*0E #set port to 4800,N,8,1
U-Blox = #U-Blox 5, 6 and probably 7
$PUBX,40,GGA,1,1,1,1,0,0*5A #turn on GGA all ports
$PUBX,40,GLL,1,1,1,1,0,0*5C #turn on GLL all ports
$PUBX,40,GSA,0,0,0,0,0,0*4E #turn off GSA all ports
$PUBX,40,GSV,0,0,0,0,0,0*59 #turn off GSV all ports
$PUBX,40,RMC,1,1,1,1,0,0*47 #turn on RMC all ports
$PUBX,40,VTG,0,0,0,0,0,0*5E #turn off VTG all ports
$PUBX,40,GRS,0,0,0,0,0,0*5D #turn off GRS all ports
$PUBX,40,GST,0,0,0,0,0,0*5B #turn off GST all ports
$PUBX,40,ZDA,1,1,1,1,0,0*44 #turn on ZDA all ports
$PUBX,40,GBS,0,0,0,0,0,0*4D #turn off GBS all ports
$PUBX,40,DTM,0,0,0,0,0,0*46 #turn off DTM all ports
$PUBX,40,GPQ,0,0,0,0,0,0*5D #turn off GPQ all ports
$PUBX,40,TXT,0,0,0,0,0,0*43 #turn off TXT all ports
$PUBX,40,THS,0,0,0,0,0,0*54 #turn off THS all ports (U-Blox 6)
$PUBX,41,1,0007,0003,4800,0*13 # set port 1 to 4800 baud
SureGPS = #Sure Electronics SKG16B
$PMTK225,0*2B
$PMTK314,1,1,0,1,0,5,0,0,0,0,0,0,0,0,0,0,0,1,0*2D
$PMTK301,2*2E
$PMTK397,0*23
$PMTK102*31
$PMTK313,1*2E
$PMTK513,1*28
$PMTK319,0*25
$PMTK527,0.00*00
$PMTK251,9600*17 #really needs to work at 9600 baud
Default = #Sponsored, probably a Ublox
$PUBX,40,GSV,0,0,0,0*59
$PUBX,40,GLL,0,0,0,0*5C
$PUBX,40,ZDA,0,0,0,0*44
$PUBX,40,VTG,0,0,0,0*5E
$PUBX,40,GSV,0,0,0,0*59
$PUBX,40,GSA,0,0,0,0*4E
$PUBX,40,GGA,0,0,0,0
$PUBX,40,TXT,0,0,0,0
$PUBX,40,RMC,0,0,0,0*46
$PUBX,41,1,0007,0003,4800,0
$PUBX,40,ZDA,1,1,1,1
Generic = #do nothing
Garmin = #most Garmin
$PGRMC,,,,,,,,,,3,,2,4*52 #enable PPS @ 100ms
$PGRMC1,,1,,,,,,W,,,,,,,*30 #enable WAAS
$PGRMO,,3*74 #turn off all sentences
$PGRMO,GPRMC,1*3D #enable RMC
$PGRMO,GPGGA,1*20 #enable GGA
$PGRMO,GPGLL,1*26 #enable GLL
MediaTek = #Adafruit, Fastrax, some Garmin and others
$PMTK225,0*2B #normal power mode
$PMTK314,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0*28 #enable GLL, RMC, GGA and ZDA
$PMTK301,2*2E #enable WAAS
$PMTK320,0*2F #power save off
$PMTK330,0*2E #set WGS84 datum
$PMTK386,0*23 #disable static navigation (MT333X)
$PMTK397,0*23 #disable static navigation (MT332X)
$PMTK251,4800*14 #4800 baud rate
SiRF = #used by many devices
$PSRF103,00,00,01,01*25 #turn on GGA
$PSRF103,01,00,01,01*24 #turn on GLL
$PSRF103,02,00,00,01*24 #turn off GSA
$PSRF103,03,00,00,01*24 #turn off GSV
$PSRF103,04,00,01,01*24 #turn on RMC
$PSRF103,05,00,00,01*24 #turn off VTG
$PSRF100,1,4800,8,1,0*0E #set port to 4800,N,8,1
U-Blox = #U-Blox 5, 6 and probably 7
$PUBX,40,GGA,1,1,1,1,0,0*5A #turn on GGA all ports
$PUBX,40,GLL,1,1,1,1,0,0*5C #turn on GLL all ports
$PUBX,40,GSA,0,0,0,0,0,0*4E #turn off GSA all ports
$PUBX,40,GSV,0,0,0,0,0,0*59 #turn off GSV all ports
$PUBX,40,RMC,1,1,1,1,0,0*47 #turn on RMC all ports
$PUBX,40,VTG,0,0,0,0,0,0*5E #turn off VTG all ports
$PUBX,40,GRS,0,0,0,0,0,0*5D #turn off GRS all ports
$PUBX,40,GST,0,0,0,0,0,0*5B #turn off GST all ports
$PUBX,40,ZDA,1,1,1,1,0,0*44 #turn on ZDA all ports
$PUBX,40,GBS,0,0,0,0,0,0*4D #turn off GBS all ports
$PUBX,40,DTM,0,0,0,0,0,0*46 #turn off DTM all ports
$PUBX,40,GPQ,0,0,0,0,0,0*5D #turn off GPQ all ports
$PUBX,40,TXT,0,0,0,0,0,0*43 #turn off TXT all ports
$PUBX,40,THS,0,0,0,0,0,0*54 #turn off THS all ports (U-Blox 6)
$PUBX,41,1,0007,0003,4800,0*13 # set port 1 to 4800 baud
SureGPS = #Sure Electronics SKG16B
$PMTK225,0*2B
$PMTK314,1,1,0,1,0,5,0,0,0,0,0,0,0,0,0,0,0,1,0*2D
$PMTK301,2*2E
$PMTK397,0*23
$PMTK102*31
$PMTK313,1*2E
$PMTK513,1*28
$PMTK319,0*25
$PMTK527,0.00*00
$PMTK251,9600*17 #really needs to work at 9600 baud
*/
function set_gps_default(form) {
//This handles a new config and also a reset to a defined default config
var gpsdef = new Object();
//get the text description of the selected type
var e = document.getElementById("gpstype");
var type = e.options[e.selectedIndex].value;
//stuff the JS object as needed for each type
switch(type) {
case "Default":
gpsdef['nmea'] = 0;
gpsdef['speed'] = 0;
gpsdef['fudge1'] = "0.155";
gpsdef['fudge2'] = "";
gpsdef['inittxt'] = "JFBVQlgsNDAsR1NWLDAsMCwwLDAqNTkNCiRQVUJYLDQwLEdMTCwwLDAsMCwwKjVDDQokUFVCWCw0MCxaREEsMCwwLDAsMCo0NA0KJFBVQlgsNDAsVlRHLDAsMCwwLDAqNUUNCiRQVUJYLDQwLEdTViwwLDAsMCwwKjU5DQokUFVCWCw0MCxHU0EsMCwwLDAsMCo0RQ0KJFBVQlgsNDAsR0dBLDAsMCwwLDANCiRQVUJYLDQwLFRYVCwwLDAsMCwwDQokUFVCWCw0MCxSTUMsMCwwLDAsMCo0Ng0KJFBVQlgsNDEsMSwwMDA3LDAwMDMsNDgwMCwwDQokUFVCWCw0MCxaREEsMSwxLDEsMQ0K";
break;
case "Garmin":
gpsdef['nmea'] = 0;
gpsdef['speed'] = 0;
gpsdef['fudge1'] = "";
gpsdef['fudge2'] = "0.600";
gpsdef['inittxt'] = "JFBHUk1DLCwsLCwsLCwsLDMsLDIsOCo1RQ0KJFBHUk1DMSwsMSwsLCwsLFcsLCwsLCwsKjMwDQokUEdSTU8sLDMqNzQNCiRQR1JNTyxHUFJNQywxKjNEDQokUEdSTU8sR1BHR0EsMSoyMA0KJFBHUk1PLEdQR0xMLDEqMjYNCg==";
break;
case "Generic":
gpsdef['nmea'] = 0;
gpsdef['speed'] = 0;
gpsdef['fudge1'] = "";
gpsdef['fudge2'] = "0.400";
gpsdef['inittxt'] = "";
break;
case "MediaTek":
gpsdef['nmea'] = 0;
gpsdef['speed'] = 0;
gpsdef['fudge1'] = "";
gpsdef['fudge2'] = "0.400";
gpsdef['inittxt'] = "JFBNVEsyMjUsMCoyQg0KJFBNVEszMTQsMSwxLDAsMSwwLDAsMCwwLDAsMCwwLDAsMCwwLDAsMCwwLDEsMCoyOA0KJFBNVEszMDEsMioyRQ0KJFBNVEszMjAsMCoyRg0KJFBNVEszMzAsMCoyRQ0KJFBNVEszODYsMCoyMw0KJFBNVEszOTcsMCoyMw0KJFBNVEsyNTEsNDgwMCoxNA0K";
break;
case "SiRF":
gpsdef['nmea'] = 0;
gpsdef['speed'] = 0;
gpsdef['fudge1'] = "";
gpsdef['fudge2'] = "0.704"; //valid for 4800, 0.688 @ 9600, 0.640 @ USB
gpsdef['inittxt'] = "JFBTUkYxMDMsMDAsMDAsMDEsMDEqMjUNCiRQU1JGMTAzLDAxLDAwLDAxLDAxKjI0DQokUFNSRjEwMywwMiwwMCwwMCwwMSoyNA0KJFBTUkYxMDMsMDMsMDAsMDAsMDEqMjQNCiRQU1JGMTAzLDA0LDAwLDAxLDAxKjI0DQokUFNSRjEwMywwNSwwMCwwMCwwMSoyNA0KJFBTUkYxMDAsMSw0ODAwLDgsMSwwKjBFDQo=";
break;
case "U-Blox":
gpsdef['nmea'] = 0;
gpsdef['speed'] = 0;
gpsdef['fudge1'] = "";
gpsdef['fudge2'] = "0.400";
gpsdef['inittxt'] = "JFBVQlgsNDAsR0dBLDEsMSwxLDEsMCwwKjVBDQokUFVCWCw0MCxHTEwsMSwxLDEsMSwwLDAqNUMNCiRQVUJYLDQwLEdTQSwwLDAsMCwwLDAsMCo0RQ0KJFBVQlgsNDAsR1NWLDAsMCwwLDAsMCwwKjU5DQokUFVCWCw0MCxSTUMsMSwxLDEsMSwwLDAqNDcNCiRQVUJYLDQwLFZURywwLDAsMCwwLDAsMCo1RQ0KJFBVQlgsNDAsR1JTLDAsMCwwLDAsMCwwKjVEDQokUFVCWCw0MCxHU1QsMCwwLDAsMCwwLDAqNUINCiRQVUJYLDQwLFpEQSwxLDEsMSwxLDAsMCo0NA0KJFBVQlgsNDAsR0JTLDAsMCwwLDAsMCwwKjREDQokUFVCWCw0MCxEVE0sMCwwLDAsMCwwLDAqNDYNCiRQVUJYLDQwLEdQUSwwLDAsMCwwLDAsMCo1RA0KJFBVQlgsNDAsVFhULDAsMCwwLDAsMCwwKjQzDQokUFVCWCw0MCxUSFMsMCwwLDAsMCwwLDAqNTQNCiRQVUJYLDQxLDEsMDAwNywwMDAzLDQ4MDAsMCoxMw0K";
break;
case "SureGPS":
gpsdef['nmea'] = 1;
gpsdef['speed'] = 16;
gpsdef['fudge1'] = "";
gpsdef['fudge2'] = "0.407";
gpsdef['inittxt'] = "JFBNVEsyMjUsMCoyQg0KJFBNVEszMTQsMSwxLDAsMSwwLDUsMCwwLDAsMCwwLDAsMCwwLDAsMCwwLDEsMCoyRA0KJFBNVEszMDEsMioyRQ0KJFBNVEszOTcsMCoyMw0KJFBNVEsxMDIqMzENCiRQTVRLMzEzLDEqMkUNCiRQTVRLNTEzLDEqMjgNCiRQTVRLMzE5LDAqMjUNCiRQTVRLNTI3LDAuMDAqMDANCiRQTVRLMjUxLDk2MDAqMTcNCg==";
break;
default:
return;
}
//then update the html and set the common stuff
document.getElementById("gpsnmea").selectedIndex = gpsdef['nmea'];
document.getElementById("gpsspeed").selectedIndex = gpsdef['speed'];
form.gpsfudge1.value = gpsdef['fudge1'];
form.gpsfudge2.value = gpsdef['fudge2'];
form.gpsstratum.value = "";
form.gpsrefid.value = "";
form.gpsspeed.value = gpsdef['speed'];
document.getElementById("gpsflag1").checked=true
document.getElementById("gpsflag2").checked=false
document.getElementById("gpsflag3").checked=true
document.getElementById("gpsflag4").checked=false
document.getElementById("gpssubsec").checked=false
form.gpsinitcmd.value = atob(gpsdef['inittxt']);
}
//function to compute a NMEA checksum derived from the public domain function at http://www.hhhh.org/wiml/proj/nmeaxor.html
function NMEAChecksum(cmd) {
// Compute the checksum by XORing all the character values in the string.
var checksum = 0;
for(var i = 0; i < cmd.length; i++) {
checksum = checksum ^ cmd.charCodeAt(i);
}
// Convert it to hexadecimal (base-16, upper case, most significant byte first).
var hexsum = Number(checksum).toString(16).toUpperCase();
if (hexsum.length < 2) {
hexsum = ("00" + hexsum).slice(-2);
}
// Display the result
document.getElementById("nmeachecksum").innerHTML = hexsum;
}
//]]>
</script>
<?php include("fbegin.inc"); ?>
function set_gps_default() {
//This handles a new config and also a reset to a defined default config
var gpsdef = new Object();
//get the text description of the selected type
var e = document.getElementById("gpstype");
var type = e.options[e.selectedIndex].value;
//stuff the JS object as needed for each type
switch(type) {
case "Default":
gpsdef['nmea'] = 0;
gpsdef['speed'] = 0;
gpsdef['fudge1'] = "0.155";
gpsdef['fudge2'] = "";
gpsdef['inittxt'] = "JFBVQlgsNDAsR1NWLDAsMCwwLDAqNTkNCiRQVUJYLDQwLEdMTCwwLDAsMCwwKjVDDQokUFVCWCw0MCxaREEsMCwwLDAsMCo0NA0KJFBVQlgsNDAsVlRHLDAsMCwwLDAqNUUNCiRQVUJYLDQwLEdTViwwLDAsMCwwKjU5DQokUFVCWCw0MCxHU0EsMCwwLDAsMCo0RQ0KJFBVQlgsNDAsR0dBLDAsMCwwLDANCiRQVUJYLDQwLFRYVCwwLDAsMCwwDQokUFVCWCw0MCxSTUMsMCwwLDAsMCo0Ng0KJFBVQlgsNDEsMSwwMDA3LDAwMDMsNDgwMCwwDQokUFVCWCw0MCxaREEsMSwxLDEsMQ0K";
break;
case "Garmin":
gpsdef['nmea'] = 0;
gpsdef['speed'] = 0;
gpsdef['fudge1'] = "";
gpsdef['fudge2'] = "0.600";
gpsdef['inittxt'] = "JFBHUk1DLCwsLCwsLCwsLDMsLDIsOCo1RQ0KJFBHUk1DMSwsMSwsLCwsLFcsLCwsLCwsKjMwDQokUEdSTU8sLDMqNzQNCiRQR1JNTyxHUFJNQywxKjNEDQokUEdSTU8sR1BHR0EsMSoyMA0KJFBHUk1PLEdQR0xMLDEqMjYNCg==";
break;
case "Generic":
gpsdef['nmea'] = 0;
gpsdef['speed'] = 0;
gpsdef['fudge1'] = "";
gpsdef['fudge2'] = "0.400";
gpsdef['inittxt'] = "";
break;
case "MediaTek":
gpsdef['nmea'] = 0;
gpsdef['speed'] = 0;
gpsdef['fudge1'] = "";
gpsdef['fudge2'] = "0.400";
gpsdef['inittxt'] = "JFBNVEsyMjUsMCoyQg0KJFBNVEszMTQsMSwxLDAsMSwwLDAsMCwwLDAsMCwwLDAsMCwwLDAsMCwwLDEsMCoyOA0KJFBNVEszMDEsMioyRQ0KJFBNVEszMjAsMCoyRg0KJFBNVEszMzAsMCoyRQ0KJFBNVEszODYsMCoyMw0KJFBNVEszOTcsMCoyMw0KJFBNVEsyNTEsNDgwMCoxNA0K";
break;
case "SiRF":
gpsdef['nmea'] = 0;
gpsdef['speed'] = 0;
gpsdef['fudge1'] = "";
gpsdef['fudge2'] = "0.704"; //valid for 4800, 0.688 @ 9600, 0.640 @ USB
gpsdef['inittxt'] = "JFBTUkYxMDMsMDAsMDAsMDEsMDEqMjUNCiRQU1JGMTAzLDAxLDAwLDAxLDAxKjI0DQokUFNSRjEwMywwMiwwMCwwMCwwMSoyNA0KJFBTUkYxMDMsMDMsMDAsMDAsMDEqMjQNCiRQU1JGMTAzLDA0LDAwLDAxLDAxKjI0DQokUFNSRjEwMywwNSwwMCwwMCwwMSoyNA0KJFBTUkYxMDAsMSw0ODAwLDgsMSwwKjBFDQo=";
break;
case "U-Blox":
gpsdef['nmea'] = 0;
gpsdef['speed'] = 0;
gpsdef['fudge1'] = "";
gpsdef['fudge2'] = "0.400";
gpsdef['inittxt'] = "JFBVQlgsNDAsR0dBLDEsMSwxLDEsMCwwKjVBDQokUFVCWCw0MCxHTEwsMSwxLDEsMSwwLDAqNUMNCiRQVUJYLDQwLEdTQSwwLDAsMCwwLDAsMCo0RQ0KJFBVQlgsNDAsR1NWLDAsMCwwLDAsMCwwKjU5DQokUFVCWCw0MCxSTUMsMSwxLDEsMSwwLDAqNDcNCiRQVUJYLDQwLFZURywwLDAsMCwwLDAsMCo1RQ0KJFBVQlgsNDAsR1JTLDAsMCwwLDAsMCwwKjVEDQokUFVCWCw0MCxHU1QsMCwwLDAsMCwwLDAqNUINCiRQVUJYLDQwLFpEQSwxLDEsMSwxLDAsMCo0NA0KJFBVQlgsNDAsR0JTLDAsMCwwLDAsMCwwKjREDQokUFVCWCw0MCxEVE0sMCwwLDAsMCwwLDAqNDYNCiRQVUJYLDQwLEdQUSwwLDAsMCwwLDAsMCo1RA0KJFBVQlgsNDAsVFhULDAsMCwwLDAsMCwwKjQzDQokUFVCWCw0MCxUSFMsMCwwLDAsMCwwLDAqNTQNCiRQVUJYLDQxLDEsMDAwNywwMDAzLDQ4MDAsMCoxMw0K";
break;
case "SureGPS":
gpsdef['nmea'] = 1;
gpsdef['speed'] = 16;
gpsdef['fudge1'] = "";
gpsdef['fudge2'] = "0.407";
gpsdef['inittxt'] = "JFBNVEsyMjUsMCoyQg0KJFBNVEszMTQsMSwxLDAsMSwwLDUsMCwwLDAsMCwwLDAsMCwwLDAsMCwwLDEsMCoyRA0KJFBNVEszMDEsMioyRQ0KJFBNVEszOTcsMCoyMw0KJFBNVEsxMDIqMzENCiRQTVRLMzEzLDEqMkUNCiRQTVRLNTEzLDEqMjgNCiRQTVRLMzE5LDAqMjUNCiRQTVRLNTI3LDAuMDAqMDANCiRQTVRLMjUxLDk2MDAqMTcNCg==";
break;
default:
return;
}
//then update the html and set the common stuff
$("#gpsnmea").val(gpsdef['nmea']);
$("#gpsspeed").val(gpsdef['speed']);
$("#gpsfudge1").val(gpsdef['fudge1']);
$("#gpsfudge2").val(gpsdef['fudge2']);
$("#gpsstratum").val("");
$("#gpsrefid").val("");
$("#gpsspeed").val(gpsdef['speed']);
$('#gpsflag1').prop('checked', true);
$('#gpsflag2').prop('checked', false);
$('#gpsflag3').prop('checked', true);
$('#gpsflag4').prop('checked', false);
$('#gpssubsec').prop('checked', false);
$("#gpsinitcmd").val(atob(gpsdef['inittxt']));
$("#gpsnmea").change();
$('.selectpicker').selectpicker('refresh');
}
//function to compute a NMEA checksum derived from the public domain function at http://www.hhhh.org/wiml/proj/nmeaxor.html
function NMEAChecksum(cmd) {
// Compute the checksum by XORing all the character values in the string.
var checksum = 0;
for (var i = 0; i < cmd.length; i++) {
checksum = checksum ^ cmd.charCodeAt(i);
}
// Convert it to hexadecimal (base-16, upper case, most significant byte first).
var hexsum = Number(checksum).toString(16).toUpperCase();
if (hexsum.length < 2) {
hexsum = ("00" + hexsum).slice(-2);
}
// Display the result
document.getElementById("nmeachecksum").innerHTML = hexsum;
}
$( document ).ready(function() {
$("#gpsnmea").change(function(){
var nmea_id = 0;
$("#gpsnmea option:selected").each(function(){
nmea_id = nmea_id + parseInt($(this).val());
});
$("#nmea").val(nmea_id);
});
$("#gpstype").change(set_gps_default);
});
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<?php if (isset($input_errors) && count($input_errors) > 0) print_input_errors($input_errors); ?>
<?php if (isset($savemsg)) print_info_box($savemsg); ?>
<section class="col-xs-12">
<div class="tab-content content-box col-xs-12">
<form action="services_ntpd_gps.php" method="post" name="iform" id="iform" accept-charset="utf-8">
<div class="table-responsive">
<table class="table table-striped">
<tr>
<td colspan="2" valign="top" class="listtopic"><?=gettext("NTP Serial GPS Configuration"); ?></td>
</tr>
<tr>
<td width="22%" valign="top" class="vncellreq">
</td>
<td width="78%" class="vtable"><?=gettext('A GPS connected via a serial port may be used as a reference clock for NTP. If the GPS also supports PPS and is properly configured, and connected, that GPS may also be used as a Pulse Per Second clock reference. NOTE: a USB GPS may work, but is not recommended due to USB bus timing issues.') ?>
<br />
<br /><?php echo gettext("For the best results, NTP should have at least three sources of time. So it is best to configure at least 2 servers under"); ?> <a href="services_ntpd.php"><?php echo gettext("Services > NTP"); ?></a> <?php echo gettext("to minimize clock drift if the GPS data is not valid over time. Otherwise ntpd may only use values from the unsynchronized local clock when providing time to clients."); ?>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext("GPS"); ?></td>
<td width="78%" valign="top" class="vtable">
<!-- 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)">
<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="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="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="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.");?>
<br />
<br />
<strong><?php echo gettext("Note: ");?></strong><?php echo gettext("Select Generic if your GPS is not listed."); ?><br />
<strong><?php echo gettext("Note: ");?></strong><?php echo gettext("The perdefined configurations assume your GPS has already been set to NMEA mode."); ?>
</td>
</tr>
<?php
/* Probing would be nice, but much more complex. Would need to listen to each port for 1s+ and watch for strings. */
$serialports = glob("/dev/cua?[0-9]{,.[0-9]}", GLOB_BRACE);
if (!empty($serialports)):
?>
<tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext('Serial port') ?></td>
<td width="78%" class="vtable">
<select name="gpsport" class="formselect">
<option value="">none</option>
<?php
foreach ($serialports as $port):
$shortport = substr($port,5);
$selected = '';
if (isset($pconfig['port']) && $shortport === $pconfig['port']) {
$selected = 'selected="selected"';
}
?>
<option value="<?php echo $shortport;?>"<?php echo $selected;?>><?php echo $shortport;?></option>
<?php endforeach; ?>
</select>&nbsp;
<?php echo gettext("All serial ports are listed, be sure to pick the port with the GPS attached."); ?>
<br /><br />
<select id="gpsspeed" name="gpsspeed" class="formselect">
<option value="0"<?php if(empty($pconfig['speed'])) echo " selected=\"selected\""; ?>>4800</option>
<option value="16"<?php if(isset($pconfig['speed']) && $pconfig['speed'] === '16') echo " selected=\"selected\"";?>>9600</option>
<option value="32"<?php if(isset($pconfig['speed']) && $pconfig['speed'] === '32') echo " selected=\"selected\"";?>>19200</option>
<option value="48"<?php if(isset($pconfig['speed']) && $pconfig['speed'] === '48') echo " selected=\"selected\"";?>>38400</option>
<option value="64"<?php if(isset($pconfig['speed']) && $pconfig['speed'] === '64') echo " selected=\"selected\"";?>>57600</option>
<option value="80"<?php if(isset($pconfig['speed']) && $pconfig['speed'] === '80') echo " selected=\"selected\"";?>>115200</option>
</select>&nbsp;<?php echo gettext("Serial port baud rate."); ?>
<br />
<br />
<?php echo gettext("Note: A higher baud rate is generally only helpful if the GPS is sending too many sentences. It is recommended to configure the GPS to send only one sentence at a baud rate of 4800 or 9600."); ?>
</td>
</tr>
<?php
endif;
?>
<tr>
<!-- 1 = RMC, 2 = GGA, 4 = GLL, 8 = ZDA or ZDG -->
<td width="22%" valign="top" class="vncellreq"><?=gettext('NMEA sentences') ?></td>
<td width="78%" class="vtable">
<select id="gpsnmea" name="gpsnmea[]" multiple="multiple" class="formselect" size="5">
<option value="0"<?php if(empty($pconfig['nmea'])) echo " selected=\"selected\""; ?>>All</option>
<option value="1"<?php if(isset($pconfig['nmea']) && $pconfig['nmea'] & 1) echo " selected=\"selected\"";?>>RMC</option>
<option value="2"<?php if(isset($pconfig['nmea']) && $pconfig['nmea'] & 2) echo " selected=\"selected\"";?>>GGA</option>
<option value="4"<?php if(isset($pconfig['nmea']) && $pconfig['nmea'] & 4) echo " selected=\"selected\"";?>>GLL</option>
<option value="8"<?php if(isset($pconfig['nmea']) && $pconfig['nmea'] & 8) echo " selected=\"selected\"";?>>ZDA or ZDG</option>
</select><br />
<?php echo gettext("By default NTP will listen for all supported NMEA sentences. Here one or more sentences to listen for may be specified."); ?>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext('Fudge time 1') ?></td>
<td width="78%" class="vtable">
<input name="gpsfudge1" type="text" class="formfld unknown" id="gpsfudge1" min="-1" max="1" size="20" value="<?=htmlspecialchars(isset($pconfig['fudge1'])?$pconfig['fudge1']:"");?>" />(<?php echo gettext("seconds");?>)<br />
<?php echo gettext("Fudge time 1 is used to specify the GPS PPS signal offset");?> (<?php echo gettext("default");?>: 0.0).</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext('Fudge time 2') ?></td>
<td width="78%" class="vtable">
<input name="gpsfudge2" type="text" class="formfld unknown" id="gpsfudge2" min="-1" max="1" size="20" value="<?=htmlspecialchars(isset($pconfig['fudge2'])?$pconfig['fudge2']:"");?>" />(<?php echo gettext("seconds");?>)<br />
<?php echo gettext("Fudge time 2 is used to specify the GPS time offset");?> (<?php echo gettext("default");?>: 0.0).</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext('Stratum') ?></td>
<td width="78%" class="vtable">
<input name="gpsstratum" type="text" class="formfld unknown" id="gpsstratum" max="16" size="20" value="<?=htmlspecialchars(isset($pconfig['stratum'])?$pconfig['stratum']:"");?>" /><?php echo gettext("(0-16)");?><br />
<?php echo gettext("This may be used to change the GPS Clock stratum");?> (<?php echo gettext("default");?>: 0). <?php echo gettext("This may be useful if, for some reason, you want ntpd to prefer a different clock"); ?></td>
</tr>
<tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext('Flags') ?></td>
<td width="78%" class="vtable">
<table>
<tr>
<td>
<?php echo gettext("Normally there should be no need to change these options from the defaults."); ?><br />
</td>
</tr>
</table>
<table>
<tr>
<td>
<input name="gpsprefer" type="checkbox" class="formcheckbox" id="gpsprefer" onclick="ToggleOther('gpsprefer', 'gpsselect')"<?php if(empty($pconfig['prefer'])) echo " checked=\"checked\""; ?> />
</td>
<td>
<span class="vexpl"><?php echo gettext("NTP should prefer this clock (default: enabled)."); ?></span>
</td>
</tr>
<tr>
<td>
<input name="gpsselect" type="checkbox" class="formcheckbox" id="gpsselect" onclick="ToggleOther('gpsselect', 'gpsprefer')"<?php if(!empty($pconfig['noselect'])) echo " checked=\"checked\""; ?> />
</td>
<td>
<span class="vexpl"><?php echo gettext("NTP should not use this clock, it will be displayed for reference only(default: disabled)."); ?></span>
</td>
</tr>
<tr>
<td>
<input name="gpsflag1" type="checkbox" class="formcheckbox" id="gpsflag1"<?php if(!empty($pconfig['flag1'])) echo " checked=\"checked\""; ?> />
</td>
<td>
<span class="vexpl"><?php echo gettext("Enable PPS signal processing (default: enabled)."); ?></span>
</td>
</tr>
<tr>
<td>
<input name="gpsflag2" type="checkbox" class="formcheckbox" id="gpsflag2"<?php if(!empty($pconfig['flag2'])) echo " checked=\"checked\""; ?> />
</td>
<td>
<span class="vexpl"><?php echo gettext("Enable falling edge PPS signal processing (default: rising edge)."); ?></span>
</td>
</tr>
<tr>
<td>
<input name="gpsflag3" type="checkbox" class="formcheckbox" id="gpsflag3"<?php if(!empty($pconfig['flag3'])) echo " checked=\"checked\""; ?> />
</td>
<td>
<span class="vexpl"><?php echo gettext("Enable kernel PPS clock discipline (default: enabled)."); ?></span>
</td>
</tr>
<tr>
<td>
<input name="gpsflag4" type="checkbox" class="formcheckbox" id="gpsflag4"<?php if(!empty($pconfig['flag4'])) echo " checked=\"checked\""; ?> />
</td>
<td>
<span class="vexpl"><?php echo gettext("Obscure location in timestamp (default: unobscured)."); ?></span>
</td>
</tr>
<tr>
<td>
<input name="gpssubsec" type="checkbox" class="formcheckbox" id="gpssubsec"<?php if(!empty($pconfig['subsec'])) echo " checked=\"checked\""; ?> />
</td>
<td>
<span class="vexpl"><?php echo gettext("Log the sub-second fraction of the received time stamp (default: Not logged).<br />Note: enabling this will rapidly fill the log, but is useful for tuning Fudge time 2."); ?></span>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext('Clock ID') ?></td>
<td width="78%" class="vtable">
<input name="gpsrefid" type="text" class="formfld unknown" id="gpsrefid" maxlength= "4" size="20" value="<?=htmlspecialchars(isset($pconfig['refid'])?$pconfig['refid']:"");?>" /><?php echo gettext("(1 to 4 charactors)");?><br />
<?php echo gettext("This may be used to change the GPS Clock ID");?> (<?php echo gettext("default");?>: GPS).</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext('GPS Initialization') ?></td>
<td width="78%" class="vtable">
<div id="showgpsinitbox">
<input type="button" onclick="show_advanced('showgpsinitbox', 'showgpsinit')" value="<?=gettext("Advanced");?>" /> - <?=gettext("Show GPS Initialization commands");?>
</div>
<div id="showgpsinit" style="display:none">
<p>
<textarea name="gpsinitcmd" class="formpre" id="gpsinitcmd" cols="65" rows="7"><?=htmlspecialchars(base64_decode(isset($pconfig['initcmd'])?$pconfig['initcmd']:"")); /*resultmatch*/?></textarea><br />
<?php echo gettext("Note: Commands entered here will be sent to the GPS during initialization. Please read and understand your GPS documentation before making any changes here.");?><br /><br />
<strong><?php echo gettext("NMEA checksum calculator");?>:</strong>
<br />
<?php echo gettext("Enter the text between &quot;$&quot; and &quot;*&quot; of a NMEA command string:");?><br /> $<input name="nmeastring" type="text" class="formfld unknown" id="nmeastring" size="30" value="" />*<span id="nmeachecksum"><?php echo gettext("checksum");?></span>&nbsp;&nbsp;
<input type="button" onclick="NMEAChecksum(nmeastring.value)" value="<?=gettext("Calculate NMEA checksum");?>" /><br /></p>
</div>
</td>
</tr>
<tr>
<td width="22%" valign="top">&nbsp;</td>
<td width="78%">
<input name="Submit" type="submit" class="btn btn-primary" value="<?=gettext("Save");?>" />
</td>
</tr>
</table>
</div>
</form>
</div>
</section>
</div>
</div>
</section>
<script type="text/javascript">
//<![CDATA[
set_gps_default(document.getElementById('iform'));
//]]>
</script>
<?php include("fbegin.inc"); ?>
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<?php if (isset($input_errors) && count($input_errors) > 0) print_input_errors($input_errors); ?>
<?php if (isset($savemsg)) print_info_box($savemsg); ?>
<section class="col-xs-12">
<div class="tab-content content-box col-xs-12">
<form method="post" name="iform" id="iform">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<td width="22%">
<strong><?=gettext("NTP Serial GPS Configuration"); ?></strong>
</td>
<td width="78%" align="right">
<small><?=gettext("full help"); ?> </small>
<i class="fa fa-toggle-off text-danger" style="cursor: pointer;" id="show_all_help_page" type="button"></i>
&nbsp;&nbsp;
</td>
</tr>
</thead>
<tbody>
<tr>
<td><a id="help_for_gps" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("GPS"); ?></td>
<td>
<!-- Start with the original "Default", list a "Generic" and then specific configs alphabetically -->
<select id="gpstype" name="type" class="formselect">
<option value="Generic" title="Generic"<?=empty($pconfig['type']) || $pconfig['type'] == 'Generic' ? " selected=\"selected\"" : "";?>><?=gettext('Generic') ?></option>
<option value="Default"<?=$pconfig['type'] == 'Default' ? " selected=\"selected\"" : ""; ?>><?=gettext('Default') ?></option>
<option value="Garmin" title="$PGRM... Most Garmin"<?=$pconfig['type'] == 'Garmin' ? " selected=\"selected\"" :"";?>><?=gettext('Garmin') ?></option>
<option value="MediaTek" title="$PMTK... Adafruit, Fastrax, some Garmin and others"<?=$pconfig['type'] == 'MediaTek' ? " selected=\"selected\"" :"";?>>MediaTek</option>
<option value="SiRF" title="$PSRF... Used by many devices"<?=$pconfig['type'] == 'sirf' ? " selected=\"selected\"" :"";?>><?=gettext('SiRF') ?></option>
<option value="U-Blox" title="$PUBX... U-Blox 5, 6 and probably 7"<?=$pconfig['type'] == 'U-Blox' ? " selected=\"selected\"" : "";?>><?=gettext('U-Blox') ?></option>
<option value="SureGPS" title="$PMTK... Sure Electronics SKG16B"<?=$pconfig['type'] == 'SureGPS' ? " selected=\"selected\"" : "";?>><?=gettext('SureGPS') ?></option>
<option value="Custom"<?=$pconfig['type'] == 'Custom' ? " selected=\"selected\"" : ""; ?>><?=gettext('Custom') ?></option>
</select>
<div class="hidden" for="help_for_gps">
<?=gettext("This option allows you to select a predefined configuration.");?>
<br />
<strong><?=gettext("Note: ");?></strong><?=gettext("Select Generic if your GPS is not listed."); ?><br />
<strong><?=gettext("Note: ");?></strong><?=gettext("The perdefined configurations assume your GPS has already been set to NMEA mode."); ?>
</div>
</td>
</tr>
<?php
/* Probing would be nice, but much more complex. Would need to listen to each port for 1s+ and watch for strings. */
$serialports = glob("/dev/cua?[0-9]{,.[0-9]}", GLOB_BRACE);
if (!empty($serialports)):?>
<tr>
<td><a id="help_for_gpsport" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext('Serial port') ?></td>
<td>
<select name="port" class="selectpicker">
<option value=""><?=gettext("none");?></option>
<?php
foreach ($serialports as $port):?>
<option value="<?=substr($port,5);?>" <?=substr($port,5) === $pconfig['port'] ? 'selected="selected"' : "";?>>
<?=substr($port,5);?>
</option>
<?php
endforeach; ?>
</select>
<div class="hidden" for="help_for_gpsport">
<?=gettext("All serial ports are listed, be sure to pick the port with the GPS attached."); ?>
</div>
<br/>
<?=gettext("Serial port baud rate."); ?><br />
<select id="gpsspeed" name="speed" class="selectpicker">
<option value="0" <?=empty($pconfig['speed']) ? " selected=\"selected\"" : ""; ?>>4800</option>
<option value="16" <?=$pconfig['speed'] === '16' ? " selected=\"selected\"" : "";?>>9600</option>
<option value="32" <?=$pconfig['speed'] === '32' ? " selected=\"selected\"" : "";?>>19200</option>
<option value="48" <?=$pconfig['speed'] === '48' ? " selected=\"selected\"" : "";?>>38400</option>
<option value="64" <?=$pconfig['speed'] === '64' ? " selected=\"selected\"" : "";?>>57600</option>
<option value="80" <?=$pconfig['speed'] === '80' ? " selected=\"selected\"" : "";?>>115200</option>
</select>
<div class="hidden" for="help_for_gpsport">
<?=gettext("Note: A higher baud rate is generally only helpful if the GPS is sending too many sentences. It is recommended to configure the GPS to send only one sentence at a baud rate of 4800 or 9600."); ?>
</div>
</td>
</tr>
<?php
endif;?>
<tr>
<!-- 1 = RMC, 2 = GGA, 4 = GLL, 8 = ZDA or ZDG -->
<td><a id="help_for_nmea" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext('NMEA sentences') ?></td>
<td>
<input type="hidden" name="nmea" value="<?=$pconfig['nmea'];?>" id="nmea">
<select id="gpsnmea" multiple="multiple" class="selectpicker">
<option value="0" <?=empty($pconfig['nmea']) ? " selected=\"selected\"" : ""; ?>><?=gettext("All");?></option>
<option value="1" <?=$pconfig['nmea'] & 1 ? " selected=\"selected\"" : "";?>><?=gettext("RMC");?></option>
<option value="2" <?=$pconfig['nmea'] & 2 ? " selected=\"selected\"" : "";?>><?=gettext("GGA");?></option>
<option value="4" <?=$pconfig['nmea'] & 4 ? " selected=\"selected\"" : "";?>><?=gettext("GLL");?></option>
<option value="8" <?=$pconfig['nmea'] & 8 ? " selected=\"selected\"" : "";?>><?=gettext("ZDA or ZDG");?></option>
</select>
<div class="hidden" for="help_for_nmea">
<?=gettext("By default NTP will listen for all supported NMEA sentences. Here one or more sentences to listen for may be specified."); ?>
</div>
</td>
</tr>
<tr>
<td><a id="help_for_fudge1" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext('Fudge time 1') ?> (<?=gettext("seconds");?>)</td>
<td>
<input name="fudge1" type="text" id="gpsfudge1" min="-1" max="1" size="20" value="<?=$pconfig['fudge1'];?>" />
<div class="hidden" for="help_for_fudge1">
<?=gettext("Fudge time 1 is used to specify the GPS PPS signal offset");?> (<?=gettext("default");?>: 0.0).
</div>
</tr>
<tr>
<td><a id="help_for_fudge2" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext('Fudge time 2') ?> (<?=gettext("seconds");?>) </td>
<td>
<input name="fudge2" type="text" id="gpsfudge2" min="-1" max="1" size="20" value="<?=$pconfig['fudge2'];?>" />
<div class="hidden" for="help_for_fudge2">
<?=gettext("Fudge time 2 is used to specify the GPS time offset");?> (<?=gettext("default");?>: 0.0).
</div>
</td>
</tr>
<tr>
<td><a id="help_for_stratum" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext('Stratum') ?></td>
<td>
<input name="stratum" type="text" id="gpsstratum" value="<?=$pconfig['stratum'];?>" />
<div class="hidden" for="help_for_stratum">
<?=gettext("(0-16)");?><br />
<?=gettext("This may be used to change the GPS Clock stratum");?> (<?=gettext("default");?>: 0). <?=gettext("This may be useful if, for some reason, you want ntpd to prefer a different clock"); ?>
</div>
</td>
</tr>
<tr>
<td><i class="fa fa-info-circle text-muted"></i> <?=gettext('Flags') ?></td>
<td>
<table class="table table-condensed">
<tr>
<td colspan="2">
<?=gettext("Normally there should be no need to change these options from the defaults."); ?><br />
</td>
</tr>
<tr>
<td>
<input name="prefer" type="checkbox" id="gpsprefer" onclick="ToggleOther('gpsprefer', 'gpsselect')"<?=empty($pconfig['prefer']) ? " checked=\"checked\"" : ""; ?> />
</td>
<td>
<?=gettext("NTP should prefer this clock (default: enabled)."); ?>
</td>
</tr>
<tr>
<td>
<input name="noselect" type="checkbox" id="gpsselect" onclick="ToggleOther('gpsselect', 'gpsprefer')"<?=!empty($pconfig['noselect']) ? " checked=\"checked\"" : ""; ?> />
</td>
<td>
<?=gettext("NTP should not use this clock, it will be displayed for reference only(default: disabled)."); ?>
</td>
</tr>
<tr>
<td>
<input name="flag1" type="checkbox" id="gpsflag1"<?=!empty($pconfig['flag1']) ? " checked=\"checked\"" : ""; ?> />
</td>
<td>
<?=gettext("Enable PPS signal processing (default: enabled)."); ?>
</td>
</tr>
<tr>
<td>
<input name="flag2" type="checkbox" id="gpsflag2"<?=!empty($pconfig['flag2']) ? " checked=\"checked\"" : ""; ?> />
</td>
<td>
<?=gettext("Enable falling edge PPS signal processing (default: rising edge)."); ?>
</td>
</tr>
<tr>
<td>
<input name="flag3" type="checkbox" id="gpsflag3"<?=!empty($pconfig['flag3']) ? " checked=\"checked\"" : ""; ?> />
</td>
<td>
<?=gettext("Enable kernel PPS clock discipline (default: enabled)."); ?>
</td>
</tr>
<tr>
<td>
<input name="flag4" type="checkbox" id="gpsflag4"<?=!empty($pconfig['flag4']) ? " checked=\"checked\"" : ""; ?> />
</td>
<td>
<?=gettext("Obscure location in timestamp (default: unobscured)."); ?>
</td>
</tr>
<tr>
<td>
<input name="subsec" type="checkbox" id="gpssubsec"<?=!empty($pconfig['subsec']) ? " checked=\"checked\"" : ""; ?> />
</td>
<td>
<?=gettext("Log the sub-second fraction of the received time stamp (default: Not logged).<br />Note: enabling this will rapidly fill the log, but is useful for tuning Fudge time 2."); ?>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td><a id="help_for_refid" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext('Clock ID') ?></td>
<td>
<input name="refid" type="text" id="gpsrefid" value="<?=$pconfig['refid'];?>" />
<div class="hidden" for="help_for_refid">
<?=gettext("(1 to 4 charactors)");?><br />
<?=gettext("This may be used to change the GPS Clock ID");?> (<?=gettext("default");?>: GPS).
</div>
</td>
</tr>
<tr>
<td><i class="fa fa-info-circle text-muted"></i> <?=gettext('GPS Initialization') ?></td>
<td>
<div id="showgpsinitbox">
<input type="button" onclick="show_advanced('showgpsinitbox', 'showgpsinit')" value="<?=gettext("Advanced");?>" /> - <?=gettext("Show GPS Initialization commands");?>
</div>
<div id="showgpsinit" style="display:none">
<textarea name="initcmd" class="formpre" id="gpsinitcmd" cols="65" rows="7"><?=base64_decode($pconfig['initcmd']);?></textarea><br />
<?=gettext("Note: Commands entered here will be sent to the GPS during initialization. Please read and understand your GPS documentation before making any changes here.");?><br /><br />
<strong><?=gettext("NMEA checksum calculator");?>:</strong>
<br />
<?=gettext("Enter the text between &quot;$&quot; and &quot;*&quot; of a NMEA command string:");?><br /> $<input name="nmeastring" type="text" id="nmeastring" size="30" value="" />*<span id="nmeachecksum"><?=gettext("checksum");?></span>&nbsp;&nbsp;
<input type="button" onclick="NMEAChecksum(nmeastring.value)" value="<?=gettext("Calculate NMEA checksum");?>" />
</div>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<input name="Submit" type="submit" class="btn btn-primary" value="<?=gettext("Save");?>" />
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="2">
<?=gettext('A GPS connected via a serial port may be used as a reference clock for NTP. If the GPS also supports PPS and is properly configured, and connected, that GPS may also be used as a Pulse Per Second clock reference. NOTE: a USB GPS may work, but is not recommended due to USB bus timing issues.') ?>
<br />
<br /><?=gettext("For the best results, NTP should have at least three sources of time. So it is best to configure at least 2 servers under"); ?> <a href="services_ntpd.php"><?=gettext("Services > NTP"); ?></a> <?=gettext("to minimize clock drift if the GPS data is not valid over time. Otherwise ntpd may only use values from the unsynchronized local clock when providing time to clients."); ?>
</td>
</tr>
</tfoot>
</table>
</div>
</form>
</div>
</section>
</div>
</div>
</section>
<?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