QT實現批量配置
需求
- 一些參數需要批量化配置
- 之前搭建的FPGA的寄存器控制模型
- 使用AXI-lite搭建
- 直接操作上位機
- 這里需要一個可以快速配置所有參數的上位機
- 需要保存文件,可以保留上一次的參數
直接實現
- 使用輸入框復制,每個輸入框配置一個下載按鈕
- 加載的時間很長,且實現繁瑣
- 需要不斷地拖動UI控件
表格實現
- 將參數直接制作成表格
- 在表格中完成參數地控制
- 參數直接全部丟給ARM,UDP的寬度足以支撐這個參數同時更新

實現步驟
- 庫文件直接同名導入頭文件
#include "fpga_subs.h"
#include "ui_fpga_subs.h"
#include <QFile>
#include <QFileInfo>
#include <QDebug>
#include <QTableWidgetItem>
fpga_subs::fpga_subs(QWidget *parent) :
QWidget(parent),
ui(new Ui::fpga_subs)
{
ui->setupUi(this);
//QRegExp regx("[A-Fa-f0-9]{4}");
//QValidator *validator = new QRegExpValidator(regx, ui->lineEdit);
//ui->lineEdit->setValidator(validator);
table = new QTableWidget(row,column+1,this);
ui->ui_table_layout->addWidget(table);
table->resize(900,350);
QStringList head_lab;
head_lab << "0x0000" << "0x0001" << "0x0002" << "0x0003" << "note";
table->setHorizontalHeaderLabels(head_lab);
QStringList column_lab;
for(int i = 0; i < row * column; i=i+4)
{
column_lab << QString::number(i);
table->setVerticalHeaderLabels(column_lab);
}
}
fpga_subs::~fpga_subs()
{
delete ui;
}
void fpga_subs::update_file_path(QList<QString> p_list)
{
p_fpga_file = p_list[P_FPGA_FILE]; //path update
on_ui_rd_param_clicked(); //update chart
}
void fpga_subs::on_ui_rd_param_clicked()
{
QString pns_ini;
pns_ini = p_fpga_file + "fpga_ini.dat";
QFile f(pns_ini);
QFileInfo fi(pns_ini);
qDebug() << pns_ini;
if(!fi.exists())
{
QString info = "no file " + pns_ini + " to read";
emit info_trig(0,CODE_FPGA_SET,"error",info);
return;
}
f.open(QIODevice::ReadOnly | QIODevice::Text);
l_fpga_set.clear();
for(int j = 0; j < row * column; j++)
{
l_fpga_set.append("0");
}
int i = 0;
while(!f.atEnd() && i < row * column)
{
QByteArray b_line = f.readLine();
QString s_line(b_line);
s_line.remove("\n");
l_fpga_set.replace(i,s_line);
i ++;
}
f.close();
qDebug() << l_fpga_set;
for(int i = 0; i <row;i++)
{
for(int j = 0; j < column; j++)
{
//table->item(i,j)->setText(l_fpga_set[i*4+j]);
QTableWidgetItem *item = new QTableWidgetItem;
item->setText(l_fpga_set[i*4+j]);
table->setItem(i,j,item);
//delete item;
}
}
}
void fpga_subs::on_ui_wr_param_clicked()
{
l_fpga_set.clear();
for(int i = 0; i <row;i++)
{
for(int j = 0; j < column; j++)
{
//table->item(i,j)->setText(l_fpga_set[i*4+j]);
QTableWidgetItem *item_rd = new QTableWidgetItem;
item_rd = table->item(i,j);
if(item_rd == NULL)
{
l_fpga_set.append("0");
}
else
{
l_fpga_set.append(item_rd->text());
}
}
}
//write file
QString pns_ini;
pns_ini = p_fpga_file + "fpga_ini.dat";
QFile f(pns_ini);
f.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream f_out(&f);
f.seek(0);
for(int i = 0; i < row * column; i++)
{
f_out << l_fpga_set[i] << "\n";
}
f.close();
}
效果
- 直接將表格的數據和文件連接
- 配置的參數保存在文件中
- 后續將寫入部分直接發送信號UDP模塊就可以實現實際配置到FPGA
======== ======\\ ======= -
|| || \\ // \\ /-\
|| || || // // \\
|| || // || // \\
====== ======= || === ========
|| || || \\ // \\
|| || \\ || // \\
|| || \\ // // \\
|| || ======= // \\
作者:綠葉落秋風,專注FPGA技術分析和分享,轉載請注明原文鏈接:http://www.rzrgm.cn/electricdream/p/17507493.html,文中資源鏈接如下:
1. GITHUB開源倉庫
浙公網安備 33010602011771號