#%TITLE% Macromotors_utils.mac
#%NAME%
# Some macros to handle XML manipulations for macromotors writing
#%CATEGORY% Tools
#%DESCRIPTION%
#In the following:
#%BR%- <controller> refers to the generic controller name
#%BR%<controller>.xml contains the list of equipments (instances) of that type,
#for the spec session
#%BR%- <equipment> (or module) refers to a particular instance of
#controller (ex: equipments pslit, sslit are of type slit), and is a group
#of motors (macromotors and real motors having some links between them)
#%BR%<equipment>.xml describe a particular equipment in xml format. It contains
#properties and references to motors.
#We assume that :
#%BR%- xml files for controllers and equipments are situated from the
#hardware repository location at the <spec> subdirectory.
#%BR%- xml files for motors are situated from the hardware repository
#location, at the <spec>/<motors> subdirectory
#%END%
#%UU% (mne)
#%MDESC%Creates a spechw object for this motor mnemonic, and
#load the properties of the associated xml file.
#This macro reads <mne>.xml file.
#%BR%WE SUPPOSE THAT THE XML FILE ASSOCIATED IS SITUATED FROM THE
#HWR LOCATION INT THE <spec>/<motors> SUBDIRECTORY
#%BR% - returns always 0
def CreateMotor(mne)'{
local motname
motname = motor_mne(mne)
c_newObj(motname)
ret = c_loadByProp(motname,sprintf("%s/%s","motors",motname))
return(0)
}'
#%UU% (mne,prop,[val])
#%MDESC% sets or reads a property for a spechw motor object
#created with CreateMotor
#%BR% - returns the property value if reading
#%BR% - returns 0 if setting
#%BR% - returns __error__ if error
def motor_prop(mne,prop,val)'{
local trois myprop motorname mystr ind obj
dbgp "motor_prop: " \'"mne"\' " " \'"prop"\' " " \'"val"\'
trois = whatis(\'val\')
motorname = motor_mne(mne)
if (prop == "?") {
mystr = ""
obj = c_getObjName(motorname)
for (ind in @obj["local"]) {
mystr = concatstring(mystr,ind)
}
return(mystr)
}
if ( (trois & 0x08000000) == 0x08000000) {
# unset: we want to read
dbgp "...motor_prop: reading " \'"prop"\'
myprop = c_getObjProp(motorname,prop)
dbgp "...motor_prop: returns: " \'"myprop"\'
return(myprop)
}
else {
# we want to set with this value
dbgp "...motor_prop: setting " \'"prop"\' "to " \'"val"\'
c_setObjProp(motorname,prop,val)
return(0)
}
}'
#%UU%(mne)
#%MDESC% shows properties of spechw object <mne> created by CreateMotor
def ShowMotor(mne)' {
local motorname
motorname = motor_mne(mne)
c_showObj(motorname)
}'
#%UU%(controller)
#%MDESC%Creates the list of equipment for a particular
#type of macromotor controller <controller>.
#This macro does:
#%BR%- Create controller object (equipment list) from <controller>.xml file
#%BR%- Create object for each equipment appearing in that file
#(read the list of <equipment>.xml)
#%BR% Then, on each equipment object:
#%BR%- get 'macromotor' property (which is a list
#of 'role' associated to macromotors), check that everyone is in the spec config
#and is of correct macromotor type
#%BR%- get 'realmotor' property (which is a list
#of 'role' associated to real motors), and check that everyone is in the
#spec config.
#%BR%- associate each motor of these list to its equipment, inside the controller
#object.
#%BR%WE SUPPOSE THAT THE <controller>.xml and each <equipment>.xml XML FILE
#ASSOCIATED IS SITUATED FROM THE
#HWR LOCATION INT THE <spec> SUBDIRECTORY.
#%BR% - returns 0 if OK
#%BR% - returns -1 if error
def CreateEquipmentList(controller)'{
local mylist mystr ii macrorolelist realrolelist modulename
local ret
ret = c_createEquipList(controller,controller)
if (ret == -1) {
# error reading XML file
return(-1)
}
mylist = GetEquipmentList(controller)
if (mylist == __error__) {
return(-1)
}
nb = split(mylist,mystr)
for (ii=0; ii <nb; ii++) {
modulename = mystr[ii]
ret = CreateEquipment(modulename,controller)
macrorolelist = equipment_prop(modulename,"macromotor")
EquipmentRegisterMacro(modulename,macrorolelist)
realrolelist = equipment_prop(modulename,"realmotor")
EquipmentRegisterReal(modulename,realrolelist)
}
return(0)
}'
#%UU% (controller)
#%MDESC%Gets the list of equipment for a particular
#type of macromotor controller <controller>. We assume that a CreateEquipmentList has
#been performed previously on it.
#%BR% - returns a string list, or __error__ in case of error
def GetEquipmentList(controller)'{
local mylist
mylist = c_getObjProp(controller,"modules")
return(mylist)
}'
#%IU%(modulename,controller)
#%MDESC%Creates a spechw object for the equipment <modulename>, and
#load the properties of the xml file. The <controller> is the
#macromotor controller type of the equipment, this name is given in
#the spec config.
#This macro reads <modulename>.xml file
#%BR% From the xml file containing <role> and associated <hwrid> keys,
#this macro creates a spechw object whose properties are the xml
#<role> values and the associated properties values are the
#motors mnemonics extracted from the <hwrid> values representing motor names
#with their path from the hardware repository.
#%BR%WE SUPPOSE THAT THE XML FILE ASSOCIATED IS SITUATED AT THE
#HWR LOCATION.
#%BR% - returns always 0
def CreateEquipment(modulename,controller)'{
local ret
c_newObj(modulename)
c_setObjProp(modulename,"controller",controller)
# extracts the motors
ret = c_loadMotorsByRole(modulename,modulename)
ret = c_loadByProp(modulename,modulename)
return(0)
}'
#%UU% (controller)
#%MDESC% Shows properties of corresponding <controller> object
def ShowController(cname) '{
c_showObj(cname)
}'
#%UU% (equipment)
#%MDESC% Shows properties of corresponding <equipment> object
def ShowEquipment(cname) '{
c_showObj(cname)
}'
#%UU% (modulename,prop,[val])
#%MDESC% sets or reads a property for a spechw equipment object
#created with CreateEquipment.
#%BR%This macro can also be used on controller objects
#%BR% - returns the property value if reading
#%BR% - returns 0 if setting
#%BR% - returns __error__ if error
def equipment_prop(modulename,prop,val)'{
local trois myprop mystr ind obj
dbgp "equipment_prop: " \'"modulename"\' " " \'"prop"\' " " \'"val"\'
if (prop == "?") {
mystr = "getkeyof"
obj = c_getObjName(modulename)
for (ind in @obj["local"]) {
mystr = concatstring(mystr,ind)
}
return(mystr)
}
if (prop == "getkeyof") {
# particular case: we give val, which is the value
# we are trying to find the key of:
myprop = c_getObjKey(modulename,val)
return(myprop)
}
trois = whatis(\'val\')
if ( (trois & 0x08000000) == 0x08000000) {
# unset: we want to read
dbgp "...equipment_prop: reading " \'"prop"\'
myprop = c_getObjProp(modulename,prop)
dbgp "...equipment_prop: returns: " \'"myprop"\'
return(myprop)
}
else {
# we want to set with this value
dbgp "...equipment_prop: setting " \'"prop"\' "to " \'"val"\'
c_setObjProp(modulename,prop,val)
return(0)
}
}'
#%IU% (modulename, string_list)
#%MDESC% For an equipment <modulename> already created with
#CreateEquipment macro,
#this macro gets every name of the <string_list> (each is supposed to
#be a <role> associated to a motor name). It
#does the following things:
#%BR% - the name is supposed to be a <role> of the equipment
#(see CreateEquipment above) or equivallent: key associated to a motor mnemonic
#%BR% - the associated motor appears in the spec config,
#as a macromotor of correct macromotor type:
#in case of problem, a significant message is printed.
#%BR% - associate to this motor its <modulename> equipment,
#in order to identify later, with GetEquipment macro, to which
#equipment it belongs.
#%BR% - returns always 0
def EquipmentRegisterMacro(modulename,string_list)'{
local myarr nb mymot controller
nb = split(string_list,myarr)
for (ii=0; ii<nb; ii++) {
if (c_hasObjProp(modulename,myarr[ii]) == 1) {
# get macro motor name
mymot = c_getObjProp(modulename,myarr[ii])
controller = c_getObjProp(modulename,"controller")
# register as macro motor (that checks its config existency)
ret = c_registerMotor(modulename,mymot,"macro",controller)
if (ret == -1) {
p modulename"("modulename") motor " mymot " not found in the config !!!"
}
else if (ret == -2) {
p modulename"("modulename") motor " mymot " is not of " controller " macromotor type !!! "
}
else if (ret == -3){
p modulename"("modulename") motor " mymot " cannot be registered as " controller
}
# define its unit container
c_setObjProp(controller,mymot,modulename)
}
}
return(0)
}'
#%IU% (modulename, string_list)
#%MDESC% For an equipment <modulename> already created with
#CreateEquipment macro,
#this macro gets every name of the <string_list> (each is supposed to
#be a <role> associated to a motor name). It
#does the following things:
#%BR% - the name is supposed to be a <role> of the equipment
#(see CreateEquipment above) or equivallent: key associated to a motor mnemonic
#%BR% - the associated motor appears in the spec config.
#in case of problem, a significant message is printed.
#%BR% - associate to this motor its <modulename> equipment,
#in order to identify later, with GetEquipment macro, to which
#equipment it belongs.
#%BR% - returns always 0
def EquipmentRegisterReal(modulename,string_list)'{
local myarr nb mymot controller
nb = split(string_list,myarr)
for (ii=0; ii<nb; ii++) {
if (c_hasObjProp(modulename,myarr[ii]) == 1) {
# get real motor name
mymot = c_getObjProp(modulename,myarr[ii])
controller = c_getObjProp(modulename,"controller")
# register as real motor (that checks its config existency)
ret = c_registerMotor(modulename,mymot,"real")
if (ret == -1) {
p modulename"("controller") motor " mymot " not found in the config "
}
# define its unit container
c_setObjProp(controller,mymot,modulename)
}
}
}'
#%UU%(motormne,controller)
#%MDESC% Checks that this motor is really expected in one of the modules
#defined for the 'controller' macrocontroller (just to see it is
#not an extra one)
#%BR%- returns the list of real motors of that equipment (list done
#by EquipmentRegisterReal) if OK.
#%BR%- returns -1 if no such list.
def EquipmentGetReal(modulename)'{
local reallist all
reallist = equipment_prop(modulename,"allrealmotor")
all = equipment_prop(modulename,"allrealmotor")
if (all == "__error__") {
all = -1
}
return (all)
}'
#%UU%(motormne,controller)
#%MDESC% Looks controller object for equipment associated to motor mnemonic <motormne>
#%BR%- returns equipment name if OK
#%BR%- returns -1 if not OK
def GetEquipment(motormne,controller)'{
local motname
motname = motor_mne(motormne)
mymodule = c_getObjProp(controller,motname)
if (mymodule == "__error__"){
mymodule = -1
}
return mymodule
}'
#%MACROS%
#%IMACROS%
#%DEPENDENCIES% XML_utils.mac XML_obj.mac
#
#%AUTHOR%
#%TOC%
|