Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
distributed oscilloscope
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Projects
distributed oscilloscope
Commits
20e27334
Commit
20e27334
authored
Aug 14, 2019
by
Milosz Malczak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
doc: started adding docstrings
parent
79ad78c7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
145 additions
and
4 deletions
+145
-4
connection_manager.py
...ware/DistributedOscilloscope/server/connection_manager.py
+4
-0
expose.py
software/DistributedOscilloscope/server/expose.py
+130
-0
user_app.py
software/DistributedOscilloscope/server/user_app.py
+11
-4
No files found.
software/DistributedOscilloscope/server/connection_manager.py
View file @
20e27334
...
...
@@ -5,6 +5,10 @@ logger = logging.getLogger(__name__)
class
ConnectionManager
():
"""
Manages connections with all nodes. Provides access to the nodes for other
classes
"""
def
__init__
(
self
):
self
.
__user_apps
=
dict
()
...
...
software/DistributedOscilloscope/server/expose.py
View file @
20e27334
"""
expose.py
============================================
Exposes the functionalities of the Server to other Device Applications and to
User Applications. All communication with other applications is done using
Expose classs
"""
from
zmq.utils.monitor
import
recv_monitor_message
from
zmq.utils.monitor
import
parse_monitor_message
import
zmq
...
...
@@ -7,8 +15,16 @@ logger = logging.getLogger(__name__)
from
DistributedOscilloscope.utilities.ipaddr
import
get_ip
from
DistributedOscilloscope.utilities
import
serialization
class
Expose
():
"""
Top level class
:param connection_manager: :class:`~server.connection_manager.ConnectionManager`
:param port_user: port on which it listens for User Applications connections
:param port_device: port on which it listens for devices connections
"""
def
__init__
(
self
,
connection_manager
,
port_user
,
port_device
):
self
.
__connection_manager
=
connection_manager
self
.
__port_user
=
port_user
...
...
@@ -17,26 +33,70 @@ class Expose():
def
add_channel
(
self
,
oscilloscope_channel_idx
,
unique_ADC_name
,
ADC_channel_idx
,
user_app_name
):
"""
Add channel in the User Application
Called by the User Application
:param oscilloscope_channel_idx: index of the channel in the user
\
application
:param unique_ADC_name: name of the ADC
:param ADC_channel_index: channel index of the ADC
:param user_app_name: name of the User Application
"""
user_app
=
self
.
__connection_manager
.
get_user_app
(
user_app_name
)
ADC
=
self
.
__connection_manager
.
get_ADC
(
unique_ADC_name
)
user_app
.
add_channel
(
oscilloscope_channel_idx
,
ADC
,
ADC_channel_idx
)
def
remove_channel
(
self
,
oscilloscope_channel_idx
,
user_app_name
):
"""
Remove channel from the User Application
Called by the User Application
:param oscilloscope_channel_idx: index of the channel in the user
\
application
:param user_app_name: name of the User Application
"""
user_app
=
self
.
__connection_manager
.
get_user_app
(
user_app_name
)
user_app
.
remove_channel
(
oscilloscope_channel_idx
)
def
add_trigger
(
self
,
type
,
unique_ADC_name
,
ADC_trigger_idx
,
user_app_name
):
"""
Add trigger in the User Application
Called by the User Application
:param type: type of the trigger
:param unique_ADC_name: name of the ADC
:param ADC_trigger_index: trigger index of the ADC
:param user_app_name: name of the User Application
"""
user_app
=
self
.
__connection_manager
.
get_user_app
(
user_app_name
)
ADC
=
self
.
__connection_manager
.
get_ADC
(
unique_ADC_name
)
user_app
.
add_trigger
(
type
,
ADC
,
ADC_trigger_idx
)
def
remove_trigger
(
self
,
user_app_name
):
"""
Remove trigger from the User Application
Called by the User Application
:param user_app_name: name of the User Application
"""
user_app
=
self
.
__connection_manager
.
get_user_app
(
user_app_name
)
user_app
.
remove_trigger
()
def
set_ADC_parameter
(
self
,
parameter_name
,
value
,
unique_ADC_name
,
idx
=
None
):
"""
Generic function, used to modify parameters of the ADC
Called by the User Application
:param parameter_name: name of the parameter to be modified
:param value: new value of the parameter
:param unique_ADC_name: name of the ADC
:param idx: index of the given parameter if applies
"""
ADC
=
self
.
__connection_manager
.
get_ADC
(
unique_ADC_name
)
try
:
ADC
.
set_ADC_parameter
(
parameter_name
,
value
,
idx
)
...
...
@@ -44,30 +104,92 @@ class Expose():
print
(
"Set_ADC_parameter error {}"
.
format
(
e
))
def
single_acquisition
(
self
,
user_app_name
):
"""
Called by the User Application
Starts single acquisition in the given User Application
:param user_app_name: name of the User Application
"""
user_app
=
self
.
__connection_manager
.
get_user_app
(
user_app_name
)
user_app
.
configure_acquisition_ADCs_used
()
def
run_acquisition
(
self
,
run
,
user_app_name
):
"""
Called by the User Application
Starts or stops continuous acquisition in the given User Application
:param run: defines if the acquisition is to be started or stopped
:param user_app_name: name of the User Application
"""
user_app
=
self
.
__connection_manager
.
get_user_app
(
user_app_name
)
user_app
.
run_acquisition
(
run
)
def
set_pre_post_samples
(
self
,
presamples
,
postsamples
,
user_app_name
):
"""
Called by the User Application
Defines he number of presamples and postsamples that are to be set in
all ADCs used by the given User Application
:param presamples: number of presamples
:param postsamples: number of postsamples
:param user_app_name: name of the User Application
"""
user_app
=
self
.
__connection_manager
.
get_user_app
(
user_app_name
)
user_app
.
set_pre_post_samples
(
presamples
,
postsamples
)
def
get_user_app_settings
(
self
,
user_app_name
):
"""
Called by the User Application
Retrieves the parameters of channels and trigger used by the
particular User Application as well as length of the acquisition.
:param user_app_name: name of the User Application
:return: Dictionary with required settings
"""
user_app
=
self
.
__connection_manager
.
get_user_app
(
user_app_name
)
return
user_app
.
get_user_app_settings
()
def
register_user_app
(
self
,
user_app_name
,
addr
,
port
):
"""
Called by the User Application
Registers User Application in the Distributed Oscilloscope
:param addr: IP address of the socket of the User Application
:param port: port of the socket of the User Application
:param user_app_name: name of the User Application
"""
self
.
__connection_manager
.
register_user_app
(
user_app_name
,
str
(
addr
),
port
)
def
unregister_user_app
(
self
,
user_app_name
):
"""
Called by the User Application
Unregisters User Application in the Distributed Oscilloscope
:param user_app_name: name of the User Application
"""
self
.
__connection_manager
.
unregister_user_app
(
user_app_name
)
"""---------------------------ADC--------------------------------------"""
def
update_data
(
self
,
timestamp
,
pre_post
,
data
,
unique_ADC_name
):
"""
Called by the Device Application
Adds the acquisition data to the acquisition data queue in the ADC.
Every time the new data arrives, the ADC notifies the User Application
class, which checks if all rrequired data has arrived and is properly
aligned. If yes, it sends the data to the actuall User Application
:param timestamp: timestamp with the information about the time of the
trigger
:param pre_post: number of acquired presamples and postsamples
:param data: dictionary with ADC channels indexes as keys, containing
acquisition data
:param unique_ADC_name: name of the ADC
"""
if
(
data
==
0
):
self
.
__connection_manager
.
stop_acquisition_if_user_app_contains_ADC
(
unique_ADC_name
)
...
...
@@ -78,10 +200,18 @@ class Expose():
return
True
def
register_ADC
(
self
,
unique_ADC_name
,
addr
,
port
):
"""
Called by the Device Application
"""
self
.
__connection_manager
.
register_ADC
(
unique_ADC_name
,
str
(
addr
),
port
)
def
unregister_ADC
(
self
,
unique_ADC_name
):
"""
Called by the Device Application
"""
self
.
__connection_manager
.
unregister_ADC
(
unique_ADC_name
)
"""---------------------------ADC--------------------------------------"""
...
...
software/DistributedOscilloscope/server/user_app.py
View file @
20e27334
...
...
@@ -12,6 +12,17 @@ class HorizontalSettingsError(Exception):
class
UserApplication
():
"""
It is a model of the User Application.
All changes in the User Application are reflected here(adding/removing
channels, triggers, starting/stopping acquisition, changing the acquisition
length.
All changes that affect the User Apllication are done through this class
(availability of the devices, acquisition data)
"""
def
__init__
(
self
,
name
,
user_app_addr
,
user_app_port
,
connection_manager
):
self
.
name
=
name
...
...
@@ -149,8 +160,6 @@ class UserApplication():
else
:
logger
.
info
(
"No trigger selected"
)
def
configure_acquisition_ADCs_used
(
self
):
if
self
.
__trigger
is
not
None
:
for
ADC
in
self
.
__ADCs_used
:
...
...
@@ -167,8 +176,6 @@ class UserApplication():
for
channel_idx
,
channel
in
self
.
__channels
.
items
():
channel
.
timestamp_pre_post_data
=
[]
def
__all_data_aligned
(
self
,
max_timestamp
):
for
channel_idx
,
channel
in
self
.
__channels
.
items
():
timestamp
=
channel
.
timestamp_pre_post_data
[
0
][
'timestamp'
]
...
...
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