Save/load calkit SCPI command + re-entrancy bugfix during calibration
This commit is contained in:
parent
9b7f457aa5
commit
b03c8b3958
@ -1,10 +1,12 @@
|
||||
import socket
|
||||
from asyncio import IncompleteReadError # only import the exception class
|
||||
import time
|
||||
|
||||
class SocketStreamReader:
|
||||
def __init__(self, sock: socket.socket):
|
||||
self._sock = sock
|
||||
self._recv_buffer = bytearray()
|
||||
self.timeout = 1.0
|
||||
|
||||
def read(self, num_bytes: int = -1) -> bytes:
|
||||
raise NotImplementedError
|
||||
@ -32,10 +34,13 @@ class SocketStreamReader:
|
||||
bytes_read = self._recv_into(memoryview(buf))
|
||||
assert bytes_read == len(buf)
|
||||
|
||||
timeout = time.time() + self.timeout
|
||||
while True:
|
||||
idx = buf.find(separator, start)
|
||||
if idx != -1:
|
||||
break
|
||||
elif time.time() > timeout:
|
||||
raise Exception("Timed out waiting for response from GUI")
|
||||
|
||||
start = len(self._recv_buffer)
|
||||
bytes_read = self._recv_into(memoryview(chunk))
|
||||
@ -53,7 +58,10 @@ class SocketStreamReader:
|
||||
self._recv_buffer = self._recv_buffer[bytes_read:]
|
||||
if bytes_read == len(view):
|
||||
return bytes_read
|
||||
bytes_read += self._sock.recv_into(view[bytes_read:])
|
||||
try:
|
||||
bytes_read += self._sock.recv_into(view[bytes_read:], 0, socket.MSG_DONTWAIT)
|
||||
except:
|
||||
pass
|
||||
return bytes_read
|
||||
|
||||
class libreVNA:
|
||||
|
@ -293,6 +293,7 @@ Calibration::Calibration()
|
||||
}
|
||||
return SCPI::getResultName(SCPI::Result::True);
|
||||
}));
|
||||
add(&kit);
|
||||
}
|
||||
|
||||
QString Calibration::TypeToString(Calibration::Type type)
|
||||
|
@ -16,12 +16,33 @@ using json = nlohmann::json;
|
||||
using namespace std;
|
||||
|
||||
Calkit::Calkit()
|
||||
: SCPINode("KIT")
|
||||
{
|
||||
|
||||
// set default values
|
||||
for(auto e : descr) {
|
||||
e.var.setValue(e.def);
|
||||
}
|
||||
|
||||
add(new SCPICommand("SAVE", [=](QStringList params) -> QString {
|
||||
if(params.size() != 1 ) {
|
||||
// no filename given or no calibration active
|
||||
return SCPI::getResultName(SCPI::Result::Error);
|
||||
}
|
||||
toFile(params[0]);
|
||||
return SCPI::getResultName(SCPI::Result::Empty);
|
||||
}, nullptr));
|
||||
add(new SCPICommand("LOAD", nullptr, [=](QStringList params) -> QString {
|
||||
if(params.size() != 1) {
|
||||
// no filename given or no calibration active
|
||||
return SCPI::getResultName(SCPI::Result::False);
|
||||
}
|
||||
try {
|
||||
*this = fromFile(params[0]);
|
||||
return SCPI::getResultName(SCPI::Result::True);
|
||||
} catch (runtime_error &e) {
|
||||
return SCPI::getResultName(SCPI::Result::False);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
void Calkit::toFile(QString filename)
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "Util/qpointervariant.h"
|
||||
#include "calstandard.h"
|
||||
#include "savable.h"
|
||||
#include "scpi.h"
|
||||
|
||||
#include "LibreCAL/caldevice.h"
|
||||
|
||||
@ -12,7 +13,7 @@
|
||||
#include <complex>
|
||||
#include <QDir>
|
||||
|
||||
class Calkit : public Savable
|
||||
class Calkit : public Savable, public SCPINode
|
||||
{
|
||||
friend class CalkitDialog;
|
||||
friend class LibreCALDialog;
|
||||
|
@ -510,6 +510,7 @@ void Device::ReceivedData()
|
||||
dataBuffer->removeBytes(handled_len);
|
||||
switch(packet.type) {
|
||||
case Protocol::PacketType::VNADatapoint:
|
||||
// qDebug() << "Got point" << packet.VNAdatapoint->pointNum;
|
||||
emit DatapointReceived(this, packet.VNAdatapoint);
|
||||
break;
|
||||
case Protocol::PacketType::ManualStatusV1:
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "virtualdevice.h"
|
||||
#include "virtualdevice.h"
|
||||
|
||||
#include "preferences.h"
|
||||
#include "CustomWidgets/informationbox.h"
|
||||
|
@ -64,6 +64,9 @@ VNA::VNA(AppWindow *window, QString name)
|
||||
calMeasuring = false;
|
||||
calWaitFirst = false;
|
||||
calDialog.reset();
|
||||
// A modal QProgressDialog calls processEvents() in setValue(). Needs to use a queued connection to update the progress
|
||||
// value from within the NewDatapoint slot to prevent possible re-entrancy.
|
||||
connect(this, &VNA::calibrationMeasurementPercentage, &calDialog, &QProgressDialog::setValue, Qt::QueuedConnection);
|
||||
changingSettings = false;
|
||||
settings.sweepType = SweepType::Frequency;
|
||||
settings.zerospan = false;
|
||||
@ -837,11 +840,12 @@ void VNA::NewDatapoint(VirtualDevice::VNAMeasurement m)
|
||||
if(m_avg.pointNum == settings.npoints - 1) {
|
||||
calMeasuring = false;
|
||||
cal.measurementsComplete();
|
||||
calDialog.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
int percentage = (((average.currentSweep() - 1) * 100) + (m_avg.pointNum + 1) * 100 / settings.npoints) / averages;
|
||||
calDialog.setValue(percentage);
|
||||
emit calibrationMeasurementPercentage(percentage);
|
||||
}
|
||||
|
||||
cal.correctMeasurement(m_avg);
|
||||
@ -879,6 +883,7 @@ void VNA::NewDatapoint(VirtualDevice::VNAMeasurement m)
|
||||
UpdateAverageCount();
|
||||
markerModel->updateMarkers();
|
||||
}
|
||||
|
||||
static unsigned int lastPoint = 0;
|
||||
if(m_avg.pointNum > 0 && m_avg.pointNum != lastPoint + 1) {
|
||||
qWarning() << "Got point" << m_avg.pointNum << "but last received point was" << lastPoint << "("<<(m_avg.pointNum-lastPoint-1)<<"missed points)";
|
||||
|
@ -191,6 +191,8 @@ signals:
|
||||
|
||||
void sweepStopped();
|
||||
void sweepStarted();
|
||||
|
||||
void calibrationMeasurementPercentage(int percent);
|
||||
};
|
||||
|
||||
#endif // VNA_H
|
||||
|
@ -546,7 +546,7 @@ void AppWindow::SetupSCPI()
|
||||
if(active) {
|
||||
switch(active->getType()) {
|
||||
case Mode::Type::VNA: return "VNA";
|
||||
case Mode::Type::SG: return "SG";
|
||||
case Mode::Type::SG: return "GEN";
|
||||
case Mode::Type::SA: return "SA";
|
||||
case Mode::Type::Last: return SCPI::getResultName(SCPI::Result::Error);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user