diff --git a/plugins/feature/afc/afc.h b/plugins/feature/afc/afc.h index 01205736f..767f874a5 100644 --- a/plugins/feature/afc/afc.h +++ b/plugins/feature/afc/afc.h @@ -159,6 +159,7 @@ public: virtual bool handleMessage(const Message& cmd); virtual void getIdentifier(QString& id) const { id = objectName(); } + virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) const { title = m_settings.m_title; } virtual QByteArray serialize() const; diff --git a/plugins/feature/ais/ais.h b/plugins/feature/ais/ais.h index 59ce986e1..8ded17815 100644 --- a/plugins/feature/ais/ais.h +++ b/plugins/feature/ais/ais.h @@ -68,6 +68,7 @@ public: virtual bool handleMessage(const Message& cmd); virtual void getIdentifier(QString& id) const { id = objectName(); } + virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) const { title = m_settings.m_title; } virtual QByteArray serialize() const; diff --git a/plugins/feature/antennatools/antennatools.h b/plugins/feature/antennatools/antennatools.h index e4f65ac40..ab0306f6f 100644 --- a/plugins/feature/antennatools/antennatools.h +++ b/plugins/feature/antennatools/antennatools.h @@ -69,6 +69,7 @@ public: virtual bool handleMessage(const Message& cmd); virtual void getIdentifier(QString& id) const { id = objectName(); } + virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) const { title = m_settings.m_title; } virtual QByteArray serialize() const; diff --git a/plugins/feature/aprs/aprs.h b/plugins/feature/aprs/aprs.h index 0d587fc1f..c54510b73 100644 --- a/plugins/feature/aprs/aprs.h +++ b/plugins/feature/aprs/aprs.h @@ -120,6 +120,7 @@ public: virtual bool handleMessage(const Message& cmd); virtual void getIdentifier(QString& id) const { id = objectName(); } + virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) const { title = m_settings.m_title; } virtual QByteArray serialize() const; diff --git a/plugins/feature/demodanalyzer/demodanalyzer.h b/plugins/feature/demodanalyzer/demodanalyzer.h index 1413c25d3..fc29400fd 100644 --- a/plugins/feature/demodanalyzer/demodanalyzer.h +++ b/plugins/feature/demodanalyzer/demodanalyzer.h @@ -162,6 +162,7 @@ public: virtual bool handleMessage(const Message& cmd); virtual void getIdentifier(QString& id) const { id = objectName(); } + virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) const { title = m_settings.m_title; } virtual QByteArray serialize() const; diff --git a/plugins/feature/gs232controller/gs232controller.h b/plugins/feature/gs232controller/gs232controller.h index 20c3f0cde..20dc9084d 100644 --- a/plugins/feature/gs232controller/gs232controller.h +++ b/plugins/feature/gs232controller/gs232controller.h @@ -107,6 +107,7 @@ public: virtual bool handleMessage(const Message& cmd); virtual void getIdentifier(QString& id) const { id = objectName(); } + virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) const { title = m_settings.m_title; } virtual QByteArray serialize() const; diff --git a/plugins/feature/jogdialcontroller/jogdialcontroller.h b/plugins/feature/jogdialcontroller/jogdialcontroller.h index 00163d6d4..58e621d21 100644 --- a/plugins/feature/jogdialcontroller/jogdialcontroller.h +++ b/plugins/feature/jogdialcontroller/jogdialcontroller.h @@ -155,6 +155,7 @@ public: virtual bool handleMessage(const Message& cmd); virtual void getIdentifier(QString& id) const { id = objectName(); } + virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) const { title = m_settings.m_title; } virtual QByteArray serialize() const; diff --git a/plugins/feature/map/map.h b/plugins/feature/map/map.h index fca1a7475..7d93a49cc 100644 --- a/plugins/feature/map/map.h +++ b/plugins/feature/map/map.h @@ -109,6 +109,7 @@ public: virtual bool handleMessage(const Message& cmd); virtual void getIdentifier(QString& id) const { id = objectName(); } + virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) const { title = m_settings.m_title; } virtual QByteArray serialize() const; diff --git a/plugins/feature/pertester/pertester.h b/plugins/feature/pertester/pertester.h index 3b7cb89a7..61a22ba7e 100644 --- a/plugins/feature/pertester/pertester.h +++ b/plugins/feature/pertester/pertester.h @@ -122,6 +122,7 @@ public: virtual bool handleMessage(const Message& cmd); virtual void getIdentifier(QString& id) const { id = objectName(); } + virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) const { title = m_settings.m_title; } virtual QByteArray serialize() const; diff --git a/plugins/feature/radiosonde/radiosonde.h b/plugins/feature/radiosonde/radiosonde.h index d98521764..6e1e4aec5 100644 --- a/plugins/feature/radiosonde/radiosonde.h +++ b/plugins/feature/radiosonde/radiosonde.h @@ -68,6 +68,7 @@ public: virtual bool handleMessage(const Message& cmd); virtual void getIdentifier(QString& id) const { id = objectName(); } + virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) const { title = m_settings.m_title; } virtual QByteArray serialize() const; diff --git a/plugins/feature/rigctlserver/rigctlserver.h b/plugins/feature/rigctlserver/rigctlserver.h index 6f6313a95..3ab0277db 100644 --- a/plugins/feature/rigctlserver/rigctlserver.h +++ b/plugins/feature/rigctlserver/rigctlserver.h @@ -87,6 +87,7 @@ public: virtual bool handleMessage(const Message& cmd); virtual void getIdentifier(QString& id) const { id = objectName(); } + virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) const { title = m_settings.m_title; } virtual QByteArray serialize() const; diff --git a/plugins/feature/satellitetracker/satellitetracker.h b/plugins/feature/satellitetracker/satellitetracker.h index 4c0c4c09a..d8c4a4b93 100644 --- a/plugins/feature/satellitetracker/satellitetracker.h +++ b/plugins/feature/satellitetracker/satellitetracker.h @@ -126,6 +126,7 @@ public: virtual bool handleMessage(const Message& cmd); virtual void getIdentifier(QString& id) const { id = objectName(); } + virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) const { title = m_settings.m_title; } virtual QByteArray serialize() const; diff --git a/plugins/feature/simpleptt/simpleptt.h b/plugins/feature/simpleptt/simpleptt.h index 5f57fac03..182b53f9e 100644 --- a/plugins/feature/simpleptt/simpleptt.h +++ b/plugins/feature/simpleptt/simpleptt.h @@ -105,6 +105,7 @@ public: virtual bool handleMessage(const Message& cmd); virtual void getIdentifier(QString& id) const { id = objectName(); } + virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) const { title = m_settings.m_title; } virtual QByteArray serialize() const; diff --git a/plugins/feature/startracker/startracker.cpp b/plugins/feature/startracker/startracker.cpp index e0ee6c6cb..ac56c837a 100644 --- a/plugins/feature/startracker/startracker.cpp +++ b/plugins/feature/startracker/startracker.cpp @@ -27,6 +27,7 @@ #include "SWGDeviceState.h" #include "SWGStarTrackerDisplaySettings.h" +#include "device/deviceset.h" #include "dsp/dspengine.h" #include "util/weather.h" #include "util/units.h" @@ -53,8 +54,6 @@ StarTracker::StarTracker(WebAPIAdapterInterface *webAPIAdapterInterface) : m_worker->moveToThread(&m_thread); m_state = StIdle; m_errorMessage = "StarTracker error"; - connect(&m_updatePipesTimer, SIGNAL(timeout()), this, SLOT(updatePipes())); - m_updatePipesTimer.start(1000); m_networkManager = new QNetworkAccessManager(); QObject::connect( m_networkManager, @@ -69,10 +68,13 @@ StarTracker::StarTracker(WebAPIAdapterInterface *webAPIAdapterInterface) : m_temps.append(new FITS(":/startracker/startracker/408mhz_ra_dec.fits")); m_temps.append(new FITS(":/startracker/startracker/1420mhz_ra_dec.fits")); m_spectralIndex = new FITS(":/startracker/startracker/408mhz_ra_dec_spectral_index.fits"); + scanAvailableChannels(); + connect(MainCore::instance(), SIGNAL(channelAdded(int, ChannelAPI*)), this, SLOT(handleChannelAdded(int, ChannelAPI*))); } StarTracker::~StarTracker() { + disconnect(MainCore::instance(), SIGNAL(channelAdded(int, ChannelAPI*)), this, SLOT(handleChannelAdded(int, ChannelAPI*))); QObject::disconnect( m_networkManager, &QNetworkAccessManager::finished, @@ -170,23 +172,6 @@ bool StarTracker::handleMessage(const Message& cmd) } } -void StarTracker::updatePipes() -{ - QList availablePipes = updateAvailablePipeSources("startracker.display", StarTrackerSettings::m_pipeTypes, StarTrackerSettings::m_pipeURIs, this); - - if (availablePipes != m_availablePipes) - { - m_availablePipes = availablePipes; - if (getMessageQueueToGUI()) - { - MsgReportPipes *msgToGUI = MsgReportPipes::create(); - QList& msgAvailablePipes = msgToGUI->getAvailablePipes(); - msgAvailablePipes.append(availablePipes); - getMessageQueueToGUI()->push(msgToGUI); - } - } -} - QByteArray StarTracker::serialize() const { return m_settings.serialize(); @@ -902,3 +887,92 @@ bool StarTracker::calcSkyTemperature(double frequency, double beamwidth, double } } } + +void StarTracker::scanAvailableChannels() +{ + MainCore *mainCore = MainCore::instance(); + MessagePipes& messagePipes = mainCore->getMessagePipes(); + std::vector& deviceSets = mainCore->getDeviceSets(); + m_availableChannels.clear(); + + for (const auto& deviceSet : deviceSets) + { + DSPDeviceSourceEngine *deviceSourceEngine = deviceSet->m_deviceSourceEngine; + + if (deviceSourceEngine) + { + for (int chi = 0; chi < deviceSet->getNumberOfChannels(); chi++) + { + ChannelAPI *channel = deviceSet->getChannelAt(chi); + + if (StarTrackerSettings::m_pipeURIs.contains(channel->getURI()) && !m_availableChannels.contains(channel)) + { + qDebug("StarTracker::scanAvailableChannels: register %d:%d %s (%p)", + deviceSet->getIndex(), chi, qPrintable(channel->getURI()), channel); + ObjectPipe *pipe = messagePipes.registerProducerToConsumer(channel, this, "startracker.display"); + MessageQueue *messageQueue = qobject_cast(pipe->m_element); + QObject::connect( + messageQueue, + &MessageQueue::messageEnqueued, + this, + [=](){ this->handleChannelMessageQueue(messageQueue); }, + Qt::QueuedConnection + ); + connect(pipe, SIGNAL(toBeDeleted(int, QObject*)), this, SLOT(handleMessagePipeToBeDeleted(int, QObject*))); + m_availableChannels.insert(channel); + } + } + } + } +} + +void StarTracker::handleChannelAdded(int deviceSetIndex, ChannelAPI *channel) +{ + qDebug("StarTracker::handleChannelAdded: deviceSetIndex: %d:%d channel: %s (%p)", + deviceSetIndex, channel->getIndexInDeviceSet(), qPrintable(channel->getURI()), channel); + DeviceSet *deviceSet = MainCore::instance()->getDeviceSets()[deviceSetIndex]; + DSPDeviceSourceEngine *deviceSourceEngine = deviceSet->m_deviceSourceEngine; + + if (deviceSourceEngine && StarTrackerSettings::m_pipeURIs.contains(channel->getURI())) + { + if (!m_availableChannels.contains(channel)) + { + MessagePipes& messagePipes = MainCore::instance()->getMessagePipes(); + ObjectPipe *pipe = messagePipes.registerProducerToConsumer(channel, this, "startracker.display"); + MessageQueue *messageQueue = qobject_cast(pipe->m_element); + QObject::connect( + messageQueue, + &MessageQueue::messageEnqueued, + this, + [=](){ this->handleChannelMessageQueue(messageQueue); }, + Qt::QueuedConnection + ); + connect(pipe, SIGNAL(toBeDeleted(int, QObject*)), this, SLOT(handleMessagePipeToBeDeleted(int, QObject*))); + m_availableChannels.insert(channel); + } + } +} + +void StarTracker::handleMessagePipeToBeDeleted(int reason, QObject* object) +{ + if (reason == 0) // producer (channel) + { + if (m_availableChannels.contains((ChannelAPI*) object)) + { + qDebug("StarTracker::handleMessagePipeToBeDeleted: removing channel at (%p)", object); + m_availableChannels.remove((ChannelAPI*) object); + } + } +} + +void StarTracker::handleChannelMessageQueue(MessageQueue* messageQueue) +{ + Message* message; + + while ((message = messageQueue->pop()) != nullptr) + { + if (handleMessage(*message)) { + delete message; + } + } +} diff --git a/plugins/feature/startracker/startracker.h b/plugins/feature/startracker/startracker.h index 073e44fd4..30130d929 100644 --- a/plugins/feature/startracker/startracker.h +++ b/plugins/feature/startracker/startracker.h @@ -21,7 +21,6 @@ #include #include -#include #include "feature/feature.h" #include "util/message.h" @@ -109,6 +108,7 @@ public: virtual bool handleMessage(const Message& cmd); virtual void getIdentifier(QString& id) const { id = objectName(); } + virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) const { title = m_settings.m_title; } virtual QByteArray serialize() const; @@ -160,8 +160,6 @@ private: QNetworkAccessManager *m_networkManager; QNetworkRequest m_networkRequest; - QList m_availablePipes; - QTimer m_updatePipesTimer; Weather *m_weather; float m_solarFlux; @@ -176,7 +174,6 @@ private: double applyBeam(const FITS *fits, double beamwidth, double ra, double dec, int& imgX, int& imgY) const; private slots: - void updatePipes(); void networkManagerFinished(QNetworkReply *reply); void weatherUpdated(float temperature, float pressure, float humidity); }; diff --git a/plugins/feature/vorlocalizer/vorlocalizer.h b/plugins/feature/vorlocalizer/vorlocalizer.h index 147fee8ca..af7c0bafc 100644 --- a/plugins/feature/vorlocalizer/vorlocalizer.h +++ b/plugins/feature/vorlocalizer/vorlocalizer.h @@ -139,6 +139,7 @@ public: virtual bool handleMessage(const Message& cmd); virtual void getIdentifier(QString& id) const { id = objectName(); } + virtual QString getIdentifier() const { return objectName(); } virtual void getTitle(QString& title) const { title = m_settings.m_title; } virtual QByteArray serialize() const; diff --git a/sdrbase/feature/feature.h b/sdrbase/feature/feature.h index 29197cc09..a40c5bf1f 100644 --- a/sdrbase/feature/feature.h +++ b/sdrbase/feature/feature.h @@ -58,6 +58,7 @@ public: const QString& getURI() const { return m_uri; } virtual void getIdentifier(QString& id) const = 0; + virtual QString getIdentifier() const = 0; virtual void getTitle(QString& title) const = 0; virtual void setName(const QString& name) { m_name = name; } virtual const QString& getName() const { return m_name; }