From c4fa95a8241a7f807924b402febff22cfc1d6e9b Mon Sep 17 00:00:00 2001 From: John Klug Date: Wed, 11 Jan 2017 18:40:04 -0600 Subject: Add new parameters for evaluating GPS fix status. --- recipes-navigation/gpsd/gpsd/gpsd-default | 14 +++ recipes-navigation/gpsd/gpsd/gpsd_ubx_fixed.sh | 142 +++++++++++++++++++++++++ recipes-navigation/gpsd/gpsd_3.16.bb | 9 +- 3 files changed, 160 insertions(+), 5 deletions(-) create mode 100755 recipes-navigation/gpsd/gpsd/gpsd_ubx_fixed.sh (limited to 'recipes-navigation') diff --git a/recipes-navigation/gpsd/gpsd/gpsd-default b/recipes-navigation/gpsd/gpsd/gpsd-default index 00576d3..7c4e6bb 100644 --- a/recipes-navigation/gpsd/gpsd/gpsd-default +++ b/recipes-navigation/gpsd/gpsd/gpsd-default @@ -10,3 +10,17 @@ GPS_BAUD=115200 GPS_DEVICES="$GPS_LINE /dev/pps0" GPSD_NOSTART=0 + +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" diff --git a/recipes-navigation/gpsd/gpsd/gpsd_ubx_fixed.sh b/recipes-navigation/gpsd/gpsd/gpsd_ubx_fixed.sh new file mode 100755 index 0000000..9fd3f7f --- /dev/null +++ b/recipes-navigation/gpsd/gpsd/gpsd_ubx_fixed.sh @@ -0,0 +1,142 @@ +#!/bin/bash +# Fix file creation for U-Blox 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. +if [[ -r /etc/default/gpsd ]] ; then + . /etc/default/gpsd +else + echo "Must configure GPSD requirements" + exit 1 +fi +UBXNAVSOL='b56201063400' +UBXNAVSOLLEN=60 + +function rm_gps_file +{ + if [[ -n "${GPS_FIXFILE}" ]] && [[ -f ${GPS_FIXFILE} ]] ; then + rm -f "${GPS_FIXFILE}" + fi +} + +# Most exits are errors, so remove the GPS fix file. +trap rm_gps_file EXIT + +if ! [[ -x /usr/bin/gpsmon ]] ; then + logger -p user.err "gpsd_ubx_3dfix.sh: Please install gpsmon" + exit 0 +fi + + +# Terminate gpsmon after 10 seconds if it is our child +( + sleep 10 + ppid=$$ + # echo "looking for shell ${ppid}" + gpsmonpid=$(ps -o pid,ppid,comm -e | egrep "[[:space:]]${ppid}[[:space:]]+gpsmon$" | sed -r 's/^[[:space:]]*([0-9]*)[[:space:]]+.*/\1/') + # echo sleeper TERM found pid $gpsmonpid + 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/') + # echo sleeper KILL found pid $gpsmonpid + if ((${#gpsmonpid})) ; then + logger -p user.info "terminating gpscat(${gpsmonpid}) with SIGKILL" + kill -9 ${gpsmonpid} + fi +) & + +fix="" +status="" + +# egrep in busybox has a horrible buffering issue. +# echo My shell pid is $$ +# echo Place data fix, status +stuff="$(gpsmon -a 2>&1 | { + OIFS=${IFS} + IFS=$'\n' + while read ln ; do + if [[ $ln =~ ^[[:space:]]*\(${UBXNAVSOLLEN}\)[[:space:]]*${UBXNAVSOL}....................(..)(.) ]] ; then + IFS=${OIFS} + fix="${BASH_REMATCH[1]}" + if ((${#fix} == 0)) ; then + fix="unknown" + fi + status=$(echo "${BASH_REMATCH[2]}") + if ((${#status} == 0)) ; then + status="unknown" + fi + break; + fi + oldln="${ln}" + done + if ((${#fix})) && ((${#status})) ; then + echo "$fix,$status" + else + echo "${oldln}" + fi +})" + +if ((${#stuff} == 0)) ; then + logger -p user.err No data from GPS + exit 1 +fi + +if [[ -t 1 ]] ; then + stty echo icanon +fi + +OIFS=${IFS} +IFS=, +set $stuff +fix="$1" +status="$2" +IFS=${OIFS} + +# fixOK is the least significant bit of a hex single digit +case $status in + [13579bBdDfF]) + ((fixOK=1)) + ;; + [02468aAcCeE]) + ((fixOK=0)) + ;; + *) + logger -p user.err "Is GPSD running?" + logger -p user.err "FIX OK field should be single hex digit: gpsmon data: $stuff" + exit 1 + break + ;; +esac + +# echo "status is $status. fixOK is $fixOK" + + +if ((fixOK == 0)) ; then + logger -p user.err "Problem with the GPS fix. The fix is an even value, \"$status\", and should be an odd value. fixOK=${fixOK}" + exit 1 + # Retry later. How? +fi + +# 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 + logger user.info "GPS has fix $fix found in list GPSFIX: $GPSFIX" + echo $x >"${GPS_FIXFILE}" + GPS_FIXFILE="" + exit 0 + fi +done + +logger -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_3.16.bb b/recipes-navigation/gpsd/gpsd_3.16.bb index 20b2cad..cf4b578 100644 --- a/recipes-navigation/gpsd/gpsd_3.16.bb +++ b/recipes-navigation/gpsd/gpsd_3.16.bb @@ -16,6 +16,7 @@ SRC_URI = "${SAVANNAH_GNU_MIRROR}/${BPN}/${BP}.tar.gz \ file://0005-suppress-text-in-binary.patch \ file://gpsd-default \ file://gpsd \ + file:://gpsd_ubx_fixed.sh \ file://60-gpsd.rules \ file://gpsd.service \ " @@ -88,12 +89,10 @@ do_install_append() { install -m 0755 ${WORKDIR}/gpsd ${D}/${sysconfdir}/init.d/ install -d ${D}/${sysconfdir}/default install -m 0644 ${WORKDIR}/gpsd-default ${D}/${sysconfdir}/default/gpsd.default + install -d ${D}/usr/sbin + install -m 0644 ${WORKDIR}/gpsd_ubx_fixed.sh ${D}/usr/sbin/gpsd_ubx_fixed - #support for udev - install -d ${D}/${sysconfdir}/udev/rules.d - install -m 0644 ${WORKDIR}/60-gpsd.rules ${D}/${sysconfdir}/udev/rules.d - install -d ${D}${base_libdir}/udev/ - install -m 0755 ${S}/gpsd.hotplug ${D}${base_libdir}/udev/ + # UDEV code assumed a USB GPS. #support for python install -d ${D}/${PYTHON_SITEPACKAGES_DIR}/gps -- cgit v1.2.3