Skip to content

Commit

Permalink
Merge pull request #2 from ALBA-Synchrotron/master
Browse files Browse the repository at this point in the history
update to latest Alba version
  • Loading branch information
valerixb authored Jan 29, 2021
2 parents e982420 + d914e09 commit 1024c8a
Show file tree
Hide file tree
Showing 14 changed files with 810 additions and 784 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ commit = True
message = Bump version {current_version} to {new_version}
tag = True
tag_name = {new_version}
current_version = 0.3.0
current_version = 0.5.2
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+))?
serialize =
{major}.{minor}.{patch}
Expand Down
26 changes: 24 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,27 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [0.5.x]

## [0.3.X]
### Added
- Migrate to python 3
- Migrate to Qt 5
- Add protection to create configuration folders
- Add the axis as optional parameter on the script.

### Fixed
- Fix classifiers to upload to PyPi

## [0.4.0]

### Added
- Allow to save on the file
- Allow to save the setting to a file

### Fixed


## [0.3.0]

### Added
- Allow to set the signals from command line.
Expand Down Expand Up @@ -34,4 +53,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
[keepachangelog.com]: http://keepachangelog.com
[0.1.0]: https://github.com/ALBA-Synchrotron/IcepapOCS/compare/0.1.0...0.2.0
[0.2.1]: https://github.com/ALBA-Synchrotron/IcepapOCS/compare/0.2.0...0.2.1
[0.3.X]: https://github.com/ALBA-Synchrotron/IcepapOCS/compare/0.3.0...HEAD
[0.3.0]: https://github.com/ALBA-Synchrotron/IcepapOCS/compare/0.2.1...0.3.0
[0.4.0]: https://github.com/ALBA-Synchrotron/IcepapOCS/compare/0.3.0...0.4.0
[0.5.x]: https://github.com/ALBA-Synchrotron/IcepapOCS/compare/0.4.0...HEAD

2 changes: 1 addition & 1 deletion icepaposc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@

# The version is updated automatically with bumpversion
# Do not update manually
version = '0.3.0'
version = '0.5.2'
11 changes: 6 additions & 5 deletions icepaposc/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
# -----------------------------------------------------------------------------

import sys
from PyQt4.QtGui import QApplication
from window_main import WindowMain
from PyQt5.QtWidgets import QApplication
from .window_main import WindowMain
import argparse
from __init__ import version
from . import version


def get_parser():
Expand All @@ -40,6 +40,7 @@ def get_parser():
parse.add_argument('--version', action='version', version=ver)

parse.add_argument('host', help='IcePAP Host')
parse.add_argument('--axis', help='Selected axis', default=1, type=int)
parse.add_argument('-p', '--port', type=int, default=5000,
help='IcePAP port')
parse.add_argument('-t', '--timeout', type=int, default=3,
Expand All @@ -49,7 +50,7 @@ def get_parser():
'<driver>:<signal name>:<Y-axis>')

# TODO: Allow to pass the axes preselected and type of graph
# parse.add_argument('axes', nargs='*', help='Axes to save, default all',
# parse.add_argument('-a', nargs='*', help='Axes to save, default all',
# type=int, default=[])
# save_cmd.add_argument('-d', '--debug', action='store_true',
# help='Activate log level DEBUG')
Expand All @@ -61,7 +62,7 @@ def main():
args = get_parser().parse_args()

app = QApplication(sys.argv)
win = WindowMain(args.host, args.port, args.timeout, args.sig)
win = WindowMain(args.host, args.port, args.timeout, args.sig, args.axis)
win.show()
sys.exit(app.exec_())

Expand Down
49 changes: 21 additions & 28 deletions icepaposc/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@
# along with IcepapOCS. If not, see <http://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------------

from PyQt4.QtCore import QTimer
from PyQt4.QtCore import QString
from PyQt5 import QtCore
from collections import OrderedDict
from pyIcePAP import EthIcePAPController
from channel import Channel
from icepap import IcePAPController
from .channel import Channel
import time


