Project

General

Profile

« Previous | Next » 

Revision d627983d

Added by Jack Booth over 8 years ago

Parse GPS initialization commands, extended status for GPSs other than SureGPS and make optional.
- Parse GPS initialization commands for explicitly configured GPS commands
- Add extended GPS status if GPGSV or GPGGA are explicitly configured
- Add config option to toggle extended status
- Clean up some variables on status page and widget.

View differences:

src/usr/local/www/services_ntpd_gps.php
52 52
	write_config(gettext("Setting default NTPd settings"));
53 53
}
54 54

  
55
function parse_ublox(&$nmeaset, $splitline) {
56
	$id_idx = 1;
57
	$msg_idx = 2;
58
	$ddc_idx = 3;
59
	if ($splitline[$id_idx] == '40' && $splitline[$ddc_idx]) {
60
		$nmeaset['GP' . $splitline[$msg_idx]] = 1;
61
	}
62
}
63

  
64
function parse_garmin(&$nmeaset, $splitline) {
65
	$msg_idx = 1;
66
	$mode_idx = 2;
67
	if ($splitline[$mode_idx] == '1') {
68
		$nmeaset[$splitline[$msg_idx]] = 1;
69
	}
70
}
71

  
72
function parse_mtk(&$nmeaset, $splitline) {
73
	$nmeamap = [
74
		1 => 'GPGLL',
75
		2 => 'GPRMC',
76
		3 => 'GPVTG',
77
		4 => 'GPGGA',
78
		5 => 'GPGSA',
79
		6 => 'GPGSV',
80
		7 => 'GPGRS',
81
		8 => 'GPGST',
82
	];
83
	for ($x = 1; $x < 9; $x++) {
84
		if($splitline[$x]) {
85
			$nmeaset[$nmeamap[$x]] = 1;
86
		}
87
	}
88
}
89

  
90
function parse_sirf(&$nmeaset, $splitline) {
91
	$msg_idx = 1;
92
	$mode_idx = 2;
93
	$rate_idx = 3;
94
	$nmeamap = [
95
		0 => 'GPGGA',
96
		1 => 'GPGLL',
97
		2 => 'GPGSA',
98
		3 => 'GPGSV',
99
		4 => 'GPRMC',
100
		5 => 'GPVTG',
101
	];
102
	if (!(int)$splitline[$mode_idx] && (int)$splitline[$rate_idx]) {
103
		$nmeaset[$nmeamap[(int)$splitline[$msg_idx]]] = 1;
104
	}
105
}
106

  
107
function parse_initcmd(&$nmeaset, $initcmd) {
108
	$type_idx = 0;
109
	$nmeaset = [];
110
	$split_initcmd = preg_split('/[\s]+/', $initcmd);
111
	foreach ($split_initcmd as $line) {
112
		$splitline = preg_split('/[,\*]+/', $line);
113
		if ($splitline[$type_idx] == '$PUBX') {
114
			parse_ublox($nmeaset, $splitline);
115
		} elseif ($splitline[$type_idx] == '$PGRMO') {
116
			parse_garmin($nmeaset, $splitline);
117
		} elseif ($splitline[$type_idx] == '$PMTK314') {
118
			parse_mtk($nmeaset, $splitline);
119
		} elseif ($splitline[$type_idx] == '$PSRF103') {
120
			parse_sirf($nmeaset, $splitline);
121
		}
122
	}
123
}
124

  
55 125
if ($_POST) {
56 126
	unset($input_errors);
57 127

  
......
146 216
		unset($config['ntpd']['gps']['refid']);
147 217
	}
148 218

  
219
	if (!empty($_POST['extstatus'])) {
220
		$config['ntpd']['gps']['extstatus'] = $_POST['extstatus'];
221
	} elseif (isset($config['ntpd']['gps']['extstatus'])) {
222
		unset($config['ntpd']['gps']['extstatus']);
223
	}
