New driver for AeroLas Doppler drive for Emu

This commit is contained in:
Douglas Clowes
2014-12-02 16:15:12 +11:00
parent 8ff7368f34
commit 99671f2aa5
2 changed files with 513 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
# vim: ft=tcl ts=8 sts=2 sw=2 expandtab autoindent smartindent nocindent
driver aerolas_doppler = {
protocol = modbus_ap;
class = instrument;
simulation_group = motor_simulation;
group = {
readable = 1;
writeable = 1;
type = int;
fetch_function = getInteger;
read_function = rdInteger;
write_function = wrInteger;
var run_cmd = {
allowed = "0,1";
read_command = "1";
write_command = "1";
}
type = float;
fetch_function = getFloat;
read_function = rdFloat;
write_function = wrFloat;
var amplitude = {
read_command = "2";
write_command = "2";
}
var velocity = {
type = float;
read_command = "4";
write_command = "4";
}
}
code fetch_function getFloat = {
@TCL
set cmd "1:3:${cmd_str}:1:F32"
@END
}
code read_function rdFloat = {
@TCL
@END
}
code write_function wrFloat = {
@TCL
set cmd "1:16:${cmd_str}:1:F32:${par}"
@END
}
code fetch_function getInteger = {
@TCL
set cmd "1:3:${cmd_str}:1:U16"
@END
}
code read_function rdInteger = {
@TCL
@END
}
code write_function wrInteger = {
@TCL
set cmd "1:16:${cmd_str}:1:U16:${par}"
@END
}
}

View File

