New driver for the Oxford Mercury (using conditional and exec)

This commit is contained in:
Douglas Clowes
2014-11-20 14:46:24 +11:00
parent 01c0bf1f3c
commit a7e6017fd5

View File

@ -0,0 +1,162 @@
#
# Oxford Mercury with all devices as conditional groups
# vim: ft=tcl ts=8 sts=2 sw=2 expandtab autoindent smartindent nocindent
#
# Douglas Clowes (Douglas.Clowes@ansto.gov.au) November 2014
#
driver oxford_mercury = {
vendor = oxford;
device = mercury;
protocol = std;
class = environment;
simulation_group = environment_simulation;
# cards is the cards in the mercury slots 12345678
# H=Heater(1-3), V=Valve(4), L=Level(5), T=Temp(1-8), P=Pres(5,8), N=None(1-8)
# assoc is the associated actuator (H,V) for the controller (T,P) in the slot
add_args = 'id {cards NNNNNNNN} {assoc 00000000} {ttol 1} {ptol 5} {vtol 5}';
make_args = 'id {cards NNNNNNNN} {assoc 00000000} {ttol 1} {ptol 5} {vtol 5}';
group = {
group_property 'cards' = '${cards}';
group_property 'assoc' = '${assoc}';
group Temp0 = {
# Always the motherboard, always there
priv = user; type = float; readable = 5;
var sensor = { readable = 1; read_command = 'READ:DEV:MB1.T1:TEMP:SIG:TEMP'; permlink = 'T.S00'; }
var nick = { type=text; readable = 15; read_command = 'READ:DEV:MB1.T1:TEMP:NICK'; read_function = rdText; }
var power = { read_command = 'READ:DEV:MB0.H1:HTR:SIG:POWR'; }
var setpoint = { read_command = 'READ:DEV:MB1.T1:TEMP:LOOP:TSET';
driveable = Temp0/sensor; lowerlimit = 0; upperlimit = 333; tolerance = '${ttol}'; property settle_time = 15;
writeable = 1; write_function = setPoint; write_command = 'SET:DEV:MB1.T1:TEMP:LOOP:TSET:';
permlink = 'T.SP00';
}
}
%exec
exec_output = []
for i in range(8):
exec_output += [""]
exec_output += [" group Temp%d = {" % (i+1)]
exec_output += [" conditional = '[string equal -nocase [string index ${cards} %d] T]';" % i]
exec_output += [" priv = user; type = float; readable = 5;"]
exec_output += [" var sensor = { readable = 1; read_command = 'READ:DEV:DB%d.T1:TEMP:SIG:TEMP'; permlink = 'T.S%02d'; }" % (i+1,i+1)]
exec_output += [" var nick = { type=text; readable = 15; read_command = 'READ:DEV:DB%d.T1:TEMP:NICK'; read_function = rdText; }" % (i+1)]
if i > 4:
exec_output += [" var power = {"]
exec_output += [" conditional = '[string equal -nocase [string index ${cards} %d] H] && [string equal -nocase [string index ${assoc} %d] %d]';" % (i-5, i, i-4)]
exec_output += [" read_command = 'READ:DEV:DB%d.H1:HTR:SIG:POWR';" % (i - 4)]
exec_output += [" }"]
exec_output += [" var setpoint = {"]
exec_output += [" conditional = '[string equal -nocase [string index ${cards} %d] H] && [string equal -nocase [string index ${assoc} %d] %d]';" % (i-5, i, i-4)]
exec_output += [" read_command = 'READ:DEV:DB%d.T1:TEMP:LOOP:TSET';" % (i + 1)]
exec_output += [" driveable = Temp%d/sensor; lowerlimit = 0; upperlimit = 333; tolerance = '${ttol}'; property settle_time = 15;" % (i + 1)]
exec_output += [" writeable = 1; write_function = setPoint; write_command = 'SET:DEV:DB%d.T1:TEMP:LOOP:TSET:';" % (i + 1)]
exec_output += [" permlink = 'T.SP%02d';" % (i + 1)]
exec_output += [" }"]
exec_output += [" }"]
%end
group Pres5 = {
conditional = '[string equal -nocase [string index ${cards} 4] P]';
priv = user; type = float; readable = 5;
var sensor = { readable = 1; read_command = 'READ:DEV:DB5.P1:PRES:SIG:PRES'; permlink = 'P.PS05'; units = "mB"; }
var nick = { type=text; readable = 15; read_command = 'READ:DEV:DB5.P1:PRES:NICK'; read_function = rdText; }
var valve = {
conditional = '[string equal -nocase [string index ${cards} 3] V] && [string equal -nocase [string index ${assoc} 4] 4]';
read_command = 'READ:DEV:DB4.G1:AUX:SIG:OPEN';
}
var setpoint = {
conditional = '[string equal -nocase [string index ${cards} 3] V] && [string equal -nocase [string index ${assoc} 4] 4]';
read_command = 'READ:DEV:DB5.P1:PRES:LOOP:TSET';
driveable = Pres5/sensor; lowerlimit = 0; upperlimit = 333; tolerance = '${ptol}'; property settle_time = 15;
writeable = 1; write_function = setPoint; write_command = 'SET:DEV:DB8.P1:PRES:LOOP:TSET:';
permlink = 'P.PSP05'; units = "mB";
}
}
group Pres8 = {
conditional = '[string equal -nocase [string index ${cards} 7] P]';
priv = user; type = float; readable = 5;
var sensor = { readable = 1; read_command = 'READ:DEV:DB8.P1:PRES:SIG:PRES'; permlink = 'P.PS08'; units = "mB"; }
var nick = { type=text; readable = 15; read_command = 'READ:DEV:DB8.P1:PRES:NICK'; read_function = rdText; }
var valve = {
conditional = '[string equal -nocase [string index ${cards} 3] V] && [string equal -nocase [string index ${assoc} 7] 4]';
read_command = 'READ:DEV:DB4.G1:AUX:SIG:OPEN';
}
var setpoint = {
conditional = '[string equal -nocase [string index ${cards} 3] V] && [string equal -nocase [string index ${assoc} 7] 4]';
read_command = 'READ:DEV:DB8.P1:PRES:LOOP:TSET';
driveable = Pres8/sensor; lowerlimit = 0; upperlimit = 333; tolerance = '${ptol}'; property settle_time = 15;
writeable = 1; write_function = setPoint; write_command = 'SET:DEV:DB8.P1:PRES:LOOP:TSET:';
permlink = 'P.PSP08'; units = "mB";
}
}
group Valve = {
conditional = '[string equal -nocase [string index ${cards} 3] V]';
priv = user; type = float;
var sensor = {
readable = 5; read_command = 'READ:DEV:DB4.G1:AUX:SIG:OPEN';
}
var nick = { type=text; readable = 15; read_command = 'READ:DEV:DB4.G1:AUX:NICK'; read_function = rdText; }
var setpoint = {
driveable = Valve/sensor; lowerlimit = 0; upperlimit = 100; tolerance = '${vtol}'; property settle_time = 30;
writeable = 1; write_function = setValve; write_command = 'SET:DEV:DB4.G1:AUX:SIG:OPEN:';
}
}
group Level = {
conditional = '[string equal -nocase [string index ${cards} 4] L]';
priv = user; type = float; readable = 15;
var Nitrogen = { read_command = 'READ:DEV:DB5.L1:LVL:SIG:NIT:LEV'; permlink = 'T.N2'; }
var Helium = { read_command = 'READ:DEV:DB5.L1:LVL:SIG:HEL:LEV'; permlink = 'T.He'; }
var nick = { type=text; readable = 15; read_command = 'READ:DEV:DB5.L1:LVL:NICK'; read_function = rdText; }
}
}
code read_function rdValue = {
@TCL
set value [lindex [split "${data}" ":"] end]
if {[string equal -nocase [string index ${value} end] K]} {
set value [string range ${value} 0 end-1]
}
if {[string equal -nocase ${value} NaN]} {
set value 0
}
if {[string equal -nocase ${value} inf] || [string equal -nocase ${value} -inf]} {
set value 0
}
if {![string is double ${value}]} {
set value 0
}
scan ${value} "%g" data
@END
}
code read_function rdText = {
@ scan [lindex [split "$data" ":"] end] "%s" data
}
code Write_function setPoint = {
}
code Write_function setValve = {
}
code preamble = {
@TCL
proc make_config {sct_controller} {
set syscat [${sct_controller} transact READ:SYS:CAT]
set result ""
set devs [regexp -inline -all {DEV:D[[:alnum:]\.]*:[[:alnum:]]*} ${syscat}]
foreach dev [lsort ${devs}] {
set typ [string index [lindex [split ${dev} :] end] 0]
set typ [string map {A V} ${typ}]
clientput "${dev} ${typ}"
set result "${result}${typ}"
}
clientput "Result: ${result}"
return ${result}
}
@END
}
}