Project

General

Profile

Download (25.5 KB) Statistics
| Branch: | Tag: | Revision:
1 aa2aebfd nagyrobi
<?php
2
/* $Id$ */
3
/*
4
	Copyright (C) 2013	Dagorlad
5
	Copyright (C) 2012	Jim Pingle
6
	All rights reserved.
7
8
	Redistribution and use in source and binary forms, with or without
9
	modification, are permitted provided that the following conditions are met:
10
11
	1. Redistributions of source code must retain the above copyright notice,
12
	   this list of conditions and the following disclaimer.
13
14
	2. Redistributions in binary form must reproduce the above copyright
15
	   notice, this list of conditions and the following disclaimer in the
16
	   documentation and/or other materials provided with the distribution.
17
18
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
	POSSIBILITY OF SUCH DAMAGE.
28
*/
29
/*
30
	pfSense_MODULE:	ntpd_gps
31
*/
32
33
##|+PRIV
34
##|*IDENT=page-services-ntpd-gps
35
##|*NAME=Services: NTP Serial GPS page
36
##|*DESCR=Allow access to the 'Services: NTP Serial GPS' page..
37
##|*MATCH=services_ntpd_gps.php*
38
##|-PRIV
39
40 a3498099 Ermal
require_once("guiconfig.inc");
41 aa2aebfd nagyrobi
42
function set_default_gps() {
43 a3498099 Ermal
	global $config;
44
45
	if (!is_array($config['ntpd']))
46
		$config['ntpd'] = array();
47
	 if (is_array($config['ntpd']['gps']))
48
		unset($config['ntpd']['gps']);
49
50
	$config['ntpd']['gps'] = array();
51 aa2aebfd nagyrobi
	$config['ntpd']['gps']['type'] = 'Default';
52
	/* copy an existing configured GPS port if it exists, the unset may be uncommented post production */
53 a3498099 Ermal
	if (!empty($config['ntpd']['gpsport']) && empty($config['ntpd']['gps']['port'])) {
54 aa2aebfd nagyrobi
		$config['ntpd']['gps']['port'] = $config['ntpd']['gpsport'];
55 a3498099 Ermal
		unset($config['ntpd']['gpsport']); /* this removes the original port config from config.xml */
56
		$config['ntpd']['gps']['speed'] = 0;
57
		$config['ntpd']['gps']['nmea'] = 0;
58 aa2aebfd nagyrobi
	}
59 a3498099 Ermal
60
	write_config("Setting default NTPd settings");
61 aa2aebfd nagyrobi
}
62
63
if ($_POST) {
64
65
	unset($input_errors);
66
67
	if (!$input_errors) {
68
		if (!empty($_POST['gpsport']) && file_exists('/dev/'.$_POST['gpsport']))
69
			$config['ntpd']['gps']['port'] = $_POST['gpsport'];
70
		/* if port is not set, remove all the gps config */
71
		else unset($config['ntpd']['gps']);
72
73
		if (!empty($_POST['gpstype']))
74
			$config['ntpd']['gps']['type'] = $_POST['gpstype'];
75
		elseif (isset($config['ntpd']['gps']['type']))
76
			unset($config['ntpd']['gps']['type']);
77
78
		if (!empty($_POST['gpsspeed']))
79
			$config['ntpd']['gps']['speed'] = $_POST['gpsspeed'];
80
		elseif (isset($config['ntpd']['gps']['speed']))
81
			unset($config['ntpd']['gps']['speed']);
82
83
		if (!empty($_POST['gpsnmea']) && ($_POST['gpsnmea'][0] === "0"))
84
			$config['ntpd']['gps']['nmea'] = "0";
85
		else
86
			$config['ntpd']['gps']['nmea'] = strval(array_sum($_POST['gpsnmea']));
87
88
		if (!empty($_POST['gpsfudge1']))
89
			$config['ntpd']['gps']['fudge1'] = $_POST['gpsfudge1'];
90
		elseif (isset($config['ntpd']['gps']['fudge1']))
91
			unset($config['ntpd']['gps']['fudge1']);
92
93
		if (!empty($_POST['gpsfudge2']))
94
			$config['ntpd']['gps']['fudge2'] = $_POST['gpsfudge2'];
95
		elseif (isset($config['ntpd']['gps']['fudge2']))
96
			unset($config['ntpd']['gps']['fudge2']);
97
98
		if (!empty($_POST['gpsstratum']) && ($_POST['gpsstratum']) < 17 )
99
			$config['ntpd']['gps']['stratum'] = $_POST['gpsstratum'];
100
		elseif (isset($config['ntpd']['gps']['stratum']))
101
			unset($config['ntpd']['gps']['stratum']);
102
103
		if (empty($_POST['gpsprefer']))
104
			$config['ntpd']['gps']['prefer'] = 'on';
105
		elseif (isset($config['ntpd']['gps']['prefer']))
106
			unset($config['ntpd']['gps']['prefer']);
107
108
		if (!empty($_POST['gpsselect']))
109
			$config['ntpd']['gps']['noselect'] = $_POST['gpsselect'];
110
		elseif (isset($config['ntpd']['gps']['noselect']))
111
			unset($config['ntpd']['gps']['noselect']);
112
113
		if (!empty($_POST['gpsflag1']))
114
			$config['ntpd']['gps']['flag1'] = $_POST['gpsflag1'];
115
		elseif (isset($config['ntpd']['gps']['flag1']))
116
			unset($config['ntpd']['gps']['flag1']);
117
118
		if (!empty($_POST['gpsflag2']))
119
			$config['ntpd']['gps']['flag2'] = $_POST['gpsflag2'];
120
		elseif (isset($config['ntpd']['gps']['flag2']))
121
			unset($config['ntpd']['gps']['flag2']);
122
123
		if (!empty($_POST['gpsflag3']))
124
			$config['ntpd']['gps']['flag3'] = $_POST['gpsflag3'];
125
		elseif (isset($config['ntpd']['gps']['flag3']))
126
			unset($config['ntpd']['gps']['flag3']);
127
128
		if (!empty($_POST['gpsflag4']))
129
			$config['ntpd']['gps']['flag4'] = $_POST['gpsflag4'];
130
		elseif (isset($config['ntpd']['gps']['flag4']))
131
			unset($config['ntpd']['gps']['flag4']);
132
133
		if (!empty($_POST['gpssubsec']))
134
			$config['ntpd']['gps']['subsec'] = $_POST['gpssubsec'];
135
		elseif (isset($config['ntpd']['gps']['subsec']))
136
			unset($config['ntpd']['gps']['subsec']);
137
138
		if (!empty($_POST['gpsrefid']))
139
			$config['ntpd']['gps']['refid'] = $_POST['gpsrefid'];
140
		elseif (isset($config['ntpd']['gps']['refid']))
141
			unset($config['ntpd']['gps']['refid']);
142
			
143
		if (!empty($_POST['gpsinitcmd']))
144
			$config['ntpd']['gps']['initcmd'] = base64_encode($_POST['gpsinitcmd']);
145
		elseif (isset($config['ntpd']['gps']['initcmd']))
146
			unset($config['ntpd']['gps']['initcmd']);
147
148
		write_config("Updated NTP GPS Settings");
149
150
		$retval = 0;
151
		$retval = system_ntp_configure();
152
		$savemsg = get_std_save_message($retval);
153
	}
154 a3498099 Ermal
} else {
155 aa2aebfd nagyrobi
	/* set defaults if they do not already exist */
156 a3498099 Ermal
	if (!is_array($config['ntpd']) || !is_array($config['ntpd']['gps']) || empty($config['ntpd']['gps']['type'])) {
157 aa2aebfd nagyrobi
		set_default_gps();
158
	}
159
}
160
$pconfig = &$config['ntpd']['gps'];
161
162
$pgtitle = array(gettext("Services"),gettext("NTP GPS"));
163
$shortcut_section = "ntp";
164
include("head.inc");
165
?>
166
167
<script type="text/javascript">
168
169
	function show_advanced(showboxID, configvalueID) {
170
		document.getElementById(showboxID).innerHTML='';
171
		aodiv = document.getElementById(configvalueID);
172
		aodiv.style.display = "block";
173
	}
