#include "mainwindow.h" #include #include #include #include #include #include "./ui_mainwindow.h" #include "ads129x/ads129x_type.h" #include "algo/iflytop_simple_filter.h" #include "electrocardiograph_tester.hpp" #include "filter_algo_mgr.hpp" #include "logger.hpp" #include "qt_serial_datachannel.hpp" #include "widgetplot2d.h" #include "zexception.hpp" WidgetPlot2D *wp2d; using namespace std; using namespace iflytop; typedef enum { kone_lead_ecg, kthree_lead_ecg, kone_lead_ecg_v2, } device_type_t; static MainWindow *m_mainWindow; static QTDataChannel G_QTDataChannel; static device_type_t m_devicetype; static const uint32_t str2int(QString str) { // 如果0x开头,按16进制转换 // 如果0b开头,按2进制转换 // 否则按10进制转换 // 去除掉str中_ str.remove("_"); if (str.startsWith("0x")) { return str.toUInt(nullptr, 16); } else if (str.startsWith("0b")) { // remove 0b str.remove(0, 2); return str.toUInt(nullptr, 2); } else { return str.toUInt(nullptr, 10); } } #define TAG "MainWindow" 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; } void MainWindow::log_output(QtMsgType type, const QMessageLogContext &context, const QString &msg) {} void MainWindow::doinui_slot(QFunction func) { if (func.get()) func.get()(); } void MainWindow::ishow(const char *fmt, ...) { va_list args; va_start(args, fmt); char buf[1024] = {0}; vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); QString text(buf); QString info; info.append(QDateTime::currentDateTime().toString("hh:mm:ss.zzz ")); info.append(" |"); info.append(text); emit doinui_signal(QFunction([this, info]() { ui->instructionPreview->append(info); })); } void MainWindow::instructionPreviewClear() { ui->instructionPreview->document()->clear(); } void MainWindow::reportPreviewShow(const char *fmt, ...) { va_list args; va_start(args, fmt); char buf[1024] = {0}; vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); QString text(buf); QString info; info.append(QDateTime::currentDateTime().toString("hh:mm:ss.zzz ")); info.append(text); emit doinui_signal(QFunction([this, info]() { if (ui->reportPreview->document()->lineCount() > 1000) { ui->reportPreview->document()->clear(); } ui->reportPreview->append(info); })); } void MainWindow::blockDataUploadPreviewShow(const char *fmt, ...) { va_list args; va_start(args, fmt); char buf[1024] = {0}; vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); QString text(buf); QString info; info.append(QDateTime::currentDateTime().toString("hh:mm:ss.zzz ")); info.append(text); emit doinui_signal(QFunction([this, info]() { if (ui->uploadDataPreview->document()->lineCount() > 1000) { ui->uploadDataPreview->document()->clear(); } ui->uploadDataPreview->append(info); })); } void MainWindow::rawDataPreviewShow(const char *fmt, ...) { va_list args; va_start(args, fmt); char buf[1024] = {0}; vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); QString text(buf); 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); })); } // uploadDataPreview #pragma pack(push, 1) typedef struct { uint16_t header; int16_t wave1; int16_t wave2; int16_t wave3; int16_t wave4; int16_t wave5; uint8_t check; uint16_t tail; } Wave_t; #pragma pack(pop) void MainWindow::displayInfo(bool suc, QString info) {} MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { /******************************************************************************* * QT初始化 * *******************************************************************************/ ui->setupUi(this); m_mainWindow = this; qRegisterMetaType("int32_t"); qRegisterMetaType("uint32_t"); qRegisterMetaType("float"); qRegisterMetaType>("function"); qRegisterMetaType("QFunction"); connect(this, SIGNAL(doinui_signal(QFunction)), this, SLOT(doinui_slot(QFunction))); // qInstallMessageHandler(log_output); wp2d = new WidgetPlot2D(); wp2d->initGraphName(QStringList() << "心电"); /******************************************************************************* * 页面逻辑初始化 * *******************************************************************************/ constructUI(); ui->TestCmd_writeSubICRegMask_p0->setPlaceholderText("寄存器地址"); ui->TestCmd_writeSubICRegMask_p1->setPlaceholderText("偏移"); ui->TestCmd_writeSubICRegMask_p2->setPlaceholderText("位数"); ui->TestCmd_writeSubICRegMask_p3->setPlaceholderText("值"); ui->TestCmd_writeSubICReg_p0->setPlaceholderText("寄存器地址"); ui->TestCmd_writeSubICReg_p1->setPlaceholderText("值"); /******************************************************************************* * 业务逻辑构造 * *******************************************************************************/ G_QTDataChannel.init(); ElectrocardiographTester::ins()->initialize(&G_QTDataChannel); } MainWindow::~MainWindow() { delete ui; } /******************************************************************************* * UI相关构造 * *******************************************************************************/ void MainWindow::constructUI() { /******************************************************************************* * 指令串口UI * *******************************************************************************/ { const auto infos = QSerialPortInfo::availablePorts(); for (const QSerialPortInfo &info : infos) { ui->serialPortCB->addItem(info.portName()); } } ui->serialBaudrateCB->addItem("9600"); ui->serialBaudrateCB->addItem("14400"); ui->serialBaudrateCB->addItem("19200"); ui->serialBaudrateCB->addItem("38400"); ui->serialBaudrateCB->addItem("57600"); ui->serialBaudrateCB->addItem("115200"); ui->serialBaudrateCB->addItem("460800"); ui->serialBaudrateCB->addItem("500000"); ui->serialBaudrateCB->setCurrentIndex(6); 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); if (!G_QTDataChannel.open()) { QMessageBox::about(NULL, "提示", "串口无法打开,串口不存在或已被占??"); return; } ui->serialOpenKey->setText("关闭"); // 下拉菜单控件使能 ui->serialBaudrateCB->setEnabled(false); ui->serialPortCB->setEnabled(false); ui->serialPortRefreshKey->setEnabled(false); ui->deviceType->setEnabled(false); } else { G_QTDataChannel.close(); ui->serialOpenKey->setText("打开"); ui->serialBaudrateCB->setEnabled(true); ui->serialPortCB->setEnabled(true); ui->serialPortRefreshKey->setEnabled(true); ui->deviceType->setEnabled(true); } }); /******************************************************************************* * 波形串口UI * *******************************************************************************/ { ui->deviceType->addItem("单导联一代(M1001)"); ui->deviceType->addItem("三导联一代(M1002)"); ui->deviceType->addItem("单导联二代(M1003)"); ui->deviceType->setCurrentIndex(0); connect(ui->deviceType, &QComboBox::currentTextChanged, this, [this](const QString &text) { if (text == "单导联一代(M1001)") { m_devicetype = kone_lead_ecg; } else if (text == "三导联一代(M1002)") { m_devicetype = kthree_lead_ecg; } else if (text == "单导联二代(M1003)") { m_devicetype = kone_lead_ecg_v2; } }); } // 事件填充 ElectrocardiographTester::ins()->regReportCB([this](bool checkok, ify_hrs_packet_t *report_packet, size_t len) { int reportType = report_packet->cmd; switch (reportType) { case ify_hrs_report_heartrate_data: { if (m_devicetype == kone_lead_ecg) { heartrate_report_packet_t *heartrate_report = (heartrate_report_packet_t *)report_packet; static uint32_t lastpacket_index = 0; static uint32_t lostpacket = 0; if ((lastpacket_index + 5) != (heartrate_report->sample_data_index)) { lostpacket++; } lastpacket_index = heartrate_report->sample_data_index; reportPreviewShow("[preview data ] lost:%d index %d", lostpacket, heartrate_report->sample_data_index); if (checkok) { uint16_t data0 = (uint16_t)(heartrate_report->data[0]) + ((uint16_t)heartrate_report->data[1] << 8); uint16_t data1 = (uint16_t)(heartrate_report->data[2]) + ((uint16_t)heartrate_report->data[3] << 8); uint16_t data2 = (uint16_t)(heartrate_report->data[4]) + ((uint16_t)heartrate_report->data[5] << 8); uint16_t data3 = (uint16_t)(heartrate_report->data[6]) + ((uint16_t)heartrate_report->data[7] << 8); uint16_t data4 = (uint16_t)(heartrate_report->data[8]) + ((uint16_t)heartrate_report->data[9] << 8); emit doinui_signal(QFunction([this, data0, data1, data2, data3, data4]() { // wp2d->addData("心电", data0, 0); wp2d->addData("心电", data1, 2); wp2d->addData("心电", data2, 4); wp2d->addData("心电", data3, 6); wp2d->addData("心电", data4, 8); })); } } else if (m_devicetype == kthree_lead_ecg) { } else if (m_devicetype == kone_lead_ecg_v2) { if (!checkok) return; m1003_heartrate_report_packet_t *heartrate_report = (m1003_heartrate_report_packet_t *)report_packet; static uint32_t lostpacket = 0; { static uint32_t lastpacket_index = 0; if ((lastpacket_index + heartrate_report->sample_data_num) != (heartrate_report->sample_data_index)) { lostpacket++; } lastpacket_index = heartrate_report->sample_data_index; } reportPreviewShow("[preview data ] lost:%d index %d leadoff 0x%x", // lostpacket, heartrate_report->sample_data_index, heartrate_report->leadoff_state); for (int i = 0; i < heartrate_report->sample_data_num; i++) { int16_t data = heartrate_report->frame[i]; int32_t frameIndex = heartrate_report->sample_data_index + i; data = FilterAlgoMgr::ins()->processData("心电", data); emit doinui_signal(QFunction([this, data, i]() { wp2d->addData("心电", data, i * 2); })); } } break; } case ify_hrs_report_battery_level: { reportPreviewShow("[battery_level ]"); break; } case ify_hrs_report_low_battey_level: { reportPreviewShow("[low_battey ]"); break; } case ify_hrs_report_sample_finish_end: { reportPreviewShow("[sample_finish ]"); break; } case ify_hrs_report_sensor_drop_detect: { sensor_drop_event_report_packet_t *sensor_drop_report = (sensor_drop_event_report_packet_t *)report_packet->data; reportPreviewShow("[sensor_drop ] %s %s", zhex2binary(sensor_drop_report->drop_state0).c_str(), zhex2binary(sensor_drop_report->drop_state1).c_str()); break; } case ify_hrs_report_record_upload_end: { uint32_t checksum = *(uint32_t *)report_packet->data; reportPreviewShow("[upload end ] checksum: 0x%08x", checksum); break; } default: break; } }); ElectrocardiographTester::ins()->regCh4CheckSumPacketReport([this](uint32_t rxcnt, uint32_t report_packet_checksum) { // blockDataUploadPreviewShow("RXCNT %d CHECKSUM 0x%08x", rxcnt, report_packet_checksum); }); ElectrocardiographTester::ins()->regRawDataCB([this](raw_data_type_t type, uint8_t *hex, uint32_t hexlen) { if (type == kcmd_cmd) { rawDataPreviewShow("[CMD ] %s", zhex2str(hex, hexlen).c_str()); } else if (type == kcmd_receipt) { rawDataPreviewShow("[RECEIPT] %s", zhex2str(hex, hexlen).c_str()); } else if (type == kcmd_report) { rawDataPreviewShow("[REPORT ] %s", zhex2str(hex, hexlen).c_str()); } else if (type == kcmd_ch4_data) { // rawDataPreviewShow("[CH4 ] %s", zhex2str(hex, hexlen).c_str()); } }); } void MainWindow::processException(zexception &e) { ishow("%s:%s", e.what(), ify_hrs_error_code_to_string((ify_hrs_error_code_t)e.ecode())); } void MainWindow::on_readDeviceVersion_clicked() { instructionPreviewClear(); try { device_version_info_receipt_t version; ElectrocardiographTester::ins()->readDeviceVersion(&version); ishow("-------------- version ----------------"); ishow(" blestack_version: %d", version.blestack_version); ishow(" bootloader_version: %d", version.bootloader_version); ishow(" firmware_version: %d", version.firmware_version); ishow(" hardware_version: %d", version.hardware_version); } catch (zexception &exception) { processException(exception); } } void MainWindow::on_readDeviceState_clicked() { instructionPreviewClear(); try { device_state_receipt_t state; ElectrocardiographTester::ins()->readDeviceState(&state); ishow("-------------- state ----------------"); ishow(" drop_state0: %s", zhex2binary(state.drop_state0).c_str()); ishow(" drop_state1: %s", zhex2binary(state.drop_state1).c_str()); ishow(" sampling_state: %d", state.device_state0.sampling_state); ishow(" report_state: %d", state.device_state0.report_state); ishow(" low_battery: %d", state.device_state0.low_battery); ishow(" full_storge: %d", state.device_state0.full_storge); ishow(" holder: %d", state.device_state0.holder); ishow(" powerlevel: %d", state.powerlevel); ishow(" storage_item_num: %d", state.storage_item_num); } catch (zexception &exception) { processException(exception); } } void MainWindow::on_readTime_clicked() { instructionPreviewClear(); try { read_time_receipt_t time; ElectrocardiographTester::ins()->readTime(&time); ishow("-------------- time ----------------"); ishow(" %d/%d/%d %d:%d:%d", time.year + 2000, time.month, time.day, time.hour, time.minute, time.second); } catch (zexception &exception) { processException(exception); } } void MainWindow::on_syncTime_clicked() { instructionPreviewClear(); try { // 获取系统时间 QDateTime now = QDateTime::currentDateTime(); ElectrocardiographTester::ins()->syncTime(now.date().year() - 2000, now.date().month(), now.date().day(), now.time().hour(), now.time().minute(), now.time().second()); ishow("sync time success!"); } catch (zexception &exception) { processException(exception); } } std::string zhex2time(const uint8_t *hex, size_t len) { std::string str; if (len < 6) return str; str.append(fmt("%d/%d/%d %2d:%2d:%2d", hex[0] + 2000, hex[1], hex[2], hex[3], hex[4], hex[5])); return str; } void MainWindow::on_readAllRecords_clicked() { // 读取当前有多少条记录 instructionPreviewClear(); try { device_state_receipt_t state; ElectrocardiographTester::ins()->readDeviceState(&state); ishow("index recordid frameNum dataSize sensorNum captRate captPrec compAlgo checksum"); for (int32_t i = 0; i < state.storage_item_num; i++) { read_record_info_receipt_t record; ElectrocardiographTester::ins()->readRecordsInfo(i, &record); ishow("%d %s %8d %8d %8d %8d %8d %8d 0x%08x", i, zhex2time(record.record_id, 6).c_str(), record.frameNum, record.dataSize, record.sensorNum, record.captureRate, record.capturePrecision, record.compressAlgorithm, record.checksum); } } catch (zexception &exception) { processException(exception); } } void MainWindow::on_startUploadRecord_clicked() { instructionPreviewClear(); int reportIndex = ui->startUploadRecord_p0->toPlainText().toInt(); try { read_record_info_receipt_t record; ElectrocardiographTester::ins()->readRecordsInfo(reportIndex, &record); ElectrocardiographTester::ins()->startUploadRecord(record.record_id); ishow("start upload record [%s] success", zhex2time(record.record_id, 6).c_str()); } catch (zexception &exception) { processException(exception); } } void MainWindow::on_readSensorInfo_clicked() { instructionPreviewClear(); try { sensor_info_receipt_t sensor; ElectrocardiographTester::ins()->readSensorInfo(&sensor); ishow("-------------- sensor ----------------"); ishow(" sensor_num: %d", sensor.sensor_num); ishow(" sensor_precision: %d", sensor.sensor_precision); ishow(" sensor_sample_rate:%d", sensor.sensor_sample_rate); ishow(" sensor0_pos: %d", sensor.sensor0_pos); ishow(" sensor1_pos: %d", sensor.sensor1_pos); ishow(" sensor2_pos: %d", sensor.sensor2_pos); } catch (zexception &exception) { processException(exception); } } void MainWindow::on_readSN_clicked() { instructionPreviewClear(); try { string sn; ElectrocardiographTester::ins()->readSn(sn); ishow("-------------- sn ----------------"); ishow(" sn: %s", sn.c_str()); } catch (zexception &exception) { processException(exception); } } void MainWindow::on_stopUploadRecord_clicked() { instructionPreviewClear(); try { ElectrocardiographTester::ins()->stopUploadRecord(); ishow("stop upload record success"); } catch (zexception &exception) { processException(exception); } } void MainWindow::on_delRecord_clicked() { instructionPreviewClear(); int reportIndex = ui->delRecord_p0->toPlainText().toInt(); try { read_record_info_receipt_t record; ElectrocardiographTester::ins()->readRecordsInfo(reportIndex, &record); ElectrocardiographTester::ins()->delRecord(record.record_id); ishow("delete record [%s] success", zhex2time(record.record_id, 6).c_str()); } catch (zexception &exception) { processException(exception); } } #if 0 void MainWindow::on_startCapture_clicked() { instructionPreviewClear(); try { ElectrocardiographTester::ins()->startCapture(); ishow("start capture success"); } catch (zexception &exception) { processException(exception); } } void MainWindow::on_stopCapture_clicked() { instructionPreviewClear(); try { ElectrocardiographTester::ins()->stopCapture(); ishow("stop capture success"); } catch (zexception &exception) { processException(exception); } } #endif void MainWindow::on_startRealtimeReport_clicked() { instructionPreviewClear(); try { ElectrocardiographTester::ins()->startRealtimeReport(); ishow("start realtime report success"); wp2d->show(); } catch (zexception &exception) { processException(exception); } } void MainWindow::on_stopRealtimeReport_clicked() { instructionPreviewClear(); try { ElectrocardiographTester::ins()->stopRealtimeReport(); ishow("stop realtime report success"); wp2d->hide(); } catch (zexception &exception) { processException(exception); } } void MainWindow::on_clearPreview_clicked() { ui->reportPreview->document()->clear(); ui->uploadDataPreview->document()->clear(); ui->rawDataPreview->document()->clear(); ui->instructionPreview->document()->clear(); } void MainWindow::on_TestCmd_readSubIcRegs_clicked() { instructionPreviewClear(); try { uint8_t data[12]; data[ADS129X_REG_ID] = ElectrocardiographTester::ins()->testCmdReadReg(ADS129X_REG_ID); data[ADS129X_REG_CONFIG1] = ElectrocardiographTester::ins()->testCmdReadReg(ADS129X_REG_CONFIG1); data[ADS129X_REG_CONFIG2] = ElectrocardiographTester::ins()->testCmdReadReg(ADS129X_REG_CONFIG2); data[ADS129X_REG_LOFF] = ElectrocardiographTester::ins()->testCmdReadReg(ADS129X_REG_LOFF); data[ADS129X_REG_CH1SET] = ElectrocardiographTester::ins()->testCmdReadReg(ADS129X_REG_CH1SET); data[ADS129X_REG_CH2SET] = ElectrocardiographTester::ins()->testCmdReadReg(ADS129X_REG_CH2SET); data[ADS129X_REG_RLDSENS] = ElectrocardiographTester::ins()->testCmdReadReg(ADS129X_REG_RLDSENS); data[ADS129X_REG_LOFFSENS] = ElectrocardiographTester::ins()->testCmdReadReg(ADS129X_REG_LOFFSENS); data[ADS129X_REG_LOFFSTAT] = ElectrocardiographTester::ins()->testCmdReadReg(ADS129X_REG_LOFFSTAT); data[ADS129X_REG_RESP1] = ElectrocardiographTester::ins()->testCmdReadReg(ADS129X_REG_RESP1); data[ADS129X_REG_RESP2] = ElectrocardiographTester::ins()->testCmdReadReg(ADS129X_REG_RESP2); data[ADS129X_REG_GPIO] = ElectrocardiographTester::ins()->testCmdReadReg(ADS129X_REG_GPIO); ishow("reg %10s %02d: 0x%02x", "ID", ADS129X_REG_ID, data[ADS129X_REG_ID]); ishow("reg %10s %02d: 0x%02x", "CONFIG1", ADS129X_REG_CONFIG1, data[ADS129X_REG_CONFIG1]); ishow("reg %10s %02d: 0x%02x", "CONFIG2", ADS129X_REG_CONFIG2, data[ADS129X_REG_CONFIG2]); ishow("reg %10s %02d: 0x%02x", "LOFF", ADS129X_REG_LOFF, data[ADS129X_REG_LOFF]); ishow("reg %10s %02d: 0x%02x", "CH1SET", ADS129X_REG_CH1SET, data[ADS129X_REG_CH1SET]); ishow("reg %10s %02d: 0x%02x", "CH2SET", ADS129X_REG_CH2SET, data[ADS129X_REG_CH2SET]); ishow("reg %10s %02d: 0x%02x", "RLDSENS", ADS129X_REG_RLDSENS, data[ADS129X_REG_RLDSENS]); ishow("reg %10s %02d: 0x%02x", "LOFFSENS", ADS129X_REG_LOFFSENS, data[ADS129X_REG_LOFFSENS]); ishow("reg %10s %02d: 0x%02x %s", "LOFFSTAT", ADS129X_REG_LOFFSTAT, data[ADS129X_REG_LOFFSTAT], zhex2binary(data[ADS129X_REG_LOFFSTAT]).c_str()); ishow("reg %10s %02d: 0x%02x", "RESP1", ADS129X_REG_RESP1, data[ADS129X_REG_RESP1]); ishow("reg %10s %02d: 0x%02x", "RESP2", ADS129X_REG_RESP2, data[ADS129X_REG_RESP2]); ishow("reg %10s %02d: 0x%02x", "GPIO", ADS129X_REG_GPIO, data[ADS129X_REG_GPIO]); ishow("regs: %s", zhex2str(data, 12).c_str()); } catch (zexception &exception) { processException(exception); } } void MainWindow::on_TestCmd_writeSubICReg_clicked() { uint32_t add = str2int(ui->TestCmd_writeSubICReg_p0->toPlainText()); uint32_t val = str2int(ui->TestCmd_writeSubICReg_p1->toPlainText()); instructionPreviewClear(); try { ElectrocardiographTester::ins()->testCmdWriteReg(add, val); ishow("write reg %d: 0x%02x success", add, val); } catch (zexception &exception) { processException(exception); } } void MainWindow::on_TestCmd_writeSubICRegMask_clicked() { uint8_t add = ui->TestCmd_writeSubICRegMask_p0->toPlainText().toInt(); uint8_t off = ui->TestCmd_writeSubICRegMask_p1->toPlainText().toInt(); uint8_t bitnum = ui->TestCmd_writeSubICRegMask_p2->toPlainText().toInt(); uint8_t val = ui->TestCmd_writeSubICRegMask_p3->toPlainText().toInt(); instructionPreviewClear(); try { uint8_t regval = ElectrocardiographTester::ins()->testCmdReadReg(add); uint8_t oldval = regval; uint8_t mask = (1 << bitnum) - 1; mask = mask << off; regval = regval & (~mask); regval = regval | (val << off); ElectrocardiographTester::ins()->testCmdWriteReg(add, regval); ishow("write reg %d: 0x%02x -> 0x%02x success", add, oldval, regval); } catch (const std::exception &e) { std::cerr << e.what() << '\n'; } } void MainWindow::on_TestCmd_startCapture_clicked() { instructionPreviewClear(); try { ElectrocardiographTester::ins()->testCmdStartCapture(); ishow("call start capture success"); wp2d->show(); } catch (zexception &exception) { processException(exception); } } void MainWindow::on_TestCmd_stopCapture_clicked() { instructionPreviewClear(); try { ElectrocardiographTester::ins()->testCmdStopCapture(); ishow("call stop capture success"); } catch (zexception &exception) { processException(exception); } } void MainWindow::on_TestCmd_changeECGSrcToSquareWave_clicked() { instructionPreviewClear(); try { uint8_t cfg2 = ElectrocardiographTester::ins()->testCmdReadReg(ADS129X_REG_CONFIG2); uint8_t ch1set = ElectrocardiographTester::ins()->testCmdReadReg(ADS129X_REG_CH1SET); cfg2 = ADS129X_SET_BITS(cfg2, ADS129X_INT_TEST, ADS129X_INT_TEST_ON); cfg2 = ADS129X_SET_BITS(cfg2, ADS129X_INT_FREQ, ADS129X_INT_FREQ_AC); ch1set = ADS129X_SET_BITS(ch1set, ADS129X_MUXx, ADS129X_CHx_INPUT_TEST); ElectrocardiographTester::ins()->testCmdWriteReg(ADS129X_REG_CONFIG2, cfg2); ElectrocardiographTester::ins()->testCmdWriteReg(ADS129X_REG_CH1SET, ch1set); ishow("call change ECG src to square wave success"); } catch (zexception &exception) { processException(exception); } } void MainWindow::on_resetDevice_clicked() { instructionPreviewClear(); try { ElectrocardiographTester::ins()->reset(); } catch (zexception &exception) { // processException(exception); } ishow("call reset device success"); } void MainWindow::on_FilterUpdateParameter_clicked() { instructionPreviewClear(); FilterAlgoMgr::ins()->FilterCommon_setSampleTimeMs(ui->FilterCommon_SampleTimeMs->text().toFloat()); FilterAlgoMgr::ins()->LPFilter_setEnable(ui->LPFilter_Enable->isChecked()); FilterAlgoMgr::ins()->LPFilter_setCutoffFreqHz(ui->LPFilter_CutoffFreqHz->text().toFloat()); FilterAlgoMgr::ins()->LPFilter_setOrder(ui->LPFilter_Order->text().toInt()); FilterAlgoMgr::ins()->HPFilter_setEnable(ui->HPFilter_Enable->isChecked()); FilterAlgoMgr::ins()->HPFilter_setCutoffFreqHz(ui->HPFilter_CutoffFreqHz->text().toFloat()); FilterAlgoMgr::ins()->HPFilter_setOrder(ui->HPFilter_Order->text().toInt()); FilterAlgoMgr::ins()->NOTCHFilter_setEnable(ui->NOTCHFilter_Enable->isChecked()); FilterAlgoMgr::ins()->NOTCHFilter_setCenterFreqHz(ui->NOTCHFilter_CenterFreqHz->text().toFloat()); FilterAlgoMgr::ins()->NOTCHFilter_setNotchWidthHz(ui->NOTCHFilter_NotchWidthHz->text().toFloat()); FilterAlgoMgr::ins()->NOTCHFilter_setOrder(ui->NOTCHFilter_Order->text().toInt()); FilterAlgoMgr::ins()->updateParameter(); on_buttonTabWidget_currentChanged(0); ishow("Filter Update Parameter success"); } void MainWindow::on_buttonTabWidget_currentChanged(int index) { ui->FilterCommon_SampleTimeMs->setText(QString::number(FilterAlgoMgr::ins()->FilterCommon_getSampleTimeMs())); ui->LPFilter_Enable->setChecked(FilterAlgoMgr::ins()->LPFilter_getEnable()); ui->LPFilter_CutoffFreqHz->setText(QString::number(FilterAlgoMgr::ins()->LPFilter_getCutoffFreqHz())); ui->LPFilter_Order->setText(QString::number(FilterAlgoMgr::ins()->LPFilter_getOrder())); ui->HPFilter_Enable->setChecked(FilterAlgoMgr::ins()->HPFilter_getEnable()); ui->HPFilter_CutoffFreqHz->setText(QString::number(FilterAlgoMgr::ins()->HPFilter_getCutoffFreqHz())); ui->HPFilter_Order->setText(QString::number(FilterAlgoMgr::ins()->HPFilter_getOrder())); ui->NOTCHFilter_Enable->setChecked(FilterAlgoMgr::ins()->NOTCHFilter_getEnable()); ui->NOTCHFilter_CenterFreqHz->setText(QString::number(FilterAlgoMgr::ins()->NOTCHFilter_getCenterFreqHz())); ui->NOTCHFilter_NotchWidthHz->setText(QString::number(FilterAlgoMgr::ins()->NOTCHFilter_getNotchWidthHz())); ui->NOTCHFilter_Order->setText(QString::number(FilterAlgoMgr::ins()->NOTCHFilter_getOrder())); } void MainWindow::on_TestCmd_writeSubICAllReg_clicked() { // 0x52,0x02,0xe0,0xF1,0x00,0x80,0x00,0x03,0x12,0x02,0x07,0x0c instructionPreviewClear(); QString regs = ui->TestCmd_writeSubICAllReg_p0->toPlainText(); QStringList reglist = regs.split(","); if (reglist.size() != 12) { ishow("reg size error %d != 12", reglist.size()); return; } try { uint8_t data[12]; for (int i = 0; i < 12; i++) { data[i] = str2int(reglist[i]); } for (size_t i = 0; i < 12; i++) { ElectrocardiographTester::ins()->testCmdWriteReg(i, data[i]); ishow("write reg %d: 0x%02x success", i, data[i]); } ishow("write all reg success"); } catch (zexception &exception) { processException(exception); } } void MainWindow::on_setEcgInTestMode_clicked() { instructionPreviewClear(); try { ElectrocardiographTester::ins()->set_ecg_in_test_mode(1); ishow("set ECG in test mode success"); } catch (zexception &exception) { processException(exception); } } void MainWindow::on_setEcgInNormalMode_clicked() { instructionPreviewClear(); try { ElectrocardiographTester::ins()->set_ecg_in_test_mode(0); ishow("set ECG in test mode success"); } catch (zexception &exception) { processException(exception); } }