diff --git a/a8000_protocol b/a8000_protocol index 59082bc..5c4075a 160000 --- a/a8000_protocol +++ b/a8000_protocol @@ -1 +1 @@ -Subproject commit 59082bcc8c2a856133f693619bbd1fdc64dba0fd +Subproject commit 5c4075ae36cb16b5a1b86fc860a39a8217d2a2c8 diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 64a9f70..1343533 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -172,6 +172,39 @@ static const char *fmt(const char *fmt, ...) { return buf; } +void MainWindow::parse_ptv2_cmd(zcr_cmd_header_t *frame, int32_t packetlen) { + int cmdId = frame->cmdMainId * 256 + frame->cmdSubId; + int32_t mid = frame->subModuleid; + int32_t *param = (int32_t *)frame->data; + + if (cmdId == kmodule_set_reg) { + ZQUI::ins()->rawshow(" [-->] module_set_reg %d(mid) %s(%d) %d(val)", mid, regindex2str(param[0]), param[0], param[1]); + } else if (cmdId == kmodule_get_reg) { + ZQUI::ins()->rawshow(" [-->] module_get_reg %d(mid) %s(%d)", mid, regindex2str(param[0]), param[0]); + } else { + ZQUI::ins()->rawshow("[CMD ] %d cmdid:(%s)0x%04x mid:%d param:%s", frame->packetindex, cmdid2str(cmdId), cmdId, mid, // + zhex2str(frame->data, packetlen - sizeof(zcr_cmd_header_t)).c_str()); + } +} +void MainWindow::parse_ptv2_ack(zcr_cmd_header_t *frame, int32_t packetlen) { + int cmdId = frame->cmdMainId * 256 + frame->cmdSubId; + int32_t mid = frame->subModuleid; + int32_t *param = (int32_t *)frame->data; + if (kptv2_error_ack == frame->packetType) { + ZQUI::ins()->rawshow("[E-RECEI] %s(%d)", err::error2str(param[0]), param[0]); + } else { + ZQUI::ins()->rawshow("[ RECEI] %s", zhex2str((uint8_t *)frame, packetlen).c_str()); + } +} +void MainWindow::parse_ptv2_event(zcr_cmd_header_t *frame, int32_t packetlen) { + int cmdId = frame->cmdMainId * 256 + frame->cmdSubId; + int32_t mid = frame->subModuleid; + int32_t *param = (int32_t *)frame->data; + int32_t paramLen = packetlen - sizeof(zcr_cmd_header_t); + + ZQUI::ins()->rawshow("[EVENT ] id:%d e:%s(%d) p:%s(%d)", mid, cmdid2str(cmdId), cmdId, zhex2str(frame->data,paramLen ), paramLen); +} + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { /** * @brief QT初始化 @@ -196,14 +229,13 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi ui->menu_version->setTitle(QApplication::translate("MainWindow", VERSION, nullptr)); ui->boardId_tableWidget->resizeColumnsToContents(); - ui->boardId_tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); // x先自适应宽度 + ui->boardId_tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); // x先自适应宽度 // ui->boardId_tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents); // 然后设置要根据内容使用宽度的列 ui->boardId_tableWidget->setAlternatingRowColors(true); ui->boardId_tableWidget->setStyleSheet("alternate-background-color:rgb( 255,250,240);background-color:rgb(245,245,245)"); - ui->ioid_tableWidget->resizeColumnsToContents(); - ui->ioid_tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); // x先自适应宽度 + ui->ioid_tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); // x先自适应宽度 // ui->ioid_tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents); // 然后设置要根据内容使用宽度的列 ui->ioid_tableWidget->setAlternatingRowColors(true); ui->ioid_tableWidget->setStyleSheet("alternate-background-color:rgb( 255,250,240);background-color:rgb(245,245,245)"); @@ -222,38 +254,25 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi IflytopCanbusMaster::ins()->initialize(&G_QTDataChannel); IflytopCanbusMaster::ins()->regOnRawData([this](raw_data_type_t type, uint8_t *hex, uint32_t hexlen) { - zcr_cmd_header_t *frame = (zcr_cmd_header_t *)hex; - int cmdId = frame->cmdMainId * 256 + frame->cmdSubId; - int32_t *param = (int32_t *)frame->data; - int32_t mid = frame->subModuleid; - int32_t packetType = frame->packetType; - - if (type == kcmd_cmd) { - if (cmdId == kmodule_set_reg) { - // ZQUI::ins()->rawshow("[CMD ] %s", zhex2str(hex, hexlen).c_str()); - ZQUI::ins()->rawshow(" [-->] module_set_reg %d(mid) %s(%d) %d(val)", mid, regindex2str(param[0]), param[0], param[1]); - } else if (cmdId == kmodule_get_reg) { - // ZQUI::ins()->rawshow("[CMD ] %s", zhex2str(hex, hexlen).c_str()); - ZQUI::ins()->rawshow(" [-->] module_get_reg %d(mid) %s(%d)", mid, regindex2str(param[0]), param[0]); - } else { - if (cmdId != kmodule_get_status) { - ZQUI::ins()->rawshow("[CMD ] %d cmdid:(%s)0x%04x mid:%d param:%s", frame->packetindex, cmdid2str(cmdId), cmdId, mid, zhex2str(frame->data, hexlen - sizeof(zcr_cmd_header_t)).c_str()); - } else { - // ZQUI::ins()->rawshow("[CMD ] %s", zhex2str(hex, hexlen).c_str()); - } - } - - } else if (type == kcmd_receipt) { - if (kptv2_error_ack == packetType) { - ZQUI::ins()->rawshow("[E-RECEI] %s(%d)", err::error2str(param[0]), param[0]); - } else { - if (cmdId != kmodule_get_status) { - ZQUI::ins()->rawshow("[ RECEI] %s", zhex2str(hex, hexlen).c_str()); - } else { - } - } - } else if (type == kcmd_report) { - ZQUI::ins()->rawshow("[REPORT ] %s", zhex2str(hex, hexlen).c_str()); + zcr_cmd_header_t *frame = (zcr_cmd_header_t *)hex; + int cmdId = frame->cmdMainId * 256 + frame->cmdSubId; + + if (cmdId == kmodule_get_status) return; // 过滤掉kmodule_get_status指令 + + switch (frame->packetType) { + case kptv2_cmd: + parse_ptv2_cmd(frame, hexlen); + break; + case kptv2_ack: + case kptv2_error_ack: + parse_ptv2_ack(frame, hexlen); + break; + case kptv2_event: + parse_ptv2_event(frame, hexlen); + break; + default: + ZQUI::ins()->rawshow("[UNKOWN ] %s", zhex2str((uint8_t *)hex, hexlen).c_str()); + break; } }); } diff --git a/src/mainwindow.h b/src/mainwindow.h index d603cb2..d6eb563 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -39,6 +39,7 @@ #include "qfunction.hpp" #include "zexception.hpp" #include "zqthread.hpp" +#include "a8000_protocol\api\apibasic\packet_interface.hpp" QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; @@ -126,5 +127,10 @@ class MainWindow : public QMainWindow { void endAllocNewTab(QWidget *tab); int32_t getDeviceId(); + + private: + void parse_ptv2_cmd(iflytop::zcr::zcr_cmd_header_t *packet, int32_t packetlen); + void parse_ptv2_ack(iflytop::zcr::zcr_cmd_header_t *packet, int32_t packetlen); + void parse_ptv2_event(iflytop::zcr::zcr_cmd_header_t *packet, int32_t packetlen); }; #endif // MAINWINDOW_H diff --git a/src/tab/xyrobot_tab.cpp b/src/tab/xyrobot_tab.cpp index 23af9df..3d2ceee 100644 --- a/src/tab/xyrobot_tab.cpp +++ b/src/tab/xyrobot_tab.cpp @@ -61,7 +61,7 @@ void XYRobotTab::construct(QTabWidget *fathertab) { box->newFunc("设置位置", {"x", "y"}, [this](int argn, const char **args) { ICM->callcmd2(getDeviceId(), kxymotor_set_pos, atoi(args[0]), atoi(args[1])); }); box->newFunc("相对移动", {"dx", "dy", "velocity"}, [this](int argn, const char **args) { ICM->callcmd3(getDeviceId(), kxymotor_move_by, atoi(args[0]), atoi(args[1]), atoi(args[2])); }); box->newFunc("绝对移动", {"x", "y", "velocity"}, [this](int argn, const char **args) { ICM->callcmd3(getDeviceId(), kxymotor_move_to, atoi(args[0]), atoi(args[1]), atoi(args[2])); }); - box->newFunc("直接控制电机相对移动", {"motor1_dpos", "motor2_dpos"}, [this](int argn, const char **args) { ICM->callcmd3(getDeviceId(), kxymotor_motor_move_by_direct, atoi(args[0]), atoi(args[1])); }); + box->newFunc("直接控制电机相对移动", {"motor1_dpos", "motor2_dpos"}, [this](int argn, const char **args) { ICM->callcmd2(getDeviceId(), kxymotor_motor_move_by_direct, atoi(args[0]), atoi(args[1])); }); box->newFunc("读取全部输入IO", {}, [this](int argn, const char **args) { int32_t portState = 0;