Skip to content

Commit

Permalink
added streaming servers
Browse files Browse the repository at this point in the history
  • Loading branch information
jankae committed Jun 20, 2024
1 parent 2ba9545 commit 6ca5454
Show file tree
Hide file tree
Showing 11 changed files with 457 additions and 12 deletions.
2 changes: 2 additions & 0 deletions Software/PC_Application/LibreVNA-GUI/LibreVNA-GUI.pro
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ HEADERS += \
preferences.h \
savable.h \
scpi.h \
streamingserver.h \
tcpserver.h \
touchstone.h \
unit.h
Expand Down Expand Up @@ -301,6 +302,7 @@ SOURCES += \
preferences.cpp \
savable.cpp \
scpi.cpp \
streamingserver.cpp \
tcpserver.cpp \
touchstone.cpp \
unit.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,8 @@ void SpectrumAnalyzer::NewDatapoint(DeviceDriver::SAMeasurement m)
}
}

window->addStreamingData(m_avg, AppWindow::SADataType::Raw);

if(normalize.measuring) {
if(average.currentSweep() == averages) {
// this is the last averaging sweep, use values for normalization
Expand Down Expand Up @@ -561,6 +563,8 @@ void SpectrumAnalyzer::NewDatapoint(DeviceDriver::SAMeasurement m)
}
}

window->addStreamingData(m_avg, AppWindow::SADataType::Normalized);

traceModel.addSAData(m_avg, settings);
emit dataChanged();
if(m_avg.pointNum == DeviceDriver::SApoints() - 1) {
Expand Down
8 changes: 8 additions & 0 deletions Software/PC_Application/LibreVNA-GUI/VNA/vna.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,9 @@ void VNA::NewDatapoint(DeviceDriver::VNAMeasurement m)
}

m_avg = average.process(m_avg);

window->addStreamingData(m_avg, AppWindow::VNADataType::Raw);

if(average.settled()) {
setOperationPending(false);
}
Expand All @@ -955,6 +958,8 @@ void VNA::NewDatapoint(DeviceDriver::VNAMeasurement m)

cal.correctMeasurement(m_avg);

window->addStreamingData(m_avg, AppWindow::VNADataType::Calibrated);

TraceMath::DataType type;
if(settings.zerospan) {
type = TraceMath::DataType::TimeZeroSpan;
Expand Down Expand Up @@ -983,6 +988,9 @@ void VNA::NewDatapoint(DeviceDriver::VNAMeasurement m)
deembedding.Deembed(m_avg);
traceModel.addVNAData(m_avg, type, true);
}

window->addStreamingData(m_avg, AppWindow::VNADataType::Deembedded);

emit dataChanged();
if(m_avg.pointNum == settings.npoints - 1) {
UpdateAverageCount();
Expand Down
75 changes: 72 additions & 3 deletions Software/PC_Application/LibreVNA-GUI/appwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ AppWindow::AppWindow(QWidget *parent)
, deviceActionGroup(new QActionGroup(this))
, ui(new Ui::MainWindow)
, server(nullptr)
, streamVNARawData(nullptr)
, streamVNACalibratedData(nullptr)
, streamVNADeembeddedData(nullptr)
, streamSARawData(nullptr)
, streamSANormalizedData(nullptr)
, appVersion(APP_VERSION)
, appGitHash(APP_GIT_HASH)
{
Expand Down Expand Up @@ -97,6 +102,8 @@ AppWindow::AppWindow(QWidget *parent)
Preferences::getInstance().load();
}

auto &p = Preferences::getInstance();

device = nullptr;
// vdevice = nullptr;
modeHandler = nullptr;
Expand All @@ -109,9 +116,25 @@ AppWindow::AppWindow(QWidget *parent)
port = Preferences::getInstance().SCPIServer.port;
}
StartTCPServer(port);
Preferences::getInstance().manualTCPport();
} else if(Preferences::getInstance().SCPIServer.enabled) {
StartTCPServer(Preferences::getInstance().SCPIServer.port);
p.manualTCPport();
} else if(p.SCPIServer.enabled) {
StartTCPServer(p.SCPIServer.port);
}

if(p.StreamingServers.VNARawData.enabled) {
streamVNARawData = new StreamingServer(p.StreamingServers.VNARawData.port);
}
if(p.StreamingServers.VNACalibratedData.enabled) {
streamVNACalibratedData = new StreamingServer(p.StreamingServers.VNACalibratedData.port);
}
if(p.StreamingServers.VNADeembeddedData.enabled) {
streamVNADeembeddedData = new StreamingServer(p.StreamingServers.VNADeembeddedData.port);
}
if(p.StreamingServers.SARawData.enabled) {
streamSARawData = new StreamingServer(p.StreamingServers.SARawData.port);
}
if(p.StreamingServers.SANormalizedData.enabled) {
streamSANormalizedData = new StreamingServer(p.StreamingServers.SANormalizedData.port);
}

ui->setupUi(this);
Expand Down Expand Up @@ -1019,6 +1042,25 @@ void AppWindow::preferencesChanged()
StopTCPServer();
StartTCPServer(p.SCPIServer.port);
}

auto updateStreamingServer = [](StreamingServer **server, bool enabled, int port) {
if(*server && !enabled) {
delete *server;
*server = nullptr;
} else if(!*server && enabled) {
*server = new StreamingServer(port);
} else if(*server && (*server)->getPort() != port) {
delete *server;
*server = new StreamingServer(port);
}
};

updateStreamingServer(&streamVNARawData, p.StreamingServers.VNARawData.enabled, p.StreamingServers.VNARawData.port);
updateStreamingServer(&streamVNACalibratedData, p.StreamingServers.VNACalibratedData.enabled, p.StreamingServers.VNACalibratedData.port);
updateStreamingServer(&streamVNADeembeddedData, p.StreamingServers.VNADeembeddedData.enabled, p.StreamingServers.VNADeembeddedData.port);
updateStreamingServer(&streamSARawData, p.StreamingServers.SARawData.enabled, p.StreamingServers.SARawData.port);
updateStreamingServer(&streamSANormalizedData, p.StreamingServers.SANormalizedData.enabled, p.StreamingServers.SANormalizedData.port);

// averaging mode may have changed, update for all relevant modes
for (auto m : modeHandler->getModes())
{
Expand Down Expand Up @@ -1055,6 +1097,33 @@ SCPI* AppWindow::getSCPI()
return &scpi;
}

void AppWindow::addStreamingData(const DeviceDriver::VNAMeasurement &m, VNADataType type)
{
StreamingServer *server = nullptr;
switch(type) {
case VNADataType::Raw: server = streamVNARawData; break;
case VNADataType::Calibrated: server = streamVNACalibratedData; break;
case VNADataType::Deembedded: server = streamVNADeembeddedData; break;
}

if(server) {
server->addData(m);
}
}

void AppWindow::addStreamingData(const DeviceDriver::SAMeasurement &m, SADataType type)
{
StreamingServer *server = nullptr;
switch(type) {
case SADataType::Raw: server = streamSARawData; break;
case SADataType::Normalized: server = streamSANormalizedData; break;
}

if(server) {
server->addData(m);
}
}