174
	
175
	function ToggleOther(clicked, checkOff) {
176
		if (document.getElementById(clicked).checked) {
177
			document.getElementById(checkOff).checked=false;
178
		}
179
	}
180
181
<?php /*	
182
init commands are Base64 encoded
183
Default =	#Sponsored, probably a Ublox
184
		$PUBX,40,GSV,0,0,0,0*59
185
		$PUBX,40,GLL,0,0,0,0*5C
186
		$PUBX,40,ZDA,0,0,0,0*44
187
		$PUBX,40,VTG,0,0,0,0*5E
188
		$PUBX,40,GSV,0,0,0,0*59
189
		$PUBX,40,GSA,0,0,0,0*4E
190
		$PUBX,40,GGA,0,0,0,0
191
		$PUBX,40,TXT,0,0,0,0
192
		$PUBX,40,RMC,0,0,0,0*46
193
		$PUBX,41,1,0007,0003,4800,0
194
		$PUBX,40,ZDA,1,1,1,1
195
196
Generic =					#do nothing
197
		
198
Garmin =	#most Garmin
199
		$PGRMC,,,,,,,,,,3,,2,4*52	#enable PPS @ 100ms
200
		$PGRMC1,,1,,,,,,W,,,,,,,*30	#enable WAAS
201
		$PGRMO,,3*74			#turn off all sentences
202
		$PGRMO,GPRMC,1*3D		#enable RMC
203
		$PGRMO,GPGGA,1*20		#enable GGA
204
		$PGRMO,GPGLL,1*26		#enable GLL
205
206
MediaTek =	#Adafruit, Fastrax, some Garmin and others
207
		$PMTK225,0*2B			#normal power mode
208
		$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
209
		$PMTK301,2*2E			#enable WAAS
210
		$PMTK320,0*2F			#power save off
211
		$PMTK330,0*2E			#set WGS84 datum
212
		$PMTK386,0*23			#disable static navigation (MT333X)
213
		$PMTK397,0*23			#disable static navigation (MT332X)
214
		$PMTK251,4800*14		#4800 baud rate
215
216
SiRF =		#used by many devices
217
 		$PSRF103,00,00,01,01*25		#turn on GGA
218
		$PSRF103,01,00,01,01*24		#turn on GLL
219
		$PSRF103,02,00,00,01*24		#turn off GSA
220
		$PSRF103,03,00,00,01*24		#turn off GSV
221
		$PSRF103,04,00,01,01*24		#turn on RMC
222
		$PSRF103,05,00,00,01*24		#turn off VTG
223
		$PSRF100,1,4800,8,1,0*0E	#set port to 4800,N,8,1
224
225
U-Blox =	#U-Blox 5, 6 and probably 7
226
		$PUBX,40,GGA,1,1,1,1,0,0*5A	#turn on GGA all ports
227
		$PUBX,40,GLL,1,1,1,1,0,0*5C	#turn on GLL all ports
228
		$PUBX,40,GSA,0,0,0,0,0,0*4E	#turn off GSA all ports
229
		$PUBX,40,GSV,0,0,0,0,0,0*59	#turn off GSV all ports
230
		$PUBX,40,RMC,1,1,1,1,0,0*47	#turn on RMC all ports
231
		$PUBX,40,VTG,0,0,0,0,0,0*5E	#turn off VTG all ports
232
		$PUBX,40,GRS,0,0,0,0,0,0*5D	#turn off GRS all ports
233
		$PUBX,40,GST,0,0,0,0,0,0*5B	#turn off GST all ports
234
		$PUBX,40,ZDA,1,1,1,1,0,0*44	#turn on ZDA all ports
235
		$PUBX,40,GBS,0,0,0,0,0,0*4D	#turn off GBS all ports
236
		$PUBX,40,DTM,0,0,0,0,0,0*46	#turn off DTM all ports
237
		$PUBX,40,GPQ,0,0,0,0,0,0*5D	#turn off GPQ all ports
238
		$PUBX,40,TXT,0,0,0,0,0,0*43	#turn off TXT all ports
239
		$PUBX,40,THS,0,0,0,0,0,0*54	#turn off THS all ports (U-Blox 6)
240
		$PUBX,41,1,0007,0003,4800,0*13	# set port 1 to 4800 baud
241
		
242
SureGPS = 		#Sure Electronics SKG16B
243
		$PMTK225,0*2B
244
		$PMTK314,1,1,0,1,0,5,0,0,0,0,0,0,0,0,0,0,0,1,0*2D
245
		$PMTK301,2*2E
246
		$PMTK397,0*23
247
		$PMTK102*31
248
		$PMTK313,1*2E
249
		$PMTK513,1*28
250
		$PMTK319,0*25
251
		$PMTK527,0.00*00
252
		$PMTK251,9600*17	#really needs to work at 9600 baud
253
		
254
*/ ?>
255
256
	function set_gps_default(form) {
257
		//This handles a new config and also a reset to a defined default config
258
		var gpsdef = new Object();
259
		//get the text description of the selected type
260
		var e = document.getElementById("gpstype");
261
		var type = e.options[e.selectedIndex].text;
262
263
		//stuff the JS object as needed for each type
264
		switch(type) {
265
			case "Default":
266
				gpsdef['nmea'] = 0;
267
				gpsdef['speed'] = 0;
268
				gpsdef['fudge1'] = "0.155";
269
				gpsdef['fudge2'] = "";
270
				gpsdef['inittxt'] = "JFBVQlgsNDAsR1NWLDAsMCwwLDAqNTkNCiRQVUJYLDQwLEdMTCwwLDAsMCwwKjVDDQokUFVCWCw0MCxaREEsMCwwLDAsMCo0NA0KJFBVQlgsNDAsVlRHLDAsMCwwLDAqNUUNCiRQVUJYLDQwLEdTViwwLDAsMCwwKjU5DQokUFVCWCw0MCxHU0EsMCwwLDAsMCo0RQ0KJFBVQlgsNDAsR0dBLDAsMCwwLDANCiRQVUJYLDQwLFRYVCwwLDAsMCwwDQokUFVCWCw0MCxSTUMsMCwwLDAsMCo0Ng0KJFBVQlgsNDEsMSwwMDA3LDAwMDMsNDgwMCwwDQokUFVCWCw0MCxaREEsMSwxLDEsMQ0K";
271
				break;
272
273
			case "Garmin":
274
				gpsdef['nmea'] = 0;
275
				gpsdef['speed'] = 0;
276
				gpsdef['fudge1'] = "";
277
				gpsdef['fudge2'] = "0.600";
278
				gpsdef['inittxt'] = "JFBHUk1DLCwsLCwsLCwsLDMsLDIsOCo1RQ0KJFBHUk1DMSwsMSwsLCwsLFcsLCwsLCwsKjMwDQokUEdSTU8sLDMqNzQNCiRQR1JNTyxHUFJNQywxKjNEDQokUEdSTU8sR1BHR0EsMSoyMA0KJFBHUk1PLEdQR0xMLDEqMjYNCg==";
279
				break;
280
								
281
			case "Generic":
282
				gpsdef['nmea'] = 0;
283
				gpsdef['speed'] = 0;
284
				gpsdef['fudge1'] = "";
285
				gpsdef['fudge2'] = "0.400";
286
				gpsdef['inittxt'] = "";
287
				break;
288
289
			case "MediaTek":
290
				gpsdef['nmea'] = 0;
291
				gpsdef['speed'] = 0;
292
				gpsdef['fudge1'] = "";
293
				gpsdef['fudge2'] = "0.400";
294
				gpsdef['inittxt'] = "JFBNVEsyMjUsMCoyQg0KJFBNVEszMTQsMSwxLDAsMSwwLDAsMCwwLDAsMCwwLDAsMCwwLDAsMCwwLDEsMCoyOA0KJFBNVEszMDEsMioyRQ0KJFBNVEszMjAsMCoyRg0KJFBNVEszMzAsMCoyRQ0KJFBNVEszODYsMCoyMw0KJFBNVEszOTcsMCoyMw0KJFBNVEsyNTEsNDgwMCoxNA0K";
295
				break;
296
297
			case "SiRF":
298
				gpsdef['nmea'] = 0;
299
				gpsdef['speed'] = 0;
300
				gpsdef['fudge1'] = "";
301
				gpsdef['fudge2'] = "0.704"; //valid for 4800, 0.688 @ 9600, 0.640 @ USB
302
				gpsdef['inittxt'] = "JFBTUkYxMDMsMDAsMDAsMDEsMDEqMjUNCiRQU1JGMTAzLDAxLDAwLDAxLDAxKjI0DQokUFNSRjEwMywwMiwwMCwwMCwwMSoyNA0KJFBTUkYxMDMsMDMsMDAsMDAsMDEqMjQNCiRQU1JGMTAzLDA0LDAwLDAxLDAxKjI0DQokUFNSRjEwMywwNSwwMCwwMCwwMSoyNA0KJFBTUkYxMDAsMSw0ODAwLDgsMSwwKjBFDQo=";
303
				break;
304
305
			case "U-Blox":
306
				gpsdef['nmea'] = 0;
307
				gpsdef['speed'] = 0;
308
				gpsdef['fudge1'] = "";
309
				gpsdef['fudge2'] = "0.400";
310
				gpsdef['inittxt'] = "JFBVQlgsNDAsR0dBLDEsMSwxLDEsMCwwKjVBDQokUFVCWCw0MCxHTEwsMSwxLDEsMSwwLDAqNUMNCiRQVUJYLDQwLEdTQSwwLDAsMCwwLDAsMCo0RQ0KJFBVQlgsNDAsR1NWLDAsMCwwLDAsMCwwKjU5DQokUFVCWCw0MCxSTUMsMSwxLDEsMSwwLDAqNDcNCiRQVUJYLDQwLFZURywwLDAsMCwwLDAsMCo1RQ0KJFBVQlgsNDAsR1JTLDAsMCwwLDAsMCwwKjVEDQokUFVCWCw0MCxHU1QsMCwwLDAsMCwwLDAqNUINCiRQVUJYLDQwLFpEQSwxLDEsMSwxLDAsMCo0NA0KJFBVQlgsNDAsR0JTLDAsMCwwLDAsMCwwKjREDQokUFVCWCw0MCxEVE0sMCwwLDAsMCwwLDAqNDYNCiRQVUJYLDQwLEdQUSwwLDAsMCwwLDAsMCo1RA0KJFBVQlgsNDAsVFhULDAsMCwwLDAsMCwwKjQzDQokUFVCWCw0MCxUSFMsMCwwLDAsMCwwLDAqNTQNCiRQVUJYLDQxLDEsMDAwNywwMDAzLDQ4MDAsMCoxMw0K";
311
				break;
312
313
			case "SureGPS":
314
				gpsdef['nmea'] = 0;
315
				gpsdef['speed'] = 16;
316
				gpsdef['fudge1'] = "";
317
				gpsdef['fudge2'] = "0.400";
318
				gpsdef['inittxt'] = "JFBNVEsyMjUsMCoyQg0KJFBNVEszMTQsMSwxLDAsMSwwLDUsMCwwLDAsMCwwLDAsMCwwLDAsMCwwLDEsMCoyRA0KJFBNVEszMDEsMioyRQ0KJFBNVEszOTcsMCoyMw0KJFBNVEsxMDIqMzENCiRQTVRLMzEzLDEqMkUNCiRQTVRLNTEzLDEqMjgNCiRQTVRLMzE5LDAqMjUNCiRQTVRLNTI3LDAuMDAqMDANCiRQTVRLMjUxLDk2MDAqMTcNCg==";
319
				break;
320
321
			}
322
323
		//then update the html and set the common stuff
324
		document.getElementById("gpsnmea").selectedIndex = gpsdef['nmea'];
325
		document.getElementById("gpsspeed").selectedIndex = gpsdef['speed'];
326
		form.gpsfudge1.value = gpsdef['fudge1'];
327
		form.gpsfudge2.value = gpsdef['fudge2'];
328
		form.gpsstratum.value = "";
329
		form.gpsrefid.value = "";
330
		form.gpsspeed.value = gpsdef['speed'];
331
		document.getElementById("gpsflag1").checked=true
332
		document.getElementById("gpsflag2").checked=false
333
		document.getElementById("gpsflag3").checked=true
334
		document.getElementById("gpsflag4").checked=false
335
		document.getElementById("gpssubsec").checked=false
336
		form.gpsinitcmd.value = atob(gpsdef['inittxt']);
337
	}
