kopia lustrzana https://github.com/NanoVNA-Saver/nanovna-saver
Get rid of InvalidVNA
rodzic
3dbbd165ac
commit
a06b9191be
|
@ -38,10 +38,11 @@ class NanoVNA(VNA):
|
|||
|
||||
def __init__(self, iface: Interface):
|
||||
super().__init__(iface)
|
||||
self.version = Version(self.readVersion())
|
||||
version_string = self.readVersion()
|
||||
self.version = Version(version_string)
|
||||
|
||||
logger.debug("Testing against 0.2.0")
|
||||
if self.version.version_string.find("extended with scan") > 0:
|
||||
if version_string.find("extended with scan") > 0:
|
||||
logger.debug("Incompatible scan command detected.")
|
||||
self.features.add("Incompatible scan command")
|
||||
self.useScan = False
|
||||
|
|
|
@ -35,7 +35,7 @@ class VNA:
|
|||
|
||||
def __init__(self, iface: Interface):
|
||||
self.serial = iface
|
||||
self.version: Version = Version("0.0.0")
|
||||
self.version = Version("0.0.0")
|
||||
self.features = set()
|
||||
self.validateInput = True
|
||||
self.datapoints = VNA._datapoints[0]
|
||||
|
@ -195,31 +195,3 @@ class VNA:
|
|||
|
||||
def setSweep(self, start, stop):
|
||||
self.writeSerial(f"sweep {start} {stop} {self.datapoints}")
|
||||
|
||||
|
||||
# TODO: should be dropped and the serial part should be a connection class
|
||||
# which handles unconnected devices
|
||||
class InvalidVNA(VNA):
|
||||
name = "Invalid"
|
||||
_datapoints = (0, )
|
||||
|
||||
def setSweep(self, start, stop):
|
||||
return
|
||||
|
||||
def resetSweep(self, start, stop):
|
||||
return
|
||||
|
||||
def writeSerial(self, command):
|
||||
return
|
||||
|
||||
def readFirmware(self):
|
||||
return
|
||||
|
||||
def readFrequencies(self) -> List[int]:
|
||||
return []
|
||||
|
||||
def readValues(self, value):
|
||||
return
|
||||
|
||||
def flushSerialBuffers(self):
|
||||
return
|
||||
|
|
|
@ -37,7 +37,7 @@ from .Formatting import (
|
|||
parse_frequency,
|
||||
)
|
||||
from .Hardware.Hardware import Interface, get_interfaces, get_VNA
|
||||
from .Hardware.VNA import InvalidVNA
|
||||
from .Hardware.VNA import VNA
|
||||
from .RFTools import Datapoint, corr_att_data
|
||||
from .Charts.Chart import Chart
|
||||
from .Charts import (
|
||||
|
@ -93,7 +93,7 @@ class NanoVNASaver(QtWidgets.QWidget):
|
|||
self.noSweeps = 1 # Number of sweeps to run
|
||||
|
||||
self.interface = Interface("serial", "None")
|
||||
self.vna = InvalidVNA(self.interface)
|
||||
self.vna = VNA(self.interface)
|
||||
|
||||
self.dataLock = threading.Lock()
|
||||
# TODO: use Touchstone class as data container
|
||||
|
|
|
@ -155,36 +155,35 @@ class BandsModel(QtCore.QAbstractTableModel):
|
|||
|
||||
|
||||
class Version:
|
||||
RXP = re.compile(r"(.*\s+)?(\d+)\.(\d+)\.(\d+)(.*)")
|
||||
RXP = re.compile(r"""^
|
||||
\D*
|
||||
(?P<major>\d+)\.
|
||||
(?P<minor>\d+)\.
|
||||
(?P<revision>\d+)
|
||||
(?P<note>.*)
|
||||
$""", re.VERBOSE)
|
||||
|
||||
def __init__(self, version_string: str):
|
||||
self.major = 0
|
||||
self.minor = 0
|
||||
self.revision = 0
|
||||
self.note = ""
|
||||
self.version_string = version_string
|
||||
|
||||
results = Version.RXP.match(version_string)
|
||||
if results:
|
||||
self.major = int(results.group(2))
|
||||
self.minor = int(results.group(3))
|
||||
self.revision = int(results.group(4))
|
||||
self.note = results.group(5)
|
||||
logger.debug(
|
||||
"Parsed version as \"%d.%d.%d%s\"",
|
||||
self.major, self.minor, self.revision, self.note)
|
||||
def __init__(self, vstring: str = "0.0.0"):
|
||||
self.data = {
|
||||
"major": 0,
|
||||
"minor": 0,
|
||||
"revision": 0,
|
||||
"note": "",
|
||||
}
|
||||
try:
|
||||
self.data = Version.RXP.search(vstring).groupdict()
|
||||
for name in ("major", "minor", "revision"):
|
||||
self.data[name] = int(self.data[name])
|
||||
except AttributeError:
|
||||
logger.error("Unable to parse version: %s", vstring)
|
||||
|
||||
def __gt__(self, other: "Version") -> bool:
|
||||
if self.major > other.major:
|
||||
l, r = self.data, other.data
|
||||
for name in ("major", "minor", "revision"):
|
||||
if l[name] > r[name]:
|
||||
return True
|
||||
if self.major < other.major:
|
||||
if l[name] < r[name]:
|
||||
return False
|
||||
if self.minor > other.minor:
|
||||
return True
|
||||
if self.minor < other.minor:
|
||||
return False
|
||||
if self.revision > other.revision:
|
||||
return True
|
||||
return False
|
||||
|
||||
def __lt__(self, other: "Version") -> bool:
|
||||
|
@ -197,11 +196,8 @@ class Version:
|
|||
return self < other or self == other
|
||||
|
||||
def __eq__(self, other: "Version") -> bool:
|
||||
return (
|
||||
self.major == other.major and
|
||||
self.minor == other.minor and
|
||||
self.revision == other.revision and
|
||||
self.note == other.note)
|
||||
return self.data == other.data
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.major}.{self.minor}.{self.revision}{self.note}"
|
||||
return (f'{self.data["major"]}.{self.data["minor"]}'
|
||||
f'.{self.data["revision"]}{self.data["note"]}')
|
||||
|
|
|
@ -115,12 +115,10 @@ class AboutWindow(QtWidgets.QWidget):
|
|||
self.updateLabels()
|
||||
|
||||
def updateLabels(self):
|
||||
if self.app.vna.isValid():
|
||||
logger.debug("Valid VNA")
|
||||
v: Version = self.app.vna.version
|
||||
if self.app.interface.is_open:
|
||||
self.versionLabel.setText(
|
||||
f"NanoVNA Firmware Version: {self.app.vna.name} "
|
||||
f"v{v.version_string}")
|
||||
f"v{self.app.vna.version}")
|
||||
|
||||
def updateSettings(self):
|
||||
if self.updateCheckBox.isChecked():
|
||||
|
@ -150,7 +148,7 @@ class AboutWindow(QtWidgets.QWidget):
|
|||
self.app.settings.setValue("CheckForUpdates", "Ask")
|
||||
|
||||
def findUpdates(self, automatic=False):
|
||||
latest_version = Version("")
|
||||
latest_version = Version()
|
||||
latest_url = ""
|
||||
try:
|
||||
req = request.Request(VERSION_URL)
|
||||
|
@ -174,7 +172,7 @@ class AboutWindow(QtWidgets.QWidget):
|
|||
self.updateLabel.setText("Connection error.")
|
||||
return
|
||||
|
||||
logger.info("Latest version is %s", latest_version.version_string)
|
||||
logger.info("Latest version is %s", latest_version)
|
||||
this_version = Version(self.app.version)
|
||||
logger.info("This is %s", this_version)
|
||||
if latest_version > this_version:
|
||||
|
@ -183,9 +181,9 @@ class AboutWindow(QtWidgets.QWidget):
|
|||
QtWidgets.QMessageBox.information(
|
||||
self,
|
||||
"Updates available",
|
||||
"There is a new update for NanoVNA-Saver available!\n" +
|
||||
"Version " + latest_version.version_string + "\n\n" +
|
||||
"Press \"About\" to find the update.")
|
||||
f"There is a new update for NanoVNA-Saver available!\n"
|
||||
f"Version {latest_version}\n\n"
|
||||
f'Press "About" to find the update.')
|
||||
else:
|
||||
QtWidgets.QMessageBox.information(
|
||||
self, "Updates available",
|
||||
|
|
Ładowanie…
Reference in New Issue