specwidget.h 5.2 KB
Newer Older
丁劲犇's avatar
丁劲犇 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
/* -*- c++ -*- */
/*
 * Gqrx SDR: Software defined radio receiver powered by GNU Radio and Qt
 *           http://gqrx.dk/
 *
 * Copyright 2013 Christian Lindner DL2VCL, Stefano Leucci.
 *
 * Gqrx 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; either version 3, or (at your option)
 * any later version.
 *
 * Gqrx 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 for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Gqrx; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street,
 * Boston, MA 02110-1301, USA.
 */
#ifndef SPECWIDGET_H
#define SPECWIDGET_H

#include <QWidget>
#include <QVariant>
#include <fftw3.h>
#include <vector>
#include <QStandardItemModel>
31 32 33 34 35

#ifdef Q_OS_WINDOWS
#include "uhd_device_win32.h"
#endif
#ifdef Q_OS_LINUX
M
manjaro 已提交
36
#include "uhd_device.h"
37 38
#endif
#include "stdout_watcher.h"
丁劲犇's avatar
丁劲犇 已提交
39 40 41 42
namespace Ui {
	class specWidget;
}

M
manjaro 已提交
43
class specWidget : public QWidget, public uhd_device
丁劲犇's avatar
丁劲犇 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
{
	Q_OBJECT
	Q_PROPERTY(qint64 sampleRate READ getSampleRate WRITE setSampleRate);

public:
	explicit specWidget(QWidget *parent = nullptr);
	~specWidget();
	void setSampleRate(double rate);
	double getSampleRate(void);
protected:
	void timerEvent(QTimerEvent * e) override;
signals:
	void evt_newCenterFreq(qint64 f);
	void evt_newDemodFreq(qint64 freq, qint64 delta); /* delta is the offset from the center */
	void evt_newLowCutFreq(int f);
	void evt_newHighCutFreq(int f);
	void evt_newFilterFreq(int low, int high);  /* substitute for NewLow / NewHigh */
	void evt_pandapterRangeChanged(double min, double max);
	void evt_newZoomLevel(double level);
	void evt_newCtrlFreq(qint64);
M
manjaro 已提交
64
public slots:
丁劲犇's avatar
丁劲犇 已提交
65
	void slot_newDemodFreq(qint64 freq, qint64 delta); /* delta is the offset from the center */
66
	void slot_msg(QByteArray , bool);
丁劲犇's avatar
丁劲犇 已提交
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
public:
	void appendWavComplex(const double (* pWav)[2], const int count, double voltage_ref = 16384);
public:
	void setNewFftData(const double * rfftData, int size);
	void setNewFftDataWf(const double *  rfftData, const double *  rwfData, int size);
	void setMaxPixmapSize(int w, int h);
	void setRunningState(bool running);
	void setClickResolution(int clickres);
	void setFilterClickResolution(int clickres);
	void setFilterBoxEnabled(bool enabled);
	void setCenterLineEnabled(bool enabled);
	void setTooltipsEnabled(bool enabled);
	void setBookmarksEnabled(bool enabled);
	void setCenterFreq(quint64 f);
	void setFreqUnits(qint32 unit);
	void setDemodCenterFreq(quint64 f);
	void setFilterOffset(qint64 freq_hz);
	qint64 getFilterOffset(void);
	int getFilterBw();
	void setHiLowCutFrequencies(int LowCut, int HiCut);
	void getHiLowCutFrequencies(int *LowCut, int *HiCut);
	void setDemodRanges(int FLowCmin, int FLowCmax, int FHiCmin, int FHiCmax, bool symetric);
	void setSpanFreq(quint32 s);
	void setMaxBandiwdth(int m);
	void setHdivDelta(int delta);
	void setVdivDelta(int delta);
	void setFreqDigits(int digits);
	void setFftCenterFreq(qint64 f);
	int     getNearestPeak(QPoint pt);
	void    setWaterfallSpan(quint64 span_ms);
	quint64 getWfTimeRes(void);
	void    setFftRate(int rate_hz);
	void    clearWaterfall(void);
	bool    saveWaterfall(const QString & filename);
private slots:
	void on_pushButton_reset_clicked();
	void on_comboBox_fftSize_activated(int index);
M
manjaro 已提交
104 105 106 107
	void on_doubleSpinBox_center_valueChanged(double arg1);
	void on_spinBox_gain_valueChanged(int arg1);
	void on_doubleSpinBox_range_max_valueChanged(double arg1);
	void on_doubleSpinBox_range_min_valueChanged(double arg1);
M
manjaro 已提交
108 109
	void on_comboBox_atn_currentIndexChanged(const QString &arg1);
	void on_spinBox_chan_valueChanged(int arg1);
M
manjaro 已提交
110 111
	void on_toolButton_br_clicked();
	void on_checkBox_save_stateChanged(int arg1);
112 113 114 115 116 117 118
	void on_spinBox_bw_valueChanged(int arg1);
	void on_toolButton_br_play_clicked();
	void on_checkBox_play_stateChanged(int arg1);
	void on_doubleSpinBox_center_tx_valueChanged(double arg1);
	void on_spinBox_chan_tx_valueChanged(int arg1);
	void on_spinBox_gain_tx_valueChanged(int arg1);
	void on_spinBox_bw_tx_valueChanged(int arg1);
M
manjaro 已提交
119

丁劲犇's avatar
丁劲犇 已提交
120 121 122
private:
	void loadSettings();
	void saveSettings();
123 124 125 126 127 128 129 130 131 132
private:
	void resetProgram();
	void stopProgram();

	void initFFTW();
	void freeFFTW();
	void initRx();
	void initTx();
	void freeRx();
	void freeTx();
丁劲犇's avatar
丁劲犇 已提交
133 134
private:
	Ui::specWidget *ui = nullptr;
M
manjaro 已提交
135
	QStandardItemModel * m_attenMod = nullptr;
丁劲犇's avatar
丁劲犇 已提交
136 137 138 139 140 141 142 143 144 145
private:
	int	m_nFFTSize = 16384;
	std::vector<double> m_dHammingWnd;
	std::vector<double> m_dFFTAmp;
	fftw_plan m_pFFTPlan = nullptr;
	fftw_complex * m_pFFTIn = nullptr;
	fftw_complex * m_pFFTOut = nullptr;
	int m_nTimerID = -1;
	int m_nCurrentCenter = 0;
	double m_dManuAdd = 0;
M
manjaro 已提交
146
	//Thread
147
	uhd_io_thread * m_rxth = nullptr;
M
manjaro 已提交
148
	uhd_io_thread * m_saveth = nullptr;
149 150 151 152
	uhd_io_thread * m_txth = nullptr;
	uhd_io_thread * m_readth = nullptr;
	unsigned long long save_count;
	unsigned long long read_count;
M
manjaro 已提交
153
	std::atomic<bool> m_bSaveToFile;
154
	std::atomic<bool> m_bPlayFromFile;
M
manjaro 已提交
155
	QString m_strFolder;
156 157 158
	QString m_strFolderPlay;
	//stdout reader
	stdout_watcher * watcher = nullptr;
丁劲犇's avatar
丁劲犇 已提交
159 160 161
};

#endif // SPECWIDGET_H