#! /bin/csh
# sendm1 - C Shell script to send command to OASIS mooring at M1
#

set oasis = /oasis
set can = m1
set tncaddr = "mbari-4 v mbari-2"
set sendfile = $can.cmd
if ($#argv > 0) set sendfile = $1

if ( !(-e $sendfile) ) then
    echo "Can't find $sendfile.  Terminating"
    exit
endif

cd $oasis/raw/logs
set noclobber
set noglob
set failmail = "headley@mbari.org"

set i = 0
set datafile = $can.00
while ( -e $datafile )
	@ i++
	set datafile = $can.`printf "%02d" $i`
end

$oasis/bin/sendoasis -a "$tncaddr" -f $sendfile >& $datafile
set rtnsts = $status

if ( $rtnsts ) then
	/bin/mailx -s "Failed OASIS Command Script" $failmail << !
Download failure of file $sendfile
Return code was $rtnsts
	0 = Success
	1 = Argument error (bad command line arguments)
	2 = Couldn't acquire TNC port (there's probably a hung download)
	3 = Couldn't connect to OASIS (it's not listening)
	4 = Download error (something broke after it connected)
	5 = Abort error (somebody killed the download)
`date`
!
endif
