|
|
|
|
@ -27,9 +27,11 @@
@@ -27,9 +27,11 @@
|
|
|
|
|
#include "device/deviceenumerator.h" |
|
|
|
|
#include "dsp/devicesamplesource.h" |
|
|
|
|
#include "channel/channelapi.h" |
|
|
|
|
#include "channel/channelwebapiutils.h" |
|
|
|
|
#include "SWGChannelSettings.h" |
|
|
|
|
#include "SWGRemoteTCPSinkSettings.h" |
|
|
|
|
#include "SWGDeviceState.h" |
|
|
|
|
#include "SWGDeviceSettings.h" |
|
|
|
|
|
|
|
|
|
// Lists available physical devices to stdout
|
|
|
|
|
void RemoteTCPSinkStarter::listAvailableDevices() |
|
|
|
|
@ -53,133 +55,46 @@ void RemoteTCPSinkStarter::listAvailableDevices()
@@ -53,133 +55,46 @@ void RemoteTCPSinkStarter::listAvailableDevices()
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Instantiate specified sampling source device and create a RemoteTCPSink channel
|
|
|
|
|
// on the specified address and port and start the device
|
|
|
|
|
static void startRemoteTCPSink(const QString& address, int port, const QString& hwType, const QString& serial) |
|
|
|
|
RemoteTCPSinkStarter::RemoteTCPSinkStarter(const QString& address, int port, const QString& hwType, const QString& serial) : |
|
|
|
|
m_dataAddress(address), |
|
|
|
|
m_dataPort(port), |
|
|
|
|
m_deviceSet(nullptr) |
|
|
|
|
{ |
|
|
|
|
MainCore *mainCore = MainCore::instance(); |
|
|
|
|
|
|
|
|
|
// Delete any existing device sets, in case requested device is already in use
|
|
|
|
|
int initialDeviceSets = mainCore->getDeviceSets().size(); |
|
|
|
|
for (int i = 0; i < initialDeviceSets; i++) |
|
|
|
|
{ |
|
|
|
|
MainCore::MsgRemoveLastDeviceSet *msg = MainCore::MsgRemoveLastDeviceSet::create(); |
|
|
|
|
mainCore->getMainMessageQueue()->push(msg); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Wait until they've been deleted
|
|
|
|
|
if (initialDeviceSets > 0) |
|
|
|
|
{ |
|
|
|
|
do |
|
|
|
|
{ |
|
|
|
|
QTime dieTime = QTime::currentTime().addMSecs(100); |
|
|
|
|
while (QTime::currentTime() < dieTime) { |
|
|
|
|
QCoreApplication::processEvents(QEventLoop::AllEvents, 100); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
while (mainCore->getDeviceSets().size() > 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Create DeviceSet
|
|
|
|
|
unsigned int deviceSetIndex = mainCore->getDeviceSets().size(); |
|
|
|
|
MainCore::MsgAddDeviceSet *msg = MainCore::MsgAddDeviceSet::create(0); |
|
|
|
|
mainCore->getMainMessageQueue()->push(msg); |
|
|
|
|
|
|
|
|
|
// Switch to requested device type
|
|
|
|
|
int nbSamplingDevices = DeviceEnumerator::instance()->getNbRxSamplingDevices(); |
|
|
|
|
bool found = false; |
|
|
|
|
for (int i = 0; i < nbSamplingDevices; i++) |
|
|
|
|
{ |
|
|
|
|
const PluginInterface::SamplingDevice *samplingDevice; |
|
|
|
|
|
|
|
|
|
samplingDevice = DeviceEnumerator::instance()->getRxSamplingDevice(i); |
|
|
|
|
// Add device of requested type
|
|
|
|
|
SWGSDRangel::SWGDeviceSettings *response = new SWGSDRangel::SWGDeviceSettings(); |
|
|
|
|
response->init(); |
|
|
|
|
ChannelWebAPIUtils::addDevice(hwType, 0, QStringList(), response, this, SLOT(deviceOpened(int))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!hwType.isEmpty() && (hwType != samplingDevice->hardwareId)) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
if (!serial.isEmpty() && (serial != samplingDevice->serial)) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
void RemoteTCPSinkStarter::deviceOpened(int deviceSetIndex) |
|
|
|
|
{ |
|
|
|
|
m_deviceSet = MainCore::instance()->getDeviceSets()[deviceSetIndex]; |
|
|
|
|
// Add RemoteTCPSink channel
|
|
|
|
|
connect(MainCore::instance(), &MainCore::channelAdded, this, &RemoteTCPSinkStarter::channelAdded); |
|
|
|
|
ChannelWebAPIUtils::addChannel(deviceSetIndex, "sdrangel.channel.remotetcpsink", 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int direction = 0; |
|
|
|
|
MainCore::MsgSetDevice *msg = MainCore::MsgSetDevice::create(deviceSetIndex, i, direction); |
|
|
|
|
mainCore->getMainMessageQueue()->push(msg); |
|
|
|
|
found = true; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
if (!found) |
|
|
|
|
{ |
|
|
|
|
qCritical() << "startRemoteTCPSink: Failed to find device"; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
void RemoteTCPSinkStarter::channelAdded(int deviceSetIndex, ChannelAPI *channel) |
|
|
|
|
{ |
|
|
|
|
(void) deviceSetIndex; |
|
|
|
|
|
|
|
|
|
// Add RemoteTCPSink channel
|
|
|
|
|
PluginAPI::ChannelRegistrations *channelRegistrations = mainCore->getPluginManager()->getRxChannelRegistrations(); |
|
|
|
|
int nbRegistrations = channelRegistrations->size(); |
|
|
|
|
int index = 0; |
|
|
|
|
for (; index < nbRegistrations; index++) |
|
|
|
|
{ |
|
|
|
|
if (channelRegistrations->at(index).m_channelId == "RemoteTCPSink") { |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// Set RemoteTCPSink settings
|
|
|
|
|
ChannelWebAPIUtils::patchChannelSetting(channel, "dataAddress", m_dataAddress); |
|
|
|
|
ChannelWebAPIUtils::patchChannelSetting(channel, "dataPort", m_dataPort); |
|
|
|
|
|
|
|
|
|
if (index < nbRegistrations) |
|
|
|
|
{ |
|
|
|
|
MainCore::MsgAddChannel *msg = MainCore::MsgAddChannel::create(deviceSetIndex, index, 0); |
|
|
|
|
mainCore->getMainMessageQueue()->push(msg); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
qCritical() << "startRemoteTCPSink: RemoteTCPSink is not available"; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
int channelIndex = 0; |
|
|
|
|
// Wait for settings to be applied, then start the device
|
|
|
|
|
QTimer::singleShot(250, [=] { |
|
|
|
|
startDevice(); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Wait until device & channel are created - is there a better way?
|
|
|
|
|
DeviceSet *deviceSet = nullptr; |
|
|
|
|
ChannelAPI *channelAPI = nullptr; |
|
|
|
|
do |
|
|
|
|
{ |
|
|
|
|
QTime dieTime = QTime::currentTime().addMSecs(100); |
|
|
|
|
while (QTime::currentTime() < dieTime) { |
|
|
|
|
QCoreApplication::processEvents(QEventLoop::AllEvents, 100); |
|
|
|
|
} |
|
|
|
|
void RemoteTCPSinkStarter::startDevice() |
|
|
|
|
{ |
|
|
|
|
// Start the device
|
|
|
|
|
ChannelWebAPIUtils::run(m_deviceSet->getIndex()); |
|
|
|
|
|
|
|
|
|
if (mainCore->getDeviceSets().size() > deviceSetIndex) |
|
|
|
|
{ |
|
|
|
|
deviceSet = mainCore->getDeviceSets()[deviceSetIndex]; |
|
|
|
|
if (deviceSet) { |
|
|
|
|
channelAPI = deviceSet->m_deviceAPI->getChanelSinkAPIAt(channelIndex); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
while (channelAPI == nullptr); |
|
|
|
|
|
|
|
|
|
// Set TCP settings
|
|
|
|
|
QStringList channelSettingsKeys = {"dataAddress", "dataPort"}; |
|
|
|
|
SWGSDRangel::SWGChannelSettings response; |
|
|
|
|
response.init(); |
|
|
|
|
SWGSDRangel::SWGRemoteTCPSinkSettings *sinkSettings = response.getRemoteTcpSinkSettings(); |
|
|
|
|
sinkSettings->setDataAddress(new QString(address)); |
|
|
|
|
sinkSettings->setDataPort(port); |
|
|
|
|
QString errorMessage; |
|
|
|
|
channelAPI->webapiSettingsPutPatch(false, channelSettingsKeys, response, errorMessage); |
|
|
|
|
|
|
|
|
|
// Wait some time for settings to be applied
|
|
|
|
|
QCoreApplication::processEvents(QEventLoop::AllEvents, 100); |
|
|
|
|
|
|
|
|
|
// Start the device (use WebAPI so GUI is updated)
|
|
|
|
|
DeviceSampleSource *source = deviceSet->m_deviceAPI->getSampleSource(); |
|
|
|
|
QStringList deviceActionsKeys; |
|
|
|
|
SWGSDRangel::SWGDeviceState state; |
|
|
|
|
state.init(); |
|
|
|
|
int res = source->webapiRun(true, state, errorMessage); |
|
|
|
|
if (res != 200) { |
|
|
|
|
qCritical() << "startRemoteTCPSink: Failed to start device: " << res; |
|
|
|
|
} else { |
|
|
|
|
qInfo().nospace().noquote() << "Remote TCP Sink started on " << address << ":" << port; |
|
|
|
|
} |
|
|
|
|
// Delete object as we have finished
|
|
|
|
|
delete this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Start Remote TCP Sink on specified device, with specified address and port
|
|
|
|
|
@ -191,8 +106,7 @@ void RemoteTCPSinkStarter::start(const MainParser& parser)
@@ -191,8 +106,7 @@ void RemoteTCPSinkStarter::start(const MainParser& parser)
|
|
|
|
|
QString remoteTCPSinkSerial = parser.getRemoteTCPSinkSerial(); |
|
|
|
|
|
|
|
|
|
QTimer::singleShot(250, [=] { |
|
|
|
|
startRemoteTCPSink( |
|
|
|
|
remoteTCPSinkAddress, |
|
|
|
|
new RemoteTCPSinkStarter(remoteTCPSinkAddress, |
|
|
|
|
remoteTCPSinkPort, |
|
|
|
|
remoteTCPSinkHWType, |
|
|
|
|
remoteTCPSinkSerial); |
|
|
|
|
|