Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
HEV - High Energy Ventilator
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
5
Issues
5
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
HEV - High Energy Ventilator
Commits
8b4110b1
Commit
8b4110b1
authored
Apr 16, 2021
by
David Meredith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure writer is always closed, make _send_request priv
parent
a87bb8cb
Pipeline
#1275
canceled with stages
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
11 deletions
+15
-11
ClientDebug.py
raspberry-dataserver/ClientDebug.py
+1
-1
hevclient.py
raspberry-dataserver/hevclient.py
+14
-10
No files found.
raspberry-dataserver/ClientDebug.py
View file @
8b4110b1
...
...
@@ -202,7 +202,7 @@ class ClientPlots(QtWidgets.QMainWindow):
client
=
HEVClient
(
polling
=
False
)
# just use hevclient for requests
await
asyncio
.
sleep
(
2
)
# trigger an alarm
await
client
.
send_request
(
"CMD"
,
cmdtype
=
"SET_THRESHOLD_MIN"
,
cmd
=
"APNEA"
,
param
=
0
)
await
client
.
_send_request
(
"CMD"
,
cmdtype
=
"SET_THRESHOLD_MIN"
,
cmd
=
"APNEA"
,
param
=
0
)
while
True
:
await
asyncio
.
sleep
(
60
)
except
Exception
as
e
:
...
...
raspberry-dataserver/hevclient.py
View file @
8b4110b1
...
...
@@ -15,7 +15,7 @@
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with hev-sw. If not, see <http://www.gnu.org/licenses/>.
# with hev-sw. If not, see <http://www.gnu.org/licenses/>
.
#
# The authors would like to acknowledge the much appreciated support
# of all those involved with the High Energy Ventilator project
...
...
@@ -96,6 +96,8 @@ class HEVClient(object):
async
def
polling
(
self
)
->
None
:
"""open persistent connection with server"""
writer
=
None
data
=
None
while
True
:
try
:
reader
,
writer
=
await
asyncio
.
open_connection
(
"127.0.0.1"
,
54320
)
...
...
@@ -150,9 +152,6 @@ class HEVClient(object):
except
KeyError
:
raise
# close connection
writer
.
close
()
await
writer
.
wait_closed
()
except
ConnectionRefusedError
as
e
:
logging
.
error
(
str
(
e
)
+
" - is the microcontroller running?"
)
await
asyncio
.
sleep
(
2
)
...
...
@@ -160,12 +159,17 @@ class HEVClient(object):
# warn and reopen connection
logging
.
error
(
e
)
await
asyncio
.
sleep
(
2
)
finally
:
# close connection
if
writer
is
not
None
:
writer
.
close
()
await
writer
.
wait_closed
()
def
get_updates
(
self
,
payload
)
->
None
:
"""Overrideable function called after receiving data from the socket, with that data as an argument"""
pass
async
def
send_request
(
async
def
_
send_request
(
self
,
reqtype
,
cmdtype
:
str
=
None
,
...
...
@@ -225,19 +229,19 @@ class HEVClient(object):
# print(cmdtype, cmd, param)
try
:
return
asyncio
.
run
(
self
.
send_request
(
"CMD"
,
cmdtype
=
cmdtype
,
cmd
=
cmd
,
param
=
param
)
self
.
_
send_request
(
"CMD"
,
cmdtype
=
cmdtype
,
cmd
=
cmd
,
param
=
param
)
)
except
ConnectionRefusedError
as
error
:
logging
.
error
(
str
(
error
)
+
" - is the microcontroller running?"
)
def
ack_alarm
(
self
,
alarm
:
str
)
->
bool
:
# acknowledge alarm to remove it from the hevserver list
return
asyncio
.
run
(
self
.
send_request
(
"ALARM"
,
alarm
=
alarm
))
return
asyncio
.
run
(
self
.
_
send_request
(
"ALARM"
,
alarm
=
alarm
))
# def send_personal(self, personal: Dict[str, str]=None ) -> bool:
def
send_personal
(
self
,
personal
:
str
)
->
bool
:
# acknowledge alarm to remove it from the hevserver list
return
asyncio
.
run
(
self
.
send_request
(
"PERSONAL"
,
personal
=
personal
))
return
asyncio
.
run
(
self
.
_
send_request
(
"PERSONAL"
,
personal
=
personal
))
def
get_values
(
self
)
->
Dict
:
# get sensor values from db
...
...
@@ -246,12 +250,12 @@ class HEVClient(object):
fastdata
=
pickle
.
load
(
self
.
_mmFile
)
except
pickle
.
UnpicklingError
as
e
:
logging
.
warning
(
f
"Unpicking error {e}"
)
return
None
return
None
# Should return empty dict here?
if
type
(
fastdata
)
is
dict
:
return
fastdata
else
:
logging
.
warning
(
"Missing fastdata"
)
return
None
return
None
# Should return empty dict here?
def
get_readback
(
self
)
->
Dict
:
# get readback from db
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment