160 lines
4.9 KiB
C++
160 lines
4.9 KiB
C++
#include "mainwindow.h"
|
|
#include "./ui_mainwindow.h"
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
: QMainWindow(parent)
|
|
, ui(new Ui::MainWindow)
|
|
{
|
|
ui->setupUi(this);
|
|
uh = new UsbHandler(this);
|
|
|
|
connect(uh,&UsbHandler::productListUpdate,this,&MainWindow::comboxUpdate);
|
|
connect(uh,&UsbHandler::errorOccurred,this,&MainWindow::onLogPrint);
|
|
connect(uh,&UsbHandler::interfaceListUpdate,this,&MainWindow::comboxUpdate_interface);
|
|
connect(uh,&UsbHandler::endPointListUpdate,this,&MainWindow::comboxUpdate_endpoint);
|
|
}
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void MainWindow::on_pushButton_clicked()
|
|
{
|
|
uh->listDevices();
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::comboxUpdate(QMap<int, QString> *__productList){
|
|
ui->comboBox->clear();;
|
|
LOG_DEBUG("list length is %d",__productList->size());
|
|
QMap<int,QString>::iterator it;
|
|
for(it=__productList->begin();it!=__productList->end();it++){
|
|
ui->comboBox->addItem(QString::number(it.key())+":"+it.value());
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_pushButton_6_clicked()
|
|
{
|
|
QString tmp = ui->comboBox->currentText();
|
|
uh->openDevice(tmp.at(0).digitValue());
|
|
LOG_DEBUG("try to open device,index is %d",tmp.at(0).digitValue());
|
|
uh->listInterfaces(tmp.at(0).digitValue());
|
|
}
|
|
|
|
|
|
void MainWindow::onLogPrint(QString err){
|
|
QDateTime cur = QDateTime::currentDateTime();
|
|
QString tmp =cur.toString("yyyy-MM-dd HH:mm:ss");
|
|
ui->textBrowser->append(tmp+" --> "+err);
|
|
}
|
|
|
|
void MainWindow::on_pushButton_7_clicked()
|
|
{
|
|
uh->closeDevice();
|
|
}
|
|
|
|
|
|
void MainWindow::comboxUpdate_interface(QMap<int, QString> *__interfaceList){
|
|
ui->comboBox_2->clear();
|
|
LOG_DEBUG("list length is %d",__interfaceList->size());
|
|
QMap<int,QString>::iterator it;
|
|
for(it=__interfaceList->begin();it!=__interfaceList->end();it++){
|
|
ui->comboBox_2->addItem(QString::number(it.key())+":"+it.value());
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_pushButton_2_clicked()
|
|
{
|
|
LOG_DEBUG("Defalut: Acquire device description");
|
|
unsigned char *data =new unsigned char [18];
|
|
memset(data,0,18);
|
|
uh->sendControlTransfer(0x80,0x06,0x0100,0x0000,data,18);
|
|
for(int i=0;i<18;i++){
|
|
LOG_DEBUG("data[%d] is 0x%x",i,data[i]);
|
|
}
|
|
}
|
|
|
|
|
|
void MainWindow::comboxUpdate_endpoint(QMap<int, QString> *__endPointList){
|
|
ui->comboBox_3->clear();
|
|
LOG_DEBUG("list length is %d",__endPointList->size());
|
|
QMap<int,QString>::iterator it;
|
|
for(it=__endPointList->begin();it!=__endPointList->end();it++){
|
|
ui->comboBox_3->addItem(QString::number(it.key())+":"+it.value());
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_pushButton_8_clicked()
|
|
{
|
|
QString tmp = ui->comboBox->currentText();
|
|
int deviceIdx = tmp.at(0).digitValue();
|
|
tmp = ui->comboBox_2->currentText();
|
|
int interfaceIdx = tmp.at(0).digitValue();
|
|
uh->listInterfaceEndpoints(deviceIdx,interfaceIdx);
|
|
}
|
|
|
|
|
|
void MainWindow::on_pushButton_4_clicked()
|
|
{
|
|
QString tmp = ui->comboBox_3->currentText();
|
|
QRegularExpression regex("0x[0-9A-Fa-f]+"); // 匹配以 "0x" 开头的16进制数
|
|
QRegularExpressionMatch match = regex.match(tmp);
|
|
QString endpointAddress = match.captured(0); // 获取第一个匹配的结果
|
|
uint8_t endpointValue = endpointAddress.mid(2).toUInt(NULL, 16); // 16 表示十六进制
|
|
|
|
|
|
|
|
tmp = ui->comboBox_2->currentText();
|
|
QRegularExpression interfaceRegex("Interface #\\[(\\d+)\\]");
|
|
QRegularExpressionMatch interfaceMatch = interfaceRegex.match(tmp);
|
|
int interface = interfaceMatch.captured(1).toInt();
|
|
|
|
uint8_t* data =reinterpret_cast<uint8_t*>(ui->textEdit->toPlainText().toUtf8().data());
|
|
// uint8_t data=ui->textEdit->toPlainText().toUInt();
|
|
int len = ui->textEdit->toPlainText().length();
|
|
for(int i=0;i<len;i++){
|
|
LOG_DEBUG("Send data is 0x%x",data[i]);
|
|
}
|
|
if(uh->sendBulkTransfer(endpointValue,data,len,interface)){
|
|
LOG_DEBUG("Send endPoint 0x%x via BulkTransfer success.",endpointValue);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
void MainWindow::on_pushButton_3_clicked()
|
|
{
|
|
QString tmp = ui->comboBox_3->currentText();
|
|
QRegularExpression regex("0x[0-9A-Fa-f]+"); // 匹配以 "0x" 开头的16进制数
|
|
QRegularExpressionMatch match = regex.match(tmp);
|
|
QString endpointAddress = match.captured(0); // 获取第一个匹配的结果
|
|
uint8_t endpointValue = endpointAddress.mid(2).toUInt(NULL, 16); // 16 表示十六进制
|
|
|
|
|
|
tmp = ui->comboBox_2->currentText();
|
|
QRegularExpression interfaceRegex("Interface #\\[(\\d+)\\]");
|
|
QRegularExpressionMatch interfaceMatch = interfaceRegex.match(tmp);
|
|
int interface = interfaceMatch.captured(1).toInt();
|
|
|
|
uint8_t* data =reinterpret_cast<uint8_t*>(ui->textEdit->toPlainText().toUtf8().data());
|
|
int len = ui->textEdit->toPlainText().length();
|
|
|
|
for(int i=0;i<len;i++){
|
|
LOG_DEBUG("Send data is 0x%x",data[i]);
|
|
}
|
|
if(uh->sendAsyncTransfer(endpointValue,data,len,interface)){
|
|
LOG_DEBUG("Send endPoint 0x%x via AsyncTransfer success.",endpointValue);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_pushButton_5_clicked()
|
|
{
|
|
ui->textBrowser->clear();
|
|
}
|