#! /opt/SUNWssp/bin/ssptk -f
#
# ident	"@(#)hvHead.tcl	1.6	97/07/23 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   Main routine for the hostview product.
#
#   Suck up all the supporting files.
#   Create the main GUI.
#

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)buttonStub.tcl	1.2	96/07/31 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
proc buttonStub {} {
	puts "buttonStub"
}
#
# ident	"%Z%%M%	%I%	%E% SMI"
#
# Copyright (c) 1996-1999 by Sun Microsystems, Inc.
# All rights reserved.
#

proc bpTrap {bp flag} {
    global gBulkPowerList
    global gPowerList
    global gProblem
    global gBg1

    debug 2 "bpTrap: $bp $flag"

    if { [llength $bp] } {
	if { [string compare $flag normal ] == 0} {
	    updateBpsPres bp$bp slot_loaded
	    updateBpsFail bp$bp normal
	    greenPower bp$bp
	    litePs bp$bp
	} else {
	    updateBpsFail bp$bp fail
	    brownPower bp$bp
	    #no failed.
	    failPs bp$bp

	}
    }

    # bug#4288061: need to call decorateEveready to get PS 8-15
    # displayed (if they exist) without a sysconfigchange
    decorateEveready

    set problem 0
    foreach ndx $gPowerList {
	if {[lindex $ndx 1] == 1} {
	    set problem 1
	    debug 2 $ndx
	    break
	}
    }
    if { [ lsearch [lindex $gBulkPowerList 1] bp* ] > -1 } {
	set problem 1
    }
	if [winfo exists .iconBar.power] {
    	if {$problem == 0} {
			.iconBar.power configure -bg $gBg1
			.iconBar.power.button configure -image power
    	} else {
			.iconBar.power configure -bg $gProblem
			.iconBar.power.button configure -image powerRed
		}
    }
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***

#
# ident	"@(#)configCanvas.tcl	1.4	96/09/16 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#	fill in the hostview canvas with the initial machine configuration
#
# Get the configuration for each domain in the 'domains' list
#
# see also
# $(SCOTTY_LIBRARY)/ssp_init.tcl
#
# proc hv_get_domains {}
# 	determine the domains, assign colors, setDomain

proc hv_get_domains {} {
    global gDomainColors
    
    # find out max # of domains - 16?
    #set colors { white orange yellow pink brown}

# found out, should use MIB here, not get_domain_config
    set entry [ get_domain_config ]
    #set dom_cnt [ llength $entry ]

    set i 0
    foreach element $entry {
	set domainName [ lindex $element 0 ]
	#set color [ lindex $colors $i ]
	foreach brd [ lindex $element 4 ] {
	    debug 5 "$entry"
	    debug 5 "$brd $domainName"
	    setDomain $brd $domainName
	}
	set i [expr $i+1]
    }

return ""
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)creBitmaps.tcl	1.4	96/10/14 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   Create hostview bitmaps
#

set gBm_dir $env(SSPOPT)/bitmaps

image create photo power       -file $gBm_dir/bolt.ppm
image create photo powerRed       -file $gBm_dir/boltRed.ppm


image create bitmap sysfault    -file $gBm_dir/sysfaults.xbm
image create bitmap procs       -file $gBm_dir/procs.xbm
image create bitmap sbrds       -file $gBm_dir/sbrds.xbm

image create photo fan         -file $gBm_dir/fan.ppm
image create photo fanRed         -file $gBm_dir/fanRed.ppm

image create photo event       -file $gBm_dir/event.ppm
image create photo eventRed       -file $gBm_dir/eventRed.ppm

image create photo temperature -file $gBm_dir/temperature.ppm
image create photo temperatureRed -file $gBm_dir/temperatureRed.ppm

image create bitmap os       -file $gBm_dir/os.xbm
image create bitmap obp      -file $gBm_dir/obp.xbm
image create bitmap post     -file $gBm_dir/post.xbm
image create bitmap dhlp     -file $gBm_dir/dhlp.xbm
image create bitmap dummy    -file $gBm_dir/dummy.xbm
image create bitmap ques     -file $gBm_dir/ques.xbm
image create bitmap circle    -file $gBm_dir/circle.xbm
image create bitmap bigcircle -file $gBm_dir/bigcircle.xbm

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)detailPopup.tcl	1.2	96/07/31 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   The main GUI supports an option to directly access a detail form
#   for any given board in the system.  This function is activated by
#   positioning the cursor over a board rectangle (on the GUI) and 
#   pressing button-3.
#
#   When activated, a small window is created at the current cursor
#   position which contains option buttons.
#
#   The window is destroyed when the cursor leaves the box, or a
#   selection is taken.
#
#   There will never be more than one copy of this window active at
#   any given moment.
#

proc detailPopup {parent} {
    global gPopupBoard

    debug 1 "detailPopup:$gPopupBoard"

    set geox [winfo pointerx .]
    set geoy [winfo pointery .]

    #
    # Ensure that popup is created with cursor solidly inside.
    # Otherwise, operator might be able to attempt two copies of popup.
    #
    set geox [expr $geox-30]
    set geoy [expr $geoy-30]

    set w .detail_popup

    set bg1 red
    set bg2 yellow
    set fg1 blue
    set fg2 black

    toplevel $w

    wm transient $w .
    wm geometry $w +$geox+$geoy

    set gPopupBoard [whatBoard $parent]

    frame $w.f  
    pack $w.f -expand y -fill both 

    bind $w.f <Leave> {destroy .detail_popup}

    button $w.f.power   -bg $bg1 -fg $fg1 -activebackground $bg2 \
	    -activeforeground $fg2 -text "power" \
	    -command detailPopupPower

    button $w.f.thermal -bg $bg1 -fg $fg1 -activebackground $bg2 \
	    -activeforeground $fg2 -text "thermal" \
	    -command detailPopupThermal

    pack $w.f.power $w.f.thermal -fill x
}

#
# Tear down the popup and invoke the detail view.
#
proc detailPopupPower { } {
    global gPopupBoard

    debug 1 "detailPopupPower:$gPopupBoard"

    destroy .detail_popup

    powerDetail $gPopupBoard
}

#
# Tear down the popup and invoke the detail view.
#
proc detailPopupThermal { } {
    global gPopupBoard 

    debug 1 "detailPopupThermal:$gPopupBoard"

    destroy .detail_popup

    thermalDetail $gPopupBoard
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)diaghook.tcl	1.5	97/03/17 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#

proc diaghook {} {
    global gBoards
    global gDomains
    global gFanList
    global gProcessors
    global gThermalList
    global gPowerList
    global gDomainColors
    global gDomainColorMap
    global gPowered
    global gSystemFail
    global gBulkPowerList
    global gBusUp

    debug 1 "diaghook"

    puts  "#Hostview internal state snapshot"
    puts  "\n#board states:{board domain power loaded|empty} "
    puts $gBoards
    puts  "\n#Domains: {domain_name {sys board list}}"
    puts $gDomains
    puts  "\n#Processors: { proc number {signature state}}"
    puts $gProcessors
    puts  "\n#Thermal List: { board flag {values}} flag 1 indicates problem condition."
    puts $gThermalList
    puts  "\n#Power List: { board flag {values}} flag 1 indicates problem condition."
    puts $gPowerList
    puts  "\n#Fan List: speed_for_all { failed list } {powered list}"
    puts $gFanList
    puts  "\n#Bulk Power List: { present list } { failed list } {powered list}"
    puts $gBulkPowerList

    puts $gDomains
    puts $gDomainColors
    puts $gDomainColorMap
    puts  "\n#Powered center plane and bulk power {bp2 is PS2}"
    puts $gPowered
    puts  "\n#System Fail List: {failure domain_name {date}}"
    puts $gSystemFail
    puts  "\n#up buses"
    puts $gBusUp
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)drHostview.tcl	1.16	00/10/26 SMI"
#
# Copyright (c) 1996-2000 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   handles domain_config operations on inactive domains.
#   Invokes dr for active domains
#
# notes:
#  this is on the hostview side
#

proc drHostview { action } {
    global hvFAIL
    global hvSUCCESS
    global hvDONE
    global gDRdirectory
    global env

    set w .dr

    set targetboard [ $w.f2.right.sb get ]
    set sourcedomain [ $w.f2.right.dom get ]


    if { $action == "attach"} {
	set targetdomain [ $w.f5.right.dom get ]
    } else {
	set targetdomain no_domain
    }

    if { [string compare "" $targetdomain] == 0} {
	set targetdomain no_domain
    }
    if { [string compare "" $sourcedomain] == 0} {
	set sourcedomain no_domain
    }
    #put2textDr $w.tt.text "$targetboard $sourcedomain $targetdomain $action\n"


    #valid dr recovery condition, but only for dr.
    if { 0 } {
	if { [string compare $sourcedomain $targetdomain] == 0} {
	    put2textDr $w.tt.text \
		    "Error:\nSource and target domains are both $sourcedomain\n"
	    return $hvFAIL
	}
    }
    if { [string compare $targetboard ""] == 0} {
	put2textDr $w.tt.text "Error: a board must be selected.\n"
	return $hvFAIL
    }
    if { ![string compare no_domain $sourcedomain]  ||
    ![string compare "" $sourcedomain] } {
	if { ![string compare no_domain $targetdomain]  ||
	![string compare "" $targetdomain] } {

	    put2textDr $w.tt.text \
		    "Error:\nSource and/or target domains are not specified.\n"
	    return $hvFAIL
	}
    }

    # check if the domains are active
    # 0 - Host is UP

    if { $sourcedomain != "no_domain" } {
	if { ![llength [get_domain_entry $sourcedomain]] } {
	    put2textDr $w.tt.text \
		    "Error:\n$sourcedomain is not a valid domain name.\n"
	    return $hvFAIL
	}
	set oldSUNW_HOSTNAME $env(SUNW_HOSTNAME)
	set env(SUNW_HOSTNAME) $sourcedomain
	set sdomState [check_host -q]
	set env(SUNW_HOSTNAME) $oldSUNW_HOSTNAME
    } else {
	set sdomState 1
    }
    if { $targetdomain != "no_domain" } {
	if { ![llength [get_domain_entry $targetdomain]] } {
	    put2textDr $w.tt.text \
		    "Error:\n$targetdomain is not a valid domain name.\n"
	    return $hvFAIL
	}
	set oldSUNW_HOSTNAME $env(SUNW_HOSTNAME)
	set env(SUNW_HOSTNAME) $targetdomain
	set tdomState [check_host -q]
	set env(SUNW_HOSTNAME) $oldSUNW_HOSTNAME
    } else {
	set tdomState 1
    }
    debug 1 "sdomState: $sdomState"
    debug 1 "tdomState: $tdomState"


    if { $sdomState == 0 && $tdomState == 0  \
	    && $sourcedomain != $targetdomain || \
	    $sdomState == 0 && $targetdomain != "no_domain" \
	    && $sourcedomain != $targetdomain} {

	set result [hv_tk_dialog .dlg_fail "Hostview Warning" \
		"Dynamic Reconfiguration with two domains is not implemented.  A detach operation must be performed followed by an attach operation." \
		warning 0 OK ]
	
	return
    }
    # special dr recovery case:
    if { $sdomState == 0 && $sourcedomain == $targetdomain } {
	set sourcedomain ""
    }



#set sdomState 0
#set tdomState 0

    # if the source domain is active, 
    # dr must handle attach or detach (by first detaching).

    if { $sdomState == 0 } {
	#set sdomState active

	# is this a one domain operation?
	if { ![string compare no_domain $targetdomain]  ||
	![string compare "" $targetdomain] } {

	    set cmd "$action $targetboard $sourcedomain"
	    debug 1 "calling run_dr $cmd $targetboard $sourcedomain $targetdomain $action"
	    return [ run_dr $cmd $targetboard \
		    $sourcedomain $targetdomain $action]

	} else {
	    # detach from source domain, 
	    # then attach to target domain
	    #dr requests the keyword "detach"
	    
	    set cmd "$action $targetboard $sourcedomain $targetdomain"
	    debug 1 "calling run_dr $cmd $targetboard $sourcedomain $targetdomain $action"
	    return [ run_dr $cmd $targetboard \
		    $sourcedomain $targetdomain $action]
	}
    }
    
    # we know the source domain is inactive
    # inactive detach
    
    if  { [string compare $sourcedomain "no_domain"] != 0} {
	if { [string compare $sourcedomain ""] != 0}  {
	

	    set result [hv_tk_dialog .dlg_fail "Hostview Warning" \
			    "The DR operation selected requires the source domain to be running the operating system.  If the OS is not running, use the commands domain_remove and domain_create to reconfigure the source domain." \
			    warning 0 OK ]
	
	    return
	    #hv_rm_sysbds $targetboard $sourcedomain $targetdomain

	}
    }
    
    # we are now detached.
    # attach if needed.
    
    if { $tdomState == 0 } {
	#target domain active
	# attach or detach must mean the same in this case
	# inactive detach with active attach
	
	# inactive detach (above), then dr attach
	
	set cmd "attach $targetboard $targetdomain"
	debug 1 "calling run_dr $cmd $targetboard $sourcedomain $targetdomain attach"
	return [ run_dr $cmd $targetboard \
		$sourcedomain $targetdomain attach]

    } else {

	# is this a one domain operation?
	# if so, we are done
	if { ![string compare no_domain $targetdomain]  ||
	     ![string compare "" $targetdomain] } {
	    return hvDONE
	}

	#inactive
	switch $action {
	    attach {
			
		set result [hv_tk_dialog .dlg_fail "Hostview Warning" \
				"The DR operation selected requires the target domain to be running the operating system.  If the OS is not running, use the commands domain_remove and domain_create to reconfigure the domain." \
				warning 0 OK ]
	
		#destroy .
		return

		#return [ hv_add_sysbds $targetboard $sourcedomain \
		    $targetdomain]

	}
	detach {
		# I don't think detach applies, but
		# there seems to be some flux with the terminology ......
			
		set result [hv_tk_dialog .dlg_fail "Hostview Warning" \
				"Detach requires the domain to be running the operating system.  If the OS is not running, use the commands domain_remove and domain_create to reconfigure the domain." \
				warning 0 OK ]
		
		#destroy .
		return	

		#return [ hv_add_sysbds $targetboard $sourcedomain \
			$targetdomain]

	    }
	}
    }
    return hvDONE
    
}

proc put2textDr {dest verbage} {
    
    $dest insert end $verbage
    $dest see end
}
proc statMsg { dest targetboard sourcedomain targetdomain action} {
    put2textDr $dest "\nSystem board: $targetboard\n"
    put2textDr $dest "From domain: $sourcedomain\n"
    if { [string compare no_domain $targetdomain] != 0 } {
	put2textDr $dest "To domain: $targetdomain\n"
	put2textDr $dest "\n"
    }
    $dest tag add output 1.0 end
    $dest tag configure output -wrap word
}

proc ins2textDr {dest verbage} {
    #global gThetop

    $dest insert insert $verbage output
    #$dest see $gThetop
    $dest see end
}
#
# run_dr
#
proc run_dr {cmd targetboard sourcedomain targetdomain action} {
    global gOldCursor
    global hvSUCCESS
    global hvFAIL
    global env
    set w .dr

    #set gOldCursor [.dr cget -cursor]
    set gOldCursor [$w.buttonbox.execute cget -cursor]
    #$w config -cursor watch
    #$w.buttonbox.execute config -cursor watch


    debug 1 "env(hvInstName): $env(hvInstName)"
    debug 1 "run_dr $cmd $targetboard $sourcedomain $targetdomain $action"
    debug 1 "exec drview $action $targetboard \
	    $sourcedomain &"
    #statMsg $w.tt.text $targetboard $sourcedomain $targetdomain $action
    put2textDr $w.tt.text "invoking drview ...."

    set oldSUNW_HOSTNAME $env(SUNW_HOSTNAME)

    # set env(SUNW_HOSTNAME) to a valid domain name to make ver.exec happy, 
    # i.e., to sourcedomain or  to targetdomain
    if { [llength $sourcedomain] &&  \
         [string compare $sourcedomain no_domain] != 0 } {
	set env(SUNW_HOSTNAME) $sourcedomain
    } elseif { [llength $targetdomain] &&  \
              [string compare $targetdomain no_domain] != 0 } {
        set env(SUNW_HOSTNAME) $targetdomain
    } else  {
        error "drHostview: Not a valid domain, Should never get here!"
    }

    if { [get_domain_gen $targetdomain] == 1 } {
	put2textDr $w.tt.text "drview not supported for this domain: $targetdomain"
	return $hvFAIL
    }
    if { [get_domain_gen $sourcedomain] == 1 } {
	put2textDr $w.tt.text "drview not supported for this domain: $sourcedomain"
	return $hvFAIL
    }

    if [catch { eval exec drview $cmd &} result] {
	puts stderr $result
	put2textDr $w.tt.text "\n$result"
	#$w.buttonbox.execute config -cursor $gOldCursor
	return $hvFAIL
    }
 
    set env(SUNW_HOSTNAME) $oldSUNW_HOSTNAME

    # go back to drSelections and 
    # wait to hear back from drview before removing the window
    return $hvSUCCESS	
}
#
# hv_sysbds
#
proc hv_rm_sysbds {targetboard sourcedomain targetdomain } {
    global gOldCursor
    global hvSUCCESS
    global hvFAIL
    global hvDONE
    set w .dr
    set dest $w.tt.text


    #set gOldCursor [.dr cget -cursor]
    set gOldCursor [$w.buttonbox.execute cget -cursor]
    #$w config -cursor watch
    #$w.buttonbox.execute config -cursor watch


    set ret ""
    #rm_sysbds {$targetdomain { $targetboard }}
    statMsg $w.tt.text $targetboard $sourcedomain $targetdomain detach
    set cmdArgs [format "{%s {%s}}" $sourcedomain $targetboard]

    set ret [mari_rm_sysbds $cmdArgs]

    debug 1 "mari_rm_sysbds $cmdArgs"
    debug 1 "ret: $ret"

    if { $ret == 0 } { 
	put2textDr $dest "Succeeded."
	return $hvDONE
    } 
    if { $ret == -1 } { 
	put2textDr $dest "Error: No domains found.\n"
	return $hvFAIL
    } 
    if { $ret == -2 } { 
	put2textDr $dest "Error: Cannot detach the last board in a domain.\n"
	put2textDr $dest "May want to use domain_remove.\n"
	return $hvFAIL
    } 
    if { $ret == -3 } { 
	put2textDr $dest "Error: domain not found.\n"
	return $hvFAIL
    } 
    if { $ret == -4 } { 
	put2textDr $dest "Error: board not found in this domain.\n"
	return $hvFAIL
    }
    return $hvFAIL

}

#
# hv_add_sysbds
#
proc hv_add_sysbds {targetboard sourcedomain targetdomain } {
    global gOldCursor
    global hvSUCCESS
    global hvFAIL
    global hvDONE
    set w .dr
    set dest $w.tt.text

    set ret ""
    #set gOldCursor [.dr cget -cursor]
    set gOldCursor [$w.buttonbox.execute cget -cursor]
    #$w config -cursor watch
    #$w.buttonbox.execute config -cursor watch

    #add_sysbds {$targetdomain { $targetboard }}
    statMsg $w.tt.text $targetboard $sourcedomain $targetdomain attach
    set cmdArgs [format "{%s {%s}}" $targetdomain $targetboard]

    set ret [mari_add_sysbds $cmdArgs]

    debug 1 "mari_add_sysbds $cmdArgs"
    debug 1 "ret: $ret"

    if { $ret == 0 } { 
	put2textDr $dest "Succeeded."
	return $hvDONE
    } 
    if { $ret == -1 } { 
	put2textDr $dest "Error: No domains found.\n"
	return $hvFAIL
    } 
    if { $ret == -2 } { 
	put2textDr $dest "Error: board is already in domain.\n"
	return $hvFAIL
    } 
    if { $ret == -3 } { 
	put2textDr $dest "Error: domain not found.\n"
	put2textDr $dest "May want to use domain_create.\n"
	return $hvFAIL
    }
    return $hvFAIL

}


####===========================================







#
# exec_dr
#
## old

proc exec_dr {execCmd} {
    global gSelectedBoard
    global gPid
    global gFp
    global env
    global gHelpFlg
    global gOldCursor

    set outputDest .dr.tt.text
    set w .dr

    set gOldCursor [$w cget -cursor]

    $w config -cursor watch

    # read back the command box, allows user to edit the command
    #set cmd [ .f.right.command get ]
    #set SUNW_HOSTNAME [ .f.right.hostname get ]
    #set env(SUNW_HOSTNAME) $SUNW_HOSTNAME

    # redirect stderr and stdout
    if [catch {open "|$cmd |& cat"} fp1] {
	put2textDr $outputDest "Error: $fp1\n"
	puts stderr "Error: $fp1 \ncommand: $cmd\n"
	return "-1"
    }
    # non-blocking read
    fileevent $fp1 readable [list ReaderDr $fp1]

    set gPid [pid $fp1]
    set gFp $fp1

    # disallow subsequent executions
	#.buttonbox.execute configure -state disabled

    return ""
}

proc ReaderDr { pipe } {
    global gOldCursor
    set outputDest .dr.tt.text

    if [eof $pipe] {
	#close $pipe
	catch {close $pipe}
	.dr config -cursor $gOldCursor
	#.buttonbox.execute config -cursor $gOldCursor
	return
    }
    gets $pipe buff1
    put2textDr $outputDest $buff1
    put2textDr $outputDest \n

}



#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***




#
# ident	"@(#)drSelections.tcl	1.11	98/02/04 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   General proc to service commands as a separate process using a text
#   widget to exec a command.  
#
#	exec ${gHV_HOME}/drSelectionsPopup $cmdArg $domainName &
#	called by: genTextExec { cmdArg }
#	menuBar:	    -command "genTextExec sspLog" -underline 0
#
# notes:
#  this is on the hostview side
#

proc drSelectionsPopDet { cmdArg } {
    global gFont2
    global gHelpFlg
    global gOldCursor
    global gBg1

    debug 2 "genTextExec:$cmdArg"

    set w .dr
    if [winfo exists $w] {
	raise $w
	return
    } 

	# top level popup, but still a child of the main window
    toplevel $w

	# title based on input arg
    #wm title $w "DR Parameter Selection - $cmdArg"
    wm title $w "$cmdArg - Board and Domain Selection"
    # setting minsize or maxsize enables window resizing
    wm minsize . 30 5

	# Only want text portion of window to grow on resize, so
	# don't use -expand option when packing this frame.

    frame $w.f1 -bg $gBg1
    pack $w.f1 -fill both
    #pack $w.f -expand y -fill both

    set selectedBoard null
    set domainName no_domain
    set sourceDomain no_domain

    label $w.f1.sb -text "Select board in main window.  Then click 'Select'." -bg $gBg1
    #label $w.f1.sb -text "Select board on hostview canvas to be ${cmdArg}ed"
    #label $w.f1.sb -text "Target board selected on hostview canvas?"
    button $w.f1.but -text "select" \
	    -command "bselect $selectedBoard $sourceDomain" -bg $gBg1
    #button $w.f1.but -text "yes" -command "bselect $selectedBoard $sourceDomain"
    pack  $w.f1.sb -side left
    pack  $w.f1.but -side right

    frame $w.f2
    pack $w.f2 -fill both
    frame $w.f2.left -bg $gBg1
    pack $w.f2.left -fill both -side left
    label $w.f2.left.sb -text "Board" -bd 5 -bg $gBg1
    label $w.f2.left.dom -text "Source domain" -bd 5 -bg $gBg1
    pack $w.f2.left.sb $w.f2.left.dom -anchor e

    frame $w.f2.right -bg $gBg1
    pack  $w.f2.right -expand y -fill both

	# user input - one line
    entry $w.f2.right.sb -relief sunken -width 32 -font $gFont2
    entry $w.f2.right.dom  -relief sunken -width 32 -font $gFont2 
    pack  $w.f2.right.sb $w.f2.right.dom -anchor w


    frame $w.f3 -bg $gBg1
    pack $w.f3 -fill both
    #pack $w.f -expand y -fill both

    label $w.f3.sb -text ""


    # for intea, only single domain operations are allowed
    # with dr.

    if { 0 } {
	if { $cmdArg == "detach" } {
	    frame $w.f3a
	    pack $w.f3a -fill both
	    label $w.f3a.sb -text Optional:
	    pack  $w.f3a.sb -side left
	}
    }

    if { $cmdArg == "attach"} {

	frame $w.f4 -bg $gBg1
	pack $w.f4 -fill both
	#pack $w.f -expand y -fill both

	set labeltext "Select domain in main window.  Then click 'Select'.   "
	#set labeltext "Select domain on hostview canvas to be attached to"
	label $w.f4.sb -text $labeltext -bg $gBg1
	button $w.f4.but -text "select" -command "domselect $domainName" -bg $gBg1
	pack  $w.f4.sb -side left
	pack  $w.f4.but -side right

	frame $w.f5
	pack $w.f5 -fill both
	frame $w.f5.left -bg $gBg1
	pack $w.f5.left -fill both -side left
	label $w.f5.left.sb -text "Target domain" -bd 5 -bg $gBg1

	pack $w.f5.left.sb -anchor e

	frame $w.f5.right -bg $gBg1
	pack  $w.f5.right -expand y -fill both

	# user input - one line
	entry $w.f5.right.dom  -relief sunken -width 32 -font $gFont2 
	pack  $w.f5.right.dom -anchor w



        # grey out the target domain area. need target domain only for 2 domain action in the future
        #$w.f4.but configure -state disabled
        #$w.f5.right.dom configure -state disabled
    }

    #bind $w.f.right.command <Return> "execCmdFcn \"$execCmd\""
    #bind $w.f.right.command <Control-c> abortExec
    #focus $w.f2.right.sb

    #set execCmd "$cmdArg {$domainName $selectedBoard} &"

    #may want to add this when execute is pushed so the window is
    # smaller while user is interacting with canvas

    frame $w.tt
    pack  $w.tt -expand true -fill both
    #pack  $w.tt

    # user input - scrolled multi line - text editor
    # setgrid true makes window resizable
    #text  $w.tt.text -relief groove -setgrid true -width 80 -height 15 
    text  $w.tt.text -relief groove -setgrid true -width 40 -height 5 \
	    -yscrollcommand "$w.tt.yscroll set" \
	    -xscrollcommand "$w.tt.xscroll set"
    scrollbar $w.tt.xscroll -command "$w.tt.text xview" -orient horiz -bg $gBg1
    pack $w.tt.xscroll -side bottom -fill x 
    pack  $w.tt.text -side left -expand y -fill both


    scrollbar $w.tt.yscroll -command "$w.tt.text yview" -bg $gBg1
    pack $w.tt.yscroll -side right -fill y
    
    # this only works on a text widget
    #set gOldCursor [$w cget -cursor]
    #button $w.f.left.dom -text "Domain Selected" -command "domselect domainName"
    frame $w.buttonbox
    pack  $w.buttonbox -fill x
    #pack  $w.buttonbox -expand y -fill x 


    button $w.buttonbox.execute -text execute \
	    -command "Run $cmdArg" -bg $gBg1
    button $w.buttonbox.dismiss -text dismiss -command "destroy $w" -bg $gBg1
    button $w.buttonbox.abort   -text abort   -command "destroy $w"
    button $w.buttonbox.help    -text help	-command "helpTextExec dr" -bg $gBg1

    pack $w.buttonbox.execute $w.buttonbox.dismiss $w.buttonbox.help \
	 -side left -expand y -fill x

    #pack $w.buttonbox.execute $w.buttonbox.dismiss \
	 $w.buttonbox.abort   $w.buttonbox.help \
	 -side left -expand y -fill x
#-side left -expand y -fill x

bselect $selectedBoard $sourceDomain

}

proc bselect { selectedBoard sourceDomain } {
    upvar $selectedBoard targetBoard;		#pass by reference
    upvar $sourceDomain sdomain;		#pass by reference
    global gSelectedBoard
    set w .dr

    set targetBoard $gSelectedBoard
    $w.f2.right.sb delete 0 end
    $w.f2.right.sb insert 0 $targetBoard

        #allow Crayhostname for testing
    set sdomain [ getSelDom ]
    if { $sdomain == "no_domain" } {
	set sdomain ""
    }
    #set sdomain [ domainOrCrayhostname ]
    $w.f2.right.dom delete 0 end
    $w.f2.right.dom insert 0 $sdomain
}

proc domselect { domainName} {
    upvar $domainName targetDomain;		#pass by reference
    global gSelectedBoard
    global env
    set w .dr

    #allow Crayhostname for testing
    set targetDomain [ getSelDom ]
    #set targetDomain [ domainOrCrayhostname ]
    if { $targetDomain == "no_domain" } {
	set sdomain ""
    }
    $w.f5.right.dom delete 0 end
    $w.f5.right.dom insert 0 $targetDomain
}
proc Run { cmdArg } {
    global hvSUCCESS
    global gOldCursor
    global env
    set w .dr

    #set targetboard [ $w.f2.right.sb get ]
    #set sourcedomain [ $w.f2.right.dom get ]
    #set targetdomain [ $w.f5.right.dom get ]
    
    #set cmd "$targetboard $sourcedomain $targetdomain $cmdArg"
    #puts $cmd

    # set the state to disabled to prevent more than one drview popups. bug fix for 4036005
    $w.buttonbox.execute configure -state disabled
    $w.buttonbox.dismiss config -cursor watch
    $w.buttonbox.abort config -cursor watch

    set env(hvInstName) [tk appname]
    #set env(DRFAIL) 1
    #set ret [ drHostview \"$cmd\" ]
    set ret [drHostview $cmdArg]

    if { $ret == $hvSUCCESS } {

	#$w.buttonbox.execute config -cursor $gOldCursor
	# make sure dr shows up before destroying this one.
	#after 5000; #millisec
	#destroy $w
    } else {
	# else the user will dismiss the window after reading
	# would like to put back to $gOldCursor, but I cannot "get"
	# gOldCursor except in a text window.
    
	$w.buttonbox.execute config -state normal
	$w.buttonbox.dismiss config -cursor arrow
	$w.buttonbox.abort config -cursor arrow
    }
}

#
# drview will use "send" to call hvDrviewUp
# thus notifying hv that the window is up.
#
proc hvDrviewUp { flag msg } {
    set w .dr

    debug 1 "hvDrviewUp: $flag $msg"

    if { $flag == 0 } {
	destroy $w
	return
    }
    put2textDr $w.tt.text "Error in drview\n"
    put2textDr $w.tt.text $msg

    # reactivate execute button for maybe a new dr. for bug fix 4036005
    $w.buttonbox.execute configure  -state normal
    $w.buttonbox.dismiss config -cursor arrow
    $w.buttonbox.abort config -cursor arrow
}




#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***

#
# ident	"@(#)eventIcon.tcl	1.4	96/10/14 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#

proc eventIcon {} {
    global gBg1
    debug 0 "eventIcon"

    # once the user acknowledges this, put the color back.
    .iconBar.event configure -bg $gBg1
    .iconBar.event.button configure -image event
 
    eventTextExec
    #llength $gSystemFail


}
#
# ident	"@(#)fanDetail.tcl	1.6	98/02/03 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   Create and support the fan detail form.
#
# Main routine, causes a fanDetail form to be created.
#   proc fanDetail { } 
#
# proc createFanDetail {drawer} 
#   Actually creates the specified fanDetail form.
#

#
# Returns background color of a specified fan.
#
proc colorFanDetail {fan} {
    global gHealthy
    global gProblem
    global gGrey

    debug 2 "colorFanDetail:$fan"

    set speed [whatFanSpeed]
    set failures [whatFanFailure]
    set fanpwrlist [whatFansPowered]

    set failndx [lsearch $failures $fan]
    if {$failndx < 0} {
	set fantray [string trim $fan ab]
	set pwrndx [lsearch $fanpwrlist $fantray]
	if { $pwrndx >= 0 } { 
	    if {[string compare $speed high] == 0} {
		set color goldenrod
	    } elseif {[string compare $speed nominal] == 0} {
		set color $gHealthy
	    }
	} else {
	    set color $gGrey
	}
    } else {
	set color $gProblem
    }
    debug 2 "colorFanDetail:$fan $color"
    return $color
}

proc createFanDetail {drawer} {
    global gBg1
    global gBg2
    global gFg1
    global gFont1

    global gHealthy
    global gProblem

    debug 1 "createFanDetail:$drawer"

    set w .fanDetail_$drawer

    toplevel $w
    set bnum [string trimleft $drawer ft]
    wm title $w "FT $bnum Fan Tray"

    $w config -bg $gBg1

    frame $w.f -bg $gBg1
    pack $w.f -expand yes -fill both

    frame $w.f.fantray -borderwidth 2 -relief groove -bg $gBg1
    pack $w.f.fantray -expand yes -fill x -side right

    set target [join "$drawer a" ""]
    set color [colorFanDetail $target]
    label $w.f.fantray.fan1 -image bigcircle -bg $color

    set target [join "$drawer b" ""]
    set color [colorFanDetail $target]
    label $w.f.fantray.fan2 -image bigcircle -bg $color

    pack $w.f.fantray.fan1 $w.f.fantray.fan2

    frame $w.buttonbox -bg $gBg1
    pack $w.buttonbox -expand yes -fill x -side top
    
    button $w.buttonbox.dismiss -bg $gBg1 -fg $gFg1 \
	    -activebackground $gBg2 -activeforeground $gFg1 -text "dismiss" \
	    -command {dismissMe} -font $gFont1

    pack $w.buttonbox.dismiss -fill x
}

#
# A request to display a fan detail has been noted.
#
proc fanDetail { } {
    set geox [winfo pointerx .]
    set geoy [winfo pointery .]

    set target [winfo containing $geox $geoy]

    debug 2 "fanDetail entry:$target"

    set drawer [path2sd $target]
    debug 1 "I know this is fan drawer:$drawer"

    #
    # There can only be one copy of this window.
    #
    set w .fanDetail_$drawer
    if [winfo exists $w] {
	raise $w
	return
    } 

    createFanDetail $drawer
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)fanTrap.tcl	1.9	99/05/21 SMI"
#
# Copyright (c) 1996, 1999 by Sun Microsystems, Inc.
# All rights reserved.
#

proc fanTrap {flag args} {
    global gBg1
    global gHealthy
    global gProblem
    global gGrey
    global gFanDrawers
    global gFanMibRead

    debug 2 "fanTrap:$flag $args"

    set base .wFan
    set fanpwrlist [whatFansPowered]
    if { ![info exists gFanMibRead] } {
	#read the mib
	set gFanMibRead 1
	hv_hostinfo -f
	return
    }
    set speed [whatFanSpeed]
    set drawer [string trim $args ab]
    set detail .fanDetail_$drawer
 
    if {[string compare $flag speed] == 0} {
	#
	# Fan speed has been changed.  
	# Update the list and propagate to all fan detail windows.
	#
	updateFanSpeed $args

	foreach ft $gFanDrawers {
	    set detail .fanDetail_$ft
	    if [winfo exists $detail] {
		set fan [join "$ft a" ""]
		set color [colorFanDetail $fan]
		$detail.f.fantray.fan1 configure -bg $color
		set fan [join "$ft b" ""]
		set color [colorFanDetail $fan]
		$detail.f.fantray.fan2 configure -bg $color
	    }
	}
    } elseif {[string compare $flag fail] == 0} {
	#
	# A fan failure has been noted.
	# Update the list, propagate to system wide fan detail and 
	#   all fan detail windows.
	#
	updateFanFailure $args $flag

	if [winfo exists $base] {
	    set target "$base[sd2path $drawer]"
	    $target.icon configure -bg $gProblem
	}

	if [winfo exists $detail] {
	    if {[string first b $args] < 0} {
		debug 1 "top"
		$detail.f.fantray.fan1 configure -bg $gProblem
	    } else {
		debug 1 "bottom"
		$detail.f.fantray.fan2 configure -bg $gProblem
	    }
	} 
    } elseif {[string compare $flag repair] == 0} {
	#
	# A fan repair has been noted.
	# Update the list, propagate to system wide fan detail and 
	#   all fan detail windows.
	#
	updateFanFailure $args $flag

	if { [lsearch $fanpwrlist $drawer] == -1 } {
	    set color $gGrey
	} else {
	    if {[string compare $speed high] == 0} {
		set color goldenrod
	    } elseif {[string compare $speed nominal] == 0} {
		set color $gHealthy
	    } else {
		set color $gGrey
	    }
	}

	if [winfo exists $base] {
	    set target "$base[sd2path $drawer]"
	    $target.icon configure -bg $color
	}

	if [winfo exists $detail] {
	    if {[string first b $args] < 0} {
		debug 1 "top"
		$detail.f.fantray.fan1 configure -bg $color
	    } else {
		debug 1 "bottom"
		$detail.f.fantray.fan2 configure -bg $color
	    }
	} 
    } elseif {[string compare $flag powerOn] == 0} {
	#
	# A fan tray has been turned on
	# Update the list, propagate to system wide fan detail and 
	#   all fan detail windows.
	#
	updateFansPowered $args $flag

	if {[string compare $speed high] == 0} {
	    set color goldenrod
	} elseif {[string compare $speed nominal] == 0} {
	    set color $gHealthy
	} else {
	    set color $gGrey
	}

	if [winfo exists $base] {
	    set target "$base[sd2path $drawer]"
	    $target.icon configure -bg $color
	}

	if [winfo exists $detail] {
	    set failures [whatFanFailure]
	    set ft [string trimright "$args" ab]
	    debug 1 "top"
	    if { [lsearch $failures ${ft}a] > -1 } {
		$detail.f.fantray.fan1 configure -bg $gProblem
	    } else {
		$detail.f.fantray.fan1 configure -bg $color
	    }
	    debug 1 "bottom"
	    if { [lsearch $failures ${ft}b] > -1 } {
		$detail.f.fantray.fan2 configure -bg $gProblem
	    } else {
		$detail.f.fantray.fan2 configure -bg $color
	    }
	} 
    } elseif {[string compare $flag powerOff] == 0} {
	#
	# A fan tray has been turned off
	# Update the list, propagate to system wide fan detail and 
	#   all fan detail windows.
	#
	updateFansPowered $args $flag

	#turn off
	set color $gGrey

	if [winfo exists $base] {
	    set target "$base[sd2path $drawer]"
	    $target.icon configure -bg $color
	}

	if [winfo exists $detail] {
	    $detail.f.fantray.fan1 configure -bg $color
	    $detail.f.fantray.fan2 configure -bg $color
	}
    } else {
	debug 5 "fanTrap unknown option:$flag $args"
    }

    #
    # Fan Icon on Main GUI
    #
    set temp1 [whatFanFailure]
	if [winfo exists .iconBar.fan] {
    	if {[llength $temp1] > 0} {
			.iconBar.fan configure -bg $gProblem
			.iconBar.fan.button configure -image fanRed
    	} else {
			.iconBar.fan configure -bg $gBg1
			.iconBar.fan.button configure -image fan
		}
    }

    #
    # Update System Detail
    #



    #
    # Update Individual Detail
    #
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)genTextExec.tcl	1.18	97/04/11 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   General proc to service commands from the menu bar that use a text
#   widget to exec a command.  
#
#	This is preprocessing before invoking hostview_child.
#
#	menuBar:	    -command "genTextExec sspLog" -underline 0
#	menuBar:	    -command {exec $gDRdirectory/dr_board.tcl detach &}
#
# notes:
#  if user picks domain after execute button, restart window

proc genTextExec {cmdArg } {

    global gMY_PLATFORM
    global gSelectedBoard
    global gSelectedBoardList
    global gPlatformType
    global gMY_PLATFORM
    global gHV_HOME
    global env
    global gSystemBoards

    set domainName "null_domain"

    set domainName [ getSelDom ]
    debug 1 "genTextExec: cmdArg: $cmdArg domainName: $domainName"

    set flag ok
    set domNeeded 0
    set dialog .domdlg

    debug 1 "llength gSelectedBoardList:[ llength $gSelectedBoardList ]"

    if { [ llength $gSelectedBoardList ] } {
	set domNeeded 1
    }

    if { $domainName == "no_domain" || $domNeeded == 1} {
	switch $cmdArg {
	    bringup { set flag bail }
	    domainRename { 
		set flag bail 
		set cmdArg rename
	    }
	    domainRemove { 
		set flag bail
		set cmdArg removal
	    }
	}
	if { $flag == "bail" } {
	    set result [hv_tk_dialog $dialog "Hostview Warning" \
			    "One domain must be selected\n          for ${cmdArg}." \
			    warning 0 OK]
	    return
	}
	set domainName no_domain
    }

    if { [string compare $cmdArg "sspLog"] == 0 } {

	if { $domainName == "no_domain"} {
	    set dom ""
	    set msg "log file does not exist."
	} else {
	    set dom $domainName
	    set msg "log file does not exist for $domainName."
	}
	set msgfile "$env(SSPLOGGER)/${dom}/messages"

	if { [file exists $msgfile] != 1 } {
	    set result [tk_dialog .dlg_domr "Hostview Information" \
		    $msg \
		    info 0 Cancel ]

	    if { $result == 0 } {
		return
	    }
	}

    } elseif { [string compare $cmdArg "domainRemove"] == 0 } {
	set domainName [format "{{%s} {%s}}" \
			    $domainName $gMY_PLATFORM]

    } elseif { [string compare $cmdArg "domainCreate"] == 0 } {

	set gPresentBoards ""
	foreach brd $gSystemBoards {
	    set state [whatBoardState $brd]
	    if { [lsearch $state slot_loaded] > -1} {
		set gPresentBoards "$gPresentBoards $brd"
	    }
	}

	if { 0 } {
	    foreach brd "$gSelectedBoard $gSelectedBoardList" {
		set state [whatBoardState $brd]
		if { [lsearch $state slot_loaded] < 0} {


		    set msg "Board $brd is not present on this platform.\n\nDo you want to continue?"

		    set result [tk_dialog .dlg_domr "Hostview Question" \
					$msg \
				    questhead 1 Continue Cancel ]
		    
		    if { $result > 0 } {
			return
		    }
		}
	    }
	}

	set domainName [format "{{%s} {%s %s} {%s} {%s}}" \
		$gMY_PLATFORM $gSelectedBoard $gSelectedBoardList \
		$gPlatformType $gPresentBoards]
    } elseif { [string compare $cmdArg "bringup"] == 0 } {

	set msg "Hostview uses the Force option on bringup.\n\nDo you want to continue?"

		    set result [tk_dialog .dlg_domr "Hostview Information" \
			    $msg \
			    questhead 1 Continue Cancel ]

		    if { $result > 0 } {
			return
		    }
    }

    # domainName has evolved to actually contain an arg list 

    debug 1 "genTextExec: cmdArg domainName: $cmdArg $domainName"
    if [catch {exec hostview_child -t "$cmdArg $domainName" &} result] {
	debug 10 $result
    }
    
}

proc helpTextExec {cmdArg } {
    global gHV_HOME

    debug 2 "helpTextExec:$cmdArg"

    switch $cmdArg {
	icon {
	    if [catch {exec hostview_child -i $cmdArg &} result] {
    		debug 10 $result
	    }
   
	    #exec ${gHV_HOME}/iconHelp $cmdArg
	    return
	}
    }
    #all other help widgets
    if [catch {exec hostview_child -m $cmdArg &} result] {
	debug 10 $result
    }
    return
}

proc eventTextExec {} {
    global gSystemFail
    global gSysFailLog
    global gHvFailLogDir
    global gFilebase

    if { ![info exists gFilebase] } {
	set result [hv_tk_dialog .dlg_fail "Hostview Information" \
                    "No Failures have been recorded." \
		    info 0 OK ]

	return
    }
    debug 2 "eventTextExec:gSystemFail: $gSystemFail $gFilebase"

    if [catch {exec hostview_child -e $gSystemFail $gHvFailLogDir/$gSysFailLog $gFilebase &} result] {
	debug 10 $result
    }
    return
}

proc netconExec {} {
    global env
    global gSelectedBoardList

    set dialog .domdlg


    set domainName [ getSelDom ]
    #set domainName [ domainOrCrayhostname ]

    if { $domainName == "no_domain" || [ llength $gSelectedBoardList ] } {
	set result [hv_tk_dialog $dialog "Hostview Warning" \
		"One domain must be selected for netcontool." \
		warning 0 OK ]
	return
    }

    set oldSunw_hostname $env(SUNW_HOSTNAME)

    if { $domainName != $oldSunw_hostname } {
	set env(SUNW_HOSTNAME) $domainName
    }

    if [catch {exec netcontool &} result] {
	debug 10 $result
    }
    set env(SUNW_HOSTNAME) $oldSunw_hostname
}

proc blEditExec { } {
    global gMY_PLATFORM
    
    debug 1 "blEditExec:gMY_PLATFORM $gMY_PLATFORM"

    if [catch {exec hostview_child -B $gMY_PLATFORM &} result] {
	debug 10 $result
    }

    return
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***


#
# ident	"@(#)globals.tcl	1.31	01/03/06 SMI"
#
# Copyright (c) 1996-2001 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   Define global variables used within hostview.  
#   All global variables are prefixed w/a small g and a capital to flag
#   their devious purpose. 
#

# gDebugThreshold defines debug traffic.  0 = everything.
#=> 5  switch defaults, mib member non errors
#=>10 mibmembers error printout
###########set gDebugThreshold 0
#set gDebugThreshold 4
set gDebugThreshold 5
#set staleStateTest 0

####set gHV_HOME $env(HOSTVIEW_HOME)
set gHV_HOME .

#
# Color
#

# bg1 is the background color of the main window.
set gBg1 gray81
# powered on boards
set gBg3 blue

# bg2 is the "active background" color for buttons
set gBg2 GhostWhite

# fg1 is default text color for main window.
set gFg1 black

# Healthy color
set gHealthy green3

# Problem color
set gProblem red

# bGrey is the color of components which are present but not powered.
set gGrey grey

# Board selection (main GUI)
set gSelectedBoard ""
set gSelectedBoardList ""
set gPlatformType ""
set gOs "5.8"
set gMY_PLATFORM ""

#
# Default font
#
set gFont1 -*-helvetica-bold-r-*-*-*-120-75-75-*-*-iso8859-1
#set gFont1 -Adobe-Helvetica-Bold-R-Normal--*-120-*-*-*-*-*-* 
#set gFont2 -Adobe-Helvetica-Bold-R-Normal--*-140-*-*-*-*-*-* 
set gFont2 -*-helvetica-bold-r-*-*-*-140-75-75-*-*-iso8859-1

#
# Lists
#
set gBuss {abus2 abus3 dbus1 dbus0 abus1 abus0}
	
set gFrontPower {bp0 bp1 bp2 bp3}
set gFrontPowerEveready {bp8 bp9 bp10 bp11}
set gBackPower  {bp4 bp5 bp6 bp7}
set gBackPowerEveready  {bp12 bp13 bp14 bp15}
set gBulkPower  {bp0 bp1 bp2  bp3  bp4  bp5  bp6  bp7 \
		 bp8 bp9 bp10 bp11 bp12 bp13 bp14 bp15}
set gBulkPowerEveready	{bp8 bp9 bp10 bp11 bp12 bp13 bp14 bp15}

set gCenterBoards {ctr}
set gFrontBoards {csb0 cb0 0 1 2 3 4 5 6 7} 
#set gFrontBoards {sb0 cb0 b0 b1 b2 b3 b4 b5 b6 b7} 
set gBackBoards  {csb1 cb1 15 14 13 12 11 10 9 8} 
#set gBackBoards  {sb1 cb1 b15 b14 b13 b12 b11 b10 b9 b8} 

set gFrontSysBoards {0 1 2 3 4 5 6 7} 
#set gFrontSysBoards {b0 b1 b2 b3 b4 b5 b6 b7} 
set gBackSysBoards {8 9 10 11 12 13 14 15}
#set gBackSysBoards {b8 b9 b10 b11 b12 b13 b14 b15}
set gSystemBoards {0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15}
#set gSystemBoards {b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15}
set gcbBoards {cb0 cb1}
set gcsbBoards {csb0 csb1}

set gFanDrawers {ft0 ft1 ft2 ft3 ft4 ft5 ft6 ft7 ft8 ft9 ft10 ft11 ft12 ft13 ft14 ft15}

#
# Boards with temperature sensors
#
set gThermalSource "ctr $gFrontBoards $gBackBoards"

#
# Board List, looks like {b0 domain power loaded}
# Board List, looks like {0 domain power loaded}
#
set gBoards ""

#
# Processor List, looks like {b0 {os running}}
#   where os could be {dummy|os|obp|post|dhlp} and running
#   could be {running|exit|prerun|unknown|blacklist|redlist|not configured}
#
set gProcessors ""

#
# Domain Colors
#
# Legal domain colors (max: 16 domains)
# Note: blue is NOT used (indicates a powered-on board) and
# grey is NOT used (indicates a present, but not powered, board)
#
# (run showrgb for a list of color names)
set gDefaultDomainColors { white orange yellow pink
			brown red green violet
			purple mediumaquamarine yellowgreen maroon
			cyan darkgoldenrod navyblue tan
			grey }
# This is set, in hostview_init.tcl, to the above if not overridden:
set gDomainColors { white orange yellow pink
			brown red green violet
			purple mediumaquamarine yellowgreen maroon
			cyan darkgoldenrod navyblue tan
			grey }


# Historical: Old 8-domain colors + 1:
#set gDomainColors {white orange yellow pink brown red green violet grey }

#
# domain color mapping, initially all colors available, set to -1
# later assign the color to a domain, 0 1 2.  if a color is freed, 0 -1 1
#
set gNumDomCols [ llength $gDomainColors ]
set gDomainColorMap ""
foreach color $gDomainColors {
    set gDomainColorMap "$gDomainColorMap -1"
}
#
# Defined domains and members, looks like {orange {b0 b1 b2}}
#
set gDomains ""
#
# domain name map.  index 0 is the first domain, colormap will have 0.
# 
set gDomainNameMap ""

#
# gPowered contains the board ID of enabled boards. 
# This is simply to communicate between systemDetail and systemGraphic
# which boards could be selected.
#
set gPowered "ctr"
#set gPowered "ctr $gBulkPower"

#
# gPopupBoard contains the board ID os a button 3 popup from the main GUI.
# There can only be one of these active at any given instant.
#
set gPopupBoard 0

#
# List of fans and status, looks like {off|nominal|high {ft0b} {ft0 ft1}}
# "high { ft0b} {ft0 ft1}"
# speed for all { failed list } {powered list} { present "conf" list }
#
set gFanList "nominal {} {} {}"


# bulk power status
# for bulk power, if it's present, it's either on/fail (not off).
#  { present list } { failed list } {powered list}
set gBulkPowerList "{} {} {}"
# flag which indicates system is eveready capable, set this to one to
# force all 16 bulk power supplies to be shown unconditionally
set gEveready 0


#
# Thermal Values
#
# gTd values define the drawing coordinates used by the thermalDetail form.
# Each temperature is represented by a fat vertical line.
#
# These are treated as constants.  No application should modify these values.
# gTdX1 is initial X value of temperature bar.
# gTdY1, gTdY2 are Y values of temperature bar.
# gTdInc is increment value between bars (x coordinate, left to right).
# gTdWidth is bar width.
#
set gTdX1 36
#set gTdX1 15
set gTdY1 1
set gTdY2 150
#set gTdWidth 20
set gTdWidth 60
#set gTdInc 22
set gTdInc [expr $gTdWidth + 2]
#
# Define the max and min thermal bargraph values (Celsius).
#
set gThermalMaxTemp 110
set gThermalMinTemp 0
#
# Define where thermal trouble starts (Celsius)
#
#set gThermalProblem 60
#
# gThermalList contains the most recent values for all thermal sensors.
# List members are organized in the form {board flag {values}} where 
# flag of 1 indicates problem condition.
#
set gThermalList ""

#
# Power Values
#
# gPd values define the drawing coordinates used by the powerDetail form.
# Each voltage/current is represented by a fat vertical line.
#
# These are treated as constants.  No application should modify these values.
# gPdX1 is initial X value of voltage/current bar.
# gPdY1, gPdY2 are Y values of voltage/current bar.
# gPdInc is increment value between bars (x coordinate, left to right).
# gPdWidth is bar width.
#
set gPdX1 36
#set gPdX1 15
set gPdY1 1
set gPdY2 150
set gPdWidth 60
###set gPdWidth 30
set gPdInc [expr $gPdWidth + 2]

#set gPdInc 22
#set gPdWidth 20
#set gPdX1 15
#
# gPowerList contains the most recent values for all power sensors.
#
set gPowerList ""
# powered buses
set gBusUp ""

# flag to popup "working" window when true
set gNewWin 0

# Define various attributes supporting the edit/properties window.
# 
# gPropVar defines currently selected category
# gPropCategories defines the legal category options for this window.
#
# gProPower is the default power script filename.
#  
set gPropVar dr
set gPropCategories {general blacklist power dr}

#
# Support for properties/dr option
#
set gPropUpdateFlag no
set gPropUpdateFlag2 no

set gPropUpdateValue 10
set gPropUpdateValue2 10

#
# Support for properties/power option
#
set gPwrExecFlag no
set gPwrExecFlag2 no

set gPwrExecCmd "/opt/SUNWssp/bin/power"

#
# Support for properties/edit blacklist
#
set gEdtBlkSave yes
set gEdtBlkSave2 yes
set gEdtBlkPrint lpr
set gEdtBlkDir /optSUNWssp/etc/eng1
set gEdtBlkFile blacklist
set gEdtBlkExt .bak 
set gEdtBlkBackup yes
set gEdtBlkBackup2 yes

#
# Directory which contains the DR routines.
#
#set gDRdirectory "/home/hostview/dr2"

#
#
#
set gDRboard {cpu memory device obp unsafe all}

#
# dr memory config
#
set gMemCurSys 512
set gMemAttCap 512
set gMemMax 1024
set gMemDet 1(enabled)

set gMemConfig 256
set gInterFact 1

set gMemReduction "276 (256+20)"
set gMemRemaining 0
set gMemPercent "50% (0KB Remaining)"
set gMemTimeStart "Tue Jan 17 10:05:34 1995"
set gMemTimeNow   "Tue Jan 17 10:35:17 1995"

# directory containing bitmaps, ascii help files
set gBm_dir $env(SSPOPT)/bitmaps
set gAsciiHelp_dir $env(SSPOPT)/hv_help
set ghelpFile "*.help"

set ghelpBringupFile bringup.help	
set ghelpDrFile dr.help	
set ghelpEditmenuFile editmenu.help	
set ghelpMenuFile menu.help	
set ghelpBlacklistFile prop.help	
set ghelpPropFile prop.help	
set ghelpDomainsFile domains.help	
set ghelpEditFile edit.help	
set ghelpHotswapFile hotswap.help	
set ghelpPowerFile power.help	

#Mib poll frequency, seconds
set pollfrequency 120
set gMibTouched 0
set testfail 0

# set the freq to use when filtering failure events
#set gTrapFreq 240
set gTrapFreq 60
#set gTrapFreq 10
# set the freq to use when refreshing
#set gMibRefreshFreq 60
set gMibRefreshFreq 300
#set gMibRefreshFreq 600

#milliseconds
set gBoardPowerWait 5000

#failure mode history
set gHvFailLogDir $env(SSPVAR)/adm
#set gHvFailLogDir .

# this should be in app defaults
#set gHvMaxFails2Log 16
#set gHvMaxFails2Log 128
set gHvMaxFails2Log 64
#set gSystemFail {{arbstop mari}}
set gSystemFail ""
# each failure event writes a fixed size of info to the log file
# 2 ** 14
#set gFailTextSize 4096
#set gFailTextSize 16384
set gFailTextSize [expr $gHvMaxFails2Log * 80 + 4000]
#set gFailTextSize [expr $gHvMaxFails2Log * 80 * 3 / 4 + 4000]

# can explicity set blacklist file or set to "" for the default
# the default is: $env(SSPVAR)/etc/${platform}/blacklist
#set gBlacklistfile /export/home/ssp/mari/blacklist
set gBlacklistfile ""


# failure snapshot file delimiters
set gSnapTop ";#Hostview internal state snapshot"
set gSnapBott ";#End Hostview internal state snapshot"

set gEventFlg 0

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)hostview_init.tcl	1.6	99/10/26 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   hostview initialization file
#

# user configurable
if { [ file readable ${gHV_HOME}/.hostview ] > 0 } {
	source ${gHV_HOME}/.hostview 
}

#
# Check SSP environment variables:
#
set cray_env "SUNW_HOSTNAME SSPLOGGER"
#set cray_env "SUNW_HOSTNAME SSPETC SSPVAR SSPLOGGER"

foreach var $cray_env {
	if { ![info exists env($var)] } {
	puts "error hostview: Environment variable '$var' must be set."
	#error "hostview: Environment variable '$var' must be set."
	}
}
# for testing:	
if {[ info exists env(SSPLOGGER)] < 1} {
	set env(SSPLOGGER) /workspace/sw/xfire/mari/sspxf/hostview/adm
}

if {[ info exists env(SUNW_HOSTNAME)] < 1} {
	set env(SUNW_HOSTNAME) marvin
}


#
# Get the domain colors from file $HOME/.Xresource and save in $gDomainColors.
# Default is $gDefaultDomainColors
#
# The colors is specified thusly in $HOME/.Xresource:
#
#hostview*domainColor0: white
#. . .
#hostview*domainColor15: tan
#hostview*domainColor16: grey
#
#(domainColor0 - domainColor15 mark each board with a color for each domain.
# domainColor16 (default grey) colors boards not in a domain.)
#
#tk appname hostview
catch {option readfile "$env(HOME)/.Xdefaults" 100} errmsg

#
# Read each all the X resources, leave the default value "as is"
# if the resource was not overridden.
# Save the result(s) in the list $gDomainColors.
#
for {set i 0} {$i <= 16} {incr i} {
	# For each X resource, read it
	# "option add" doesn't work (maybe the resource name is wrong):
	option add "hostview.domainColor$i" \
		 [lindex $gDefaultDomainColors $i ] startup
	set currentColor [option get . domainColor$i Color]

	# Override the default in $gDomainColors
	if { $currentColor != "" } {
		#puts "DEBUG overriding domainColor$i with $currentColor."
		set gDomainColors [lreplace $gDomainColors $i $i $currentColor]
	}
}
#puts "DEBUG gDomainColors $gDomainColors"

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)hvDialog.tcl	1.5	98/02/04 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# hvDialog.tcl --
#	nonblocking dialog widget
# taken from dialog.tcl --
#
# This file defines the procedure tk_dialog, which creates a dialog
# box containing a bitmap, a message, and one or more buttons.
#

#
# tk_dialog:
#
# This procedure displays a dialog box, waits for a button in the dialog
# to be invoked, then returns the index of the selected button.
#
# Arguments:
# w -		Window to use for dialog top-level.
# title -	Title to display in dialog's decorative frame.
# text -	Message to display in dialog.
# bitmap -	Bitmap to display in dialog (empty string means none).
# default -	Index of button that is to display the default ring
#		(-1 means none).
# args -	One or more strings to display in buttons across the
#		bottom of the dialog box.

proc hv_tk_dialog {w title text bitmap default args} {
    global tkPriv
    global gBg1

    # 1. Create the top-level window and divide it into top
    # and bottom parts.

    catch {destroy $w}
    toplevel $w -class Dialog
    wm title $w $title
    wm iconname $w Dialog
    #wm protocol $w WM_DELETE_WINDOW { }
    ####wm transient $w [winfo toplevel [winfo parent $w]]
    frame $w.top -relief raised -bd 1 -bg $gBg1
    pack $w.top -side top -fill both
    frame $w.bot -relief raised -bd 1 -bg $gBg1
    pack $w.bot -side bottom -fill both

    # 2. Fill the top part with bitmap and message (use the option
    # database for -wraplength so that it can be overridden by
    # the caller).

    option add *Dialog.msg.wrapLength 3i widgetDefault
    label $w.msg -justify left -text $text \
	    -font -Adobe-Times-Medium-R-Normal--*-180-*-*-*-*-*-* -bg $gBg1
    pack $w.msg -in $w.top -side right -expand 1 -fill both -padx 3m -pady 3m
    if {$bitmap != ""} {
	label $w.bitmap -bitmap $bitmap -bg $gBg1
	pack $w.bitmap -in $w.top -side left -padx 3m -pady 3m
    }

    # 3. Create a row of buttons at the bottom of the dialog.

    set i 0
    foreach but $args {
	button $w.button$i -text $but -command "destroy $w"
	#button $w.button$i -text $but -command "set tkPriv(button) $i"
	if {$i == $default} {
	    frame $w.default -relief sunken -bd 1
	    raise $w.button$i $w.default
	    pack $w.default -in $w.bot -side left -expand 1 -padx 3m -pady 2m
	    pack $w.button$i -in $w.default -padx 2m -pady 2m
	} else {
	    pack $w.button$i -in $w.bot -side left -expand 1 \
		    -padx 3m -pady 2m
	}
	incr i
    }

    # 4. Withdraw the window, then update all the geometry information
    # so we know how big it wants to be, then center the window in the
    # display and de-iconify it.

    ####wm withdraw $w
    ###update idletasks
    set x [expr [winfo screenwidth $w]/2 - [winfo reqwidth $w]/2 \
	    - [winfo vrootx [winfo parent $w]]]
    set y [expr [winfo screenheight $w]/2 - [winfo reqheight $w]/2 \
	    - [winfo vrooty [winfo parent $w]]]
    wm geom $w +$x+$y
    wm deiconify $w

    # 5. Set a grab and claim the focus too.

    # 6. Wait for the user to respond, then restore the focus and
    # return the index of the selected button.  Restore the focus
    # before deleting the window, since otherwise the window manager
    # may take the focus away so we can't redirect it.  Finally,
    # restore any grab that was in effect.

    return
    #return $tkPriv(button)
}
#
# ident	"@(#)hvIncludes.tcl	1.2	96/07/31 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#	An attempt to fake a C style include file
#

set hvSUCCESS	0
set hvFAIL	1
set hvDONE	100

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)hvRmAddSysbds.tcl	1.2	96/07/31 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# hvRmAddSysbds
# taken from:	ssp_init.tcl --
# 		Startup TCL file for Xfire SSP-based applications.
#
# This file contains tcl procs that can read and write the
# domain_config files.
#

#
# Add a list of system boards to a domain. If the domain does not exist
# in the domain_config file, the request is ignored.
#
# If a list of domains is given, this routine does what it can, 
# ignores others, but reports.
#
# return vals:
#  0 success
# -1 domain_config file empty
# -2 board is already in domain. noop
# -3 domain not in domain_config, use domain_create
#
proc mari_add_sysbds domains {

	foreach i $domains {
		if { [ llength $i ] != "2" } {
			error "bad add_sysbds format [list $i]"
		}
	}
	set entry [ get_domain_config ]
	if { $entry == "" } { return -1 }
	set modified 0
	set domain_match 0
	set board_added 0
	foreach name $entry {
		set dname [ lindex $name 0 ]
		set found 0
		foreach element $domains {
			set domain_name [ lindex $element 0 ]
			set sysbds [ lindex $element 1 ]
			if { $dname == $domain_name } {
			    set domain_match 1
				set d_name [ lindex $name 0 ]
				set d_platform [ lindex $name 1 ]
				set d_machine [ lindex $name 2 ]
				set d_OS [ lindex $name 3 ]
				set d_old_sysbds [ lindex $name 4 ]
				foreach brd $sysbds {
					if { [ lsearch $d_old_sysbds $brd ] == -1 } {
						lappend d_new_sysbds $brd
						incr found
						incr modified
					}
				}
				if { $found > 0 } {
					set d_sysbds [ format "%s%s" $d_old_sysbds $d_new_sysbds ]
				    set board_added 1
				} else {
					set d_sysbds [ lindex $name 3 ]
				}
				set d_list [ format "{%s} {%s} {%s} {%s} {%s}" $d_name $d_platform $d_machine $d_OS $d_sysbds ]
				lappend data $d_list
			}
		}
		if { $found == 0 } {
			lappend data $name
		}
	}
	if { $modified == 0 } { 
	    if { $domain_match == 0 } {
		return -3
	    }
	    if { $board_added == 0 } {
		return -2
	    }
	}
	put_domain_config $data
	return 0
}


#
# Remove a list of system boards from a domain. If the domain does not
# exist in the domain_config file, the request is ignored.
# Also, if a given sysbd is not found in the sysbd_list, it is ignored.
# If a list of domains is given, this routine does what it can, 
# ignores others, but reports.
#
# return vals:
#  0 success
# -1 domain_config file empty
# -2 board is last in domain.  use domain_remove
# -3 domain not in domain_config
# -4 board not in domain in domain_config

proc mari_rm_sysbds domains {

	foreach i $domains {
		if { [ llength $i ] != "2" } {
		    #error terminates
			error "bad rm_sysbds format [list $i]"
		}
	}
	set entry [ get_domain_config ]
	if { $entry == "" } { return -1}
	set modified 0
	set domain_match 0
	set last_board 0
	foreach name $entry {
		set dname [ lindex $name 0 ]
		set found 0
		foreach element $domains {
			set domain_name [ lindex $element 0 ]
			set sysbds [ lindex $element 1 ]
			if { $dname == $domain_name } {
			    set domain_match 1
				set d_name [ lindex $name 0 ]
				set d_platform [ lindex $name 1 ]
				set d_machine [ lindex $name 2 ]
				set d_OS [ lindex $name 3 ]
				set d_old_sysbds [ lindex $name 4 ]
				foreach brd $d_old_sysbds {
					if { [ lsearch $sysbds $brd ] == -1 } {
					    # leave this board in
						lappend d_new_sysbds $brd
					} else {
						incr found
						incr modified
					}
				}
				# was this the last board in the domain?
				if { ![info exists d_new_sysbds] } {
				    set last_board 1
				    set modified [expr $modified - $found ]
				    set found 0
				}
				if { $found > 0 } {
					set d_sysbds [ format "%s" $d_new_sysbds ]
				} else {
				    # no change
					set d_sysbds [ lindex $name 3 ]
				}
				set d_list [ format "{%s} {%s} {%s} {%s} {%s}" $d_name $d_platform $d_machine $d_OS $d_sysbds ]
				lappend data $d_list
			}
		}
		if { $found == 0 } {
		    #this domain's list is unchanged.
			lappend data $name
		}
	}
	if { $modified == 0 } { 
	    if { $last_board == 1 } {
		return -2
	    }
	    if { $domain_match == 0 } {
		return -3
	    }
	    # if modified == 0 and above are false,
	    return -4
	}
	put_domain_config $data
	return 0
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***

#
# ident	"@(#)hvSnapshot.tcl	1.8	00/08/14 SMI"
#
# Copyright (c) 1996-2000 by Sun Microsystems, Inc.
# All rights reserved.
#

proc saveState_part1 { fileId  trapnum } {
    global gBoards
    global gDomains
    global gFanList
    global gProcessors
    global gThermalList
    global gPowerList
    global gDomainColors
    global gDomainColorMap
    global gPowered
    global gSystemFail
    global gBulkPowerList
    global gBusUp
    global gHostviewName
    global gSnapTop
    global gSnapBott

    global gMAXsb_volt
    global gMINsb_volt
    global gMINsb_voltOff

    global gMAXcb_volt
    global gMINcb_volt
    global gMINcb_voltOff

    global gMAXcsb_volt
    global gMINcsb_volt
    global gMINcsb_voltOff

    global gWARNasic
    global gMAXasic
    global gT911asic
    global gWARNproc
    global gMAXproc
    global gT911proc
    global gWARNps
    global gMAXps
    global gT911ps
    global gWARNamb
    global gMAXamb
    global gT911amb
    
    global gVoltDefaultMAX
    global gVoltDefaultMIN

    
    debug 1 "saveState $fileId $trapnum"


    # see if power, temp or fan are current and don't need to be read.
    # power current if power trap or power detail is up.

    if {  $trapnum >= 3 &&  $trapnum <= 23  ||  $trapnum >= 26 &&  $trapnum <= 32  } {
	set count_t 1
    } else {
	set count_t [countDetails thermal]
    }
    if {  $trapnum >= 33 &&  $trapnum <= 52 } {
	set count_p 1
    } else {
	set count_p [countDetails power]
    }
    if { $trapnum == 54 } {
	set count_f 1
    } else {
	set count_f [countDetails fan]
    }



    #set gSnapTop ";#Hostview internal state snapshot"
    puts  $fileId $gSnapTop
    puts  $fileId "\n;#board states:{board domain power loaded|empty} "
    puts  $fileId "set gBoards \"$gBoards\""
    puts  $fileId "; "
    puts $fileId  "\n;#Domains: {domain_name {sys board list}}"
    puts  $fileId "set gDomains \"$gDomains\""
    puts  $fileId "; "
    puts $fileId  "\n;#Processors: { proc number {signature state}}"
    puts  $fileId "set gProcessors \"$gProcessors\""
    puts  $fileId "; "

    if { $count_t > 0 } {
	puts  $fileId "\n;#Thermal List: { board flag {values}} flag 1 indicates problem condition."
	puts  $fileId "set gThermalList \"$gThermalList\""
	puts  $fileId "; "
    }
    if { $count_p > 0 } {
	puts $fileId  "\n;#Power List: { board flag {values}} flag 1 indicates problem condition."
	puts  $fileId "set gPowerList \"$gPowerList\""
	puts  $fileId "; "

	puts $fileId  "\n;#Bulk Power List: { present list } { failed list } {powered list}"
	puts  $fileId "set gBulkPowerList \"$gBulkPowerList\""
	puts  $fileId "; "
    }
    if { $count_f > 0 } {
	puts $fileId  "\n;#Fan List: speed_for_all { failed list } {powered list}"
	puts  $fileId "set gFanList \"$gFanList\""
	puts  $fileId "; "
    }

    #puts $fileId  "\n;#Bulk Power List: { present list } { failed list } {powered list}"
    #puts  $fileId "set gBulkPowerList \"$gBulkPowerList\""
    #puts  $fileId "; "
    
    puts  $fileId "set gDomains \"$gDomains\""
    puts  $fileId "; "
    puts  $fileId "set gDomainColors \"$gDomainColors\""
    puts  $fileId "; "
    puts  $fileId "set gDomainColorMap \"$gDomainColorMap\""
    puts  $fileId "; "
    puts $fileId  "\n;#Powered center plane and bulk power {bp2 is PS2}"
    puts  $fileId "set gPowered \"$gPowered\""
    puts  $fileId "; "
    puts $fileId  "\n;#System Fail List: {failure domain_name {date}}"
    puts  $fileId "set gSystemFail \"$gSystemFail\""
    puts  $fileId "; "
    puts  $fileId "set gBusUp \"$gBusUp\""
    puts  $fileId "; "
    puts  $fileId "set gHostviewName \"$gHostviewName\""
    puts  $fileId "; "

    puts $fileId "set gMAXsb_volt \"$gMAXsb_volt\"; "
    puts $fileId "set gMINsb_volt \"$gMINsb_volt\"; "
    puts $fileId "set gMINsb_voltOff \"$gMINsb_voltOff\"; "

    puts $fileId "set gMAXcb_volt \"$gMAXcb_volt\"; " 
    puts $fileId "set gMINcb_volt \"$gMINcb_volt\"; "
    puts $fileId "set gMINcb_voltOff \"$gMINcb_voltOff\"; "

    puts $fileId "set gMAXcsb_volt \"$gMAXcsb_volt\"; "
    puts $fileId "set gMINcsb_volt \"$gMINcsb_volt\"; "
    puts $fileId "set gMINcsb_voltOff \"$gMINcsb_voltOff\"; "

    
    puts $fileId "set gVoltDefaultMAX $gVoltDefaultMAX; "
    puts $fileId "set gVoltDefaultMIN $gVoltDefaultMIN; "

    puts $fileId "set  gWARNasic $gWARNasic; "
    puts $fileId "set  gMAXasic $gMAXasic; "
    puts $fileId "set  gT911asic $gT911asic; "
    puts $fileId "set  gWARNproc $gWARNproc; "
    puts $fileId "set  gMAXproc $gMAXproc; "
    puts $fileId "set  gT911proc $gT911proc; "
    puts $fileId "set  gWARNps $gWARNps; "
    puts $fileId "set  gMAXps $gMAXps; "
    puts $fileId "set  gT911ps $gT911ps; "
    puts $fileId "set  gWARNamb $gWARNamb; "
    puts $fileId "set  gMAXamb $gMAXamb; "
    puts $fileId "set  gT911amb $gT911amb; "

    # Bug 4284668
    # Get file offset. Pass it to hostview_child.  When hostview_child
    # calls back to hostview it passes the file offset back to
    # saveState_part2 which seeks to offset and continues writing.
    set fileOffset [tell $fileId]

    # spawn child to read mib and when it's done it'll
    # call saveState_part2
    # asyncronous mib read


    set vthresh "set gMAXsb_volt \"$gMAXsb_volt\"; set gMINsb_volt \"$gMINsb_volt\"; set gMINsb_voltOff \"$gMINsb_voltOff\"; set gMAXcb_volt \"$gMAXcb_volt\"; set gMINcb_volt \"$gMINcb_volt\"; set gMINcb_voltOff \"$gMINcb_voltOff\"; set gMAXcsb_volt \"$gMAXcsb_volt\"; set gMINcsb_volt \"$gMINcsb_volt\"; set gMINcsb_voltOff \"$gMINcsb_voltOff\"; set gVoltDefaultMAX \"$gVoltDefaultMAX\"; set gVoltDefaultMIN \"$gVoltDefaultMIN\"; "

	set tthresh "set  gWARNasic \"$gWARNasic\";  set  gMAXasic \"$gMAXasic\"; set  gT911asic \"$gT911asic\"; set  gWARNproc \"$gWARNproc\";  set  gMAXproc \"$gMAXproc\"; set  gT911proc \"$gT911proc\"; set  gWARNps \"$gWARNps\"; set  gMAXps \"$gMAXps\"; set  gT911ps \"$gT911ps\"; set  gWARNamb \"$gWARNamb\"; set  gMAXamb \"$gMAXamb\"; set  gT911amb \"$gT911amb\";"

	set tvthresh "$vthresh $tthresh"

	set args [format "{%s} {%s} {%s} {%s} {%s} {%s} {%s}" $gHostviewName $count_t $count_p $count_f $gProcessors $tvthresh $fileOffset]


    # Dump the first part of the $SSPLOGGER/hostview*.log asynchronously.
    # This is to not slow down hostview with MIB reads--which take
    # a very long time.
    #
    # First, check our child processes for a previously-existing
    # "hostview -R" process.
    # If there is one, we don't want to start another process, as one is
    # already dumping the MIB state to the same $SSPLOGGER/hostview*.log
    # file.  Running several can slow down the SSP.  Bug 4362012.
    set mypid [pid]
    set pscommand "exec /usr/bin/ps -fu ssp -oppid,args | grep -v grep | grep $mypid | grep hostview_child.-R"
    if [catch $pscommand pslist] {
	# Do an async read of temp/power/fan for failure snapshot:
	if [catch {exec hostview_child -R $args &} result]  {
		debug 10 $result
	}

    }
}


proc saveState_part2 { ThermalList PowerList FanList FileOffset } {
    global gFailFd  
    global gSnapBott  
    global gHvFailLogDir 
    global gSysFailLog

    set logFile $gHvFailLogDir/$gSysFailLog
    if { [ catch {set fileId [ open $logFile r+ 0600]} errmsg ] } {
        debug 10 "Error opening error log file: $errmsg"
	return
    }
    set gFailFd $fileId

    # Bug 4284668
    # Seek to FileOffset to position for writing part2 of the state after
    # the corresponding part1 of the state.
    seek $fileId $FileOffset start

    debug 1  "saveState_part2: ThermalList $ThermalList PowerList: $PowerList FanList $FanList"

    if { [ llength $ThermalList ] > 1 } {

	puts  $fileId "\n;#Thermal List: { board flag {values}} flag 1 indicates problem condition."
	puts  $fileId "set gThermalList \"$ThermalList\""
	puts  $fileId "; "
    }

    if { [ llength $PowerList ] > 1 } {
	set pwr [ lindex $PowerList 0 ]
	set bulk [ lindex $PowerList 1 ]
	puts $fileId  "\n;#Power List: { board flag {values}} flag 1 indicates problem condition."
	puts  $fileId "set gPowerList \"$pwr\""
	puts  $fileId "; "

	puts $fileId  "\n;#Bulk Power List: { present list } { failed list } {powered list}"
	puts  $fileId "set gBulkPowerList \"$bulk\""
	puts  $fileId "; "
    }

    if { [ llength $FanList ] > 1 } { 
	puts $fileId  "\n;#Fan List: speed_for_all { failed list } {powered list}"
	puts  $fileId "set gFanList \"$FanList\""
	puts  $fileId "; "
    }
    

    #set gSnapBott ";#End Hostview internal state snapshot"
    puts  $fileId $gSnapBott
    puts  $fileId "; "

    sysFail_part2
}


proc hvSnapshot { state } {
    global DEFAULT_BUS
    global gBg1
    global gFg1

    global gBoards
    global gDomains
    global gFanList
    global gProcessors
    global gThermalList
    global gPowerList
    global gDomainColors
    global gDomainColorMap
    global gPowered
    global gSystemFail
    global gBulkPowerList
    global gBusUp
    global gSnapInst
    global gPidMibFresh
    global gProblem

    global gMAXsb_volt
    global gMINsb_volt
    global gMINsb_voltOff

    global gMAXcb_volt
    global gMINcb_volt
    global gMINcb_voltOff

    global gMAXcsb_volt
    global gMINcsb_volt
    global gMINcsb_voltOff

        global gWARNasic
    global gMAXasic
    global gT911asic
    global gWARNproc
    global gMAXproc
    global gT911proc
    global gWARNps
    global gMAXps
    global gT911ps
    global gWARNamb
    global gMAXamb
    global gT911amb
    
    global gVoltDefaultMAX
    global gVoltDefaultMIN
    
    
    # draw the generic hostview, then fill in the actual environ
    #
    # ==>Main Menu Bar
    #
    frame .menuBar -relief groove -borderwidth 4 -bg $gBg1
    pack .menuBar -side top -fill x
 
    menuBar $gBg1
    
    #
    # ==>Icon Button Bar
    #
    frame .iconBar -bg $gBg1
    pack .iconBar -side top -anchor w -fill x
 
    iconBar $gBg1


    #
    # ==>System Graphic Display
    #
    canvas .systemGraphic -relief groove -borderwidth 4 -bg $gBg1
    pack .systemGraphic -fill both -expand yes
 
    systemGraphic $gBg1 $gFg1
    
    if {[catch [ tkwait visibility .systemGraphic ] result] } {
	debug 4 $result
	exit
    }


    pack forget .menuBar.edit .menuBar.control .menuBar.configuration\
            .menuBar.terminal .menuBar.view .menuBar.help


    .menuBar.file.m delete 0 0

    pack forget .iconBar.event

    #don't poll the mib, or read the mib
    set gPidMibFresh 99999999
    set gSnapInst 1

    wm title . "Hostview-Failure Snapshot"


    debug 1 "hvSnap: state: $state"
    eval $state


    debug 1 "hvSnap: gBoards: $gBoards"
    debug 1 "hvSnap: gDomainColorMap: $gDomainColorMap"
    debug 1 "hvSnap: gDomainColors: $gDomainColors"

    foreach blist $gBoards {

	set board [lindex $blist 0]
	if { [lsearch $blist "slot_loaded"] > -1 } {
	    boardDiscovered $board
	}
	if { [lsearch $blist "power_on"] > -1 } {
	    boardPowerUp $board
	    if { [ string first c $board ] == -1 } {
		set proc1 [expr $board * 4]
		set proclist "$proc1 [expr $proc1 + 1] [expr $proc1 + 2] [expr $proc1 + 3]"
		foreach proc $proclist {
					if {$proc < 10 } {
					    set proc 0$proc
					}
					set temp [ whatProcState $proc ]
					set sig [lindex $temp 0]
					set ste [lindex $temp 1]
					setProcIcon $proc $sig $ste
				    }
	    }
	}
	if { [lsearch $blist "jtag_on"] > -1 } {
	    setJtag $board on
	}
	if { [lsearch $blist "clock_on"] > -1 } {
	    setClock $board on
	}
    }
    debug 1 "hvSnap: gDomains: $gDomains"
    debug 1 "hvSnap: gDomainColorMap: $gDomainColorMap"
    debug 1 "hvSnap: gDomainColors: $gDomainColors"

    set busSave $gBusUp
    foreach buss $DEFAULT_BUS {
	grayBus $buss
    }
    foreach bus $busSave {
	greenBus $bus
    }

    set problem 0
    foreach ndx $gThermalList {
        if {[lindex $ndx 1] == 1} {
		    set problem 1
			break
        }
	}
    if {$problem != 0} {
		if [winfo exists .iconBar.thermal] {
			.iconBar.thermal configure -bg $gProblem
			.iconBar.thermal.button configure -image temperatureRed
        }
    }

    set problem 0
    foreach ndx $gPowerList {
        if {[lindex $ndx 1] == 1} {
	    	set problem 1
			break
        }
	}
 	if { [ lsearch [lindex $gBulkPowerList 1] bp* ] > -1 } {
       	set problem 1
   	}
	if {$problem != 0} {
		if [winfo exists .iconBar.power] {
			.iconBar.power configure -bg $gProblem
			.iconBar.power.button configure -image powerRed
		}
	}



    set problem 0
	foreach ndx $gFanList {
        if {[lindex $ndx 1] == 1} {
		    set problem 1
			break
        }
	}
    if {$problem != 0} {
    	if [winfo exists .iconBar.fan] {
			.iconBar.fan configure -bg $gProblem
			.iconBar.fan.button configure -image fanRed
        }
    }



}




#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)iconBar.tcl	1.2	96/07/31 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   Create and populate the icon bar on the main window of HostView.
#
#   Each button has a frame which turns colors for operator attention.
#

proc iconBar { bg1 } {
    frame  .iconBar.power -relief flat -borderwidth 4 -bg $bg1
    button .iconBar.power.button -image power \
	-bg white -activebackground $bg1 \
	-command {systemDetail "Power"} 

    frame  .iconBar.thermal -relief flat -borderwidth 4 -bg $bg1
    button .iconBar.thermal.button -image temperature \
	-bg white -activebackground $bg1 \
	-command {systemDetail "Thermal"} 

    frame  .iconBar.fan -relief flat -borderwidth 4 -bg $bg1
    button .iconBar.fan.button -image fan \
	-bg white -activebackground $bg1 \
	-command {systemDetail "Fan"} 

    frame .iconBar.event -relief flat -borderwidth 4 -bg $bg1

    button .iconBar.event.button -image event \
	    -command eventIcon -bg white -activebackground $bg1

    pack .iconBar.power.button .iconBar.thermal.button \
	    .iconBar.fan.button .iconBar.event.button

    pack .iconBar.power .iconBar.thermal .iconBar.fan \
	    -side left -padx 1m -pady 1m

    pack .iconBar.event -side right -padx 1m -pady 1m
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)listUtils.tcl	1.18	99/02/25 SMI"
#
# Copyright (c) 1996-1999 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   Primitives for list management.
#
# gFanList:
#   Set system fan speed.
#     proc updateFanSpeed {speed}
#   Set system fan failure.
#     proc updateFanFailure {fan flag} 
#   Get system fan speed.
#     proc whatFanSpeed {}
#   Get system fan failure.
#     proc whatFanFailure {}
# gBulkPowerList:
#   Set system BP conf list.
#     proc updateBPconf {BP flag}
#   Set system BP failure.
#     proc updateBPFailure {BP flag} 
#   Get system BP conf.
#     proc whatBPconf {}
#   Get system BP failure.
#     proc whatBPFailure {}
# gPowerList:
#   Given a board, flag and power values, update the list.
#     proc updatePower {board, flag, {power_vals}}
#   Given a board, index and 1 power value, update the list.
#     proc update1Power {board, index, power_val}
#   Given a board, return the list item.
#     proc whatPower {board}
# gThermalList:
#   Given a board, flag and temperatures, update the list.
#     proc updateThermal {board, flag, {temperatures}}
#   Given a board, index and 1 temperature, update the list.
#     proc update1Thermal {board, index, temperatures}
#   Given a board, return the list item.
#     proc whatTemperature {board}
# gDomains:
#   Given a domain, return a list of members.
#     proc whatDomain {color}
#   Given a domain and board, update the domain list.
#     proc updateDomain {domainName, board, add|delete}
#   Given a board, return it's domain.
#     proc whatIsMyDomain {board}
#   determine what domain is selected (if any)
#	whatDomainSelected {} {
#   return the domain or SUNW_HOSTNAME if no domain selected
#	domainOrCrayhostname
#   return the domain or no_domain if no domain selected
#	getSelDom
# gBoards:
#   Given a board id, update the state.
#     proc updateBoardList {board state}
#   Given a board id, return the state
#     proc whatBoardState {board}
#   Initialization for gBoards
#     proc setupBoardList {} 
# gProcessors:
#   Given a processor id (00..63) update the signature (empty|os|obp|post|dhlp) and state
#     proc updateProcList {procId state} 
#   Given a processor id (00..63) return the sig (empty|os|obp|post|dhlp). and state.
#     proc whatProcState {procId} 
#   Initialization for gProcessors
#     proc setupProcList {} 
# gPowered
#   add a board to the list of powered boards
#	greenPower {board}
#

#
# Set system fan speed.  Speed is off|nominal|high
#
proc updateFanSpeed {speed} {
    global gFanList

    debug 2 "updateFanSpeed:$speed"

    set gFanList [lreplace $gFanList 0 0 $speed]
}

#
# Set system fan failure. flag = fail|repair, fan = ft0a
#
proc updateFanFailure {fan flag} {
    global gFanList

    debug 2 "updateFanFailure:$fan $flag"

    set failures [lindex $gFanList 1]
    
    if {[string compare $flag fail] == 0} {
	if { [lsearch $failures $fan] == -1 } {
	    set failures "$failures $fan"
	    set gFanList [lreplace $gFanList 1 1 $failures]
	}
    } else {
	set temp1 ""
	foreach ndx $failures {
	    if {[string compare $ndx $fan] != 0} {
		set temp1 "$temp1 $ndx"
	    }
	}
	set gFanList [lreplace $gFanList 1 1 $temp1]
    }
}
#
# Set system fan failure. flag = on|off, fan = ft0
# update list of fans that are powered.
#
proc updateFansPowered {fan flag} {
    global gFanList

    debug 2 "updateFansPowered:$fan $flag"

    set fanspowered [lindex $gFanList 2]
    
    if {[string compare $flag powerOn] == 0} {
	if { [lsearch $fanspowered $fan] == -1 } {
	    set fanspowered "$fanspowered $fan"
	    set gFanList [lreplace $gFanList 2 2 $fanspowered]
	}
    } else {
	set temp1 ""
	foreach ndx $fanspowered {
	    if {[string compare $ndx $fan] != 0} {
		set temp1 "$temp1 $ndx"
	    }
	}
	set gFanList [lreplace $gFanList 2 2 $temp1]
    }
}
#
# Get system fan speed.
#
proc whatFanSpeed {} {
    global gFanList

    debug 2 "whatFanSpeed"

    return [lindex $gFanList 0]
}
#
# Get system fans powered list.
#
proc whatFansPowered {} {
    global gFanList

    debug 2 "whatFansPowered"

    return [lindex $gFanList 2]
}
#
#   Get system fan failure.
#
proc whatFanFailure {} {
    global gFanList
    
    debug 2 "whatFanFailure: [lindex $gFanList 1]"

    return [lindex $gFanList 1]
}
#
# Set FAN conf list
#
proc updateFanconf {FAN flag} {
    global gFanList

    debug 2 "updateFanconf:$FAN $flag"
    set fanconf [lindex $gFanList 3]

    set temp1 ""
    if { [ string compare remove $flag] == 0 } {
	foreach ndx $fanconf {
	    if {[string compare $ndx $FAN] != 0} {
		set temp1 "$temp1 $ndx"
	    }
	}
    } else {
	if { [ lsearch $gFanList $FAN ] == -1 } {
	    set temp1 "$fanconf $FAN"
	}
    }
    set gFanList [lreplace $gFanList 3 3 $temp1]
}
#
# Set BP conf list
#
proc updateBPconf {BP flag} {
    global gBulkPowerList

    debug 2 "updateBpconf:$BP $flag"
    set bpconf [lindex $gBulkPowerList 0]

    set temp1 ""
    if { [ string compare remove $flag] == 0 } {
	foreach ndx $bpconf {
	    if {[string compare $ndx $BP] != 0} {
		set temp1 "$temp1 $ndx"
	    }
	}
    } else {
	if { [ lsearch $gBulkPowerList $BP ] == -1 } {
	    set temp1 "$bpconf $BP"
	}
    }
    set gBulkPowerList [lreplace $gBulkPowerList 0 0 $temp1]
}

#
# Set system BP failure. flag = fail|repair
#
proc updateBPFailure {BP flag} {
    global gBulkPowerList

    debug 2 "updateBPFailure:$BP $flag"

    set failures [lindex $gBulkPowerList 1]
    
    if {[string compare $flag fail] == 0} {
	if { [lsearch $failures $BP] == -1 } {
	    set failures "$failures $BP"
	    set gBulkPowerList [lreplace $gBulkPowerList 1 1 $failures]
	}
    } else {
	set temp1 ""
	foreach ndx $failures {
	    if {[string compare $ndx $BP] != 0} {
		set temp1 "$temp1 $ndx"
	    }
	}
	set gBulkPowerList [lreplace $gBulkPowerList 1 1 $temp1]
    }
}
#
# 
# update list of bps that are powered.
#
proc updateBpsPowered {bp flag} {
    global gBulkPowerList

    debug 2 "updateBpsPowered:$bp $flag"

    set bpspowered [lindex $gBulkPowerList 2]
    
    if {[string compare $flag powerOn] == 0} {
	if { [lsearch $bpspowered $bp] == -1 } {
	    set bpspowered "$bpspowered $bp"
	    set gBulkPowerList [lreplace $gBulkPowerList 2 2 $bpspowered]
	}
    } else {
	set temp1 ""
	foreach ndx $bpspowered {
	    if {[string compare $ndx $bp] != 0} {
		set temp1 "$temp1 $ndx"
	    }
	}
	set gBulkPowerList [lreplace $gBulkPowerList 2 2 $temp1]
    }
}

proc updateBpsPres {bp flag} {
    global gBulkPowerList

    debug 2 "updateBpsPres:$bp $flag"

    set bpspres [lindex $gBulkPowerList 0]
    
    if {[string compare $flag slot_loaded] == 0} {
	if { [lsearch $bpspres $bp] == -1 } {
	    set bpspres "$bpspres $bp"
	    set gBulkPowerList [lreplace $gBulkPowerList 0 0 $bpspres]
	}
    } else {
	set temp1 ""
	foreach ndx $bpspres {
	    if {[string compare $ndx $bp] != 0} {
		set temp1 "$temp1 $ndx"
	    }
	}
	set gBulkPowerList [lreplace $gBulkPowerList 0 0 $temp1]
    }
}

proc updateBpsFail { bp flag } {
    global gBulkPowerList

    debug 2 "updateBpsFail:$bp flag"

    set bpsfail [lindex $gBulkPowerList 1]
    
    if { [string compare $flag fail] == 0 } {
	if { [lsearch $bpsfail $bp] == -1 } {
	    set bpsfail "$bpsfail $bp"
	    set gBulkPowerList [lreplace $gBulkPowerList 1 1 $bpsfail]
	}
    } else {
	if { [lsearch $bpsfail $bp] > -1 } {
	    set temp1 ""
	    foreach ndx $bpsfail {
		if {[string compare $ndx $bp] != 0} {
		    set temp1 "$temp1 $ndx"
		}
	    }
	    set gBulkPowerList [lreplace $gBulkPowerList 1 1 $temp1]
	}
    }
}

#
# Get system bp conf
#
proc whatBPconf {} {
    global gBulkPowerList

    debug 2 "whatBpconf"

    return [lindex $gBulkPowerList 0]
}
#
# Get system bps powered list.
#
proc whatBpsPowered {} {
    global gBulkPowerList

    debug 2 "whatBpsPowered"

    return [lindex $gBulkPowerList 2]
}
#
#   Get system bp failure.
#
proc whatBpFailure {} {
    global gBulkPowerList
    
    debug 2 "whatBpFailure"

    return [lindex $gBulkPowerList 1]
}

proc updateBusList { bus flag } {
    global gBusUp

    debug 2 "updateBusList:$bus flag"

    if { [string compare $flag up] == 0 } {
	if { [lsearch $gBusUp $bus] == -1 } {
	    set gBusUp "$gBusUp $bus"
	}
    } else {
	if { [lsearch $gBusUp $bus] > -1 } {
	    set temp1 ""
	    foreach ndx $gBusUp {
		if {[string compare $ndx $bus] != 0} {
		    set temp1 "$temp1 $ndx"
		}
	    }
	    set gBusUp $temp1
	}
    }
}



#
# Update an entry in gPowerList
#
proc updatePower {board flag pwr_vals} {
    global gPowerList

    debug 2 "updatePower:$board $flag $pwr_vals"

    set new_stuff "$board $flag {$pwr_vals}"

	if { [string compare $board 1] == 0 } {
		set board "1 "
	}
    set ndx [lsearch -glob $gPowerList $board*]

    if {$ndx < 0} {
	set gPowerList "$gPowerList {$new_stuff}"
    } else {
	set gPowerList [lreplace $gPowerList $ndx $ndx $new_stuff]
    }
}
#
# Return a entry in gPowerList
#
proc whatPower {board} {
    global gPowerList
    debug 2 "whatPower:$board"

	if { [string compare $board 1] == 0 } {
		set board "1 "
	}
    set ndx [lsearch -glob $gPowerList $board*]

    if {$ndx < 0} {
	return ""
    } else {
	return [lindex $gPowerList $ndx]
    }
}
#
# remove entry in power list
#
proc delPower {board} {
    global gPowerList
    debug 2 "delPower:$board"

	if { [string compare $board 1] == 0 } {
		set board "1 "
	}
    set ndx [lsearch -glob $gPowerList $board*]

    if {$ndx < 0} {
	return ""
    } else {
	set gPowerList [ lreplace $gPowerList $ndx $ndx ]
    }
}

#
# Update an entry in gPowerList
#
proc update1Power {board ndx pwr_val} {
    global gPowerList
    global gDebugThreshold

    debug 2 "update1Power:$board $ndx $pwr_val"

    set pwrList [whatPower $board]
    if { ![llength $pwrList ]} {
	#read the mib
	hv_hostinfo -p
	return
    }
    set flag [lindex $pwrList 1]
    set pwrs [lindex $pwrList 2]
    #1 0 {{4.0 4.1 4.2 4.3 4.4} {}}
    #cb0 0 {{4.0 4.1 4.2 4.3 4.4} {}}
    #csb0 0 {{4.0 4.1 3.0} {}}
    # no longer used: ctr 0 {{10 20 30} {}}

    set s0 [llength [lindex $pwrs 0 ]]
    set s1 [llength [lindex $pwrs 1 ]]
    set s2 [llength [lindex $pwrs 2 ]]
    if { $ndx < $s0 } {
	set pwr [lindex $pwrs 0 ]
	#set pwr [lindex [lindex $pwrList 2] 0 ]

	set temp [lindex $pwr $ndx]
	if { [ string compare $temp ""] == 0 } {
	    set message "board: $board pwrList: $pwrList gPowerList: $gPowerList"
	    logMessage $message "Hostview: error: "

	    if { $gDebugThreshold < 4 } {
		set result [hv_tk_dialog .fileerr "Hostview Error" \
				"$message" \
				warning 0 OK]
	    }

	    return
	}

	set newpwr [lreplace $pwr $ndx $ndx $pwr_val]
	set pwrs [lreplace $pwrs 0 0 $newpwr]
    } elseif { $ndx < [expr $s0 + $s1] } {
	set pwr [lindex [lindex $pwrList 2] 1 ]
	set ndx [expr $ndx - $s0]
	set newpwr [lreplace $pwr $ndx $ndx $pwr_val]
	set pwrs [lreplace $pwrs 1 1 $newpwr]
    } else {
	set pwr [lindex [lindex $pwrList 2] 2 ]
	set ndx [expr $ndx - $s0 - $s1]
	set newpwr [lreplace $pwr $ndx $ndx $pwr_val]
	set pwrs [lreplace $pwrs 2 2 $newpwr]
    }
    updatePower $board $flag $pwrs

}
#
#
# add a board to the list of powered boards
# this may only be used by ctr and bulk power
proc greenPower {board} {
    global gPowered

    debug 2 "greenPower:$board"
	if { [string compare $board bp1] == 0 } {
		set match "bp1 "
	} else {
		set match $board
	}

    set ndx [lsearch -glob $gPowered $match*]

    if {$ndx < 0} {
	set gPowered "$gPowered $board"
    }
}
proc brownPower {board} {
    global gPowered

    debug 2 "greenPower:$board"
    if { [string compare $board bp1] == 0 } {
	set match "bp1 "
    } else {
	set match $board
    }

    set ndx [lsearch -glob $gPowered $match*]
    
    if {$ndx >= 0} {
	set temp1 ""
	foreach ndx $gPowered {
	    if {[string compare $ndx $board] != 0} {
		set temp1 "$temp1 $ndx"
	    }
	}

	set gPowered $temp1
    }
}

#
# Update an entry in gThermalList
#
proc updateThermal {board flag temperatures} {
    global gThermalList

    debug 2 "updateThermal:$board $flag $temperatures"

    set new_stuff "$board $flag {$temperatures}"

	if { [string compare $board 1] == 0 } {
		set board "1 "
	}
    set ndx [lsearch -glob $gThermalList $board*]

    if {$ndx < 0} {
	set gThermalList "$gThermalList {$new_stuff}"
    } else {
	set gThermalList [lreplace $gThermalList $ndx $ndx $new_stuff]
    }
}

#
# Update an entry in gThermalList
#
proc update1Thermal {board ndx temperature} {
    global gThermalList

    debug 2 "update1Thermal:$board $ndx $temperature"

    set tempList [whatTemperature $board]
    if { ![llength $tempList ]} {
	#read the mib
	hv_hostinfo -t
	return
    }
    set flag [lindex $tempList 1]
    set temps [lindex $tempList 2]
    #1 0 {{21 21 21 21 21} {43 50 34} {52 57 53 53}}
    #cb0 0 {{0. 0. 0.} {0. 0. 0.}}
    #csb0 0 {32 32}
    #ctr 0 {{24 24 24 24 24 24 24 24 24 24 } {24 24 24 24 24 24 24 24 24 24 }}

    set s0 [llength [lindex $temps 0 ]]
    set s1 [llength [lindex $temps 1 ]]
    set s2 [llength [lindex $temps 2 ]]
    if { $ndx < $s0 } {
	set temp [lindex [lindex $tempList 2] 0 ]
	set newtemp [lreplace $temp $ndx $ndx $temperature]
	set temps [lreplace $temps 0 0 $newtemp]
    } elseif { $ndx < [expr $s0 + $s1] } {
	set temp [lindex [lindex $tempList 2] 1 ]
	set ndx [expr $ndx - $s0]
	set newtemp [lreplace $temp $ndx $ndx $temperature]
	set temps [lreplace $temps 1 1 $newtemp]
    } else {
	set temp [lindex [lindex $tempList 2] 2 ]
	set ndx [expr $ndx - $s0 - $s1]
	set newtemp [lreplace $temp $ndx $ndx $temperature]
	set temps [lreplace $temps 2 2 $newtemp]
    }
    updateThermal $board $flag $temps

}
#
# Return a entry in gThermalList
#
proc whatTemperature {board} {
    global gThermalList
    debug 2 "whatTemperature:$board"

	if { [string compare $board 1] == 0 } {
		set board "1 "
	}
    set ndx [lsearch -glob $gThermalList $board*]

    if {$ndx < 0} {
	return ""
    } else {
	return [lindex $gThermalList $ndx]
    }
}

#
# Remove an entry in gThermalList
#
proc delTemperature {board} {
    global gThermalList
    debug 2 "delTemperature:$board"

	if { [string compare $board 1] == 0 } {
		set board "1 "
	}
    set ndx [lsearch -glob $gThermalList $board*]

    if {$ndx < 0} {
	return ""
    } else {
	set gThermalList [ lreplace $gThermalList $ndx $ndx ]
    }
}


#
# Given a domain, return a list of members.
#
proc whatDomain {domainName} {
    global gDomains

    debug 2 "whatDomain:$domainName"

    set ndx [domainIndex $domainName ]
    if { $ndx < 0 } {
	return ""
    } else {
	set temp1 [lindex $gDomains $ndx]
	set temp2 [lindex $temp1 1]
	return $temp2
    }
}
#
# check domain exists, return the index
# 
#
proc domainIndex { domainName } {
    global gDomains

    set ndx [lsearch -glob $gDomains $domainName*]

    if { $ndx >= 0 } {
	set limit [ llength $gDomains ]
	while { $ndx < $limit } {
	    # make sure it's an exact match
	    if { [lsearch  [lindex $gDomains $ndx ] $domainName] >= 0 } {
		break
	    }
	    set ndx [expr $ndx + 1]
	}
	if { $ndx == $limit } {
	    set ndx -1
	}
    }
    return $ndx

}
# use to match into a 1 level nested list
proc exactMatch { theList item  } {

    set ndx [lsearch -glob $theList $item*]

    if { $ndx >= 0 } {
	set limit [ llength $theList ]
	while { $ndx < $limit } {
	    # make sure it's an exact match
	    if { [lsearch  [lindex $theList $ndx ] $item] >= 0 } {
		break
	    }
	    set ndx [expr $ndx + 1]
	}
	if { $ndx == $limit } {
	    set ndx -1
	}
    }
    return $ndx

}

#
# Given a domain, return it's color
#
proc whatColorDomain {domainName} {
    global gDomains
    global gDomainColorMap
    global gDomainColors

    debug 2 "whatColorDomain:$domainName"

    set ndx [domainIndex $domainName ]
    if { $ndx < 0 } {
	return ""
    }

    set cindx 0
    foreach color $gDomainColorMap {
	if { $color == $ndx } {
	    break
	}
	set cindx [expr $cindx + 1]
    }
    set color [lindex $gDomainColors $cindx]

    return $color
}

#
# Given a domain and board, update the domain list.
#
proc updateDomain {domainName board option} {
    global gDomains

    debug 2 "updateDomain:$domainName $board $option"

    set ndx [domainIndex $domainName ]
    #set ndx [lsearch -glob $gDomains $domainName*]

    if {[string compare $option add] == 0} {
	if {$ndx < 0} {
	    set gDomains "$gDomains {$domainName {$board}}"
	} else {
	    set temp1 [lindex $gDomains $ndx]
	    set temp2 [lindex $temp1 1]
	    set temp3 "$temp2 $board"
	    set gDomains [lreplace $gDomains $ndx $ndx "$domainName {$temp3}"]
	}
    } else {
	if {$ndx >= 0} {
	    set temp1 [lindex $gDomains $ndx]
	    set temp2 [lindex $temp1 1]
	    set temp3 ""

	    foreach ndx2 $temp2 {
		if {[lsearch $board $ndx2] < 0} {
		    set temp3 "$temp3 $ndx2"
		} 
	    }
	    set gDomains [lreplace $gDomains $ndx $ndx "$domainName {$temp3}"]
	}
    }
}

#
# Given a board, return it's domain.
#
proc whatIsMyDomain {board} {
    global gBoards

    debug 2 "whatIsMyDomain:$board"

	# gBoard List, looks like {b0 domain power loaded}

	if { [string compare $board 1] == 0 } {
		set board "1 "
	}
    set ndx [lsearch -glob $gBoards $board*]

    if {$ndx < 0} {
	return ""
    } else {
	set temp1 [lindex $gBoards $ndx]
	set temp2 [lindex $temp1 1]
	return $temp2
    }
}

#
# determine what, if any, domain is selected
#
proc whatDomainSelected {} {
    global gBoards
    global gSelectedBoard

    debug 2 "whatDomainSelected:$gSelectedBoard"

	# gBoard List, looks like {0 domain power_on slot_loaded}

	if { [string compare $gSelectedBoard 1] == 0 } {
		set board "1 "
	} else {
		set board $gSelectedBoard
	}
	if {[string length $gSelectedBoard] < 1} {
		set ndx -1
	} else {
    		set ndx [lsearch -glob $gBoards $board*]
	}

    if {$ndx < 0} {
	return ""
    } else {
	set temp1 [lindex $gBoards $ndx]
	set temp2 [lindex $temp1 1]
	return $temp2
    }
}
#
# determine what, if any, domain is selected
# return domain, if exists, or SUNW_HOSTNAME
# 
#
proc domainOrCrayhostname {} {
	global env
	global gSelectedBoard
	set domain ""

    debug 2 "domainOrCrayhostname:$gSelectedBoard"

	set domain [ whatDomainSelected ]
	debug 1 "domain: $domain"
	if {[string length $domain] > 0} {
		return $domain
	} else {
		return $env(SUNW_HOSTNAME)
	}
}
#
# determine what, if any, domain is selected
# return domain, if exists, or no_domain
# 
#
proc getSelDom {} {
	global env
	global gSelectedBoard
	set domain ""

    debug 2 "getSelDom:$gSelectedBoard"

	set domain [ whatDomainSelected ]
	debug 1 "domain: $domain"
	if {[string length $domain] > 0} {
		return $domain
	} else {
		return "no_domain"
	}
}

#
# Given a board id, update the state.
#
proc updateBoardList {board state} {
    global gBoards

    debug 2 "updateBoardList:$board $state"

	if { [string compare $board 1] == 0 } {
		set match "1 "
	} else {
		set match $board
	}
    set ndx [lsearch -glob $gBoards $match*]
    
    if {$ndx < 0} {
	debug 5 "updateBoardList search failure for:$board"
    } else {
	set gBoards [lreplace $gBoards $ndx $ndx "$board $state"]
    }
}

#
# Given a board id, return the state.
#
proc whatBoardState {board} {
    global gBoards

    debug 2 "whatBoardState:$board"

	if { [string compare $board 1] == 0 } {
		set match "1 "
	} else {
		set match $board
	}
    set ndx [lsearch -glob $gBoards $match*]

    if {$ndx < 0} {
	debug 5 "whatBoardState search failure:$board"
	return empty
    }

    set result [lindex $gBoards $ndx]
    return $result
}

#
# Initialization for gBoards
#
proc setupBoardList {} {
    global gBoards

    global gCenterBoards
    global gFrontBoards
    global gBackBoards

    debug 1 "setupBoardList"

    foreach board $gCenterBoards {
	set gBoards "$gBoards {$board no_domain power_off slot_loaded}"
    }

    set config "no_domain power_off slot_empty jtag_off clock_off"
    foreach board $gFrontBoards {
	set gBoards "$gBoards {$board $config}"
    }

    foreach board $gBackBoards {
	set gBoards "$gBoards {$board $config}"
    }
}

#
# Given a processor id (00..63) update the signature (empty|os|obp|post|dhlp)
#   and state (color).
#
proc updateProcList {procId signature color} {
    global gProcessors

    debug 2 "updateProcList:$procId $signature $color"

    set ndx [lsearch -glob $gProcessors $procId*]
    
    if {$ndx < 0} {
	debug 5 "updateProcList search failure for:$procId"
    } else {
	set gProcessors [lreplace $gProcessors $ndx $ndx "$procId {$signature $color}"]
    }
}

#
# Given a processor id (00..63) return the signature (empty|os|obp|post|dhlp)
#   and color.
# actually it's the signiture and state.
#
proc whatProcState {procId} {
    global gProcessors

    debug 2 "whatProcState:$procId"

    set ndx [lsearch -glob $gProcessors $procId*]

    if {$ndx < 0} {
	debug 5 "whatProcState search failure:$procId"
	return empty
    }

    set result [lindex $gProcessors $ndx]
    return [lindex $result 1]
}

#
# Initialization for gProcessors
#
proc setupProcList {} {
    global gProcessors

    debug 1 "setupProcList"

    for {set ndx 0} {$ndx < 64} {incr ndx} {
	if {$ndx < 10} {
	    set gProcessors "$gProcessors {0$ndx {empty empty}}"
	} else {
	    set gProcessors "$gProcessors {$ndx {empty empty}}"
	}
    }
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)menuBar.tcl	1.19	99/10/26 SMI"
#
# Copyright (c) 1996-1999 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   Create and populate the menu bar on the main window of HostView.
#
# Entry:
#   bg1 = background color.
#
# Exit:
#   Nothing.
#

proc menuBar {bg1} {
    global gDebugThreshold
    global env

    #
    # File Command and Options
    #
    menubutton .menuBar.file -text File -menu .menuBar.file.m \
	    -underline 0 -bg $bg1 -activebackground $bg1

    menu .menuBar.file.m -bg $bg1 -activebackground $bg1 -tearoff 0

    .menuBar.file.m add command -label "SSP Logs" \
	    -command "genTextExec sspLog"
    .menuBar.file.m add command -label "Quit" \
	    -command topKill

    #
    # Edit Command and Options
    #
    menubutton .menuBar.edit -text Edit -menu .menuBar.edit.m \
	    -underline 0 -bg $bg1 -activebackground $bg1

    menu .menuBar.edit.m -bg $bg1 -activebackground $bg1 -tearoff 0

    .menuBar.edit.m add command -label "Properties" \
	    -command properties -state disabled
    .menuBar.edit.m add command -label "Blacklist File" \
	    -command blEditExec

    #
    # Control Command and Options
    #
    menubutton .menuBar.control -text Control -menu .menuBar.control.m \
	    -underline 0 -bg $bg1 -activebackground $bg1

    menu .menuBar.control.m -bg $bg1 -activebackground $bg1 -tearoff 0

    .menuBar.control.m add command -label "Power" \
	    -command "genTextExec power"
    .menuBar.control.m add command -label "Bringup" \
	    -command "genTextExec bringup"
    .menuBar.control.m add command -label "Fan" \
	    -command "genTextExec fan"

    #
    # Configuration Command and Options
    #
    menubutton .menuBar.configuration -text Configuration \
	    -menu .menuBar.configuration.m \
	    -underline 0 -bg $bg1 -activebackground $bg1

    menu .menuBar.configuration.m -bg $bg1 -activebackground $bg1 -tearoff 0

    .menuBar.configuration.m add cascade -label "Board" \
	    -menu .menuBar.configuration.m.board

    menu .menuBar.configuration.m.board -tearoff 0
    .menuBar.configuration.m.board add command -label "Attach" \
	    -command {drSelectionsPopDet attach } -background $bg1 -activebackground $bg1
    .menuBar.configuration.m.board add command -label "Detach" \
	    -command {drSelectionsPopDet detach } -background $bg1 -activebackground $bg1

    .menuBar.configuration.m add cascade -label "Domain" \
	    -menu .menuBar.configuration.m.domain

    menu .menuBar.configuration.m.domain -tearoff 0
    .menuBar.configuration.m.domain add command -label "Create" \
	    -command "genTextExec domainCreate" -background $bg1 -activebackground $bg1
    .menuBar.configuration.m.domain add command -label "Remove" \
	    -command "genTextExec domainRemove" -background $bg1 -activebackground $bg1
    .menuBar.configuration.m.domain add command -label "Rename" \
	    -command "genTextExec domainRename" -background $bg1 -activebackground $bg1
    .menuBar.configuration.m.domain add command -label "Status" \
	    -command "genTextExec domainStatus" -background $bg1 -activebackground $bg1
    .menuBar.configuration.m.domain add command -label "History" \
	    -command "genTextExec domainHistory" -background $bg1 -activebackground $bg1
    #
    # Terminal Command and Options
    #
    menubutton .menuBar.terminal -text Terminal -menu .menuBar.terminal.m \
	    -underline 0 -bg $bg1 -activebackground $bg1

    menu .menuBar.terminal.m -bg $bg1 -activebackground $bg1 -tearoff 0

    .menuBar.terminal.m add command -label "netcontool" \
	    -command netconExec
    .menuBar.terminal.m add cascade -label "Connect to SSP" \
	    -menu .menuBar.terminal.m.ssp

    menu .menuBar.terminal.m.ssp -tearoff 0

    # uname -n gives current host, but hostview could be client, so
    # will need to find out ssp host: .sspprivate/ssp_to_domain + get the host
    # or MIB: cbStarfireHostName?

    .menuBar.terminal.m.ssp add command -label "xterm" \
	    -command "exec xterm \
	    -T [exec uname -n] -n [exec uname -n] \
	    -e telnet [exec uname -n] &" -background $bg1 -activebackground $bg1
	    #-command "exec xterm -e telnet [exec uname -n] &" -underline 0
	    #-command "exec xterm -fn \'-misc-fixed-bold-r-normal--14-130-75-75-c-70-iso8859-1\' -e telnet [exec uname -n] &" -underline 0

    # dtterm terminal option - enable only if /usr/dt/bin/dtterm exists
    if { [ file exists /usr/dt/bin/dtterm ] } {
	set opt_state normal 
    } else {
	set opt_state disabled
    }
    .menuBar.terminal.m.ssp add command -label "dtterm" \
	    -state $opt_state \
	    -command "exec dtterm \
	    -title [exec uname -n] -n [exec uname -n] \
	    -e telnet [exec uname -n] &" \
	    -background $bg1 -activebackground $bg1 

    .menuBar.terminal.m.ssp add command -label "cmdtool" \
	    -command "exec cmdtool \
	    -title [exec uname -n] -icon_label [exec uname -n] \
	    telnet [exec uname -n] &" -background $bg1 -activebackground $bg1
    .menuBar.terminal.m.ssp add command -label "shelltool" \
	    -command "exec shelltool \
	    -title [exec uname -n] -icon_label [exec uname -n] \
	    telnet [exec uname -n] &" -background $bg1 -activebackground $bg1

    .menuBar.terminal.m add cascade -label "Connect to Domain" \
	    -menu .menuBar.terminal.m.telnet
    menu .menuBar.terminal.m.telnet -tearoff 0

    .menuBar.terminal.m.telnet add command -label "xterm" \
	    -command "telnetExec xterm" -background $bg1 -activebackground $bg1

    # dtterm terminal option - enable only if /usr/dt/bin/dtterm exists
    if { [ file exists /usr/dt/bin/dtterm ] } {
	set opt_state normal 
    } else {
	set opt_state disabled
    }
    .menuBar.terminal.m.telnet add command -label "dtterm" \
	    -state $opt_state \
	    -command "telnetExec dtterm" \
	    -background $bg1 -activebackground $bg1 

    .menuBar.terminal.m.telnet add command -label "cmdtool" \
	    -command "telnetExec cmdtool" -background $bg1 -activebackground $bg1
    .menuBar.terminal.m.telnet add command -label "shelltool" \
	    -command "telnetExec shelltool" -background $bg1 -activebackground $bg1


    if { $gDebugThreshold  < 4 } {
	.menuBar.terminal.m add cascade -label "test" \
	    -menu .menuBar.terminal.m.test
	menu .menuBar.terminal.m.test -tearoff 0

	.menuBar.terminal.m.test add command -label "lists" \
	    -command diag_script -underline 0

    }


    #
    # View Command and Options
    #
    menubutton .menuBar.view -text View -menu .menuBar.view.m \
	    -underline 0 -bg $bg1 -activebackground $bg1

    menu .menuBar.view.m -bg $bg1 -activebackground $bg1 -tearoff 0

    .menuBar.view.m add command -label "All Domains" \
	    -command "setDomainView all"

    #
    # Failure Event Command and Options
    #
    menubutton .menuBar.failure -text Failure -menu .menuBar.failure.m \
	    -underline 0 -bg $bg1 -activebackground $bg1

	#don't use this anymore, use failure icon
    menu .menuBar.failure.m -bg $bg1 -activebackground $bg1 -tearoff 0

    .menuBar.failure.m add command -label "power supply" \
	    -command buttonStub -underline 0
    .menuBar.failure.m add command -label "system board" \
	    -command buttonStub -underline 0
    .menuBar.failure.m add command -label "processor" \
	    -command buttonStub -underline 0
    .menuBar.failure.m add command -label "system fault" \
	    -command buttonStub -underline 0

    #
    # Help Command and Options
    #
    menubutton .menuBar.help -text Help -menu .menuBar.help.m \
	    -underline 0 -bg $bg1 -activebackground $bg1

    menu .menuBar.help.m -bg $bg1 -activebackground $bg1 -tearoff 0

    .menuBar.help.m add command -label "On Icon" \
	    -command "helpTextExec icon"
    .menuBar.help.m add command -label "On Menu" \
	    -command "helpTextExec menu"
    .menuBar.help.m add command -label "On Properties" \
	    -command "helpTextExec prop"
    .menuBar.help.m add command -label "On Power" \
	    -command "helpTextExec power"
    .menuBar.help.m add command -label "On DR" \
	    -command "helpTextExec dr"
    .menuBar.help.m add command -label "On Domains" \
	    -command "helpTextExec domains"
    .menuBar.help.m add command -label "On Bringup" \
	    -command "helpTextExec bringup"
    .menuBar.help.m add command -label "On Fan" \
	    -command "helpTextExec fan"
    .menuBar.help.m add command -label "On blacklist" \
	    -command "helpTextExec blacklist"
    .menuBar.help.m add command -label "On edit" \
	    -command "helpTextExec editmenu"

    #
    # Realize menuBar
    #
    pack .menuBar.file .menuBar.edit .menuBar.control .menuBar.configuration\
	    .menuBar.terminal .menuBar.view -side left 

	# pack .menuBar.file .menuBar.edit .menuBar.control \
		.menuBar.configuration\
	    .menuBar.terminal .menuBar.view .menuBar.failure  -side left 

    pack .menuBar.help -side right
}



proc BlMenuBar {bg1} {
    global env
    global gBg1
    global gFg1

    #
    # File Command and Options
    #
    menubutton .blMenuBar.file -text File -menu .blMenuBar.file.m \
	    -underline 0 -bg $bg1 -activebackground $bg1

    menu .blMenuBar.file.m -bg $bg1 -activebackground $bg1 -tearoff 0

    .blMenuBar.file.m add command -label "New" \
	-command newBlacklist

#    .blMenuBar.file.m add command -label "Open ..." \
#	-command "" -state disabled
    .blMenuBar.file.m add command -label "Save" \
	-command "appendblacklist" -state disabled
#    .blMenuBar.file.m add command -label "SaveAs ..." \
#	-command "" -state disabled
    .blMenuBar.file.m add command -label "Print" \
	-command "printBlacklist"  -state disabled
    .blMenuBar.file.m add command -label "Close" \
	    -command "closeBLgui"

    #
    # View Command and Options
    #
    menubutton .blMenuBar.view -text View -menu .blMenuBar.view.m \
	    -underline 0 -bg $bg1 -activebackground $bg1

    menu .blMenuBar.view.m -bg $bg1 -activebackground $bg1 -tearoff 0

    .blMenuBar.view.m add command -label "Boards" \
	    -command "blklistGraphic boardView $gBg1 $gFg1"
    .blMenuBar.view.m add command -label "Processors" \
	    -command "blklistGraphic procView $gBg1 $gFg1"
#    .blMenuBar.view.m add cascade -label "Detail Board" \
#	-menu .blMenuBar.view.m.detailBoard

#    menu .blMenuBar.view.m.detailBoard -tearoff 0

#    .blMenuBar.view.m.detailBoard add command -label "0" \
#	    -command ""  -state disabled
#    .blMenuBar.view.m.detailBoard add command -label "1" \
#	    -command "" -state disabled
#    .blMenuBar.view.m.detailBoard add command -label "2" \
#	    -command "" -state disabled
#    .blMenuBar.view.m.detailBoard add command -label "3" \
#	    -command "" -state disabled
#    .blMenuBar.view.m.detailBoard add command -label "4" \
#	    -command "" -state disabled
#    .blMenuBar.view.m.detailBoard add command -label "5" \
#	    -command "" -state disabled
#    .blMenuBar.view.m.detailBoard add command -label "6" \
#	    -command "" -state disabled
#    .blMenuBar.view.m.detailBoard add command -label "7" \
#	    -command "" -state disabled
#    .blMenuBar.view.m.detailBoard add command -label "8" \
#	    -command "" -state disabled
#    .blMenuBar.view.m.detailBoard add command -label "9" \
#	    -command "" -state disabled
#    .blMenuBar.view.m.detailBoard add command -label "10" \
#	    -command "" -state disabled
#    .blMenuBar.view.m.detailBoard add command -label "11" \
#	    -command "" -state disabled
#    .blMenuBar.view.m.detailBoard add command -label "12" \
#	    -command "" -state disabled
#    .blMenuBar.view.m.detailBoard add command -label "13" \
#	    -command "" -state disabled
#    .blMenuBar.view.m.detailBoard add command -label "14" \
#	    -command "" -state disabled
#    .blMenuBar.view.m.detailBoard add command -label "15" \
#	    -command "" -state disabled

    
    #
    # Help Command and Options
    #
    menubutton .blMenuBar.help -text Help -menu .blMenuBar.help.m \
	    -underline 0 -bg $bg1 -activebackground $bg1

    menu .blMenuBar.help.m -bg $bg1 -activebackground $bg1 -tearoff 0

    .blMenuBar.help.m add command -label "On Menu" \
	    -command "helpTextExec editmenu"
    .blMenuBar.help.m add command -label "On Blacklist" \
	    -command "helpTextExec blacklist"

    #
    # Realize blMenuBar
    #
    pack .blMenuBar.file .blMenuBar.view -side left 

    pack .blMenuBar.help -side right

}


#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)menuFcns.tcl	1.12	02/12/12 SMI"
#
# Copyright (c) 1996-1999 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#	execute menu bar telnets.
#	This is needed to evaluate the domain.
#
# Get the configuration for each domain
#
# see also
# 	menuBar
#
# proc telnetExec {flag}
# 	determine the domain, exec telnet

proc telnetExec {flag} {
    global gSelectedBoardList
    
    set cmd ""
    set dialog .domdlg

    set thehost [ getSelDom ]

    if { $thehost == "no_domain" || [ llength $gSelectedBoardList ] } {
	set result [hv_tk_dialog $dialog "Hostview Warning" \
		"One domain must be selected\n\tfor telnet." \
		warning 0 OK ]
	return
    }

# when domain is not a real host error:
# and the window comes up and hangs....
#ttysw_sigwinch, can't get tty process group: Inappropriate ioctl for device

    switch $flag {
	xterm { set cmd "exec xterm \
	    -T $thehost -n $thehost \
	    -e telnet $thehost &"}
	#xterm { set cmd "exec xterm -fn \'-misc-fixed-bold-r-normal--14-130-75-75-c-70-iso8859-1\' -e telnet $thehost &"}
	dtterm { set cmd "exec dtterm \
	    -title $thehost -n $thehost \
	    -e telnet $thehost &"}
	cmdtool { set cmd "exec cmdtool \
	    -title $thehost -icon_label $thehost \
	    telnet $thehost &"}
	shelltool { set cmd "exec shelltool \
	    -title $thehost -icon_label $thehost \
	    telnet $thehost &"}
    }
    debug 1 "cmd: $cmd"
    eval $cmd
}

# 
# This kills hostview and any proc with a process group the
# same as hostview's pid, ie, children.
#
proc topKill {} {
    set mypid [pid]

    debug 1 "topKill"
    
	if [catch {exec pgrep -P $mypid } pslist] {
	debug 10 $pslist
    }
    debug 1 "pslist: $pslist"

    # kill hostview last
    set thepids "$pslist $mypid"
    debug 1 "killing thepids: $thepids"

    foreach pid1 $thepids {
	if [catch {exec kill -TERM $pid1 } result] {
	    debug 10 $result
	}
    }
}


#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)mibRefresh.tcl	1.8	99/11/18 SMI"
#
# Copyright (c) 1996-1999 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#	Periodically read the Mib and refresh popup windows
#	which are present
#
# 
#


proc KillMelater {mypid } {
    global gPidMibFresh

    if ![info exists gPidMibFresh] {
	set gPidMibFresh $mypid
    }
    debug 1 "gPidMibFresh: $gPidMibFresh"
}
proc MIBfresh {} {
global gNewWin

    debug 1 "MIBfresh"

    set t 0
    set p 0
    set f 0
    set children [winfo children .]

    foreach child $children {
	if {[lsearch $child *hermal* ] > -1 } {
	    set t 1
	} elseif {[lsearch $child *ower* ] > -1 } {
	    set p 1
	} elseif {[lsearch $child *fanDetail* ] > -1 } {
	    set f 1
	} elseif {[lsearch $child *wFan* ] > -1 } {
	    set f 1
	}
    }
    if { $t } {
	set gNewWin 0
	hv_hostinfo -t
    }
    if { $p } {
	set gNewWin 0
	hv_hostinfo -p
    }
    if { $f} {
	set gNewWin 0
	hv_hostinfo -f
    }
    return
}

# refreshmib is exec-ed (via hostview_child)
# it loops forever, and invokes mibFresh periodically.
#
proc refreshMib { hostviewName pollfreq} {
    global gHvName
    debug 1 "refreshMib: $pollfreq  $hostviewName"

    if { [string first # $hostviewName] > -1 } {
	set gHvName [split $hostviewName #]
	set gHvName [lreplace $gHvName 1 1 #[lindex $gHvName 1]]
	debug 1 "gHvName $gHvName"
    } else {
	set gHvName $hostviewName
    }
    set mypid [pid]
    if { [ catch {send $gHvName KillMelater $mypid} errmsg ] } {
	debug 4 "Error: $errmsg"
    }

    while { 1 } {
	sleep $pollfreq
	sendMsg1
    }

}
proc sendMsg1 {} {
    global gHvName

    debug 1 "sendMsg1: $gHvName"
    #set retstatus [send $dest]

    if { [ catch {send $gHvName MIBfresh} errmsg ] } {
	debug 4 "Error: $errmsg"
    }
}

proc countDetails { flag } {
    global gSnapInst

    debug 1 "countDetails $flag"

    #don't read the mib if we are the failure snapshot
    if { [info exists gSnapInst] } {
	return 5
    }

    set t 0
    set p 0
    set f 0
    set children [winfo children .]

    foreach child $children {
	if {[lsearch $child *hermal* ] > -1 } {
	    incr t
	} elseif {[lsearch $child *ower* ] > -1 } {
	    incr p
	} elseif {[lsearch $child *fanDetail* ] > -1 } {
	    incr f
	} elseif {[lsearch $child *wFan* ] > -1 } {
	    incr f
	}
    }
    switch $flag {
	"power" { return $p }
	"thermal" { return $t }
	"fan" { return $f }
    }
}

proc countWin {} {

    set count 0

    set children [winfo children .]

    foreach child $children {
	if {[lsearch $child *hermal* ] > -1 } {
	    incr count
	} elseif {[lsearch $child *ower* ] > -1 } {
	    incr count
	} elseif {[lsearch $child *fanDetail* ] > -1 } {
	    incr count
	} elseif {[lsearch $child *wFan* ] > -1 } {
	    incr count
	}
    }
    debug 1 "count win: $count"
    return $count
}

# async read used by failure snapshot
#

proc readTempPwrFan { hostviewName tflag pflag fflag processorList tvthresh
			fileOffset } {
    global gFanList
    global gThermalList
    global gPowerList
    global gBulkPowerList
    global gHvName
    global gProcessors
    global gMAXsb_volt
    global gMINsb_volt
    global gMINsb_voltOff

    global gMAXcb_volt
    global gMINcb_volt
    global gMINcb_voltOff

    global gMAXcsb_volt
    global gMINcsb_volt
    global gMINcsb_voltOff

    global gWARNasic
    global gMAXasic
    global gT911asic
    global gWARNproc
    global gMAXproc
    global gT911proc
    global gWARNps
    global gMAXps
    global gT911ps
    global gWARNamb
    global gMAXamb
    global gT911amb
    
    global gVoltDefaultMAX
    global gVoltDefaultMIN


    debug 1 "readTempPwrFan: t: $tflag p: $pflag f: $fflag $hostviewName $processorList $tvthresh $fileOffset"

    set gProcessors $processorList
	eval $tvthresh
    set temp 0
    set pwr 0
    set fan 0


    if { $tflag == 0 } {
	set gNewWin 0
	hv_hostinfo -t
	set temp $gThermalList
    }


    if { $pflag == 0 } {
	set gNewWin 0
	hv_hostinfo -p
	set pwr [format "{%s} {%s}" $gPowerList $gBulkPowerList ]
    }


    if { $fflag == 0} {
	set gNewWin 0
	hv_hostinfo -f
	set fan $gFanList
    }


    if { [string first # $hostviewName] > -1 } {
	  set gHvName [split $hostviewName #]
	  set gHvName [lreplace $gHvName 1 1 #[lindex $gHvName 1] ]
		       debug 1 "gHvName $gHvName"
    } else {
	set gHvName $hostviewName
    }

    set args [format "{%s} {%s} {%s} {%s}" $temp $pwr $fan $fileOffset]
    if { [ catch {send $gHvName saveState_part2 $args } errmsg ] } {
	debug 4 "Error: $errmsg"
    }


    destroy .

}



#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)nameUtils.tcl	1.9	99/02/26 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   This file contains routines which assist in building widget strings.
#
# Boards:
#   proc whatBoard {arg} returns board ID from path
#   proc boardPath {arg} given board ID returns path
#
# Processors:
#   proc whatProc {arg} returns system board ID from processor ID.
#   proc procPath {arg} returns widget path to arg.
#   proc procList {board} returns list of processors on a system board.
#
# System Detail:
#   proc path2sd {arg} returns item name from path.
#   proc sd2path {arg} returns widget path to arg 
#

#
# Given a processor string, return the board id
# args is complete path to board, returns board in form b0, b1.
# args is complete path to board, returns board in form 0, 1.
#
proc whatBoard {arg} {
    debug 1 "whatBoard:$arg"

    set temp2 [split $arg .]

    set ndx1 [lsearch $temp2 power]

    if {$ndx1 >= 0} {
	incr ndx1
    } else {
	set ndx1 1
	while { 1 } {
	    if {[string compare cards [lindex $temp2 $ndx1]]} {
		incr ndx1
	    } else {
		incr ndx1
		if {[string compare special [lindex $temp2 $ndx1]]} {
		} else {
		    incr ndx1
		}
		break;
	    }
	}
    }
    return [lindex $temp2 $ndx1]
}

#
# Given a board name, return the associated path.
# arg has the form b0..b15
# arg has the form 0..15
#
proc boardPath {arg} {
    debug 1 "boardPath:$arg"

    set blw .blklistGraphic
    #set blw .blklistGraphic.box

    switch $arg {
	csb0 {return .systemGraphic.front.cards.csb0}
	csb1 {return .systemGraphic.back.cards.csb1}

	cb0 {return .systemGraphic.front.cards.cb0}
	cb1 {return .systemGraphic.back.cards.cb1}

	0  {return .systemGraphic.front.cards.0}
	1  {return .systemGraphic.front.cards.1}
	2  {return .systemGraphic.front.cards.2}
	3  {return .systemGraphic.front.cards.3}
	4  {return .systemGraphic.front.cards.4}
	5  {return .systemGraphic.front.cards.5}
	6  {return .systemGraphic.front.cards.6}
	7  {return .systemGraphic.front.cards.7}

	8  {return .systemGraphic.back.cards.8}
	9  {return .systemGraphic.back.cards.9}
	10 {return .systemGraphic.back.cards.10}
	11 {return .systemGraphic.back.cards.11}
	12 {return .systemGraphic.back.cards.12}
	13 {return .systemGraphic.back.cards.13}
	14 {return .systemGraphic.back.cards.14}
	15 {return .systemGraphic.back.cards.15}

	bl_csb0 {return $blw.front.cards.csb0}
	bl_csb1 {return $blw.back.cards.csb1}

	bl_cb0 {return $blw.front.cards.cb0}
	bl_cb1 {return $blw.back.cards.cb1}

	bl_0  {return $blw.front.cards.0}
	bl_1  {return $blw.front.cards.1}
	bl_2  {return $blw.front.cards.2}
	bl_3  {return $blw.front.cards.3}
	bl_4  {return $blw.front.cards.4}
	bl_5  {return $blw.front.cards.5}
	bl_6  {return $blw.front.cards.6}
	bl_7  {return $blw.front.cards.7}

	bl_8  {return $blw.back.cards.8}
	bl_9  {return $blw.back.cards.9}
	bl_10 {return $blw.back.cards.10}
	bl_11 {return $blw.back.cards.11}
	bl_12 {return $blw.back.cards.12}
	bl_13 {return $blw.back.cards.13}
	bl_14 {return $blw.back.cards.14}
	bl_15 {return $blw.back.cards.15}

	default {debug 5 "==>SWITCH DEFAULT in boardPath:$arg"}
    }
}

#
# Given a processor id, return the associated system board.
# arg has the form 0..63, returns b0..b15
# arg has the form 0..63, returns 0..15
#
proc whatProc {arg} {
    debug 1 "whatProc:$arg"

    # Leading zero is a problem...
    set temp2 [string trimleft $arg 0]
    if {[string length $temp2] < 1} {
	set temp2 0
    } 

    set temp1 [expr $temp2/4]
    return "$temp1"
    #return "b$temp1"
}

#
# Given a processor id, return the associated path.
# arg has the form 0..63
#
proc procPath {arg} {
    debug 1 "procPath:$arg"

    set board [whatProc $arg]
    set temp1 [boardPath $board]

    if {$arg < 10} {
	set cell "0$arg"
    } else {
	set cell $arg
    }

    return "$temp1.select.domain.board.$cell"
}

#
# Given a board, return a list of processor cells.
# List is arranged as "top down" respective to the GUI.
# board = board ID in the form b0..b15
# board = board ID in the form 0..15
#
proc procList {board} {
    global gFrontSysBoards

    debug 1 "procList:$board"

    set temp1 [string trim $board bl_]
    set temp1 [string trim $temp1 b]

#    debug 1 "I know this is card:$temp1"

    set retarg {}

    if {[lsearch $gFrontSysBoards $board] < 0} {
	set cell_limit [expr (1+$temp1)*4]

	for {set cell [expr $temp1*4]} {$cell < $cell_limit} {incr cell} {
	    set retarg [concat $retarg $cell]
	}
    } else {
	set cell_limit [expr $temp1*4]
	incr temp1

	for {set cell [expr $temp1*4-1]} {$cell >=$cell_limit} {incr cell -1} {
	    if {$cell < 10} {
		set retarg [concat $retarg 0$cell]
	    } else {
		set retarg [concat $retarg $cell]
	    }
	}
    }
    debug 1 "retarg:$retarg"
    return $retarg
}

#
# Return the object identifier from a systemDetail path.
#
proc path2sd {arg} {
    global gBackBoards
    global gFrontBoards

    global gBulkPower
    global gFanDrawers

    debug 1 "path2sd:$arg"

    set temp1 [split $arg .]

    foreach ndx1 $temp1 {
	if {[string compare ctr $ndx1] == 0} {
	    return ctr
	} else {
	    set ndx2 [lsearch $gFrontBoards $ndx1]
	    if {$ndx2 >= 0} {
		return $ndx1
	    }
	    set ndx2 [lsearch $gBackBoards $ndx1]
	    if {$ndx2 >= 0} {
		return $ndx1
	    }
	    set ndx2 [lsearch $gFanDrawers $ndx1]
	    if {$ndx2 >= 0} {
		return $ndx1
	    }
	    set ndx2 [lsearch $gBulkPower $ndx1]
	    if {$ndx2 >= 0} {
		return $ndx1
	    }
	}
    }
    debug 5 "path2sd unknown item:$arg"
}

#
# Given a object name return a path usefile for the systemDetail template.
#
proc sd2path {arg} {
    debug 1 "sd2path:$arg"

    switch $arg {
	ctr {return .canvas.sub2.center.bottom.cards.ctr}

	bp0 {return .canvas.sub2.front.top.power.bp0}
	bp1 {return .canvas.sub2.front.top.power.bp1}
	bp2 {return .canvas.sub2.front.top.power.bp2}
	bp3 {return .canvas.sub2.front.top.power.bp3}
	bp4 {return .canvas.sub2.back.top.power.bp4}
	bp5 {return .canvas.sub2.back.top.power.bp5}
	bp6 {return .canvas.sub2.back.top.power.bp6}
	bp7 {return .canvas.sub2.back.top.power.bp7}
	bp8 {return .canvas.sub2.front.top.eveready.bp8}
	bp9 {return .canvas.sub2.front.top.eveready.bp9}
	bp10 {return .canvas.sub2.front.top.eveready.bp10}
	bp11 {return .canvas.sub2.front.top.eveready.bp11}
	bp12 {return .canvas.sub2.back.top.eveready.bp12}
	bp13 {return .canvas.sub2.back.top.eveready.bp13}
	bp14 {return .canvas.sub2.back.top.eveready.bp14}
	bp15 {return .canvas.sub2.back.top.eveready.bp15}

	csb0 {return .canvas.sub2.front.bottom.cards.special.csb0}
	cb0 {return .canvas.sub2.front.bottom.cards.special.cb0}

	csb1 {return .canvas.sub2.back.bottom.cards.special.csb1}
	cb1 {return .canvas.sub2.back.bottom.cards.special.cb1}

	0  {return .canvas.sub2.front.bottom.cards.0}
	1  {return .canvas.sub2.front.bottom.cards.1}
	2  {return .canvas.sub2.front.bottom.cards.2}
	3  {return .canvas.sub2.front.bottom.cards.3}
	4  {return .canvas.sub2.front.bottom.cards.4}
	5  {return .canvas.sub2.front.bottom.cards.5}
	6  {return .canvas.sub2.front.bottom.cards.6}
	7  {return .canvas.sub2.front.bottom.cards.7}

	8  {return .canvas.sub2.back.bottom.cards.8}
	9  {return .canvas.sub2.back.bottom.cards.9}
	10 {return .canvas.sub2.back.bottom.cards.10}
	11 {return .canvas.sub2.back.bottom.cards.11}
	12 {return .canvas.sub2.back.bottom.cards.12}
	13 {return .canvas.sub2.back.bottom.cards.13}
	14 {return .canvas.sub2.back.bottom.cards.14}
	15 {return .canvas.sub2.back.bottom.cards.15}

	ft0  {return .canvas.sub2.front.bottom.topfan.ft0}
	ft1  {return .canvas.sub2.front.bottom.topfan.ft1}
	ft2  {return .canvas.sub2.front.bottom.topfan.ft2}
	ft3  {return .canvas.sub2.front.bottom.topfan.ft3}
	ft4  {return .canvas.sub2.front.bottom.botfan.ft4}
	ft5  {return .canvas.sub2.front.bottom.botfan.ft5}
	ft6  {return .canvas.sub2.front.bottom.botfan.ft6}
	ft7  {return .canvas.sub2.front.bottom.botfan.ft7}

	ft8  {return .canvas.sub2.back.bottom.topfan.ft8}
	ft9  {return .canvas.sub2.back.bottom.topfan.ft9}
	ft10 {return .canvas.sub2.back.bottom.topfan.ft10}
	ft11 {return .canvas.sub2.back.bottom.topfan.ft11}
	ft12 {return .canvas.sub2.back.bottom.botfan.ft12}
	ft13 {return .canvas.sub2.back.bottom.botfan.ft13}
	ft14 {return .canvas.sub2.back.bottom.botfan.ft14}
	ft15 {return .canvas.sub2.back.bottom.botfan.ft15}

	default {debug 5 "==>SWITCH DEFAULT in sd2path:$arg"}
    }
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)populateCanvas.tcl	1.41	00/10/24 SMI"
#
# Copyright (c) 1996-2000 by Sun Microsystems, Inc.
# All rights reserved.
#
# populateCanvas ( calls hv_hostinfo )
#
# Description:
#	hv_hostinfo is a Xfire-SSP command that provides an interface
#	to fetch certain host relevant data from
#	the snmpd daemon.
#
#
# Usage:
#
#	hv_hostinfo [-fhpSt]
#
#	[-h] - report state and signature of each configured processor.
#	[-S] - interpret and report the content of the signature
#	       block for each processor.
#	[-t] - report temperature (in Centigrades) of the physical
#	       host, control boards, and system boards.
#	[-n] - report host name
#
#	[-f] - report fan configuration and status.
#	[-p] - report power supply presence on all system boards, control
#	       board, centerplane, IO cabinet, and Fan trays.
#

#
# Global MIB member definitions:
# same name space as trapAction.tcl
#

# System Board and Control Board Lists
set SYS_BRD_LST "confSysBrdList.0"
set CTRL_BRD_LST "confConBrdList.0"
set SUPP_BRD_LST "confSuppBrdList.0"
set CENT_PLANE_LST "confCenterplaneList.0"

set NDOM "confNumDomain.0"
set DOMAIN_LST "domainName domainSysBrdList"

set BULK_POWER_LST "confBulkPowerList.0"
set FAN_TRAY_LST "confFanTrayList.0"

set DEFAULT_BUS "abus2 abus3 dbus1 dbus0 abus1 abus0"

#cb clock or jtag (master has jtag clock)
set CB_MASTER "platformMasterConBrd.0"
set CB_CLOCK "platformSysClkConBrd.0"

#fix, walk table, .0 may be inactive domain
set DOM_ABUS_LST "domainABusConfig"
set DOM_DBUS_LST "domainDBusConfig"
set DOM_PROC_CONF "domainProcConfig"
set DOM_BOOT_PROC "domainBootProc"
#set DOM_ADBUS_LST "domainIndex domainABusConfig domainDBusConfig"

set PROC_SIG_STATE "procStateGenIndex procStateGenNum procStateGenPgmSignature procStateGenPgmState"

# Fan configuration and status.
set FAN_TRAY_TABLE "fanTrayGenIndex fanGenIndex fanGenStatus fanGenSpeed"
set FAN_GEN_TABLE "fanGenTraySlotNum fanGenNum fanGenStatus fanGenSpeed"

# Power Supply
set PWR_SYS_BRD confNumSysBrdPower.0
set PWR_SYS_BRD_LST confSysBrdPowerList.0
set PWR_SYS_BRD_TABLE "sysBrdGenNum sysBrdGenPower"
set PWR_CB_BRD_TABLE "cbGenNum cbGenPower"
set PWR_CSB_BRD_TABLE "suppBrdGenNum suppBrdGenPower"

set PWR_IO_CAB_TABLE "ioCabGenIndex ioCabGenPower"
set PWR_FAN_TRAY_TABLE "fanTrayGenNum fanTrayGenPower"
set PWR_BULKPOWER_TABLE "bulkPowerGenNum bulkPowerGenStatus"
set PWR_SF_SB_TABLE "sysBrdStarfireNum sysBrdStarfire3p3VDC sysBrdStarfire5VDCHK sysBrdStarfire5VDC sysBrdStarfireVDCCore sysBrdStarfire3p3VDCHK"

set PWR_SF_CB_TABLE "cbStarfireNum cbStarfire5VDC cbStarfire5VDCHK cbStarfire3p3VDCHK cbStarfire5VDCPer cbStarfire5VDCFan"

set PWR_SF_CSB_TABLE "suppBrdStarfireNum suppBrdStarfire3p3VDC suppBrdStarfire5VDCHK suppBrdStarfire3p3VDCHK"



# Temperature
set HOST_AMB_TMP platformAmbientTemp.0
set HOST_NAME platformName.0
#set TMP_PROC_TABLE "procStateGenNum procStateGenTemp"
set TMP_CTRPLANE_TABLE "centerplaneGenNum centerplaneGenTemp"
set TMP_SF_SB_TABLE "sysBrdStarfireNum sysBrdStarfireCIC0Temp sysBrdStarfireCIC1Temp sysBrdStarfireMCTemp sysBrdStarfireXDB2Temp sysBrdStarfireXDB3Temp sysBrdStarfirePROC0Temp sysBrdStarfirePROC1Temp sysBrdStarfirePROC2Temp sysBrdStarfirePROC3Temp sysBrdStarfire3p3VDCTemp sysBrdStarfire5VDCTemp sysBrdStarfireVDCCoreTemp"


set TMP_SF_CB_TABLE "cbStarfireNum cbStarfire5VDCTemp cbStarfire5VDCPerTemp cbStarfire5VDCFanTemp cbStarfireSen0Temp cbStarfireSen1Temp cbStarfireSen2Temp"

set TMP_SF_CSB_TABLE "suppBrdStarfireNum suppBrdStarfire3p3VDC1Temp suppBrdStarfire3p3VDC2Temp"

set TMP_SF_CP_TABLE "centerplaneStarfireNum centerplaneStarfireTemp0 centerplaneStarfireTemp1 centerplaneStarfireTemp2 centerplaneStarfireTemp3 centerplaneStarfireTemp4 centerplaneStarfireTemp5 centerplaneStarfireTemp6 centerplaneStarfireTemp7 centerplaneStarfireTemp8 centerplaneStarfireTemp9"


#
# hv_hostinfo command:
#
proc hv_hostinfo args {
    global env
    global gMibTouched
    global gMainCursor
    global gNewWin
    
    set cray_env "SUNW_HOSTNAME SSPETC SSPVAR"
    set MIB   "Ultra-Enterprise-10000.mib"
    set valid_args "-htSnpfbB"
    set usage "usage: hv_hostinfo \[-hStnpf\]\n \
	    \t\[-h\] - report state and signature of each configured processor.\n \
	    \t\[-t\] - report temperature of the physical host, control boards, and system boards.\n \
	    \t\[-S\] - report the content of the signature block for each processor.\n \
	    \t\[-n\] - report the platform name \n\
	    \t\[-p\] - report the voltage levels of all boards, stat of bulkpower. \n\
	    \t\[-f\] - report the state and speed of fans.\n"

    #
    # Check command line arguments
    #
    if { [ catch {CLA_Parse Args $args $valid_args} errmsg ] } {
	debug 10 "Error: $errmsg"
	debug 10 $usage
	debug 10 $args
	return
    }
    #
    # Check SSP environment variables
    #
    foreach var $cray_env {
	if { ![info exists env($var)] } {
	    error "hv_hostinfo: Environment variable '$var' must be set."
	}
    }

    set gMainCursor [. cget -cursor]
    debug 1 ".cursor: $gMainCursor"
    if [winfo exists .systemGraphic ] {
	set gMainCursor [.systemGraphic cget -cursor]
    }
    debug 1 $gMainCursor
    ##. config -cursor watch
    ##.systemGraphic config -cursor watch
    #
    # Load Xfire MIB into scotty's MIB database
    #
    if { ![file exists $env(SSPETC)/snmp/$MIB] } {
	error "hv_hostinfo: $env(SSPETC)/snmp/$MIB does not exist"
    }
    # only load mib once
    #proc static from scotty

    if { 0 } {
	static ( mib_firsttime )
	if { ![info exists mib_firsttime] } {
	    debug 1 "mib load $env(SSPETC)/snmp/$MIB"
	    mib load $env(SSPETC)/snmp/$MIB
	    set mib_firsttime 0
	}
    }
    #
    # Get a SNMP session handle to talk to the snmpd
    # by not setting community, would be read only session.
    #
    if { [ catch {set handle [ snmp session -community hostview ]} errmsg ] } {
	debug 10 "Error: $errmsg"
	if { [info exists mib_firsttime] } {
	    unset mib_firsttime
	}
	###. config -cursor $gMainCursor
	###.systemGraphic config -cursor $gMainCursor 
	return ""
    }

    $handle configure -timeout 100 -retries 1

    set gMibTouched 1
    set dialog .mibdialog

    #
    # Query the host information according to the command line arguments
    #
    if { [info exists Args(f)] } {
	if [winfo exists .iconBar ] {
	    .iconBar config -cursor watch
	    update idletasks
	}
	if { 0 } {
	    if [winfo exists .wFan] {
		.wFan config -cursor watch
	    }
	}
	#.systemGraphic config -cursor watch
	#.menuBar config -cursor watch
	if { $gNewWin } {
	    set result [hv_tk_dialog $dialog "Hostview Working" \
			    "Reading platform environment." \
			    hourglass 0 ]
	    if {[catch [ tkwait visibility $dialog ] result] } {
		debug 4 $result
	    }
	    update idletasks
	}
	#update idletasks
	
	hv_report_fan_info handle
	
	if { 1 } {
	    if [winfo exists $dialog] {
		destroy $dialog
	    }
	}
	if [winfo exists .iconBar ] {
	    .iconBar config -cursor arrow
	}
	if { 0 } {
	if [winfo exists .wFan.canvas] {
	    set curs [.wFan.canvas cget -cursor]
	    if { [string compare $curs "watch"] == 0 } {
		.wFan.canvas config -cursor arrow
	    }
	}
	}
	#.systemGraphic config -cursor arrow
	#.menuBar config -cursor arrow
    }

    if { [info exists Args(h)] } {
	if [winfo exists .iconBar ] {
	    .iconBar config -cursor watch
	}
	# changing the canvas cursor makes the screen jump and flash
	#.systemGraphic config -cursor watch
	if [winfo exists .menuBar ] {
	    .menuBar config -cursor watch
	}

	hv_report_state_info handle

	# dialog started in hvTail
	if [winfo exists $dialog] {
	    destroy $dialog
	}
	    
	if [winfo exists .iconBar ] {
	    .iconBar config -cursor arrow
	}
	#.systemGraphic config -cursor arrow
	if [winfo exists .menuBar ] {
	    .menuBar config -cursor arrow
	}
    }

    if { [info exists Args(p)] } {
	if [winfo exists .iconBar ] {
	    .iconBar config -cursor watch
	}
	if { $gNewWin } {
	    set result [hv_tk_dialog $dialog "Hostview Working" \
			    "Reading platform environment." \
			    hourglass 0 ]
	    if {[catch [ tkwait visibility $dialog] result] } {
		debug 4 $result
	    }
	    update idletasks
	}
	
	#update idletasks

	hv_report_power handle

	if [winfo exists .iconBar ] {
	    .iconBar config -cursor arrow
	}

	if { 1 } {
	    if [winfo exists $dialog] {
		destroy $dialog
	    }
	}
	if { 0 } {
	if [winfo exists .wPower.canvas] {
	    set curs [.wPower.canvas cget -cursor]
	    if { [string compare $curs "watch"] == 0 } {
		.wPower.canvas config -cursor arrow
	    }
	}
	}
    }

    if { [info exists Args(t)] } {
	if [winfo exists .iconBar ] {
	    .iconBar config -cursor watch
	}

	# this works to put the watch just on the buttons
	# and it makes a nice transition from the watch cursor.
	# if the watch cursor is on the whole canvas, it redraws (ugly).

	#.wThermal.canvas.sub2.front.bottom.cards.special.csb0 config -cursor watch
	
	if { $gNewWin } {
	    set result [hv_tk_dialog $dialog "Hostview Working" \
			    "Reading platform environment." \
			    hourglass 0 ]
	    if {[catch [ tkwait visibility $dialog ] result] } {
		debug 4 $result
	    }
	    update idletasks
	}
	
	#update idletasks

	hv_report_temperature handle
	
	if [winfo exists .iconBar ] {	
	    .iconBar config -cursor arrow
	}

	if { 1 } {
	    if [winfo exists $dialog] {
		destroy $dialog
	    }
	}
	
	if { 0 } {
	if [winfo exists .wThermal.canvas] {
	    set curs [.wThermal.canvas cget -cursor]
	    if { [string compare $curs "watch"] == 0 } {
		.wThermal.canvas config -cursor arrow
		#.wThermal.canvas.sub2.front.bottom.cards.special.csb0 config -cursor arrow
	    }
	}
	}
    }

    if { [info exists Args(b)] } {
	if [winfo exists .iconBar ] {
	    .iconBar config -cursor watch
	}

	updatebus $handle

	if [winfo exists .iconBar ] {
	    .iconBar config -cursor arrow
	}

    }

    if { [info exists Args(B)] } {
	hv_blprocs $handle

    }


    if { [info exists Args(n)] } {
	return [ eval hv_report_hostname handle]
    }

    if { [info exists Args(s)] || [info exists Args(S)] } {
	hv_report_sigb handle
    }

    $handle destroy
    ###. config -cursor $gMainCursor
    ###.systemGraphic config -cursor $gMainCursor 
}


#
# hv_hostinfo -h
#
#	detect system boards, control boards and support boards.
#	Report processor's signature and state.
#
proc hv_report_state_info { snmp_handle } {
    upvar $snmp_handle handler
    
    global SYS_BRD_LST
    global CTRL_BRD_LST
    global SUPP_BRD_LST
    global CENT_PLANE_LST
    global BULK_POWER_LST
    global FAN_TRAY_LST
    global PROC_SIG_STATE
    global DEFAULT_BUS
    global DOM_ABUS_LST
    global DOM_DBUS_LST
    global DOM_PROC_CONF
    global DOM_BOOT_PROC
    global DOMAIN_LST
    global NDOM
    global sig
    global state
    global PWR_SYS_BRD
    global PWR_SYS_BRD_LST
    global PWR_SYS_BRD_TABLE
    global PWR_CB_BRD_TABLE
    global PWR_CSB_BRD_TABLE
    global CB_MASTER
    global CB_CLOCK
    global CB_JTAG
    
    #
    # Query snmpd for System Board list and each processor's state
    # and signature. Display output to stdout.
    #
    
    set dinfo ""
    if { [ catch {set dinfo [ $handler get $SYS_BRD_LST ]} errmsg ] } {
	debug 10 "Error: $errmsg"
    }
    set brds [ split [lindex [lindex $dinfo 0] 2] - ]
    
    foreach board $brds {
	debug 5 $board
	boardDiscovered $board
    }
    #
    set cbinfo ""
    if { [ catch {set cbinfo [ $handler get $CTRL_BRD_LST ]} errmsg ] } {
	debug 10 "Error: $errmsg"
    }
    set cbrds [ split [lindex [lindex $cbinfo 0] 2] - ]
    
    set sbinfo ""
    if { [ catch {set sbinfo [ $handler get $SUPP_BRD_LST ]} errmsg ] } {
	debug 10 "Error: $errmsg"
    }
    set sbrds [ split [lindex [lindex $sbinfo 0] 2] - ]
    
    set cpinfo ""
    if { [ catch {set cpinfo [ $handler get $CENT_PLANE_LST ]} errmsg ] } {
	debug 10 "Error: $errmsg"
    }
    set cplane [ split [lindex [lindex $cpinfo 0] 2] - ]
    if { 0 }  {
	set bpinfo ""
	if { [ catch {set bpinfo [ $handler get $BULK_POWER_LST ]} errmsg ] } {
	    debug 10 "Error: $errmsg"
	}
	set bps [ split [lindex [lindex $bpinfo 0] 2] - ]
    
	foreach bp $bps {
	    updateBPconf bp$bp add
	}

	set faninfo ""
	if { [ catch {set faninfo [ $handler get $FAN_TRAY_LST ]} errmsg ] } {
	    debug 10 "Error: $errmsg"
	}
	set fans [ split [lindex [lindex $faninfo 0] 2] - ]
    
	foreach fan $fans {
	    updateFanconf ft$fan add
	}
    }
    
    debug 5 ""
    debug 5 "System Boards:  $brds"
    debug 5 "control Boards:  $cbrds\n"
    debug 5 "Support Boards:  $sbrds\n"
    debug 5 "center plane:  $cplane\n"
    #debug 5 "bulkpower:  $bps\n"
    #debug 5 "fans:  $fans\n"
    foreach board $cbrds {
	boardDiscovered cb$board
    }
    foreach board $sbrds {
	boardDiscovered csb$board
    }
    

    # Query for system board's power (either on or off)
    debug 5 "Board       Status"
    debug 5 "------------------"
    if { [ catch {$handler walk x "$PWR_SYS_BRD_TABLE" {
	set board [ lindex [lindex $x 0] 2]
	set state [lindex [lindex $x 1] 2]
	debug 5 [format "%2d      %s" \
		[lindex [lindex $x 0] 2] [lindex [lindex $x 1] 2]]
	
	if { [string compare $state on] == 0 } {
	    boardPowerUp $board
	}
}   } errmsg ] } {
	debug 10 "Error: $errmsg"
    }
    debug 5 ""
 
    # Query for control board's power (either on or off)
    debug 5 "cb Board       Status"
    debug 5 "---------------------"
    if { [ catch {$handler walk x "$PWR_CB_BRD_TABLE" {
	set board [ lindex [lindex $x 0] 2]
	set state [lindex [lindex $x 1] 2]
	debug 5 [format "%2d      %s" \
		[lindex [lindex $x 0] 2] [lindex [lindex $x 1] 2]]
	
	if { [string compare $state on] == 0 } {
	    boardPowerUp cb$board
	}
}   } errmsg ] } {
	debug 10 "Error: $errmsg"
    }
    debug 5 ""
 
    # Query for csb board's power (either on or off)
    debug 5 "csb Board       Status"
    debug 5 "---------------------"
    if { [ catch {$handler walk x "$PWR_CSB_BRD_TABLE" {
	set board [ lindex [lindex $x 0] 2]
	set state [lindex [lindex $x 1] 2]
	debug 5 [format "%2d      %s" \
		[lindex [lindex $x 0] 2] [lindex [lindex $x 1] 2]]
	
	if { [string compare $state on] == 0 } {
	    boardPowerUp csb$board
	}
}   } errmsg ] } {
	debug 10 "Error: $errmsg"
    }
    debug 5 ""
 

       
    debug 5 ""
    debug 5 "Board   Processor   Program   State"
    debug 5 "-----------------------------------"
    
    if { [ catch {$handler walk x "$PROC_SIG_STATE" {
	set proc [lindex [lindex $x 1] 2]
	set brd [ expr $proc / 4 ]
	set sig [lindex [lindex $x 2] 2]
	set ste [lindex [lindex $x 3] 2]
	debug 5 [format "%3d    %4d       %-9s%-s" \
		$brd $proc $sig $ste ]
	

	# make sure the board is powered, or this could be anomalous
	set state [whatBoardState $brd]
	if { [lsearch $state power_on] > -1 } {
	    if {$proc < 10 } {
		setProcIcon 0$proc $sig $ste
	    } else {
		setProcIcon $proc $sig $ste
	    }
	}
	debug 5 ""

    #above walk is inside a "catch"	
}   } errmsg ] } {
    debug 10 "Error: $errmsg"
}



    if { 0 } {
	#foreach board $cplane
	# hostview doesn't really have this notion.....
	# centerplane config is domain based.
	if  { [string compare $cplane ""] != 0} {
	    boardPowerUp ctr
	}
    }



    # Query for domains
    debug 5 "domain name       boards"
    debug 5 "------------------------"
    if { [ catch {$handler walk x "$DOMAIN_LST" {
	set domainName [ lindex [lindex $x 0] 2]
	set boardlist [ split [lindex [lindex $x 1] 2] - ]
	debug 5 [format "%s     %s" \
		[lindex [lindex $x 0] 2] [lindex [lindex $x 1] 2]]
	debug 5 "$boardlist"

	foreach board $boardlist {
	    setDomain $board $domainName
	}

}   } errmsg ] } {
	debug 10 "Error: $errmsg"
    }
    debug 5 ""




    
    set domInfo ""
   
    if { [ catch {  $handler get $NDOM } domInfo ] } {
	debug 10 "Error: $domInfo"
    }
    set dom_cnt 0
    set dom_cnt [lindex [lindex $domInfo 0] 2]
    debug 5 "domain count: $dom_cnt\n"

    set donebus 0
    for { set k 0 } { $k < $dom_cnt } { incr k} {

	if {[ catch {set bpinfo [ $handler get $DOM_BOOT_PROC.$k ]} errmsg ]} {
	    debug 10 "Error: $errmsg"
	}
	set bootproc [lindex [lindex $bpinfo 0] 2]
	debug 5 "boot proc:  $bootproc"
	set board [expr $bootproc / 4]
	set proc [expr $bootproc % 4]
	set bp $board.$proc
	debug 5 "boot proc:  $bp"

	if {[ catch {set bppinfo [ $handler get $DOM_PROC_CONF.$k ]} errmsg ]} {
	    debug 10 "Error: $errmsg"
	}
	set procconfig [ split [lindex [lindex $bppinfo 0] 2] - ]
	debug 5 "proc config:  $procconfig"

	# now look for blacklisted procs
	checkBLprocs $procconfig
	
	if { $donebus == 0 } {
	    set ndx [lsearch $procconfig $bp*]
	    debug 5 "ndx: $ndx"

	    # if the proc config of the boot proc has a G in it
	    # the domain is up, use it!
	    if { [string first G [lindex $procconfig $ndx] ] > -1 } {
		# grab the bus config from the first active domain, applies to all.
		#these have status attached (p118) ie: 3G  ABUS3 is good
		# need to strip off....
		# If no domain is booted, use the full configuration

		set abinfo ""
		if {[ catch {set abinfo [ $handler get $DOM_ABUS_LST.$k ]} errmsg ]} {
		    debug 10 "Error: $errmsg"
		}
		set abrds [ split [lindex [lindex $abinfo 0] 2] - ]
		debug 5 "ABUS Bus:  $abrds"
	
		foreach buss $abrds {
		    set busstat [string index $buss 1]
		    if { [string compare $busstat "G"] == 0 } {
			set busnum [string index $buss 0]
			greenBus abus$busnum
		    }
		}
	
		set dbinfo ""
		if { [ catch {set dbinfo [ $handler get $DOM_DBUS_LST.$k ]} errmsg]} {
		    debug 10 "Error: $errmsg"
		}
		set dbrds [ split [lindex [lindex $dbinfo 0] 2] - ]
		debug 5 "DBUS Bus:  $dbrds"
	
		foreach buss $dbrds {
		    set busstat [string index $buss 1]
		    if { [string compare $busstat "G"] == 0 } {
			set busnum [string index $buss 0]
			greenBus dbus$busnum
		    }
		}
	    
		set donebus 1
	    }
	}
    }
   
	


	
    debug 5 ""
    
    set clock -1
    set jtag -1
    
    #master has jtag clock
    set info ""
    if { [ catch {set info [ $handler get $CB_MASTER ]} errmsg ] } {
	debug 10 "Error: $errmsg"
    }
    set jtag [lindex [lindex $info 0] 2]
    debug 5 "jtag control board: $jtag"
    if { ![string compare 0 $jtag]  || ![string compare 1 $jtag] } {
	setJtag cb$jtag on
    }
    debug 5 "master control board: $jtag"

    set info ""
    if { [ catch {set info [ $handler get $CB_CLOCK ]} errmsg ] } {
	debug 10 "Error: $errmsg"
    }
    set clock [lindex [lindex $info 0] 2]
    debug 5 "clock control board: $clock"
    if { ![string compare 0 $clock] || ![string compare 1 $clock]} {
	setClock cb$clock on
    }


    # the MIB does not currently have power status for
    # cb, sb or centerplane.  If the cb is connected, & xfire is on,
    # the cb is on.
    # Ray plans to add cb connected object.
    # center plane is on if machine is on.

    return

}

proc hv_blprocs { handler } {
    global NDOM
    global DOM_BOOT_PROC
    global DOM_PROC_CONF


    debug 1 "hv_blprocs"
    set domInfo ""
   
    if { [ catch {  $handler get $NDOM } domInfo ] } {
	debug 10 "Error: $domInfo"
    }
    set dom_cnt 0
    set dom_cnt [lindex [lindex $domInfo 0] 2]
    debug 5 "domain count: $dom_cnt\n"

    set donebus 0
    for { set k 0 } { $k < $dom_cnt } { incr k} {

	if {[ catch {set bpinfo [ $handler get $DOM_BOOT_PROC.$k ]} errmsg ]} {
	    debug 10 "Error: $errmsg"
	}
	set bootproc [lindex [lindex $bpinfo 0] 2]
	debug 5 "boot proc:  $bootproc"
	set board [expr $bootproc / 4]
	set proc [expr $bootproc % 4]
	set bp $board.$proc
	debug 5 "boot proc:  $bp"

	if {[ catch {set bppinfo [ $handler get $DOM_PROC_CONF.$k ]} errmsg ]} {
	    debug 10 "Error: $errmsg"
	}
	set procconfig [ split [lindex [lindex $bppinfo 0] 2] - ]
	debug 5 "proc config:  $procconfig"

	# now look for blacklisted procs
	checkBLprocs $procconfig
    }
}

#
# hv_hostinfo -p
#
#	Report power supply on each system board, io cabinet, fan trays,
#	control board, and centerplane.
#
proc hv_report_power { snmp_handle } {
    upvar $snmp_handle handler
    
    #global PWR_SYS_BRD
    #global PWR_SYS_BRD_LST
    #global PWR_SYS_BRD_TABLE
    global PWR_IO_CAB_TABLE
    global PWR_FAN_TRAY_TABLE
    global PWR_SF_SB_TABLE
    global PWR_SF_CB_TABLE
    global PWR_SF_CSB_TABLE
    global PWR_BULKPOWER_TABLE
    
    #
    # Query snmpd for Number of SysBrd Power
    #

    
    set num_ctr_pwr 0
    set num_sysb_pwr 5
    set num_cb_pwr 5
    set num_csb_pwr 3
    
    # set global pwr limits from ssp resource file
#come back to
    #hvResources

    for { set i 0 } { $i < $num_sysb_pwr } { incr i } {
	set sysbd_pwr($i) 0
    }
    for { set i 0 } { $i < $num_ctr_pwr } { incr i } {
	set ctr_pwr($i) 0
    }
    for { set i 0 } { $i < $num_cb_pwr } { incr i } {
	set cb_pwr($i) 0
    }
    for { set i 0 } { $i < $num_csb_pwr } { incr i } {
	set csb_pwr($i) 0
    }


    debug 5 ""

    # Query for fan tray power supply (either on or off)
    #debug 5 "Fan Tray    Status"
    #debug 5 "------------------"
    
    if { 0 } {
	if { [ catch {$handler walk x "$PWR_FAN_TRAY_TABLE" {
	    debug 5 [format "%2d      %s" \
		    [lindex [lindex $x 0] 2] [lindex [lindex $x 1] 2]]
    }   } errmsg ] } {
	debug 10 "Error: $errmsg"
    }
}
    debug 5 ""

    # 7-17 current values deemed unreliable
    # Query for Starfire's System Board power supply
    debug 5 "System Brd 3p3VDC  5VDCHK  5VDC  VDDCore  3p3VDCHK"
    debug 5 "-----------------------------------------------"

    if { [ catch {$handler walk x "$PWR_SF_SB_TABLE" {

	set brd [lindex [lindex $x 0] 2]
	set sysbd_pwr(0) [expr [lindex [lindex $x 1] 2]/1000.0]
	set sysbd_pwr(1) [expr [lindex [lindex $x 2] 2]/1000.0]
	set sysbd_pwr(2) [expr [lindex [lindex $x 3] 2]/1000.0]
	set sysbd_pwr(3) [expr [lindex [lindex $x 4] 2]/1000.0]
	set sysbd_pwr(4) [expr [lindex [lindex $x 5] 2]/1000.0]
	
	debug 5 [format "%2d  %5s  %5s  %5s  %5s  %5s" \
		$brd $sysbd_pwr(0) $sysbd_pwr(1) $sysbd_pwr(2) \
		$sysbd_pwr(3) $sysbd_pwr(4) ]
	debug 5 ""
	# 5-voltage, no current
	#{{40 41 42 43 44} {}}

	set pwrvalue  [ format \
		"{%.5s %.5s %.5s %.5s %.5s} {}" \
		$sysbd_pwr(0) $sysbd_pwr(1) $sysbd_pwr(2) \
		$sysbd_pwr(3) $sysbd_pwr(4)]
	
	set voltvalue  [ format \
		"{%.5s %.5s %.5s %.5s %.5s} {}" \
		$sysbd_pwr(0) $sysbd_pwr(1) $sysbd_pwr(2) \
		$sysbd_pwr(3) $sysbd_pwr(4) ]

	# july 96: current values deemed unreliable, do not display.
	powerTrap $brd "$voltvalue"
	
}   } errmsg ] } {
	debug 10 "Error: $errmsg"
    }
    # Query for Control Board power supply
    debug 5 "Control Brd   5VDC   5VCCHK   3p3VDCHK   VccPer   VccFan"
    debug 5 "---------------------------------------------------"

    # should have 3 current values, not in mib
    if { [ catch {$handler walk x "$PWR_SF_CB_TABLE" {
	
	set brd [lindex [lindex $x 0] 2]
	set cb_pwr(0) [expr [lindex [lindex $x 1] 2]/1000.0]
	set cb_pwr(1) [expr [lindex [lindex $x 2] 2]/1000.0]
	set cb_pwr(2) [expr [lindex [lindex $x 3] 2]/1000.0]
	set cb_pwr(3) [expr [lindex [lindex $x 4] 2]/1000.0]
	set cb_pwr(4) [expr [lindex [lindex $x 5] 2]/1000.0]
	
	debug 5 [format "%2d  %s  %s  %s  %s  %s" \
		$brd $cb_pwr(0) $cb_pwr(1) $cb_pwr(2) \
		$cb_pwr(3) $cb_pwr(4)]
	debug 5 ""
	# 5-voltage, 0 current
	#{{40 41 42 43 44} {}}

	set voltvalue  [ format \
		"{%.5s %.5s %.5s %.5s %.5s} {}" \
		$cb_pwr(0) $cb_pwr(1) $cb_pwr(2) \
		$cb_pwr(3) $cb_pwr(4) ]
	
	# july 96: current values deemed unreliable, do not display.
	powerTrap cb$brd "$voltvalue"
	
}   } errmsg ] } {
	debug 10 "Error: $errmsg"
    }


    # Query for centerplane support Board power supply
    debug 5 "CPSupp Brd   3p3VDCHK   5VDCHK   3p3VDCHK"
    debug 5 "---------------------------------------------------"

    if { [ catch {$handler walk x "$PWR_SF_CSB_TABLE" {
	
	set brd [lindex [lindex $x 0] 2]
	set csb_pwr(0) [expr [lindex [lindex $x 1] 2]/1000.0]
	set csb_pwr(1) [expr [lindex [lindex $x 2] 2]/1000.0]
	set csb_pwr(2) [expr [lindex [lindex $x 3] 2]/1000.0]
	
	debug 5 [format "%2d  %5s  %5s  %5s" \
		$brd $csb_pwr(0) $csb_pwr(1) $csb_pwr(2) ]

	debug 5 ""
	# 3-voltage, 0 current
	#{{40 41 41} {}}

	set voltvalue  [ format \
		"{%.5s %.5s %.5s} {}" \
		$csb_pwr(0) $csb_pwr(1) $csb_pwr(2)  ]
	
	# july 96: current values deemed unreliable, do not display.
	powerTrap csb$brd "$voltvalue"
	
}   } errmsg ] } {
	debug 10 "Error: $errmsg"
    }

    if { 0 } {
	# 7-17 amp values deemed unreliable (PS1, PS2)
	# Query for Centerplane power supply
	debug 5 "Centerplane 3p3VDC0   3p3VDC1   3p3VDC2"
	debug 5 "----------------------------------------------------------"
	
	#init with 0
	for {set i 0} { $i < 2 } {incr i} {
	    for {set j 0} {$j < $num_ctr_pwr} {incr j} {
		set pwr($i) $ctr_pwr($j)
	    }
	}

	if { [ catch {$handler walk x "$PWR_CTRPLANE_TABLE" {

	    set brd [lindex [lindex $x 0] 2]
	    set ctr_pwr(0) [expr [lindex [lindex $x  1] 2]/1000.0]
	    set ctr_pwr(1) [expr [lindex [lindex $x  2] 2]/1000.0]
	    set ctr_pwr(2) [expr [lindex [lindex $x  3] 2]/1000.0]

	    #set pwrvalue {{10 20 30} {20 21 22}}
	    set pwr($brd) [ format "%.5s %.5s %.5s" \
		    $ctr_pwr(0) $ctr_pwr(1) $ctr_pwr(2) ]
	    
	    debug 5 [format "%2d  %s  %s  %s" \
		    $brd $ctr_pwr(0) $ctr_pwr(1) $ctr_pwr(2) ]
	    debug 5 ""
    }   } errmsg ] } {
	debug 10 "Error: $errmsg"
    }
    set pwrvalue [ format "{%s} {%s}" $pwr(0) $pwr(1) ]

    powerTrap ctr "$pwrvalue"
    #powerTrap $brd {$powervalue}
}

    debug 5 "bulkpower supply	status"
    debug 5 "-----------------------------"
    if { [ catch {$handler walk x "$PWR_BULKPOWER_TABLE" {

	set brd [lindex [lindex $x 0] 2]
	set bulk_pwr [lindex [lindex $x 1] 2]

	debug 5 "$brd\t$bulk_pwr"
	
	# bulk power has on/off status to read.
	# writing this mib would turn bulk power on or off.
	#

	if { ![string compare $bulk_pwr on] || ![string compare $bulk_pwr ok]} {
	    #greenPower bp$brd
	    bpTrap $brd normal
	} elseif  { ![string compare $bulk_pwr fail] } {
	    bpTrap $brd fail
	}
	
}   } errmsg ] } {
	debug 10 "Error: $errmsg"
    }
#for test
#greenPower bp4
#bpTrap 0 normal
#bpTrap 5 normal
#bpTrap 6 fail

return
}
#
# hv_hostinfo -n:
#
#	report the hostname from the MIB
#
#
proc hv_report_hostname { snmp_handle } {
    upvar $snmp_handle handler

    global HOST_NAME
    
    #
    # Query snmpd for hostname and output it.
    #
    if { [ catch {set info [ $handler get "$HOST_NAME" ] } errmsg ] } {
	debug 10 "Error: $errmsg"
	return ""
    }
    set atmp [lindex [lindex $info 0] 2]
    debug 5 "Hostname: $atmp"
    return $atmp

}
#
# hv_hostinfo -t:
#
#	Report the overall ambient temperature (on Centigrades) on the
#	Physical Host, and temperatures on the Control Boards, and
#	each System Board.
#
proc hv_report_temperature { snmp_handle } {
    upvar $snmp_handle handler
    
    global HOST_AMB_TMP
    global TMP_CTRPLANE_TABLE
    global TMP_SF_SB_TABLE
    global TMP_SF_CB_TABLE
    global TMP_SF_CSB_TABLE
    global TMP_SF_CP_TABLE
    

    set num_ctr_temp 10
    set num_sysb_temp 12
    set num_cb_temp 6
    set num_csb_temp 2

    # set global temp limits from ssp resource file
    hvResources

    for { set i 0 } { $i < $num_sysb_temp } { incr i } {
	set sysbd_temp($i) 0
    }
    for { set i 0 } { $i < $num_ctr_temp } { incr i } {
	set ctr_temp($i) 0
    }
    for { set i 0 } { $i < $num_cb_temp } { incr i } {
	set cb_temp($i) 0
    }
    for { set i 0 } { $i < $num_csb_temp } { incr i } {
	set csb_temp($i) 0
    }

    #
    # Query snmpd for ambient temperature and output it.
    #
	
    #set info [ $handler get "$HOST_AMB_TMP" ]
    #set atmp [expr [lindex [lindex $info 0] 2] / 1000.0]
    #debug 5 "Ambient temperature(C): $atmp"


    #
    # Display Starfire MIB temperatures
    #
    debug 5 ""
    debug 5 "Starfire MIBs"
    debug 5 "============="


    ## Display Starfire's system board table temp

    debug 5 "System  Brd   CIC0   CIC1   MC   XDB2   XDB3  PROC0 PROC1 PROC2 PROC3 PS2   PS3   PS4"
    debug 5 "--------------------------------------------------------------"
    if { [ catch {$handler walk x "$TMP_SF_SB_TABLE" {

	set brd [lindex [lindex $x 0] 2]
	set sysbd_temp(0) [expr [lindex [lindex $x 1] 2]/1000.0]
	set sysbd_temp(1) [expr [lindex [lindex $x 2] 2]/1000.0]
	set sysbd_temp(2) [expr [lindex [lindex $x 3] 2]/1000.0]
	set sysbd_temp(3) [expr [lindex [lindex $x 4] 2]/1000.0]
	set sysbd_temp(4) [expr [lindex [lindex $x 5] 2]/1000.0]
	set sysbd_temp(5) [expr [lindex [lindex $x 6] 2]/1000.0]
	set sysbd_temp(6) [expr [lindex [lindex $x 7] 2]/1000.0]
	set sysbd_temp(7) [expr [lindex [lindex $x 8] 2]/1000.0]
	set sysbd_temp(8) [expr [lindex [lindex $x 9] 2]/1000.0]
	set sysbd_temp(9) [expr [lindex [lindex $x 10] 2]/1000.0]
	set sysbd_temp(10) [expr [lindex [lindex $x 11] 2]/1000.0]
	set sysbd_temp(11) [expr [lindex [lindex $x 12] 2]/1000.0]
	    
	debug 5 [ format "%2d  %-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s" \
		$brd $sysbd_temp(0) $sysbd_temp(1) $sysbd_temp(2) \
		$sysbd_temp(3) $sysbd_temp(4) $sysbd_temp(5) \
		$sysbd_temp(6) $sysbd_temp(7) $sysbd_temp(8) \
		$sysbd_temp(9) $sysbd_temp(10) $sysbd_temp(11) ]
	debug 5 ""
	
	#
	# make sure procs are present to avoid displaying erroneous values
	#
	if {$brd < 8} {
	    # Boards in Back number procs in ascending order.
	    set ndx 8
	    set increment -1
	} else {
	    # Boards in Front number procs in descending order.
	    set ndx 5
	    set increment 1
	}
	#proclist returns in reverse order
	set proclist [procList $brd]
	foreach proc $proclist {
				debug 1 "[whatProcState $proc]"
		if {[string compare [lindex [whatProcState $proc] 0] "empty"] == 0 } {
			set sysbd_temp($ndx) 00
		 }
		 incr ndx $increment
	     }


	# 5-asic, 3-dc, 4-proc
	#{{40 41 42 43 44} {45 46 47} {48 49 50 51}}
	set thermvalue  [ format \
		"{%.3s %.3s %.3s %.3s %.3s} {%.3s %.3s %.3s} {%.3s %.3s %.3s %.3s}" \
		$sysbd_temp(0) $sysbd_temp(1) $sysbd_temp(2) \
		$sysbd_temp(3) $sysbd_temp(4) $sysbd_temp(9) \
		$sysbd_temp(10) $sysbd_temp(11) $sysbd_temp(5) \
		$sysbd_temp(6) $sysbd_temp(7) $sysbd_temp(8) ]

	thermalTrap $brd "$thermvalue"
	#thermalTrap $brd {$thermvalue}
	
}   } errmsg ] } {
	debug 10 "Error: $errmsg"
    }


    # Display Starfire's control board table temp
    debug 5 "Control Brd  PS1     PS2     PS3     Sen0    Sen1    Sen2"
    debug 5 "-----------------------------------------------------------"

    if { [ catch {$handler walk x "$TMP_SF_CB_TABLE" {

	set brd [lindex [lindex $x 0] 2]
	set cb_temp(0) [expr [lindex [lindex $x 1] 2]/1000.0]
	set cb_temp(1) [expr [lindex [lindex $x 2] 2]/1000.0]
	set cb_temp(2) [expr [lindex [lindex $x 3] 2]/1000.0]
	set cb_temp(3) [expr [lindex [lindex $x 4] 2]/1000.0]
	set cb_temp(4) [expr [lindex [lindex $x 5] 2]/1000.0]
	set cb_temp(5) [expr [lindex [lindex $x 6] 2]/1000.0]
	
	debug 5 [ format "%2d  %-8s%-8s%-8s%-8s%-8s%-8s" \
		$brd $cb_temp(0) $cb_temp(1) $cb_temp(2) \
		$cb_temp(3) $cb_temp(4) $cb_temp(5) ]
	debug 5 ""
	
	#set thermvalue {{45 50 55} {65 70 75}}
	set thermvalue  [ format "{%.3s %.3s %.3s} {%.3s %.3s %.3s}" \
		$cb_temp(0) $cb_temp(1) $cb_temp(2) \
		$cb_temp(3) $cb_temp(4) $cb_temp(5) ]

	thermalTrap cb$brd "$thermvalue"
	#thermalTrap cb$brd {$thermvalue}

}   } errmsg ] } {
	debug 10 "Error: $errmsg"
    }
    debug 5 ""
    # Display Starfire's centerplane support board table temp
    debug 5 "Centerpl supp Brd  PS1     PS2"
    debug 5 "---------------------------------"

    if { [ catch {$handler walk x "$TMP_SF_CSB_TABLE" {
	
	set brd [lindex [lindex $x 0] 2]
	set csb_temp(0) [expr [lindex [lindex $x 1] 2]/1000.0]
	set csb_temp(1) [expr [lindex [lindex $x 2] 2]/1000.0]

	debug 5 [ format "   %2d        %-8s%-8s" \
		$brd $csb_temp(0) $csb_temp(1) ]
	debug 5 ""

	#set thermvalue {65 70}
	set thermvalue  [ format "%.3s %.3s" $csb_temp(0) $csb_temp(1) ]

	thermalTrap csb$brd "$thermvalue"
	#thermalTrap csb$brd {$thermvalue}

}   } errmsg ] } {
	debug 10 "Error: $errmsg"
    }
    debug 5 ""

    # Display Starfire's centerplane table temp
    debug 5 "Centerplane TMP0    TMP1    TMP2    TMP3    TMP4    TMP5    TMP6    TMP7    TMP8    TMP9"
    debug 5 "-------------------------------------------------------------------------------------------"

    #init with 0
    for {set i 0} { $i < 2 } {incr i} {
	for {set j 0} {$j < $num_ctr_temp} {incr j} {
	    set therm($i) $ctr_temp($j)
	}
    }

    if { [ catch {$handler walk x "$TMP_SF_CP_TABLE" {

	set brd [lindex [lindex $x 0] 2]
	set ctr_temp(0) [expr [lindex [lindex $x  1] 2]/1000.0]
	set ctr_temp(1) [expr [lindex [lindex $x  2] 2]/1000.0]
	set ctr_temp(2) [expr [lindex [lindex $x  3] 2]/1000.0]
	set ctr_temp(3) [expr [lindex [lindex $x  4] 2]/1000.0]
	set ctr_temp(4) [expr [lindex [lindex $x  5] 2]/1000.0]
	set ctr_temp(5) [expr [lindex [lindex $x  6] 2]/1000.0]
	set ctr_temp(6) [expr [lindex [lindex $x  7] 2]/1000.0]
	set ctr_temp(7) [expr [lindex [lindex $x  8] 2]/1000.0]
	set ctr_temp(8) [expr [lindex [lindex $x  9] 2]/1000.0]
	set ctr_temp(9) [expr [lindex [lindex $x 10] 2]/1000.0]


	#set thermvalue {{10 20 30 40 50 60 50 40 30 19} {20 21 22 23 24 25 26 27 28 29}}
	set therm($brd) [ format "%.3s %.3s %.3s %.3s %.3s %.3s %.3s %.3s %.3s %.3s" \
		$ctr_temp(0) $ctr_temp(1) $ctr_temp(2) \
		$ctr_temp(3) $ctr_temp(4) $ctr_temp(5) $ctr_temp(6) \
		$ctr_temp(7) $ctr_temp(8) $ctr_temp(9) ]
	
	debug 5 [ format "%2d  %-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s" \
		$brd $ctr_temp(0) $ctr_temp(1) $ctr_temp(2) \
		$ctr_temp(3) $ctr_temp(4) $ctr_temp(5) $ctr_temp(6) \
		$ctr_temp(7) $ctr_temp(8) $ctr_temp(9) ]

}   } errmsg ] } {
	debug 10 "Error: $errmsg"
    }
    debug 5 ""
    set thermvalue [ format "{%s} {%s}" $therm(0) $therm(1) ]
    
    thermalTrap ctr "$thermvalue"
    #thermalTrap $brd {$thermvalue}
    return
}


#
# hv_hostinfo -s
#
#	Interpret and report the content of the signature block
#	for selected processors.
#
proc hv_report_sigb { snmp_handle } {
	upvar $snmp_handle handler

	global PROC_STATE_TABLE
	global PROC_MBOX_TABLE

	#
	# Query the snmpd for each proc's Signature Block and Mailbox contents.
	#
	$handler walk x "$PROC_STATE_TABLE $PROC_MBOX_TABLE" {
	set proc [lindex [lindex $x 0] 2]
	set brd		[expr $proc / 4]
	set brdProc	[expr $proc % 4]
	debug 5 [format "Processor: %2d  (board %2d, proc %d)" $proc $brd $brdProc]
		debug 5 "---------------------------------"
		debug 5 "\[Signature Block\]"
	debug 5 [format " heartbeat = %d"  [lindex [lindex $x 1] 2] ]
	debug 5 [format " signature = %s"  [lindex [lindex $x 2] 2] ]
	debug 5 [format "     state = %s"  [lindex [lindex $x 3] 2] ]
	debug 5 [format " sub-state = %s"  [lindex [lindex $x 4] 2] ]
	debug 5 [format "clock freq = %d MHz" [lindex [lindex $x 5] 2] ]
	debug 5 [format "cache size = %d KB" [lindex [lindex $x 6] 2] ]
	debug 5 [format "   version = %s" [lindex [lindex $x 7] 2] ]
	debug 5 ""
		debug 5 "\[SSP-to-HOST mailbox\]"
	debug 5 [format "    length = %d" [lindex [lindex $x 8] 2] ]
	debug 5 [format "      flag = %d" [lindex [lindex $x 9] 2] ]
	debug 5 [format "       cmd = %s" [lindex [lindex $x 10] 2] ]
	debug 5 ""
		debug 5 "\[HOST-to-SSP mailbox\]"
	debug 5 [format "    length = %d" [lindex [lindex $x 11] 2] ]
	debug 5 [format "      flag = %d" [lindex [lindex $x 12] 2] ]
	debug 5 [format "       cmd = %s" [lindex [lindex $x 13] 2] ]
	debug 5 ""
		debug 5 "\[OBP mailbox\]"
	debug 5 [format "    length = %d" [lindex [lindex $x 14] 2] ]
	debug 5 [format "      flag = %d" [lindex [lindex $x 15] 2] ]
	debug 5 [format "       cmd = %s" [lindex [lindex $x 16] 2] ]
	debug 5 ""
	debug 5 ""
	}
	return
}

#
# hv_hostinfo -f
#
#	Display fan configuration and status.
#
proc hv_report_fan_info { snmp_handle } {
    upvar $snmp_handle handler

    global FAN_TRAY_TABLE
    global FAN_GEN_TABLE
    global gDebugThreshold
    global gFanMibRead
    
    set slot -1
    set num -1
    set fanstat -1
    set speed -1
    set index ""
    #
    # Query the snmpd for each fan tray conf and status.
    #
    debug 5 "Fan Tray   Status   Speed"
    debug 5 "-------------------------"

    if { [ catch {$handler walk x "$FAN_TRAY_TABLE" {
	debug 5 [format "%3d   %s   %s" [lindex [lindex $x 0] 2] \
		     [lindex [lindex $x 1] 2] [lindex [lindex $x 2] 2] ]
    }   } errmsg ] } {
	debug 10 "Error: $errmsg"
    }
    debug 5 "fanGenTraySlotNum fanGenNum fanGenStatus fanGenSpeed"
    debug 5 "------------------------------------------------------------"
    if { [ catch {$handler walk x "$FAN_GEN_TABLE" {

	debug 5 [format "%3d   %s   %s	%s" [lindex [lindex $x 0] 2] \
		     [lindex [lindex $x 1] 2] [lindex [lindex $x 2] 2] \
		     [lindex [lindex $x 3] 2] ]

	set slot [lindex [lindex $x 0] 2] 
	set num [lindex [lindex $x 1] 2] 
	set fanstat [lindex [lindex $x 2] 2] 
	set speed [lindex [lindex $x 3] 2]

	set gFanMibRead 1
	if { [string compare $fanstat fail] == 0 } {
	    switch [expr $num % 2 ] {
		case 0 { fanTrap fail ft${slot}a }
		case 1 { fanTrap fail ft${slot}b }
	    }
	} elseif { [string compare $fanstat on] == 0 } { 
	    fanTrap powerOn ft$slot
	    #fanTrap speed nominal
	} elseif { [string compare $fanstat off] == 0 } {
	    fanTrap powerOff ft$slot
	}

	#may want to move this outside the walk, since one speed is for all.

	# all the fans run at same speed and only 2 choices exist.
	if { [string compare $speed nominal] == 0 } {
	    fanTrap speed nominal
	} elseif { [string compare $speed fast] == 0 } {
	    fanTrap speed high
	} else {
	    fanTrap speed nominal
	}

    } } errmsg ] } {
	debug 10 "Error: $errmsg"
    }
    debug 5 ""
    if { $gDebugThreshold < 0 } {
	fanTrap speed high
	#fanTrap speed nominal
	fanTrap powerOn ft0
	fanTrap powerOn ft2
	fanTrap powerOn ft12
	fanTrap powerOff ft12
	fanTrap fail ft10b
    }
    return
}


# called by hv_hostinfo -b
proc updatebus { handler } {

global NDOM DEFAULT_BUS DOM_BOOT_PROC DOM_PROC_CONF DOM_ABUS_LST DOM_DBUS_LST

foreach buss $DEFAULT_BUS {
	grayBus $buss
	    }

    set domInfo ""
   
    if { [ catch {  $handler get $NDOM } domInfo ] } {
	debug 10 "Error: $domInfo"
    }
    set dom_cnt 0
    set dom_cnt [lindex [lindex $domInfo 0] 2]
    debug 5 "domain count: $dom_cnt\n"


    for { set k 0 } { $k < $dom_cnt } { incr k} {

	if {[ catch {set bpinfo [ $handler get $DOM_BOOT_PROC.$k ]} errmsg ]} {
	    debug 10 "Error: $errmsg"
	}
	set bootproc [lindex [lindex $bpinfo 0] 2]
	debug 5 "boot proc:  $bootproc"
	set board [expr $bootproc / 4]
	set proc [expr $bootproc % 4]
	set bp $board.$proc
	debug 5 "boot proc:  $bp"

	if {[ catch {set bppinfo [ $handler get $DOM_PROC_CONF.$k ]} errmsg ]} {
	    debug 10 "Error: $errmsg"
	}
	set procconfig [ split [lindex [lindex $bppinfo 0] 2] - ]
	debug 5 "proc config:  $procconfig"
	
	set ndx [lsearch $procconfig $bp*]
	debug 5 "ndx: $ndx"

	# if the proc config of the boot proc has a G in it
	# the domain is up, use it!
	if { [string first G [lindex $procconfig $ndx] ] > -1 } {
	    # grab the bus config from the first active domain, applies to all.
	    #these have status attached (p118) ie: 3G  ABUS3 is good
	    # need to strip off....
	    # If no domain is booted, use the full configuration

	    set abinfo ""
	    if {[ catch {set abinfo [ $handler get $DOM_ABUS_LST.$k ]} errmsg ]} {
		debug 10 "Error: $errmsg"
	    }
	    set abrds [ split [lindex [lindex $abinfo 0] 2] - ]
	    debug 5 "ABUS Bus:  $abrds"
	
	    foreach buss $abrds {
		set busstat [string index $buss 1]
		if { [string compare $busstat "G"] == 0 } {
		set busnum [string index $buss 0]
		greenBus abus$busnum
	    } }
	
	    set dbinfo ""
	    if { [ catch {set dbinfo [ $handler get $DOM_DBUS_LST.$k ]} errmsg]} {
		debug 10 "Error: $errmsg"
	    }
	    set dbrds [ split [lindex [lindex $dbinfo 0] 2] - ]
	    debug 5 "DBUS Bus:  $dbrds"
	
	    foreach buss $dbrds {
		set busstat [string index $buss 1]
		if { [string compare $busstat "G"] == 0 } {
		set busnum [string index $buss 0]
		greenBus dbus$busnum
	    } }
	    
	    break
	}

    }

}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***

#
# ident	"@(#)powerDetail.tcl	1.13	98/12/10 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   Routines which support creation and manipulation of power detail.
#
# Main routine to create a power detail.  Dispatches to supporting proc.
#   proc powerDetail {candidate}
#
# Create a power detail template window for a system board.
#   proc createPowerSysBoard {board} 
#
# Create a power detail template window for a support board.
#   proc createPowerSupBoard {board}
#
# Create a power detail template window for a control board.
#   proc createPowerConBoard {board} 
#
# This routine actually creates the window for most boards.
#   proc createPowerDetail {board volt_list amp_list} 
#
# This routine creates the center plane template for power detail.
#   proc createPowerCtrBoard {target} 
#

#
# New datum has arrived, update detail.
#
proc powerDetailUpdate {board} {
    global gPowerList

    debug 2 "powerDetailUpdate:$board"

    set w .powerDetail_$board

    set ndx [lsearch -glob $gPowerList $board*]
    if {$ndx < 0} {
	debug 5 "updatePowerDetail, no entry for:$board"
	return
    }

    # if it's not powered, low voltages are ok.
    set state [whatBoardState $board]
    if { [lsearch $state power_on] < 0} {
	set onOff "off"
    } else {
	set onOff "on"
    }

    set target [lindex $gPowerList $ndx]
    set pwr_val [lindex $target 2]

    if {[string compare ctr $board] == 0} {
	wm title $w "CPLANE Power Detail"

	# 3+3 power sensors (front and back)
	set front [lindex $pwr_val 0]
	set back  [lindex $pwr_val 1]

	set panel "$w.f.volt_front"
	powerPanelUpdate $panel $front ctr-volt 0 $onOff

	set panel "$w.f.volt_back"
	powerPanelUpdate $panel $back ctr-volt 0 $onOff
    } elseif {[string first csb $board] >= 0} {
	set bnum [string trimleft $board csb]
	wm title $w "CSB $bnum Power Detail"

	#3 voltage 2 current power sensors
	set v    [lindex $pwr_val 0]
	set i	 [lindex $pwr_val 1]

	set panel "$w.f.volt"
	powerPanelUpdate $panel $v csb-volt $bnum $onOff
	set panel "$w.f.amp"
	powerPanelUpdate $panel $i csb-amp $bnum $onOff
    } elseif {[string first cb $board] >= 0} {
	set bnum [string trimleft $board cb]
	wm title $w "CB $bnum Power Detail"

	# 5 voltage sensors on board, 3 current
	set v	[lindex $pwr_val 0]
	set i	[lindex $pwr_val 1]

	set panel "$w.f.volt"
	powerPanelUpdate $panel $v cb-volt $bnum $onOff

	set panel "$w.f.amp"
	powerPanelUpdate $panel $i cb-amp $bnum $onOff
    } else {
	set bnum [string trimleft $board sb]
	wm title $w "SB $bnum Power Detail"

	# system board: 5 voltage sensors on board, 5 current
	set v	[lindex $pwr_val 0]
	set i	[lindex $pwr_val 1]

	set panel "$w.f.volt"
	powerPanelUpdate $panel $v sb-volt $bnum $onOff

	set panel "$w.f.amp"
	powerPanelUpdate $panel $i sb-amp $bnum $onOff

    }
}

#
# Do the actual grunt work for updating the bars and text.
# panel = canvas to update.  values = list of pwr_val.
#
proc powerPanelUpdate {panel values component board onOff} {

    global gPdX1
    global gPdY2
    global gPdInc

    debug 2 "powerPanelUpdate:$panel $values $onOff"

    set tag_id 0
    set xx $gPdX1

    foreach member $values {
	set tag "text$tag_id"

	$panel dchars $tag 0 5
	$panel itemconfigure $tag -text $member

	set tag "bar$tag_id"

	set yy [powerGuageY $member]
	set color [powerGuageColor $member $component $board $tag_id $onOff]

	$panel coords $tag $xx $gPdY2 $xx $yy
	$panel itemconfigure $tag -fill $color

	incr tag_id
	incr xx $gPdInc
    }
}

#
# Return y coordinate to represent the current power.
#
proc powerGuageY {power_val} {
    global gPdY1
    global gPdY2

    global gVoltDefaultMIN
    global gVoltDefaultMAX

    debug 2 "powerGuageY:$power_val"

    #current not supported July 96
    set low_bound [expr $gVoltDefaultMIN -2 ]
    set high_bound [expr $gVoltDefaultMAX +2 ]

    set power_delta [expr $high_bound - $low_bound]

    if {$power_val > $high_bound} {
	set adj_pwr $power_delta
    } elseif {$power_val  < $low_bound} {
	set adj_pwr 0
    } else {
	set adj_pwr [expr $power_val  - $low_bound]
    }

    set pixel_delta [expr $gPdY2 - $gPdY1]

    set retvalue \
	    [expr double($adj_pwr*$pixel_delta)/double($power_delta)]

    set retvalue [expr $gPdY2 - int($retvalue)]

    return $retvalue
}

#
# Given a power, return the approprate power color
#

#
proc powerGuageColor {power component brdnum ndx onOff} {
    global gHealthy
    global gProblem

    global gMAXsb_volt
    global gMAXcsb_volt
    global gMAXcb_volt
    global gMAXctr_volt
    global gMINsb_volt
    global gMINsb_voltOff
    global gMINcsb_volt
    global gMINcsb_voltOff
    global gMINcb_volt
    global gMINcb_voltOff
    #global gMINctr_volt

    global gVoltDefaultMAX
    global gVoltDefaultMIN
    global gTargetVcore

    debug 2 "powerGuageColor:$power $component $brdnum $ndx $onOff"

    #current not supported July 96
    if {[string first "amp" $component] != -1} {
	return $gHealthy
    }

    set highpwrThresh $gVoltDefaultMAX
    set lowpwrThresh $gVoltDefaultMIN

    set trailer ""
    if { [string compare $onOff "off"] == 0 } {
	set trailer "Off"
    }

    if {[string compare $component "sb-volt"] == 0} {
	set low [join "gMINsb_volt $trailer" ""]

	# use set for an extra dereference
	set lowpwrThresh [lindex [set $low] $ndx]

	#set lowpwrThresh [lindex $gMINsb_volt $ndx]

	set highpwrThresh [lindex $gMAXsb_volt $ndx]
	debug 1 "low: [set $low] lowpwrThresh: $lowpwrThresh"

	# this code fixes support for variable vcore values -- it
	# slows hostview down slightly, but the code changes required
	# to properly cache the vcore_target are more than I want
	# to deal with right now (due to the ugliness of hostview
	# itself)  I pity the fool who has to read this code!
	#
	# ndx == 3 means this code is only used when checking Vcore
	if { $ndx == 3 } {
	    set tolerance .03
	    set vcore_target [sysboard_target_vcore $brdnum]
	    set lowpwrThresh [expr $vcore_target * (1.0 - $tolerance) ]
	    set highpwrThresh [expr $vcore_target * (1.0 + $tolerance) ]
	}

    } elseif {[string compare $component "csb-volt"] == 0} {
	set lowpwrThresh [lindex $gMINcsb_volt $ndx]
	set highpwrThresh [lindex $gMAXcsb_volt $ndx]
    } elseif {[string compare $component "cb-volt"] == 0} {
	set lowpwrThresh [lindex $gMINcb_volt $ndx]
	set highpwrThresh [lindex $gMAXcb_volt $ndx]
    } elseif {[string compare $component "ctr-volt"] == 0} {
	set lowpwrThresh [lindex $gMINctr_volt $ndx]
	set highpwrThresh [lindex $gMAXctr_volt $ndx]
    }

    debug 2 "powerGuageColor:power:$power $component brdnum: $brdnum highpwrThresh: $highpwrThresh lowpwrThresh: $lowpwrThresh onOff: $onOff"

    if {$power > $highpwrThresh} {
	return $gProblem
    }
    if {$power < $lowpwrThresh} {
	return $gProblem
    }
    return $gHealthy
}



#
# Create a power detail window for all boards except the center plane.
#
proc createPowerDetail {board volt_list amp_list} {
    global gBg1
    global gFg1
    global gFont1
    global gFont2

    global gPdX1
    global gPdY1
    global gPdY2
    global gPdInc
    global gPdWidth

    global gHealthy
    global gPowerList

    debug 2 "createPowerDetail:$board $volt_list $amp_list"

    set w .powerDetail_$board

    toplevel $w
    wm title $w "Board $board Power Detail"

    frame $w.f  
    pack $w.f -expand yes -fill both

    set x1 $gPdX1
    set y1 $gPdY1
    set y2 $gPdY2

    canvas $w.f.volt -relief groove -borderwidth 2 -height $gPdY2 \
	    -width [expr [llength $volt_list] * $gPdInc + 2] -background $gBg1
    canvas $w.f.amp   -relief groove -borderwidth 2 -height $gPdY2 \
	    -width [expr [llength $amp_list] * $gPdInc + 2] -background $gBg1

    pack $w.f.volt -expand yes -fill both -side left
    #pack $w.f.volt $w.f.amp -expand yes -fill both -side left

    set tag_id 0
    foreach bar $volt_list {
	$w.f.volt create line [expr $x1] [expr $y1] [expr $x1] [expr $y1] \
		-width $gPdWidth -fill $gHealthy -tags "bar$tag_id"

	$w.f.volt create text [expr $x1] [expr $y2-10] -text NA \
		-tags "text$tag_id"

	$w.f.volt create text [expr $x1] [expr $y2-25] -text $bar

	incr tag_id
	incr x1 $gPdInc
    }

    set tag_id 0
    set x1 $gPdX1
    foreach bar $amp_list {
	$w.f.amp create line [expr $x1] [expr $y1] [expr $x1] [expr $y1] \
		-width $gPdWidth -fill $gHealthy -tags "bar$tag_id"

	$w.f.amp create text [expr $x1] [expr $y2-10] -text NA \
		-tags "text$tag_id"

	$w.f.amp create text [expr $x1] [expr $y2-25] -text $bar

	incr tag_id
	incr x1 $gPdInc
    }

    frame $w.buttonbox 
    pack $w.buttonbox -expand yes -fill x -side left

    button $w.buttonbox.dismiss   -bg $gBg1 -fg $gFg1 \
	    -activebackground $gBg1 -activeforeground $gFg1 -text "dismiss" \
	    -command {dismissMe} -font $gFont1

    pack $w.buttonbox.dismiss -fill x 

        #
    # If power data is known, display it.
    #
    if {[lsearch -glob $gPowerList $board*] >= 0} {
	powerDetailUpdate $board
    }
}

#
# Create a power detail template window for a support board.
#
proc createPowerSupBoard {board} {
    debug 1 "createPowerSupBoard:$board"

    set amp_list {i1 i2}
    set volt_list {3.3VDC 5VDCHK 3.3VDCHK}
    #set volt_list {v1 v2}

    createPowerDetail $board $volt_list $amp_list
}

#
# Create a power detail template window for a control board.
#
proc createPowerConBoard {board} {
    debug 1 "createPowerConBoard:$board"

    set amp_list {i1 i2 i3}
    set volt_list {VDC VCCHK 3.3VDCHK VccPer VccFan}
    #set volt_list {v1 v2 v3 v4 v5}

    createPowerDetail $board $volt_list $amp_list
}

#
# Create a power detail template window for a system board.
#
proc createPowerSysBoard {board} {
    debug 1 "createPowerSysBoard:$board"

    set amp_list {i1 i2 i3 i4 i5}
    set volt_list {VDD 5VDCHK 5VDC VDDCore 3.3VDCHK}
    #set volt_list {v1 v2 v3 v4 v5}

    createPowerDetail $board $volt_list $amp_list
}

#
# Create a template for the center board.
#
proc createPowerCtrBoard {target} {
    global gBg1
    global gFg1
    global gFont1

    global gPdX1
    global gPdY1
    global gPdY2
    global gPdInc
    global gPdWidth
    global gPowerList

    global gHealthy

    debug 2 "createPowerCtrBoard:$target"

    set w .powerDetail_$target

    toplevel $w
    wm title $w "CPLANE Power Detail"

    frame $w.f  
    pack $w.f -expand yes -fill both

    set x1 $gPdX1
    set y1 $gPdY1
    set y2 $gPdY2

    #set volt_list_front {3.3VDC0 3.3VDC1 3.3VDC2}
    set volt_list_front {}
    set volt_list_back {}
    #set volt_list_back {3.3VDC0 3.3VDC1 3.3VDC2}
    #set volt_list_front {v1 v2 v3}
    #set volt_list_back {v3 v2 v1}

    canvas $w.f.volt_front -relief groove -borderwidth 2 -height $gPdY2 \
	    -width [expr [llength $volt_list_front] * $gPdInc + 2]
    canvas $w.f.volt_back -relief groove -borderwidth 2 -height $gPdY2 \
	    -width [expr [llength $volt_list_back] * $gPdInc + 2]

    pack $w.f.volt_front $w.f.volt_back -expand yes -fill both -side left

    set tag_id 0
    foreach bar $volt_list_front {
	$w.f.volt_front create line \
		[expr $x1] [expr $y1] [expr $x1] [expr $y1] \
		-width $gPdWidth -fill $gHealthy -tags "bar$tag_id"

	$w.f.volt_front create text [expr $x1] [expr $y2-10] -text NA \
		-tags "text$tag_id"

	$w.f.volt_front create text [expr $x1] [expr $y2-25] -text $bar

	incr tag_id
	incr x1 $gPdInc
    }

    set tag_id 0
    set x1 $gPdX1
    foreach bar $volt_list_back {
	$w.f.volt_back create line \
		[expr $x1] [expr $y1] [expr $x1] [expr $y1] \
		-width $gPdWidth -fill $gHealthy -tags "bar$tag_id"

	$w.f.volt_back create text [expr $x1] [expr $y2-10] -text NA \
		-tags "text$tag_id"

	$w.f.volt_back create text [expr $x1] [expr $y2-25] -text $bar

	incr tag_id
	incr x1 $gPdInc
    }

    frame $w.buttonbox 
    pack $w.buttonbox -expand yes -fill x -side left

    button $w.buttonbox.dismiss   -bg $gBg1 -fg $gFg1 \
	    -activebackground $gBg1 -activeforeground $gFg1 -text "dismiss" \
	    -command {dismissMe} -font $gFont1

    pack $w.buttonbox.dismiss -fill x 

    #
    # If power data is known, display it.
    #
    if {[lsearch -glob $gPowerList $target*] >= 0} {
        powerDetailUpdate $target
    }

}

#
# A request to display power detail has been noted.
#
proc powerDetail {candidate} {
    global gPowerList
    global gPidMibFresh
    global gHostviewName
    global gMibRefreshFreq

    debug 2 "powerDetail:$candidate"

    #
    # There can only be one copy of this window.
    #
    set w .powerDetail_$candidate
    if [winfo exists $w] {
	raise $w
	return
    }
    # if no power details are up, read the mib
    set count [countDetails power]
    debug 1 "count details: $count"
    if { $count <= 0 } {
	hv_hostinfo -p
    }
    switch $candidate {
	ctr {return}

	csb0 {createPowerSupBoard $candidate }
	csb1 {createPowerSupBoard $candidate }

	cb0 {createPowerConBoard $candidate }
	cb1 {createPowerConBoard $candidate }

	0  {createPowerSysBoard $candidate}
	1  {createPowerSysBoard $candidate}
	2  {createPowerSysBoard $candidate}
	3  {createPowerSysBoard $candidate}
	4  {createPowerSysBoard $candidate}
	5  {createPowerSysBoard $candidate}
	6  {createPowerSysBoard $candidate}
	7  {createPowerSysBoard $candidate}

	8  {createPowerSysBoard $candidate}
	9  {createPowerSysBoard $candidate}
	10 {createPowerSysBoard $candidate}
	11 {createPowerSysBoard $candidate}
	12 {createPowerSysBoard $candidate}
	13 {createPowerSysBoard $candidate}
	14 {createPowerSysBoard $candidate}
	15 {createPowerSysBoard $candidate}

	default {debug 5 "==>SWITCH DEFAULT in powerDetail:$candidate"}
    }
    if ![info exists gPidMibFresh] {
	if [catch {exec hostview_child -M "$gHostviewName $gMibRefreshFreq" &} 	result] {
    		debug 10 $result
	}
    }
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)powerTrap.tcl	1.10	98/12/10 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#

proc powerTrap {board pwr_vals} {
    global gBg1
    global gProblem
    global gHealthy

    global gPowerList
    global gBulkPowerList

    
    global gBackBoards
    global gFrontBoards

    global gBackSysBoards
    global gFrontSysBoards

    global gMAXsb_volt
    global gMAXcsb_volt
    global gMAXcb_volt
    global gMAXctr_volt
    global gMINsb_volt
    global gMINcsb_volt
    global gMINcb_volt

    debug 2 "powerTrap:$board $pwr_vals"


    # if it's not powered, low voltages are ok.
    set state [whatBoardState $board]
    if { [lsearch $state power_on] < 0} {
	set onOff "off"
    } else {
	set onOff "on"
    }

    #
    # Begin by updating the power value list.
    #
    updatePower $board 0 $pwr_vals


    #
    # Refresh the detail form
    #
    set w .powerDetail_$board
    if [winfo exists $w] {
	$w.buttonbox.dismiss config -state disabled
	$w.buttonbox.dismiss config -cursor watch
	powerDetailUpdate $board
	$w.buttonbox.dismiss config -state normal
	$w.buttonbox.dismiss config -cursor arrow
    }
    
    set problem 0
    set count 0
    set brdnum 0

    if {[string first ctr $board] >= 0} {
	# 3+3 voltage sensors (front and back)
	foreach ndx1 $pwr_vals {
	    if { $problem == 0} {
		foreach ndx2 $ndx1 {
		    set color [powerGuageColor $ndx2 ctr-volt $brdnum $count $onOff]
		    if {[string compare $color $gProblem] == 0} {
			debug 1 "powerTrap:$board voltage out of tolerance"
			set problem 1
			break
		    }
		    incr count
		}
		set count 0
	    }
	}
    } elseif {[string first csb $board] >= 0} {
	# #3 voltage 2 current power sensors
	set volts	[lindex $pwr_vals 0]
	#current not supported (later?)
	set amps	[lindex $pwr_vals 1]
	foreach ndx2 $volts {
	    set brdnum [string trimleft "$board" csb]
	    set color [powerGuageColor $ndx2 csb-volt $brdnum $count $onOff ]
	    if {[string compare $color $gProblem] == 0} {
		debug 1 "powerTrap:$board voltage out of tolerance"
		set problem 1
		break
	    }
	    incr count
	}
    } elseif {[string first cb $board] >= 0} {
	# 5 voltage sensors on board, 3 current
	set volts	[lindex $pwr_vals 0]
	set amps	[lindex $pwr_vals 1]
	foreach ndx2 $volts {
	    set brdnum [string trimleft "$board" "cb"]
	    set color [powerGuageColor $ndx2 cb-volt $brdnum $count $onOff]
	    if {[string compare $color $gProblem] == 0} {
		debug 1 "powerTrap:$board voltage out of tolerance"
		set problem 1
		break
	    }
	    incr count
	}
    } else {
	# system board: 5 voltage sensors on board, 5 current
	set volts	[lindex $pwr_vals 0]
	set amps	[lindex $pwr_vals 1]
	foreach ndx2 $volts {
	    set brdnum [string trimleft "$board" sb]
	    set color [powerGuageColor $ndx2 sb-volt $brdnum $count $onOff]
	    if {[string compare $color $gProblem] == 0} {
		debug 1 "powerTrap:$board voltage out of tolerance"
		set problem 1
		break
	    }
	    incr count
	}
    }
    #
    # If there is a power problem, flag the operators attention.
    #
    if {$problem} {
	debug 2 "power problem noted"

	updatePower $board 1 $pwr_vals

	if [winfo exists .iconBar.power] {
		.iconBar.power configure -bg $gProblem
		.iconBar.power.button configure -image powerRed
	}

	if [winfo exists .wPower] {
	    set target ".wPower[sd2path $board]"
	    $target configure -bg $gProblem
	}
    } else {
	if [winfo exists .wPower] {
	    set target ".wPower[sd2path $board]"
	    $target configure -bg $gHealthy
	}

	set problem 0
	foreach ndx $gPowerList {
	    if {[lindex $ndx 1] == 1} {
		set problem 1
		debug 2 $ndx
		break
	    }
	}
	if { [ lsearch [lindex $gBulkPowerList 1] bp* ] > -1 } {
		set problem 1
	}
	if [winfo exists .iconBar.power] {
	    if {$problem == 0} {
	    	.iconBar.power configure -bg $gBg1
	    	.iconBar.power.button configure -image power
	    } else {
	    	.iconBar.power configure -bg $gProblem
	    	.iconBar.power.button configure -image powerRed
	    }
	}
    }

}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)properties.tcl	1.3	96/10/04 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   Define various configuration options.
#   This window is interesting in that the contents of the middle 
#   canvas change depending upon which property category is selected.
#
# proc properties {} 
#   Executive for the properties form.
#
# proc proGeneral {base}
#   Support the "general" category option.
#
# proc proBlacklist {base}
#   Support the "blacklist" category option.
#
# proc proProperties {base} 
#   Support the "dr" category option.
#
# proc proPower {base} 
#   Support the "power" category option.
#
# proc propApply {} 
#   Support the "apply" button.
#
# proc propSelect {arg} 
#   Support the category selection.  This is a binding handler.
#

proc properties {} {
    global gPropVar
    global gPropCategories

    debug 4 "properties"

    set w .properties
    
    #
    # There can only be one copy of this window.
    #
    if [winfo exists $w] {
        raise $w
        return
    } 
    
    set w [toplevel .properties -class proPerties]

    wm title $w "Hostview Properties"

    #
    # .f0 is for entire window
    #
    frame $w.f0
    pack $w.f0 -expand y -fill both

    #
    # .f1 is for category selection
    #
    frame $w.f0.f1
    pack  $w.f0.f1 -expand y -fill x

    label $w.f0.f1.label -text "Category"
    pack  $w.f0.f1.label -expand y -fill x

    frame $w.f0.f1.z
    pack  $w.f0.f1.z -expand y -fill x

    #
    # Define a radio button for each property category.
    # Each button has a binding which will cause the middle canvas
    # to update.
    #
    foreach ndx $gPropCategories {
	switch $ndx {
	    general {
		set textarg $ndx
	    }
	    blacklist {
		set textarg "edit blacklist"
	    }
	    power {
		set textarg $ndx
	    }
	    dr {
		set textarg $ndx
	    }
	}
	radiobutton $w.f0.f1.z.$ndx -text $textarg \
		-variable gPropVar -value $ndx
	pack $w.f0.f1.z.$ndx -side left -expand y -fill x

	bind $w.f0.f1.z.$ndx <Button-1> {propSelect %W}
    }

    #
    # Define, but do not populate the canvas.  
    # This is for the benefit of packer.
    #
    canvas $w.f0.f2
    pack   $w.f0.f2 -fill both -expand y

    #
    # .f3 is button bar
    #
    frame $w.f0.f3
    pack  $w.f0.f3 -expand y -fill x

    foreach ndx {apply save reset dismiss help} {
	switch $ndx {
	    apply {
		set command propApply
	    }
	    save {
		set command dismissMe
	    }
	    reset {
		set command dismissMe
	    }
	    dismiss {
		set command dismissMe
	    }
	    help {
		set command dismissMe
	    }
	}
	
	button $w.f0.f3.$ndx -text $ndx -command $command
	pack   $w.f0.f3.$ndx -side left -expand y -fill x
    }

    #
    # Select a middle canvas
    # 
    propSelect $gPropVar
}

#
# Support General Options
#
proc proGeneral {base} {
    debug 5 "proGeneral:$base"

    debug 5 "proBlacklist:$base"

    set test1 [winfo children $base]

    set base "$base.x"

    if {[llength $test1] > 0} {
	destroy $base
    }

    frame $base -borderwidth 4 -relief groove
    pack  $base -expand y -fill both

    label $base.label1 -text "not implemented"
    pack  $base.label1
}

#
# Support Edit Blacklist Options
#
proc proBlacklist {base} {
    global gEdtBlkSave
    global gEdtBlkSave2
    global gEdtBlkPrint
    global gEdtBlkDir
    global gEdtBlkFile
    global gEdtBlkExt
    global gEdtBlkBackup
    global gEdtBlkBackup2

    debug 5 "proBlacklist:$base"

    set gEdtBlkSave2 $gEdtBlkSave
    set gEdtBlkBackup2 $gEdtBlkBackup

    set test1 [winfo children $base]

    set base "$base.x"

    if {[llength $test1] > 0} {
	destroy $base
    }

    set wid1 20

    frame $base -borderwidth 4 -relief groove
    pack  $base -expand y -fill both

    frame $base.a
    pack  $base.a

    label $base.a.label1 -text "Save Confirmation:" -width $wid1
    pack  $base.a.label1 -side left

    foreach ndx {yes no} {
	radiobutton $base.a.$ndx -text $ndx -variable gEdtBlkSave2 -value $ndx
	pack $base.a.$ndx -side left
    }

    frame $base.b
    pack  $base.b

    label $base.b.label1 -text "Backup:" -width $wid1
    pack  $base.b.label1 -side left

    foreach ndx {yes no} {
	radiobutton $base.b.$ndx -text $ndx -variable gEdtBlkBackup2 \
		-value $ndx
	pack $base.b.$ndx -side left
    }

    frame $base.c
    pack  $base.c

    label $base.c.label1 -text "Print Script:" -width $wid1
    pack  $base.c.label1 -side left

    entry $base.c.entry1 -width 30 -relief sunken
    pack  $base.c.entry1 -side left

    $base.c.entry1 insert 0 $gEdtBlkPrint

    frame $base.d
    pack  $base.d

    label $base.d.label1 -text "Blacklist Directory:" -width $wid1
    pack  $base.d.label1 -side left

    entry $base.d.entry1 -width 30 -relief sunken
    pack  $base.d.entry1 -side left

    $base.d.entry1 insert 0 $gEdtBlkDir

    frame $base.e
    pack  $base.e

    label $base.e.label1 -text "Blacklist Filename:" -width $wid1
    pack  $base.e.label1 -side left

    entry $base.e.entry1  -width 30 -relief sunken
    pack  $base.e.entry1  -side left

    $base.e.entry1 insert 0 $gEdtBlkFile

    frame $base.f
    pack  $base.f

    label $base.f.label1 -text "Backup Extension:" -width $wid1
    pack  $base.f.label1 -side left

    entry $base.f.entry1  -width 30 -relief sunken
    pack  $base.f.entry1  -side left

    $base.f.entry1 insert 0 $gEdtBlkExt
}

#
# Support the DR option
#
proc proProperties {base} {
    global gPropUpdateFlag
    global gPropUpdateValue
    global gPropUpdateFlag2
    global gPropUpdateValue2

    set gPropUpdateFlag2 $gPropUpdateFlag
    set gPropUpdateValue2 $gPropUpdateValue

    debug 5 "proProperties:$base"

    set test1 [winfo children $base]

    set base "$base.x"

    if {[llength $test1] > 0} {
	destroy $base
    }

    frame $base -borderwidth 4 -relief groove
    pack  $base -expand y -fill both

    label $base.label1 -text "Auto Update Cost Information"
    pack  $base.label1

    frame $base.a
    pack  $base.a -expand y

    foreach ndx {yes no} {
	radiobutton $base.a.$ndx -text $ndx -variable gPropUpdateFlag2 \
		-value $ndx
	pack $base.a.$ndx -side left
    }

    label $base.label2 -text "Delay Between Updates"
    pack  $base.label2 -expand y -fill x

    scale $base.scale1 -from 1 -to 60 -orient horizontal \
	    -variable gPropUpdateValue2
    pack  $base.scale1 -expand y -fill x

    $base.scale1 set $gPropUpdateValue2
}

#
# Create the power properties display.
#
proc proPower {base} {
    global gPwrExecFlag
    global gPwrExecFlag2

    global gPwrExecCmd

    debug 5 "proProperties:$base"

    set gPwrExecFlag2 $gPwrExecFlag

    set test1 [winfo children $base]

    set base "$base.x"

    if {[llength $test1] > 0} {
	destroy $base
    }

    frame $base -borderwidth 4 -relief groove
    pack  $base -expand y -fill both

    frame $base.b
    pack  $base.b

    label $base.b.label1 -text "Execute Confirmation:"
    pack  $base.b.label1 -side left

    frame $base.b.a
    pack  $base.b.a -expand y -side left

    foreach ndx {yes no} {
	radiobutton $base.b.a.$ndx -text $ndx -variable gPwrExecFlag2 \
		-value $ndx
	pack $base.b.a.$ndx -side left
    }

    frame $base.c
    pack  $base.c

    label $base.c.label2 -text "Power Command:"
    pack  $base.c.label2 -side left

    entry $base.c.pwrcmd -width 30 -relief sunken
    pack  $base.c.pwrcmd -side left

    $base.c.pwrcmd insert 0 $gPwrExecCmd
}

#
# Apply the current settings.
#
proc propApply {} {
    global gPropVar

    global gPropUpdateFlag
    global gPropUpdateFlag2 

    global gPropUpdateValue
    global gPropUpdateValue2 

    global gPwrExecFlag
    global gPwrExecFlag2

    global gPwrExecCmd
    global gPwrExecCmd2

    global gEdtBlkSave
    global gEdtBlkSave2

    global gEdtBlkPrint
    global gEdtBlkDir
    global gEdtBlkFile
    global gEdtBlkExt

    global gEdtBlkBackup
    global gEdtBlkBackup2

    debug 1 "propApply:$gPropVar"

    switch $gPropVar {
	general {
	}
	blacklist {
	    set gEdtBlkSave $gEdtBlkSave2
	    set gEdtBlkBackup $gEdtBlkBackup2
	    
	    set gEdtBlkPrint [.properties.f0.f2.x.c.entry1 get]
	    set gEdtBlkDir   [.properties.f0.f2.x.d.entry1 get]
	    set gEdtBlkFile  [.properties.f0.f2.x.e.entry1 get]
	    set gEdtBlkExt   [.properties.f0.f2.x.f.entry1 get]
	}
	power {
	    set gPwrExecCmd [.properties.f0.f2.x.c.pwrcmd get]
	    set gPwrExecFlag $gPwrExecFlag2
	    dismissMe
	}
	dr {
	    set gPropUpdateFlag $gPropUpdateFlag2
	    set gPropUpdateValue $gPropUpdateValue2
	    dismissMe
	}
	default {
	    debug 5 "==>SWITCH DEFAULT in propApply:$gPropVar"
	}
    }
}

#
# Service a bind event for a category selection.
#
proc propSelect {arg} {
    global gPropVar

    puts "propSelect:$gPropVar $arg"

    set temp1 [split $arg .]
    set temp2 [lindex $temp1 [expr [llength $temp1]-1]]

    switch $temp2 {
	general {
	    proGeneral .properties.f0.f2
	}
	blacklist {
	    proBlacklist .properties.f0.f2
	}
	power {
	    proPower .properties.f0.f2
	}
	dr {
	    proProperties .properties.f0.f2
	}
    }
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)rmDomain.tcl	1.5	97/03/17 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#	remove a domain from hostview's variables
#

proc rmDomain {domainName} {
    global gDomains
    global gDomainColorMap
    global gDomainColors

    debug 2 "rmDomain:$domainName"

    # the boards were removed by rmBfromDomain

    # find this domain in gDomains
    set ndx [domainIndex $domainName ] 
    if { $ndx < 0 } {
	return ""
    }

    #
    # free the domain color, find it in the map
    #
    set cindx 0
    foreach color $gDomainColorMap {
	if { $color == $ndx } {
	    break
	}
	set cindx [expr $cindx + 1]
    }
    # mark this color free "-1"
    set gDomainColorMap [lreplace $gDomainColorMap $cindx $cindx "-1"]
	debug 1 "rmDomain: gDomainColorMap: $gDomainColorMap"
    set color [lindex $gDomainColors $cindx]

    #set maxdindx [ expr [ llength $gDomains ] - 1 ]
    set cindx2 0
    # removed one domain, so the others shift down
    #
    foreach color $gDomainColorMap {
	if { $color > $ndx } {
	    set gDomainColorMap [lreplace $gDomainColorMap $cindx2 $cindx2 [expr $color -1]]
		debug 1 "rmDomain: gDomainColorMap: $gDomainColorMap"
	} 
	set cindx2 [expr $cindx2 + 1]
    }
    set ddnx 0
    set newdom ""
    foreach dom $gDomains {
	if { $ddnx != $ndx } {
	    set newdom [format "%s {%s}" $newdom [lindex $gDomains $ddnx]]
	    #set newdom "$newdom [lindex $gDomains $ddnx]"
	}
	set ddnx [expr $ddnx + 1]
    }
    set gDomains $newdom

    # remove the domain from the menu bar view
    #
    #set temp1 [whatDomain $domainName]
    #set temp1 [whatDomain $color]
    #if {[llength $temp1] < 1} 
    
    # the menu has 2 items above
    set mentry [expr $ndx + 1 +1]
    #set mentry [expr $ndx + 1 +2] #disabling shared memory changed this count.
    .menuBar.view.m delete $mentry $mentry

    #.menuBar.view.m add command -label $color -background $color\
	    #-command "setDomainView $color"
}

#
# Title: rmBfromDomain
#
# Description:
#	remove a system board from a domain
#

proc rmBfromDomain {board domainName} {
    global gDomains
    global gBg1

    debug 2 "rmBfromDomain:$board $domainName"

    # find domain in gDomains
    set dndx [domainIndex $domainName ] 
    if { $dndx < 0 } {
	return ""
    }

    set temp1 [whatBoardState $board]
    set limit [llength $temp1]
    set result ""

    #
    # Mark domain as "no_domain"
    #
    for {set ndx 1} {$ndx < $limit} {incr ndx} {
	if {$ndx == 1} {
	    set result "$result no_domain"
	} else {
	    set result "$result [lindex $temp1 $ndx]"
	}
    }
    updateBoardList $board $result

    #
    # remove the board from gDomains.
    #
    # {domssp {0}} {domts4 {8 9 10 11}}

    set dom [lindex $gDomains $dndx ]
    set ldndx [lsearch [lindex $dom 1] $board]

    if { $ldndx > -1 } {

	updateDomain $domainName $board delete

	#
	# if that was the last board, remove the domain
	#
	set numbrds [llength [lindex $dom 1] ]
	if { $numbrds == 1 } {
	    debug 1 "removing domain: $domainName"
	    rmDomain $domainName
	}
    }
	
    #actually remove color from the canvas
    setBoardDomainColor $board $gBg1

}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)setDomain.tcl	1.5	97/03/17 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#

proc setDomain {board domainName} {
    global gDomains
    global gDomainColorMap
    global gDomainColors

    debug 2 "setDomain:$board $domainName"
    #debug 2 "setDomain:$board $color"

    set temp1 [whatBoardState $board]
    set limit [llength $temp1]
    set result ""

    #
    # Mark domain
    #
    for {set ndx 1} {$ndx < $limit} {incr ndx} {
	if {$ndx == 1} {
	    set result "$result $domainName"
	} else {
	    set result "$result [lindex $temp1 $ndx]"
	}
    }
    updateBoardList $board $result

    if { [lsearch $temp1 slot_empty] > -1 } {
	return
    }
    #
    # get or assign the domain color
    #

    set ndx [domainIndex $domainName ]
	debug 1 "setDomain: domainIndex: $ndx"

    set cindx 0
    if { $ndx < 0 } {
	# this is a new domain
	debug 1 "setDomain: new domain"
	set dindx [ llength $gDomains ]
	foreach color $gDomainColorMap {
	    if { $color < 0 } {
		# this color is available.
		break
	    } 
	    set cindx [expr $cindx + 1]
	}
	set gDomainColorMap [lreplace $gDomainColorMap $cindx $cindx $dindx]
	debug 1 "setDomain: gDomainColorMap: $gDomainColorMap"
	set color [lindex $gDomainColors $cindx]
    } else {
	debug 1 "gDomainColorMap: $gDomainColorMap"
	debug 1 "gDomainColors: $gDomainColors"
	
	foreach color $gDomainColorMap {
		debug 1 "color: $color index: $ndx"
	    if { $color == $ndx } {
		set color [lindex $gDomainColors $cindx]
		break
	    } else {
		set cindx [expr $cindx + 1]
	    }
	}
    }
    #actually color the canvas
    setBoardDomainColor $board $color
#
#
#

    set temp1 [whatDomain $domainName ]
    if {[llength $temp1] < 1} {
	.menuBar.view.m add command -label $domainName -background $color\
		-command "setDomainView $domainName"

	#.menuBar.view.m add command -label $color -background $color\
		#-command "setDomainView $color"
    }

    if { [lsearch $temp1 $board] < 0 } {
	updateDomain $domainName $board add
    }

    set temp1 [whatBoardState $board]
    set limit [llength $temp1]
    set result ""

    #
    # Mark domain affiliation
    #
    for {set ndx 1} {$ndx < $limit} {incr ndx} {
	if {$ndx == 1} {
	    set result "$result $domainName"
	    #set result "$result $color"
	} else {
	    set result "$result [lindex $temp1 $ndx]"
	}
    }
    updateBoardList $board $result
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)setDomainView.tcl	1.8	97/02/07 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
#   The main GUI has the ability to display subsets of boards based
#   upon domain affiliation.
#

proc setDomainView {domain} {
    global gBg1
    global gBg3
    global gFg1
    global gSelectedBoard
    global gSelectedBoardList
    global gDomainView
    global gGrey

    global gSystemBoards

    debug 2 "setDomainView:$domain"

    if {[string compare $domain all] == 0} {
	if [info exists gDomainView] {
	    unset gDomainView
	}
	foreach board $gSystemBoards {
	    set temp1 [whatBoardState $board]
	    debug 2 "setDomainView:$domain: whatBoardState: $temp1"
	    set temp2 [lindex $temp1 2]
	    if {[string compare $temp2 power_on] == 0} {

		grayedSys $board $gGrey $gGrey
		visibleSys $board $gBg3 $gFg1
	    } else {
		set temp2 [lindex $temp1 3]
		if {[string compare $temp2 slot_loaded] == 0} {
		    grayedSys $board $gGrey $gGrey
		    set dom [whatIsMyDomain $board]
		    if {[string compare $dom "no_domain"] != 0} {
			setDomain $board $dom
		    }
		}
	    }
	}
    } else {
	set gDomainView $domain
	foreach board $gSystemBoards {
	    invisibleSys $board $gBg1 $gBg1 noUpdate
	}

	set candidates [whatDomain $domain]

	foreach board $candidates {
	    #visibleSys $board $gBg3 $gFg1
	    set temp1 [whatBoardState $board]
	    set temp2 [lindex $temp1 2]
	    if {[string compare $temp2 power_on] == 0} {

		grayedSys $board $gGrey $gGrey
		visibleSys $board $gBg3 $gFg1
	    } else {
		set temp2 [lindex $temp1 3]
		if {[string compare $temp2 slot_loaded] == 0} {
		    grayedSys $board $gGrey $gGrey
		    setDomain $board $domain
		}
	    }
	}
	# see if the selection frame still applies
	debug 1 "setDomainView getSelDom: [getSelDom]"
	if { [string compare [ getSelDom ] $domain] != 0 } {
	    if { [string length $gSelectedBoard] > 0 } {
	    if { 0 } {
		if {[string compare [ getSelDom ] "no_domain"] != 0}
	    }

		set result [boardPath $gSelectedBoard]
		$result.select configure -bg $gBg1
		set gSelectedBoard ""

		foreach board $gSelectedBoardList {
		    set result [boardPath $board]
		    $result.select configure -bg $gBg1
		}
		set gSelectedBoardList ""
	    }
	    #explicity select this domain
	    foreach board $candidates {
		set temp1 [whatBoardState $board]
		set temp2 [lindex $temp1 2]

		set result [boardPath $board]
		$result.select configure -bg black
		set gSelectedBoard $board
		break

	    }
	} else {
	    # the main selection frame was still valid, check the rest
	    set newgSelectedBoardList ""
	    foreach board $gSelectedBoardList {
		if { [string compare [ whatIsMyDomain $board ] $domain] != 0 } {
		    set result [boardPath $board]
		    $result.select configure -bg $gBg1
		} else {
		    set newgSelectedBoardList "$newgSelectedBoardList $board"
		}
		  
	    }
	    set gSelectedBoardList $newgSelectedBoardList

	}
    }
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)slotManager.tcl	1.20	99/03/25 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   Routines which manage board insertion/removal from the Xfire card cage.
#

#
# Invoke this routine when a new board is discovered in the card cage.
#
proc boardDiscovered {board} {
    global gGrey
    debug 2 "boardDiscovered:$board"

    set temp1 [whatBoardState $board]
    set limit [llength $temp1]
    set result ""

    #
    # Mark "slot_loaded"
    #
    for {set ndx 1} {$ndx < $limit} {incr ndx} {
	if {$ndx == 3} {
	    set result "$result slot_loaded"
	} else {
	    set result "$result [lindex $temp1 $ndx]"
	}
    }

    updateBoardList $board $result

    #
    # Make visible on main GUI
    #
    set bg1 $gGrey
    set fg1 $gGrey
    if {[string compare ctr $board] == 0} {
	debug 5 "boardDiscovered $gGrey centerboard not yet coded"
    } elseif {[string first csb $board] >= 0} {
	grayedSB $board $bg1 $fg1
    } elseif {[string first cb $board] >= 0} {
	grayedCB $board $bg1 $fg1
    } else {
	grayedSys $board $bg1 $fg1
    }
}
#
# Invoke this routine when a board is removed from the card cage.
#
proc boardRemoved {board} {
    global gGrey
    global gBg1
    global gFg1
    debug 2 "boardRemoved:$board"
    global gSelectedBoard
    global gSelectedBoardList

    set temp1 [whatBoardState $board]
    set limit [llength $temp1]
    set result ""
    
    #
    # Mark "slot_empty"
    #
    for {set ndx 1} {$ndx < $limit} {incr ndx} {
	if {$ndx == 2} {
	    set result "$result power_off"
	} elseif {$ndx == 3} {
	    set result "$result slot_empty"
	} else {
	    set result "$result [lindex $temp1 $ndx]"
	}
    }

    updateBoardList $board $result

    #
    # Make invisible on main GUI
    #
    if {[string first ctr $board] >= 0} {
    } elseif {[string first addr $board] >= 0} {
	grayBus $board
    } elseif {[string first data $board] >= 0} {
	grayBus $board
    } elseif {[string first csb $board] >= 0} {
	invisibleSB $board $gBg1 $gFg1
    } elseif {[string first cb $board] >= 0} {
	invisibleCB $board $gBg1 $gFg1
    } else {
	invisibleSys $board $gBg1 $gFg1 update
    }
    
    #
    # Make visible on detail forms
    #
    systemDisableBoard $board

    # deselect if board was selected

    if { [lsearch $gSelectedBoardList $board ] > -1 ||
	 [ string compare $gSelectedBoard $board ] == 0 } {
	boardSelectTog $board
    }

    # delete from power and thermal lists
    delTemperature $board
    delPower $board
    
}
#
#
#
proc boardPowerDown {board} {
    global gBg1
    global gFg1

    debug 3 "boardPowerDown:$board"

    set temp1 [whatBoardState $board]
    set limit [llength $temp1]
    set result ""

    #
    # Mark "power_off"
    #
    for {set ndx 1} {$ndx < $limit} {incr ndx} {
	if {$ndx == 2} {
	    set result "$result power_off"
	} else {
	    set result "$result [lindex $temp1 $ndx]"
	}
    }
    updateBoardList $board $result

    #
    # Remove from main GUI
    #

    if {[string first ctr $board] >= 0} {
    } elseif {[string first addr $board] >= 0} {
	grayBus $board
    } elseif {[string first data $board] >= 0} {
	grayBus $board
    } elseif {[string first csb $board] >= 0} {
	grayedSB $board $gBg1 $gFg1
    } elseif {[string first cb $board] >= 0} {
	grayedCB $board $gBg1 $gFg1
    } else { 
	invisibleSys $board $gBg1 $gFg1 NOupdate
	set cells [procList $board]
	foreach cell $cells {
	    updateProcList $cell unknown unknown
	}
	grayedSys $board $gBg1 $gFg1
    }

    #
    # Make visible on detail forms
    #
    systemDisableBoard $board
}

#
# Invoke this routine when a board is powered up.
#
proc boardPowerUp {board} {
    global gFg1
    global gBg1
    global gBg3

    debug 2 "boardPowerUp:$board"

    set temp1 [whatBoardState $board]
    set limit [llength $temp1]
    set result ""

    #
    # Mark "power_on"
    #
    for {set ndx 1} {$ndx < $limit} {incr ndx} {
	if {$ndx == 2} {
	    set result "$result power_on"
	} else {
	    set result "$result [lindex $temp1 $ndx]"
	}
    }
    updateBoardList $board $result

    #
    # Make visible on main GUI
    #
    if {[string first ctr $board] >= 0} {
    } elseif {[string first addr $board] >= 0} {
	greenBus $board
    } elseif {[string first data $board] >= 0} {
	greenBus $board
    } elseif {[string first csb $board] >= 0} {
	visibleSB $board $gBg3 $gFg1
    } elseif {[string first cb $board] >= 0} {
	visibleCB $board $gBg3 $gFg1
    } else {
	visibleSys $board $gBg3 $gFg1
    }

    #
    # Make visible on detail forms
    #
    systemEnableBoard $board
}

#
# Define which control board has JTAG
#
proc setJtag {board flag} {
    global gFg1
    global gBg1

    debug 2 "setJtag:$board $flag"

    set temp1 [whatBoardState $board]
    set limit [llength $temp1]
    set result ""

    #
    # Mark "jtag_on" or "jtag_off"
    #
    for {set ndx 1} {$ndx < $limit} {incr ndx} {
	if {$ndx == 4} {
	    set result "$result jtag_$flag"
	} else {
	    set result "$result [lindex $temp1 $ndx]"
	}
    }
    updateBoardList $board $result

    #
    # Make visible on main GUI
    #
    if { [string compare $flag on] == 0 } {
	visibleJtag $board $gBg1 $gFg1
    } else {
	invisibleJtag $board $gBg1 $gBg1
    }
}

#
# Define which control board supplies clock
#
proc setClock {board flag} {
    global gFg1
    global gBg1

    debug 2 "setClock:$board $flag"

    set temp1 [whatBoardState $board]
    set limit [llength $temp1]
    set result ""

    #
    # Mark "clock_on" or "clock_off
    #
    for {set ndx 1} {$ndx < $limit} {incr ndx} {
	if {$ndx == 5} {
	    set result "$result clock_$flag"
	} else {
	    set result "$result [lindex $temp1 $ndx]"
	}
    }
    updateBoardList $board $result

    #
    # Make visible on main GUI
    #
    if { [string compare $flag on] == 0 } {
	visibleClock $board $gBg1 $gFg1
    } else {
	invisibleClock $board $gBg1 $gBg1
    }
}

#
#
#
proc setProcIcon {proc state color} {
    debug 2 "setProcIcon:$proc $state $color"

    updateProcList $proc $state $color
    updateProcIcon $proc
}

proc checkBLprocs { procconfigin } {

    debug 1 "checkBLprocs: $procconfigin"
    
    set procconfig $procconfigin
    #set procconfig [ split $procconfigin - ]
    debug 5 "proc config:  $procconfig"

    foreach proc $procconfig {
			      if { [string first G $proc ] < 0 } {  
				  # this one isn't good
				  set ndx [ expr [string length $proc] -1]
				  set state [ string index $proc $ndx ]
				  set procnum [ string index $proc [expr $ndx -1 ]]
				  set brdnum [ lindex [ split $proc . ] 0 ]
				  set hvprocnum [ expr $brdnum * 4 + $procnum ]
		    
				  if {$hvprocnum < 10 } {
				      debug 1 "setProcIconBl 0$hvprocnum  $state $brdnum"
				      setProcIconBl 0$hvprocnum  $state $brdnum
				  } else {
				      debug 1 "setProcIconBl: $hvprocnum $state $brdnum"
				      setProcIconBl $hvprocnum $state $brdnum
				  }
			      }
			  }
}

#
# domain based proc info 
# black and redlist
# this is only called if the proc is not G  (not good)
#
proc setProcIconBl {proc instate board } {
    debug 2 "setProcIconBL:$proc $instate $board"

    # return if it's missing

    set state unknown

	#R { set state redlist }
    switch $instate {
	B { set state blacklist }
	U { set state present }
	M { return }
	default { return }
    }

    debug 1 "updateProcList: $proc none $state"
    updateProcList $proc none $state

    # make sure the board is powered, or don't color it
    set brdstate [whatBoardState $board]
    if { [lsearch $brdstate power_on] > -1 } {
	updateProcIcon $proc
	debug 1 "updateProcIcon: $proc"
    }
}

# Invoke this routine when a new fan_bp is discovered in the card cage.
#
# come back and code this!
#
proc fan_bpDiscovered {fan_bp flag} {
    global gGrey
    global gFanList
    global gEveready
    debug 2 "fan_bpDiscovered:$fan_bp $flag"

    #set temp1 [whatFan_BpState $fan_bp]
    set temp1 ""
    set limit [llength $temp1]
    set result ""

    #
    # Mark "slot_loaded"
    #
    #check if fan_bp is 0 or ft0 or ft0b
    #high { ft0b} {ft0 ft1}", speed for all { failed list } {powered}
    if { [lsearch [lindex $gFanList 1] $fan_bp] > -1} {
    }
    for {set ndx 1} {$ndx < $limit} {incr ndx} {
	if {$ndx == 3} {
	    set result "$result slot_loaded"
	} else {
	    set result "$result [lindex $temp1 $ndx]"
	}
    }

    #updateFan_BpList $fan_bp $result

    #
    # Mark slot present on main GUI
    #
    if {[string compare $flag bpower] == 0} {
	if { $fan_bp >= 8 } {
	    set gEveready 1
	    showEveready
	}
	# only lite the power supply if we haven't already
	set bulkfail [whatBpFailure]
	set bulkconf [whatBPconf]

	set ndx [lsearch $bulkfail "bp$fan_bp"]
	if { $ndx < 0 } {
	    # it looks good, assume it is powered
	    litePs bp$fan_bp
	} else {
	    # it is failing, and we've not received a normal trap yet
	    failPs bp$fan_bp
	}
    } elseif {[string first ft $fan_bp] >= 0} {
	liteFan $fan_bp
    }
}
# Invoke this routine when a fan or bulk power supply
# is removed from the card cage.
#
# come back and code this!
#
proc fan_bpRemoved {fan_bp flag} {
    global gGrey
    debug 2 "fan_bpRemoved:$fan_bp $flag"

    #set temp1 [what${flag}State $fan_bp]
    set temp1 ""
    set limit [llength $temp1]
    set result ""
    
    #
    # Mark "slot_empty"
    #
    for {set ndx 1} {$ndx < $limit} {incr ndx} {
	if {$ndx == 2} {
	    set result "$result power_off"
	} elseif {$ndx == 3} {
	    set result "$result slot_empty"
	} else {
	    set result "$result [lindex $temp1 $ndx]"
	}
    }

    #updateFan_BpList $fan_bp $result

    #
    # Mark slot empty on main GUI
    #
    if {[string first bp $fan_bp] >= 0} {
	dimPs $fan_bp
    } elseif {[string first ft $fan_bp] >= 0} {
	dimFan $fan_bp
    }
    
    #
    # Make visible on detail forms
    #
    #systemDisableFan_Bp $fan_bp
}
proc liteFan { ft } {
    global gHealthy
    global gBg2
    global gFg1

    set option Fan
    set w .w$option
 
    #
    # There can only be one copy of this window.
    #
    if [winfo exists $w] {
	set target "$w[sd2path $ft]"
	$target.icon configure -state normal -bg $gHealthy \
		-activebackground $gBg2 -command fanDetail
	$target.id configure -fg $gFg1
    }
}
proc dimFan { ft } {
    global gBg1
    global gBg2
    global gFg1

    set option Fan
    set w .w$option
 
    #
    # There can only be one copy of this window.
    #
    if [winfo exists $w] {
	set target "$w[sd2path $ft]"
	$target.icon configure -state normal -bg $gBg1 \
		-activebackground $gBg2 -command fanDetail
	$target.id configure -fg $gFg1
    }
}
proc litePs { bp } {
    global gHealthy
    global gBg2

    set option Power
    set w .w$option
 
    #
    # There can only be one copy of this window.
    #
    if [winfo exists $w] {
	set target "$w[sd2path $bp]"
	$target configure -state disabled -bg $gHealthy \
		-activebackground $gBg2 -command powerDetailDispatch
    }
}
proc dimPs { bp } {
    global gBg1
    global gFg1

    set option Power
    set w .w$option
 
    #
    # There can only be one copy of this window.
    #
    if [winfo exists $w] {
	set target "$w[sd2path $bp]"
	$target configure -state disabled -bg $gBg1 -fg $gFg1 \
		-command ""
    }
}
proc failPs { bp } {
    global gProblem
    global gBg2

    set option Power
    set w .w$option
 
    #
    # There can only be one copy of this window.
    #
    if [winfo exists $w] {
	set target "$w[sd2path $bp]"
	$target configure -state disabled -bg $gProblem \
		-activebackground $gBg2 -command powerDetailDispatch
    }
}

#
# This makes eveready supplies visible by mapping them.
#
proc showEveready {} {
    global gEveready
    if { $gEveready == 0 } {
	# not an eveready system
	return
    }
    foreach w { .wPower .wFan .wThermal } {
	if [winfo exists $w] {
	    pack "$w.canvas.sub2.back.top.eveready" -side left
	    pack "$w.canvas.sub2.front.top.eveready" -side right
	}
    }
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)sspUtils.tcl	1.12	98/12/10 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#

#
#
# Define the max and min thermal and power thresholds.
# from the ssp_resource file.
#
#


proc hvResources {} {
	global env
    global gWARNasic
    global gMAXasic
    global gT911asic
    global gWARNproc
    global gMAXproc
    global gT911proc
    global gWARNps
    global gMAXps
    global gT911ps
    global gWARNamb
    global gMAXamb
    global gT911amb
    
    global gVoltDefaultMAX
    global gVoltDefaultMIN

    global gMAXsys33vdd
    global gMINsys33vdd
    global gMAXsys5vdchk
    global gMINsys5vdchk
    global gMAXsys5vdc
    global gMINsys5vdc
    global gMAXsysvddcore
    global gMINsysvddcore
    global gMAXsys33vdchk
    global gMINsys33vdchk


    global gMAXsuppBrd5vdchk
    global gMINsuppBrd5vdchk
    global gMAXsuppBrd33vdchk
    global gMINsuppBrd33vdchk
    global gMAXsuppBrd33vdc0
    global gMINsuppBrd33vdc0

    global gMAXcontrol33vdc
    global gMINcontrol33vdc
    global gMAXcontrol5vdc
    global gMINcontrol5vdc
    global gMAXcontrol5vdchk
    global gMINcontrol5vdchk

    global gMAXsb_volt
    global gMINsb_volt
    global gMINsb_voltOff
    global gMAXcb_volt
    global gMINcb_volt
    global gMINcb_voltOff
    global gMAXcsb_volt
    global gMINcsb_volt
    global gMINcsb_voltOff

	global gPlatformType

    # initialize
    set gWARNasic 60
    set gMAXasic 80
    set gT911asic 85
    set gWARNproc 60
    set gMAXproc 80
    set gT911proc 85
    set gWARNps 80
    set gMAXps 92
    set gT911ps 100
    set gWARNamb 40
    set gMAXamb 45
    set gT911amb 50
    
    set gMINsys33vdd 3.1
    set gMAXsys5vdchk 5.2
    set gMINsys5vdchk 4.7
    set gMAXsys5vdc 5.2
    set gMINsys5vdc 4.7
    set gMAXsysvddcore 3.4
    set gMINsysvddcore 1.4
    # these bracket all possible processor types on a Starfire
    set gMAXsysvddcore 3.70
    set gMINsysvddcore 1.35
    set gMAXsys33vdchk 3.4
    set gMINsys33vdchk 3.1

    set gMAXsuppBrd5vdchk 5.25
    set gMINsuppBrd5vdchk 4.75
    set gMAXsuppBrd33vdchk 3.47
    set gMINsuppBrd33vdchk 3.13
    set gMAXsuppBrd33vdc0 3.47
    set gMINsuppBrd33vdc0 3.13


    set gMAXcontrol33vdc 3.4
    set gMINcontrol33vdc 3.1
    set gMAXcontrol5vdc 5.2
    set gMINcontrol5vdc 4.7
    set gMAXcontrol5vdchk 5.2
    set gMINcontrol5vdchk 4.7
    #
    set gMAXcontrolvccper 5.2
    set gMINcontrolvccper 4.0
    set gMAXcontrolvccfan 5.2
    set gMINcontrolvccfan 4.0
    #set gMAXsupp5vdchk 5.2
    #set gMINsupp5vdchk 4.7
    #set gMAXsupp33vdchk 3.4
    #set gMINsupp33vdchk 3.1

    # Ultra Enterprise platform type
    if { [ catch  { set gPlatformType  [lindex [lindex [get_cb_config] 0] 1]} errMsg ] } {
	# Log errMsg message to messages file
	logMessage $errMsg "hostview"
	return
    } 

    set gWARNasic [format "%.5s" [expr [ssp_get_resource $gPlatformType.WARNasic] /1000.0]]
    set gMAXasic [format "%.5s" [expr [ssp_get_resource $gPlatformType.MAXasic]  /1000.0]]
    set gT911asic [format "%.5s" [expr [ssp_get_resource $gPlatformType.T911asic]  /1000.0]]
    
    set gWARNproc [format "%.5s" [expr [ssp_get_resource $gPlatformType.WARNproc]   /1000.0]]
    set gMAXproc [format "%.5s" [expr [ssp_get_resource $gPlatformType.MAXproc] 	    /1000.0]]
    set gT911proc [format "%.5s" [expr [ssp_get_resource $gPlatformType.T911proc] /1000.0]]
    
    set gWARNps [format "%.5s" [expr [ssp_get_resource $gPlatformType.WARNps]    /1000.0]]
    set gMAXps [format "%.5s" [expr [ssp_get_resource $gPlatformType.MAXps] \
	    /1000.0]]
    set gT911ps [format "%.5s" [expr [ssp_get_resource $gPlatformType.T911proc] 	    /1000.0]]
    
    set gWARNamb [format "%.5s" [expr [ssp_get_resource $gPlatformType.WARNamb] 	    /1000.0]]
    set gMAXamb [format "%.5s" [expr [ssp_get_resource $gPlatformType.MAXamb]	    /1000.0]]
    set gT911amb [format "%.5s" [expr [ssp_get_resource $gPlatformType.T911amb]	    /1000.0]]



    set gMAXsys33vdd [format "%.5s" [expr [ssp_get_resource $gPlatformType.MAXsys33vdd]	/1000.0]]
    set gMINsys33vdd [format "%.5s" [expr [ssp_get_resource $gPlatformType.MINsys33vdd]	/1000.0]]
    set gMAXsys5vdchk [format "%.5s" [expr [ssp_get_resource $gPlatformType.MAXsys5vdchk]	/1000.0]]
    set gMINsys5vdchk [format "%.5s" [expr [ssp_get_resource $gPlatformType.MINsys5vdchk]	/1000.0]]
    set gMAXsys5vdc [format "%.5s" [expr [ssp_get_resource $gPlatformType.MAXsys5vdc ]	/1000.0]]
    set gMINsys5vdc [format "%.5s" [expr [ssp_get_resource $gPlatformType.MINsys5vdc ]	/1000.0]]
#    set gMAXsysvddcore [format "%.5s" [expr [ssp_get_resource $gPlatformType.MAXsysvddcore ]	/1000.0]]
#    set gMINsysvddcore [format "%.5s" [expr [ssp_get_resource $gPlatformType.MINsysvddcore ]	/1000.0]]
#    set gMAXsysvddcore [format "%.5s" [expr [ssp_get_resource $gPlatformType.MAXsysvddcore ]	/1000.0]]
#    set gMINsysvddcore [format "%.5s" [expr [ssp_get_resource  $gPlatformType.MINsysvddcore ]	/1000.0]]
    set gMAXsys33vdchk [format "%.5s" [expr [ssp_get_resource $gPlatformType.MAXsys33vdchk ]	/1000.0]]
    set gMINsys33vdchk [format "%.5s" [expr [ssp_get_resource $gPlatformType.MINsys33vdchk ]	/1000.0]]
    set gMAXsuppBrd5vdchk [format "%.5s" [expr [ssp_get_resource $gPlatformType.MAXsuppBrd5vdchk ]	/1000.0]]
    set gMINsuppBrd5vdchk [format "%.5s" [expr [ssp_get_resource $gPlatformType.MINsuppBrd5vdchk ]	/1000.0]]
    set gMAXsuppBrd33vdchk [format "%.5s" [expr [ssp_get_resource $gPlatformType.MAXsuppBrd33vdchk ]	/1000.0]]
    set gMINsuppBrd33vdchk [format "%.5s" [expr [ssp_get_resource $gPlatformType.MINsuppBrd33vdchk ]	/1000.0]]
    set gMAXsuppBrd33vdc0 [format "%.5s" [expr [ssp_get_resource $gPlatformType.MAXsuppBrd33vdc0 ]	/1000.0]]
    set gMINsuppBrd33vdc0 [format "%.5s" [expr [ssp_get_resource $gPlatformType.MINsuppBrd33vdc0 ]	/1000.0]]

    set gMAXcontrol33vdc [format "%.5s" [expr [ssp_get_resource $gPlatformType.MAXcontrol33vdc ]	/1000.0]]
    set gMINcontrol33vdc [format "%.5s" [expr [ssp_get_resource $gPlatformType.MINcontrol33vdc ]	/1000.0]]
    set gMAXcontrol5vdc [format "%.5s" [expr [ssp_get_resource $gPlatformType.MAXcontrol5vdc ]	/1000.0]]
    set gMINcontrol5vdc [format "%.5s" [expr [ssp_get_resource $gPlatformType.MINcontrol5vdc ]	/1000.0]]
    
    set gMAXcontrol5vdchk  [format "%.5s" [expr [ssp_get_resource $gPlatformType.MAXcontrol5vdchk ]	/1000.0]]
    set gMINcontrol5vdchk [format "%.5s" [expr [ssp_get_resource $gPlatformType.MINcontrol5vdchk ]	/1000.0]]

    set gMAXcontrolvccper  [format "%.5s" [expr [ssp_get_resource $gPlatformType.MAXcontrolvccper ]	/1000.0]]
    set gMINcontrolvccper [format "%.5s" [expr [ssp_get_resource $gPlatformType.MINcontrolvccper ]	/1000.0]]

    set gMAXcontrolvccfan  [format "%.5s" [expr [ssp_get_resource $gPlatformType.MAXcontrolvccfan ]	/1000.0]]
    set gMINcontrolvccfan [format "%.5s" [expr [ssp_get_resource $gPlatformType.MINcontrolvccfan ]	/1000.0]]


    set gMAXsb_volt "$gMAXsys33vdd $gMAXsys5vdchk $gMAXsys5vdc $gMAXsysvddcore $gMAXsys33vdchk"
    set gMINsb_volt "$gMINsys33vdd $gMINsys5vdchk $gMINsys5vdc $gMINsysvddcore $gMINsys33vdchk"
    set gMINsb_voltOff "-1 $gMINsys5vdchk -1 -1 $gMINsys33vdchk"

    set gMAXcb_volt "$gMAXcontrol5vdc $gMAXcontrol5vdchk $gMAXcontrol33vdc $gMAXcontrolvccper $gMAXcontrolvccfan"
    set gMINcb_volt "$gMINcontrol5vdc $gMINcontrol5vdchk $gMINcontrol33vdc $gMINcontrolvccper $gMINcontrolvccfan"
    set gMINcb_voltOff "-1 $gMINcontrol5vdchk -1 -1 -1"

    set gMAXcsb_volt "$gMAXsuppBrd33vdc0 $gMAXsuppBrd5vdchk $gMAXsuppBrd33vdchk"
    set gMINcsb_volt "$gMINsuppBrd33vdc0 $gMINsuppBrd5vdchk $gMINsuppBrd33vdchk"
    set gMINcsb_voltOff "-1 $gMINsuppBrd5vdchk $gMINsuppBrd33vdchk"

    set gVoltDefaultMAX $gMAXsys5vdchk
    set gVoltDefaultMIN $gMINsys33vdchk

    debug 2 "gMAXsb_volt: $gMAXsb_volt"
    debug 2 "gMINsb_volt: $gMINsb_volt"
    debug 2 "gMINsb_voltOff: $gMINsb_voltOff"

    debug 2 "gMAXcb_volt: $gMAXcb_volt"
    debug 2 "gMINcb_volt: $gMINcb_volt"
    debug 2 "gMINcb_voltOff: $gMINcb_voltOff"

    debug 2 "gMAXcsb_volt: $gMAXcsb_volt"
    debug 2 "gMINcsb_volt: $gMINcsb_volt"
    debug 2 "gMINcsb_voltOff: $gMINcsb_voltOff"



}
#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)stale.tcl	1.8	97/01/31 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#	Periodically read the Mib and popup window
#	if MIB does not respond.
#
# notes:
# if snmp answers, destroy popup if it exists.
# if snmp doesn't answer, leave popup or create popup.
# snmp gets $retries tries to answer.
#


proc staleState {} {
    global gMibTouched
    global testfail
    global gDebugThreshold
    global staleStateTest

    debug 1 "staleState"

    set dialog .dlg

    set platform [eval hv_hostinfo -n]

    #after does not work as desired here, and sleep would hang hostview
    if { 0 } {
	set retries 3
	set retrytime 1000; #milliseconds
	for { set i 0} { $i < $retries } {incr i} {
	    if { [string compare $platform ""] == 0 } {
		after $retrytime "set platform [eval hv_hostinfo -n]"
	    } else {
		break
	    }
	}
    }

    #for testing
    if { [info exists staleStateTest] } {
	incr testfail
	if { [expr $testfail % 5] == 0} {
	    set platform ""
	}
    }
  
    #
    #may want to change warning bitmap to error bitmap

    if { [string compare $platform ""] != 0 } {
	if [winfo exists $dialog] {
	    destroy $dialog
	}
    } else {
	if ![winfo exists $dialog] {
	    set result [hv_tk_dialog $dialog "Hostview Warning" \
		    "Stale state.  No response from SNMP manager." \
		    warning 0 OK Cancel]
	}
    }
    set gMibTouched 0
    return
}
proc MIBmonitor {} {

    debug 1 "MIBmonitor"
    set act [eval wasMIBtouched]
    if { $act } {
	staleState
    } else {
	if [winfo exists .dlg] {
	    destroy .dlg
	}
    }
    return
}
proc wasMIBtouched {} {
    global gMibTouched
    
    if { $gMibTouched } {
	set gMibTouched 0
	return 0
    } 
    return 1
}

# staleDriver is exec-ed (via hostview_child)
# it loops forever, and invokes staleState periodically.
#
proc staleDriver { hostviewName pollfreq } {
    global gHvName

    debug 1 "staleDriver: $pollfreq  $hostviewName"

    if { [string first # $hostviewName] > -1 } {
	set gHvName [split $hostviewName #]
	set gHvName [lreplace $gHvName 1 1 #[lindex $gHvName 1]]
	debug 1 "gHvName $gHvName"
    } else {
	set gHvName $hostviewName
    }
    #destroy .

    while { 1 } {
	sleep $pollfreq
	sendMsg
    }

}
proc sendMsg {} {
    global gHvName

    debug 1 "sendMsg:$gHvName"
    #set retstatus [send $dest]
	debug 4 "mib poll event"
    if { [ catch {send $gHvName MIBmonitor} errmsg ] } {
	debug 4 "Error: $errmsg"
    }
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)sysDetailUtils.tcl	1.17	99/12/22 SMI"
#
# Copyright (c) 1996, 1999 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   Routines which support different systemDetail forms.
#
# Create a systemDetail form for thermal activity.
#   proc decorateThermal {base} 
#
# Create a systemDetail form for power activity.
#   proc decoratePower {base} 
#
# Create a systemDetail form for fan activity.
#   proc decorateFan {base} 
#
# Button-3 support, determine the board and invoke the detail.
#   proc powerDetailDispatch { }
#
# Button-3 support, determine the board and invoke the detail.
#   proc thermalDetailDispatch { }
#
# Grey out a disabled board.
#   proc systemDisableBoard {board} 
#
# Color a newly board.
#   proc systemEnableBoard {board} 
#

#
# Decorate a systemDetail template for thermal.
#
proc decorateThermal {base} {
    global gBg2
    global gHealthy
    global gProblem
    global gBackBoards
    global gFrontBoards
    global gThermalList

    debug 2 "decorateThermal:$base"

    # if no thermal details are up, read the mib
    set count [countDetails thermal]
    debug 1 "count details: $count"
    if { $count <= 1 } {
	if {[catch [ tkwait visibility $base ] result] } {
	    debug 4 $result
	    return
	}
	hv_hostinfo -t
    }
    
    #
    # Enable front system boards
    #
    foreach board $gFrontBoards {
	set temp1 [whatBoardState $board]
	set temp2 [lindex $temp1 3]
	if {[string compare slot_loaded $temp2] == 0} {
	    set temp1 [whatTemperature $board]
	    set temp2 [lindex $temp1 1]
	    if {$temp2 == 1} {
		set color $gProblem
	    } else {
		set color $gHealthy
	    }
	    set target "$base[sd2path $board]"
	    $target configure -state normal -bg $color \
		    -activebackground $gBg2 \
		    -command thermalDetailDispatch
	}
    }

    #
    # Enable back system boards
    #
    foreach board $gBackBoards {
	set temp1 [whatBoardState $board]
	set temp2 [lindex $temp1 3]
	if {[string compare slot_loaded $temp2] == 0} {
	    set temp1 [whatTemperature $board]
	    set temp2 [lindex $temp1 1]
	    if {$temp2 == 1} {
		set color $gProblem
	    } else {
		set color $gHealthy
	    }
	    set target "$base[sd2path $board]"
	    $target configure -state normal -bg $color \
		    -activebackground $gBg2 \
		    -command thermalDetailDispatch
	}
    }

    #
    # Enable buss
    #
    foreach board {ctr} {
    #foreach buss {ctr}
	set temp1 [whatBoardState $board]
	set temp2 [lindex $temp1 3]
	if {[string compare slot_loaded $temp2] == 0} {
	    set temp1 [whatTemperature $board]
	    set temp2 [lindex $temp1 1]
	    if {$temp2 == 1} {
		set color $gProblem
	    } else {
		set color $gHealthy
	    }
	    set target "$base[sd2path $board]"
    	    $target configure -state normal -bg $color \
		    -activebackground $gBg2 \
		    -command thermalDetailDispatch
	}
    }
}

#
# Determine which window is active, invoke thermal detail.
#
proc thermalDetailDispatch { } {
    debug 2 "thermalDetailDispatch"

    set geox [winfo pointerx .]
    set geoy [winfo pointery .]

    set temp1 [winfo containing $geox $geoy]

    set temp2 [split $temp1 .]
    set temp3 [llength $temp2]
    incr temp3 -1

    thermalDetail [lindex $temp2 $temp3]
}

#
# Show eveready power supplies conditionally
#
proc decorateEveready {} {
    global gBulkPowerEveready
    global gEveready
    set bulkconf [whatBPconf]

    # bug#4288061: need to check for failed power supplies too
    set bulkfail [whatBpFailure]

    if { $gEveready != 0 } {
	# its there, so show it
	showEveready
	# no need to check
	return
    }

    # we check to see if Eveready option is installed
    # first check for configured (and powered on) power supplies
    foreach bp $gBulkPowerEveready {
	set ndx [lsearch $bulkconf $bp]
	if {$ndx >= 0} {
	    set gEveready 1
	    showEveready
	    # found one, no more checking needed
	    return
	}
    }

    # bug#4288061: also check for failed power supplies
    foreach bp $gBulkPowerEveready {
	set ndx [lsearch $bulkfail $bp]
	if {$ndx >= 0} {
	    set gEveready 1
	    showEveready
	    # found one, no more checking needed
	    return
	}
    }

    # must not be an eveready system
}

#
# Create a system detail for Power systems
#
proc decoratePower {base} {
    global gBg2
    global gHealthy
    global gProblem
    global gPowered
    global gPowerList

    global gBulkPower

    global gBackBoards
    global gFrontBoards

    debug 2 "decoratePower:$base"
    
    # if no power details are up, read the mib
    set count [countDetails power]
    debug 1 "count details: $count"
    if { $count <= 1 } {
	if {[catch [ tkwait visibility $base ] result] } {
	    debug 4 $result
	    return
	}
	hv_hostinfo -p
    }

    set bulkconf [ whatBPconf ]
    set bulkfailed [ whatBpFailure ]
    debug 1 "decoratePower: bulkconf: $bulkconf bulkfailed: $bulkfailed"
    #
    # Enable all bulk power supplies
    #
    foreach board $gBulkPower {
	set ndx [lsearch $bulkconf $board]
	if {$ndx >= 0} {
	    set target "$base[sd2path $board]"
	    $target configure -state disabled -bg $gHealthy \
		-activebackground $gBg2 -command powerDetailDispatch
	} else { 
	    set ndx [lsearch $bulkfailed $board]
	    if {$ndx >= 0} {
		set target "$base[sd2path $board]"
		$target configure -state disabled -bg $gProblem \
		    -activebackground $gBg2 -command powerDetailDispatch
	    }
	}
    }

    #
    # Enable individual board power for front boards.
    #
    foreach board $gFrontBoards {
	set temp1 [whatBoardState $board]
	set temp2 [lindex $temp1 3]
	if {[string compare slot_loaded $temp2] == 0} {
	    set temp1 [whatPower $board]
            set temp2 [lindex $temp1 1]
            if {$temp2 == 1} {
                set color $gProblem
            } else {
                set color $gHealthy
            }

	    set target "$base[sd2path $board]"
	    $target configure -state normal -bg $color \
		    -activebackground $gBg2 -command powerDetailDispatch
	}
    }

    #
    # Enable individual board power for back boards.
    #
    foreach board $gBackBoards {
	set temp1 [whatBoardState $board]
	set temp2 [lindex $temp1 3]
	if {[string compare slot_loaded $temp2] == 0} {
	    set temp1 [whatPower $board]
            set temp2 [lindex $temp1 1]
            if {$temp2 == 1} {
                set color $gProblem
            } else {
                set color $gHealthy
            }

	    set target "$base[sd2path $board]"
	    $target configure -state normal -bg $color \
		    -activebackground $gBg2 -command powerDetailDispatch
	}
    }

    #
    # Center Board Power
    #	disabled 10 96 Mari Mortell

    if { 0 } {
	foreach board {ctr} {
	    set temp1 [whatBoardState $board]
	    set temp2 [lindex $temp1 2]
	    if {[string compare power_on $temp2] == 0} {
		set temp1 [whatPower $board]
		set temp2 [lindex $temp1 1]
		if {$temp2 == 1} {
		    set color $gProblem
		} else {
		    set color $gHealthy
		}
		
		set target "$base[sd2path $board]"
		$target configure -state normal -bg $color \
			-activebackground $gBg2 -command powerDetailDispatch
	    }
	}
    }
}

#
# Determine which window is active, invoke power detail.
#
proc powerDetailDispatch { } {
    debug 2 "powerDetailDispatch"

    set geox [winfo pointerx .]
    set geoy [winfo pointery .]

    set temp1 [winfo containing $geox $geoy]

    set temp2 [split $temp1 .]
    set temp3 [llength $temp2]
    incr temp3 -1

    powerDetail [lindex $temp2 $temp3]
}

#
# Create the Fan Overview
#
proc decorateFan {base} {
    global gFg1
    global gBg1
    global gBg2
    global gProblem
    global gHealthy
    global gGrey
    global gFanDrawers

    debug 2 "decorateFan:$base"

    # if no fan details are up, read the fan mib
    set count [countDetails fan]
    debug 1 "count details: $count"
    if { $count <= 1 } {
	if {[catch [ tkwait visibility $base] result] } {
	    debug 4 $result
	    return
	}
	hv_hostinfo -f
    }
    set failures [whatFanFailure]
    set speed [whatFanSpeed]
    set fanpwrlist [whatFansPowered]
    set badtrays ""
    foreach ndx $failures {
	set temp1 [string trim $ndx ab]
	set badtrays "$badtrays $temp1"
    }
    
    foreach drawer $gFanDrawers {
	set target "$base[sd2path $drawer]"
	debug 1 $target
	
	set failndx [lsearch $badtrays $drawer]
	if {$failndx < 0} {
	    set pwrndx [lsearch $fanpwrlist $drawer]
	    if { $pwrndx >= 0 } { 
		if {[string compare $speed high] == 0} {
		    set color goldenrod
		} elseif {[string compare $speed nominal] == 0} {
		    set color $gHealthy
		}
	    } else {
		set color $gGrey
	    } 
	} else {
	    set color $gProblem
	}
	$target.icon configure -state normal -bg $color \
		-activebackground $gBg2 -command fanDetail
	$target.id configure -fg $gFg1 
    }

    frame $base.canvas.leg -bg $gBg1 -borderwidth 2
    #frame $base.canvas.leg -borderwidth 2
    pack  $base.canvas.leg -fill both -expand yes \
	    -padx 2m -pady 1m -side bottom

    label $base.canvas.leg.leg1 -text "nominal speed: green" -bg $gBg1
    label $base.canvas.leg.leg2 -text "high speed: amber" -bg $gBg1
    pack  $base.canvas.leg.leg1 $base.canvas.leg.leg2 -side left -expand yes -fill both

}

#
# A board has become disabled.  bug fix 4036323, leave it active
#
proc systemDisableBoard {board} {
    global gFg1
    global gBg1

    debug 2 "systemDisableBoard:$board"

    foreach base {.wPower .wThermal} {
	if [winfo exists $base] {
	    set target [sd2path $board]
	    $base$target configure -bg $gBg1 
	}
    }
}

#
# A board has become enabled.  Color it.
#
proc systemEnableBoard {board} {
    global gHealthy

    debug 2 "systemEnabledBoard:$board"

    set base .wThermal
    if [winfo exists $base] {
	set target [sd2path $board]
	$base$target configure -state normal -bg $gHealthy \
		-command thermalDetailDispatch
    }

    set base .wPower 
    if [winfo exists $base] {
	set target [sd2path $board]
	$base$target configure -state normal -bg $gHealthy \
		-command powerDetailDispatch
    }
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***

#
# ident	"@(#)sysGraphUtils.tcl	1.23	99/01/14 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   Supporting routines for the systemGraphic display.
#
# Update a processor icon:
#   proc updateProcIcon {procid symbol}
#   proc getImage { signiture }
#
# Make a support board visible:
#   proc visibleSB {target bg1 fg1}
#
# Make a "grayed out" support board.
#   proc grayedSB {target bg1 fg1}
#
# Make a control board visible:
#   proc visibleCB {target bg1 fg1}
#
# Make a "grayed out" control board.
#   proc grayedCB {target bg1 fg1}
#
# Make a system board visible:
#   proc visibleSys {target bg1 fg1}
#
# Make a "grayed out" system board:
#   proc grayedSys {target bg1 fg1}
#
# Make a system board invisible:
#   proc invisibleSys {target bg1 fg1 procStateFlag}
#
# Set a Control Board to provide JTAG
#   proc visibleJtag {target bg1 fg1}
#
# Set a Control Board to provide clock
#   proc visibleClock {target bg1 fg1}
#
# Select a board on the main GUI (Button 1 event).
#   proc boardSelect {arg}
#
# Set a buss state (color)
#   proc bussState {buss bg1 fg1}
#
# Set a domain color
#   proc setBoardDomainColor {board color}
#

# Update a processor icon.
# procid = processor id in the range 0..63
#
proc updateProcIcon {procid} {
    debug 2 "updateProcIcon:$procid"

    set target [procPath $procid]
    set target "$target.icon"

    set temp1 [whatProcState $procid]
    
    set symbol [getImage [lindex $temp1 0]]
    set color  [iconRunColor [lindex $temp1 1]]

    $target configure -image $symbol -bg $color
}
proc getImage { signiture } {

    switch $signiture {
	"download-helper" { set signiture dhlp }
	"open-boot-prom"  { set signiture obp }
	"power-on-selftest" { set signiture post }
	"operating-system" { set signiture os }
	"dummy"		{ set signiture dummy }
	"empty"		{ set signiture dummy }
	"none"		{ set signiture dummy }
	"unknown"	{ set signiture ques }
    }
    switch $signiture {
	dhlp {}
	obp {}
	post {}
	os {}
	ques {}
	dummy {}
	default {
	    debug 5 "==>SWITCH DEFAULT in getImage:$signiture"
	    set signiture ques
	}
    }
    return $signiture
}
#
# Make a support board (sb0, sb1) visible.  Establish bindings.
# Make a support board (csb0, csb1) visible.  Establish bindings.
# target = csb0, csb1
#
proc visibleSB {target bg1 fg1} {
    debug 1 "visibleSB:$target $bg1 $fg1"

    set result [boardPath $target]
    set winboard $result.select.domain

    $winboard configure -bg $bg1 -relief groove
    #$winboard configure -bg blue -relief groove
    $winboard.board configure -bg $bg1 -relief raised
    #$winboard.board configure -bg blue -relief raised

    #bind $winboard.board.cell <Button-1> {boardSelect %W}
    bind $winboard.board.cell <Button-3> {detailPopup %W}

    #bind $winboard.board.cell.id <Button-1> {boardSelect %W}
    bind $winboard.board.cell.id <Button-3> {detailPopup %W}

    #bind $winboard.board.cell <Button-2> {boardSelectTog %W}
    #bind $winboard.board.cell.id <Button-2> {boardSelectTog %W}
}

proc invisibleSB {target bg1 fg1} {
    debug 1 "invisibleSB:$target"

    set result [boardPath $target]
    set winboard $result.select.domain

    $winboard configure -relief flat -bg $bg1
    $winboard.board configure -relief flat -bg $bg1

    bind $winboard.board.cell <Button-1> ""
    bind $winboard.board.cell <Button-2> ""
    bind $winboard.board.cell <Button-3> ""

    bind $winboard.board.cell.id <Button-1> ""
    bind $winboard.board.cell.id <Button-2> ""
    bind $winboard.board.cell.id <Button-3> ""
}

#
# Draw a present, but powered down support board
#
proc grayedSB {target bg1 fg1} {
    debug 1 "grayedSB:$target"

    set result [boardPath $target]
    set winboard $result.select.domain

    $winboard configure -relief flat -bg $bg1
    $winboard.board configure -relief flat -bg $bg1

    bind $winboard.board.cell <Button-1> {boardSelect %W}
    bind $winboard.board.cell.id <Button-1> {boardSelect %W}
    bind $winboard.board.cell <Button-2> {boardSelectTog %W}
    bind $winboard.board.cell.id <Button-2> {boardSelectTog %W}
}

#
# Make a control board (cb0, cb1) visible.  Establish bindings.
# target = cb0, cb1
#
proc visibleCB {target bg1 fg1} {
    debug 1 "visibleCB:$target $bg1 $fg1"

    set result [boardPath $target]
    set winboard $result.select.domain

    $winboard configure -bg $bg1 -relief groove
    $winboard.board configure -bg $bg1 -relief raised
    #$winboard configure -bg blue -relief groove
    #$winboard.board configure -bg blue -relief raised

    bind $winboard.board.cell <Button-3> {detailPopup %W}
    bind $winboard.board.cell.jtag <Button-3> {detailPopup %W}
    bind $winboard.board.cell.clock <Button-3> {detailPopup %W}
}
proc invisibleCB {target bg1 fg1} {
    debug 1 "invisibleCB:$target"

    set result [boardPath $target]
    set winboard $result.select.domain

    $winboard configure -relief flat -bg $bg1
    $winboard.board configure -relief flat -bg $bg1

    bind $winboard.board.cell <Button-1> ""
    bind $winboard.board.cell <Button-3> ""

    bind $winboard.board.cell.jtag <Button-1> ""
    bind $winboard.board.cell.jtag <Button-3> ""

    bind $winboard.board.cell.clock <Button-1> ""
    bind $winboard.board.cell.clock <Button-3> ""

    setClock $target off
    setJtag $target off
}
#
# Draw a present, but powered down control board
#
proc grayedCB {target bg1 fg1} {
    debug 1 "grayedCB:$target"

    set result [boardPath $target]
    set winboard $result.select.domain

    $winboard configure -relief flat -bg $bg1
    $winboard.board configure -relief flat -bg $bg1

    #bind $winboard.board.cell <Button-1> {boardSelect %W}
    #bind $winboard.board.cell.jtag <Button-1> {boardSelect %W}
    #bind $winboard.board.cell.clock <Button-1> {boardSelect %W}

}

#
# Make a system board visible.  Establish bindings.
# target = b0..b15
#
proc visibleSys {target bg1 fg1} {
    debug 1 "visibleSys:$target bg: $bg1 fg: $fg1"
    global gBg1

    set result [boardPath $target]
    set winboard $result.select.domain

    $winboard configure -bg grey -relief flat
    #$winboard configure -bg $bg1 -relief flat
    $winboard.board configure -bg $bg1 -relief raised
    #$winboard.board configure -bg blue -relief raised

    #
    # If this board has a domain affiliation, color it in.
    #

	set target [string trim $target bl_]

    set temp1 [whatBoardState $target]
    set domain [lindex $temp1 1]
    if {[string compare "no_domain" $domain] != 0} {
	set color [whatColorDomain  $domain ]
	setBoardDomainColor $target $color
    }

    set cells [procList $target]

    foreach cell $cells {
	set temp1 [procPath $cell]
	$temp1.id configure -fg $fg1

	set cell_temp [whatProcState $cell]
	set cell_state [lindex $cell_temp 0]
	set symbol [getImage $cell_state]
	set cell_color [iconRunColor [lindex $cell_temp 1]]
	
	$temp1.icon configure -image $symbol -bg $cell_color

	pack $temp1.id 	$temp1.icon -side left

	#bind $temp1      <Button-2> {boardSelect %W}
	#bind $temp1
	#Error: no event type or button # or keysym
	#bind $temp1      <Shift><Button-1> {boardSelect %W}

	if { 0 } {
	    bind $temp1      <Button-1> {boardSelect %W}
	    bind $temp1.id   <Button-1> {boardSelect %W}
	    bind $temp1.icon <Button-1> {boardSelect %W}

	    bind $temp1	<Button-2> {boardSelectTog %W}
	    bind $temp1.id	<Button-2> {boardSelectTog %W}
	    bind $temp1.icon	<Button-2> {boardSelectTog %W}
	}

	bind $temp1      <Button-3> {detailPopup %W}
	bind $temp1.id   <Button-3> {detailPopup %W}
	bind $temp1.icon <Button-3> {detailPopup %W}
    }
}

#
# Create a present, but not powered board.
#
proc grayedSys {target bg1 fg1} {
    debug 1 "grayedSys:$target $bg1 $fg1"

#result is null
    set result [boardPath $target]
    set winboard $result.select.domain

    $winboard configure -relief flat -bg $bg1
    $winboard.board configure -relief flat -bg $bg1

    set cells [procList $target]

    foreach cell $cells {
	set temp1 [procPath $cell]

	bind $temp1      <Button-1> {boardSelect %W}
	bind $temp1.id   <Button-1> {boardSelect %W}
	bind $temp1.icon <Button-1> {boardSelect %W}

	bind $temp1	<Button-2> {boardSelectTog %W}
	bind $temp1.id	<Button-2> {boardSelectTog %W}
	bind $temp1.icon	<Button-2> {boardSelectTog %W}
    }

}

#
# Make a system board invisible.
# target = b0..b15, bg1 = background color, fg1 = text color
#
proc invisibleSys {target bg1 fg1 procStateFlag } {
    debug 3 "invisibleSys:$target  procStateFlag  $procStateFlag"

    set result [boardPath $target]
    set winboard $result.select.domain

    $winboard configure -relief flat -bg $bg1
    $winboard.board configure -relief flat -bg $bg1

    set cells [procList $target]

    foreach cell $cells {
	set temp1 [procPath $cell]

	bind $temp1 <Button-1> ""
	bind $temp1 <Button-2> ""
	bind $temp1 <Button-3> ""

	bind $temp1.id <Button-1> ""
	bind $temp1.id <Button-2> ""
	bind $temp1.id <Button-3> ""

	bind $temp1.icon <Button-1> ""
	bind $temp1.icon <Button-2> ""
	bind $temp1.icon <Button-3> ""

	$temp1.id configure -fg $bg1
	$temp1.icon configure -image dummy -bg $bg1 -highlightbackground $bg1
	if { [string compare $procStateFlag "update"] == 0 } {
	    updateProcList $cell empty empty
	}
    }
}

#
# This CB supplies JTAG.
# target = cb0, cb1
#
proc visibleJtag {target bg1 fg1} {
    debug 1 "visibleJtag:$target"

    set winboard [boardPath $target]
    set winboard $winboard.select.domain.board.cell.jtag
    $winboard configure -foreground $fg1 
}
#
# This CB supplies JTAG.
# target = cb0, cb1
#
proc invisibleJtag {target bg1 fg1} {
    debug 1 "invisibleJtag:$target"

    set winboard [boardPath $target]
    set winboard $winboard.select.domain.board.cell.jtag
    $winboard configure -relief flat -bg $bg1 -fg $fg1
}

#
# This CB supplies clock
# target = cb0, cb1
#
proc visibleClock {target bg1 fg1} {
    debug 1 "visibleClock:$target"

    set winboard [boardPath $target]
    set winboard $winboard.select.domain.board.cell.clock
    $winboard configure -foreground $fg1 
}
#
# This CB supplies clock
# target = cb0, cb1
#
proc invisibleClock {target bg1 fg1} {
    debug 1 "invisibleClock:$target"

    set winboard [boardPath $target]
    set winboard $winboard.select.domain.board.cell.clock
    $winboard configure -relief flat -bg $bg1 -fg $fg1
}

#
# Operator has pressed button 1 on a board
# This event is enabled via binding.
#
proc boardSelect {arg} {
    global gBg1
    global gBackBoards
    global gFrontBoards

    global gSelectedBoard
    global gSelectedBoardList

    debug 1 "boardSelect from:$arg"


    foreach board $gSelectedBoardList {
	    set result [boardPath $board]
	    $result.select configure -bg $gBg1
    }
    set gSelectedBoardList ""

    #
    # Reset the selection frame
    #
    if {[string length $gSelectedBoard] > 0} {
	set result [boardPath $gSelectedBoard]
	$result.select configure -bg $gBg1
    }

    #
    # Build a path to the select frame and color it.
    #
    set temp1 [whatBoard $arg]
    set temp2 [boardPath $temp1]
    set temp3 "$temp2.select"

    set gSelectedBoard $temp1

    $temp3 configure -bg black

    debug 1 "1: gSelectedBoardList: $gSelectedBoardList theSelectedB: $temp1 gSelectedBoard: $gSelectedBoard"


}


#
# Operator has pressed button 2 on a board
# toggle selection of this board.
# This event is enabled via binding.
# arg can be full path to board, or just the board # 
#
proc boardSelectTog {arg} {
    global gBg1
    global gBackBoards
    global gFrontBoards

    global gSelectedBoard
    global gSelectedBoardList

    debug 1 "boardSelectTog from:$arg"


    # if it is gselectedboard, turn it off and promote one of the others
    # if there are any.

    #
    # Build a path to the select frame and color it.
    #
    if { [ string length $arg ] < 5 } {
	# a board number
	set temp1 $arg
    } else {
	#full path
	set temp1 [whatBoard $arg]
    }
    set temp2 [boardPath $temp1]
    set temp3 "$temp2.select"

    set theSelectedB $temp1
    debug 1 "1: gSelectedBoardList: $gSelectedBoardList theSelectedB: $theSelectedB"

    #
    # Reset the selection frame
    #
    set ndx [lsearch $gSelectedBoardList $theSelectedB ]
    if { $ndx > -1 } {

	#toggle this board from selected to deselected.

	#set gSelectedBoardList [lreplace $gSelectedBoardList $ndx $ndx ""]

	set temp1 ""
	set cnt 0
	foreach board $gSelectedBoardList {
	    if { $cnt != $ndx } {
		set temp1 "$temp1 [lindex $gSelectedBoardList $cnt]"
	    }
	    incr cnt
	}
	set gSelectedBoardList $temp1

	set result [boardPath $theSelectedB]
	$result.select configure -bg $gBg1
    } elseif { [string compare $theSelectedB $gSelectedBoard] == 0 } {

	# it was selected by button-1 before
	
	if { [llength $gSelectedBoardList] > 0 } {
	    # promote one or set to null
	    set gSelectedBoard [lindex $gSelectedBoardList 0]

	    set len [llength $gSelectedBoardList]
	    set temp1 ""
	    for { set i 1 } { $i < $len } { incr i} {
		debug 1 "temp1: $temp1"
		set temp1 "$temp1 [lindex $gSelectedBoardList $i]"
	    }
	    set gSelectedBoardList $temp1
	} else {
	    # promote one or set to null
	    set gSelectedBoard ""
	}

	set result [boardPath $theSelectedB]
	$result.select configure -bg $gBg1

    } else {
	#toggle this board to selected.

	if { [string compare $gSelectedBoard ""] == 0 } {
	    set gSelectedBoard $theSelectedB
	} else {
	    if { [string compare $gSelectedBoardList ""] == 0 } {
		set gSelectedBoardList $theSelectedB
	    } else {	
	        set gSelectedBoardList "$gSelectedBoardList $theSelectedB"
	    }
	}

	$temp3 configure -bg black
    }
    debug 1 "2: gSelectedBoardList: $gSelectedBoardList theSelectedB: $theSelectedB gSelectedBoard: $gSelectedBoard"
}



#
# Return a background color for a processor icon.
#
proc iconRunColor {arg} {
    global gBg1

    debug 2 "iconRunColor:$arg"

        # the following states are the states defined in sigblock.h or introduced by hostview
    switch $arg {
	blacklist             {return Black}
	redlist               {return Red}
	run	              {return green3}
	exit                  {return Maroon}
	prerun                {return Yellow2}
	arbstop               {return Maroon}
	reset                 {return Maroon}
	poweroff              {return Maroon}
	detached              {return Maroon}
	callback              {return green3}
	watchdog              {return Maroon}
	watchdog-sync         {return green3}
	offline               {return green3}
	booting               {return green3}
	unknown               {return Blue2}
        xir                   {return Maroon}
        xir-sync              {return green3}
        sir                   {return Maroon}
        sir-sync              {return green3}
        redmode               {return Maroon}
        redmode-sync          {return green3}
        quiesced              {return green3}
        quiesce-in-progress   {return green3}
        resume-in-progress    {return green3}
        none                  {return Blue2}
	present               {return White}
	running               {return green3}
	dummy                 {return $gBg1}
	empty                 {return $gBg1}

	default {
	    debug 5 "==>SWITCH DEFAULT in iconRunColor:$arg"
	    return Blue2
	}
    }
}

#
# Set a running buss.
#
proc greenBus {buss} {
    global gHealthy

    debug 1 "greenBbuss:$buss"

    set candidate ".systemGraphic.buss.$buss.id"
    $candidate configure -bg $gHealthy

    updateBusList $buss up
}
#
# turn off a  buss.
#
proc grayBus {buss} {
    global gGrey

    debug 1 "grayBuss:$buss"

    set candidate ".systemGraphic.buss.$buss.id"
    $candidate configure -bg $gGrey

    updateBusList $buss down
}
#
# Color the domain frame
# board in the form b0, b1, etc.
#
proc setBoardDomainColor {board color} {
    debug 1 "setBoardDomainColor:$board $color"

    set temp1 [boardPath $board]
    set temp2 "$temp1.select.domain"

    $temp2 configure -bg $color
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***

#
# ident	"@(#)systemDetail.tcl	1.16	99/03/22 SMI"
#
# Copyright (c) 1996, 1999 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   The systemDetail gives a picture of the system state.
#   There are three views which use the same template: power, fan and thermal.
#
#   Invoking "systemDetail {option}" where option = {Power, Fan, Thermal}
#   will cause the appropriate template to be created.
#
#   What actually happens is a generic template is created here, with
#   everything grayed out.  Other processes can count on all the attributes
#   to be present in the window, and make them visible as needed.
#
# Main Routine:
#   proc systemDetail {option}
#
# Label The Cabinet:
#   proc addLabels {s2 bg1 fg1}
#
# Add the Bulk Power Supplies:
#   proc addBulkPower {s2 bg1 fg1}
#
# Add the Fan Trays:
#   proc addFans {s2 bg1 fg1} 
#
# Add the Card Cage (Boards):
#   proc addCards {s2 bg1 fg1}
#
# Populate the "sub2" frame, which contains most of the detail.
#   proc populateSub2 {s2 bg1 fg1}
#

#
# Label the front and back of the cabinet.
#
# s2 = window descriptor to frame sub2
#
# bg1 = background color
# fg1 = foreground color (text) 
#
proc addLabels {s2 bg1 fg1} {
    global gFont1

    debug 1 "addLabels:$s2"

    foreach ndx1 {front center back} {
	label $s2.$ndx1.top.idx -text $ndx1 -bg $bg1 -fg $fg1 -font $gFont1
	pack  $s2.$ndx1.top.idx
    }
    # the front and back of the machine were reversed.
    $s2.front.top.idx configure -text Back
    $s2.center.top.idx configure -text bus
    $s2.back.top.idx configure -text Front
}

#
# Add the bulk power symbols.
#
# s2 = window descriptor to frame sub2
#
# bg1 = background color
# fg1 = foreground color (text)
#
proc addBulkPower {s2 bg1 fg1} {
    global gFont1
    global gFrontPower
    global gBackPower
    global gFrontPowerEveready
    global gBackPowerEveready
    global gBg1

    debug 1 "addBulkPower:$s2"
    #
    # the four shelves
    #
    frame $s2.front.top.power -bg $bg1 -borderwidth 2
    pack  $s2.front.top.power -side left
    frame $s2.front.top.eveready -bg $bg1 -borderwidth 2
    pack  $s2.front.top.eveready -side right
    frame $s2.back.top.power -bg $bg1 -borderwidth 2
    pack  $s2.back.top.power -side right
    
    frame $s2.back.top.eveready -bg $bg1 -borderwidth 2
    pack  $s2.back.top.eveready -side left

    #
    # front supplies
    #
    foreach ndx1 $gFrontPower {
	set bp [format "%2d" [ string trimleft $ndx1 bp]]
	button $s2.front.top.power.$ndx1 -text "PS $bp" -bg $bg1 -fg $fg1 \
	    -state disabled
	pack  $s2.front.top.power.$ndx1
    }

    foreach ndx1 $gFrontPowerEveready {
	set bp [format "%2d" [ string trimleft $ndx1 bp]]
	button $s2.front.top.eveready.$ndx1 -text "PS $bp" -bg $gBg1 -fg $fg1 \
	    -state disabled
	pack  $s2.front.top.eveready.$ndx1
    }

    #
    # back supplies
    #
    foreach ndx1 $gBackPower {
	set bp [format "%2d" [ string trimleft $ndx1 bp]]
	button $s2.back.top.power.$ndx1 -text "PS $bp" -bg $bg1 -fg $fg1 \
		-state disabled

	pack  $s2.back.top.power.$ndx1
    }
    foreach ndx1 $gBackPowerEveready {
	set bp [format "%2d" [ string trimleft $ndx1 bp]]
	button $s2.back.top.eveready.$ndx1 -text "PS $bp" -bg $bg1 -fg $fg1 \
	    -state disabled

	pack  $s2.back.top.eveready.$ndx1
    }

    #
    # start with Eveready supplies hidden (unmapped)
    #
    pack forget $s2.front.top.eveready
    pack forget $s2.back.top.eveready
}

#
# Add the fan icons and labels.
#
# s2 = window descriptor to frame sub2
#
# bg1 = background color
# fg1 = foreground color (text) 
#
proc addFans {s2 bg1 fg1} {
    global gFont1
    global gFanDrawers

    debug 2 "addFans:$s2"

    foreach drawer $gFanDrawers {
	set target "$s2[sd2path $drawer]"

	frame $target -bg $bg1 -borderwidth 2 -relief groove
	pack $target -fill both -expand yes -side left

	button $target.icon -image circle -font $gFont1 \
		-bg $bg1 -highlightbackground $bg1 -state disabled

	set fan [ string trimleft $drawer ft]

	label $target.id -bg $bg1 -fg $bg1 -text "FT $fan"


	pack $target.icon $target.id -side left -expand yes
    }
}

#
# Draw the cards
#
proc addCards {s2 bg1 fg1} {
    global gFont1
    global gBackSysBoards
    global gFrontSysBoards

    debug 1 "addCards:$s2"

    #
    # Front boards
    #
    frame  $s2.front.bottom.cards.special -bg $bg1
    pack   $s2.front.bottom.cards.special -side left -expand yes -fill both

    button $s2.front.bottom.cards.special.csb0 -text "CSB 0" -bg $bg1 -fg $fg1 \
	    -padx 0 -state disabled

    button $s2.front.bottom.cards.special.cb0 -text "CB 0" -bg $bg1 -fg $fg1 \
	    -padx 0 -state disabled

    pack $s2.front.bottom.cards.special.csb0 \
	    $s2.front.bottom.cards.special.cb0 -expand yes -fill both

    foreach board $gFrontSysBoards {
	button $s2.front.bottom.cards.$board -bg $bg1 -fg $fg1 -text $board \
		-padx 0 -state disabled

	pack   $s2.front.bottom.cards.$board -side left -expand yes -fill both
    }

    foreach board {ctr} {
	button $s2.center.bottom.cards.$board -bg $bg1 -fg $fg1 \
		-state disabled -font $gFont1
	pack   $s2.center.bottom.cards.$board -side left -expand yes -fill both
    }

    #
    # Back boards
    #
    frame  $s2.back.bottom.cards.special -bg $bg1
    pack   $s2.back.bottom.cards.special -side right -expand yes -fill both

    button $s2.back.bottom.cards.special.csb1 -text "CSB 1" -bg $bg1 -fg $fg1 \
	    -padx 0 -state disabled

    button $s2.back.bottom.cards.special.cb1 -text "CB 1" -bg $bg1 -fg $fg1 \
	    -padx 0 -state disabled

    pack $s2.back.bottom.cards.special.csb1 \
	    $s2.back.bottom.cards.special.cb1 -expand yes -fill both

    foreach board $gBackSysBoards {
	button $s2.back.bottom.cards.$board -bg $bg1 -fg $fg1 -text $board \
		-padx 0 -state disabled

	pack   $s2.back.bottom.cards.$board -side left -expand yes -fill both
    }
}

#
# The "sub2" frame is what contains the most components.
# Create the sub2 frame.
# 
proc populateSub2 {w bg1 fg1} {
    set s2 $w.canvas.sub2

    debug 1 "populateSub2:$s2"

    #
    # Start by creating all the frames.
    #
    foreach ndx1 {front center back} {
	#
	# front, center, back refer to machine cabinet.
	# front, back will become card cages.
	# center is buss.
	#
	frame $s2.$ndx1 -bg $bg1 -relief groove -borderwidth 2
	pack  $s2.$ndx1 -side left -fill both -expand yes 

	foreach ndx2 {top bottom} {
	    #
	    # top is for bulk power supplies
	    # bottom is for card cage.
	    frame $s2.$ndx1.$ndx2 -bg $bg1
	    pack  $s2.$ndx1.$ndx2 -fill both -expand yes
	}

	foreach ndx3 {topfan cards botfan} {
	    #
	    # card cages have two rows of fans and the cards they cool
	    #
	    frame $s2.$ndx1.$ndx2.$ndx3 -bg $bg1
	    pack  $s2.$ndx1.$ndx2.$ndx3 -fill both -expand yes \
		    -padx 1m -pady 1m
	}
    }
    
#    set bg1 "red"
#    set fg1 "white"

    addFans $w $bg1 $fg1

    addLabels $s2 $bg1 $fg1
    addCards $s2 $bg1 $fg1
    addBulkPower $s2 $bg1 $fg1
}

#
# This form supports display of the system operating parameters 
# (i.e. power, temperature and fan overview).
#
proc systemDetail {option} {
    global gBg1
    global gFg1
    global gFont1
    global gPidMibFresh
    global gHostviewName
    global gMibRefreshFreq
    global gNewWin

    debug 4 "systemDetail:$option"

    set w .w$option
    
    #
    # There can only be one copy of this window.
    #
    if [winfo exists $w] {
	raise $w
	return
    } 

    toplevel $w -background $gBg1

    set title "$option Status Display"
    wm title $w $title

    canvas $w.canvas -bg $gBg1
    pack   $w.canvas -fill both -expand yes -padx 2m -pady 2m

	#$w.canvas config -cursor watch
	#flag this to bring up the "working" dialog
	set gNewWin 1
    #
    # sub1 for decorative label at top of canvas
    #
#    frame $w.canvas.sub1 -bg $gBg1 
#    pack  $w.canvas.sub1 -side top -fill both -expand yes
#
#    label $w.canvas.sub1.id -text $title -bg $gBg1 -fg $gFg1
#    pack  $w.canvas.sub1.id -side top -fill x -expand yes

    #
    # sub2 for working area
    #
    set s2 $w.canvas.sub2
    frame $s2 -bg $gBg1 -borderwidth 2
    pack  $s2 -fill both -expand yes

    #
    # button bar for command options
    #
    frame $w.canvas.buttonbar -bg $gBg1 -borderwidth 2 
    pack  $w.canvas.buttonbar -fill both -expand yes \
	    -padx 2m -pady 1m -side bottom

    button $w.canvas.buttonbar.dismiss -bg $gBg1 -fg $gFg1\
	    -activebackground $gBg1 -activeforeground $gFg1 -text dismiss \
            -command "dismissWoption $w" -font $gFont1
    pack  $w.canvas.buttonbar.dismiss

    #
    # Main window areas have been defined.
    # Now place various attributes on the window.
    #
    populateSub2 $w $gBg1 $gFg1
    
    #
    # At this point, the grayed out window has been created.
    # Enable various attributes (like color) depending upon
    # what type of window was built, equipment states, etc.
    #
    switch $option {
	Power   {decoratePower   $w}
	Fan     {decorateFan     $w}
	Thermal {decorateThermal $w}
    }
    decorateEveready

    # fire off a background proc to schedule window refresh
    if ![info exists gPidMibFresh] {
	debug 1 "exec hostview_child -M $gHostviewName $gMibRefreshFreq"
	if [catch {exec hostview_child -M "$gHostviewName $gMibRefreshFreq" &} result] {
	    debug 10 $result
	}
    }
}
proc dismissWoption {w } {
    global gPidMibFresh

    debug 1 "dismissWoption: $w"

    set count [countWin]

    if { $count < 2 } {
	if { [info exists gPidMibFresh] && [ string compare $gPidMibFresh "99999999"] != 0 } {
	    debug 1 "killing gPidMibFresh: $gPidMibFresh"
	    if [catch {exec kill $gPidMibFresh} result] {
		debug 1 $result
	    }
	    unset gPidMibFresh
	}
    }

    destroy $w

}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)systemGraphic.tcl	1.7	97/07/23 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   This file supports the main GUI canvas.  Place everything on the canvas
#   to establish path names and geometry.  Most objects will be invisible.
#   Subsequent routines can make objects visible by changing colors.
#
# Main Routine:
#   proc systemGraphic {bg1 fg1}
# 
# System Board Decoration:
#   proc decorateSys {parent bg1 fg1 bg2 fg2}
#
# Support Board Decoration:
#   proc decorateSB {parent id bg1 fg1 bg2 fg2}
#
# Control Board Decoration:
#   proc decorateCB {parent id bg1 fg1 bg2 fg2}
#
# Create Front of Cabinet:
#   proc frontTemplate {parent bg1 fg1 bg2 fg2}
#
# Create Back of Cabinet:
#   proc backTemplate {parent bg1 fg1 bg2 fg2}
#
# Create Center Plane:
#   proc bussTemplate {parent bg1 fg1}
#

#
# Processor rectangles need icons and labels.  
# These need to be present, visible or not so packer knows what to do.
#
# bg1 = default background color
# fg1 = text color
# bg2 = diag backround color
# fg2 = diag foreground color
#
proc decorateSys {parent bg1 fg1 bg2 fg2} {
    debug 1 "decorateSys:$parent"

    set cells [procList $parent]

    foreach cell $cells {
	set temp1 [procPath $cell]
	frame $temp1 -bg $bg1

	label $temp1.id -text $cell -bg $bg1 -foreground $fg2
	label $temp1.icon -image dummy -bg $fg2 -highlightbackground $bg1

	pack $temp1 -side top
	pack $temp1.id $temp1.icon -side left
    }
}

#
# SB are different from processors in that:
#    No internal icons
#    Smaller
#
proc decorateSB {parent id bg1 fg1 bg2 fg2} {
    debug 1 "decorateSB:$id"
    #
    # System Boards must be on top.  Redefine for packer.
    #
    set temp1 [split $parent .]
#    debug 1 "decorateSB:$temp1"

    set temp2 ".[lindex $temp1 1]"

    for {set ndx 2} {$ndx <= 5} {incr ndx} {
	set temp2 "$temp2.[lindex $temp1 $ndx]"
    }
#    debug 1 "decorateSB:$temp2"

    if {[string compare $id "csb0"]} {
	pack $temp2 -side top
    } else {
	pack $temp2 -side bottom
    }

    frame $parent.cell -bg $bg1
    pack $parent.cell

    #
    # Make invisible, but I need the text for spacing
    #
    label $parent.cell.id -text "X" -bg $bg1 -foreground $bg1
    pack $parent.cell.id -padx 1m -pady 2m
}

#
# Control Board
#
proc decorateCB {parent id bg1 fg1 bg2 fg2} {
    debug 1 "decorateCB:$id"

    #
    # System Boards must be on top.  Redefine for packer.
    #
    set temp1 [split $parent .]
#    debug 1 $temp1

    set temp2 ".[lindex $temp1 1]"
#    debug 1 $temp2

    for {set ndx 2} {$ndx <= 5} {incr ndx} {
	set temp2 "$temp2.[lindex $temp1 $ndx]"
    }
#    debug 1 $temp2

    if {[string compare $id "cb0"]} {
	pack $temp2 -side bottom
    } else {
	pack $temp2 -side top
    }

    frame $parent.cell -bg $bg1
    pack $parent.cell

    #
    # Make invisible, but I need the text for spacing
    #
    label $parent.cell.jtag -text "J" -bg $bg1 -foreground $bg1
    label $parent.cell.clock -text "C" -bg $bg1 -foreground $bg1

    pack $parent.cell.jtag $parent.cell.clock -padx 1m -pady 2m
}

#
# bg1 = default background color
# fg1 = text color
# bg2 = diag backround color
# fg2 = diag foreground color
#
proc frontTemplate {parent bg1 fg1 bg2 fg2} {
    global gFrontBoards

    debug 1 "frontTemplate:$parent"

    foreach slot $gFrontBoards {
	frame $parent.$slot -bg $bg1
	if {[string first csb $slot] >= 0} {
	    set csb [ string trimleft $slot csb]
	    label $parent.$slot.id -text "CSB $csb" -bg $bg1
	} elseif {[string first cb $slot] >= 0} {
	    set cb [ string trimleft $slot cb]
	    label $parent.$slot.id -text "CB $cb" -bg $bg1
	} else {
	    label $parent.$slot.id -text "SB $slot" -bg $bg1
	}


	pack $parent.$slot -side left -fill both -expand yes
	pack $parent.$slot.id -side bottom

	frame $parent.$slot.select -relief flat -borderwidth 4 -bg $bg1
	pack  $parent.$slot.select -padx 1m -side top

	frame $parent.$slot.select.domain -relief flat -borderwidth 4 -bg $bg2
	pack  $parent.$slot.select.domain -side bottom

	set winboard $parent.$slot.select.domain.board

	frame $winboard -relief flat -borderwidth 4 -bg $bg1
	pack  $winboard

	switch $slot {
	    csb0 {decorateSB $winboard $slot $bg1 $fg1 $bg2 $fg2 }
	    cb0 {decorateCB $winboard $slot $bg1 $fg1 $bg2 $fg2 }
	    0  {decorateSys $slot $bg1 $fg1 $bg2 $fg2 }
	    1  {decorateSys $slot $bg1 $fg1 $bg2 $fg2 }
	    2  {decorateSys $slot $bg1 $fg1 $bg2 $fg2 }
	    3  {decorateSys $slot $bg1 $fg1 $bg2 $fg2 }
	    4  {decorateSys $slot $bg1 $fg1 $bg2 $fg2 }
	    5  {decorateSys $slot $bg1 $fg1 $bg2 $fg2 }
	    6  {decorateSys $slot $bg1 $fg1 $bg2 $fg2 }
	    7  {decorateSys $slot $bg1 $fg1 $bg2 $fg2 }
	}
    }
}

#
# bg1 = default background color
# fg1 = text color
# bg2 = diag backround color
# fg2 = diag foreground color
#
proc backTemplate {parent bg1 fg1 bg2 fg2} {
    global gBackBoards

    debug 1 "backTemplate:$parent"

    foreach slot $gBackBoards {
	frame $parent.$slot -bg $bg1
	
	if {[string first csb $slot] >= 0} {
	    set csb [ string trimleft $slot csb]
	    label $parent.$slot.id -text "CSB $csb" -bg $bg1
	} elseif {[string first cb $slot] >= 0} {
	    set cb [ string trimleft $slot cb]
	    label $parent.$slot.id -text "CB $cb" -bg $bg1
	} else {
	    label $parent.$slot.id -text "SB $slot" -bg $bg1
	}

	pack $parent.$slot -side left -fill both -expand yes
	pack $parent.$slot.id -side top

	frame $parent.$slot.select -relief flat -borderwidth 4 -bg $bg1
	pack  $parent.$slot.select -padx 1m -side bottom

	frame $parent.$slot.select.domain -relief flat -borderwidth 4 -bg $bg2
	pack  $parent.$slot.select.domain -side bottom

	set winboard $parent.$slot.select.domain.board

	frame $winboard -relief flat -borderwidth 4 -bg $bg1
	pack  $winboard

	switch $slot {
	    csb1 {decorateSB $winboard $slot $bg1 $fg1 $bg2 $fg2 }
	    cb1 {decorateCB $winboard $slot $bg1 $fg1 $bg2 $fg2 }
	    8  {decorateSys $slot $bg1 $fg1 $bg2 $fg2 }
	    9  {decorateSys $slot $bg1 $fg1 $bg2 $fg2 }
	    10 {decorateSys $slot $bg1 $fg1 $bg2 $fg2 }
	    11 {decorateSys $slot $bg1 $fg1 $bg2 $fg2 }
	    12 {decorateSys $slot $bg1 $fg1 $bg2 $fg2 }
	    13 {decorateSys $slot $bg1 $fg1 $bg2 $fg2 }
	    14 {decorateSys $slot $bg1 $fg1 $bg2 $fg2 }
	    15 {decorateSys $slot $bg1 $fg1 $bg2 $fg2 }
	}
    }
}

proc bussTemplate {parent bg1 fg1} {
    debug 1 "bussTemplate:$parent"

    set labeltext "ABUS2 ABUS3 DBUS1 DBUS0 ABUS1 ABUS0"
    set cnt 0

    foreach buss {abus2 abus3 dbus1 dbus0 abus1 abus0} {
	frame $parent.$buss -borderwidth 1 -relief groove  -bg $bg1
	pack $parent.$buss -side top -expand yes -fill x

	label $parent.$buss.id -text [lindex $labeltext $cnt] \
		-bg $bg1 -foreground $fg1
	pack $parent.$buss.id -expand yes -fill x
	incr cnt
    }
}

#
# bg1 = overall background color
# fg1 = letters
#
proc systemGraphic {bg1 fg1} {
    debug 4 "systemGraphic"
    #
    # back is for cards in the rear of the machine
    #
    frame .systemGraphic.back -bg $bg1
    pack  .systemGraphic.back -fill both -expand yes -padx 2m -pady 2m

    # the front and back of the machine were reversed.
    label .systemGraphic.back.id -text Front -bg $bg1 -fg $fg1
    pack  .systemGraphic.back.id -side top 

    frame .systemGraphic.back.cards -bg $bg1 
    pack  .systemGraphic.back.cards -side bottom -fill both -expand yes

#    backTemplate .systemGraphic.back.cards $bg1 $fg1 blue red
    backTemplate .systemGraphic.back.cards $bg1 $fg1 $bg1 $bg1

    #
    # center is for the system buss diagram
    #
    frame .systemGraphic.buss -bg $bg1 -relief groove -borderwidth 4
    pack  .systemGraphic.buss -fill x -expand yes -padx 2m

#    bussTemplate .systemGraphic.buss $bg1 $fg1
    bussTemplate .systemGraphic.buss gray black 

    #
    # front is for cards in the front of the machine
    #
    frame .systemGraphic.front -bg $bg1
    pack  .systemGraphic.front -fill both -expand yes -padx 2m -pady 2m

    # the front and back of the machine were reversed.
    label .systemGraphic.front.id -text Back -bg $bg1 -fg $fg1
    pack  .systemGraphic.front.id -side bottom

    frame .systemGraphic.front.cards -bg $bg1
    pack  .systemGraphic.front.cards -side bottom -fill both -expand yes

#    frontTemplate .systemGraphic.front.cards $bg1 $fg1 blue red
    frontTemplate .systemGraphic.front.cards $bg1 $fg1 $bg1 $bg1
}


#
# invisibleSystemGraphic: make the main GUI invisible
#
proc invisibleSystemGraphic {bg1 fg1} {
    global gBackBoards
    global gFrontBoards

    debug 4 "invisibleSystemGraphic"

    # make the cards in the back  of the system invisible
    foreach slot $gBackBoards {
       switch $slot {
          csb1  {invisibleSB $slot $bg1 $fg1 }
          cb1   {invisibleCB $slot $bg1 $fg1 
                 invisibleJtag $slot $bg1 $bg1  
                 invisibleClock $slot $bg1 $bg1}
          8     {invisibleSys $slot $bg1 $fg1 NOupdate
                 setBoardDomainColor $slot $bg1 }
          9     {invisibleSys $slot $bg1 $fg1 NOupdate
                 setBoardDomainColor $slot $bg1 }
          10    {invisibleSys $slot $bg1 $fg1 NOupdate
                 setBoardDomainColor $slot $bg1 }
          11    {invisibleSys $slot $bg1 $fg1 NOupdate
                 setBoardDomainColor $slot $bg1 }
          12    {invisibleSys $slot $bg1 $fg1 NOupdate
                 setBoardDomainColor $slot $bg1 }
          13    {invisibleSys $slot $bg1 $fg1 NOupdate
                 setBoardDomainColor $slot $bg1 }
          14    {invisibleSys $slot $bg1 $fg1 NOupdate
                 setBoardDomainColor $slot $bg1 }
          15    {invisibleSys $slot $bg1 $fg1 NOupdate
                 setBoardDomainColor $slot $bg1 }
       }
    }


    # make the buses invisible
    foreach buss {abus2 abus3 dbus1 dbus0 abus1 abus0} {
       grayBus $buss 
    }


    # make the cards in the front of the system invisible
    foreach slot $gFrontBoards {
       switch $slot {
          csb0  {invisibleSB $slot $bg1 $fg1 }
          cb0   {invisibleCB $slot $bg1 $fg1 
                 invisibleJtag $slot $bg1 $bg1  
                 invisibleClock $slot $bg1 $bg1}
          0     {invisibleSys $slot $bg1 $fg1 NOupdate
                 setBoardDomainColor $slot $bg1 }
          1     {invisibleSys $slot $bg1 $fg1 NOupdate
                 setBoardDomainColor $slot $bg1 }
          2     {invisibleSys $slot $bg1 $fg1 NOupdate
                 setBoardDomainColor $slot $bg1 }
          3     {invisibleSys $slot $bg1 $fg1 NOupdate
                 setBoardDomainColor $slot $bg1 }
          4     {invisibleSys $slot $bg1 $fg1 NOupdate
                 setBoardDomainColor $slot $bg1 }
          5     {invisibleSys $slot $bg1 $fg1 NOupdate
                 setBoardDomainColor $slot $bg1 }
          6     {invisibleSys $slot $bg1 $fg1 NOupdate
                 setBoardDomainColor $slot $bg1 }
          7     {invisibleSys $slot $bg1 $fg1 NOupdate
                 setBoardDomainColor $slot $bg1 }
       }
    }

}


#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***p

# ident	"@(#)thermalDetail.tcl	1.13	98/02/04 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   Routines which support display and manipulation of "thermal detail"
#   windows.  There is a separate routine for each type of "thermal detail."
#   (i.e. system, support, control and center board).
#
# Main routine.  Dispatches according to board type.
#   proc thermalDetail {board}
#
# Draw thermal detail for center board (buss).
#   proc thermalDetailCtrBoard {board}
#
# Draw thermal detail for control board.
#   proc thermalDetailConBoard {board}
#
# Draw thermal detail for support board.
#   proc thermalDetailSupBoard {board} 
#
# Draw thermal detail for system board.
#   proc thermalDetailSysBoard {board} 
#
# Update the text and bars (executive).
#   proc thermalDetailUpdate {board}
#
# Update the text and bars (grunt work).
#   proc thermalPanelUpdate {panel values component offset} {
#
# Determine the actual Y coordinate for this temperature.
#   proc thermalGuageY {temperature} 
#
# Determine the fill color for this temperature bar.
#   proc updateThermalGuage {board therm temperature}  
#

#
# New datum has arrived, update detail.
#
proc thermalDetailUpdate {board} {
    global gThermalList

    debug 2 "thermalDetailUpdate:$board"

    set w .thermalDetail_$board

    set ndx [lsearch -glob $gThermalList $board*]
    if {$ndx < 0} {
	debug 5 "updateThermalDetail, no entry for:$board"
	return
    }

    set target [lindex $gThermalList $ndx]
    set temperatures [lindex $target 2]

    if {[string compare ctr $board] == 0} {
	# 10x2 temperature sensors (front and back)
	set front [lindex $temperatures 0]
	set back  [lindex $temperatures 1]

	set panel "$w.f.front"
	thermalPanelUpdate $panel $front asic 10

	set panel "$w.f.back"
	thermalPanelUpdate $panel $back asic 10
    } elseif {[string first csb $board] >= 0} {
	# 2 temperature sensors
	set dc $temperatures

	set panel "$w.f.dc"
	thermalPanelUpdate $panel $dc dc 0
    } elseif {[string first cb $board] >= 0} {
		# 3 temperature sensors on board, 3 ambient
		set dc      [lindex $temperatures 0]
		set ambient [lindex $temperatures 1]

		set panel "$w.f.dc"
		thermalPanelUpdate $panel $dc dc 0

		set panel "$w.f.ambient"
		thermalPanelUpdate $panel $ambient amb 0
    } else {
		set asic  [lindex $temperatures 0]
		set dc    [lindex $temperatures 1]
		set procz [lindex $temperatures 2]

		set panel "$w.f.asic"
		thermalPanelUpdate $panel $asic asic 0

		set panel "$w.f.dc"
		thermalPanelUpdate $panel $dc dc 0

		set panel "$w.f.proc"
		thermalPanelUpdate $panel $procz proc 0
    }
}

#
# Do the actual grunt work for updating the bars and text.
# panel = canvas to update.  values = list of temperatures.
#
proc thermalPanelUpdate {panel values component offset} {
    global gTdX1
    global gTdY2
    global gTdInc

    debug 2 "thermalPanelUpdate:$panel $values"

    set tag_id 0
    set xx $gTdX1

#puts "Inside thermalPanelUpdate $panel $component"
    foreach ndx $values {
#puts "   Inside thermalPanelUpdate $ndx"
	set tag "text$tag_id"

	$panel dchars $tag 0 5
	$panel itemconfigure $tag -text $ndx

	set tag "bar$tag_id"

	set yy [thermalGuageY $ndx]
	set color [thermalGuageColor $ndx $component]

	$panel coords $tag $xx $gTdY2 $xx $yy
	$panel itemconfigure $tag -fill $color

	incr tag_id
	incr xx [expr $gTdInc - $offset]
    }
}

#
# Return y coordinate to represent the current temperature.
#
proc thermalGuageY {temperature} {
    global gTdY1
    global gTdY2

    global gThermalMaxTemp 
    global gThermalMinTemp

    debug 2 "thermalGuageY:$temperature"

    set low_bound $gThermalMinTemp
    set high_bound $gThermalMaxTemp

    set temperature_delta [expr $high_bound - $low_bound]

    if {$temperature > $high_bound} {
	set adj_temp $temperature_delta
    } elseif {$temperature < $low_bound} {
	set adj_temp 0
    } else {
	set adj_temp [expr $temperature - $low_bound]
    }

    set pixel_delta [expr $gTdY2 - $gTdY1]

    set retvalue \
	    [expr double($adj_temp*$pixel_delta)/double($temperature_delta)]

    set retvalue [expr $gTdY2 - int($retvalue)]

    return $retvalue
}

#
# Given a temperature, return the approprate thermal color
#
proc thermalGuageColor {temperature component } {
    global gHealthy
    global gProblem
    global gThermalProblem
    global gWARNps
    global gWARNproc
    global gWARNamb
    global gWARNasic

    debug 2 "thermalGuageColor:temp: $temperature component: $component  "

    if {[string compare $component "dc"] == 0} {
	set thermalThresh $gWARNps
    } elseif {[string compare $component "amb"] == 0} {
	set thermalThresh $gWARNamb
    } elseif {[string compare $component "proc"] == 0} {
	set thermalThresh $gWARNproc
    } elseif {[string compare $component "asic"] == 0} {
	set thermalThresh $gWARNasic
    }

    debug 2 "thermalGuageColor:temp: $temperature thermalThresh: $thermalThresh"

    if {$temperature > $thermalThresh} {
	return $gProblem
    }
    return $gHealthy
}

#
# Create a thermal detail for a particular system board.
#
proc thermalDetailSysBoard {board} {
    global gBg1
    global gFg1
    global gFont1
    global gFont2

    global gTdX1
    global gTdY1
    global gTdY2
    global gTdInc
    global gTdWidth
    global gWARNasic
    global gWARNps
    global gWARNproc

    global gHealthy

    global gThermalList

    debug 2 "thermalDetailSysBoard entry:$board"

    set w .thermalDetail_$board

    toplevel $w
    wm title $w "SB $board Thermal Detail"

    frame $w.f -bg $gBg1
    pack $w.f -expand yes -fill both

    set x1 $gTdX1
    set y1 $gTdY1
    set y2 $gTdY2

    #
    # Note these lists match the layout of gThermalList
    #
    set asic_list {A0 A1 A2 A3 A4}
    set dc_list   {T3.3VDC T5VDC TVDCCore}
    #set dc_list   {DC1 DC2 DC3}
    set proc_list {P0 P1 P2 P3}

    canvas $w.f.asic -relief groove -borderwidth 2 -height $gTdY2 \
	    -width [expr [llength $asic_list] * $gTdInc + 6] \
	    -background $gBg1 -highlightthickness 0
    canvas $w.f.dc   -relief groove -borderwidth 2 -height $gTdY2 \
	    -width [expr [llength $dc_list] * $gTdInc + 6] \
	    -background $gBg1 -highlightthickness 0 
    canvas $w.f.proc -relief groove -borderwidth 2 -height $gTdY2 \
	    -width [expr [llength $proc_list] * $gTdInc + 6] \
	    -background $gBg1 -highlightthickness 0

    pack $w.f.asic $w.f.dc $w.f.proc -expand yes -fill both -side left -padx 2 -pady 2

    #Draw the threshhold temperature lines.
    set yy [thermalGuageY $gWARNasic]
    $w.f.asic create line [expr 10 ] [expr $yy] \
		[expr [llength $asic_list] * $gTdInc + 2] [expr $yy] \
		-width 2 -fill red -stipple gray50
    set yy [thermalGuageY $gWARNps]
    $w.f.dc create line [expr 10 ] [expr $yy] \
		[expr [llength $dc_list] * $gTdInc + 2] [expr $yy] \
		-width 2 -fill red -stipple gray50
    set yy [thermalGuageY $gWARNproc]
    $w.f.proc create line [expr 10 ] [expr $yy] \
		[expr [llength $proc_list] * $gTdInc + 2] [expr $yy] \
		-width 2 -fill red -stipple gray50

    set tag_id 0
    foreach bar $asic_list {
	$w.f.asic create line [expr $x1] [expr $y1] [expr $x1] [expr $y1] \
		-width $gTdWidth -fill $gHealthy -tags "bar$tag_id"

	$w.f.asic create text [expr $x1] [expr $y2-10] -text NA \
		-tags "text$tag_id"

	$w.f.asic create text [expr $x1] [expr $y2-25] -text -${bar}-

	incr x1 $gTdInc
	incr tag_id
    }

    set leg "Asic Temperatures"
    #incr x1 $gTdInc
    set x1 [expr $x1 / 2 - [ string length $leg] / 4]
    $w.f.asic create text [expr $x1] [expr $gTdY2 * .15 ] -text $leg


    set tag_id 0
    set x1 $gTdX1
    foreach bar $dc_list {
	$w.f.dc create line [expr $x1] [expr $y1] [expr $x1] [expr $y1] \
		-width $gTdWidth -fill $gHealthy -tags "bar$tag_id"

	$w.f.dc create text [expr $x1] [expr $y2-10] -text NA \
		-tags "text$tag_id"
		#-tags "text$tag_id" -font $gFont1

	$w.f.dc create text [expr $x1] [expr $y2-25] -text $bar

	incr x1 $gTdInc
	incr tag_id
    }

    set leg "DC Temperatures"
    #set x1 [expr $x1 - $gTdInc]
    set x1 [expr $x1 / 2 - [string length $leg] / 2 - 2]
    $w.f.dc create text [expr $x1] [expr $gTdY2 * .15 ] -text $leg

    set tag_id 0
    set x1 $gTdX1
    foreach bar $proc_list {
	$w.f.proc create line [expr $x1] [expr $y1] [expr $x1] [expr $y1] \
		-width $gTdWidth -fill $gHealthy -tags "bar$tag_id"

	$w.f.proc create text [expr $x1] [expr $y2-10] -text NA \
		-tags "text$tag_id"

	$w.f.proc create text [expr $x1] [expr $y2-25] -text -${bar}-

	incr x1 $gTdInc
	incr tag_id
    }

    set leg "Processor Temperatures"
    set x1 [expr $x1 / 2 - [string length $leg] / 2 - 2]
    $w.f.proc create text [expr $x1] [expr $gTdY2 * .15 ] -text $leg


    frame $w.buttonbox -bg $gBg1
    pack $w.buttonbox -expand yes -fill x -side left

    button $w.buttonbox.dismiss   -bg $gBg1 -fg $gFg1 \
	    -activebackground $gBg1 -activeforeground $gFg1 -text "dismiss" \
	    -command { dismissMe } -font $gFont1 -highlightthickness 0

    #pack $w.buttonbox.dismiss -fill x 
    pack $w.buttonbox.dismiss

    #
    # If temperature data is known, display it.
    #
    if {[lsearch -glob $gThermalList $board*] >= 0} {
	thermalDetailUpdate $board
    }
}

#
# Create a thermal detail for a particular support board.
#
proc thermalDetailSupBoard {board} {
    global gBg1
    global gFg1
    global gFont1

    global gTdX1
    global gTdY1
    global gTdY2
    global gTdInc
    global gTdWidth
    global gWARNps

    global gHealthy

    global gThermalList

    set w .thermalDetail_$board

    toplevel $w
    set bnum [string trimleft $board csb]
    wm title $w "CSB $bnum Thermal Detail"

    debug 1 "thermalDetailSupBoard entry:$board"

    frame $w.f  -bg $gBg1
    pack $w.f -expand yes -fill both

    set x1 $gTdX1
    set y1 $gTdY1
    set y2 $gTdY2

    set dc_list {T3.3VDC1 T3.3VDC2}
    #set dc_list {DC1 DC2}

    canvas $w.f.dc -relief groove -borderwidth 2 -height $gTdY2 \
	    -width [expr [llength $dc_list] * $gTdInc + 6] \
	    -background $gBg1 -highlightthickness 0

    pack $w.f.dc -expand yes -fill both -side left -padx 2 -pady 2

    #Draw the threshhold temperature lines.
    set yy [thermalGuageY $gWARNps]
    $w.f.dc create line [expr 10 ] [expr $yy] \
                [expr [llength $dc_list] * $gTdInc + 2] [expr $yy] \
                -width 2 -fill red -stipple gray50

    set tag_id 0
    foreach bar $dc_list {
	$w.f.dc create line [expr $x1] [expr $y1] [expr $x1] [expr $y1] \
		-width $gTdWidth -fill $gHealthy -tags "bar$tag_id"

	$w.f.dc create text [expr $x1] [expr $y2-10] -text NA \
		-tags "text$tag_id"

	$w.f.dc create text [expr $x1] [expr $y2-25] -text $bar

	incr tag_id
	incr x1 $gTdInc
    }

    set leg "DC Temperatures"
    #incr x1 $gTdInc
    #set x1 [expr [llength $dc_list] * $gTdInc + 2]
    set x1 [expr $x1 / 2 - [string length $leg] / 2 - 4]
    $w.f.dc create text [expr $x1] [expr $gTdY2 * .15 ] -text $leg


    frame $w.buttonbox -bg $gBg1
    pack $w.buttonbox -expand yes -fill x -side left

    button $w.buttonbox.dismiss   -bg $gBg1 -fg $gFg1 \
	    -activebackground $gBg1 -activeforeground $gFg1 -text "dismiss" \
	    -command { dismissMe } -font $gFont1 -highlightthickness 0 

    pack $w.buttonbox.dismiss -fill x -padx 3 -pady 3

    #
    # If temperature data is known, display it.
    #
    if {[lsearch -glob $gThermalList $board*] >= 0} {
	thermalDetailUpdate $board
    }
}

#
# Create a thermal detail for a particular control board.
#
proc thermalDetailConBoard {board} {
    global gBg1
    global gFg1
    global gFont1

    global gTdX1
    global gTdY1
    global gTdY2
    global gTdInc
    global gTdWidth

    global gHealthy

    global gThermalList

    global gWARNps
    global gWARNamb

    set w .thermalDetail_$board

    toplevel $w
    set bnum [string trimleft $board cb]
    wm title $w "CB $bnum Thermal Detail"

    debug 1 "thermalDetailBoard entry:$board"

    frame $w.f -background $gBg1
    pack $w.f -expand yes -fill both

    set x1 $gTdX1
    set y1 $gTdY1
    set y2 $gTdY2

    set dc_list   {T5VDC T5VDCPer T5VDCFan}
    #set dc_list   {DC1 DC2 DC3}
    set ambient_list {A1 A2 A3}

    canvas $w.f.dc -relief groove -borderwidth 2 -height $gTdY2 \
	    -width [expr [llength $dc_list] * $gTdInc + 6] \
	    -background $gBg1 -highlightthickness 0

    canvas $w.f.ambient -relief groove -borderwidth 2 -height $gTdY2 \
	    -width [expr [llength $ambient_list] * $gTdInc + 6] \
	    -background $gBg1 -highlightthickness 0

    pack $w.f.dc $w.f.ambient -expand yes -fill both -side left -padx 2 -pady 2
    #pack $w.f.dc $w.f.ambient -expand no -side left -padx 20 -pady 10

    #Draw the threshhold temperature lines.
    set yy [thermalGuageY $gWARNps]
    $w.f.dc create line [expr 10 ] [expr $yy] \
                [expr [llength $dc_list] * $gTdInc + 2] [expr $yy] \
                -width 2 -fill red -stipple gray50
    set yy [thermalGuageY $gWARNamb]
    $w.f.ambient create line [expr 10 ] [expr $yy] \
                [expr [llength $ambient_list] * $gTdInc + 2] [expr $yy] \
                -width 2 -fill red -stipple gray50

    set tag_id 0
    set x1 $gTdX1
    foreach bar $dc_list {
	$w.f.dc create line [expr $x1] [expr $y1] [expr $x1] [expr $y1] \
		-width $gTdWidth -fill $gHealthy -tags "bar$tag_id"

	$w.f.dc create text [expr $x1] [expr $y2-10] -text NA \
		-tags "text$tag_id"

	$w.f.dc create text [expr $x1] [expr $y2-25] -text $bar

	incr tag_id
	incr x1 $gTdInc
    }

    set leg "DC Temperatures"
    set x1 [expr $x1 / 2 - [string length $leg] / 2 - 4]
    $w.f.dc create text [expr $x1] [expr $gTdY2 * .15 ] -text $leg


    set tag_id 0
    set x1 $gTdX1
    foreach bar $ambient_list {
	$w.f.ambient create line [expr $x1] [expr $y1] [expr $x1] [expr $y1] \
		-width $gTdWidth -fill $gHealthy -tags "bar$tag_id"

	$w.f.ambient create text [expr $x1] [expr $y2-10] -text NA \
		-tags "text$tag_id"

	$w.f.ambient create text [expr $x1] [expr $y2-25] -text -${bar}-

	incr tag_id
	incr x1 $gTdInc
    }

    set leg "Ambient Temperatures"
    set x1 [expr $x1 / 2 - [string length $leg] / 2 - 2]
    $w.f.ambient create text [expr $x1] [expr $gTdY2 * .15 ] -text $leg

    frame $w.buttonbox -bg $gBg1
    pack $w.buttonbox -expand yes -fill x -side left

    button $w.buttonbox.dismiss   -bg $gBg1 -fg $gFg1 \
	    -activebackground $gBg1 -activeforeground $gFg1 -text "dismiss" \
	    -command { dismissMe } -font $gFont1 -highlightthickness 0

    pack $w.buttonbox.dismiss -fill x -padx 3 -pady 3

    #
    # If temperature data is known, display it.
    #
    if {[lsearch -glob $gThermalList $board*] >= 0} {
	thermalDetailUpdate $board
    }
}

#
# Create a thermal detail for centerplane.
#
proc thermalDetailCtrBoard {board} {
    global gBg1
    global gFg1
    global gFont1

    global gTdX1
    global gTdY1
    global gTdY2
    global gTdInc
    global gTdWidth
    global gWARNasic

    # It was necessary to reduce the width of the temperature bars in order
    # to reduce the overall width of the CPLANE Thermal Detail window is it 
    # would not be wider than the monitor.  Ref. bug # ________.
    set cplanetdWidth [expr $gTdWidth - 10]
    set cplanetdInc   [expr $gTdInc - 10]

    # will need to update thermalPanelUpdate to make ctr scale
    set tdx1 5
    #set tdx1 [expr $gTdX1 *3 /4 ]
    set tdwidth 45
    #set tdwidth 45
    #set tdwidth [expr $gTdWidth *3 /4 ]
    set tdinc [expr $tdwidth +2]
    #set tdinc [expr $tdwidth + 2]

    global gHealthy

    global gThermalList

    set w .thermalDetail_$board

    toplevel $w
    wm title $w "CPLANE Thermal Detail"

    debug 1 "thermalDetailBoard entry:$board"

    frame $w.f  -bg $gBg1
    pack $w.f -expand yes -fill both

    set x1 $tdx1
    #set x1 $gTdX1
    set y1 $gTdY1
    set y2 $gTdY2

    set front_list { F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 }
    set back_list { B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 }

    canvas $w.f.front -relief groove -borderwidth 2 -height $gTdY2 \
	    -width [expr [llength $front_list] * $cplanetdInc + 12] \
	    -background $gBg1
	    #-width [expr [llength $front_list] * $tdinc + 2]

    canvas $w.f.back -relief groove -borderwidth 2 -height $gTdY2 \
	    -width [expr [llength $back_list] * $cplanetdInc + 12] \
	    -background $gBg1
	    #-width [expr [llength $back_list] * $tdinc + 2]

    pack $w.f.front $w.f.back -expand yes -fill both -side left

    #Draw the threshhold temperature lines.
    set yy [thermalGuageY $gWARNasic]
    $w.f.front create line [expr 12 ] [expr $yy] \
		[expr [llength $front_list] * $cplanetdInc + 8] [expr $yy] \
		-width 2 -fill red -stipple gray50
    $w.f.back create line [expr 12 ] [expr $yy] \
		[expr [llength $front_list] * $cplanetdInc + 8] [expr $yy] \
		-width 2 -fill red -stipple gray50

    # Create the front temperature bars.
    set tag_id 0
    #set x1 $tdx1
    set x1 $gTdX1
    foreach bar $front_list {
	$w.f.front create line [expr $x1] [expr $y1] [expr $x1] [expr $y1] \
		-width [expr $cplanetdWidth] -fill $gHealthy -tags "bar$tag_id"
		#-width $tdwidth -fill $gHealthy -tags "bar$tag_id"

	debug 1 "\n"
	debug 1 "create line x1 y1 x1 y1: $x1 $y1 $x1 $y1 width $tdwidth"

	$w.f.front create text [expr $x1] [expr $y2-10] -text NA \
		-tags "text$tag_id"

	$w.f.front create text [expr $x1] [expr $y2-25] -text -${bar}-

	incr tag_id
	#incr x1 $tdinc
	incr x1 [expr $cplanetdInc]

	debug 1 "new x1: $x1"

    }

    set leg "Asic Temperatures"
    set x1 [expr $x1 / 2 - [string length $leg] / 2 - 4]
    $w.f.front create text [expr $x1] [expr $gTdY2 * .15 ] -text $leg


    # Create the back temperature bars.
    set tag_id 0
    #set x1 $tdx1
    set x1 $gTdX1
    foreach bar $back_list {
	$w.f.back create line [expr $x1] [expr $y1] [expr $x1] [expr $y1] \
		-width $cplanetdWidth -fill $gHealthy -tags "bar$tag_id"
		#-width $tdwidth -fill $gHealthy -tags "bar$tag_id"

	$w.f.back create text [expr $x1] [expr $y2-10] -text NA \
		-tags "text$tag_id"
		#-tags "text$tag_id" -font $gFont1

	$w.f.back create text [expr $x1] [expr $y2-25] -text -${bar}-

	incr tag_id
	#incr x1 $tdinc
	#incr x1 $gTdInc
	incr x1 [expr $cplanetdInc]
    }

    set leg "Asic Temperatures"
    set x1 [expr $x1 / 2 - [string length $leg] / 2 - 4]
    $w.f.back create text [expr $x1] [expr $gTdY2 * .15 ] -text $leg


    frame $w.buttonbox -bg $gBg1
    pack $w.buttonbox -expand yes -fill x -side left

    button $w.buttonbox.dismiss   -bg $gBg1 -fg $gFg1 \
	    -activebackground $gBg1 -activeforeground $gFg1 -text "dismiss" \
	    -command { dismissMe } -font $gFont1 -padx 0

    pack $w.buttonbox.dismiss -fill x 

    #
    # If temperature data is known, display it.
    #
    if {[lsearch -glob $gThermalList $board*] >= 0} {
	thermalDetailUpdate $board
    }
}

#
# A request to display thermal detail for a particular board has been noted.
#
proc thermalDetail {board} {
    global gThermalList
    global gPidMibFresh
    global gHostviewName
    global gMibRefreshFreq

    debug 2 "thermalDetail entry:$board"
    if { [llength $board] < 1 } {
	debug 2 "thermalDetail board is null"
	return
    }

    #
    # There can only be one copy of this window.
    #
    set w .thermalDetail_$board
    if [winfo exists $w] {
	raise $w
	return
    } 

    switch $board {
	ctr {thermalDetailCtrBoard $board}

	csb0 {thermalDetailSupBoard $board}
	csb1 {thermalDetailSupBoard $board}

	cb0 {thermalDetailConBoard $board}
	cb1 {thermalDetailConBoard $board}

	0  {thermalDetailSysBoard $board}
	1  {thermalDetailSysBoard $board}
	2  {thermalDetailSysBoard $board}
	3  {thermalDetailSysBoard $board}
	4  {thermalDetailSysBoard $board}
	5  {thermalDetailSysBoard $board}
	6  {thermalDetailSysBoard $board}
	7  {thermalDetailSysBoard $board}

	8  {thermalDetailSysBoard $board}
	9  {thermalDetailSysBoard $board}
	10 {thermalDetailSysBoard $board}
	11 {thermalDetailSysBoard $board}
	12 {thermalDetailSysBoard $board}
	13 {thermalDetailSysBoard $board}
	14 {thermalDetailSysBoard $board}
	15 {thermalDetailSysBoard $board}

	default {debug 5 "==>SWITCH DEFAULT in thermalDetail: $board"}
    }

    # if no thermal details are up, read the mib
    set count [countDetails thermal]
    debug 1 "count details: $count"
    if { $count < 2 } {
	if {[catch [ tkwait visibility $w ] result] } {
	    debug 4 $result
	    return
	}
	hv_hostinfo -t
    }

    if ![info exists gPidMibFresh] {
	if {[catch {exec hostview_child -M "$gHostviewName $gMibRefreshFreq" &} result] } {
	    debug 10 $result
	}
    }
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)thermalTrap.tcl	1.7	97/07/01 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   New temperature information has arrived.
#   Add it to gThermalList, test for excessive temperatures.
#   Cause various windows to be updated.
#

proc thermalTrap {board temps} {
    global gBg1
    global gProblem
    global gHealthy

    global gThermalList
    global gThermalProblem

    global gBackBoards
    global gFrontBoards

    global gBackSysBoards
    global gFrontSysBoards

    global gWARNps
    global gWARNproc
    global gWARNasic
    global gWARNamb

    debug 2 "thermalTrap:$board $temps"

    #
    # Begin by updating the thermal value list.
    #
    updateThermal $board 0 $temps

    #
    # Refresh the detail form
    #
    set w .thermalDetail_$board
    if [winfo exists $w] {
	$w.buttonbox.dismiss config -state disabled
	$w.buttonbox.dismiss config -cursor watch
	thermalDetailUpdate $board
	$w.buttonbox.dismiss config -state normal
	$w.buttonbox.dismiss config -cursor arrow
    }

    #
    # Test for problem event
    #
    set problem 0
    if {[string compare ctr $board] == 0} {
	# 10x2 temperature sensors (front and back)
	foreach ndx1 $temps {
	    foreach ndx2 $ndx1 {
                # temp checking should be against gWARNasic, not gWARNamb. bug fix 4057857
		if {$ndx2 > $gWARNasic} {
		#####if {$ndx2 > $gThermalProblem}
		    debug 1 "thermalTrap:$board hot temperature"
		    set problem 1
		}
	    }
	}
    } elseif {[string first csb $board] >= 0} {
	# 2 temperature sensors on board (dc)
	foreach ndx2 $temps {
	    if {$ndx2 > $gWARNps} {
	    ######if {$ndx2 > $gThermalProblem}
		debug 1 "thermalTrap:$board hot temperature"
		set problem 1
	    }
	}
    } elseif {[string first cb $board] >= 0} {
	# 3 temperature sensors on board (dc), 3 ambient
	set count 0
	foreach ndx1 $temps {
	    foreach ndx2 $ndx1 {
		if { $count < 3} {
		    if {$ndx2 > $gWARNps} {
		    #####if {$ndx2 > $gThermalProblem}
			debug 1 "thermalTrap:$board hot temperature"
			set problem 1
		    }
		} else {
		    if {$ndx2 > $gWARNamb} {
			debug 1 "thermalTrap:$board hot temperature"
			set problem 1
		    }
		}
		incr count
	    }
	}
    } else {
	# 12 temperature sensors on board, 5 asic, 3 dc, 4 proc
	set count 0
	foreach ndx1 $temps {
	    foreach ndx2 $ndx1 {
		if { $count < 8 } {
		    if { $count < 5 } {
			if {$ndx2 > $gWARNasic} {
			    ###if {$ndx2 > $gThermalProblem}
			    debug 1 "thermalTrap:$board hot temperature"
			    set problem 1
			} 
		    } else {
			if {$ndx2 > $gWARNps} {
			    debug 1 "thermalTrap:$board hot temperature"
			    set problem 1 
			} 
		    }
		} else {
		    if {$ndx2 > $gWARNproc} {
			debug 1 "thermalTrap:$board hot temperature"
			set problem 1
		    }
		}
		incr count
	    }
	}
    }

    #
    # If there is a temperature problem, flag the operators attention.
    #
    if {$problem} {
	debug 2 "thermal problem noted"

	updateThermal $board 1 $temps

	if [winfo exists .iconBar.thermal] {
		.iconBar.thermal configure -bg $gProblem
		.iconBar.thermal.button configure -image temperatureRed
	}

	if [winfo exists .wThermal] {
	    set target ".wThermal[sd2path $board]"
	    $target configure -bg $gProblem
	}
    } else {
	if [winfo exists .wThermal] {
	    set target ".wThermal[sd2path $board]"
	    $target configure -bg $gHealthy
	}

	set problem 0
	foreach ndx $gThermalList {
	    if {[lindex $ndx 1] == 1} {
		set problem 1
	    }
	    if {$problem == 0} {
			if [winfo exists .iconBar.thermal] {
				.iconBar.thermal configure -bg $gBg1
				.iconBar.thermal.button configure -image temperature
			}
	    }
	}
    }
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)trapAction.tcl	1.39	99/11/22 SMI"
#
# Copyright (c) 1996-1999 by Sun Microsystems, Inc.
# All rights reserved.
#
# this files contains individual trap handlers for each trap.
# only one handler is installed, with a case statement calling
# the trap handlers in this file.
#
#
#
#
#
#
#
# Global variable declaration:
# same name space as populateCanvas.tcl
set ins 0

set PLATFORM_MIB platformName.$ins
set SYSBRD_NUM sysBrdStarfireNum.
set CBBRD_NUM cbStarfireNum.
set CP_NUM centerplaneStarfireNum.
set CSB_NUM suppBrdStarfireNum.

set SYSBRD_GENNUM sysBrdGenNum.
set CBBRD_GENNUM cbGenNum.
set CP_GENNUM centerplaneGenNum.
set CSB_GENNUM suppBrdGenNum.
set FAN_NUM fanGenNum.
set FAN_SLOT fanGenTraySlotNum.
set FAN_STAT fanGenStatus.
set BP_NUM bulkPowerGenNum.

set SYSBRDS confSysBrdList.$ins
set SYSPROCS confProcList.$ins
set CONBRDS confConBrdList.$ins
set SUPPBRDS confSuppBrdList.$ins
set FANLIST confFanTrayList.$ins
set BPOWERLIST confBulkPowerList.$ins

set DOMAINNAME domainName
set DOMAINSYSBRDS domainSysBrdList

set NUM_DOMAIN confNumDomain
set DOMAINNUMSYSBRD domainNumSysBrd
#set domABUS domainABusConfig
#set domDBUS domainDBusConfig


set PROCNUM procStateGenNum.
set PGMSIGNATURE procStateGenPgmSignature.
set PGMSTATE procStateGenPgmState.
set PGMSUBSTATE procStateGenPgmSubState.

set OLD_TMP_SB_TABLE "sysBrdStarfireCIC0Temp sysBrdStarfireCIC1Temp sysBrdStarfireMCTemp sysBrdStarfireXDB2Temp sysBrdStarfireXDB3Temp sysBrdStarfirePROC0Temp sysBrdStarfirePROC1Temp sysBrdStarfirePROC2Temp sysBrdStarfirePROC3Temp sysBrdStarfirePS2Temp sysBrdStarfirePS4Temp sysBrdStarfirePS5Temp"

set TMP_SB_TABLE "sysBrdStarfireCIC0Temp sysBrdStarfireCIC1Temp sysBrdStarfireMCTemp sysBrdStarfireXDB2Temp sysBrdStarfireXDB3Temp sysBrdStarfirePROC0Temp sysBrdStarfirePROC1Temp sysBrdStarfirePROC2Temp sysBrdStarfirePROC3Temp sysBrdStarfire3p3VDCTemp sysBrdStarfireVDCCoreTemp sysBrdStarfire5VDCTemp"

set OLD_TMP_CB_TABLE "cbStarfirePS1Temp cbStarfirePS2Temp cbStarfirePS3Temp cbStarfireSen0Temp cbStarfireSen1Temp cbStarfireSen2Temp"

set TMP_CB_TABLE "cbStarfire5VDCTemp cbStarfire5VDCPerTemp cbStarfire5VDCFanTemp cbStarfireSen0Temp cbStarfireSen1Temp cbStarfireSen2Temp"

set OLD_TMP_CSB_TABLE "suppBrdStarfirePS1Temp suppBrdStarfirePS2Temp"

set TMP_CSB_TABLE "suppBrdStarfire3p3VDC1Temp suppBrdStarfire3p3VDC2Temp"

set TMP_CP_TABLE "centerplaneStarfireTemp0 centerplaneStarfireTemp1 centerplaneStarfireTemp2 centerplaneStarfireTemp3 centerplaneStarfireTemp4 centerplaneStarfireTemp5 centerplaneStarfireTemp6 centerplaneStarfireTemp7 centerplaneStarfireTemp8 centerplaneStarfireTemp9"

set OLD_PWR_SB_TABLE "sysBrdStarfireVDD sysBrdStarfire5VDCHK sysBrdStarfire5VDC sysBrdStarfireVDDCore sysBrdStarfire3p3VDCHK"

set PWR_SB_TABLE "sysBrdStarfire3p3VDC sysBrdStarfire5VDCHK sysBrdStarfire5VDC sysBrdStarfireVDCCore sysBrdStarfire3p3VDCHK"

set OLD_PWR_CB_TABLE "cbStarfire5VDC cbStarfire5VDCHK cbStarfire3p3VDCHK cbStarfireVccPer cbStarfireVccFan"

set PWR_CB_TABLE "cbStarfire5VDC cbStarfire5VDCHK cbStarfire3p3VDCHK cbStarfire5VDCPer cbStarfire5VDCFan"

set OLD_PWR_CSB_TABLE "suppBrdStarfire5VDCHK suppBrdStarfire3p3VDCHK"

set PWR_CSB_TABLE "suppBrdStarfire3p3VDC suppBrdStarfire5VDCHK suppBrdStarfire3p3VDCHK"

set OLD_PWR_CP_TABLE "centerplaneStarfire3p3VDC0 centerplaneStarfire3p3VDC1 centerplaneStarfire3p3VDC2"

set PWR_CP_TABLE ""

# trap 0 domainChange

proc domainChange { list } {

    global DOMAINNAME domainName
    global DOMAINSYSBRDS domainSysBrdList

    global NUM_DOMAIN confNumDomain
    global DOMAINNUMSYSBRD domainNumSysBrd
    #global domABUS domainABusConfig
    #global domDBUS domainDBusConfig

    global gDomains
    global gDomainView

    debug 1 "domainChange: "
    set ndx -1
    foreach vb $list {
	if {[lsearch [mib name [lindex $vb 0]] $NUM_DOMAIN*] > -1 } {
	    set numDomain [ lindex $vb 2]
	    break
	}
    }
    if { ![info exists numDomain] } {
	return ""
    }

    #build up new gDomains: "{xf2 {2}} {xf2-b4 {4}}"

    foreach vb $list {
	set instance [lindex [split [mib name [lindex $vb 0]] .] 1]
	set mibname [lindex [split [mib name [lindex $vb 0]] .] 0]
	if { [string compare $mibname $DOMAINSYSBRDS] == 0 } {
	    set domainsys($instance) [split [lindex $vb 2] -]
	} elseif { [string compare $mibname $DOMAINNAME] == 0 } {
	    set domainname($instance) [lindex $vb 2]
	}
    }
    set newgDomains ""
    for { set i 0 } { $i < $numDomain } { incr i} {
	set eachdomain [format "%s {%s}" $domainname($i) $domainsys($i)]
	set newgDomains [format "%s {%s}" $newgDomains $eachdomain]
    }

    debug 1 "newgDomains: $newgDomains"
    debug 1 "gDomains: $gDomains"
    # compare new list with the old list.
    for { set i 0 } { $i < [llength $gDomains ] } { incr i} {
	set old($i) [lindex $gDomains $i]
	set oldname($i) [lindex $old($i) 0]

	set domndx [exactMatch $newgDomains $oldname($i) ]
	set oldboards($i) [lindex $old($i) 1]

	if { $domndx == -1 } {
	    
	    # remove this domain
	    foreach board $oldboards($i) {
		# this removes boards, canvas color and domain if last board.
		rmBfromDomain $board $oldname($i)
	    }
	} else {
	    foreach board $oldboards($i) {
		set ndx -1
		set ndx [lsearch [lindex [lindex $newgDomains $domndx] 1 ] $board]
		# this board is not in the new config
		if { $ndx == -1 } {
		    rmBfromDomain $board $oldname($i)
		}
	    }
	    foreach board [lindex [lindex $newgDomains $domndx] 1] {
		set ndx -1
		set ndx [lsearch $oldboards($i) $board]
		if { $ndx == -1 } {
		    # this board is a new addition
		    setDomain $board $oldname($i)
		}
	    }
	}
    }
    # ok, now all the domains whose names are still here have
    # been updated.  Look for brand new domains to add.

    for { set i 0 } { $i < [llength $newgDomains ] } { incr i} {
	set dndx [domainIndex [lindex [lindex $newgDomains $i] 0]]
	if { $dndx == -1 } {
	    # new domain
	    set newname [lindex [lindex $newgDomains $i] 0]
	    foreach board [ lindex [lindex $newgDomains $i] 1 ] {
		setDomain $board $newname
	    }
	}
    }
    debug 1 "gDomains: $gDomains"
    # if we were only viewing a single domain, put it back like that
    if [info exists gDomainView] {
	setDomainView $gDomainView
    }
}
# trap 3 sysBrdTempNorm
# trap 4 sysBrdTempHigh
# trap 5 sysBrdTempWarn
# trap 6 sysBrdTempMax
# trap 7 sysBrdTemp911
# trap 8 sysBrdTempBad

proc sbtempTrap { list type flag } {
    global SYSBRD_NUM
    global TMP_SB_TABLE


    set norm 3
    set ndx -1
    foreach vb $list {
	if {[lsearch [mib name [lindex $vb 0]] $SYSBRD_NUM*] > -1 } {
	    set sysbrd [ lindex $vb 2]
	    break
	}
    }
    if { ![info exists sysbrd] } {
	return ""
    }

    foreach vb $list {
	if { [lsearch $TMP_SB_TABLE [lindex [split \
		[mib name [lindex $vb 0]] .] 0]] > -1 } {
	    set ndx [lsearch $TMP_SB_TABLE [lindex [split \
		    [mib name [lindex $vb 0]] .] 0]]

	    set temp [format "%.2s" [expr [lindex $vb 2] /1000.0]]
	    update1Thermal $sysbrd $ndx $temp
	}
    }
    if { $ndx >= 0 } {
	set thermvalue [lindex [whatTemperature $sysbrd] 2]
	thermalTrap $sysbrd "$thermvalue" 
    }

    set type "System Board $sysbrd temperature is at $type levels"
    # anomalous temps are logged, normal trap clears the filtering.
    if { $flag != $norm } {
	sysFail $list $type $flag
    } else {
	clearTrap $flag $sysbrd
    }
}

# trap 10 cbTempNorm
# trap 11 cbTempHigh
# trap 12 cbTempWarn
# trap 13 cbTempMax
# trap 14 cbTemp911
# trap 15 cbTempBad
proc cbtempTrap { list type flag} {
    global CBBRD_NUM
    global TMP_CB_TABLE

    set norm 10
    set ndx -1
    foreach vb $list {
	if {[lsearch [mib name [lindex $vb 0]] $CBBRD_NUM*] > -1 } {
	    set board [ lindex $vb 2]
	    break
	}
    }
    if { ![info exists board] } {
	return ""
    }

    foreach vb $list {
	if { [lsearch $TMP_CB_TABLE [lindex [split \
		[mib name [lindex $vb 0]] .] 0]] > -1 } {
	    set ndx [lsearch $TMP_CB_TABLE [lindex [split \
		    [mib name [lindex $vb 0]] .] 0]]

	    set temp [format "%.2s" [expr [lindex $vb 2] /1000.0]]
	    update1Thermal cb$board $ndx $temp
	}
    }
    if { $ndx >= 0 } {
	set thermvalue [lindex [whatTemperature cb$board] 2]
	thermalTrap cb$board "$thermvalue" 
    }

    set type "Control Board $board temperature is at $type levels"

    # anomalous temps are logged
    if { $flag != $norm } {
	sysFail $list $type $flag
    } else {
	clearTrap $flag $board
    }
}


# trap 17 ctrTempNorm
# trap 18 ctrTempHigh
# trap 19 ctrTempWarn
# trap 20 ctrTempMax
# trap 21 ctrTemp911
# trap 22 ctrTempBad
proc ctrtempTrap { list type flag} {
    global CP_NUM
    global TMP_CP_TABLE


    set norm 17
    set ndx -1
    foreach vb $list {
	if {[lsearch [mib name [lindex $vb 0]] $CP_NUM*] > -1 } {
	    set board [ lindex $vb 2]
	    break
	}
    }
    if { ![info exists board] } {
	return ""
    }

    foreach vb $list {
	if { [lsearch $TMP_CP_TABLE [lindex [split \
		[mib name [lindex $vb 0]] .] 0]] > -1 } {
	    set ndx [lsearch $TMP_CP_TABLE [lindex [split \
		    [mib name [lindex $vb 0]] .] 0]]

	    set temp [format "%.2s" [expr [lindex $vb 2] /1000.0]]

	    # centerplane 0, 1 are on same gui, kept in one list.
	    set offset [expr $board * [llength $TMP_CP_TABLE]]
	    update1Thermal ctr [expr $ndx + $offset] $temp
	}
    }
    if { $ndx >= 0 } {
	set thermvalue [lindex [whatTemperature ctr] 2]
	thermalTrap ctr "$thermvalue" 
    }
    set type "Centerplane $board temperature is at $type levels"

    # anomalous temps are logged
    if { $flag != $norm } {
	sysFail $list $type $flag
    } else {
	clearTrap $flag $board
    }
}


# trap 24 cbeconnected
# no longer sending normal traps on startup.
# this is the replacement

proc cbeConnected { list  } {
    global gBg1
    global gFg1
    global gBoards
    global gProcessors
    global gBusUP
    global gDomains
    global gSelectedBoard
    global gSelectedBoardList
    global gDomainColorMap
    global gDomainNameMap
    global gDomainColors


    sendNormTraps

    # clear out the internal lists for boards and procs and buses
    set gBoards ""
    setupBoardList

    set gProcessors ""
    setupProcList

    set gBusUP ""

    # deselect the boards and reset the list
    foreach board $gSelectedBoard  {
        set result [boardPath $board]
        debug 1 $result
        $result.select configure -bg $gBg1
    }
    set gSelectedBoard ""
    set gSelectedBoardList ""

    # remove old domains  to prevent same domain from showing up on View twice
    foreach domain $gDomains  {
       set domainName [lindex $domain 0]
       debug 1 $domainName
       rmDomain  $domainName
    }
    set gDomains ""


    # reset domain color map 
    set gDomainColorMap ""
    foreach color $gDomainColors {
       set gDomainColorMap "$gDomainColorMap -1"
    }

    # clear out the drawing on the main GUI with cleared out lists 
    invisibleSystemGraphic $gBg1 $gFg1
   
    # read mib data after cbe reconnected. 
    hv_hostinfo -h
    MIBfresh
}

# trap 26 csbTempNorm
# trap 27 csbTempHigh
# trap 28 csbTempWarn
# trap 29 csbTempMax
# trap 30 csbTemp911
# trap 31 csbTempBad

proc csbtempTrap { list type flag } {
    global CSB_NUM
    global TMP_CSB_TABLE


    set norm 26
    set ndx -1
    foreach vb $list {
	if {[lsearch [mib name [lindex $vb 0]] $CSB_NUM*] > -1 } {
	    set board [ lindex $vb 2]
	    break
	}
    }
    if { ![info exists board] } {
	debug 1 "no board name given"
	return ""
    }

    foreach vb $list {
	if { [lsearch $TMP_CSB_TABLE [lindex [split \
		[mib name [lindex $vb 0]] .] 0]] > -1 } {
	    set ndx [lsearch $TMP_CSB_TABLE [lindex [split \
		    [mib name [lindex $vb 0]] .] 0]]

	    set temp [format "%.2s" [expr [lindex $vb 2] /1000.0]]
	    update1Thermal csb$board $ndx $temp
	}
    }
    if { $ndx >= 0 } {
	set thermvalue [lindex [whatTemperature csb$board] 2]
	thermalTrap csb$board "$thermvalue" 
    }
    set type "Centerplane Support Board $board temperature is at $type levels"

    # anomalous temps are logged
    if { $flag != $norm } {
	sysFail $list $type $flag
    } else {
	clearTrap $flag $board
    }
}




# trap 33 sysBrdVoltNorm
# trap 34 sysBrdVoltMax
# trap 35 sysBrdVoltMin
# trap 36 sysBrdVoltBad

proc sbvoltTrap { list type flag } {
    global SYSBRD_NUM
    global PWR_SB_TABLE


    set norm 33
    set ndx -1
    foreach vb $list {
	if {[lsearch [mib name [lindex $vb 0]] $SYSBRD_NUM*] > -1 } {
	    set sysbrd [ lindex $vb 2]
	    break
	}
    }
    if { ![info exists sysbrd] } {
	return ""
    }

    foreach vb $list {
	if { [lsearch $PWR_SB_TABLE [lindex [split \
		[mib name [lindex $vb 0]] .] 0]] > -1 } {
	    set ndx [lsearch $PWR_SB_TABLE [lindex [split \
		    [mib name [lindex $vb 0]] .] 0]]

	    set volt [format "%.5s" [expr [lindex $vb 2] /1000.0]]
	    update1Power $sysbrd $ndx $volt
	}
    }
    if { $ndx >= 0 } {
	set voltvalue [lindex [whatPower $sysbrd] 2]
	powerTrap $sysbrd "$voltvalue" 
    }

    set type "System Board $sysbrd Voltages are $type"

    # anomalous voltages are logged
    if { $flag != $norm } {
	sysFail $list $type $flag
    } else {
	clearTrap $flag $sysbrd
    }
}

# trap 38 cbVoltNorm
# trap 39 cbVoltMax
# trap 40 cbVoltMin
# trap 41 cbVoltBad

proc cbvoltTrap { list type flag} {
    global CBBRD_NUM
    global PWR_CB_TABLE


    set norm 38
    set ndx -1
    foreach vb $list {
	if {[lsearch [mib name [lindex $vb 0]] $CBBRD_NUM*] > -1 } {
	    set board [ lindex $vb 2]
	    break
	}
    }
    if { ![info exists board] } {
	return ""
    }

    foreach vb $list {
	if { [lsearch $PWR_CB_TABLE [lindex [split \
		[mib name [lindex $vb 0]] .] 0]] > -1 } {
	    set ndx [lsearch $PWR_CB_TABLE [lindex [split \
		    [mib name [lindex $vb 0]] .] 0]]

	    set volt [format "%.5s" [expr [lindex $vb 2] /1000.0]]
	    update1Power cb$board $ndx $volt
	}
    }
    if { $ndx >= 0 } {
	set voltvalue [lindex [whatPower cb$board] 2]
	powerTrap cb$board "$voltvalue" 
    }

    set type "Control Board $board Voltages are $type"

    # anomalous voltages are logged
    if { $flag != $norm } {
	sysFail $list $type $flag
    } else {
	clearTrap $flag $board
    }
}

# will go away with the new mib, no voltages on the centerplane

# trap 43 ctrVoltNorm
# trap 44 ctrVoltMax
# trap 45 ctrVoltMin
# trap 46 ctrVoltBad

proc ctrvoltTrap { list type flag} {
    
    global CP_NUM
    global PWR_CP_TABLE


    set norm 43
    set ndx -1
    foreach vb $list {
	if {[lsearch [mib name [lindex $vb 0]] $CP_NUM*] > -1 } {
	    set board [ lindex $vb 2]
	    break
	}
    }
    if { ![info exists board] } {
	return ""
    }

    foreach vb $list {
	if { [lsearch $PWR_CP_TABLE [lindex [split \
		[mib name [lindex $vb 0]] .] 0]] > -1 } {
	    set ndx [lsearch $PWR_CP_TABLE [lindex [split \
		    [mib name [lindex $vb 0]] .] 0]]
	    
	    set temp [format "%.5s" [expr [lindex $vb 2] /1000.0]]
	    
	    # centerplane 0, 1 are on same gui, kept in one list.
	    set offset [expr $board * [llength $PWR_CP_TABLE]]
	    update1Power ctr [expr $ndx + $offset] $temp
	}
    }
    if { $ndx >= 0 } {
	set pwrvalue [lindex [whatPower ctr] 2]
	powerTrap ctr "$pwrvalue" 
    }
    
    set type "Centerplane $board Voltages are $type"

    # anomalous voltages are logged
    if { $flag != $norm } {
	sysFail $list $type $flag
    }  else {
	clearTrap $flag $board
    }
}



# trap 48 csbVoltNorm
# trap 49 csbVoltMax
# trap 50 csbVoltMin
# trap 51 csbVoltBad


proc csbvoltTrap { list type flag } {

    global CSB_NUM
    global PWR_CSB_TABLE
    
    debug 1 "csbvoltTrap: $flag"

    set norm 48
    set ndx -1
    foreach vb $list {
	if {[lsearch [mib name [lindex $vb 0]] $CSB_NUM*] > -1 } {
	    set board [ lindex $vb 2]
	    break
	}
    }
    if { ![info exists board] } {
	debug 1 "no board name given"
	return ""
    }
    debug 1 $board

    foreach vb $list {
	if { [lsearch $PWR_CSB_TABLE [lindex [split \
		[mib name [lindex $vb 0]] .] 0]] > -1 } {
	    set ndx [lsearch $PWR_CSB_TABLE [lindex [split \
		    [mib name [lindex $vb 0]] .] 0]]
	    
	    set temp [format "%.5s" [expr [lindex $vb 2] /1000.0]]
	    update1Power csb$board $ndx $temp
	}
    }
    if { $ndx >= 0 } {
	set pwrvalue [lindex [whatPower csb$board] 2]
	powerTrap csb$board "$pwrvalue" 
    }

    set type "Centerplane Support Board $board Voltages are $type"

    # anomalous voltages are logged
    if { $flag != $norm } {
	sysFail $list $type $flag
    } else {
	clearTrap $flag $board
    }
}
    

# trap 53 fanNorm
# trap 54 fanFail

proc fanTrapResp { list flag} {
    global FAN_NUM
    global FAN_SLOT
    global FAN_STAT

    set num ""
    set slot ""
    set status ""
    foreach vb $list {
	if {[lsearch [mib name [lindex $vb 0]] $FAN_NUM*] > -1 } {
	    set num [lindex $vb 2]
	} elseif {[lsearch [mib name [lindex $vb 0]] $FAN_SLOT*] > -1} {
	    set slot [lindex $vb 2]
	} elseif {[lsearch [mib name [lindex $vb 0]] $FAN_STAT*] > -1} {
	    set status [lindex $vb 2]
	}
    }
    if { ![llength $slot] || ![llength $num] } {
	debug 5 "slot: $slot or fan num: $num missing from trap"
	return ""
    }

    if { [string compare $flag fail] == 0} {
	set action fail
    } else {
	set action repair
    }

    debug 1 "fanTrapResp: $action $slot $num"

    switch [expr [expr $num +2 ] % 2 ] {
	"0" { set fanid ft${slot}a }
	"1" { set fanid ft${slot}b }
    }
    fanTrap $action $fanid

    if { $flag == "norm" } {
	if { $status == "on" } {
	    #sysFail $list "Fan $num in slot $slot is" on ;# bugid 4234748
	    fanTrap powerOn $fanid
	} else {
	    #sysFail $list "Fan $num in slot $slot is" off ;# bugid 4234748
	    fanTrap powerOff $fanid
	}
    } elseif { $flag == "fail" } {
	#fanTrap fail $fanid
	# the filtering doesn't work because fan traps come
	# at a low frequency compared to arbstop etc.  fix after fcs.
	sysFail $list "Fan $num in slot $slot has" failed

    }
}

# trap 55 sysconfigchange
proc sysconfigchange {list } {
    global SYSBRDS
    global SYSPROCS
    global CONBRDS
    global SUPPBRDS
    global FANLIST
    global BPOWERLIST
    global gSystemBoards
    global gcbBoards
    global gcsbBoards
    global gFanDrawers
    global gBulkPower
    global gDomainView


    foreach vb $list {
	if {[string compare [mib name [lindex $vb 0]] $SYSBRDS] == 0 } {
	    set sysbrds [ split [lindex $vb 2] - ]
	    debug 1 "sysbrds: $sysbrds"
	} elseif {[string compare [mib name [lindex $vb 0]] $SYSPROCS] == 0} {
	    set sysprocs [ split [lindex $vb 2] - ]
	    debug 1 "sysprocs: $sysprocs"
	} elseif {[string compare [mib name [lindex $vb 0]] $CONBRDS] == 0} {
	    set conbrds [ split [lindex $vb 2] - ]
	    debug 1 "conbrds: $conbrds"
	} elseif {[string compare [mib name [lindex $vb 0]] $SUPPBRDS] == 0} {
	    set suppbrds [ split [lindex $vb 2] - ]
	    debug 1 "suppbrds: $suppbrds"
	} elseif {[string compare [mib name [lindex $vb 0]] $FANLIST] == 0} {
	    set fanlist [ split [lindex $vb 2] - ]
	    debug 1 "fanlist: $fanlist"
	} elseif {[string compare [mib name [lindex $vb 0]] $BPOWERLIST] == 0} {
	    set bpowerlist [ split [lindex $vb 2] - ]
	    debug 1 "bpowerlist: $bpowerlist"
	}
    }
    if { [ info exists sysprocs] } {
	set proclist ""
	foreach proc $sysprocs {
	    set eaproc [ split $proc . ]
	    set procnum [expr [lindex $eaproc 0] * 4 + [lindex $eaproc 1]]
	    set proclist "$proclist $procnum"
	}
	#update gProcessors
    }

    if { [info exists sysbrds] } {
	debug 1 "sysbrds: $sysbrds"
	foreach board $gSystemBoards {
	    set found 0
	    if { [string first $board $sysbrds] > -1} {
		foreach sbrd $sysbrds {
		    if { [string compare $sbrd $board] == 0 } {
			boardDiscovered $board
			set state [whatBoardState $board]
			if { [lsearch $state power_on] > -1} {
			    boardPowerUp $board
			}
			set dom [whatIsMyDomain $board]
			if { [string compare $dom "no_domain"] != 0} {
			    setDomain $board $dom
			}
			set found 1
			break
		    }
		}
	    }
	    if { !$found } {
		boardPowerDown $board
		boardRemoved $board
		if { [string compare [whatIsMyDomain $board] "no_domain"] != 0} {
		    set dom [whatIsMyDomain $board]
		    #remove the color
		    rmBfromDomain $board $dom
		    # but leave it marked as a member of the domain
		    setDomain $board $dom
		}
	    }
	}
    } 
    if { [info exists conbrds] } {
	foreach board $gcbBoards {
	    set cb [ string trimleft $board cb]
	    if { [string first $cb $conbrds] > -1} {
		boardDiscovered cb$cb
		set state [whatBoardState cb$cb]
		if { [lsearch $state power_on] > -1} {
		    boardPowerUp cb$cb
		}
	    } else {
		boardPowerDown cb$cb
		boardRemoved cb$cb
		#boardPowerDown cb$cb
	    }
	}
    }
    if { [info exists suppbrds] } {
	foreach board $gcsbBoards {
	    set csb [ string trimleft $board csb]
	    if { [string first $csb $suppbrds] > -1} {
		boardDiscovered csb$csb
		set state [whatBoardState csb$csb]
		if { [lsearch $state power_on] > -1} {
		    boardPowerUp csb$csb
		}
	    } else {
		boardPowerDown csb$csb
		boardRemoved csb$csb
		#boardPowerDown csb$csb
	    }
	}
    }
    if { [info exists fanlist] } {
	foreach fantray $gFanDrawers {
	    set found 0
	    set traynum [ string trimleft $fantray ft]
	    if { [string first $traynum $fanlist] > -1} {
		foreach fan $fanlist {
		    if { [string compare $fan $traynum] == 0 } {
			fan_bpDiscovered ft$traynum fan
			set found 1
			break
		    }
		}
	    }
	    if { !$found } {
		fan_bpRemoved ft$traynum fan
		set fans [whatFansPowered]
		if {[lsearch $fans ft$traynum] > -1 } {
		    updateFansPowered ft$traynum powerOff
		}
		set fans [whatFanFailure]
		if {[lsearch $fans ft$traynum*] > -1 } {
		    updateFanFailure ft${traynum}a repair
		    updateFanFailure ft${traynum}b repair
		}
	    }
	}
    }
    if { [info exists bpowerlist] } {
	foreach bpower $gBulkPower {
	    set found 0
	    set ps [ string trimleft $bpower bp]
	    if { [string first $ps $bpowerlist] > -1} {
		foreach supply $bpowerlist {
		    if { [string compare $supply $ps] == 0 } {
			fan_bpDiscovered $ps bpower
			set found 1
			break
		    }
		}
	    }
	    if { !$found } {
		fan_bpRemoved bp$ps bpower
		updateBPconf bp$ps remove
		set BPs [whatBpsPowered]
		if {[lsearch $BPs bp$ps] > -1 } {
		    updateBPsPowered bp$ps powerOff
		}
		set BPs [whatBpFailure]
		if {[lsearch $BPs bp$ps] > -1 } {
		    updateBPFailure bp$ps repair
		}

	    }
	}
    }
    # if we were only viewing a single domain, put it back like that
    if [info exists gDomainView] {
	setDomainView $gDomainView
    }
}

# trap 56 arbitrationstop
# trap 57 recordStop
# trap 58 watchdog
# trap 59 environmentalShutdown
# trap 60 reboot
# trap 61 panic1
# trap 62 panic2
# trap 63 panicReboot
# trap 64 heartbeatFailure
# trap 74 clusterArbstop
# trap 75 clusterRecordstop

proc sysFail {list flag intflag} {
    global gHvFailLogDir
    global gSysFailLog
    global gProblem
    global DOMAINNAME
    global gSystemFail
    global gFailTextSize
    global gFilebase
    global gHvMaxFails2Log
    global gFailCircCount
	global gFailFd
	global gNdx
    

    debug 1 "$flag $intflag"
    # filter so repeated events don't get written to the log
    set ret [hvTrapFilter $intflag $list]
    debug 1 "filter: $ret"

    if { $ret } {
	return
    }

    if { [catch {set now [exec date]} result] } {
        debug 10 $result
        return
    }
    set when [ format "{%s}" $now]
    foreach vb $list {
	if {[lsearch [mib name [lindex $vb 0]] $DOMAINNAME*] > -1 } {
	    set domainname [lindex $vb 2]
	    break
	}
    }

    if { [info exists domainname] } {
	set where $domainname
    } else {
	set where $intflag
    }
    set flag [ format "{ %s }" $flag ]

    set currsize 0
    set baksize 0
    set biggest [expr $gFailTextSize * $gHvMaxFails2Log]

    set numfails [llength $gSystemFail]

    # keep one backup log file, overwite the backup if there was on
    # already.   

    # If our current one is getting too big, 
    # make it a circular buffer.

    if { $numfails == 0  } {
	#    if { $numfails == 0 || $numfails > $gHvMaxFails2Log  }

	set gFailCircCount 0

	if { [file exists $gHvFailLogDir/$gSysFailLog] } {
	    if { [ catch {set currsize [file size $gHvFailLogDir/$gSysFailLog]} errmsg ] } {

		debug 10 "Error reading file $gHvFailLogDir/$gSysFailLog"
		set result [hv_tk_dialog .fileerr "Hostview Error" \
			"Error reading file $gHvFailLogDir/$gSysFailLog" \
			warning 0 OK]
	    }
	    if { [file exists $gHvFailLogDir/${gSysFailLog}.bak] } {
		if { [ catch {set baksize [file size $gHvFailLogDir/${gSysFailLog}.bak]} errmsg ] } {
		    debug 10 "Error reading file $gHvFailLogDir/${gSysFailLog}.bak"
		    set result [hv_tk_dialog .fileerr "Hostview Error" \
			    "Error reading file $gHvFailLogDir/${gSysFailLog}.bak" \
			    warning 0 OK]
		}
	    }
	    if { [expr $currsize + $baksize] < $biggest } {
		if { [catch {exec cat $gHvFailLogDir/$gSysFailLog > $gHvFailLogDir/${gSysFailLog}.bak} errmsg]} {
		    debug 10 "Error concatenating $gHvFailLogDir/$gSysFailLog on $gHvFailLogDir/${gSysFailLog}.bak"
		    set result [hv_tk_dialog .fileerr "Hostview Error" \
			    "Error concatenating $gHvFailLogDir/$gSysFailLog on $gHvFailLogDir/${gSysFailLog}.bak"
		    warning 0 OK]
		}

	    } else {
		if { [catch {exec mv $gHvFailLogDir/$gSysFailLog $gHvFailLogDir/${gSysFailLog}.bak} errmsg]} {
		    debug 10 "Error moving $gHvFailLogDir/$gSysFailLog to $gHvFailLogDir/${gSysFailLog}.bak"
		    set result [hv_tk_dialog .fileerr "Hostview Error" \
			    "Error moving $gHvFailLogDir/$gSysFailLog to $gHvFailLogDir/${gSysFailLog}.bak"
		    warning 0 OK]
		}

	    }
	    if { [catch {exec rm -f $gHvFailLogDir/$gSysFailLog} errmsg]} {
		debug 10 "Error removing $gHvFailLogDir/$gSysFailLog"
		set result [hv_tk_dialog .fileerr "Hostview Error" \
			"Error removing $gHvFailLogDir/$gSysFailLog"
		warning 0 OK]
	    }

	}
    } 


    # if the failure list gets too long, start over, history
    # is in the log file

    if { $numfails >= $gHvMaxFails2Log } {

	set gFailCircCount [expr $gFailCircCount % $gHvMaxFails2Log]

	set gSystemFail [lreplace $gSystemFail $gFailCircCount $gFailCircCount [format {%s %s %s} $flag $where $when]]
	#set gSystemFail ""
    } else {

	set gSystemFail "$gSystemFail {$flag $where $when}"
    }

    # this will creat/append
    # 
    
    if { [file writable $gHvFailLogDir/$gSysFailLog] } {
	if { [ catch {set fileId [ open $gHvFailLogDir/$gSysFailLog r+ 0600]} errmsg ] } {
	    debug 10 "Error opening error log file: $errmsg"
	    return
	}
	if { ![info exists gFilebase] } {
	    set gFilebase [file size $gHvFailLogDir/$gSysFailLog]
	}
    } else {
	if { ![info exists gFilebase] } {
	    set gFilebase 0
	}
	if { [ catch {set fileId [ open $gHvFailLogDir/$gSysFailLog w 0600]} errmsg ] } {
	    debug 10 "Error opening error log file: $errmsg"
	    return
	}
    }


    set ndx $gFailCircCount
    incr gFailCircCount
    #set ndx [expr [llength $gSystemFail] -1]
        
    seek $fileId [expr $gFailTextSize * $ndx + $gFilebase] start

    set junk [tell $fileId]
    debug 1 "tell: $junk"

    debug 1 "gFailCircCount gFailTextSize * ndx + gFilebase: $gFailCircCount $gFailTextSize * $ndx + $gFilebase"

    puts $fileId "=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+="
    puts $fileId $when
    
    if { [info exists domainname] } {
	puts $fileId "domain name: $domainname"
    }


    saveState_part1 $fileId $intflag
    close $fileId

    set gFailFd $fileId
    set gNdx $ndx

}

proc sysFail_part2 { } {
	global gHvFailLogDir
	global gSysFailLog
	global gProblem
	global DOMAINNAME
	global gSystemFail
	global gFailTextSize
	global gFilebase
	global gHvMaxFails2Log
	global gFailCircCount
	global gFailFd
	global gNdx


	set fileId $gFailFd
	set ndx $gNdx

    puts $fileId "=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+="

    #
    # Fill the remainder of the current record with x's so as not to leave
    # unprintable characters in these "holes"
    #
    set current [tell $fileId]
    set end [expr (($current - $gFilebase) / $gFailTextSize + 1) * $gFailTextSize -1]

    set buff ""
    debug 1 "current: $current end: $end"
    set j 0
    for { set i $current } { $i < $end } { incr i } {
	if { $j == 70} {
	    set buff "${buff}\n"
	    set j 0
	} else {
	    set buff "${buff}x"
	    incr j
	}
    }
    debug 1 "buff: $buff buff"
    puts $fileId $buff

    close $fileId
    
    .iconBar.event configure -bg $gProblem
    .iconBar.event.button configure -image eventRed
    
    # should push event icon to bring this up, here for testing
    #eventTextExec
    
}

# trap 65 signatureBlockChange

proc sigblk {list} {

    global PROCNUM
    global PGMSIGNATURE
    global PGMSTATE
    global PGMSUBSTATE
    global gDomainView


    foreach vb $list {
	if {[lsearch [mib name [lindex $vb 0]] $PROCNUM*] > -1 } {
	    set proc [lindex $vb 2]
	} elseif {[lsearch [mib name [lindex $vb 0]] $PGMSIGNATURE*] > -1 } {
	    set sig [lindex $vb 2]
	} elseif {[lsearch [mib name [lindex $vb 0]] $PGMSTATE*] > -1 } {
	    set procstate [lindex $vb 2]
	} elseif {[lsearch [mib name [lindex $vb 0]] $PGMSUBSTATE*] > -1 } {
	    set substate [lindex $vb 2]
	}
    }
    if { [info exists proc] } {
	set brd [ expr $proc / 4 ]
	# make sure the board is powered, or this could be anomalous
	set brdstate [whatBoardState $brd]

	if { [lsearch $brdstate power_on] > -1 } {
	    if {$proc < 10 } {
		set proc 0$proc
	    }

	    set oldstate [lindex [whatProcState $proc] 1]
	    debug 1 "sigblk: oldstate: $oldstate"
	    setProcIcon $proc $sig $procstate

	    # it may actually be blacklisted
	    if { $oldstate == "blacklist" } {
		hv_hostinfo -B
	    }
	}
    } else {
	debug 1 "no processor on signature change trap"
    }
     # if we were only viewing a single domain, put it back like that
    if [info exists gDomainView] {
	setDomainView $gDomainView
    }
}



# trap powerOff
# trap powerOn

proc powerChange {list flag} {

    global SYSBRD_GENNUM
    global CBBRD_GENNUM
    global CP_GENNUM
    global CSB_GENNUM

    global gSystemBoards
    global gcbBoards
    global gcsbBoards
    global gcpBoards

    global gBg1
    global gFg1
    global gDomainView

    global gSelectedBoard
    global gSelectedBoardList

    global gBoardPowerWait

    debug 1 "powerChange $flag $list"
    foreach vb $list {

	set sysbrd ""
	set conbrd ""
	set suppbrd ""
	set cpbrd ""

	if {[lsearch [mib name [lindex $vb 0]] $SYSBRD_GENNUM*] > -1 } {
	    set sysbrd [ lindex $vb 2]
	} elseif {[lsearch [mib name [lindex $vb 0]] $CSB_GENNUM*] > -1} {
	    set suppbrd [ lindex $vb 2]
	} elseif {[lsearch [mib name [lindex $vb 0]] $CBBRD_GENNUM*] > -1} {
	    set conbrd [ lindex $vb 2]
	} elseif {[lsearch [mib name [lindex $vb 0]] $CP_GENNUM*] > -1} {
	    set cpbrd [ lindex $vb 2]
	}

	if { [llength $sysbrd] } {
	    debug 1 "sysbrd: $sysbrd"
	    if { [string compare $flag powerOn] == 0} {
		boardPowerUp $sysbrd
	    } else {
		#invisibleSys $sysbrd $gBg1 $gBg1 NOupdate
		boardPowerDown $sysbrd
		boardDiscovered $sysbrd
		set temp1 [whatBoardState $sysbrd]
		set dom [whatIsMyDomain $sysbrd]
		if {[string compare $dom "no_domain"] != 0} {
		    setDomain $sysbrd $dom
		}
		if { [lsearch $gSelectedBoardList $sysbrd ] > -1 ||
		     [ string compare $gSelectedBoard $sysbrd ] == 0 } {
		    boardSelectTog $sysbrd
		}
		#setDomain $board $domain
	    }
	} elseif { [llength $suppbrd] } {
	    if { [string compare $flag powerOn] == 0} {
		boardPowerUp csb$suppbrd
	    } else {
		boardPowerDown csb$suppbrd
		invisibleSB csb$suppbrd $gBg1 $gBg1
		boardDiscovered csb$suppbrd
	    }
	} elseif { [llength $conbrd] } {
	    if { [string compare $flag powerOn] == 0} {
		boardPowerUp cb$conbrd
	    } else {
		boardPowerDown cb$conbrd
		invisibleCB cb$conbrd $gBg1 $gBg1
		boardDiscovered cb$conbrd
	    }
	} elseif { [llength $cpbrd] } {
	    if { [string compare $flag powerOn] == 0} {
		boardPowerUp ctr
	    } else {
		boardPowerDown ctr
	    }
	}
    }

    # if any power displays are up, read the mib

    after $gBoardPowerWait {
	if { [ countDetails power ] } {
	    hv_hostinfo -p
	}
    }
     # if we were only viewing a single domain, put it back like that
    if [info exists gDomainView] {
	setDomainView $gDomainView
    }
}

# 70 bulkPowerNorm
# 71 bulkPowerFail

proc bpStat { list flag } {
    global BP_NUM

    debug 1 "bpStat $flag $list"
    foreach vb $list {
	if {[lsearch [mib name [lindex $vb 0]] $BP_NUM*] > -1 } {
	    set bp [ lindex $vb 2]
	} 
    }
    if { [llength $bp] } {
	if { [string compare $flag on ] == 0} {
	    #sysFail $list "Bulk Power $bp has been turned"  $flag
	    bpTrap $bp normal

	} else {
	    # filtering doesn't work due to low freq trap occurance,
	    # fix after fcs
	     #sysFail $list "Bulk Power $bp is turned off or has"  $flag
	     bpTrap $bp fail


	}
    }
}

# 72 bootprocChange

proc bootprocChange { list } {
    global gDomainView
    global DOM_PROC_CONF
    global domABUS

    # used to determine black listed procs

    debug 1 "bootprocChange 72: list: $list"

    
    set procconfig ""
    foreach vb $list {
	
	if {[lsearch [mib name [lindex $vb 0]] $DOM_PROC_CONF*] > -1 } {
	    set procconfig [ lindex $vb 2]
	    debug 1 "procconfig: $procconfig"
	} elseif {[lsearch [mib name [lindex $vb 0]] $DOM_PROC_CONF*] > -1} {
	    set abus [ lindex $vb 2]
	}
    }

    # now look for blacklisted procs
	
    if {[ llength $procconfig ] } {
	set procconfig [ split $procconfig - ]
	checkBLprocs $procconfig
    }

    #figure out bus config
    # note could do this without reading mib, use input here....
    hv_hostinfo -b


    # if we were only viewing a single domain, put it back like that
    if [info exists gDomainView] {
	setDomainView $gDomainView
    }
}

proc traptest { list } {
    for { set i 0 } { $i < 5 } { incr i} {
	puts "traptest $i sleep"
	sleep 5
    }
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"%Z%%M%	%I%	%E% SMI"
#
# Copyright (c) 1996-1999 by Sun Microsystems, Inc.
# All rights reserved.
#
#
# filter repeated occurances of the same trap
#
# temp/power traps, once received for a particular board,
# are filtered until a normal trap comes for that board.
#
# other failures have timestamps and are filtered based on trap frequency.
#
# return: 0 if a new trap
#	  1 if a repeated trap
#
proc hvTrapFilter { trapid list } {
    global TRAPID
    global trapseen
    global DOMAINNAME

    #set ARBSTOP_TRAP 0
    set suppbrdVoltChangeTrap 56
    set PanicTrapList "61 62 63"

    debug 1 "trapFilter: $trapid"

    if { [catch {set timestamp [eval exec {date "+%Y %m %d %H %M %S"}]} result] } {
       debug 10 $result
       return 0 
    }
    # E.g., 1996 09 03 17 46 18 (bug 4108443 - use 4-digit years)

    #see if this trap has been here before
    if { ![info exists trapseen($trapid)] } {
	if { $trapid < $suppbrdVoltChangeTrap } {
	    set board [getTrapBoardNum $list]
	    addtrap2list $trapid $board $list
	} else {
	    addtrap2list $trapid "$timestamp" $list

	    # filter every panic trap like another
	    if { [lsearch $PanicTrapList $trapid ] > -1 } {
		addPanicTraps $trapid $list $PanicTrapList $timestamp
	    }
	}
	return 0
    } else {
	# only keep  temp / power on transistion
	# cleared by normal traps or cbe disconnect
	if { $trapid < $suppbrdVoltChangeTrap } {
	    set res [tempPowerCompare $trapid $list]
	    if { $res == 0 } {
		#moved below
		####addtrap2list $trapid "$timestamp" $list
	    }
	} else {
	    # failure traps are filtered by timestamp

	    set res [comparetraplist $trapid "$timestamp" $list]
	    addtrap2list $trapid "$timestamp" $list

	    # filter every panic trap like another
	    if { [lsearch $PanicTrapList $trapid ] > -1 } {

		set domainname "no_domain"
		foreach vb $list {
		    if {[lsearch [mib name [lindex $vb 0]] $DOMAINNAME*] > -1 } {
			set domainname [lindex $vb 2]
			break
		    }
		}
		set res [comparetraplist $trapid "$timestamp" $domainname]
		addPanicTraps $trapid $list $PanicTrapList $timestamp
	    }
	}
	if { $res == 0 } {
	    # new trap
	    return 0
	} else {
	    return 1
	}
    }


}

proc addPanicTraps { trapid list PanicTrapList timestamp } {
    global DOMAINNAME

    debug 1 "addPanicTraps: $trapid"

    # filter every panic trap like another
    if { [lsearch $PanicTrapList $trapid ] > -1 } {
	set domainname "no_domain"
	foreach vb $list {
	    if {[lsearch [mib name [lindex $vb 0]] $DOMAINNAME*] > -1 } {
		set domainname [lindex $vb 2]
		break
	    }
	}
	foreach trapnum $PanicTrapList {
	    addtrap2list $trapnum "$timestamp" $domainname
	}
    }
}

proc sendNormTraps { } {
    global gFrontBoards
    global gBackBoards

    set normalmap(all) "3 10 17 26 33 38 43 48"

    set allboards "$gFrontBoards $gBackBoards"
    foreach trapid $normalmap(all) {
	foreach board $allboards {
		clearTrap $trapid $board
	}
    }
}

proc clearTrap { trapid board} {
    global trapseen

    set normalmap(3) "4 5 6 7 8"
    set normalmap(10) "11 12 13 14 15"
    set normalmap(17) "18 19 20 21 22"
    set normalmap(26) "27 28 29 30 31"
    set normalmap(33) "34 35 36"
    set normalmap(38) "39 40 41"
    set normalmap(43) "44 45 46"
    set normalmap(48) "49 50 51"
    

    debug 1 "clearTrap: trapid: $trapid board: $board"

    # these are cleared by a normal trap
    # prune by board
    # the normal traps are the first of 4 traps for each (max, min, bad)
    
    foreach trapid2 $normalmap($trapid) {
	if { [info exists trapseen($trapid2)] } {

	    set temp1 ""
	    foreach trap $trapseen($trapid2) {
		set oldboard [lindex $trap 0]
		if { [string compare $board $oldboard] != 0 } {
		    set temp1 [format "%s {%s}" $temp1 $trap]
		}
	    }
    
	    set trapseen($trapid2) $temp1
	    debug 1 "pruned trapseen($trapid2): $trapseen($trapid2) board: $board"
	    if { [llength $trapseen($trapid2)] == 0 } {
		unset trapseen($trapid2)
		return 0
	    }
	}
    }
}


proc tempPowerCompare {trapid list} {

    global gTrapFreq
    global trapseen
    global SYSBRD_NUM
    global CBBRD_NUM
    global CSB_NUM
    global CP_NUM

    debug 1 "tempPowerCompare: $trapid"
    debug 1 "trapseen($trapid) $trapseen($trapid)"


    # no, these are cleared by a normal trap
    # non-cleared traps were found.  compare the actual data
    # first compare the board number, then
    # compare the mib names in the traps

    if { 0 } {
	set notime "[lindex  [lindex $list 0] 0] [lindex  [lindex $list 0] 1] "
	set list [lreplace $list 0 0 $notime]
	#debug 1 "list: $list"
    }

    set found 0
    foreach trap $trapseen($trapid) {

	foreach vb $list {
	    if {[lsearch [mib name [lindex $vb 0]] $SYSBRD_NUM*] > -1 } {
		set board [ lindex $vb 2]
		break
	    } elseif {[lsearch [mib name [lindex $vb 0]] $CBBRD_NUM*] > -1 } {
		set board [ lindex $vb 2]
		break
	    } elseif {[lsearch [mib name [lindex $vb 0]] $CSB_NUM*] > -1 } {
		set board [ lindex $vb 2]
		break
	    } elseif {[lsearch [mib name [lindex $vb 0]] $CP_NUM*] > -1 } {
		set board [ lindex $vb 2]
		break
	    }
	}
	if { ![info exists board] } {
	    #return 0
	    debug 10 "tempPowerCompare: no board number on $trapid $list"
	    set found 1
	    break
	}

	set oldlist [lindex $trap 1]
	if { [llength $list] != [llength $oldlist] } {
	    break
	}

	foreach vb $list {
	    set mibname [lindex  [lindex $list 0] 0]
	    set namematch 0
	    foreach vb $oldlist {
		set oldmibname [lindex  [lindex $oldlist 0] 0]
		if { [string compare $oldmibname $mibname] == 0 } {
		    set namematch 1
		    break
		}
	    }
	    if { $namematch != 1 } {
		break
	    }
	}
	if { $namematch != 1 } {
		break
	}

	foreach vb $oldlist {
	    if {[lsearch [mib name [lindex $vb 0]] $SYSBRD_NUM*] > -1 } {
		set oldboard [ lindex $vb 2]
		break
	    } elseif {[lsearch [mib name [lindex $vb 0]] $CBBRD_NUM*] > -1 } {
		set oldboard [ lindex $vb 2]
		break
	    } elseif {[lsearch [mib name [lindex $vb 0]] $CSB_NUM*] > -1 } {
		set oldboard [ lindex $vb 2]
		break
	    } elseif {[lsearch [mib name [lindex $vb 0]] $CP_NUM*] > -1 } {
		set oldboard [ lindex $vb 2]
		break
	    }
	}
	if { ![info exists oldboard] } {
	    #return 0
	     debug 10 "tempPowerCompare: no OLDboard number on $trapid $list"
	     set found 1
	     break
	}
	if { $board == $oldboard } {
	    set found 1
	}
    }
    if { $found == 1 } {
	return 1
    } else {
	addtrap2list $trapid $board $list
	return 0
    }

}

proc getTrapBoardNum { list } {

    global SYSBRD_NUM
    global CBBRD_NUM
    global CSB_NUM
    global CP_NUM

    set board ""
    foreach vb $list {
	if {[lsearch [mib name [lindex $vb 0]] $SYSBRD_NUM*] > -1 } {
	    set board [ lindex $vb 2]
	    break
	} elseif {[lsearch [mib name [lindex $vb 0]] $CBBRD_NUM*] > -1 } {
	    set board [ lindex $vb 2]
	    break
	} elseif {[lsearch [mib name [lindex $vb 0]] $CSB_NUM*] > -1 } {
	    set board [ lindex $vb 2]
	    break
	} elseif {[lsearch [mib name [lindex $vb 0]] $CP_NUM*] > -1 } {
	    set board [ lindex $vb 2]
	    break
	}
    }
    return $board
}

proc addtrap2list {trapid timestamp list} {

    global trapseen
    
    debug 1 "addtrap2list: $trapid $timestamp"
    #debug 1 "list: $list"

    if { [info exists trapseen($trapid)] } {
	set oldlist $trapseen($trapid)
    } else {
	set oldlist ""
    }
    set newtrap [format "{%s} {%s}" $timestamp $list]
    set temp1 [format "%s {%s}" $oldlist $newtrap]
    set trapseen($trapid) $temp1
    debug 1 "trapseen($trapid) $trapseen($trapid)"

}

#
# trapseen($trapid) : "{{timestamp} {list}} {{timestamp} {list}} "
#
proc comparetraplist {trapid newtime list} {
    global gTrapFreq
    global trapseen

    debug 1 "comparetraplist: $trapid $newtime"
    debug 1 "trapseen($trapid) $trapseen($trapid)"

    #prune old timestamps

    set temp1 ""
    foreach trap $trapseen($trapid) {
	set timestamp [lindex $trap 0]
	if { [comparetime $timestamp $newtime $gTrapFreq] == 1 } {
	    set temp1 [format "%s {%s}" $temp1 $trap]
	}
    }
    
    set trapseen($trapid) $temp1
    debug 1 "pruned trapseen($trapid): $trapseen($trapid)"
    if { [llength $trapseen($trapid)] == 0 } {
	unset trapseen($trapid)
	return 0
    }

    # recent traps were found.  compare the actual data

    # remove the time from the trap so a match is possible

    set notime "[lindex  [lindex $list 0] 0] [lindex  [lindex $list 0] 1] "
    set list [lreplace $list 0 0 $notime]
    #debug 1 "list: $list"

    foreach trap $trapseen($trapid) {
	set oldlist [lindex $trap 1]
	set notime "[lindex  [lindex $oldlist 0] 0] [lindex  [lindex $oldlist 0] 1] "
	set oldlist [lreplace $oldlist 0 0 $notime]
	#debug 1 "oldlist: $oldlist"
	
	if { [string compare $oldlist $list] == 0 } {
	    return 1
	}
    }
    return 0
}

#
# return 0 if time2 is later by more than delta seconds
# return 1 if time2 is later by less than delta seconds
# 
proc comparetime { time1 time2 delta} {
    
    debug 1 "comparetime: $time1 $time2 $delta"
    

    #convert to seconds
    set year1 [ string trimleft [lindex $time1 0] 0 ]
    set year2 [ string trimleft [lindex $time2 0] 0 ]
    set month1 [ string trimleft [lindex $time1 1] 0 ]
    set month2 [ string trimleft [lindex $time2 1] 0 ]
    set day1 [ string trimleft [lindex $time1 2] 0 ]
    set day2 [ string trimleft [lindex $time2 2] 0 ]
    set hour1 [ string trimleft [lindex $time1 3] 0 ]
    set hour2 [ string trimleft [lindex $time2 3] 0 ]
    set min1 [ string trimleft [lindex $time1 4]  0 ]
    set min2 [ string trimleft [lindex $time2 4] 0 ]
    set sec1 [ string trimleft [lindex $time1 5]  0 ]
    set sec2 [ string trimleft [lindex $time2 5] 0 ]

    # trim turns 00 into ""
    foreach val "year1 year2 month1 month2 day1 day2 hour1 hour2 min1 min2 sec1 sec2" {
	eval set v $$val
	if { $v == "" } {
	    eval set $val 0
	}   
    }
    
    # Convert two-digit years to four-digit years (bug 4108443).
    # Digits 00 - 68 are 2000 - 2068 and 69 - 99 are 1969 - 1999:
    if { $year1 <= 99 } {
    	if { $year1 < 69 } {
       	    incr year1 2000
       	} else {
       	    incr year1 1900
       	}
    }
    if { $year2 <= 99 } {
	if { $year2 < 69 } {
	    incr year2 2000
	} else {
	   incr year2 1900
	}
    }

    set year1 [expr [expr $year1 - 1995] * 3600 * 24 * 365]
    set year2 [expr [expr $year2 - 1995] * 3600 * 24 * 365]
    set month1 [expr [monthcase $month1 $year1 ] * 3600 * 24]
    set month2 [expr [monthcase $month2 $year2 ] * 3600 * 24]
    set day1 [expr [expr $day1 -1] * 3600 * 24 ]
    set day2 [expr [expr $day2 -1] * 3600 * 24 ]
    set hour1 [expr $hour1 *3600 ]
    set hour2 [expr $hour2 *3600 ]
    set min1 [expr $min1 *60 ]
    set min2 [expr $min2 *60 ]


    set timesec1 [expr $year1 + $month1 + $day1 + $hour1 + $min1 + $sec1]

    set timesec2 [expr $year2 + $month2 + $day2 + $hour2 + $min2 + $sec2]


    #debug 1 "time1 sec: $timesec1"
    #debug 1 "time2 sec: $timesec2"
    if { [expr $timesec2 - $timesec1] > $delta } {
	return 0
    } else {
	return 1
    }

}


proc monthcase { month year } {

    # Is this a leap year?
    # Note: leap years are divisible by 4 unless divisible by 100 unless by 400
    if {((($year % 4) == 0) && (($year % 100) != 0)) || (($year % 400) == 0)} {
	# leap year
	set feb_days 29
    } else {
	set feb_days 28
    }
	 
    switch $month {
	1 { return 0 }
	2 { return 31}
	3 { return [expr 31 + $feb_days]}
	4 { return [expr 31 + $feb_days +31]}
	5 { return [expr 31 + $feb_days +31 +30]}
	6 { return [expr 31 + $feb_days +31 +30 +31]}
	7 { return [expr 31 + $feb_days +31 +30 +31 +30]}
	8 { return [expr 31 + $feb_days +31 +30 +31 +30 +31]}
	9 { return [expr 31 + $feb_days +31 +30 +31 +30 +31 + 31]}
	10 { return [expr 31 + $feb_days +31 +30 +31 +30 +31 + 31 + 30]}
	11 { return [expr 31 + $feb_days +31 +30 +31 +30 +31 + 31 + 30 + 31]}
	12 { return [expr 31 + $feb_days +31 +30 +31 +30 +31 + 31 + 30 + 31 + 30]}
	
    }
}


#
# ident	"@(#)trapListen.tcl	1.19	99/04/28 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# hv_trap is a tool that listens to the snmpd for traps.
# the appropriate action is taken by hostview.
#
#
#
# Usage:
#
#	hv_trap -x start
#
#		start - start physical host monitoring.
#
#
# References:
#	edd(1M) daemon
#	snmpd(1M) daemon
#	straps(1M) daemon
#	Starfire.mib
#

# Global variable declaration:
set ins 0
set TRAPID snmpTrapOID

set PLATFORM_MIB platformName.$ins

# hvtrap SNMP trap handler
set hvTrapSession {}

#
# hv_trap: main program
#
proc hv_trap args {
    global env
    global hvTrapSession

    set usage "usage: hv_trap -x start"

    # required environment variables:
    set cray_env "SUNW_HOSTNAME SSPETC SSPVAR"

    # straps daemon: port number
    set STRAPS 162

    set valid_args "x:"
    set hvtrap_opt(start)	1

    #
    # Check command line arguments
    #
    if { [ catch {CLA_Parse Args $args $valid_args } errmsg ] } {
	puts "Error: $errmsg"
	error $usage
    }

    #
    # Check for valid command line arguments
    #
    if { [array size Args] } {
	if { ![info exists hvtrap_opt($Args(x))] } {
	    # Invalid hvtrap command
	    debug 1 "Error: unknown command `$Args(x)`"
	    error $usage
	}
    }

    #
    # Check environment variables
    #
    foreach var $cray_env {
	if { ![info exists env($var)] } {
	    error "hv_trap: Environment variable '$var' must be set."
	}
    }

    #
    # Get a SNMP session handle to talk to the snmpd
    #
    if { 0 } {
    if { [ catch { set handle [ snmp session -community hvtrap.cmd ] } errmsg ] } {
	puts "Error: $errmsg"
	error "The 'snmpd' agent may not be running."
    }
}

    #
    #
    # -Set trap handler once and send cmd to snmpd.
    if { ![llength $hvTrapSession] } {
      if {[catch { set hvTrapSession [ snmp session -community snmptrap -port $STRAPS ] } errmsg ] } {
            puts "Error: $errmsg"
            puts "The 'snmpd' agent may not be running or SUNW_HOSTNAME is incorrect."
            exit
        }
	$hvTrapSession bind "" trap {hv_traphandler %A "%V"}
    }
    
    #$handle destroy
}


#
# hv_traphandler
#
#	Callback procedure for receiving a trap from straps daemon. The trap
#	is sent by snmpd to straps once hvtrap has modified the
#	sspPlatformAppEddControl member in the MIB. In response, straps
#	broadcasts the trap to all its clients (we are one of them). This
#	way we know hvtrap has responded to us as required.
#
#	NOTE: this trap handler only works if in the scotty shell.
#
proc hv_traphandler {ip list} {
    global hvTrapSession
    global PLATFORM_MIB
    global gMY_PLATFORM
    global TRAPID

    #traps queued hold up i/o
    #flush 

    # have to look at all the varbinds because order is not guaranteed.
    #debug 1 "trap received from $ip"
    foreach vb $list {
	#debug 1 "trap varbind: $vb"
	if { [mib name [lindex $vb 0]] == $PLATFORM_MIB } {
	    if { [string compare [lindex $vb 2] $gMY_PLATFORM ] != 0 } {
		# ignore if not our platform
		debug 1 "not us: [lindex $vb 2]"
		return ""
	    }
	} elseif {[lsearch [mib name [lindex $vb 0]] $TRAPID*] > -1 } {
	    set flag [lindex [split [lindex $vb 2] .] 2]
	    debug 1 "traphandler came via trapid: $TRAPID"
	} elseif { [lsearch [lindex $vb 2] ccitt.0.*] > -1 } {
	    set flag [ string trimleft [lindex $vb 2] ccitt.0.]
	} elseif { [lsearch [lindex $vb 2] server.0.*] > -1 } {

	    set flag [ string trimleft [lindex $vb 2] server.0.]
	}
    }
    debug 5 "flag: $flag"

    #9 sys_brd_temp_change_trap not bcast to hostview
    #16 cb_temp_change_trap not bcast to hostview
    #23 ctr_temp_change_trap not bcast to hostview
    #32 supp_brd_temp_change_trap not bcast to hostview
    #37 sys_brd_volt_change_trap not bcast to hostview
    #42 cb_volt_change_trap not bcast to hostview
    #47 ctr_volt_change_trap not bcast to hostview
    #52 csb_volt_change_trap not bcast to hostview

    switch $flag {
        0 { domainChange $list }
	
        3 { sbtempTrap $list Normal $flag}
        4 { sbtempTrap $list High $flag}
        5 { sbtempTrap $list Warning $flag}
        6 { sbtempTrap $list MAX $flag}
        7 { sbtempTrap $list T911 $flag }
        8 { sbtempTrap $list BAD $flag }
	9 { }
	
	10 { cbtempTrap $list Normal $flag }
        11 { cbtempTrap $list High $flag}
        12 { cbtempTrap $list Warning $flag}
        13 { cbtempTrap $list MAX $flag}
        14 { cbtempTrap $list T911 $flag}
        15 { cbtempTrap $list BAD $flag}
	16 { }
	
	17 { ctrtempTrap $list Normal $flag}
        18 { ctrtempTrap $list High $flag}
        19 { ctrtempTrap $list Warning $flag}
        20 { ctrtempTrap $list MAX $flag}
        21 { ctrtempTrap $list T911 $flag}
        22 { ctrtempTrap $list BAD $flag}
	23 { }
	24 { cbeConnected $list }
	25 { }
	
	26 { csbtempTrap $list Normal $flag }
        27 { csbtempTrap $list High $flag}
        28 { csbtempTrap $list Warning $flag}
        29 { csbtempTrap $list MAX $flag}
        30 { csbtempTrap $list T911 $flag}
        31 { csbtempTrap $list BAD $flag }
	32 { }
	
	33 { sbvoltTrap $list Normal $flag }
	34 { sbvoltTrap $list "Above MAXs" $flag}
	35 { sbvoltTrap $list "Below MINs" $flag}
	36 { sbvoltTrap $list BAD $flag}
	37 {}
	
	38 { cbvoltTrap $list Normal $flag}
	39 { cbvoltTrap $list "Above MAXs" $flag}
	40 { cbvoltTrap $list "Below MINs" $flag}
	41 { cbvoltTrap $list BAD $flag }
	42 { }
	
	43 { ctrvoltTrap $list Normal $flag }
	44 { ctrvoltTrap $list "Above MAXs" $flag }
	45 { ctrvoltTrap $list "Below MINs" $flag }
	46 { ctrvoltTrap $list BAD $flag }
	47 { }
	
	48 { csbvoltTrap $list Normal $flag }
	49 { csbvoltTrap $list "Above MAXs" $flag }
	50 { csbvoltTrap $list "Below MINs" $flag }
	51 { csbvoltTrap $list BAD $flag }
	52 { }
	
	53 { fanTrapResp $list norm }
	54 { fanTrapResp $list fail }
	55 { sysconfigchange $list }
	56 { sysFail $list arbstop $flag}
	57 { sysFail $list recordstop $flag}
	58 { sysFail $list watchdog $flag}
	59 { sysFail $list environmentalShutdown $flag }
	60 { }
	61 { sysFail $list panic1 $flag }
	62 { sysFail $list panic2 $flag }
	63 { sysFail $list panicReboot $flag }
	64 { sysFail $list heartbeatFailure $flag }

	65 { sigblk $list }

	66 { powerChange $list powerOff }
	67 { powerChange $list powerOn }
	68 { powerChange $list powerOff }
	69 { powerChange $list powerOn }

	70 { bpStat $list on }
	71 { bpStat $list failed }
	72 { bootprocChange $list }

	74 { sysFail $list clusterArbstop $flag}
	75 { sysFail $list clusterRecordstop $flag}

	79 { powerChange $list powerOff }
	80 { powerChange $list powerOn }

	99 { traptest $list }
    }
}

#
# ident	"@(#)utilities.tcl	1.5	97/03/17 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   GP support routines.
#

#
# Somewhere, a dismiss button has been pressed.
# Find that sucker and nuke it.
#
proc dismissMe { } {
    global gPidMibFresh

    set geox [winfo pointerx .]
    set geoy [winfo pointery .]
    set target1 [winfo containing $geox $geoy]

    debug 1 "I think this is:$target1"

    set target2 [split $target1 .]

    set target3 [lindex $target2 1]

    set count [countWin]

    if { $count < 2 } {
	if { [info exists gPidMibFresh] && [ string compare $gPidMibFresh "99999999"] != 0 } {
	    debug 1 "killing gPidMibFresh: $gPidMibFresh"
	    if [catch {exec kill $gPidMibFresh} result] {
		debug 1 $result
	    }
	    unset gPidMibFresh
	}
    }

    destroy .$target3

    return $target1
}

#
# Write debug traffic to stdout.
#
proc debug {flag arg} {
    global gDebugThreshold

    if {$flag > $gDebugThreshold} {
	puts "$flag $arg"
    }
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)writeLog.tcl	1.2	96/09/04 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#

proc writeLog {fileId} {
    global gBoards
    global gDomains
    global gFanList
    global gProcessors
    global gThermalList
    global gPowerList
    global gDomainColors
    global gDomainColorMap
    global gPowered
    global gSystemFail
    global gBulkPowerList

	debug 1 "writeLog: $fileId"

    puts $fileId "#Hostview internal state snapshot"
    puts $fileId "\n#board states:{board domain power loaded|empty} "
    puts $fileId $gBoards
    puts $fileId "\n#Domains: {domain_name {sys board list}}"
    puts $fileId $gDomains
    puts $fileId "\n#Processors: { proc number {signature state}}"
    puts $fileId $gProcessors
    puts $fileId "\n#Thermal List: { board flag {values}} flag 1 indicates problem condition."
    puts $fileId $gThermalList
    puts $fileId "\n#Power List: { board flag {values}} flag 1 indicates problem condition."
    puts $fileId $gPowerList
    puts $fileId "\n#Fan List: speed_for_all { failed list } {powered list}"
    puts $fileId $gFanList"
    puts $fileId "\n#Bulk Power List: { present list } { failed list } {powered list}"
    puts $fileId $gBulkPowerList

    puts $fileId "\n#Powered center plane and bulk power {bp2 is PS2}"
    puts $fileId $gPowered
    puts $fileId "\n#System Fail List: {failure domain_name {date}}"
    puts $fileId $gSystemFail
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)utilities	1.2	96/07/31 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#

#
# Write debug traffic to stdout.
#
proc debug {flag arg} {
    global gDebugThreshold

    if {$flag > $gDebugThreshold} {
	puts $arg
    }
}

#
# fake.
# Send a command to hostview
#
proc xmt {arg} {
    debug 1 "xmt:$arg"
    set retstatus [ eval $arg ]

    if {$retstatus == 0} {
	debug 1 "xmt retstatus:$retstatus"
    } else {
	debug 3 "xmt retstatus:$retstatus"
    }
}

#
# Send a command to hostview
#
proc xmt_send {arg} {
    debug 1 "xmt:$arg"
    set retstatus [send hv $arg]

    if {$retstatus == 0} {
	debug 1 "xmt retstatus:$retstatus"
    } else {
	debug 3 "xmt retstatus:$retstatus"
    }
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)diag_script	1.2	96/07/31 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   This script tells hostview to enable all the boards.
#   Establishes JTAG and Clock.
#   Establishes two domains (orange and white).
#

proc diag_script {} {
    diaghook
    debug 5 "end..."
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)fanfailure	1.2	96/07/31 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   Set fan failure
#

proc fanfailure {} {
    xmt "fanTrap fail ft0b"
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)fanrepair	1.2	96/07/31 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   Set fan repair
#

proc fanrepair {} {
    xmt "fanTrap repair ft0b"
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)globals	1.2	96/07/31 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#

# gDebugThreshold defines debug traffic.  0 = everything.
#set gDebugThreshold 5

# bg1 is the background color of the main window
#set gBg1 "gray81"

# fg1 is the default text color
#set gFg1 "black"

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)hifans	1.2	96/07/31 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   Set high speed fan operation
#

proc hifans {} {
    xmt "fanTrap speed high"
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)normfans	1.2	96/07/31 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   Set normal speed fan operation
#

proc normfans {} {
    xmt "fanTrap speed normal"
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)script0	1.2	96/07/31 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   This script tells hostview to enable all the boards.
#   Establishes JTAG and Clock.
#   Establishes two domains (orange and white).
#

proc script0 {} {
    global gBg1
    global gFg1

    debug 5 "begin..."
    debug 5 "This system is fully populated"

    foreach board {0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15} {
	 boardDiscovered $board
#	xmt "grayedSys $board grey grey"
    }

    foreach board {cb0 cb1} {
	boardDiscovered $board
#	xmt "grayedCB $board grey grey"
    }

    foreach board {csb0 csb1} {
	boardDiscovered $board
#	xmt "grayedSB $board grey grey"
    }

    debug 5 "end..."
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)script1	1.2	96/07/31 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   This script tells hostview to enable all the boards.
#   Establishes JTAG and Clock.
#   Establishes two domains (orange and white).
#

proc script1 {} {
    global gBg1
    global gFg1

    debug 5 "begin..."
    debug 5 "This system is fully populated"

 boardPowerUp ctr

    foreach buss {addr2 addr3 data1 data0 addr1 addr0} {
	 greenBuss $buss
    }

#    foreach board {b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15} 
     foreach board {0 1 2 3 5 6 7 8 9 10 11 13 14 15} {
	 boardPowerUp $board
    }

    foreach board {cb0 cb1} {
	 boardPowerUp $board
    }

     setJtag cb0
     setClock cb1

    foreach board {csb0 csb1} {
	 boardPowerUp $board
    }

    debug 5 "end..."
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)script1a	1.2	96/07/31 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   Establishes two domains (orange and white).
#

proc script1a {} {
    for {set ndx 0} {$ndx < 16} {incr ndx} {
	if {$ndx < 10} {
	     setProcIcon 0$ndx os running
	} else {
	     setProcIcon $ndx os running
	}
    }

    for {set ndx 32} {$ndx < 48} {incr ndx} {
	 setProcIcon $ndx os running
    }

    for {set ndx 28} {$ndx < 32} {incr ndx} {
	 setProcIcon $ndx dhlp unknown
    }

    for {set ndx 24} {$ndx < 28} {incr ndx} {
	 setProcIcon $ndx post unknown
    }

    for {set ndx 20} {$ndx < 24} {incr ndx} {
	 setProcIcon $ndx obp prerun
    }

	if { 1 } {
    		foreach board {0 1 3} {
	 		setDomain $board orange
    		}

    		foreach board {8 9 10 11} {
	 		setDomain $board white
    		}
	} else {
		hv_get_domains
	}

#     setDomainView white

#    foreach bp {bp0 bp1 bp2 bp3 bp4 bp5 bp6 bp7} {
#	 greenPower $bp
#    }

    debug 5 "end..."
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)script2	1.2	96/07/31 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#

proc script2 {} {
    global gBg1
    global gFg1

    set thermvalue {{20 25 30 35 40} {45 50 55} {60 65 70 75}}
    xmt "thermalTrap 0 {$thermvalue}"
    xmt "thermalTrap 8 {$thermvalue}"

    set thermvalue {{45 50 55} {65 70 75}}
    xmt "thermalTrap cb0 {$thermvalue}"

    set thermvalue {45 75}
    xmt "thermalTrap csb1 {$thermvalue}"

    set thermvalue {{40 41 42 43 44} {45 46 47} {48 49 50 51}}
    xmt "thermalTrap 1 {$thermvalue}"
    xmt "thermalTrap 2 {$thermvalue}"
    xmt "thermalTrap 3 {$thermvalue}"
#    xmt "thermalTrap 4 {$thermvalue}"
    xmt "thermalTrap 9 {$thermvalue}"
    xmt "thermalTrap 10 {$thermvalue}"
    xmt "thermalTrap 11 {$thermvalue}"
#    xmt "thermalTrap 12 {$thermvalue}"

    set thermvalue {{40 41 42} {49 50 51}}
    xmt "thermalTrap cb1 {$thermvalue}"

    set thermvalue {20 45}
    xmt "thermalTrap csb0 {$thermvalue}"

    set thermvalue {{10 20 30 40 50 60 70 80 90 99} {20 21 22 23 24 25 26 27 28 29}}
    xmt "thermalTrap ctr {$thermvalue}"
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)script3	1.2	96/07/31 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   Cool everybody down.
#

proc script3 {} {
    global gBg1
    global gFg1

    set thermvalue {{20 25 30 35 40} {45 50 55} {60 65 70 75}}
    set thermvalue {{45 50 55} {65 70 75}}
    set thermvalue {45 75}

    set thermvalue {{40 41 42 43 44} {45 46 47} {48 49 50 51}}
    xmt "thermalTrap 1 {$thermvalue}"
    xmt "thermalTrap 2 {$thermvalue}"
    xmt "thermalTrap 3 {$thermvalue}"
#    xmt "thermalTrap 4 {$thermvalue}"
    xmt "thermalTrap 9 {$thermvalue}"
    xmt "thermalTrap 10 {$thermvalue}"
    xmt "thermalTrap 11 {$thermvalue}"
#    xmt "thermalTrap 12 {$thermvalue}"

    xmt "thermalTrap 0 {$thermvalue}"
    xmt "thermalTrap 8 {$thermvalue}"

    set thermvalue {{40 41 42} {49 50 51}}
    xmt "thermalTrap cb1 {$thermvalue}"
    xmt "thermalTrap cb0 {$thermvalue}"

    set thermvalue {20 45}
    xmt "thermalTrap csb0 {$thermvalue}"
    xmt "thermalTrap csb1 {$thermvalue}"

    set thermvalue {{10 20 30 40 50 60 50 40 30 19} {20 21 22 23 24 25 26 27 28 29}}
    xmt "thermalTrap ctr {$thermvalue}"
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)script4	1.2	96/07/31 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   Power down some boards.
#

proc script4 {} {
    global gBg1
    global gFg1

    xmt "boardPowerDown b14"

    xmt "boardPowerDown b6"
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)script5	1.2	96/07/31 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   Restore some boards.
#

proc script5 {} {
    global gBg1
    global gFg1

    xmt "boardPowerUp b14"

    xmt "boardPowerUp b6"
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)script6	1.2	96/07/31 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   Supply voltage and crurrent values.  Some out of tolerance.
#

proc script6 {} {
    set valuez {{10 20 30 40 50} {10 20 30 40 50}}
    xmt "powerTrap b0 {$valuez}"
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)script7	1.2	96/07/31 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
# All rights reserved.
#
# Description:
#   Nicely behaved voltage and current values.
#

proc script7 {} {
    set valuez {{10 20 30 40 50} {10 20 30 40 50}}
    xmt "powerTrap b0 {$valuez}"
}

#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
#
# ident	"@(#)hvTail.tcl	1.25	99/01/27 SMI"
#
# Copyright (c) 1996-1999 by Sun Microsystems, Inc.
# All rights reserved.
#
# pragma ident  "@(#)hvTail.tcl 1.25     99/01/27 SMI"
#
# Description:
#   Main routine for the hostview product.
#
#   Create the main GUI.
#


#debug 10 "Hostview - Reading Platform environment........"

set valid_args "v:t:p:"

set usage "usage: hv_hostinfo \[-vtp]\n \
	\t\[-t\] \[yes\]  - traps enabled \n\
	\t\[-p\] \[seconds\]  - poll temp/power mib after seconds \n\
	\t\[-v\] \[level\]  - debug mode at level: 'default' or a number\n"


set flags [lindex $argv 0]
set cmdArgs [lindex $argv 1]
if { [ catch {CLA_Parse Args $argv $valid_args} errmsg ] } {
    debug 10 "Error: $errmsg"
    debug 10 $usage
    exit
}

if { [info exists Args(v)] } {

    if {$Args(v) == "default" } {
	set gDebugThreshold 4
    } else {
	set gDebugThreshold $Args(v)
    }
    debug 5 "debug level: $gDebugThreshold"
}
set gtrapsOn 1
if { [info exists Args(t)] } {

    if { $Args(t) == "no" ||  $Args(t) == "off" } {
	set gtrapsOn 0
	debug 5 "traps off"
    }
}
if { [info exists Args(p)] } {

    if {$Args(p) != "" } {
	set gMibRefreshFreq $Args(p)
    }
    debug 5 "mib refresh frequency (sec) $gMibRefreshFreq"
}
#
# What is the local environment?
#
debug 5 "tk_version:$tk_version"
debug 5 "tk_patchLevel:$tk_patchLevel"
debug 5 "tk_library:$tk_library"

debug 5 "tcl_version:$tcl_version"
debug 5 "tcl_patchLevel:$tcl_patchLevel"
debug 5 "tcl_library:$tcl_library"

#
# ==>Initialization
#
setupProcList
setupBoardList

#
# Main Window.
# Title needs to say something like "Hostview-eng4"
#
#set f1 [open "|/bin/uname -n" r]
#gets $f1 hostname
#close $f1

#wm title . "Hostview-$hostname"

##################################
# to run blacklist standalone, uncomment here and delete rest of file.
# blacklistStart xf5
##################################

#
# ==>Main Menu Bar
#
frame .menuBar -relief groove -borderwidth 4 -bg $gBg1
pack .menuBar -side top -fill x

menuBar $gBg1

#
# ==>Icon Button Bar
#
frame .iconBar -bg $gBg1
pack .iconBar -side top -anchor w -fill x

iconBar $gBg1


#
# ==>System Graphic Display
#
canvas .systemGraphic -relief groove -borderwidth 4 -bg $gBg1
pack .systemGraphic -fill both -expand yes

systemGraphic $gBg1 $gFg1

if {[catch [ tkwait visibility .systemGraphic ] result] } {
    debug 4 $result
    exit
}

#
# At this point, hostview is running.
# Anything after here is just decoration.
#

set dialog .mibdialog

set result [hv_tk_dialog $dialog "Hostview Working" \
		"Reading platform environment." \
		hourglass 0 ]
#set result [hv_tk_dialog $dialog "Hostview Working" \
    "Reading platform environment." \
    hourglass 0 OK]
if {[catch [ tkwait visibility $dialog] result] } {
	    debug 4 $result
}

update idletasks



#read the mib
set gMY_PLATFORM ""

#debug 1 "[exec date] above date before hv_hostinfo -n"
set gMY_PLATFORM [eval hv_hostinfo -n]
wm title . "Hostview-$gMY_PLATFORM"
#debug 1 "[exec date] above date after hv_hostinfo -n"

set gOldSUNW_HOSTNAME $env(SUNW_HOSTNAME)
set env(SUNW_HOSTNAME) $gMY_PLATFORM

#main canvas population


#debug 1  "[exec date] above date before canvas pop"
#after 5000 hv_hostinfo -h
hv_hostinfo -h

#after 10000 hv_get_domains
#hv_get_domains

# moved to decorateThermal, sysDetaiUtils
#may need to do here, in case an overtemp exists, want to display
#and the trap has come and gone...

#debug 1 "[exec date] above date before temp"
#hv_hostinfo -t
#puts "[exec date] above date after temp"

#debug 1 "[exec date] above date before hvResources"
hvResources
#puts "[exec date] above date after hvResources"

#debug 1 "[exec date] above date before fans"
#hv_hostinfo -f
#puts "[exec date] above date after fans"

#debug 1 "[exec date] above date before power"
#hv_hostinfo -p
#puts "[exec date] above date after power"


# poll the mib
set gHostviewName [tk appname]
if { [llength $gHostviewName] > 1 } {
    set gHostviewName [lindex $gHostviewName 0][lindex $gHostviewName 1]
}
if { 1 } {
    if [catch {exec hostview_child -p "$gHostviewName $pollfrequency" &} result] {
	debug 10 $result
    }
}

set gSysFailLog $gMY_PLATFORM-$gHostviewName.log

if { $gtrapsOn } {
    hv_trap -x start
}

 # register with the window manager
    wm command . "$argv0 $argv"
    if { [catch {wm client . [exec uname -n]} result]} {
        debug 10 $result
    }
    wm protocol . WM_DELETE_WINDOW topKill


#;;; Local Variables: ***
#;;; mode:tcl ***
#;;; End: ***
