-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from Raghav67816/main
Directory cleanup and restructure
- Loading branch information
Showing
18 changed files
with
1,642 additions
and
2,589 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
Software/PC/Backend/desktop_browser_app/signals_simulator/config/config.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
Software/PC/Backend/desktop_browser_app/signals_simulator/config/extra.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"num_signals": 5, "bit_depth": 16, "duration": 1.0, "fs": 500.0} |
82 changes: 82 additions & 0 deletions
82
Software/PC/Backend/desktop_browser_app/signals_simulator/data_manager.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
""" | ||
The DataManager class is a data transmitter and receiver | ||
Usage: | ||
The files which need data to SEND & READ data simultaneously | ||
""" | ||
import time | ||
from threading import Thread | ||
from paho.mqtt.client import Client | ||
from typing import Any | ||
|
||
|
||
class DataManager: | ||
def __init__(self, client_id: str, topic_sub: str | None, topic_pub: str | None, | ||
processing_func: Any = None, close_after_first_list: bool = False): | ||
super().__init__() | ||
|
||
self.host = "127.0.0.1" # localhost | ||
self.port = 3000 | ||
|
||
self.client = Client(client_id) | ||
self.close_after_first_list = close_after_first_list | ||
|
||
self.client.on_connect = self.on_connect | ||
self.client.on_disconnect = self.on_disconnect | ||
self.client.on_message = self.on_message | ||
|
||
self.data = None | ||
|
||
self.client.connect(self.host, self.port) | ||
|
||
if topic_sub is None: | ||
pass | ||
else: | ||
self.client.subscribe(topic_sub) | ||
|
||
self.helper_func = processing_func | ||
self.topic_pub = topic_pub | ||
self.topic_sub = topic_sub | ||
|
||
def server_loop(self): | ||
self.client.loop_forever() | ||
|
||
def listen(self): | ||
if self.topic_sub is None: | ||
raise Exception("Instance cannot subscribe to topic. Set topic_sub parameter to subscribe") | ||
else: | ||
thread = Thread(target=self.server_loop) | ||
thread.start() | ||
|
||
def set_data(self, data: Any): | ||
self.data = data | ||
|
||
def get_data(self): | ||
return self.data | ||
|
||
def publish(self, sleep_time: float): | ||
if self.topic_pub is None: | ||
raise Exception("Instance cannot publish data. Provide topic_pub parameter.") | ||
thread = Thread(target=self.publish_data, args=[sleep_time]) | ||
thread.start() | ||
|
||
def publish_data(self, sleep_time: float = 0): | ||
data = self.get_data() | ||
if data is None: | ||
self.client.publish(topic=self.topic_pub, payload="NaN") | ||
elif data is not None: | ||
self.client.publish(topic=self.topic_pub, payload=data) | ||
time.sleep(sleep_time) | ||
|
||
# Callbacks | ||
def on_connect(self, client, userdata, flags, rc): | ||
print("connected to host") | ||
|
||
def on_message(self, client, userdata, message): | ||
self.helper_func(message.payload.decode("utf-8")) | ||
if self.close_after_first_list: | ||
self.client.unsubscribe(self.topic_sub) | ||
else: | ||
pass | ||
|
||
def on_disconnect(self, client, userdata, flags, rc): | ||
print(f"{client.client_id} disconnected from {self.host}") |
101 changes: 101 additions & 0 deletions
101
Software/PC/Backend/desktop_browser_app/signals_simulator/signals_param.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
################################################################################ | ||
## Form generated from reading UI file 'signals_param.ui' | ||
## | ||
## Created by: Qt User Interface Compiler version 6.6.2 | ||
## | ||
## WARNING! All changes made in this file will be lost when recompiling UI file! | ||
################################################################################ | ||
|
||
from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale, | ||
QMetaObject, QObject, QPoint, QRect, | ||
QSize, QTime, QUrl, Qt) | ||
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor, | ||
QFont, QFontDatabase, QGradient, QIcon, | ||
QImage, QKeySequence, QLinearGradient, QPainter, | ||
QPalette, QPixmap, QRadialGradient, QTransform) | ||
from PySide6.QtWidgets import (QAbstractButton, QApplication, QDialog, QDialogButtonBox, | ||
QFormLayout, QFrame, QLabel, QLineEdit, | ||
QSizePolicy, QVBoxLayout, QWidget) | ||
|
||
class Ui_signalParams(object): | ||
def setupUi(self, signalParams): | ||
if not signalParams.objectName(): | ||
signalParams.setObjectName(u"signalParams") | ||
signalParams.resize(400, 187) | ||
self.verticalLayout = QVBoxLayout(signalParams) | ||
self.verticalLayout.setObjectName(u"verticalLayout") | ||
self.frame = QFrame(signalParams) | ||
self.frame.setObjectName(u"frame") | ||
self.frame.setFrameShape(QFrame.StyledPanel) | ||
self.frame.setFrameShadow(QFrame.Raised) | ||
self.formLayout = QFormLayout(self.frame) | ||
self.formLayout.setObjectName(u"formLayout") | ||
self.formLayout.setHorizontalSpacing(20) | ||
self.num_signal_label = QLabel(self.frame) | ||
self.num_signal_label.setObjectName(u"num_signal_label") | ||
|
||
self.formLayout.setWidget(0, QFormLayout.LabelRole, self.num_signal_label) | ||
|
||
self.numSignalInput = QLineEdit(self.frame) | ||
self.numSignalInput.setObjectName(u"numSignalInput") | ||
|
||
self.formLayout.setWidget(0, QFormLayout.FieldRole, self.numSignalInput) | ||
|
||
self.bit_depth_label = QLabel(self.frame) | ||
self.bit_depth_label.setObjectName(u"bit_depth_label") | ||
|
||
self.formLayout.setWidget(1, QFormLayout.LabelRole, self.bit_depth_label) | ||
|
||
self.bit_depth_input = QLineEdit(self.frame) | ||
self.bit_depth_input.setObjectName(u"bit_depth_input") | ||
|
||
self.formLayout.setWidget(1, QFormLayout.FieldRole, self.bit_depth_input) | ||
|
||
self.fs_label = QLabel(self.frame) | ||
self.fs_label.setObjectName(u"fs_label") | ||
|
||
self.formLayout.setWidget(2, QFormLayout.LabelRole, self.fs_label) | ||
|
||
self.fs_input = QLineEdit(self.frame) | ||
self.fs_input.setObjectName(u"fs_input") | ||
|
||
self.formLayout.setWidget(2, QFormLayout.FieldRole, self.fs_input) | ||
|
||
self.durationLabel = QLabel(self.frame) | ||
self.durationLabel.setObjectName(u"durationLabel") | ||
|
||
self.formLayout.setWidget(3, QFormLayout.LabelRole, self.durationLabel) | ||
|
||
self.durationLineEdit = QLineEdit(self.frame) | ||
self.durationLineEdit.setObjectName(u"durationLineEdit") | ||
|
||
self.formLayout.setWidget(3, QFormLayout.FieldRole, self.durationLineEdit) | ||
|
||
|
||
self.verticalLayout.addWidget(self.frame) | ||
|
||
self.buttonBox = QDialogButtonBox(signalParams) | ||
self.buttonBox.setObjectName(u"buttonBox") | ||
self.buttonBox.setOrientation(Qt.Horizontal) | ||
self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Ok) | ||
|
||
self.verticalLayout.addWidget(self.buttonBox) | ||
|
||
|
||
self.retranslateUi(signalParams) | ||
self.buttonBox.accepted.connect(signalParams.accept) | ||
self.buttonBox.rejected.connect(signalParams.reject) | ||
|
||
QMetaObject.connectSlotsByName(signalParams) | ||
# setupUi | ||
|
||
def retranslateUi(self, signalParams): | ||
signalParams.setWindowTitle(QCoreApplication.translate("signalParams", u"Signals Parameters", None)) | ||
self.num_signal_label.setText(QCoreApplication.translate("signalParams", u"Number Of Signals: ", None)) | ||
self.bit_depth_label.setText(QCoreApplication.translate("signalParams", u"Bit Depth:", None)) | ||
self.fs_label.setText(QCoreApplication.translate("signalParams", u"Sampling Freq: ", None)) | ||
self.durationLabel.setText(QCoreApplication.translate("signalParams", u"Duration", None)) | ||
# retranslateUi | ||
|
119 changes: 119 additions & 0 deletions
119
Software/PC/Backend/desktop_browser_app/signals_simulator/ui files/signals_param.ui
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>signalParams</class> | ||
<widget class="QDialog" name="signalParams"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>400</width> | ||
<height>187</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Signals Parameters</string> | ||
</property> | ||
<layout class="QVBoxLayout" name="verticalLayout"> | ||
<item> | ||
<widget class="QFrame" name="frame"> | ||
<property name="frameShape"> | ||
<enum>QFrame::StyledPanel</enum> | ||
</property> | ||
<property name="frameShadow"> | ||
<enum>QFrame::Raised</enum> | ||
</property> | ||
<layout class="QFormLayout" name="formLayout"> | ||
<property name="horizontalSpacing"> | ||
<number>20</number> | ||
</property> | ||
<item row="0" column="0"> | ||
<widget class="QLabel" name="num_signal_label"> | ||
<property name="text"> | ||
<string>Number Of Signals: </string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="0" column="1"> | ||
<widget class="QLineEdit" name="numSignalInput"/> | ||
</item> | ||
<item row="1" column="0"> | ||
<widget class="QLabel" name="bit_depth_label"> | ||
<property name="text"> | ||
<string>Bit Depth:</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="1" column="1"> | ||
<widget class="QLineEdit" name="bit_depth_input"/> | ||
</item> | ||
<item row="2" column="0"> | ||
<widget class="QLabel" name="fs_label"> | ||
<property name="text"> | ||
<string>Sampling Freq: </string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="2" column="1"> | ||
<widget class="QLineEdit" name="fs_input"/> | ||
</item> | ||
<item row="3" column="0"> | ||
<widget class="QLabel" name="durationLabel"> | ||
<property name="text"> | ||
<string>Duration</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="3" column="1"> | ||
<widget class="QLineEdit" name="durationLineEdit"/> | ||
</item> | ||
</layout> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QDialogButtonBox" name="buttonBox"> | ||
<property name="orientation"> | ||
<enum>Qt::Horizontal</enum> | ||
</property> | ||
<property name="standardButtons"> | ||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
<resources/> | ||
<connections> | ||
<connection> | ||
<sender>buttonBox</sender> | ||
<signal>accepted()</signal> | ||
<receiver>signalParams</receiver> | ||
<slot>accept()</slot> | ||
<hints> | ||
<hint type="sourcelabel"> | ||
<x>248</x> | ||
<y>254</y> | ||
</hint> | ||
<hint type="destinationlabel"> | ||
<x>157</x> | ||
<y>274</y> | ||
</hint> | ||
</hints> | ||
</connection> | ||
<connection> | ||
<sender>buttonBox</sender> | ||
<signal>rejected()</signal> | ||
<receiver>signalParams</receiver> | ||
<slot>reject()</slot> | ||
<hints> | ||
<hint type="sourcelabel"> | ||
<x>316</x> | ||
<y>260</y> | ||
</hint> | ||
<hint type="destinationlabel"> | ||
<x>286</x> | ||
<y>274</y> | ||
</hint> | ||
</hints> | ||
</connection> | ||
</connections> | ||
</ui> |
Oops, something went wrong.