summaryrefslogtreecommitdiff
path: root/recipes-navigation/gpsd/gpsd
diff options
context:
space:
mode:
authorJohn Klug <john.klug@multitech.com>2017-01-12 16:31:34 -0600
committerJohn Klug <john.klug@multitech.com>2017-01-12 16:31:34 -0600
commit94ec4baeb66a9bf1bfb2d86b532403514f2175c6 (patch)
tree43833773a35a3b354c02929ca45fc728b992501d /recipes-navigation/gpsd/gpsd
parente0dc5fbcf8465f710f9f2f64009d9f488b8a17bb (diff)
downloadmeta-mlinux-94ec4baeb66a9bf1bfb2d86b532403514f2175c6.tar.gz
meta-mlinux-94ec4baeb66a9bf1bfb2d86b532403514f2175c6.tar.bz2
meta-mlinux-94ec4baeb66a9bf1bfb2d86b532403514f2175c6.zip
Add script to set the system clock directly from the GPS.
Diffstat (limited to 'recipes-navigation/gpsd/gpsd')
-rwxr-xr-xrecipes-navigation/gpsd/gpsd/gpsd_ubx_settime.sh47
1 files changed, 47 insertions, 0 deletions
diff --git a/recipes-navigation/gpsd/gpsd/gpsd_ubx_settime.sh b/recipes-navigation/gpsd/gpsd/gpsd_ubx_settime.sh
new file mode 100755
index 0000000..7f22719
--- /dev/null
+++ b/recipes-navigation/gpsd/gpsd/gpsd_ubx_settime.sh
@@ -0,0 +1,47 @@
+#!/bin/bash
+# PPS= 1484247472.29561104 clock= 1484247990.00000000 offset= 517.704388959
+
+trap "stty echo icanon" exit
+
+OIFS=$IFS
+IFS=$'\n'
+if ! /usr/sbin/gpsd_ubx_fixed ; then
+ logger -e -p user.warn "GPS does not have a fix yet. Try again later."
+ exit 1
+fi
+# This shell script is shaped by two things:
+# Lousy performance of sed and grep when used with gpsmon
+# Need to terminate
+# Terminate gpsmon after 10 seconds if it is our child
+(
+ sleep 10
+ ppid=$$
+ gpsmonpid=$(ps -o pid,ppid,comm -e | egrep "[[:space:]]${ppid}[[:space:]]+gpsmon$" | sed -r 's/^[[:space:]]*([0-9]*)[[:space:]]+.*/\1/')
+ if ((${#gpsmonpid})) ; then
+ logger -p user.info "terminating gpscat(${gpsmonpid}) with SIGTERM"
+ kill ${gpsmonpid}
+ else
+ exit 0
+ fi
+ sleep 2
+ gpsmonpid=$(ps -o pid,ppid,comm -e | egrep "[[:space:]]${ppid}[[:space:]]+gpsmon$" | sed -r 's/^[[:space:]]*([0-9]*)[[:space:]]+.*/\1/')
+ if ((${#gpsmonpid})) ; then
+ logger -p user.info "terminating gpscat(${gpsmonpid}) with SIGKILL"
+ kill -9 ${gpsmonpid}
+ fi
+) &
+
+
+epoch=$(gpsmon -a 2>&1 | ( while read ln ; do
+ if [[ $ln =~ ^[[:space:]]*PPS=.*clock=[[:space:]]*([0-9]*)\. ]] ; then
+ echo ${BASH_REMATCH[1]}
+ break
+ fi
+done ))
+if [[ $epoch =~ ^[0-9]+$ ]] ; then
+ date +%s -s @${epoch} >/dev/null
+else
+ logger user.err "gpsmon output is bad."
+ exit 1
+fi
+exit 0