#!/usr/bin/tclsh
#-------------------------------------------------------------------------
# This is the regression test for SICS on the MARS instrument
#
# Mark Koennecke, November 2006
#------------------------------------------------------------------------
source sicstcldebug.tcl
source insttestutil.tcl
source marsinventory.tcl

#------ If there is another argument, test at localhost: for debugging...
if {$argc > 0} {
	set instrument local
} else {
	set instrument mars
} 

initSicsDebug $instrument
config rights lnsmanager lnsMARSlns

set th [SICSValue th01]
if {[string equal $instrument local]} {
    colldr tf 12
}

standardPrelude $instrument count
set thresh [SICSValue "el737  getthrehold 1"]

#---------- configuration
lappend notList chopperspeed snailphase masterphase rabbitphase fourphase 
lappend notList fivephase s1phase mphase s2phase s3phase s4phase mspeed
lappend notList masterspeed

lappend commandList "count timer 2"
lappend commandList "repeat 2"
lappend commandList "wwwsics"
lappend commandList "marsupdateinfo"
lappend commandList "colldr th 86."


lappend interruptList "colldr th 77."
lappend interruptList "count timer 120"
lappend interruptList "exe insttestbatch.tcl"


set par(inventory) $inventory
set par(driveCommand) drive
set par(motorList) $motors
set par(notList) $notList
set par(commandList) $commandList
set par(interruptList) $interruptList
set par(instrument) $instrument
set par(user) lnsmanager
set par(password) lnsSICSlns

#================= actually test =====================================
set counters [runStandardTests par]

#--------- Test detection system
puts stdout "Testing detector"
set det 1
count timer 600
set tf [SICSValue "hm notimebin"]
set counts [SICSValue "hm sum 0 24 0 $tf"]
if {$counts <= 0}  {
   set det 0
}
if {$det == 1} {
	puts stdout "Detector passed"
} else {
   puts stdout "Check detector, found no noise after 10 minutes counting"
}
#--------- put detector back where it was
colldr th $th

standardRestore
el737 setthreshold 1 $thresh

#------------ print a summary
set inst [string toupper $instrument]
puts stdout "Test Summary for $inst"
printStandardSummary $counters
puts stdout "Choppers NOT tested!!"

exit
