diff --git a/FofbTool/Configuration.py b/FofbTool/Configuration.py index 755e60c07cac9282ac1e977dc82530e04681263b..bf8cf9d9b7f0f7634c2c10e7e3a550b5f756bee5 100644 --- a/FofbTool/Configuration.py +++ b/FofbTool/Configuration.py @@ -162,7 +162,7 @@ def cellnode_configure_combpm(cellnodename, bpmallowed=None): # CONFIGURE COM LBP ################################################################################################### -def cellnode_configure_comlbp(cellnodename, bpmallowed=None): +def cellnode_configure_comlbp(cellnodename, seqoffset=0): """ Configure the comlbp block of a CellNode. For now, nothing done @@ -172,12 +172,35 @@ def cellnode_configure_comlbp(cellnodename, bpmallowed=None): cellnodename: str The target cellnode, ie 'cellnode-c09' + seqoffset: int + Sequence offset to configure + RETURN ------ success: boolean True if configuration is a success """ + # Get device proxy + try: + p = config["tangopath.fofbnodes"][cellnodename.lower()] + except KeyError: + logger.error("Wrong cellnodename. Possibilities are {}".format(list(config['tangopath.fofbnodes'].keys()))) + return False + + 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 False + + + logger.debug("Program sequence offset {} in {}".format(seqoffset, cellnodename)) + for n in range(4): + prx["comlbp{}_seqoffset".format(n)]=seqoffset + + logger.info("Configuration of ComLBP done on {}.".format(p)) return True diff --git a/FofbTool/Operation.py b/FofbTool/Operation.py index 33e9a2e371153be2073223e0a30418ba508f760d..1e2273134dc30c266af4b3655750af1146938913 100644 --- a/FofbTool/Operation.py +++ b/FofbTool/Operation.py @@ -21,32 +21,46 @@ logger = logging.getLogger("FofbTool") # OPERATIONS ON CCN ################################################################################################### -def align_ccn(nodename): +def align_ccn(node_tangopath, comlbpif=0): """ - Align FA sequence number on a cellnode + Align FA sequence number on a cellnode. Returns the computed offset. + PARAMETERS ---------- - nodename: str - The target fofbnode, ie 'cellnode-c09' or 'centralnode' + node_tangopath: str + The target fofbnode tango path, ie 'ans/dg/fofb-cellnode-c09' + + comlbpif: int + which comlbp interface to use (0 to 3) + + RETURNS + ------- + seqoffset: int or None + If success, return the found sequece offset. + Return None on failure. """ - prx=FofbTool.Utils.get_prx_from_nodename(nodename) - if prx is None: - logger.error("Failed to align CCN on {}".format(nodename)) - return + try: + prx=tango.DeviceProxy(node_tangopath) + prx.ping() + except tango.DevFailed: + logger.error("Failed to obtain tango proxy or to ping to {}".format(node_tangopath)) + return None logger.info("Trying to detect and align FA sequences") - logger.debug("Reset offsets on comlbp") - set_comlbp_seqoffset(nodename, 0) + logger.debug("Reset offset on comlbp") + prx["comlbp{}_seqoffset".format(comlbpif)]=0 + + # TODO reset and start comlbp and combpm # Loop until two consecutives identical measures - N=[7,3] + N=[7,3] # random start while N[-2] != N[-1]: if len(N) > 7: logger.error("Could not measure sequence offset.") - return False + return None logger.debug("Latch two sequence numbers without offset") prx.ccnpack0_control=1 # let it roll a bit to collect data @@ -70,7 +84,8 @@ def align_ccn(nodename): N=N+0x10000 - set_comlbp_seqoffset(nodename, N) + logger.debug("Setting sequence offset to {}".format(N)) + prx["comlbp{}_seqoffset".format(comlbpif)]=N seqoffset=N logger.debug("Perform autocheck") @@ -83,22 +98,9 @@ def align_ccn(nodename): if not N in (-1, 1): logger.warning("Corrected sequence offset measured = {}, something might be wrong. Run it again".format(N)) - return False + return None return seqoffset -def set_comlbp_seqoffset(nodename, N): - """ Set sequence offset for all comlbp interfaces """ - - prx=FofbTool.Utils.get_prx_from_nodename(nodename) - if prx is None: - logger.error("Failed to align CCN on {}".format(nodename)) - return - - logger.info("Program sequence offset {} in {}".format(N, nodename)) - for n in range(4): - prx["comlbp{}_seqoffset".format(n)]=N - - def stop_ccn(nodename): """ Stop the communication with cellnode on the specified fofbnode. diff --git a/FofbTool/Utils.py b/FofbTool/Utils.py index b273b14fbcab7c92f54c3a7d336b83b411e2c46f..6c1fafbb6f50ab15c3a1cfd3c2ed9d5190ccaefc 100644 --- a/FofbTool/Utils.py +++ b/FofbTool/Utils.py @@ -325,8 +325,9 @@ def align_all_ccn(cellnodename, force=False): return logger.debug("Use {} for sequence alignement".format(cellnodename)) - seqoffset = FofbTool.Operation.align_ccn(cellnodename) - if not seqoffset: + cellnodepath=FofbTool.Utils.get_prx_from_nodename(cellnodename) + seqoffset = FofbTool.Operation.align_ccn(cellnodepath, 0) + if seqoffset is None: logger.error("Could not align all ccn") return @@ -334,6 +335,6 @@ def align_all_ccn(cellnodename, force=False): for n,p in FofbTool.Configuration.config["tangopath.fofbnodes"].items(): if 'cellnode' in n: try: - FofbTool.Operation.set_comlbp_seqoffset(n, seqoffset) + FofbTool.Configuration.cellnode_configure_comlbp(n, seqoffset) except (tango.DevFailed, TypeError): logger.error("Could not set comlbp offset on {}".format(n))