@@ -0,0 +1,450 @@
# Generated driver for aerolas_doppler
# vim: ft=tcl tabstop=8 softtabstop=2 shiftwidth=2 nocindent smartindent
#
namespace eval ::scobj::aerolas_doppler {
set debug_threshold 5
}
proc ::scobj::aerolas_doppler::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 now [clock seconds]
set ts [clock format ${now} -format "%Y%m%d"]
set log_file_name "../log/aerolas_doppler_[basename ${tc_root}]_${ts}.log"
set fd [open "${log_file_name}" "a"]
set ts [clock format ${now} -format "%T"]
puts ${fd} "${ts} ${debug_string}"
close ${fd}
}
} catch_message ]
}
proc ::scobj::aerolas_doppler::sics_log {debug_level debug_string} {
set catch_status [ catch {
set debug_threshold ${::scobj::aerolas_doppler::debug_threshold}
if {${debug_level} >= ${debug_threshold}} {
sicslog "::scobj::aerolas_doppler::${debug_string}"
}
} catch_message ]
}
# check function for hset change
proc ::scobj::aerolas_doppler::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::aerolas_doppler::getFloat {tc_root nextState cmd_str} {
set catch_status [ catch {
debug_log ${tc_root} 1 "getFloat tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
if { [hpropexists [sct] geterror] } {
hdelprop [sct] geterror
}
set cmd "${cmd_str}"
# getFloat hook code starts
set cmd "1:3:${cmd_str}:1:F32"
# getFloat hook code ends
if { [hpropexists [sct] geterror] } {
debug_log ${tc_root} 9 "[sct] error: [sct geterror]"
error "[sct geterror]"
}
debug_log ${tc_root} 1 "getFloat 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::aerolas_doppler::getInteger {tc_root nextState cmd_str} {
set catch_status [ catch {
debug_log ${tc_root} 1 "getInteger tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
if { [hpropexists [sct] geterror] } {
hdelprop [sct] geterror
}
set cmd "${cmd_str}"
# getInteger hook code starts
set cmd "1:3:${cmd_str}:1:U16"
# getInteger hook code ends
if { [hpropexists [sct] geterror] } {
debug_log ${tc_root} 9 "[sct] error: [sct geterror]"
error "[sct geterror]"
}
debug_log ${tc_root} 1 "getInteger 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::aerolas_doppler::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::aerolas_doppler::rdFloat {tc_root} {
set catch_status [ catch {
debug_log ${tc_root} 1 "rdFloat 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]"
}
# rdFloat 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::aerolas_doppler::rdInteger {tc_root} {
set catch_status [ catch {
debug_log ${tc_root} 1 "rdInteger 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]"
}
# rdInteger 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 write a parameter value on a device
proc ::scobj::aerolas_doppler::wrFloat {tc_root nextState cmd_str} {
set catch_status [ catch {
debug_log ${tc_root} 1 "wrFloat 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}"
# wrFloat hook code starts
set cmd "1:16:${cmd_str}:1:F32:${par}"
# wrFloat hook code ends
if { [hpropexists [sct] geterror] } {
debug_log ${tc_root} 9 "[sct] error: [sct geterror]"
error "[sct geterror]"
}
if { [hpropexists [sct] driving] } {
if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } {
sct driving 1
}
}
debug_log ${tc_root} 1 "wrFloat 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 write a parameter value on a device
proc ::scobj::aerolas_doppler::wrInteger {tc_root nextState cmd_str} {
set catch_status [ catch {
debug_log ${tc_root} 1 "wrInteger 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}"
# wrInteger hook code starts
set cmd "1:16:${cmd_str}:1:U16:${par}"
# wrInteger hook code ends
if { [hpropexists [sct] geterror] } {
debug_log ${tc_root} 9 "[sct] error: [sct geterror]"
error "[sct geterror]"
}
if { [hpropexists [sct] driving] } {
if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } {
sct driving 1
}
}
debug_log ${tc_root} 1 "wrInteger 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::aerolas_doppler::mkDriver { sct_controller name device_class simulation_flag ip_address tcp_port } {
::scobj::aerolas_doppler::sics_log 9 "::scobj::aerolas_doppler::mkDriver ${sct_controller} ${name} ${device_class} ${simulation_flag} ${ip_address} ${tcp_port}"
set ns "[namespace current]"
set catch_status [ catch {
MakeSICSObj ${name} SCT_OBJECT
sicslist setatt ${name} driver aerolas_doppler
sicslist setatt ${name} klass ${device_class}
sicslist setatt ${name} long_name ${name}
set scobj_hpath /sics/${name}
hfactory ${scobj_hpath}/amplitude plain user float
hsetprop ${scobj_hpath}/amplitude read ${ns}::getFloat ${scobj_hpath} rdFloat {2}
hsetprop ${scobj_hpath}/amplitude rdFloat ${ns}::rdFloat ${scobj_hpath}
hsetprop ${scobj_hpath}/amplitude write ${ns}::wrFloat ${scobj_hpath} noResponse {2}
hsetprop ${scobj_hpath}/amplitude noResponse ${ns}::noResponse ${scobj_hpath}
hsetprop ${scobj_hpath}/amplitude check ${ns}::checkrange ${scobj_hpath}
hsetprop ${scobj_hpath}/amplitude control true
hsetprop ${scobj_hpath}/amplitude data true
hsetprop ${scobj_hpath}/amplitude mutable true
hsetprop ${scobj_hpath}/amplitude nxsave true
hsetprop ${scobj_hpath}/amplitude oldval 0.0
hsetprop ${scobj_hpath}/amplitude klass "parameter"
hsetprop ${scobj_hpath}/amplitude sdsinfo "::nexus::scobj::sdsinfo"
hsetprop ${scobj_hpath}/amplitude type "part"
hsetprop ${scobj_hpath}/amplitude nxalias "${name}_amplitude"
if {[string equal -nocase "${simulation_flag}" "false"]} {
${sct_controller} poll ${scobj_hpath}/amplitude 1
${sct_controller} write ${scobj_hpath}/amplitude
hsetprop ${scobj_hpath}/amplitude simulated false
} else {
::scobj::aerolas_doppler::sics_log 9 "simulation_flag=${simulation_flag} => No poll/write for aerolas_doppler"
hsetprop ${scobj_hpath}/amplitude simulated true
}
hfactory ${scobj_hpath}/run_cmd plain user int
hsetprop ${scobj_hpath}/run_cmd read ${ns}::getInteger ${scobj_hpath} rdInteger {1}
hsetprop ${scobj_hpath}/run_cmd rdInteger ${ns}::rdInteger ${scobj_hpath}
hsetprop ${scobj_hpath}/run_cmd write ${ns}::wrInteger ${scobj_hpath} noResponse {1}
hsetprop ${scobj_hpath}/run_cmd noResponse ${ns}::noResponse ${scobj_hpath}
hsetprop ${scobj_hpath}/run_cmd check ${ns}::checkrange ${scobj_hpath}
hsetprop ${scobj_hpath}/run_cmd control true
hsetprop ${scobj_hpath}/run_cmd data true
hsetprop ${scobj_hpath}/run_cmd mutable true
hsetprop ${scobj_hpath}/run_cmd nxsave true
hsetprop ${scobj_hpath}/run_cmd values 0,1
hsetprop ${scobj_hpath}/run_cmd oldval 0
hsetprop ${scobj_hpath}/run_cmd klass "parameter"
hsetprop ${scobj_hpath}/run_cmd sdsinfo "::nexus::scobj::sdsinfo"
hsetprop ${scobj_hpath}/run_cmd type "part"
hsetprop ${scobj_hpath}/run_cmd nxalias "${name}_run_cmd"
if {[string equal -nocase "${simulation_flag}" "false"]} {
${sct_controller} poll ${scobj_hpath}/run_cmd 1
${sct_controller} write ${scobj_hpath}/run_cmd
hsetprop ${scobj_hpath}/run_cmd simulated false
} else {
::scobj::aerolas_doppler::sics_log 9 "simulation_flag=${simulation_flag} => No poll/write for aerolas_doppler"
hsetprop ${scobj_hpath}/run_cmd simulated true
}
hfactory ${scobj_hpath}/velocity plain user float
hsetprop ${scobj_hpath}/velocity read ${ns}::getFloat ${scobj_hpath} rdFloat {4}
hsetprop ${scobj_hpath}/velocity rdFloat ${ns}::rdFloat ${scobj_hpath}
hsetprop ${scobj_hpath}/velocity write ${ns}::wrFloat ${scobj_hpath} noResponse {4}
hsetprop ${scobj_hpath}/velocity noResponse ${ns}::noResponse ${scobj_hpath}
hsetprop ${scobj_hpath}/velocity check ${ns}::checkrange ${scobj_hpath}
hsetprop ${scobj_hpath}/velocity control true
hsetprop ${scobj_hpath}/velocity data true
hsetprop ${scobj_hpath}/velocity mutable true
hsetprop ${scobj_hpath}/velocity nxsave true
hsetprop ${scobj_hpath}/velocity oldval 0.0
hsetprop ${scobj_hpath}/velocity klass "parameter"
hsetprop ${scobj_hpath}/velocity sdsinfo "::nexus::scobj::sdsinfo"
hsetprop ${scobj_hpath}/velocity type "part"
hsetprop ${scobj_hpath}/velocity nxalias "${name}_velocity"
if {[string equal -nocase "${simulation_flag}" "false"]} {
${sct_controller} poll ${scobj_hpath}/velocity 1
${sct_controller} write ${scobj_hpath}/velocity
hsetprop ${scobj_hpath}/velocity simulated false
} else {
::scobj::aerolas_doppler::sics_log 9 "simulation_flag=${simulation_flag} => No poll/write for aerolas_doppler"
hsetprop ${scobj_hpath}/velocity simulated true
}
hsetprop ${scobj_hpath} data "true"
hsetprop ${scobj_hpath} klass "@none"
hsetprop ${scobj_hpath} type "part"
hsetprop ${scobj_hpath} driver aerolas_doppler
hsetprop ${scobj_hpath} klass ${device_class}
hsetprop ${scobj_hpath} data true
hsetprop ${scobj_hpath} debug_threshold 5
# mkDriver hook code goes here
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
proc ::scobj::aerolas_doppler::add_driver {name device_class simulation_flag ip_address tcp_port} {
set catch_status [ catch {
::scobj::aerolas_doppler::sics_log 9 "::scobj::aerolas_doppler::add_driver ${name} ${device_class} ${simulation_flag} ${ip_address} ${tcp_port}"
if {[string equal -nocase "${simulation_flag}" "false"]} {
if {[string equal -nocase "aqadapter" "${ip_address}"]} {
::scobj::aerolas_doppler::sics_log 9 "makesctcontroller sct_${name} aqadapter ${tcp_port}"
makesctcontroller sct_${name} aqadapter ${tcp_port}
} else {
::scobj::aerolas_doppler::sics_log 9 "makesctcontroller sct_${name} modbus_ap ${ip_address}:${tcp_port}"
makesctcontroller sct_${name} modbus_ap ${ip_address}:${tcp_port}
}
} else {
::scobj::aerolas_doppler::sics_log 9 "simulation_flag=${simulation_flag} => Null sctcontroller for aerolas_doppler"
::scobj::aerolas_doppler::sics_log 9 "makesctcontroller sct_${name} aqadapter NULL"
makesctcontroller sct_${name} aqadapter NULL
}
::scobj::aerolas_doppler::sics_log 1 "::scobj::aerolas_doppler::mkDriver sct_${name} ${name} ${device_class} ${simulation_flag} ${ip_address} ${tcp_port}"
::scobj::aerolas_doppler::mkDriver sct_${name} ${name} ${device_class} ${simulation_flag} ${ip_address} ${tcp_port}
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
namespace eval ::scobj::aerolas_doppler {
namespace export debug_threshold
namespace export debug_log
namespace export sics_log
namespace export mkDriver
namespace export add_driver
}
proc add_aerolas_doppler {name ip_address tcp_port} {
set simulation_flag "[string tolower [SplitReply [motor_simulation]]]"
::scobj::aerolas_doppler::add_driver ${name} "instrument" ${simulation_flag} ${ip_address} ${tcp_port}
}
clientput "file evaluation of sct_aerolas_doppler.tcl"
::scobj::aerolas_doppler::sics_log 9 "file evaluation of sct_aerolas_doppler.tcl"
proc ::scobj::aerolas_doppler::read_config {} {
set catch_status [ catch {
set ns "::scobj::aerolas_doppler"
dict for {k u} $::config_dict {
if { [dict exists $u "implementation"] } {
set simulation_flag "[string tolower [SplitReply [motor_simulation]]]"
set device_class "instrument"
if { !([dict exists $u "name"] && [dict exists $u "enabled"]) } {
continue
}
set enabled [string tolower [dict get $u "enabled"]]
if { ! ([string equal -nocase $enabled "true" ] || [string equal -nocase $enabled "always"]) } {
continue
}
if { [dict exists $u "simulation_group"] } {
set simulation_flag [SplitReply [[string tolower [dict get $u "simulation_group"]]]]
}
if { [dict exists $u "device_class"] } {
set device_class "[dict get $u "device_class"]"
}
set name [dict get $u name]
set implementation [dict get $u "implementation"]
if { !([dict exists $::config_dict $implementation]) } {
continue
}
set v [dict get $::config_dict $implementation]
if { !([dict exists $v "driver"]) } {
continue
}
if { [string equal -nocase [dict get $v "driver"] "aerolas_doppler"] } {
if { ![string equal -nocase "${simulation_flag}" "false"] } {
set asyncqueue "null"
${ns}::sics_log 9 "simulation_flag=${simulation_flag} => using null asyncqueue"
${ns}::sics_log 9 "makesctcontroller sct_${name} aqadapter NULL"
makesctcontroller sct_${name} aqadapter NULL
} elseif { [dict exists $v "asyncqueue"] } {
set asyncqueue [dict get $v "asyncqueue"]
if { [string equal -nocase ${asyncqueue} "sct"] } {
set ip_address [dict get $v ip]
set tcp_port [dict get $v port]
makesctcontroller sct_${name} modbus_ap ${ip_address}:${tcp_port}
} else {
makesctcontroller sct_${name} aqadapter ${asyncqueue}
}
} else {
if { [dict exists $v "asyncprotocol"] } {
set asyncprotocol [dict get $v "asyncprotocol"]
} else {
set asyncprotocol ${name}_protocol
MakeAsyncProtocol ${asyncprotocol}
if { [dict exists $v "sendterminator"] } {
${asyncprotocol} sendterminator "[dict get $v "sendterminator"]"
} elseif { [dict exists $v "terminator"] } {
${asyncprotocol} sendterminator "[dict get $v "terminator"]"
}
if { [dict exists $v "replyterminator"] } {
${asyncprotocol} replyterminator "[dict get $v "replyterminator"]"
} elseif { [dict exists $v "terminator"] } {
${asyncprotocol} replyterminator "[dict get $v "terminator"]"
}
}
set asyncqueue ${name}_queue
set ip_address [dict get $v ip]
set tcp_port [dict get $v port]
MakeAsyncQueue ${asyncqueue} ${asyncprotocol} ${ip_address} ${tcp_port}
if { [dict exists $v "timeout"] } {
${asyncqueue} timeout "[dict get $v "timeout"]"
}
makesctcontroller sct_${name} aqadapter ${asyncqueue}
}
${ns}::mkDriver sct_${name} ${name} ${device_class} ${simulation_flag} ${ip_address} ${tcp_port}
}
}
}
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
if { [info exists ::config_dict] } {
::scobj::aerolas_doppler::read_config
} else {
::scobj::aerolas_doppler::sics_log 5 "No config dict"
}