Commit e7a479fa authored by Matias Guijarro's avatar Matias Guijarro

spec: move bliss macros to bliss namespace (fix #76) (step 1)

parent 366e579a
Pipeline #1487 passed with stages
in 7 minutes and 13 seconds
#%TITLE% bliss.mac
#%NAME%
# bliss.mac - SPEC macros to integrate bliss control system
#
#%OVERVIEW%
# SPEC macros to integrate bliss control system %BR% \
# It assumes the existance of a TANGO Bliss DS with a Bliss device class %BR% \
# with a name SPECBL/bliss/<session> %BR% \
# %BR% \
# Short way: add %B%need\ bliss%B% and %B%blisssetup%B% to your setup files %BR% \
# %BR% \
# %BR%
#%EXAMPLE%
# %DL%
# %DT%blisssetup
# %DD%Configures to use the bliss session with the same name as the
# spec session
# %DT%blisssetup sixc
# %DD%Configures to use the bliss 'sixc' session
# %DT%blisssetup sixc 1
# %DD%Configures to use the bliss 'sixc' session, replacing standard spec
# macros (use with extreme caution)
# %DT%b_wa
# %DD%Runs the %B%wa%B% function in bliss (if replaced spec macros in
# blisssetup, then macro is just "wa" not "b_wa". Same goes for following
# examples)
# %DT%b_umv th 180
# %DD%Runs the %B%umv%B% function in bliss
# %DT%b_ascan th 0 180 100 0.1
# %DD%Runs the %B%ascan%B% function in bliss
# %XDL%
#
def blisssetup '{
global BLISS_DEVICE
local name result
name = SPEC
if ($# > 0) {
name = "$1"
}
BLISS_DEVICE = SPECBL "/bliss/" name
result = _bliss_expose_all()
if (result == 0) {
printf("bliss info: \'%s\' session configured with \'%s\'\n", \
name, BLISS_DEVICE)
}
}'
def _bliss_msg(msg) '{
printf("%s\n", msg)
}'
def _bliss_error_desc(msg) '{
# Prints <msg> message.
# Prints only "desc" field of the TANGO_ERR_STACK
# other fields are too useless for users
_bliss_msg(msg)
_bliss_msg("Details:")
for (item in TANGO_ERR_STACK) {
if (index(item, "desc")) {
_bliss_msg(TANGO_ERR_STACK[item])
}
}
}'
def _bliss_print_err '{
local msg
if (TANGO_ERR != "0") {
if (TANGO_ERR == "API_DeviceNotExported") {
msg = "bliss server is not running or inacessible"
} else {
msg = sprintf("%s\n%s", TANGO_ERR_STACK[0]["reason"], \
TANGO_ERR_STACK[0]["desc"])
}
eprintf("bliss error: %s\n", msg)
}
}'
def _bliss_io(cmd_name) '{
local dev result
dev = _get_bliss_device()
TANGO_ERR = -1
result = tango_io(dev, cmd_name)
_bliss_print_err
return result
}'
def _bliss_io_param(cmd_name, param) '{
local dev result
dev = _get_bliss_device()
TANGO_ERR = -1
if (tango_io(dev, cmd_name, param, result) == 0) {
return result
}
_bliss_print_err
return
}'
def _bliss_get(attr_name) '{
local dev result
dev = _get_bliss_device()
TANGO_ERR = -1
if (tango_get(dev, attr_name, result) == 0) {
return result
}
_bliss_print_err
return
}'
def _bliss_get_array(attr_name) '{
local dev result[]
dev = _get_bliss_device()
TANGO_ERR = -1
if (tango_get(dev, attr_name, result) != -1) {
return (result)
}
_bliss_print_err
return
}'
def _bliss_put(attr_name, value) '{
local dev
dev = _get_bliss_device()
TANGO_ERR = -1
if (tango_put(dev, attr_name, value) == 0) {
return 0
}
_bliss_print_err
return -1
}'
def _bliss_update_channel(channel) '{
local value
value = _bliss_get(channel)
if (TANGO_ERR != "0") {
return -1
}
printf("%s", value)
return 0
}'
def _bliss_update_output() '{
if(_bliss_update_channel("output_channel") != 0) {
return -1
}
if(_bliss_update_channel("error_channel") != 0) {
return -1
}
}'
def _bliss_update_input() '{
local need_input inp
need_input = _bliss_get("need_input")
if (TANGO_ERR != "0") {
return -1
}
if (need_input) {
inp = input() "\n"
if (_bliss_put("input_channel", inp) != 0) {
return -1
}
}
return 0
}'
def _bliss_stop(cmd_id) '{
_bliss_io_param("stop", cmd_id)
_bliss_update_output()
}'
def _bliss_run(params) '{
local cmd_id running cleanup
cmd_id = _bliss_io_param("execute", params)
if (TANGO_ERR != "0") {
return -1
}
cleanup = sprintf("_bliss_stop(%lld)", cmd_id)
cdef("cleanup_once", cleanup, "_bliss_run_")
running = 1
while (running) {
if(_bliss_update_output() != 0) {
return -1
}
if(_bliss_update_input() != 0) {
return -1
}
running = _bliss_io_param("is_running", cmd_id)
if (TANGO_ERR != "0") {
return -1
}
sleep(0.1)
}
if(_bliss_update_output() != 0) {
return -1
}
cdef("cleanup_once", "", "_bliss_run_", "delete")
}'
def _get_bliss_device(p) '{
global BLISS_DEVICE
local dev
if (BLISS_DEVICE == 0) {
dev = SPECBL "/bliss/" SPEC
BLISS_DEVICE = dev
}
else {
dev = BLISS_DEVICE
}
return (dev)
}'
def blisskeys '{
local bliss_dev keys[]
bliss_dev = _get_bliss_device()
tango_get(bliss_dev, "namespace", keys)
# TODO: print output to screen
}'
def __to_py_cmd(cmd, spec_args) '{
local args nargs result next
nargs = split(spec_args, args)
if (!nargs) {
result = cmd "()"
} else {
result = cmd "("
for(i=0; i<nargs; i++) {
if (i < (nargs-1)) {
suffix = ", "
}
else {
suffix = ")"
}
result = result args[i] suffix
}
}
return(result)
}'
def _bliss_execute(cmd, spec_args) '{
local args
py_cmd = __to_py_cmd(cmd, spec_args)
_bliss_run(py_cmd)
}'
def b_run '{
_bliss_run("$*")
}'
def _bliss_expose_all() '{
local i functions[]
local dev
dev = _get_bliss_device()
TANGO_ERR = -1
if (tango_get(dev, "functions", functions) == -1) {
_bliss_print_err
return -1
}
for(i in functions) {
_bliss_expose(functions[i])
}
return 0
}'
def _bliss_expose(cmd) '{
local _cmd prefix
prefix = "b_"
_cmd = "rdef " prefix cmd " \'{ _bliss_execute(\"" cmd "\", \"$*\") }\'"
eval(_cmd)
}'
print "Deprecation warning: bliss.mac is deprecated. " \
"Use bliss/bliss.mac instead"
jdo bliss/bliss.mac
#%TITLE% bliss.mac
#%NAME%
# bliss.mac - SPEC macros to integrate bliss control system
#
#%OVERVIEW%
# SPEC macros to integrate bliss control system %BR% \
# It assumes the existance of a TANGO Bliss DS with a Bliss device class %BR% \
# with a name SPECBL/bliss/<session> %BR% \
# %BR% \
# Short way: add %B%need\ bliss%B% and %B%blisssetup%B% to your setup files %BR% \
# %BR% \
# %BR%
#%EXAMPLE%
# %DL%
# %DT%blisssetup
# %DD%Configures to use the bliss session with the same name as the
# spec session
# %DT%blisssetup sixc
# %DD%Configures to use the bliss 'sixc' session
# %DT%blisssetup sixc 1
# %DD%Configures to use the bliss 'sixc' session, replacing standard spec
# macros (use with extreme caution)
# %DT%b_wa
# %DD%Runs the %B%wa%B% function in bliss (if replaced spec macros in
# blisssetup, then macro is just "wa" not "b_wa". Same goes for following
# examples)
# %DT%b_umv th 180
# %DD%Runs the %B%umv%B% function in bliss
# %DT%b_ascan th 0 180 100 0.1
# %DD%Runs the %B%ascan%B% function in bliss
# %XDL%
#
def blisssetup '{
global BLISS_DEVICE
local name result
name = SPEC
if ($# > 0) {
name = "$1"
}
BLISS_DEVICE = SPECBL "/bliss/" name
result = _bliss_expose_all()
if (result == 0) {
printf("bliss info: \'%s\' session configured with \'%s\'\n", \
name, BLISS_DEVICE)
}
}'
def _bliss_msg(msg) '{
printf("%s\n", msg)
}'
def _bliss_error_desc(msg) '{
# Prints <msg> message.
# Prints only "desc" field of the TANGO_ERR_STACK
# other fields are too useless for users
_bliss_msg(msg)
_bliss_msg("Details:")
for (item in TANGO_ERR_STACK) {
if (index(item, "desc")) {
_bliss_msg(TANGO_ERR_STACK[item])
}
}
}'
def _bliss_print_err '{
local msg
if (TANGO_ERR != "0") {
if (TANGO_ERR == "API_DeviceNotExported") {
msg = "bliss server is not running or inacessible"
} else {
msg = sprintf("%s\n%s", TANGO_ERR_STACK[0]["reason"], \
TANGO_ERR_STACK[0]["desc"])
}
eprintf("bliss error: %s\n", msg)
}
}'
def _bliss_io(cmd_name) '{
local dev result
dev = _get_bliss_device()
TANGO_ERR = -1
result = tango_io(dev, cmd_name)
_bliss_print_err
return result
}'
def _bliss_io_param(cmd_name, param) '{
local dev result
dev = _get_bliss_device()
TANGO_ERR = -1
if (tango_io(dev, cmd_name, param, result) == 0) {
return result
}
_bliss_print_err
return
}'
def _bliss_get(attr_name) '{
local dev result
dev = _get_bliss_device()
TANGO_ERR = -1
if (tango_get(dev, attr_name, result) == 0) {
return result
}
_bliss_print_err
return
}'
def _bliss_get_array(attr_name) '{
local dev result[]
dev = _get_bliss_device()
TANGO_ERR = -1
if (tango_get(dev, attr_name, result) != -1) {
return (result)
}
_bliss_print_err
return
}'
def _bliss_put(attr_name, value) '{
local dev
dev = _get_bliss_device()
TANGO_ERR = -1
if (tango_put(dev, attr_name, value) == 0) {
return 0
}
_bliss_print_err
return -1
}'
def _bliss_update_channel(channel) '{
local value
value = _bliss_get(channel)
if (TANGO_ERR != "0") {
return -1
}
printf("%s", value)
return 0
}'
def _bliss_update_output() '{
if(_bliss_update_channel("output_channel") != 0) {
return -1
}
if(_bliss_update_channel("error_channel") != 0) {
return -1
}
}'
def _bliss_update_input() '{
local need_input inp
need_input = _bliss_get("need_input")
if (TANGO_ERR != "0") {
return -1
}
if (need_input) {
inp = input() "\n"
if (_bliss_put("input_channel", inp) != 0) {
return -1
}
}
return 0
}'
def _bliss_stop(cmd_id) '{
_bliss_io_param("stop", cmd_id)
_bliss_update_output()
}'
def _bliss_run(params) '{
local cmd_id running cleanup
cmd_id = _bliss_io_param("execute", params)
if (TANGO_ERR != "0") {
return -1
}
cleanup = sprintf("_bliss_stop(%lld)", cmd_id)
cdef("cleanup_once", cleanup, "_bliss_run_")
running = 1
while (running) {
if(_bliss_update_output() != 0) {
return -1
}
if(_bliss_update_input() != 0) {
return -1
}
running = _bliss_io_param("is_running", cmd_id)
if (TANGO_ERR != "0") {
return -1
}
sleep(0.1)
}
if(_bliss_update_output() != 0) {
return -1
}
cdef("cleanup_once", "", "_bliss_run_", "delete")
}'
def _get_bliss_device(p) '{
global BLISS_DEVICE
local dev
if (BLISS_DEVICE == 0) {
dev = SPECBL "/bliss/" SPEC
BLISS_DEVICE = dev
}
else {
dev = BLISS_DEVICE
}
return (dev)
}'
def blisskeys '{
local bliss_dev keys[]
bliss_dev = _get_bliss_device()
tango_get(bliss_dev, "namespace", keys)
# TODO: print output to screen
}'
def __to_py_cmd(cmd, spec_args) '{
local args nargs result next
nargs = split(spec_args, args)
if (!nargs) {
result = cmd "()"
} else {
result = cmd "("
for(i=0; i<nargs; i++) {
if (i < (nargs-1)) {
suffix = ", "
}
else {
suffix = ")"
}
result = result args[i] suffix
}
}
return(result)
}'
def _bliss_execute(cmd, spec_args) '{
local args
py_cmd = __to_py_cmd(cmd, spec_args)
_bliss_run(py_cmd)
}'
def b_run '{
_bliss_run("$*")
}'
def _bliss_expose_all() '{
local i functions[]
local dev
dev = _get_bliss_device()
TANGO_ERR = -1
if (tango_get(dev, "functions", functions) == -1) {
_bliss_print_err
return -1
}
for(i in functions) {
_bliss_expose(functions[i])
}
return 0
}'
def _bliss_expose(cmd) '{
local _cmd prefix
prefix = "b_"
_cmd = "rdef " prefix cmd " \'{ _bliss_execute(\"" cmd "\", \"$*\") }\'"
eval(_cmd)
}'
def ct2_config(cnum, type, unit, module, chan) '{
local mne factor ctrl_dev
global CT2_MAC_HDW[]
ctrl_dev = ct2_ADDR
if (type == "ctrl") {
printf("Using P201 \"%s\" counters\n", ctrl_dev)
return
}
mne = cnt_mne(cnum)
if (chan == 0) {
printf("Configuring \"%s\" as timer\n", mne)
factor = counter_par(cnum, "scale")
tango_put(ctrl_dev, "timer_freq", factor)
tango_put(ctrl_dev, "acq_mode", "IntTrigReadout")
tango_put(ctrl_dev, "acq_point_period", 0)
CT2_MAC_HDW[ctrl_dev]["int_cnt"] = 11
}
}'
def ct2_cmd(cnum, key, p1, p2) '{
local chan is_running ctrl_dev acq_chan acq_chan_list[] sep val[] int_cnt
local cnt_idx cnt_i
global CT2_MAC_HDW_LAST[]
ctrl_dev = ct2_ADDR
if (cnum != "..")
chan = counter_par(cnum, "channel")
if (key == "get_status") {
is_running = (tango_get(ctrl_dev, "acq_status") == "Running")
CT2_MAC_HDW[ctrl_dev]["running"] = is_running
return is_running
} else if (key == "prestart_all") {
CT2_MAC_HDW[ctrl_dev]["acq_channels"] = ""
CT2_MAC_HDW[ctrl_dev]["nb_channels"] = 0
CT2_MAC_HDW_LAST["valid"] = 0
} else if (key == "start_one") {
if (chan != 0) {
acq_chan = CT2_MAC_HDW[ctrl_dev]["acq_channels"]
sep = length(acq_chan) ? " " : ""
acq_chan = sprintf("%s%s%d", acq_chan, sep, chan)
CT2_MAC_HDW[ctrl_dev]["acq_channels"] = acq_chan
cnt_idx = CT2_MAC_HDW[ctrl_dev]["nb_channels"]++
counter_par(cnum, "counter_idx", cnt_idx, "add")
} else {
tango_put(ctrl_dev, "acq_expo_time", p1)
split(CT2_MAC_HDW[ctrl_dev]["acq_channels"], acq_chan_list)
tango_put(ctrl_dev, "acq_channels", acq_chan_list)
tango_put(ctrl_dev, "acq_nb_points", 1)
tango_io(ctrl_dev, "prepare_acq")
tango_io(ctrl_dev, "start_acq")
}
} else if (key == "counts") {
if (!CT2_MAC_HDW_LAST["valid"]) {
tango_get(ctrl_dev, "counters", val)
int_cnt = CT2_MAC_HDW[ctrl_dev]["int_cnt"]
if (val[int_cnt - 1] != 0) {
cnt_idx = (chan ? chan : int_cnt) - 1
return val[cnt_idx]
}
TANGO_ERR = -1
tango_get(ctrl_dev, "data", val)
if (TANGO_ERR != "0")
return -1
for (cnt_i in val)
CT2_MAC_HDW_LAST[cnt_i] = val[cnt_i]
CT2_MAC_HDW_LAST["valid"] = 1
}
if (chan)
cnt_idx = counter_par(cnum, "counter_idx")
else
cnt_idx = CT2_MAC_HDW[ctrl_dev]["nb_channels"]
return CT2_MAC_HDW_LAST[cnt_idx]
} else if (key == "halt_all") {
tango_io(ctrl_dev, "stop_acq")
}
}'
def ct2_get(cnum, key, val_arr) '{
local ctrl_dev arr_keys
ctrl_dev = counter_par(cnum, "address")
if (key == "?") {
printf("%s\n%s\n%s\n", \
"acq_mode, acq_status, timer_freq, acq_nb_points", \
"acq_expo_time, acq_point_period, last_point_nb", \
"acq_channels, counters, latches, data")
return
}
arr_keys = " acq_channels counters latches data "
if (index(arr_keys, sprintf(" %s ", key)) > 0) {
return tango_get(ctrl_dev, key, val_arr)
} else {
return tango_get(ctrl_dev, key)
}
}'
def ct2_put(cnum, key, val) '{
local ctrl_dev mode_str
ctrl_dev = counter_par(cnum, "address")
if (key == "?") {
printf("%s\n%s\n%s\n", \
"acq_mode, acq_status, timer_freq, acq_nb_points", \
"acq_expo_time, acq_point_period, last_point_nb", \
"acq_channels")
return
}
return tango_put(ctrl_dev, key, val)
}'
def ct2_io(cnum, cmd) '{
local ctrl_dev mode_str val val_arr[]
ctrl_dev = counter_par(cnum, "address")
if (cmd == "?") {
printf("%s\n%s\n", \
"prepare_acq, start_acq, stop_acq, trigger_point", \
"trigger_latch")
return
}
tango_io(ctrl_dev, cmd)
}'
This diff is collapsed.
def nanodac_setup '{
if($# < 1)
{
print "Usage: $0 <TANGO_URL>\n"
exit
}
global NANODAC_SERVER_URL
NANODAC_SERVER_URL = "$1"
global NANODAC_MOT[]
cdef("user_getangles", "_nanodac_getangles\n", "nanodacmot")
cdef("user_checkall", "_nanodac_moveall\n", "nanodacmot")
cdef("user_motorsrun", "_nanodac_motorsrun\n", "nanodacmot")
global NANODAC_CNT[]
cdef("user_getcounts", "_nanodac_getcounts\n", "nanodaccnt", 0x10)
}'
def nanodac_unsetup '{
cdef("", "", "nanodacmot", "delete")
cdef("", "", "nanodaccnt", "delete")
}'
def nanodac_menu '{
local option nl i
option = 1
while((option != "quit") && (option != "q"))
{
tty_cntl("cl")
nl = 0
tty_move(0, nl++, "Nanodac Status:")
nl++
tty_cntl("so")
tty_cntl("md")
tty_move(0, nl++, "Channels info:")
tty_move(9, nl, "PV")
tty_move(16, nl, "PV2")
tty_move(22, nl, "Type")
tty_move(28, nl++, "Lin type")
tty_cntl("se")
tty_cntl("me")
for(i = 1; i < 5;++i)
{
local val
tty_move(4, nl, i)
val = tango_get(NANODAC_SERVER_URL,sprintf("c%d_pv",i))
tty_move(9, nl,sprintf("%.2f",val))
val = tango_get(NANODAC_SERVER_URL,sprintf("c%d_pv2",i))
tty_move(16, nl,sprintf("%.1f",val))
val = tango_get(NANODAC_SERVER_URL,sprintf("c%d_type",i))
tty_move(22, nl,val)
val = tango_get(NANODAC_SERVER_URL,sprintf("c%d_lintype",i))
tty_move(28, nl++,val)
}
++nl
tty_cntl("so")
tty_cntl("md")
tty_move(0, nl++, "Loop:")
tty_move(9, nl, "PV")
tty_move(16, nl, "Slope")
tty_move(22, nl, "Targetsp")
tty_move(31, nl, "Workingsp")
tty_move(41, nl, "P")
tty_move(48, nl, "I")
tty_move(55, nl++, "D")
tty_cntl("se")
tty_cntl("me")
for(i = 1; i < 3;++i)
{
local val
tty_move(4, nl, i)
</