224

  
149 225
	if (!empty($_POST['gpsinitcmd'])) {
150 226
		$config['ntpd']['gps']['initcmd'] = base64_encode($_POST['gpsinitcmd']);
227
		parse_initcmd($config['ntpd']['gps']['nmeaset'], $_POST['gpsinitcmd']);
151 228
	} elseif (isset($config['ntpd']['gps']['initcmd'])) {
152 229
		unset($config['ntpd']['gps']['initcmd']);
230
		unset($config['ntpd']['gps']['nmeaset']);
153 231
	}
154 232

  
155 233
	write_config(gettext("Updated NTP GPS Settings"));
......
335 413
	$pconfig['subsec']
336 414
))->setHelp('Enabling this will rapidly fill the log, but is useful for tuning Fudge time 2.');
337 415

  
416
$section->addInput(new Form_Checkbox(
417
	'extstatus',
418
	null,
419
	'Display extended GPS status (default: checked).',
420
	$pconfig['extstatus']
421
))->setHelp('Enable extended GPS status if GPGSV or GPGGA are explicitly enabled by GPS initialization commands.');
422

  
338 423
$section->addInput(new Form_Input(
339 424
	'gpsrefid',
340 425
	'Clock ID',
......
509 594
		$('#gpsflag3').prop('checked', true);
510 595
		$('#gpsflag4').prop('checked', false);
511 596
		$('#gpssubsec').prop('checked', false);
597
		$('#extstatus').prop('checked', true);
512 598
	}
513 599

  
514 600
	// Show advanced GPS options ==============================================
src/usr/local/www/status_ntpd.php
103 103
				$gps_vars = explode(",", $tmp);
104 104
				$gps_ok = ($gps_vars[2] == "A");
105 105
				$gps_lat_deg = substr($gps_vars[3], 0, 2);
106
				$gps_lat_min = substr($gps_vars[3], 2) / 60.0;
106
				$gps_lat_min = substr($gps_vars[3], 2);
107 107
				$gps_lon_deg = substr($gps_vars[5], 0, 3);
108
				$gps_lon_min = substr($gps_vars[5], 3) / 60.0;
109
				$gps_lat = $gps_lat_deg + $gps_lat_min;
108
				$gps_lon_min = substr($gps_vars[5], 3);
109
				$gps_lat = $gps_lat_deg + $gps_lat_min / 60.0;
110 110
				$gps_lat = $gps_lat * (($gps_vars[4] == "N") ? 1 : -1);
111
				$gps_lon = $gps_lon_deg + $gps_lon_min;
111
				$gps_lon = $gps_lon_deg + $gps_lon_min / 60.0;
112 112
				$gps_lon = $gps_lon * (($gps_vars[6] == "E") ? 1 : -1);
113
				$gps_la = $gps_vars[4];
114
				$gps_lo = $gps_vars[6];
113
				$gps_lat_dir = $gps_vars[4];
114
				$gps_lon_dir = $gps_vars[6];
115 115
			} elseif (substr($tmp, 0, 6) == '$GPGGA') {
116 116
				$gps_vars = explode(",", $tmp);
117 117
				$gps_ok = $gps_vars[6];
118 118
				$gps_lat_deg = substr($gps_vars[2], 0, 2);
119
				$gps_lat_min = substr($gps_vars[2], 2) / 60.0;
119
				$gps_lat_min = substr($gps_vars[2], 2);
120 120
				$gps_lon_deg = substr($gps_vars[4], 0, 3);
121
				$gps_lon_min = substr($gps_vars[4], 3) / 60.0;
122
				$gps_lat = $gps_lat_deg + $gps_lat_min;
121
				$gps_lon_min = substr($gps_vars[4], 3);
122
				$gps_lat = $gps_lat_deg + $gps_lat_min / 60.0;
123 123
				$gps_lat = $gps_lat * (($gps_vars[3] == "N") ? 1 : -1);
124
				$gps_lon = $gps_lon_deg + $gps_lon_min;
124
				$gps_lon = $gps_lon_deg + $gps_lon_min / 60.0;
125 125
				$gps_lon = $gps_lon * (($gps_vars[5] == "E") ? 1 : -1);
126 126
				$gps_alt = $gps_vars[9];
127 127
				$gps_alt_unit = $gps_vars[10];
128 128
				$gps_sat = (int)$gps_vars[7];
129
				$gps_la = $gps_vars[3];
130
				$gps_lo = $gps_vars[5];
129
				$gps_lat_dir = $gps_vars[3];
130
				$gps_lon_dir = $gps_vars[5];
131 131
			} elseif (substr($tmp, 0, 6) == '$GPGLL') {
132 132
				$gps_vars = preg_split('/[,\*]+/', $tmp);
133 133
				$gps_ok = ($gps_vars[6] == "A");
134 134
				$gps_lat_deg = substr($gps_vars[1], 0, 2);
135
				$gps_lat_min = substr($gps_vars[1], 2) / 60.0;
135
				$gps_lat_min = substr($gps_vars[1], 2);
136 136
				$gps_lon_deg = substr($gps_vars[3], 0, 3);
137
				$gps_lon_min = substr($gps_vars[3], 3) / 60.0;
138
				$gps_lat = $gps_lat_deg + $gps_lat_min;
137
				$gps_lon_min = substr($gps_vars[3], 3);
138
				$gps_lat = $gps_lat_deg + $gps_lat_min / 60.0;
139 139
				$gps_lat = $gps_lat * (($gps_vars[2] == "N") ? 1 : -1);
140
				$gps_lon = $gps_lon_deg + $gps_lon_min;
140
				$gps_lon = $gps_lon_deg + $gps_lon_min / 60.0;
141 141
				$gps_lon = $gps_lon * (($gps_vars[4] == "E") ? 1 : -1);
142
				$gps_la = $gps_vars[2];
143
				$gps_lo = $gps_vars[4];
142
				$gps_lat_dir = $gps_vars[2];
143
				$gps_lon_dir = $gps_vars[4];
144 144
			}