338
339
	//function to compute a NMEA checksum derived from the public domain function at http://www.hhhh.org/wiml/proj/nmeaxor.html
340
	function NMEAChecksum(cmd) {
341
		// Compute the checksum by XORing all the character values in the string.
342
		var checksum = 0;
343
		for(var i = 0; i < cmd.length; i++) {
344
			checksum = checksum ^ cmd.charCodeAt(i);
345
		}
346
		// Convert it to hexadecimal (base-16, upper case, most significant byte first).
347
		var hexsum = Number(checksum).toString(16).toUpperCase();
348
		if (hexsum.length < 2) {
349
			hexsum = ("00" + hexsum).slice(-2);
350
		}
351
		// Display the result
352
		document.getElementById("nmeachecksum").innerHTML = hexsum;
353
	}
354
355
</script>
356
357
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
358
<?php include("fbegin.inc"); ?>
359
<form action="services_ntpd_gps.php" method="post" name="iform" id="iform" accept-charset="utf-8">
360
<?php if ($input_errors) print_input_errors($input_errors); ?>
361
<?php if ($savemsg) print_info_box($savemsg); ?>
362
363
<table width="100%" border="0" cellpadding="0" cellspacing="0">
364
  <tr>
365
	<td>
366
<?php
367
	$tab_array = array();
