Skip to content
Snippets Groups Projects
Commit 289d18c6 authored by Jan David Mol's avatar Jan David Mol
Browse files

L2SS-337: Fix writing of a device's own attributes. Turns out, we need to...

L2SS-337: Fix writing of a device's own attributes. Turns out, we need to setup a DeviceProxy pointing to ourselves.
parent f8af2505
No related branches found
No related tags found
1 merge request!98L2SS-337: Add useful static defaults to some of our attributes
......@@ -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"
]
}
}
......
......@@ -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
......@@ -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
# ----------
......
......@@ -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
# ----------
......
#! /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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment