From daeab19c124ba865892aa4d83e7ed16bd15027f9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20J=C3=BCrges?= <jurges@astron.nl>
Date: Thu, 22 Nov 2018 14:20:45 +0000
Subject: [PATCH] Task SW-533:  Refactor to use supported_modes =
 ['rawvoltage', 'subband'] for TBB stuff

---
 MAC/Services/TBB/TBBServer/lib/tbbservice.py |  4 ++--
 MAC/TBB/lib/tbb_config.py                    |  2 +-
 MAC/TBB/lib/tbb_load_firmware.py             | 24 +++++++++-----------
 MAC/TBB/lib/tbb_start_recording.py           |  8 +++----
 4 files changed, 17 insertions(+), 21 deletions(-)

diff --git a/MAC/Services/TBB/TBBServer/lib/tbbservice.py b/MAC/Services/TBB/TBBServer/lib/tbbservice.py
index ad50dfb9824..856a08d3881 100644
--- a/MAC/Services/TBB/TBBServer/lib/tbbservice.py
+++ b/MAC/Services/TBB/TBBServer/lib/tbbservice.py
@@ -239,10 +239,10 @@ class TBBControlService:
             """
             Command TBBs in ALERT mode to start data recording.
             :param stations:  string - Only TBBs of these stations will be commanded to start data recording.
-            :param mode:  string - Parameter to set-up data recording in either \"subbands\" or \"rawvoltage\" mode.
+            :param mode:  string - Parameter to set-up data recording in either \"subband\" or \"rawvoltage\" mode.
             :param sub_bands:  string - The list of sub-bands that the RSP will be set-up for. 
             """
-            log_message = "Starting the TBB data recording for mode %s on stations %s in subbands %s" % (mode, stations, subbands)
+            log_message = "Starting the TBB data recording for mode %s on stations %s in sub-bands %s" % (mode, stations, subbands)
             logger.info(log_message + "...")
             start_tbb(stations, mode, subbands)
             logger.info(log_message + "done.")
diff --git a/MAC/TBB/lib/tbb_config.py b/MAC/TBB/lib/tbb_config.py
index b86a09205ca..6ce04c082c4 100644
--- a/MAC/TBB/lib/tbb_config.py
+++ b/MAC/TBB/lib/tbb_config.py
@@ -27,4 +27,4 @@ else:
     rsp_command = "/opt/lofar/bin/rspctl "
 lcurun_command = "lcurun"
 
-supported_firmwares = ['timeseries', 'subbands']
+supported_modes = ['rawvoltage', 'subband']
diff --git a/MAC/TBB/lib/tbb_load_firmware.py b/MAC/TBB/lib/tbb_load_firmware.py
index 4ffcafd46d6..c27cab6094a 100755
--- a/MAC/TBB/lib/tbb_load_firmware.py
+++ b/MAC/TBB/lib/tbb_load_firmware.py
@@ -10,25 +10,23 @@ import argparse
 import time
 import subprocess
 import logging
-from lofar.mac.tbb.tbb_config import lcurun_command, tbb_command
+from lofar.mac.tbb.tbb_config import supported_modes, lcurun_command, tbb_command
 
-supported_firmwares = ['timeseries', 'subbands']
 
-def load_tbb_firmware(stations, firmware):
-
-    logging.info('Loading TBB firmware \"%s\"' % (firmware))
+def load_tbb_firmware(stations, mode):
+    logging.info('Loading TBB firmware for mode \"%s\"' % (mode))
 
     # This is hardcoded for now.  There is no reliable way to tell from the output
     # of tbbctl --imageinfo what a firmware can do.  Everything there is a string that
     # gets passed by the --writeimage command.  So even the image name can be wrong or
     # misleading.
     # So:  the ALERT firmware must be in slot #2!
-    if firmware == "subbands":
+    if mode == "subband":
         slot = 2
     else:
         slot = 1
 
