New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NTPd Autoset GPS device baud rate. Issue #7284 #4213
Conversation
041c48f
to
3185148
Compare
src/etc/inc/system.inc
Outdated
usleep(1000); | ||
// Set timeout to 5s | ||
$timeout=microtime(true)+5; | ||
if($fp = fopen($device, 'r')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a space between if
and (
src/etc/inc/system.inc
Outdated
$c = fread($fp, $buffersize - $cnt); | ||
|
||
// Wait for data to arive | ||
if($c === false || strlen($c) == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a space between if
and (
.
Each test in the if
needs its own set of parenthesis.
src/etc/inc/system.inc
Outdated
|
||
$contents.=$c; | ||
$cnt = $cnt + strlen($c); | ||
} while($cnt < $buffersize && microtime(true)<$timeout); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a space between while
and (
.
Needs spaces around <
in the second test.
Each test needs its own set of parenthesis.
src/etc/inc/system.inc
Outdated
|
||
$nmeasentences = ['RMC', 'GGA', 'GLL', 'ZDA', 'ZDG', 'PGRMF']; | ||
foreach ($nmeasentences as $sentence) { | ||
if(strpos($contents, $sentence) > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a space between if
and (
src/etc/inc/system.inc
Outdated
if (strpos($contents, '0') > 0) { | ||
$filters = ['`', '?', '/', '~']; | ||
foreach ($filters as $filter) { | ||
if(strpos($contents, $filter) !== false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a space between if
and (
src/etc/inc/system.inc
Outdated
break; | ||
} | ||
} | ||
if($found === false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a space between if
and (
.
src/etc/inc/system.inc
Outdated
/* XXX: Why not file_put_contents to the device */ | ||
@file_put_contents('/tmp/gps.init', $gps_init); | ||
mwexec("cat /tmp/gps.init > {$serialport}"); | ||
@file_put_contents($gps_device, $gps_init); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that actually work as expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unable to check now (no GPS device available)
I can leave this strings as-is, or test it later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll test @file_put_contents ($ gps_device, $ gps_init); when I get the gps device
Now I leave it as-is
src/etc/inc/system.inc
Outdated
@file_put_contents($gps_device, $gps_init); | ||
|
||
if ($found && $config['ntpd']['gps']['autobaudinit']) { | ||
mwexec("stty -f {$serialport} raw speed {$gpsbaud}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See previous comments about stty
and variables in the command.
src/etc/inc/system.inc
Outdated
/* Remove old /etc/remote entry if it exists */ | ||
if (mwexec("/usr/bin/grep -c '^gps0' /etc/remote")) { | ||
mwexec("/usr/bin/sed -i '' -n '/gps0/!p' /etc/remote"); | ||
} | ||
|
||
/* Add /etc/remote entry in case we need to read from the GPS with tip */ | ||
if (intval(`grep -c '^gps0' /etc/remote`) == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix this grep to use the full path while you're at it
@@ -198,9 +198,18 @@ function autocorrect_initcmd($initcmd) { | |||
|
|||
if (!empty($_POST['gpsspeed'])) { | |||
$config['ntpd']['gps']['speed'] = $_POST['gpsspeed']; | |||
if($_POST['gpsspeed'] == 'autoalways') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a space between if
and (
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all fixed
src/etc/inc/system.inc
Outdated
$c = fread($fp, $buffersize - $cnt); | ||
|
||
// Wait for data to arive | ||
if ($c === false || strlen($c) == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each test requires its own set of parenthesis
src/etc/inc/system.inc
Outdated
64 => '57600', | ||
80 => '115200' | ||
); | ||
$revspeeds = array_flip($speeds); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do an array_flip()
here? You only use this variable once below. It would be better to skip this and use array_search()
later.
src/etc/inc/system.inc
Outdated
mwexec("/bin/stty -f " . escapeshellarg($serialport) . " raw speed " . escapeshellarg($gpsbaud)); | ||
mwexec("/bin/stty -f " . escapeshellarg($serialport) . ".init raw speed " . escapeshellarg($gpsbaud)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since these two lines are practically the same here and when used again, it would probably be beneficial to make a function that takes the port and baud as arguments, and then call that from both places. That way if the init process changes in the future, only one place needs to be updated.
src/etc/inc/system.inc
Outdated
mwexec("/bin/stty -f " . escapeshellarg($serialport) . " raw speed " . escapeshellarg($baud)); | ||
mwexec("/bin/stty -f " . escapeshellarg($serialport) . ".init raw speed " . escapeshellarg($baud)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See previous note about making this a function
src/etc/inc/system.inc
Outdated
mwexec("/bin/stty -f " . escapeshellarg($serialport) . " raw speed " . escapeshellarg($gpsbaud)); | ||
mwexec("/bin/stty -f " . escapeshellarg($serialport) . ".init raw speed " . escapeshellarg($gpsbaud)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See previous note about making this a function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all fixed
It would be nice to have the option to attempt to auto configure the baud rate for a GPS device.
Useful if you don't know the baud rate of your device.
Or for some devices that lose their configurations during power outages.
Or when changing the baud rate.
This is resolved copy of the original PR #3561 by @jskyboo