summaryrefslogtreecommitdiff
path: root/recipes-navigation
diff options
context:
space:
mode:
authorJohn Klug <john.klug@multitech.com>2019-03-15 17:44:37 -0500
committerJohn Klug <john.klug@multitech.com>2019-03-15 17:44:37 -0500
commitc342cb9ecde8b366cdec3e21af87b0e4746d7078 (patch)
treed4ae07fb942bc450335914a57e7d105e458e0130 /recipes-navigation
parent4ab23ea883917948fd575ca9dec446af6dee859e (diff)
downloadmeta-mlinux-c342cb9ecde8b366cdec3e21af87b0e4746d7078.tar.gz
meta-mlinux-c342cb9ecde8b366cdec3e21af87b0e4746d7078.tar.bz2
meta-mlinux-c342cb9ecde8b366cdec3e21af87b0e4746d7078.zip
Make gpsd recipe independent of U-Blox and faster time setting with improved gpsd_settime.
Diffstat (limited to 'recipes-navigation')
-rwxr-xr-xrecipes-navigation/gpsd/gpsd/gpsd6
-rw-r--r--recipes-navigation/gpsd/gpsd/gpsd-default24
-rw-r--r--recipes-navigation/gpsd/gpsd/gpsd_fixed.sh125
-rwxr-xr-xrecipes-navigation/gpsd/gpsd/gpsd_settime.sh84
-rwxr-xr-xrecipes-navigation/gpsd/gpsd/gpsd_ubx_fixed.sh3
-rwxr-xr-xrecipes-navigation/gpsd/gpsd/gpsd_ubx_settime.sh2
-rw-r--r--recipes-navigation/gpsd/gpsd_3.18.1.bb9
7 files changed, 235 insertions, 18 deletions
diff --git a/recipes-navigation/gpsd/gpsd/gpsd b/recipes-navigation/gpsd/gpsd/gpsd
index 33a8470..95e2a84 100755
--- a/recipes-navigation/gpsd/gpsd/gpsd
+++ b/recipes-navigation/gpsd/gpsd/gpsd
@@ -72,8 +72,10 @@ do_start()
# 1 if daemon was already running
# 2 if daemon could not be started
- if [[ -n ${SET_GPS_SPEED} ]] ; then
- eval "${SET_GPS_SPEED}"
+ # If the SET_GPS_SPEED function exists, call it to set the GPS Speed.
+ what=$(type SET_GPS_SPEED 2>/dev/null)
+ if [[ $what =~ SET_GPS_SPEED[[:space:]]is[[:space:]]a[[:space:]]function ]] ; then
+ SET_GPS_SPEED
fi
/usr/sbin/start-stop-daemon -N -20 --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
diff --git a/recipes-navigation/gpsd/gpsd/gpsd-default b/recipes-navigation/gpsd/gpsd/gpsd-default
index bb4df93..168b0cf 100644
--- a/recipes-navigation/gpsd/gpsd/gpsd-default
+++ b/recipes-navigation/gpsd/gpsd/gpsd-default
@@ -16,17 +16,14 @@ GPS_BAUD=115200
GPS_FIXFILE=/var/run/gpsfix
-# GPSD/UBlox Lock requiremnt
-# Create GPS_FIXFILE when reached.
-# UBlox NAV SOL (0x01 0x06) at gpsFix value
-# and above
-# 00 No Fix
-# 01 Dead reckoning only
-# 02 2D fix
-# 03 3D fix
-# 04 GPS + dead reckoning combined
-# 05 Time only fix
-GPSFIX="03 05"
+# GPSD Json TPV object, mode field.
+# See: http://www.catb.org/gpsd/gpsd_json.html
+#
+# 0 Unknown
+# 1 No fix
+# 2 2D fix
+# 3 3D fix
+GPSFIX="3"
# U-Blox defaults to 9600. If the
# default speed is not set before changing
@@ -52,7 +49,7 @@ GPSFIX="03 05"
# If the line speed is already 115200, we
# should not need to change the baud rate.
#
-read -r -d '' SET_GPS_SPEED <<"EOF"
+function SET_GPS_SPEED {
if [[ $(cat /run/config/gpstype) == u-blox ]] ; then
logger -t gpsd -p daemon.info "Attempting to set baud rate to ${GPS_BAUD}"
if ! gpsctl -T 20 -t u-blox -s $GPS_BAUD -b -f $GPS_LINE ; then
@@ -67,6 +64,5 @@ if [[ $(cat /run/config/gpstype) == u-blox ]] ; then
gpsctl -T 2 -f $GPS_LINE
stty -F $GPS_LINE $GPS_BAUD
fi
-EOF
-
+}
diff --git a/recipes-navigation/gpsd/gpsd/gpsd_fixed.sh b/recipes-navigation/gpsd/gpsd/gpsd_fixed.sh
new file mode 100644
index 0000000..915c7be
--- /dev/null
+++ b/recipes-navigation/gpsd/gpsd/gpsd_fixed.sh
@@ -0,0 +1,125 @@
+#!/bin/bash
+# This script filters the gpspipe -w
+# (json) output from GPSD. The GPS fix
+# is taken from the mode parameter of
+# the GPSD TPV object in the json output.
+# Values are:
+#
+# 0 Unseen
+# 1 No fix
+# 2 2D
+# 3 3D
+#
+# Fix file creation for GPS.
+# If GPS reaches expected
+# fix level, file GSP_FIXFILE is created.
+# This is to know when to set the system
+# and hardware clock, and when
+# it is safe to start ntp.
+# DEBUG=1 to set debug
+NAME=gpsd_ubx_fixed
+shopt -s expand_aliases
+alias LG="logger -t ${NAME}"
+if [[ -r /etc/default/gpsd ]] ; then
+ . /etc/default/gpsd
+else
+ echo "Must configure GPSD requirements"
+ exit 1
+fi
+
+function rm_gps_file
+{
+ if [[ -n "${GPS_FIXFILE}" ]] && [[ -f ${GPS_FIXFILE} ]] ; then
+ rm -f "${GPS_FIXFILE}"
+ fi
+}
+function kill_it
+{
+ cmd=$1
+ pid=$2
+ sig=$3
+ ((DEBUG)) && LG -p user.info "terminating $cmd(${pid}) with SIG${sig}"
+ kill -SIG${sig} ${pid} >/dev/null 2>&1
+ result=$?
+ ((DEBUG)) && LG -p user.info "kill -SIG${sig} ${pid} result is $result"
+}
+
+# Most exits are errors, so remove the GPS fix file.
+trap rm_gps_file EXIT
+
+if ! [[ -x /usr/bin/gpspipe ]] ; then
+ LG -p user.err "Please install gpspipe"
+ exit 0
+fi
+
+# Terminate gpspipe after 10 seconds if it is our child
+# gpspipe has issues with terminals and stalling on terminal
+# read of the console.
+(
+ sleep 10
+ # We use BASHPID because our parent, $$, may have already exited, and
+ # then ps will not work. BASHPID is the current subshell.
+ ppid=$BASHPID
+ pgid=$(ps --no-heading -o pgid -p $ppid)
+
+ if ((${#pgid} == 0)) ; then
+ LG -p user.err "Could not find a pgid for $ppid"
+ ps -fjp $ppid | LG -p user.error
+ fi
+
+ # pgrep does not work during boot.
+ pgrpmemb=$(ps --no-heading -o pgid,pid,comm -e | grep '^ *'"${pgid}"' *' | sed -r 's/^ *[0-9]+ *//')
+ gpspipepid=$(echo "${pgrpmemb}" | egrep '[[:space:]]gpspipe$' | sed 's/[[:space:]].*//')
+
+ ((DEBUG)) && LG -p user.info "$pgid is pgid $gpspipepid is gpspipepid"
+ # Find the gpspipepid that is our grandchild
+ ((didkill=0))
+
+ # for loop is in case gpspipepid has children.
+ for p in ${gpspipepid} ; do
+ if ((${#p})) ; then
+ kill_it gpspipe $p TERM
+ ((didkill=p))
+ break
+ fi
+ done
+ if ((didkill == 0)) ; then
+ exit 0
+ fi
+ # Do a sigkill to be sure.
+ sleep 2
+ kill_it gpspipe $didkill KILL
+) &
+
+fix=""
+status=""
+
+# egrep in busybox has a horrible buffering issue.
+# echo My shell pid is $$
+# echo Place data fix, status
+fix="$(gpspipe -w | grep -m1 '{"class":"TPV","device":"/dev/gps0",.*"mode":' | sed -e 's/.*"mode"://' -e 's/[},].*//')"
+
+if ((${#fix} == 0)) ; then
+ LG -p user.err "No data from GPS"
+ exit 1
+fi
+
+
+# echo "status is $status. fixOK is $fixOK"
+
+
+# echo "fix is $fix. Is it in $GPSFIX?"
+# Test the GPS fixOK
+for x in $GPSFIX ; do
+ # echo test $x with $fix
+ if [[ $x == $fix ]] ; then
+ LG -p user.info "GPS has fix $fix found in list GPSFIX: $GPSFIX"
+ echo $x >"${GPS_FIXFILE}"
+ GPS_FIXFILE=""
+ exit 0
+ fi
+done
+
+LG -p user.info "GPS fix is bad: $fix and should be one of: $GPSFIX"
+# Start later
+exit 1
diff --git a/recipes-navigation/gpsd/gpsd/gpsd_settime.sh b/recipes-navigation/gpsd/gpsd/gpsd_settime.sh
new file mode 100755
index 0000000..578013b
--- /dev/null
+++ b/recipes-navigation/gpsd/gpsd/gpsd_settime.sh
@@ -0,0 +1,84 @@
+#!/bin/bash
+# Get the time from gpspipe, and if present, set the time.
+# DEBUG=1 to set debug
+NAME=gpsd_ubx_settime
+shopt -s expand_aliases
+alias LG="logger -t $NAME"
+function kill_it
+{
+ cmd=$1
+ pid=$2
+ sig=$3
+ ((DEBUG)) && LG -p user.info "terminating $cmd(${pid}) with SIG${sig}"
+ kill -SIG${sig} ${pid}
+ result=$?
+ ((DEBUG)) && LG -p user.info "kill -SIG${sig} ${pid} result is $result"
+}
+
+trap "stty echo icanon" exit
+
+OIFS=$IFS
+IFS=$'\n'
+if ! /usr/sbin/gpsd_fixed </dev/null ; then
+ LG -s -p user.warn "GPS does not have a fix yet. Try again later."
+ exit 1
+fi
+
+
+# Terminate gpspipe after 10 seconds if it is our child
+# gpspipe has issues with terminals and stalling on terminal
+# read of the console.
+(
+ sleep 10
+ ppid=$BASHPID
+ pgid=$(ps --no-heading -o pgid -p $ppid)
+
+ if ((${#pgid} == 0)) ; then
+ LG -p user.err "Could not find a pgid for $ppid"
+ ps -fjp $ppid | LG -p user.error
+ fi
+
+ # pgrep does not work during boot.
+ pgrpmemb=$(ps --no-heading -o pgid,pid,comm -e | grep '^ *'"${pgid}"' *' | sed -r 's/^ *[0-9]+ *//')
+ gpspipepid=$(echo "${pgrpmemb}" | egrep '[[:space:]]gpspipe$' | sed 's/[[:space:]].*//')
+
+ ((DEBUG)) && LG -p user.info "$pgid is pgid $gpspipepid is gpspipepid"
+ # Find the gpspipepid that is our grandchild
+ ((didkill=0))
+
+ # for loop is in case gpspipepid has children.
+ for p in ${gpspipepid} ; do
+ if ((${#p})) ; then
+ kill_it gpspipe $p TERM
+ ((didkill=p))
+ break
+ fi
+ done
+ if ((didkill == 0)) ; then
+ exit 0
+ fi
+ # Do a sigkill to be sure.
+ sleep 2
+ kill_it gpspipe $didkill KILL
+) &
+
+# Get the ISO8601 time from GPSD
+ISO8601=$(gpspipe -w | grep -m1 '{"class":"TPV","device":"/dev/gps0","status":.*,"time":"' | sed -e 's/.*,"time":"//' -e 's/Z",.*//')
+
+if (( ${#ISO8601} > 18 )) ; then
+ LG -p user.warn "Updating time to time, ${ISO8601}."
+ [[ $ISO8601 =~ ([^-]*)-([^-]*)-([^T]*)T([^:]*):([^:]*):([^\.]*)\. ]]
+ Y=${BASH_REMATCH[1]}
+ M=${BASH_REMATCH[2]}
+ D=${BASH_REMATCH[3]}
+ h=${BASH_REMATCH[4]}
+ m=${BASH_REMATCH[5]}
+ s=${BASH_REMATCH[6]}
+fi
+if ((${#Y} == 4 )) && ((${#M} > 0)) && ((${#D} > 0)) && ((${#h} > 0)) && ((${#m} > 0)) && ((${#s} > 0)) ; then
+ date -u "${Y}.${M}.${D}-${h}:${m}:${s}" >/dev/null
+else
+ LG -p user.err "gpspipe output is bad or missing"
+ exit 1
+fi
+exit 0
diff --git a/recipes-navigation/gpsd/gpsd/gpsd_ubx_fixed.sh b/recipes-navigation/gpsd/gpsd/gpsd_ubx_fixed.sh
index a1b59cf..82254c2 100755
--- a/recipes-navigation/gpsd/gpsd/gpsd_ubx_fixed.sh
+++ b/recipes-navigation/gpsd/gpsd/gpsd_ubx_fixed.sh
@@ -1,4 +1,6 @@
#!/bin/bash
+# This script is deprecated.
+# Use gpsd_fixed instead.
# Fix file creation for U-Blox GPS.
# If GPS reaches expected
# fix level, file GSP_FIXFILE is created.
@@ -6,6 +8,7 @@
# and hardware clock, and when
# it is safe to start ntp.
# DEBUG=1 to set debug
+#
NAME=gpsd_ubx_fixed
shopt -s expand_aliases
alias LG=logger\ -t\ ${NAME}
diff --git a/recipes-navigation/gpsd/gpsd/gpsd_ubx_settime.sh b/recipes-navigation/gpsd/gpsd/gpsd_ubx_settime.sh
index 15dc9c7..b497138 100755
--- a/recipes-navigation/gpsd/gpsd/gpsd_ubx_settime.sh
+++ b/recipes-navigation/gpsd/gpsd/gpsd_ubx_settime.sh
@@ -1,4 +1,6 @@
#!/bin/bash
+# This function is deprecated.
+# Use gpsd_settime instead.
# PPS= 1484247472.29561104 clock= 1484247990.00000000 offset= 517.704388959
# DEBUG=1 to set debug
NAME=gpsd_ubx_settime
diff --git a/recipes-navigation/gpsd/gpsd_3.18.1.bb b/recipes-navigation/gpsd/gpsd_3.18.1.bb
index 021d86a..5793344 100644
--- a/recipes-navigation/gpsd/gpsd_3.18.1.bb
+++ b/recipes-navigation/gpsd/gpsd_3.18.1.bb
@@ -4,7 +4,7 @@ LICENSE = "BSD"
LIC_FILES_CHKSUM = "file://COPYING;md5=d217a23f408e91c94359447735bc1800"
DEPENDS = "dbus dbus-glib ncurses python libusb1 chrpath-replacement-native pps-tools"
PROVIDES = "virtual/gpsd"
-PR="m4"
+PR="m5"
EXTRANATIVEPATH += "chrpath-native"
@@ -21,6 +21,8 @@ SRC_URI = "${SAVANNAH_GNU_MIRROR}/${BPN}/${BP}.tar.gz \
file://gpsd \
file://gpsd_ubx_fixed.sh \
file://gpsd_ubx_settime.sh \
+ file://gpsd_fixed.sh \
+ file://gpsd_settime.sh \
file://gpsd.rules \
file://gpsd.service \
"
@@ -128,6 +130,9 @@ do_install_append() {
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
+ install -m 0755 ${WORKDIR}/gpsd_fixed.sh ${D}${sbindir}/gpsd_fixed
+ install -m 0755 ${WORKDIR}/gpsd_settime.sh ${D}${sbindir}/gpsd_settime
+
#support for udev
install -d ${D}/${sysconfdir}/udev/rules.d
@@ -176,7 +181,7 @@ FILES_${PN}-dev += "${libdir}/pkgconfdir/libgpsd.pc ${libdir}/pkgconfdir/libgps.
${libdir}/libQgpsmm.prl \
${includedir}/gps.h ${includedir}/libgpsmm.h ${includedir}/gps"
-FILES_${PN} += "${sbindir}/gpsd_ubx_fixed ${sbindir}/gpsd_ubx_settime"
+FILES_${PN} += "${sbindir}/gpsd_*"
FILES_python-pygps-dbg += " ${libdir}/python*/site-packages/gps/.debug"