提交 477c1669 编写于 作者: D dev

c++ unit ok

上级 dbb467e9
......@@ -411,8 +411,9 @@ void specWidget::initRx()
return;
//保存文件
m_strFolder = ui->lineEdit_folder->text();
m_rx_points = 0;
save_count = 0;
m_bSaveToFile = ui->checkBox_save->isChecked();
double dfreq = ui->doubleSpinBox_center->value();
double spr = ui->doubleSpinBox_spr->value();
......@@ -490,10 +491,11 @@ void specWidget::initTx()
});
read_count = m_rx_bufsz/2;
m_tx_points = 0;
//读取文件
m_strFolder = ui->lineEdit_folder_play->text();
m_strFolderPlay = ui->lineEdit_folder_play->text();
QDir cdir(m_strFolder);
QDir cdir(m_strFolderPlay);
QStringList lst_filter;
lst_filter << "*.pcm";
QFileInfoList lstFiles = cdir.entryInfoList(lst_filter,QDir::Files|QDir::Readable,QDir::Name);
......@@ -537,7 +539,7 @@ void specWidget::initTx()
if (new_begin < batchread)
memcpy(m_data_iq_tx, &m_data_iq_tx[m_tx_bufsz],sizeof(short)*2*new_begin);
if (read_count < batchread )
if (real_size < batchread )
{
fIn.close();
++currfile;
......@@ -655,7 +657,7 @@ void specWidget::timerEvent(QTimerEvent * e)
}
else
{
size_t he = m_rx_points - save_count;
int he = m_rx_points - save_count;
ui->lcdNumber_saveBehind->display((double)he);
......@@ -766,7 +768,7 @@ void specWidget::on_spinBox_bw_valueChanged(int arg1)
void specWidget::on_toolButton_br_play_clicked()
{
QString str = QFileDialog::getExistingDirectory(this,tr("Input from"),ui->lineEdit_folder->text());
QString str = QFileDialog::getExistingDirectory(this,tr("Input from"),ui->lineEdit_folder_play->text());
if (str.length())
ui->lineEdit_folder_play->setText(str);
}
......
......@@ -153,6 +153,7 @@ private:
std::atomic<bool> m_bSaveToFile;
std::atomic<bool> m_bPlayFromFile;
QString m_strFolder;
QString m_strFolderPlay;
//stdout reader
stdout_watcher * watcher = nullptr;
};
......
......@@ -242,7 +242,7 @@
<x>0</x>
<y>0</y>
<width>320</width>
<height>504</height>
<height>495</height>
</rect>
</property>
<attribute name="label">
......@@ -267,6 +267,9 @@
<property name="maximum">
<double>102400.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
<property name="value">
<double>1200.000000000000000</double>
</property>
......@@ -397,6 +400,9 @@
<property name="maximum">
<double>102400.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
<property name="value">
<double>1200.000000000000000</double>
</property>
......@@ -498,7 +504,7 @@
<x>0</x>
<y>0</y>
<width>320</width>
<height>504</height>
<height>495</height>
</rect>
</property>
<attribute name="label">
......@@ -662,7 +668,7 @@
<x>0</x>
<y>0</y>
<width>320</width>
<height>504</height>
<height>495</height>
</rect>
</property>
<attribute name="label">
......
......@@ -40,6 +40,7 @@ uhd_device::uhd_device()
,m_rx_points(0)
{
m_data_iq_rx = new short [m_rx_bufsz+1024*1024][2]{{0,0}};
m_data_iq_tx = new short [m_tx_bufsz+1024*1024][2]{{0,0}};
}
uhd_device::uhd_device(const std::string &args)
......@@ -50,6 +51,7 @@ uhd_device::uhd_device(const std::string &args)
{
m_data_iq_rx = new short [m_rx_bufsz+1024*1024][2]{{0,0}};
m_data_iq_tx = new short [m_tx_bufsz+1024*1024][2]{{0,0}};
}
uhd_device::~uhd_device()
{
......@@ -60,7 +62,7 @@ uhd_device::~uhd_device()
}
delete[] m_data_iq_rx;
delete[] m_data_iq_tx;
}
......@@ -136,6 +138,7 @@ void uhd_device::run_RxIO()
stream_args_rx.channels.push_back(m_rx_channel);
rx_streamer::sptr rx_stream = usrp->get_rx_stream(stream_args_rx);
memset (m_data_iq_rx,0,m_rx_bufsz*sizeof(m_data_iq_rx[0]));
m_rx_points = 0;
//接收线程
auto thcall_rx = [&]()->void{
......@@ -146,7 +149,8 @@ void uhd_device::run_RxIO()
stream_cmd.time_spec = uhd::time_spec_t();
m_rx_streaming = true;
rx_stream->issue_stream_cmd(stream_cmd);
while (!stop_signal_called)
{
try {
while (!stop_signal_called)
{
......@@ -177,11 +181,12 @@ void uhd_device::run_RxIO()
}
} catch (...) {
stop_signal_called = true;
//stop_signal_called = true;
}
}
stream_cmd.stream_now = false;
rx_stream->issue_stream_cmd(stream_cmd);
m_rx_streaming = false;
stream_cmd.stream_now = false;
rx_stream->issue_stream_cmd(stream_cmd);
m_rx_streaming = false;
};
//启动线程
uhd_io_thread * rx_thread = new uhd_io_thread(thcall_rx,0);
......@@ -229,27 +234,79 @@ void uhd_device::set_rx_atn(const std::string & atn)
double uhd_device::set_rx_gain(double gain)
{
if (usrp)
{
usrp->set_rx_gain(gain,m_rx_channel);
return usrp->get_rx_gain(m_rx_channel);
return usrp->get_rx_gain(m_rx_channel);
}
return gain;
}
double uhd_device::set_rx_bandwidth(double bw)
{
if (usrp && bw>=200000)
if (usrp)
{
double srate = usrp->get_rx_rate(m_rx_channel);
fprintf(stderr, "Current RX Rate: %f...\n", srate);
if (bw < 200000 || bw >=srate)
bw = srate;
usrp->set_rx_bandwidth(bw,m_rx_channel);
bw = usrp->get_rx_bandwidth(m_rx_channel);
}
else if (usrp )
{
usrp->set_rx_bandwidth(usrp->get_rx_rate(m_rx_channel),m_rx_channel);
bw = usrp->get_rx_bandwidth(m_rx_channel);
}
return bw;
}
void uhd_device::run_TxIO()
{
//创建流对象实例
uhd::stream_args_t stream_args_tx("sc16", "sc16");
stream_args_tx.channels.push_back(m_tx_channel);
tx_streamer::sptr tx_stream = usrp->get_tx_stream(stream_args_tx);
m_tx_points = 0;
memset (m_data_iq_tx,0,m_tx_bufsz*sizeof(m_data_iq_tx[0]));
//发射线程
auto thcall_tx = [&]()->void{
uhd::tx_metadata_t md_tx;
m_tx_streaming = true;
md_tx.has_time_spec = false;
md_tx.start_of_burst = false;
md_tx.end_of_burst = false;
while (!stop_signal_called)
{
try {
while (!stop_signal_called)
{
const size_t off = m_tx_points % m_tx_bufsz;
const size_t new_begin = (m_tx_points +m_txblock_size ) % m_tx_bufsz;
if (new_begin < m_txblock_size)
memcpy(&m_data_iq_tx[m_tx_bufsz], m_data_iq_tx, sizeof(short)*2*new_begin);
const void * addr = (void *)m_data_iq_tx[off];
size_t sent = tx_stream->send(addr, m_txblock_size,md_tx, 1);
m_tx_points += sent;
}
} catch (...) {
//stop_signal_called = true;
}
QThread::msleep(10);
}
m_tx_streaming = false;
};
//启动线程
uhd_io_thread * tx_thread = new uhd_io_thread(thcall_tx,0);
tx_thread->start(QThread::TimeCriticalPriority);
//主线程不断打印状态
while (!stop_signal_called)
{
std::this_thread::sleep_for(std::chrono::milliseconds(400));
}
//退出
tx_thread->wait();
tx_thread->deleteLater();
}
quint64 uhd_device::set_tx_freq(const quint64 freq_in_hz)
{
if (usrp)
......@@ -277,8 +334,11 @@ double uhd_device::set_tx_rate(const double sprate)
double uhd_device::set_tx_gain(double gain)
{
if (usrp)
{
usrp->set_tx_gain(gain,m_tx_channel);
return usrp->get_tx_gain(m_tx_channel);
return usrp->get_tx_gain(m_tx_channel);
}
return gain;
}
double uhd_device::set_tx_bandwidth(double bw)
......
......@@ -38,20 +38,26 @@ public:
bool open_device();
bool close_device();
void run_RxIO();
void run_TxIO();
protected:
std::atomic<bool> stop_signal_called;
std::atomic<bool> m_rx_streaming;
std::atomic<bool> m_tx_streaming;
std::string m_dev_args;
size_t m_rxblock_size = 10000;
size_t m_txblock_size = 10000;
uhd::usrp::multi_usrp::sptr usrp;
size_t m_rx_channel = 0;
size_t m_tx_channel = 0;
protected:
//初始化队列
short (*m_data_iq_rx)[2] = nullptr;
size_t m_rx_bufsz = 1024*1024*16;
short (*m_data_iq_tx)[2] = nullptr;
size_t m_rx_bufsz = 1024*1024*4;
size_t m_tx_bufsz = 1024*1024*4;
//收发计数
unsigned long long m_rx_points = 0;
unsigned long long m_tx_points = 0;
public:
quint64 set_rx_freq(const quint64 freq_in_hz);
double set_rx_rate(const double sprate);
......
......@@ -160,7 +160,7 @@ void uhd_device::run_RxIO()
uhd_rx_streamer_handle rx_streamer = 0;
uhd_rx_metadata_handle rx_meta = 0;
memset (m_data_iq_rx,0,m_rx_bufsz*sizeof(m_data_iq_rx[0]));
m_rx_points = 0;
//接收线程
auto thcall_rx = [&]()->void{
......@@ -345,7 +345,7 @@ void uhd_device::run_TxIO()
uhd_tx_streamer_handle tx_streamer = 0;
uhd_tx_metadata_handle tx_meta = 0;
memset (m_data_iq_tx,0,m_tx_bufsz*sizeof(m_data_iq_tx[0]));
m_tx_points = 0;
//发射线程
auto thcall_tx = [&]()->void{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册