class Collector:
"""Feeds a subscriber with collected IcePAP signal data."""

def __init__(self, host, port, timeout, callback):
def __init__(self, host, port, timeout, settings, callback):
"""
Initializes an instance of class Collector.
Expand Down Expand Up @@ -78,18 +77,18 @@ def __init__(self, host, port, timeout, callback):
)
self.host = host
self.port = port
self.settings = settings
self.cb = callback
self.icepap_system = None
self.channels_subscribed = {}
self.channels = {}
self.channel_id = 0
self.current_channel = 0
self.sig_list = self.sig_getters.keys()
self.sig_list = list(self.sig_getters.keys())

try:
self.icepap_system = EthIcePAPController(self.host,
self.port,
timeout)
self.icepap_system = IcePAPController(self.host, self.port,
timeout, auto_axes=True)
except Exception as e:
msg = 'Failed to instantiate master controller.\nHost: ' \
'{}\nPort: {}\n{}'.format(self.host, self.port, e)
Expand All @@ -99,23 +98,17 @@ def __init__(self, host, port, timeout, callback):
'Aborting.'.format(self.host)
raise Exception(msg)

self.tick_interval_min = 10 # [milliseconds]
self.tick_interval_max = 1000 # [milliseconds]
self.tick_interval = 50 # [milliseconds]
self.sample_buf_len_min = 1
self.sample_buf_len_max = 100
self.sample_buf_len = 2
self.ticker = QTimer()
self.ticker = QtCore.QTimer()
self.ticker.timeout.connect(self._tick)
self.ticker.start(self.tick_interval)
self.ticker.start(self.settings.sample_rate)

def get_available_drivers(self):
"""
Retrieves the available drivers.
Return: List of available drivers.
"""
return self.icepap_system.keys()
return self.icepap_system.axes

def get_available_signals(self):
"""
Expand Down Expand Up @@ -150,15 +143,15 @@ def subscribe(self, icepap_addr, signal_name):
signal_name - Signal name.
Return - A positive integer id used when unsubscribing.
"""
for ch in self.channels_subscribed.values():
for ch in list(self.channels_subscribed.values()):
if ch.equals(icepap_addr, signal_name):
msg = 'Channel already exists.\nAddr: ' \
'{}\nSignal: {}'.format(icepap_addr, signal_name)
raise Exception(msg)
channel = Channel(icepap_addr, signal_name)
sn = QString(signal_name)
cond_1 = sn.endsWith('Tgtenc')
cond_2 = sn.endsWith('Shftenc')
sn = str(signal_name)
cond_1 = sn.endswith('Tgtenc')
cond_2 = sn.endswith('Shftenc')
cond_3 = sn == 'DifAxMeasure'
if cond_1 or cond_2 or cond_3:
try:
Expand All @@ -183,8 +176,8 @@ def start(self, subscription_id):
subscription_id - The given subscription id.
"""
if subscription_id in self.channels_subscribed.keys() and \
subscription_id not in self.channels.keys():
if subscription_id in list(self.channels_subscribed.keys()) and \
subscription_id not in list(self.channels.keys()):
self.channels[subscription_id] = \
self.channels_subscribed[subscription_id]

