diff --git a/devices/clients/sst_client.py b/devices/clients/sst_client.py index 4a1bc5376ef3a2bb458bb0f7fd905aa7963d8f49..4aa4e3c68bb9e2b49e815feb605e8e7b7c2adce3 100644 --- a/devices/clients/sst_client.py +++ b/devices/clients/sst_client.py @@ -7,7 +7,7 @@ import socket import time from clients.comms_client import CommClient -from devices.sdp_statistics.statistics_packet import SSTPacket +from devices.sdp.statistics_packet import SSTPacket logger = logging.getLogger() diff --git a/devices/devices/sdp_statistics/__init__.py b/devices/devices/sdp/__init__.py similarity index 100% rename from devices/devices/sdp_statistics/__init__.py rename to devices/devices/sdp/__init__.py diff --git a/devices/SST.py b/devices/devices/sdp/sst.py similarity index 95% rename from devices/SST.py rename to devices/devices/sdp/sst.py index e9ee22d1187eb580c58ad397b33c687c28e409a0..5d614323bc7b807797ae3547366ae0efed779d2c 100644 --- a/devices/SST.py +++ b/devices/devices/sdp/sst.py @@ -11,6 +11,13 @@ """ +# TODO(Corne): Remove sys.path.append hack once packaging is in place! +import os, sys +currentdir = os.path.dirname(os.path.realpath(__file__)) +parentdir = os.path.dirname(currentdir) +parentdir = os.path.dirname(parentdir) +sys.path.append(parentdir) + # PyTango imports from tango.server import run from tango.server import device_property, attribute diff --git a/devices/devices/sdp_statistics/statistics_packet.py b/devices/devices/sdp/statistics_packet.py similarity index 100% rename from devices/devices/sdp_statistics/statistics_packet.py rename to devices/devices/sdp/statistics_packet.py diff --git a/devices/devices/sdp_statistics/sst.py b/devices/devices/sdp_statistics/sst.py deleted file mode 100644 index 5ea315fd9808fe1fd7dcc456b64d17e858977a1c..0000000000000000000000000000000000000000 --- a/devices/devices/sdp_statistics/sst.py +++ /dev/null @@ -1,108 +0,0 @@ -# -*- coding: utf-8 -*- -# -# This file is part of the Statistics project -# -# -# -# Distributed under the terms of the APACHE license. -# See LICENSE.txt for more info. - -""" Statistics Device Server for LOFAR2.0 - -""" - -# TODO(Corne): Remove sys.path.append hack once packaging is in place! -import os, sys -currentdir = os.path.dirname(os.path.realpath(__file__)) -parentdir = os.path.dirname(currentdir) -parentdir = os.path.dirname(parentdir) -sys.path.append(parentdir) - -# PyTango imports -from tango.server import run -from tango.server import device_property -# Additional import - -from clients.sst_client import sst_client - -from clients.attribute_wrapper import attribute_wrapper -from devices.hardware_device import hardware_device - -from common.lofar_logging import device_logging_to_python, log_exceptions - -import numpy - -__all__ = ["SST", "main"] - -@device_logging_to_python({"device": "SST"}) -class SST(hardware_device): - - # ----------------- - # Device Properties - # ----------------- - - SST_Port = device_property( - dtype='DevUShort', - mandatory=True - ) - - # ---------- - # Attributes - # ---------- - # -------- - - # SST client annotation consists of a dict that contains the parameter name that needs to be read. - # Example: comms_annotation={"parameter": "this_value_R"} - packet_count_R = attribute_wrapper(comms_annotation={"parameter": "packet_count_R"}, datatype=numpy.int64) - last_packet_timestamp_R = attribute_wrapper(comms_annotation={"parameter": "last_packet_timestamp_R"}, datatype=numpy.int64) - queue_percentage_used_R = attribute_wrapper(comms_annotation={"parameter": "queue_percentage_used_R"}, datatype=numpy.double) - - # -------- - # overloaded functions - def configure_for_off(self): - """ user code here. is called when the state is set to OFF """ - - # Stop keep-alive - try: - self.sst_client.stop() - except Exception as e: - self.warn_stream("Exception while stopping sst_client in configure_for_off function: {}. Exception ignored".format(e)) - - @log_exceptions() - def configure_for_initialise(self): - """ user code here. is called when the sate is set to INIT """ - """Initialises the attributes and properties of the statistics device.""" - - self.sst_client = sst_client("0.0.0.0", self.SST_Port, self.Fault, self) - - # map an access helper class - for i in self.attr_list(): - try: - i.set_comm_client(self.sst_client) - except Exception as e: - # use the pass function instead of setting read/write fails - i.set_pass_func() - self.warn_stream("error while setting the sst attribute {} read/write function. {}. using pass function instead".format(i, e)) - pass - - self.sst_client.start() - - # -------- - # Commands - # -------- - -# ---------- -# Run server -# ---------- -def main(args=None, **kwargs): - """Main function of the Statistics Device module.""" - - from common.lofar_logging import configure_logger - import logging - configure_logger(logging.getLogger()) - - return run((SST,), args=args, **kwargs) - - -if __name__ == '__main__': - main() diff --git a/docker-compose/device-sst.yml b/docker-compose/device-sst.yml index c42496700eaf96347825a93c5050dc90744c1888..992980bcaafd8de43e85c56d134f9736944e2eac 100644 --- a/docker-compose/device-sst.yml +++ b/docker-compose/device-sst.yml @@ -26,7 +26,7 @@ services: - control - data ports: - - 5001:5001/udp + - 5001:5001/udp volumes: - ${TANGO_LOFAR_CONTAINER_MOUNT} environment: @@ -37,5 +37,5 @@ services: - --timeout=30 - --strict - -- - - python3 -u ${TANGO_LOFAR_CONTAINER_DIR}/devices/devices/sst.py LTS -v + - python3 -u ${TANGO_LOFAR_CONTAINER_DIR}/devices/devices/sdp/sst.py LTS -v restart: on-failure