Skip to content

Instantly share code, notes, and snippets.

@scientress
Created August 23, 2018 18:00
Show Gist options
  • Save scientress/19e6ee925f20957231cd8179508eecba to your computer and use it in GitHub Desktop.
Save scientress/19e6ee925f20957231cd8179508eecba to your computer and use it in GitHub Desktop.
#!/bin/sh
# gpsd device-hook script for Sierra Wireless cards, by Jenny Danzmayr, based on Bjørn Mork script
#
# gpsd will not poll a device before it is opened, at which time this script is called
# This means that we can unconditionally add the GPS inteface to gpsd without wasting any power.
# It will be activated when the first client connects to gpsd, and this script is called
#
# gpsd will also deactivate the port after some inactivity period
# figure out the parent usb device
GPSDEVICE="$(readlink -f "$1")"
USBDEV=`ls -l "$GPSDEVICE" |sed -ne 's!^c......... [0-9]* [^ ]* [^ ]* \([0-9]*\), \([0-9]*\) .*!/sys/dev/char/\1:\2/device/../..!p'`
#echo "$GPSDEVICE -> $USBDEV"
# silently ignore any non-USB ports
if [ ! -r "$USBDEV/idVendor" ] || [ ! -r "$USBDEV/idProduct" ]; then
exit 0
fi
VID=`cat "$USBDEV/idVendor"`
PID=`cat "$USBDEV/idProduct"`
case "$2" in
ACTIVATE)
CMD=START
;;
*)
CMD=STOP
;;
esac
case "$VID:$PID" in
"1199:9071" |\
"1199:9079" )
echo "sending command \$GPS_${CMD} to $GPSDEVICE" >&2
echo \$GPS_$CMD >"$GPSDEVICE"
;;
*)
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment