247 lines
9.1 KiB
Python
Executable File
247 lines
9.1 KiB
Python
Executable File
#!/usr/bin/env python
|
|
#*-----------------------------------------------------------------------*
|
|
#| |
|
|
#| Copyright (c) 2019 by Paul Scherrer Institute (http://www.psi.ch) |
|
|
#| |
|
|
#| Author Thierry Zamofing (thierry.zamofing@psi.ch) |
|
|
#*-----------------------------------------------------------------------*
|
|
'''
|
|
generate .subs and _startup.script files
|
|
mode bits:
|
|
0x001: genIOC()
|
|
0x008: genLauncher()
|
|
|
|
Long Doc'''
|
|
from __future__ import print_function
|
|
|
|
import logging, sys, os, json
|
|
import string
|
|
|
|
class Generate:
|
|
yamlParam={
|
|
# ioc : ( host , port , ver , arch , osys , osys_id ,
|
|
# 'SAR-CSSU-EXPMX1' : ('SAR-CSSU-EXPMX1' , 50001 , '3.14.12' , 'moxa42-armv6l' , 'moxa42-armv6l' , 'moxa42-armv6l' , ) ,
|
|
'SAR-CPPM-EXPMX1' : ('SAR-CPPM-EXPMX1' , 50001 , '7.0.7' , 'eldk42-ppc4xxFP' , 'eldk42-ppc4xxFP' , 'eldk42-ppc4xxFP' , ) ,
|
|
'SAR-CPPM-EXPMX2' : ('SAR-CPPM-EXPMX2' , 50001 , '7.0.7' , 'eldk42-ppc4xxFP' , 'eldk42-ppc4xxFP' , 'eldk42-ppc4xxFP' , ) ,
|
|
'SAR-CPPM-EXPMX3' : ('SAR-CPPM-EXPMX3' , 50001 , '7.0.7' , 'eldk42-ppc4xxFP' , 'eldk42-ppc4xxFP' , 'eldk42-ppc4xxFP' , ) ,
|
|
'SAR-CPPM-EXPMX4' : ('SAR-CPPM-EXPMX4' , 50001 , '7.0.7' , 'eldk42-ppc4xxFP' , 'eldk42-ppc4xxFP' , 'eldk42-ppc4xxFP' , ) ,
|
|
'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' ) ,
|
|
),
|
|
}
|
|
|
|
pb_host2param={
|
|
# 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"',),
|
|
}
|
|
|
|
tplYaml='''\
|
|
ioc_host: {host}
|
|
ioc_port: {port}
|
|
epics_version: {ver}
|
|
cpu_architecture: {arch}
|
|
os: {osys}
|
|
os_id: {osys_id}
|
|
'''
|
|
|
|
lutSensMcs={'S':0, 'SR':1, 'SP':2, 'SC':3, 'SR20':4, 'M':5, 'SD':6, 'SR2':7, 'MD':8, 'SC500':9, 'User Def':10,
|
|
'None':11, 'LC':12, 'L':13}
|
|
|
|
tplMcsCtrl='''\
|
|
epicsEnvSet("ENGINEER", "T. Zamofing (zamofing_t)")
|
|
epicsEnvSet("LOCATION", "0.Z553.58")
|
|
|
|
#load module
|
|
# motorSmarAct community driver
|
|
# smarActMot PSI templates and other files
|
|
require motorSmarAct zamofing_t
|
|
#require motorSmarAct
|
|
require smarActMot
|
|
# -------------
|
|
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)
|
|
'''
|
|
|
|
tplMcsAxis='''\
|
|
smarActMCSCreateAxis({port}, {axis}, {chan})
|
|
'''
|
|
|
|
mcs_subs_hdr='''\
|
|
file asyn.template {{{{P={prefix}, PORT=asyn{port}}}}}
|
|
|
|
##### MCS
|
|
file $(smarActMot_DIR)/db/MCS_axis.template
|
|
{{
|
|
pattern
|
|
{{PORT ,S ,M ,ADDR,DESC ,DIR,VBAS,VMAX,DHLM,DLLM,EGU,SENSOR ,UDSENS,RTRY}}
|
|
'''
|
|
|
|
tplScriptPowerBrickIOC='''\
|
|
##########################################
|
|
# DO NOT EDIT: Generated with generate.py
|
|
# This is the IOC on host {host}
|
|
##########################################
|
|
# PPMAC responsible: Thierry Zamofing
|
|
##########################################
|
|
{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)
|
|
|
|
############################################
|
|
#--------! Devices configuration ---------!#
|
|
############################################
|
|
{devConf}
|
|
'''
|
|
|
|
tplEVR='''\
|
|
####### initialise 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 ##################
|
|
# 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"
|
|
'''
|
|
|
|
def __init__(self):
|
|
os.makedirs('gen/ioc/',exist_ok=True)
|
|
#os.makedirs('gen/db/',exist_ok=True)
|
|
|
|
def genYAML(self):
|
|
|
|
for ioc,p in self.yamlParam.items():
|
|
param=dict(zip(('host','port','ver','arch','osys','osys_id',),p))
|
|
fn=f'gen/ioc/{ioc}_parameters.yaml'
|
|
print('generate '+fn+' ...')
|
|
fh=open(fn,'w')
|
|
fh.write(self.tplYaml.format(**param))
|
|
fh.close()
|
|
print('done.')
|
|
|
|
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()
|
|
print('done.')
|
|
|
|
def genLauncher(self):
|
|
print('### genLauncher ###')
|
|
|
|
# os.makedirs('gen/',exist_ok=True)
|
|
# fn='gen/launcher_part.json'
|
|
# print('generate '+fn+'...')
|
|
# fh=open(fn,'w')
|
|
# for dev,ioc in dev2ioc.items():
|
|
# fh.write('''\
|
|
#{{ "type": "caqtdm" , "text": "{dev} translation", "panel": "galil_dmc_ctrl.ui", "macros": "DMC={dev}_DMC1:,M1=TX" }},
|
|
#'''.format(dev=dev))
|
|
# fh.close()
|
|
|
|
def genSmarActIOC(self,ioc):
|
|
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']
|
|
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))
|
|
|
|
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')
|
|
|
|
|
|
|
|
|
|
if __name__=='__main__':
|
|
def parse_args():
|
|
import argparse
|
|
(h, t)=os.path.split(sys.argv[0]);cmd='\n '+(t if len(h)>20 else sys.argv[0])+' '
|
|
#print(sys.argv,h,t)
|
|
exampleCmd=('', '-m0xf -v0' )
|
|
epilog=__doc__+'\nExamples:'+''.join(map(lambda s:cmd+s, exampleCmd))+'\n'
|
|
|
|
parser = argparse.ArgumentParser(epilog=epilog,formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
parser.add_argument('-m', '--mode', type=lambda x: int(x,0), help='mode bits', default=0xff)
|
|
args = parser.parse_args()
|
|
#print(args)
|
|
|
|
obj=Generate()
|
|
if args.mode&0x1:
|
|
obj.genYAML()
|
|
if args.mode&0x2:
|
|
obj.genIOC()
|
|
if args.mode&0x4:
|
|
obj.genLauncher()
|
|
|
|
parse_args()
|
|
|