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
42df77bf
Commit
42df77bf
authored
May 11, 2021
by
Dónal Murray
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Strip out unused mmap tooling
parent
ce130a11
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
1 addition
and
38 deletions
+1
-38
hevclient.py
raspberry-dataserver/hevclient.py
+1
-38
No files found.
raspberry-dataserver/hevclient.py
View file @
42df77bf
...
...
@@ -38,13 +38,6 @@ logging.basicConfig(
level
=
logging
.
INFO
,
format
=
"
%(asctime)
s -
%(levelname)
s -
%(message)
s"
)
# use /dev/shm (in memory tmpfs) to hold the data, should be stable over Flask shenanigans when restaring scripts
import
mmap
import
pickle
import
os
mmFileName
=
"/dev/shm/HEVClient_lastData.mmap"
class
HEVPacketError
(
Exception
):
pass
...
...
@@ -65,27 +58,10 @@ class HEVClient(object):
self
.
_polling
=
polling
# keep reading data into db
self
.
_lock
=
threading
.
Lock
()
# lock for the database
self
.
_mmFile
=
None
if
os
.
access
(
mmFileName
,
os
.
F_OK
):
self
.
_mmFile
=
open
(
mmFileName
,
"a+b"
)
else
:
self
.
_mmFile
=
open
(
mmFileName
,
"x+b"
)
self
.
_mmFile
.
write
(
b
"0"
*
10000
)
# ~10kb is enough I hope for one event
self
.
_mmMap
=
mmap
.
mmap
(
self
.
_mmFile
.
fileno
(),
0
)
# Map to in memory object
self
.
_mmMap
.
seek
(
0
)
self
.
_mmMap
.
write
(
pickle
.
dumps
(
"Data not yet set"
)
)
# ensure no old or unset data in file
self
.
_mmMap
.
flush
()
# start polling in another thread unless told otherwise
if
self
.
_polling
:
self
.
start_polling
()
def
__del__
(
self
):
self
.
_mmMap
.
close
()
self
.
_mmFile
.
close
()
def
start_polling
(
self
):
"""start worker thread to update db in the background"""
worker
=
threading
.
Thread
(
target
=
self
.
start_client
,
daemon
=
True
)
...
...
@@ -114,9 +90,6 @@ class HEVClient(object):
elif
payload
[
"type"
]
==
"DATA"
:
with
self
.
_lock
:
self
.
_fastdata
=
payload
[
"DATA"
]
self
.
_mmMap
.
seek
(
0
)
self
.
_mmMap
.
write
(
pickle
.
dumps
(
self
.
_fastdata
))
self
.
_mmMap
.
flush
()
elif
payload
[
"type"
]
==
"READBACK"
:
with
self
.
_lock
:
self
.
_readback
=
payload
[
"READBACK"
]
...
...
@@ -245,17 +218,7 @@ class HEVClient(object):
def
get_values
(
self
)
->
Dict
:
# get sensor values from db
self
.
_mmFile
.
seek
(
0
)
try
:
fastdata
=
pickle
.
load
(
self
.
_mmFile
)
except
pickle
.
UnpicklingError
as
e
:
logging
.
warning
(
f
"Unpicking error {e}"
)
return
None
# Should return empty dict here?
if
type
(
fastdata
)
is
dict
:
return
fastdata
else
:
logging
.
warning
(
"Missing fastdata"
)
return
None
# Should return empty dict here?
return
self
.
_fastdata
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