Revision c977d6b1
Added by Jack Booth over 8 years ago
src/usr/local/www/services_ntpd_gps.php | ||
---|---|---|
154 | 154 |
} |
155 | 155 |
} |
156 | 156 |
|
157 |
function NMEAChecksum($cmd) { |
|
158 |
$checksum = 0; |
|
159 |
for ($i=0; $i<strlen($cmd); $i++) { |
|
160 |
$checksum = ($checksum ^ ord($cmd[$i])); |
|
161 |
} |
|
162 |
return strtoupper(str_pad(dechex($checksum), 2, '0', STR_PAD_LEFT)); |
|
163 |
} |
|
164 |
|
|
165 |
function autocorrect_initcmd($initcmd) { |
|
166 |
$cmds = ''; |
|
167 |
$split_initcmd = preg_split('/[\s]+/', $initcmd); |
|
168 |
foreach ($split_initcmd as $line) { |
|
169 |
if (!strlen($line)) { |
|
170 |
continue; |
|
171 |
} |
|
172 |
$begin = ($line[0] == '$') ? 1 : 0; |
|
173 |
$astpos = strrpos($line, '*'); |
|
174 |
$end = ($astpos !== false) ? $astpos : strlen($line); |
|
175 |
$trimline = substr($line, $begin, $end-$begin); |
|
176 |
$cmds = $cmds . '$' . $trimline . '*' . NMEAChecksum($trimline) . "\r\n"; |
|
177 |
} |
|
178 |
return $cmds; |
|
179 |
} |
|
180 |
|
|
157 | 181 |
if ($_POST) { |
158 | 182 |
unset($input_errors); |
159 | 183 |
|
... | ... | |
254 | 278 |
unset($config['ntpd']['gps']['extstatus']); |
255 | 279 |
} |
256 | 280 |
|
281 |
if (!empty($_POST['autocorrect_initcmd'])) { |
|
282 |
$config['ntpd']['gps']['autocorrect_initcmd'] = $_POST['autocorrect_initcmd']; |
|
283 |
} elseif (isset($config['ntpd']['gps']['autocorrect_initcmd'])) { |
|
284 |
unset($config['ntpd']['gps']['autocorrect_initcmd']); |
|
285 |
} |
|
286 |
|
|
257 | 287 |
if (!empty($_POST['gpsinitcmd'])) { |
258 |
$config['ntpd']['gps']['initcmd'] = base64_encode($_POST['gpsinitcmd']); |
|
259 |
parse_initcmd($config['ntpd']['gps']['nmeaset'], $_POST['gpsinitcmd']); |
|
288 |
$initcmd = $_POST['gpsinitcmd']; |
|
289 |
if ($config['ntpd']['gps']['autocorrect_initcmd']) { |
|
290 |
$initcmd = autocorrect_initcmd($initcmd); |
|
291 |
} |
|
292 |
$config['ntpd']['gps']['initcmd'] = base64_encode($initcmd); |
|
293 |
parse_initcmd($config['ntpd']['gps']['nmeaset'], $initcmd); |
|
260 | 294 |
} elseif (isset($config['ntpd']['gps']['initcmd'])) { |
261 | 295 |
unset($config['ntpd']['gps']['initcmd']); |
262 | 296 |
unset($config['ntpd']['gps']['nmeaset']); |
... | ... | |
475 | 509 |
base64_decode($pconfig['initcmd']) |
476 | 510 |
))->setHelp('Commands entered here will be sent to the GPS during initialization. Please read and understand the GPS documentation before making any changes here.'); |
477 | 511 |
|
512 |
$section->addInput(new Form_Checkbox( |
|
513 |
'autocorrect_initcmd', |
|
514 |
null, |
|
515 |
'Auto correct malformed initialization commands. (default: checked).', |
|
516 |
$pconfig['autocorrect_initcmd'] |
|
517 |
))->setHelp('Calculates and appends checksum and missing special characters "$" and "*". Disable if causing errors.'); |
|
518 |
|
|
478 | 519 |
$group = new Form_Group('NMEA Checksum Calculator'); |
479 | 520 |
|
480 | 521 |
$group->add(new Form_Input( |
... | ... | |
621 | 662 |
$('#gpsflag4').prop('checked', false); |
622 | 663 |
$('#gpssubsec').prop('checked', false); |
623 | 664 |
$('#extstatus').prop('checked', true); |
665 |
$('#autocorrect_initcmd').prop('checked', true); |
|
624 | 666 |
} |
625 | 667 |
|
626 | 668 |
// Show advanced GPS options ============================================== |
... | ... | |
644 | 686 |
} |
645 | 687 |
|
646 | 688 |
hideInput('gpsinitcmd', !showadvgps); |
689 |
hideInput('autocorrect_initcmd', !showadvgps); |
|
647 | 690 |
hideClass('calculator', !showadvgps); |
648 | 691 |
|
649 | 692 |
if (showadvgps) { |
Also available in: Unified diff
Feature #7159 Add GPS initialization command auto correct tool
Corrects malformed NMEA sentences by calculating and appending the checksum and adding missing special characters "$" and "*"
(cherry picked from commit 8c23d92a159c1282e7d185665977f0c45d45f845)