Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
Schrankenwaerter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
vaclab
Schrankenwaerter
Commits
77441937
There was a problem fetching the pipeline summary.
Commit
77441937
authored
8 years ago
by
stephanputzke
Browse files
Options
Downloads
Patches
Plain Diff
Better error handling in case cluster is offline
parent
22d17acf
No related branches found
No related tags found
No related merge requests found
Pipeline
#
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ValveClusterServer.py
+39
-9
39 additions, 9 deletions
ValveClusterServer.py
observer.html
+10
-2
10 additions, 2 deletions
observer.html
with
49 additions
and
11 deletions
ValveClusterServer.py
+
39
−
9
View file @
77441937
...
...
@@ -25,6 +25,8 @@ def isValidValveNumString(num):
def
errorNotAValidValveNumber
(
num
):
return
'
%s not a number or not in allowed range [1-24]
'
%
num
clusterOfflineError
=
{
'
success
'
:
False
,
'
status
'
:
'
Valvecluster is offline
'
}
#####
# Define routes
...
...
@@ -44,6 +46,8 @@ Get description of all valves
@get
(
'
/description
'
)
def
recipe_description
():
valveStates
=
getValveStates
()
if
valveStates
is
None
:
return
{
'
success
'
:
False
,
'
version
'
:
1.1
,
'
name
'
:
'
Schrankenwaerter
'
,
'
status
'
:
'
Valvecluster is offline
'
}
valveNums
=
range
(
1
,
len
(
valveStates
)
+
1
)
valves
=
{
...
...
@@ -114,6 +118,9 @@ Get state of one or all control valves
def
recipe_controlValveState
(
num
=
None
):
valveStates
=
getControlValveStates
()
if
valveStates
is
None
:
return
clusterOfflineError
if
num
is
None
:
return
{
'
success
'
:
True
,
'
state
'
:
dict
(
zip
(
range
(
1
,
len
(
valveStates
)
+
1
),
valveStates
))
}
...
...
@@ -133,6 +140,9 @@ of each valve
def
recipe_valveState
(
num
=
None
):
valveStates
=
getValveStates
()
if
valveStates
is
None
:
return
clusterOfflineError
if
num
is
None
:
return
{
'
success
'
:
True
,
'
state
'
:
dict
(
zip
(
range
(
1
,
len
(
valveStates
)
+
1
),
valveStates
))
}
if
not
isValidValveNumString
(
num
):
...
...
@@ -166,19 +176,24 @@ def recipe_canOpenCloseValve(num,action):
def
send
(
command
):
url
=
'
http://10.0.0.31/http_in_ci?ci:%s
'
%
command
content
=
None
try
:
content
=
urllib2
.
urlopen
(
url
,
timeout
=
0.2
).
read
()
except
urllib2
.
URLError
,
e
:
# For Python 2.6
if
isinstance
(
e
.
reason
,
socket
.
timeout
):
print
'
timeout
'
,
e
return
None
else
:
print
'
urlerror:
'
,
e
#return None
except
httplib
.
BadStatusLine
as
e
:
#print e.args
return
None
print
e
#return None
except
:
import
sys
print
"
Unexpected error:
"
,
sys
.
exc_info
()[
0
]
#print content
#print
'Content:',
content
return
content
def
int2bitField
(
n
):
...
...
@@ -276,11 +291,19 @@ def getControlValveStates():
# 6 = 255 = 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
state
=
send
(
'
DAW%i
'
%
unitNum
)[
1
:]
# Cluster returns sth like '=130'
# -> chop of leading '='
state
=
send
(
'
DAW%i
'
%
unitNum
)
if
state
==
None
:
# Cluster is offline!
return
None
state
=
state
[
1
:]
# Cluster returns sth like '=130'
# -> chop of leading '='
return
int2bitField
(
int
(
state
))[:
8
]
# only first 8 bits are used
states
=
[
getControlValveState
(
unitNum
)
for
unitNum
in
ausgangsWort
]
for
state
in
states
:
if
state
is
None
:
# Cluster is offline!
return
None
states
=
[
item
for
sublist
in
states
for
item
in
sublist
]
states
=
states
[:
32
:
2
]
+
states
[
32
:]
...
...
@@ -307,11 +330,18 @@ def getValveStates():
'''
assert
(
unitNum
in
eingangsWort
),
\
'
Unit number not in range of allowed eingangswörter
'
state
=
send
(
'
DEW%i
'
%
unitNum
)[
1
:]
# Cluster returns sth like '=130'
# -> chop of leading '='
state
=
send
(
'
DEW%i
'
%
unitNum
)
if
state
==
None
:
# Cluster is offline!
return
None
state
=
state
[
1
:]
# Cluster returns sth like '=130'
# -> chop of leading '='
return
int2bitField
(
int
(
state
))
states
=
np
.
array
([
getUnitState
(
unitNum
)
for
unitNum
in
eingangsWort
])
for
state
in
states
:
if
state
is
None
:
# Cluster is offline!
return
None
states
=
states
.
reshape
(
-
1
,
2
)
def
stateListToNumber
(
state
):
...
...
This diff is collapsed.
Click to expand it.
observer.html
+
10
−
2
View file @
77441937
...
...
@@ -61,8 +61,11 @@
// Look for Schrankenwärter server. If found, adjust connect button and set up the valve list.
function
openConnectionToSchrankenwarter
()
{
// If connection is already open then close it (toggle open/close state)
if
(
$
(
'
#connectButton
'
).
button
(
"
option
"
,
"
label
"
)
==
'
Connect
'
)
{
if
(
$
(
'
#connectButton
'
).
button
(
"
option
"
,
"
label
"
)
==
'
Connect
'
)
{
//Lousy definition of state...
$
(
'
#statusTextField
'
).
text
(
'
Status: Connecting...
'
)
if
(
$
(
'
#buttoncontainer
'
).
is
(
'
:empty
'
)){
setupValveList
();
}
$
.
getJSON
(
inselAdresse
+
'
description
'
,
function
(
data
)
{
console
.
log
(
data
)
...
...
@@ -78,6 +81,8 @@
refreshIntervalId
=
setInterval
(
function
()
{
updateValveStates
()
},
200
)
}
else
{
$
(
'
#statusTextField
'
).
text
(
'
Status:
'
+
data
.
status
)
}
}
).
error
(
function
()
{
closeConnectionToSchrankenwarter
();
})
...
...
@@ -102,7 +107,7 @@
function
setupValveList
()
{
$
.
getJSON
(
inselAdresse
+
'
description
'
,
function
(
data
)
{
if
(
data
.
success
!=
tru
e
)
{
if
(
data
.
success
==
fals
e
)
{
$
(
'
#statusTextField
'
).
text
(
'
Error during communication with valve cluster
'
);
console
.
log
(
'
Communication error, response of valve cluster:
'
+
data
);
}
else
{
...
...
@@ -155,6 +160,9 @@
listItem
.
removeClass
(
classes
).
addClass
(
'
undef
'
);
}
})
}
else
{
console
.
log
(
'
Error in updateValveStates, cluster seems to be offline
'
);
closeConnectionToSchrankenwarter
()
}
}).
error
(
function
()
{
console
.
log
(
'
Error in updateValveStates
'
);
...
...
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