You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
310 lines
10 KiB
310 lines
10 KiB
#include "mainwindow.h"
|
|
|
|
#include <QDateTime>
|
|
#include <QMessageBox>
|
|
#include <QtConcurrent>
|
|
#include <QtCore/QVariant>
|
|
#include <QtSerialPort/QSerialPort>
|
|
#include <QtSerialPort/QSerialPortInfo>
|
|
#include <QtWidgets/QLineEdit>
|
|
|
|
#include "./ui_mainwindow.h"
|
|
#include "iflytop_canbus/iflytop_canbus_master.hpp"
|
|
#include "logger.hpp"
|
|
#include "qt_serial_datachannel.hpp"
|
|
#include "reglist.hpp"
|
|
#include "zexception.hpp"
|
|
#include "zui/z_function_list_box.hpp"
|
|
#include "zui/zq_vtab_page.hpp"
|
|
//
|
|
#include <thread>
|
|
|
|
#include "zui/zui.hpp"
|
|
//
|
|
#include "tab/board_ext_tab.hpp"
|
|
#include "tab/code_scaner_tab.hpp"
|
|
#include "tab/fan_ctrl_tab.hpp"
|
|
#include "tab/id_card_read_tab.hpp"
|
|
#include "tab/mini_servo_tab.hpp"
|
|
#include "tab/module_opera_tab.hpp"
|
|
#include "tab/pipette_ctrl_tab.hpp"
|
|
#include "tab/step_motor_ctrl_tab.hpp"
|
|
#include "tab/water_cooling_temperature_tab.hpp"
|
|
#include "tab/xyrobot_tab.hpp"
|
|
#include "tab/plate_code_scaner_tab.hpp"
|
|
#include "version.h"
|
|
|
|
using namespace std;
|
|
using namespace iflytop;
|
|
using namespace zcr;
|
|
typedef enum {
|
|
kone_lead_ecg,
|
|
kthree_lead_ecg,
|
|
} device_type_t;
|
|
|
|
static MainWindow *m_mainWindow;
|
|
static QTDataChannel G_QTDataChannel;
|
|
static QTDataChannel G_WaveDataChannel;
|
|
|
|
int PublicState_DeviceIDVal = 0;
|
|
|
|
int getDeviceId() { return PublicState_DeviceIDVal; }
|
|
|
|
Ui::MainWindow *main_ui;
|
|
|
|
QT_REQUIRE_CONFIG(groupbox);
|
|
|
|
#define TAG "MainWindow"
|
|
|
|
// static inline const char *fmt(const char *fmt, ...) {
|
|
// va_list args;
|
|
// va_start(args, fmt);
|
|
// static char buf[1024] = {0};
|
|
// vsnprintf(buf, sizeof(buf), fmt, args);
|
|
// va_end(args);
|
|
// return buf;
|
|
// }
|
|
|
|
void MainWindow::log_output(QtMsgType type, const QMessageLogContext &context, const QString &msg) {}
|
|
void MainWindow::doinui_slot(QFunction func) {
|
|
if (func.get()) func.get()();
|
|
}
|
|
|
|
/***********************************************************************************************************************
|
|
* PreviewShow *
|
|
***********************************************************************************************************************/
|
|
|
|
void MainWindow::ishow(QString text) {
|
|
QString info;
|
|
info.append(QDateTime::currentDateTime().toString("hh:mm:ss"));
|
|
info.append("|");
|
|
info.append(text);
|
|
emit doinui_signal(QFunction([this, info]() { ui->instructionPreview->append(info); }));
|
|
}
|
|
|
|
void MainWindow::rawshow(QString text) {
|
|
QString info;
|
|
|
|
info.append(QDateTime::currentDateTime().toString("hh:mm:ss.zzz"));
|
|
info.append(text);
|
|
emit doinui_signal(QFunction([this, info]() {
|
|
if (ui->rawDataPreview->document()->lineCount() > 1000) {
|
|
ui->rawDataPreview->document()->clear();
|
|
}
|
|
ui->rawDataPreview->append(info);
|
|
}));
|
|
}
|
|
|
|
void MainWindow::instructionPreviewClear() {
|
|
doinui_signal(QFunction([this]() { ui->instructionPreview->clear(); }));
|
|
}
|
|
|
|
/***********************************************************************************************************************
|
|
* UI相关构造 *
|
|
***********************************************************************************************************************/
|
|
|
|
void MainWindow::constructBaseUI() {
|
|
/**
|
|
* @brief 指令串口UI
|
|
*/
|
|
{
|
|
const auto infos = QSerialPortInfo::availablePorts();
|
|
for (const QSerialPortInfo &info : infos) {
|
|
ui->serialPortCB->addItem(info.portName());
|
|
}
|
|
}
|
|
|
|
ui->serialBaudrateCB->addItem("2000000");
|
|
ui->serialBaudrateCB->setCurrentIndex(0);
|
|
|
|
connect(ui->serialPortRefreshKey, &QPushButton::clicked, this, [this](bool check) {
|
|
ui->serialPortCB->clear();
|
|
const auto infos = QSerialPortInfo::availablePorts();
|
|
for (const QSerialPortInfo &info : infos) {
|
|
ui->serialPortCB->addItem(info.portName());
|
|
}
|
|
});
|
|
|
|
connect(ui->serialOpenKey, &QPushButton::clicked, this, [=](bool check) {
|
|
// 打开串口
|
|
if (ui->serialOpenKey->text() == "打开") {
|
|
G_QTDataChannel.setPortName(ui->serialPortCB->currentText().toStdString());
|
|
G_QTDataChannel.setBaudRate(ui->serialBaudrateCB->currentText().toInt());
|
|
G_QTDataChannel.setDataBits(QSerialPort::Data8);
|
|
G_QTDataChannel.setParity(QSerialPort::NoParity);
|
|
G_QTDataChannel.setFlowControl(QSerialPort::NoFlowControl);
|
|
G_QTDataChannel.setStopBits(QSerialPort::OneStop);
|
|
|
|
/**
|
|
* @brief 串口打开时,初始化相应参数
|
|
*/
|
|
|
|
if (!G_QTDataChannel.open()) {
|
|
QMessageBox::about(NULL, "提示", "串口无法打开,串口不存在或已被占??");
|
|
return;
|
|
}
|
|
ui->serialOpenKey->setText("关闭");
|
|
// 下拉菜单控件使能
|
|
ui->serialBaudrateCB->setEnabled(false);
|
|
ui->serialPortCB->setEnabled(false);
|
|
ui->serialPortRefreshKey->setEnabled(false);
|
|
|
|
IflytopCanbusMaster::ins()->updateChannelConfig();
|
|
|
|
} else {
|
|
G_QTDataChannel.close();
|
|
ui->serialOpenKey->setText("打开");
|
|
ui->serialBaudrateCB->setEnabled(true);
|
|
ui->serialPortCB->setEnabled(true);
|
|
ui->serialPortRefreshKey->setEnabled(true);
|
|
}
|
|
});
|
|
}
|
|
|
|
void MainWindow::displayInfo(bool suc, QString info) {}
|
|
|
|
static const char *fmt(const char *fmt, ...) {
|
|
va_list args;
|
|
va_start(args, fmt);
|
|
static char buf[1024] = {0};
|
|
vsnprintf(buf, sizeof(buf), fmt, args);
|
|
va_end(args);
|
|
return buf;
|
|
}
|
|
|
|
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
|
|
/**
|
|
* @brief QT初始化
|
|
*/
|
|
|
|
// VERSION
|
|
|
|
main_ui = ui;
|
|
|
|
ui->setupUi(this);
|
|
m_mainWindow = this;
|
|
qRegisterMetaType<int32_t>("int32_t");
|
|
qRegisterMetaType<uint32_t>("uint32_t");
|
|
qRegisterMetaType<float>("float");
|
|
qRegisterMetaType<function<void()>>("function<void()>");
|
|
qRegisterMetaType<QFunction>("QFunction");
|
|
connect(this, SIGNAL(doinui_signal(QFunction)), this, SLOT(doinui_slot(QFunction)));
|
|
ZQUI::ins()->initialize();
|
|
ZQUI::ins()->setishow([this](QString text) { ishow(text); });
|
|
ZQUI::ins()->setrawshow([this](QString text) { rawshow(text); });
|
|
ZQUI::ins()->setInstructionPreviewClear([this]() { instructionPreviewClear(); });
|
|
|
|
ui->menu_version->setTitle(QApplication::translate("MainWindow", VERSION, nullptr));
|
|
|
|
/**
|
|
* @brief 页面逻辑初始化
|
|
*/
|
|
constructBaseUI();
|
|
constructAppUI();
|
|
|
|
/**
|
|
* @brief 业务逻辑构造
|
|
*/
|
|
G_QTDataChannel.init();
|
|
G_WaveDataChannel.init();
|
|
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());
|
|
}
|
|
});
|
|
}
|
|
MainWindow::~MainWindow() { delete ui; }
|
|
|
|
void MainWindow::processException(const zexception &e) { //
|
|
ZQUI::ins()->ishow("%s", e.what());
|
|
}
|
|
|
|
int32_t MainWindow::getDeviceId() { return PublicState_DeviceIDVal; }
|
|
|
|
void MainWindow::constructAppUI() {
|
|
ModuleOperaTab::inst()->construct(ui->moduleOpera);
|
|
BoardExtTab::inst()->construct(ui->buttonTabWidget);
|
|
|
|
StepMotorCtrlTab::inst()->construct(ui->buttonTabWidget);
|
|
StepMotorCtrlTab::inst()->constructRegTab(ui->buttonTabWidget);
|
|
|
|
MiniServoTab::inst()->construct(ui->buttonTabWidget);
|
|
CodeScanerTab::inst()->construct(ui->buttonTabWidget);
|
|
PipetteCtrlTab::inst()->construct(ui->buttonTabWidget);
|
|
|
|
WaterCoolingTemperatureControlerTab::inst()->construct(ui->buttonTabWidget);
|
|
FanCtrlTab::inst()->construct(ui->buttonTabWidget);
|
|
XYRobotTab::inst()->construct(ui->buttonTabWidget);
|
|
|
|
IDCardReaderTab::inst()->construct(ui->buttonTabWidget);
|
|
PlateCodeScanerTab::inst()->construct(ui->buttonTabWidget);
|
|
|
|
|
|
}
|
|
|
|
void MainWindow::on_PublicState_ConfirmKey_clicked() {}
|
|
void MainWindow::on_PublicState_DeviceID_textChanged() { PublicState_DeviceIDVal = ui->PublicState_DeviceID->toPlainText().toInt(); }
|
|
|
|
void MainWindow::on_clearPreview_clicked() {
|
|
doinui_signal(QFunction([this]() { ui->instructionPreview->clear(); }));
|
|
doinui_signal(QFunction([this]() { ui->rawDataPreview->clear(); }));
|
|
}
|
|
|
|
void MainWindow::on_dumpFuncListButton_clicked() {
|
|
zcr::cmdinfo_t *cmdtable = cmdid_get_table();
|
|
ui->instructionPreview->clear();
|
|
for (int i = 0; i < cmdid_get_table_size(); i++) {
|
|
ZQUI::ins()->ishow("%-50s %8d (0x%04x)", cmdtable[i].fnname, cmdtable[i].index, cmdtable[i].index);
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_dumpErrorCodeButton_clicked() {
|
|
ui->instructionPreview->clear();
|
|
|
|
err::ecode_table_item_t *err_table = err::error_get_table();
|
|
for (int i = 0; i < err::error_get_table_size(); i++) {
|
|
ZQUI::ins()->ishow("%-50s %d", err_table[i].info, err_table[i].index);
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_dumpRegListButton_clicked() {
|
|
ui->instructionPreview->clear();
|
|
|
|
reginfo_t *regtable = reg_get_table();
|
|
for (int i = 0; i < reg_get_table_size(); i++) {
|
|
ZQUI::ins()->ishow("%-50s %d", regtable[i].regname, regtable[i].index);
|
|
}
|
|
}
|
|
|