1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-17 23:28:50 -05:00

Added microsecond epoch as unique id to channel instances

This commit is contained in:
f4exb 2017-11-19 11:36:20 +01:00
parent b91ad7c4b7
commit d0572a6f84
18 changed files with 204 additions and 9 deletions

View File

@ -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;

View File

@ -18,10 +18,12 @@
#ifndef INCLUDE_DSDDEMOD_H
#define INCLUDE_DSDDEMOD_H
#include <dsp/basebandsamplesink.h>
#include <dsp/phasediscri.h>
#include <QMutex>
#include <vector>
#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; }

View File

@ -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

View File

@ -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;
}

View File

@ -44,6 +44,7 @@ struct DSDDemodSettings
QString m_udpAddress;
quint16 m_udpPort;
quint32 m_rgbColor;
QString m_title;
Serializable *m_channelMarker;
Serializable *m_scopeGUI;

View File

@ -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

View File

@ -16,8 +16,11 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include "util/uid.h"
#include "channelsinkapi.h"
ChannelSinkAPI::ChannelSinkAPI() :
m_indexInDeviceSet(-1)
{ }
m_indexInDeviceSet(-1),
m_uid(UidCalculator::getNewObjectId())
{
}

View File

@ -20,6 +20,8 @@
#define SDRBASE_CHANNEL_CHANNELSINKAPI_H_
#include <QString>
#include <stdint.h>
#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;
};

View File

@ -16,9 +16,11 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include "util/uid.h"
#include "channelsourceapi.h"
ChannelSourceAPI::ChannelSourceAPI() :
m_indexInDeviceSet(-1)
m_indexInDeviceSet(-1),
m_uid(UidCalculator::getNewObjectId())
{ }

View File

@ -20,6 +20,8 @@
#define SDRBASE_CHANNEL_CHANNELSOURCEAPI_H_
#include <QString>
#include <stdint.h>
#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;
};

View File

@ -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\

88
sdrbase/util/uid.cpp Normal file
View File

@ -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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include <QDateTime>
#include <QTime>
#include <QCoreApplication>
#include <QHostInfo>
#include <QCryptographicHash>
#ifdef _WIN32_
#include <windows.h>
#else
#include <sys/time.h>
#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
}

45
sdrbase/util/uid.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef SDRBASE_UTIL_UID_H_
#define SDRBASE_UTIL_UID_H_
#include <stdint.h>
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_ */

View File

@ -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());
}

View File

@ -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

View File

@ -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:
</div>
<div id="generator">
<div class="content">
Generated 2017-11-19T03:28:56.995+01:00
Generated 2017-11-19T10:38:58.684+01:00
</div>
</div>
</div>

View File

@ -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;

View File

@ -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;
};