0
|
1 |
#!/usr/bin/expect -f
|
|
2 |
#======================================================================
|
|
3 |
# L A D C P _ S E N D _ C M D
|
|
4 |
# doc: Wed Mar 10 22:23:52 2004
|
|
5 |
# dlm: Wed Nov 19 15:16:20 2008
|
|
6 |
# (c) 2004 A.M. Thurnherr
|
|
7 |
# uE-Info: 26 14 NIL 0 0 72 2 2 8 NIL ofnI
|
|
8 |
#======================================================================
|
|
9 |
|
|
10 |
# HISTORY:
|
|
11 |
# Apr 4, 2004: - adapted from [ladcp1]
|
|
12 |
# Feb 14, 2006: - BUG: log files were written to bin dir
|
|
13 |
# Nov 6, 2006: - adapted to old regsub
|
|
14 |
# Nov 19, 2008: - adapted to new firmware behavior (load_factory_defaults)
|
|
15 |
# Nov 19, 2008: - added version
|
|
16 |
|
|
17 |
#----------------------------------------------------------------------
|
|
18 |
# Setup
|
|
19 |
#----------------------------------------------------------------------
|
|
20 |
|
|
21 |
log_user 0;
|
|
22 |
source DEFAULTS.expect;
|
|
23 |
regsub {dir1} [exec which dir1] {libBB.expect} path;
|
|
24 |
source $path;
|
|
25 |
|
|
26 |
print_version;
|
|
27 |
|
|
28 |
if {$argc != 2} {
|
|
29 |
error "Usage: $argv0 <tty port> <cmd-file>"
|
|
30 |
}
|
|
31 |
if {![file isfile [lindex $argv 1]]} {
|
|
32 |
error "[lindex $argv 1]: no such file"
|
|
33 |
}
|
|
34 |
|
|
35 |
set ask 1;
|
|
36 |
if {[file isfile .last_stn]} {
|
|
37 |
set stn [format $stn_format [expr [exec cat .last_stn] + 1]];
|
|
38 |
if {[affirm "Use station number $stn? (y/N) " 10]} {
|
|
39 |
set ask 0;
|
|
40 |
}
|
|
41 |
}
|
|
42 |
if {$ask == 1} {
|
|
43 |
set stn [format $stn_format [input_int "Station number = "]];
|
|
44 |
}
|
|
45 |
|
|
46 |
if ![file isdirectory $raw_dir] {
|
|
47 |
error "directory $raw_dir does not exist";
|
|
48 |
}
|
|
49 |
set cast_dir [format %s/%s $raw_dir $stn];
|
|
50 |
if [file isdirectory $cast_dir] {
|
|
51 |
error "data directory $cast_dir already exists!";
|
|
52 |
}
|
|
53 |
set prev_cast_dir [format %s/%s $raw_dir [expr $stn - 1]];
|
|
54 |
if {![file isdirectory $prev_cast_dir]} {
|
|
55 |
if {![affirm "WARNING: previous-station data directory $prev_cast_dir does not exist --- are you sure the station number $stn is ok? (y/N) " 10]} {
|
|
56 |
send_error "$argv0 aborted\n";
|
|
57 |
exit 0;
|
|
58 |
}
|
|
59 |
}
|
|
60 |
|
|
61 |
#----------------------------------------------------------------------
|
|
62 |
# Deploy LADCP
|
|
63 |
#----------------------------------------------------------------------
|
|
64 |
|
|
65 |
set_color;
|
|
66 |
send_user "Connecting to instrument...";
|
|
67 |
spawn bbabble -ms [lindex $argv 0];
|
|
68 |
wait_for_startup;
|
|
69 |
reset_instrument;
|
|
70 |
if {![memory_empty]} {
|
|
71 |
if {![affirm "\nWARNING: Memory is not empty; continue anyway? (y/N) " 10 1]} {
|
|
72 |
send_user "Putting instrument to sleep...";
|
|
73 |
put_to_sleep;
|
|
74 |
send_user "\nDone\n";
|
|
75 |
exit;
|
|
76 |
}
|
|
77 |
} else {
|
|
78 |
send_user "\n";
|
|
79 |
}
|
|
80 |
|
|
81 |
exec mkdir $cast_dir;
|
|
82 |
exec cp [lindex $argv 1] $cast_dir;
|
|
83 |
exec echo $stn > .last_stn;
|
|
84 |
cd $cast_dir;
|
|
85 |
|
|
86 |
if {![file isfile [lindex $argv 1]]} {
|
|
87 |
error "Failed to copy [lindex $argv 1] to [pwd]";
|
|
88 |
}
|
|
89 |
|
|
90 |
regsub {.*/} $argv0 {} basename;
|
|
91 |
start_logging [format %s_%03d.log $basename $stn];
|
|
92 |
|
|
93 |
send_user "Resetting instrument to factory defaults...";
|
|
94 |
load_factory_defaults;
|
|
95 |
|
|
96 |
send_user "Setting instrument clock...";
|
|
97 |
set_computer_time;
|
|
98 |
set_instrument_clock;
|
|
99 |
|
|
100 |
send_user "\nSetting deployment name...";
|
|
101 |
set_deployment_name [format $master_deployment_name_fmt $stn];
|
|
102 |
|
|
103 |
send_user "\nUploading command file";
|
|
104 |
upload_file [lindex $argv 1] [format %s_log [lindex $argv 1]] "DEPLOY.hwconfig";
|
|
105 |
|
|
106 |
send_user "\nDone\n";
|