-    logging.info("It is assumed that the %s firmware is in slot %d!" % (firmware, slot))
+    logging.info("It is assumed that the firmware for mode \"%s\" is in slot %d!" % (mode, slot))
 
     relay = [lcurun_command, stations]
     cmd = [tbb_command, '--config=%s' % slot]
@@ -41,9 +39,9 @@ def load_tbb_firmware(stations, firmware):
     wait_time = 60
     interval = 10
     for sleep_time in range(wait_time, 0, -interval):
-        logging.info("Waited %ds of %ds for the TBB boards to load the %s firmware..." % (wait_time - sleep_time, wait_time, firmware))
+        logging.info("Waited %ds of %ds for the TBB boards to load the firmware for mode \"%s\"..." % (wait_time - sleep_time, wait_time, mode))
         time.sleep(interval)
-    logging.info("TBBs should now have the %s firmware loaded.  Check the output of the following command!" % (firmware))
+    logging.info("TBBs should now have the firmware for mode \"%s\" loaded.  Check the output of the following command!" % (mode))
 
     for board in range(6):
         cmd = [tbb_command, '--imageinfo=%s' % str(board)]
@@ -55,10 +53,10 @@ def load_tbb_firmware(stations, firmware):
 def main():
     parser = argparse.ArgumentParser("This script will load a TBB firmware on a bunch of stations and the respective boards there.")
     parser.add_argument('-s', '--stations', dest='stations', help="comma-separated list of station LCUs (e.g. cs030c,cs031c; also accepts lcurun aliases like 'today', 'nl', ...)", default='today')
-    parser.add_argument('-f', '--firmware', dest='firmware', help="supported tbb firmwares: %s" % supported_firmwares, default='subbands')
+    parser.add_argument('-m', '--mode', dest='mode', help="supported tbb modes: %s" % supported_modes, default='subband')
     args = parser.parse_args()
 
-    if args.firmware not in supported_firmwares:
-        raise ValueError('Firmware must be one of %s' % supported_firmwares)
+    if args.mode not in supported_modes:
+        raise ValueError('Mode must be one of %s' % supported_modes)
 
-    load_tbb_firmware(args.stations, args.firmware)
+    load_tbb_firmware(args.stations, args.mode)
diff --git a/MAC/TBB/lib/tbb_start_recording.py b/MAC/TBB/lib/tbb_start_recording.py
index 23651347b34..62238235f72 100755
--- a/MAC/TBB/lib/tbb_start_recording.py
+++ b/MAC/TBB/lib/tbb_start_recording.py
@@ -10,15 +10,13 @@ import argparse
 import time
 import subprocess
 import logging
-from lofar.mac.tbb.tbb_config import lcurun_command, tbb_command, rsp_command
-
-supported_modes = ['transient', 'subbands']
+from lofar.mac.tbb.tbb_config import supported_modes, lcurun_command, tbb_command, rsp_command
 
 def start_tbb(stations, mode, subbands):
 
     logging.info('Starting TBB recording')
 
-    if mode == 'subbands':
+    if mode == 'subband':
         rspctl_mode_cmd = [rsp_command, '--tbbmode=%s,%s' % (mode, subbands)]
     else:
         rspctl_mode_cmd = [rsp_command, '--tbbmode=%s' % (mode)]
@@ -43,7 +41,7 @@ def main():
 
     parser = argparse.ArgumentParser("This script will start TBB recording on a bunch of stations.")
     parser.add_argument('-s', '--stations', dest='stations', help="comma-separated list of station LCUs (e.g. cs030c,cs031c; also accepts lcurun aliases like 'today', 'nl', ...)", default='today')
-    parser.add_argument('-m', '--mode', dest='mode', help="supported tbb modes: %s" % supported_modes, default='subbands')
+    parser.add_argument('-m', '--mode', dest='mode', help="supported tbb modes: %s" % supported_modes, default='subband')
     parser.add_argument('-b', '--subbands', dest='subbands', help='Subband range, e.g. 10:496', default='10:496')
     args = parser.parse_args()
 
-- 
GitLab