From 619b08f868a0ab41873aba1efc6599a391436f1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cwangbo=E2=80=9D?= <“mailbowang@163.com”> Date: Tue, 8 Oct 2024 16:31:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=8E=86=E5=8F=B2=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CableTool/common.h | 15 ++++ CableTool/widget.cpp | 163 ++++++++++++++++++++++++++++++++++++++++--- CableTool/widget.h | 28 ++++++-- 3 files changed, 193 insertions(+), 13 deletions(-) diff --git a/CableTool/common.h b/CableTool/common.h index 8f57f8c..c780af7 100644 --- a/CableTool/common.h +++ b/CableTool/common.h @@ -92,6 +92,7 @@ typedef unsigned uint32_t; #define USART_BUF_SIZE 1088 #define DEBUG_DATA_SIZE 1024 #define UPDATE_DATA_SIZE DEBUG_DATA_SIZE +#define FD_BUF_LEN 256 #define MONITOR_ADCi_NOTIFY_OK 0x101 #define MONITOR_ADC_NOTIFY_OK 0x102 @@ -450,6 +451,20 @@ typedef struct uint8_t reserve[2]; } waveParam_t; +/* Note: 必须保证这个结构体的大小是可以被flash扇区大小整除的,比如128,256... */ +typedef struct +{ + uint64_t id; + uint32_t run_time; // 时间, 单位 s + int16_t temperature; // 设备温度, 单位: 0.1℃ + uint16_t vin; // 工作电压, 单位: mv + uint16_t vbat; // 电池电压, 单位: mv + uint16_t vsc; // 超级电容电压, 单位: mv + uint16_t defect[4]; // 缺陷电流最大值 mA + uint32_t elec[DAU_PORT_POWER_CNT]; // 通道电流有效值 mA + uint8_t col_flag; // DAU 采集标志位 + uint8_t reserve[3]; // Reserve +} fd_data_t; /* Exported macro ------------------------------------------------------------*/ diff --git a/CableTool/widget.cpp b/CableTool/widget.cpp index 0fb9171..912c243 100644 --- a/CableTool/widget.cpp +++ b/CableTool/widget.cpp @@ -8,6 +8,15 @@ #include #include +QWidget *ReadOnlyDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + Q_UNUSED(parent) + Q_UNUSED(option) + Q_UNUSED(index) + return nullptr; +} + + Widget::Widget(QWidget *parent) : QWidget(parent),ui(new Ui::form) { @@ -41,6 +50,9 @@ Widget::Widget(QWidget *parent) logIndex = 0; waveIndex = 0; is_wave_up = 0; + dataIndex = 0; + is_data_up = false; + logSum = 0; energyMode[0] = "未知"; energyMode[1] = "正常模式"; @@ -85,6 +97,38 @@ Widget::Widget(QWidget *parent) //searchUsablePort(); + readOnlyDelegate = new ReadOnlyDelegate(this); + + /* 配置历史数据页面表格 */ + //如下代码设置横向表格头的间隔线,有四个方向的间隔线,不需要间隔线的可以设置为0px + ui->historyDataTable->horizontalHeader()->setStyleSheet( + "QHeaderView::section{" + "border-top:0px solid #E5E5E5;" + "border-left:0px solid #E5E5E5;" + "border-right:0.5px solid #E5E5E5;" + "border-bottom: 0.5px solid #E5E5E5;" + "background-color:red;" + "padding:4px;" + "}" + ); + + for(int i = 0; i < ui->historyDataTable->columnCount(); i++) + { + ui->historyDataTable->setItemDelegateForColumn(i, readOnlyDelegate); + } + ui->historyDataTable->horizontalHeader()->resizeSection(0, 50); + ui->historyDataTable->horizontalHeader()->resizeSection(1, 130); + ui->historyDataTable->horizontalHeader()->resizeSection(2, 60); + ui->historyDataTable->horizontalHeader()->resizeSection(3, 60); + ui->historyDataTable->horizontalHeader()->resizeSection(4, 60); + ui->historyDataTable->horizontalHeader()->resizeSection(5, 60); + ui->historyDataTable->horizontalHeader()->resizeSection(6, 110); + ui->historyDataTable->horizontalHeader()->resizeSection(7, 110); + ui->historyDataTable->horizontalHeader()->resizeSection(8, 110); + ui->historyDataTable->horizontalHeader()->resizeSection(9, 110); + ui->historyDataTable->horizontalHeader()->resizeSection(10, 110); + ui->historyDataTable->horizontalHeader()->resizeSection(11, 110); + } Widget::~Widget() @@ -866,7 +910,90 @@ int Widget::protoAdjustInfo(char *data) return 0; } +int Widget::protoHistoryData(char * data) +{ + mul_head_t *header = reinterpret_cast(data + sizeof(proto_head_t)); + fd_data_t *pHistoryData; + uint32_t cnt = 0; + /* 数据头校验. */ + if (header->index != dataIndex + || header->len > UPDATE_DATA_SIZE) + { + return -1; + } + /* 获取文件. */ + cnt = header->len / FD_BUF_LEN; + for(uint32_t i = 0; i < cnt; i++) + { + pHistoryData = reinterpret_cast(data + sizeof(proto_head_t) + sizeof(mul_head_t) + i * FD_BUF_LEN); + int32_t row = ui->historyDataTable->rowCount(); + ui->historyDataTable->insertRow(row); + + QTableWidgetItem *item = new QTableWidgetItem (QString::number(pHistoryData->id)); + ui->historyDataTable->setItem(row, 0, item); + + time_t cur = static_cast(pHistoryData->run_time); + tm *day; + day = localtime(&cur); + QString temp; + temp.sprintf("%d/%d/%d %d:%d:%d", day->tm_year + 1900, day->tm_mon+1, day->tm_mday, day->tm_hour, day->tm_min, day->tm_sec); + item = new QTableWidgetItem (temp); + ui->historyDataTable->setItem(row, 1, item); + + temp.sprintf("%.2f", pHistoryData->temperature / 10.0); + item = new QTableWidgetItem (temp); + ui->historyDataTable->setItem(row, 2, item); + temp.sprintf("%.2f", pHistoryData->vin / 1000.0); + item = new QTableWidgetItem (temp); + ui->historyDataTable->setItem(row, 3, item); + temp.sprintf("%.2f", pHistoryData->vbat / 1000.0); + item = new QTableWidgetItem (temp); + ui->historyDataTable->setItem(row, 4, item); + temp.sprintf("%.2f", pHistoryData->vsc / 1000.0); + item = new QTableWidgetItem (temp); + ui->historyDataTable->setItem(row, 5, item); + temp.sprintf("%.2f", pHistoryData->elec[0] / 1000.0); + item = new QTableWidgetItem (temp); + ui->historyDataTable->setItem(row, 6, item); + temp.sprintf("%.2f", pHistoryData->elec[1] / 1000.0); + item = new QTableWidgetItem (temp); + ui->historyDataTable->setItem(row, 7, item); + temp.sprintf("%.2f", pHistoryData->elec[2] / 1000.0); + item = new QTableWidgetItem (temp); + ui->historyDataTable->setItem(row, 8, item); + temp.sprintf("%.2f", pHistoryData->elec[3] / 1000.0); + item = new QTableWidgetItem (temp); + ui->historyDataTable->setItem(row, 9, item); + temp.sprintf("%.2f", pHistoryData->elec[4] / 1000.0); + item = new QTableWidgetItem (temp); + ui->historyDataTable->setItem(row, 10, item); + temp.sprintf("%.2f", pHistoryData->elec[5] / 1000.0); + item = new QTableWidgetItem (temp); + ui->historyDataTable->setItem(row, 11, item); + } + + if (header->len < UPDATE_DATA_SIZE) + { + //work->multipleIndexSet(0); + //work->stateSet(CM_usart::WS_IDLE); + dataIndex = 0; + buttonEnable(true); + ui->dataIndexLabel->setText("下载完成"); + QMessageBox::information(this, "SUCCEED", "历史数据下载完成.", QMessageBox::Ok); + ui->historyDataButton->setText("下载数据"); + is_data_up = false; + } + else + { + dataIndex = header->index + 1; + QString temp; + temp.sprintf("%d / %d", dataIndex, ui->historyDataEdit->text().toInt()); + ui->dataIndexLabel->setText(temp); + //work->multipleIndexSet(header->index + 1); + sendMsgHistoryDataGet(); + } +} int Widget::paraseProtocols(char *data) { @@ -943,7 +1070,7 @@ int Widget::paraseProtocols(char *data) //_debug_pkt_log_get(); break; case DEBUG_PRV_HISTORY_DATA: - //_debug_pkt_history_data_get(); + protoHistoryData(data); break; case DEBUG_PRV_ADJ_MANUAL: protoManualAdjust(data); @@ -1318,7 +1445,7 @@ int Widget::sendMsgWaveCol() return 0; } -int Widget::senMsgWaveCal() +int Widget::sendMsgWaveCal() { char buf[2048] = {0}; uint32_t *crc = nullptr; @@ -1339,6 +1466,29 @@ int Widget::senMsgWaveCal() return 0; } +int Widget::sendMsgHistoryDataGet() +{ + char buf[2048] = {0}; + uint32_t *crc = nullptr; + proto_head_t *header = reinterpret_cast(buf); + mul_head_t *m_head = reinterpret_cast(buf + sizeof(proto_head_t)); + int32_t *data = reinterpret_cast(buf + sizeof(proto_head_t) + sizeof(mul_head_t)); + + /* 初始化报文头. */ + protoHeaderInit(header, sizeof(proto_head_t) + sizeof(mul_head_t) + sizeof(uint32_t), clientDevInfo.id, DEBUG_CT_PRV_REQUEST, DEBUG_PRV_HISTORY_DATA); + + m_head->index = dataIndex; + m_head->len = 0; + *data = logSum; + + /* 计算校验位. */ + crc = reinterpret_cast(buf + header->len); + *crc = crc32(buf, header->len); + + HexPrint(__FUNCTION__, buf, header->len + 4); + writeData(buf, header->len + 4); + return 0; +} @@ -1677,7 +1827,7 @@ void Widget::on_waveColButton_clicked() void Widget::on_waveRefreshButton_clicked() { - + sendMsgDeviceStateGet(); } void Widget::on_waveCalButton_clicked() @@ -1734,10 +1884,9 @@ void Widget::on_historyDataButton_clicked() dataIndex = 0; QString temp; temp.sprintf("0 / %d", ui->historyDataEdit->text().toInt()); - //work->logSumSet(ui->historyDataEdit->text().toInt()); + logSum = ui->historyDataEdit->text().toInt(); ui->dataIndexLabel->setText(temp); - //work->multipleIndexSet(0); - //work->stateSet(CM_usart::WS_HISTORY_DATA_GET); + sendMsgHistoryDataGet(); int row = ui->historyDataTable->rowCount(); if (row > 0) @@ -2055,8 +2204,6 @@ void Widget::on_adjButton_clicked() } /* 下发配置. */ - //work->adjChSet(&adj); buttonEnable(false); - //work->stateSet(CM_usart::WS_ADJ_AUTO); sendMsgDeviceAdjustMode(DEBUG_PRV_ADJ_AUTO); } diff --git a/CableTool/widget.h b/CableTool/widget.h index 53903e1..9dd3e4c 100644 --- a/CableTool/widget.h +++ b/CableTool/widget.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include "common.h" @@ -11,12 +12,20 @@ namespace Ui { //新增的 class form; } -typedef struct _ST_DEV_INFO -{ - -} stDevInfo; #define USART_BUF_SIZE 1088 + +/* 设置tableview某行/列不可编辑. */ +class ReadOnlyDelegate: public QItemDelegate +{ + +public: + ReadOnlyDelegate(QWidget *parent = nullptr):QItemDelegate(parent) + {} + + QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,const QModelIndex &index) const override; +}; + class Widget : public QWidget { Q_OBJECT @@ -133,6 +142,8 @@ private: int protoManualAdjust(char *data); int protoAdjustInfo(char *data); + + int protoHistoryData(char *data); int paraseProtocols(char *data); int snedMsgDeviceInfoGet(); @@ -159,7 +170,9 @@ private: int sendMsgWaveCol(); - int senMsgWaveCal(); + int sendMsgWaveCal(); + + int sendMsgHistoryDataGet(); Ui::form *ui; //新增的 QSerialPort *serialPort; @@ -195,6 +208,11 @@ private: uint32_t logIndex; uint8_t is_data_up; uint32_t dataIndex; + int32_t logSum; + + + ReadOnlyDelegate* readOnlyDelegate; }; + #endif // WIDGET_H