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

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

# HISTORY:
#  Mar 10, 2004: - begun
#  Mar 18, 2004: - released
#  Mar 20, 2004: - changed hwconfig file names
#  Jun 18, 2004: - BUG: could not handle stn 008
#  Jan 25, 2005: - BUG: bbabble could not be in relative path (on MacOSX)
#  Feb 14, 2006: - BUG: log files were written to bin dir
#  Oct  4, 2006: - adapted to older expect version
#  Oct 28, 2006: - allowed for lrb downcasing filenames
#  Nov  6, 2006: - BUG: error when DL download finished much before UL
#  Nov 19, 2008: - added version
#  Aug 25, 2010: - DEFAULTS.expect -> CRUISE_SETUP.expect
#		 - libBB.expect -> libRDI.expect
#  Aug 26, 2010: - added support for ymodem_download_cmd
#  Dec  1, 2010: - BUG: ymodem_receive_cmd instead of ymodem_download_cmd
#  Nov 10, 2013: - added directory listing before download
#  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 ![file isdirectory $raw_dir] {
	error "directory $raw_dir does not exist";
}

if {$argc != 0} {
  if {![affirm "downloading files to directory [lindex $argv 0] --- ok (y/N)? " 10]} {
    exit;
  }
}

#----------------------------------------------------------------------
# List Memory Contents
#----------------------------------------------------------------------

spawn bbabble -ms $tty0 $tty1;

set_color;
send_user "Connecting to instruments...";
wait_for_startup;
reset_two_instruments;

select_DL 0; send_user "\n"; list_dir;
select_UL; send_user "\n"; list_dir;

#----------------------------------------------------------------------
# Get Station Number & Carry Out Sanity Check
#----------------------------------------------------------------------

send_user "\nGetting station number...";
select_DL;
set DL_deployment_name [get_deployment_name];
if {[scan $DL_deployment_name $DL_deployment_name_fmt DL_stn] != 1} {
	send_error "$DL_deployment_name $DL_deployment_name_fmt";
	error "Can't get station number of DL";
}
select_UL; set UL_deployment_name [get_deployment_name];
set UL_deployment_name [get_deployment_name];
if {[scan $UL_deployment_name $UL_deployment_name_fmt UL_stn] != 1} {
	error "Can't get station number of UL";
}
if {$DL_stn != $UL_stn} {
	select_DL; put_to_sleep; select_UL; put_to_sleep;
	error "DL/UL stations disagree";
}
set stn [format $stn_format $DL_stn];
send_user "\[$stn\]";

set cast_dir [format %s/%s $raw_dir $stn];
if {![file isdirectory $cast_dir]} {
	select_DL; put_to_sleep; select_UL; put_to_sleep;
	error "cast directory $cast_dir does not exist!";
}
regsub {^[^/]} [exec which bbabble] "[exec pwd]/&" bbabble;
if {$argc == 1} {				# override download directory
	set cast_dir [lindex $argv 0];
	if {![file isdir $cast_dir]} {exec mkdir $cast_dir}
}

cd $cast_dir;
if {[llength [glob -nocomplain {*.[0-9][0-9][0-9]}]] > 0} {
	select_DL; put_to_sleep; select_UL; put_to_sleep;
	error "cast directory [pwd] contains RDI data files!";
}

send \004;

#----------------------------------------------------------------------
# Download Data
#----------------------------------------------------------------------

regsub {.*/} $argv0 {} basename;
start_logging [format %s_%03d.log $basename $DL_stn];

spawn $bbabble -msy $ymodem_receive_cmd $tty0 $tty1;
wait_for_startup;

send_user "\nSaving hardware configurations...";
select_DL; save_hardware_config [format %s000.LOG $DL_deployment_name];
resume_logging [format %s_%03d.log $basename $DL_stn];
select_UL; save_hardware_config [format %s000.LOG $UL_deployment_name];
resume_logging [format %s_%03d.log $basename $DL_stn];

send_user "\nStarting parallel downloads...";
select_DL; start_download;
select_UL; start_download;

# NB: UL is assumed to download faster => finish it first, coz otherwise
#     it may auto-sleep and cause problems later on

send_user "\n";
set_color 1; log_user 1; wait_for_download_finish $DL_stn $download_timeout;
log_user 0; set_color;
send_user "\nPutting UL to sleep..."; put_to_sleep; send_user "\n";

toggle_instrument;
set_color 0; log_user 1; wait_for_download_finish $DL_stn $download_timeout;
log_user 0; set_color;
send_user "\nPutting DL to sleep..."; ensure_sleep; send_user "\n";
	
#----------------------------------------------------------------------
# Check and Backup Data
#----------------------------------------------------------------------

send_user "\nChecking data files...\n";
set_color 0; check_data [format %s000.000 [format $DL_deployment_name_fmt $DL_stn]];
set_color 1; check_data [format %s000.000 [format $UL_deployment_name_fmt $UL_stn]];
set_color;

send_user "Backing up data files...";
backup_DL_data $DL_stn;
backup_UL_data $DL_stn;

send_user "\nDone\n"