QT实现参数批量配置

Posted on 2023-06-26 23:46  绿叶落秋风  阅读(118)  评论(0编辑  收藏  举报

QT实现批量配置

需求

  • 一些参数需要批量化配置
  • 之前搭建的FPGA的寄存器控制模型
    • 使用AXI-lite搭建
    • 直接操作上位机
  • 这里需要一个可以快速配置所有参数的上位机
  • 需要保存文件,可以保留上一次的参数

直接实现

  • 使用输入框复制,每个输入框配置一个下载按钮
  • 加载的时间很长,且实现繁琐
    • 需要不断地拖动UI控件

表格实现

  • 将参数直接制作成表格
  • 在表格中完成参数地控制
  • 参数直接全部丢给ARM,UDP的宽度足以支撑这个参数同时更新

img

实现步骤

  • 库文件直接同名导入头文件
#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