Expand All @@ -194,12 +187,12 @@ def unsubscribe(self, subscription_id):
subscription_id - The given subscription id.
"""
if subscription_id in self.channels_subscribed.keys():
if subscription_id in list(self.channels_subscribed.keys()):
del self.channels[subscription_id]
del self.channels_subscribed[subscription_id]

def _tick(self):
for subscription_id, channel in self.channels.iteritems():
for subscription_id, channel in self.channels.items():
self.current_channel = subscription_id
try:
addr = channel.icepap_address
Expand All @@ -211,10 +204,10 @@ def _tick(self):
continue
tv = (time.time(), val)
channel.collected_samples.append(tv)
if len(channel.collected_samples) >= self.sample_buf_len:
if len(channel.collected_samples) >= self.settings.dump_rate:
self.cb(subscription_id, channel.collected_samples)
channel.collected_samples = []
self.ticker.start(self.tick_interval)
self.ticker.start(self.settings.sample_rate)

def _getter_pos_axis(self, addr):
return self.icepap_system[addr].pos
Expand Down
104 changes: 67 additions & 37 deletions icepaposc/curve_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
# along with IcepapOCS. If not, see <http://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------------

from PyQt4.QtGui import QColor
from PyQt4.QtCore import Qt
from PyQt5 import QtCore, QtGui
from collections import namedtuple
from threading import RLock
from pyqtgraph import PlotCurveItem
Expand All @@ -31,37 +30,68 @@ class CurveItem:
['pen_color', 'pen_width', 'pen_style'])

colors = [
SignalAppearance(QColor(255, 255, 0), 1, Qt.SolidLine),
SignalAppearance(QColor(255, 0, 0), 1, Qt.SolidLine),
SignalAppearance(QColor(0, 255, 0), 1, Qt.SolidLine),
SignalAppearance(QColor(255, 255, 255), 1, Qt.SolidLine),
SignalAppearance(QColor(51, 153, 255), 1, Qt.SolidLine),
SignalAppearance(QColor(0, 255, 255), 1, Qt.SolidLine),
SignalAppearance(QColor(255, 0, 255), 1, Qt.SolidLine),
SignalAppearance(QColor(204, 153, 102), 1, Qt.SolidLine),
SignalAppearance(QColor(0, 0, 255), 1, Qt.SolidLine),
SignalAppearance(QColor(0, 255, 0), 1, Qt.SolidLine),
SignalAppearance(QColor(255, 204, 0), 1, Qt.SolidLine),
SignalAppearance(QColor(153, 255, 153), 2, Qt.DotLine),
SignalAppearance(QColor(255, 170, 0), 2, Qt.DashLine),
SignalAppearance(QColor(255, 0, 0), 2, Qt.DashLine),
SignalAppearance(QColor(0, 255, 255), 1, Qt.DotLine),
SignalAppearance(QColor(255, 170, 255), 1, Qt.DashLine),
SignalAppearance(QColor(127, 255, 127), 1, Qt.DashLine),
SignalAppearance(QColor(255, 255, 127), 1, Qt.DashLine),
SignalAppearance(QColor(255, 0, 0), 2, Qt.DotLine),
SignalAppearance(QColor(255, 0, 0), 1, Qt.DashLine),
SignalAppearance(QColor(0, 255, 0), 2, Qt.DotLine),
SignalAppearance(QColor(255, 255, 255), 2, Qt.SolidLine),
SignalAppearance(QColor(51, 153, 255), 1, Qt.DashLine),
SignalAppearance(QColor(255, 0, 255), 1, Qt.DashLine),
SignalAppearance(QColor(255, 153, 204), 1, Qt.DashLine),
SignalAppearance(QColor(204, 153, 102), 1, Qt.DashLine),
SignalAppearance(QColor(255, 204, 0), 1, Qt.DashLine),
SignalAppearance(QColor(255, 0, 255), 1, Qt.DashLine),
SignalAppearance(QColor(255, 153, 204), 1, Qt.DashLine),
SignalAppearance(QColor(204, 153, 102), 1, Qt.DashLine),
SignalAppearance(QColor(255, 204, 0), 1, Qt.DashLine)
SignalAppearance(QtGui.QColor(255, 255, 0), 1,
QtCore.Qt.SolidLine),
SignalAppearance(QtGui.QColor(255, 0, 0), 1,
QtCore.Qt.SolidLine),
SignalAppearance(QtGui.QColor(0, 255, 0), 1,
QtCore.Qt.SolidLine),
SignalAppearance(QtGui.QColor(255, 255, 255), 1,
QtCore.Qt.SolidLine),
SignalAppearance(QtGui.QColor(51, 153, 255), 1,
QtCore.Qt.SolidLine),
SignalAppearance(QtGui.QColor(0, 255, 255), 1,
QtCore.Qt.SolidLine),
SignalAppearance(QtGui.QColor(255, 0, 255), 1,
QtCore.Qt.SolidLine),
SignalAppearance(QtGui.QColor(204, 153, 102), 1,
QtCore.Qt.SolidLine),
SignalAppearance(QtGui.QColor(0, 0, 255), 1,
QtCore.Qt.SolidLine),
SignalAppearance(QtGui.QColor(0, 255, 0), 1,
QtCore.Qt.SolidLine),
SignalAppearance(QtGui.QColor(255, 204, 0), 1,
QtCore.Qt.SolidLine),
SignalAppearance(QtGui.QColor(153, 255, 153), 2,
QtCore.Qt.DotLine),
SignalAppearance(QtGui.QColor(255, 170, 0), 2,
QtCore.Qt.DashLine),
SignalAppearance(QtGui.QColor(255, 0, 0), 2,
QtCore.Qt.DashLine),
SignalAppearance(QtGui.QColor(0, 255, 255), 1,
QtCore.Qt.DotLine),
SignalAppearance(QtGui.QColor(255, 170, 255), 1,
QtCore.Qt.DashLine),
SignalAppearance(QtGui.QColor(127, 255, 127), 1,
QtCore.Qt.DashLine),
SignalAppearance(QtGui.QColor(255, 255, 127), 1,
QtCore.Qt.DashLine),
SignalAppearance(QtGui.QColor(255, 0, 0), 2,
QtCore.Qt.DotLine),
SignalAppearance(QtGui.QColor(255, 0, 0), 1,
QtCore.Qt.DashLine),
SignalAppearance(QtGui.QColor(0, 255, 0), 2,
QtCore.Qt.DotLine),
SignalAppearance(QtGui.QColor(255, 255, 255), 2,
QtCore.Qt.SolidLine),
SignalAppearance(QtGui.QColor(51, 153, 255), 1,
QtCore.Qt.DashLine),
SignalAppearance(QtGui.QColor(255, 0, 255), 1,
QtCore.Qt.DashLine),
SignalAppearance(QtGui.QColor(255, 153, 204), 1,
QtCore.Qt.DashLine),
SignalAppearance(QtGui.QColor(204, 153, 102), 1,
QtCore.Qt.DashLine),
SignalAppearance(QtGui.QColor(255, 204, 0), 1,
QtCore.Qt.DashLine),
SignalAppearance(QtGui.QColor(255, 0, 255), 1,
QtCore.Qt.DashLine),
SignalAppearance(QtGui.QColor(255, 153, 204), 1,
QtCore.Qt.DashLine),
SignalAppearance(QtGui.QColor(204, 153, 102), 1,
QtCore.Qt.DashLine),
SignalAppearance(QtGui.QColor(255, 204, 0), 1,
QtCore.Qt.DashLine)
]

def __init__(self, subscription_id, driver_addr, sig_name, y_axis,
Expand Down Expand Up @@ -108,8 +138,8 @@ def create_curve(self):
def update_curve(self, time_min, time_max):
"""Updates the curve with recent collected data."""
with self.lock:
idx_min = self._get_time_index(time_min)
idx_max = self._get_time_index(time_max)
idx_min = self.get_time_index(time_min)
idx_max = self.get_time_index(time_max)
self.curve.setData(x=self.array_time[idx_min:idx_max],
y=self.array_val[idx_min:idx_max])

Expand Down Expand Up @@ -159,14 +189,14 @@ def get_y(self, time_val):
Return: Signal value corresponding to an adjacent sample in time.
"""
with self.lock:
idx = self._get_time_index(time_val)
idx = self.get_time_index(time_val)
return self.array_val[idx]

def clear(self):
self.array_time[:] = []
self.array_val[:] = []

def _get_time_index(self, time_val):
def get_time_index(self, time_val):
"""
Retrieve the sample index corresponding to the provided time value.
Expand Down
Loading

0 comments on commit 1024c8a

Please sign in to comment.