#!/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 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"',), } tplYaml='''\ cpu_architecture: {os} os: {os} os_id: {os} epics_version: 7.0.7 ioc_host: {host} ioc_port: {port} ''' ################################################################## # DO NOT EDIT: Generated with epics_ioc_modules/OATT/generate.py # This is the IOC on "{host}" port {port}: ################################################################## tplScriptPowerBrickIOC='''\ ##################################### # PPMAC responsible: Thierry Zamofing ##################################### {req} ############################################ #------! Common PPMAC configuration !------# ############################################ # Load common configuration require PB_COMMON # Define controller #powerPmacCreateController(, , ) 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" ''' class CPPM: def __init__(self): pass def genIOC(self): print('### genIOC ###') tpl=tplScriptPowerBrickIOC os.makedirs('gen/ioc/',exist_ok=True) #os.makedirs('gen/db/',exist_ok=True) fh=open('gen/ioc/Makefile','w') fh.write('include /ioc/tools/ioc.makefile\n') fh.close() port=50001 osys='eldk42-ppc4xxFP' for host,v in host2param.items(): devConf,=v req='' fn='gen/ioc/{host}_startup.script'.format(host=host) print('generate '+fn+'...') fh=open(fn,'w') fh.write(tpl.format(host=host,port=port,req=req,devConf=devConf)) if host=='SAR-CPPM-EXPMX1': fh.write(tplEVR) fh.close() fn='gen/ioc/{host}_parameters.yaml'.format(host=host) print('generate '+fn+'...') fh=open(fn,'w') fh.write(tplYaml.format(os=osys,host=host,port=port)) 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() 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=CPPM() if args.mode&0x1: obj.genIOC() if args.mode&0x2: obj.genLauncher() parse_args()