#! /bin/sh
# ############################################################################
#                                                                            #
#            Copyright (C) 1985, 1986, 1987, 1990, Alias Research, Inc.      #
#                                                                            #
#    These coded instructions,  statements and  computer programs contain    #
#    unpublished information proprietary to Alias Research, Inc.  and are    #
#    protected by the Canadian and US Federal copyright law. They may not    #
#    be disclosed to third parties  or copied  or duplicated, in whole or    #
#    in part,  without the prior written consent of Alias Research,  Inc.    #
#                                                                            #
# Unpublished-rights reserved under the Copyright Laws of the United States. #
#                                                                            #
# ############################################################################
#
# $Source: /tmp_mnt/worf/root/v/alias5.1/src/Utility/stand/RCS/fromava.sh,v $ $Revision: 5.0 $
# $Author: software $ $Date: 94/03/23 02:39:59 $

programname=`basename $0`
avaport=/dev/ttyd2

help()
{
	/bin/cat << EOF
PURPOSE:   transfer image from AVA-3 and store into ALIAS format pixfile
USAGE:     $programname [-d <port>] [<file>]
FLAGS:
-d <port>  this specifies that the AVA-3 is connected to the host through
           the specified serial port. The default port is $avaport.
<file>     specifies the name of ALIAS format pixfile. If <file> is not
           specified the ALIAS format pixfile is sent to standard output
COMMENTS:
           This program should be started first and then the appropriate
           transfer program should be started on the AVA-3.
EOF
}

error()
{
	echo ${programname}: $1 1>&2
	exit 1
}

if [ "$1" = "-" ]; then
	help
	exit 0
fi

while getopts d: arg
do
	case $arg in
	d)	avaport="$OPTARG" ;;
	\?)
		error "invalid option -$arg" ;;
	esac
done

#
#	shift past all options
#
shift `expr $OPTIND - 1`

if [ $# -gt 1 ]; then
	error \
"Usage:\\n$programname [-d <port>] [<file>]"
fi

if [ $# -eq 1 ]; then
	imagefile=$1
fi

kermit -l $avaport -b 9600 -ki | ava_decode $imagefile
