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

Merge branch '2021-04-07-cleanup' into 'master'

Generic code cleanup

See merge request !16
parents 734551c7 3612cb18
No related branches found
No related tags found
1 merge request!16Generic code cleanup
Showing
with 68 additions and 38 deletions
File moved
File moved
File moved
File moved
File moved
File moved
...@@ -19,12 +19,12 @@ from tango import AttrWriteType ...@@ -19,12 +19,12 @@ from tango import AttrWriteType
import numpy import numpy
# Additional import # Additional import
from src.wrappers import * from util.wrappers import *
from clients.opcua_connection import OPCUAConnection from clients.opcua_connection import OPCUAConnection
from src.attribute_wrapper import attribute_wrapper from util.attribute_wrapper import attribute_wrapper
from src.hardware_device import hardware_device from util.hardware_device import hardware_device
from src.lofar_logging import device_logging_to_python from util.lofar_logging import device_logging_to_python, log_exceptions
__all__ = ["PCC", "main"] __all__ = ["PCC", "main"]
...@@ -100,6 +100,7 @@ class PCC(hardware_device): ...@@ -100,6 +100,7 @@ class PCC(hardware_device):
RCU_monitor_rate_RW = attribute_wrapper(comms_annotation=["2:PCC", "2:RCU_monitor_rate_RW"], datatype=numpy.float64, RCU_monitor_rate_RW = attribute_wrapper(comms_annotation=["2:PCC", "2:RCU_monitor_rate_RW"], datatype=numpy.float64,
access=AttrWriteType.READ_WRITE) access=AttrWriteType.READ_WRITE)
@log_exceptions()
def delete_device(self): def delete_device(self):
"""Hook to delete resources allocated in init_device. """Hook to delete resources allocated in init_device.
...@@ -115,11 +116,13 @@ class PCC(hardware_device): ...@@ -115,11 +116,13 @@ class PCC(hardware_device):
# -------- # --------
# overloaded functions # overloaded functions
# -------- # --------
@log_exceptions()
def off(self): def off(self):
""" user code here. is called when the state is set to OFF """ """ user code here. is called when the state is set to OFF """
# Stop keep-alive # Stop keep-alive
self.OPCua_client.stop() self.OPCua_client.stop()
@log_exceptions()
def initialise(self): def initialise(self):
""" user code here. is called when the state is set to INIT """ """ user code here. is called when the state is set to INIT """
...@@ -146,13 +149,15 @@ class PCC(hardware_device): ...@@ -146,13 +149,15 @@ class PCC(hardware_device):
self.OPCua_client.start() self.OPCua_client.start()
# -------- # --------
# Commands # Commands
# -------- # --------
@command() @command()
@DebugIt() @DebugIt()
@only_when_on @only_when_on()
@fault_on_error @fault_on_error()
def RCU_off(self): def RCU_off(self):
""" """
...@@ -162,8 +167,8 @@ class PCC(hardware_device): ...@@ -162,8 +167,8 @@ class PCC(hardware_device):
@command() @command()
@DebugIt() @DebugIt()
@only_when_on @only_when_on()
@fault_on_error @fault_on_error()
def RCU_on(self): def RCU_on(self):
""" """
...@@ -173,8 +178,8 @@ class PCC(hardware_device): ...@@ -173,8 +178,8 @@ class PCC(hardware_device):
@command() @command()
@DebugIt() @DebugIt()
@only_when_on @only_when_on()
@fault_on_error @fault_on_error()
def ADC_on(self): def ADC_on(self):
""" """
...@@ -184,8 +189,8 @@ class PCC(hardware_device): ...@@ -184,8 +189,8 @@ class PCC(hardware_device):
@command() @command()
@DebugIt() @DebugIt()
@only_when_on @only_when_on()
@fault_on_error @fault_on_error()
def RCU_update(self): def RCU_update(self):
""" """
...@@ -195,8 +200,8 @@ class PCC(hardware_device): ...@@ -195,8 +200,8 @@ class PCC(hardware_device):
@command() @command()
@DebugIt() @DebugIt()
@only_when_on @only_when_on()
@fault_on_error @fault_on_error()
def CLK_off(self): def CLK_off(self):
""" """
...@@ -206,8 +211,8 @@ class PCC(hardware_device): ...@@ -206,8 +211,8 @@ class PCC(hardware_device):
@command() @command()
@DebugIt() @DebugIt()
@only_when_on @only_when_on()
@fault_on_error @fault_on_error()
def CLK_on(self): def CLK_on(self):
""" """
...@@ -217,8 +222,8 @@ class PCC(hardware_device): ...@@ -217,8 +222,8 @@ class PCC(hardware_device):
@command() @command()
@DebugIt() @DebugIt()
@only_when_on @only_when_on()
@fault_on_error @fault_on_error()
def CLK_PLL_setup(self): def CLK_PLL_setup(self):
""" """
......
...@@ -18,10 +18,10 @@ from tango import AttrWriteType ...@@ -18,10 +18,10 @@ from tango import AttrWriteType
# Additional import # Additional import
from clients.opcua_connection import OPCUAConnection from clients.opcua_connection import OPCUAConnection
from src.attribute_wrapper import attribute_wrapper from util.attribute_wrapper import attribute_wrapper
from src.hardware_device import hardware_device from util.hardware_device import hardware_device
from src.lofar_logging import device_logging_to_python from util.lofar_logging import device_logging_to_python, log_exceptions
import numpy import numpy
...@@ -82,6 +82,7 @@ class SDP(hardware_device): ...@@ -82,6 +82,7 @@ class SDP(hardware_device):
"""Method always executed before any TANGO command is executed.""" """Method always executed before any TANGO command is executed."""
pass pass
@log_exceptions()
def delete_device(self): def delete_device(self):
"""Hook to delete resources allocated in init_device. """Hook to delete resources allocated in init_device.
...@@ -97,15 +98,17 @@ class SDP(hardware_device): ...@@ -97,15 +98,17 @@ class SDP(hardware_device):
# -------- # --------
# overloaded functions # overloaded functions
# -------- # --------
@log_exceptions()
def off(self): def off(self):
""" user code here. is called when the state is set to OFF """ """ user code here. is called when the state is set to OFF """
# Stop keep-alive # Stop keep-alive
self.opcua_connection.stop() self.opcua_connection.stop()
@log_exceptions()
def initialise(self): def initialise(self):
""" user code here. is called when the sate is set to INIT """ """ user code here. is called when the sate is set to INIT """
"""Initialises the attributes and properties of the PCC.""" """Initialises the attributes and properties of the SDP."""
# set up the OPC ua client # set up the OPC ua client
self.OPCua_client = OPCUAConnection("opc.tcp://{}:{}/".format(self.OPC_Server_Name, self.OPC_Server_Port), "http://lofar.eu", self.OPC_Time_Out, self.Fault, self) self.OPCua_client = OPCUAConnection("opc.tcp://{}:{}/".format(self.OPC_Server_Name, self.OPC_Server_Port), "http://lofar.eu", self.OPC_Time_Out, self.Fault, self)
......
from ._version import get_versions
__version__ = get_versions()['version']
del get_versions
from threading import Thread from threading import Thread
import socket import socket
from src.comms_client import CommClient from util.comms_client import CommClient
import numpy import numpy
import opcua import opcua
from opcua import Client from opcua import Client
......
from src.comms_client import CommClient from util.comms_client import CommClient
import numpy import numpy
import os import os
......
...@@ -14,8 +14,8 @@ from tango.server import run ...@@ -14,8 +14,8 @@ from tango.server import run
from tango import AttrWriteType from tango import AttrWriteType
# Additional import # Additional import
from src.attribute_wrapper import attribute_wrapper from util.attribute_wrapper import attribute_wrapper
from src.hardware_device import hardware_device from util.hardware_device import hardware_device
__all__ = ["HW_dev"] __all__ = ["HW_dev"]
......
# See the docstring in versioneer.py for instructions. Note that you must
# re-run 'versioneer.py setup' after changing this section, and commit the
# resulting files.
[versioneer]
#VCS = git
#style = pep440
#versionfile_source =
#versionfile_build =
#tag_prefix =
#parentdir_prefix =
...@@ -17,8 +17,8 @@ from tango import DevState ...@@ -17,8 +17,8 @@ from tango import DevState
# Additional import # Additional import
from clients.test_client import test_client from clients.test_client import test_client
from src.attribute_wrapper import * from util.attribute_wrapper import *
from src.hardware_device import * from util.hardware_device import *
__all__ = ["test_device", "main"] __all__ = ["test_device", "main"]
......
File moved
...@@ -3,7 +3,7 @@ from tango import AttrWriteType ...@@ -3,7 +3,7 @@ from tango import AttrWriteType
import numpy import numpy
from src.wrappers import only_when_on, fault_on_error from util.wrappers import only_when_on, fault_on_error
import logging import logging
logger = logging.getLogger() logger = logging.getLogger()
...@@ -61,8 +61,8 @@ class attribute_wrapper(attribute): ...@@ -61,8 +61,8 @@ class attribute_wrapper(attribute):
if access == AttrWriteType.READ_WRITE: if access == AttrWriteType.READ_WRITE:
""" if the attribute is of READ_WRITE type, assign the RW and write function to it""" """ if the attribute is of READ_WRITE type, assign the RW and write function to it"""
@only_when_on @only_when_on()
@fault_on_error @fault_on_error()
def read_RW(device): def read_RW(device):
# print("read_RW {}, {}x{}, {}, {}".format(me.name, me.dim_x, me.dim_y, me.attr_type, me.value)) # print("read_RW {}, {}x{}, {}, {}".format(me.name, me.dim_x, me.dim_y, me.attr_type, me.value))
""" """
...@@ -74,8 +74,8 @@ class attribute_wrapper(attribute): ...@@ -74,8 +74,8 @@ class attribute_wrapper(attribute):
raise Exception("Attribute read_RW function error, attempted to read value_dict with key: `%s`, are you sure this exists?", raise Exception("Attribute read_RW function error, attempted to read value_dict with key: `%s`, are you sure this exists?",
self) from e self) from e
@only_when_on @only_when_on()
@fault_on_error @fault_on_error()
def write_RW(device, value): def write_RW(device, value):
""" """
_write_RW writes a value to this attribute _write_RW writes a value to this attribute
...@@ -91,8 +91,8 @@ class attribute_wrapper(attribute): ...@@ -91,8 +91,8 @@ class attribute_wrapper(attribute):
else: else:
""" if the attribute is of READ type, assign the read function to it""" """ if the attribute is of READ type, assign the read function to it"""
@only_when_on @only_when_on()
@fault_on_error @fault_on_error()
def read_R(device): def read_R(device):
""" """
_read_R reads the attribute value, stores it and returns it" _read_R reads the attribute value, stores it and returns it"
......
File moved
...@@ -16,12 +16,12 @@ from tango.server import Device, command ...@@ -16,12 +16,12 @@ from tango.server import Device, command
from tango import DevState, DebugIt from tango import DevState, DebugIt
# Additional import # Additional import
from src.attribute_wrapper import attribute_wrapper from util.attribute_wrapper import attribute_wrapper
from src.lofar_logging import log_exceptions from util.lofar_logging import log_exceptions
__all__ = ["hardware_device"] __all__ = ["hardware_device"]
from src.wrappers import only_in_states from util.wrappers import only_in_states, fault_on_error
#@log_exceptions() #@log_exceptions()
class hardware_device(Device): class hardware_device(Device):
...@@ -74,6 +74,8 @@ class hardware_device(Device): ...@@ -74,6 +74,8 @@ class hardware_device(Device):
@command() @command()
@only_in_states([DevState.FAULT, DevState.OFF]) @only_in_states([DevState.FAULT, DevState.OFF])
@DebugIt() @DebugIt()
@fault_on_error()
@log_exceptions()
def Initialise(self): def Initialise(self):
""" """
Command to ask for initialisation of this device. Can only be called in FAULT or OFF state. Command to ask for initialisation of this device. Can only be called in FAULT or OFF state.
...@@ -90,6 +92,8 @@ class hardware_device(Device): ...@@ -90,6 +92,8 @@ class hardware_device(Device):
@command() @command()
@only_in_states([DevState.STANDBY]) @only_in_states([DevState.STANDBY])
@DebugIt() @DebugIt()
@fault_on_error()
@log_exceptions()
def On(self): def On(self):
""" """
Command to ask for initialisation of this device. Can only be called in FAULT or OFF state. Command to ask for initialisation of this device. Can only be called in FAULT or OFF state.
...@@ -101,6 +105,7 @@ class hardware_device(Device): ...@@ -101,6 +105,7 @@ class hardware_device(Device):
@command() @command()
@DebugIt() @DebugIt()
@log_exceptions()
def Off(self): def Off(self):
""" """
Command to ask for shutdown of this device. Command to ask for shutdown of this device.
...@@ -122,6 +127,7 @@ class hardware_device(Device): ...@@ -122,6 +127,7 @@ class hardware_device(Device):
@command() @command()
@only_in_states([DevState.ON, DevState.INIT, DevState.STANDBY]) @only_in_states([DevState.ON, DevState.INIT, DevState.STANDBY])
@DebugIt() @DebugIt()
@log_exceptions()
def Fault(self): def Fault(self):
""" """
FAULT state is used to indicate our connection with the OPC-UA server is down. FAULT state is used to indicate our connection with the OPC-UA server is down.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment