diff --git a/CDB/LOFAR_ConfigDb.json b/CDB/LOFAR_ConfigDb.json index 705f701556224fa4936e35916993aa2d4d05107e..197686104afa47aeb018b0c5caade4d286a4fe9b 100644 --- a/CDB/LOFAR_ConfigDb.json +++ b/CDB/LOFAR_ConfigDb.json @@ -684,6 +684,24 @@ "OPC_Time_Out": [ "5.0" ], + "FPGA_sdp_info_station_id_RW_default": [ + "901", + "901", + "901", + "901", + "901", + "901", + "901", + "901", + "901", + "901", + "901", + "901", + "901", + "901", + "901", + "901" + ], "polled_attr": [ "fpga_temp_r", "1000", @@ -735,6 +753,60 @@ ], "OPC_Time_Out": [ "5.0" + ], + "FPGA_sst_offload_hdr_eth_destination_mac_RW_default": [ + "6c:2b:59:97:cb:de", + "6c:2b:59:97:cb:de", + "6c:2b:59:97:cb:de", + "6c:2b:59:97:cb:de", + "6c:2b:59:97:cb:de", + "6c:2b:59:97:cb:de", + "6c:2b:59:97:cb:de", + "6c:2b:59:97:cb:de", + "6c:2b:59:97:cb:de", + "6c:2b:59:97:cb:de", + "6c:2b:59:97:cb:de", + "6c:2b:59:97:cb:de", + "6c:2b:59:97:cb:de", + "6c:2b:59:97:cb:de", + "6c:2b:59:97:cb:de", + "6c:2b:59:97:cb:de" + ], + "FPGA_sst_offload_hdr_ip_destination_address_RW_default": [ + "10.99.250.250", + "10.99.250.250", + "10.99.250.250", + "10.99.250.250", + "10.99.250.250", + "10.99.250.250", + "10.99.250.250", + "10.99.250.250", + "10.99.250.250", + "10.99.250.250", + "10.99.250.250", + "10.99.250.250", + "10.99.250.250", + "10.99.250.250", + "10.99.250.250", + "10.99.250.250" + ], + "FPGA_sst_offload_hdr_udp_destination_port_RW_default": [ + "5001", + "5001", + "5001", + "5001", + "5001", + "5001", + "5001", + "5001", + "5001", + "5001", + "5001", + "5001", + "5001", + "5001", + "5001", + "5001" ] } } diff --git a/devices/devices/hardware_device.py b/devices/devices/hardware_device.py index 524c378c1256eb5cc09fb9af12b21d5d0f781a09..c0e7df614d95e40f9816f9332f2832c8f3d4166c 100644 --- a/devices/devices/hardware_device.py +++ b/devices/devices/hardware_device.py @@ -14,8 +14,8 @@ from abc import ABCMeta, abstractmethod # PyTango imports -from tango.server import Device, command, DeviceMeta -from tango import DevState, DebugIt +from tango.server import Device, command, DeviceMeta, attribute +from tango import DevState, DebugIt, Attribute, DeviceProxy # Additional import from clients.attribute_wrapper import attribute_wrapper @@ -161,7 +161,6 @@ class hardware_device(Device, metaclass=AbstractDeviceMetas): self.configure_for_fault() self.set_state(DevState.FAULT) - # functions that can or must be overloaded def configure_for_fault(self): pass @@ -192,3 +191,36 @@ class hardware_device(Device, metaclass=AbstractDeviceMetas): self.Off() self.debug_stream("Shut down. Good bye.") + + @command() + @only_in_states([DevState.STANDBY, DevState.ON]) + @DebugIt() + @log_exceptions() + def set_defaults(self): + """ Set hardware points to their default value. + + A hardware point XXX is set to the value of the object member named XXX_default, if it exists. + XXX_default can be f.e. a constant, or a device_property. + """ + + # we cannot write directly to our attribute, as that would not + # trigger a write_{name} call. See https://www.tango-controls.org/community/forum/c/development/c/accessing-own-deviceproxy-class/?page=1#post-2021 + + # obtain a proxy to myself, to write values + proxy = DeviceProxy(self.get_name()) + + # for all my members + for name in dir(self): + attr = getattr(self, name) + # check if it's an attribute, and there is a default value available + if isinstance(attr, Attribute) and hasattr(self, f"{name}_default"): + try: + default_value = getattr(self, f"{name}_default") + + # set the attribute to the configured default + self.debug_stream(f"Setting attribute {name} to {default_value}") + proxy.write_attribute(name, default_value) + except Exception as e: + # log which attribute we're addressing + raise Exception(f"Cannot assign default to attribute {name}") from e + diff --git a/devices/devices/sdp/sdp.py b/devices/devices/sdp/sdp.py index b611f5a9f0289981da65b16fa9dd5224261a1749..c1730ab621f0da57bc486240ec662c84f6cde1ed 100644 --- a/devices/devices/sdp/sdp.py +++ b/devices/devices/sdp/sdp.py @@ -69,6 +69,23 @@ class SDP(hardware_device): mandatory=True ) + FPGA_processing_enable_RW_default = device_property( + dtype='DevVarBooleanArray', + mandatory=False, + default_value=[True] * 16 + ) + + FPGA_wg_enable_RW_default = device_property( + dtype='DevVarBooleanArray', + mandatory=False, + default_value=[[False] * 12] * 16 + ) + + FPGA_sdp_info_station_id_RW_default = device_property( + dtype='DevVarULongArray', + mandatory=True + ) + # ---------- # Attributes # ---------- diff --git a/devices/devices/sdp/sst.py b/devices/devices/sdp/sst.py index 1a62a4edcf28c84f7be865d38f7d5312417b497e..792162fd50adcefdb420fd621e853261d83da17b 100644 --- a/devices/devices/sdp/sst.py +++ b/devices/devices/sdp/sst.py @@ -48,6 +48,21 @@ class SST(Statistics): # Device Properties # ----------------- + FPGA_sst_offload_hdr_eth_destination_mac_RW_default = device_property( + dtype='DevVarStringArray', + mandatory=True + ) + + FPGA_sst_offload_hdr_ip_destination_address_RW_default = device_property( + dtype='DevVarStringArray', + mandatory=True + ) + + FPGA_sst_offload_hdr_udp_destination_port_RW_default = device_property( + dtype='DevVarUShortArray', + mandatory=True + ) + # ---------- # Attributes # ---------- diff --git a/devices/toolkit/startup.py b/devices/toolkit/startup.py index 0f4bcbe702b1bd1edb873234763d56455b6009b4..e1cc092b01b3714d80f0b8ca827856bde451c78b 100644 --- a/devices/toolkit/startup.py +++ b/devices/toolkit/startup.py @@ -1,36 +1,49 @@ #! /usr/bin/env python3 +import tango +import logging +logger = logging.getLogger() -def startup(device: str, force_restart: bool): +def startup(device: str, force_restart: bool) -> tango.DeviceProxy: ''' Start a LOFAR Tango device: pcc = startup(device = 'LTS/PCC/1', force_restart = False) ''' - import tango proxy = tango.DeviceProxy(device) state = proxy.state() + # go to OFF, but only if force_restart is True if force_restart is True: - print("Forcing device {} restart.".format(device)) + logger.warning(f"Forcing device {device} restart.") proxy.off() state = proxy.state() if state is not tango._tango.DevState.OFF: - print("Device {} cannot perform off although restart has been enforced, state = {}. Please investigate.".format(device, state)) + logger.error(f"Device {device} cannot perform off although restart has been enforced, state = {state}. Please investigate.") return proxy + if state is not tango._tango.DevState.OFF: - print("Device {} is not in OFF state, cannot start it. state = {}".format(device, state)) + logger.error(f"Device {device} is not in OFF state, cannot start it. state = {state}") return proxy - print("Device {} is in OFF, performing initialisation.".format(device)) + + # Initialise device + logger.info(f"Device {device} is in OFF, performing initialisation.") proxy.initialise() state = proxy.state() if state is not tango._tango.DevState.STANDBY: - print("Device {} cannot perform initialise, state = {}. Please investigate.".format(device, state)) + logger.error(f"Device {device} cannot perform initialise, state = {state}. Please investigate.") return proxy - print("Device {} is in STANDBY, performing on.".format(device)) + + # Set default values + logger.info(f"Device {device} is in STANDBY, setting default values.") + proxy.set_defaults() + + # Turn on device + logger.info(f"Device {device} is in STANDBY, performing on.") proxy.on() state = proxy.state() if state is not tango._tango.DevState.ON: - print("Device {} cannot perform on, state = {}. Please investigate.".format(device, state)) + logger.error(f"Device {device} cannot perform on, state = {state}. Please investigate.") else: - print("Device {} has successfully reached ON state.".format(device)) + logger.info(f"Device {device} has successfully reached ON state.") + return proxy