From: SnickerSun Date: Fri, 15 Mar 2024 01:39:55 +0000 (+0800) Subject: original source from sdk 602 X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=01caf04b29584de6c2e29985c303c0a14e382166;p=mirrors%2Ffactory_tool.git original source from sdk 602 --- diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..041dcc3 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,68 @@ +cmake_minimum_required(VERSION 3.5) + +project(untitled LANGUAGES CXX) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(RC_ICONS windows.ico) +# QtCreator supports the following variables for Android, which are identical to qmake Android variables. +# Check http://doc.qt.io/qt-5/deployment-android.html for more information. +# They need to be set before the find_package(Qt5 ...) call. + +#if(ANDROID) +# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") +# if (ANDROID_ABI STREQUAL "armeabi-v7a") +# set(ANDROID_EXTRA_LIBS +# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so +# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so) +# endif() +#endif() + +find_package(Qt5 COMPONENTS Widgets LinguistTools REQUIRED) + +set(TS_FILES untitled_zh_CN.ts) +include_directories(${CMAKE_SOURCE_DIR}/src) +if(ANDROID) + add_library(untitled SHARED + main.cpp + mainwindow.cpp + mainwindow.h + mainwindow.ui + ${TS_FILES} + ) +else() + add_executable(untitled + WIN32 + main.cpp + mainwindow.cpp + mainwindow.h + mainwindow.ui + mythread.h + mythread.cpp + custom.h + custom.cpp + Demoqrc.qrc + demopng.rc + at_data.cpp + at_data.h + result_thread.cpp + result_thread.h + common.h + ${TS_FILES} + ) +endif() + +target_link_libraries(untitled PRIVATE + Qt5::Widgets + ${CMAKE_SOURCE_DIR}/lib/libwireless_tools.dll) +target_link_libraries(untitled PRIVATE + Qt5::Widgets + ${CMAKE_SOURCE_DIR}/lib/libsecurec.a) + +qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES}) diff --git a/Demoqrc.qrc b/Demoqrc.qrc new file mode 100644 index 0000000..7f18d42 --- /dev/null +++ b/Demoqrc.qrc @@ -0,0 +1,8 @@ + + + icon/windows.png + icon/windows.ico + icon/FAIL.ico + icon/succ.ico + + diff --git a/at_data.cpp b/at_data.cpp new file mode 100644 index 0000000..993d64d --- /dev/null +++ b/at_data.cpp @@ -0,0 +1,134 @@ +#include + +At_Process::At_Process(QObject *parent) +{ + Q_UNUSED(parent); + phy_type_list<<"01"<<"02"; + ble_pattern_type_list<<"02 "<<"00 "<<"01 "; + br_pattern_type_list<<"03 "<<"04 "<<"09 "; + packet_type_list<<"04 01 "<<"0B 01 "<<"0F 01 "<<"04 00 "<<"0A 00 "<<"0E 00 "<<"08 00 "<<"0B 00 "<<"0F 00 "; + br_len_array<<27<<183<<339<<54<<367<<679<<83<<552<<1021; + board_cmd_map.insert(BT_MODE_BR_TX,"AT^BTTX="); + board_cmd_map.insert(BT_MODE_BR_RX,"AT^BTRX="); + board_cmd_map.insert(BT_MODE_BLE_TX,"AT^BLETX="); + board_cmd_map.insert(BT_MODE_BLE_RX,"AT^BLERX="); + board_cmd_map.insert(BT_MODE_BTDUTMODE, "AT^BTDUTMODE="); + board_cmd_map.insert(DONGLE_MODE_SPPCONN,"AT+SPPCONN="); + board_cmd_map.insert(DONGLE_MODE_AT,"AT"); + board_cmd_map.insert(DONGLE_MODE_ADDR,"AT+ADDR"); + board_cmd_map.insert(BT_MODE_BTLO,"AT^BTLO="); + board_cmd_map.insert(BT_MODE_BTPWR,"AT^BTPWR="); + +} +At_Process::~At_Process(){} +QString At_Process::at_get_packet_type(int packet_type_index) +{ + return packet_type_list.at(packet_type_index); +} +int At_Process::at_get_packet_len(int packet_type_index) +{ + return br_len_array.at(packet_type_index); +} +QString At_Process::at_get_br_pattern_type(int pattern_type_index) +{ + return br_pattern_type_list.at(pattern_type_index); +} +QString At_Process::at_get_ble_pattern_type(int pattern_type_index) +{ + return ble_pattern_type_list.at(pattern_type_index); +} + +QString At_Process::at_get_ble_phy_type(int phy_type_index) +{ + return phy_type_list.at(phy_type_index); +} +QString At_Process::at_get_cmd_board(at_mode_board mode) +{ + return board_cmd_map[mode]; +} +QString At_Process::at_get_switch_format(QString br_switch) +{ + QString str; + if(br_switch.contains("OFF")){ + str="00"; + }else if(br_switch.contains("ON")){ + str="01 "; + } + return str; +} +QString At_Process::at_get_br_format(at_mode_board mode,QString br_switch,QString channel, int packet_type_index, QString payload_len, int pattern_type) +{ + QString str; + str += at_get_switch_format(br_switch); + if(br_switch.contains("ON")){ + str += QString("%1 ").arg(channel.toUInt(), 2, 16, QLatin1Char('0')); + str += at_get_packet_type(packet_type_index); + QString str_temp = QString("%1").arg(payload_len.toUInt(), 4, 16, QLatin1Char('0')); + str.insert(9, str_temp.mid(0, 2)+" "); + str.insert(9, str_temp.mid(2, 2)+" "); + str += at_get_br_pattern_type(pattern_type); + if(mode==BT_MODE_BR_TX){ + str.insert(3, "02 "); + } + } + return str; +} + +QString At_Process::at_get_ble_format(at_mode_board mode,QString br_switch,QString channel,int pattern_type_index, QString payload_len, int phy_index) +{ + QString str=NULL; + str += at_get_switch_format(br_switch); + if(br_switch.contains("ON")){ + str += QString("%1 ").arg(channel.toUInt(), 2, 16, QLatin1Char('0')); + if(mode==BT_MODE_BLE_TX){ + str+= at_get_ble_pattern_type(pattern_type_index); + str+= QString("%1 ").arg(payload_len.toUInt(), 2, 16, QLatin1Char('0')); + } + str+=at_get_ble_phy_type(phy_index); + } + return str; +} + + +bool At_Process::at_send_cmd_board(at_mode_board mode,QString format) +{ + char *buf=nullptr; + uint32_t buf_len=0; + bool ret=false; + QString str=at_get_cmd_board(mode); + str+=format; + str+="\r\n"; + buf = (char *)str.toStdString().c_str(); + buf_len = strlen(buf); + if(uapi_uart_tx_data(buf, buf_len)){ + ret=true; + } + return ret; +} + +bool At_Process::at_send_cmd_string(at_module_id module_id, at_cmd_id cmd_id,QString format) +{ + char *buf = nullptr; + uint32_t buf_len=0; + bool ret=false; + QByteArray arr = format.toLatin1(); + buf = arr.data(); + buf_len = arr.size(); + if (uapi_at_send(module_id, cmd_id, (uint8_t *)buf, buf_len, at_callback) == SUCC) { + at_set_id(module_id, cmd_id); + ret=true; + } + return ret; +} + +void At_Process::at_set_id(at_module_id at_module_id_temp, at_cmd_id at_cmd_id_temp) +{ + at_module_id_save = at_module_id_temp; + at_cmd_id_save = at_cmd_id_temp; +} + +void At_Process::at_get_id(at_module_id *at_module_id, at_cmd_id *at_cmd_id) +{ + *at_module_id = at_module_id_save; + *at_cmd_id = at_cmd_id_save; +} diff --git a/at_data.h b/at_data.h new file mode 100644 index 0000000..8323390 --- /dev/null +++ b/at_data.h @@ -0,0 +1,112 @@ +#ifndef AT_DATA_H +#define AT_DATA_H + +#include +#include +#include +#include +#include + +struct at_media_command { + uint8_t cmd[2]; + uint8_t payload[0]; +}; + +enum at_br_packet_type +{ + PACKET_DH1, + PACKET_DH3, + PACKET_DH5, + PACKET_2DH1, + PACKET_2DH3, + PACKET_2DH5, + PACKET_3DH1, + PACKET_3DH3, + PACKET_3DH5, +}; + +enum at_ble_phy +{ + PHY_1M, + PHY_2M, +}; + +enum at_pattern_type +{ + PATTERN_TYPE_1, + PATTERN_TYPE_2, + PATTERN_TYPE_3, +}; + +enum at_mode_board +{ + BT_MODE_BR_TX, + BT_MODE_BR_RX, + BT_MODE_BLE_TX, + BT_MODE_BLE_RX, + BT_MODE_BTDUTMODE, + BT_MODE_BTLO, + BT_MODE_BTPWR, + DONGLE_MODE_SPPCONN, + DONGLE_MODE_AT, + DONGLE_MODE_ADDR, + MODE_MAX, +}; + +enum at_module_id +{ + MODULE_MCU =0x08, + MODULE_BT =0x09, + MODULE_AUDIO =0x0A, +}; + +enum at_cmd_id +{ + AUDIO_CMD = 0x00, + MCU_CMD_FSRM = 0x09, + MCU_CMD_STACKINFO = 0x0D, + MCU_CMD_CHECK_CONNECTED=0x40, + MCU_CMD_RETURN_VALUE=0x41, + BT_CMD_SETTXPOWER = 0x7A, + BT_CMD_DUTMODE = 0x7D, + BT_CMD_GET_RX = 0x83, + BT_CMD_BR_TX, + BT_CMD_BR_RX, + BT_CMD_BLE_TX, + BT_CMD_BLE_RX, + BT_CMD_DELAY_MS, + BT_CMD_DONGLE_MAC, + BT_CMD_RX_RESULT = 0xFF, +}; + + +class At_Process +{ +public: + At_Process(QObject *parent = 0); + ~At_Process(); + QString at_get_br_format(at_mode_board bt_mode,QString br_switch,QString channel, int packet_type, QString payload_len, int pattern_type); + QString at_get_ble_format(at_mode_board bt_mode,QString br_switch,QString channel,int pattern_type_index , QString payload_len, int phy_index); + bool at_send_cmd_string(at_module_id module_id, at_cmd_id cmd_id,QString format); + bool at_send_cmd_board(at_mode_board bt_mode,QString format); + void at_get_id(at_module_id *at_module_id, at_cmd_id *at_cmd_id); + int at_get_packet_len(int packet_type); + QString at_get_switch_format(QString br_switch); +private: + at_module_id at_module_id_save; + at_cmd_id at_cmd_id_save; + QStringList phy_type_list; + QStringList ble_pattern_type_list; + QStringList br_pattern_type_list; + QStringList packet_type_list; + QVector br_len_array; + QMap board_cmd_map; +private: + QString at_get_cmd_board(at_mode_board bt_mode); + QString at_get_ble_phy_type(int phy_type_index); + QString at_get_ble_pattern_type(int pattern_type); + QString at_get_br_pattern_type(int pattern_type); + QString at_get_packet_type(int packet_type); + void at_set_id(at_module_id at_module_id, at_cmd_id at_cmd_id); +}; +#endif // AT_DATA_H diff --git a/common.h b/common.h new file mode 100644 index 0000000..c9ed230 --- /dev/null +++ b/common.h @@ -0,0 +1,16 @@ +#ifndef COMMON_H +#define COMMON_H + +#include +#include + +typedef uint8_t* u8Piont; +typedef void* vPiont; + +Q_DECLARE_METATYPE(u8Piont); +Q_DECLARE_METATYPE(vPiont); + +#define MESSAGE_INFO_COLOR(STRING) "" STRING "" " " +#define CHECK_DONGLE_CONNECTED + +#endif // COMMON_H diff --git a/custom.cpp b/custom.cpp new file mode 100644 index 0000000..542ed25 --- /dev/null +++ b/custom.cpp @@ -0,0 +1,48 @@ +#include + +MyComboBox::MyComboBox(QWidget *paraent) : QComboBox(paraent) {} +MyComboBox::~MyComboBox() {} + +void MyComboBox::mousePressEvent(QMouseEvent *e) +{ + if (e->button() == Qt::LeftButton) { + emit mouse_clicked(true); + } + QComboBox::mousePressEvent(e); +} + +void MyComboBox::ChangeItem(QString str) +{ + for(int i=0;icount();i++ ){ + if(this->itemText(i).contains(str)){ + this->setCurrentIndex(i); + break; + } + } +} + +MyLineEdit::MyLineEdit(QWidget *parent):QLineEdit(parent) +{ + +} + +void MyLineEdit::keyPressEvent(QKeyEvent *event) +{ + qDebug()<key(); + if(event->key()==Qt::Key_Up){ + int current_data=this->text().toInt()+1; + const QIntValidator *validator=(QIntValidator *)this->validator(); + if(current_data <= validator->top()){ + this->setText(QString::number(current_data,10)); + } + }else if(event->key()==Qt::Key_Down){ + int current_data=this->text().toInt()-1; + const QIntValidator *validator=(QIntValidator *)this->validator(); + if(current_data >= validator->bottom()){ + this->setText(QString::number(current_data,10)); + } + }else{ + QLineEdit::keyPressEvent(event);//执行 + } + event->ignore();//输出后,才将继续执行主窗口的keypressEvent事件 +} diff --git a/custom.h b/custom.h new file mode 100644 index 0000000..dca637f --- /dev/null +++ b/custom.h @@ -0,0 +1,70 @@ +#ifndef MYCOMBOBOX_H +#define MYCOMBOBOX_H +#include +#include +#include +#include +#include +#include + +// 自定义 QComboBox 类,实现 clicked 信号 +class MyComboBox : public QComboBox +{ + Q_OBJECT + public: + explicit MyComboBox(QWidget *paraent = 0); + ~MyComboBox(); + void ChangeItem(QString str); + protected: + virtual void mousePressEvent(QMouseEvent *e) override; + signals: + void mouse_clicked(bool); +}; + +// 自定义MyLineEdit类,实现 up down按键自动加减值 +class MyLineEdit : public QLineEdit +{ + Q_OBJECT +public: + explicit MyLineEdit(QWidget *parent=0); +protected: + void keyPressEvent(QKeyEvent *event); +}; + +class MyValidator : public QIntValidator +{ + Q_OBJECT +public: + explicit MyValidator(QObject * parent = 0):QIntValidator(parent) + { + } + MyValidator(int bottom, int top, QObject * parent):QIntValidator(bottom, top, parent) + { + } + virtual void setRange(int bottom, int top) + { + QIntValidator::setRange(bottom, top); + } + ~MyValidator() + { + } + virtual State validate(QString &str, int &n) const + { + if(str.contains("+")){ + return Invalid; + } + if(n > 1 && str.startsWith("0")){ + return Invalid; + } + if(str.toInt()top()){ + return Invalid; + } + return QIntValidator::validate(str, n); + } +// virtual void fixup(QString &s) const +// { +// s = QString("%1").arg(bottom()); +// } +}; + +#endif // MYCOMBOBOX_H diff --git a/demopng.rc b/demopng.rc new file mode 100644 index 0000000..4b0ae81 --- /dev/null +++ b/demopng.rc @@ -0,0 +1 @@ +IDI_ICON1 ICON DISCARDABLE "icon/windows.ico" diff --git a/icon/FAIL.ico b/icon/FAIL.ico new file mode 100644 index 0000000..abdb54e Binary files /dev/null and b/icon/FAIL.ico differ diff --git a/icon/succ.ico b/icon/succ.ico new file mode 100644 index 0000000..61fb14f Binary files /dev/null and b/icon/succ.ico differ diff --git a/icon/windows.ico b/icon/windows.ico new file mode 100644 index 0000000..4bb7bc8 Binary files /dev/null and b/icon/windows.ico differ diff --git a/icon/windows.png b/icon/windows.png new file mode 100644 index 0000000..f0cc3a0 Binary files /dev/null and b/icon/windows.png differ diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..177bfa0 --- /dev/null +++ b/main.cpp @@ -0,0 +1,10 @@ +#include "mainwindow.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + return a.exec(); +} diff --git a/mainwindow.cpp b/mainwindow.cpp new file mode 100644 index 0000000..960ba57 --- /dev/null +++ b/mainwindow.cpp @@ -0,0 +1,1058 @@ +#include "mainwindow.h" +#include "./ui_mainwindow.h" +// 初始化线程、状态寄存器、配置信息 +MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) +{ + ui->setupUi(this); + result_thread = new Result_Thread(this); + result_thread->start(); + result_thread->pause(); + at_handler = new At_Process(this); + ui_setting_read(); + at_set_bt_format(); +} + +// 结束线程 +MainWindow::~MainWindow() +{ + if (spp_timer_handle != NULL) { + spp_timer_handle->stop(); + spp_timer_handle = NULL; + } + if (spp_connected_handle != NULL) { + spp_connected_handle->stop(); + spp_connected_handle = NULL; + } + ui_setting_save(); + result_thread->stop(); + result_thread->wait(); + if (transmit_timer_handle != NULL) { + transmit_timer_handle->stop(); + transmit_timer_handle = NULL; + } + if (ui->pbtn_open_uart->isChecked()) { + if (uapi_uart_close() == TRUE) { + } + } + delete result_thread; + delete at_handler; + delete ui; +} + +void MainWindow::ui_display(QString str,bool inOrOut) +{ +// QTime Time= QTime::currentTime();//获取系统当前的时间 +// QString str_time = Time.toString("[hh:mm:ss ");//格式化时间 + ui->txtb_dispaly->moveCursor(QTextCursor::End); + if(inOrOut){ + ui->txtb_dispaly->setTextColor(QColor(127, 255, 0)); + }else{ + ui->txtb_dispaly->setTextColor(Qt::red); + } +// if(inOrOut){ +// str_time.append("IN] : "); +// }else{ +// str_time.append("OUT] : "); +// } +// str.prepend(str_time); +// str+="\r\n"; + ui->txtb_dispaly->insertPlainText(str); + ui->txtb_dispaly->moveCursor(QTextCursor::End); +} + +void MainWindow::ui_tab_mainwindow_complete() +{ + if (ui->stkw_stage->currentIndex() == PAGE_COMPLETE) { + ui->action_complete->setChecked(true); + return; + } + ui->stkw_stage->setCurrentIndex(PAGE_COMPLETE); + ui->ledit_spp_addr->setEnabled(true); + ui->connected_flag->setStyleSheet("QPushButton{background-color: rgb(255, 0, 0);}"); + if (spp_connected_handle != NULL) { + spp_connected_handle->start(1500); + } + if (ui->action_board->isChecked()) { + ui->action_board->setChecked(false); + } + if(ui->pbtn_open_uart->isChecked()){ + uart_close(); + } +} +void MainWindow::ui_tab_mainwindow_board() +{ + if (ui->stkw_stage->currentIndex() == PAGE_BOARD) { + ui->action_board->setChecked(true); + return; + } + ui->stkw_stage->setCurrentIndex(PAGE_BOARD); + ui->ledit_spp_addr->setEnabled(false); + ui->connected_flag->setStyleSheet("QPushButton{background-color: rgb(240, 240, 240);}"); + if (spp_connected_handle != NULL) { + spp_connected_handle->stop(); + } + dongle_is_connected = false; + if (ui->action_complete->isChecked()) { + ui->action_complete->setChecked(false); + } + if(ui->pbtn_open_uart->isChecked()){ + uart_close(); + } + +} +void MainWindow::ui_save_windows() +{ + QString fname = QFileDialog::getExistingDirectory(this, "请选择文件"); + QFile file(fname+"/save.txt"); + if (!file.open(QFile::WriteOnly | QFile::Text)) //检测文件是否打开 + { + QMessageBox::information(this, "Error Message", "Please Select a Text File!"); + return; + } + + QTextStream out(&file); //分行写入文件 + out << ui->txtb_dispaly->toPlainText(); //这里的File_edit就是之前声明的Textedit控件的名字 +} +// 存储config配置文件 +void MainWindow::ui_setting_save() +{ + QSettings *settings = new QSettings("Setting.ini", QSettings::IniFormat); + + // 写入第一组数据 + settings->beginGroup("Uart_setting"); + settings->setValue("uart_com", ui->cbox_uart_com_select->currentText()); + settings->setValue("uart_baud", ui->cbox_uart_baud_select->currentIndex()); + settings->setValue("spp_addr", ui->ledit_spp_addr->text()); + settings->sync(); + settings->endGroup(); + // 写入第二组数据 + settings->beginGroup("Download_Setting"); + settings->setValue("download_board_path", ui->ledit_formboad_bordpath->text()); + settings->setValue("download_local_path", ui->ledit_frombord_savefilepath->text()); + settings->sync(); + settings->endGroup(); + + settings->beginGroup("Upload_Setting"); + settings->setValue("upload_board_path", ui->ledit_toboard_boardpath->text()); + settings->setValue("upload_local_path", ui->ledit_toboard_filepath->text()); + settings->sync(); + settings->endGroup(); + + settings->beginGroup("At_Setting"); + settings->setValue("at_mediamusicplay", ui->ledit_at_mediamusicplay->text()); + settings->setValue("at_mediaaudiorecord", ui->ledit_at_mediaaudiorecord->text()); + settings->setValue("at_fsrm", ui->ledit_at_fsrm->text()); + settings->setValue("at_delay_ms", ui->ledit_delay_ms->text()); + settings->setValue("at_spp_addr", ui->ledit_dongle_mac->text()); + settings->setValue("custom_module_id", ui->ledit_at_custom_moduleId->text()); + settings->setValue("custom_cmd_id", ui->ledit_at_custom_CmdId->text()); + settings->setValue("custom_payload", ui->ledit_at_custom_Payload->text()); + settings->sync(); + settings->endGroup(); + + delete settings; + settings = nullptr; +} +// 读取config配置 +void MainWindow::ui_setting_read() +{ + uart_com_select(); + QSettings *settings = new QSettings("Setting.ini", QSettings::IniFormat); + ui->cbox_uart_com_select->ChangeItem(settings->value("Uart_setting/uart_com").toString()); + ui->cbox_uart_baud_select->setCurrentIndex(settings->value("Uart_setting/uart_baud").toInt()); + ui->ledit_spp_addr->setText(settings->value("Uart_setting/spp_addr").toString()); + ui->tbw_stage_complete->setEnabled(true); + ui->ledit_formboad_bordpath->setText(settings->value("Download_Setting/download_board_path").toString()); + ui->ledit_frombord_savefilepath->setText(settings->value("Download_Setting/download_local_path").toString()); + ui->ledit_toboard_boardpath->setText(settings->value("Upload_Setting/upload_board_path").toString()); + ui->ledit_toboard_filepath->setText(settings->value("Upload_Setting/upload_local_path").toString()); + ui->ledit_at_mediamusicplay->setText(settings->value("At_Setting/at_mediamusicplay").toString()); + ui->ledit_at_mediaaudiorecord->setText(settings->value("At_Setting/at_mediaaudiorecord").toString()); + ui->ledit_at_fsrm->setText(settings->value("At_Setting/at_fsrm").toString()); + ui->ledit_delay_ms->setText(settings->value("At_Setting/at_delay_ms").toString()); + ui->ledit_dongle_mac->setText(settings->value("At_Setting/at_spp_addr").toString()); + ui->ledit_at_custom_moduleId->setText(settings->value("At_Setting/custom_module_id").toString()); + ui->ledit_at_custom_CmdId->setText(settings->value("At_Setting/custom_cmd_id").toString()); + ui->ledit_at_custom_Payload->setText(settings->value("At_Setting/custom_payload").toString()); + ui->tbw_stage_complete->setEnabled(false); + ui->ledit_btlo_channel->setText("0"); + ui->ledit_btpwr_powerchip->setText("2"); +} + + +/* --------------------------------uart操作--------------------------- */ +void MainWindow::uart_process() +{ + if (ui->pbtn_open_uart->isChecked()) { + QString str_com = ui->cbox_uart_com_select->currentText(); + QString str_uart_baud = ui->cbox_uart_baud_select->currentText(); + uart_open(str_com,str_uart_baud); + } else { + uart_close(); + } +} +void MainWindow::uart_open(QString com,QString com_baud) +{ + char buf[15] = {0}; + uint32_t band = com_baud.toUInt(); + com.replace("COM", ""); + int comNumber = com.toInt(); + if (comNumber < COM_NUMBER) { + (void)sprintf_s(buf, "COM%d", comNumber); + } else { + (void)sprintf_s(buf, "\\\\.\\COM%d", comNumber); + } + if (uapi_uart_open(buf, band)) { + uapi_uart_callback_register(uart_callback); + result_thread->resume(); + + if(ui->stkw_stage->currentIndex() == PAGE_COMPLETE){ + ui->tbw_stage_complete->setEnabled(true); + ui->pbtn_spp_connect->setEnabled(true); + }else if(ui->stkw_stage->currentIndex() == PAGE_BOARD){ + ui->tbw_stage_board->setEnabled(true); + } + + ui->pbtn_open_uart->setText("关闭串口"); +// ui_display("open uart success.\r\n",false); + if(!ui->pbtn_open_uart->isChecked()){ + ui->pbtn_open_uart->setChecked(true); + } + } else { +// ui_display("open uart fail.\r\n",false,false); + QMessageBox::warning(this, tr("串口"), tr("打开串口失败!"), QMessageBox::Ok); + ui->pbtn_open_uart->setChecked(false); + } +} +void MainWindow::uart_close() +{ + if (uapi_uart_close() == TRUE) { + result_thread->pause(); +// ui_display("close uart success.\r\n",false); + ui->tbw_stage_complete->setEnabled(false); + ui->tbw_stage_board->setEnabled(false); + ui->pbtn_spp_connect->setEnabled(false); + ui->pbtn_open_uart->setText("打开串口"); + if(ui->pbtn_open_uart->isChecked()){ + ui->pbtn_open_uart->setChecked(false); + } + if (spp_connected_handle != NULL) { + spp_connected_handle->stop(); + spp_connected_handle = NULL; + } + if (spp_timer_handle != NULL) { + spp_timer_handle->stop(); + spp_timer_handle = NULL; + } + } else { +// ui_display("close uart fail.\r\n",false); + } +} +void MainWindow::uart_send_data() +{ + QString str; + char *buf = nullptr; + int buf_len = 0; + if(ui->stkw_stage->currentIndex() == PAGE_COMPLETE){ + str = ui->tedit_input_data->toPlainText(); + }else{ + str = ui->tedit_input_data_board->toPlainText(); + } + uapi_uart_callback_register(uart_callback); + if (ui->ckbox_hex_send->isChecked()) { + QByteArray array = str.toLatin1(); + QByteArray hex_bytes = QByteArray::fromHex(array.data()); + buf_len = hex_bytes.size(); + buf = hex_bytes.data(); + str=str.toUpper(); + } else { + if ((ui->stkw_stage->currentIndex() == PAGE_COMPLETE &&ui->ckbox_word_wrap->isChecked())|| + (ui->stkw_stage->currentIndex() ==PAGE_BOARD && ui->ckbox_word_wrap_board->isChecked())) { + str+="\r\n"; + } + buf = (char *)str.toStdString().c_str(); + buf_len = strlen(buf); + } + uapi_uart_tx_data(buf, buf_len); + ui_display(str,false); +} + +// uart收到的数据进行回显到显示栏 +void MainWindow::uart_rx_dispaly(int buf_len, u8Piont buf) +{ + uart_rx_flag = true; + if (uart_rx_Ignoring_display) { + QString str((char *)buf); + if(str.contains("ADDR")){ + ui->ledit_dongle_mac->setText(str.mid(str.indexOf("=",0)+1,12)); + } + return; + } + QString str; + QByteArray data((const char*)buf, buf_len); + if (ui->ckbox_Hex_Display->isChecked()) { + for (int i = 0; i < data.size(); i++) { + str += QString("%1 ").arg((quint8)data.at(i), 2, 16, QChar('0')); + } + str=str.toUpper(); + } else { + for (int i = 0; i < data.size(); i++) { + str += QString(data.at(i)); + } + } + ui_display(str,true); + free(buf); +} + +void MainWindow::uart_check_dtr_rts() +{ + bool rts = false, dtr = false; + if (ui->ckbox_rts->isChecked()) { + rts = true; + } + if (ui->ckbox_dtr->isChecked()) { + dtr = true; + } + if (uapi_uart_set_rts_dtr(rts, dtr) == TRUE) { +// ui_display("set rts dtr success.\r\n",false); + } +} + +void MainWindow::uart_com_select() +{ + ui->cbox_uart_com_select->clear(); + QStringList strlist = uart_get_enable_comm_or_port(); + qSort(strlist.begin(), strlist.end(),[](const QString& s1, const QString& s2){ + QString a1=s1;QString a2=s2; + return a1.replace("COM","").toInt() < a2.replace("COM","").toInt(); }); + ui->cbox_uart_com_select->addItems(strlist); +} +void MainWindow::uart_com_switch(QString com) +{ + QString str_uart_baud = ui->cbox_uart_baud_select->currentText(); + if(ui->pbtn_open_uart->isChecked()){ + uart_close(); + uart_open(com,str_uart_baud); + } +} +void MainWindow::uart_baud_switch(QString baud) +{ + QString str_com = ui->cbox_uart_com_select->currentText(); + if(ui->pbtn_open_uart->isChecked()){ + uart_close(); + uart_open(str_com,baud); + } +} +// nIndex为索引号 bValue选择返回值为key还是value,默认为value +QString MainWindow::uart_get_comm_or_port(int nIndex, bool bValue) +{ + QString strCommRet = QObject::tr(""); + HKEY hKey; + if (::RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("HARDWARE\\DEVICEMAP\\SERIALCOMM"), 0, KEY_READ, &hKey) != 0) { + QMessageBox::warning(this, tr("注册表"), tr("无法打开注册表!"), QMessageBox::Ok); + return QObject::tr(""); // 无法打开注册表 + } + QString strKeyMsg; // 键名 + QString strValueMsg; // 键值 + TCHAR portName[256]; // 键名数组 + TCHAR commName[256]; // 键值数组 + ulong nKeySize = sizeof(portName); + ulong nValueSize = sizeof(commName); + ulong nType; + if (::RegEnumValue(hKey, nIndex, portName, &nKeySize, 0, &nType, (BYTE *)commName, &nValueSize) == 0) { // 列举键名 + // 读取键名 + for (uint i = 0; i < nKeySize; i++) { + if (portName[i] != 0x00) + strKeyMsg.append(portName[i]); + } + // 读取键值 + for (uint j = 0; j < nValueSize; j++) { + if (commName[j] != 0x00) + strValueMsg.append(commName[j]); + } + if (bValue) + strCommRet = strValueMsg; + else + strCommRet = strKeyMsg; + } else { + ::RegCloseKey(hKey); // 关闭注册表 + return QObject::tr(""); // 无可用串口 + } + return strCommRet; +} + +QStringList MainWindow::uart_get_enable_comm_or_port() +{ + QStringList CommPortList; + QString strCommPath = QObject::tr("HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP\\SERIALCOMM"); + QSettings *settings = new QSettings(strCommPath, QSettings::NativeFormat); + QStringList keyList = settings->allKeys(); + if (!keyList.isEmpty()) { + for (int i = 0; i < keyList.count(); i++) + CommPortList.append(uart_get_comm_or_port(i, true)); + } + return CommPortList; +} + +/* ------------------------------------------------------------------- */ +void MainWindow::spp_connected_callback() +{ + at_handler->at_send_cmd_string(MODULE_MCU,MCU_CMD_CHECK_CONNECTED,NULL); + dongle_connected_times++; + if (dongle_connected_times > 5) { + ui_display("Dongle has been disconnected.\r\n",false); + dongle_is_connected = false; + } + if (dongle_is_connected == true) { + ui->connected_flag->setStyleSheet("QPushButton{background-color: rgb(0, 255, 64);}"); + } else { + ui->connected_flag->setStyleSheet("QPushButton{background-color: rgb(255, 0, 0);}"); + } +} + +void MainWindow::spp_timer_callback() +{ + bool final_ret = false; + if (dongle_try_count > 5) { + ui_display("\r\nNo device, check the dongle is connected.\r\n",false); + final_ret = true; + } + if (uart_rx_flag == false) { + at_handler->at_send_cmd_string(MODULE_MCU,MCU_CMD_CHECK_CONNECTED,NULL); + dongle_try_count++; + } else if (spp_try_count % 3 == 0) { // 每3次重新发送一次连接AT命令 + QString str = ui->ledit_spp_addr->text(); + at_handler->at_send_cmd_board(DONGLE_MODE_SPPCONN,str); + } else if (spp_try_count > 10) { // 循环10次还有数据上报则表示连接失败 + ui_display("\r\nconnect fail.\r\n",false); + final_ret = true; + } + if (dongle_is_connected == true) { + final_ret = true; + ui_display("\r\nDongle has been connected.\r\n",false); + if (spp_connected_handle == NULL) { + spp_connected_handle = new QTimer(this); + connect(spp_connected_handle, SIGNAL(timeout()), this, SLOT(spp_connected_callback())); + spp_connected_handle->start(1500); + } + } + if (final_ret == false) { + at_handler->at_send_cmd_board(DONGLE_MODE_AT,NULL); + spp_try_count++; + uart_rx_flag = false; + ui_display(".",false); + } else { + spp_timer_handle->stop(); + spp_timer_handle = NULL; + uart_rx_Ignoring_display = false; + ui->pbtn_spp_connect->setEnabled(true); + } +} + +void MainWindow::spp_connect() +{ + uart_rx_Ignoring_display = true; + dongle_is_connected = false; + dongle_try_count = 0; + spp_try_count = 0; + uapi_uart_callback_register(uart_callback); + at_handler->at_send_cmd_board(DONGLE_MODE_ADDR,NULL); + ui_display("spp connectting...",false); + spp_timer_handle = new QTimer(this); + connect(spp_timer_handle, SIGNAL(timeout()), this, SLOT(spp_timer_callback())); + // spp查询定时器周期为1500ms + spp_timer_handle->start(1500); + ui->pbtn_spp_connect->setEnabled(false); +} + +/* ------------------------------------------------------------------------ */ +/* -------------------------业务处理部分------------------------------------- */ + +void MainWindow::transmit_ls_rx_diaplay(int transmit_ls_size, vPiont transmit_ls_buff) +{ + if(transmit_ls_size>0){ + ui_display("文件名 大小\r\n",true); + } + uapi_ls_info_t *transmit_ls_buff_temp = (uapi_ls_info_t *)transmit_ls_buff; + for (int i = 0; i < transmit_ls_size; i++) { + QString strName = QString::fromUtf8((char *)(transmit_ls_buff_temp[i].name)); + QString strFileLen = QString::number(transmit_ls_buff_temp[i].file_size,10); + if (transmit_ls_buff_temp[i].is_dir) { + strName.append("/"); + } + ui_display(strName+" "+strFileLen+"\r\n",true); + ui->cbox_fromborad_filelist->addItem(strName,strFileLen); + } + free(transmit_ls_buff); +} + +void MainWindow::transmit_rx_display(bool transmit_result_flag) +{ + uint32_t total_size=0; + uint32_t current_size=0; + transmit_get_data_count(&total_size,¤t_size); + uint32_t value = transmit_result_flag ? total_size : 0; + if (transmit_timer_handle) { + transmit_timer_handle->stop(); + transmit_timer_handle = NULL; + } + if (transmit_download_or_upload == TRANSMIT_UPLOAD) { + ui->pbar_toboard->setValue(value); + ui->pbtn_toboard_Upload->setEnabled(true); + } + if (transmit_download_or_upload == TRANSMIT_DOWNLOAD) { + ui->pbar_fromboard->setValue(value); + ui->pbtn_fromboard_download->setEnabled(true); + } + if (transmit_result_flag) { + ui_display("download or upload file success.\r\n",false); + } else { + ui_display("download or upload file fail.\r\n",false); + } + transmit_download_or_upload = TRANSMIT_IDLE; + ui->pbtn_fromboard_delete->setEnabled(true); + ui->pbtn_fromboard_getfilelist->setEnabled(true); +} + +void MainWindow::transmit_fromboard_name_change() +{ + ui->cbox_fromborad_filelist->clear(); +} + +void MainWindow::transmit_fromboard_selectfilepath() +{ + QString fname = QFileDialog::getExistingDirectory(this, "请选择文件"); + ui->ledit_frombord_savefilepath->setText(fname); +} + +void MainWindow::transmit_fromboard_getfilelist() +{ + QString str = ui->ledit_formboad_bordpath->text(); + if (str.isEmpty()) { + QMessageBox::warning(this, tr("File Path"), tr("文件路径为空!"), QMessageBox::Ok); + return; + } + ui->cbox_fromborad_filelist->clear(); + char *buf = (char *)str.toStdString().c_str(); + int ret = uapi_ls_send(buf, strlen(buf), ls_callback); + if (ret == FAIL) { + QMessageBox::warning(this, tr("ls"), tr("ls fail!\r\n"), QMessageBox::Ok); + } + tansmit_fromborad_borad_list.push_back(str); + QCompleter *com = new QCompleter(tansmit_fromborad_borad_list, this); + com->setCaseSensitivity(Qt::CaseInsensitive); + delete ui->ledit_formboad_bordpath->completer(); + ui->ledit_formboad_bordpath->setCompleter(com); +} + +void MainWindow::transmit_fromboard_download() +{ + QString str_savepath = ui->ledit_frombord_savefilepath->text(); + QString str_file_path = ui->ledit_formboad_bordpath->text(); + QString str_file_name = ui->cbox_fromborad_filelist->currentText(); + if (str_savepath.isEmpty() || str_file_path.isEmpty() || str_file_name.isEmpty()) { + QMessageBox::warning(this, tr("File Path"), tr("文件路径为空!"), QMessageBox::Ok); + return; + } + if (str_file_name.contains("/")) { + QMessageBox::warning(this, tr("Board File Name"), tr("请选择正确的文件!"), QMessageBox::Ok); + return; + } + qDebug()<cbox_fromborad_filelist->currentData().toInt(); + if(ui->cbox_fromborad_filelist->currentData().toInt()==0){ + QMessageBox::warning(this, tr("Board File Name"), tr("文件大小为0!"), QMessageBox::Ok); + return; + } + if(!str_file_path.endsWith("/")){ + str_file_path.append("/"); + } + str_file_path.append(str_file_name); + std::string buf_temp = str_file_path.toStdString(); + char *str_file_buff = (char *)buf_temp.c_str(); + std::string buf_temp2 = str_savepath.toStdString(); + char *str_save_buff = (char *)buf_temp2.c_str(); + int ret = uapi_file_download(str_file_buff, str_save_buff, transmit_callback); + if (ret == FAIL) { + QMessageBox::warning(this, tr("Downloade"), tr("文件下载启动失败!"), QMessageBox::Ok); + return; + } + transmit_progress_start(); + transmit_download_or_upload = TRANSMIT_DOWNLOAD; + transmit_fromborad_local_list.push_back(str_savepath); + QCompleter *com = new QCompleter(transmit_fromborad_local_list, this); + com->setCaseSensitivity(Qt::CaseInsensitive); + delete ui->ledit_frombord_savefilepath->completer(); + ui->ledit_frombord_savefilepath->setCompleter(com); + ui->pbtn_fromboard_download->setEnabled(false); + ui->pbtn_fromboard_delete->setEnabled(false); + ui->pbtn_fromboard_getfilelist->setEnabled(false); +} + +void MainWindow::transmit_fromboard_delete() +{ + QString str_file_path = ui->ledit_formboad_bordpath->text(); + QString str_file_name = ui->cbox_fromborad_filelist->currentText(); + if (str_file_path.isEmpty() || str_file_name.isEmpty()) { + QMessageBox::warning(this, tr("File Path"), tr("文件路径为空!"), QMessageBox::Ok); + return; + } + if (str_file_name.contains("/")) { + str_file_name.chop(1); + } else { + str_file_path.append("/"); + } + str_file_path.append(str_file_name); + char *str_file_buff = (char *)str_file_path.toStdString().c_str(); + int ret = uapi_file_delete(str_file_buff, strlen(str_file_buff)); // ls + if (ret == FAIL) { + QMessageBox::warning(this, tr("delete"), tr("delete file fail!\r\n"), QMessageBox::Ok); + } + ui->cbox_fromborad_filelist->removeItem(ui->cbox_fromborad_filelist->currentIndex()); +} + +void MainWindow::transmit_fromboard_stop() +{ + if (transmit_timer_handle) { + transmit_timer_handle->stop(); + transmit_timer_handle = NULL; + } + transmit_download_or_upload = TRANSMIT_IDLE; + ui->pbar_fromboard->setValue(0); + ui->pbtn_fromboard_download->setEnabled(true); + ui->pbtn_fromboard_delete->setEnabled(true); + ui->pbtn_fromboard_getfilelist->setEnabled(true); + uapi_file_transmit_stop(); +} + +void MainWindow::transmit_toboard_choosefile() +{ + QString fname = QFileDialog::getOpenFileName(this, "请选择文件"); + ui->ledit_toboard_filepath->setText(fname); +} + +void MainWindow::transmit_toboard_upload() +{ + QString board_file_path = ui->ledit_toboard_boardpath->text(); + QString local_file_path = ui->ledit_toboard_filepath->text(); + if (board_file_path.isEmpty() || local_file_path.isEmpty()) { + QMessageBox::warning(this, tr("File Path"), tr("文件路径为空!"), QMessageBox::Ok); + return; + } + char *buf_board_file_path = (char *)board_file_path.toStdString().c_str(); + char *buf_local_file_path = (char *)local_file_path.toStdString().c_str(); + int ret = uapi_file_upload(buf_board_file_path, buf_local_file_path, transmit_callback); + if (ret == FAIL) { + QMessageBox::warning(this, tr("Upload"), tr("文件上传启动失败!\r\n"), QMessageBox::Ok); + return; + } + transmit_progress_start(); + transmit_download_or_upload = TRANSMIT_UPLOAD; + transmit_toboard_local_list.push_back(local_file_path); + transmit_toboard_borad_list.push_back(board_file_path); + QCompleter *com1 = new QCompleter(transmit_toboard_local_list, this); + com1->setCaseSensitivity(Qt::CaseInsensitive); + delete ui->ledit_toboard_filepath->completer(); + ui->ledit_toboard_filepath->setCompleter(com1); + QCompleter *com2 = new QCompleter(transmit_toboard_borad_list, this); + com2->setCaseSensitivity(Qt::CaseInsensitive); + delete ui->ledit_toboard_boardpath->completer(); + ui->ledit_toboard_boardpath->setCompleter(com2); + ui->pbtn_toboard_Upload->setEnabled(false); +} + +void MainWindow::transmit_toboard_stop() +{ + if (transmit_timer_handle) { + transmit_timer_handle->stop(); + transmit_timer_handle = NULL; + } + transmit_download_or_upload = TRANSMIT_IDLE; + ui->pbar_toboard->setValue(0); + ui->pbtn_toboard_Upload->setEnabled(true); + uapi_file_transmit_stop(); +} + +void MainWindow::transmit_update_progress() +{ + uint32_t total_size=0; + uint32_t current_size=0; + transmit_get_data_count(&total_size,¤t_size); + if (transmit_download_or_upload == TRANSMIT_UPLOAD) { + ui->pbar_toboard->setMaximum(total_size); + ui->pbar_toboard->setValue(current_size); + } + if (transmit_download_or_upload == TRANSMIT_DOWNLOAD) { + ui->pbar_fromboard->setMaximum(total_size); + ui->pbar_fromboard->setValue(current_size); + } +} +void MainWindow::transmit_progress_start() +{ + transmit_timer_handle = new QTimer(this); + connect(transmit_timer_handle, SIGNAL(timeout()), this, SLOT(transmit_update_progress())); + // 进度条更新时间为60ms + transmit_timer_handle->start(60); +} +void MainWindow::at_check_send_status(bool flag) +{ + if(flag){ + ui_display("at cmd send success.\r\n",false); + }else{ + QMessageBox::warning(this, tr("AT"), tr("AT send fail!\r\n"), QMessageBox::Ok); + ui_display("at cmd send fail.\r\n",false); + } +} + +void MainWindow::dongle_suspend() +{ + if(ui->stkw_stage->currentIndex() == PAGE_COMPLETE){ + ui->tbw_stage_complete->setEnabled(false); + ui->pbtn_spp_connect->setEnabled(true); + }else if(ui->stkw_stage->currentIndex() == PAGE_BOARD){ + ui->tbw_stage_board->setEnabled(false); + } +} + +void MainWindow::dongle_resume() +{ + if(ui->stkw_stage->currentIndex() == PAGE_COMPLETE){ + ui->tbw_stage_complete->setEnabled(true); + ui->pbtn_spp_connect->setEnabled(true); + }else if(ui->stkw_stage->currentIndex() == PAGE_BOARD){ + ui->tbw_stage_board->setEnabled(true); + } +} + +void MainWindow::at_rx_display(int at_buf_len, u8Piont at_buf) +{ + Q_UNUSED(at_buf_len); + at_module_id at_module_id_temp; + at_cmd_id at_cmd_id_temp; + at_handler->at_get_id(&at_module_id_temp, &at_cmd_id_temp); + if (at_buf[0] == MODULE_BT && at_buf[1] == BT_CMD_RX_RESULT) { // 耦合测试RxCount + uint32_t rx_count = at_buf[2] + (at_buf[3] << 8); + ui->ledit_display_rx_count->setText(QString::number(rx_count)); + } else if (at_buf[0] == MODULE_MCU && at_buf[1] == MCU_CMD_CHECK_CONNECTED) { // Dongle是否已连接 + dongle_is_connected = true; + dongle_connected_times = 0; + dongle_resume(); + } else if (at_buf[0] == MODULE_MCU && at_buf[1] == MCU_CMD_RETURN_VALUE) { + for (int i = 0; i < 40; i++) { + qDebug("buf[%d] is %d.\r\n", i, at_buf[i]); + } + ui_display("cmd executed " + (QString)(at_buf[2] == 0 ? "Succ!" : "Fail!") + "\r\n",false); + if (at_buf[3] != 0) { + QByteArray data((const char*)&at_buf[4], at_buf[3]); + ui_display(QString(data),false); + } + } else if (at_buf[0] == at_module_id_temp && at_buf[1] == at_cmd_id_temp) { + ui_display("at receive success.\r\n",false); + } else { + ui_display("at receive fail.\r\n",false); + } + free(at_buf); +} + +void MainWindow::at_stackinfo_send() +{ + at_check_send_status(at_handler->at_send_cmd_string(MODULE_MCU,MCU_CMD_STACKINFO,NULL)); +} + +void MainWindow::at_fsrm_send() +{ + QString str = ui->ledit_at_fsrm->text(); + if (str.isEmpty()) { + QMessageBox::warning(this, tr("File Path"), tr("文件路径为空!"), QMessageBox::Ok); + return; + } + at_check_send_status(at_handler->at_send_cmd_string(MODULE_MCU,MCU_CMD_FSRM,str)); +} + +void MainWindow::at_mediamusicplay_send() +{ + uint8_t media_buf_cmd[2] = {0x00, 0x00}; + QString str = ui->ledit_at_mediamusicplay->text(); + if (str.isEmpty()) { + QMessageBox::warning(this, tr("File Path"), tr("文件路径为空!"), QMessageBox::Ok); + return; + } + QString media_sub_str; + QByteArray data((const char*)media_buf_cmd, 2); + for (int i = 0; i < data.size(); i++) { + media_sub_str += QString(data.at(i)); + } + str.prepend(media_sub_str); + at_check_send_status(at_handler->at_send_cmd_string(MODULE_AUDIO,AUDIO_CMD,str)); +} + +void MainWindow::at_mediamusicstop_send() +{ + uint8_t media_buf_cmd[2] = {0x00, 0x03}; + QString media_sub_str; + QByteArray data((const char*)media_buf_cmd, 2); + for (int i = 0; i < data.size(); i++) { + media_sub_str += QString(data.at(i)); + } + at_check_send_status(at_handler->at_send_cmd_string(MODULE_AUDIO,AUDIO_CMD,media_sub_str)); +} + +void MainWindow::at_mediaaudiorecord_send() +{ + uint8_t media_buf_cmd[2] = {0x01, 0x00}; + QString str = ui->ledit_at_mediaaudiorecord->text(); + if (str.isEmpty()) { + QMessageBox::warning(this, tr("File Path"), tr("文件路径为空!"), QMessageBox::Ok); + return; + } + QString media_sub_str; + QByteArray data((const char*)media_buf_cmd, 2); + for (int i = 0; i < data.size(); i++) { + media_sub_str += QString(data.at(i)); + } + str.prepend(media_sub_str); + at_check_send_status(at_handler->at_send_cmd_string(MODULE_AUDIO,AUDIO_CMD,str)); +} + +/* ----------------------- 耦合测试设置 ------------------------------------------------- */ +void MainWindow::at_bt_delay_ms_complete() +{ + QString str = ui->ledit_delay_ms->text(); + at_check_send_status(at_handler->at_send_cmd_string(MODULE_BT,BT_CMD_DELAY_MS,str)); +} + +void MainWindow::at_set_dongle_addr_complete() +{ + QString str = ui->ledit_dongle_mac->text(); + if (str.isEmpty() || str.size() != 12) { + QMessageBox::warning(this, tr("File Path"), tr("MAC地址为空!"), QMessageBox::Ok); + return; + } + at_check_send_status(at_handler->at_send_cmd_string(MODULE_BT,BT_CMD_DONGLE_MAC,str)); +} +void MainWindow::at_set_bt_format() +{ + ui->ledit_br_rx_channel_complete->setValidator(new MyValidator(0,78,this)); + ui->ledit_br_tx_channel_complete->setValidator(new MyValidator(0,78,this)); + ui->ledit_ble_rx_channel_complete->setValidator(new MyValidator(0,39,this)); + ui->ledit_ble_tx_channel_complete->setValidator(new MyValidator(0,39,this)); + ui->ledit_br_rx_PayloadLen_complete->setValidator(new MyValidator(0,27,this)); + ui->ledit_br_tx_PayloadLen_complete->setValidator(new MyValidator(0,27,this)); + ui->ledit_ble_tx_PayloadLen_complete->setValidator(new MyValidator(0,255,this)); + + ui->ledit_br_rx_channel_board->setValidator(new MyValidator(0,78,this)); + ui->ledit_br_tx_channel_board->setValidator(new MyValidator(0,78,this)); + ui->ledit_ble_rx_channel_board->setValidator(new MyValidator(0,39,this)); + ui->ledit_ble_tx_channel_board->setValidator(new MyValidator(0,39,this)); + ui->ledit_br_rx_PayloadLen_board->setValidator(new MyValidator(0,27,this)); + ui->ledit_br_tx_PayloadLen_board->setValidator(new MyValidator(0,27,this)); + ui->ledit_ble_tx_PayloadLen_board->setValidator(new MyValidator(0,255,this)); + ui->ledit_btlo_channel->setValidator(new MyValidator(0,78,this)); +} + +void MainWindow::at_check_bt_len(int packtype_index) +{ + QComboBox *cbox = qobject_cast(sender()); + int len=at_handler->at_get_packet_len(packtype_index); + QString name = cbox->objectName(); + if(name == "cbox_br_tx_PacketType_complete"){ + const MyValidator *validator=(MyValidator *)ui->ledit_br_tx_PayloadLen_complete->validator(); + delete validator; + ui->ledit_br_tx_PayloadLen_complete->setPlaceholderText("Length(0-"+QString::number(len)+")"); + ui->ledit_br_tx_PayloadLen_complete->setValidator(new MyValidator(0,len,this)); + }else if(name == "cbox_br_rx_PacketType_complete"){ + const MyValidator *validator=(MyValidator *)ui->ledit_br_rx_PayloadLen_complete->validator(); + delete validator; + ui->ledit_br_rx_PayloadLen_complete->setPlaceholderText("Length(0-"+QString::number(len)+")"); + ui->ledit_br_rx_PayloadLen_complete->setValidator(new MyValidator(0,len,this)); + }else if(name == "cbox_br_tx_PacketType_board"){ + const MyValidator *validator=(MyValidator *)ui->ledit_br_tx_PayloadLen_board->validator(); + delete validator; + ui->ledit_br_tx_PayloadLen_board->setPlaceholderText("Length(0-"+QString::number(len)+")"); + ui->ledit_br_tx_PayloadLen_board->setValidator(new MyValidator(0,len,this)); + }else if(name == "cbox_br_rx_PacketType_board"){ + const MyValidator *validator=(MyValidator *)ui->ledit_br_rx_PayloadLen_board->validator(); + delete validator; + ui->ledit_br_rx_PayloadLen_board->setPlaceholderText("Length(0-"+QString::number(len)+")"); + ui->ledit_br_rx_PayloadLen_board->setValidator(new MyValidator(0,len,this)); + } +} + +/* -----------------------耦合测试-整机段------------------------------------------------ */ +void MainWindow::at_get_rx_count_complete() +{ + at_check_send_status(at_handler->at_send_cmd_string(MODULE_BT,BT_CMD_GET_RX, NULL)); +} + +void MainWindow::at_bt_tx_complete() +{ + QString br_tx_switch = ui->cbox_br_tx_on_or_off_complete->currentText(); + QString channel = ui->ledit_br_tx_channel_complete->text(); + int packet_type_index = ui->cbox_br_tx_PacketType_complete->currentIndex(); + QString payload_len = ui->ledit_br_tx_PayloadLen_complete->text(); + int pattern_type_index = ui->cbox_br_tx_pattern_type_complete->currentIndex(); + QString format=at_handler->at_get_br_format(BT_MODE_BR_TX,br_tx_switch,channel,packet_type_index,payload_len,pattern_type_index); + if(format==NULL){ + QMessageBox::warning(this, tr("AT"), tr("length错误!"), QMessageBox::Ok); + } + at_check_send_status(at_handler->at_send_cmd_string(MODULE_BT,BT_CMD_BR_TX,format)); + dongle_is_connected = false; + dongle_suspend(); +} + +void MainWindow::at_bt_rx_complete() +{ + QString br_tx_switch = ui->cbox_br_tx_on_or_off_complete->currentText(); + QString channel = ui->ledit_br_rx_channel_complete->text(); + int packet_type_index = ui->cbox_br_rx_PacketType_complete->currentIndex(); + QString payload_len = ui->ledit_br_rx_PayloadLen_complete->text(); + int pattern_type_index = ui->cbox_br_rx_pattern_type_complete->currentIndex(); + QString format=at_handler->at_get_br_format(BT_MODE_BR_RX,br_tx_switch,channel,packet_type_index,payload_len,pattern_type_index); + if(format==NULL){ + QMessageBox::warning(this, tr("AT"), tr("length错误!"), QMessageBox::Ok); + } + at_check_send_status(at_handler->at_send_cmd_string(MODULE_BT,BT_CMD_BR_RX,format)); + dongle_is_connected = false; + dongle_suspend(); +} + +void MainWindow::at_ble_tx_complete() +{ + QString br_tx_switch = ui->cbox_ble_tx_on_or_off_complete->currentText(); + QString channel = ui->ledit_ble_tx_channel_complete->text(); + int pattern_type_index = ui->cbox_ble_tx_pattern_type_complete->currentIndex(); + QString payload_len = ui->ledit_ble_tx_PayloadLen_complete->text(); + int phy_type_index = ui->cbox_ble_tx_PacketType_complete->currentIndex(); + QString format=at_handler->at_get_ble_format(BT_MODE_BLE_TX,br_tx_switch,channel,pattern_type_index,payload_len,phy_type_index); + at_check_send_status(at_handler->at_send_cmd_string(MODULE_BT,BT_CMD_BLE_TX,format)); + dongle_is_connected = false; + dongle_suspend(); +} + +void MainWindow::at_ble_rx_complete() +{ + QString br_tx_switch = ui->cbox_ble_rx_on_or_off_complete->currentText(); + QString channel = ui->ledit_ble_rx_channel_complete->text(); + int phy_type_index = ui->cbox_ble_rx_PacketType_complete->currentIndex(); + QString format=at_handler->at_get_ble_format(BT_MODE_BLE_RX,br_tx_switch,channel,0,0,phy_type_index); + at_check_send_status(at_handler->at_send_cmd_string(MODULE_BT,BT_CMD_BLE_RX,format)); + dongle_is_connected = false; + dongle_suspend(); +} + +void MainWindow::at_custom_send() +{ + QString moduleId = ui->ledit_at_custom_moduleId->text(); + QString cmdId = ui->ledit_at_custom_CmdId->text(); + QString payload = ui->ledit_at_custom_Payload->text(); + bool ok; + at_check_send_status(at_handler->at_send_cmd_string((at_module_id)moduleId.toUInt(&ok,16),(at_cmd_id)cmdId.toUInt(&ok,16),payload)); +} +/* -----------------------传导测试-单板段------------------------------------------------ */ +void MainWindow::at_bt_tx_board() +{ + QString br_tx_switch = ui->cbox_br_tx_on_or_off_board->currentText(); + if (br_tx_switch.contains("ON") && bt_test_switch == true) { + QMessageBox::warning(this, tr("操作错误"), tr("应先关闭射频测试项!"), QMessageBox::Ok); + } + bt_test_switch = br_tx_switch.contains("ON") ? true : false; + QString channel = ui->ledit_br_tx_channel_board->text(); + int packet_type_index = ui->cbox_br_tx_PacketType_board->currentIndex(); + QString payload_len = ui->ledit_br_tx_PayloadLen_board->text(); + int pattern_type_index = ui->cbox_br_tx_pattern_type_board->currentIndex(); + QString format=at_handler->at_get_br_format(BT_MODE_BR_TX,br_tx_switch,channel,packet_type_index,payload_len,pattern_type_index); + if(format==NULL){ + QMessageBox::warning(this, tr("AT"), tr("length错误!"), QMessageBox::Ok); + } + at_check_send_status(at_handler->at_send_cmd_board(BT_MODE_BR_TX,format)); +} +void MainWindow::at_bt_rx_board() +{ + QString br_rx_switch = ui->cbox_br_rx_on_or_off_board->currentText(); + if (br_rx_switch.contains("ON") && bt_test_switch == true) { + QMessageBox::warning(this, tr("操作错误"), tr("应先关闭射频测试项!"), QMessageBox::Ok); + } + bt_test_switch = br_rx_switch.contains("ON") ? true : false; + QString channel = ui->ledit_br_rx_channel_board->text(); + int packet_type_index = ui->cbox_br_rx_PacketType_board->currentIndex(); + QString payload_len = ui->ledit_br_rx_PayloadLen_board->text(); + int pattern_type_index = ui->cbox_br_rx_pattern_type_board->currentIndex(); + QString format=at_handler->at_get_br_format(BT_MODE_BR_RX,br_rx_switch,channel,packet_type_index,payload_len,pattern_type_index); + if(format==NULL){ + QMessageBox::warning(this, tr("AT"), tr("length错误!"), QMessageBox::Ok); + } + at_check_send_status(at_handler->at_send_cmd_board(BT_MODE_BR_RX,format)); +} +void MainWindow::at_ble_tx_board() +{ + QString ble_tx_switch = ui->cbox_ble_tx_on_or_off_board->currentText(); + if (ble_tx_switch.contains("ON") && bt_test_switch == true) { + QMessageBox::warning(this, tr("操作错误"), tr("应先关闭射频测试项!"), QMessageBox::Ok); + } + bt_test_switch = ble_tx_switch.contains("ON") ? true : false; + QString channel = ui->ledit_ble_tx_channel_board->text(); + int pattern_type_index = ui->cbox_ble_tx_pattern_type_board->currentIndex(); + QString payload_len = ui->ledit_ble_tx_PayloadLen_board->text(); + int phy_type_index = ui->cbox_ble_tx_PacketType_board->currentIndex(); + QString format=at_handler->at_get_ble_format(BT_MODE_BLE_TX,ble_tx_switch,channel,pattern_type_index,payload_len,phy_type_index); + at_check_send_status(at_handler->at_send_cmd_board(BT_MODE_BLE_TX,format)); +} +void MainWindow::at_ble_rx_board() +{ + QString ble_rx_switch = ui->cbox_ble_rx_on_or_off_board->currentText(); + if (ble_rx_switch.contains("ON") && bt_test_switch == true) { + QMessageBox::warning(this, tr("操作错误"), tr("应先关闭射频测试项!"), QMessageBox::Ok); + } + bt_test_switch = ble_rx_switch.contains("ON") ? true : false; + QString channel = ui->ledit_ble_rx_channel_board->text(); + int phy_type_index = ui->cbox_ble_rx_PacketType_board->currentIndex(); + QString format=at_handler->at_get_ble_format(BT_MODE_BLE_RX,ble_rx_switch,channel,0,0,phy_type_index); + at_check_send_status(at_handler->at_send_cmd_board(BT_MODE_BLE_RX,format)); +} + +void MainWindow::at_bt_dutmode_board() +{ + QString bt_dutmode_switch = ui->cbox_btdutmode_on_or_off_board->currentText(); + if (bt_dutmode_switch.contains("ON") && bt_test_switch == true) { + QMessageBox::warning(this, tr("操作错误"), tr("应先关闭射频测试项!"), QMessageBox::Ok); + } + bt_test_switch = bt_dutmode_switch.contains("ON") ? true : false; + QString format=at_handler->at_get_switch_format(bt_dutmode_switch); + at_check_send_status(at_handler->at_send_cmd_board(BT_MODE_BTDUTMODE,format)); +} +void MainWindow::at_bt_btlo_board() +{ + QString format; + format += ui->ledit_btlo_channel->text()+","; + format += "7,"; + if(ui->cbox_btlo_on_or_off_board->currentText().contains("ON")){ + format+="1"; + }else{ + format+="2"; + } + at_check_send_status(at_handler->at_send_cmd_board(BT_MODE_BTLO,format)); +} + +void MainWindow::at_bt_btpwr_board() +{ + QString format; + format += ui->ledit_btpwr_powerchip->text()+","; + if(ui->cbox_btpwr_on_or_off_board->currentText().contains("ON")){ + format+="1"; + }else{ + format+="0"; + } + at_check_send_status(at_handler->at_send_cmd_board(BT_MODE_BTPWR,format)); +} + +void MainWindow::at_bt_wakeup() +{ + QString format= "012345678901234567890123456789"; + at_check_send_status(at_handler->at_send_cmd_board(MODE_MAX,format)); +} + +void MainWindow::at_bt_sleep() +{ + QString format= "AT^RMVO"; + at_check_send_status(at_handler->at_send_cmd_board(MODE_MAX,format)); +} +/* ----------------------------------------------------------------------------------- */ diff --git a/mainwindow.h b/mainwindow.h new file mode 100644 index 0000000..8a58b37 --- /dev/null +++ b/mainwindow.h @@ -0,0 +1,145 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include +#include +#include +#include +#include +#include "header.h" +#include "result_thread.h" +#include "common.h" +#include "at_data.h" +#include "QFileDialog" +#include "QMessageBox" +#include "QTime" + +#define COM_NUMBER 10 + +// 封装了UI上需要调用的所有函数接口 +QT_BEGIN_NAMESPACE +namespace Ui { +class MainWindow; +} +QT_END_NAMESPACE + +class MainWindow : public QMainWindow { + Q_OBJECT + +public: + MainWindow(QWidget *parent = nullptr); + ~MainWindow(); + +private: + Ui::MainWindow *ui; + /* ------------------------uart------------------------------- */ + Result_Thread *result_thread; + // 是否忽略uart数据,不回显 + bool uart_rx_Ignoring_display {false}; + // 是否有uart通路数据上报 + bool uart_rx_flag {false}; + bool dongle_is_connected {false}; + int dongle_connected_times {0}; + QStringList uart_get_enable_comm_or_port(); + QString uart_get_comm_or_port(int nIndex, bool bValue); + void uart_open(QString com,QString com_band); + void uart_close(); + /* ------------------------spp-------------------------------- */ + QTimer *spp_timer_handle {NULL}; + QTimer *spp_connected_handle {NULL}; + int dongle_try_count {0}; + int spp_try_count {0}; + + /* -----------------------transmit---------------------------- */ + QStringList transmit_fromborad_local_list; + QStringList tansmit_fromborad_borad_list; + QStringList transmit_toboard_local_list; + QStringList transmit_toboard_borad_list; + typedef enum{ + TRANSMIT_IDLE, + TRANSMIT_DOWNLOAD, + TRANSMIT_UPLOAD, + }transmit_mode; + // download is 1,uplaod is 2 + transmit_mode transmit_download_or_upload {TRANSMIT_IDLE}; + QTimer *transmit_timer_handle {NULL}; + void transmit_progress_start(); + /* -------------------------UI------------------------------- */ + enum ui_page{ + PAGE_COMPLETE, + PAGE_BOARD, + }; + void ui_setting_save(); + void ui_setting_read(); + void ui_display(QString str,bool inOrOut); + /* -------------------------AT------------------------------- */ + At_Process *at_handler; + void at_check_send_status(bool flag); + void at_set_bt_format(); + bool bt_test_switch {false}; + /* ------------------------end------------------------------ */ + +private slots: + /* --------------------------UI------------------------------ */ + void ui_tab_mainwindow_complete(); + void ui_tab_mainwindow_board(); + void ui_save_windows(); + /* -------------------------uart----------------------------- */ + void uart_process(); + void uart_send_data(); + void uart_rx_dispaly(int buf_len, u8Piont buf); + void uart_check_dtr_rts(); + void uart_com_select(); + void uart_com_switch(QString com); + void uart_baud_switch(QString baud); + /* -------------------------spp------------------------------- */ + void spp_connect(); + void spp_timer_callback(); + void spp_connected_callback(); + void dongle_suspend(); + void dongle_resume(); + /* -----------------------at/transmit---------------------------- */ + void at_rx_display(int at_buf_len, u8Piont at_buf); + void at_stackinfo_send(); + void at_fsrm_send(); + void at_mediamusicplay_send(); + void at_mediamusicstop_send(); + void at_mediaaudiorecord_send(); + void at_custom_send(); + void transmit_ls_rx_diaplay(int transmit_ls_size, vPiont transmit_ls_buff); + void transmit_rx_display(bool transmit_result_flag); + void transmit_update_progress(); + void transmit_fromboard_name_change(); + void transmit_fromboard_selectfilepath(); + void transmit_fromboard_getfilelist(); + void transmit_fromboard_download(); + void transmit_fromboard_delete(); + void transmit_fromboard_stop(); + void transmit_toboard_choosefile(); + void transmit_toboard_upload(); + void transmit_toboard_stop(); + /* ----------------------- 耦合测试设置 --------------------------- */ + void at_set_dongle_addr_complete(); + void at_bt_delay_ms_complete(); + void at_check_bt_len(int packtype_index); + /* -----------------------耦合测试-整机段-------------------------- */ + void at_get_rx_count_complete(); + void at_bt_tx_complete(); // BT长发(非信令) + void at_bt_rx_complete(); // BT长收(非信令) + void at_ble_tx_complete(); // BLE长发(非信令) + void at_ble_rx_complete(); // BLE长收(非信令) + /* -----------------------传导测试-单板段-------------------------- */ + void at_bt_tx_board(); // BT长发(非信令) + void at_bt_rx_board(); // BT长收(非信令) + void at_ble_tx_board(); // BLE长发(非信令) + void at_ble_rx_board(); // BLE长收(非信令) + void at_bt_dutmode_board(); + void at_bt_btlo_board(); + void at_bt_btpwr_board(); + void at_bt_wakeup(); + void at_bt_sleep(); + /* ------------------------------------------------------------- */ +}; +#endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui new file mode 100644 index 0000000..84ece13 --- /dev/null +++ b/mainwindow.ui @@ -0,0 +1,3848 @@ + + + MainWindow + + + + 0 + 0 + 890 + 707 + + + + + 黑体 + 50 + false + + + + Factory_Tools + + + + :/icon/windows.ico:/icon/windows.ico + + + 1.000000000000000 + + + Qt::LeftToRight + + + + + + 0 + 0 + 631 + 371 + + + + + Times New Roman + 10 + + + + true + + + QTextBrowser{background-color:rgb(26, 26, 26); + color:rgb(127, 255, 0)} + + + Qt::ScrollBarAlwaysOn + + + Qt::TextBrowserInteraction + + + + + + 0 + 370 + 891 + 311 + + + + + 黑体 + 50 + false + + + + 0 + + + + + false + + + + 0 + 0 + 891 + 291 + + + + + 0 + 0 + + + + + 黑体 + 12 + 50 + false + + + + ArrowCursor + + + 0 + + + + Debug + + + + + 0 + 0 + 771 + 261 + + + + + + + 790 + 30 + 75 + 23 + + + + + Times New Roman + 10 + 50 + false + + + + 发送 + + + + + + 790 + 83 + 75 + 23 + + + + + Times New Roman + 10 + 50 + false + + + + 清除发送 + + + + + + 789 + 157 + 88 + 16 + + + + + Times New Roman + 10 + 50 + false + + + + 加回车换行 + + + false + + + + + + To Board + + + + + 20 + 210 + 831 + 23 + + + + 0 + + + false + + + + + + 20 + 20 + 831 + 161 + + + + + Times New Roman + 10 + 50 + false + + + + Upload File + + + + + 10 + 40 + 121 + 21 + + + + + Times New Roman + 10 + 50 + false + + + + Local File Path: + + + + + + 10 + 100 + 121 + 20 + + + + + Times New Roman + 10 + 50 + false + + + + Board File Path: + + + + + + 730 + 100 + 75 + 23 + + + + + Times New Roman + 10 + 50 + false + + + + stop + + + + + + 140 + 100 + 471 + 20 + + + + + + + 640 + 40 + 161 + 23 + + + + + Times New Roman + 10 + 50 + false + + + + Choose File + + + + + + 640 + 100 + 75 + 23 + + + + + Times New Roman + 10 + 50 + false + + + + Upload + + + false + + + + + + 140 + 40 + 471 + 20 + + + + + + + + From Board + + + + + 20 + 20 + 701 + 71 + + + + + Times New Roman + 10 + 50 + false + + + + File Storage + + + + + 10 + 30 + 121 + 21 + + + + + Times New Roman + 10 + 50 + false + + + + Local File Path: + + + + + + 140 + 30 + 421 + 20 + + + + + + + 580 + 30 + 91 + 23 + + + + + Times New Roman + 10 + 50 + false + + + + .... + + + + + + + 20 + 110 + 701 + 101 + + + + + Times New Roman + 10 + 50 + false + + + + File Selector + + + + + 40 + 20 + 71 + 20 + + + + + Times New Roman + 10 + 50 + false + + + + File Path: + + + + + + 140 + 20 + 531 + 20 + + + + + + + 140 + 60 + 411 + 22 + + + + + + + 570 + 60 + 101 + 23 + + + + + Times New Roman + 9 + 50 + false + + + + Get file List + + + + + + 40 + 60 + 71 + 20 + + + + + Times New Roman + 10 + 50 + false + + + + File Name: + + + + + + 290 + 130 + 75 + 23 + + + + PushButton + + + + + + + 20 + 220 + 711 + 20 + + + + 0 + + + + + + 760 + 20 + 95 + 201 + + + + + + + + Times New Roman + 10 + 50 + false + + + + Download + + + false + + + + + + + + Times New Roman + 10 + 50 + false + + + + Delete + + + + + + + + Times New Roman + 10 + 50 + false + + + + Stop + + + + + + + + + AT命令 + + + + + 0 + 0 + 891 + 271 + + + + + 黑体 + 10 + 50 + false + + + + QTabWidget::West + + + QTabWidget::Triangular + + + 0 + + + Qt::ElideNone + + + + MCU + + + + + 20 + 10 + 831 + 211 + + + + Debug + + + + + 20 + 30 + 791 + 31 + + + + + 10 + + + + + StackInfo + + + + + + + 待开发 + + + + + + + 待开发 + + + + + + + 待开发 + + + + + + + 待开发 + + + + + + + + + 20 + 90 + 371 + 30 + + + + + + + + + + FSRM + + + + + + + + + 20 + 150 + 731 + 25 + + + + + + + 发送 + + + + + + + Qt::Horizontal + + + QSizePolicy::Minimum + + + + 30 + 20 + + + + + + + + + 黑体 + 8 + 50 + false + + + + module id + + + + + + + + 黑体 + 8 + 50 + false + + + + cmd id + + + + + + + payload + + + + + + + + + + MEDIA + + + + + 20 + 10 + 821 + 161 + + + + Media + + + + + 20 + 30 + 591 + 32 + + + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + + + Music Play + + + + + + + Music Stop + + + + + + + + + 20 + 80 + 591 + 32 + + + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + + + Audio Record + + + + + + + + + + BT + + + + + 20 + 10 + 821 + 111 + + + + 耦合测试设置 + + + + + 20 + 40 + 671 + 25 + + + + + + + + 0 + 0 + + + + 延时时间 + + + + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + ms + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + DongleMAC + + + + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + 耦合测试 + + + + + 20 + 10 + 831 + 121 + + + + BR EDR + + + + + 20 + 20 + 761 + 81 + + + + + + + + 0 + 0 + + + + Qt::DefaultContextMenu + + + + DH1 + + + + + DH3 + + + + + DH5 + + + + + 2-DH1 + + + + + 2-DH3 + + + + + 2-DH5 + + + + + 3-DH1 + + + + + 3-DH3 + + + + + 3-DH5 + + + + + + + + Length(0-27) + + + + + + + + 0 + 0 + + + + + ON + + + + + + + + + 0 + 0 + + + + + 10101010 + + + + + PRBS9 + + + + + 11110000 + + + + + + + + + 0 + 0 + + + + BR RX + + + + + + + + 0 + 0 + + + + 0 + + + + ON + + + + + + + + + 0 + 0 + + + + BR TX + + + + + + + + 0 + 0 + + + + + + + true + + + QLineEdit::Normal + + + Channel(0-78) + + + Qt::LogicalMoveStyle + + + false + + + + + + + + 0 + 0 + + + + + + + Channel(0-78) + + + + + + + + 0 + 0 + + + + Qt::DefaultContextMenu + + + + DH1 + + + + + DH3 + + + + + DH5 + + + + + 2-DH1 + + + + + 2-DH3 + + + + + 2-DH5 + + + + + 3-DH1 + + + + + 3-DH3 + + + + + 3-DH5 + + + + + + + + + 0 + 0 + + + + + 10101010 + + + + + PRBS9 + + + + + 11110000 + + + + + + + + Length(0-27) + + + + + + + + + + 20 + 140 + 831 + 111 + + + + BLE + + + + + 20 + 70 + 461 + 26 + + + + + 3 + + + + + + 0 + 0 + + + + + ON + + + + + + + + Channel(0-39) + + + + + + + + 0 + 0 + + + + Qt::DefaultContextMenu + + + + BLE 1M + + + + + BLE 2M + + + + + + + + + 0 + 0 + + + + BLE RX + + + + + + + + + 20 + 21 + 761 + 25 + + + + + + + + 0 + 0 + + + + BLE TX + + + + + + + + 0 + 0 + + + + + ON + + + + + + + + Channel(0-39) + + + + + + + + 0 + 0 + + + + + 10101010 + + + + + PRBS9 + + + + + 11110000 + + + + + + + + Length(0-255) + + + + + + + + 0 + 0 + + + + Qt::DefaultContextMenu + + + + BLE 1M + + + + + BLE 2M + + + + + + + + + + 560 + 70 + 221 + 25 + + + + + + + 获取RX Count + + + + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + + + + + + + false + + + + 0 + 0 + 911 + 291 + + + + + 黑体 + 12 + 50 + false + + + + 2 + + + + Debug + + + + + 0 + 0 + 771 + 261 + + + + + + + 790 + 30 + 75 + 23 + + + + + 黑体 + 10 + 50 + false + + + + 发送 + + + + + + 790 + 83 + 75 + 23 + + + + + 黑体 + 10 + 50 + false + + + + 清除发送 + + + + + + 789 + 157 + 88 + 16 + + + + + 黑体 + 10 + 50 + false + + + + 加回车换行 + + + false + + + + + + MCU + + + + + BT + + + + + 0 + 0 + 911 + 281 + + + + + 黑体 + 10 + 50 + false + + + + QTabWidget::West + + + QTabWidget::Triangular + + + 2 + + + Qt::ElideNone + + + false + + + + 非信令测试 + + + + + 20 + 140 + 831 + 111 + + + + BLE + + + + + 20 + 20 + 761 + 25 + + + + + + + + 0 + 0 + + + + BLE TX + + + + + + + + 0 + 0 + + + + + ON + + + + + OFF + + + + + + + + + + + Channel(0-39) + + + + + + + + 0 + 0 + + + + + 10101010 + + + + + PRBS9 + + + + + 11110000 + + + + + + + + Length(0-255) + + + + + + + + 0 + 0 + + + + Qt::DefaultContextMenu + + + + BLE 1M + + + + + BLE 2M + + + + + + + + + + 20 + 69 + 461 + 26 + + + + + 3 + + + + + + 0 + 0 + + + + + ON + + + + + OFF + + + + + + + + Channel(0-39) + + + + + + + + 0 + 0 + + + + Qt::DefaultContextMenu + + + + BLE 1M + + + + + BLE 2M + + + + + + + + + 0 + 0 + + + + BLE RX + + + + + + + + + + 20 + 10 + 831 + 121 + + + + BR EDR + + + + + 20 + 20 + 761 + 81 + + + + + + + + 0 + 0 + + + + + ON + + + + + OFF + + + + + + + + + 0 + 0 + + + + + 10101010 + + + + + PRBS9 + + + + + 11110000 + + + + + + + + + 0 + 0 + + + + Qt::DefaultContextMenu + + + + DH1 + + + + + DH3 + + + + + DH5 + + + + + 2-DH1 + + + + + 2-DH3 + + + + + 2-DH5 + + + + + 3-DH1 + + + + + 3-DH3 + + + + + 3-DH5 + + + + + + + + + 0 + 0 + + + + + + + Channel(0-78) + + + + + + + + 0 + 0 + + + + + 10101010 + + + + + PRBS9 + + + + + 11110000 + + + + + + + + + 0 + 0 + + + + BR RX + + + + + + + Length(0-27) + + + + + + + + 0 + 0 + + + + 0 + + + + ON + + + + + OFF + + + + + + + + Length(0-27) + + + + + + + + 0 + 0 + + + + BR TX + + + + + + + + 0 + 0 + + + + Qt::DefaultContextMenu + + + + DH1 + + + + + DH3 + + + + + DH5 + + + + + 2-DH1 + + + + + 2-DH3 + + + + + 2-DH5 + + + + + 3-DH1 + + + + + 3-DH3 + + + + + 3-DH5 + + + + + + + + + 0 + 0 + + + + + + + Channel(0-78) + + + + + + + + + + 信令测试 + + + + + 20 + 10 + 831 + 111 + + + + 信令 + + + + + 20 + 30 + 371 + 29 + + + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 0 + 0 + + + + BTDUTMODE + + + + + + + + 0 + 0 + + + + 信令测试: + + + + + + + + 0 + 0 + + + + + ON + + + + + OFF + + + + + + + + Qt::Horizontal + + + + 30 + 20 + + + + + + + + + + + 其他 + + + + + 20 + 20 + 791 + 121 + + + + 单音测试与功率调整 + + + + + 30 + 40 + 731 + 25 + + + + + 10 + + + + + channel(0-78) + + + + + + + + 0 + 0 + + + + 功率调整 + + + + + + + + 0 + 0 + + + + 单音测试 + + + + + + + + 0 + 0 + + + + + ON + + + + + OFF + + + + + + + + + 0 + 0 + + + + + ON + + + + + OFF + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + power chip(2-14) + + + + + + + + + + 20 + 140 + 791 + 111 + + + + BT_UART + + + + + 30 + 40 + 75 + 23 + + + + 唤醒 + + + + + + 150 + 40 + 75 + 23 + + + + 睡眠 + + + + + + + + + + + + + 650 + 0 + 224 + 389 + + + + + 5 + + + 20 + + + 5 + + + 20 + + + 20 + + + + + + 0 + 0 + + + + + 黑体 + 9 + 50 + false + + + + ArrowCursor + + + false + + + 115200 + + + 6 + + + true + + + + 4800 + + + + + 9600 + + + + + 14400 + + + + + 19200 + + + + + 38400 + + + + + 57600 + + + + + 115200 + + + + + 128000 + + + + + 230400 + + + + + 256000 + + + + + 460800 + + + + + 500000 + + + + + 512000 + + + + + 600000 + + + + + 750000 + + + + + 921600 + + + + + 1000000 + + + + + 1500000 + + + + + 2000000 + + + + + + + + + 0 + 0 + + + + + 黑体 + 9 + 50 + false + + + + + + + MAC地址 + + + + + + + + 0 + 0 + + + + 串口操作 + + + + + + + + 0 + 0 + + + + + 黑体 + 9 + 50 + false + + + + RTS + + + + + + + + 0 + 0 + + + + + 黑体 + 9 + 50 + false + + + + 保存窗口 + + + + + + + + 0 + 0 + + + + + 黑体 + 9 + 50 + false + + + + DTR + + + + + + + + 0 + 0 + + + + + 黑体 + 9 + 50 + false + + + + 16进制显示 + + + + + + + + 0 + 0 + + + + + 黑体 + 9 + 50 + false + + + + 打开串口 + + + true + + + false + + + false + + + false + + + + + + + false + + + + 0 + 0 + + + + + 黑体 + 9 + 50 + false + + + + 连接设备 + + + false + + + + + + + + 0 + 0 + + + + + 黑体 + 9 + 50 + false + + + + 16进制发送 + + + + + + + + 0 + 0 + + + + + 黑体 + 9 + 50 + false + + + + + COM1 + + + + + + + + + 0 + 0 + + + + + 黑体 + 9 + 50 + false + + + + 清除接收 + + + + + + + + 20 + 20 + + + + QPushButton{background-color: rgb(255, 0, 0);} + + + + + + + + + + + + + 0 + 0 + 890 + 22 + + + + + 黑体 + 12 + 50 + false + + + + + + 12 + + + + 菜单 + + + + + + + + + + true + + + true + + + + + true + + + true + + + 整机 + + + + 黑体 + 12 + + + + + + true + + + false + + + 单板 + + + + 12 + + + + + + dongle调试 + + + + 12 + + + + + + + MyComboBox + QComboBox +
custom.h
+ + mouse_clicked(bool) + +
+ + MyLineEdit + QLineEdit +
custom.h
+
+
+ + + + + + pbtn_open_uart + clicked() + MainWindow + uart_process() + + + 849 + 154 + + + 838 + 261 + + + + + pbtn_clear_display + clicked() + txtb_dispaly + clear() + + + 849 + 293 + + + 614 + 380 + + + + + ckbox_dtr + stateChanged(int) + MainWindow + uart_check_dtr_rts() + + + 815 + 334 + + + 882 + 371 + + + + + ckbox_rts + stateChanged(int) + MainWindow + uart_check_dtr_rts() + + + 711 + 334 + + + 758 + 373 + + + + + cbox_uart_com_select + mouse_clicked(bool) + MainWindow + uart_com_select() + + + 719 + 61 + + + 888 + 100 + + + + + pbtn_spp_connect + clicked() + MainWindow + spp_connect() + + + 811 + 245 + + + 888 + 267 + + + + + pbtn_toboard_stop + clicked() + MainWindow + transmit_toboard_stop() + + + 810 + 559 + + + 739 + 294 + + + + + pbtn_toboard_Upload + clicked() + MainWindow + transmit_toboard_upload() + + + 715 + 559 + + + 665 + 296 + + + + + pbtn_fromboard_getfilelist + clicked() + MainWindow + transmit_fromboard_getfilelist() + + + 670 + 609 + + + 654 + 408 + + + + + pbtn_send_data + clicked() + MainWindow + uart_send_data() + + + 844 + 469 + + + 865 + 411 + + + + + pbtn_fromboard_download + clicked() + MainWindow + transmit_fromboard_download() + + + 830 + 489 + + + 849 + 420 + + + + + pbtn_fromboard_selectfilepath + clicked() + MainWindow + transmit_fromboard_selectfilepath() + + + 665 + 489 + + + 673 + 417 + + + + + pbtn_clear_senddata + clicked() + tedit_input_data + clear() + + + 866 + 522 + + + 700 + 591 + + + + + pbtn_fromboard_stop + clicked() + MainWindow + transmit_fromboard_stop() + + + 855 + 605 + + + 676 + 315 + + + + + pbtn_fromboard_delete + clicked() + MainWindow + transmit_fromboard_delete() + + + 855 + 547 + + + 671 + 351 + + + + + ledit_formboad_bordpath + textEdited(QString) + MainWindow + transmit_fromboard_name_change() + + + 499 + 566 + + + 688 + 273 + + + + + pbtn_toboard_choosefile + clicked() + MainWindow + transmit_toboard_choosefile() + + + 736 + 499 + + + 660 + 343 + + + + + action_complete + triggered(bool) + MainWindow + ui_tab_mainwindow_complete() + + + -1 + -1 + + + 468 + 363 + + + + + action_board + triggered(bool) + MainWindow + ui_tab_mainwindow_board() + + + -1 + -1 + + + 539 + 363 + + + + + pbtn_board + clicked() + tedit_input_data_board + clear() + + + 822 + 522 + + + 767 + 568 + + + + + pbtn_send_data_board + clicked() + MainWindow + uart_send_data() + + + 842 + 469 + + + 888 + 484 + + + + + pbtn_at_mediaaudiorecord + clicked() + MainWindow + at_mediaaudiorecord_send() + + + 646 + 535 + + + 643 + 285 + + + + + pbtn_at_stackinfo + clicked() + MainWindow + at_stackinfo_send() + + + 160 + 485 + + + 654 + 412 + + + + + pbtn_at_fsrm + clicked() + MainWindow + at_fsrm_send() + + + 428 + 544 + + + 655 + 254 + + + + + pbtn_at_mediamusicstop + clicked() + MainWindow + at_mediamusicstop_send() + + + 646 + 485 + + + 656 + 381 + + + + + pbtn_at_mediamusicplay + clicked() + MainWindow + at_mediamusicplay_send() + + + 545 + 485 + + + 654 + 330 + + + + + pbtn_br_tx_complete + clicked() + MainWindow + at_bt_tx_complete() + + + 156 + 481 + + + 636 + 372 + + + + + pbtn_br_rx_complete + clicked() + MainWindow + at_bt_rx_complete() + + + 156 + 519 + + + 637 + 335 + + + + + pbtn_ble_tx_complete + clicked() + MainWindow + at_ble_tx_complete() + + + 149 + 603 + + + 639 + 361 + + + + + pbtn_ble_rx_complete + clicked() + MainWindow + at_ble_rx_complete() + + + 141 + 652 + + + 444 + 354 + + + + + pbtn_br_tx_board + clicked() + MainWindow + at_bt_tx_board() + + + 156 + 481 + + + 639 + 325 + + + + + pbtn_br_rx_board + clicked() + MainWindow + at_bt_rx_board() + + + 156 + 519 + + + 646 + 169 + + + + + pbtn_btdutmode_board + clicked() + MainWindow + at_bt_dutmode_board() + + + 265 + 484 + + + 646 + 210 + + + + + pbtn_ble_tx_board + clicked() + MainWindow + at_ble_tx_board() + + + 139 + 581 + + + 633 + 248 + + + + + pbtn_ble_rx_board + clicked() + MainWindow + at_ble_rx_board() + + + 139 + 630 + + + 643 + 204 + + + + + pbtn_get_rx_count + clicked() + MainWindow + at_get_rx_count_complete() + + + 674 + 652 + + + 647 + 134 + + + + + pbtn_delay_time + clicked() + MainWindow + at_bt_delay_ms_complete() + + + 134 + 492 + + + 637 + 161 + + + + + pbtn_donglemac + clicked() + MainWindow + at_set_dongle_addr_complete() + + + 581 + 492 + + + 653 + 126 + + + + + cbox_uart_com_select + activated(QString) + MainWindow + uart_com_switch(QString) + + + 702 + 55 + + + 764 + 76 + + + + + cbox_uart_baud_select + activated(QString) + MainWindow + uart_baud_switch(QString) + + + 712 + 103 + + + 744 + 133 + + + + + cbox_br_tx_PacketType_complete + activated(int) + MainWindow + at_check_bt_len(int) + + + 514 + 479 + + + 649 + 73 + + + + + cbox_br_rx_PacketType_complete + activated(int) + MainWindow + at_check_bt_len(int) + + + 514 + 517 + + + 647 + 55 + + + + + cbox_br_tx_PacketType_board + activated(int) + MainWindow + at_check_bt_len(int) + + + 514 + 479 + + + 639 + 116 + + + + + cbox_br_rx_PacketType_board + activated(int) + MainWindow + at_check_bt_len(int) + + + 514 + 517 + + + 638 + 85 + + + + + pushButton + clicked() + MainWindow + ui_save_windows() + + + 702 + 285 + + + 647 + 236 + + + + + pbtn_btlo_board + clicked() + MainWindow + at_bt_btlo_board() + + + 144 + 502 + + + 642 + 200 + + + + + pbtn_btpwr_board + clicked() + MainWindow + at_bt_btpwr_board() + + + 589 + 502 + + + 684 + 304 + + + + + pbtn_at_custom_send + clicked() + MainWindow + at_custom_send() + + + 169 + 602 + + + 661 + 190 + + + + + pushButton_3 + clicked() + MainWindow + at_bt_wakeup() + + + 122 + 615 + + + 957 + 601 + + + + + pushButton_4 + clicked() + MainWindow + at_bt_sleep() + + + 244 + 615 + + + 970 + 548 + + + + + + transmit_toboard_choosefile() + uart_send_data() + uart_process() + check_word_wrap() + check_hex_display() + at_stackinfo_send() + uart_check_dtr_rts() + uart_com_select() + transmit_fromboard_selectfilepath() + transmit_fromboard_getfilelist() + transmit_fromboard_download() + transmit_toboard_upload() + transmit_toboard_stop() + transmit_fromboard_delete() + transmit_fromboard_stop() + spp_connect() + transmit_fromboard_name_change() + at_fsrm_send() + at_mediamusicplay_send() + at_mediamusicstop_send() + at_mediaaudiorecord_send() + ui_tab_mainwindow_complete() + ui_tab_mainwindow_board() + at_bt_tx_complete() + at_bt_rx_complete() + at_ble_tx_complete() + at_ble_rx_complete() + at_bt_rx_board() + at_bt_tx_board() + at_ble_tx_board() + at_ble_rx_board() + at_bt_dutmode_board() + at_bt_delay_ms_complete() + at_set_dongle_addr_complete() + at_get_rx_count_complete() + uart_com_switch(QString) + uart_baud_switch(QString) + at_check_bt_len(int) + ui_save_windows() + at_bt_btlo_board() + at_bt_btpwr_board() + at_custom_send() + at_bt_wakeup() + at_bt_sleep() + +
diff --git a/mythread.cpp b/mythread.cpp new file mode 100644 index 0000000..6d0a5db --- /dev/null +++ b/mythread.cpp @@ -0,0 +1,61 @@ +#include "mythread.h" + +MyThread::MyThread() +{ + stopped = false; + pauseFlag = false; +} + +MyThread::~MyThread() +{ +} + +void MyThread::process() +{ +} + +void MyThread::run() +{ + while (true) { + QMutexLocker locker(&m_lock_stop); + if (stopped) { + stopped = false; + qDebug() << "线程终止"; + return; + } + if (pauseFlag) { + m_lock_Pause.lock(); + condition.wait(&m_lock_Pause); + m_lock_Pause.unlock(); + } + process(); + } + stopped = false; + pauseFlag = false; +} + +void MyThread::pause() +{ + if (this->isRunning() && !pauseFlag) { + pauseFlag = true; + } +} + +void MyThread::resume() +{ + if (this->isRunning() && pauseFlag) { + pauseFlag = false; + condition.wakeAll(); + } +} + +void MyThread::stop() +{ + if (this->isRunning()) { + if (pauseFlag) { + this->resume(); + } + QMutexLocker locker(&m_lock_stop); + stopped = true; + } +} diff --git a/mythread.h b/mythread.h new file mode 100644 index 0000000..20bce24 --- /dev/null +++ b/mythread.h @@ -0,0 +1,33 @@ +#ifndef MYTHREAD_H +#define MYTHREAD_H + +#include +#include +#include +#include +#include +#include + /*-----------------------rx回调函数线程-------------------------------*/ + // 当回调函数执行时,会唤醒此线程。 根据回调函数返回值执行对应函数。 +class MyThread : public QThread +{ + public: + explicit MyThread(); + ~MyThread(); + void stop(); + + protected: + void run() override final; + virtual void process(); + public slots: + void pause(); + void resume(); + + private: + QMutex m_lock_stop; + volatile bool stopped; + QMutex m_lock_Pause; + std::atomic_bool pauseFlag; + QWaitCondition condition; +}; +#endif // MYTHREAD_H diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..15e8891 --- /dev/null +++ b/readme.txt @@ -0,0 +1 @@ +本软件使用QT库进行UI界面设计。 \ No newline at end of file diff --git a/result_thread.cpp b/result_thread.cpp new file mode 100644 index 0000000..30a8ca3 --- /dev/null +++ b/result_thread.cpp @@ -0,0 +1,102 @@ +#include "result_thread.h" + +struct result_info g_result_info={0,NULL,0,NULL,false,NONE_DATA,0,NULL}; +QMutex g_result_thread_mlock; +QWaitCondition g_result_thread_condition; + + + +Result_Thread::Result_Thread(QObject *parent) +{ + obj=parent; +} + +Result_Thread::~Result_Thread() +{ +} + +// 给 UI 线程发送消息 +void Result_Thread::process() +{ + g_result_thread_mlock.lock(); + g_result_thread_condition.wait(&g_result_thread_mlock, MLOCK_TIMEOUT); + switch (g_result_info.result_thread_flag) { + case UART_RX_DATA: + QMetaObject::invokeMethod(obj, "uart_rx_dispaly", Q_ARG(int, g_result_info.uart_rx_buf_len),Q_ARG(u8Piont,g_result_info.uart_rx_buf)); // 让UI线程执行 Uart_Rx_Dispaly 槽函数 + g_result_info.result_thread_flag = NONE_DATA; + break; + case LS_RESULT_DATA: + QMetaObject::invokeMethod(obj, "transmit_ls_rx_diaplay",Q_ARG(int , g_result_info.transmit_ls_size),Q_ARG(vPiont,g_result_info.transmit_ls_buff)); + g_result_info.result_thread_flag = NONE_DATA; + break; + case TRANSMIT_FILE_DATA: + QMetaObject::invokeMethod(obj, "transmit_rx_display",Q_ARG(bool, g_result_info.transmit_result_flag)); + g_result_info.transmit_result_flag = false; + g_result_info.result_thread_flag = NONE_DATA; + break; + case AT_RESULT_DATA: + QMetaObject::invokeMethod(obj, "at_rx_display",Q_ARG(int, g_result_info.at_result_len),Q_ARG(u8Piont,g_result_info.at_result_buf)); + g_result_info.result_thread_flag = NONE_DATA; + break; + default: + break; + } + g_result_thread_mlock.unlock(); +} + +uint32_t uart_callback(void *buf, uint32_t buf_len) +{ + g_result_info.uart_rx_buf_len = (int)buf_len; + // rx的数据不包含\0,所以多分配1字节。 + g_result_info.uart_rx_buf=(uint8_t *)malloc(buf_len); + memset(g_result_info.uart_rx_buf,0,buf_len); + memcpy_s(g_result_info.uart_rx_buf, buf_len, (uint8_t *)buf, buf_len); + g_result_info.result_thread_flag = UART_RX_DATA; + g_result_thread_mlock.lock(); + g_result_thread_condition.wakeAll(); + g_result_thread_mlock.unlock(); + return 0; +} + +uint32_t ls_callback(uint32_t size, void *buff) +{ + g_result_info.transmit_ls_buff = (uapi_ls_info_t *)malloc(size * sizeof(uapi_ls_info_t)+1); + memcpy_s(g_result_info.transmit_ls_buff, size * sizeof(uapi_ls_info_t), (uapi_ls_info_t *)buff, size * sizeof(uapi_ls_info_t)); + g_result_info.transmit_ls_size = static_cast(size); + g_result_info.result_thread_flag = LS_RESULT_DATA; + g_result_thread_mlock.lock(); + g_result_thread_condition.wakeAll(); + g_result_thread_mlock.unlock(); + return 0; +} + +uint32_t transmit_callback(bool is_finished, uintptr_t usr_data) +{ + g_result_info.transmit_result_flag = is_finished; + Q_UNUSED(usr_data); + g_result_info.result_thread_flag = TRANSMIT_FILE_DATA; + g_result_thread_mlock.lock(); + g_result_thread_condition.wakeAll(); + g_result_thread_mlock.unlock(); + return 0; +} + +uint32_t at_callback(void *buf, uint32_t len) +{ + uint8_t * at_buff = (uint8_t *)malloc(len); + memcpy_s(at_buff, len , buf, len); + g_result_info.at_result_buf = (uint8_t *)at_buff; + g_result_info.at_result_len = len; + g_result_info.result_thread_flag = AT_RESULT_DATA; + g_result_thread_mlock.lock(); + g_result_thread_condition.wakeAll(); + g_result_thread_mlock.unlock(); + return 0; +} +void transmit_get_data_count(uint32_t *total_size, uint32_t *current_size) +{ + uapi_transmit_progress transmint_data_count; + uapi_transmit_process(&transmint_data_count); + *total_size=transmint_data_count.total_size; + *current_size=transmint_data_count.transmited_size; +} diff --git a/result_thread.h b/result_thread.h new file mode 100644 index 0000000..5a1671d --- /dev/null +++ b/result_thread.h @@ -0,0 +1,58 @@ +#ifndef RESULT_THREAD_H +#define RESULT_THREAD_H +#include "mythread.h" +#include "common.h" +#include +#include +#include +#include +#include + +#define BUF_SIZE 4096 +#define MLOCK_TIMEOUT 2000 +enum get_data_flag +{ + NONE_DATA = -1, + UART_RX_DATA = 0, + LS_RESULT_DATA, + TRANSMIT_FILE_DATA, + AT_RESULT_DATA, +}; + +struct result_info{ + // uart收到的数据 + int uart_rx_buf_len; + uint8_t *uart_rx_buf; + + // ls数据大小和内容 + int transmit_ls_size; + uapi_ls_info_t *transmit_ls_buff; + + // 传输文件是否成功 + bool transmit_result_flag; + + // 当前回调函数标记 + int result_thread_flag; + + // at调用返回 + int at_result_len; + uint8_t *at_result_buf; +}; + +class Result_Thread : public MyThread +{ +public: + Result_Thread(QObject *parent = 0); + ~Result_Thread(); +protected: + void process() override final; +private: + QObject *obj; +}; + +uint32_t uart_callback(void *buf, uint32_t buf_len); +uint32_t ls_callback(uint32_t size, void *buff); +uint32_t transmit_callback(bool is_finished, uintptr_t usr_data); +uint32_t at_callback(void *buf, uint32_t len); +void transmit_get_data_count(uint32_t *total_size, uint32_t *current_size); +#endif // RESULT_THREAD_H diff --git a/src/header.h b/src/header.h new file mode 100644 index 0000000..f49da08 --- /dev/null +++ b/src/header.h @@ -0,0 +1,53 @@ +#ifndef HEADER_H +#define HEADER_H +#include + +#ifdef __cplusplus +extern "C" { +#endif +/*-----------------------业务处理-------------------------------*/ +typedef struct { + uint32_t total_size; + uint32_t transmited_size; +} uapi_transmit_progress; + +typedef enum { + FAIL = 0x0, + SUCC = 0x1, +} uapi_errcode; + +typedef struct { + uint16_t sn; + uint8_t name_len; + uint8_t is_dir; + uint32_t file_size; + uint8_t name[0xFF]; +} uapi_ls_info_t; + + + +typedef uint32_t (*uart_rx_function)(void *buf, uint32_t len); +typedef uint32_t (*at_result_callback)(void *buf, uint32_t len); +typedef uint32_t (*transmit_ls_result)(uint32_t size,void *buff); +typedef uint32_t (*transmit_result_hook)(bool is_finished, uintptr_t usr_data); + + +uapi_errcode uapi_at_send(uint8_t module_id, uint8_t cmd_id, uint8_t *pkt, uint32_t pkt_size,at_result_callback callback); +uapi_errcode uapi_file_download(char* board_file_path,char* local_file_path,transmit_result_hook handler); +uapi_errcode uapi_file_upload(char* board_file_path,char* local_file_path,transmit_result_hook handler); +uapi_errcode uapi_ls_send(char *path, uint32_t path_len,transmit_ls_result callback); // ls +uapi_errcode uapi_file_delete(char *board_file_path, uint32_t board_file_path_len); +uapi_errcode uapi_file_transmit_stop(void); +uapi_errcode uapi_transmit_process(uapi_transmit_progress *data); +/*----------------------------------------------------------*/ +uapi_errcode uapi_uart_open(const char *com, uint32_t baud); +uapi_errcode uapi_uart_tx_data(void *buf, uint32_t buf_len); +uapi_errcode uapi_uart_callback_register(uart_rx_function callback); +uapi_errcode uapi_uart_close(void); +uapi_errcode uapi_uart_set_rts_dtr(int rts_flag, int dtr_flag); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/untitled_zh_CN.ts b/untitled_zh_CN.ts new file mode 100644 index 0000000..806770f --- /dev/null +++ b/untitled_zh_CN.ts @@ -0,0 +1,844 @@ + + + + + MainWindow + + + 打开串口 + + + + + AT命令 + + + + + + + 发送 + + + + + + + Debug + + + + + + 清除发送 + + + + + From Board + From Boad + + + + + File Storage + + + + + + Local File Path: + + + + + Factory_Tools + + + + + To Board + + + + + Upload File + + + + + Board File Path: + + + + + Choose File + + + + + .... + + + + + File Selector + + + + + File Path: + + + + + Get file List + + + + + File Name: + + + + + Download + + + + + Delete + + + + + Stop + + + + + + MCU + + + + + + + + 待开发 + + + + + FSRM + + + + + module id + + + + + cmd id + + + + + payload + + + + + MEDIA + + + + + Media + + + + + Music Play + + + + + Music Stop + + + + + Audio Record + + + + + + BT + + + + + + + + Channel(0-78) + + + + + + + + Channel(0-39) + + + + + + Length(0-255) + + + + + BTDUTMODE + + + + + 信令测试: + + + + + 其他 + + + + + 单音测试与功率调整 + + + + + channel(0-78) + + + + + 功率调整 + + + + + 单音测试 + + + + + power chip(2-14) + + + + + BT_UART + + + + + 唤醒 + + + + + 睡眠 + + + + + dongle调试 + + + + + + + + + + + OFF + + + + + 耦合测试设置 + + + + + 延时时间 + + + + + ms + + + + + DongleMAC + + + + + 耦合测试 + + + + + + BR EDR + + + + + + + + 2-DH5 + + + + + + + + Length(0-27) + Length + + + + + + + + DH1 + + + + + + + + + + + + + + + ON + + + + + + BR TX + + + + + + + + + + 10101010 + + + + + + + + + + PRBS9 + + + + + + + + + + 11110000 + + + + + + + + DH3 + + + + + + + + DH5 + + + + + + + + 2-DH1 + + + + + + + + 2-DH3 + + + + + + + + 3-DH1 + + + + + + + + 3-DH3 + + + + + + + + 3-DH5 + + + + + + BR RX + + + + + + BLE + + + + + + BLE TX + + + + + + + + BLE 1M + + + + + + + + BLE 2M + + + + + + BLE RX + + + + + 非信令测试 + + + + + 信令测试 + + + + + 菜单 + + + + + 单板 + + + + + 整机 + + + + + 4800 + + + + + 9600 + + + + + 14400 + + + + + 19200 + + + + + 38400 + + + + + 57600 + + + + + + 115200 + + + + + 获取RX Count + + + + + 信令 + + + + + 128000 + + + + + 230400 + + + + + 256000 + + + + + 460800 + + + + + 500000 + + + + + 512000 + + + + + 600000 + + + + + 750000 + + + + + 921600 + + + + + 1000000 + + + + + 1500000 + + + + + 2000000 + + + + + 连接设备 + + + + + MAC地址 + + + + + + 加回车换行 + + + + + + Upload + + + + + stop + + + + + StackInfo + + + + + PushButton + + + + + 串口操作 + + + + + 清除接收 + + + + + 保存窗口 + + + + + 16进制显示 + + + + + 16进制发送 + + + + + RTS + + + + + DTR + + + + + COM1 + + + + + 串口 + + + + + 打开串口失败! + + + + + 注册表 + + + + + 无法打开注册表! + + + + + ls fail! + + + + + + 文件大小为0! + + + + + 文件下载启动失败! + + + + + + + + + AT + + + + + AT send fail! + + + + + + ls + + + + + + + + + + + + File Path + File + + + + + + + + + + 文件路径为空! + + + + + + Board File Name + + + + + Downloade + + + + + delete + + + + + delete file fail! + + + + + + 文件路径为空! + + + + + 文件上传启动失败! + + + + + + MAC地址为空! + + + + + + + + length错误! + + + + + + + + + 操作错误 + + + + + + + + + 应先关闭射频测试项! + + + + + 请选择正确的文件! + + + + + QObject + + + HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM + + + +