From 3ddcefe0257e231b82863c1a27ac281794b5164c Mon Sep 17 00:00:00 2001
From: Jan David Mol <mol@astron.nl>
Date: Mon, 6 Dec 2021 15:04:50 +0100
Subject: [PATCH] L2SS-478: Added skeleton Beam device

---
 CDB/LOFAR_ConfigDb.json                       |  7 +++
 docker-compose/device-beam.yml                | 33 +++++++++++++
 .../startup/01-devices.py                     |  3 +-
 docs/source/devices/beam.rst                  |  8 +++
 docs/source/index.rst                         |  1 +
 sbin/run_integration_test.sh                  |  4 +-
 tangostationcontrol/setup.cfg                 |  1 +
 .../tangostationcontrol/devices/beam.py       | 49 +++++++++++++++++++
 .../tangostationcontrol/devices/boot.py       |  1 +
 .../devices/test_device_beam.py               | 15 ++++++
 10 files changed, 119 insertions(+), 3 deletions(-)
 create mode 100644 docker-compose/device-beam.yml
 create mode 100644 docs/source/devices/beam.rst
 create mode 100644 tangostationcontrol/tangostationcontrol/devices/beam.py
 create mode 100644 tangostationcontrol/tangostationcontrol/integration_test/devices/test_device_beam.py

diff --git a/CDB/LOFAR_ConfigDb.json b/CDB/LOFAR_ConfigDb.json
index 6886437ce..60b011592 100644
--- a/CDB/LOFAR_ConfigDb.json
+++ b/CDB/LOFAR_ConfigDb.json
@@ -21,6 +21,13 @@
                 }
             }
         },
+        "Beam": {
+            "STAT": {
+                "Beam": {
+                    "STAT/Beam/1": {}
+                }
+            }
+        },
         "boot": {
             "STAT": {
                 "Boot": {
diff --git a/docker-compose/device-beam.yml b/docker-compose/device-beam.yml
new file mode 100644
index 000000000..3312ec6a2
--- /dev/null
+++ b/docker-compose/device-beam.yml
@@ -0,0 +1,33 @@
+#
+# Requires:
+#   - lofar-device-base.yml
+#
+version: '2'
+
+services:
+  device-beam:
+    image: device-beam
+    # build explicitly, as docker-compose does not understand a local image
+    # being shared among services.
+    build:
+        context: lofar-device-base
+        args:
+            SOURCE_IMAGE: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}-tango-itango:${TANGO_ITANGO_VERSION}
+    container_name: ${CONTAINER_NAME_PREFIX}device-beam
+    networks:
+      - control
+    ports:
+      - "5711:5711" # unique port for this DS
+    extra_hosts:
+      - "host.docker.internal:host-gateway"
+    volumes:
+      - ..:/opt/lofar/tango:rw
+    environment:
+      - TANGO_HOST=${TANGO_HOST}
+    working_dir: /opt/lofar/tango
+    entrypoint:
+      - bin/start-ds.sh
+      # configure CORBA to _listen_ on 0:port, but tell others we're _reachable_ through ${HOSTNAME}:port, since CORBA
+      # can't know about our Docker port forwarding
+      - l2ss-beam Beam STAT -v -ORBendPoint giop:tcp:0:5708 -ORBendPointPublish giop:tcp:${HOSTNAME}:5708
+    restart: unless-stopped
diff --git a/docker-compose/jupyter/ipython-profiles/stationcontrol-jupyter/startup/01-devices.py b/docker-compose/jupyter/ipython-profiles/stationcontrol-jupyter/startup/01-devices.py
index 74692f10f..03e7b75b4 100644
--- a/docker-compose/jupyter/ipython-profiles/stationcontrol-jupyter/startup/01-devices.py
+++ b/docker-compose/jupyter/ipython-profiles/stationcontrol-jupyter/startup/01-devices.py
@@ -7,7 +7,8 @@ sst = DeviceProxy("STAT/SST/1")
 xst = DeviceProxy("STAT/XST/1")
 unb2 = DeviceProxy("STAT/UNB2/1")
 boot = DeviceProxy("STAT/Boot/1")
+beam = DeviceProxy("STAT/Beam/1")
 docker = DeviceProxy("STAT/Docker/1")
 
 # Put them in a list in case one wants to iterate
-devices = [apsct, apspu, recv, sdp, sst, xst, unb2, boot, docker]
+devices = [apsct, apspu, recv, sdp, sst, xst, unb2, boot, beam, docker]
diff --git a/docs/source/devices/beam.rst b/docs/source/devices/beam.rst
new file mode 100644
index 000000000..c469162df
--- /dev/null
+++ b/docs/source/devices/beam.rst
@@ -0,0 +1,8 @@
+Beam
+====================
+
+The ``beam == DeviceProxy("STAT/Beam/1")`` device sets up the beamforming on the station:
+
+- The HBA tiles in RECV need *analog beamforming* to combine their 16 antennas into a single input for the RCU,
+- THe LBAs or HBA tiles need *digital beamforming* in SDP to combine their signals into beamlets.
+
diff --git a/docs/source/index.rst b/docs/source/index.rst
index 119d95164..7baab2934 100644
--- a/docs/source/index.rst
+++ b/docs/source/index.rst
@@ -19,6 +19,7 @@ Even without having access to any LOFAR2.0 hardware, you can install the full st
    installation
    interfaces/overview
    devices/using
+   devices/beam
    devices/boot
    devices/docker
    devices/recv
diff --git a/sbin/run_integration_test.sh b/sbin/run_integration_test.sh
index c3c37983a..5ec1d299b 100755
--- a/sbin/run_integration_test.sh
+++ b/sbin/run_integration_test.sh
@@ -15,7 +15,7 @@ cd "$LOFAR20_DIR/docker-compose" || exit 1
 make build
 
 # Start and stop sequence
-make stop device-boot device-docker device-apsct device-apspu device-sdp device-recv device-sst device-unb2 device-xst sdptr-sim recv-sim unb2-sim apsct-sim apspu-sim
+make stop device-boot device-docker device-apsct device-apspu device-sdp device-recv device-sst device-unb2 device-xst device-beam sdptr-sim recv-sim unb2-sim apsct-sim apspu-sim
 make start databaseds dsconfig elk
 
 # Give dsconfig and databaseds time to start
@@ -32,7 +32,7 @@ make start sdptr-sim recv-sim unb2-sim apsct-sim apspu-sim
 # Give the simulators time to start
 sleep 5
 
-make start device-boot device-apsct device-apspu device-sdp device-recv device-sst device-unb2 device-xst
+make start device-boot device-apsct device-apspu device-sdp device-recv device-sst device-unb2 device-xst device-beam
 
 # Give devices time to restart
 # TODO(Corne Lukken): Use a nicer more reliable mechanism
diff --git a/tangostationcontrol/setup.cfg b/tangostationcontrol/setup.cfg
index e6101c890..31662e40d 100644
--- a/tangostationcontrol/setup.cfg
+++ b/tangostationcontrol/setup.cfg
@@ -36,6 +36,7 @@ where=./
 console_scripts =
     l2ss-apsct = tangostationcontrol.devices.apsct:main
     l2ss-apspu = tangostationcontrol.devices.apspu:main
+    l2ss-beam = tangostationcontrol.devices.beam:main
     l2ss-boot = tangostationcontrol.devices.boot:main
     l2ss-docker-device = tangostationcontrol.devices.docker_device:main
     l2ss-observation = tangostationcontrol.devices.observation:main
diff --git a/tangostationcontrol/tangostationcontrol/devices/beam.py b/tangostationcontrol/tangostationcontrol/devices/beam.py
new file mode 100644
index 000000000..575e667e0
--- /dev/null
+++ b/tangostationcontrol/tangostationcontrol/devices/beam.py
@@ -0,0 +1,49 @@
+# -*- coding: utf-8 -*-
+#
+# Distributed under the terms of the APACHE license.
+# See LICENSE.txt for more info.
+
+""" Beam Device Server for LOFAR2.0
+
+"""
+
+# PyTango imports
+from tango import AttrWriteType
+import numpy
+# Additional import
+
+from tangostationcontrol.devices.device_decorators import *
+from tangostationcontrol.common.entrypoint import entry
+from tangostationcontrol.clients.attribute_wrapper import attribute_wrapper
+from tangostationcontrol.devices.lofar_device import lofar_device
+from tangostationcontrol.common.lofar_logging import device_logging_to_python, log_exceptions
+
+__all__ = ["Beam", "main"]
+
+
+@device_logging_to_python()
+class Beam(lofar_device):
+    # -----------------
+    # Device Properties
+    # -----------------
+
+    # ----------
+    # Attributes
+    # ----------
+
+    # --------
+    # overloaded functions
+    # --------
+
+
+    # --------
+    # Commands
+    # --------
+
+
+# ----------
+# Run server
+# ----------
+def main(**kwargs):
+    """Main function of the ObservationControl module."""
+    return entry(Beam, **kwargs)
diff --git a/tangostationcontrol/tangostationcontrol/devices/boot.py b/tangostationcontrol/tangostationcontrol/devices/boot.py
index c4df70bf5..5f2e9b76e 100644
--- a/tangostationcontrol/tangostationcontrol/devices/boot.py
+++ b/tangostationcontrol/tangostationcontrol/devices/boot.py
@@ -251,6 +251,7 @@ class Boot(lofar_device):
                        "STAT/SDP/1",    # SDP controls the mask for SST/XST/BST, so initialise it first
                        "STAT/SST/1",
                        "STAT/XST/1",
+                       "STAT/Beam/1",   # Accesses RECV and SDP
                       ],
     )
 
diff --git a/tangostationcontrol/tangostationcontrol/integration_test/devices/test_device_beam.py b/tangostationcontrol/tangostationcontrol/integration_test/devices/test_device_beam.py
new file mode 100644
index 000000000..b6be958cf
--- /dev/null
+++ b/tangostationcontrol/tangostationcontrol/integration_test/devices/test_device_beam.py
@@ -0,0 +1,15 @@
+# -*- coding: utf-8 -*-
+#
+# This file is part of the LOFAR 2.0 Station Software
+#
+#
+#
+# Distributed under the terms of the APACHE license.
+# See LICENSE.txt for more info.
+
+from .base import AbstractTestBases
+
+class TestDeviceBeam(AbstractTestBases.TestDeviceBase):
+
+    def setUp(self):
+        super().setUp("STAT/Beam/1")
-- 
GitLab