diff --git a/mainwindow.cpp b/mainwindow.cpp index 586cb28..4dd7e9a 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -15,7 +15,8 @@ using namespace iflytop; using namespace clst; using namespace std; -static MainWindow *m_mainWindow; +static MainWindow *m_mainWindow; +static CLSTControler *m_clstc; #define TAG "MainWindow" static const char *fmt(const char *fmt, ...) { @@ -47,6 +48,25 @@ static const uint32_t str2int(QString str) { static QSerialPort G_SerialPort; static QTDataChannel G_QTDataChannel; +static const QString zaferror_to_str(zaf_error_code_t value) { + if (value == kaf_ec_overtime) { + return "操作超时"; + } else if (value == kaf_ec_device_notopen) { + return "设备未打开"; + } else { + return "未知错误"; + } +} + +#define DO(action) \ + { \ + zaf_error_code_t ecode = action; \ + if (ecode != kaf_ec_success) { \ + ui->informationBrowser->setText(zaferror_to_str(ecode)); \ + return; \ + } \ + } + void MainWindow::log_output(QtMsgType type, const QMessageLogContext &context, const QString &msg) { // QString text; // text.append(msg); @@ -117,11 +137,43 @@ void MainWindow::constructUI() { ui->serialPortRefreshKey->setEnabled(true); } }); + + /******************************************************************************* + * 刷新页面 * + *******************************************************************************/ + connect(ui->refreshPageKey, &QPushButton::clicked, this, [=](bool check) { // + + }); + + /******************************************************************************* + * 保存配置 * + *******************************************************************************/ + connect(ui->storageConfigKey, &QPushButton::clicked, this, [=](bool check) { // + DO(m_clstc->storageConfigs()); + ui->informationBrowser->setText("保存配置成功"); + }); + + /******************************************************************************* + * 重启设备 * + *******************************************************************************/ + connect(ui->rebootDeviceKey, &QPushButton::clicked, this, [=](bool check) { // + DO(m_clstc->reboot()); + ui->informationBrowser->setText("重启设备成功"); + }); + + /******************************************************************************* + * 恢复出厂设置 * + *******************************************************************************/ + connect(ui->factoryResetKey, &QPushButton::clicked, this, [=](bool check) { // + DO(m_clstc->factoryReset()); + ui->informationBrowser->setText("恢复出厂设置成功"); + }); } MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { G_QTDataChannel.bind(&G_SerialPort); CLSTControler::ins()->initialize(&G_QTDataChannel); + m_clstc = CLSTControler::ins(); ui->setupUi(this); m_mainWindow = this; @@ -133,6 +185,27 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi // qInstallMessageHandler(log_output); connect(this, SIGNAL(doinui_signal(QFunction)), this, SLOT(doinui_slot(QFunction))); constructUI(); + + m_clstc->regRawDataListener([this](uart_message_type_t type, uint8_t *data, size_t len) { + QString text; + if (type == kuart_raw_tx) { + text.append("TX: "); + for (size_t i = 0; i < len; i++) { + text.append(fmt("%02X ", data[i])); + } + } else if (type == kuart_raw_rx) { + text.append("RX: "); + for (size_t i = 0; i < len; i++) { + text.append(fmt("%02X ", data[i])); + } + } + emit doinui_signal(QFunction([this, text]() { + if (ui->instructionPreview->document()->lineCount() > 20) { + ui->instructionPreview->clear(); + } + ui->instructionPreview->append(text); + })); + }); } MainWindow::~MainWindow() { delete ui; } \ No newline at end of file diff --git a/src/camera_light_src_timing_controller/clst_controler.cpp b/src/camera_light_src_timing_controller/clst_controler.cpp index fa658ff..8fc4671 100644 --- a/src/camera_light_src_timing_controller/clst_controler.cpp +++ b/src/camera_light_src_timing_controller/clst_controler.cpp @@ -140,7 +140,11 @@ zaf_error_code_t CLSTControler::sendPacket(zaf_packet_header_t *packet, uint32_t } if (!m_channel) { - return kaf_ec_overtime; + return kaf_ec_device_notopen; + } + + if (m_channel->isOpen() == false) { + return kaf_ec_device_notopen; } if (m_raw_data_cb) { @@ -254,7 +258,7 @@ zaf_error_code_t CLSTControler::factoryReset() { txdata[txpacklen - 2] = PACKET_TAIL & 0xFF; txdata[txpacklen - 1] = (PACKET_TAIL >> 8) & 0xFF; - zaf_error_code_t ecode = sendPacket(txpacket, txpacklen, 1000); + zaf_error_code_t ecode = sendPacket(txpacket, txpacklen, 100); if (ecode != kaf_ec_success) return ecode; return kaf_ec_success; diff --git a/src/camera_light_src_timing_controller/clst_controler.hpp b/src/camera_light_src_timing_controller/clst_controler.hpp index 79c2787..dbd0c1a 100644 --- a/src/camera_light_src_timing_controller/clst_controler.hpp +++ b/src/camera_light_src_timing_controller/clst_controler.hpp @@ -59,10 +59,8 @@ class CLSTControler { RxReceiptContext m_rxReceiptContext; mutex m_rxReceiptContext_lock; - mutex m_tx_lock; - raw_data_cb_t m_raw_data_cb; uint16_t txindex = 0; diff --git a/zaf_protocol b/zaf_protocol index 7d27a34..19d549a 160000 --- a/zaf_protocol +++ b/zaf_protocol @@ -1 +1 @@ -Subproject commit 7d27a34ee665cc3cba2d12ff357e774e34871b38 +Subproject commit 19d549a123f6dcf6e1a47b012a64bf659740638d