Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jankae committed Dec 2, 2024
1 parent b95e966 commit 9e33a29
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ LibreVNATCPDriver::LibreVNATCPDriver()
ssdpSockets.push_back(socket);
}

connect(&ssdpTimer, &QTimer::timeout,this, &LibreVNATCPDriver::SSDRequest);
ssdpTimer.start(1000);

specificSettings.push_back(Savable::SettingDescription(&captureRawReceiverValues, "LibreVNATCPDriver.captureRawReceiverValues", false));
specificSettings.push_back(Savable::SettingDescription(&harmonicMixing, "LibreVNATCPDriver.harmonicMixing", false));
specificSettings.push_back(Savable::SettingDescription(&SASignalID, "LibreVNATCPDriver.signalID", true));
Expand All @@ -60,26 +63,6 @@ QString LibreVNATCPDriver::getDriverName()

std::set<QString> LibreVNATCPDriver::GetAvailableDevices()
{
QByteArray data;
data.append("M-SEARCH * HTTP/1.1\r\n"
"HOST: 239.255.255.250:1900\r\n"
"MAN: \"ssdp:discover\"\r\n"
"MX: 1\r\n"
"ST: ");
data.append(service_name.toUtf8());
data.append("\r\n"
"\r\n");

// just delete everything instead of keeping old entries (they will answer again if they are still available)
detectedDevices.clear();
// pruneDetectedDevices();
for(auto s : ssdpSockets) {
s->writeDatagram(data.data(), SSDPaddress, SSDPport);
}

// need delay here while still processing events
SynSleep::sleep(100);

std::set<QString> serials;
for(auto d : detectedDevices) {
serials.insert(d.serial);
Expand Down Expand Up @@ -171,6 +154,25 @@ void LibreVNATCPDriver::registerTypes()
qDebug() << "Registering meta type: " << qRegisterMetaType<TransmissionResult>();
}

void LibreVNATCPDriver::SSDRequest()
{
QByteArray data;
data.append("M-SEARCH * HTTP/1.1\r\n"
"HOST: 239.255.255.250:1900\r\n"
"MAN: \"ssdp:discover\"\r\n"
"MX: 1\r\n"
"ST: ");
data.append(service_name.toUtf8());
data.append("\r\n"
"\r\n");

pruneDetectedDevices();

for(auto s : ssdpSockets) {
s->writeDatagram(data.data(), SSDPaddress, SSDPport);
}
}

void LibreVNATCPDriver::SSDPreceived(QUdpSocket *sock)
{
while(sock->hasPendingDatagrams()) {
Expand All @@ -183,7 +185,7 @@ void LibreVNATCPDriver::SSDPreceived(QUdpSocket *sock)
QString ssdp_string = QString(buf);
auto lines = ssdp_string.split("\r\n");

QString location, st, serial, max_age;
QString location, st, serial, max_age = "2";

if(lines[0] != "HTTP/1.1 200 OK") {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class LibreVNATCPDriver : public LibreVNADriver
}

private slots:
void SSDRequest();
void SSDPreceived(QUdpSocket *sock);
void ReceivedData();
void ReceivedLog();
Expand Down Expand Up @@ -101,6 +102,7 @@ private slots:
QQueue<Transmission> transmissionQueue;
bool startNextTransmission();
QTimer transmissionTimer;
QTimer ssdpTimer;
bool transmissionActive;

std::thread *m_receiveThread;
Expand Down
36 changes: 0 additions & 36 deletions Software/PC_Application/LibreVNA-GUI/Util/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,6 @@
#include <QEventLoop>
#include <QTimer>

class SynSleep: public QObject {
Q_OBJECT
public:
SynSleep(){
needRunning=1;
}

public slots:
void sleep(){
if (needRunning==1)
loop.exec();
}

void reset(){
needRunning=1;
}

virtual void finish(){
needRunning=0;
loop.exit();
}

static void sleep(int ms) {
QTimer tim;
tim.setSingleShot(true);
auto ss = SynSleep();
connect(&tim, &QTimer::timeout, &ss, &SynSleep::finish);
tim.start(ms);
ss.sleep();
}

private:
QEventLoop loop;
int needRunning;
};

namespace Util {
template<typename T> T Scale(T value, T from_low, T from_high, T to_low, T to_high, bool log_from = false, bool log_to = false) {
T normalized;
Expand Down
2 changes: 1 addition & 1 deletion Software/PC_Application/LibreVNA-GUI/appwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ void AppWindow::SetupSCPI()
void AppWindow::StartTCPServer(int port)
{
server = new TCPServer(port);
connect(server, &TCPServer::received, &scpi, &SCPI::input, Qt::QueuedConnection);
connect(server, &TCPServer::received, &scpi, &SCPI::input);
connect(&scpi, &SCPI::output, server, &TCPServer::send);
}

Expand Down
22 changes: 17 additions & 5 deletions Software/PC_Application/LibreVNA-GUI/scpi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#include <QDebug>

SCPI::SCPI() :
SCPINode("")
SCPINode(""),
semQueue(QSemaphore(1)),
semProcessing(QSemaphore(1))
{
WAIexecuting = false;
OPCsetBitScheduled = false;
Expand Down Expand Up @@ -178,21 +180,30 @@ QString SCPI::getResultName(SCPI::Result r)

void SCPI::input(QString line)
{
semQueue.acquire();
cmdQueue.append(line);
if(!processing) {
semQueue.release();
if(semProcessing.available()) {
process();
}
}

void SCPI::process()
{
processing = true;
while(!WAIexecuting && !cmdQueue.isEmpty()) {
semProcessing.acquire();
semQueue.acquire();
auto queueBuf = cmdQueue;
semQueue.release();
while(!WAIexecuting && !queueBuf.isEmpty()) {
semQueue.acquire();
auto cmd = cmdQueue.front();
cmdQueue.pop_front();
queueBuf = cmdQueue;
semQueue.release();
auto cmds = cmd.split(";");
SCPINode *lastNode = this;
for(auto cmd : cmds) {
qDebug() << "Handling cmd " << cmd;
if(cmd.size() > 0) {
if(cmd[0] == ':' || cmd[0] == '*') {
// reset to root node
Expand All @@ -216,9 +227,10 @@ void SCPI::process()
emit output(response);
}
}
qDebug() << "handling done";
}
}
processing = false;
semProcessing.release();
}

void SCPI::someOperationCompleted()
Expand Down
3 changes: 3 additions & 0 deletions Software/PC_Application/LibreVNA-GUI/scpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <QString>
#include <QObject>
#include <QSemaphore>
#include <vector>
#include <functional>

Expand Down Expand Up @@ -122,6 +123,8 @@ public slots:

QList<QString> cmdQueue;
bool processing;
QSemaphore semQueue;
QSemaphore semProcessing;
};

#endif // SCPI_H

0 comments on commit 9e33a29

Please sign in to comment.