Skip to content

Commit

Permalink
Implement user selectable I/Q file location.
Browse files Browse the repository at this point in the history
The user can now select where to store raw I/Q files ($HOME by default).
  • Loading branch information
csete committed Aug 4, 2014
1 parent c4868f5 commit 17dda92
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 17 deletions.
8 changes: 5 additions & 3 deletions applications/gqrx/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ MainWindow::MainWindow(const QString cfgfile, bool edit_conf, QWidget *parent) :
connect(uiDockFft, SIGNAL(peakDetectionToggled(bool)), this, SLOT(setPeakDetection(bool)));

// I/Q playback
connect(iq_tool, SIGNAL(startRecording()), this, SLOT(startIqRecording()));
connect(iq_tool, SIGNAL(startRecording(QString)), this, SLOT(startIqRecording(QString)));
connect(iq_tool, SIGNAL(stopRecording()), this, SLOT(stopIqRecording()));
connect(iq_tool, SIGNAL(startPlayback(QString,float)), this, SLOT(startIqPlayback(QString,float)));
connect(iq_tool, SIGNAL(stopPlayback()), this, SLOT(stopIqPlayback()));
Expand Down Expand Up @@ -438,6 +438,7 @@ bool MainWindow::loadConfig(const QString cfgfile, bool check_crash)
setNewFrequency(ui->freqCtrl->getFrequency()); // ensure all GUI and RF is updated

remote->readSettings(m_settings);
iq_tool->readSettings(m_settings);

return conf_ok;
}
Expand Down Expand Up @@ -510,6 +511,7 @@ void MainWindow::storeSession()
uiDockAudio->saveSettings(m_settings);

remote->saveSettings(m_settings);
iq_tool->saveSettings(m_settings);
}
}

Expand Down Expand Up @@ -1275,15 +1277,15 @@ void MainWindow::stopAudioStreaming()
}

/*! \brief Start I/Q recording. */
void MainWindow::startIqRecording()
void MainWindow::startIqRecording(const QString recdir)
{
qDebug() << __func__;
// generate file name using date, time, rf freq in kHz and BW in Hz
// gqrx_iq_yyyymmdd_hhmmss_freq_bw_fc.raw
qint64 freq = ui->freqCtrl->getFrequency();
qint64 sr = (qint64)(rx->get_input_rate());
QString lastRec = QDateTime::currentDateTimeUtc().
toString("gqrx_yyyyMMdd_hhmmss_%1_%2_fc.'raw'").arg(freq).arg(sr);
toString("%1/gqrx_yyyyMMdd_hhmmss_%2_%3_fc.'raw'").arg(recdir).arg(freq).arg(sr);

// start recorder; fails if recording already in progress
if (rx->start_iq_recording(lastRec.toStdString()))
Expand Down
2 changes: 1 addition & 1 deletion applications/gqrx/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private slots:
void stopAudioStreaming();

/* I/Q playback and recording*/
void startIqRecording();
void startIqRecording(const QString recdir);
void stopIqRecording();
void startIqPlayback(const QString filename, float samprate);
void stopIqPlayback();
Expand Down
72 changes: 67 additions & 5 deletions qtgui/iq_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
*/
#include <QMessageBox>
#include <QDebug>
#include <QFileDialog>
#include <QFileInfo>
#include <QDir>
#include <QPalette>
#include <QString>
#include <QStringList>
#include <QTime>
Expand All @@ -47,9 +49,12 @@ CIqTool::CIqTool(QWidget *parent) :
rec_len = 0;
plot_spp = 1;

ui->locationEntry->setText(QDir::currentPath());
//ui->recDirEdit->setText(QDir::currentPath());

recdir = new QDir("", "*.raw");
recdir = new QDir(QDir::homePath(), "*.raw");

error_palette = new QPalette();
error_palette->setColor(QPalette::Text, Qt::red);

timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(timeoutFunction()));
Expand All @@ -61,6 +66,7 @@ CIqTool::~CIqTool()
delete timer;
delete ui;
delete recdir;
delete error_palette;

}