145 145
		}
146 146
	}
147 147
}
148 148

  
149
if (isset($config['ntpd']['gps']['type']) && ($config['ntpd']['gps']['type'] == 'SureGPS') && (isset($gps_ok))) {
150
	//GSV message is only enabled by init commands in services_ntpd_gps.php for SureGPS board
151
	$gpsport = fopen("/dev/gps0", "r+");
152
	while ($gpsport) {
149
if (isset($gps_ok) && isset($config['ntpd']['gps']['extstatus']) && ($config['ntpd']['gps']['nmeaset']['gpgsv'] || $config['ntpd']['gps']['nmeaset']['gpgga'])) {
150
	$lookfor['GPGSV'] = $config['ntpd']['gps']['nmeaset']['gpgsv'];
151
	$lookfor['GPGGA'] = !isset($gps_sat) && $config['ntpd']['gps']['nmeaset']['gpgga'];
152
	$gpsport = fopen('/dev/gps0', 'r+');
153
	while ($gpsport && ($lookfor['GPGSV'] || $lookfor['GPGGA'])) {
153 154
		$buffer = fgets($gpsport);
154
		if (substr($buffer, 0, 6) == '$GPGSV') {
155
			//echo $buffer."\n";
155
		if ($lookfor['GPGSV'] && substr($buffer, 0, 6) == '$GPGSV') {
156 156
			$gpgsv = explode(',', $buffer);
157
			$gps_satview = $gpgsv[3];
158
			break;
157
			$gps_satview = (int)$gpgsv[3];
158
			$lookfor['GPGSV'] = 0;
159
		} elseif ($lookfor['GPGGA'] && substr($buffer, 0, 6) == '$GPGGA') {
160
			$gpgga = explode(',', $buffer);
161
			$gps_sat = (int)$gpgga[7];
162
			$gps_alt = $gpgga[9];
163
			$gps_alt_unit = $gpgga[10];
164
			$lookfor['GPGGA'] = 0;
159 165
		}
160 166
	}
161 167
}
......
211 217
}
212 218

  
213 219
function print_gps() {
214
	global 	$gps_lat, $gps_lon, $gps_lat_deg, $gps_lon_deg, $gps_lat_min, $gps_lon_min, $gps_la, $gps_lo,
220
	global 	$gps_lat, $gps_lon, $gps_lat_deg, $gps_lon_deg, $gps_lat_min, $gps_lon_min, $gps_lat_dir, $gps_lon_dir,
215 221
			$gps_alt, $gps_alt_unit, $gps_sat, $gps_satview, $gps_goo_lnk;
216 222

  
217 223
	print("<tr>\n");
......
219 225
	printf("%.5f", $gps_lat);
220 226
	print(" (");
221 227
	printf("%d%s", $gps_lat_deg, "&deg;");
222
	printf("%.5f", $gps_lat_min*60);
223
	print($gps_la);
228
	printf("%.5f", $gps_lat_min);
229
	print($gps_lat_dir);
224 230
	print(")");
225 231
	print("</td>\n");
226 232
	print("<td>\n");
227 233
	printf("%.5f", $gps_lon);
228 234
	print(" (");
229 235
	printf("%d%s", $gps_lon_deg, "&deg;");
230
	printf("%.5f", $gps_lon_min*60);
231
	print($gps_lo);
236
	printf("%.5f", $gps_lon_min);
237
	print($gps_lon_dir);
232 238
	print(")");
233 239
	print("</td>\n");
234 240

  
src/usr/local/www/widgets/widgets/ntp_status.widget.php
83 83
				$gps_vars = explode(",", $tmp);
84 84
				$gps_ok	= ($gps_vars[2] == "A");
85 85
				$gps_lat_deg = substr($gps_vars[3], 0, 2);
86
				$gps_lat_min = substr($gps_vars[3], 2) / 60.0;
86
				$gps_lat_min = substr($gps_vars[3], 2);
87 87
				$gps_lon_deg = substr($gps_vars[5], 0, 3);
88
				$gps_lon_min = substr($gps_vars[5], 3) / 60.0;
89
				$gps_lat = $gps_lat_deg + $gps_lat_min;
88
				$gps_lon_min = substr($gps_vars[5], 3);
89
				$gps_lat = $gps_lat_deg + $gps_lat_min / 60.0;
90 90
				$gps_lat = $gps_lat * (($gps_vars[4] == "N") ? 1 : -1);
91
				$gps_lon = $gps_lon_deg + $gps_lon_min;
91
				$gps_lon = $gps_lon_deg + $gps_lon_min / 60.0;
92 92
				$gps_lon = $gps_lon * (($gps_vars[6] == "E") ? 1 : -1);
93
				$gps_la = $gps_vars[4];
94
				$gps_lo = $gps_vars[6];
93
				$gps_lat_dir = $gps_vars[4];
94
				$gps_lon_dir = $gps_vars[6];
95 95
			} elseif (substr($tmp, 0, 6) == '$GPGGA') {
96 96
				$gps_vars = explode(",", $tmp);
97 97
				$gps_ok	= $gps_vars[6];
98 98
				$gps_lat_deg = substr($gps_vars[2], 0, 2);
99
				$gps_lat_min = substr($gps_vars[2], 2) / 60.0;
99
				$gps_lat_min = substr($gps_vars[2], 2);
100 100
				$gps_lon_deg = substr($gps_vars[4], 0, 3);
101
				$gps_lon_min = substr($gps_vars[4], 3) / 60.0;
102
				$gps_lat = $gps_lat_deg + $gps_lat_min;
101
				$gps_lon_min = substr($gps_vars[4], 3);
102
				$gps_lat = $gps_lat_deg + $gps_lat_min / 60.0;
103 103
				$gps_lat = $gps_lat * (($gps_vars[3] == "N") ? 1 : -1);
104
				$gps_lon = $gps_lon_deg + $gps_lon_min;
104
				$gps_lon = $gps_lon_deg + $gps_lon_min / 60.0;
105 105
				$gps_lon = $gps_lon * (($gps_vars[5] == "E") ? 1 : -1);
106 106
				$gps_alt = $gps_vars[9];
107 107
				$gps_alt_unit = $gps_vars[10];
108 108
				$gps_sat = (int)$gps_vars[7];
109
				$gps_la = $gps_vars[3];
110
				$gps_lo = $gps_vars[5];
109
				$gps_lat_dir = $gps_vars[3];
110
				$gps_lon_dir = $gps_vars[5];
111 111
			} elseif (substr($tmp, 0, 6) == '$GPGLL') {
112 112
				$gps_vars = preg_split('/[,\*]+/', $tmp);
113 113
				$gps_ok	= ($gps_vars[6] == "A");
114 114
				$gps_lat_deg = substr($gps_vars[1], 0, 2);
115
				$gps_lat_min = substr($gps_vars[1], 2) / 60.0;
115
				$gps_lat_min = substr($gps_vars[1], 2);
116 116
				$gps_lon_deg = substr($gps_vars[3], 0, 3);
117
				$gps_lon_min = substr($gps_vars[3], 3) / 60.0;
118
				$gps_lat = $gps_lat_deg + $gps_lat_min;
117
				$gps_lon_min = substr($gps_vars[3], 3);
118
				$gps_lat = $gps_lat_deg + $gps_lat_min / 60.0;
119 119
				$gps_lat = $gps_lat * (($gps_vars[2] == "N") ? 1 : -1);
120
				$gps_lon = $gps_lon_deg + $gps_lon_min;
120
				$gps_lon = $gps_lon_deg + $gps_lon_min / 60.0;
121 121
				$gps_lon = $gps_lon * (($gps_vars[4] == "E") ? 1 : -1);
122
				$gps_la = $gps_vars[2];
123
				$gps_lo = $gps_vars[4];
122
				$gps_lat_dir = $gps_vars[2];
123
				$gps_lon_dir = $gps_vars[4];
124 124
			}
125 125
		}
126 126
	}
