Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
tango
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LOFAR2.0
tango
Commits
82a7c0f9
Commit
82a7c0f9
authored
3 years ago
by
Taya Snijder
Browse files
Options
Downloads
Patches
Plain Diff
unremoved file
parent
7c6bbb2d
No related branches found
No related tags found
1 merge request
!27
Resolve #2021 "04 16 branched from master apsctl device"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
devices/util/hardware_device.py
+169
-0
169 additions, 0 deletions
devices/util/hardware_device.py
with
169 additions
and
0 deletions
devices/util/hardware_device.py
0 → 100644
+
169
−
0
View file @
82a7c0f9
# -*- coding: utf-8 -*-
#
# This file is part of the PCC project
#
#
#
# Distributed under the terms of the APACHE license.
# See LICENSE.txt for more info.
"""
PCC Device Server for LOFAR2.0
"""
# PyTango imports
from
tango.server
import
Device
,
command
from
tango
import
DevState
,
DebugIt
# Additional import
from
util.attribute_wrapper
import
attribute_wrapper
from
util.lofar_logging
import
log_exceptions
__all__
=
[
"
hardware_device
"
]
from
util.wrappers
import
only_in_states
,
fault_on_error
#@log_exceptions()
class
hardware_device
(
Device
):
"""
**Properties:**
States are as follows:
INIT = Device is initialising.
STANDBY = Device is initialised, but pends external configuration and an explicit turning on,
ON = Device is fully configured, functional, controls the hardware, and is possibly actively running,
FAULT = Device detected an unrecoverable error, and is thus malfunctional,
OFF = Device is turned off, drops connection to the hardware,
The following state transitions are implemented:
boot -> OFF: Triggered by tango. Device will be instantiated,
OFF -> INIT: Triggered by device. Device will initialise (connect to hardware, other devices),
INIT -> STANDBY: Triggered by device. Device is initialised, and is ready for additional configuration by the user,
STANDBY -> ON: Triggered by user. Device reports to be functional,
* -> FAULT: Triggered by device. Device has degraded to malfunctional, for example because the connection to the hardware is lost,
* -> FAULT: Triggered by user. Emulate a forced malfunction for integration testing purposes,
* -> OFF: Triggered by user. Device is turned off. Triggered by the Off() command,
FAULT -> INIT: Triggered by user. Device is reinitialised to recover from an error,
The user triggers their transitions by the commands reflecting the target state (Initialise(), On(), Fault()).
"""
@classmethod
def
attr_list
(
cls
):
"""
Return a list of all the attribute_wrapper members of this class.
"""
return
[
v
for
k
,
v
in
cls
.
__dict__
.
items
()
if
type
(
v
)
==
attribute_wrapper
]
def
setup_value_dict
(
self
):
"""
set the initial value for all the attribute wrapper objects
"""
self
.
value_dict
=
{
i
:
i
.
initial_value
()
for
i
in
self
.
attr_list
()}
def
init_device
(
self
):
"""
Instantiates the device in the OFF state.
"""
# NOTE: Will delete_device first, if necessary
Device
.
init_device
(
self
)
self
.
set_state
(
DevState
.
OFF
)
# --------
# Commands
# --------
@command
()
@only_in_states
([
DevState
.
FAULT
,
DevState
.
OFF
])
@DebugIt
()
@fault_on_error
()
@log_exceptions
()
def
Initialise
(
self
):
"""
Command to ask for initialisation of this device. Can only be called in FAULT or OFF state.
:return:None
"""
self
.
set_state
(
DevState
.
INIT
)
self
.
setup_value_dict
()
self
.
configure_for_initialise
()
self
.
set_state
(
DevState
.
STANDBY
)
@command
()
@only_in_states
([
DevState
.
STANDBY
])
@DebugIt
()
@fault_on_error
()
@log_exceptions
()
def
On
(
self
):
"""
Command to ask for initialisation of this device. Can only be called in FAULT or OFF state.
:return:None
"""
self
.
configure_for_on
()
self
.
set_state
(
DevState
.
ON
)
@command
()
@DebugIt
()
@log_exceptions
()
def
Off
(
self
):
"""
Command to ask for shutdown of this device.
:return:None
"""
if
self
.
get_state
()
==
DevState
.
OFF
:
# Already off. Don't complain.
return
# Turn off
self
.
set_state
(
DevState
.
OFF
)
self
.
configure_for_off
()
# Turn off again, in case of race conditions through reconnecting
self
.
set_state
(
DevState
.
OFF
)
@command
()
@only_in_states
([
DevState
.
ON
,
DevState
.
INIT
,
DevState
.
STANDBY
])
@DebugIt
()
@log_exceptions
()
def
Fault
(
self
):
"""
FAULT state is used to indicate our connection with the OPC-UA server is down.
This device will try to reconnect once, and transition to the ON state on success.
If reconnecting fails, the user needs to call Initialise() to retry to restart this device.
:return:None
"""
self
.
configure_for_fault
()
self
.
set_state
(
DevState
.
FAULT
)
# functions that can be overloaded
def
configure_for_fault
(
self
):
pass
def
configure_for_off
(
self
):
pass
def
configure_for_on
(
self
):
pass
def
configure_for_initialise
(
self
):
pass
def
always_executed_hook
(
self
):
"""
Method always executed before any TANGO command is executed.
"""
pass
def
delete_device
(
self
):
"""
Hook to delete resources allocated in init_device.
This method allows for any memory or other resources allocated in the
init_device method to be released. This method is called by the device
destructor and by the device Init command (a Tango built-in).
"""
self
.
debug_stream
(
"
Shutting down...
"
)
self
.
Off
()
self
.
debug_stream
(
"
Shut down. Good bye.
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment