|
|
@ -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; |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|