Expand Down Expand Up @@ -171,8 +177,6 @@ void CIqTool::on_plotButton_clicked()
QFile *file = new QFile(recdir->filePath(current_file));
if (!file->open(QIODevice::ReadOnly))
{
qDebug() << "Error opening file???";

return;
}

Expand Down Expand Up @@ -240,7 +244,7 @@ void CIqTool::on_recButton_clicked(bool checked)
{
ui->playButton->setEnabled(false);
//ui->plotButton->setEnabled(false);
emit startRecording();
emit startRecording(recdir->path());

refreshDir();
ui->listWidget->setCurrentRow(ui->listWidget->count()-1);
Expand Down Expand Up @@ -290,6 +294,64 @@ void CIqTool::showEvent(QShowEvent * event)
timer->start(1000);
}


void CIqTool::saveSettings(QSettings *settings)
{
if (!settings)
return;

// Location of baseband recordings
QString dir = recdir->path();
if (dir != QDir::homePath())
settings->setValue("baseband/rec_dir", dir);
else
settings->remove("baseband/rec_dir");

}

void CIqTool::readSettings(QSettings *settings)
{
if (!settings)
return;

// Location of baseband recordings
QString dir = settings->value("baseband/rec_dir", QDir::homePath()).toString();
ui->recDirEdit->setText(dir);
}


/*! \brief Slot called when the recordings directory has changed either
* because of user input or programmatically.
*/
void CIqTool::on_recDirEdit_textChanged(const QString &dir)
{
if (recdir->exists(dir))
{
ui->recDirEdit->setPalette(QPalette()); // Clear custom color
recdir->setPath(dir);
recdir->cd(dir);
//emit newRecDirSelected(dir);
}
else
{
ui->recDirEdit->setPalette(*error_palette); // indicate error
}
}

/*! \brief Slot called when the user clicks on the "Select" button. */
void CIqTool::on_recDirButton_clicked()
{
QString dir = QFileDialog::getExistingDirectory(this, tr("Select a directory"),
ui->recDirEdit->text(),
QFileDialog::ShowDirsOnly |
QFileDialog::DontResolveSymlinks);

if (!dir.isNull())
ui->recDirEdit->setText(dir);
}



void CIqTool::timeoutFunction(void)
{
refreshDir();
Expand Down
14 changes: 11 additions & 3 deletions qtgui/iq_tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <QCloseEvent>
#include <QDialog>
#include <QDir>
#include <QPalette>
#include <QSettings>
#include <QShowEvent>
#include <QString>
#include <QTimer>
Expand Down Expand Up @@ -56,8 +58,11 @@ class CIqTool : public QDialog
void closeEvent(QCloseEvent *event);
void showEvent(QShowEvent * event);

void saveSettings(QSettings *settings);
void readSettings(QSettings *settings);

signals:
void startRecording();
void startRecording(const QString recdir);
void stopRecording();
void startPlayback(const QString filename, float samprate);
void stopPlayback();
Expand All @@ -68,6 +73,8 @@ public slots:
void cancelPlayback();

private slots:
void on_recDirEdit_textChanged(const QString &text);
void on_recDirButton_clicked();
void on_recButton_clicked(bool checked);
void on_playButton_clicked(bool checked);
void on_plotButton_clicked();
Expand All @@ -84,8 +91,9 @@ private slots:
private:
Ui::CIqTool *ui;

QDir *recdir;
QTimer *timer;
QDir *recdir;
QTimer *timer;
QPalette *error_palette; /*!< Palette used to indicate an error. */

QString current_file; /*!< Selected file in file browser. */

Expand Down
10 changes: 5 additions & 5 deletions qtgui/iq_tool.ui
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,26 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="locationLabel">
<widget class="QLabel" name="recDirLabel">
<property name="text">
<string>Location:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="locationEntry">
<widget class="QLineEdit" name="recDirEdit">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="toolTip">
<string>Enter a different location or use the select button</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="locationButton">
<widget class="QPushButton" name="recDirButton">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
Expand Down

0 comments on commit 17dda92

Please sign in to comment.