Hello fox guys,

I wrote a simple shell script, which allows to read out the most
important gps-parameters from the nmea-message, received by the gps-mouse:


file: "gps_d"
-----------------------snip-----------------------
#!/bin/sh
# The script is made by gazoox - don't remove this line ;)
# stty xxx xxx  Configure your serial-Port if needed!
gps=/dev/ttyUSB0
echo "?" > /var/gps_latitude
echo "?" > /var/gps_longitude
echo "?" > /var/gps_altitude
echo "?" > /var/gps_sats_in_view
echo "?" > /var/gps_heading
echo "?" > /var/gps_speed
echo gazoox greets you --> gps_Deamon started 
while true;
do
awk -F , '$1=="$GPGGA" {print}' $gps | head -n 1 > /var/gps_GPGGA
awk -F , '$1=="$GPRMC" {print}' $gps | head -n 1 > /var/gps_GPRMC
echo
echo
echo --------------------------
echo : $(cat /var/gps_GPGGA)
echo : $(cat /var/gps_GPRMC)
# echo $(awk -F , '$1=="$GPGGA" {print $2}' /var/gps_GPGGA)
# echo $(awk -F , '$1=="$GPRMC" {print $2}' /var/gps_GPRMC)     
awk -F , '$1=="$GPRMC" {print $3}' /var/gps_GPRMC > /var/gps_valid
good_pos=$(cat /var/gps_valid)
case $good_pos in
        V)      echo GPS Data is NOT VALID !!!
                echo "?" > /var/gps_latitude
                echo "?" > /var/gps_longitude
                echo "?" > /var/gps_altitude
                awk -F , '$1=="$GPGGA" {print $8}' /var/gps_GPGGA >
/var/gps_sats_in_view >
                echo "?" > /var/gps_heading
                echo "?" > /var/gps_speed
                ;;                      
        A)      # echo GPS Data is valid
                awk -F , '$1=="$GPGGA" {print $3 $4}' /var/gps_GPGGA >
/var/gps_latitude
                awk -F , '$1=="$GPGGA" {print $5 $6}' /var/gps_GPGGA >
/var/gps_longitude
                awk -F , '$1=="$GPGGA" {print $10 $11}' /var/gps_GPGGA >
/var/gps_altitude
                awk -F , '$1=="$GPGGA" {print $8}' /var/gps_GPGGA >
/var/gps_sats_in_view                   
                awk -F , '$1=="$GPRMC" {print $9}' /var/gps_GPRMC > 
/var/gps_heading
                awk -F , '$1=="$GPRMC" {print $8}' /var/gps_GPRMC > 
/var/gps_speed
                ;;
        esac
        echo    
        echo lat_________: $(cat /var/gps_latitude)
        echo lon_________: $(cat /var/gps_longitude)
        echo altitude____: $(cat /var/gps_altitude)
        echo sats_in_view: $(cat /var/gps_sats_in_view)
        echo heading_____: $(cat /var/gps_heading)°     
        speed=$(cat /var/gps_speed)
        if [ "$speed" = "" ]; then
                speed=0
        fi      
        echo speed_______: $speed knots 
        sleep 1
done
exit 0

-----------------------snip-----------------------



It works with my USB-mouse with an pl-2302 serial to usb
changer, but should work with all standard gps-mice (serial or usb
with fox-supported usb-serial chips).

A few notes and explanations:

1) 
First, you should check on wich device the data is received. Check
/dev/ttyUSB[x] or the serials on /dev/ttyS[x]. You can print the data
via "cat /dev/ttyUSB0" for example. If you connect a serial mouse,
configure the serial port with "stty" first.

2) 
Make your "stty" entry in the script, if needed.

3) 
gps=... must represent your correspondenting device

4) 
The script is running in an endless loop. Each data line is checked
via "awk". The each data is writen into a separate file which includes
the parameter in readable ascii. (The /var directory is in the ram,
not in flash!). A little bit tricky was to recognize the lines and
then move the SINGLE message line to a separate file for extracting
the parameters in the next step. When you use "cat /dev/ttyUSB0" for
example, a EOF-signal (end of file) is never received...

5) 
You can run the script as a background task with "gps_d &". You can
remove the echo lines or start it with "gps_d > /dev/null &" if you
don't want a console output.

6) 
-->When the script runs in backgroung, you can access and use the
parameter files (/var/gps_xxxx) in your own scripts, compiled c
programs or even in a html script from the webbrowser.
In the shell you could use it with "cat /var/gps_xxxx"

7) 
The processing of the NMEA-data lines are optimized for my
gps-mouse. Note that awk is waiting for the GPGGA and then for the
GPRMC line before the results are written in the parameter files.
Perhaps you can get a faster processing if you swap the first two
lines ("awk...") after the do command.

8) 
For starting the script automatically after booting up, include a
small startup script in /etc/init.d/boottime. All scripts in this
directory are runned after the boot process. Don't forget "chmod +x .."
for example:
--snip--
#!/bin/sh
exec /mnt/1/my_deamons/gps_d > /dev/null &
exit 0
--snip--

9) 
The skript works not realy in realtime, but fast enough. Even the
gps-mouse sends only one gps coordinate every second. Faster update
rates are not usual with the cheap ones.

Have fun!



I spend much time on my "foxboard project", so please leave a comment
if this HowTo was helpfull for you.

Greetings
gazoox

Reply via email to