368
	$tab_array[] = array(gettext("NTP"), false, "services_ntpd.php");
369
	$tab_array[] = array(gettext("Serial GPS"), true, "services_ntpd_gps.php");
370
	$tab_array[] = array(gettext("PPS"), false, "services_ntpd_pps.php");
371
	display_top_tabs($tab_array);
372
?>
373
	</td>
374
  </tr>
375
  <tr>
376
	<td>
377
	<div id="mainarea">
378
	<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
379
		<tr>
380
			<td colspan="2" valign="top" class="listtopic"><?=gettext("NTP Serial GPS Configuration"); ?></td>
381
		</tr>
382
		<tr>
383
			<td width="22%" valign="top" class="vncellreq">
384
			</td>
385
			<td width="78%" class="vtable">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.
386 8cd558b6 ayvis
			<br />
387
			<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."); ?>
388 aa2aebfd nagyrobi
			</td>
389
		</tr>
390
		<tr>
391
			<td width="22%" valign="top" class="vncellreq"><?=gettext("GPS"); ?></td>
392
			<td width="78%" valign="top" class="vtable">
393
			<?php /* Start with the original "Default", list a "Generic" and then specific configs alphabetically */ ?>
394
				<select id="gpstype" name="gpstype" class="formselect" onchange="set_gps_default(this.form)">
