#!/bin/bash
#
# find-garmin
#
# iterate through all valid Garmin receiver baud rates and detect if the
# GPS receiver is sending/receiving.
#

if [ -z "$1" ]; then
    echo "Usage: find-garmin <device>"
    exit 1
fi

for baudrate in 4800 9600 38400 19200; do

    stty -F $1 $baudrate

    gps-garmin --device $1 --is-garmin > /dev/null 2>&1

    if [ $? -eq 0 ]; then
        echo -n "Garmin GPS receiver found at " 1>&2
        echo -n "${baudrate}"
        echo "." 1>&2
        exit 0
    fi

done

echo "Garmin GPS receiver not found." 1>&2
exit 1