#!/usr/bin/expect -- # Kermit to ROSR. First use 'g' to go to operate mode in case the rosr was # left in the menu. Then 't' to go to menu, prompt='>'. Command 'fc' closes # the shutter. Quit connection and bootoff the power. set PROGRAMNAME RosrShutDown set VERSION 2 set EDITDATE 180608 # Connect to ROSR. Go to terminal mode. 'd325' points the drum inside. # 'fc' closes the shutter. 'bootoff' shuts off the power. # puts "RUN PROGRAM $PROGRAMNAME, VERSION $VERSION, EDITDATE $EDITDATE" set loguser 0; # test 0-quiet, 1=verbose log_user $loguser; # SETUP FILE DEFINED set setupfile "setup/su.txt"; ## SEE IF THE SETUP FILE EXISTS if [catch {open $setupfile} sufile] { puts "Setup file open fails, exit 1" exit 1 } global ROSR ROSRPID #======================================================== # PROCEDURE TO CONNECT TO ROSR #============================================================ proc SpawnRosr { hubip rosrport} { global ROSR ROSRPID if { [string first "dev" $hubip] == -1 } { set str [spawn_kermit $hubip $rosrport] set ROSR [lindex $str 0]; set ROSRPID [lindex $str 1]; #send_user "SPAWN ROSR KERMIT, IP=$hubip, port=$rosrport, spawn_id=$ROSR, pid=$ROSRPID\n" } else { set str [spawn_kermit232 $hubip] set ROSR [lindex $str 0]; set ROSRPID [lindex $str 1]; #send_user "SPAWN KERMIT232, IP=$hubip, spawn_id=$ROSR, pid=$ROSRPID\n" } } #=========================================================================== # PROCEDURE TO CONNECT TO A PORT USING KERMIT # input # serialport = full path name for the serial port, e.g. /dev/tty.usbserial0 # baud = desired baud rate, e.g. 9600 #============================================ proc spawn_kermit {hubip portnumber} { # START PROCESS -- KERMIT set pid [spawn kermit] expect { timeout {send_user "KERMIT FAILS TO OPEN\n"; exit 1} ">>" } # OPEN THE PORT send "set host $hubip $portnumber\r" expect ">>" send "set tcp keepalive on 0\r\n" expect ">>" send "set tcp linger OFF\r\n" expect ">>" send "set tcp nodelay on\r\n" expect ">>" send "set telnet echo local\r\n" expect ">>" # this is important for using the rsr menu # raw means send CR by itself, not CRLF and NOT CRNul send "set telnet newline-mode nvt raw\r\n" expect ">>" # CONNECT send "connect\r" expect { timeout {send_user "TIMEOUT, NO CONNECT"; exit 1} "Conn*---" { } #v15 } set out $spawn_id; lappend out $pid return $out } #=========================================================================== # PROCEDURE TO CONNECT RS232 TO A PORT USING KERMIT # input # serialport = full path name for the serial port, e.g. /dev/tty.usbserial0 # baud = desired baud rate, e.g. 9600 #============================================ proc spawn_kermit232 {hubip} { # START PROCESS -- KERMIT set pid [spawn sudo kermit] expect { "assword" { send "r0srr0sr\n" } ">>" { send "\n" } } #send_user "!> pid = $pid\n"; set timeout 4 expect { timeout {"KERMIT FAILS TO OPEN\n"; exit 1} ">>" } # OPEN THE PORT ## OPEN THE PORT send "set line $hubip\r" expect ">>" #send_user "set line $hubip\n"; ## SPEED send "set speed 9600\r" ## DUPLEX send "set duplex full\r" expect ">>" ## LOCAL ECHO send "set local-echo on\r" expect ">>" ## FLOW CONTROL send "set flow none\r" expect ">>" ## CARRIER WATCH send "set carrier-watch off\r" expect ">>" ## LOG send "log session ../data/capture.txt append\r" expect ">>" ## CONNECT send "connect\r" expect { "Conn*---" {send_user "232 CONNECTED\n"} timeout {send_user "TIMEOUT, NO CONNECT"; exit 1} } set out $spawn_id; lappend out $pid return $out } #==================== END PROCEDURES ============================================= # PDS SERIAL HUB spawn -noecho getsetupinfo $setupfile "SERIAL HUB IP" expect -re "(\.*)(\r)"; set hubip $expect_out(1,string) # ROSR PORT spawn -noecho getsetupinfo $setupfile "ROSR PORT" expect -re "(\.*)(\r)"; set rosrport $expect_out(1,string) send_user "hub ip: $hubip port: $rosrport\n"; # OPEN SERIAL PORTS SpawnRosr $hubip $rosrport set spawn_id $ROSR # SEND G TO BE SURE WE ARE sampling send "g\r" sleep 1 # NOW SEND 'T' TO GO TO MENU send "t" expect { timeout {send_user "timeout waiting for prompt\n"} ">" {} } send "fc\r" expect { timeout {send_user "timeout waiting for prompt\n"} ">" {send_user "fc prompt received\n"} } # Kermit break ^\ q = 0X1C send \028 send "q" # bootoff set ip [exec getsetupinfo "setup/su.txt" "IBOOT IP"] if { $ip == 0 } { send_user "No iboot in this DAQ\n" } else { exec bootoff } send_user "FINISHED\n"; exit 0;