diff --git a/plugins/channelrx/demoddsd/dsddemod.cpp b/plugins/channelrx/demoddsd/dsddemod.cpp index d18120847..e632e5d6e 100644 --- a/plugins/channelrx/demoddsd/dsddemod.cpp +++ b/plugins/channelrx/demoddsd/dsddemod.cpp @@ -80,6 +80,7 @@ DSDDemod::DSDDemod(DeviceSourceAPI *deviceAPI) : m_channelizer = new DownChannelizer(this); m_threadedChannelizer = new ThreadedBasebandSampleSink(m_channelizer, this); m_deviceAPI->addThreadedSink(m_threadedChannelizer); + m_deviceAPI->addChannelAPI(this); applySettings(m_settings, true); } @@ -91,6 +92,7 @@ DSDDemod::~DSDDemod() DSPEngine::instance()->removeAudioSink(&m_audioFifo2); delete m_udpBufferAudio; + m_deviceAPI->removeChannelAPI(this); m_deviceAPI->removeThreadedSink(m_threadedChannelizer); delete m_threadedChannelizer; delete m_channelizer; diff --git a/plugins/channelrx/demoddsd/dsddemod.h b/plugins/channelrx/demoddsd/dsddemod.h index 1b4e0e896..54d0623d8 100644 --- a/plugins/channelrx/demoddsd/dsddemod.h +++ b/plugins/channelrx/demoddsd/dsddemod.h @@ -18,10 +18,12 @@ #ifndef INCLUDE_DSDDEMOD_H #define INCLUDE_DSDDEMOD_H -#include -#include #include #include + +#include "dsp/basebandsamplesink.h" +#include "channel/channelsinkapi.h" +#include "dsp/phasediscri.h" #include "dsp/nco.h" #include "dsp/interpolator.h" #include "dsp/lowpass.h" @@ -40,7 +42,7 @@ class DeviceSourceAPI; class ThreadedBasebandSampleSink; class DownChannelizer; -class DSDDemod : public BasebandSampleSink { +class DSDDemod : public BasebandSampleSink, public ChannelSinkAPI { public: class MsgConfigureDSDDemod : public Message { MESSAGE_CLASS_DECLARATION @@ -99,6 +101,10 @@ public: virtual void stop(); virtual bool handleMessage(const Message& cmd); + virtual int getDeltaFrequency() const { return m_settings.m_inputFrequencyOffset; } + virtual void getIdentifier(QString& id) { id = objectName(); } + virtual void getTitle(QString& title) { title = m_settings.m_title; } + double getMagSq() { return m_magsq; } bool getSquelchOpen() const { return m_squelchOpen; } diff --git a/plugins/channelrx/demoddsd/dsddemodgui.cpp b/plugins/channelrx/demoddsd/dsddemodgui.cpp index 0d4f5685c..858da1592 100644 --- a/plugins/channelrx/demoddsd/dsddemodgui.cpp +++ b/plugins/channelrx/demoddsd/dsddemodgui.cpp @@ -232,8 +232,9 @@ void DSDDemodGUI::onMenuDialogCalled(const QPoint &p) m_settings.m_udpAddress = m_channelMarker.getUDPAddress(), m_settings.m_udpPort = m_channelMarker.getUDPSendPort(), m_settings.m_rgbColor = m_channelMarker.getColor().rgb(); + m_settings.m_title = m_channelMarker.getTitle(); - setWindowTitle(m_channelMarker.getTitle()); + setWindowTitle(m_settings.m_title); setTitleColor(m_settings.m_rgbColor); displayUDPAddress(); @@ -338,6 +339,7 @@ void DSDDemodGUI::displaySettings() m_channelMarker.blockSignals(true); m_channelMarker.setCenterFrequency(m_settings.m_inputFrequencyOffset); m_channelMarker.setColor(m_settings.m_rgbColor); + m_channelMarker.setTitle(m_settings.m_title); m_channelMarker.blockSignals(false); setTitleColor(m_settings.m_rgbColor); // activate signal on the last setting only diff --git a/plugins/channelrx/demoddsd/dsddemodsettings.cpp b/plugins/channelrx/demoddsd/dsddemodsettings.cpp index 6d409c2b3..729caa1db 100644 --- a/plugins/channelrx/demoddsd/dsddemodsettings.cpp +++ b/plugins/channelrx/demoddsd/dsddemodsettings.cpp @@ -51,6 +51,7 @@ void DSDDemodSettings::resetToDefaults() m_udpAddress = "127.0.0.1"; m_udpPort = 9999; m_rgbColor = QColor(0, 255, 255).rgb(); + m_title = "DSD Demodulator"; } QByteArray DSDDemodSettings::serialize() const @@ -81,6 +82,8 @@ QByteArray DSDDemodSettings::serialize() const s.writeBlob(17, m_channelMarker->serialize()); } + s.writeString(18, m_title); + return s.final(); } @@ -132,6 +135,7 @@ bool DSDDemodSettings::deserialize(const QByteArray& data) d.readBool(14, &m_slot1On, false); d.readBool(15, &m_slot2On, false); d.readBool(16, &m_tdmaStereo, false); + d.readString(18, &m_title, "DSD Demodulator"); return true; } diff --git a/plugins/channelrx/demoddsd/dsddemodsettings.h b/plugins/channelrx/demoddsd/dsddemodsettings.h index d8729a222..6c2e17e5c 100644 --- a/plugins/channelrx/demoddsd/dsddemodsettings.h +++ b/plugins/channelrx/demoddsd/dsddemodsettings.h @@ -44,6 +44,7 @@ struct DSDDemodSettings QString m_udpAddress; quint16 m_udpPort; quint32 m_rgbColor; + QString m_title; Serializable *m_channelMarker; Serializable *m_scopeGUI; diff --git a/sdrbase/CMakeLists.txt b/sdrbase/CMakeLists.txt index d5be46da4..bb0f15be0 100644 --- a/sdrbase/CMakeLists.txt +++ b/sdrbase/CMakeLists.txt @@ -63,6 +63,7 @@ set(sdrbase_SOURCES util/samplesourceserializer.cpp util/simpleserializer.cpp #util/spinlock.cpp + util/uid.cpp plugin/plugininterface.cpp plugin/pluginapi.cpp @@ -162,6 +163,7 @@ set(sdrbase_HEADERS util/samplesourceserializer.h util/simpleserializer.h #util/spinlock.h + util/uid.h webapi/webapiadapterinterface.h webapi/webapirequestmapper.h diff --git a/sdrbase/channel/channelsinkapi.cpp b/sdrbase/channel/channelsinkapi.cpp index 34285a83e..3a00b8001 100644 --- a/sdrbase/channel/channelsinkapi.cpp +++ b/sdrbase/channel/channelsinkapi.cpp @@ -16,8 +16,11 @@ // along with this program. If not, see . // /////////////////////////////////////////////////////////////////////////////////// +#include "util/uid.h" #include "channelsinkapi.h" ChannelSinkAPI::ChannelSinkAPI() : - m_indexInDeviceSet(-1) -{ } + m_indexInDeviceSet(-1), + m_uid(UidCalculator::getNewObjectId()) +{ +} diff --git a/sdrbase/channel/channelsinkapi.h b/sdrbase/channel/channelsinkapi.h index 0bc51fea9..1ecb14587 100644 --- a/sdrbase/channel/channelsinkapi.h +++ b/sdrbase/channel/channelsinkapi.h @@ -20,6 +20,8 @@ #define SDRBASE_CHANNEL_CHANNELSINKAPI_H_ #include +#include + #include "util/export.h" class SDRANGEL_API ChannelSinkAPI { @@ -33,9 +35,11 @@ public: int getIndexInDeviceSet() const { return m_indexInDeviceSet; } void setIndexInDeviceSet(int indexInDeviceSet) { m_indexInDeviceSet = indexInDeviceSet; } + uint64_t getUID() const { return m_uid; } private: int m_indexInDeviceSet; + uint64_t m_uid; }; diff --git a/sdrbase/channel/channelsourceapi.cpp b/sdrbase/channel/channelsourceapi.cpp index 07b06b9c3..5cf607aaa 100644 --- a/sdrbase/channel/channelsourceapi.cpp +++ b/sdrbase/channel/channelsourceapi.cpp @@ -16,9 +16,11 @@ // along with this program. If not, see . // /////////////////////////////////////////////////////////////////////////////////// +#include "util/uid.h" #include "channelsourceapi.h" ChannelSourceAPI::ChannelSourceAPI() : - m_indexInDeviceSet(-1) + m_indexInDeviceSet(-1), + m_uid(UidCalculator::getNewObjectId()) { } diff --git a/sdrbase/channel/channelsourceapi.h b/sdrbase/channel/channelsourceapi.h index 01bf9822a..4767b8f26 100644 --- a/sdrbase/channel/channelsourceapi.h +++ b/sdrbase/channel/channelsourceapi.h @@ -20,6 +20,8 @@ #define SDRBASE_CHANNEL_CHANNELSOURCEAPI_H_ #include +#include + #include "util/export.h" class SDRANGEL_API ChannelSourceAPI { @@ -33,9 +35,11 @@ public: int getIndexInDeviceSet() const { return m_indexInDeviceSet; } void setIndexInDeviceSet(int indexInDeviceSet) { m_indexInDeviceSet = indexInDeviceSet; } + uint64_t getUID() const { return m_uid; } private: int m_indexInDeviceSet; + uint64_t m_uid; }; diff --git a/sdrbase/sdrbase.pro b/sdrbase/sdrbase.pro index 1f1edb569..1c03bf6de 100644 --- a/sdrbase/sdrbase.pro +++ b/sdrbase/sdrbase.pro @@ -104,6 +104,7 @@ SOURCES += audio/audiodeviceinfo.cpp\ util/syncmessenger.cpp\ util/samplesourceserializer.cpp\ util/simpleserializer.cpp\ + util/uid.cpp\ plugin/plugininterface.cpp\ plugin/pluginapi.cpp\ plugin/pluginmanager.cpp\ @@ -189,6 +190,7 @@ HEADERS += audio/audiodeviceinfo.h\ util/syncmessenger.h\ util/samplesourceserializer.h\ util/simpleserializer.h\ + util/uid.h\ webapi/webapiadapterinterface.h\ webapi/webapirequestmapper.h\ webapi/webapiserver.h\ diff --git a/sdrbase/util/uid.cpp b/sdrbase/util/uid.cpp new file mode 100644 index 000000000..386f16586 --- /dev/null +++ b/sdrbase/util/uid.cpp @@ -0,0 +1,88 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2017 F4EXB // +// written by Edouard Griffiths // +// // +// Object unique id calculator loosely inspired by MongoDB object id // +// // +// 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 // +// the Free Software Foundation as version 3 of the License, or // +// // +// 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 V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include + +#ifdef _WIN32_ +#include +#else +#include +#endif + +#include "uid.h" + +uint64_t UidCalculator::getNewObjectId() +{ + QDateTime currentDateTime = QDateTime::currentDateTime(); + uint64_t uid = currentDateTime.toTime_t(); + uid *= 1000000UL; // make room for microseconds + +// Fallback to milliseconds: +// QTime timeNow = QTime::currentTime(); +// uint64_t usecs = timeNow.msec() * 1000UL; +// uid += usecs; + uid += getCurrentMiroseconds(); + + return uid; +} + +uint32_t UidCalculator::getNewInstanceId() +{ + uint32_t uid = (QCoreApplication::applicationPid() % (1<<16)); + + QString hostname = QHostInfo::localHostName(); + QByteArray hashKey = QCryptographicHash::hash(hostname.toUtf8(), QCryptographicHash::Sha1); + uint32_t hashHost = 0; + + for (int i = 0; i < hashKey.size(); i++) { + char c = hashKey.at(i); + hashHost += (uint32_t) c; + } + + hashHost %= (1<<16); + uid += (hashHost<<16); + + return uid; +} + +uint64_t UidCalculator::getCurrentMiroseconds() +{ +#ifdef _WIN32_ + LARGE_INTEGER tickPerSecond; + LARGE_INTEGER tick; // a point in time + + // get the high resolution counter's accuracy + QueryPerformanceFrequency(&tickPerSecond); + + // what time is it ? + QueryPerformanceCounter(&tick); + + // and here we get the current microsecond! \o/ + return (tick.QuadPart % tickPerSecond.QuadPart); +#else + struct timeval tv; + gettimeofday(&tv, 0); + return tv.tv_usec; +#endif +} + diff --git a/sdrbase/util/uid.h b/sdrbase/util/uid.h new file mode 100644 index 000000000..eb7b82e7f --- /dev/null +++ b/sdrbase/util/uid.h @@ -0,0 +1,45 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2017 F4EXB // +// written by Edouard Griffiths // +// // +// Object unique id calculator loosely inspired by MongoDB object id // +// // +// 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 // +// the Free Software Foundation as version 3 of the License, or // +// // +// 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 V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// +#ifndef SDRBASE_UTIL_UID_H_ +#define SDRBASE_UTIL_UID_H_ + +#include + +class UidCalculator +{ +public: + /** + * Get a new object unique Id. It is the addition of: + * - 6 digit microseconds in current second + * - 4 byte Unix epoch multiplied by 1000000 + */ + static uint64_t getNewObjectId(); + + /** + * Get a new instance unique Id. It is made of from LSB to MSB: + * - 2 byte process id + * - 2 byte hashed host name + */ + static uint32_t getNewInstanceId(); + +private: + static uint64_t getCurrentMiroseconds(); +}; + +#endif /* SDRBASE_UTIL_UID_H_ */ diff --git a/sdrgui/webapi/webapiadaptergui.cpp b/sdrgui/webapi/webapiadaptergui.cpp index 18c9b0358..51c376a14 100644 --- a/sdrgui/webapi/webapiadaptergui.cpp +++ b/sdrgui/webapi/webapiadaptergui.cpp @@ -97,6 +97,7 @@ int WebAPIAdapterGUI::instanceSummary( ChannelSourceAPI *channel = (*it)->m_deviceSinkAPI->getChanelAPIAt(i); channels->back()->setDeltaFrequency(channel->getDeltaFrequency()); channels->back()->setIndex(channel->getIndexInDeviceSet()); + channels->back()->setUid(channel->getUID()); channel->getIdentifier(*channels->back()->getId()); channel->getTitle(*channels->back()->getTitle()); } @@ -126,6 +127,7 @@ int WebAPIAdapterGUI::instanceSummary( ChannelSinkAPI *channel = (*it)->m_deviceSourceAPI->getChanelAPIAt(i); channels->back()->setDeltaFrequency(channel->getDeltaFrequency()); channels->back()->setIndex(channel->getIndexInDeviceSet()); + channels->back()->setUid(channel->getUID()); channel->getIdentifier(*channels->back()->getId()); channel->getTitle(*channels->back()->getTitle()); } diff --git a/swagger/sdrangel/api/swagger/swagger.yaml b/swagger/sdrangel/api/swagger/swagger.yaml index d646a1bf0..dccc63df7 100644 --- a/swagger/sdrangel/api/swagger/swagger.yaml +++ b/swagger/sdrangel/api/swagger/swagger.yaml @@ -599,6 +599,7 @@ definitions: required: - index - id + - uid - title - deltaFrequency properties: @@ -608,6 +609,10 @@ definitions: id: description: "Key to identify the type of channel" type: string + uid: + description: "Channel instance unique id" + type: integer + format: int64 title: description: "Freeform title of the channel" type: string diff --git a/swagger/sdrangel/code/html2/index.html b/swagger/sdrangel/code/html2/index.html index 395d9abd1..e4e111799 100644 --- a/swagger/sdrangel/code/html2/index.html +++ b/swagger/sdrangel/code/html2/index.html @@ -737,7 +737,7 @@ margin-bottom: 20px; "description" : "Audio devices selected" }; defs.Channel = { - "required" : [ "deltaFrequency", "id", "index", "title" ], + "required" : [ "deltaFrequency", "id", "index", "title", "uid" ], "properties" : { "index" : { "type" : "integer", @@ -747,6 +747,11 @@ margin-bottom: 20px; "type" : "string", "description" : "Key to identify the type of channel" }, + "uid" : { + "type" : "integer", + "format" : "int64", + "description" : "Channel instance unique id" + }, "title" : { "type" : "string", "description" : "Freeform title of the channel" @@ -7297,7 +7302,7 @@ except ApiException as e:
- Generated 2017-11-19T03:28:56.995+01:00 + Generated 2017-11-19T10:38:58.684+01:00
diff --git a/swagger/sdrangel/code/qt5/client/SWGChannel.cpp b/swagger/sdrangel/code/qt5/client/SWGChannel.cpp index a6a1b5ea4..9cf29b172 100644 --- a/swagger/sdrangel/code/qt5/client/SWGChannel.cpp +++ b/swagger/sdrangel/code/qt5/client/SWGChannel.cpp @@ -39,6 +39,7 @@ void SWGChannel::init() { index = 0; id = new QString(""); + uid = 0L; title = new QString(""); delta_frequency = 0; } @@ -51,6 +52,7 @@ SWGChannel::cleanup() { delete id; } + if(title != nullptr) { delete title; } @@ -70,6 +72,7 @@ void SWGChannel::fromJsonObject(QJsonObject &pJson) { ::Swagger::setValue(&index, pJson["index"], "qint32", ""); ::Swagger::setValue(&id, pJson["id"], "QString", "QString"); + ::Swagger::setValue(&uid, pJson["uid"], "qint64", ""); ::Swagger::setValue(&title, pJson["title"], "QString", "QString"); ::Swagger::setValue(&delta_frequency, pJson["deltaFrequency"], "qint32", ""); } @@ -92,6 +95,8 @@ SWGChannel::asJsonObject() { toJsonValue(QString("id"), id, obj, QString("QString")); + obj->insert("uid", QJsonValue(uid)); + toJsonValue(QString("title"), title, obj, QString("QString")); obj->insert("deltaFrequency", QJsonValue(delta_frequency)); @@ -117,6 +122,15 @@ SWGChannel::setId(QString* id) { this->id = id; } +qint64 +SWGChannel::getUid() { + return uid; +} +void +SWGChannel::setUid(qint64 uid) { + this->uid = uid; +} + QString* SWGChannel::getTitle() { return title; diff --git a/swagger/sdrangel/code/qt5/client/SWGChannel.h b/swagger/sdrangel/code/qt5/client/SWGChannel.h index 9b8a802ac..7749c256a 100644 --- a/swagger/sdrangel/code/qt5/client/SWGChannel.h +++ b/swagger/sdrangel/code/qt5/client/SWGChannel.h @@ -48,6 +48,9 @@ public: QString* getId(); void setId(QString* id); + qint64 getUid(); + void setUid(qint64 uid); + QString* getTitle(); void setTitle(QString* title); @@ -58,6 +61,7 @@ public: private: qint32 index; QString* id; + qint64 uid; QString* title; qint32 delta_frequency; };