# itc mercury temperarture

namespace eval itctemp {} {
}

proc stdConfig::itctemp {slot {htrslot ""}} {
  controller std

  variable name

  prop startcmd *IDN?

  obj ips_mercury rd
  prop read stdSct::read
  prop readcmd READ:DEV:${slot}:TEMP:SIG:TEMP
  prop update itctemp::update
  
  kids $name {
    node raw rd
    prop readcmd READ:DEV:${slot}:TEMP:SIG:RES
    prop read stdSct::read
    prop update itctemp::update

    if {$htrslot ne ""} {
      node set wr
      prop readcmd READ:DEV:${slot}:TEMP:LOOP:TSET
      prop read stdSct::read
      prop update itctemp::update
      prop write itctemp::write

      node control wr -int
      prop enum OFF=0,ON=1
      prop readcmd READ:DEV:${slot}:TEMP:LOOP:ENAB
      prop read stdSct::read
      prop update itctemp::update
      prop write itctemp::enumwrite
      prop label control

      node htr rd
      prop readcmd READ:DEV:${htrslot}:HTR:SIG:VOLT
      prop read stdSct::read
      prop update itctemp::update

      node pow rd
      prop readcmd READ:DEV:${htrslot}:HTR:SIG:POWR
      prop read stdSct::read
      prop update itctemp::update
    }
  }
}

proc itctemp::update {} {
  set val [lindex [split [sct result] :] end]
  if {$val eq "N/A" || $val eq "INVALID"} {
    # clientput [sct]:[sct send]
  } else {
    if {[silent "" sct enum] ne ""} {
      enum_decode [sct] $val val nam
    }
    sct update $val
  }
  return idle
}

proc itctemp::write {} {
  set cmd [string map {READ: SET:} [sct readcmd]]:%g
  sct send [format $cmd [sct target]]
  return read
}

proc itctemp::enumwrite {} {
  set cmd [string map {READ: SET:} [sct readcmd]]:%s
  sct send [format $cmd [enum_txt_req [sct]]]
  return read
}
