enhance generate.py

This commit is contained in:
2023-07-21 18:43:00 +02:00
parent de7285d542
commit c4b5891b29
14 changed files with 275 additions and 270 deletions

View File

@@ -8,8 +8,9 @@
'''
generate .subs and _startup.script files
mode bits:
0x001: genIOC()
0x008: genLauncher()
0x001: genYAML()
0x002: genIOC()
0x004: genLauncher()
Long Doc'''
from __future__ import print_function
@@ -28,36 +29,107 @@ class Generate:
'SARES30-CPCL-MCSSMX' : ('saresc-softioc-11' , 50001 , '7.0.6' , 'x86_64' , 'RHEL7' , 'rhel' , ) ,
}
mxSmarAct={
'port':'MCS',
'host':'129.129.244.32',
'prefix':'SARES30-SMX',
'motLst':(
# description , PV name , axis , hlm , llm , dir , sens ,
('COLLI:TX' , 'MCS1' , 0 , 12 , -10 , 1 , 'S' ) ,
('COLLI:TY' , 'MCS2' , 1 , 12 , -10 , 1 , 'S' ) ,
('Motor3' , 'MCS3' , 2 , 10 , -10 , 0 , 'S' ) ,
('POSTTUBE:TX1' , 'MCS4' , 3 , 10 , -10 , 0 , 'S' ) ,
('POSTTUBE:TX2' , 'MCS5' , 4 , 10 , -10 , 0 , 'S' ) ,
('POSTTUBE:TY1' , 'MCS6' , 5 , 15 , -20 , 0 , 'S' ) ,
('POSTTUBE:TY2' , 'MCS7' , 6 , 15 , -20 , 0 , 'S' ) ,
('POSTTUBE:TZ' , 'MCS8' , 7 , 10 , -10 , 1 , 'S' ) ,
('Motor9' , 'MCS9' , 8 , 10 , -10 , 0 , 'S' ) ,
('SLITS:X1' , 'MCS10' , 9 , 10 , -10 , 1 , 'S' ) ,
('SLITS:X2' , 'MCS11' , 10 , 10 , -10 , 1 , 'S' ) ,
('SLITS:Y1' , 'MCS12' , 11 , 10 , -10 , 1 , 'S' ) ,
('SLITS:Y2' , 'MCS13' , 12 , 10 , -10 , 1 , 'S' ) ,
('XEYE:TX' , 'MCS14' , 13 , 10 , -10 , 0 , 'S' ) ,
('XEYE:TY' , 'MCS15' , 14 , 10 , -10 , 0 , 'S' ) ,
),
iocSmarAct={
'SARES30-CPCL-MCSSMX':
{
'port':'MCS',
'host':'129.129.244.32', # 00:04:a3:a2:71:35, MCS0060 Serial: 3762
'prefix':'SARES30-SMX',
'loc':'EH.057 MobRack',
'motLst':(
# description , PV name , axis , hlm , llm , dir , egu , sens ,
('COLLI:TX' , 'MCS1' , 0 , 12 , -10 , 1 , 'mm' , 'S' ) ,
('COLLI:TY' , 'MCS2' , 1 , 12 , -10 , 1 , 'mm' , 'S' ) ,
('Motor3' , 'MCS3' , 2 , 10 , -10 , 0 , 'mm' , 'S' ) ,
('POSTTUBE:TX1' , 'MCS4' , 3 , 10 , -10 , 0 , 'mm' , 'S' ) ,
('POSTTUBE:TX2' , 'MCS5' , 4 , 10 , -10 , 0 , 'mm' , 'S' ) ,
('POSTTUBE:TY1' , 'MCS6' , 5 , 15 , -20 , 0 , 'mm' , 'S' ) ,
('POSTTUBE:TY2' , 'MCS7' , 6 , 15 , -20 , 0 , 'mm' , 'S' ) ,
('POSTTUBE:TZ' , 'MCS8' , 7 , 10 , -10 , 1 , 'mm' , 'S' ) ,
('Motor9' , 'MCS9' , 8 , 10 , -10 , 0 , 'mm' , 'S' ) ,
('SLITS:X1' , 'MCS10' , 9 , 10 , -10 , 1 , 'mm' , 'S' ) ,
('SLITS:X2' , 'MCS11' , 10 , 10 , -10 , 1 , 'mm' , 'S' ) ,
('SLITS:Y1' , 'MCS12' , 11 , 10 , -10 , 1 , 'mm' , 'S' ) ,
('SLITS:Y2' , 'MCS13' , 12 , 10 , -10 , 1 , 'mm' , 'S' ) ,
('XEYE:TX' , 'MCS14' , 13 , 10 , -10 , 0 , 'mm' , 'S' ) ,
('XEYE:TY' , 'MCS15' , 14 , 10 , -10 , 0 , 'mm' , 'S' ) ,
),
}
}
pb_host2param={
iocPowerBrick={
# HOST runScript
'SAR-CPPM-EXPMX1':('','require ESB_MX\nrunScript $(ESB_MX_DIR)/add_EXPMX1.cmd "P=SAR-EXPMX,PORT=PPMAC1"',),
'SAR-CPPM-EXPMX2':('','require ESB_MX\nrunScript $(ESB_MX_DIR)/add_EXPMX2.cmd "P=SAR-EXPMX,PORT=PPMAC1"',),
'SAR-CPPM-EXPMX3':('','require ESB_MX\nrunScript $(ESB_MX_DIR)/add_EXPMX3.cmd "P=SAR-EXPMX,PORT=PPMAC1"',),
'SAR-CPPM-EXPMX4':('','require ESB_MX\nrunScript $(ESB_MX_DIR)/add_EXPMX4.cmd "P=SAR-EXPMX,PORT=PPMAC1"',),
'SAR-CPPM-EXPMX1':{
'port':'PPMAC',
'prefix':'SAR-EXPMX',
'loc':'EH.057 MobRack',
'fmt':
'{{{P:10},{M:10},{ADDR:4},{DESC:19},{DIR:3},{VELO:4},{HVEL:4},{MRES:5},{PREC:4},{EGU:4}}}\n',
'motLst':(
( 'DESC' , 'M' , 'ADDR' , 'DIR' , 'VELO' , 'HVEL' , 'MRES' , 'PREC' , 'EGU' ) ,
( '"Sample F-Trans Y"' , 'MOT_FY' , 1 , 0 , 16 , 2 , 0.001 , 4 , 'mm' ) ,
( '"Sample F-Trans X"' , 'MOT_FX' , 2 , 1 , 16 , 2 , 0.001 , 4 , 'mm' ) ,
( '"Rotation Y"' , 'MOT_ROT_Y' , 3 , 0 , 50 , 50 , 0.001 , 4 , 'deg' ) ,
( '"Sample C-Trans X"' , 'MOT_CX' , 4 , 1 , 2 , 2 , 0.001 , 4 , 'mm' ) ,
( '"Sample C-Trans Z"' , 'MOT_CZ' , 5 , 1 , 2 , 2 , 0.001 , 4 , 'mm' ) ,
( '"Interfero Y"' , 'ENC_FY' , 6 , 0 , 2 , 2 , 0.001 , 4 , 'mm' ) ,
( '"Interfero X"' , 'ENC_FX' , 7 , 0 , 2 , 2 , 0.001 , 4 , 'mm' ) ,
),
},
'SAR-CPPM-EXPMX2':{
'port':'PPMAC',
'prefix':'SAR-EXPMX',
'loc':'EH.057 MobRack',
'fmt':
'{{{P:10},{M:10},{ADDR:4},{DESC:12},{DIR:3},{VELO:4},{HVEL:4},{MRES:5},{PREC:4},{EGU:4}}}\n',
'motLst':(
( 'DESC' , 'M' , 'ADDR' , 'DIR' , 'VELO' , 'HVEL' , 'MRES' , 'PREC' , 'EGU' ) ,
( '"Wedge 1"' , 'MOT_WEDGE1' , 1 , 0 , 1. , .5 , 0.001 , 3 , 'mm' ) ,
( '"Wedge 2"' , 'MOT_WEDGE2' , 2 , 0 , 1. , .5 , 0.001 , 3 , 'mm' ) ,
( '"Wedge 3"' , 'MOT_WEDGE3' , 3 , 0 , 1. , .5 , 0.001 , 3 , 'mm' ) ,
( '"Wedge 4"' , 'MOT_WEDGE4' , 4 , 0 , 1. , .5 , 0.001 , 3 , 'mm' ) ,
( '"Wedge X"' , 'MOT_WEDGEX' , 9 , 1 , 1. , .5 , 0.001 , 3 , 'mm' ) ,
( '"Wedge Y"' , 'MOT_WEDGEY' , 10 , 0 , 1. , .5 , 0.001 , 3 , 'mm' ) ,
( '"Wedge A"' , 'MOT_WEDGEA' , 11 , 0 , 1. , .5 , 0.001 , 3 , 'mm' ) ,
( '"Wedge B"' , 'MOT_WEDGEB' , 12 , 1 , 1. , .5 , 0.001 , 3 , 'mm' ) ,
( '"Backlight"' , 'MOT_BLGT' , 5 , 1 , 40E3 , 20E3 , 1 , 0 , 'usr' ) ,
( '"Cryojet"' , 'MOT_CRYO' , 6 , 1 , 10. , 5. , 0.001 , 3 , 'mm' ) ,
),
},
'SAR-CPPM-EXPMX3':{
'port':'PPMAC',
'prefix':'SAR-EXPMX',
'loc':'EH.057 MobRack',
'fmt':
'{{{P:10},{M:10},{ADDR:4},{DESC:13},{DIR:3},{VELO:4},{MRES:5},{PREC:4},{EGU:4}}}\n',
'motLst':(
( 'DESC' , 'M' , 'ADDR' , 'DIR' , 'VELO' , 'MRES' , 'PREC' , 'EGU' ) ,
( '"Girder 1"' , 'MOT_GIR_1' , 1 , 0 , 40 , 0.001 , 3 , 'deg' ) ,
( '"Girder 2"' , 'MOT_GIR_2' , 2 , 0 , 40 , 0.001 , 3 , 'deg' ) ,
( '"Girder 3"' , 'MOT_GIR_3' , 3 , 0 , 40 , 0.001 , 3 , 'deg' ) ,
( '"Girder 4"' , 'MOT_GIR_4' , 4 , 0 , 40 , 0.001 , 3 , 'deg' ) ,
( '"Girder 5"' , 'MOT_GIR_5' , 5 , 0 , 40 , 0.001 , 3 , 'deg' ) ,
( '"Girder X"' , 'MOT_GIR_X' , 9 , 0 , 40 , 0.001 , 3 , 'mm' ) ,
( '"Girder Y"' , 'MOT_GIR_Y' , 10 , 0 , 40 , 0.001 , 3 , 'mm' ) ,
( '"Girder U"' , 'MOT_GIR_U' , 11 , 0 , 40 , 0.001 , 3 , 'mrad' ) ,
( '"Girder V"' , 'MOT_GIR_V' , 12 , 0 , 40 , 0.001 , 3 , 'mrad' ) ,
( '"Girder W"' , 'MOT_GIR_W' , 13 , 0 , 40 , 0.001 , 3 , 'mrad' ) ,
( '"Detector Z"' , 'MOT_DET_Z' , 6 , 1 , 4 , 0.001 , 3 , 'mm' ) ,
),
},
'SAR-CPPM-EXPMX4':{
'port':'PPMAC',
'prefix':'SAR-EXPMX',
'loc':'EH.057 MobRack',
'fmt':
'{{{P:10},{M:10},{ADDR:4},{DESC:27},{DIR:3},{VELO:4},{MRES:5},{PREC:4},{EGU:4}}}\n',
'motLst':(
('DESC', 'M', 'ADDR', 'DIR', 'VELO', 'MRES', 'PREC', 'EGU'),
# desc , m , addr , dir , velo , hvel , accl , jar , mres , prec , egu , dhlm , dllm ,
# NOT YET ANY MOTOR
),
},
}
tplYaml='''\
@@ -73,26 +145,34 @@ os_id: {osys_id}
'None':11, 'LC':12, 'L':13}
tplMcsCtrl='''\
epicsEnvSet("ENGINEER", "T. Zamofing (zamofing_t)")
epicsEnvSet("LOCATION", "0.Z553.58")
###################################################################
# DO NOT EDIT: Generated with epics_ioc_modules/ESB_MX/generate.py
# This is the IOC {ioc} on {ioc_host}:{ioc_port}
##################################################################
#load module
epicsEnvSet("ENGINEER", "T. Zamofing (zamofing_t)")
epicsEnvSet("LOCATION", "{loc}")
###### require modules ############
# motorSmarAct community driver
# smarActMot PSI templates and other files
require motorSmarAct zamofing_t
#require motorSmarAct
require motorSmarAct
require smarActMot
# -------------
require ESB_MX
###### initialize device ############
drvAsynIPPortConfigure("asyn{port}", "{host}:5000", 0, 0, 0)
# PORT, MCS_PORT, number of axes, active poll period (sec), idle poll period (sec)
smarActMCSCreateController("{port}", "asyn{port}", {num_ax}, 0.1, 1.0)
###### initialize axes ############
'''
tplMcsAxis='''\
smarActMCSCreateAxis({port}, {axis}, {chan})
'''
mcs_subs_hdr='''\
mcsSubsHdr='''\
file asyn.template {{{{P={prefix}, PORT=asyn{port}}}}}
##### MCS
@@ -102,43 +182,49 @@ file $(smarActMot_DIR)/db/MCS_axis.template
{{PORT ,S ,M ,ADDR,DESC ,DIR,VBAS,VMAX,DHLM,DLLM,EGU,SENSOR ,UDSENS,RTRY}}
'''
tplScriptPowerBrickIOC='''\
tplPwrBrkCtrl='''\
##########################################
# DO NOT EDIT: Generated with generate.py
# This is the IOC on host {host}
# This is the IOC on host {ioc}
##########################################
# PPMAC responsible: Thierry Zamofing
##########################################
###### initialize device ############
require PB_COMMON
{req}
############################################
#------! Common PPMAC configuration !------#
############################################
# Load common configuration
require PB_COMMON
# Define controller
#powerPmacCreateController(<port_name>, <moving_poll_pseriod [ms]>, <idle_poll_period [ms]>)
powerPmacCreateController("PPMAC1", 200, 1000)
powerPmacCreateController("{port}", 200, 1000)
############################################
#--------! Devices configuration ---------!#
############################################
{devConf}
###### initialize axes ############
'''
tplEVR='''\
####### initialise EVR ##############################
tplPwrBrkAxis='''\
powerPmacCreateAxis({PORT}, {ADDR})
'''
tplEVR='''
###### initialize EVR ############
# https://git.psi.ch/epics_driver_modules/mrfioc2
require mrfioc2
runScript $(mrfioc2_DIR)/mrfioc2_evr-PCIe.cmd, "DEVICE=EVR0,EVR_SUBS=$(ESB_MX_DIR)/db/evr_PCIe-300DC.subs,EVR_DOMAIN=0x2,EVR_BUS=0x21,SYS=SAR-EXPMX"
####### initialise EVR data buffer ##################
###### initialize EVR data buffer ############
# https://git.psi.ch/epics_driver_modules/mrfioc2_regDev
require mrfioc2_regDev
runScript $(mrfioc2_regDev_DIR)/mrfioc2_regDev_pulseID_RX.cmd, "DEVICE=EVR0,SYS=SAR-EXPMX"
'''
pwrBrkSubsHdr='''\
file asyn.template {{{{P={prefix}, PORT={port},R=asyn{idx}}}}}
file PPMACMotor.template
{{
pattern
'''
def __init__(self):
os.makedirs('gen/ioc/',exist_ok=True)
#os.makedirs('gen/db/',exist_ok=True)
@@ -156,26 +242,14 @@ runScript $(mrfioc2_regDev_DIR)/mrfioc2_regDev_pulseID_RX.cmd, "DEVICE=EVR0,SYS=
def genIOC(self):
print('### genIOC ###')
tplIOC=Generate.tplScriptPowerBrickIOC
yamlParam=Generate.yamlParam
pb_h2p=Generate.pb_host2param
tplEVR=Generate.tplEVR
fh=open('gen/ioc/Makefile','w')
fh.write('include /ioc/tools/ioc.makefile\n')
fh.close()
for host in yamlParam.keys():
if not host in pb_h2p:
assert(host=='SARES30-CPCL-MCSSMX')
self.genSmarActIOC(host)
continue
req,devConf=pb_h2p[host]
fn='gen/ioc/{host}_startup.script'.format(host=host)
print('generate '+fn+' ...')
fh=open(fn,'w')
fh.write(tplIOC.format(host=host,req=req,devConf=devConf))
if host=='SAR-CPPM-EXPMX1':
fh.write(tplEVR)
fh.close()
fn='gen/ioc/Makefile'
print('generate '+fn+' ...')
with open(fn,'w') as fh:
fh.write('include /ioc/tools/ioc.makefile\n')
self.genPowerBrickIOC()
self.genSmarActIOC()
print('done.')
def genLauncher(self):
@@ -191,35 +265,125 @@ runScript $(mrfioc2_regDev_DIR)/mrfioc2_regDev_pulseID_RX.cmd, "DEVICE=EVR0,SYS=
#'''.format(dev=dev))
# fh.close()
def genSmarActIOC(self,ioc):
def genPowerBrickIOC(self):
yamlParam=Generate.yamlParam
tplEVR=Generate.tplEVR
tplCtrl=Generate.tplPwrBrkCtrl
tplAxis=Generate.tplPwrBrkAxis
#tplAxSR=Generate.tplMcsAxisSaveRestore
subsHdr=Generate.pwrBrkSubsHdr
for ioc,v in Generate.iocPowerBrick.items():
# fh_ss startup script
# fh_sb substitution
# fh_sr save restore
fmt=' '+v['fmt']
hdr=v['motLst'][0]
if len(v['motLst'])>1:
motLst=v['motLst'][1:]
else:
motLst=tuple()
param= {k: v[k] for k in {'port','prefix','loc'}}
param['ioc']=ioc
param['idx']=ioc[-1]
param['num_ax']=len(motLst)
param['req']='require ESB_MX\n\n! $(gpasciiCommander_DIR)/gpasciiCommander --path $(ESB_MX_DIR) $(ESB_MX_DIR)/{prefix}{idx}.cfg'.format(**param)
#print(param)
fn=f'gen/ioc/{ioc}_startup.script'
print('generate '+fn+' ...')
fh_ss=open(fn,'w')
fn=f'gen/ioc/{ioc}_gen.subs' # with a name _* the .subs file is recognize by the 'ioc install' tool
print('generate '+fn+' ...')
fh_sb=open(fn,'w')
#fn=f'gen/ioc/cfg/{ioc}_sr.req'
#print('generate '+fn+' ...')
#fh_sr=open(fn,'w')
fh_ss.write(tplCtrl.format(**param))
fh_sb.write(subsHdr.format(**param))
port=param['port']
prefix=param['prefix']
motPar=dict(zip(hdr, hdr))
motPar['PORT']='PORT'
motPar['P']='P'
fh_sb.write(fmt.format(**motPar))
for motPar in motLst:
motPar=dict(zip(hdr, motPar))
motPar['PORT']=v['port']
motPar['P']=v['prefix']
fh_sb.write(fmt.format(**motPar))
fh_ss.write(tplAxis.format(**motPar))
#fh_sr.write(tplAxSR.format(prefix=prefix,m=m))
fh_sb.write('}\n\n')
if ioc=='SAR-CPPM-EXPMX1':
fh_ss.write(tplEVR)
fh_ss.close()
fh_sb.close()
def genSmarActIOC(self):
tplCtrl=Generate.tplMcsCtrl
tplAxis=Generate.tplMcsAxis
motLst=Generate.mxSmarAct['motLst']
subs=Generate.mcs_subs_hdr
host=Generate.mxSmarAct['host']
prefix=Generate.mxSmarAct['prefix']
port=Generate.mxSmarAct['port']
#tplAxSR=Generate.tplMcsAxisSaveRestore
subsHdr=Generate.mcsSubsHdr
lutSens=Generate.lutSensMcs
num_ax=len(motLst)
fn=f'gen/ioc/{ioc}_startup.script'
print('generate '+fn+' ...')
with open(fn,'w') as fh_ss:
fh_ss.write(tplCtrl.format(host=host,port=port,num_ax=num_ax))
os.makedirs('gen/ioc/cfg/',exist_ok=True)
for ioc,v in Generate.iocSmarAct.items():
# fh_ss startup script
# fh_sb substitution
# fh_sr save restore
fn_subs=f'gen/ioc/{ioc}_gen.subs' # with a name _* the .subs file is recognize by the 'ioc install' tool
print('generate '+fn_subs+'...')
with open(fn_subs,'w') as fh:
fh.write(subs.format(port=port,prefix=prefix))
for d, m, a, hlm, llm, dir,sens in motLst:
sens=lutSens[sens]
param={'PORT':port,'S':prefix,'M':m,'ADDR':a,'DESC':'"'+d+'"',
'DIR':dir,'VBAS':0,'VMAX':2,'DHLM':hlm,'DLLM':llm,'EGU':'mm','SENSOR':sens,'UDSENS':0,'RTRY':1}
fh.write(' {{{PORT:10},{S:16},{M:10},{ADDR:4},{DESC:27},{DIR:3},{VBAS:4},{VMAX:4},{DHLM:4},{DLLM:4},{EGU:3},{SENSOR:7},{UDSENS:5}{RTRY:5}}}\n'.format(**param))
fh_ss.write(tplAxis.format(port=port,axis=a,chan=a))
fh.write('}\n\n')
motLst=v['motLst']
param= {k: v[k] for k in {'port','host','prefix','loc'}}
ioc_host,ioc_port=Generate.yamlParam[ioc][:2]
param['ioc']=ioc
param['ioc_host']=ioc_host
param['ioc_port']=ioc_port
param['num_ax']=len(motLst)
#print(param)
fn=f'gen/ioc/{ioc}_startup.script'
print('generate '+fn+' ...')
fh_ss=open(fn,'w')
fn=f'gen/ioc/{ioc}_gen.subs' # with a name _* the .subs file is recognize by the 'ioc install' tool
print('generate '+fn+' ...')
fh_sb=open(fn,'w')
#fn=f'gen/ioc/cfg/{ioc}_sr.req'
#print('generate '+fn+' ...')
#fh_sr=open(fn,'w')
fh_ss.write(tplCtrl.format(**param))
fh_sb.write(subsHdr.format(**param))
port=param['port']
prefix=param['prefix']
for d, m, a, hlm, llm, dir,egu,sens in motLst:
sens=lutSens[sens]
param={'PORT':port,'S':prefix,'M':m,'ADDR':a,'DESC':'"'+d+'"',
'DIR':dir,'VBAS':0,'VMAX':2,'DHLM':hlm,'DLLM':llm,'EGU':egu,'SENSOR':sens,'UDSENS':0,'RTRY':1}
fh_sb.write(' {{{PORT:10},{S:16},{M:10},{ADDR:4},{DESC:27},{DIR:3},{VBAS:4},{VMAX:4},{DHLM:4},{DLLM:4},{EGU:3},{SENSOR:7},{UDSENS:5}{RTRY:5}}}\n'.format(**param))
fh_ss.write(tplAxis.format(port=port,axis=a,chan=a))
#fh_sr.write(tplAxSR.format(prefix=prefix,m=m))
fh_sb.write('}\n\n')
fh_ss.close()
fh_sb.close()
#fh_sr.close()
#fn='gen/ioc/asyn.template'
#print('generate '+fn+' ...')
#with open(fn,'w') as fh:
# fh.write(Generate.tpl_asyn)
if __name__=='__main__':
def parse_args():