更新历史数据界面

main
“wangbo” 8 months ago
parent ae0c16e7eb
commit 619b08f868

@ -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 ------------------------------------------------------------*/

@ -8,6 +8,15 @@
#include <QFileInfo>
#include <QFileDialog>
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<mul_head_t*>(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<fd_data_t*>(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<time_t>(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<proto_head_t*>(buf);
mul_head_t *m_head = reinterpret_cast<mul_head_t*>(buf + sizeof(proto_head_t));
int32_t *data = reinterpret_cast<int32_t*>(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<uint32_t*>(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);
}

@ -4,6 +4,7 @@
#include <QWidget>
#include <QSerialPort>
#include <QSettings>
#include <QItemDelegate>
#include <stdint.h>
#include "common.h"
@ -11,12 +12,20 @@ namespace Ui { //新增的
class form;
}
typedef struct _ST_DEV_INFO
#define USART_BUF_SIZE 1088
/* 设置tableview某行/列不可编辑. */
class ReadOnlyDelegate: public QItemDelegate
{
} stDevInfo;
public:
ReadOnlyDelegate(QWidget *parent = nullptr):QItemDelegate(parent)
{}
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,const QModelIndex &index) const override;
};
#define USART_BUF_SIZE 1088
class Widget : public QWidget
{
Q_OBJECT
@ -134,6 +143,8 @@ private:
int protoAdjustInfo(char *data);
int protoHistoryData(char *data);
int paraseProtocols(char *data);
int snedMsgDeviceInfoGet();
int sendMsgDeviceInfoSet();
@ -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

Loading…
Cancel
Save