Thread
:
Using N810 as a bluetooth GPS module
View Single Post
tz1
2008-10-23 , 17:57
Posts: 716 | Thanked: 236 times | Joined on Dec 2007
#
20
Annotated:
#!/bin/sh
The pound sign is treated as a comment. The pair #! tells the system that it is a runnable shell script, and should be passed to the program which follows, in this case "/bin/sh". You can find similar things for python, e.g. /usr/bin/python or /usr/bin/gawk.
if [ $# == 0 ]; then
The if/then are basic programming constructs in the shell. The "[" is actually the "test" command (see manpage for test) which processes everything to the closing bracket and returns a value. $# is the number of parameters on the command line. So the statement says do the following section (up to an else or "fi" - fi ends if, esac ends case, they like spelling backwards...
sdptool add SP
This is a bluetooth command (from the package bluez-utils-test - search the fora for links) which turns on the SerialProfile, so it can look like it has a serial port.
while true; do
rfcomm -r -i hci0 listen 2 1 $0 {}
done
The while-true just creates an infinite loop. The rfcomm command is another bluetooth utility which listens for a connection then executes a program. In this case $0 which ends up being this
same
script (with a parameter this time, and the parameter will be the port the bluetooth wants to talk over). It will repeatedly run after disconnecting each session, and a disconnect will kill the script it runs.
fi
exec /usr/libexec/navicore-gpsd-helper >$1
fi ends the if section, and we only come here if there is a parameter, in this case it will be in "$1" which will expand to something like "/dev/rfcomm2". So this will run the navicore-gpsd-helper and the output will go out over the bluetooth serial port.
The "exec" says to overlay the shell process with the command, so instead of having a shell calling an executable with parameters, the shell process
becomes
the executable with parameters saving resources.
Quote & Reply
|
The Following 2 Users Say Thank You to tz1 For This Useful Post:
cadmus
,
qwerty12
tz1
View Public Profile
Send a private message to tz1
Find all posts by tz1