void AppWindow::setModeStatus(QString msg)
{
lModeInfo.setText(msg);
Expand Down
21 changes: 21 additions & 0 deletions Software/PC_Application/LibreVNA-GUI/appwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "preferences.h"
#include "scpi.h"
#include "tcpserver.h"
#include "streamingserver.h"
#include "Device/devicedriver.h"

#include <QWidget>
Expand Down Expand Up @@ -52,6 +53,21 @@ class AppWindow : public QMainWindow

SCPI* getSCPI();

enum class VNADataType {
Raw = 0,
Calibrated = 1,
Deembedded = 2,
};

void addStreamingData(const DeviceDriver::VNAMeasurement &m, VNADataType type);

enum class SADataType {
Raw = 0,
Normalized = 1,
};

void addStreamingData(const DeviceDriver::SAMeasurement &m, SADataType type);

public slots:
void setModeStatus(QString msg);

Expand Down Expand Up @@ -143,6 +159,11 @@ private slots:

SCPI scpi;
TCPServer *server;
StreamingServer *streamVNARawData;
StreamingServer *streamVNACalibratedData;
StreamingServer *streamVNADeembeddedData;
StreamingServer *streamSARawData;
StreamingServer *streamSANormalizedData;

QString appVersion;
QString appGitHash;
Expand Down
22 changes: 22 additions & 0 deletions Software/PC_Application/LibreVNA-GUI/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,17 @@ void PreferencesDialog::setInitialGUIState()
ui->SCPIServerEnabled->setChecked(p->SCPIServer.enabled);
ui->SCPIServerPort->setValue(p->SCPIServer.port);

ui->streamingServerVNArawEnabled->setChecked(p->StreamingServers.VNARawData.enabled);
ui->streamingServerVNArawPort->setValue(p->StreamingServers.VNARawData.port);
ui->streamingServerVNAcalibratedEnabled->setChecked(p->StreamingServers.VNACalibratedData.enabled);
ui->streamingServerVNAcalibratedPort->setValue(p->StreamingServers.VNACalibratedData.port);
ui->streamingServerVNAdeembeddedEnabled->setChecked(p->StreamingServers.VNADeembeddedData.enabled);
ui->streamingServerVNAdeembeddedPort->setValue(p->StreamingServers.VNADeembeddedData.port);
ui->streamingServerSArawEnabled->setChecked(p->StreamingServers.SARawData.enabled);
ui->streamingServerSArawPort->setValue(p->StreamingServers.SARawData.port);
ui->streamingServerSAnormalizedEnabled->setChecked(p->StreamingServers.SANormalizedData.enabled);
ui->streamingServerSAnormalizedPort->setValue(p->StreamingServers.SANormalizedData.port);

ui->DebugMaxUSBlogSize->setValue(p->Debug.USBlogSizeLimit);
ui->DebugSaveTraceData->setChecked(p->Debug.saveTraceData);

Expand Down Expand Up @@ -420,6 +431,17 @@ void PreferencesDialog::updateFromGUI()
p->SCPIServer.enabled = ui->SCPIServerEnabled->isChecked();
p->SCPIServer.port = ui->SCPIServerPort->value();

p->StreamingServers.VNARawData.enabled = ui->streamingServerVNArawEnabled->isChecked();
p->StreamingServers.VNARawData.port = ui->streamingServerVNArawPort->value();
p->StreamingServers.VNACalibratedData.enabled = ui->streamingServerVNAcalibratedEnabled->isChecked();
p->StreamingServers.VNACalibratedData.port = ui->streamingServerVNAcalibratedPort->value();
p->StreamingServers.VNADeembeddedData.enabled = ui->streamingServerVNAdeembeddedEnabled->isChecked();
p->StreamingServers.VNADeembeddedData.port = ui->streamingServerVNAdeembeddedPort->value();
p->StreamingServers.SARawData.enabled = ui->streamingServerSArawEnabled->isChecked();
p->StreamingServers.SARawData.port = ui->streamingServerSArawPort->value();
p->StreamingServers.SANormalizedData.enabled = ui->streamingServerSAnormalizedEnabled->isChecked();
p->StreamingServers.SANormalizedData.port = ui->streamingServerSAnormalizedPort->value();

p->Debug.USBlogSizeLimit = ui->DebugMaxUSBlogSize->value();
p->Debug.saveTraceData = ui->DebugSaveTraceData->isChecked();

Expand Down
32 changes: 32 additions & 0 deletions Software/PC_Application/LibreVNA-GUI/preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,28 @@ class Preferences : public Savable {
bool enabled;
int port;
} SCPIServer;
struct {
struct {
bool enabled;
int port;
} VNARawData;
struct {
bool enabled;
int port;
} VNACalibratedData;
struct {
bool enabled;
int port;
} VNADeembeddedData;
struct {
bool enabled;
int port;
} SARawData;
struct {
bool enabled;
int port;
} SANormalizedData;
} StreamingServers;
struct {
double USBlogSizeLimit;
bool saveTraceData;
Expand Down Expand Up @@ -273,6 +295,16 @@ class Preferences : public Savable {
{&Marker.symbolStyle, "Marker.symbolStyle", MarkerSymbolStyle::EmptyNumberAbove},
{&SCPIServer.enabled, "SCPIServer.enabled", true},
{&SCPIServer.port, "SCPIServer.port", 19542},
{&StreamingServers.VNARawData.enabled, "StreamingServers.VNARawData.enabled", false},
{&StreamingServers.VNARawData.port, "StreamingServers.VNARawData.port", 19000},
{&StreamingServers.VNACalibratedData.enabled, "StreamingServers.VNACalibratedData.enabled", false},
{&StreamingServers.VNACalibratedData.port, "StreamingServers.VNACalibratedData.port", 19001},
{&StreamingServers.VNADeembeddedData.enabled, "StreamingServers.VNADeembeddedData.enabled", false},
{&StreamingServers.VNADeembeddedData.port, "StreamingServers.VNADeembeddedData.port", 19002},
{&StreamingServers.SARawData.enabled, "StreamingServers.sARawData.enabled", false},
{&StreamingServers.SARawData.port, "StreamingServers.sARawData.port", 19100},
{&StreamingServers.SANormalizedData.enabled, "StreamingServers.SANormalizedData.enabled", false},
{&StreamingServers.SANormalizedData.port, "StreamingServers.SANormalizedData.port", 19101},
{&Debug.USBlogSizeLimit, "Debug.USBlogSizeLimit", 10000000.0},
{&Debug.saveTraceData, "Debug.saveTraceData", false},
}};
Expand Down
Loading

0 comments on commit 6ca5454

Please sign in to comment.