diff --git a/FofbTool/CommandLineInterface.py b/FofbTool/CommandLineInterface.py index 9e448bffc5427681bd8bcb7443120415c01c1b63..30f1bef4e8916f461edd5770e0936663eeb7e406 100755 --- a/FofbTool/CommandLineInterface.py +++ b/FofbTool/CommandLineInterface.py @@ -16,7 +16,7 @@ if __name__ == '__main__': # Safer import: add the parent dir in path sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) import FofbTool.Utils - import FofbTool.Configuration + import FofbTool.Configuration # Still needs for one function, TODO # Get the module logger @@ -39,10 +39,25 @@ if __name__ == '__main__': parser.add_argument("--DS-conf", action="store_true", help="Applying attribute configuration on Tango Device Servers. This is required after restart of devices.") + parser.add_argument("--stop", action="store_true", + help="Stop command for the CCN and ComBPM applications blocks.") + parser.add_argument("--stop-combpm", action="store_true", + help="Stop command for the ComBPM applications blocks.") + parser.add_argument("--stop-ccn", action="store_true", + help="Stop command for the ComBPM applications blocks.") + parser.add_argument("--configure", choices=["combpm", "ccn", "comcorr", "corr", "all", "every"], nargs="+", help="Configuration commands for the Fofb applications blocs."+ " 'all' is for all com, not configuring corrector. 'every' configure everything.") + parser.add_argument("--start", action="store_true", + help="Start command for the CCN and ComBPM applications blocks.") + parser.add_argument("--start-combpm", action="store_true", + help="Start command for the ComBPM applications blocks.") + parser.add_argument("--start-ccn", action="store_true", + help="Start command for the ComBPM applications blocks.") + + args = parser.parse_args() # Set log level from args @@ -60,15 +75,26 @@ if __name__ == '__main__': if args.DS_conf: FofbTool.Utils.confds_opcua() - for conf in args.configure: - if conf in ("combpm", "all", "every"): - FofbTool.Utils.conf_all_combpm() - if conf in ("comcorr", "all", "every"): - FofbTool.Utils.conf_all_comcorr() - if conf in ("ccn", "all", "every"): - FofbTool.Utils.conf_all_ccn() - if conf in ("corr", "every"): - FofbTool.Configuration.centralnode_configure_corr() + if args.stop or args.stop_combpm: + FofbTool.Utils.stop_all_combpm() + if args.stop or args.stop_ccn: + FofbTool.Utils.stop_all_ccn() + + if not args.configure is None: + for conf in args.configure: + if conf in ("combpm", "all", "every"): + FofbTool.Utils.conf_all_combpm() + if conf in ("comcorr", "all", "every"): + FofbTool.Utils.conf_all_comcorr() + if conf in ("ccn", "all", "every"): + FofbTool.Utils.conf_all_ccn() + if conf in ("corr", "every"): + FofbTool.Configuration.centralnode_configure_corr() + + if args.start or args.start_combpm: + FofbTool.Utils.start_all_combpm() + if args.start or args.start_ccn: + FofbTool.Utils.start_all_ccn() exit(0) @@ -82,19 +108,6 @@ if __name__ == '__main__': centralnode_configure_respmat(centralnode_subscriber, args.respmat) - - if args.conf: - for cnp in cellnode_subscribers: - cellnode_configure_combpm(cnp) - cellnode_configure_comcorr(cnp, not args.disable_corr) - time.sleep(2) - cellnode_configure_ccn(cnp) - centralnode_configure_ccn(centralnode_subscriber) - centralnode_configure_corr(centralnode_subscriber) - elif args.disable_corr: - for cnp in cellnode_subscribers: - cellnode_configure_comcorr(cnp, not args.disable_corr) - if args.start: for cnp in cellnode_subscribers: cellnode_start_ccn(cnp) diff --git a/FofbTool/Configuration.py b/FofbTool/Configuration.py index 1b1f2b30ceae1d8bf993b0b459bc6e4728f18745..b46297414273acf2014c72c08d34e64e0af4d271 100755 --- a/FofbTool/Configuration.py +++ b/FofbTool/Configuration.py @@ -8,9 +8,7 @@ import tango import logging -import argparse import numpy as np -import time import FofbTool.Utils diff --git a/FofbTool/Operation.py b/FofbTool/Operation.py new file mode 100755 index 0000000000000000000000000000000000000000..a4ce10cf2122e29f287ea509fe01402ebcb5922c --- /dev/null +++ b/FofbTool/Operation.py @@ -0,0 +1,196 @@ +################################################################################################### +# OPERATION FUNCTIONS +################################################################################################### +# +# Contains functions to operate the FOFB application. +# +################################################################################################### + +import tango +import logging +import numpy as np +import time +import FofbTool.Utils + + +# Get the module logger +logger = logging.getLogger("FofbTool") + + +################################################################################################### +# OPERATIONS ON CCN +################################################################################################### + +def stop_ccn(nodename): + """ + Stop the communication with cellnode on the specified fofbnode. + + PARAMETERS + ---------- + nodename: str + The target fofbnode, ie 'cellnode-c09' or 'centralnode' + + """ + prx=FofbTool.Utils.get_prx_from_nodename(nodename) + if prx is None: + logger.error("Failed to stop CCN on {}".format(nodename)) + return + + + logger.info("Stopping CCN on {}".format(nodename)) + nint=1 + if 'central' in nodename: + nint = 4 + for n in range(nint): + prx["ccnpack{}_control".format(n)] = False + prx["ccnunpack{}_control".format(n)] = False + +def reset_ccn(nodename): + """ + Reset the communication with cellnode on the specified fofbnode. + + PARAMETERS + ---------- + nodename: str + The target fofbnode, ie 'cellnode-c09' or 'centralnode' + + """ + prx=FofbTool.Utils.get_prx_from_nodename(nodename) + if prx is None: + logger.error("Failed to reset CCN on {}".format(nodename)) + return + + logger.info("Reset CCN on {}".format(nodename)) + nint=1 + if 'central' in nodename: + nint = 4 + for n in range(nint): + prx["ccneth{}_reset".format(n)] = 0x60000001 # impossible to write 0xE0000001 + prx["ccneth{}_gt_reset".format(n)] = 1 + + time.sleep(2) + + for n in range(nint): + prx["ccneth{}_gt_reset".format(n)] = 0 + prx["ccneth{}_reset".format(n)] = 0 + + ack_ccn(nodename) + +def start_ccn(nodename): + """ + Start the communication with cellnode on the specified fofbnode. + + PARAMETERS + ---------- + nodename: str + The target fofbnode, ie 'cellnode-c09' or 'centralnode' + + """ + prx=FofbTool.Utils.get_prx_from_nodename(nodename) + if prx is None: + logger.error("Failed to start CCN on {}".format(nodename)) + return + + logger.info("Starting CCN on {}".format(nodename)) + nint=1 + if 'central' in nodename: + nint = 4 + for n in range(nint): + prx["ccnpack{}_control".format(n)] = True + prx["ccnunpack{}_control".format(n)] = True + +def ack_ccn(nodename): + """ + Start the communication with cellnode on the specified fofbnode. + + PARAMETERS + ---------- + nodename: str + The target fofbnode, ie 'cellnode-c09' or 'centralnode' + + """ + prx=FofbTool.Utils.get_prx_from_nodename(nodename) + if prx is None: + logger.error("Failed to ack CCN on {}".format(nodename)) + return + + + logger.info("Ack CCN error on {}".format(nodename)) + nint=1 + if 'central' in nodename: + nint = 4 + for n in range(nint): + prx["ccnpack{}_reset_error".format(n)] = True + prx["ccnunpack{}_reset_error".format(n)] = True + + time.sleep(1) + + for n in range(nint): + prx["ccnpack{}_reset_error".format(n)] = False + prx["ccnunpack{}_reset_error".format(n)] = False + +################################################################################################### +# OPERATIONS ON CCN +################################################################################################### + +def stop_combpm(cellnodename): + """ + Stop the communication with bpm on the specified cellnode. + + PARAMETERS + ---------- + cellnodename: str + The target fofbnode, ie 'cellnode-c09' + + """ + prx=FofbTool.Utils.get_prx_from_cellnodename(cellnodename) + if prx is None: + logger.error("Failed to stop ComBPM on {}".format(p)) + return + + logger.info("Stopping ComBPM on {}".format(cellnodename)) + prx["combpm_reset"] = 1 + prx["combpm_gt_control"] = 0x5 + +def start_combpm(cellnodename): + """ + Start the communication with bpm on the specified cellnode. + + PARAMETERS + ---------- + cellnodename: str + The target fofbnode, ie 'cellnode-c09' + + """ + prx=FofbTool.Utils.get_prx_from_cellnodename(cellnodename) + if prx is None: + logger.error("Failed to start ComBPM on {}".format(cellnodename)) + return + + logger.info("Starting ComBpm on {}".format(cellnodename)) + prx["combpm_reset"] = 0 + prx["combpm_gt_control"] = 0x1 + time.sleep(1) + ack_combpm(cellnodename) + + +def ack_combpm(cellnodename): + """ + Ack errors on the communication with bpm on the specified cellnode. + + PARAMETERS + ---------- + cellnodename: str + The target fofbnode, ie 'cellnode-c09' + + """ + prx=FofbTool.Utils.get_prx_from_cellnodename(cellnodename) + if prx is None: + logger.error("Failed to start ComBPM on {}".format(cellnodename)) + return + + logger.info("Ack ComBpm on {}".format(cellnodename)) + prx["combpm_reset_error"] = True + time.sleep(1) + prx["combpm_reset_error"] = False + diff --git a/FofbTool/Utils.py b/FofbTool/Utils.py index 02237b8027f2b3eb79915f1406ce62ee2c6fb7f8..1e40081c6e7f46464032d25e8ae7834f6d34d221 100644 --- a/FofbTool/Utils.py +++ b/FofbTool/Utils.py @@ -9,6 +9,8 @@ import tango import logging import FofbTool.DeviceAttributeConfiguration +import FofbTool.Configuration +import FofbTool.Operation # Get the module logger logger = logging.getLogger("FofbTool") @@ -181,3 +183,115 @@ def conf_all_ccn(): return success +def get_prx_from_nodename(nodename): + """ + Return a tango.DeviceProxy from a node name. + On failure, log error and return None. + + PARAMETERS + ---------- + nodename: str + The target fofbnode, ie 'cellnode-c09' or 'centralnode' + + RETURN + ------ + prx: tango.DeviceProxy or None + """ + # Get device proxy + try: + p = FofbTool.Utils.tangopath_nodes[nodename.lower()] + except KeyError: + logger.error("Wrong nodename. Possibilities are {}".format(FofbTool.Utils.tangopath_nodes.keys())) + return None + + try: + prx= tango.DeviceProxy(p) + except tango.DevFailed as e: + logger.error("Failed to get the Device proxy to '{}'".format(p)) + logger.debug(str(e)) + return None + + return prx + + + +def get_prx_from_cellnodename(cellnodename): + """ + Return a tango.DeviceProxy from a cellnode name. + On failure, log error and return None. + + PARAMETERS + ---------- + nodename: str + The target fofbnode, ie 'cellnode-c09' + + RETURN + ------ + prx: tango.DeviceProxy or None + """ + # Get device proxy + try: + p = FofbTool.Utils.tangopath_cellnodes[cellnodename.lower()] + except KeyError: + logger.error("Wrong nodename. Possibilities are {}".format(FofbTool.Utils.tangopath_cellnodes.keys())) + return None + + try: + prx= tango.DeviceProxy(p) + except tango.DevFailed as e: + logger.error("Failed to get the Device proxy to '{}'".format(p)) + logger.debug(str(e)) + return None + + return prx + +def stop_all_combpm(): + """ + Apply stop command on all Cellnodes. + Check beforehand that the FOFB is not running. Display warning if. + + """ + + if not check_fofbnotrunning(): + logger.warning("Not running stop combpm because FOFB seems to be running.") + + for i,(n,p) in enumerate(tangopath_cellnodes.items()): + FofbTool.Operation.stop_combpm(n) + + +def stop_all_ccn(): + """ + Apply stop and reset commands on all fofbnodes. + Check beforehand that the FOFB is not running. Display warning if. + + """ + + if not check_fofbnotrunning(): + logger.warning("Not running stop combpm because FOFB seems to be running.") + + for i,(n,p) in enumerate(tangopath_nodes.items()): + FofbTool.Operation.stop_ccn(n) + FofbTool.Operation.reset_ccn(n) + + + +def start_all_combpm(): + """ + Apply start command on all Cellnodes. + + """ + + for i,(n,p) in enumerate(tangopath_cellnodes.items()): + FofbTool.Operation.start_combpm(n) + + +def start_all_ccn(): + """ + Apply stop and reset commands on all fofbnodes. + + """ + + for i,(n,p) in enumerate(tangopath_nodes.items()): + FofbTool.Operation.start_ccn(n) + +