395
					<option value="Default"<?php if($pconfig['type'] == 'Default') echo ' selected'; ?>>Default</option>
396
					<option value="Generic" title="Generic"<?php if($pconfig['type'] == 'Generic') echo ' selected';?>>Generic</option>
397
					<option value="Garmin" title="$PGRM... Most Garmin"<?php if($pconfig['type'] == 'Garmin') echo ' selected';?>>Garmin</option>
398
					<option value="MediaTek" title="$PMTK... Adafruit, Fastrax, some Garmin and others"<?php if($pconfig['type'] == 'MediaTek') echo ' selected';?>>MediaTek</option>
399
					<option value="SiRF" title="$PSRF... Used by many devices"<?php if($pconfig['type'] == 'sirf') echo ' selected';?>>SiRF</option>
400
					<option value="U-Blox" title="$PUBX... U-Blox 5, 6 and probably 7"<?php if($pconfig['type'] == 'U-Blox') echo ' selected';?>>U-Blox</option>
401
					<option value="SureGPS" title="$PMTK... Sure Electronics SKG16B"<?php if($pconfig['type'] == 'SureGPS') echo ' selected';?>>SureGPS</option>
402
				</select> <?php echo gettext("This option allows you to select a predefined configuration.");?>
403 8cd558b6 ayvis
				<br />
