diff options
author | John Klug <john.klug@multitech.com> | 2017-01-12 16:31:34 -0600 |
---|---|---|
committer | John Klug <john.klug@multitech.com> | 2017-01-12 16:31:34 -0600 |
commit | 94ec4baeb66a9bf1bfb2d86b532403514f2175c6 (patch) | |
tree | 43833773a35a3b354c02929ca45fc728b992501d | |
parent | e0dc5fbcf8465f710f9f2f64009d9f488b8a17bb (diff) | |
download | meta-mlinux-94ec4baeb66a9bf1bfb2d86b532403514f2175c6.tar.gz meta-mlinux-94ec4baeb66a9bf1bfb2d86b532403514f2175c6.tar.bz2 meta-mlinux-94ec4baeb66a9bf1bfb2d86b532403514f2175c6.zip |
Add script to set the system clock directly from the GPS.
-rwxr-xr-x | recipes-navigation/gpsd/gpsd/gpsd_ubx_settime.sh | 47 | ||||
-rw-r--r-- | recipes-navigation/gpsd/gpsd_3.16.bb | 4 |
2 files changed, 50 insertions, 1 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 diff --git a/recipes-navigation/gpsd/gpsd_3.16.bb b/recipes-navigation/gpsd/gpsd_3.16.bb index f2a5c05..e5b3207 100644 --- a/recipes-navigation/gpsd/gpsd_3.16.bb +++ b/recipes-navigation/gpsd/gpsd_3.16.bb @@ -17,6 +17,7 @@ SRC_URI = "${SAVANNAH_GNU_MIRROR}/${BPN}/${BP}.tar.gz \ file://gpsd-default \ file://gpsd \ file://gpsd_ubx_fixed.sh \ + file://gpsd_ubx_settime.sh \ file://60-gpsd.rules \ file://gpsd.service \ " @@ -91,6 +92,7 @@ do_install_append() { install -m 0644 ${WORKDIR}/gpsd-default ${D}/${sysconfdir}/default/gpsd.default install -d ${D}${sbindir} install -m 0755 ${WORKDIR}/gpsd_ubx_fixed.sh ${D}${sbindir}/gpsd_ubx_fixed + install -m 0755 ${WORKDIR}/gpsd_ubx_settime.sh ${D}${sbindir}/gpsd_ubx_settime # UDEV code assumed a USB GPS. @@ -133,7 +135,7 @@ SUMMARY_libgps = "C service library used for communicating with gpsd" FILES_libgps = "${libdir}/libgps.so.*" SUMMARY_gpsd-conf = "gpsd configuration files and init scripts" -FILES_gpsd-conf = "${sysconfdir} ${sbindir}/gpsd_ubx_fixed" +FILES_gpsd-conf = "${sysconfdir} ${sbindir}/gpsd_ubx_fixed ${sbindir}/gpsd_ubx_settime" CONFFILES_gpsd-conf = "${sysconfdir}/default/gpsd.default" SUMMARY_gpsd-gpsctl = "Tool for tweaking GPS modes" |