Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
HEV - High Energy Ventilator
Manage
Activity
Members
Labels
Plan
Issues
5
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor 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
Projects
HEV - High Energy Ventilator
Commits
bf960b3e
Commit
bf960b3e
authored
4 years ago
by
Dónal Murray
Browse files
Options
Downloads
Patches
Plain Diff
Fix event checking and nullbyte termination
parent
9f6a5546
Branches
Branches containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
raspberry-dataserver/hevclient.py
+3
-3
3 additions, 3 deletions
raspberry-dataserver/hevclient.py
raspberry-dataserver/hevserver.py
+5
-3
5 additions, 3 deletions
raspberry-dataserver/hevserver.py
with
8 additions
and
6 deletions
raspberry-dataserver/hevclient.py
+
3
−
3
View file @
bf960b3e
...
...
@@ -40,7 +40,7 @@ class HEVClient(object):
# grab data from the socket as soon as it is available and dump it in the db
while
self
.
_polling
:
try
:
data
=
await
reader
.
readuntil
(
b
'
\0
'
)
data
=
await
reader
.
readuntil
(
separator
=
b
'
\0
'
)
data
=
data
[:
-
1
]
# snip off nullbyte
payload
=
json
.
loads
(
data
.
decode
(
"
utf-8
"
))
if
payload
[
"
type
"
]
==
"
keepalive
"
:
...
...
@@ -92,13 +92,13 @@ class HEVClient(object):
}
logging
.
info
(
payload
)
packet
=
json
.
dumps
(
payload
).
encode
()
packet
=
json
.
dumps
(
payload
).
encode
()
+
b
'
\0
'
writer
.
write
(
packet
)
await
writer
.
drain
()
# wait for acknowledge
data
=
await
reader
.
read
_
until
(
b
'
\0
'
)
data
=
await
reader
.
readuntil
(
separator
=
b
'
\0
'
)
data
=
data
[:
-
1
]
try
:
data
=
json
.
loads
(
data
.
decode
(
"
utf-8
"
))
...
...
This diff is collapsed.
Click to expand it.
raspberry-dataserver/hevserver.py
+
5
−
3
View file @
bf960b3e
...
...
@@ -76,7 +76,7 @@ class HEVServer(object):
async
def
handle_request
(
self
,
reader
:
asyncio
.
StreamReader
,
writer
:
asyncio
.
StreamWriter
)
->
None
:
# listen for queries on the request socket
data
=
await
reader
.
read
_
until
(
b
'
\0
'
)
data
=
await
reader
.
readuntil
(
separator
=
b
'
\0
'
)
data
=
data
[:
-
1
]
# snip off nullbyte
request
=
json
.
loads
(
data
.
decode
(
"
utf-8
"
))
...
...
@@ -133,7 +133,7 @@ class HEVServer(object):
payload
=
{
"
type
"
:
"
nack
"
}
# send reply and close connection
packet
=
json
.
dumps
(
payload
).
encode
()
packet
=
json
.
dumps
(
payload
).
encode
()
+
b
'
\0
'
writer
.
write
(
packet
)
await
writer
.
drain
()
writer
.
close
()
...
...
@@ -146,13 +146,15 @@ class HEVServer(object):
while
self
.
_broadcasting
:
# wait for data from serial port
# set timeout such that there is never pileup
if
not
self
.
_datavalid
.
is_set
:
if
not
self
.
_datavalid
.
is_set
()
:
# make sure client is still connected
await
asyncio
.
sleep
(
0.05
)
broadcast_packet
=
{
"
type
"
:
"
keepalive
"
}
else
:
# take lock of db and prepare packet
with
self
.
_dblock
:
if
self
.
_values
is
None
:
continue
# should never get here
values
:
List
[
float
]
=
self
.
_values
alarms
=
self
.
_alarms
if
len
(
self
.
_alarms
)
>
0
else
None
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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