STEPBYSTEP设计一个USB调试助手之十二:实现标准请求SETUP模板填充

原创 嵌入式Lee 2024-04-16 08:00

一. 前言

前面我们已经实现了控制传输并进行了测试,但是每次8字节的SETUP内容都需要手动填入,一般可能记不住需要去翻规格书,所以我们可以优化下UI,实现对于标准请求可以设定提示,根据提示进行设置。我们通过子窗口来实现,需要将子窗口中设置的SETUP返回到主窗口中。以上子窗口和主窗口的信息交互我们通过信号槽来实现。

.UI设计

2.1创建类

文件->New File... 按照如下添加WidgetForm

2.2 设计UI

Form.ui设计如下

ui文件内容如下


<ui version="4.0"> <class>Formclass> <widget class="QWidget" name="Form"> <property name="geometry"> <rect> <x>0x> <y>0y> <width>673width> <height>377height> rect> property> <property name="windowTitle"> <string>Formstring> property> <layout class="QVBoxLayout" name="verticalLayout" stretch="10,0,0,0"> <item> <layout class="QGridLayout" name="gridLayout" rowstretch="1,0,0" columnstretch="3,0,0,0,0,0,0"> <item row="1" column="4"> <widget class="QLineEdit" name="lineEdit_2"/> item> <item row="0" column="6"> <widget class="QLabel" name="label_5"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> <horstretch>0horstretch> <verstretch>0verstretch> sizepolicy> property> <property name="text"> <string>wLengthstring> property> widget> item> <item row="1" column="0"> <layout class="QGridLayout" name="gridLayout_2"> <item row="0" column="1"> <widget class="QLabel" name="label_6"> <property name="text"> <string>Typestring> property> widget> item> <item row="0" column="0"> <widget class="QLabel" name="label_7"> <property name="text"> <string>Directionstring> property> widget> item> <item row="0" column="2"> <widget class="QLabel" name="label_8"> <property name="text"> <string>Recipientstring> property> widget> item> <item row="1" column="0"> <widget class="QComboBox" name="comboBox"/> item> <item row="1" column="1"> <widget class="QComboBox" name="comboBox_3"/> item> <item row="1" column="2"> <widget class="QComboBox" name="comboBox_4"/> item> layout> item> <item row="0" column="1"> <widget class="QLabel" name="label_2"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> <horstretch>0horstretch> <verstretch>0verstretch> sizepolicy> property> <property name="text"> <string>bRequeststring> property> widget> item> <item row="0" column="2"> <widget class="QLabel" name="label_3"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> <horstretch>0horstretch> <verstretch>0verstretch> sizepolicy> property> <property name="text"> <string>wValue_Lstring> property> widget> item> <item row="1" column="2"> <widget class="QLineEdit" name="lineEdit"/> item> <item row="0" column="4"> <widget class="QLabel" name="label_4"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> <horstretch>0horstretch> <verstretch>0verstretch> sizepolicy> property> <property name="text"> <string>wIndex_Lstring> property> widget> item> <item row="0" column="3"> <widget class="QLabel" name="label_9"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> <horstretch>0horstretch> <verstretch>0verstretch> sizepolicy> property> <property name="text"> <string>wValue_Hstring> property> widget> item> <item row="0" column="0"> <widget class="QLabel" name="label"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> <horstretch>0horstretch> <verstretch>0verstretch> sizepolicy> property> <property name="text"> <string>bmRequestTypestring> property> widget> item> <item row="1" column="6"> <widget class="QLineEdit" name="lineEdit_3"/> item> <item row="0" column="5"> <widget class="QLabel" name="label_10"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> <horstretch>0horstretch> <verstretch>0verstretch> sizepolicy> property> <property name="text"> <string>wIndex_Hstring> property> widget> item> <item row="1" column="1"> <widget class="QComboBox" name="comboBox_2"/> item> <item row="1" column="5"> <widget class="QLineEdit" name="lineEdit_5"/> item> <item row="1" column="3"> <widget class="QLineEdit" name="lineEdit_4"/> item> layout> item> <item> <widget class="QLabel" name="label_11"> <property name="text"> <string>提示string> property> widget> item> <item> <widget class="QTextEdit" name="textEdit"/> item> <item> <widget class="QPushButton" name="pushButton"> <property name="text"> <string>确认string> property> widget> item> layout> widget> <resources/> <connections/>ui>

.交互

3.1 信号槽实现子窗口返回数据到主窗口

Form.h

类中添加信号函数

signals:void sendData(QString data);

Form.cpp中添加确认按键处理,发送信号数据

void Form::on_pushButton_clicked(){    QString str = "800600020000FE00";
QByteArray setup_data; setup_data.resize(8); uint8_t Direction = ui->comboBox->currentIndex(); uint8_t Type = ui->comboBox_3->currentIndex(); uint8_t Recipient = ui->comboBox_4->currentIndex(); uint8_t bRequest = ui->comboBox_2->currentIndex(); uint8_t wValue_L = ui->lineEdit->text().toUInt(); uint8_t wValue_H = ui->lineEdit_4->text().toUInt(); uint8_t wIndex_L = ui->lineEdit_2->text().toUInt(); uint8_t wIndex_H = ui->lineEdit_5->text().toUInt(); uint16_t wLength = ui->lineEdit_3->text().toUInt();
setup_data[0] = (uint8_t)(Direction<<7) | (uint8_t)(Type<<4) | (uint8_t)(Recipient<<0); setup_data[1] = bRequest; setup_data[2] = wValue_L; setup_data[3] = wValue_H; setup_data[4] = wIndex_L; setup_data[5] = wIndex_H; setup_data[6] = wLength & 0xFF; setup_data[7] = (wLength>>8) & 0xFF;
str = ByteArrayToHexString(setup_data); emit sendData(str); this->close();}

主窗口类中添加成员

QWidget *setupform;

添加信号槽

private slots:    void reshow_setup(QString);

主窗口构造函数处,new Form实例,链接信号和槽

    setupform = new Form;connect(setupform,SIGNAL(sendData(QString)),this,SLOT(reshow_setup(QString)));

主窗口实现槽处理

void MainWindow::reshow_setup(QString str){    this->show();    ui->textEdit_5->setText(str);}

3.2 子窗口初始化

form.cpp

构造函数初始化如下,设置默认参数

Form::Form(QWidget *parent)    : QWidget(parent)    , ui(new Ui::Form){    ui->setupUi(this);
ui->comboBox->clear(); ui->comboBox->addItems(QStringList("0=Host-to-device")); ui->comboBox->addItems(QStringList("1=Device-to-host")); ui->comboBox->setCurrentIndex(1);
ui->comboBox_3->clear(); ui->comboBox_3->addItems(QStringList("0=Standard")); ui->comboBox_3->addItems(QStringList("1=Class")); ui->comboBox_3->addItems(QStringList("2=Vendor")); ui->comboBox_3->addItems(QStringList("3=Reserved")); ui->comboBox_3->setCurrentIndex(0);
ui->comboBox_4->clear(); ui->comboBox_4->addItems(QStringList("0=Device")); ui->comboBox_4->addItems(QStringList("1=Interface")); ui->comboBox_4->addItems(QStringList("2=Endpoint")); ui->comboBox_4->addItems(QStringList("3=Other")); ui->comboBox_4->setCurrentIndex(0);
ui->comboBox_2->clear(); ui->comboBox_2->addItems(QStringList("0=GET_STATUS")); ui->comboBox_2->addItems(QStringList("1=CLEAR_FEATURE")); ui->comboBox_2->addItems(QStringList("2=Reserved")); ui->comboBox_2->addItems(QStringList("3=SET_FEATURE")); ui->comboBox_2->addItems(QStringList("4=Reserved")); ui->comboBox_2->addItems(QStringList("5=SET_ADDRESS")); ui->comboBox_2->addItems(QStringList("6=GET_DESCRIPTOR")); ui->comboBox_2->addItems(QStringList("7=SET_DESCRIPTOR")); ui->comboBox_2->addItems(QStringList("8=GET_CONFIGURATION")); ui->comboBox_2->addItems(QStringList("9=SET_CONFIGURATION")); ui->comboBox_2->addItems(QStringList("10=GET_INTERFACE")); ui->comboBox_2->addItems(QStringList("11=SET_INTERFACE")); ui->comboBox_2->addItems(QStringList("12=SYNCH_FRAME")); ui->comboBox_2->setCurrentIndex(6);
ui->textEdit->setText(QString("wValue_L:填描述符索引\n")+ QString("wValue_H:填描述符类型\n")+ QString("DEVICE=1,CONFIGURATION=2,STRING=3,INTERFACE=4,ENDPOINT=5,DEVICE_QUALIFIER=6,OTHER_SPEED_CONFIGURATION=7,INTERFACE_POWER=8\n")+ QString("wIndex:填0/语言ID(04 09)\n")+ QString("wLength:填描述符长度")); ui->lineEdit_3->setText("255");
ui->lineEdit->setText("0"); ui->lineEdit_4->setText("0"); ui->lineEdit_2->setText("0"); ui->lineEdit_5->setText("0"); ui->lineEdit_3->setText("255");}