404
				<br />
405 aa2aebfd nagyrobi
				<strong><?php echo gettext(" Note: ");?></strong><?php echo gettext("Default is the configuration of pfSense 2.1 and earlier"); ?>
406
				<?php echo gettext(" (not recommended). Select Generic if your GPS is not listed.)"); ?>
407
				<strong><?php echo gettext(" Note: ");?></strong><?php echo gettext("The perdefined configurations assume your GPS has already been set to NMEA mode."); ?>
408
			</td>
409
		</tr>
410
411
<?php /* Probing would be nice, but much more complex. Would need to listen to each port for 1s+ and watch for strings. */ ?>
412
<?php $serialports = glob("/dev/cua?[0-9]{,.[0-9]}", GLOB_BRACE); ?>
413
<?php if (!empty($serialports)): ?>
414
		<tr>
415
			<td width="22%" valign="top" class="vncellreq">Serial port</td>
416
			<td width="78%" class="vtable">
417
				<select name="gpsport" class="formselect">
418
					<option value="">none</option>
419
					<?php foreach ($serialports as $port):
420
						$shortport = substr($port,5);
421
						$selected = ($shortport == $pconfig['port']) ? " selected" : "";?>
422
						<option value="<?php echo $shortport;?>"<?php echo $selected;?>><?php echo $shortport;?></option>
423
					<?php endforeach; ?>
424
				</select>&nbsp;
425
				<?php echo gettext("All serial ports are listed, be sure to pick the port with the GPS attached."); ?>
426 8cd558b6 ayvis
				<br /><br />
427 aa2aebfd nagyrobi
				<select id="gpsspeed" name="gpsspeed" class="formselect">
428
					<option value="0"<?php if(!$pconfig['speed']) echo ' selected'; ?>>4800</option>
429
					<option value="16"<?php if($pconfig['speed'] === '16') echo ' selected';?>>9600</option>
430
					<option value="32"<?php if($pconfig['speed'] === '32') echo ' selected';?>>19200</option>
431
					<option value="48"<?php if($pconfig['speed'] === '48') echo ' selected';?>>38400</option>
432
					<option value="64"<?php if($pconfig['speed'] === '64') echo ' selected';?>>57600</option>
