Commit 398083cd authored by Matias Guijarro's avatar Matias Guijarro
Browse files

Merge branch 'tango_fixes' into 'master'

Bliss tango server addons and fixes

See merge request !430
parents c7a54579 109a2885
......@@ -202,7 +202,7 @@ class BlissAxisManager(Device):
elif not self.group_dict:
print 'BlissAxisManager: move_done event with no group'
return
if 'sender' in kws:
sender = kws['sender']
groupid = [gid for gid, grp in self.group_dict.items()
......@@ -620,7 +620,7 @@ class BlissAxis(Device):
self.debug_stream("In read_Home_side()")
return self.attr_Home_side_read
@attribute(dtype=float,
@attribute(dtype=float,
doc='Size of the relative step performed by the ' \
'StepUp and StepDown commands.\nThe StepSize' \
'is expressed in physical unit',
......@@ -1143,6 +1143,9 @@ def initialize_bliss(info, db=None):
axis_names = []
for name in object_names:
obj_cfg = cfg.get_config(name)
# if tango_server is defined it means it is manually added
if 'tango_server' in obj_cfg:
continue
if obj_cfg.plugin == 'emotion':
axis_names.append(name)
......
......@@ -25,6 +25,7 @@ import StringIO
import functools
import itertools
import traceback
import collections
import cPickle
import base64
import datetime
......@@ -42,6 +43,7 @@ from bliss import shell
from bliss.common import event
from bliss.common import data_manager
from bliss.common.utils import grouped
from bliss.config import settings
from bliss.config.static import get_config
from bliss.controllers.motor_group import Group
......@@ -156,7 +158,7 @@ class Bliss(Device):
#: Session names (default: None, meaning use server instance name as
#: session name)
session_names = device_property(dtype=[str], default_value=None)
session_names = device_property(dtype=[str], default_value=[])
#: Sanitize or not the command to be executed
#: If True, it will allow you to send a command like: 'wm th phi'
......@@ -179,7 +181,7 @@ class Bliss(Device):
self.__tasks = {}
self.__results = {}
if self.session_names is None:
if not self.session_names:
util = Util.instance()
self.session_names = [util.get_ds_inst_name()]
......@@ -232,6 +234,10 @@ class Bliss(Device):
def object_names(self):
return self._object_names
@attribute(dtype=(str,), max_dim_x=10000)
def axis_device_names(self):
return [dev.get_name() for dev in self.__get_axis_devices().values()]
@attribute(dtype=(str,), max_dim_x=10000)
def tasks(self):
return ['{0} {1}'.format(tid, cmd) for tid, (_, cmd) in self.__tasks.items()]
......@@ -305,6 +311,21 @@ class Bliss(Device):
except Exception as e:
sys.excepthook(*sys.exc_info())
def __reload(self):
get_config().reload()
def __get_axis_devices(self):
util = Util.instance()
result = dict()
for dev in util.get_device_list("*"):
dev_class = dev.get_device_class()
if dev_class:
class_name = dev_class.get_name()
if class_name.startswith("BlissAxis_"):
axis = dev.axis
result[axis.name] = dev
return result
@command(dtype_in=str, dtype_out=int)
def eval(self, cmd):
self._log.info('evaluating: %s', cmd)
......@@ -348,18 +369,18 @@ class Bliss(Device):
@command(dtype_in=(str,), doc_in='Flat list of pairs motor, position',
dtype_out=str, doc_out='Group identifier')
def motor_group_move(self, axes_pos):
def axis_group_move(self, axes_pos):
axes = map(get_bliss_obj, axes_pos[::2])
axes_positions = map(float, axes_pos[1::2])
axes_pos_dict = dict(zip(axes, axes_positions))
group = Group(*axes)
event.connect(group, 'move_done', self.__on_motor_group_move_done)
group.move(axes_pos_dict)
event.connect(group, 'move_done', self.__on_axis_group_move_done)
group.move(axes_pos_dict, wait=False)
group_id = ','.join(map(':'.join, grouped(axes_pos, 2)))
self.group_dict[group_id] = group
return group_id
def __on_motor_group_move_done(self, move_done, **kwargs):
def __on_axis_group_move_done(self, move_done, **kwargs):
if not move_done:
return
elif not self.group_dict:
......@@ -378,8 +399,9 @@ class Bliss(Device):
self.group_dict.pop(group_id)
@command(dtype_in=str, doc_in='Group identifier')
def motor_group_state(self, group_id):
@command(dtype_in=str, doc_in='Group identifier',
dtype_out=[str], doc_out='"flat list of pairs motor, status')
def axis_group_state(self, group_id):
"""
Return the individual state of motors in the group
"""
......@@ -393,7 +415,7 @@ class Bliss(Device):
return list(itertools.chain(*name_state_list))
@command(dtype_in=str, doc_in='Group identifier')
def motor_group_abort(self, group_id):
def axis_group_abort(self, group_id):
"""
Abort motor group movement
"""
......@@ -402,6 +424,41 @@ class Bliss(Device):
group = self.group_dict[group_id]
group.stop(wait=False)
@command(dtype_in=str,
doc_in='JSON representation of a map: <setting_name, setting_value>')
def set_settings(self, json_value):
data = json.loads(json_value)
for key, value in data.items():
setting = settings.HashSetting(key)
setting.set(value)
@command(dtype_in=str, doc_in='JSON representation of list<setting_name>',
dtype_out=str, doc_out='')
def get_settings(self, json_value):
data = json.loads(json_value)
result = {}
if isinstance(data, dict):
data = data.values()
elif isinstance(data, (str, unicode)):
data = data,
for element in data:
if element:
setting = settings.HashSetting(element)
result[element] = setting.get_all()
return json.dumps(result)
@command
def reload_config(self):
self.__reload()
@command(dtype_in=bool, doc_in='reload (true to do a reload before ' \
'apply configuration, false not to)')
def apply_config(self, reload):
if reload:
self._reload()
for dev in self.__get_axis_devices().values():
dev.axis.apply_config(reload=False)
def register_server(server_type, server_instance,
domain=None, family='bliss', member=None,
......@@ -517,6 +574,8 @@ def __initialize(args, db=None):
shell_info=shell_info)
for name in os.listdir(this_dir):
if name.startswith('.'):
continue
if name.endswith(suffix):
module_name = '{0}.{1}'.format(__package__, name[:-3])
_log.info('searching for init in %s...', module_name)
......
......@@ -60,10 +60,15 @@ global EMOTION_COMP_FUNC[]
def bliss_get_axes(mot_name) '{
local TTT[]
local TTT[] ctrl_dev
# Do not remove the following line...
TTT[0] = TTT[0]
tango_io(motor_par(mot_name, "bliss_axis_master_ds"), "GetAxisList", TTT)
ctrl_dev = motor_par(mot_name, "bliss_axis_master_ds")
bliss_class = motor_par(mot_name, "bliss_axis_master_class")
if (bliss_class == "Bliss")
tango_get(ctrl_dev, "axis_device_names", TTT)
else
tango_io(ctrl_dev, "GetAxisList", TTT)
return TTT
}'
......@@ -290,7 +295,7 @@ def eeconfig '{
#%MDESC% \
# Called on config/reconfig
def tango_mot_config(motnum, type, unit, module, channel) '{
local _ctrl_ds_name _msg
local _ctrl_ds_name _msg bliss_class cmd
_ctrl_ds_name = tango_mot_ADDR
......@@ -315,10 +320,20 @@ def tango_mot_config(motnum, type, unit, module, channel) '{
tango_mot_reset_motion(_ctrl_ds_name)
tango_io(_ctrl_ds_name, "ReloadConfig")
bliss_class = tango_mot_bliss_class(_ctrl_ds_name)
if (bliss_class == "-1") {
tango_mot_err(sprintf("error querying %s class", _ctrl_ds_name))
return ".error."
} else if (bliss_class == "Unknown") {
tango_mot_err(sprintf("unknown %s class", _ctrl_ds_name))
return ".error."
}
cmd = (bliss_class == "Bliss") ? "reload_config" : "ReloadConfig"
tango_io(_ctrl_ds_name, cmd)
if (TANGO_ERR != "0"){
_msg = sprintf("Cmd=ReloadConfig: controller %d (%s) ", \
unit, _ctrl_ds_name)
_msg = sprintf("Cmd=%s: controller %d (%s) ", \
cmd, unit, _ctrl_ds_name)
_tango_mot_error_desc(_msg)
return ".error."
}
......@@ -335,6 +350,8 @@ def tango_mot_config(motnum, type, unit, module, channel) '{
_mot_mne = motor_mne(motnum)
bliss_class = tango_mot_bliss_class(_ctrl_ds_name)
# Always include the "in_config" internal flag
motor_par(motnum, "in_config", 0, "add")
......@@ -381,6 +398,7 @@ def tango_mot_config(motnum, type, unit, module, channel) '{
# Store the BlissAxis master DS name for future refs
motor_par(motnum, "bliss_axis_master_ds", _ctrl_ds_name, "add")
motor_par(motnum, "bliss_axis_master_class", bliss_class, "add")
motor_par(motnum, "dev_name", _axis_ds_name, "add")
# On a reconfig, restores config value of axis (no_reload=1).
......@@ -522,6 +540,36 @@ def tango_mot_config(motnum, type, unit, module, channel) '{
}'
#%IU% (ctrl_dev)
#%MDESC% \
# Returns Tango server class, either Bliss or BlissAxisManager \
#%DL% \
#%UL% \
#%LI%<ctrl_dev> : Controller Tango device name \
#%XUL%
def tango_mot_bliss_class(ctrl_dev) '{
local ret out_str cmd_str aux_file
if (unix("mktemp --tmpdir spec_tango_mod.XXXXXX", aux_file) != 0)
return -1
aux_file = substr(aux_file, 1, length(aux_file) - 1)
on(aux_file); offt
TANGO_ERR = "-1"
ret = tango_io(ctrl_dev, "?")
ont; close(aux_file)
cmd_str = sprintf("cat %s; rm -f %s", aux_file, aux_file)
unix(cmd_str, out_str)
if (ret < 0)
return -1
if (index(out_str, "axis_group_move") > 0)
return "Bliss"
if (index(out_str, "GroupMove") > 0)
return "BlissAxisManager"
return "Unknown"
}'
#%IU% (motnum, key, action, p1, p2)
#%MDESC% \
# The hmacmot_par function is called when various motor parameters are set %BR% \
......@@ -1014,13 +1062,14 @@ def tango_mot_reset_motion(ctrl_dev) '{
global TANGO_MOT_CTRL[]
TANGO_MOT_CTRL[ctrl_dev]["grpmotion"] = ""
TANGO_MOT_CTRL[ctrl_dev]["grpid"] = ""
TANGO_MOT_CTRL[ctrl_dev]["bliss_class"] = ""
}'
#%IU% (<ctrl_dev>, <motnum>, <pos>)
#%MDESC%
# Add a motion to the specified ctrl device
def tango_mot_add_motion(ctrl_dev, motnum, pos) '{
local motion axis_name mot_mne sep pos_str
local motion axis_name mot_mne sep pos_str bliss_class
motion = TANGO_MOT_CTRL[ctrl_dev]["grpmotion"]
mot_mne = motor_mne(motnum)
......@@ -1029,6 +1078,11 @@ def tango_mot_add_motion(ctrl_dev, motnum, pos) '{
pos_str = sprintf("%.20g", user(motnum, pos))
motion = sprintf("%s%s%s:%s:%s", motion, sep, mot_mne, axis_name, pos_str)
TANGO_MOT_CTRL[ctrl_dev]["grpmotion"] = motion
if (TANGO_MOT_CTRL[ctrl_dev]["bliss_class"] == "") {
bliss_class = motor_par(motnum, "bliss_axis_master_class")
TANGO_MOT_CTRL[ctrl_dev]["bliss_class"] = bliss_class
}
}'
#%IU% (<ctrl_dev>, <motnum>)
......@@ -1052,7 +1106,8 @@ def tango_mot_concerns_motion(ctrl_dev, motnum) '{
#%MDESC%
# Start a motion on the specified ctrl device
def tango_mot_start_motion(ctrl_dev) '{
local motion nb_mot grptok[] mottok[] arr_mot[] arr_in[] i j ret
local motion nb_mot grptok[] mottok[] arr_mot[] arr_in[] i j ret cmd
local bliss_class
motion = TANGO_MOT_CTRL[ctrl_dev]["grpmotion"]
nb_mot = split(motion, grptok, ",")
......@@ -1067,10 +1122,12 @@ def tango_mot_start_motion(ctrl_dev) '{
}
TANGO_ERR = -1
ret = tango_io(ctrl_dev, "GroupMove", arr_in)
bliss_class = TANGO_MOT_CTRL[ctrl_dev]["bliss_class"]
cmd = (bliss_class == "Bliss") ? "axis_group_move" : "GroupMove"
ret = tango_io(ctrl_dev, cmd, arr_in)
if (TANGO_ERR != "0") {
local _msg axis_name
_msg = sprintf("Cmd=GroupMove: %s: ", ctrl_dev)
_msg = sprintf("Cmd=%s: %s: ", cmd, ctrl_dev)
for (i = 0; i < nb_mot; i++) {
_msg = sprintf("%s%s%s", _msg, i ? "," : "", arr_mot[i])
axis_name = arr_in[i * 2]
......@@ -1090,17 +1147,19 @@ def tango_mot_start_motion(ctrl_dev) '{
#%MDESC%
# Poll motion state and record if it is finished
def tango_mot_check_motion(ctrl_dev) '{
local motionid arr_out[] ret
local motionid arr_out[] ret cmd bliss_class
motionid = TANGO_MOT_CTRL[ctrl_dev]["grpid"]
if (!motionid)
return
TANGO_ERR = -1
ret = tango_io(ctrl_dev, "GroupState", motionid, arr_out)
bliss_class = TANGO_MOT_CTRL[ctrl_dev]["bliss_class"]
cmd = (bliss_class == "Bliss") ? "axis_group_state" : "GroupState"
ret = tango_io(ctrl_dev, cmd, motionid, arr_out)
if (TANGO_ERR != "0") {
local _msg
_msg = sprintf("Cmd=GroupState: %s: ", ctrl_dev)
_msg = sprintf("Cmd=%s: %s: ", cmd, ctrl_dev)
_tango_mot_error_desc(sprintf("%s: %s", _msg, motionid))
} else if (ret == 0) {
tango_mot_reset_motion(ctrl_dev)
......@@ -1111,17 +1170,19 @@ def tango_mot_check_motion(ctrl_dev) '{
#%MDESC%
# Abort motion
def tango_mot_abort_motion(ctrl_dev) '{
local motionid ret
local motionid ret cmd bliss_class
motionid = TANGO_MOT_CTRL[ctrl_dev]["grpid"]
if (!motionid)
return
TANGO_ERR = -1
ret = tango_io(ctrl_dev, "GroupAbort", motionid)
bliss_class = TANGO_MOT_CTRL[ctrl_dev]["bliss_class"]
cmd = (bliss_class == "Bliss") ? "axis_group_abort" : "GroupAbort"
ret = tango_io(ctrl_dev, cmd, motionid)
if (TANGO_ERR != "0") {
local _msg
_msg = sprintf("Cmd=GroupAbort: %s: ", ctrl_dev)
_msg = sprintf("Cmd=%s: %s: ", ctrl_dev)
_tango_mot_error_desc(sprintf("%s: %s", _msg, motionid))
}
}'
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment