From bd0c0b5556b3f3a9b81f8dfa8573db947b053344 Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Wed, 28 May 2014 17:29:36 +1000 Subject: [PATCH] Bilby Astrium Chopper Driver and Fake Chopper --- .../TEST_SICS/fakeDChopper/SIM_ASTRIUM.py | 92 +++ .../bilby/config/chopper/astrium_chopper.sct | 109 ++++ .../config/chopper/sct_astrium_chopper.tcl | 572 ++++++++++++++++++ 3 files changed, 773 insertions(+) create mode 100755 site_ansto/instrument/TEST_SICS/fakeDChopper/SIM_ASTRIUM.py create mode 100644 site_ansto/instrument/bilby/config/chopper/astrium_chopper.sct create mode 100644 site_ansto/instrument/bilby/config/chopper/sct_astrium_chopper.tcl diff --git a/site_ansto/instrument/TEST_SICS/fakeDChopper/SIM_ASTRIUM.py b/site_ansto/instrument/TEST_SICS/fakeDChopper/SIM_ASTRIUM.py new file mode 100755 index 00000000..215e9e1f --- /dev/null +++ b/site_ansto/instrument/TEST_SICS/fakeDChopper/SIM_ASTRIUM.py @@ -0,0 +1,92 @@ +#!/usr/bin/python +# vim: ft=python ts=8 sts=4 sw=4 et autoindent smartindent nocindent +# author: Douglas Clowes (douglas.clowes@ansto.gov.au) 2014 +# +from twisted.internet import reactor, protocol +from twisted.protocols.basic import LineReceiver +users = {"Bilby":"RwN"} + +class Astrium_Chopper(LineReceiver): + def __init__(self): + print dir(self) + print dir(self.transport) + self.delimiter = '\r' + self.state = 0 + # TODO + + def write(self, data): + print "transmitted:", data + self.transport.write(data) + + def lineReceived(self, data): + print "lineReceived:", data + if self.state == 1: # expecting user: + if data.startswith("user:"): + uid = data.split(':', 1)[1] + if uid in users: + self.state = 2 + self.uid = uid + self.write("#SES#Fill in your password") + return + self.write("#SES#Fill in your user ID") + if self.state == 2: # expecting password: + if data.startswith("password:"): + pwd = data.split(':', 1)[1] + if pwd == users[self.uid]: + self.state = 3 + self.write("#SES#Hello") + return + if self.state == 3: # expecting command + if data.startswith("#SOS#STATE "): + unit = data.split(' ', 1)[1] + print "Unit:", repr(unit) + if unit.isdigit(): + unit = int(unit) + if not (1 <= unit <= 4): + self.write("#SOS#NCCEPT CH NO "\ + + str(unit)\ + + ": NOT VALID") + return + self.write(\ + "#SOS#ACCEPT CH= "\ + + str(unit)\ + + "# State= Synchron."\ + + "#ASPEED= 0"\ + + "#RSPEED= 0"\ + + "#APHASE= -0.7" + str(unit)\ + + "#RPHASE= 0"\ + + "#AVETO = 0"\ + + "#DIR = CW"\ + + "#MONIT = ok"\ + + "#FLOWR = 3.7"\ + + "#WTEMP = 14.2"\ + + "#MTEMP = 18.1"\ + + "#MVIBR = 0.0"\ + + "#MVACU = 0.0022"\ + + "#DATE = "\ + + "9/10/2009"\ + + "#TIME = "\ + + "4:48:36 PM"\ + + "#") + return + if data.startswith("#SOS#"): + self.write(\ + "#SOS#NCCEPT "\ + + "garbag"\ + + ": UNKOWN CMD") + def rawDataReceived(self, data): + print "rawDataReceived:", data + + def connectionMade(self): + print "connectionMade" + self.write("#SES#Fill in your user ID") + self.state = 1 + +def main(): + factory = protocol.ServerFactory() + factory.protocol = Astrium_Chopper + reactor.listenTCP(60000, factory) + reactor.run() + +if __name__ == "__main__": + main() diff --git a/site_ansto/instrument/bilby/config/chopper/astrium_chopper.sct b/site_ansto/instrument/bilby/config/chopper/astrium_chopper.sct new file mode 100644 index 00000000..cdddc380 --- /dev/null +++ b/site_ansto/instrument/bilby/config/chopper/astrium_chopper.sct @@ -0,0 +1,109 @@ +driver astrium_chopper = { + debug_threshold = 2; + vendor = astrium; device = chopper; protocol = std; + class = NXdisk_chopper; simulation_group = chopper_simulation; + + group blade_1 = { + var state = { + type = text; mutable = true; priv = user; readable = 1; + read_command = '1'; fetch_function = fetchState; read_function = readState; + property 'my_state' = 'idle'; + } + var rspeed = { type = float; } + var aspeed = { type = float; mutable = true; } + var rphase = { type = float; } + var aphase = { type = float; mutable = true; } + } + + group blade_2 = { + var state = { + type = text; mutable = true; priv = user; readable = 1; + read_command = '2'; fetch_function = fetchState; read_function = readState; + property 'my_state' = 'idle'; + } + var rspeed = { type = float; } + var aspeed = { type = float; mutable = true; } + var rphase = { type = float; } + var aphase = { type = float; mutable = true; } + } + + group blade_3 = { + var state = { + type = text; mutable = true; priv = user; readable = 1; + read_command = '3'; fetch_function = fetchState; read_function = readState; + property 'my_state' = 'idle'; + } + var rspeed = { type = float; } + var aspeed = { type = float; mutable = true; } + var rphase = { type = float; } + var aphase = { type = float; mutable = true; } + } + + group blade_4 = { + var state = { + type = text; mutable = true; priv = user; readable = 1; + read_command = '4'; fetch_function = fetchState; read_function = readState; + property 'my_state' = 'idle'; + } + var rspeed = { type = float; } + var aspeed = { type = float; mutable = true; } + var rphase = { type = float; } + var aphase = { type = float; mutable = true; } + } + + code fetch_function fetchState = {%% + set my_state [sct my_state] + if { ${my_state} == "user" } { + set cmd "user:Bilby" + } elseif { ${my_state} == "password" } { + set cmd "password:RwN" + } else { + set cmd "#SOS#STATE ${cmd_str}" + } + %%} + + code read_function readState = {%% + if { [string equal -length 22 ${data} "#SES#Fill in your user"] } { + sct my_state "user" + set nextState "read" + } elseif { [string equal -length 22 ${data} "#SES#Fill in your pass"] } { + sct my_state "password" + set nextState "read" + } elseif { [string equal -length 22 ${data} "#SES#You are not a val"] } { + sct my_state "user" + set nextState "read" + } else { + sct my_state "idle" + set nextState "idle" + if { [string equal -length 12 ${data} "#SOS#ACCEPT "] } { + set my_status [split [string range ${data} 12 end] "#"] + foreach field ${my_status} { + set lst [split ${field} "="] + if { [llength ${lst}] > 1 } { + set lhs "[string trim [lindex ${lst} 0]]" + set rhs "[string trim [lindex ${lst} 1]]" + sct "attr_${lhs}" "${rhs}" + set base [pathname [sct]] + foreach node [list ASPEED RSPEED APHASE RPHASE] { + if { [string equal -nocase "${lhs}" "${node}"] } { + if { "[hval ${base}/${node}]" != "${rhs}" } { + hset ${base}/${node} "${rhs}" + } + } + } + if { [string equal -nocase ${lhs} "STATE"] } { + set data "${rhs}" + } + } + } + } else { + sct geterror "${data}" + } + + } + %%} + + code mkDriver = {%% + hsetprop ${scobj_hpath} debug_threshold 1 + %%} +} diff --git a/site_ansto/instrument/bilby/config/chopper/sct_astrium_chopper.tcl b/site_ansto/instrument/bilby/config/chopper/sct_astrium_chopper.tcl new file mode 100644 index 00000000..5302b067 --- /dev/null +++ b/site_ansto/instrument/bilby/config/chopper/sct_astrium_chopper.tcl @@ -0,0 +1,572 @@ +# Generated driver for astrium_chopper +# vim: ft=tcl tabstop=8 softtabstop=2 shiftwidth=2 nocindent smartindent +# + +namespace eval ::scobj::astrium_chopper { + set debug_threshold 2 +} + +proc ::scobj::astrium_chopper::debug_log {tc_root debug_level debug_string} { + set catch_status [ catch { + set debug_threshold [hgetpropval ${tc_root} debug_threshold] + if {${debug_level} >= ${debug_threshold}} { + set fd [open "/tmp/astrium_chopper_[basename ${tc_root}].log" "a"] + set line "[clock format [clock seconds] -format "%T"] ${debug_string}" + puts ${fd} "${line}" + close ${fd} + } + } catch_message ] +} + +proc ::scobj::astrium_chopper::sics_log {debug_level debug_string} { + set catch_status [ catch { + set debug_threshold ${::scobj::astrium_chopper::debug_threshold} + if {${debug_level} >= ${debug_threshold}} { + sicslog "::scobj::astrium_chopper::${debug_string}" + } + } catch_message ] +} + +# check function for hset change +proc ::scobj::astrium_chopper::checkrange {tc_root} { + set catch_status [ catch { + debug_log ${tc_root} 1 "checkrange tc_root=${tc_root} sct=[sct] target=[sct target]" + set setpoint [sct target] + if { [hpropexists [sct] lowerlimit] } { + set lolimit [sct lowerlimit] + } else { + # lowerlimit not set, use target + set lolimit [sct target] + } + if { [hpropexists [sct] upperlimit] } { + set hilimit [sct upperlimit] + } else { + # upperlimit not set, use target + set hilimit [sct target] + } +# checkrange hook code goes here + if { ${setpoint} < ${lolimit} || ${setpoint} > ${hilimit} } { + error "setpoint ${setpoint} violates limits (${lolimit}..${hilimit}) on [sct]" + } + return OK + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + +# function to request the read of a parameter on a device +proc ::scobj::astrium_chopper::fetchState {tc_root nextState cmd_str} { + set catch_status [ catch { + debug_log ${tc_root} 1 "fetchState tc_root=${tc_root} sct=[sct] cmd=${cmd_str}" + if { [hpropexists [sct] geterror] } { + hdelprop [sct] geterror + } + set cmd "${cmd_str}" +# fetchState hook code starts + set my_state [sct my_state] + if { ${my_state} == "user" } { + set cmd "user:Bilby" + } elseif { ${my_state} == "password" } { + set cmd "password:RwN" + } else { + set cmd "#SOS#STATE ${cmd_str}" + } +# fetchState hook code ends + if { [hpropexists [sct] geterror] } { + debug_log ${tc_root} 9 "[sct] error: [sct geterror]" + error "[sct geterror]" + } + debug_log ${tc_root} 1 "fetchState sct send ${cmd}" + if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} { + sct send "${cmd}" + } + return ${nextState} + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + +# function to request the read of a parameter on a device +proc ::scobj::astrium_chopper::getValue {tc_root nextState cmd_str} { + set catch_status [ catch { + debug_log ${tc_root} 1 "getValue tc_root=${tc_root} sct=[sct] cmd=${cmd_str}" + if { [hpropexists [sct] geterror] } { + hdelprop [sct] geterror + } + set cmd "${cmd_str}" +# getValue hook code goes here + debug_log ${tc_root} 1 "getValue sct send ${cmd}" + if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} { + sct send "${cmd}" + } + return ${nextState} + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + +# function to check the write parameter on a device +proc ::scobj::astrium_chopper::noResponse {tc_root} { + set catch_status [ catch { + debug_log ${tc_root} 1 "noResponse tc_root=${tc_root} sct=[sct] resp=[sct result]" +# noResponse hook code goes here + return "idle" + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + +# function to parse the read of a parameter on a device +proc ::scobj::astrium_chopper::rdValue {tc_root} { + set catch_status [ catch { + debug_log ${tc_root} 1 "rdValue tc_root=${tc_root} sct=[sct] result=[sct result]" + if { [hpropexists [sct] geterror] } { + hdelprop [sct] geterror + } + set data [sct result] + set nextState "idle" + if {[string equal -nocase -length 7 ${data} "ASCERR:"]} { + # the protocol driver has reported an error + sct geterror "${data}" + error "[sct geterror]" + } +# rdValue hook code goes here + if { ${data} != [sct oldval] } { + debug_log ${tc_root} 1 "[sct] changed to new:${data}, from old:[sct oldval]" + sct oldval ${data} + sct update ${data} + sct utime readtime + } + return ${nextState} + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + +# function to parse the read of a parameter on a device +proc ::scobj::astrium_chopper::readState {tc_root} { + set catch_status [ catch { + debug_log ${tc_root} 1 "readState tc_root=${tc_root} sct=[sct] result=[sct result]" + if { [hpropexists [sct] geterror] } { + hdelprop [sct] geterror + } + set data [sct result] + set nextState "idle" + if {[string equal -nocase -length 7 ${data} "ASCERR:"]} { + # the protocol driver has reported an error + sct geterror "${data}" + error "[sct geterror]" + } +# readState hook code starts + if { [string equal -length 22 ${data} "#SES#Fill in your user"] } { + sct my_state "user" + set nextState "read" + } elseif { [string equal -length 22 ${data} "#SES#Fill in your pass"] } { + sct my_state "password" + set nextState "read" + } elseif { [string equal -length 22 ${data} "#SES#You are not a val"] } { + sct my_state "user" + set nextState "read" + } else { + sct my_state "idle" + set nextState "idle" + if { [string equal -length 12 ${data} "#SOS#ACCEPT "] } { + set my_status [split [string range ${data} 12 end] "#"] + foreach field ${my_status} { + set lst [split ${field} "="] + if { [llength ${lst}] > 1 } { + set lhs "[string trim [lindex ${lst} 0]]" + set rhs "[string trim [lindex ${lst} 1]]" + sct "attr_${lhs}" "${rhs}" + set base [pathname [sct]] + foreach node [list ASPEED RSPEED APHASE RPHASE] { + if { [string equal -nocase "${lhs}" "${node}"] } { + if { "[hval ${base}/${node}]" != "${rhs}" } { + hset ${base}/${node} "${rhs}" + } + } + } + if { [string equal -nocase ${lhs} "STATE"] } { + set data "${rhs}" + } + } + } + } else { + sct geterror "${data}" + } + } +# readState hook code ends + if { [hpropexists [sct] geterror] } { + debug_log ${tc_root} 9 "[sct] error: [sct geterror]" + error "[sct geterror]" + } + if { ${data} != [sct oldval] } { + debug_log ${tc_root} 1 "[sct] changed to new:${data}, from old:[sct oldval]" + sct oldval ${data} + sct update ${data} + sct utime readtime + } + return ${nextState} + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + +# function to write a parameter value on a device +proc ::scobj::astrium_chopper::setValue {tc_root nextState cmd_str} { + set catch_status [ catch { + debug_log ${tc_root} 1 "setValue tc_root=${tc_root} sct=[sct] cmd=${cmd_str}" + if { [hpropexists [sct] geterror] } { + hdelprop [sct] geterror + } + set par [sct target] + set cmd "${cmd_str}${par}" +# setValue hook code goes here + if { [hpropexists [sct] driving] } { + if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } { + sct driving 1 + } + } + debug_log ${tc_root} 1 "setValue sct send ${cmd}" + if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} { + sct send "${cmd}" + } + return ${nextState} + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + +proc ::scobj::astrium_chopper::mkDriver { sct_controller name } { + ::scobj::astrium_chopper::sics_log 9 "::scobj::astrium_chopper::mkDriver for ${name}" + set ns "[namespace current]" + set catch_status [ catch { + + MakeSICSObj ${name} SCT_OBJECT + + sicslist setatt ${name} klass NXdisk_chopper + sicslist setatt ${name} long_name ${name} + + set scobj_hpath /sics/${name} + + hfactory ${scobj_hpath}/blade_1 plain spy none + + hfactory ${scobj_hpath}/blade_1/aphase plain user float + hsetprop ${scobj_hpath}/blade_1/aphase control true + hsetprop ${scobj_hpath}/blade_1/aphase data true + hsetprop ${scobj_hpath}/blade_1/aphase mutable true + hsetprop ${scobj_hpath}/blade_1/aphase nxsave true + hsetprop ${scobj_hpath}/blade_1/aphase oldval 0.0 + hsetprop ${scobj_hpath}/blade_1/aphase sdsinfo "::nexus::scobj::sdsinfo" + hsetprop ${scobj_hpath}/blade_1/aphase type "part" + hsetprop ${scobj_hpath}/blade_1/aphase nxalias "${name}_blade_1_aphase" + + hfactory ${scobj_hpath}/blade_1/aspeed plain user float + hsetprop ${scobj_hpath}/blade_1/aspeed control true + hsetprop ${scobj_hpath}/blade_1/aspeed data true + hsetprop ${scobj_hpath}/blade_1/aspeed mutable true + hsetprop ${scobj_hpath}/blade_1/aspeed nxsave true + hsetprop ${scobj_hpath}/blade_1/aspeed oldval 0.0 + hsetprop ${scobj_hpath}/blade_1/aspeed sdsinfo "::nexus::scobj::sdsinfo" + hsetprop ${scobj_hpath}/blade_1/aspeed type "part" + hsetprop ${scobj_hpath}/blade_1/aspeed nxalias "${name}_blade_1_aspeed" + + hfactory ${scobj_hpath}/blade_1/rphase plain user float + hsetprop ${scobj_hpath}/blade_1/rphase control true + hsetprop ${scobj_hpath}/blade_1/rphase data true + hsetprop ${scobj_hpath}/blade_1/rphase mutable false + hsetprop ${scobj_hpath}/blade_1/rphase nxsave true + hsetprop ${scobj_hpath}/blade_1/rphase oldval 0.0 + hsetprop ${scobj_hpath}/blade_1/rphase sdsinfo "::nexus::scobj::sdsinfo" + hsetprop ${scobj_hpath}/blade_1/rphase type "part" + hsetprop ${scobj_hpath}/blade_1/rphase nxalias "${name}_blade_1_rphase" + + hfactory ${scobj_hpath}/blade_1/rspeed plain user float + hsetprop ${scobj_hpath}/blade_1/rspeed control true + hsetprop ${scobj_hpath}/blade_1/rspeed data true + hsetprop ${scobj_hpath}/blade_1/rspeed mutable false + hsetprop ${scobj_hpath}/blade_1/rspeed nxsave true + hsetprop ${scobj_hpath}/blade_1/rspeed oldval 0.0 + hsetprop ${scobj_hpath}/blade_1/rspeed sdsinfo "::nexus::scobj::sdsinfo" + hsetprop ${scobj_hpath}/blade_1/rspeed type "part" + hsetprop ${scobj_hpath}/blade_1/rspeed nxalias "${name}_blade_1_rspeed" + + hfactory ${scobj_hpath}/blade_1/state plain user text + hsetprop ${scobj_hpath}/blade_1/state read ${ns}::fetchState ${scobj_hpath} readState {1} + hsetprop ${scobj_hpath}/blade_1/state readState ${ns}::readState ${scobj_hpath} + hsetprop ${scobj_hpath}/blade_1/state control true + hsetprop ${scobj_hpath}/blade_1/state data true + hsetprop ${scobj_hpath}/blade_1/state mutable true + hsetprop ${scobj_hpath}/blade_1/state nxsave true + hsetprop ${scobj_hpath}/blade_1/state oldval UNKNOWN + hsetprop ${scobj_hpath}/blade_1/state my_state "idle" + hsetprop ${scobj_hpath}/blade_1/state sdsinfo "::nexus::scobj::sdsinfo" + hsetprop ${scobj_hpath}/blade_1/state type "part" + hsetprop ${scobj_hpath}/blade_1/state nxalias "${name}_blade_1_state" + + if {[string equal -nocase [SplitReply [chopper_simulation]] "false"]} { + ${sct_controller} poll ${scobj_hpath}/blade_1/state 1 + } else { + ::scobj::astrium_chopper::sics_log 9 "[chopper_simulation] => No poll/write for astrium_chopper" + } + + hfactory ${scobj_hpath}/blade_2 plain spy none + + hfactory ${scobj_hpath}/blade_2/aphase plain user float + hsetprop ${scobj_hpath}/blade_2/aphase control true + hsetprop ${scobj_hpath}/blade_2/aphase data true + hsetprop ${scobj_hpath}/blade_2/aphase mutable true + hsetprop ${scobj_hpath}/blade_2/aphase nxsave true + hsetprop ${scobj_hpath}/blade_2/aphase oldval 0.0 + hsetprop ${scobj_hpath}/blade_2/aphase sdsinfo "::nexus::scobj::sdsinfo" + hsetprop ${scobj_hpath}/blade_2/aphase type "part" + hsetprop ${scobj_hpath}/blade_2/aphase nxalias "${name}_blade_2_aphase" + + hfactory ${scobj_hpath}/blade_2/aspeed plain user float + hsetprop ${scobj_hpath}/blade_2/aspeed control true + hsetprop ${scobj_hpath}/blade_2/aspeed data true + hsetprop ${scobj_hpath}/blade_2/aspeed mutable true + hsetprop ${scobj_hpath}/blade_2/aspeed nxsave true + hsetprop ${scobj_hpath}/blade_2/aspeed oldval 0.0 + hsetprop ${scobj_hpath}/blade_2/aspeed sdsinfo "::nexus::scobj::sdsinfo" + hsetprop ${scobj_hpath}/blade_2/aspeed type "part" + hsetprop ${scobj_hpath}/blade_2/aspeed nxalias "${name}_blade_2_aspeed" + + hfactory ${scobj_hpath}/blade_2/rphase plain user float + hsetprop ${scobj_hpath}/blade_2/rphase control true + hsetprop ${scobj_hpath}/blade_2/rphase data true + hsetprop ${scobj_hpath}/blade_2/rphase mutable false + hsetprop ${scobj_hpath}/blade_2/rphase nxsave true + hsetprop ${scobj_hpath}/blade_2/rphase oldval 0.0 + hsetprop ${scobj_hpath}/blade_2/rphase sdsinfo "::nexus::scobj::sdsinfo" + hsetprop ${scobj_hpath}/blade_2/rphase type "part" + hsetprop ${scobj_hpath}/blade_2/rphase nxalias "${name}_blade_2_rphase" + + hfactory ${scobj_hpath}/blade_2/rspeed plain user float + hsetprop ${scobj_hpath}/blade_2/rspeed control true + hsetprop ${scobj_hpath}/blade_2/rspeed data true + hsetprop ${scobj_hpath}/blade_2/rspeed mutable false + hsetprop ${scobj_hpath}/blade_2/rspeed nxsave true + hsetprop ${scobj_hpath}/blade_2/rspeed oldval 0.0 + hsetprop ${scobj_hpath}/blade_2/rspeed sdsinfo "::nexus::scobj::sdsinfo" + hsetprop ${scobj_hpath}/blade_2/rspeed type "part" + hsetprop ${scobj_hpath}/blade_2/rspeed nxalias "${name}_blade_2_rspeed" + + hfactory ${scobj_hpath}/blade_2/state plain user text + hsetprop ${scobj_hpath}/blade_2/state read ${ns}::fetchState ${scobj_hpath} readState {2} + hsetprop ${scobj_hpath}/blade_2/state readState ${ns}::readState ${scobj_hpath} + hsetprop ${scobj_hpath}/blade_2/state control true + hsetprop ${scobj_hpath}/blade_2/state data true + hsetprop ${scobj_hpath}/blade_2/state mutable true + hsetprop ${scobj_hpath}/blade_2/state nxsave true + hsetprop ${scobj_hpath}/blade_2/state oldval UNKNOWN + hsetprop ${scobj_hpath}/blade_2/state my_state "idle" + hsetprop ${scobj_hpath}/blade_2/state sdsinfo "::nexus::scobj::sdsinfo" + hsetprop ${scobj_hpath}/blade_2/state type "part" + hsetprop ${scobj_hpath}/blade_2/state nxalias "${name}_blade_2_state" + + if {[string equal -nocase [SplitReply [chopper_simulation]] "false"]} { + ${sct_controller} poll ${scobj_hpath}/blade_2/state 1 + } else { + ::scobj::astrium_chopper::sics_log 9 "[chopper_simulation] => No poll/write for astrium_chopper" + } + + hfactory ${scobj_hpath}/blade_3 plain spy none + + hfactory ${scobj_hpath}/blade_3/aphase plain user float + hsetprop ${scobj_hpath}/blade_3/aphase control true + hsetprop ${scobj_hpath}/blade_3/aphase data true + hsetprop ${scobj_hpath}/blade_3/aphase mutable true + hsetprop ${scobj_hpath}/blade_3/aphase nxsave true + hsetprop ${scobj_hpath}/blade_3/aphase oldval 0.0 + hsetprop ${scobj_hpath}/blade_3/aphase sdsinfo "::nexus::scobj::sdsinfo" + hsetprop ${scobj_hpath}/blade_3/aphase type "part" + hsetprop ${scobj_hpath}/blade_3/aphase nxalias "${name}_blade_3_aphase" + + hfactory ${scobj_hpath}/blade_3/aspeed plain user float + hsetprop ${scobj_hpath}/blade_3/aspeed control true + hsetprop ${scobj_hpath}/blade_3/aspeed data true + hsetprop ${scobj_hpath}/blade_3/aspeed mutable true + hsetprop ${scobj_hpath}/blade_3/aspeed nxsave true + hsetprop ${scobj_hpath}/blade_3/aspeed oldval 0.0 + hsetprop ${scobj_hpath}/blade_3/aspeed sdsinfo "::nexus::scobj::sdsinfo" + hsetprop ${scobj_hpath}/blade_3/aspeed type "part" + hsetprop ${scobj_hpath}/blade_3/aspeed nxalias "${name}_blade_3_aspeed" + + hfactory ${scobj_hpath}/blade_3/rphase plain user float + hsetprop ${scobj_hpath}/blade_3/rphase control true + hsetprop ${scobj_hpath}/blade_3/rphase data true + hsetprop ${scobj_hpath}/blade_3/rphase mutable false + hsetprop ${scobj_hpath}/blade_3/rphase nxsave true + hsetprop ${scobj_hpath}/blade_3/rphase oldval 0.0 + hsetprop ${scobj_hpath}/blade_3/rphase sdsinfo "::nexus::scobj::sdsinfo" + hsetprop ${scobj_hpath}/blade_3/rphase type "part" + hsetprop ${scobj_hpath}/blade_3/rphase nxalias "${name}_blade_3_rphase" + + hfactory ${scobj_hpath}/blade_3/rspeed plain user float + hsetprop ${scobj_hpath}/blade_3/rspeed control true + hsetprop ${scobj_hpath}/blade_3/rspeed data true + hsetprop ${scobj_hpath}/blade_3/rspeed mutable false + hsetprop ${scobj_hpath}/blade_3/rspeed nxsave true + hsetprop ${scobj_hpath}/blade_3/rspeed oldval 0.0 + hsetprop ${scobj_hpath}/blade_3/rspeed sdsinfo "::nexus::scobj::sdsinfo" + hsetprop ${scobj_hpath}/blade_3/rspeed type "part" + hsetprop ${scobj_hpath}/blade_3/rspeed nxalias "${name}_blade_3_rspeed" + + hfactory ${scobj_hpath}/blade_3/state plain user text + hsetprop ${scobj_hpath}/blade_3/state read ${ns}::fetchState ${scobj_hpath} readState {3} + hsetprop ${scobj_hpath}/blade_3/state readState ${ns}::readState ${scobj_hpath} + hsetprop ${scobj_hpath}/blade_3/state control true + hsetprop ${scobj_hpath}/blade_3/state data true + hsetprop ${scobj_hpath}/blade_3/state mutable true + hsetprop ${scobj_hpath}/blade_3/state nxsave true + hsetprop ${scobj_hpath}/blade_3/state oldval UNKNOWN + hsetprop ${scobj_hpath}/blade_3/state my_state "idle" + hsetprop ${scobj_hpath}/blade_3/state sdsinfo "::nexus::scobj::sdsinfo" + hsetprop ${scobj_hpath}/blade_3/state type "part" + hsetprop ${scobj_hpath}/blade_3/state nxalias "${name}_blade_3_state" + + if {[string equal -nocase [SplitReply [chopper_simulation]] "false"]} { + ${sct_controller} poll ${scobj_hpath}/blade_3/state 1 + } else { + ::scobj::astrium_chopper::sics_log 9 "[chopper_simulation] => No poll/write for astrium_chopper" + } + + hfactory ${scobj_hpath}/blade_4 plain spy none + + hfactory ${scobj_hpath}/blade_4/aphase plain user float + hsetprop ${scobj_hpath}/blade_4/aphase control true + hsetprop ${scobj_hpath}/blade_4/aphase data true + hsetprop ${scobj_hpath}/blade_4/aphase mutable true + hsetprop ${scobj_hpath}/blade_4/aphase nxsave true + hsetprop ${scobj_hpath}/blade_4/aphase oldval 0.0 + hsetprop ${scobj_hpath}/blade_4/aphase sdsinfo "::nexus::scobj::sdsinfo" + hsetprop ${scobj_hpath}/blade_4/aphase type "part" + hsetprop ${scobj_hpath}/blade_4/aphase nxalias "${name}_blade_4_aphase" + + hfactory ${scobj_hpath}/blade_4/aspeed plain user float + hsetprop ${scobj_hpath}/blade_4/aspeed control true + hsetprop ${scobj_hpath}/blade_4/aspeed data true + hsetprop ${scobj_hpath}/blade_4/aspeed mutable true + hsetprop ${scobj_hpath}/blade_4/aspeed nxsave true + hsetprop ${scobj_hpath}/blade_4/aspeed oldval 0.0 + hsetprop ${scobj_hpath}/blade_4/aspeed sdsinfo "::nexus::scobj::sdsinfo" + hsetprop ${scobj_hpath}/blade_4/aspeed type "part" + hsetprop ${scobj_hpath}/blade_4/aspeed nxalias "${name}_blade_4_aspeed" + + hfactory ${scobj_hpath}/blade_4/rphase plain user float + hsetprop ${scobj_hpath}/blade_4/rphase control true + hsetprop ${scobj_hpath}/blade_4/rphase data true + hsetprop ${scobj_hpath}/blade_4/rphase mutable false + hsetprop ${scobj_hpath}/blade_4/rphase nxsave true + hsetprop ${scobj_hpath}/blade_4/rphase oldval 0.0 + hsetprop ${scobj_hpath}/blade_4/rphase sdsinfo "::nexus::scobj::sdsinfo" + hsetprop ${scobj_hpath}/blade_4/rphase type "part" + hsetprop ${scobj_hpath}/blade_4/rphase nxalias "${name}_blade_4_rphase" + + hfactory ${scobj_hpath}/blade_4/rspeed plain user float + hsetprop ${scobj_hpath}/blade_4/rspeed control true + hsetprop ${scobj_hpath}/blade_4/rspeed data true + hsetprop ${scobj_hpath}/blade_4/rspeed mutable false + hsetprop ${scobj_hpath}/blade_4/rspeed nxsave true + hsetprop ${scobj_hpath}/blade_4/rspeed oldval 0.0 + hsetprop ${scobj_hpath}/blade_4/rspeed sdsinfo "::nexus::scobj::sdsinfo" + hsetprop ${scobj_hpath}/blade_4/rspeed type "part" + hsetprop ${scobj_hpath}/blade_4/rspeed nxalias "${name}_blade_4_rspeed" + + hfactory ${scobj_hpath}/blade_4/state plain user text + hsetprop ${scobj_hpath}/blade_4/state read ${ns}::fetchState ${scobj_hpath} readState {4} + hsetprop ${scobj_hpath}/blade_4/state readState ${ns}::readState ${scobj_hpath} + hsetprop ${scobj_hpath}/blade_4/state control true + hsetprop ${scobj_hpath}/blade_4/state data true + hsetprop ${scobj_hpath}/blade_4/state mutable true + hsetprop ${scobj_hpath}/blade_4/state nxsave true + hsetprop ${scobj_hpath}/blade_4/state oldval UNKNOWN + hsetprop ${scobj_hpath}/blade_4/state my_state "idle" + hsetprop ${scobj_hpath}/blade_4/state sdsinfo "::nexus::scobj::sdsinfo" + hsetprop ${scobj_hpath}/blade_4/state type "part" + hsetprop ${scobj_hpath}/blade_4/state nxalias "${name}_blade_4_state" + + if {[string equal -nocase [SplitReply [chopper_simulation]] "false"]} { + ${sct_controller} poll ${scobj_hpath}/blade_4/state 1 + } else { + ::scobj::astrium_chopper::sics_log 9 "[chopper_simulation] => No poll/write for astrium_chopper" + } + hsetprop ${scobj_hpath} klass NXdisk_chopper + hsetprop ${scobj_hpath} debug_threshold 2 +# mkDriver hook code starts + hsetprop ${scobj_hpath} debug_threshold 1 +# mkDriver hook code ends + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + +namespace eval ::scobj::astrium_chopper { + namespace export debug_threshold + namespace export debug_log + namespace export sics_log + namespace export mkDriver +} + +proc add_astrium_chopper {name IP port} { + set catch_status [ catch { + ::scobj::astrium_chopper::sics_log 9 "add_astrium_chopper ${name} ${IP} ${port}" + if {[string equal -nocase [SplitReply [chopper_simulation]] "false"]} { + if {[string equal -nocase "aqadapter" "${IP}"]} { + ::scobj::astrium_chopper::sics_log 9 "makesctcontroller sct_${name} aqadapter ${port}" + makesctcontroller sct_${name} aqadapter ${port} + } else { + ::scobj::astrium_chopper::sics_log 9 "makesctcontroller sct_${name} std ${IP}:${port}" + makesctcontroller sct_${name} std ${IP}:${port} + } + } else { + ::scobj::astrium_chopper::sics_log 9 "[chopper_simulation] => No sctcontroller for astrium_chopper" + } + ::scobj::astrium_chopper::sics_log 1 "::scobj::astrium_chopper::mkDriver sct_${name} ${name}" + ::scobj::astrium_chopper::mkDriver sct_${name} ${name} + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + +puts stdout "file evaluation of sct_astrium_chopper.tcl" +::scobj::astrium_chopper::sics_log 9 "file evaluation of sct_astrium_chopper.tcl" + +proc ::scobj::astrium_chopper::read_config {} { + set catch_status [ catch { + set ns "::scobj::astrium_chopper" + dict for {k v} $::config_dict { + if { [dict exists $v "driver"] } { + if { [dict get $v "driver"] == "astrium_chopper" } { + if { [dict get $v enabled] } { + set name [dict get $v name] + if { ![string equal -nocase [SplitReply [chopper_simulation]] "false"] } { + set asyncqueue "null" + ${ns}::sics_log 9 "[chopper_simulation] => using null asyncqueue" + } elseif { [dict exists $v "asyncqueue"] } { + set asyncqueue [dict get $v "asyncqueue"] + } else { + if { [dict exists $v "asyncprotocol"] } { + set asyncprotocol [dict get $v "asyncprotocol"] + } else { + set asyncprotocol ${name}_protocol + MakeAsyncProtocol ${asyncprotocol} + if { [dict exists $v "terminator"] } { + ${asyncprotocol} sendterminator "[dict get $v "terminator"]" + ${asyncprotocol} replyterminator "[dict get $v "terminator"]" + } + } + set asyncqueue ${name}_queue + set IP [dict get $v ip] + set PORT [dict get $v port] + MakeAsyncQueue ${asyncqueue} ${asyncprotocol} ${IP} ${PORT} + if { [dict exists $v "timeout"] } { + ${asyncqueue} timeout "[dict get $v "timeout"]" + } + } + add_astrium_chopper ${name} "aqadapter" ${asyncqueue} + } + } + } + } + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + +if { [info exists ::config_dict] } { + ::scobj::astrium_chopper::read_config +} else { + ::scobj::astrium_chopper::sics_log 5 "No config dict" +}