code tidy and bug fixes
r2962 | dcl | 2010-06-25 15:11:25 +1000 (Fri, 25 Jun 2010) | 2 lines
This commit is contained in:
@@ -9,25 +9,33 @@ namespace eval ::scobj::itc500 {
|
||||
# /tempcont/sensor/value
|
||||
proc debug_log {args} {
|
||||
set fd [open "/tmp/itc500.log" a]
|
||||
puts $fd $args
|
||||
puts $fd "[clock format [clock seconds] -format "%T"] $args"
|
||||
close $fd
|
||||
}
|
||||
|
||||
proc getValue {nextState cmd} {
|
||||
sct send $cmd
|
||||
debug_log "getValue $cmd sct=[sct]"
|
||||
sct send "@1$cmd"
|
||||
return $nextState
|
||||
}
|
||||
proc setValue {nextState cmd} {
|
||||
set par [expr int(18 * [sct target])]
|
||||
sct send "$cmd $par"
|
||||
proc setValue {tc_root nextState cmd} {
|
||||
debug_log "setValue $cmd sct=[sct]"
|
||||
set my_model "[SplitReply [hgetprop $tc_root/itc500_state my_model]]"
|
||||
if {$my_model == "ITC502"} {
|
||||
set par [expr {int(10 * [sct target])}]
|
||||
} else {
|
||||
set par "[sct target]"
|
||||
}
|
||||
sct send "@1$cmd $par"
|
||||
debug_log "setValue $cmd $par"
|
||||
return $nextState
|
||||
}
|
||||
|
||||
proc setPoint {tc_root nextState cmd} {
|
||||
debug_log "setPoint $tc_root $nextState $cmd sct=[sct]"
|
||||
set my_model "[SplitReply [hgetprop $tc_root/itc500_state my_model]]"
|
||||
if {$my_model == "ITC502"} {
|
||||
set par [expr int(10 * [sct target])]
|
||||
set par [expr {int(10 * [sct target])}]
|
||||
} else {
|
||||
set par "[sct target]"
|
||||
}
|
||||
@@ -36,16 +44,17 @@ debug_log "setValue $cmd $par"
|
||||
# Called by drive adapter
|
||||
hsetprop $tc_root/setpoint driving 1
|
||||
}
|
||||
sct send "$cmd$par"
|
||||
sct send "@1$cmd$par"
|
||||
debug_log "setPoint $cmd$par"
|
||||
return $nextState
|
||||
}
|
||||
|
||||
proc rdValue {tc_root} {
|
||||
debug_log "rdValue tc_root=$tc_root sct=[sct]"
|
||||
set data [sct result]
|
||||
if [ catch {
|
||||
if {[ catch {
|
||||
debug_log "rdValue $tc_root [sct] result=$data"
|
||||
} message ] {
|
||||
} catch_message ]} {
|
||||
debug_log "rdValue $tc_root failure"
|
||||
}
|
||||
switch -glob -- $data {
|
||||
@@ -59,7 +68,7 @@ debug_log "rdValue $tc_root failure"
|
||||
if {$my_model == "ITC502"} {
|
||||
debug_log "rdValue $tc_root ITC502-a result=$data"
|
||||
set rslt [scan $data %d data]
|
||||
set data [expr $data / 10.0]
|
||||
set data [expr {$data / 10.0}]
|
||||
debug_log "rdValue $tc_root ITC502-b result=$data"
|
||||
} elseif {$my_model == "ITC503"} {
|
||||
debug_log "rdValue $tc_root ITC503-a result=$data"
|
||||
@@ -81,22 +90,24 @@ debug_log "rdValue new data for $tc_root [sct] $my_model result=$data"
|
||||
}
|
||||
|
||||
proc getState {tc_root nextState cmd} {
|
||||
debug_log "getState $tc_root $nextState $cmd sct=[sct]"
|
||||
if {[ catch {
|
||||
set my_state "[SplitReply [hgetprop $tc_root/itc500_state my_state]]"
|
||||
if {$my_state == "STATE_V"} {
|
||||
set my_cmd "V"
|
||||
} elseif {$my_state == "STATE_X"} {
|
||||
set my_cmd "X"
|
||||
} elseif {$my_state == "STATE_C"} {
|
||||
set my_cmd "C1"
|
||||
set my_cmd "C3"
|
||||
} elseif {$my_state == "STATE_A0"} {
|
||||
set my_cmd "A0"
|
||||
} elseif {$my_state == "STATE_A"} {
|
||||
set auto 0
|
||||
if {[hval $tc_root/heater_auto] > 0} {
|
||||
set auto [expr $auto + 1]
|
||||
set auto [expr {$auto + 1}]
|
||||
}
|
||||
if {[hval $tc_root/cooler_auto] > 0} {
|
||||
set auto [expr $auto + 2]
|
||||
set auto [expr {$auto + 2}]
|
||||
}
|
||||
set my_cmd "A$auto"
|
||||
} elseif {$my_state == "STATE_H"} {
|
||||
@@ -109,22 +120,26 @@ debug_log "rdValue new data for $tc_root [sct] $my_model result=$data"
|
||||
hsetprop $tc_root/itc500_state my_state "STATE_X"
|
||||
set my_cmd "X"
|
||||
}
|
||||
sct send "$my_cmd"
|
||||
sct send "@1$my_cmd"
|
||||
debug_log "getState end $tc_root state=$my_state, cmd=$my_cmd"
|
||||
} catch_message ]} {
|
||||
debug_log "getState error: $catch_message"
|
||||
}
|
||||
debug_log "getState returns: $nextState"
|
||||
return $nextState
|
||||
}
|
||||
|
||||
proc checktol {tc_root currtime timecheck} {
|
||||
debug_log "checktol $tc_root $currtime $timecheck"
|
||||
set temp [hval $tc_root/sensor/value]
|
||||
set lotemp [expr [$tc_root/setpoint] - [hval $tc_root/tolerance]]
|
||||
set hitemp [expr [$tc_root/setpoint] + [hval $tc_root/tolerance]]
|
||||
set lotemp [expr {[$tc_root/setpoint] - [hval $tc_root/tolerance]}]
|
||||
set hitemp [expr {[$tc_root/setpoint] + [hval $tc_root/tolerance]}]
|
||||
if { $temp < $lotemp || $temp > $hitemp} {
|
||||
hset $tc_root/emon/isintol 0
|
||||
return 0
|
||||
} else {
|
||||
set timeout [hval $tc_root/tolerance/settletime]
|
||||
if {[expr $currtime - $timecheck] > $timeout} {
|
||||
if { ($currtime - $timecheck) > $timeout } {
|
||||
hset $tc_root/emon/isintol 1
|
||||
}
|
||||
return 1
|
||||
@@ -134,6 +149,9 @@ debug_log "checktol $tc_root $currtime $timecheck"
|
||||
##
|
||||
# @brief Reads the current itc500 state and error messages.
|
||||
proc rdState {tc_root} {
|
||||
debug_log "rdState $tc_root sct=[sct]"
|
||||
if {[ catch {
|
||||
set nextState ""
|
||||
set my_state "[SplitReply [hgetprop $tc_root/itc500_state my_state]]"
|
||||
set my_model "[SplitReply [hgetprop $tc_root/itc500_state my_model]]"
|
||||
debug_log "rdState $tc_root state=$my_state, response=[sct result], version=$my_model"
|
||||
@@ -148,8 +166,8 @@ debug_log "rdState $tc_root state=$my_state, response=[sct result], version=$my_
|
||||
hsetprop $tc_root/itc500_state my_state "STATE_X"
|
||||
set my_model "[SplitReply [hgetprop $tc_root/itc500_state my_model]]"
|
||||
debug_log "rdState $tc_root state=$my_state, version=$my_model"
|
||||
# return idle
|
||||
return getState
|
||||
# set nextState idle
|
||||
set nextState read
|
||||
} elseif {$my_state == "STATE_X"} {
|
||||
hsetprop $tc_root/itc500_state my_status "[sct result]"
|
||||
set my_status "[SplitReply [hgetprop $tc_root/itc500_state my_status]]"
|
||||
@@ -158,10 +176,10 @@ debug_log "rdState my_status=$my_status"
|
||||
debug_log "rdState $tc_root status($rslt)= X$the_x A$the_a C$the_c S[format %02d $the_s] H$the_h L$the_l"
|
||||
set auto 0
|
||||
if {[hval $tc_root/heater_auto] > 0} {
|
||||
set auto [expr $auto + 1]
|
||||
set auto [expr {$auto + 1}]
|
||||
}
|
||||
if {[hval $tc_root/cooler_auto] > 0} {
|
||||
set auto [expr $auto + 2]
|
||||
set auto [expr {$auto + 2}]
|
||||
}
|
||||
if {$the_c != 1} {
|
||||
hsetprop $tc_root/itc500_state my_state "STATE_C"
|
||||
@@ -175,16 +193,16 @@ debug_log "rdState $tc_root status($rslt)= X$the_x A$the_a C$the_c S[format %02d
|
||||
hsetprop $tc_root/itc500_state my_state "STATE_F"
|
||||
}
|
||||
hsetprop $tc_root/control_sensor oldval $the_h
|
||||
return getState
|
||||
set nextState read
|
||||
} elseif {$my_state == "STATE_C"} {
|
||||
set my_status "[SplitReply [hgetprop $tc_root/itc500_state my_status]]"
|
||||
set rslt [scan $my_status "X%dA%dC%dS%dH%dL%d" the_x the_a the_c the_s the_h the_l]
|
||||
set auto 0
|
||||
if {[hval $tc_root/heater_auto] > 0} {
|
||||
set auto [expr $auto + 1]
|
||||
set auto [expr {$auto + 1}]
|
||||
}
|
||||
if {[hval $tc_root/cooler_auto] > 0} {
|
||||
set auto [expr $auto + 2]
|
||||
set auto [expr {$auto + 2}]
|
||||
}
|
||||
if {[hval $tc_root/control_sensor] != $the_h} {
|
||||
hsetprop $tc_root/itc500_state my_state "STATE_A0"
|
||||
@@ -195,36 +213,37 @@ debug_log "rdState $tc_root status($rslt)= X$the_x A$the_a C$the_c S[format %02d
|
||||
} else {
|
||||
hsetprop $tc_root/itc500_state my_state "STATE_F"
|
||||
}
|
||||
return getState
|
||||
set nextState read
|
||||
} elseif {$my_state == "STATE_A0"} {
|
||||
hsetprop $tc_root/itc500_state my_state "STATE_H"
|
||||
return getState
|
||||
set nextState read
|
||||
} elseif {$my_state == "STATE_H"} {
|
||||
hsetprop $tc_root/itc500_state my_state "STATE_T0"
|
||||
return getState
|
||||
set nextState read
|
||||
} elseif {$my_state == "STATE_T0"} {
|
||||
hsetprop $tc_root/itc500_state my_state "STATE_A"
|
||||
return getState
|
||||
set nextState read
|
||||
} elseif {$my_state == "STATE_T"} {
|
||||
hsetprop $tc_root/itc500_state my_state "STATE_F"
|
||||
return getState
|
||||
set nextState read
|
||||
} elseif {$my_state == "STATE_A"} {
|
||||
hsetprop $tc_root/itc500_state my_state "STATE_F"
|
||||
return getState
|
||||
set nextState read
|
||||
} elseif {$my_state == "STATE_F"} {
|
||||
hsetprop $tc_root/itc500_state my_state "STATE_X"
|
||||
} else {
|
||||
hsetprop $tc_root/itc500_state my_state "STATE_X"
|
||||
}
|
||||
if { $nextState == "" } {
|
||||
set my_status "[SplitReply [hgetprop $tc_root/itc500_state my_status]]"
|
||||
debug_log "rdState my_status=$my_status"
|
||||
set rslt [scan $my_status "X%dA%dC%dS%dH%dL%d" the_x the_a the_c the_s the_h the_l]
|
||||
debug_log "rdState $tc_root status($rslt)= X$the_x A$the_a C$the_c S[format %02d $the_s] H$the_h L$the_l"
|
||||
set my_driving [SplitReply [hgetprop $tc_root/setpoint driving]]
|
||||
debug_log "rdState $tc_root: driving=$my_driving"
|
||||
if [ catch {
|
||||
if {[ catch {
|
||||
set val "[hval $tc_root/setpoint]"
|
||||
} message ] {
|
||||
} message ]} {
|
||||
set val 0
|
||||
debug_log "rdState $tc_root: setpoint=failure"
|
||||
}
|
||||
@@ -246,8 +265,8 @@ debug_log "rdState $tc_root: initialised target to: target=$tgt"
|
||||
set temp [hval $tc_root/sensor/value]
|
||||
}
|
||||
set tol [hval $tc_root/tolerance]
|
||||
set lotemp [expr $tgt - $tol]
|
||||
set hitemp [expr $tgt + $tol]
|
||||
set lotemp [expr {$tgt - $tol}]
|
||||
set hitemp [expr {$tgt + $tol}]
|
||||
debug_log "rdState driving $tc_root until $temp in ($lotemp, $hitemp)"
|
||||
if {$temp < $lotemp} {
|
||||
} elseif {$temp > $hitemp} {
|
||||
@@ -257,7 +276,13 @@ debug_log "rdState driving $tc_root until $temp in ($lotemp, $hitemp)"
|
||||
debug_log "rdState driving $tc_root finished at $temp in ($lotemp, $hitemp)"
|
||||
}
|
||||
}
|
||||
return idle
|
||||
set nextState idle
|
||||
}
|
||||
} catch_message ]} {
|
||||
debug_log "rdState error: $catch_message"
|
||||
}
|
||||
debug_log "rdState returns: $nextState"
|
||||
return $nextState
|
||||
}
|
||||
|
||||
proc noResponse {} {
|
||||
@@ -282,7 +307,7 @@ debug_log "rdState driving $tc_root finished at $temp in ($lotemp, $hitemp)"
|
||||
# NOTE: The drive adapter initially sets the writestatus to "start" and will
|
||||
# only call this when writestatus!="start"
|
||||
proc drivestatus {tc_root} {
|
||||
if [sct driving] {
|
||||
if {[sct driving]} {
|
||||
return busy
|
||||
} else {
|
||||
return idle
|
||||
@@ -297,7 +322,7 @@ debug_log "halt $tc_root"
|
||||
}
|
||||
|
||||
proc mk_sct_oxford_itc500 {sct_controller klass tempobj tol} {
|
||||
if [ catch {
|
||||
if {[ catch {
|
||||
set ns ::scobj::itc500
|
||||
|
||||
MakeSICSObj $tempobj SCT_OBJECT
|
||||
@@ -481,8 +506,8 @@ debug_log "halt $tc_root"
|
||||
if {[SplitReply [environment_simulation]]=="false"} {
|
||||
ansto_makesctdrive ${tempobj}_driveable $scobj_hpath/setpoint $scobj_hpath/sensor/value $sct_controller
|
||||
}
|
||||
} message ] {
|
||||
return -code error $message
|
||||
} catch_message ]} {
|
||||
return -code error $catch_message
|
||||
}
|
||||
}
|
||||
namespace export mk_sct_oxford_itc500
|
||||
@@ -516,4 +541,4 @@ close $fd
|
||||
namespace import ::scobj::itc500::*
|
||||
|
||||
#add_itc500 itc500 137.157.201.213 502 5
|
||||
add_itc500 itc500 localhost 30509 5
|
||||
#add_itc500 itc500 localhost 30509 5
|
||||
|
||||
Reference in New Issue
Block a user