diff --git a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/amplitudecaldialog.cpp b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/amplitudecaldialog.cpp index 20b40fa..4b598f7 100644 --- a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/amplitudecaldialog.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/amplitudecaldialog.cpp @@ -192,7 +192,7 @@ void AmplitudeCalDialog::setAmplitude(double amplitude, unsigned int point, bool void AmplitudeCalDialog::ReceivedPoint(Protocol::AmplitudeCorrectionPoint p) { -// qDebug() << "Received amplitude calibration point" << p.pointNum << "/" << p.totalPoints; + qDebug() << "Received amplitude calibration point" << p.pointNum << "/" << p.totalPoints; CorrectionPoint c; c.frequency = p.freq * 10.0; c.correctionPort1 = p.port1; @@ -216,7 +216,7 @@ void AmplitudeCalDialog::LoadFromDevice() ui->load->setEnabled(false); dev->setIdle(); RemoveAllPoints(); -// qDebug() << "Asking for amplitude calibration"; + qDebug() << "Asking for amplitude calibration"; connect(this, &AmplitudeCalDialog::AmplitudeCorrectionPointReceived, this, &AmplitudeCalDialog::ReceivedPoint, Qt::QueuedConnection); dev->sendWithoutPayload(requestCommand()); edited = false; diff --git a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriver.cpp b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriver.cpp index 1d82210..70e00b8 100644 --- a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriver.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriver.cpp @@ -524,6 +524,7 @@ void LibreVNADriver::registerTypes() { qRegisterMetaType(); qRegisterMetaType(); + qRegisterMetaType(); } void LibreVNADriver::setSynchronization(LibreVNADriver::Synchronization s, bool master) diff --git a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriver.h b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriver.h index 0edf7e1..3a4167a 100644 --- a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriver.h +++ b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriver.h @@ -160,7 +160,7 @@ public: * If the device driver uses a queued signal/slot connection with custom data types, these types must be registered before emitting the signal. * Register them within this function with qRegisterMetaType("Name"); */ - virtual void registerTypes(); + virtual void registerTypes() override; enum class Synchronization { Disabled = 0, @@ -222,6 +222,7 @@ protected: Q_DECLARE_METATYPE(Protocol::PacketInfo) Q_DECLARE_METATYPE(LibreVNADriver::TransmissionResult) +Q_DECLARE_METATYPE(Protocol::AmplitudeCorrectionPoint); #endif // LIBREVNADRIVER_H diff --git a/Software/PC_Application/LibreVNA-GUI/Device/device.h b/Software/PC_Application/LibreVNA-GUI/Device/device.h deleted file mode 100644 index 5bddb27..0000000 --- a/Software/PC_Application/LibreVNA-GUI/Device/device.h +++ /dev/null @@ -1,149 +0,0 @@ -#ifndef DEVICE_H -#define DEVICE_H - -#include "../../VNA_embedded/Application/Communication/Protocol.hpp" - -#include "LibreVNA/librevnausbdriver.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -Q_DECLARE_METATYPE(Protocol::Datapoint) -Q_DECLARE_METATYPE(Protocol::ManualStatusV1) -Q_DECLARE_METATYPE(Protocol::SpectrumAnalyzerResult) -Q_DECLARE_METATYPE(Protocol::AmplitudeCorrectionPoint) - -//class USBInBuffer : public QObject { -// Q_OBJECT -//public: -// USBInBuffer(libusb_device_handle *handle, unsigned char endpoint, int buffer_size); -// ~USBInBuffer(); - -// void removeBytes(int handled_bytes); -// int getReceived() const; -// uint8_t *getBuffer() const; - -//signals: -// void DataReceived(); -// void TransferError(); - -//private: -// void Callback(libusb_transfer *transfer); -// static void LIBUSB_CALL CallbackTrampoline(libusb_transfer *transfer); -// libusb_transfer *transfer; -// unsigned char *buffer; -// int buffer_size; -// int received_size; -// bool inCallback; -// bool cancelling; -// std::condition_variable cv; -//}; - - -class Device : public QObject -{ - Q_OBJECT -public: - enum class TransmissionResult { - Ack, - Nack, - Timeout, - InternalError, - }; - Q_ENUM(TransmissionResult) - - // connect to a VNA device. If serial is specified only connecting to this device, otherwise to the first one found - Device(QString serial = QString(), bool ignoreOpenError = false); - ~Device(); - - static void RegisterTypes(); - bool SendPacket(const Protocol::PacketInfo& packet, std::function cb = nullptr, unsigned int timeout = 500); - bool Configure(Protocol::SweepSettings settings, std::function cb = nullptr); - bool Configure(Protocol::SpectrumAnalyzerSettings settings, std::function cb = nullptr); - bool SetManual(Protocol::ManualControlV1 manual); - bool SetIdle(std::function cb = nullptr); - bool SendFirmwareChunk(Protocol::FirmwarePacket &fw); - bool SendCommandWithoutPayload(Protocol::PacketType type, std::function cb = nullptr); - QString serial() const; - const Protocol::DeviceInfo& Info(); - static const Protocol::DeviceInfo& Info(Device *dev); - Protocol::DeviceStatusV1& StatusV1(); - static const Protocol::DeviceStatusV1& StatusV1(Device *dev); - QString getLastDeviceInfoString(); - - // Returns serial numbers of all connected devices - static std::set GetDevices(); -signals: - void DatapointReceived(Device*, Protocol::VNADatapoint<32>*); - void ManualStatusReceived(Protocol::ManualStatusV1); - void SpectrumResultReceived(Device*, Protocol::SpectrumAnalyzerResult); - void AmplitudeCorrectionPointReceived(Protocol::AmplitudeCorrectionPoint); - void FrequencyCorrectionReceived(float ppm); - void DeviceInfoUpdated(Device*); - void DeviceStatusUpdated(Device*); - void ConnectionLost(); - void AckReceived(); - void NackReceived(); - void TriggerReceived(bool set); - void LogLineReceived(QString line); - void NeedsFirmwareUpdate(int usedProtocol, int requiredProtocol); -public slots: - void SetTrigger(bool set); -private slots: - void ReceivedData(); - void ReceivedLog(); - void transmissionTimeout() { - transmissionFinished(TransmissionResult::Timeout); - } - void transmissionFinished(TransmissionResult result); -signals: - void receivedAnswer(TransmissionResult result); - -private: - static constexpr int EP_Data_Out_Addr = 0x01; - static constexpr int EP_Data_In_Addr = 0x81; - static constexpr int EP_Log_In_Addr = 0x82; - - void USBHandleThread(); - // foundCallback is called for every device that is found. If it returns true the search continues, otherwise it is aborted. - // When the search is aborted the last found device is still opened - static void SearchDevices(std::function foundCallback, libusb_context *context, bool ignoreOpenError); - - libusb_device_handle *m_handle; - libusb_context *m_context; - USBInBuffer *dataBuffer; - USBInBuffer *logBuffer; - - class Transmission { - public: - Protocol::PacketInfo packet; - unsigned int timeout; - std::function callback; - }; - - std::mutex transmissionMutex; - QQueue transmissionQueue; - bool startNextTransmission(); - QTimer transmissionTimer; - bool transmissionActive; - - QString m_serial; - bool m_connected; - std::thread *m_receiveThread; - Protocol::DeviceInfo info; - bool infoValid; - union { - Protocol::DeviceStatusV1 v1; - } status; - - std::mutex accessMutex; -}; - -#endif // DEVICE_H diff --git a/Software/PC_Application/LibreVNA-GUI/VNA/vna.h b/Software/PC_Application/LibreVNA-GUI/VNA/vna.h index 4a5dc8d..a80f028 100644 --- a/Software/PC_Application/LibreVNA-GUI/VNA/vna.h +++ b/Software/PC_Application/LibreVNA-GUI/VNA/vna.h @@ -4,7 +4,6 @@ #include "appwindow.h" #include "mode.h" #include "CustomWidgets/tilewidget.h" -#include "Device/device.h" #include "Deembedding/deembedding.h" #include "scpi.h" #include "Traces/tracewidget.h"