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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LOFAR2.0
tango
Commits
bd1a51d8
Commit
bd1a51d8
authored
Jan 13, 2021
by
Jan David Mol
Browse files
Options
Downloads
Patches
Plain Diff
Added comments for state and state transitions
parent
69403aa1
No related branches found
No related tags found
1 merge request
!1
State management
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
RCUSCC/RCUSCC/RCUSCC.py
+28
-6
28 additions, 6 deletions
RCUSCC/RCUSCC/RCUSCC.py
with
28 additions
and
6 deletions
RCUSCC/RCUSCC/RCUSCC.py
+
28
−
6
View file @
bd1a51d8
...
@@ -42,6 +42,21 @@ class RCUSCC(Device):
...
@@ -42,6 +42,21 @@ class RCUSCC(Device):
- Type:
'
DevULong
'
- Type:
'
DevULong
'
OPC_Time_Out
OPC_Time_Out
- Type:
'
DevDouble
'
- Type:
'
DevDouble
'
States are as follows:
ON = Device is functional and controls the hardware,
OFF = Device is turned off, drops connection to the hardware,
FAULT = Device detected an unrecoverable error, and is malfunctional,
INIT = Device is initialising.
The following state transitions are implemented:
boot -> INIT: Device will initialise when it is started,
INIT -> ON: Device will report to be functional when initialisation succeeds
INIT -> FAULT: Device will degrade to malfunctional if initialisation fails
ON -> FAULT: Device will degrade to malfunctional if an unrecoverable error is encountered
* -> OFF: Device is turned off. Triggered by the Off() command.
FAULT -> INIT: Device is reinitialised to recover from an error. Triggered by the Init() command.
OFF -> INIT: Device is turned on again. Triggered by the Init() command.
"""
"""
client
=
0
client
=
0
name_space_index
=
0
name_space_index
=
0
...
@@ -258,11 +273,11 @@ class RCUSCC(Device):
...
@@ -258,11 +273,11 @@ 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
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
# Connect to OPC-UA -- will set ON state on success
self
.
opcua_connection
=
OPCUAConnection
(
self
.
client
,
self
.
On
,
self
.
Fault
,
self
)
self
.
opcua_connection
=
OPCUAConnection
(
self
.
client
,
self
.
On
,
self
.
_
Fault
,
self
)
if
not
self
.
opcua_connection
.
connect
():
if
not
self
.
opcua_connection
.
connect
():
# hardware or infra is down -- needs fixing first
# hardware or infra is down -- needs fixing first
self
.
Fault
()
self
.
_
Fault
()
return
return
# Retrieve and map server attributes
# Retrieve and map server attributes
...
@@ -270,7 +285,7 @@ class RCUSCC(Device):
...
@@ -270,7 +285,7 @@ class RCUSCC(Device):
self
.
_map_attributes
()
self
.
_map_attributes
()
except
Exception
as
e
:
except
Exception
as
e
:
self
.
error_stream
(
"
Could not map server interface: %s
"
,
e
)
self
.
error_stream
(
"
Could not map server interface: %s
"
,
e
)
self
.
Fault
()
self
.
_
Fault
()
return
return
# Start keep-alive
# Start keep-alive
...
@@ -428,6 +443,7 @@ class RCUSCC(Device):
...
@@ -428,6 +443,7 @@ class RCUSCC(Device):
@DebugIt
()
@DebugIt
()
def
Init
(
self
):
def
Init
(
self
):
"""
"""
Command to ask for initialisation of this device. Can only be called in FAULT or OFF state.
:return:None
:return:None
"""
"""
...
@@ -436,13 +452,17 @@ class RCUSCC(Device):
...
@@ -436,13 +452,17 @@ class RCUSCC(Device):
@command
(
@command
(
)
)
@only_in_states
([
DevState
.
INIT
,
DevState
.
ON
,
DevState
.
FAULT
])
@DebugIt
()
@DebugIt
()
def
Off
(
self
):
def
Off
(
self
):
"""
"""
Command to ask for shutdown of this device.
:return:None
:return:None
"""
"""
if
self
.
get_state
()
==
DevState
.
OFF
:
# Already off. Don't complain.
return
# Turn off
# Turn off
self
.
set_state
(
DevState
.
OFF
)
self
.
set_state
(
DevState
.
OFF
)
...
@@ -453,11 +473,13 @@ class RCUSCC(Device):
...
@@ -453,11 +473,13 @@ class RCUSCC(Device):
self
.
set_state
(
DevState
.
OFF
)
self
.
set_state
(
DevState
.
OFF
)
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.
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
:return:None
"""
"""
...
...
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