127 127

  
128
	if (isset($config['ntpd']['gps']['type']) && ($config['ntpd']['gps']['type'] == 'SureGPS') && (isset($gps_ok))) {
129
		//GSV message is only enabled by init commands in services_ntpd_gps.php for SureGPS board
130
		$gpsport = fopen("/dev/gps0", "r+");
131
		while ($gpsport) {
128
	if (isset($gps_ok) && isset($config['ntpd']['gps']['extstatus']) && ($config['ntpd']['gps']['nmeaset']['gpgsv'] || $config['ntpd']['gps']['nmeaset']['gpgga'])) {
129
		$lookfor['GPGSV'] = $config['ntpd']['gps']['nmeaset']['gpgsv'];
130
		$lookfor['GPGGA'] = !isset($gps_sat) && $config['ntpd']['gps']['nmeaset']['gpgga'];
131
		$gpsport = fopen('/dev/gps0', 'r+');
132
		while ($gpsport && ($lookfor['GPGSV'] || $lookfor['GPGGA'])) {
132 133
			$buffer = fgets($gpsport);
133
			if (substr($buffer, 0, 6) == '$GPGSV') {
134
				//echo $buffer."\n";
134
			if ($lookfor['GPGSV'] && substr($buffer, 0, 6) == '$GPGSV') {
135 135
				$gpgsv = explode(',', $buffer);
136
				$gps_satview = $gpgsv[3];
137
				break;
136
				$gps_satview = (int)$gpgsv[3];
137
				$lookfor['GPGSV'] = 0;
138
			} elseif ($lookfor['GPGGA'] && substr($buffer, 0, 6) == '$GPGGA') {
139
				$gpgga = explode(',', $buffer);
140
				$gps_sat = (int)$gpgga[7];
141
				$gps_alt = $gpgga[9];
142
				$gps_alt_unit = $gpgga[10];
143
				$lookfor['GPGGA'] = 0;
138 144
			}
139 145
		}
140 146
	}
......
169 175
			<td>
170 176
				<a target="_gmaps" href="http://maps.google.com/?q=<?=$gps_lat;?>,<?=$gps_lon;?>">
171 177
				<?php
172
				echo sprintf("%.5f", $gps_lat) . " " . $gps_la . ", " . sprintf("%.5f", $gps_lon) . " " . $gps_lo; ?>
178
				echo sprintf("%.5f", $gps_lat) . " " . $gps_lat_dir . ", " . sprintf("%.5f", $gps_lon) . " " . $gps_lon_dir; ?>
173 179
				</a>
174 180
				<?php if (isset($gps_alt)) {echo " (" . $gps_alt . " " . $gps_alt_unit . " alt.)";} ?>
175 181
			</td>

Also available in: Unified diff