diff --git a/.gitignore b/.gitignore index f548268..7ccedc6 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,6 @@ *.lai *.so *.so.* -*.dll *.dylib # Qt-es @@ -52,4 +51,5 @@ compile_commands.json *_qmlcache.qrc Source/bin/* -Source/.qmake.stash \ No newline at end of file +Source/.qmake.stash +Source/build \ No newline at end of file diff --git a/Source/cudaSDR.pri b/Source/cudaSDR.pri index b2d304d..9bd73d5 100644 --- a/Source/cudaSDR.pri +++ b/Source/cudaSDR.pri @@ -24,7 +24,8 @@ HEADERS += \ ./src/DataEngine/cusdr_chirpProcessor.h \ ./src/DataEngine/cusdr_dataEngine.h \ ./src/DataEngine/cusdr_dataIO.h \ - ./src/DataEngine/cusdr_discoverer.h \ + ./src/DataEngine/cusdr_discoverer_P1.h \ + ./src/DataEngine/cusdr_discoverer_P2.h \ ./src/DataEngine/cusdr_receiver.h \ ./src/DataEngine/soundout.h \ ./src/DataEngine/fractresampler.h \ @@ -99,7 +100,8 @@ HEADERS += \ ./src/DataEngine/cusdr_chirpProcessor.h \ ./src/DataEngine/cusdr_dataEngine.h \ ./src/DataEngine/cusdr_dataIO.h \ - ./src/DataEngine/cusdr_discoverer.h \ + ./src/DataEngine/cusdr_discoverer_P1.h \ + ./src/DataEngine/cusdr_discoverer_P2.h \ ./src/DataEngine/cusdr_receiver.h \ ./src/DataEngine/soundout.h \ ./src/DataEngine/fractresampler.h \ @@ -172,7 +174,8 @@ SOURCES += \ ./src/DataEngine/cusdr_chirpProcessor.cpp \ ./src/DataEngine/cusdr_dataEngine.cpp \ ./src/DataEngine/cusdr_dataIO.cpp \ - ./src/DataEngine/cusdr_discoverer.cpp \ + ./src/DataEngine/cusdr_discoverer_P1.cpp \ + ./src/DataEngine/cusdr_discoverer_P2.cpp \ ./src/DataEngine/cusdr_receiver.cpp \ ./src/DataEngine/soundout.cpp \ ./src/DataEngine/fractresampler.cpp \ @@ -240,7 +243,8 @@ SOURCES += \ ./src/DataEngine/cusdr_chirpProcessor.cpp \ ./src/DataEngine/cusdr_dataEngine.cpp \ ./src/DataEngine/cusdr_dataIO.cpp \ - ./src/DataEngine/cusdr_discoverer.cpp \ + ./src/DataEngine/cusdr_discoverer_P1.cpp \ + ./src/DataEngine/cusdr_discoverer_P2.cpp \ ./src/DataEngine/cusdr_receiver.cpp \ ./src/DataEngine/soundout.cpp \ ./src/DataEngine/fractresampler.cpp \ diff --git a/Source/cudaSDR.pro b/Source/cudaSDR.pro index d2afea8..37c8d71 100644 --- a/Source/cudaSDR.pro +++ b/Source/cudaSDR.pro @@ -1,4 +1,4 @@ -QT += core gui network multimedia opengl +QT += core gui network multimedia opengl widgets QMAKE_CFLAGS_RELEASE = -O4 QMAKE_CXXFLAGS_RELEASE = -O4 QMAKE_LFLAGS_RELEASE = -O4 @@ -7,7 +7,7 @@ TARGET = cudaSDR TEMPLATE = app CONFIG += qt warn_on -CONFIG += console +#CONFIG += console CONFIG += mobility CONFIG += $$QMAKE_HOST.arch message(CONFIG: $$QMAKE_HOST.arch) @@ -83,7 +83,7 @@ win32 { -luser32 \ -lKernel32 INCLUDEPATH +=$$PWD/lib - LIBS += $$PWD/lib/libfftw3f-3.a + LIBS += $$PWD/lib/libfftw3f-3.dll } OBJECTS_DIR = ./bld/o diff --git a/Source/cudaSDR.pro.user b/Source/cudaSDR.pro.user index 6ae2ddb..8a8617a 100644 --- a/Source/cudaSDR.pro.user +++ b/Source/cudaSDR.pro.user @@ -1,14 +1,14 @@ - + EnvironmentId - {e51181fc-176a-40ca-a8e0-59157399e831} + {9df2227e-2f94-4455-9fee-2b0603509b19} ProjectExplorer.Project.ActiveTarget - 0 + 0 ProjectExplorer.Project.EditorSettings @@ -28,7 +28,7 @@ QmlJSGlobal - 2 + 2 UTF-8 false 4 @@ -37,33 +37,47 @@ true true 1 + 0 + false true false - 0 + 2 true true 0 8 true + false 1 true true true + *.md, *.MD, Makefile false + true + true ProjectExplorer.Project.PluginSettings - - -fno-delayed-template-parsing - - true - Builtin.Questionable + + true + false + true + true + true + true + + + 0 + true + true true Builtin.DefaultTidyAndClazy - 4 + 6 + true @@ -74,35 +88,29 @@ ProjectExplorer.Project.Target.0 - Desktop Qt 5.15.0 MinGW 32-bit - Desktop Qt 5.15.0 MinGW 32-bit - qt.qt5.5150.win32_mingw81_kit - 0 - 0 - 0 + Desktop + Desktop Qt 5.15.2 MinGW 64-bit + Desktop Qt 5.15.2 MinGW 64-bit + qt.qt5.5152.win64_mingw81_kit + 0 + 0 + 0 - true 0 - C:\Users\karpe\Documents\cudaSDR\build-cudaSDR-Desktop_Qt_5_15_0_MinGW_32_bit-Debug - C:/Users/karpe/Documents/cudaSDR/build-cudaSDR-Desktop_Qt_5_15_0_MinGW_32_bit-Debug + C:\Users\karpe\Documents\source\cudaSDR\Source\build\Debug + C:/Users/karpe/Documents/source/cudaSDR/Source/build/Debug true QtProjectManager.QMakeBuildStep - false true Qt4ProjectManager.MakeStep - - false - - - false - 2 + 2 Сборка Сборка ProjectExplorer.BuildSteps.Build @@ -111,49 +119,37 @@ true Qt4ProjectManager.MakeStep - - true clean - - false - 1 + 1 Очистка Очистка ProjectExplorer.BuildSteps.Clean 2 false + + false Отладка Qt4ProjectManager.Qt4BuildConfiguration 2 - 2 - 2 - true - 2 - C:\Users\karpe\Documents\cudaSDR\build-cudaSDR-Desktop_Qt_5_15_0_MinGW_32_bit-Release - C:/Users/karpe/Documents/cudaSDR/build-cudaSDR-Desktop_Qt_5_15_0_MinGW_32_bit-Release + C:\Users\karpe\Documents\source\cudaSDR\Source\build\Release + C:/Users/karpe/Documents/source/cudaSDR/Source/build/Release true QtProjectManager.QMakeBuildStep - false true Qt4ProjectManager.MakeStep - - false - - - false - 2 + 2 Сборка Сборка ProjectExplorer.BuildSteps.Build @@ -162,49 +158,39 @@ true Qt4ProjectManager.MakeStep - - true clean - - false - 1 + 1 Очистка Очистка ProjectExplorer.BuildSteps.Clean 2 false + + false Выпуск Qt4ProjectManager.Qt4BuildConfiguration 0 0 - 2 - true 0 - C:\Users\karpe\Documents\cudaSDR\build-cudaSDR-Desktop_Qt_5_15_0_MinGW_32_bit-Profile - C:/Users/karpe/Documents/cudaSDR/build-cudaSDR-Desktop_Qt_5_15_0_MinGW_32_bit-Profile + C:\Users\karpe\Documents\source\cudaSDR\Source\build\Profile + C:/Users/karpe/Documents/source/cudaSDR/Source/build/Profile true QtProjectManager.QMakeBuildStep - false true Qt4ProjectManager.MakeStep - - false - - - false - 2 + 2 Сборка Сборка ProjectExplorer.BuildSteps.Build @@ -213,19 +199,17 @@ true Qt4ProjectManager.MakeStep - - true clean - - false - 1 + 1 Очистка Очистка ProjectExplorer.BuildSteps.Clean 2 false + + false Профилирование Qt4ProjectManager.Qt4BuildConfiguration @@ -233,10 +217,10 @@ 0 0 - 3 + 3 - 0 + 0 Развёртывание Развёртывание ProjectExplorer.BuildSteps.Deploy @@ -246,342 +230,30 @@ false ProjectExplorer.DefaultDeployConfiguration - 1 - + 1 - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F true - 4096 - false - false - 1000 - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 + 0 true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - + 2 - Qt4ProjectManager.Qt4RunConfiguration:C:/Users/karpe/Documents/cudaSDR/Source/cudaSDR.pro - C:/Users/karpe/Documents/cudaSDR/Source/cudaSDR.pro - - false - - false + false + -e cpu-cycles --call-graph "dwarf,4096" -F 250 + + ProjectExplorer.CustomExecutableRunConfiguration + + false true - true - false - false true - - C:/Users/karpe/Documents/cudaSDR/build-cudaSDR-Desktop_Qt_5_15_0_MinGW_32_bit-Debug/bin - 1 - - - - ProjectExplorer.Project.Target.1 - - Desktop Qt 5.15.0 MinGW 64-bit - Desktop Qt 5.15.0 MinGW 64-bit - qt.qt5.5150.win64_mingw81_kit - 0 - 0 - 0 - - true - 0 - C:\Users\karpe\Documents\cudaSDR\build-cudaSDR-Desktop_Qt_5_15_0_MinGW_64_bit-Debug - C:/Users/karpe/Documents/cudaSDR/build-cudaSDR-Desktop_Qt_5_15_0_MinGW_64_bit-Debug - - - true - QtProjectManager.QMakeBuildStep - - false - - - - true - Qt4ProjectManager.MakeStep - - false - - - false - - 2 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - - true - clean - - false - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Отладка - Qt4ProjectManager.Qt4BuildConfiguration - 2 - 2 - 2 - - - true - 2 - C:\Users\karpe\Documents\cudaSDR\build-cudaSDR-Desktop_Qt_5_15_0_MinGW_64_bit-Release - C:/Users/karpe/Documents/cudaSDR/build-cudaSDR-Desktop_Qt_5_15_0_MinGW_64_bit-Release - - - true - QtProjectManager.QMakeBuildStep - - false - - - - true - Qt4ProjectManager.MakeStep - - false - - - false - - 2 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - - true - clean - - false - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Выпуск - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - 2 - - - true - 0 - C:\Users\karpe\Documents\cudaSDR\build-cudaSDR-Desktop_Qt_5_15_0_MinGW_64_bit-Profile - C:/Users/karpe/Documents/cudaSDR/build-cudaSDR-Desktop_Qt_5_15_0_MinGW_64_bit-Profile - - - true - QtProjectManager.QMakeBuildStep - - false - - - - true - Qt4ProjectManager.MakeStep - - false - - - false - - 2 - Сборка - Сборка - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - - true - clean - - false - - 1 - Очистка - Очистка - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Профилирование - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - 0 - - 3 - - - 0 - Развёртывание - Развёртывание - ProjectExplorer.BuildSteps.Deploy - - 1 - - false - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - dwarf - - cpu-cycles - - - 250 - - -e - cpu-cycles - --call-graph - dwarf,4096 - -F - 250 - - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - Qt4ProjectManager.Qt4RunConfiguration:C:/Users/karpe/Documents/cudaSDR/Source/cudaSDR.pro - C:/Users/karpe/Documents/cudaSDR/Source/cudaSDR.pro - - false - - false - true - true - false - false - true - - - - 1 + 1 ProjectExplorer.Project.TargetCount - 2 + 1 ProjectExplorer.Project.Updater.FileVersion diff --git a/Source/lib/fftw3.h b/Source/lib/fftw3.h index 4326eae..39661d2 100644 --- a/Source/lib/fftw3.h +++ b/Source/lib/fftw3.h @@ -132,8 +132,8 @@ typedef enum fftw_r2r_kind_do_not_use_me X(r2r_kind); \ \ typedef fftw_write_char_func_do_not_use_me X(write_char_func); \ typedef fftw_read_char_func_do_not_use_me X(read_char_func); \ - \ -FFTW_EXTERN void X(execute)(const X(plan) p); \ + \ +FFTW_EXTERN void X(execute)(const X(plan) p); \ \ FFTW_EXTERN X(plan) X(plan_dft)(int rank, const int *n, \ C *in, C *out, int sign, unsigned flags); \ @@ -320,6 +320,7 @@ FFTW_EXTERN void X(set_timelimit)(double t); \ FFTW_EXTERN void X(plan_with_nthreads)(int nthreads); \ FFTW_EXTERN int X(init_threads)(void); \ FFTW_EXTERN void X(cleanup_threads)(void); \ +FFTW_EXTERN void X(make_planner_thread_safe)(void); \ \ FFTW_EXTERN int X(export_wisdom_to_filename)(const char *filename); \ FFTW_EXTERN void X(export_wisdom_to_file)(FILE *output_file); \ @@ -361,7 +362,7 @@ FFTW_DEFINE_API(FFTW_MANGLE_LONG_DOUBLE, long double, fftwl_complex) /* __float128 (quad precision) is a gcc extension on i386, x86_64, and ia64 for gcc >= 4.6 (compiled in FFTW with --enable-quad-precision) */ #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) \ - && !(defined(__ICC) || defined(__INTEL_COMPILER)) \ + && !(defined(__ICC) || defined(__INTEL_COMPILER) || defined(__CUDACC__) || defined(__PGI)) \ && (defined(__i386__) || defined(__x86_64__) || defined(__ia64__)) # if !defined(FFTW_NO_Complex) && defined(_Complex_I) && defined(complex) && defined(I) /* note: __float128 is a typedef, which is not supported with the _Complex diff --git a/Source/lib/libfftw3f-3.dll b/Source/lib/libfftw3f-3.dll new file mode 100644 index 0000000..32a3fcf Binary files /dev/null and b/Source/lib/libfftw3f-3.dll differ diff --git a/Source/src/DataEngine/cusdr_dataEngine.cpp b/Source/src/DataEngine/cusdr_dataEngine.cpp index 8fae53f..3ab684c 100644 --- a/Source/src/DataEngine/cusdr_dataEngine.cpp +++ b/Source/src/DataEngine/cusdr_dataEngine.cpp @@ -1434,7 +1434,7 @@ void DataEngine::disconnectDSPSlots() { void DataEngine::createDiscoverer() { - m_discoverer = new Discoverer(&io); + m_discoverer = new DiscovererP1(&io); m_discoveryThread = new QThreadEx(); m_discoverer->moveToThread(m_discoveryThread); diff --git a/Source/src/DataEngine/cusdr_dataEngine.h b/Source/src/DataEngine/cusdr_dataEngine.h index 770a8fa..55bc981 100644 --- a/Source/src/DataEngine/cusdr_dataEngine.h +++ b/Source/src/DataEngine/cusdr_dataEngine.h @@ -48,7 +48,7 @@ #include "cusdr_receiver.h" #include "cusdr_chirpProcessor.h" #include "cusdr_audioReceiver.h" -#include "cusdr_discoverer.h" +#include "cusdr_discoverer_P1.h" #include "Util/qcircularbuffer.h" #include "QtDSP/qtdsp_fft.h" #include "QtDSP/qtdsp_filter.h" @@ -198,7 +198,7 @@ private: AudioEngine* m_audioEngine; AudioOutProcessor* m_audioOutProcessor; ChirpProcessor* m_chirpProcessor; - Discoverer* m_discoverer; + DiscovererP1* m_discoverer; QThreadEx* m_discoveryThread; QThreadEx* m_dataIOThread; diff --git a/Source/src/DataEngine/cusdr_discoverer.cpp b/Source/src/DataEngine/cusdr_discoverer_P1.cpp similarity index 87% rename from Source/src/DataEngine/cusdr_discoverer.cpp rename to Source/src/DataEngine/cusdr_discoverer_P1.cpp index 1e205e1..0d077eb 100644 --- a/Source/src/DataEngine/cusdr_discoverer.cpp +++ b/Source/src/DataEngine/cusdr_discoverer_P1.cpp @@ -27,7 +27,7 @@ #define LOG_DISCOVERER -#include "cusdr_discoverer.h" +#include "cusdr_discoverer_P1.h" #include "Util/cusdr_buttons.h" @@ -45,7 +45,7 @@ //#define btn_height 18 //#define btn_width 74 -Discoverer::Discoverer(THPSDRParameter *ioData) +DiscovererP1::DiscovererP1(THPSDRParameter *ioData) : QObject() , set(Settings::instance()) , io(ioData) @@ -53,12 +53,12 @@ Discoverer::Discoverer(THPSDRParameter *ioData) m_deviceCards = set->getMetisCardsList(); } -Discoverer::~Discoverer() { +DiscovererP1::~DiscovererP1() { } -TNetworkDevicecard mc; +TNetworkDevicecard mcP1; -void Discoverer::initHPSDRDevice() { +void DiscovererP1::initHPSDRDevice() { m_searchTime.start(); @@ -95,7 +95,7 @@ void Discoverer::initHPSDRDevice() { io->networkIOMutex.unlock(); } -int Discoverer::findHPSDRDevices() { +int DiscovererP1::findHPSDRDevices() { int devicesFound = 0; @@ -193,18 +193,18 @@ int Discoverer::findHPSDRDevices() { quint16 port; m_deviceDatagram.resize(socket.pendingDatagramSize()); - socket.readDatagram(m_deviceDatagram.data(), m_deviceDatagram.size(), &mc.ip_address, &port); + socket.readDatagram(m_deviceDatagram.data(), m_deviceDatagram.size(), &mcP1.ip_address, &port); if (m_deviceDatagram[0] == (char)0xEF && m_deviceDatagram[1] == (char)0xFE) { if (m_deviceDatagram[2] == (char)0x02) { - sprintf(mc.mac_address, "%02X:%02X:%02X:%02X:%02X:%02X", + sprintf(mcP1.mac_address, "%02X:%02X:%02X:%02X:%02X:%02X", m_deviceDatagram[3] & 0xFF, m_deviceDatagram[4] & 0xFF, m_deviceDatagram[5] & 0xFF, m_deviceDatagram[6] & 0xFF, m_deviceDatagram[7] & 0xFF, m_deviceDatagram[8] & 0xFF); io->networkIOMutex.lock(); - DISCOVERER_DEBUG << "Device found at " << qPrintable(mc.ip_address.toString()) << ":" << port << "; Mac addr: [" << mc.mac_address << "]"; + DISCOVERER_DEBUG << "Device found at " << qPrintable(mcP1.ip_address.toString()) << ":" << port << "; Mac addr: [" << mcP1.mac_address << "]"; DISCOVERER_DEBUG << "Device code version: " << qPrintable(QString::number(m_deviceDatagram.at(9), 16)); io->networkIOMutex.unlock(); @@ -224,17 +224,17 @@ int Discoverer::findHPSDRDevices() { str = "Hermes-Lite"; } - mc.boardID = no; - mc.boardName = str; + mcP1.boardID = no; + mcP1.boardName = str; io->networkIOMutex.lock(); DISCOVERER_DEBUG << "Device board ID: " << no; DISCOVERER_DEBUG << "Device is: " << qPrintable(str); io->networkIOMutex.unlock(); - m_deviceCards.append(mc); + m_deviceCards.append(mcP1); str += " ("; - str += mc.ip_address.toString(); + str += mcP1.ip_address.toString(); str += ")"; set->addNetworkIOComboBoxEntry(str); @@ -266,20 +266,20 @@ int Discoverer::findHPSDRDevices() { return devicesFound; } -void Discoverer::displayDiscoverySocketError(QAbstractSocket::SocketError error) { +void DiscovererP1::displayDiscoverySocketError(QAbstractSocket::SocketError error) { io->networkIOMutex.lock(); DISCOVERER_DEBUG << "discovery socket error: " << error; io->networkIOMutex.unlock(); } -void Discoverer::clear() { +void DiscovererP1::clear() { //m_metisDeviceComboBox->clear(); m_deviceCards.clear(); } -void Discoverer::shutdownHPSDRDevice() { +void DiscovererP1::shutdownHPSDRDevice() { QByteArray arr; arr.resize(64); @@ -291,7 +291,7 @@ void Discoverer::shutdownHPSDRDevice() { for (int i = 4; i < 64; i++) arr[i] = 0x00; QUdpSocket socket; - QHostAddress addr = mc.ip_address; + QHostAddress addr = mcP1.ip_address; for (int i = 0; i < 10; i++) { diff --git a/Source/src/DataEngine/cusdr_discoverer.h b/Source/src/DataEngine/cusdr_discoverer_P1.h similarity index 86% rename from Source/src/DataEngine/cusdr_discoverer.h rename to Source/src/DataEngine/cusdr_discoverer_P1.h index ea8e006..79eca7a 100644 --- a/Source/src/DataEngine/cusdr_discoverer.h +++ b/Source/src/DataEngine/cusdr_discoverer_P1.h @@ -1,87 +1,87 @@ -/** -* @file cusdr_discoverer.h -* @brief HPSDR device discoverer header file -* @author Hermann von Hasseln, DL3HVH -* @version 0.1 -* @date 2012-05-19 -*/ - -/* - * - * Copyright 2012 Hermann von Hasseln, DL3HVH - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License version 2 as - * published by the Free Software Foundation - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details - * - * You should have received a copy of the GNU Library General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef _CUSDR_DISCOVERER_H -#define _CUSDR_DISCOVERER_H - -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include - -#include "cusdr_settings.h" - -#ifdef LOG_DISCOVERER -# define DISCOVERER_DEBUG qDebug().nospace() << "Discoverer::\t" -#else -# define DISCOVERER_DEBUG nullDebug() -#endif - - -class Discoverer : public QObject { - - Q_OBJECT - -public: - Discoverer(THPSDRParameter *ioData = 0); - ~Discoverer(); - - int findHPSDRDevices(); - void clear(); - void shutdownHPSDRDevice(); - -public slots: - void initHPSDRDevice(); - - -private slots: - void displayDiscoverySocketError(QAbstractSocket::SocketError error); - -private: - Settings* set; - THPSDRParameter* io; - QTime m_searchTime; - - QByteArray m_findDatagram; - QByteArray m_deviceDatagram; - - //QString m_deviceStr; - - TNetworkDevicecard m_deviceCard; - QList m_deviceCards; - -signals: - -}; - -#endif // _CUSDR_DISCOVERER_H +/** +* @file cusdr_discoverer.h +* @brief HPSDR device discoverer header file +* @author Hermann von Hasseln, DL3HVH +* @version 0.1 +* @date 2012-05-19 +*/ + +/* + * + * Copyright 2012 Hermann von Hasseln, DL3HVH + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef _CUSDR_DISCOVERER_P1_H +#define _CUSDR_DISCOVERER_P1_H + +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include +//#include + +#include "cusdr_settings.h" + +#ifdef LOG_DISCOVERER +# define DISCOVERER_DEBUG qDebug().nospace() << "Discoverer::\t" +#else +# define DISCOVERER_DEBUG nullDebug() +#endif + + +class DiscovererP1 : public QObject { + + Q_OBJECT + +public: + DiscovererP1(THPSDRParameter *ioData = 0); + ~DiscovererP1(); + + int findHPSDRDevices(); + void clear(); + void shutdownHPSDRDevice(); + +public slots: + void initHPSDRDevice(); + + +private slots: + void displayDiscoverySocketError(QAbstractSocket::SocketError error); + +private: + Settings* set; + THPSDRParameter* io; + QTime m_searchTime; + + QByteArray m_findDatagram; + QByteArray m_deviceDatagram; + + //QString m_deviceStr; + + TNetworkDevicecard m_deviceCard; + QList m_deviceCards; + +signals: + +}; + +#endif // _CUSDR_DISCOVERER_P1_H diff --git a/Source/src/DataEngine/cusdr_discoverer_P2.cpp b/Source/src/DataEngine/cusdr_discoverer_P2.cpp new file mode 100644 index 0000000..edfd41e --- /dev/null +++ b/Source/src/DataEngine/cusdr_discoverer_P2.cpp @@ -0,0 +1,293 @@ +/** +* @file cusdr_discoverer.cpp +* @brief HPSDR device discoverer class +* @author Hermann von Hasseln, DL3HVH +* @version 0.1 +* @date 2012-05-19 +*/ + +/* + * + * Copyright 2012 Hermann von Hasseln, DL3HVH + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#define LOG_DISCOVERER + +#include "cusdr_discoverer_P2.h" +#include "Util/cusdr_buttons.h" + + +DiscovererP2::DiscovererP2(THPSDRParameter *ioData) + : QObject() + , set(Settings::instance()) + , io(ioData) +{ + m_deviceCards = set->getMetisCardsList(); +} + +DiscovererP2::~DiscovererP2() { +} + +TNetworkDevicecard mcP2; + +void DiscovererP2::initHPSDRDevice() { + + m_searchTime.start(); + + int deviceNo = 0; + while (deviceNo == 0) { + + deviceNo = findHPSDRDevices(); + + if (deviceNo > 1) { + + set->setHPSDRDeviceNumber(deviceNo); + break; + } + + if (deviceNo > 0) { + + set->setHPSDRDeviceNumber(deviceNo); + break; + } + + if (m_searchTime.elapsed() > 1000) { + + set->setHPSDRDeviceNumber(0); + break; + } + + io->networkIOMutex.lock(); + DISCOVERER_DEBUG << "no device protocol 2 found - trying again..."; + io->networkIOMutex.unlock(); + } + + io->networkIOMutex.lock(); + io->devicefound.wakeAll(); + io->networkIOMutex.unlock(); +} + +int DiscovererP2::findHPSDRDevices() { + + int devicesFound = 0; + + m_findDatagram.resize(60); + m_findDatagram[0] = (char)0x00; + m_findDatagram[1] = (char)0x00; + m_findDatagram[2] = (char)0x00; + m_findDatagram[3] = (char)0x00; + m_findDatagram[4] = (char)0x02; + for (int i = 5; i < 60; i++) + m_findDatagram[i] = (char)0x00; + + QUdpSocket socket; + + CHECKED_CONNECT( + &socket, + SIGNAL(error(QAbstractSocket::SocketError)), + this, + SLOT(displayDiscoverySocketError(QAbstractSocket::SocketError))); + + io->networkIOMutex.lock(); + DISCOVERER_DEBUG << "using " << qPrintable(QHostAddress(set->getHPSDRDeviceLocalAddr()).toString()) << " for discovery protocol 2."; + io->networkIOMutex.unlock(); + + // clear comboBox entries in the network dialogue + set->clearNetworkIOComboBoxEntry(); + +#if defined(Q_OS_WIN32) + + if (socket.bind( + QHostAddress(set->getHPSDRDeviceLocalAddr()), 0, + QUdpSocket::ReuseAddressHint | QUdpSocket::ShareAddress)) + //QUdpSocket::ReuseAddressHint)) + { + set->setMetisPort(this, socket.localPort()); + io->networkIOMutex.lock(); + DISCOVERER_DEBUG << "discovery_socket protocol 2 bound successfully to port " << socket.localPort(); + io->networkIOMutex.unlock(); + } + else { + + io->networkIOMutex.lock(); + DISCOVERER_DEBUG << "discovery_socket protocol 2 bind failed."; + io->networkIOMutex.unlock(); + + socket.close(); + return 0; + } +#elif defined(Q_OS_LINUX) + + if (socket.bind( + QHostAddress(set->getHPSDRDeviceLocalAddr()), + QUdpSocket::DefaultForPlatform)) + { + CHECKED_CONNECT( + &socket, + SIGNAL(error(QAbstractSocket::SocketError)), + this, + SLOT(displayDiscoverySocketError(QAbstractSocket::SocketError))); + + set->setMetisPort(this, socket.localPort()); + io->networkIOMutex.lock(); + DISCOVERER_DEBUG << "discovery_socket protocol 2 bound successfully to port " << socket.localPort(); + io->networkIOMutex.unlock(); + } + else { + + io->networkIOMutex.lock(); + DISCOVERER_DEBUG << "discovery_socket protocol 2 bind failed."; + io->networkIOMutex.unlock(); + + socket.close(); + return 0; + } +#endif + + if (socket.writeDatagram(m_findDatagram, QHostAddress::Broadcast, DISCOVERY_PORT) == 60) { + + io->networkIOMutex.lock(); + DISCOVERER_DEBUG << "discovery protocol 2 data sent."; + io->networkIOMutex.unlock(); + } + else { + + io->networkIOMutex.lock(); + DISCOVERER_DEBUG << "discovery protocol 2 data not sent."; + io->networkIOMutex.unlock(); + } + + + // wait a little + //SleeperThread::msleep(30); + SleeperThread::msleep(500); + + while (socket.hasPendingDatagrams()) { + + quint16 port; + int status; + int device; + + m_deviceDatagram.resize(socket.pendingDatagramSize()); + socket.readDatagram(m_deviceDatagram.data(), m_deviceDatagram.size(), &mcP2.ip_address, &port); + + if (m_deviceDatagram[0] == (char)0 && m_deviceDatagram[1] == (char)0 && m_deviceDatagram[2] == (char)0 && m_deviceDatagram[3] == (char)0) { + status = m_deviceDatagram[4] & 0xFF; + + if (status == 2 || status == 3) { + + sprintf(mcP2.mac_address, "%02X:%02X:%02X:%02X:%02X:%02X", + m_deviceDatagram[5] & 0xFF, m_deviceDatagram[6] & 0xFF, m_deviceDatagram[7] & 0xFF, + m_deviceDatagram[8] & 0xFF, m_deviceDatagram[9] & 0xFF, m_deviceDatagram[10] & 0xFF); + + io->networkIOMutex.lock(); + DISCOVERER_DEBUG << "Device on protocol 2 found at " << qPrintable(mcP2.ip_address.toString()) << ":" << port << "; Mac addr: [" << mcP2.mac_address << "]"; + DISCOVERER_DEBUG << "Device protocol 2 code version: " << qPrintable(QString::number(m_deviceDatagram[13], 10)); + io->networkIOMutex.unlock(); + + device = m_deviceDatagram[11] & 0xFF; + QString str; + if (device == 0) + str = "ATLAS"; + else if (device == 1) + str = "HERMES_ANAN-10_100)"; + else if (device == 2) + str = "HERMES_ANAN_10E_100B)"; + else if (device == 3) + str = "ANGELA_ANAN_100D)"; + else if (device == 4) + str = "ORION_ANAN_200D)"; + else if (device == 5) + str = "ORION_Mk_II_ANAN-7_8000DLE)"; + else if (device == 6) { + str = "Hermes-Lite"; + } + + mcP2.boardID = device; + mcP2.boardName = str; + io->networkIOMutex.lock(); + DISCOVERER_DEBUG << "Protocol 2 device board ID: " << device; + DISCOVERER_DEBUG << "Protocol 2 device is: " << qPrintable(str); + io->networkIOMutex.unlock(); + + m_deviceCards.append(mcP2); + + str += " ("; + str += mcP2.ip_address.toString(); + str += ")"; + + set->addNetworkIOComboBoxEntry(str); + devicesFound++; + } + else { + + io->networkIOMutex.lock(); + DISCOVERER_DEBUG << "Device protocol 2 already sending data - trying to shut down..."; + io->networkIOMutex.unlock(); + + shutdownHPSDRDevice(); + clear(); + } + } + + } + set->setMetisCardList(m_deviceCards); + + if (devicesFound == 1) { + + set->setCurrentHPSDRDevice(m_deviceCards.at(0)); + io->networkIOMutex.lock(); + DISCOVERER_DEBUG << "Device selected: " << qPrintable(m_deviceCards.at(0).ip_address.toString()); + io->networkIOMutex.unlock(); + } + + socket.close(); + return devicesFound; +} + +void DiscovererP2::displayDiscoverySocketError(QAbstractSocket::SocketError error) { + + io->networkIOMutex.lock(); + DISCOVERER_DEBUG << "discovery protocol 2 socket error: " << error; + io->networkIOMutex.unlock(); +} + +void DiscovererP2::clear() { + + //m_metisDeviceComboBox->clear(); + m_deviceCards.clear(); +} + +void DiscovererP2::shutdownHPSDRDevice() { + + long sequence = 0; + QByteArray arr; + arr.resize(1444); + + arr[0] = sequence >> 24; + arr[1] = sequence >> 16; + arr[2] = sequence >> 8; + arr[3] = sequence; + arr[4] = 0; + + QUdpSocket socket; + QHostAddress addr = mcP2.ip_address; + + if (socket.writeDatagram(arr, addr, HIGH_PRIORITY_FROM_HOST_PORT) < 0) { + DISCOVERER_DEBUG << "protocol 2 forced shutdown socket write failed."; + } +} diff --git a/Source/src/DataEngine/cusdr_discoverer_P2.h b/Source/src/DataEngine/cusdr_discoverer_P2.h new file mode 100644 index 0000000..490e908 --- /dev/null +++ b/Source/src/DataEngine/cusdr_discoverer_P2.h @@ -0,0 +1,76 @@ +/** +* @file cusdr_discoverer.h +* @brief HPSDR device discoverer header file +* @author Hermann von Hasseln, DL3HVH +* @version 0.1 +* @date 2012-05-19 +*/ + +/* + * + * Copyright 2012 Hermann von Hasseln, DL3HVH + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef _CUSDR_DISCOVERER_P2_H +#define _CUSDR_DISCOVERER_P2_H + +#include "cusdr_settings.h" + +#ifdef LOG_DISCOVERER +# define DISCOVERER_DEBUG qDebug().nospace() << "DiscovererP2::\t" +#else +# define DISCOVERER_DEBUG nullDebug() +#endif + + +class DiscovererP2 : public QObject { + + Q_OBJECT + +public: + DiscovererP2(THPSDRParameter *ioData = 0); + ~DiscovererP2(); + + int findHPSDRDevices(); + void clear(); + void shutdownHPSDRDevice(); + +public slots: + void initHPSDRDevice(); + + +private slots: + void displayDiscoverySocketError(QAbstractSocket::SocketError error); + +private: + Settings* set; + THPSDRParameter* io; + QTime m_searchTime; + + QByteArray m_findDatagram; + QByteArray m_deviceDatagram; + + //QString m_deviceStr; + + TNetworkDevicecard m_deviceCard; + QList m_deviceCards; + +signals: + +}; + +#endif // _CUSDR_DISCOVERER_P2_H diff --git a/Source/src/cusdr_settings.h b/Source/src/cusdr_settings.h index 3bc2809..4ade040 100644 --- a/Source/src/cusdr_settings.h +++ b/Source/src/cusdr_settings.h @@ -180,6 +180,10 @@ static int my_fftw_read_char(void *f) { return fgetc((FILE *) f); } #define DEVICE_PORT 1024 #define DATA_PORT 8886 +//PROTOCOL 2 definitions +#define DISCOVERY_PORT 1024 +#define HIGH_PRIORITY_FROM_HOST_PORT 1027 + // ************************************** // Audio definitions