GpsService
From GumstixDocsWiki
Creating a script
In order to keep a bluetooth GPS unit connected to the gumstix we need a script which watches the bluetooth connection and re-establishes it if the gpsd loses the connection. The following shell script does just that:
#!/bin/sh
# Use "hcitool scan" to find out the MAC address
GPS_MAC=00:11:67:80:75:F4
# Use "sdptool browse GPS_MAC_ADDRESS" to find out the channel (it is listed
# in a line beginning with RFCOMM) after you know the MAC address
SERIAL_PORT_CHANNEL=1
while true; do
# Kill old gpsd instances
echo "Killing all gpsd"
killall gpsd;
sleep 2;
killall -9 gpsd
# Add a new Serial Port service, in order to keep the original Serial Port unaffected
# Local services can be displayed with: sdptool browse ff:ff:ff:00:00:00
echo "Adding a new serial port"
sdptool del 0x10001 > /dev/null
if sdptool add --channel=2 SP; then
echo "Adding SP successful";
else
echo "Adding failed";
sleep 10;
continue;
fi
sdptool setattr 0x010000 0x100 "Ch 1 Serial (getty)" > /dev/null
sdptool setattr 0x010001 0x100 "Ch 2 Serial (GPS)" > /dev/null
# Scanning for gps
echo "Scanning for GPS";
while ! hcitool scan | grep $GPS_MAC > /dev/null; do
sleep 10;
echo "Scanning for GPS";
done
echo "GPS with MAC $GPS_MAC found"
# Try to bind channel 1 (/dev/rfcomm1) to the GPS serial port
while ! rfcomm | grep $GPS_MAC | grep clean > /dev/null; do
echo "Establishing channel to GPS"
rfcomm release 1
rfcomm bind 1 $GPS_MAC $SERIAL_PORT_CHANNEL
sleep 2
done
echo "Starting gpsd"
gpsd -n /dev/rfcomm1
echo "Waiting for gpsd to get connected";
sleep 20
if rfcomm | grep $GPS_MAC | grep connected > /dev/null; then
echo "GPS connected, going into watchdog mode"
fi
while rfcomm | grep $GPS_MAC | grep connected > /dev/null; do
sleep 10
done
echo "gpsd disconnected";
done
Just adjust GPS_MAC to fit your GPS (use "hcitool scan" to find out the address). This script only works for bluetooth GPS devices which do not require a PIN code. You can save it under /usb/bin/gps_service and run it at startup. Please not that I had problems to connect to my GPS while being connected to the gumstix via bluetooth.

