mirror of
https://github.com/jankae/LibreVNA.git
synced 2025-12-06 07:12:10 +01:00
fix tests
This commit is contained in:
parent
b95e966041
commit
9e33a294cd
|
|
@ -44,6 +44,9 @@ LibreVNATCPDriver::LibreVNATCPDriver()
|
||||||
ssdpSockets.push_back(socket);
|
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(&captureRawReceiverValues, "LibreVNATCPDriver.captureRawReceiverValues", false));
|
||||||
specificSettings.push_back(Savable::SettingDescription(&harmonicMixing, "LibreVNATCPDriver.harmonicMixing", false));
|
specificSettings.push_back(Savable::SettingDescription(&harmonicMixing, "LibreVNATCPDriver.harmonicMixing", false));
|
||||||
specificSettings.push_back(Savable::SettingDescription(&SASignalID, "LibreVNATCPDriver.signalID", true));
|
specificSettings.push_back(Savable::SettingDescription(&SASignalID, "LibreVNATCPDriver.signalID", true));
|
||||||
|
|
@ -60,26 +63,6 @@ QString LibreVNATCPDriver::getDriverName()
|
||||||
|
|
||||||
std::set<QString> LibreVNATCPDriver::GetAvailableDevices()
|
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;
|
std::set<QString> serials;
|
||||||
for(auto d : detectedDevices) {
|
for(auto d : detectedDevices) {
|
||||||
serials.insert(d.serial);
|
serials.insert(d.serial);
|
||||||
|
|
@ -171,6 +154,25 @@ void LibreVNATCPDriver::registerTypes()
|
||||||
qDebug() << "Registering meta type: " << qRegisterMetaType<TransmissionResult>();
|
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)
|
void LibreVNATCPDriver::SSDPreceived(QUdpSocket *sock)
|
||||||
{
|
{
|
||||||
while(sock->hasPendingDatagrams()) {
|
while(sock->hasPendingDatagrams()) {
|
||||||
|
|
@ -183,7 +185,7 @@ void LibreVNATCPDriver::SSDPreceived(QUdpSocket *sock)
|
||||||
QString ssdp_string = QString(buf);
|
QString ssdp_string = QString(buf);
|
||||||
auto lines = ssdp_string.split("\r\n");
|
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") {
|
if(lines[0] != "HTTP/1.1 200 OK") {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void SSDRequest();
|
||||||
void SSDPreceived(QUdpSocket *sock);
|
void SSDPreceived(QUdpSocket *sock);
|
||||||
void ReceivedData();
|
void ReceivedData();
|
||||||
void ReceivedLog();
|
void ReceivedLog();
|
||||||
|
|
@ -101,6 +102,7 @@ private:
|
||||||
QQueue<Transmission> transmissionQueue;
|
QQueue<Transmission> transmissionQueue;
|
||||||
bool startNextTransmission();
|
bool startNextTransmission();
|
||||||
QTimer transmissionTimer;
|
QTimer transmissionTimer;
|
||||||
|
QTimer ssdpTimer;
|
||||||
bool transmissionActive;
|
bool transmissionActive;
|
||||||
|
|
||||||
std::thread *m_receiveThread;
|
std::thread *m_receiveThread;
|
||||||
|
|
|
||||||
|
|
@ -11,42 +11,6 @@
|
||||||
#include <QEventLoop>
|
#include <QEventLoop>
|
||||||
#include <QTimer>
|
#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 {
|
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) {
|
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;
|
T normalized;
|
||||||
|
|
|
||||||
|
|
@ -1019,7 +1019,7 @@ void AppWindow::SetupSCPI()
|
||||||
void AppWindow::StartTCPServer(int port)
|
void AppWindow::StartTCPServer(int port)
|
||||||
{
|
{
|
||||||
server = new TCPServer(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);
|
connect(&scpi, &SCPI::output, server, &TCPServer::send);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,9 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
SCPI::SCPI() :
|
SCPI::SCPI() :
|
||||||
SCPINode("")
|
SCPINode(""),
|
||||||
|
semQueue(QSemaphore(1)),
|
||||||
|
semProcessing(QSemaphore(1))
|
||||||
{
|
{
|
||||||
WAIexecuting = false;
|
WAIexecuting = false;
|
||||||
OPCsetBitScheduled = false;
|
OPCsetBitScheduled = false;
|
||||||
|
|
@ -178,21 +180,30 @@ QString SCPI::getResultName(SCPI::Result r)
|
||||||
|
|
||||||
void SCPI::input(QString line)
|
void SCPI::input(QString line)
|
||||||
{
|
{
|
||||||
|
semQueue.acquire();
|
||||||
cmdQueue.append(line);
|
cmdQueue.append(line);
|
||||||
if(!processing) {
|
semQueue.release();
|
||||||
|
if(semProcessing.available()) {
|
||||||
process();
|
process();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SCPI::process()
|
void SCPI::process()
|
||||||
{
|
{
|
||||||
processing = true;
|
semProcessing.acquire();
|
||||||
while(!WAIexecuting && !cmdQueue.isEmpty()) {
|
semQueue.acquire();
|
||||||
|
auto queueBuf = cmdQueue;
|
||||||
|
semQueue.release();
|
||||||
|
while(!WAIexecuting && !queueBuf.isEmpty()) {
|
||||||
|
semQueue.acquire();
|
||||||
auto cmd = cmdQueue.front();
|
auto cmd = cmdQueue.front();
|
||||||
cmdQueue.pop_front();
|
cmdQueue.pop_front();
|
||||||
|
queueBuf = cmdQueue;
|
||||||
|
semQueue.release();
|
||||||
auto cmds = cmd.split(";");
|
auto cmds = cmd.split(";");
|
||||||
SCPINode *lastNode = this;
|
SCPINode *lastNode = this;
|
||||||
for(auto cmd : cmds) {
|
for(auto cmd : cmds) {
|
||||||
|
qDebug() << "Handling cmd " << cmd;
|
||||||
if(cmd.size() > 0) {
|
if(cmd.size() > 0) {
|
||||||
if(cmd[0] == ':' || cmd[0] == '*') {
|
if(cmd[0] == ':' || cmd[0] == '*') {
|
||||||
// reset to root node
|
// reset to root node
|
||||||
|
|
@ -216,9 +227,10 @@ void SCPI::process()
|
||||||
emit output(response);
|
emit output(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
qDebug() << "handling done";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
processing = false;
|
semProcessing.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SCPI::someOperationCompleted()
|
void SCPI::someOperationCompleted()
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QSemaphore>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
|
@ -122,6 +123,8 @@ private:
|
||||||
|
|
||||||
QList<QString> cmdQueue;
|
QList<QString> cmdQueue;
|
||||||
bool processing;
|
bool processing;
|
||||||
|
QSemaphore semQueue;
|
||||||
|
QSemaphore semProcessing;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SCPI_H
|
#endif // SCPI_H
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue