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

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

initSicsDebug $instrument
config rights lnsmanager lnsSICSlns

standradPrelude $instrument count
 
#--------- remember detector position...
set detpos [SICSValue detectorx]
bsin
drive detectorx 3.

#---------- configuration
set notList [list nvs nvswatch lambda]

lappend commandList "count timer 2"
lappend commandList "repeat 2"
lappend commandList "coll 3"
lappend commandList "testVarValue coll 3"
lappend commandList "coll 18"
lappend commandList "testVarValue coll 18"
lappend commandList "bsout"
lappend commandList "bsin"
lappend commandList "att 1"
lappend commandList "wwwsics"
lappend commandList "statusinfo"
lappend commandList "hmframe 0"
lappend commandList "fileframe 0 0"


lappend interruptList "drive detectorx 18."
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 counts [SICSValue "banana sum 0 128 0 128"]
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
drive detectorx $detpos
standardRestore

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