3.3 setup自动设置

bRequest为准进行解析

void Form::on_comboBox_2_activated(int index){    //uint8_t bRequest = ui->comboBox_2->currentIndex();    switch(index)    {    case 0:        /* GET_STATUS */        ui->comboBox->setCurrentIndex(1);        ui->textEdit->setText("wIndex_L:填0/接口号/端点号");        ui->lineEdit_3->setText("2");    break;    case 1:        /* CLEAR_FEATURE */        ui->comboBox->setCurrentIndex(0);        ui->comboBox_3->setCurrentIndex(0);        ui->textEdit->setText(QString("wIndex_L:填0/接口号/端点号\n")+                              QString("wValue_L:\n")+                              QString("ENDPOINT_HALT=0(Recipient:Endpoint),\n")+                              QString("DEVICE_REMOTE_WAKEUP=1(Recipient:Device),\n")+                              QString("TEST_MODE=2(Recipient:Device)"));        ui->lineEdit_3->setText("0");    break;    case 3:        /* SET_FEATURE */        ui->comboBox->setCurrentIndex(0);        ui->comboBox_3->setCurrentIndex(0);        ui->textEdit->setText(QString("wIndex_L:填0/接口号/端点号\n")+                              QString("wValue_L:")+                              QString("ENDPOINT_HALT=0(Recipient:Endpoint),\n")+                              QString("DEVICE_REMOTE_WAKEUP=1(Recipient:Device),\n")+                              QString("TEST_MODE=2(Recipient:Device)"));        ui->lineEdit_3->setText("0");    break;    case 5:        /* SET_ADDRESS */        ui->comboBox->setCurrentIndex(0);        ui->comboBox_3->setCurrentIndex(0);        ui->comboBox_4->setCurrentIndex(0);        ui->textEdit->setText("wValue_L:填地址");        ui->lineEdit_3->setText("0");    break;    case 6:        /* GET_DESCRIPTOR */        ui->comboBox->setCurrentIndex(1);        ui->comboBox_3->setCurrentIndex(0);        ui->comboBox_4->setCurrentIndex(0);        ui->textEdit->setText(QString("wValue_L:填描述符索引\n")+                              QString("wValue_H:填描述符类型\n")+                              QString("DEVICE=1,CONFIGURATION=2,STRING=3,INTERFACE=4,ENDPOINT=5,DEVICE_QUALIFIER=6,OTHER_SPEED_CONFIGURATION=7,INTERFACE_POWER=8\n")+                              QString("wIndex:填0/语言ID(04 09)\n")+                              QString("wLength:填描述符长度"));        ui->lineEdit_3->setText("255");    break;    case 7:        /* SET_DESCRIPTOR */        ui->comboBox->setCurrentIndex(0);        ui->comboBox_3->setCurrentIndex(0);        ui->comboBox_4->setCurrentIndex(0);        ui->textEdit->setText(QString("wValue_L:填描述符索引\n")+                              QString("wValue_H:填描述符类型\n")+                              QString("DEVICE=1,CONFIGURATION=2,STRING=3,INTERFACE=4,ENDPOINT=5,DEVICE_QUALIFIER=6,OTHER_SPEED_CONFIGURATION=7,INTERFACE_POWER=8\n")+                              QString("wIndex:填0/语言ID(04 09)\n")+                              QString("wLength:填描述符长度"));    break;    case 8:        /* GET_CONFIGURATION*/        ui->comboBox->setCurrentIndex(1);        ui->comboBox_3->setCurrentIndex(0);        ui->comboBox_4->setCurrentIndex(0);        ui->textEdit->setText(QString("wValue:填0\n")+                              QString("wIndex:填0\n")+                              QString("wLength:填1"));        ui->lineEdit_3->setText("1");    break;    case 9:        /* SET_CONFIGURATION*/        ui->comboBox->setCurrentIndex(0);        ui->comboBox_3->setCurrentIndex(0);        ui->comboBox_4->setCurrentIndex(0);        ui->textEdit->setText(QString("wValue_L:填配置值\n")+                              QString("wIndex:填0\n")+                              QString("wLength:填0"));        ui->lineEdit_3->setText("0");    break;    case 10:        /* GET_INTERFACE */        ui->comboBox->setCurrentIndex(1);        ui->comboBox_3->setCurrentIndex(0);        ui->comboBox_4->setCurrentIndex(1);        ui->textEdit->setText(QString("wValue:填0\n")+                              QString("wIndex_L:填接口号\n")+                              QString("wLength:填1"));        ui->lineEdit_3->setText("1");    break;    case 11:        /* SET_INTERFACE */        ui->comboBox->setCurrentIndex(0);        ui->comboBox_3->setCurrentIndex(0);        ui->comboBox_4->setCurrentIndex(1);        ui->textEdit->setText(QString("wValue_L:填Alternate Setting\n")+                                      QString("wIndex_L:填接口号\n")+                                  QString("wLength:填0"));                              ui->lineEdit_3->setText("0");    break;    case 12:        /* GET_INTERFACE */        ui->comboBox->setCurrentIndex(1);        ui->comboBox_3->setCurrentIndex(0);        ui->comboBox_4->setCurrentIndex(2);        ui->textEdit->setText(QString("wValue:填0\n")+                                      QString("wIndex_L:填端点号\n")+                                  QString("wLength:填2\n")+                                  QString("Data:填2字节Frame Number"));        ui->lineEdit_3->setText("2");    break;    }}

.测试

setup设置,进入子窗口

根据提示获取设备描述符,再点击确认

点击开始获取设备描述符

测试获取配置描述符

测试获取字符串描述符

.总结

以上实现了标准请求的解析和提示,可以方便用户使用进行测试控制传输的标准请求,后面还可以继续完善除了标准请求的其他请求。


评论 (0)
  • 4月22日下午,备受瞩目的飞凌嵌入式「2025嵌入式及边缘AI技术论坛」在深圳深铁皇冠假日酒店盛大举行,此次活动邀请到了200余位嵌入式技术领域的技术专家、企业代表和工程师用户,共享嵌入式及边缘AI技术的盛宴!1、精彩纷呈的展区产品及方案展区是本场活动的第一场重头戏,从硬件产品到软件系统,从企业级应用到高校教学应用,都吸引了现场来宾的驻足观看和交流讨论。全产品矩阵展区展示了飞凌嵌入式丰富的产品线,从嵌入式板卡到工控机,从进口芯片平台到全国产平台,无不体现出飞凌嵌入式在嵌入式主控设备研发设计方面的
    飞凌嵌入式 2025-04-28 14:43 181浏览
  • 文/Leon编辑/cc孙聪颖‍2023年,厨电行业在相对平稳的市场环境中迎来温和复苏,看似为行业增长积蓄势能。带着对市场向好的预期,2024 年初,老板电器副董事长兼总经理任富佳为企业定下双位数增长目标。然而现实与预期相悖,过去一年,这家老牌厨电企业不仅未能达成业绩目标,曾提出的“三年再造一个老板电器”愿景,也因市场下行压力面临落空风险。作为“企二代”管理者,任富佳在掌舵企业穿越市场周期的过程中,正面临着前所未有的挑战。4月29日,老板电器(002508.SZ)发布了2024年年度报告及2025
    华尔街科技眼 2025-04-30 12:40 297浏览
  • 贞光科技代理品牌紫光国芯的车规级LPDDR4内存正成为智能驾驶舱的核心选择。在汽车电子国产化浪潮中,其产品以宽温域稳定工作能力、优异电磁兼容性和超长使用寿命赢得市场认可。紫光国芯不仅确保供应链安全可控,还提供专业本地技术支持。面向未来,紫光国芯正研发LPDDR5车规级产品,将以更高带宽、更低功耗支持汽车智能化发展。随着智能网联汽车的迅猛发展,智能驾驶舱作为人机交互的核心载体,对处理器和存储器的性能与可靠性提出了更高要求。在汽车电子国产化浪潮中,贞光科技代理品牌紫光国芯的车规级LPDDR4内存凭借
    贞光科技 2025-04-28 16:52 333浏览
  • 你是不是也有在公共场合被偷看手机或笔电的经验呢?科技时代下,不少现代人的各式机密数据都在手机、平板或是笔电等可携式的3C产品上处理,若是经常性地需要在公共场合使用,不管是工作上的机密文件,或是重要的个人信息等,民众都有防窃防盗意识,为了避免他人窥探内容,都会选择使用「防窥保护贴片」,以防止数据外泄。现今市面上「防窥保护贴」、「防窥片」、「屏幕防窥膜」等产品就是这种目的下产物 (以下简称防窥片)!防窥片功能与常见问题解析首先,防窥片最主要的功能就是用来防止他人窥视屏幕上的隐私信息,它是利用百叶窗的
    百佳泰测试实验室 2025-04-30 13:28 527浏览
  • 浪潮之上:智能时代的觉醒    近日参加了一场课题的答辩,这是医疗人工智能揭榜挂帅的国家项目的地区考场,参与者众多,围绕着医疗健康的主题,八仙过海各显神通,百花齐放。   中国大地正在发生着激动人心的场景:深圳前海深港人工智能算力中心高速运转的液冷服务器,武汉马路上自动驾驶出租车穿行的智慧道路,机器人参与北京的马拉松竞赛。从中央到地方,人工智能相关政策和消息如雨后春笋般不断出台,数字中国的建设图景正在智能浪潮中徐徐展开,战略布局如同围棋
    广州铁金刚 2025-04-30 15:24 279浏览
  • 一、gao效冷却与控温机制‌1、‌冷媒流动设计‌采用低压液氮(或液氦)通过毛细管路导入蒸发器,蒸汽喷射至样品腔实现快速冷却,冷却效率高(室温至80K约20分钟,至4.2K约30分钟)。通过控温仪动态调节蒸发器加热功率,结合温度传感器(如PT100铂电阻或Cernox磁场不敏感传感器),实现±0.01K的高精度温度稳定性。2、‌宽温区覆盖与扩展性‌标准温区为80K-325K,通过降压选件可将下限延伸至65K(液氮模式)或4K(液氦模式)。可选配475K高温模块,满足材料在ji端温度下的性能测试需求
    锦正茂科技 2025-04-30 13:08 434浏览
  • 文/郭楚妤编辑/cc孙聪颖‍越来越多的企业开始蚕食动力电池市场,行业“去宁王化”态势逐渐明显。随着这种趋势的加强,打开新的市场对于宁德时代而言至关重要。“我们不希望被定义为电池的制造者,而是希望把自己称作新能源产业的开拓者。”4月21日,在宁德时代举行的“超级科技日”发布会上,宁德时代掌门人曾毓群如是说。随着宁德时代核心新品骁遥双核电池的发布,其搭载的“电电增程”技术也走进业界视野。除此之外,经过近3年试水,宁德时代在换电业务上重资加码。曾毓群认为换电是一个重资产、高投入、长周期的产业,涉及的利
    华尔街科技眼 2025-04-28 21:55 208浏览
  • 随着电子元器件的快速发展,导致各种常见的贴片电阻元器件也越来越小,给我们分辨也就变得越来越难,下面就由smt贴片加工厂_安徽英特丽就来告诉大家如何分辨的SMT贴片元器件。先来看看贴片电感和贴片电容的区分:(1)看颜色(黑色)——一般黑色都是贴片电感。贴片电容只有勇于精密设备中的贴片钽电容才是黑色的,其他普通贴片电容基本都不是黑色的。(2)看型号标码——贴片电感以L开头,贴片电容以C开头。从外形是圆形初步判断应为电感,测量两端电阻为零点几欧,则为电感。(3)检测——贴片电感一般阻值小,更没有“充放
    贴片加工小安 2025-04-29 14:59 338浏览
  • 网约车,真的“饱和”了?近日,网约车市场的 “饱和” 话题再度引发热议。多地陆续发布网约车风险预警,提醒从业者谨慎入局,这背后究竟隐藏着怎样的市场现状呢?从数据来看,网约车市场的“过剩”现象已愈发明显。以东莞为例,截至2024年12月底,全市网约车数量超过5.77万辆,考取网约车驾驶员证的人数更是超过13.48万人。随着司机数量的不断攀升,订单量却未能同步增长,导致单车日均接单量和营收双双下降。2024年下半年,东莞网约出租车单车日均订单量约10.5单,而单车日均营收也不容乐
    用户1742991715177 2025-04-29 18:28 297浏览
  • 在CAN总线分析软件领域,当CANoe不再是唯一选择时,虹科PCAN-Explorer 6软件成为了一个有竞争力的解决方案。在现代工业控制和汽车领域,CAN总线分析软件的重要性不言而喻。随着技术的进步和市场需求的多样化,单一的解决方案已无法满足所有用户的需求。正是在这样的背景下,虹科PCAN-Explorer 6软件以其独特的模块化设计和灵活的功能扩展,为CAN总线分析领域带来了新的选择和可能性。本文将深入探讨虹科PCAN-Explorer 6软件如何以其创新的模块化插件策略,提供定制化的功能选
    虹科汽车智能互联 2025-04-28 16:00 237浏览
  • 在智能硬件设备趋向微型化的背景下,语音芯片方案厂商针对小体积设备开发了多款超小型语音芯片方案,其中WTV系列和WT2003H系列凭借其QFN封装设计、高性能与高集成度,成为微型设备语音方案的理想选择。以下从封装特性、功能优势及典型应用场景三个方面进行详细介绍。一、超小体积封装:QFN技术的核心优势WTV系列与WT2003H系列均提供QFN封装(如QFN32,尺寸为4×4mm),这种封装形式具有以下特点:体积紧凑:QFN封装通过减少引脚间距和优化内部结构,显著缩小芯片体积,适用于智能门铃、穿戴设备
    广州唯创电子 2025-04-30 09:02 335浏览
我要评论
0
0
点击右上角,分享到朋友圈 我知道啦
请使用浏览器分享功能 我知道啦