From a519a04338d2619b612ea7502b860cc158a81004 Mon Sep 17 00:00:00 2001
From: Leon Hiemstra <hiemstra@astron.nl>
Date: Fri, 3 Aug 2018 11:29:02 +0000
Subject: [PATCH] Task #1894: main_w_mac.py deleted. Further dev in:
 svn/apertif/commissioning/trunk/main

---
 .../apertif/commissioning/main_w_mac.py       | 312 ------------------
 1 file changed, 312 deletions(-)
 delete mode 100644 applications/apertif/commissioning/main_w_mac.py

diff --git a/applications/apertif/commissioning/main_w_mac.py b/applications/apertif/commissioning/main_w_mac.py
deleted file mode 100644
index f5544d206f..0000000000
--- a/applications/apertif/commissioning/main_w_mac.py
+++ /dev/null
@@ -1,312 +0,0 @@
-#!/usr/bin/env python
-###############################################################################
-#
-# Copyright (C) 2017
-# ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
-# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-#
-###############################################################################
-
-# Author:
-# . Daniel van der Schuur
-# . Boudewijn Hut
-# Purpose:
-# . Run UniBoard commands on remote dish LCUs and local correlator LCU to start
-#   data streams
-# Usage: 
-# . python main.py --app <application> --tel <telescopes> --unb <uniboards> --opt <options>
-#        . application = "apertif-ag", "apertif-dev", "arts_sc1" or "arts_sc4"
-#        . telescopes = 2,3,4,..,c,d
-#        . unb = bands = 0,1,2,..15
-#        . options = noflash (optional, debug/development only)
-
-import shell
-import test_case
-import common as cm
-import time
-import numpy as np
-import os
-import sys
-from apertif.messaging.send_file import send_and_wait_files
-from pprint import pprint
-
-
-def writeParset(command, lcu_list=None, exec_time='utcnow()', args=[], parset_template='low_level_parset.template', parset_path='/tmp/parset.parset'):
-    ''' Replace the parset template keys
-    
-    Input Arguments:
-    command         = string, the command for which the parset is generated
-    lcu_list        = list of strings with lcu hostnames where the parset should be send to
-    exec_time       = string, the execution time for this parset
-    args            = list of strings, added as argument lines to the parset
-    parset_template = string, the location of the parset template
-    parset_path     = string, the location for the generated parset
-    
-    Output Arguments:
-    parset_path     = sting, location of the generate parset
-    '''
-    # determine recipient list
-    controller = command2controller(command)
-    ctr_list = lculist2controllerlist(controller, lcu_list)
-    # update parset by template keys
-    with open(parset_template, 'r') as file :
-        filedata = file.read()
-    filedata = filedata.replace('@CONTROLLERS@', str(ctr_list))
-    filedata = filedata.replace('@COMMAND@', command)
-    filedata = filedata.replace('@EXEC_TIME@', exec_time)
-    # add argument lines
-    for arg in args:
-        filedata += '%s\n' % arg
-    # save parset
-    with open(parset_path, 'w') as file:
-        file.write(filedata)
-    print 'command: %s' % command
-    print 'recipientlist: %s' % str(ctr_list)
-    print 'execution_time: %s' % exec_time
-    return parset_path
-
-def command2controller(command):
-    ''' Determine which controller executes that low level command'''
-    drivers = ['uni', 'dcu', 'log', 'pac']
-    if command[0:3] in drivers:
-        controller = 'SignalControl'
-    else:
-        print 'Cannot determine controller for command: %s' % command
-        sys.exit(1)
-    return controller
-
-def lculist2controllerlist(controller, lcu_list=None):
-    ''' Convert a list of lcus and controller name to an expanded controller list
-    Example
-    lcu_list = ['lcu-rt2', 'lcu-rt4']
-    controller = 'SignalControl'
-    ctr_list = lculist2controllerlist(controller, lcu_list)
-    print str(ctr_list)
-    ['SignalControl@lcu-rt2', 'SignalControl@lcu-rt4']
-    '''
-    ctr_list = []
-    if lcu_list == None:
-        ctr_list.append(controller)
-    else:
-        for lcu in lcu_list:
-            ctr_list.append('%s@%s' % (controller, lcu))
-    return ctr_list
-
-
-
-
-
-
-###############################################################################
-# Test case contains logging/printing functionality
-###############################################################################
-tc = test_case.Testcase('MAIN - ', '')
-
-
-
-
-supportedApps = ['apertif-ag', 'apertif-dev', 'arts_sc1', 'arts_sc4']
-if tc.appStr in supportedApps:
-    app_str = 'Application: ' + tc.appStr
-    tc.append_log(1, app_str)
-else:
-    tc.append_log(1, 'Exit due to unsupported --app , must be one of %s.' % supportedApps)
-    sys.exit()
-
-lcu_str = 'Targetting LCUs: '
-LCUS = []
-for tel in tc.telStrList:
-    if tel == '':
-        continue
-    LCUS.append('lcu-rt' + str(tel))
-    lcu_str = lcu_str + ' lcu-rt' + str(tel) + ','
-tc.append_log(1, lcu_str[:-1])
-
-
-unb_str = 'Targetting UniBoards: ' + str(tc.unbStr)
-tc.append_log(1, unb_str)
-
-#tc.polStr
-#tc.polNrs
-print 'Polarisation: ' + tc.polStr
-
-opt_str = 'Options: ' + tc.optStr
-tc.append_log(1, opt_str)
-
-if tc.polStr == '0':
-    UNBS_BF = '0:3'
-elif tc.polStr == '1':
-    UNBS_BF = '4:7'
-else:
-    UNBS_BF = '0:7'
-
-print 'UNBS_BF = ' + UNBS_BF
-
-################################################################################
-## Check if central UniBoard system is ready for action. If not, exit immediately.
-################################################################################
-#if tc.unbStr == '':
-#    print 'Omitting call to central_status, since no XC boards are addressed.'
-#else:
-#    cmd = '. $RADIOHDL/applications/apertif/commissioning/central_status.sh ' + tc.appStr + ' ' + tc.telStr + ' ' + tc.unbStr + ' ' + 'precheck' + ' ' + tc.polStr
-#    print 'ccu-corr'+':$ '+cmd
-#    output = shell.ssh_cmd('ccu-corr', cmd, tc)
-#    if "Error" in output or not "Passed" in output:
-#        print "Exiting due to central errors"
-#        sys.exit()
-#
-################################################################################
-## Check if dish UniBoard systems are ready for action. If not, exit immediately.
-################################################################################
-#command = '. $RADIOHDL/applications/apertif/commissioning/dish_status.sh ' + tc.appStr + ' ' + 'precheck' + ' ' + tc.polStr
-#for lcu in LCUS:
-#    print lcu+':$ '+command
-#    output = (shell.ssh_cmd(lcu, command, tc))
-#    if "Error" in output or not "Passed" in output:
-#        print "Exiting due to dish errors"
-#        sys.exit()
-#
-################################################################################
-## Run remote dish commands in background
-################################################################################
-#print 'POL, RUN', tc.polStr, tc.runStr
-#subcommand = '. $RADIOHDL/applications/apertif/commissioning/dish_commands.sh ' + tc.appStr + ' ' + tc.optStr + ' ' + tc.polStr + ' ' + tc.runStr + ' ' + ','.join(map(str,tc.unbNrs))
-#for lcu in LCUS:
-#    command = subcommand + ' > ~/'+lcu+'_dish_commands.log '
-#    print lcu+':$ '+command
-#    shell.ssh_cmd_bkgnd(lcu, command)
-#
-################################################################################
-## Run central commands in foreground
-################################################################################
-#if tc.unbStr == '':
-#    pass
-#else:
-#    subcommand = '. $RADIOHDL/applications/apertif/commissioning/central_commands.sh ' + tc.appStr + ' ' + tc.telStr + ' ' + tc.unbStr + ' ' + tc.optStr + ' ' + tc.polStr
-#    command = subcommand + ' | tee ~/central_commands.log '
-#    print 'ccu-corr'+':$ '+command
-#    shell.ssh_cmd('ccu-corr', command, tc)
-#
-################################################################################
-## Wait until remote dish commands are done
-################################################################################
-#command = 'ps -efd | grep [d]ish_commands.sh'
-#for lcu in LCUS:
-#    while True:
-#        output = (shell.ssh_cmd(lcu, command, tc))
-#        if not "dish_commands.sh" in output:
-#            print lcu, "ready"
-#            break
-#        else:
-#            time.sleep(1)
-#        
-################################################################################
-## Reset the XAUI cores in the front end Apertif beam former
-################################################################################
-#if tc.unbStr == '':
-#    print 'Omitting xaui reset, since no XC boards are addressed.'
-#else:
-#    cmd = 'python $UPE/peripherals/pi_tr_xaui.py --unb ' + UNBS_BF + ' --fn 0:3 -r 0:2 --reg reset_control_status=3'
-#    for lcu in LCUS:
-#        print lcu+':$ '+cmd
-#        shell.ssh_cmd_bkgnd(lcu, cmd)
-#    
-#    ###############################################################################
-#    # Reset the XAUI cores in all central FPGAs
-#    # . Loop through a list of individual UniBoards instead of targeting all 
-#    #   UniBoards in one command; in case one of them fails the others will still work.
-#    ###############################################################################
-#    for unb in tc.unbNrs:
-#        cmd = 'python $UPE/peripherals/pi_tr_xaui.py --unb ' + str(unb) + ' --fn 0:3 --bn 0:3 -r 0:2 --reg reset_control_status=3'
-#        shell.ssh_cmd('ccu-corr', cmd, tc)
-################################################################################
-## Enable data path if this is not a re-run
-################################################################################
-if tc.run == True: 
-
-    ###############################################################################
-    # Enable the data path synchonously
-    ###############################################################################
-    BLOCKS_PER_SEC = 781250
-    arm_time = 5 # seconds to arm system
-    curr_time = time.time()
-    curr_time_rounded = round(curr_time)
-    bsn_init_sec = int(np.ceil(curr_time + arm_time)) # seconds after epoch (for next PPS after arm_time)
-    bsn_init = BLOCKS_PER_SEC*(bsn_init_sec)
-    
-    cmd = 'python $UPE/peripherals/util_bsn_source.py --unb ' + UNBS_BF + ' --bn 0:3 -n 11 -r %s' %str(bsn_init)
-    for lcu in LCUS:
-        shell.ssh_cmd(lcu, cmd, tc)
-    
-    tc.append_log(1, 'Current time         : ' + str(curr_time))
-    tc.append_log(1, 'Scheduled start time : ' + str(bsn_init_sec))
-    tc.append_log(1, 'Scheduled start BSN  : ' + str(bsn_init))
-    
-    # Wait until local time is 1.8s before bsn_init_sec
-    cm.do_until_ge(time.time, bsn_init_sec-1.8, ms_retry=10, s_timeout=20) 
-
-    if tc.mac == True:
-        print "Uniboard driver: Wait for PPS..."
-        parset_path = writeParset('uniboard_ppswait', lcu_list=LCUS, args=['nodelist=[4]'])
-        # send parset and wait for response
-        reply = send_and_wait_files(parset_path, timeout=3.0)
-        # print response
-        reply = reply[parset_path]
-        pprint(reply)
-
-        print "Uniboard driver: Enable Datapath at next PPS..."
-        parset_path = writeParset('uniboard_dpon', lcu_list=LCUS)
-        # send parset and wait for response
-        reply = send_and_wait_files(parset_path, timeout=3.0)
-        # print response
-        reply = reply[parset_path]
-        pprint(reply)
-    else:
-        # wait until PPS; should occur in ~0.8s
-        cmd = 'python $UPE/peripherals/util_ppsh.py --unb ' + UNBS_BF[0] + ' --bn 0 -n 4'
-        print 'cmd = %s' % cmd
-        shell.ssh_cmd(LCUS[0], cmd, tc)
-
-        # We are now at ~bsn_init_sec-1. Enable the data path on the next PPS
-        for lcu in LCUS:
-            cmd = ['/usr/bin/ssh', 'ssh', '-x', lcu, 'python', '$UPE/peripherals/util_bsn_source.py', '--unb', UNBS_BF, '--bn', '0:3', '-n', '1']
-            print cmd
-            os.spawnl(os.P_NOWAIT, *cmd)
-
-
-###############################################################################
-# Everything should be up and running - check dish UniBoard system
-###############################################################################
-command = '. $RADIOHDL/applications/apertif/commissioning/dish_status.sh ' + tc.appStr + ' ' + 'postcheck' + ' ' + tc.polStr
-for lcu in LCUS:
-    print lcu+':$ '+command
-    output = (shell.ssh_cmd(lcu, command, tc))
-    if "Error" in output or not "Passed" in output:
-        print "Found post-command dish errors"
-
-###############################################################################
-# Everything should be up and running - check central UniBoard system
-###############################################################################
-if tc.unbStr == '':
-    print 'Omitting call to central_status, since no XC boards are addressed.'
-else:
-    cmd = '. $RADIOHDL/applications/apertif/commissioning/central_status.sh ' + tc.appStr + ' ' + tc.telStr + ' ' + tc.unbStr + ' ' + 'postcheck' + ' ' + tc.polStr
-    print 'ccu-corr'+':$ '+cmd
-    output = shell.ssh_cmd('ccu-corr', cmd, tc)
-    if "Error" in output or not "Passed" in output:
-        print "Found post-command central errors"
-
-
-- 
GitLab