sw: add load/save options, re-work adc/dac ratio setting
This commit is contained in:
+59
-15
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import math
|
import math
|
||||||
|
import json
|
||||||
import socket
|
import socket
|
||||||
import platform
|
import platform
|
||||||
|
|
||||||
@@ -14,6 +15,19 @@ from PyQt6.QtCore import Qt
|
|||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
from PyQt6.QtWidgets import QApplication, QMainWindow
|
from PyQt6.QtWidgets import QApplication, QMainWindow
|
||||||
|
|
||||||
|
SETTINGS_LIST = [
|
||||||
|
"dac_dw",
|
||||||
|
"adc_dw",
|
||||||
|
"nmax",
|
||||||
|
"window_size",
|
||||||
|
"packet_size",
|
||||||
|
"adc_clk",
|
||||||
|
"dac_clk",
|
||||||
|
"accum_width",
|
||||||
|
"recv_port",
|
||||||
|
"send_port",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ReflectometerConfig:
|
class ReflectometerConfig:
|
||||||
@@ -31,7 +45,9 @@ class ReflectometerConfig:
|
|||||||
pulse_height: int
|
pulse_height: int
|
||||||
pulse_num: int
|
pulse_num: int
|
||||||
|
|
||||||
adc_dac_ratio: float = 0.52
|
# adc_dac_ratio: float = 0.52
|
||||||
|
adc_clk: float = 65
|
||||||
|
dac_clk: float = 125
|
||||||
socket_timeout_sec: float = 2.0
|
socket_timeout_sec: float = 2.0
|
||||||
|
|
||||||
|
|
||||||
@@ -108,7 +124,8 @@ class ReflectometerWorker(QObject):
|
|||||||
output += 0b10001000.to_bytes(1, "little")
|
output += 0b10001000.to_bytes(1, "little")
|
||||||
|
|
||||||
pulse_period_adc = (
|
pulse_period_adc = (
|
||||||
int(self.config.pulse_period * self.config.adc_dac_ratio)
|
int(self.config.pulse_period *
|
||||||
|
(self.config.adc_clk / self.config.dac_clk))
|
||||||
// self.config.window_size
|
// self.config.window_size
|
||||||
) * self.config.window_size
|
) * self.config.window_size
|
||||||
|
|
||||||
@@ -126,7 +143,7 @@ class ReflectometerWorker(QObject):
|
|||||||
def _recv_data(self) -> list[int]:
|
def _recv_data(self) -> list[int]:
|
||||||
packet_count = math.ceil(
|
packet_count = math.ceil(
|
||||||
(
|
(
|
||||||
self.config.adc_dac_ratio
|
(self.config.adc_clk / self.config.dac_clk)
|
||||||
* self.config.pulse_period
|
* self.config.pulse_period
|
||||||
/ self.config.window_size
|
/ self.config.window_size
|
||||||
* self.config.data_width
|
* self.config.data_width
|
||||||
@@ -135,7 +152,7 @@ class ReflectometerWorker(QObject):
|
|||||||
)
|
)
|
||||||
|
|
||||||
expected_length = math.ceil(
|
expected_length = math.ceil(
|
||||||
self.config.adc_dac_ratio
|
(self.config.adc_clk / self.config.dac_clk)
|
||||||
* self.config.pulse_period
|
* self.config.pulse_period
|
||||||
/ self.config.window_size
|
/ self.config.window_size
|
||||||
)
|
)
|
||||||
@@ -227,7 +244,6 @@ class MainWindow(QMainWindow):
|
|||||||
self.nmax = 4096
|
self.nmax = 4096
|
||||||
self.packet_size = 1024
|
self.packet_size = 1024
|
||||||
self.window_size = 65
|
self.window_size = 65
|
||||||
self.adc_dac_ration = 0.52
|
|
||||||
self.accum_width = 32
|
self.accum_width = 32
|
||||||
|
|
||||||
# setup
|
# setup
|
||||||
@@ -239,8 +255,6 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
self.data = []
|
self.data = []
|
||||||
|
|
||||||
self.adc_dac_ratio = 0.52
|
|
||||||
|
|
||||||
self.measurement_thread = None
|
self.measurement_thread = None
|
||||||
self.measurement_worker = None
|
self.measurement_worker = None
|
||||||
|
|
||||||
@@ -250,8 +264,32 @@ class MainWindow(QMainWindow):
|
|||||||
self.button_start.clicked.connect(self.run_measurement)
|
self.button_start.clicked.connect(self.run_measurement)
|
||||||
self.button_graph_autoscale.clicked.connect(self.reset_graph_autoscale)
|
self.button_graph_autoscale.clicked.connect(self.reset_graph_autoscale)
|
||||||
|
|
||||||
# ping utils
|
self.button_save.clicked.connect(self.save_config)
|
||||||
|
self.button_load.clicked.connect(self.load_config)
|
||||||
|
|
||||||
|
# load/save
|
||||||
|
|
||||||
|
def save_config(self):
|
||||||
|
|
||||||
|
conf = {}
|
||||||
|
for setting in SETTINGS_LIST:
|
||||||
|
conf[setting] = self.__getattribute__(setting)
|
||||||
|
with open(".settings.json", "w") as f:
|
||||||
|
f.write(json.dumps(conf))
|
||||||
|
self.label_save_status.setText("Настройки сохранены")
|
||||||
|
|
||||||
|
def load_config(self):
|
||||||
|
try:
|
||||||
|
with open(".settings.json", 'r') as f:
|
||||||
|
conf = json.loads(f.read())
|
||||||
|
except FileNotFoundError:
|
||||||
|
self.label_save_status.setText("Нет сохранненого .setting.json")
|
||||||
|
return
|
||||||
|
for setting in conf:
|
||||||
|
self.__getattribute__(f"box_{setting}").setValue(conf[setting])
|
||||||
|
self.label_save_status.setText("Настройки загружены")
|
||||||
|
|
||||||
|
# ping utils
|
||||||
def check_ping(self):
|
def check_ping(self):
|
||||||
ip = self.line_ip.text().strip()
|
ip = self.line_ip.text().strip()
|
||||||
|
|
||||||
@@ -280,14 +318,14 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
if system_name == "windows":
|
if system_name == "windows":
|
||||||
program = "ping"
|
program = "ping"
|
||||||
arguments = ["-n", "1", "-w", "2000", ip]
|
arguments = ["-n", "1", "-w", "1000", ip]
|
||||||
else:
|
else:
|
||||||
program = "ping"
|
program = "ping"
|
||||||
arguments = ["-c", "1", "-W", "2", ip]
|
arguments = ["-c", "1", "-W", "1", ip]
|
||||||
|
|
||||||
self.ping_process.start(program, arguments)
|
self.ping_process.start(program, arguments)
|
||||||
# fallback
|
# fallback
|
||||||
self.ping_timeout_timer.start(2000)
|
self.ping_timeout_timer.start(1000)
|
||||||
|
|
||||||
def on_ping_finished(self, exit_code, exit_status):
|
def on_ping_finished(self, exit_code, exit_status):
|
||||||
self.ping_timeout_timer.stop()
|
self.ping_timeout_timer.stop()
|
||||||
@@ -456,8 +494,13 @@ class MainWindow(QMainWindow):
|
|||||||
)
|
)
|
||||||
|
|
||||||
self._bind_spinbox_setting(
|
self._bind_spinbox_setting(
|
||||||
name="adc_dac_ratio",
|
name="adc_clk",
|
||||||
box=self.box_adc_dac_ratio,
|
box=self.box_adc_clk,
|
||||||
|
)
|
||||||
|
|
||||||
|
self._bind_spinbox_setting(
|
||||||
|
name="dac_clk",
|
||||||
|
box=self.box_dac_clk,
|
||||||
)
|
)
|
||||||
|
|
||||||
self._bind_spinbox_setting(
|
self._bind_spinbox_setting(
|
||||||
@@ -642,7 +685,8 @@ class MainWindow(QMainWindow):
|
|||||||
pulse_height=self.pulse_height,
|
pulse_height=self.pulse_height,
|
||||||
pulse_num=self.pulse_num,
|
pulse_num=self.pulse_num,
|
||||||
|
|
||||||
adc_dac_ratio=self.adc_dac_ratio,
|
adc_clk=self.adc_clk,
|
||||||
|
dac_clk=self.dac_clk
|
||||||
)
|
)
|
||||||
|
|
||||||
def on_data_received(self, data: list[int]):
|
def on_data_received(self, data: list[int]):
|
||||||
@@ -711,7 +755,7 @@ class MainWindow(QMainWindow):
|
|||||||
reference = [0] * length
|
reference = [0] * length
|
||||||
|
|
||||||
actual_pulse_width = round(
|
actual_pulse_width = round(
|
||||||
(self.pulse_width * self.adc_dac_ratio) / self.window_size)
|
(self.pulse_width * self.adc_clk / self.dac_clk) / self.window_size)
|
||||||
|
|
||||||
reference[0:actual_pulse_width] = [
|
reference[0:actual_pulse_width] = [
|
||||||
(self.pulse_height / 2 ** (self.dac_dw - self.adc_dw)) - 2 ** (self.adc_dw - 1), ] * (actual_pulse_width - 1)
|
(self.pulse_height / 2 ** (self.dac_dw - self.adc_dw)) - 2 ** (self.adc_dw - 1), ] * (actual_pulse_width - 1)
|
||||||
|
|||||||
Reference in New Issue
Block a user