From d88313f742e628e5e4e59023c17a009c25acffcd Mon Sep 17 00:00:00 2001 From: saji Date: Tue, 4 Jul 2023 00:50:34 -0500 Subject: [PATCH] make some python happen --- py/pytelem/backend.py | 16 ++++++++++++ py/pytelem/bms.py | 58 +++++++++++++++++++++++++++++++++++++++++++ py/pytelem/gui.py | 2 +- py/pytelem/optimus.py | 1 - 4 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 py/pytelem/bms.py diff --git a/py/pytelem/backend.py b/py/pytelem/backend.py index dcf4430..c67fcce 100644 --- a/py/pytelem/backend.py +++ b/py/pytelem/backend.py @@ -1,3 +1,19 @@ import aiohttp import orjson import threading + +# connect to websocket - create thread that handles JSON events +class TelemetryServer(QObject): + """Connection to upstream database""" + + conn_url: str + "Something like http://:8082" + + callbacks: Dict[str, Signal] + + def __init__(self, url: str, parent=None): + super().__init__(parent) + self.conn_url = url + + + diff --git a/py/pytelem/bms.py b/py/pytelem/bms.py new file mode 100644 index 0000000..cd53cee --- /dev/null +++ b/py/pytelem/bms.py @@ -0,0 +1,58 @@ +from typing_extensions import TypedDict + +from PySide6.QtCore import QObject +from PySide6.QtWidgets import QDockWidget, QGridLayout, QGroupBox, QHBoxLayout, QLabel, QVBoxLayout, QWidget + +ContactorStates = TypedDict("ContactorStates", {}) + + +class BMSState(QObject): + """Represents the BMS state, including history.""" + main_voltage: float + aux_voltage: float + current: float + + def __init__(self, parent=None, upstream=None): + super().__init__(parent) + # uhh, take a connection to the upstream? + + +class BMSModuleViewer(QDockWidget): + """BMS module status viewer (temp and voltage)""" + + layout: QGridLayout + + def __init__(self) -> None: + super().__init__() + self.layout = QGridLayout(self) + + +class BMSOverview(QWidget): + layout: QGridLayout + + + def __init__(self, parent=None) -> None: + super().__init__(parent) + self.layout = QGridLayout(self) + main_voltage_label = QLabel("Main Voltage", self) + self.layout.addWidget(main_voltage_label, row=1, column=0) + aux_v_label= QLabel("Aux Voltage", self) + self.layout.addWidget(aux_v_label, row=1, column=1) + current_label = QLabel("Battery Current", self) + self.layout.addWidget(current_label, row=1, column=2) + + # now add widgets that display the numeric values. + # then make slots that take floats and display them. + +class BMSStatus(QDockWidget): + + layout: QVBoxLayout + contactors: QGroupBox + + def __init__(self, parent = None): + super().__init__("Battery Status", parent) + + self.layout = QVBoxLayout(self) + self.contactors = QGroupBox("Contactor State", self) + self.layout.addWidget(self.contactors) + diff --git a/py/pytelem/gui.py b/py/pytelem/gui.py index 57d9526..6d09071 100644 --- a/py/pytelem/gui.py +++ b/py/pytelem/gui.py @@ -30,7 +30,7 @@ class PacketTree(QWidget): splitter = QtWidgets.QSplitter(self) layout = QtWidgets.QVBoxLayout() - splitter.setOrientation(Qt.Vertical) +# splitter.setOrientation(Qt.Vertical) self.tree = QTreeView() self.prop_table = pyqtgraph.parametertree.ParameterTree() splitter.addWidget(self.tree) diff --git a/py/pytelem/optimus.py b/py/pytelem/optimus.py index d11ef56..a3ec7df 100644 --- a/py/pytelem/optimus.py +++ b/py/pytelem/optimus.py @@ -77,7 +77,6 @@ def make_cubic(a, b, c, d): @jit -@vmap def get_radiation_direct(yday, altitude_deg): """Calculate the direct radiation at a given day of the year given the angle of the sun from the horizon."""