SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
filesinkgui.cpp
Go to the documentation of this file.
1 // Copyright (C) 2016 Edouard Griffiths, F4EXB //
3 // //
4 // This program is free software; you can redistribute it and/or modify //
5 // it under the terms of the GNU General Public License as published by //
6 // the Free Software Foundation as version 3 of the License, or //
7 // (at your option) any later version. //
8 // //
9 // This program is distributed in the hope that it will be useful, //
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
12 // GNU General Public License V3 for more details. //
13 // //
14 // You should have received a copy of the GNU General Public License //
15 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
17 
18 #include <QDebug>
19 
20 #include <QTime>
21 #include <QDateTime>
22 #include <QString>
23 #include <QFileDialog>
24 #include <QMessageBox>
25 
26 #include "ui_filesinkgui.h"
27 #include "plugin/pluginapi.h"
28 #include "gui/colormapper.h"
29 #include "gui/glspectrum.h"
30 #include "dsp/dspengine.h"
31 #include "dsp/dspcommands.h"
32 
33 #include "mainwindow.h"
34 
35 #include "device/deviceapi.h"
36 #include "device/deviceuiset.h"
37 #include "filesinkgui.h"
38 
39 FileSinkGui::FileSinkGui(DeviceUISet *deviceUISet, QWidget* parent) :
40  QWidget(parent),
41  ui(new Ui::FileSinkGui),
42  m_deviceUISet(deviceUISet),
43  m_doApplySettings(true),
44  m_forceSettings(true),
45  m_settings(),
46  m_fileName("./test.sdriq"),
47  m_deviceSampleSink(0),
48  m_sampleRate(0),
49  m_generation(false),
50  m_startingTimeStamp(0),
51  m_samplesCount(0),
52  m_tickCount(0),
53  m_lastEngineState(DeviceAPI::StNotStarted)
54 {
55  ui->setupUi(this);
56 
57  ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold));
58  ui->centerFrequency->setValueRange(7, 0, pow(10,7));
59 
60  ui->sampleRate->setColorMapper(ColorMapper(ColorMapper::GrayGreenYellow));
61  ui->sampleRate->setValueRange(7, 32000U, 9000000U);
62 
63  ui->fileNameText->setText(m_fileName);
64 
65  connect(&(m_deviceUISet->m_deviceAPI->getMasterTimer()), SIGNAL(timeout()), this, SLOT(tick()));
66  connect(&m_updateTimer, SIGNAL(timeout()), this, SLOT(updateHardware()));
67  connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus()));
68  m_statusTimer.start(500);
69 
71 
73  connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection);
74 }
75 
77 {
78  delete ui;
79 }
80 
82 {
83  delete this;
84 }
85 
86 void FileSinkGui::setName(const QString& name)
87 {
88  setObjectName(name);
89 }
90 
91 QString FileSinkGui::getName() const
92 {
93  return objectName();
94 }
95 
97 {
100  sendSettings();
101 }
102 
104 {
106 }
107 
108 void FileSinkGui::setCenterFrequency(qint64 centerFrequency)
109 {
110  m_settings.m_centerFrequency = centerFrequency;
111  displaySettings();
112  sendSettings();
113 }
114 
115 QByteArray FileSinkGui::serialize() const
116 {
117  return m_settings.serialize();
118 }
119 
120 bool FileSinkGui::deserialize(const QByteArray& data)
121 {
122  if(m_settings.deserialize(data)) {
123  displaySettings();
124  m_forceSettings = true;
125  sendSettings();
126  return true;
127  } else {
128  resetToDefaults();
129  return false;
130  }
131 }
132 
134 {
136  {
137  qDebug("FileSinkGui::handleMessage: message: MsgConfigureFileSink");
139  m_settings = cfg.getSettings();
140  blockApplySettings(true);
141  displaySettings();
142  blockApplySettings(false);
143  return true;
144  }
146  {
147  m_generation = ((FileSinkOutput::MsgReportFileSinkGeneration&)message).getAcquisition();
148  qDebug("FileSinkGui::handleMessage: message: MsgReportFileSinkGeneration: %s", m_generation ? "start" : "stop");
150  return true;
151  }
153  {
154  m_samplesCount = ((FileSinkOutput::MsgReportFileSinkStreamTiming&)message).getSamplesCount();
156  return true;
157  }
158  else if (FileSinkOutput::MsgStartStop::match(message))
159  {
161  qDebug("FileSinkGui::handleMessage: message: MsgStartStop: %s", notif.getStartStop() ? "start" : "stop");
162  blockApplySettings(true);
163  ui->startStop->setChecked(notif.getStartStop());
164  blockApplySettings(false);
165  return true;
166  }
167  else
168  {
169  return false;
170  }
171 }
172 
174 {
175  Message* message;
176 
177  while ((message = m_inputMessageQueue.pop()) != 0)
178  {
179 
180  if (DSPSignalNotification::match(*message))
181  {
182  DSPSignalNotification* notif = (DSPSignalNotification*) message;
183  qDebug("FileSinkGui::handleInputMessages: DSPSignalNotification: SampleRate:%d, CenterFrequency:%llu", notif->getSampleRate(), notif->getCenterFrequency());
184  m_sampleRate = notif->getSampleRate();
187 
188  delete message;
189  }
190  else
191  {
192  if (handleMessage(*message))
193  {
194  delete message;
195  }
196  }
197  }
198 }
199 
201 {
204  ui->deviceRateText->setText(tr("%1k").arg((float)(m_sampleRate*(1<<m_settings.m_log2Interp)) / 1000));
205 }
206 
208 {
209  ui->centerFrequency->setValue(m_settings.m_centerFrequency / 1000);
210  ui->sampleRate->setValue(m_settings.m_sampleRate);
211 }
212 
214 {
215  if(!m_updateTimer.isActive())
216  m_updateTimer.start(100);
217 }
218 
219 
221 {
222  qDebug() << "FileSinkGui::updateHardware";
225  m_forceSettings = false;
226  m_updateTimer.stop();
227 }
228 
230 {
231  int state = m_deviceUISet->m_deviceAPI->state();
232 
233  if(m_lastEngineState != state)
234  {
235  switch(state)
236  {
238  ui->startStop->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
239  break;
240  case DeviceAPI::StIdle:
241  ui->startStop->setStyleSheet("QToolButton { background-color : blue; }");
242  break;
244  ui->startStop->setStyleSheet("QToolButton { background-color : green; }");
245  break;
246  case DeviceAPI::StError:
247  ui->startStop->setStyleSheet("QToolButton { background-color : red; }");
248  QMessageBox::information(this, tr("Message"), m_deviceUISet->m_deviceAPI->errorMessage());
249  break;
250  default:
251  break;
252  }
253 
254  m_lastEngineState = state;
255  }
256 }
257 
259 {
260  m_settings.m_centerFrequency = value * 1000;
261  sendSettings();
262 }
263 
265 {
266  m_settings.m_sampleRate = value;
267  sendSettings();
268 }
269 
271 {
272  if (index < 0) {
273  return;
274  }
275 
276  m_settings.m_log2Interp = index;
278  sendSettings();
279 }
280 
282 {
283  if (m_doApplySettings)
284  {
287  }
288 }
289 
291 {
292  (void) checked;
293  QString fileName = QFileDialog::getSaveFileName(this,
294  tr("Save I/Q record file"), ".", tr("SDR I/Q Files (*.sdriq)"), 0, QFileDialog::DontUseNativeDialog);
295 
296  if (fileName != "")
297  {
298  m_fileName = fileName;
299  ui->fileNameText->setText(m_fileName);
301  }
302 }
303 
305 {
306  qDebug() << "FileSinkGui::configureFileName: " << m_fileName.toStdString().c_str();
309 }
310 
312 {
313  ui->showFileDialog->setEnabled(!m_generation);
314 }
315 
317 {
318  int t_sec = 0;
319  int t_msec = 0;
320 
321  if (m_settings.m_sampleRate > 0){
322  t_msec = ((m_samplesCount * 1000) / m_settings.m_sampleRate) % 1000;
324  }
325 
326  QTime t(0, 0, 0, 0);
327  t = t.addSecs(t_sec);
328  t = t.addMSecs(t_msec);
329  QString s_timems = t.toString("HH:mm:ss.zzz");
330  ui->relTimeText->setText(s_timems);
331 }
332 
334 {
335  if ((++m_tickCount & 0xf) == 0)
336  {
339  }
340 }
Message * pop()
Pop message from queue.
void handleInputMessages()
void push(Message *message, bool emitSignal=true)
Push message onto queue.
void setSampleRate(qint32 sampleRate)
Definition: glspectrum.cpp:211
QString m_fileName
Definition: filesinkgui.h:64
bool deserialize(const QByteArray &data)
void on_startStop_toggled(bool checked)
bool deserialize(const QByteArray &data)
void updateStatus()
DeviceUISet * m_deviceUISet
Definition: filesinkgui.h:60
virtual void destroy()
Definition: filesinkgui.cpp:81
void updateHardware()
void on_sampleRate_changed(quint64 value)
const QTimer & getMasterTimer() const
This is the DSPEngine master timer.
Definition: deviceapi.h:173
bool m_generation
Definition: filesinkgui.h:70
void configureFileName()
QString errorMessage()
Last error message from the device engine.
Definition: deviceapi.cpp:290
MessageQueue m_inputMessageQueue
Definition: filesinkgui.h:75
virtual void setCenterFrequency(qint64 centerFrequency)
DeviceSampleSink * getSampleSink()
Return pointer to the device sample sink (single Tx) or nullptr.
Definition: deviceapi.cpp:222
FileSinkSettings m_settings
Definition: filesinkgui.h:63
Fixed< IntType, IntBits > arg(const std::complex< Fixed< IntType, IntBits > > &val)
Definition: fixed.h:2401
GLSpectrum * getSpectrum()
Direct spectrum getter.
Definition: deviceuiset.h:57
engine is before initialization
Definition: deviceapi.h:53
QTimer m_statusTimer
Definition: filesinkgui.h:66
DeviceSampleSink * m_deviceSampleSink
Definition: filesinkgui.h:67
void updateWithStreamTime()
static MsgConfigureFileSinkStreamTiming * create()
qint64 getCenterFrequency() const
Definition: dspcommands.h:329
void updateSampleRateAndFrequency()
EngineState state() const
Return the state of the device engine corresponding to the stream type.
Definition: deviceapi.cpp:277
void on_centerFrequency_changed(quint64 value)
DeviceAPI * m_deviceAPI
Definition: deviceuiset.h:48
engine is idle
Definition: deviceapi.h:54
MessageQueue * getInputMessageQueue()
static MsgStartStop * create(bool startStop)
virtual ~FileSinkGui()
Definition: filesinkgui.cpp:76
int m_lastEngineState
Definition: filesinkgui.h:74
void displaySettings()
std::size_t m_tickCount
Definition: filesinkgui.h:73
int m_sampleRate
Definition: filesinkgui.h:68
FileSinkGui(DeviceUISet *deviceUISet, QWidget *parent=0)
Definition: filesinkgui.cpp:39
static bool match(const Message *message)
Definition: message.cpp:45
const FileSinkSettings & getSettings() const
void on_showFileDialog_clicked(bool checked)
QTimer m_updateTimer
Definition: filesinkgui.h:65
void blockApplySettings(bool block)
Definition: filesinkgui.h:77
void sendSettings()
void resetToDefaults()
Definition: filesinkgui.cpp:96
Ui::FileSinkGui * ui
Definition: filesinkgui.h:58
void setName(const QString &name)
Definition: filesinkgui.cpp:86
void updateWithGeneration()
QByteArray serialize() const
static MsgConfigureFileSinkName * create(const QString &fileName)
quint64 m_deviceCenterFrequency
Center frequency in device.
Definition: filesinkgui.h:69
int m_samplesCount
Definition: filesinkgui.h:72
int getSampleRate() const
Definition: dspcommands.h:328
QByteArray serialize() const
void setCenterFrequency(qint64 frequency)
Definition: glspectrum.cpp:175
engine is running
Definition: deviceapi.h:56
QString getName() const
Definition: filesinkgui.cpp:91
void on_interp_currentIndexChanged(int index)
virtual bool handleMessage(const Message &message)
static MsgConfigureFileSink * create(const FileSinkSettings &settings, bool force)
engine is in error
Definition: deviceapi.h:57
bool m_doApplySettings
Definition: filesinkgui.h:61
virtual qint64 getCenterFrequency() const
bool m_forceSettings
Definition: filesinkgui.h:62