From 12c775941c2e813c586f412a9cce2403e2c04364 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Wed, 3 Apr 2024 20:40:57 +0800 Subject: [PATCH] V1.0 --- mainwindow.cpp | 133 +++++++++++++++++++++++++++++++++----- mainwindow.h | 4 +- mainwindow.ui | 49 ++++++++++++++ src/electrocardiograph_tester.cpp | 12 +++- src/electrocardiograph_tester.hpp | 2 +- 5 files changed, 182 insertions(+), 18 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 5610656..c93ce3b 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -14,9 +14,15 @@ using namespace std; using namespace iflytop; +typedef enum { + kone_lead_ecg, + kthree_lead_ecg, +} device_type_t; static MainWindow *m_mainWindow; static QTDataChannel G_QTDataChannel; +static QTDataChannel G_WaveDataChannel; +static device_type_t m_devicetype; #define TAG "MainWindow" @@ -108,6 +114,40 @@ void MainWindow::rawDataPreviewShow(const char *fmt, ...) { } // 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::displayWave(int16_t wave1, int16_t wave2, int16_t wave3) { + // 1. 生成波形数据 + Wave_t wave; + wave.header = 0xAAAA; + wave.wave1 = wave1; + wave.wave2 = wave2; + wave.wave3 = wave3; + wave.wave4 = 0; + wave.wave5 = 0; + wave.tail = 0x5555; + wave.check = 0; + + uint8_t check = 0; + for (size_t i = 2; i < sizeof(wave) - 2; i++) { + check += ((uint8_t *)&wave)[i]; + } + wave.check = check; + // 2. 发送波形数据 + G_WaveDataChannel.send((uint8_t *)&wave, sizeof(wave)); +} + void MainWindow::displayInfo(bool suc, QString info) {} MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { @@ -133,6 +173,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi * 业务逻辑构造 * *******************************************************************************/ G_QTDataChannel.init(); + G_WaveDataChannel.init(); ElectrocardiographTester::ins()->initialize(&G_QTDataChannel); } MainWindow::~MainWindow() { delete ui; } @@ -142,16 +183,15 @@ MainWindow::~MainWindow() { delete ui; } *******************************************************************************/ void MainWindow::constructUI() { /******************************************************************************* - * serialPortCB * + * 指令串口UI * *******************************************************************************/ - const auto infos = QSerialPortInfo::availablePorts(); - for (const QSerialPortInfo &info : infos) { - ui->serialPortCB->addItem(info.portName()); + { + 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"); @@ -162,9 +202,6 @@ void MainWindow::constructUI() { 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(); @@ -173,9 +210,6 @@ void MainWindow::constructUI() { } }); - /******************************************************************************* - * 打开串口 * - *******************************************************************************/ connect(ui->serialOpenKey, &QPushButton::clicked, this, [=](bool check) { // 打开串口 if (ui->serialOpenKey->text() == "打开") { @@ -204,13 +238,82 @@ void MainWindow::constructUI() { } }); + /******************************************************************************* + * 波形串口UI * + *******************************************************************************/ + { + const auto infos = QSerialPortInfo::availablePorts(); + for (const QSerialPortInfo &info : infos) { + ui->waveSerialPortCB->addItem(info.portName()); + } + } + + ui->waveSerialBaudrateCB->addItem("9600"); + ui->waveSerialBaudrateCB->addItem("14400"); + ui->waveSerialBaudrateCB->addItem("19200"); + ui->waveSerialBaudrateCB->addItem("38400"); + ui->waveSerialBaudrateCB->addItem("57600"); + ui->waveSerialBaudrateCB->addItem("115200"); + ui->waveSerialBaudrateCB->addItem("460800"); + ui->waveSerialBaudrateCB->addItem("500000"); + ui->waveSerialBaudrateCB->setCurrentIndex(6); + + connect(ui->waveSerialPortRefreshKey, &QPushButton::clicked, this, [this](bool check) { + ui->waveSerialPortCB->clear(); + const auto infos = QSerialPortInfo::availablePorts(); + for (const QSerialPortInfo &info : infos) { + ui->waveSerialPortCB->addItem(info.portName()); + } + }); + + connect(ui->waveSerialOpenKey, &QPushButton::clicked, this, [=](bool check) { + // 打开串口 + if (ui->waveSerialOpenKey->text() == "打开") { + G_WaveDataChannel.setPortName(ui->waveSerialPortCB->currentText().toStdString()); + G_WaveDataChannel.setBaudRate(ui->waveSerialBaudrateCB->currentText().toInt()); + G_WaveDataChannel.setDataBits(QSerialPort::Data8); + G_WaveDataChannel.setParity(QSerialPort::NoParity); + G_WaveDataChannel.setFlowControl(QSerialPort::NoFlowControl); + G_WaveDataChannel.setStopBits(QSerialPort::OneStop); + + if (!G_WaveDataChannel.open()) { + QMessageBox::about(NULL, "提示", "串口无法打开,串口不存在或已被占??"); + return; + } + ui->waveSerialOpenKey->setText("关闭"); + // 下拉菜单控件使能 + ui->waveSerialBaudrateCB->setEnabled(false); + ui->waveSerialPortCB->setEnabled(false); + ui->waveSerialPortRefreshKey->setEnabled(false); + } else { + G_WaveDataChannel.close(); + ui->waveSerialOpenKey->setText("打开"); + ui->waveSerialBaudrateCB->setEnabled(true); + ui->waveSerialPortCB->setEnabled(true); + ui->waveSerialPortRefreshKey->setEnabled(true); + } + }); + // 事件填充 - ElectrocardiographTester::ins()->regReportCB([this](ify_hrs_packet_t *report_packet, size_t len) { + 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: { heartrate_report_packet_t *heartrate_report = (heartrate_report_packet_t *)report_packet; - reportPreviewShow("[preview data ] index %llu", heartrate_report->sample_data_index); + // reportPreviewShow("[preview data ] index %llu", heartrate_report->sample_data_index); + + uint16_t header = 0xA55A; + uint16_t tail = 0xB55B; + G_WaveDataChannel.send((uint8_t *)&header, sizeof(header)); + G_WaveDataChannel.send((uint8_t *)report_packet, len); + G_WaveDataChannel.send((uint8_t *)&tail, sizeof(tail)); + + // if (m_devicetype == kone_lead_ecg) { + reportPreviewShow("[preview data ] checksum_ok:%d index %llu", checkok, heartrate_report->sample_data_index); + // } else if (m_devicetype == kthree_lead_ecg) { + // displayWave(heartrate_report->data[0], heartrate_report->data[1], heartrate_report->data[2]); + // } + break; } case ify_hrs_report_battery_level: { diff --git a/mainwindow.h b/mainwindow.h index 5bd5edc..6d9742c 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -107,7 +107,7 @@ class MainWindow : public QMainWindow { void on_clearPreview_clicked(); -signals: + signals: void doinui_signal(QFunction); private: @@ -118,6 +118,8 @@ signals: void blockDataUploadPreviewShow(const char *fmt, ...); void rawDataPreviewShow(const char *fmt, ...); + void displayWave(int16_t wave1, int16_t wave2, int16_t wave3); + void displayInfo(bool suc, QString info); private: diff --git a/mainwindow.ui b/mainwindow.ui index ce28d2e..e6ecf95 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -659,6 +659,55 @@ QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical { + + + + 16777215 + 16777215 + + + + 波形串口设置 + + + + + + + + + 打开 + + + + + + + + + + 波特率 + + + + + + + 串口 + + + + + + + 刷新 + + + + + + + diff --git a/src/electrocardiograph_tester.cpp b/src/electrocardiograph_tester.cpp index 66b0dd7..5fa3a5b 100644 --- a/src/electrocardiograph_tester.cpp +++ b/src/electrocardiograph_tester.cpp @@ -156,8 +156,18 @@ void ElectrocardiographTester::processRxReportPacket(ify_hrs_packet_t *rx, int32 if (m_on_report == nullptr) { return; } + uint8_t *rawrx = (uint8_t *)rx; + uint8_t checsum = 0; + bool checkok = true; + for (int32_t i = 0; i < rxlen - 1; i++) { + checsum += rawrx[i]; + } + if (checsum != rawrx[rxlen - 1]) { + checkok = false; + } + if (m_on_raw_data_cb) m_on_raw_data_cb(kcmd_report, (uint8_t *)rx, rxlen); - m_on_report(rx, rxlen); + m_on_report(checkok, rx, rxlen); } void ElectrocardiographTester::sendCmd(ify_hrs_packet_t *tx, int32_t txlen, ify_hrs_packet_t *rx, int32_t *rxlen, int32_t overtime) { diff --git a/src/electrocardiograph_tester.hpp b/src/electrocardiograph_tester.hpp index b31d175..fa666b9 100644 --- a/src/electrocardiograph_tester.hpp +++ b/src/electrocardiograph_tester.hpp @@ -27,7 +27,7 @@ typedef enum { kcmd_ch4_data, } raw_data_type_t; -typedef function on_report_t; +typedef function on_report_t; typedef function on_ch4_check_sum_packet_report_t; typedef function on_raw_data_t;