433
					<option value="80"<?php if($pconfig['speed'] === '80') echo ' selected';?>>115200</option>
434
				</select>&nbsp;<?php echo gettext("Serial port baud rate."); ?>
435 8cd558b6 ayvis
				<br />
436
				<br />
437 aa2aebfd nagyrobi
				<?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."); ?>
438
			</td>
439
		</tr>
440
<?php endif; ?>
441
		<tr>
442
<?php /* 1 = MRC, 2 = GGA, 4 = GLL, 8 = ZDA or ZDG */?>
443
			<td width="22%" valign="top" class="vncellreq">NMEA sentences</td>
444
			<td width="78%" class="vtable">
445
				<select id="gpsnmea" name="gpsnmea[]" multiple="true" class="formselect">
446
					<option value="0"<?php if(!$pconfig['nmea']) echo ' selected'; ?>>All</option>
447
					<option value="1"<?php if($pconfig['nmea'] & 1) echo ' selected';?>>MRC</option>
448
					<option value="2"<?php if($pconfig['nmea'] & 2) echo ' selected';?>>GGA</option>
449
					<option value="4"<?php if($pconfig['nmea'] & 4) echo ' selected';?>>GLL</option>
450
					<option value="8"<?php if($pconfig['nmea'] & 8) echo ' selected';?>>ZDA or ZDG</option>
451 8cd558b6 ayvis
				</select><br />
452 aa2aebfd nagyrobi
				<?php echo gettext("By default NTP will listen for all supported NMEA sentences. Here one or more sentences to listen for may be specified."); ?>
453
			</td>
454
		</tr>
455
		<tr>
456
			<td width="22%" valign="top" class="vncellreq">Fudge time 1</td>
457
			<td width="78%" class="vtable">
458 8cd558b6 ayvis
				<input name="gpsfudge1" type="text" class="formfld unknown" id="gpsfudge1" min="-1" max="1" size="20" value="<?=htmlspecialchars($pconfig['fudge1']);?>">(<?php echo gettext("seconds");?>)<br />
459 aa2aebfd nagyrobi
				<?php echo gettext("Fudge time 1 is used to specify the GPS PPS signal offset");?> (<?php echo gettext("default");?>: 0.0).</td>
460
		</tr>
461
		<tr>
462
			<td width="22%" valign="top" class="vncellreq">Fudge time 2</td>
463
			<td width="78%" class="vtable">
464 8cd558b6 ayvis
				<input name="gpsfudge2" type="text" class="formfld unknown" id="gpsfudge2" min="-1" max="1" size="20" value="<?=htmlspecialchars($pconfig['fudge2']);?>">(<?php echo gettext("seconds");?>)<br />
465 aa2aebfd nagyrobi
				<?php echo gettext("Fudge time 2 is used to specify the GPS time offset");?> (<?php echo gettext("default");?>: 0.0).</td>
466
		</tr>
467
		<tr>
468
			<td width="22%" valign="top" class="vncellreq">Stratum</td>
469
			<td width="78%" class="vtable">
470 8cd558b6 ayvis
				<input name="gpsstratum" type="text" class="formfld unknown" id="gpsstratum" max="16" size="20" value="<?=htmlspecialchars($pconfig['stratum']);?>"><?php echo gettext("(0-16)");?><br />
471 aa2aebfd nagyrobi
				<?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>
472
		</tr>
473
		<tr>
474
			<td width="22%" valign="top" class="vncellreq">Flags</td>
475
			<td width="78%" class="vtable">
476
				<table>
477
					<tr>
478
						<td>
479 8cd558b6 ayvis
				<?php echo gettext("Normally there should be no need to change these options from the defaults."); ?><br />
480 aa2aebfd nagyrobi
						</td>
481
					</tr>
482
				</table>
483
				<table>
484
					<tr>
485
						<td>
486
							<input name="gpsprefer" type="checkbox" class="formcheckbox" id="gpsprefer" OnClick="ToggleOther('gpsprefer', 'gpsselect')"<?php if(!$pconfig['prefer']) echo ' checked'; ?>>
487
						</td>
488
						<td>
489
							<span class="vexpl"><?php echo gettext("NTP should prefer this clock (default: enabled)."); ?></span>
490
						</td>
491
					</tr>
492
					<tr>
493
						<td>
494
							<input name="gpsselect" type="checkbox" class="formcheckbox" id="gpsselect" OnClick="ToggleOther('gpsselect', 'gpsprefer')"<?php if($pconfig['noselect']) echo ' checked'; ?>>
495
						</td>
