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
d0ea78fa
Unverified
Commit
d0ea78fa
authored
4 years ago
by
Dónal Murray
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #24 from chrisburr/hevfromtxt-time
Add hevserver.py --debug and make hevfromtxt set timestamps correctly
parents
d80fad65
97aaef88
Branches
Branches containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
raspberry-dataserver/hevfromtxt.py
+14
-10
14 additions, 10 deletions
raspberry-dataserver/hevfromtxt.py
raspberry-dataserver/hevserver.py
+9
-6
9 additions, 6 deletions
raspberry-dataserver/hevserver.py
with
23 additions
and
16 deletions
raspberry-dataserver/hevfromtxt.py
+
14
−
10
View file @
d0ea78fa
...
...
@@ -25,7 +25,7 @@ class hevfromtxt():
self
.
_volume
=
h
[:,
3
].
tolist
()
self
.
_length
=
len
(
self
.
_pressure
)
self
.
_pos
=
0
# position within sample
self
.
_
delay
=
0.2
# time period
self
.
_
increment
=
1
# received queue and observers to be notified on update
self
.
_payloadrecv
=
deque
(
maxlen
=
16
)
...
...
@@ -34,22 +34,26 @@ class hevfromtxt():
sendingWorker
.
start
()
def
generate
(
self
)
->
None
:
time_offset
=
0
while
True
:
# grab next array from filedump
increment
=
int
(
round
(
self
.
_delay
/
0.2
))
increment
=
1
if
increment
<
1
else
increment
self
.
_pos
=
self
.
_pos
+
increment
if
self
.
_pos
+
increment
<
self
.
_length
else
0
payload
=
CommsCommon
.
DataFormat
()
# directly setting private member variables in this edge case
payload
=
CommsCommon
.
DataFormat
()
payload
.
_version
=
payload
.
_RPI_VERSION
payload
.
_timestamp
=
self
.
_timestamp
[
self
.
_pos
]
payload
.
_timestamp
=
time_offset
+
self
.
_timestamp
[
self
.
_pos
]
payload
.
_pressure_buffer
=
self
.
_pressure
[
self
.
_pos
]
payload
.
_pressure_inhale
=
self
.
_volume
[
self
.
_pos
]
payload
.
_temperature_buffer
=
self
.
_flow
[
self
.
_pos
]
self
.
payloadrecv
=
payload
time
.
sleep
(
self
.
_delay
)
if
self
.
_pos
+
self
.
_increment
<
self
.
_length
:
delay
=
self
.
_timestamp
[
self
.
_pos
+
self
.
_increment
]
-
self
.
_timestamp
[
self
.
_pos
]
self
.
_pos
=
self
.
_pos
+
self
.
_increment
else
:
delay
=
self
.
_timestamp
[
self
.
_pos
]
-
self
.
_timestamp
[
self
.
_pos
-
self
.
_increment
]
time_offset
+=
self
.
_timestamp
[
self
.
_pos
]
self
.
_pos
=
0
time
.
sleep
(
delay
)
# callback to dependants to read the received payload
@property
...
...
This diff is collapsed.
Click to expand it.
raspberry-dataserver/hevserver.py
+
9
−
6
View file @
d0ea78fa
...
...
@@ -16,8 +16,8 @@ from collections import deque
from
serial.tools
import
list_ports
from
typing
import
List
import
logging
logging
.
basicConfig
(
level
=
logging
.
DEBUG
,
format
=
'
%(asctime)s - %(levelname)s - %(message)s
'
)
logging
.
basicConfig
(
format
=
'
%(asctime)s - %(levelname)s - %(message)s
'
)
logging
.
getLogger
().
setLevel
(
logging
.
INFO
)
class
HEVPacketError
(
Exception
):
pass
...
...
@@ -173,13 +173,13 @@ class HEVServer(object):
broadcast_packet
=
{
"
type
"
:
"
broadcast
"
}
broadcast_packet
[
"
sensors
"
]
=
values
broadcast_packet
[
"
alarms
"
]
=
alarms
# add alarms key/value pair
logging
.
debug
(
f
"
Send:
{
json
.
dumps
(
broadcast_packet
,
indent
=
4
)
}
"
)
# take control of datavalid and reset it
with
self
.
_dvlock
:
self
.
_datavalid
.
clear
()
logging
.
info
(
f
"
Send data for timestamp:
{
broadcast_packet
[
'
sensors
'
][
'
timestamp
'
]
}
"
)
logging
.
debug
(
f
"
Send:
{
json
.
dumps
(
broadcast_packet
,
indent
=
4
)
}
"
)
try
:
writer
.
write
(
json
.
dumps
(
broadcast_packet
).
encode
())
await
writer
.
drain
()
...
...
@@ -209,7 +209,7 @@ class HEVServer(object):
# get address for log
addr
=
server
.
sockets
[
0
].
getsockname
()
logging
.
info
(
f
"
Serving on
{
addr
}
"
)
logging
.
debug
(
f
"
Serving on
{
addr
}
"
)
async
with
server
:
await
server
.
serve_forever
()
...
...
@@ -233,7 +233,10 @@ if __name__ == "__main__":
#parser to allow us to pass arguments to hevserver
parser
=
argparse
.
ArgumentParser
(
description
=
'
Arguments to run hevserver
'
)
parser
.
add_argument
(
'
--inputFile
'
,
type
=
str
,
default
=
''
,
help
=
'
a test file to load data
'
)
parser
.
add_argument
(
'
-d
'
,
'
--debug
'
,
action
=
'
store_true
'
,
help
=
'
Show debug output
'
)
args
=
parser
.
parse_args
()
if
args
.
debug
:
logging
.
getLogger
().
setLevel
(
logging
.
DEBUG
)
# check if input file was specified
if
args
.
inputFile
!=
''
:
...
...
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