Change device connections to catch initial device status

This commit is contained in:
Jan Käberich 2023-02-17 15:12:59 +01:00
parent 5544bec231
commit 289a3909fd
3 changed files with 31 additions and 27 deletions

View File

@ -541,7 +541,7 @@ void LibreVNADriver::handleReceivedPacket(const Protocol::PacketInfo &packet)
} }
switch(packet.type) { switch(packet.type) {
case Protocol::PacketType::DeviceInfo: case Protocol::PacketType::DeviceInfo: {
// Check protocol version // Check protocol version
if(packet.info.ProtocolVersion != Protocol::Version) { if(packet.info.ProtocolVersion != Protocol::Version) {
auto ret = InformationBox::AskQuestion("Warning", auto ret = InformationBox::AskQuestion("Warning",
@ -562,7 +562,8 @@ void LibreVNADriver::handleReceivedPacket(const Protocol::PacketInfo &packet)
Feature::SA, Feature::SATrackingGenerator, Feature::SATrackingOffset, Feature::SA, Feature::SATrackingGenerator, Feature::SATrackingOffset,
Feature::ExtRefIn, Feature::ExtRefOut, Feature::ExtRefIn, Feature::ExtRefOut,
}; };
info.Limits.VNA.ports = 2; auto ports = packet.info.hardware_version == 0xFF ? 1 : 2;
info.Limits.VNA.ports = ports;
info.Limits.VNA.minFreq = packet.info.limits_minFreq; info.Limits.VNA.minFreq = packet.info.limits_minFreq;
info.Limits.VNA.maxFreq = harmonicMixing ? packet.info.limits_maxFreqHarmonic : packet.info.limits_maxFreq; info.Limits.VNA.maxFreq = harmonicMixing ? packet.info.limits_maxFreqHarmonic : packet.info.limits_maxFreq;
info.Limits.VNA.maxPoints = packet.info.limits_maxPoints; info.Limits.VNA.maxPoints = packet.info.limits_maxPoints;
@ -571,13 +572,13 @@ void LibreVNADriver::handleReceivedPacket(const Protocol::PacketInfo &packet)
info.Limits.VNA.mindBm = (double) packet.info.limits_cdbm_min / 100; info.Limits.VNA.mindBm = (double) packet.info.limits_cdbm_min / 100;
info.Limits.VNA.maxdBm = (double) packet.info.limits_cdbm_max / 100; info.Limits.VNA.maxdBm = (double) packet.info.limits_cdbm_max / 100;
info.Limits.Generator.ports = 2; info.Limits.Generator.ports = ports;
info.Limits.Generator.minFreq = packet.info.limits_minFreq; info.Limits.Generator.minFreq = packet.info.limits_minFreq;
info.Limits.Generator.maxFreq = packet.info.limits_maxFreq; info.Limits.Generator.maxFreq = packet.info.limits_maxFreq;
info.Limits.Generator.mindBm = (double) packet.info.limits_cdbm_min / 100; info.Limits.Generator.mindBm = (double) packet.info.limits_cdbm_min / 100;
info.Limits.Generator.maxdBm = (double) packet.info.limits_cdbm_max / 100; info.Limits.Generator.maxdBm = (double) packet.info.limits_cdbm_max / 100;
info.Limits.SA.ports = 2; info.Limits.SA.ports = ports;
info.Limits.SA.minFreq = packet.info.limits_minFreq; info.Limits.SA.minFreq = packet.info.limits_minFreq;
info.Limits.SA.maxFreq = packet.info.limits_maxFreq; info.Limits.SA.maxFreq = packet.info.limits_maxFreq;
info.Limits.SA.minRBW = packet.info.limits_minRBW; info.Limits.SA.minRBW = packet.info.limits_minRBW;
@ -587,6 +588,7 @@ void LibreVNADriver::handleReceivedPacket(const Protocol::PacketInfo &packet)
limits_maxAmplitudePoints = packet.info.limits_maxAmplitudePoints; limits_maxAmplitudePoints = packet.info.limits_maxAmplitudePoints;
emit InfoUpdated(); emit InfoUpdated();
}
break; break;
case Protocol::PacketType::DeviceStatusV1: case Protocol::PacketType::DeviceStatusV1:
lastStatus = packet.statusV1; lastStatus = packet.statusV1;

View File

@ -18,14 +18,23 @@ static constexpr int SSDPport = 1900;
LibreVNATCPDriver::LibreVNATCPDriver() LibreVNATCPDriver::LibreVNATCPDriver()
: LibreVNADriver() : LibreVNADriver()
{ {
// dataSocket = nullptr;
// logSocket = nullptr;
connected = false; connected = false;
m_receiveThread = nullptr; m_receiveThread = nullptr;
auto interfaces = QNetworkInterface::allInterfaces(); auto interfaces = QNetworkInterface::allInterfaces();
for(auto i : interfaces) { for(auto i : interfaces) {
qDebug() << this << i.type();
switch(i.type()) {
case QNetworkInterface::Ethernet:
case QNetworkInterface::Wifi:
case QNetworkInterface::Virtual:
case QNetworkInterface::Unknown:
break;
default:
// skip all other interface types
continue;
}
auto socket = new QUdpSocket(); auto socket = new QUdpSocket();
socket->bind(QHostAddress::AnyIPv4, 0, QUdpSocket::ShareAddress); socket->bind(QHostAddress::AnyIPv4, 0, QUdpSocket::ShareAddress);
socket->setMulticastInterface(i); socket->setMulticastInterface(i);
@ -103,9 +112,6 @@ bool LibreVNATCPDriver::connectTo(QString serial)
} }
// attempt to connect to the device // attempt to connect to the device
// dataSocket = new QTcpSocket();
// logSocket = new QTcpSocket();
dataSocket.connectToHost(devInfo.address, DataPort); dataSocket.connectToHost(devInfo.address, DataPort);
logSocket.connectToHost(devInfo.address, LogPort); logSocket.connectToHost(devInfo.address, LogPort);
@ -114,10 +120,6 @@ bool LibreVNATCPDriver::connectTo(QString serial)
// at least one socket failed // at least one socket failed
dataSocket.close(); dataSocket.close();
logSocket.close(); logSocket.close();
// delete dataSocket;
// delete logSocket;
// dataSocket = nullptr;
// logSocket = nullptr;
InformationBox::ShowError("Error", "TCP connection timed out"); InformationBox::ShowError("Error", "TCP connection timed out");
return false; return false;
} }

View File

@ -17,7 +17,6 @@
#include "VNA/vna.h" #include "VNA/vna.h"
#include "Generator/generator.h" #include "Generator/generator.h"
#include "SpectrumAnalyzer/spectrumanalyzer.h" #include "SpectrumAnalyzer/spectrumanalyzer.h"
#include "CustomWidgets/jsonpickerdialog.h"
#include "CustomWidgets/informationbox.h" #include "CustomWidgets/informationbox.h"
#include "Util/app_common.h" #include "Util/app_common.h"
#include "about.h" #include "about.h"
@ -337,6 +336,20 @@ bool AppWindow::ConnectToDevice(QString serial, DeviceDriver *driver)
if(d->GetAvailableDevices().count(serial)) { if(d->GetAvailableDevices().count(serial)) {
// this driver can connect to the device // this driver can connect to the device
connect(d, &DeviceDriver::InfoUpdated, this, &AppWindow::DeviceInfoUpdated, Qt::QueuedConnection); connect(d, &DeviceDriver::InfoUpdated, this, &AppWindow::DeviceInfoUpdated, Qt::QueuedConnection);
connect(d, &DeviceDriver::LogLineReceived, &deviceLog, &DeviceLog::addLine);
connect(d, &DeviceDriver::ConnectionLost, this, &AppWindow::DeviceConnectionLost);
connect(d, &DeviceDriver::StatusUpdated, this, &AppWindow::DeviceStatusUpdated);
connect(d, &DeviceDriver::FlagsUpdated, this, &AppWindow::DeviceFlagsUpdated);
connect(d, &DeviceDriver::releaseControl, this, [=](){
if(lastActiveMode) {
modeHandler->activate(lastActiveMode);
}
});
connect(d, &DeviceDriver::acquireControl, this, [=](){
lastActiveMode = modeHandler->getActiveMode();
modeHandler->deactivate(lastActiveMode);
});
if(d->connectDevice(serial)) { if(d->connectDevice(serial)) {
device = d; device = d;
} else { } else {
@ -351,19 +364,6 @@ bool AppWindow::ConnectToDevice(QString serial, DeviceDriver *driver)
return false; return false;
} }
UpdateStatusBar(AppWindow::DeviceStatusBar::Connected); UpdateStatusBar(AppWindow::DeviceStatusBar::Connected);
connect(device, &DeviceDriver::LogLineReceived, &deviceLog, &DeviceLog::addLine);
connect(device, &DeviceDriver::ConnectionLost, this, &AppWindow::DeviceConnectionLost);
connect(device, &DeviceDriver::StatusUpdated, this, &AppWindow::DeviceStatusUpdated);
connect(device, &DeviceDriver::FlagsUpdated, this, &AppWindow::DeviceFlagsUpdated);
connect(device, &DeviceDriver::releaseControl, this, [=](){
if(lastActiveMode) {
modeHandler->activate(lastActiveMode);
}
});
connect(device, &DeviceDriver::acquireControl, this, [=](){
lastActiveMode = modeHandler->getActiveMode();
modeHandler->deactivate(lastActiveMode);
});
// connect(vdevice, &VirtualDevice::NeedsFirmwareUpdate, this, &AppWindow::DeviceNeedsUpdate); // connect(vdevice, &VirtualDevice::NeedsFirmwareUpdate, this, &AppWindow::DeviceNeedsUpdate);
ui->actionDisconnect->setEnabled(true); ui->actionDisconnect->setEnabled(true);
// find correct position to add device specific actions at // find correct position to add device specific actions at