1 #!/usr/bin/expect -f |
1 #!/usr/bin/expect -f |
2 #====================================================================== |
2 #====================================================================== |
3 # L I B R D I . E X P E C T |
3 # L I B R D I . E X P E C T |
4 # doc: Mon Mar 8 02:57:35 2004 |
4 # doc: Mon Mar 8 02:57:35 2004 |
5 # dlm: Wed Dec 29 16:00:39 2010 |
5 # dlm: Fri Jul 3 10:23:56 2020 |
6 # (c) 2004 A.M. Thurnherr |
6 # (c) 2004 A.M. Thurnherr |
7 # uE-Info: 255 0 NIL 0 0 72 2 2 8 NIL ofnI |
7 # uE-Info: 48 40 NIL 0 0 72 2 2 8 NIL ofnI |
8 #====================================================================== |
8 #====================================================================== |
9 |
9 |
10 # HISTORY: |
10 # HISTORY: |
11 # Mar 8, 2004: - incepted (NBP0402) |
11 # Mar 8, 2004: - incepted (NBP0402) |
12 # Mar 15, 2004: - released |
12 # Mar 15, 2004: - released |
41 # instruments sent to the DIMES cruise |
41 # instruments sent to the DIMES cruise |
42 # Aug 25, 2010: - libBB.expect -> libRDI.expect |
42 # Aug 25, 2010: - libBB.expect -> libRDI.expect |
43 # Dec 1, 2010: - replaced ! by * in upload_file |
43 # Dec 1, 2010: - replaced ! by * in upload_file |
44 # Dec 9, 2010: - increased timeout to 10s in load_factory_defaults |
44 # Dec 9, 2010: - increased timeout to 10s in load_factory_defaults |
45 # Dec 10, 2010: - changed version to 1.5 |
45 # Dec 10, 2010: - changed version to 1.5 |
46 # Dec 29, 2010: - implemented work-around to always wake up slave first |
46 # Dec 29, 2010: - implemented work-around to always wake up uplooker first |
|
47 # Jul 3, 2020: - expunged master/slave terminology |
|
48 # - changed version to 1.6 |
47 |
49 |
48 # NOTE: after having written this, I am not much of a fan of TCL and and |
50 # NOTE: after having written this, I am not much of a fan of TCL and and |
49 # expect(1) syntax any more... |
51 # expect(1) syntax any more... |
50 |
52 |
51 # PS0 ON BB150 NOTE: |
53 # PS0 ON BB150 NOTE: |
144 -timeout 3 "Instrument" |
146 -timeout 3 "Instrument" |
145 } |
147 } |
146 if {$cid == 0} {set cid 1} else {set cid 0} |
148 if {$cid == 0} {set cid 1} else {set cid 0} |
147 } |
149 } |
148 |
150 |
149 proc select_master {{toggle_first 1}} { # select master & check S/N |
151 proc select_DL {{toggle_first 1}} { # select DL & check S/N |
150 global cid master_sn slave_sn; |
152 global cid DL_sn UL_sn; |
151 |
153 |
152 if {$toggle_first} toggle_instrument; |
154 if {$toggle_first} toggle_instrument; |
153 gobble_prompts; |
155 gobble_prompts; |
154 send "\r"; wait_for_prompt; # save current value |
156 send "\r"; wait_for_prompt; # save current value |
155 send "PS0\r"; |
157 send "PS0\r"; |
156 expect { |
158 expect { |
157 timeout {error "Can't determine serial number"} |
159 timeout {error "Can't determine serial number"} |
158 -timeout 8 -re "Instrument S/N: $master_sn.*>|Xducer Ser #: $master_sn.*>|PS0...>" {} |
160 -timeout 8 -re "Instrument S/N: $DL_sn.*>|Xducer Ser #: $DL_sn.*>|PS0...>" {} |
159 -timeout 8 -re "Instrument S/N: $slave_sn.*>" { |
161 -timeout 8 -re "Instrument S/N: $UL_sn.*>" { |
160 toggle_instrument; |
162 toggle_instrument; |
161 send "PS0\r"; |
163 send "PS0\r"; |
162 expect { |
164 expect { |
163 timeout {error "Can't determine serial number"} |
165 timeout {error "Can't determine serial number"} |
164 -timeout 8 -re "Instrument S/N: $master_sn.*>|Xducer Ser #: $master_sn.*>|PS0...>" {} |
166 -timeout 8 -re "Instrument S/N: $DL_sn.*>|Xducer Ser #: $DL_sn.*>|PS0...>" {} |
165 -timeout 8 -re "Instrument S/N: $slave_sn.*>" { |
167 -timeout 8 -re "Instrument S/N: $UL_sn.*>" { |
166 error "Can't switch to master" |
168 error "Can't switch to DL" |
167 } |
169 } |
168 } |
170 } |
169 } |
171 } |
170 } |
172 } |
171 set cid 0; |
173 set cid 0; |
172 } |
174 } |
173 |
175 |
174 proc select_slave {{toggle_first 1}} { # select slave & check S/N |
176 proc select_UL {{toggle_first 1}} { # select UL & check S/N |
175 global cid master_sn slave_sn; |
177 global cid DL_sn UL_sn; |
176 |
178 |
177 if {$toggle_first} toggle_instrument; |
179 if {$toggle_first} toggle_instrument; |
178 gobble_prompts; |
180 gobble_prompts; |
179 send "\r"; wait_for_prompt; # save current value |
181 send "\r"; wait_for_prompt; # save current value |
180 send "PS0\r"; |
182 send "PS0\r"; |
181 expect { |
183 expect { |
182 timeout {error "Can't determine master/slave"} |
184 timeout {error "Can't determine DL/UL"} |
183 -timeout 8 -re "Instrument S/N: $slave_sn.*>" {} |
185 -timeout 8 -re "Instrument S/N: $UL_sn.*>" {} |
184 -timeout 8 -re "Instrument S/N: $master_sn.*>|Xducer Ser #: $master_sn.*>|PS0...>" { |
186 -timeout 8 -re "Instrument S/N: $DL_sn.*>|Xducer Ser #: $DL_sn.*>|PS0...>" { |
185 toggle_instrument; |
187 toggle_instrument; |
186 send "PS0\r"; |
188 send "PS0\r"; |
187 expect { |
189 expect { |
188 timeout {error "Can't determine master/slave"} |
190 timeout {error "Can't determine DL/UL"} |
189 -timeout 8 -re "Instrument S/N: $slave_sn.*>" {} |
191 -timeout 8 -re "Instrument S/N: $UL_sn.*>" {} |
190 -timeout 8 -re "Instrument S/N: $master_sn.*>|Xducer Ser #: $master_sn.*>|PS0...>" { |
192 -timeout 8 -re "Instrument S/N: $DL_sn.*>|Xducer Ser #: $DL_sn.*>|PS0...>" { |
191 error "Can't switch to slave" |
193 error "Can't switch to UL" |
192 } |
194 } |
193 } |
195 } |
194 } |
196 } |
195 } |
197 } |
196 set cid 1; |
198 set cid 1; |
220 -timeout 5 ">"; # instrument response received |
222 -timeout 5 ">"; # instrument response received |
221 } |
223 } |
222 } |
224 } |
223 |
225 |
224 # In 2010 on the DIMES UK2 cruise, it was found that the instruments did |
226 # In 2010 on the DIMES UK2 cruise, it was found that the instruments did |
225 # not communicate correctly, unless the slave was woken up first. On previous |
227 # not communicate correctly, unless the UL was woken up first. On previous |
226 # cruises it had also been found that the order in which the instruments are |
228 # cruises it had also been found that the order in which the instruments are |
227 # woken up can matter, although it had not been recorded which of the instruments |
229 # woken up can matter, although it had not been recorded which of the instruments |
228 # has to be woken first. An early workaround consisted in having a commented-out |
230 # has to be woken first. An early workaround consisted in having a commented-out |
229 # toggle_instrument statement at the beginning of reset_two_instruments. In case |
231 # toggle_instrument statement at the beginning of reset_two_instruments. In case |
230 # the communication did not work, that statement could simply be uncommented. |
232 # the communication did not work, that statement could simply be uncommented. |
231 # Another workaround would be to switch the serial ports the master/slave |
233 # Another workaround would be to switch the serial ports the DL/UL |
232 # ADCPs were connected to. Neither workaround is satisfacory, of course. Therefore |
234 # ADCPs were connected to. Neither workaround is satisfacory, of course. Therefore |
233 # I decided to modify the routine reset_two_instruments to wake up an instrument, |
235 # I decided to modify the routine reset_two_instruments to wake up an instrument, |
234 # determine whether it is the slave and, if not, send it back to sleep, toggle, |
236 # determine whether it is the UL and, if not, send it back to sleep, toggle, |
235 # and wake up the other one. I am hoping that this is solves the problems once |
237 # and wake up the other one. I am hoping that this is solves the problems once |
236 # and for all. If not, the code between the ### WORKAROUND markers should be |
238 # and for all. If not, the code between the ### WORKAROUND markers should be |
237 # removed because it slows down comms with the ADCPs even more. In case of |
239 # removed because it slows down comms with the ADCPs even more. In case of |
238 # wakeup/comms problems, the serial lines should then be switched. |
240 # wakeup/comms problems, the serial lines should then be switched. |
239 |
241 |
240 proc reset_two_instruments {} { # reset regardless of state |
242 proc reset_two_instruments {} { # reset regardless of state |
241 global cid master_sn slave_sn; |
243 global cid DL_sn UL_sn; |
242 set ok 0; |
244 set ok 0; |
243 |
245 |
244 while {$ok < 2} { |
246 while {$ok < 2} { |
245 no_error_BREAK; |
247 no_error_BREAK; |
246 send "\r"; expect { |
248 send "\r"; expect { |
254 } |
256 } |
255 ### WORKAROUND BEGIN |
257 ### WORKAROUND BEGIN |
256 send "PS0\r"; |
258 send "PS0\r"; |
257 expect { |
259 expect { |
258 timeout {error "Can't determine serial number"} |
260 timeout {error "Can't determine serial number"} |
259 -timeout 8 -re "Instrument S/N: $master_sn.*>|Xducer Ser #: $master_sn.*>|PS0...>" { |
261 -timeout 8 -re "Instrument S/N: $DL_sn.*>|Xducer Ser #: $DL_sn.*>|PS0...>" { |
260 put_to_sleep; |
262 put_to_sleep; |
261 toggle_instrument; |
263 toggle_instrument; |
262 put_to_sleep; |
264 put_to_sleep; |
263 reset_two_instruments; |
265 reset_two_instruments; |
264 toggle_instrument; |
266 toggle_instrument; |
265 } |
267 } |
266 -timeout 8 -re "Instrument S/N: $slave_sn.*>" { |
268 -timeout 8 -re "Instrument S/N: $UL_sn.*>" { |
267 toggle_instrument; |
269 toggle_instrument; |
268 } |
270 } |
269 send "PS0\r"; |
271 send "PS0\r"; |
270 expect { |
272 expect { |
271 timeout {error "Can't determine serial number"} |
273 timeout {error "Can't determine serial number"} |
272 -timeout 8 -re "Instrument S/N: $master_sn.*>|Xducer Ser #: $master_sn.*>|PS0...>" {} |
274 -timeout 8 -re "Instrument S/N: $DL_sn.*>|Xducer Ser #: $DL_sn.*>|PS0...>" {} |
273 -timeout 8 -re "Instrument S/N: $slave_sn.*>" { |
275 -timeout 8 -re "Instrument S/N: $UL_sn.*>" { |
274 error "Can't switch to master" |
276 error "Can't switch to DL" |
275 } |
277 } |
276 } |
278 } |
277 } |
279 } |
278 set cid 0; |
280 set cid 0; |
279 ### WORKAROUND ELSE |
281 ### WORKAROUND ELSE |
280 # select_master; |
282 # select_DL; |
281 ### WORKAROUND END |
283 ### WORKAROUND END |
282 } |
284 } |
283 |
285 |
284 proc wait_for_prompt {{tout 5}} { # wait for prompt |
286 proc wait_for_prompt {{tout 5}} { # wait for prompt |
285 expect { |
287 expect { |
342 error "Download did not finish ok"; |
344 error "Download did not finish ok"; |
343 } |
345 } |
344 } |
346 } |
345 expect -timeout 5 ">"; |
347 expect -timeout 5 ">"; |
346 |
348 |
347 global cid master_download_filename slave_download_filename; |
349 global cid DL_download_filename UL_download_filename; |
348 global master_deployment_name_fmt slave_deployment_name_fmt; |
350 global DL_deployment_name_fmt UL_deployment_name_fmt; |
349 if {$cid == 0} { |
351 if {$cid == 0} { |
350 rename_master_download_file [format $master_deployment_name_fmt $stn]000.000; |
352 rename_DL_download_file [format $DL_deployment_name_fmt $stn]000.000; |
351 } else { |
353 } else { |
352 rename_slave_download_file [format $slave_deployment_name_fmt $stn]000.000; |
354 rename_UL_download_file [format $UL_deployment_name_fmt $stn]000.000; |
353 } |
355 } |
354 } |
356 } |
355 |
357 |
356 proc list_dir {} { # list directory |
358 proc list_dir {} { # list directory |
357 global cid; |
359 global cid; |
543 expect -timeout 1 "ERR"; # BB150 |
545 expect -timeout 1 "ERR"; # BB150 |
544 wait_for_prompt; |
546 wait_for_prompt; |
545 } |
547 } |
546 |
548 |
547 proc get_deployment_name {} { # get deployment name |
549 proc get_deployment_name {} { # get deployment name |
548 global stn_format master_deployment_name_fmt; |
550 global stn_format DL_deployment_name_fmt; |
549 gobble_prompts; |
551 gobble_prompts; |
550 send "\r"; wait_for_prompt; |
552 send "\r"; wait_for_prompt; |
551 send "RN?\r"; sleep 1; |
553 send "RN?\r"; sleep 1; |
552 expect { |
554 expect { |
553 timeout {error "Can't get deployment name";} |
555 timeout {error "Can't get deployment name";} |
554 -timeout 1 "ERR" { # BB150 |
556 -timeout 1 "ERR" { # BB150 |
555 if {![file isfile .last_stn]} { |
557 if {![file isfile .last_stn]} { |
556 error "Can't find .last_stn"; |
558 error "Can't find .last_stn"; |
557 } |
559 } |
558 set stn [exec cat .last_stn]; |
560 set stn [exec cat .last_stn]; |
559 set dn [format $master_deployment_name_fmt $stn]; |
561 set dn [format $DL_deployment_name_fmt $stn]; |
560 wait_for_prompt; |
562 wait_for_prompt; |
561 return $dn; |
563 return $dn; |
562 } |
564 } |
563 -timeout 5 -re {Current deployment name = ([^\r]*)} |
565 -timeout 5 -re {Current deployment name = ([^\r]*)} |
564 } |
566 } |