#======================================================================
# C R U I S E _ S E T U P . E X P E C T
# doc: Wed Mar 10 21:14:18 2004
# dlm: Thu Aug 26 19:49:03 2010
# (c) 2004 A.M. Thurnherr
# uE-Info: 118 24 NIL 0 0 72 2 2 8 NIL ofnI
#======================================================================
#--------
# HISTORY
#--------
# Mar 10, 2004: - created during NBP0402
# Apr 4, 2004: - final version NBP0402
# Jun 15, 2004: - adapted to BB150/Workhorse setup
# Jun 16, 2004: - ditto
# Jun 19, 2004: - BUG: could not handle multiple BB150 data files
# Jan 19, 2006: - updated documentation
# - allowed for empty-string time_server
# Nov 4, 2006: - changed backup dir structure
# Aug 25, 2010: - rename* funs modified to allow them to be used to
# that downladed file names have correct case
# - renamed from DEFAULTS.expect to CRUISE_SETUP.expect
# Aug 26, 2010: - added ymodem_receive_cmd
# - changed default string quotes to {} to prevent Tcl variable
# and command substitutions
#-----------
# TWEAKABLES
#-----------
# At the beginning of each cast, the clock of the acquisition computer should
# synchronized with the master clock used for timestamping the GPS information.
# The easiest way to accomplish this is by probing an NTP server on the ship
# (if there is one), which can be defined by setting the following variable.
# If there is no such server available, the variable should be set to the
# empty string (set time_server {}), in which case clock synchronization must
# be done differently (e.g. manually).
set time_server {199.92.161.2};
# bbabble needs to know the tty device name(s) of the serial connection(s)
# to the ADCP head(s). If only one head is connected, tty1 is ignored.
# If two heads are connected, the device names are exchangeable, i.e.
# either instrument can be connected to either port.
set tty0 {/dev/ttyS0};
set tty1 {/dev/ttyS1};
# In case of 2 ADCP heads, babble needs to know which is the master and
# which is the slave. This is accomplished by setting the following variables
# to the corresponding instrument serial numbers (PS0 output). By convention,
# the downlooker is the master. If only a single head is connected, both
# variables are ignored.
set master_sn 7877;
set slave_sn 1412;
# Before deployment, every ADCP head has to be programmed by sending it
# a corresponding command file, defined by the following variables. If only
# a single head is connected, the slave_* variable is ignored.
set master_cmd_file {MASTER.cmd};
set slave_cmd_file {SLAVE.cmd};
# For convenience, it is best to use the station number to name the ADCP data
# files, and to indicate whether the data file comes from the master or
# slave. The following variables variables define the printf(3) format
# that is used to create the files names from the station number. If only
# a single head is connected, the slave_* variable is ignored.
# NOTE: Some implementations of the ymodem protocol (notably lrb running
# under Mandrake 8) use lowercase for the downloaded file. It is
# therefore better to use only lowercase characters in the deployment
# names.
set master_deployment_name_fmt {%03ddn};
set slave_deployment_name_fmt {%03dup};
# Older RDI instruments (e.g. the BB150) do not allow the data-file name
# to be defined in the instrument, in which case the files have to be
# renamed after downloading. The following variables define the shell
# globbing patterns for the master and slave. For example, the UH BB150
# used during CLIVAR P02 generated files with extension .612; the coresponding
# globbing pattern is {*.612}. If only a single head is connected, the
# slave_* variable is ignored.
# NB: For dual-headed LADCP systems it is important that the globs do not
# match both master and slave data files. {*.000} therefore will not
# work for dual-head Workhorse systems.
set master_download_glob {};
set slave_download_glob {};
# For consistency it is nicest if low station numbers contain leading
# zeroes. The following variable defines the corresponding printf(3) format.
set stn_format {%03d};
# The following directory is used to store command files, instrument
# configurations and ADCP data. Separate subdirectories (named according to
# stn_format) are used for each cast.
set raw_dir {../data/raw};
# After downloading, the data directory is backed up to the following
# directory. Make sure that it resides on a different disk than raw_dir.
# Empty string disables backup for testing purposes.
# NOTE: RELATIVE PATHNAMES MUST START FROM CAST DIR (NOT ACQUISITION DIR)
set backup_dir {../../backup/raw};
# By default, bbabble will look for standard UN*X ymodem receive
# programs (rb and lrb). If neither of these exist, if neither is in the
# current $PATH, or if options have to be passed (as is the case on some
# Linux distributions to ensure that the downloaded files have consistent
# (upper-)case filenames, the following variable can be set to a non-empty
# string, such as {rb -u}
set ymodem_receive_cmd {}
# bbabble can be made to abort downloading after a preset amount of time,
# defined by the following variable.
set download_timeout 999999;
#----------------------------------------------------------------------
# Semi-Standard Functions
#----------------------------------------------------------------------
proc set_computer_time {} { # set computer clock
global time_server;
if {[string length $time_server] == 0} {return}
exec sudo rdate -s $time_server;
}
proc check_data {file} { # check data file
exec sh -c "scanbb $file";
exec sh -c "sed -n '/^zmax/,/^zend/s/ at.*/m/p' `basename $file .000`.scn > /dev/tty";
}
proc backup_master_data {stn} { # copy data to network
global master_deployment_name_fmt master_cmd_file backup_dir;
if {[string length $backup_dir] == 0} {return}
if {![file isdirectory $backup_dir]} {
error "$backup_dir does not exist relative to [pwd]";
}
set master_dir [format $backup_dir/$master_deployment_name_fmt $stn];
if {![file isdirectory $master_dir]} {exec mkdir $master_dir};
exec sh -c "cp [format $master_deployment_name_fmt $stn]* $master_dir";
exec sh -c "cp $master_cmd_file* $master_dir";
exec sh -c "cp *log $master_dir";
}
proc backup_slave_data {stn} { # copy data to network
global slave_deployment_name_fmt slave_cmd_file backup_dir;
if {[string length $backup_dir] == 0} {return}
if {![file isdirectory $backup_dir]} {
error "$backup_dir does not exist relative to [pwd]";
}
set slave_dir [format $backup_dir/$slave_deployment_name_fmt $stn];
if {![file isdirectory $slave_dir]} {exec mkdir $slave_dir};
exec sh -c "cp [format $slave_deployment_name_fmt $stn]* $slave_dir";
exec sh -c "cp $slave_cmd_file* $slave_dir";
exec sh -c "cp *log $slave_dir";
}
proc rename_master_download_file {target} { # rename after download
global master_download_glob;
if {[string length $master_download_glob] == 0} {return}
set files [glob -nocomplain $master_download_glob];
set nfiles [llength $files];
if {$nfiles == 0} {
if {![file exists $target]} {
error {can't find downloaded master file};
}
return;
}
if {$nfiles > 1} {
send_user {WARNING: Multiple files downloaded from master --- rename, backup, check manually!};
}
if {![string equal [lindex $files end] $target]} {
exec mv [lindex $files end] $target;
}
}
proc rename_slave_download_file {target} { # rename after download
global slave_download_glob;
if {[string length $slave_download_glob] == 0} {return}
set files [glob -nocomplain $slave_download_glob];
set nfiles [llength $files];
if {$nfiles == 0} {
if {![file exists $target]} {
error {can't find downloaded slave file};
}
return;
}
if {$nfiles > 1} {
send_user {WARNING: Multiple files downloaded from slave --- rename, backup, check manually!};
}
if {![string equal [lindex $files end] $target]} {
exec mv [lindex $files end] $target;
}
}