19 #include <QNetworkAccessManager> 20 #include <QNetworkReply> 46 m_deviceAPI(deviceAPI),
47 m_basebandSampleRate(48000),
48 m_outputSampleRate(48000),
49 m_inputFrequencyOffset(0),
52 m_spectrumEnabled(false),
53 m_spectrumChunkSize(2160),
54 m_spectrumChunkCounter(0),
56 m_movingAverage(16, 1e-10),
57 m_inMovingAverage(480, 1e-10),
59 m_sampleRateAvgCounter(0),
63 m_levelNbSamples(480),
65 m_squelchOpenCount(0),
66 m_squelchCloseCount(0),
67 m_squelchThreshold(4800),
69 m_SSBFilterBufferIndex(0),
70 m_settingsMutex(QMutex::Recursive)
150 double magsq = ci.real() * ci.real() + ci.imag() * ci.imag();
335 qDebug() <<
"UDPSource::handleMessage: MsgChannelizerNotification";
344 qDebug() <<
"UDPSource::handleMessage: MsgConfigureChannelizer:" 357 qDebug() <<
"UDPSource::handleMessage: MsgConfigureUDPSource";
390 qDebug(
"UDPSource::handleMessage: MsgSampleRateCorrection: corr: %+.6f new rate: %.0f: avg rate: %.0f",
419 qDebug() <<
"UDPSource::handleMessage: MsgUDPSourceSpectrum: m_spectrumEnabled: " <<
m_spectrumEnabled;
429 qDebug() <<
"UDPSource::handleMessage: MsgResetReadIndex";
464 qDebug() <<
"UDPSource::applyChannelSettings:" 465 <<
" basebandSampleRate: " << basebandSampleRate
466 <<
" outputSampleRate: " << outputSampleRate
467 <<
" inputFrequencyOffset: " << inputFrequencyOffset;
494 qDebug() <<
"UDPSource::applySettings:" 505 <<
" m_gainIn: " << settings.
m_gainIn 508 <<
" m_squelch: " << settings.
m_squelch <<
"dB" 512 <<
" force: " << force;
514 QList<QString> reverseAPIKeys;
517 reverseAPIKeys.append(
"inputFrequencyOffset");
520 reverseAPIKeys.append(
"sampleFormat");
523 reverseAPIKeys.append(
"inputSampleRate");
526 reverseAPIKeys.append(
"rfBandwidth");
529 reverseAPIKeys.append(
"lowCutoff");
532 reverseAPIKeys.append(
"fmDeviation");
535 reverseAPIKeys.append(
"amModFactor");
538 reverseAPIKeys.append(
"udpAddress");
541 reverseAPIKeys.append(
"udpPort");
544 reverseAPIKeys.append(
"channelMute");
547 reverseAPIKeys.append(
"gainIn");
550 reverseAPIKeys.append(
"gainOut");
553 reverseAPIKeys.append(
"squelchGate");
556 reverseAPIKeys.append(
"squelch");
559 reverseAPIKeys.append(
"squelchEnabled");
562 reverseAPIKeys.append(
"autoRWBalance");
565 reverseAPIKeys.append(
"stereoInput");
676 QString& errorMessage)
687 const QStringList& channelSettingsKeys,
689 QString& errorMessage)
693 bool frequencyOffsetChanged =
false;
695 if (channelSettingsKeys.contains(
"sampleFormat")) {
698 if (channelSettingsKeys.contains(
"inputSampleRate")) {
701 if (channelSettingsKeys.contains(
"inputFrequencyOffset"))
704 frequencyOffsetChanged =
true;
706 if (channelSettingsKeys.contains(
"rfBandwidth")) {
709 if (channelSettingsKeys.contains(
"lowCutoff")) {
712 if (channelSettingsKeys.contains(
"fmDeviation")) {
715 if (channelSettingsKeys.contains(
"amModFactor")) {
718 if (channelSettingsKeys.contains(
"channelMute")) {
721 if (channelSettingsKeys.contains(
"gainIn")) {
724 if (channelSettingsKeys.contains(
"gainOut")) {
727 if (channelSettingsKeys.contains(
"squelch")) {
730 if (channelSettingsKeys.contains(
"squelchGate")) {
733 if (channelSettingsKeys.contains(
"squelchEnabled")) {
736 if (channelSettingsKeys.contains(
"autoRWBalance")) {
739 if (channelSettingsKeys.contains(
"stereoInput")) {
742 if (channelSettingsKeys.contains(
"rgbColor")) {
745 if (channelSettingsKeys.contains(
"udpAddress")) {
748 if (channelSettingsKeys.contains(
"udpPort")) {
751 if (channelSettingsKeys.contains(
"title")) {
754 if (channelSettingsKeys.contains(
"useReverseAPI")) {
757 if (channelSettingsKeys.contains(
"reverseAPIAddress")) {
760 if (channelSettingsKeys.contains(
"reverseAPIPort")) {
763 if (channelSettingsKeys.contains(
"reverseAPIDeviceIndex")) {
766 if (channelSettingsKeys.contains(
"reverseAPIChannelIndex")) {
770 if (frequencyOffsetChanged)
794 QString& errorMessage)
870 if (channelSettingsKeys.contains(
"sampleFormat") || force) {
873 if (channelSettingsKeys.contains(
"inputSampleRate") || force) {
876 if (channelSettingsKeys.contains(
"inputFrequencyOffset") || force) {
879 if (channelSettingsKeys.contains(
"rfBandwidth") || force) {
882 if (channelSettingsKeys.contains(
"lowCutoff") || force) {
885 if (channelSettingsKeys.contains(
"fmDeviation") || force) {
888 if (channelSettingsKeys.contains(
"amModFactor") || force) {
891 if (channelSettingsKeys.contains(
"channelMute") || force) {
894 if (channelSettingsKeys.contains(
"gainIn") || force) {
897 if (channelSettingsKeys.contains(
"gainOut") || force) {
900 if (channelSettingsKeys.contains(
"squelch") || force) {
903 if (channelSettingsKeys.contains(
"squelchGate") || force) {
906 if (channelSettingsKeys.contains(
"squelchEnabled") || force) {
909 if (channelSettingsKeys.contains(
"autoRWBalance") || force) {
912 if (channelSettingsKeys.contains(
"stereoInput") || force) {
915 if (channelSettingsKeys.contains(
"rgbColor") || force) {
918 if (channelSettingsKeys.contains(
"udpAddress") || force) {
921 if (channelSettingsKeys.contains(
"udpPort") || force) {
924 if (channelSettingsKeys.contains(
"title") || force) {
928 QString channelSettingsURL = QString(
"http://%1:%2/sdrangel/deviceset/%3/channel/%4/settings")
934 m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader,
"application/json");
936 QBuffer *buffer=
new QBuffer();
937 buffer->open((QBuffer::ReadWrite));
938 buffer->write(swgChannelSettings->
asJson().toUtf8());
944 delete swgChannelSettings;
949 QNetworkReply::NetworkError replyError = reply->error();
953 qWarning() <<
"UDPSource::networkManagerFinished:" 954 <<
" error(" << (int) replyError
955 <<
"): " << replyError
956 <<
": " << reply->errorString();
960 QString answer = reply->readAll();
962 qDebug(
"UDPSource::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
float m_modPhasor
Phasor for FM modulation.
virtual bool deserialize(const QByteArray &data)
void setLowCutoff(float low_cutoff)
double getInMagSq() const
void setOriginatorChannelIndex(qint32 originator_channel_index)
int m_spectrumChunkCounter
Complex nextIQ()
Return next complex sample.
QNetworkRequest m_networkRequest
bool decimate(Real *distance, const Complex &next, Complex *result)
void push(Message *message, bool emitSignal=true)
Push message onto queue.
qint32 getReverseApiDeviceIndex()
void setReverseApiDeviceIndex(qint32 reverse_api_device_index)
virtual int webapiSettingsPutPatch(bool force, const QStringList &channelSettingsKeys, SWGSDRangel::SWGChannelSettings &response, QString &errorMessage)
Fixed< IntType, IntBits > cos(Fixed< IntType, IntBits > const &x)
Complex * m_SSBFilterBuffer
void setReverseApiChannelIndex(qint32 reverse_api_channel_index)
void setFmDeviation(qint32 fm_deviation)
static const QString m_channelId
void applySettings(const UDPSourceSettings &settings, bool force=false)
void removeChannelSourceAPI(ChannelAPI *channelAPI, int streamIndex=0)
static double dbPower(double magsq, double floor=1e-12)
QString * getReverseApiAddress()
void initSquelch(bool open)
void setChannelSampleRate(qint32 channel_sample_rate)
void create(int phaseSteps, double sampleRate, double cutoff, double nbTapsPerPhase=4.5)
bool interpolate(Real *distance, const Complex &next, Complex *result)
int m_inputFrequencyOffset
int getDeviceSetIndex() const
static MsgResetReadIndex * create()
static const QString m_channelIdURI
virtual void pull(Sample &sample)
void removeChannelSource(ThreadedBasebandSampleSource *sink, int streamIndex=0)
Remove a channel source (Tx)
void setReverseApiAddress(QString *reverse_api_address)
static const int m_sampleRateAverageItems
virtual int webapiReportGet(SWGSDRangel::SWGChannelReport &response, QString &errorMessage)
void setSampleFormat(qint32 sample_format)
MessageQueue * getInputMessageQueue()
Get the queue for asynchronous inbound communication.
void setReverseApiPort(qint32 reverse_api_port)
SWGUDPSourceSettings * getUdpSourceSettings()
void setUdpAddress(QString *udp_address)
void networkManagerFinished(QNetworkReply *reply)
int m_SSBFilterBufferIndex
Fixed< IntType, IntBits > abs(Fixed< IntType, IntBits > const &x)
void setStereoInput(qint32 stereo_input)
BasebandSampleSink * m_spectrum
Real m_interpolatorDistanceRemain
UDPSourceSettings m_settings
void setSquelchGate(float squelch_gate)
static const int m_ssbFftLen
void setAutoRWBalance(bool autoRWBalance)
void setChannelType(QString *channel_type)
virtual void feed(const SampleVector::const_iterator &begin, const SampleVector::const_iterator &end, bool positiveOnly)=0
void addChannelSource(ThreadedBasebandSampleSource *sink, int streamIndex=0)
Add a channel source (Tx)
QNetworkAccessManager * m_networkManager
void setOriginatorDeviceSetIndex(qint32 originator_device_set_index)
void webapiFormatChannelSettings(SWGSDRangel::SWGChannelSettings &response, const UDPSourceSettings &settings)
MovingAverage< double > m_inMovingAverage
MovingAverage< double > m_movingAverage
void setSpectrum(bool enabled)
void setAmModFactor(float am_mod_factor)
void setBufferGauge(qint32 buffer_gauge)
std::complex< float > cmplx
void setInputSampleRate(float input_sample_rate)
Real m_squelch
squared magnitude
void readMonoSample(qint16 &t)
void webapiReverseSendSettings(QList< QString > &channelSettingsKeys, const UDPSourceSettings &settings, bool force)
void setSquelch(float squelch)
void webapiFormatChannelReport(SWGSDRangel::SWGChannelReport &response)
Real m_actualInputSampleRate
sample rate with UDP buffer skew compensation
void setUseReverseApi(qint32 use_reverse_api)
qint64 m_inputFrequencyOffset
void readSample(qint16 &t)
audio mono
UDPSourceUDPHandler m_udpHandler
virtual bool handleMessage(const Message &cmd)=0
Processing of a message. Returns true if message has actually been processed.
int32_t getBufferGauge() const
int getBasebandSampleRate() const
#define MESSAGE_CLASS_DEFINITION(Name, BaseClass)
fftfilt * m_SSBFilter
Complex filter for SSB modulation.
void configureUDPLink(const QString &address, quint16 port)
void setSquelchEnabled(qint32 squelch_enabled)
qint64 getInputFrequencyOffset()
void create_filter(float f1, float f2)
void setTitle(QString *title)
QString m_reverseAPIAddress
virtual int webapiSettingsGet(SWGSDRangel::SWGChannelSettings &response, QString &errorMessage)
Fixed< IntType, IntBits > sin(Fixed< IntType, IntBits > const &x)
qint32 getAutoRwBalance()
void setInputPowerDb(float input_power_db)
static bool match(const Message *message)
QByteArray serialize() const
void setFreq(Real freq, Real sampleRate)
bool deserialize(const QByteArray &data)
uint16_t m_reverseAPIPort
Fixed< IntType, IntBits > sqrt(Fixed< IntType, IntBits > const &x)
void setUdpPort(qint32 udp_port)
void setDirection(qint32 direction)
uint16_t m_reverseAPIDeviceIndex
bool m_interpolatorConsumed
qint32 getUseReverseApi()
void setGainIn(float gain_in)
virtual QString asJson() override
qint32 getReverseApiPort()
virtual bool handleMessage(const Message &cmd)
Processing of a message. Returns true if message has actually been processed.
void setRgbColor(qint32 rgb_color)
int m_sampleRateAvgCounter
float getInputSampleRate()
void setInputFrequencyOffset(qint64 input_frequency_offset)
void setAutoRwBalance(qint32 auto_rw_balance)
qint64 getFrequencyOffset() const
UDPSource(DeviceAPI *deviceAPI)
static MsgUDPSourceSpectrum * create(bool enabled)
uint16_t m_reverseAPIChannelIndex
qint32 getSquelchEnabled()
MessageQueue * m_guiMessageQueue
Input message queue to the GUI.
void applyChannelSettings(int basebandSampleRate, int outputSampleRate, int inputFrequencyOffset, bool force=false)
Real m_interpolatorDistance
void setSquelch(qint32 squelch)
void setRfBandwidth(float rf_bandwidth)
void resizeBuffer(float sampleRate)
Interpolator m_interpolator
QString * getUdpAddress()
int runSSB(const cmplx &in, cmplx **out, bool usb, bool getDC=true)
SWGUDPSourceReport * getUdpSourceReport()
MessageQueue m_inputMessageQueue
Queue for asynchronous inbound communication.
void levelChanged(qreal rmsLevel, qreal peakLevel, int numSamples)
Real m_squelchGate
seconds
SampleFormat m_sampleFormat
int getSampleRate() const
ThreadedBasebandSampleSource * m_threadedChannelizer
qint32 getReverseApiChannelIndex()
void addChannelSourceAPI(ChannelAPI *channelAPI, int streamIndex=0)
SampleVector m_sampleBuffer
void calculateSquelch(double value)
float getCorrectionFactor() const
void setChannelPowerDb(float channel_power_db)
int getIndexInDeviceSet() const
std::complex< Real > Complex
UpChannelizer * m_channelizer
void setChannelMute(qint32 channel_mute)
void setFeedbackMessageQueue(MessageQueue *messageQueue)
void resize(int historySize, Type initial)
static double powerFromdB(double powerdB)
void setGainOut(float gain_out)
T max(const T &x, const T &y)
void setUdpSourceReport(SWGUDPSourceReport *udp_source_report)
void calculateLevel(Real sample)
virtual QByteArray serialize() const
void setUdpSourceSettings(SWGUDPSourceSettings *udp_source_settings)
void configure(MessageQueue *messageQueue, int sampleRate, int centerFrequency)
float getRawDeltaRatio() const
unsigned __int64 uint64_t