implement discovery prototol 2

This commit is contained in:
2024-04-12 15:42:22 +03:00
parent 5ca9e52769
commit 72138fad19
13 changed files with 560 additions and 510 deletions
+1 -1
View File
@@ -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);
+2 -2
View File
@@ -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;
@@ -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++) {
@@ -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 <QObject>
//#include <QComboBox>
//#include <QDialogButtonBox>
//#include <QLabel>
//#include <QPushButton>
//#include <QVBoxLayout>
//#include <QCheckBox>
//#include <QSlider>
//#include <QSpinBox>
//#include <QElapsedTimer>
#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<TNetworkDevicecard> 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 <QObject>
//#include <QComboBox>
//#include <QDialogButtonBox>
//#include <QLabel>
//#include <QPushButton>
//#include <QVBoxLayout>
//#include <QCheckBox>
//#include <QSlider>
//#include <QSpinBox>
//#include <QElapsedTimer>
#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<TNetworkDevicecard> m_deviceCards;
signals:
};
#endif // _CUSDR_DISCOVERER_P1_H
@@ -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.";
}
}
@@ -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<TNetworkDevicecard> m_deviceCards;
signals:
};
#endif // _CUSDR_DISCOVERER_P2_H