496
						<td>
497
							<span class="vexpl"><?php echo gettext("NTP should not use this clock, it will be displayed for reference only(default: disabled)."); ?></span>
498
						</td>
499
					</tr>
500
					<tr>
501
						<td>
502
							<input name="gpsflag1" type="checkbox" class="formcheckbox" id="gpsflag1"<?php if($pconfig['flag1']) echo ' checked'; ?>>
503
						</td>
504
						<td>
505
							<span class="vexpl"><?php echo gettext("Enable PPS signal processing (default: enabled)."); ?></span>
506
						</td>
507
					</tr>
508
					<tr>
509
						<td>
510
							<input name="gpsflag2" type="checkbox" class="formcheckbox" id="gpsflag2"<?php if($pconfig['flag2']) echo ' checked'; ?>>
511
						</td>
512
						<td>
513
							<span class="vexpl"><?php echo gettext("Enable falling edge PPS signal processing (default: rising edge)."); ?></span>
514
						</td>
515
					</tr>
516
					<tr>
517
						<td>
518
							<input name="gpsflag3" type="checkbox" class="formcheckbox" id="gpsflag3"<?php if($pconfig['flag3']) echo ' checked'; ?>>
519
						</td>
520
						<td>
521
							<span class="vexpl"><?php echo gettext("Enable kernel PPS clock discipline (default: enabled)."); ?></span>
522
						</td>
523
					</tr>
524
					<tr>
525
						<td>
526
							<input name="gpsflag4" type="checkbox" class="formcheckbox" id="gpsflag4"<?php if($pconfig['flag4']) echo ' checked'; ?>>
527
						</td>
528
						<td>
529
							<span class="vexpl"><?php echo gettext("Obscure location in timestamp (default: unobscured)."); ?></span>
530
						</td>
531
					</tr>
532
					<tr>
533
						<td>
534
							<input name="gpssubsec" type="checkbox" class="formcheckbox" id="gpssubsec"<?php if($pconfig['subsec']) echo ' checked'; ?>>
535
						</td>
536
						<td>
537 8cd558b6 ayvis
							<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>
538 aa2aebfd nagyrobi
						</td>
539
					</tr>
540
				</table>
541
			</td>
542
		</tr>
543
		<tr>
544
			<td width="22%" valign="top" class="vncellreq">Clock ID</td>
545
			<td width="78%" class="vtable">
546 8cd558b6 ayvis
				<input name="gpsrefid" type="text" class="formfld unknown" id="gpsrefid" maxlength= "4" size="20" value="<?=htmlspecialchars($pconfig['refid']);?>"><?php echo gettext("(1 to 4 charactors)");?><br />
547 aa2aebfd nagyrobi
				<?php echo gettext("This may be used to change the GPS Clock ID");?> (<?php echo gettext("default");?>: GPS).</td>
548
		</tr>
549
		<tr>
550
			<td width="22%" valign="top" class="vncellreq">GPS Initialization</td>
551
			<td width="78%" class="vtable">
552
				<div id="showgpsinitbox">
553 91f026b0 ayvis
					<input type="button" onClick="show_advanced('showgpsinitbox', 'showgpsinit')" value="<?=gettext("Advanced");?>" /> - <?=gettext("Show GPS Initialization commands");?></a>
554 aa2aebfd nagyrobi
				</div>
555
				<div id="showgpsinit" style="display:none">
556
					<p>
557
					<textarea name="gpsinitcmd" class="formpre" id="gpsinitcmd" cols="65" rows="7"><?=htmlspecialchars(base64_decode($pconfig['initcmd'])); /*resultmatch*/?></textarea><br />
558
					<?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 />
559
					<strong><?php echo gettext("NMEA checksum calculator");?>:</strong>
560
					<br />
561
					<?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
562 91f026b0 ayvis
					<input type="button" onClick="NMEAChecksum(nmeastring.value)" value="<?=gettext("Calculate NMEA checksum");?>" /><br />
563 aa2aebfd nagyrobi
				</div>
564
			</td>
565
		</tr>
566
		<tr>
567
			<td width="22%" valign="top">&nbsp;</td>
568
			<td width="78%">
569
			<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>">
570
			</td>
571
		</tr>
572
	</table>
573
	</div>
574
	</td>
575
  </tr>
576
</table>
577 91f026b0 ayvis
<script type="text/javascript"><!-- set_gps_default(this.form); --></script>
578 aa2aebfd nagyrobi
</form>
579
<?php include("fend.inc"); ?>
580
</body>
581
</html>