Fix warnings and formatting

This commit is contained in:
Jon Beniston 2023-09-05 17:14:09 +01:00
parent 11042dc889
commit 60c55970d3
4 changed files with 235 additions and 235 deletions

View File

@ -95,7 +95,7 @@ static int runQtApplication(int argc, char* argv[], qtwebapp::LoggerWithFile *lo
{ {
// Disable log on console, so we can more easily see device list // Disable log on console, so we can more easily see device list
logger->setConsoleMinMessageLevel(QtFatalMsg); logger->setConsoleMinMessageLevel(QtFatalMsg);
// Don't pass logger to MainWindow, otherwise it can reenable log output // Don't pass logger to MainServer, otherwise it can reenable log output
logger = nullptr; logger = nullptr;
} }

View File

@ -39,10 +39,10 @@ public:
const QString& getFFTWFWisdomFileName() const { return m_fftwfWindowFileName; } const QString& getFFTWFWisdomFileName() const { return m_fftwfWindowFileName; }
bool getRemoteTCPSink() const { return m_remoteTCPSink; } bool getRemoteTCPSink() const { return m_remoteTCPSink; }
const QString& getRemoteTCPSinkAddressOption() const { return m_remoteTCPSinkAddress; } const QString& getRemoteTCPSinkAddressOption() const { return m_remoteTCPSinkAddress; }
const int getRemoteTCPSinkPortOption() const { return m_remoteTCPSinkPort; } int getRemoteTCPSinkPortOption() const { return m_remoteTCPSinkPort; }
const QString& getRemoteTCPSinkHWType() const { return m_remoteTCPSinkHWType; } const QString& getRemoteTCPSinkHWType() const { return m_remoteTCPSinkHWType; }
const QString& getRemoteTCPSinkSerial() const { return m_remoteTCPSinkSerial; } const QString& getRemoteTCPSinkSerial() const { return m_remoteTCPSinkSerial; }
const bool getListDevices() const { return m_listDevices; } bool getListDevices() const { return m_listDevices; }
private: private:
QString m_serverAddress; QString m_serverAddress;

View File

@ -1,200 +1,200 @@
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2023 Jon Beniston, M7RCE // // Copyright (C) 2023 Jon Beniston, M7RCE //
// // // //
// This program is free software; you can redistribute it and/or modify // // This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by // // it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or // // the Free Software Foundation as version 3 of the License, or //
// (at your option) any later version. // // (at your option) any later version. //
// // // //
// This program is distributed in the hope that it will be useful, // // This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of // // but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. // // GNU General Public License V3 for more details. //
// // // //
// You should have received a copy of the GNU General Public License // // You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. // // along with this program. If not, see <http://www.gnu.org/licenses/>. //
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
#include <stdio.h> #include <stdio.h>
#include <QTimer> #include <QTimer>
#include "remotetcpsinkstarter.h" #include "remotetcpsinkstarter.h"
#include "maincore.h" #include "maincore.h"
#include "device/deviceset.h" #include "device/deviceset.h"
#include "device/deviceapi.h" #include "device/deviceapi.h"
#include "device/deviceenumerator.h" #include "device/deviceenumerator.h"
#include "dsp/devicesamplesource.h" #include "dsp/devicesamplesource.h"
#include "channel/channelapi.h" #include "channel/channelapi.h"
#include "SWGChannelSettings.h" #include "SWGChannelSettings.h"
#include "SWGRemoteTCPSinkSettings.h" #include "SWGRemoteTCPSinkSettings.h"
#include "SWGDeviceState.h" #include "SWGDeviceState.h"
// Lists available physical devices to stdout // Lists available physical devices to stdout
void RemoteTCPSinkStarter::listAvailableDevices() void RemoteTCPSinkStarter::listAvailableDevices()
{ {
int nbSamplingDevices = DeviceEnumerator::instance()->getNbRxSamplingDevices(); int nbSamplingDevices = DeviceEnumerator::instance()->getNbRxSamplingDevices();
printf("Available devices:\n"); printf("Available devices:\n");
for (int i = 0; i < nbSamplingDevices; i++) for (int i = 0; i < nbSamplingDevices; i++)
{ {
const PluginInterface::SamplingDevice *samplingDevice; const PluginInterface::SamplingDevice *samplingDevice;
samplingDevice = DeviceEnumerator::instance()->getRxSamplingDevice(i); samplingDevice = DeviceEnumerator::instance()->getRxSamplingDevice(i);
if (samplingDevice->type == PluginInterface::SamplingDevice::PhysicalDevice) if (samplingDevice->type == PluginInterface::SamplingDevice::PhysicalDevice)
{ {
printf(" HWType: %s", qPrintable(samplingDevice->hardwareId)); printf(" HWType: %s", qPrintable(samplingDevice->hardwareId));
if (!samplingDevice->serial.isEmpty()) { if (!samplingDevice->serial.isEmpty()) {
printf(" Serial: %s", qPrintable(samplingDevice->serial)); printf(" Serial: %s", qPrintable(samplingDevice->serial));
} }
printf("\n"); printf("\n");
} }
} }
} }
// Instantiate specified sampling source device and create a RemoteTCPSink channel // Instantiate specified sampling source device and create a RemoteTCPSink channel
// on the specified address and port and start the device // on the specified address and port and start the device
static void startRemoteTCPSink(const QString& address, int port, const QString& hwType, const QString& serial) static void startRemoteTCPSink(const QString& address, int port, const QString& hwType, const QString& serial)
{ {
MainCore *mainCore = MainCore::instance(); MainCore *mainCore = MainCore::instance();
// Delete any existing device sets, in case requested device is already in use // Delete any existing device sets, in case requested device is already in use
int initialDeviceSets = mainCore->getDeviceSets().size(); int initialDeviceSets = mainCore->getDeviceSets().size();
for (int i = 0; i < initialDeviceSets; i++) for (int i = 0; i < initialDeviceSets; i++)
{ {
MainCore::MsgRemoveLastDeviceSet *msg = MainCore::MsgRemoveLastDeviceSet::create(); MainCore::MsgRemoveLastDeviceSet *msg = MainCore::MsgRemoveLastDeviceSet::create();
mainCore->getMainMessageQueue()->push(msg); mainCore->getMainMessageQueue()->push(msg);
} }
// Wait until they've been deleted // Wait until they've been deleted
if (initialDeviceSets > 0) if (initialDeviceSets > 0)
{ {
do do
{ {
QTime dieTime = QTime::currentTime().addMSecs(100); QTime dieTime = QTime::currentTime().addMSecs(100);
while (QTime::currentTime() < dieTime) { while (QTime::currentTime() < dieTime) {
QCoreApplication::processEvents(QEventLoop::AllEvents, 100); QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
} }
} }
while (mainCore->getDeviceSets().size() > 0); while (mainCore->getDeviceSets().size() > 0);
} }
// Create DeviceSet // Create DeviceSet
int deviceSetIndex = mainCore->getDeviceSets().size(); unsigned int deviceSetIndex = mainCore->getDeviceSets().size();
MainCore::MsgAddDeviceSet *msg = MainCore::MsgAddDeviceSet::create(0); MainCore::MsgAddDeviceSet *msg = MainCore::MsgAddDeviceSet::create(0);
mainCore->getMainMessageQueue()->push(msg); mainCore->getMainMessageQueue()->push(msg);
// Switch to requested device type // Switch to requested device type
int nbSamplingDevices = DeviceEnumerator::instance()->getNbRxSamplingDevices(); int nbSamplingDevices = DeviceEnumerator::instance()->getNbRxSamplingDevices();
bool found = false; bool found = false;
for (int i = 0; i < nbSamplingDevices; i++) for (int i = 0; i < nbSamplingDevices; i++)
{ {
const PluginInterface::SamplingDevice *samplingDevice; const PluginInterface::SamplingDevice *samplingDevice;
samplingDevice = DeviceEnumerator::instance()->getRxSamplingDevice(i); samplingDevice = DeviceEnumerator::instance()->getRxSamplingDevice(i);
if (!hwType.isEmpty() && (hwType != samplingDevice->hardwareId)) { if (!hwType.isEmpty() && (hwType != samplingDevice->hardwareId)) {
continue; continue;
} }
if (!serial.isEmpty() && (serial != samplingDevice->serial)) { if (!serial.isEmpty() && (serial != samplingDevice->serial)) {
continue; continue;
} }
int direction = 0; int direction = 0;
MainCore::MsgSetDevice *msg = MainCore::MsgSetDevice::create(deviceSetIndex, i, direction); MainCore::MsgSetDevice *msg = MainCore::MsgSetDevice::create(deviceSetIndex, i, direction);
mainCore->getMainMessageQueue()->push(msg); mainCore->getMainMessageQueue()->push(msg);
found = true; found = true;
break; break;
} }
if (!found) if (!found)
{ {
qCritical() << "startRemoteTCPSink: Failed to find device"; qCritical() << "startRemoteTCPSink: Failed to find device";
return; return;
} }
// Add RemoteTCPSink channel // Add RemoteTCPSink channel
PluginAPI::ChannelRegistrations *channelRegistrations = mainCore->getPluginManager()->getRxChannelRegistrations(); PluginAPI::ChannelRegistrations *channelRegistrations = mainCore->getPluginManager()->getRxChannelRegistrations();
int nbRegistrations = channelRegistrations->size(); int nbRegistrations = channelRegistrations->size();
int index = 0; int index = 0;
for (; index < nbRegistrations; index++) for (; index < nbRegistrations; index++)
{ {
if (channelRegistrations->at(index).m_channelId == "RemoteTCPSink") { if (channelRegistrations->at(index).m_channelId == "RemoteTCPSink") {
break; break;
} }
} }
if (index < nbRegistrations) if (index < nbRegistrations)
{ {
MainCore::MsgAddChannel *msg = MainCore::MsgAddChannel::create(deviceSetIndex, index, 0); MainCore::MsgAddChannel *msg = MainCore::MsgAddChannel::create(deviceSetIndex, index, 0);
mainCore->getMainMessageQueue()->push(msg); mainCore->getMainMessageQueue()->push(msg);
} }
else else
{ {
qCritical() << "startRemoteTCPSink: RemoteTCPSink is not available"; qCritical() << "startRemoteTCPSink: RemoteTCPSink is not available";
return; return;
} }
int channelIndex = 0; int channelIndex = 0;
// Wait until device & channel are created - is there a better way? // Wait until device & channel are created - is there a better way?
DeviceSet *deviceSet = nullptr; DeviceSet *deviceSet = nullptr;
ChannelAPI *channelAPI = nullptr; ChannelAPI *channelAPI = nullptr;
do do
{ {
QTime dieTime = QTime::currentTime().addMSecs(100); QTime dieTime = QTime::currentTime().addMSecs(100);
while (QTime::currentTime() < dieTime) { while (QTime::currentTime() < dieTime) {
QCoreApplication::processEvents(QEventLoop::AllEvents, 100); QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
} }
if (mainCore->getDeviceSets().size() > deviceSetIndex) if (mainCore->getDeviceSets().size() > deviceSetIndex)
{ {
deviceSet = mainCore->getDeviceSets()[deviceSetIndex]; deviceSet = mainCore->getDeviceSets()[deviceSetIndex];
if (deviceSet) { if (deviceSet) {
channelAPI = deviceSet->m_deviceAPI->getChanelSinkAPIAt(channelIndex); channelAPI = deviceSet->m_deviceAPI->getChanelSinkAPIAt(channelIndex);
} }
} }
} }
while (channelAPI == nullptr); while (channelAPI == nullptr);
// Set TCP settings // Set TCP settings
QStringList channelSettingsKeys = {"dataAddress", "dataPort"}; QStringList channelSettingsKeys = {"dataAddress", "dataPort"};
SWGSDRangel::SWGChannelSettings response; SWGSDRangel::SWGChannelSettings response;
response.init(); response.init();
SWGSDRangel::SWGRemoteTCPSinkSettings *sinkSettings = response.getRemoteTcpSinkSettings(); SWGSDRangel::SWGRemoteTCPSinkSettings *sinkSettings = response.getRemoteTcpSinkSettings();
sinkSettings->setDataAddress(new QString(address)); sinkSettings->setDataAddress(new QString(address));
sinkSettings->setDataPort(port); sinkSettings->setDataPort(port);
QString errorMessage; QString errorMessage;
channelAPI->webapiSettingsPutPatch(false, channelSettingsKeys, response, errorMessage); channelAPI->webapiSettingsPutPatch(false, channelSettingsKeys, response, errorMessage);
// Wait some time for settings to be applied // Wait some time for settings to be applied
QCoreApplication::processEvents(QEventLoop::AllEvents, 100); QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
// Start the device (use WebAPI so GUI is updated) // Start the device (use WebAPI so GUI is updated)
DeviceSampleSource *source = deviceSet->m_deviceAPI->getSampleSource(); DeviceSampleSource *source = deviceSet->m_deviceAPI->getSampleSource();
QStringList deviceActionsKeys; QStringList deviceActionsKeys;
SWGSDRangel::SWGDeviceState state; SWGSDRangel::SWGDeviceState state;
state.init(); state.init();
int res = source->webapiRun(true, state, errorMessage); int res = source->webapiRun(true, state, errorMessage);
if (res != 200) { if (res != 200) {
qCritical() << "startRemoteTCPSink: Failed to start device: " << res; qCritical() << "startRemoteTCPSink: Failed to start device: " << res;
} else { } else {
qInfo().nospace().noquote() << "Remote TCP Sink started on " << address << ":" << port; qInfo().nospace().noquote() << "Remote TCP Sink started on " << address << ":" << port;
} }
} }
// Start Remote TCP Sink on specified device, with specified address and port // Start Remote TCP Sink on specified device, with specified address and port
void RemoteTCPSinkStarter::start(const MainParser& parser) void RemoteTCPSinkStarter::start(const MainParser& parser)
{ {
QString remoteTCPSinkAddress = parser.getRemoteTCPSinkAddressOption(); QString remoteTCPSinkAddress = parser.getRemoteTCPSinkAddressOption();
int remoteTCPSinkPort = parser.getRemoteTCPSinkPortOption(); int remoteTCPSinkPort = parser.getRemoteTCPSinkPortOption();
QString remoteTCPSinkHWType = parser.getRemoteTCPSinkHWType(); QString remoteTCPSinkHWType = parser.getRemoteTCPSinkHWType();
QString remoteTCPSinkSerial = parser.getRemoteTCPSinkSerial(); QString remoteTCPSinkSerial = parser.getRemoteTCPSinkSerial();
QTimer::singleShot(250, [=] { QTimer::singleShot(250, [=] {
startRemoteTCPSink( startRemoteTCPSink(
remoteTCPSinkAddress, remoteTCPSinkAddress,
remoteTCPSinkPort, remoteTCPSinkPort,
remoteTCPSinkHWType, remoteTCPSinkHWType,
remoteTCPSinkSerial); remoteTCPSinkSerial);
}); });
} }

View File

@ -1,32 +1,32 @@
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2023 Jon Beniston, M7RCE // // Copyright (C) 2023 Jon Beniston, M7RCE //
// // // //
// This program is free software; you can redistribute it and/or modify // // This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by // // it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or // // the Free Software Foundation as version 3 of the License, or //
// (at your option) any later version. // // (at your option) any later version. //
// // // //
// This program is distributed in the hope that it will be useful, // // This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of // // but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. // // GNU General Public License V3 for more details. //
// // // //
// You should have received a copy of the GNU General Public License // // You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. // // along with this program. If not, see <http://www.gnu.org/licenses/>. //
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
#ifndef REMOTETCPSINKSTARTER_H #ifndef REMOTETCPSINKSTARTER_H
#define REMOTETCPSINKSTARTER_H #define REMOTETCPSINKSTARTER_H
#include "mainparser.h" #include "mainparser.h"
#include "export.h" #include "export.h"
class SDRBASE_API RemoteTCPSinkStarter { class SDRBASE_API RemoteTCPSinkStarter {
public: public:
static void listAvailableDevices(); static void listAvailableDevices();
static void start(const MainParser& parser); static void start(const MainParser& parser);
}; };
#endif /* REMOTETCPSINKSTARTER_H */ #endif /* REMOTETCPSINKSTARTER_H */