Skip to content
GitLab
Explore
Sign in
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
0afb2183
Commit
0afb2183
authored
4 years ago
by
Thomas Juerges
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' into 2021-01-14-pypcc2
parents
093d2b5b
0b73e774
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!2
Refactor for Paulus' pypcc2 version with arrays
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+3
-0
3 additions, 0 deletions
.gitignore
RCUSCC/RCUSCC/RCUSCC.py
+66
-17
66 additions, 17 deletions
RCUSCC/RCUSCC/RCUSCC.py
RCUSCC/RCUSCC/wrappers.py
+17
-1
17 additions, 1 deletion
RCUSCC/RCUSCC/wrappers.py
with
86 additions
and
18 deletions
.gitignore
+
3
−
0
View file @
0afb2183
...
...
@@ -3,3 +3,6 @@
**/__pycache__
**/env
**/vscode-server.tar
**/.project
**/.pydevproject
**/.settings/org.eclipse.core.resources.prefs
This diff is collapsed.
Click to expand it.
RCUSCC/RCUSCC/RCUSCC.py
+
66
−
17
View file @
0afb2183
...
...
@@ -25,7 +25,7 @@ import sys
import
opcua
import
numpy
from
wrappers
import
only_when_on
,
fault_on_error
from
wrappers
import
only_in_states
,
only_when_on
,
fault_on_error
from
opcua_connection
import
OPCUAConnection
__all__
=
[
"
RCUSCC
"
,
"
main
"
]
...
...
@@ -42,6 +42,25 @@ class RCUSCC(Device):
- Type:
'
DevULong
'
OPC_Time_Out
- Type:
'
DevDouble
'
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 (Init(), On(), Fault()).
"""
client
=
0
name_space_index
=
0
...
...
@@ -245,11 +264,16 @@ class RCUSCC(Device):
self
.
debug_stream
(
"
Mapping OPC-UA MP/CP to attributes done.
"
)
def
init_device
(
self
):
"""
In
itialises the attributes and properties of the RCUSCC.
"""
"""
In
stantiates the device in the OFF state.
"""
# NOTE: Will delete_device first, if necessary
Device
.
init_device
(
self
)
self
.
set_state
(
DevState
.
OFF
)
def
initialise
(
self
):
"""
Initialises the attributes and properties of the RCUSCC.
"""
self
.
set_state
(
DevState
.
INIT
)
# Init the dict that contains attribute to OPC-UA MP/CP mappings.
...
...
@@ -323,9 +347,10 @@ class RCUSCC(Device):
self
.
client
=
opcua
.
Client
(
"
opc.tcp://{}:{}/
"
.
format
(
self
.
OPC_Server_Name
,
self
.
OPC_Server_Port
),
self
.
OPC_Time_Out
)
# timeout in seconds
# Connect to OPC-UA -- will set ON state on success
self
.
opcua_connection
=
OPCUAConnection
(
self
.
client
,
self
.
On
,
self
.
Fault
,
self
)
# Connect to OPC-UA -- will set ON state on success
in case of a reconnect
self
.
opcua_connection
=
OPCUAConnection
(
self
.
client
,
self
.
Standby
,
self
.
Fault
,
self
)
# Explicitly connect
if
not
self
.
opcua_connection
.
connect
():
# hardware or infra is down -- needs fixing first
self
.
Fault
()
...
...
@@ -342,22 +367,14 @@ class RCUSCC(Device):
# Start keep-alive
self
.
opcua_connection
.
start
()
# Everything went ok -- go online
self
.
On
()
# Set the masks
# TODO
# Read default masks from config DB
self
.
write_RCU_mask_RW
(
self
.
_RCU_mask_RW
)
self
.
write_Ant_mask_RW
(
self
.
_Ant_mask_RW
)
@DebugIt
()
def
On
(
self
):
"""
:return:None
"""
self
.
set_state
(
DevState
.
ON
)
# Everything went ok -- go standby.
self
.
set_state
(
DevState
.
STANDBY
)
def
always_executed_hook
(
self
):
...
...
@@ -583,23 +600,53 @@ class RCUSCC(Device):
@command
(
)
@only_in_states
([
DevState
.
FAULT
,
DevState
.
OFF
])
@DebugIt
()
def
Init
(
self
):
"""
Command to ask for initialisation of this device. Can only be called in FAULT or OFF state.
:return:None
"""
self
.
initialise
()
@only_in_states
([
DevState
.
INIT
])
def
Standby
(
self
):
"""
Command to ask for initialisation of this device. Can only be called in FAULT or OFF state.
:return:None
"""
self
.
init_device
()
self
.
set_state
(
DevState
.
STANDBY
)
@command
(
)
@only_in_states
([
DevState
.
STANDBY
])
@DebugIt
()
def
On
(
self
):
"""
Command to ask for initialisation of this device. Can only be called in FAULT or OFF state.
:return:None
"""
self
.
set_state
(
DevState
.
ON
)
@command
(
)
@DebugIt
()
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
)
...
...
@@ -609,15 +656,17 @@ class RCUSCC(Device):
# 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
()
def
Fault
(
self
):
"""
FAULT state is used to indicate our connection with the OPC-UA server is down.
This device will try to reconnect, and transition to the ON state on success.
This device will try to reconnect once, and transition to the ON state on success.
If reconnecting fails, the user needs to call Init() to retry to restart this device.
:return:None
"""
...
...
This diff is collapsed.
Click to expand it.
RCUSCC/RCUSCC/wrappers.py
+
17
−
1
View file @
0afb2183
...
...
@@ -2,7 +2,23 @@ from tango import DevState
from
functools
import
wraps
import
traceback
__all__
=
[
"
only_when_on
"
,
"
fault_on_error
"
]
__all__
=
[
"
only_in_states
"
,
"
only_when_on
"
,
"
fault_on_error
"
]
def
only_in_states
(
func
,
allowed_states
):
"""
Wrapper to return None when the device isn
'
t in ON state.
If in ON state, calls & returns the wrapped function.
"""
@wraps
(
func
)
def
state_check_wrapper
(
self
,
*
args
,
**
kwargs
):
if
self
.
get_state
()
not
in
allowed_states
:
return
None
return
func
(
self
,
*
args
,
**
kwargs
)
return
state_check_wrapper
def
only_when_on
(
func
):
"""
...
...
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