Because I was bored by manual connection of BT GPS, I've put together a script which automatize this process.
Big thanks to sebt3 for AWK parsing of rfcomm.conf file!
What ConBTGPS expects?
1) you've installed gpsd
2) your BT GPS is added in /etc/bluetooth/rfcomm.conf
3) your BT GPS is turned on
Check the wiki for details how to install gpsd and add your BT GPS.
http://pandorawiki.org/GPS
What ConBTGPS does?
It checks if your BT is on - if not, it starts it up, if your BT GPS is correctly added in /etc/bluetooth/rfcomm.conf and if gpsd is running.
If these conditions are met, it tries to connect with your BT GPS and checks if there is any communication.
What ConBTGPS doesn't?
It doesn't check the GPS signal or satelite visibility. It's also incapable of making a breakfast for you
Before I upload it into repos, I ask those of you who are using BT GPS with either TangoGPS or modRana (or any other mapping app) for testing. Let me know about any issues you find.
If anybody wants to amend the script for USB GPS, feel free to do it.
And here's the script. I was resurrecting my shell scripting skills after long years so don't be surprised if you find any glitches or weird constructions in it.
Edit: 2011-06-15
To download the latest version of ConBTGPS, go to repos.
conbtgps.pnd
Big thanks to sebt3 for AWK parsing of rfcomm.conf file!
What ConBTGPS expects?
1) you've installed gpsd
2) your BT GPS is added in /etc/bluetooth/rfcomm.conf
3) your BT GPS is turned on
Check the wiki for details how to install gpsd and add your BT GPS.
http://pandorawiki.org/GPS
What ConBTGPS does?
It checks if your BT is on - if not, it starts it up, if your BT GPS is correctly added in /etc/bluetooth/rfcomm.conf and if gpsd is running.
If these conditions are met, it tries to connect with your BT GPS and checks if there is any communication.
What ConBTGPS doesn't?
It doesn't check the GPS signal or satelite visibility. It's also incapable of making a breakfast for you
Before I upload it into repos, I ask those of you who are using BT GPS with either TangoGPS or modRana (or any other mapping app) for testing. Let me know about any issues you find.
If anybody wants to amend the script for USB GPS, feel free to do it.
And here's the script. I was resurrecting my shell scripting skills after long years so don't be surprised if you find any glitches or weird constructions in it.
Code:
#!/bin/sh
# Delete control file from previous sessions
rm .btcommtemp
# Inform user
zenity --info --text="ConBTGPS\n\nTurn on your BT GPS first."
# Check if bluetooth is on.
if [ ! -f $HOME/.op_btenabled ];
then
echo BT is OFF, starting it.
# Using OP script to turn BT on.
/usr/pandora/scripts/op_bluetooth.sh
else
echo BT was already ON.
fi
# We don't want to let the program write its configuration, savestates etc. to the NAND.
#So we need to export our HOME environment variable first.
export HOME=/mnt/utmp/conbtgps/
# stop gpsd first
sudo /etc/init.d/gpsd stop
# release all possibly connected devices
echo Trying to release all previously connected BT devices.
sudo rfcomm release all
# Check if rfcomm.conf exists
if [ -f /etc/bluetooth/rfcomm.conf ];
then
echo /etc/bluetooth/rfcomm.conf exists, OK.
MYBTGPSMAC=`awk 'BEGIN{r="";f=0}END{if(f==1)print r}/^rfcomm/&&(f==0||r==""){f=0;r=""}/device.*;/&&r==""{r=substr($2,1,length($2)-1)}/comment/&&/GPS/{f=1}' < /etc/bluetooth/rfcomm.conf`
# Check if MYBTGPSMAC is not empty
if [ ! "$MYBTGPSMAC" ];
then
echo No appropriate MAC address found in /etc/bluetooth/rfcomm.conf!
zenity --error --text="ConBTGPS\n\nNo appropriate MAC address found in /etc/bluetooth/rfcomm.conf!"
exit 1
else
# Validate format of MAC address
if [ `echo $MYBTGPSMAC | sed -n "/^\([0-9A-Z][0-9A-Z]:\)\{5\}[0-9A-Z][0-9A-Z]$/p"` ];
then
# Connect to BT GPS device
GPSDEVICE=`awk 'BEGIN{r=""}/^rfcomm/{r=$1}/comment/&&/GPS/{print r;exit}' < /etc/bluetooth/rfcomm.conf`
sudo rfcomm bind /dev/$GPSDEVICE $MYBTGPSMAC
echo Connecting to $MYBTGPSMAC
# Start gpsd
gpsd /dev/$GPSDEVICE;
echo Starting gpsd ...
# gpsd check
SERVICE='gpsd'
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
echo "$SERVICE started successfully."
head /dev/$GPSDEVICE > .btcommtemp
notify-send -u normal "ConBTGPS" "Waiting for BT GPS response."
sleep 6
BTCOMMTEMP=.btcommtemp
if [ -s $BTCOMMTEMP ];
then
notify-send -u normal "ConBTGPS" "BT GPS is connected."
#Tidy up
rm .btcommtemp
else
zenity --error --text="ConBTGPS\n\nThere is no communication running on $GPSDEVICE\nMake sure your BT GPS is on."
fi
else
echo "$SERVICE is not running"
zenity --error --text="ConBTGPS\n\ngpsd is not running or installed. GPS positioning will not be available."
fi
else
# Wrong address
echo MAC address has wrong format.
zenity --error --text="ConBTGPS\n\nBT GPS MAC address in /etc/bluetooth/rfcomm.conf has wrong format."
fi
fi
else
echo "/etc/bluetooth/rfcomm.conf does not exist!"
zenity --error --text="ConBTGPS\n\n/etc/bluetooth/rfcomm.conf doesn't exist."
exit 1
fi
Edit: 2011-06-15
To download the latest version of ConBTGPS, go to repos.
conbtgps.pnd
Attachments
Last edited by a moderator: