From 4c9e6b55ac7baee6cb5697dc706c90e05bfeffa5 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Tue, 4 Jun 2024 22:03:57 +0800 Subject: [PATCH] update --- CMakeLists.txt | 1 + a8000_protocol | 2 +- iflytop_canbus/iflytop_canbus_master.cpp | 3 ++ iflytop_canbus/iflytop_canbus_master.hpp | 2 + src/mainwindow.cpp | 2 + src/mainwindow.ui | 2 +- src/tab/board_ext_tab.cpp | 11 +++++ src/tab/code_scaner_tab.cpp | 80 ++++++++++++++++++++++++++++++++ src/tab/code_scaner_tab.hpp | 43 +++++++++++++++++ src/tab/module_opera_tab.cpp | 5 +- 10 files changed, 148 insertions(+), 3 deletions(-) create mode 100644 src/tab/code_scaner_tab.cpp create mode 100644 src/tab/code_scaner_tab.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index d1e3cfd..92d553e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,6 +51,7 @@ set(PROJECT_SOURCES src/tab/module_opera_tab.cpp src/tab/board_ext_tab.cpp src/tab/mini_servo_tab.cpp + src/tab/code_scaner_tab.cpp a8000_protocol/api/apibasic/errorcode.cpp diff --git a/a8000_protocol b/a8000_protocol index 97b8fb4..a85673b 160000 --- a/a8000_protocol +++ b/a8000_protocol @@ -1 +1 @@ -Subproject commit 97b8fb482b00a1eef33677f582e4ecbf2ed6db25 +Subproject commit a85673b9c1b9a54c0e91a3e3f4299106a749e56d diff --git a/iflytop_canbus/iflytop_canbus_master.cpp b/iflytop_canbus/iflytop_canbus_master.cpp index 1608c45..d7dd7d7 100644 --- a/iflytop_canbus/iflytop_canbus_master.cpp +++ b/iflytop_canbus/iflytop_canbus_master.cpp @@ -107,6 +107,9 @@ void IflytopCanbusMaster::readreg(int32_t device_id, int32_t regaddr, int32_t *v int32_t IflytopCanbusMaster::getAck(int32_t index) { return *(int32_t *)(&m_receipt_frame->data[index]); } +uint8_t *IflytopCanbusMaster::getAckBuf() { return m_receipt_frame->data; } +int32_t IflytopCanbusMaster::getAckBufLen() { return m_receipt_len - sizeof(zcr_cmd_header_t); } + void IflytopCanbusMaster::writereg(int32_t device_id, int32_t regaddr, int32_t val) { callcmd2(device_id, kmodule_set_reg, regaddr, val, 10); } void IflytopCanbusMaster::callcmd0(int32_t device_id, int32_t cmdid, int32_t overtime) { callcmd(device_id, cmdid, nullptr, 0, overtime); } diff --git a/iflytop_canbus/iflytop_canbus_master.hpp b/iflytop_canbus/iflytop_canbus_master.hpp index bce0548..558759e 100644 --- a/iflytop_canbus/iflytop_canbus_master.hpp +++ b/iflytop_canbus/iflytop_canbus_master.hpp @@ -97,6 +97,8 @@ class IflytopCanbusMaster { void sendraw(int32_t fromId, uint8_t *data, size_t len); int32_t getAck(int32_t index); + uint8_t* getAckBuf(); + int32_t getAckBufLen(); public: /*********************************************************************************************************************** diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 01f0c75..e6f1e74 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -22,6 +22,7 @@ #include "zui/zui.hpp" // #include "tab/board_ext_tab.hpp" +#include "tab/code_scaner_tab.hpp" #include "tab/mini_servo_tab.hpp" #include "tab/module_opera_tab.hpp" #include "tab/step_motor_ctrl_tab.hpp" @@ -279,6 +280,7 @@ void MainWindow::constructAppUI() { StepMotorCtrlTab::inst()->constructRegTab(ui->buttonTabWidget); MiniServoTab::inst()->construct(ui->buttonTabWidget); + CodeScanerTab::inst()->construct(ui->buttonTabWidget); } void MainWindow::on_PublicState_ConfirmKey_clicked() {} diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 5d7188f..0ba948d 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -1010,8 +1010,8 @@ p, li { white-space: pre-wrap; } <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Consolas','Courier New','monospace'; font-size:11pt; color:#ff0000;">50  板夹仓加热</span></p> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Consolas','Courier New','monospace'; font-size:11pt; color:#ff0000;">60  进出料 </span></p> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Consolas','Courier New','monospace'; font-size:11pt; color:#ff0000;"> 进料电机(61)</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Consolas','Courier New','monospace'; font-size:11pt; color:#ff0000;"> 出料电机(63)</span></p> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Consolas','Courier New','monospace'; font-size:11pt; color:#ff0000;"> 转移电机(62)</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Consolas','Courier New','monospace'; font-size:11pt; color:#ff0000;"> 出料电机(63)</span></p> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Consolas','Courier New','monospace'; font-size:11pt; color:#ff0000;"> 扫码器(64)</span></p> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Consolas','Courier New','monospace'; font-size:11pt; color:#ff0000;">70  孵育盘 </span></p> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Consolas','Courier New','monospace'; font-size:11pt; color:#ff0000;"> 孵育盘转盘(71)</span></p> diff --git a/src/tab/board_ext_tab.cpp b/src/tab/board_ext_tab.cpp index e506f5d..55257ff 100644 --- a/src/tab/board_ext_tab.cpp +++ b/src/tab/board_ext_tab.cpp @@ -23,6 +23,12 @@ BoardExtTab *BoardExtTab::inst() { return ins; } +static inline const char *hex2binstr(int32_t hex) { + static char buf[32]; + sprintf(buf, "%d%d%d%d_%d%d%d%d", (hex >> 7) & 1, (hex >> 6) & 1, (hex >> 5) & 1, (hex >> 4) & 1, (hex >> 3) & 1, (hex >> 2) & 1, (hex >> 1) & 1, (hex >> 0) & 1); + return buf; +} + void BoardExtTab::construct(QTabWidget *fathertab) { ZQVTabPage *tab = new ZQVTabPage(fathertab, "板载扩展资源"); /*********************************************************************************************************************** @@ -36,6 +42,11 @@ void BoardExtTab::construct(QTabWidget *fathertab) { ICM->callcmd1(getDeviceId(), kboard_read_ext_io, atoi(args[0])); ZQUI::ins()->ishow("Status:%d", ICM->getAck(0)); }); + box->newFunc("读取全部IO", {"ioindex"}, [this](int argn, const char **args) { + int32_t status = 0; + ICM->callcmd1(getDeviceId(), kboard_read_muti_io, atoi(args[0])); + ZQUI::ins()->ishow("IOState:%s", hex2binstr(ICM->getAck(0))); + }); box->newFunc("写入IO", {"ioindex", "iostate"}, [this](int argn, const char **args) { ICM->callcmd1(getDeviceId(), kboard_write_ext_io, atoi(args[0]), atoi(args[1])); }); } diff --git a/src/tab/code_scaner_tab.cpp b/src/tab/code_scaner_tab.cpp new file mode 100644 index 0000000..a781e69 --- /dev/null +++ b/src/tab/code_scaner_tab.cpp @@ -0,0 +1,80 @@ +#include "code_scaner_tab.hpp" + +#include "iflytop_canbus/iflytop_canbus_master.hpp" +#include "logger.hpp" +#include "qt_serial_datachannel.hpp" +#include "zexception.hpp" +#include "zui/z_function_list_box.hpp" +#include "zui/z_reg_table_list_box.hpp" +#include "zui/zq_vtab_page.hpp" +// +#include "./mainwindow.h" +#include "zui\zqui.hpp" +// +using namespace iflytop; +using namespace std; + +extern Ui::MainWindow *main_ui; + +extern int getDeviceId(); + +CodeScanerTab *CodeScanerTab::inst() { + static CodeScanerTab *ins = new CodeScanerTab(); + return ins; +} + +void CodeScanerTab::construct(QTabWidget *fathertab) { + ZQVTabPage *tab = new ZQVTabPage(fathertab, "扫码器"); + /*********************************************************************************************************************** + * 模块操作 * + ***********************************************************************************************************************/ + { + ZQFunctionListBox *box = new ZQFunctionListBox(tab, "方法", 4); + + box->newFunc("开始扫描", {}, [this](int argn, const char **args) { + ICM->callcmd0(getDeviceId(), kcode_scaner_start_scan); + }); + + box->newFunc("停止扫描", {}, [this](int argn, const char **args) { + ICM->callcmd0(getDeviceId(), kcode_scaner_stop_scan); + }); + + box->newFunc("扫描结果是否准备好", {}, [this](int argn, const char **args) { + ICM->callcmd0(getDeviceId(), kcode_scaner_result_is_ready); + ZQUI::ins()->ishow("ready:%d", ICM->getAck(0)); + }); + + box->newFunc("读取扫描结果", {}, [this](int argn, const char **args) { + ICM->callcmd0(getDeviceId(), kcode_scaner_read_scaner_result); + + uint8_t *resultbuf = ICM->getAckBuf(); + int32_t resultlen = ICM->getAckBufLen(); + + ZQUI::ins()->ishow("result:%s(%d)", string(resultbuf, resultbuf + resultlen).c_str(), resultlen); + }); + } + + /*********************************************************************************************************************** + * 寄存器操作 * + ***********************************************************************************************************************/ + { + ZRegTableList *tableBox = new ZRegTableList(tab, "寄存器操作"); + tableBox->initializeRegOperation( + [this](int32_t add, int32_t val) { // + ICM->writereg(getDeviceId(), add, val); + return true; + }, + [this](int32_t add, int32_t *val) { // + ICM->readreg(getDeviceId(), add, val); + return true; + }); + + tableBox->addReg("mod-version", kreg_module_version, ZRegItem::krw | ZRegItem::kdec); + tableBox->addReg("mod-type", kreg_module_type, ZRegItem::krw | ZRegItem::kdec); + tableBox->addReg("mod-status", kreg_module_status, ZRegItem::krw | ZRegItem::kdec); + tableBox->addReg("mod-errorcode", kreg_module_errorcode, ZRegItem::krw | ZRegItem::kdec); + tableBox->addSpacer(); + } + + tab->addSpacer(); +} diff --git a/src/tab/code_scaner_tab.hpp b/src/tab/code_scaner_tab.hpp new file mode 100644 index 0000000..17eec54 --- /dev/null +++ b/src/tab/code_scaner_tab.hpp @@ -0,0 +1,43 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +// +#include + +namespace iflytop { +using namespace std; + +class CodeScanerTab { + public: + static CodeScanerTab *inst(); + + void construct(QTabWidget *fathertab); +}; +} // namespace iflytop diff --git a/src/tab/module_opera_tab.cpp b/src/tab/module_opera_tab.cpp index 45a9352..46d6c85 100644 --- a/src/tab/module_opera_tab.cpp +++ b/src/tab/module_opera_tab.cpp @@ -46,7 +46,7 @@ static const char *module_type2_str(int id) { case kfan_ctrl_module: return "风扇控制"; case kcode_scaner: - return "风扇控制"; + return "扫码器"; case kpipette_ctrl_module: return "移液体枪控制"; case ka8000_optical_module: @@ -87,6 +87,9 @@ void ModuleOperaTab::construct(QWidget *parent) { int moduleType; IflytopCanbusMaster::ins()->readreg(i, kreg_module_type, &moduleType); + if (i % 10 == 0) { + ZQUI::ins()->ishow(""); + } ZQUI::ins()->ishow("module :%d isOnline type:%s", i, module_type2_str(moduleType)); } catch (const zexception &e) { if (e.ecode() != ke_overtime) {