ladcp1
author A.M. Thurnherr <athurnherr@yahoo.com>
Fri, 03 Jul 2020 10:25:08 -0400
changeset 12 5e67754f6457
parent 5 f41d45fe7ae9
permissions -rwxr-xr-x
V1.6: no more master/slave terminology

#!/usr/bin/expect -f
#======================================================================
#                    L A D C P 1 
#                    doc: Wed Mar 10 22:23:52 2004
#                    dlm: Fri Jul  3 10:16:21 2020
#                    (c) 2004 A.M. Thurnherr
#                    uE-Info: 21 40 NIL 0 0 72 2 2 8 NIL ofnI
#======================================================================

# HISTORY:
#  Apr  4, 2004: - adapted from [ladcp2]
#  Jun 17, 2004: - BUG: bombed on station #008 (octal digit)
#  Feb 14, 2006: - BUG: log files were written to bin dir
#  Oct 28, 2006: - adapted to old version of expect
#  Oct 31, 2007: - BUG: wrong default on non-empty memory
#  Nov 19, 2008: - adapted to new firmware behavior (load_factory_defaults)
#  Nov 19, 2008: - added version
#  Aug 25, 2010: - DEFAULTS.expect -> CRUISE_SETUP.expect
#		 - libBB.expect -> libRDI.expect
#  Dec 10, 2010: - allow restarting a cast with same number
#  Jul  3, 2020: - expunged master/slave terminology

#----------------------------------------------------------------------
# Setup
#----------------------------------------------------------------------

log_user 0;
source CRUISE_SETUP.expect;
regsub {dir1} [exec which dir1] {libRDI.expect} path;
source $path;

print_version;

if {$argc == 0} {
	set ask 1;
	if {[file isfile .last_stn]} {
		set stn [expr [exec cat .last_stn] + 1];
		set stnstr [format $stn_format $stn];
		if {[affirm "Use station number $stnstr? (y/N) " 10]} {
			set ask 0;
		}
	}
	if {$ask == 1} {
		set stn [input_int "Station number = "];
		set stnstr [format $stn_format $stn];
	}
} else {
	set stn [lindex $argv 0];
	set stnstr [format $stn_format $stn];
}

if ![file isdirectory $raw_dir] {
	error "directory $raw_dir does not exist";
}

set cast_dir [format %s/%s $raw_dir $stnstr];
if [file isdirectory $cast_dir] {
	if {![affirm "WARNING: data directory $cast_dir exists --- are you sure station number $stnstr is ok? (y/N) " 10]} {
		send_error "$argv0 aborted\n";
		exit 0;
	}
	set attempt 1;					# rename
	while {[file isdirectory $cast_dir.aborted$attempt]} {
		set attempt [expr $attempt + 1];
	}
	exec mv $cast_dir $cast_dir.aborted$attempt;
	send_user "data directory $cast_dir renamed to $cast_dir.aborted$attempt\n"
}

set prev_cast_dir [format %s/$stn_format $raw_dir [expr $stn - 1]];
if {![file isdirectory $prev_cast_dir]} {
	if {![affirm "WARNING: previous-station data directory $prev_cast_dir does not exist --- are you sure station number $stnstr is ok? (y/N) " 10]} {
		send_error "$argv0 aborted\n";
		exit 0;
	}
}

#----------------------------------------------------------------------
# Deploy LADCP
#----------------------------------------------------------------------

set_color;
send_user "Connecting to instrument...";
spawn bbabble -ms $tty0;
wait_for_startup;
reset_instrument;
if {![memory_empty]} {
	if {![affirm "\nWARNING: Memory is not empty; continue anyway? (y/N) " 10]} {
		send_user "Putting instrument to sleep...";
		put_to_sleep;
		send_user "\nDone\n";
		exit;
	}
} else {
	send_user "\n";
}

exec mkdir $cast_dir;
exec cp $DL_cmd_file $cast_dir;
exec echo $stn > .last_stn;
cd $cast_dir;

if {![file isfile $DL_cmd_file]} {
	error "Failed to copy $DL_cmd_file to [pwd]";
}


regsub {.*/} $argv0 {} basename;
start_logging [format %s_%s.log $basename $stnstr];

send_user "Resetting instrument to factory defaults...";
load_factory_defaults;

send_user "\nSetting instrument clock...";
set_computer_time;
set_instrument_clock;

send_user "\nSetting deployment name...";
set_deployment_name [format $DL_deployment_name_fmt $stn];

send_user "\nUploading command file";
upload_file $DL_cmd_file [format %s_log $DL_cmd_file] "[format $DL_deployment_name_fmt $stn].hwconfig";

send_user "\nDone\n";