From 0c24fbd71993346f70eb9c3b8ad89cf080a33fc2 Mon Sep 17 00:00:00 2001 From: null <156478575@qq.com> Date: Sat, 14 Oct 2023 10:12:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E6=AD=A5=E5=AE=8C=E6=88=90=E5=8D=87?= =?UTF-8?q?=E7=BA=A7=E5=8C=85=E5=88=B6=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/mcuDownload/mcudownload.cpp | 150 +++- Src/mcuDownload/mcudownload.h | 3 + Src/network/network.h | 2 +- Src/protocol/customer/protocol_HDsmart.c | 8 +- Src/protocol/customer/protocol_HDsmart.h | 2 +- Src/protocol/verify.h | 2 +- Src/serial/serial.cpp | 975 ++++++++++------------- Src/serial/serial.h | 107 ++- Src/system/debug.cpp | 9 +- Src/system/system.h | 6 +- Src/system/upgrade.c | 282 +++++++ Src/system/upgrade.h | 85 ++ Src/upackage/upackage.cpp | 311 ++++++-- Src/upackage/upackage.h | 17 +- mainwindow.cpp | 69 +- mainwindow.h | 18 + multiTools.pro | 11 +- multiTools.pro.user | 18 +- 18 files changed, 1340 insertions(+), 735 deletions(-) create mode 100644 Src/system/upgrade.c create mode 100644 Src/system/upgrade.h diff --git a/Src/mcuDownload/mcudownload.cpp b/Src/mcuDownload/mcudownload.cpp index 8c85682..feeb720 100644 --- a/Src/mcuDownload/mcudownload.cpp +++ b/Src/mcuDownload/mcudownload.cpp @@ -2,6 +2,8 @@ #include "../system/system.h" #include "../system/debug.h" #include "../protocol/verify.h" +#include "../system/upgrade.h" + #define PROGRAM_SIGNATURE0 0xCDF5EEDA /*ASCII*/ #define PROGRAM_SIGNATURE1 0x4D756E5A /*GB2312*/ @@ -61,15 +63,15 @@ void mcuDownload::McuDownload_UiInit(void) downloadLayout->addWidget(downFileLEdit,0,0,1,6); downloadLayout->addWidget(openButton,0,6,1,1); - downloadLayout->addWidget(addrLabel,1,0,1,1); - downloadLayout->addWidget(addrLEdit,1,1,1,1); - downloadLayout->addWidget(productLabel,1,5,1,1); - downloadLayout->addWidget(productTypeBox,1,6,1,1); - downloadLayout->addWidget(verifyCBox,2,0,1,1); - downloadLayout->addWidget(runCBox,3,0,1,1); + //downloadLayout->addWidget(addrLabel,1,0,1,1); + //downloadLayout->addWidget(addrLEdit,1,1,1,1); + //downloadLayout->addWidget(productLabel,1,5,1,1); + // downloadLayout->addWidget(productTypeBox,1,6,1,1); + downloadLayout->addWidget(verifyCBox,1,0,1,1); + downloadLayout->addWidget(runCBox,2,0,1,1); - downloadLayout->addWidget(clearButton,3,5,1,1); - downloadLayout->addWidget(startButton,3,6,1,1); + downloadLayout->addWidget(clearButton,2,5,1,1); + downloadLayout->addWidget(startButton,2,6,1,1); downloadGroupBox->setLayout(downloadLayout); mainLayout->addWidget(downloadGroupBox); @@ -109,7 +111,7 @@ void mcuDownload::McuDownload_UiCreate(void) */ void mcuDownload::McuDownload_OpenFile(void) { - QStringList filelist=QFileDialog::getOpenFileNames(this,QString::fromLocal8Bit("文件"),downFileName,QString::fromLocal8Bit("*.bin"));//用个文件登陆框来选择文件,包括多个文件 + QStringList filelist=QFileDialog::getOpenFileNames(this,QString::fromLocal8Bit("文件"),downFileName,QString::fromLocal8Bit("*.bin *.FPK"));//用个文件登陆框来选择文件,包括多个文件 if(!filelist.isEmpty()) { for(int i=0;iclear(); downFileLEdit->setText(downFileName); + McuDownload_FileParsing(); } startButton->setEnabled(true); } @@ -400,5 +403,134 @@ UINT8 mcuDownload::McuDownload_WriteUUID(void) return OK; } +/* +**************************************************************** +* 功能:更新文件解析 +* 输入:无 +* 输出:无 +* 返回值:无 +**************************************************************** +*/ +UINT8 mcuDownload::McuDownload_FileParsing(void) +{ + UINT8 _buf[256]; + UINT32 crcValue; + QString disString; + + upackageFile = new QFile(downFileName); + upackageFile->open(QIODevice::ReadOnly); + + QFileInfo info(downFileName);//获取文件信息 + + DEBUG_MSG("File Size :%d\r\n",info.size()); + upackageFile->read((char *)_buf , 256); + crcValue = 0; + crcValue = Verify_CalCRC32(_buf, 252); + DEBUG_MSG("crcValue :%X\r\n",crcValue); + g_upgradeInfo.crc = (_buf[252] | (UINT32)(_buf[253] << 8) | (UINT32)(_buf[254] << 16) | (UINT32)(_buf[255] << 24)); /*信息头CRC32校验*/ + QString str = QString::fromLocal8Bit("信息头CRC32: "); + disString.sprintf("%s0x%X\r\n",str.toUtf8().data(),g_upgradeInfo.crc); + logTbrowser->append(disString); + + //repaint(); + + if (crcValue == g_upgradeInfo.crc) + { + g_upgradeInfo.signature = (_buf[0] | (UINT32)(_buf[1] << 8) | (UINT32)(_buf[2] << 16) | (UINT32)(_buf[3] << 24)); /*签名0x4D756E5A*/ + str = QString::fromLocal8Bit("签名: "); + disString.sprintf("%s0x%X",str.toUtf8().data(),g_upgradeInfo.signature); + logTbrowser->append(disString); + + g_upgradeInfo.fVersion = (_buf[4] | (UINT32)(_buf[5] << 8) | (UINT32)(_buf[6] << 16) | (UINT32)(_buf[7] << 24)); /*固件包格式版本*/ + str = QString::fromLocal8Bit("固件包格式版本: "); + disString.sprintf("%sV%d.%d.%d",str.toUtf8().data(),_buf[6], _buf[5], _buf[4]); + logTbrowser->append(disString); + + g_upgradeInfo.totalSize = (_buf[8] | (UINT32)(_buf[9] << 8) | (UINT32)(_buf[10] << 16) | (UINT32)(_buf[11] << 24)); /*固件包总大小*/ + str = QString::fromLocal8Bit("固件包总大小: "); + disString.sprintf("%s%d",str.toUtf8().data(),g_upgradeInfo.totalSize); + logTbrowser->append(disString); + + g_upgradeInfo.version = (_buf[12] | (UINT32)(_buf[13] << 8) | (UINT32)(_buf[14] << 16) | (UINT32)(_buf[15] << 24)); /*固件应用版本*/ + str = QString::fromLocal8Bit("应用版本: "); + disString.sprintf("%sV%d.%d.%d",str.toUtf8().data(),_buf[14], _buf[13], _buf[12]); + logTbrowser->append(disString); + + memcpy(g_upgradeInfo.author, &_buf[16], 24); /*固件包创建者www.hdsmart.net.cn*/ + g_upgradeInfo.author[23] = 0; + str = QString::fromLocal8Bit("固件包创建者: "); + disString.sprintf("%s%s",str.toUtf8().data(),g_upgradeInfo.author); + logTbrowser->append(disString); + + memcpy(g_upgradeInfo.name, &_buf[40], 24); /*固件App名称*/ + g_upgradeInfo.name[23] = 0; + str = QString::fromLocal8Bit("App名称: "); + disString.sprintf("%s%s",str.toUtf8().data(),g_upgradeInfo.name); + logTbrowser->append(disString); + + memcpy(g_upgradeInfo.date, &_buf[64], 32); /*固件包创建时间*/ + g_upgradeInfo.date[31] = 0; + str = QString::fromLocal8Bit("固件创建时间: "); + disString.sprintf("%s%s",str.toUtf8().data(),g_upgradeInfo.date); + logTbrowser->append(disString); + + memcpy(g_upgradeInfo.model, &_buf[96], 16); /*固件包创建时间*/ + g_upgradeInfo.date[15] = 0; + str = QString::fromLocal8Bit("型号: "); + disString.sprintf("%s%s",str.toUtf8().data(),g_upgradeInfo.model); + logTbrowser->append(disString); + + g_upgradeInfo.fBlock = _buf[112]; /*需要更新的固件块个数,最大10个块*/ + str = QString::fromLocal8Bit("固件块个数: "); + disString.sprintf("%s%d",str.toUtf8().data(),g_upgradeInfo.fBlock); + logTbrowser->append(disString); + + g_upgradeInfo.logo = _buf[113]; /*是否需要更新LOGO,如需更新则第1个数据块为LOGO数据*/ + str = QString::fromLocal8Bit("LOGO类型: "); + disString.sprintf("%s%d",str.toUtf8().data(),g_upgradeInfo.logo); + logTbrowser->append(disString); + + g_upgradeInfo.compress = _buf[114]; /*压缩类型*/ + str = QString::fromLocal8Bit("压缩类型: "); + disString.sprintf("%s%d",str.toUtf8().data(),g_upgradeInfo.compress); + logTbrowser->append(disString); + + g_upgradeInfo.encryption = _buf[115]; /*加密类型*/ + str = QString::fromLocal8Bit("加密类型: "); + disString.sprintf("%s%d",str.toUtf8().data(),g_upgradeInfo.encryption); + logTbrowser->append(disString); + for (int i = 0; i < g_upgradeInfo.fBlock; i++) + { + g_upgradeInfo.info[i].size = (_buf[119 + i * 16] | (UINT32)(_buf[119 + i * 16 + 1] << 8) | \ + (UINT32)(_buf[119 + i * 16 + 2] << 16) | (UINT32)(_buf[119 + i * 16 + 3] << 24)); /*固件大小*/ + g_upgradeInfo.info[i].crc32 = (_buf[123 + i * 16] | (UINT32)(_buf[123 + i * 16 + 1] << 8) | \ + (UINT32)(_buf[123 + i * 16 + 2] << 16) | (UINT32)(_buf[123 + i * 16 + 3] << 24)); /*固件大小*/ + g_upgradeInfo.info[i].offset = (_buf[127 + i * 16] | (UINT32)(_buf[127 + i * 16 + 1] << 8) | \ + (UINT32)(_buf[127 + i * 16 + 2] << 16) | (UINT32)(_buf[127 + i * 16 + 3] << 24)); /*固件大小*/ + g_upgradeInfo.info[i].addr = (_buf[131 + i * 16] | (UINT32)(_buf[131 + i * 16 + 1] << 8) | \ + (UINT32)(_buf[131 + i * 16 + 2] << 16) | (UINT32)(_buf[131 + i * 16 + 3] << 24)); /*固件大小*/ + str = QString::fromLocal8Bit("固件块:"); + disString.sprintf("%s%d size = %d crc32 = 0x%X offset = %d addr = 0x%X",str.toUtf8().data(),i, g_upgradeInfo.info[i].size, g_upgradeInfo.info[i].crc32, \ + g_upgradeInfo.info[i].offset, g_upgradeInfo.info[i].addr); + logTbrowser->append(disString); + + } + } + else + { + QString str = QString::fromLocal8Bit("固件信息头解析失败\r\n信息头crcValue:"); + disString.sprintf("%s0x%X",str.toUtf8().data(),crcValue); + logTbrowser->append(disString); + } +#if 0 + for (int i = 0; i < 256; i++) + { + printf("%02X ", _buf[i]); + if ((i % 16) == 15) + printf("\r\n"); + } +#endif + upackageFile->close(); +} diff --git a/Src/mcuDownload/mcudownload.h b/Src/mcuDownload/mcudownload.h index b1f76db..a413408 100644 --- a/Src/mcuDownload/mcudownload.h +++ b/Src/mcuDownload/mcudownload.h @@ -34,6 +34,7 @@ public: UINT8 McuDownload_VerifyOwner(void); UINT8 McuDownload_WriteUUID(void); UINT8 McuDownload_ReadUUID(void); + UINT8 McuDownload_FileParsing(void); signals: private slots: @@ -47,6 +48,8 @@ private: UINT32 uuid[3]; UINT32 signature[3]; QProcess DownloadProcess; + QFile *upackageFile; + QDataStream *upackageFileStream; bool startDown; QString downFileName; diff --git a/Src/network/network.h b/Src/network/network.h index 7d63750..90ed1e0 100644 --- a/Src/network/network.h +++ b/Src/network/network.h @@ -63,7 +63,7 @@ private slots: void NetWork_stateChanged(QAbstractSocket::SocketState); void NetWork_DispData(void); private: - UINT8 netWorkStatus; + UINT8 netWorkStatus; QTimer *dispTimer; QTcpServer *tcpServer; diff --git a/Src/protocol/customer/protocol_HDsmart.c b/Src/protocol/customer/protocol_HDsmart.c index 3597e2b..edfc0a4 100644 --- a/Src/protocol/customer/protocol_HDsmart.c +++ b/Src/protocol/customer/protocol_HDsmart.c @@ -54,13 +54,9 @@ XX #include "../../system/debug.h" char g_caHDSmartFun[HDSMART_MAX_FUN][20] = {"B0","B1","B2","B3","B4","BE","BF"}; -char g_caHDSmartCmd[HDSMART_MAX_CMD][20] = {"0","1","2","3","4",\ - "10","11","12","13","14",\ - "60","61","62","63","64","65","66","67","68","69", \ - "6A","71","72","73","74","75","76","77","78","79", \ - "80","81","82","83","84","85","86","87","88","89", \ +char g_caHDSmartCmd[HDSMART_MAX_CMD][20] = {"80","81","82","83","84","85","86","87","88","89", \ "D0","D1","D2","D3","D4","D5","D6","D7","D8","D9", \ - "C0","C1","C2","C3","C4","C5","C6","C7","E0","A7"}; + "C0","E0","AB"}; /* *********************************************************************************** diff --git a/Src/protocol/customer/protocol_HDsmart.h b/Src/protocol/customer/protocol_HDsmart.h index bdf7755..6c6fb13 100644 --- a/Src/protocol/customer/protocol_HDsmart.h +++ b/Src/protocol/customer/protocol_HDsmart.h @@ -14,7 +14,7 @@ #define HDSMART_FRAME_HEAD2 0x5A #define HDSMART_MAX_FUN 7 -#define HDSMART_MAX_CMD 60 +#define HDSMART_MAX_CMD 23 /*功能字节枚举*/ typedef enum diff --git a/Src/protocol/verify.h b/Src/protocol/verify.h index 476f57e..c508cb6 100644 --- a/Src/protocol/verify.h +++ b/Src/protocol/verify.h @@ -18,7 +18,7 @@ UCHAR Verify_CRC8Rohc(UCHAR *_Buff,UCHAR _len); UCHAR Verify_CRC8Maxim(UCHAR *_Buff,UCHAR _len); USHORT Verify_CRC16Modbus(UCHAR *_Buff,UCHAR _len); UINT32 Verify_CalCRC32(UINT8 *_buf,UINT32 _len); - +UINT32 HDlib_CalCRC32(UINT8* _buf, UINT32 _len); #ifdef __cplusplus } diff --git a/Src/serial/serial.cpp b/Src/serial/serial.cpp index fa4899f..bee8cbf 100644 --- a/Src/serial/serial.cpp +++ b/Src/serial/serial.cpp @@ -4,12 +4,9 @@ #include "../system/debug.h" #include "../protocol/protocol.h" -#include "../protocol/verify.h" #define BAUD_MAX_NUM 8 static char gs_baud[BAUD_MAX_NUM][20] = {"1200","2400","4800","9600","19200","38400","57600","115200"}; -#define FILE_TYPE_MAX_NUM 3 - DataBuff_T gs_serialBuf; serial::serial(QWidget *parent) : QWidget(parent) @@ -31,9 +28,7 @@ serial::serial(QWidget *parent) : QWidget(parent) } serialComStatus = false; curTime = 0; - serialSendCnt = 0; - serialReceCnt = 0; - realTimer->start(500); + Sys_memset((void *)&gs_serialBuf,0,sizeof(DataBuff_T)); if(Fifo_Init(&(gs_serialBuf.fifo),4096) != FifoOK) { @@ -42,45 +37,43 @@ serial::serial(QWidget *parent) : QWidget(parent) } Serial_MultiInit(); + serialChartTimer->start(50); + connect(serialChartTimer, SIGNAL(timeout()), this, SLOT(Serial_ChartTimeOut())); /*串口定时处理接收数据*/ + connect(serialPort, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(Serial_ErrorHandle(QSerialPort::SerialPortError))); - connect(realTimer, SIGNAL(timeout()), this, SLOT(Serial_UpdateTime())); /*更新实时时钟*/ connect(serialTimer, SIGNAL(timeout()), this, SLOT(Serial_TimeOut())); /*串口定时处理接收数据*/ connect(serialReceTimer, SIGNAL(timeout()), this, SLOT(Serial_receTimeOut())); /*接收空闲*/ - connect(scanButton, SIGNAL(clicked()), this, SLOT(Serial_ScanCom())); - connect(operatButton, SIGNAL(clicked()), this, SLOT(Serial_Operat())); - connect(receHexRButton, SIGNAL(toggled(bool)), this, SLOT(Serial_ReceFormat(bool))); - connect(receClearButton, SIGNAL(clicked()), this, SLOT(Serial_ClearRece())); + connect(configPart.scanButton, SIGNAL(clicked()), this, SLOT(Serial_ScanCom())); + connect(configPart.operatButton, SIGNAL(clicked()), this, SLOT(Serial_Operat())); + connect(configPart.hexRButton, SIGNAL(toggled(bool)), this, SLOT(Serial_ReceFormat(bool))); + connect(configPart.waveRButton, SIGNAL(toggled(bool)), this, SLOT(Serial_ReceFormat(bool))); + + connect(configPart.receClearButton, SIGNAL(clicked()), this, SLOT(Serial_ClearRece())); connect(onceClearButton, SIGNAL(clicked()), this, SLOT(Serial_ClearSend())); connect(onceSendButton, SIGNAL(clicked()), this, SLOT(Serial_SendData())); /*****************************************串口协议************************************************/ connect(sendTabWindget, SIGNAL(currentChanged(int)), this, SLOT(Serial_SendModeChanged(int))); - connect(protocolSendButton, SIGNAL(clicked()), this, SLOT(Serial_SendData())); - connect(protocolClearButton, SIGNAL(clicked()), this, SLOT(Serial_ProtocolClearSend())); + connect(protSendPart.sendButton, SIGNAL(clicked()), this, SLOT(Serial_SendData())); + connect(protSendPart.clearButton, SIGNAL(clicked()), this, SLOT(Serial_ProtocolClearSend())); //connect(protocolDataLEdit, SIGNAL(textChanged(const QString&)), this, SLOT(Serial_protocolDataChanged(const QString&))); - connect(protocolDataLEdit, SIGNAL(textEdited(const QString&)), this, SLOT(Serial_protocolDataChanged(const QString&))); - connect(protocolTypeBox, SIGNAL(currentIndexChanged(int)), this, SLOT(Serial_protocolTypeChanged(int))); - connect(protocolCrcTypeBox, SIGNAL(currentIndexChanged(int)), this, SLOT(Serial_protocolCrcChanged(int))); - connect(protocolSendTime, SIGNAL(stateChanged(int)), this, SLOT(Serial_ProtocolSendTime(int))); + connect(protSendPart.dataLEdit, SIGNAL(textEdited(const QString&)), this, SLOT(Serial_protocolDataChanged(const QString&))); + connect(protSendPart.typeBox, SIGNAL(currentIndexChanged(int)), this, SLOT(Serial_protocolTypeChanged(int))); + connect(protSendPart.crcTypeBox, SIGNAL(currentIndexChanged(int)), this, SLOT(Serial_protocolCrcChanged(int))); + connect(protSendPart.timeChBox, SIGNAL(stateChanged(int)), this, SLOT(Serial_ProtocolSendTime(int))); connect(protocolSendTimer, SIGNAL(timeout()), this, SLOT(Serial_ProtocolSendTimeOut())); connect(protocolTimer, SIGNAL(timeout()), this, SLOT(Serial_ProtocolReceTimeOut())); - connect(protocolFileAddButton, SIGNAL(clicked()), this, SLOT(Serial_ProtocolOpenFile())); - connect(protocolFileSendButton, SIGNAL(clicked()), this, SLOT(Serial_ProtocolSendFile())); + connect(protSendPart.fileAddButton, SIGNAL(clicked()), this, SLOT(Serial_ProtocolOpenFile())); + connect(protSendPart.fileSendButton, SIGNAL(clicked()), this, SLOT(Serial_ProtocolSendFile())); - connect(protocolVersionButton, SIGNAL(clicked()), this, SLOT(Serial_ProtocolVersionQuery())); /*****************************************串口多条发送************************************************/ connect(multiTypeBox, SIGNAL(currentIndexChanged(int)), this, SLOT(Serial_MultiTypeChanged(int))); //connect(itemLData[0], SIGNAL( editingFinished()), this, SLOT(Serial_MultiLineEditFinish())); connect(multiSaveButton, SIGNAL(clicked()), this, SLOT(Serial_MultiLineEditFinish())); - for(int i = 0;i < 5;i++) - { - connect(itemButton[i], SIGNAL(clicked()), this, SLOT(Serial_MultiSendData())); - connect(itemButton1[i], SIGNAL(clicked()), this, SLOT(Serial_MultiSendData())); - } } #if 0 @@ -100,16 +93,17 @@ serial::~serial() void serial::Serial_Init(void) { serialPort = new QSerialPort; - realTimer = new QTimer; + serialTimer = new QTimer; serialReceTimer = new QTimer; protocolTimer = new QTimer; protocolSendTimer = new QTimer; + serialChartTimer = new QTimer; Serial_UiInit(); /**********************************波特率************************************/ - baudBox->clear(); //清除组件内容 + configPart.baudBox->clear(); //清除组件内容 QStringList strList; for(int i=0;iaddItems(strList); //将列表加入组件 - baudBox->setCurrentIndex(7); + configPart.baudBox->addItems(strList); //将列表加入组件 + configPart.baudBox->setCurrentIndex(7); /**********************************数据位************************************/ - dataBox->clear(); + configPart.dataBox->clear(); strList.clear(); strList<<"8"<<"7"<<"6"; - dataBox->addItems(strList); + configPart.dataBox->addItems(strList); /**********************************检验位************************************/ strList.clear(); - checkBox->clear(); + configPart.checkBox->clear(); strList<addItems(strList); + configPart.checkBox->addItems(strList); /**********************************停止位************************************/ strList.clear(); - stopBox->clear(); + configPart.stopBox->clear(); strList<<"1"<<"1.5"<<"2"; - stopBox->addItems(strList); + configPart.stopBox->addItems(strList); /***********************************协议发送****************************************/ QStringList cmdStrList; - protocolIDBox->clear(); - protocolFunBox->clear(); + protSendPart.funCBox->clear(); + protSendPart.idCBox->clear(); UINT8 type = g_ProtocolData.type; QStringList funStrList; for(int i=0;iaddItems(funStrList); + protSendPart.funCBox->addItems(funStrList); for(int i=0;iaddItems(cmdStrList); + protSendPart.idCBox->addItems(cmdStrList); QStringList crcStrList; - protocolCrcTypeBox->clear(); + protSendPart.crcTypeBox->clear(); for(int i=0;iaddItems(crcStrList); + protSendPart.crcTypeBox->addItems(crcStrList); QStringList cmdTypeStrList; - protocolTypeBox->clear(); + protSendPart.typeBox->clear(); for(int i=0;iaddItems(cmdTypeStrList); + protSendPart.typeBox->addItems(cmdTypeStrList); multiTypeBox->addItems(cmdTypeStrList); - } /* * ********************************************************************* @@ -182,42 +175,60 @@ void serial::Serial_UiInit(void) Serial_UiCreate(); /*************串口接收区**************/ - receHex->setVisible(0); - receLayout->addWidget(receText); - receLayout->addWidget(receHex); - /************************串口配置**************************************/ - configSubLayout->addWidget(comBox,0,0,1,2); - configSubLayout->addWidget(baudLabel,1,0,1,1); - configSubLayout->addWidget(baudBox,1,1,1,1); - configSubLayout->addWidget(dataLabel,2,0,1,1); - configSubLayout->addWidget(dataBox,2,1,1,1); - configSubLayout->addWidget(stopLabel,3,0,1,1); - configSubLayout->addWidget(stopBox,3,1,1,1); - configSubLayout->addWidget(checkLabel,4,0,1,1); - configSubLayout->addWidget(checkBox,4,1,1,1); - configSubLayout->addWidget(scanButton,5,1,1,1); - configSubLayout->addWidget(operatButton,6,1,1,1); - receRButtonGroup->addButton(receAscllRButton); - receRButtonGroup->addButton(receHexRButton); - configSubLayout->addWidget(receAscllRButton,7,0,1,1); - configSubLayout->addWidget(receHexRButton,7,1,1,1); - configSubLayout->addWidget(receClearButton,8,0,1,1); - configSubLayout->addWidget(receSaveButton,8,1,1,1); - - configGroupBox->setLayout(configSubLayout); - configGroupBox->setMaximumWidth(250); - - configLayout->addWidget(configGroupBox); - configLayout->addStretch(); - - /************************状态区**************************************/ - statusLayout->addStretch(); - statusLayout->addWidget(sendCntLabel); - statusLayout->addWidget(receCntLabel); - statusLayout->addStretch(); - statusLayout->addWidget(curTimeLabel); + recePart.layout->addWidget(recePart.ascllText); + recePart.layout->addWidget(recePart.hexText); + recePart.layout->addWidget(recePart.chartView); + xIndex = 0; + recePart.axisX->setTickCount(10); + recePart.axisX->setLabelFormat("%i"); + recePart.axisX->setRange(0,100); + // recePart.axisX->setTitleText(QString::fromLocal8Bit("时间")); + recePart.chart->addAxis(recePart.axisX, Qt::AlignBottom); + + recePart.axisY->setTickCount(10); + recePart.axisY->setRange(0,100); + recePart.axisY->setLabelFormat("%i"); + // recePart.axisY->setTitleText(QString::fromLocal8Bit("幅度")); + recePart.chart->addAxis(recePart.axisY, Qt::AlignLeft); + for(int i = 0;i < 5;i++) + { + recePart.chart->addSeries(recePart.series[i]); + recePart.series[i]->attachAxis(recePart.axisX); + recePart.series[i]->attachAxis(recePart.axisY); + } + recePart.chart->legend()->hide(); + //recePart.chart->setTitle(QString::fromLocal8Bit("串口波形")) + recePart.chartView->setRenderHint(QPainter::Antialiasing); + + /************************串口配置**************************************/ + configPart.subLayout->addWidget(configPart.comBox,0,0,1,2); + configPart.subLayout->addWidget(configPart.baudLabel,1,0,1,1); + configPart.subLayout->addWidget(configPart.baudBox,1,1,1,1); + configPart.subLayout->addWidget(configPart.dataLabel,2,0,1,1); + configPart.subLayout->addWidget(configPart.dataBox,2,1,1,1); + configPart.subLayout->addWidget(configPart.stopLabel,3,0,1,1); + configPart.subLayout->addWidget(configPart.stopBox,3,1,1,1); + configPart.subLayout->addWidget(configPart.checkLabel,4,0,1,1); + configPart.subLayout->addWidget(configPart.checkBox,4,1,1,1); + configPart.subLayout->addWidget(configPart.scanButton,5,1,1,1); + configPart.subLayout->addWidget(configPart.operatButton,6,1,1,1); + configPart.receRButtonGroup->addButton(configPart.ascllRButton); + configPart.receRButtonGroup->addButton(configPart.hexRButton); + configPart.receRButtonGroup->addButton(configPart.waveRButton); + + configPart.subLayout->addWidget(configPart.ascllRButton,7,0,1,1); + configPart.subLayout->addWidget(configPart.hexRButton,7,1,1,1); + configPart.subLayout->addWidget(configPart.waveRButton,8,0,1,1); + configPart.subLayout->addWidget(configPart.receClearButton,9,0,1,1); + configPart.subLayout->addWidget(configPart.receSaveButton,9,1,1,1); + + configPart.configGBox->setLayout(configPart.subLayout); + configPart.configGBox->setMaximumWidth(250); + + configPart.layout->addWidget(configPart.configGBox); + configPart.layout->addStretch(); /************************发送区**************************************/ @@ -241,57 +252,65 @@ void serial::Serial_UiInit(void) /*****************协议发送***************/ - protocolHeadLEdit->setMaximumWidth(100); - protocolPeriod->setMaximumWidth(100); + protSendPart.headLEdit->setMaximumWidth(100); + protSendPart.periodLEdit->setMaximumWidth(100); - protocolFileBar->setRange(0,100); - protocolFileBar->setValue(0); - protocolFileBar->setOrientation (Qt::Horizontal); + protSendPart.fileBar->setRange(0,100); + protSendPart.fileBar->setValue(0); + protSendPart.fileBar->setOrientation (Qt::Horizontal); QRegExp rx("^[0-9a-fA-F ]+$"); - QValidator *vali=new QRegExpValidator(rx,protocolDataLEdit); - protocolDataLEdit->setValidator(vali); - - - protocolLayout1->addWidget(protocolHeadLabel); - protocolLayout1->addWidget(protocolHeadLEdit); - protocolLayout1->addWidget(protocolFunLabel); - protocolLayout1->addWidget(protocolFunBox); - protocolLayout1->addWidget(protocolIDLabel); - protocolLayout1->addWidget(protocolIDBox); - protocolLayout1->addWidget(protocolDataLEdit); - - protocolLayout2->addWidget(protocolTypeLabel); - protocolLayout2->addWidget(protocolTypeBox); - protocolLayout2->addWidget(protocolRespCBox); - protocolLayout2->addWidget(protocolVersionButton); - - protocolLayout2->addStretch(); - protocolLayout2->addWidget(protocolClearButton); - protocolLayout2->addWidget(protocolSendButton); - - protocolLayout3->addWidget(protocolCrcTypeLabel); - protocolLayout3->addWidget(protocolCrcTypeBox); - protocolLayout3->addWidget(protocolCrcValueLabel); - protocolLayout3->addStretch(); - protocolLayout3->addWidget(protocolSendTime); - protocolLayout3->addWidget(protocolPeriod); - protocolLayout3->addWidget(protocolPeriodLabel); - - protocolLayout4->addWidget(protocolFileLEdit); - protocolLayout4->addWidget(protocolFileAddButton); - - protocolLayout5->addWidget(protocolFileBar); - protocolLayout5->addWidget(protocolFileSendButton); - - protocolLayout6->addWidget(protocolData); - - protocolLayout->addLayout(protocolLayout1); - protocolLayout->addLayout(protocolLayout2); - protocolLayout->addLayout(protocolLayout3); - protocolLayout->addLayout(protocolLayout4); - protocolLayout->addLayout(protocolLayout5); - protocolLayout->addLayout(protocolLayout6); - protocolGroupBox->setLayout(protocolLayout); + QValidator *vali=new QRegExpValidator(rx,protSendPart.dataLEdit); + protSendPart.dataLEdit->setValidator(vali); + + protSendPart.layout->addWidget(protSendPart.headLabel,0,0,1,1); + protSendPart.layout->addWidget(protSendPart.headLEdit,0,1,1,1); + protSendPart.layout->addWidget(protSendPart.funLabel,0,2,1,1); + protSendPart.layout->addWidget(protSendPart.funCBox,0,3,1,1); + protSendPart.layout->addWidget(protSendPart.idLabel,0,4,1,1); + protSendPart.layout->addWidget(protSendPart.idCBox,0,5,1,1); + protSendPart.layout->addWidget(protSendPart.dataLEdit,0,6,1,6); + + protSendPart.layout->addWidget(protSendPart.typeLabel,1,0,1,1); + protSendPart.layout->addWidget(protSendPart.typeBox,1,1,1,1); + protSendPart.layout->addWidget(protSendPart.respChBox,1,2,1,1); + protSendPart.layout->addWidget(protSendPart.clearButton,1,10,1,1); + protSendPart.layout->addWidget(protSendPart.sendButton,1,11,1,1); + + protSendPart.layout->addWidget(protSendPart.crcTypeLabel,2,0,1,1); + protSendPart.layout->addWidget(protSendPart.crcTypeBox,2,1,1,1); + protSendPart.layout->addWidget(protSendPart.crcValueLabel,2,2,1,1); + protSendPart.layout->addWidget(protSendPart.timeChBox,2,9,1,1); + protSendPart.layout->addWidget(protSendPart.periodLEdit,2,10,1,1); + protSendPart.layout->addWidget(protSendPart.periodLabel,2,11,1,1); + + protSendPart.layout->addWidget(protSendPart.fileLEdit,3,0,1,11); + protSendPart.layout->addWidget(protSendPart.fileAddButton,3,11,1,1); + + protSendPart.layout->addWidget(protSendPart.fileBar,4,0,1,11); + protSendPart.layout->addWidget(protSendPart.fileSendButton,4,11,1,1); + + protSendPart.layout->addWidget(protSendPart.protocolDataLEdit,5,0,1,12); + + protSendPart.headLabel->setMaximumWidth(50); + protSendPart.respChBox->setMaximumWidth(50); + protSendPart.crcTypeLabel->setMaximumWidth(50); + + protSendPart.funLabel->setMaximumWidth(80); + protSendPart.crcTypeLabel->setMaximumWidth(80); + protSendPart.crcValueLabel->setMaximumWidth(80); + + protSendPart.idLabel->setMaximumWidth(30); + protSendPart.funCBox->setMaximumWidth(50); + protSendPart.idCBox->setMaximumWidth(50); + + protSendPart.timeChBox->setMaximumWidth(80); + + protSendPart.clearButton->setMaximumWidth(80); + protSendPart.sendButton->setMaximumWidth(80); + protSendPart.fileAddButton->setMaximumWidth(80); + protSendPart.fileSendButton->setMaximumWidth(80); + + protSendPart.protGBox->setLayout(protSendPart.layout); /*****************多条发送***************/ for(int i = 0;i < 5;i++) @@ -348,27 +367,27 @@ void serial::Serial_UiInit(void) sendTabWindget->setMaximumHeight(250); sendTabWindget->addTab(onceGroupBox,QString::fromLocal8Bit("单条发送")); - sendTabWindget->addTab(protocolGroupBox,QString::fromLocal8Bit("协议发送")); + sendTabWindget->addTab(protSendPart.protGBox,QString::fromLocal8Bit("协议发送")); sendTabWindget->addTab(multiGroupBox,QString::fromLocal8Bit("多条发送")); - receLayout->addLayout(configLayout); + recePart.layout->addLayout(configPart.layout); - mainLayout->addLayout(receLayout); + mainLayout->addLayout(recePart.layout); mainLayout->addWidget(sendTabWindget); - mainLayout->addLayout(statusLayout); this->setLayout(mainLayout); onceSendButton->setEnabled(false); - receHex->setVisible(false); - receAscllRButton->setChecked(true); - receSaveButton->setEnabled(false); + recePart.hexText->setVisible(false); + recePart.chartView->setVisible(false); + + configPart.ascllRButton->setChecked(true); + configPart.receSaveButton->setEnabled(false); onceAscllRButton->setChecked(true); - protocolSendButton->setEnabled(false); + protSendPart.fileSendButton->setEnabled(false); + protSendPart.fileAddButton->setEnabled(false); - protocolFileAddButton->setEnabled(false); - protocolFileSendButton->setEnabled(false); } /* * ********************************************************************* @@ -381,39 +400,48 @@ void serial::Serial_UiInit(void) void serial::Serial_UiCreate(void) { mainLayout = new QVBoxLayout; - receLayout = new QHBoxLayout; - configLayout = new QVBoxLayout; - statusLayout = new QHBoxLayout; + /************************接收区**************************************/ - receText = new QTextBrowser; - receHex = new QTextBrowser; + recePart.layout = new QHBoxLayout; + recePart.ascllText = new QTextBrowser; + recePart.hexText = new QTextBrowser; + + for(int i = 0;i < 5;i++) + { + recePart.series[i] = new QLineSeries; + } + recePart.axisX = new QValueAxis; + recePart.axisY = new QValueAxis; + recePart.chart = new QChart; + recePart.chartView = new QChartView(recePart.chart); + /************************串口配置**************************************/ - configSubLayout = new QGridLayout; - configGroupBox = new QGroupBox(QString::fromLocal8Bit("串口配置")); - - baudLabel = new QLabel(QString::fromLocal8Bit("波特率")); - dataLabel = new QLabel(QString::fromLocal8Bit("数据位")); - checkLabel = new QLabel(QString::fromLocal8Bit("检验位")); - stopLabel = new QLabel(QString::fromLocal8Bit("停止位")); - - comBox = new QComboBox; - baudBox = new QComboBox; - dataBox = new QComboBox; - checkBox = new QComboBox; - stopBox = new QComboBox; - scanButton = new QPushButton(QString::fromLocal8Bit("扫描")); - operatButton = new QPushButton(QString::fromLocal8Bit("打开")); - receRButtonGroup = new QButtonGroup; - receAscllRButton = new QRadioButton(QString::fromLocal8Bit("ASCLL")); - receHexRButton = new QRadioButton(QString::fromLocal8Bit("Hex")); - receClearButton = new QPushButton(QString::fromLocal8Bit("清除接收")); - receSaveButton = new QPushButton(QString::fromLocal8Bit("保存到文件")); - - /************************状态区**************************************/ - curTimeLabel = new QLabel; - sendCntLabel = new QLabel(QString::fromLocal8Bit("TX:0")); - receCntLabel = new QLabel(QString::fromLocal8Bit("RX:0")); + configPart.layout = new QVBoxLayout; + configPart.subLayout = new QGridLayout; + configPart.configGBox = new QGroupBox(QString::fromLocal8Bit("串口配置")); + + configPart.baudLabel = new QLabel(QString::fromLocal8Bit("波特率")); + configPart.dataLabel = new QLabel(QString::fromLocal8Bit("数据位")); + configPart.checkLabel = new QLabel(QString::fromLocal8Bit("检验位")); + configPart.stopLabel = new QLabel(QString::fromLocal8Bit("停止位")); + + configPart.comBox = new QComboBox; + configPart.baudBox = new QComboBox; + configPart.dataBox = new QComboBox; + configPart.checkBox = new QComboBox; + configPart.stopBox = new QComboBox; + configPart.scanButton = new QPushButton(QString::fromLocal8Bit("扫描")); + configPart.operatButton = new QPushButton(QString::fromLocal8Bit("打开")); + configPart.receRButtonGroup = new QButtonGroup; + configPart.ascllRButton = new QRadioButton(QString::fromLocal8Bit("ASCLL")); + configPart.hexRButton = new QRadioButton(QString::fromLocal8Bit("Hex")); + configPart.waveRButton = new QRadioButton(QString::fromLocal8Bit("Wave")); + + configPart.receClearButton = new QPushButton(QString::fromLocal8Bit("清除接收")); + configPart.receSaveButton = new QPushButton(QString::fromLocal8Bit("保存到文件")); + + /************************发送区**************************************/ sendTabWindget = new QTabWidget; @@ -433,48 +461,40 @@ void serial::Serial_UiCreate(void) onceSendText = new QTextEdit; /*****************协议发送***************/ - - protocolLayout = new QVBoxLayout; - protocolGroupBox = new QGroupBox; - - protocolLayout1 = new QHBoxLayout; - protocolLayout2 = new QHBoxLayout; - protocolLayout3 = new QHBoxLayout; - protocolLayout4 = new QHBoxLayout; - protocolLayout5 = new QHBoxLayout; - protocolLayout6 = new QHBoxLayout; - - protocolHeadLabel = new QLabel(QString::fromLocal8Bit("协议帧头")); - protocolHeadLEdit = new QLineEdit("A5 5A"); - protocolFunLabel = new QLabel(QString::fromLocal8Bit("Fun")); - protocolFunBox = new QComboBox; - protocolIDLabel = new QLabel(QString::fromLocal8Bit("ID")); - protocolIDBox = new QComboBox; - protocolDataLEdit = new QLineEdit; - - protocolTypeLabel = new QLabel(QString::fromLocal8Bit("协议类型")); - protocolTypeBox = new QComboBox; - protocolRespCBox = new QCheckBox(QString::fromLocal8Bit("应答")); - protocolVersionButton = new QPushButton(QString::fromLocal8Bit("版本查询")); - protocolClearButton = new QPushButton(QString::fromLocal8Bit("清除发送")); - protocolSendButton = new QPushButton(QString::fromLocal8Bit("发送")); - - protocolCrcTypeLabel = new QLabel(QString::fromLocal8Bit("校验类型")); - protocolCrcTypeBox = new QComboBox; - protocolCrcValueLabel = new QLabel(QString::fromLocal8Bit("校验值 0x00")); - protocolSendTime = new QCheckBox(QString::fromLocal8Bit("定时发送")); - protocolPeriodLabel = new QLabel(QString::fromLocal8Bit("ms周期")); - protocolPeriod = new QLineEdit(QString::fromLocal8Bit("1000")); - - protocolFileLEdit = new QLineEdit; - protocolFileAddButton = new QPushButton(QString::fromLocal8Bit("打开文件")); - - protocolFileSendButton = new QPushButton(QString::fromLocal8Bit("发送文件")); - protocolFileBar = new QProgressBar; + protSendPart.layout = new QGridLayout; + protSendPart.protGBox = new QGroupBox; + + + protSendPart.headLabel = new QLabel(QString::fromLocal8Bit("协议帧头")); + protSendPart.headLEdit = new QLineEdit("A5 5A"); + protSendPart.funLabel = new QLabel(QString::fromLocal8Bit("Fun")); + protSendPart.funCBox = new QComboBox; + protSendPart.idLabel = new QLabel(QString::fromLocal8Bit("ID")); + protSendPart.idCBox = new QComboBox; + protSendPart.dataLEdit = new QLineEdit; + + protSendPart.typeLabel = new QLabel(QString::fromLocal8Bit("协议类型")); + protSendPart.typeBox = new QComboBox; + protSendPart.respChBox = new QCheckBox(QString::fromLocal8Bit("应答")); + protSendPart.clearButton = new QPushButton(QString::fromLocal8Bit("清除发送")); + protSendPart.sendButton = new QPushButton(QString::fromLocal8Bit("发送")); + + protSendPart.crcTypeLabel = new QLabel(QString::fromLocal8Bit("校验类型")); + protSendPart.crcTypeBox = new QComboBox; + protSendPart.crcValueLabel = new QLabel(QString::fromLocal8Bit("校验值 0x00")); + protSendPart.timeChBox = new QCheckBox(QString::fromLocal8Bit("定时发送")); + protSendPart.periodLabel = new QLabel(QString::fromLocal8Bit("ms周期")); + protSendPart.periodLEdit = new QLineEdit(QString::fromLocal8Bit("1000")); + + protSendPart.fileLEdit = new QLineEdit; + protSendPart.fileAddButton = new QPushButton(QString::fromLocal8Bit("打开文件")); + + protSendPart.fileSendButton = new QPushButton(QString::fromLocal8Bit("发送文件")); + protSendPart.fileBar = new QProgressBar; protocolFile = new QFile; protocolFileStream = new QDataStream; - protocolData = new QLineEdit; + protSendPart.protocolDataLEdit = new QLineEdit; /*****************多条发送***************/ multiLayout = new QVBoxLayout; /*垂直布局*/ @@ -516,28 +536,12 @@ void serial::Serial_UiCreate(void) * 返回值:无 **************************************************************** */ -void serial::Serial_UpdateTime(void) -{ - QTime timeCur = QTime::currentTime(); - - //curTimeLabel->setText(tr("%1").arg(timeCur.toString())); - curTimeLabel->setText(timeCur.toString("hh:mm:ss")); - Serial_UpdateCnt(); -} -/* -**************************************************************** -* 功能:更新实时时间 -* 输入:无 -* 输出:无 -* 返回值:无 -**************************************************************** -*/ void serial::Serial_ScanCom(void) { serialName.clear(); if(NULL != serialPort) { - comBox->clear(); + configPart.comBox->clear(); QStringList strList; foreach(const QSerialPortInfo &info,QSerialPortInfo::availablePorts()) /*查找串口*/ { @@ -545,7 +549,7 @@ void serial::Serial_ScanCom(void) availableport.setPortName(info.portName()); - //if(availableport.open(QIODevice::ReadWrite)) /*串口是否可读可写*/ + if(availableport.open(QIODevice::ReadWrite)) /*串口是否可读可写*/ { QString temp = ""; temp += info.portName(); @@ -558,14 +562,14 @@ void serial::Serial_ScanCom(void) QByteArray ba = info.portName().toLatin1(); ch=ba.data(); - INFO_MSG("Port Name: %s\r\n",ch); + INFO_MSG("Port Name: %s",ch); ba = info.description().toLatin1(); ch=ba.data(); - INFO_MSG("description: %s\r\n",ch); + INFO_MSG("description: %s",ch); availableport.close(); } } - comBox->addItems(strList); + configPart.comBox->addItems(strList); } else { @@ -586,14 +590,14 @@ void serial::Serial_Operat(void) { if(Serial_Open() == OK) { - operatButton->setText(QString::fromLocal8Bit("关闭串口")); + configPart.operatButton->setText(QString::fromLocal8Bit("关闭串口")); serialComStatus = 1; } } else { Serial_Close(); - operatButton->setText(QString::fromLocal8Bit("打开串口")); + configPart.operatButton->setText(QString::fromLocal8Bit("打开串口")); serialComStatus = 0; } } @@ -612,7 +616,7 @@ void serial::Serial_ErrorHandle(QSerialPort::SerialPortError _error) ERROR_MSG("Serial port error:%X\r\n",_error); Serial_Close(); - operatButton->setText(QString::fromLocal8Bit("打开串口")); + configPart.operatButton->setText(QString::fromLocal8Bit("打开串口")); serialComStatus = false; QMessageBox::about(NULL, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("串口已断开!")); @@ -644,10 +648,24 @@ void serial::Serial_ReceData(void) */ void serial::Serial_ReceFormat(bool flags) { - if(flags)//if(ReceHEX->isChecked()) - receHex->setVisible(true); + if(configPart.hexRButton->isChecked()) + recePart.hexText->setVisible(true); + else + recePart.hexText->setVisible(false); + if(configPart.waveRButton->isChecked()) + recePart.chartView->setVisible(true); else - receHex->setVisible(false); + { + recePart.chartView->setVisible(false); + for(int i = 0;i < 5;i++) + { + recePart.series[i]->clear(); + } + recePart.axisX->setTickCount(10); + recePart.axisX->setRange(0, 100); + xIndex = 0; + } + } /* **************************************************************** @@ -659,9 +677,16 @@ void serial::Serial_ReceFormat(bool flags) */ void serial::Serial_ClearRece(void) { - receText->clear(); - receHex->clear(); - serialReceCnt = 0; + recePart.ascllText->clear(); + recePart.hexText->clear(); + g_sysData.serialRxCnt = 0; + for(int i = 0;i < 5;i++) + { + recePart.series[i]->clear(); + } + recePart.axisX->setTickCount(10); + recePart.axisX->setRange(0, 100); + xIndex = 0; } /* **************************************************************** @@ -674,7 +699,7 @@ void serial::Serial_ClearRece(void) void serial::Serial_ClearSend(void) { onceSendText->clear(); - serialSendCnt = 0; + g_sysData.serialTxCnt = 0; } /* **************************************************************** @@ -701,6 +726,27 @@ void serial::Serial_SendData(void) else QMessageBox::warning(this,QString::fromLocal8Bit("警告"),QString::fromLocal8Bit("没有打开串口"),QMessageBox::Ok); } +void serial::Serial_ChartTimeOut() +{ + if(recePart.chartView->isVisible()) + { + QDateTime dt; + QString current_dt = dt.currentDateTime().toString("yyyy:MM:dd:hh:mm:ss:zzz"); + qsrand(dt.currentDateTime().toTime_t()); + int y = qrand() % 20; + if(xIndex == 1000) + recePart.axisX->setTickCount(7); + for(int i = 0;i < 5;i++) + { + recePart.series[i]->append(xIndex,y + i * 20); + } + qreal x = recePart.chart->plotArea().width() / 100; + + if(xIndex > 100) + recePart.chart->scroll(x,0); + xIndex ++; + } +} /* **************************************************************** * 功能:串口接收500ms时间超时 @@ -737,10 +783,10 @@ void serial::Serial_TimeOut(void) Serial_ProtocolRece(buf); break; case 2: - receText->append(str); + recePart.ascllText->append(str); break; } - serialReceCnt += buf.length(); + g_sysData.serialRxCnt += buf.length(); } buf.clear(); @@ -786,10 +832,10 @@ void serial::Serial_receTimeOut(void) Serial_ProtocolRece(buf); break; case 2: - Serial_OnceRece(buf); + recePart.ascllText->append(str); break; } - serialReceCnt += buf.length(); + g_sysData.serialRxCnt += buf.length(); } buf.clear(); Serial_DataDisply(serialBuf); @@ -807,10 +853,10 @@ void serial::Serial_SendModeChanged(int index) { if(index == 1) { - if(!receHex->isVisible()) + if(!recePart.hexText->isVisible()) { - receHex->setVisible(true); - receHexRButton->setChecked(true); + recePart.hexText->setVisible(true); + configPart.hexRButton->setChecked(true); } protocolTimer->start(50); } @@ -830,11 +876,11 @@ void serial::Serial_SendModeChanged(int index) */ void serial::Serial_ProtocolClearSend(void) { - serialSendCnt = 0; - protocolDataLEdit->clear(); - protocolFileLEdit->clear(); - protocolData->clear(); - protocolFileSendButton->setEnabled(false); + g_sysData.serialTxCnt = 0; + protSendPart.dataLEdit->clear(); + protSendPart.fileLEdit->clear(); + protSendPart.protocolDataLEdit->clear(); + protSendPart.sendButton->setEnabled(false); } /* **************************************************************** @@ -846,46 +892,18 @@ void serial::Serial_ProtocolClearSend(void) */ void serial::Serial_protocolDataChanged(const QString &arg1) { - UINT32 textLen,len,i; + UINT32 textLen,i; QString uStr,uStr1,uStr2; - len = arg1.count(); - if(protocolDataCnt == len) - return; - if(arg1 == "") + textLen = arg1.count(); + if(protocolDataCnt == textLen) return; - uStr1 = arg1; qDebug()< len) - { - if(len > 2) - { - if(arg1.at(arg1.size() - 3) == " ") - { - - uStr2 = uStr1; - uStr1 = uStr2.left(uStr2.size()-1); - textLen --; - } - } - else - { - if((textLen % 2) == 0) - { - uStr2 = uStr1; - uStr1 = uStr2.left(uStr2.size()-1); - textLen --; - } - } - } qDebug()<<"textLen"<setText(uStr); + protSendPart.dataLEdit->setText(uStr); protocolDataCnt = uStr.count(); } @@ -916,50 +934,49 @@ void serial::Serial_protocolTypeChanged(int index) g_ProtocolData.type = index; if((g_ProtocolData.type == ProtocolCustom)||(g_ProtocolData.type == ProtocolHDsmart)) { - protocolFunLabel->setVisible(true); - protocolFunBox->setVisible(true); - protocolVersionButton->setVisible(true); + protSendPart.funLabel->setVisible(true); + protSendPart.funCBox->setVisible(true); + } else { - protocolFunLabel->setVisible(false); - protocolFunBox->setVisible(false); - protocolVersionButton->setVisible(false); + protSendPart.funLabel->setVisible(false); + protSendPart.funCBox->setVisible(false); } /*******************设置帧头***********************/ if((g_ProtocolData.type == ProtocolCustom)||(g_ProtocolData.type == ProtocolHDsmart)) { - protocolHeadLEdit->setText("A5 5A"); + protSendPart.headLEdit->setText("A5 5A"); } /*******************设置校验类型***********************/ if(g_ProtocolData.type == ProtocolCustom) { - protocolCrcTypeBox->setCurrentIndex(ProtocolCheckLRC); - protocolCrcTypeBox->setEnabled(true); + protSendPart.crcTypeBox->setCurrentIndex(ProtocolCheckLRC); + protSendPart.crcTypeBox->setEnabled(true); } else if(g_ProtocolData.type == ProtocolHDsmart) { - protocolCrcTypeBox->setCurrentIndex(ProtocolCheckLRC); - protocolCrcTypeBox->setEnabled(false); + protSendPart.crcTypeBox->setCurrentIndex(ProtocolCheckLRC); + protSendPart.crcTypeBox->setEnabled(false); } QStringList cmdStrList; - protocolIDBox->clear(); - protocolFunBox->clear(); + protSendPart.idCBox->clear(); + protSendPart.funCBox->clear(); uint8_t type = g_ProtocolData.type; QStringList funStrList; for(int i=0;iaddItems(funStrList); + protSendPart.funCBox->addItems(funStrList); for(int i=0;iaddItems(cmdStrList); + protSendPart.idCBox->addItems(cmdStrList); } /* **************************************************************** @@ -986,7 +1003,7 @@ void serial::Serial_ProtocolSendTime(int _status) uint32_t uiPeriod = 0; if (_status == Qt::Checked) // "选中" { - QString str = protocolPeriod->text(); + QString str = protSendPart.periodLEdit->text(); uiPeriod = str.toUInt(); protocolSendTimer->start(uiPeriod); } @@ -1037,7 +1054,7 @@ void serial::Serial_ProtocolReceTimeOut(void) */ void serial::Serial_ProtocolOpenFile(void) { - QStringList filelist=QFileDialog::getOpenFileNames(this,QString::fromLocal8Bit("文件"),serialFileName,QString::fromLocal8Bit("*.bin *.FPK"));//用个文件登陆框来选择文件,包括多个文件 + QStringList filelist=QFileDialog::getOpenFileNames(this,QString::fromLocal8Bit("文件"),serialFileName,QString::fromLocal8Bit("*.bin"));//用个文件登陆框来选择文件,包括多个文件 if(!filelist.isEmpty()) { for(int i=0;iclear(); - protocolFileLEdit->setText(serialFileName); + protSendPart.fileLEdit->clear(); + protSendPart.fileLEdit->setText(serialFileName); } - protocolFileSendButton->setEnabled(true); + protSendPart.fileSendButton->setEnabled(true); } - protocolFileBar->setValue(0); + protSendPart.fileBar->setValue(0); } /* **************************************************************** @@ -1064,6 +1081,9 @@ void serial::Serial_ProtocolSendFile(void) { if(serialPort->isOpen()) { + //protocolFileAddButton->setEnabled(false); + //protocolFileSendButton->setEnabled(false); + protocolFile = new QFile(serialFileName); protocolFile->open(QIODevice::ReadOnly); @@ -1071,31 +1091,19 @@ void serial::Serial_ProtocolSendFile(void) g_ProtocolData.fileSize = info.size(); g_ProtocolData.fileCurPos = 0; DEBUG_MSG("File Size :%d\r\n",g_ProtocolData.fileSize); - char *p = (char *)malloc(g_ProtocolData.fileSize); - if(p != NULL) - { - protocolFile->read(p,g_ProtocolData.fileSize); - DEBUG_MSG("File CRC32 :%X\r\n",Verify_CalCRC32((UINT8 *)p,g_ProtocolData.fileSize)); - free(p); - protocolFile->close(); - } - else - { - DEBUG_MSG("malloc Fail\r\n"); - } + g_ProtocolData.isSendFile = true; g_ProtocolData.packNum = 0; - protocolFile->open(QIODevice::ReadOnly); - if(Serial_ProtocolSendFileData(g_ProtocolData.packNum) ==0xFFFFFFFF) + if(Serial_ProtocolSendFile(g_ProtocolData.packNum) ==0xFFFFFFFF) { - protocolFileAddButton->setEnabled(true); - protocolFileSendButton->setEnabled(true); + protSendPart.fileAddButton->setEnabled(true); + protSendPart.fileSendButton->setEnabled(true); g_ProtocolData.fileSize = 0; g_ProtocolData.fileCurPos = 0; g_ProtocolData.isSendFile = false; g_ProtocolData.packNum = 0; protocolFile->close(); - ERROR_MSG("SendFile close"); + ERROR_MSG("SendFile"); } } else @@ -1103,72 +1111,6 @@ void serial::Serial_ProtocolSendFile(void) } /* **************************************************************** -* 功能:协议版本查询快捷方式 -* 输入:无 -* 输出:无 -* 返回值:无 -**************************************************************** -*/ -void serial::Serial_ProtocolVersionQuery(void) -{ - uint8_t sendBuf[255] ={0}; - UINT cmdLen = 0; - - QString str = protocolHeadLEdit->text(); - QStringList strList = str.split(" "); - for(int i=0;isetText(uStr); - if(g_ProtocolData.crcType != ProtocolCheckNone) - { - QString crcStr; - crcStr.sprintf("0x%X",sendBuf[cmdLen -1]); - protocolCrcValueLabel->setText(crcStr); - } - else - { - protocolCrcValueLabel->setText("0xFF"); - } - serialPort->write((const char *)sendBuf, cmdLen); - serialSendCnt += cmdLen; - -} -/* -**************************************************************** * 功能:多条发送条目类型改变 * 输入:无 * 输出:无 @@ -1221,73 +1163,6 @@ void serial::Serial_MultiLineEditFinish() MySqlData->MySqlDatabase_Modify(MySqlData->table_name,i + 5,sta,itemLData1[i]->text()); } } -/* -**************************************************************** -* 功能:多条发送条目数据 -* 输入:无 -* 输出:无 -* 返回值:无 -**************************************************************** -*/ -void serial::Serial_MultiSendData(void) -{ - UINT32 item = 0,cmdLen = 0; - UINT8 sendBuf[255] ={0}; - QString itemStr; - for(int i = 0;i < 5;i++) - { - if(itemButton[i]->hasFocus()) - { - item = i; - itemStr = itemLData[i]->text(); - break; - } - if(itemButton1[i]->hasFocus()) - { - item = i + 5; - itemStr = itemLData1[i]->text(); - break; - } - } - DEBUG_MSG("itemButton[%d]",item); - UINT32 textLen,i; - QString uStr; - - textLen = itemStr.count(); - - qDebug()<<"textLen"<isChecked()) - { - itemStr.replace(" ","");//移除空格 - textLen = itemStr.count(); - for(i = 0;i < (textLen / 2);i++) - { - uStr.clear(); - uStr = itemStr.mid(2 * i,2); - sendBuf[cmdLen] = uStr.toInt(0,16); - cmdLen++; - } - if(textLen % 2) - { - uStr = itemStr.mid(2 * i,2); - sendBuf[cmdLen] = uStr.toInt(0,16); - cmdLen++; - } - } - else - { - QByteArray byteData = itemStr.toUtf8(); - - for(int i = 0;i < byteData.length();i++) - { - sendBuf[cmdLen] = byteData[i]; - cmdLen++; - } - } - - serialPort->write((const char *)sendBuf, cmdLen); - serialSendCnt += cmdLen; -} /*******************************************功能函数开始区**********************************************/ /* **************************************************************** @@ -1299,11 +1174,11 @@ void serial::Serial_MultiSendData(void) */ UINT32 serial::Serial_Open(void) { - if(comBox->count() != 0)//存在串口就进入 + if(configPart.comBox->count() != 0)//存在串口就进入 { - serialPort->setPortName(serialName[comBox->currentIndex()]);/*设置串口名*/ + serialPort->setPortName(serialName[configPart.comBox->currentIndex()]);/*设置串口名*/ - switch(baudBox->currentIndex()) /*设置波特率*/ + switch(configPart.baudBox->currentIndex()) /*设置波特率*/ { case 0: serialPort->setBaudRate(QSerialPort::Baud1200); @@ -1333,7 +1208,7 @@ UINT32 serial::Serial_Open(void) serialPort->setBaudRate(QSerialPort::Baud115200); break; } - switch(dataBox->currentIndex()) /*设置数据位*/ + switch(configPart.dataBox->currentIndex()) /*设置数据位*/ { case 0: serialPort->setDataBits(QSerialPort::Data8); @@ -1348,7 +1223,7 @@ UINT32 serial::Serial_Open(void) serialPort->setDataBits(QSerialPort::Data8); break; } - switch(checkBox->currentIndex()) /*设置校验位*/ + switch(configPart.checkBox->currentIndex()) /*设置校验位*/ { case 0: serialPort->setParity(QSerialPort::NoParity); @@ -1360,7 +1235,7 @@ UINT32 serial::Serial_Open(void) serialPort->setParity(QSerialPort::EvenParity); break; } - switch(stopBox->currentIndex()) /*设置停止位*/ + switch(configPart.stopBox->currentIndex()) /*设置停止位*/ { case 0: serialPort->setStopBits(QSerialPort::OneStop); @@ -1385,21 +1260,21 @@ UINT32 serial::Serial_Open(void) return NOK; } onceSendButton->setEnabled(true); - protocolSendButton->setEnabled(true); - protocolFileAddButton->setEnabled(true); + protSendPart.sendButton->setEnabled(true); + protSendPart.fileAddButton->setEnabled(true); //串口设置的下拉控件失能 - comBox->setEnabled(false); - baudBox->setEnabled(false); - dataBox->setEnabled(false); - checkBox->setEnabled(false); - stopBox->setEnabled(false); - scanButton->setEnabled(false); + configPart.comBox->setEnabled(false); + configPart.baudBox->setEnabled(false); + configPart.dataBox->setEnabled(false); + configPart.checkBox->setEnabled(false); + configPart.stopBox->setEnabled(false); + configPart.scanButton->setEnabled(false); char* pchar; QByteArray byteArray; - byteArray = comBox->currentText().toLatin1(); + byteArray = configPart.comBox->currentText().toLatin1(); pchar = byteArray.data(); INFO_MSG("%s Open\r\n",pchar); @@ -1427,28 +1302,28 @@ void serial::Serial_Close(void) char* pchar; QByteArray byteArray; - byteArray = comBox->currentText().toLatin1(); + byteArray = configPart.comBox->currentText().toLatin1(); pchar = byteArray.data(); INFO_MSG("%s Close\r\n",pchar); serialPort->close(); onceSendButton->setEnabled(false); - protocolSendButton->setEnabled(false); + protSendPart.sendButton->setEnabled(false); //串口设置的下拉控件使能 - comBox->setEnabled(true); - baudBox->setEnabled(true); - dataBox->setEnabled(true); - checkBox->setEnabled(true); - stopBox->setEnabled(true); - scanButton->setEnabled(true); + configPart.comBox->setEnabled(true); + configPart.baudBox->setEnabled(true); + configPart.dataBox->setEnabled(true); + configPart.checkBox->setEnabled(true); + configPart.stopBox->setEnabled(true); + configPart.scanButton->setEnabled(true); if (protocolSendTimer->isActive() ) protocolSendTimer->stop(); - protocolSendTime->setChecked(false); + protSendPart.timeChBox->setChecked(false); - protocolFileAddButton->setEnabled(false); - protocolFileSendButton->setEnabled(false); + protSendPart.fileAddButton->setEnabled(false); + protSendPart.fileSendButton->setEnabled(false); } /* **************************************************************** @@ -1518,8 +1393,8 @@ void serial::Serial_DataDisply(QByteArray _buf) UINT8 data; QString str; str.clear(); - receText->moveCursor(QTextCursor::End); - receText->setTextColor(Qt::black); + recePart.ascllText->moveCursor(QTextCursor::End); + recePart.ascllText->setTextColor(Qt::black); while (1) { ucLevel = Serial_GetLevel(_buf,i); @@ -1528,28 +1403,28 @@ void serial::Serial_DataDisply(QByteArray _buf) { if(!str.isEmpty()) { - receText->textCursor().insertText(str); + recePart.ascllText->textCursor().insertText(str); str.clear(); - receText->moveCursor(QTextCursor::End); + recePart.ascllText->moveCursor(QTextCursor::End); } if((ucLevel & 0xf00) == 0) - receText->setTextColor(Qt::black); + recePart.ascllText->setTextColor(Qt::black); switch (ucLevel & 0x00f) { case 1: - receText->setTextColor(Qt::red); + recePart.ascllText->setTextColor(Qt::red); break; case 2: - receText->setTextColor(Qt::darkGreen); + recePart.ascllText->setTextColor(Qt::darkGreen); break; case 3: - receText->setTextColor(Qt::darkYellow); + recePart.ascllText->setTextColor(Qt::darkYellow); break; case 4: - receText->setTextColor(Qt::blue); + recePart.ascllText->setTextColor(Qt::blue); break; default: - receText->setTextColor(Qt::black); + recePart.ascllText->setTextColor(Qt::black); break; } if(ucLevel & 0x1000) @@ -1569,10 +1444,10 @@ void serial::Serial_DataDisply(QByteArray _buf) break; if(data == '\0') { - receText->textCursor().insertText(str); + recePart.ascllText->textCursor().insertText(str); str.clear(); - receText->moveCursor(QTextCursor::End); - receText->setTextColor(Qt::black); + recePart.ascllText->moveCursor(QTextCursor::End); + recePart.ascllText->setTextColor(Qt::black); } else { @@ -1582,30 +1457,10 @@ void serial::Serial_DataDisply(QByteArray _buf) } if(!str.isEmpty()) { - receText->textCursor().insertText(str); + recePart.ascllText->textCursor().insertText(str); str.clear(); } - receText->moveCursor(QTextCursor::End); -} -/* -**************************************************************** -* 功能:单次接收显示 -* 输入:_buf:数据缓存 -* 输出:无 -* 返回值:无 -**************************************************************** -*/ -void serial::Serial_UpdateCnt(void) -{ - - QString crcStr; - crcStr.sprintf("TX:%ld",serialSendCnt); - sendCntLabel->setText(crcStr); - - crcStr.clear(); - crcStr.sprintf("RX:%ld",serialReceCnt); - receCntLabel->setText(crcStr); - + recePart.ascllText->moveCursor(QTextCursor::End); } /* **************************************************************** @@ -1618,7 +1473,7 @@ void serial::Serial_UpdateCnt(void) void serial::Serial_OnceRece(QByteArray _buf) { // 如果需要16进制显示数据 - if (receHexRButton->isChecked()) + if (configPart.hexRButton->isChecked()) { QString hex_data = _buf.toHex().data(); /*将buf里的数据转换成16进制*/ hex_data = hex_data.toUpper(); /*字母转换成大写*/ @@ -1631,9 +1486,9 @@ void serial::Serial_OnceRece(QByteArray _buf) hex_str+=st; hex_str+=' '; /*两个16进制数之间用空格隔开*/ } - receHex->append(hex_str); + recePart.hexText->append(hex_str); } - receHex->moveCursor(QTextCursor::End); + recePart.hexText->moveCursor(QTextCursor::End); } /* **************************************************************** @@ -1677,14 +1532,14 @@ void serial::Serial_OnceSend(void) } else serialPort->write(str.toLocal8Bit()); - serialSendCnt += str.length(); + g_sysData.serialTxCnt += str.length(); if(onceNewCBox->isChecked())//判断是否需要发送新行 { char data[2]; data[0] = 0x0d; data[1] = 0x0a; serialPort->write((const char *)data, 2); - serialSendCnt += 2; + g_sysData.serialTxCnt += 2; } } /* @@ -1701,7 +1556,7 @@ void serial::Serial_ProtocolSend(void) uint8_t fun = 0,cmdId = 0; UINT cmdLen = 0; - QString str = protocolHeadLEdit->text(); + QString str = protSendPart.headLEdit->text(); QStringList strList = str.split(" "); for(int i=0;icurrentText(); + str = protSendPart.funCBox->currentText(); fun = str.toInt(0,16); g_frameSend.fun = fun; /************获取指令ID************/ str.clear(); - str = protocolIDBox->currentText(); + str = protSendPart.idCBox->currentText(); cmdId = str.toInt(0,16); g_frameSend.cmdId = cmdId; /************获取指令数据************/ - QString strD = protocolDataLEdit->text(); + QString strD = protSendPart.dataLEdit->text(); QStringList strDList = strD.split(" "); g_frameSend.len = 0; for(int i=0;isetText(uStr); + protSendPart.protocolDataLEdit->setText(uStr); //QString crcStr = QString::number(crcValue); if(g_ProtocolData.crcType != ProtocolCheckNone) { QString crcStr; crcStr.sprintf("0x%X",sendBuf[cmdLen -1]); - protocolCrcValueLabel->setText(crcStr); + protSendPart.crcValueLabel->setText(crcStr); } else { - protocolCrcValueLabel->setText("0xFF"); + protSendPart.crcValueLabel->setText("0xFF"); } serialPort->write((const char *)sendBuf, cmdLen); - serialSendCnt += cmdLen; + g_sysData.serialTxCnt += cmdLen; } /* **************************************************************** @@ -1828,15 +1683,12 @@ void serial::Serial_ProtocolParse(void) str = QString::fromLocal8Bit("指令CRC:"); receTemp.sprintf("%02X\r\n",g_frameRece.crc.value); //格式化字符串 strRece = strRece + str + receTemp; - receText->append(strRece); - receText->moveCursor(QTextCursor::End); + recePart.ascllText->append(strRece); + recePart.ascllText->moveCursor(QTextCursor::End); /*****************************接收区文本显示结束******************************************************/ //receText->append(cmdBuff); - if(protocolRespCBox->isChecked()) - { + if(protSendPart.respChBox->isChecked()) Serial_ProtocolResp(); - } - if((g_ProtocolData.type == ProtocolCustom) || (g_ProtocolData.type == ProtocolHDsmart)) { UINT uiPackNum = 0; @@ -1844,26 +1696,28 @@ void serial::Serial_ProtocolParse(void) { if(g_ProtocolData.isSendFile) { + DEBUG_MSG("isSendFile"); uiPackNum = (UINT)(g_frameRece.data[1]+(g_frameRece.data[2] << 8)); - DEBUG_MSG("SendFile uiPackNum = %d\r\n",uiPackNum); + DEBUG_MSG("uiPackNum = %d\r\n",uiPackNum); if((g_ProtocolData.packNum + 1) == uiPackNum) { g_ProtocolData.packNum = uiPackNum; - if(Serial_ProtocolSendFileData(g_ProtocolData.packNum) == 0xFFFFFFFF) + if(Serial_ProtocolSendFile(g_ProtocolData.packNum) == 0xFFFFFFFF) { - protocolFileAddButton->setEnabled(true); - protocolFileSendButton->setEnabled(true); + protSendPart.fileAddButton->setEnabled(true); + protSendPart.fileSendButton->setEnabled(true); g_ProtocolData.fileSize = 0; g_ProtocolData.fileCurPos = 0; g_ProtocolData.isSendFile = false; g_ProtocolData.packNum = 0; ERROR_MSG("SendFile Fail"); } + DEBUG_MSG("uiPackNum = %d\r\n",g_ProtocolData.packNum); if(g_ProtocolData.fileCurPos == g_ProtocolData.fileSize) { - protocolFileAddButton->setEnabled(true); - protocolFileSendButton->setEnabled(true); + protSendPart.fileAddButton->setEnabled(true); + protSendPart.fileSendButton->setEnabled(true); g_ProtocolData.fileSize = 0; g_ProtocolData.fileCurPos = 0; g_ProtocolData.isSendFile = false; @@ -1881,33 +1735,33 @@ void serial::Serial_ProtocolParse(void) str = QString::fromLocal8Bit("固件版本: "); strVersion.sprintf("V%d.%d.%d",g_frameRece.data[1],g_frameRece.data[2],g_frameRece.data[3]); //格式化字符串 str += strVersion; - receText->append(str); + recePart.ascllText->append(str); str.clear(); str = QString::fromLocal8Bit("App版本: "); strVersion.sprintf("V%d.%d.%d",g_frameRece.data[4],g_frameRece.data[5],g_frameRece.data[6]); //格式化字符串 str += strVersion; - receText->append(str); + recePart.ascllText->append(str); str.clear(); str = QString::fromLocal8Bit("硬件版本: "); strVersion.sprintf("V%d",g_frameRece.data[7]); //格式化字符串 str += strVersion; - receText->append(str); + recePart.ascllText->append(str); str.clear(); str = QString::fromLocal8Bit("协议版本: "); strVersion.sprintf("V%d",g_frameRece.data[8]); //格式化字符串 str += strVersion; - receText->append(str); + recePart.ascllText->append(str); str.clear(); str = QString::fromLocal8Bit("编译日期: "); strVersion.sprintf("%d-%02d-%02d",g_frameRece.data[9] + 2000,g_frameRece.data[10],g_frameRece.data[11]); //格式化字符串 str += strVersion; - receText->append(str); + recePart.ascllText->append(str); str.clear(); str = QString::fromLocal8Bit("编译时间: "); - strVersion.sprintf("%02d:%02d:%02d\n",g_frameRece.data[12],g_frameRece.data[13],g_frameRece.data[14]); //格式化字符串 + strVersion.sprintf("%02d:%02d:%02d",g_frameRece.data[12],g_frameRece.data[13],g_frameRece.data[14]); //格式化字符串 str += strVersion; - receText->append(str); - receText->moveCursor(QTextCursor::End); + recePart.ascllText->append(str); + recePart.ascllText->moveCursor(QTextCursor::End); } } } @@ -1940,13 +1794,13 @@ void serial::Serial_ProtocolResp(void) * 返回值:无 **************************************************************** */ -UINT32 serial::Serial_ProtocolSendFileData(UINT _pack) +UINT32 serial::Serial_ProtocolSendFile(UINT _pack) { UCHAR sendBuf[1200] ={0}; UCHAR fun = 0,cmdId = 0; UINT cmdLen = 0; - QString str = protocolHeadLEdit->text(); + QString str = protSendPart.headLEdit->text(); //qDebug()<<"protocolHead:"<currentText(); + str = protSendPart.funCBox->currentText(); fun = str.toInt(0,16); g_frameSend.fun = fun; /************获取指令ID************/ str.clear(); - str = protocolIDBox->currentText(); + str = protSendPart.idCBox->currentText(); cmdId = str.toInt(0,16); g_frameSend.cmdId = cmdId; - g_ProtocolData.fileType = cmdId; /************配置数据数据************/ if((g_ProtocolData.type == ProtocolCustom) || (g_ProtocolData.type == ProtocolHDsmart)) @@ -1996,6 +1849,7 @@ UINT32 serial::Serial_ProtocolSendFileData(UINT _pack) g_frameSend.data[0] =0x2; /*下载中*/ CHAR fileData[200]; int len = protocolFile->read(fileData,200);//读取一行数据 + DEBUG_MSG("len = %d",len); for(int i = 0; i < len;i++) { g_frameSend.data[7+i] = fileData[i]; @@ -2005,7 +1859,7 @@ UINT32 serial::Serial_ProtocolSendFileData(UINT _pack) g_ProtocolData.fileCurPos += len; DEBUG_MSG("fileCurPos = %d",g_ProtocolData.fileCurPos); DEBUG_MSG("fileSize = %d",g_ProtocolData.fileSize); - protocolFileBar->setValue((g_ProtocolData.fileCurPos * 100)/g_ProtocolData.fileSize); + protSendPart.fileBar->setValue((g_ProtocolData.fileCurPos * 100)/g_ProtocolData.fileSize); if(g_ProtocolData.fileCurPos >= g_ProtocolData.fileSize) { protocolFile->close(); @@ -2023,19 +1877,20 @@ UINT32 serial::Serial_ProtocolSendFileData(UINT _pack) { QString crcStr; crcStr.sprintf("0x%X",sendBuf[cmdLen -1]); - protocolCrcValueLabel->setText(crcStr); + protSendPart.crcValueLabel->setText(crcStr); } else - protocolCrcValueLabel->setText("0xFF"); + protSendPart.crcValueLabel->setText("0xFF"); serialPort->write((const char *)sendBuf, cmdLen); - if(cmdLen > 14) - cmdLen = 14; + if(cmdLen > 11) + cmdLen = 11; for(UINT i = 0;itext(); + QString str = protSendPart.headLEdit->text(); //qDebug()<<"protocolHead:"<currentText(); + str = protSendPart.funCBox->currentText(); fun = str.toInt(0,16); //qDebug()<<"protocolFun:"<currentText(); + str = protSendPart.idCBox->currentText(); cmdId = str.toInt(0,16); g_frameSend.cmdId = cmdId; //qDebug()<<"protocolID:"<setText(crcStr); + protSendPart.crcValueLabel->setText(crcStr); serialPort->write((const char *)sendBuf, cmdLen); return; } diff --git a/Src/serial/serial.h b/Src/serial/serial.h index 6752554..33c8492 100644 --- a/Src/serial/serial.h +++ b/Src/serial/serial.h @@ -12,6 +12,14 @@ #include #include +#include +#include +#include +#include +#include + +QT_CHARTS_USE_NAMESPACE + #include #include #include @@ -56,18 +64,19 @@ public: void Serial_ProtocolParse(void); void Serial_ProtocolResp(void); - UINT32 Serial_ProtocolSendFileData(UINT _pack); + UINT32 Serial_ProtocolSendFile(UINT _pack); void Serial_ProtocolRequestFile(UINT _pack); void Serial_MultiInit(void); signals: private slots: - void Serial_UpdateTime(void); + void Serial_ScanCom(void); void Serial_Operat(void); void Serial_ErrorHandle(QSerialPort::SerialPortError _error); + void Serial_ChartTimeOut(void); void Serial_TimeOut(void); void Serial_receTimeOut(void); @@ -91,16 +100,13 @@ private slots: void Serial_ProtocolOpenFile(void); void Serial_ProtocolSendFile(void); - void Serial_ProtocolVersionQuery(void); void Serial_MultiTypeChanged(int index); void Serial_MultiLineEditFinish(); - - void Serial_MultiSendData(void); private: MySqlDatabase *MySqlData; int curTime; - UINT64 serialSendCnt,serialReceCnt; + UINT64 xIndex; UINT64 serialComStatus; UINT64 protocolDataCnt; @@ -117,39 +123,47 @@ private: }MultiData_T; QSerialPort *serialPort; - QTimer *realTimer; QTimer *serialTimer; + QTimer *serialChartTimer; QTimer *serialReceTimer; QTimer *protocolTimer; QTimer *protocolSendTimer; /************************布局**************************************/ QVBoxLayout *mainLayout; - QHBoxLayout *receLayout; - QVBoxLayout *configLayout; - QHBoxLayout *statusLayout; - /*************串口配置**************/ - QGridLayout *configSubLayout; - QGroupBox *configGroupBox; - QLabel *baudLabel,*dataLabel,*checkLabel,*stopLabel; - QLabel *operatLabel; - QComboBox *comBox,*baudBox,*dataBox,*checkBox,*stopBox; - QPushButton *scanButton; - QPushButton *operatButton; - - QButtonGroup *receRButtonGroup; - QRadioButton *receAscllRButton; - QRadioButton *receHexRButton; - QPushButton *receClearButton; - QPushButton *receSaveButton; /************************接收区**************************************/ - QTextBrowser *receText; - QTextBrowser *receHex; + struct Receive{ + QHBoxLayout *layout; + QTextBrowser *ascllText; + QTextBrowser *hexText; + + /***************接收区*************/ + QLineSeries *series[5]; + QChart *chart; + + //QDateTimeAxis *axisX; + QValueAxis *axisX; + QValueAxis *axisY; + QChartView *chartView; + }recePart; + + /************************串口配置**************************************/ + struct ConfigWindow{ + QVBoxLayout *layout; + QGridLayout *subLayout; + + QGroupBox *configGBox; + QLabel *baudLabel,*dataLabel,*checkLabel,*stopLabel; + QLabel *operatLabel; + QComboBox *comBox,*baudBox,*dataBox,*checkBox,*stopBox; + QPushButton *scanButton,*operatButton,*receClearButton,*receSaveButton; + + QButtonGroup *receRButtonGroup; + QRadioButton *ascllRButton,*hexRButton,*waveRButton; + }configPart; + /***************************/ - /************************状态区**************************************/ - QLabel *curTimeLabel; - QLabel *sendCntLabel,*receCntLabel; /************************发送区**************************************/ QTabWidget *sendTabWindget; @@ -168,39 +182,24 @@ private: QTextEdit *onceSendText; /*****************协议发送***************/ + struct SendProtocol{ + QGridLayout *layout; - QVBoxLayout *protocolLayout; - QGroupBox *protocolGroupBox; + QGroupBox *protGBox; - QHBoxLayout *protocolLayout1,*protocolLayout2,*protocolLayout3; - QHBoxLayout *protocolLayout4,*protocolLayout5,*protocolLayout6; - - QLabel *protocolHeadLabel,*protocolFunLabel,*protocolIDLabel; - QLineEdit *protocolHeadLEdit,*protocolDataLEdit; - QComboBox *protocolFunBox,*protocolIDBox; - - QLabel *protocolTypeLabel; - QComboBox *protocolTypeBox; - QCheckBox *protocolRespCBox; - QPushButton *protocolClearButton,*protocolSendButton; - QPushButton *protocolVersionButton; - - QLabel *protocolCrcTypeLabel,*protocolCrcValueLabel,*protocolPeriodLabel; - QComboBox *protocolCrcTypeBox; - QCheckBox *protocolSendTime; - QLineEdit *protocolPeriod; + QLabel *headLabel,*funLabel,*idLabel,*typeLabel,*crcTypeLabel,*crcValueLabel,*periodLabel; + QLineEdit *headLEdit,*dataLEdit,*periodLEdit,*fileLEdit,*protocolDataLEdit; + QComboBox *funCBox,*idCBox,*typeBox,*crcTypeBox; + QCheckBox *respChBox,*timeChBox; + QPushButton *clearButton,*sendButton, *fileAddButton,*fileSendButton; + QProgressBar *fileBar; + }protSendPart; //发送文件 - QLineEdit *protocolFileLEdit; - QPushButton *protocolFileAddButton; - QPushButton *protocolFileSendButton; - QProgressBar *protocolFileBar; QFile *protocolFile; QDataStream *protocolFileStream; - QLineEdit *protocolData; - /*****************多条发送***************/ QVBoxLayout *multiLayout; /*垂直布局*/ QGridLayout *itemLayout; diff --git a/Src/system/debug.cpp b/Src/system/debug.cpp index b76bfbf..790f845 100644 --- a/Src/system/debug.cpp +++ b/Src/system/debug.cpp @@ -24,10 +24,12 @@ static const char *g_logString[] = { * 返回值:字符个数 *********************************************************** */ +char buf_str[2048]; /* 特别注意,如果printf的变量较多,注意此局部变量的大小是否够用 */ +char outBuf[2048]; int App_Printf(uint8_t level,const char * format, ... ) { char Level_str[10]; - char buf_str[512]; /* 特别注意,如果printf的变量较多,注意此局部变量的大小是否够用 */ + va_list v_args; if (level > PRINT_LEVEL) /*判断打印等级*/ @@ -45,9 +47,10 @@ int App_Printf(uint8_t level,const char * format, ... ) v_args); va_end(v_args); if(level == LOG_COMMON_LEVEL) - qDebug("%s\n",buf_str); + qDebug("%s",buf_str); else - qDebug("%s%s\n",Level_str,buf_str); + qDebug("%s%s",Level_str,buf_str); + return 0; } diff --git a/Src/system/system.h b/Src/system/system.h index 4df3a42..7445113 100644 --- a/Src/system/system.h +++ b/Src/system/system.h @@ -34,7 +34,10 @@ typedef struct{ }SysInfo_T; /**************系统数据**************/ typedef struct{ - RealTime_T realTime; + UINT64 serialTxCnt; + UINT64 serialRxCnt; + UINT64 wifiTxCnt; + UINT64 wifiRxCnt; }SysData_T; /**************缓存数据结构**************/ typedef struct{ @@ -45,7 +48,6 @@ typedef struct{ extern uint8_t g_ucRuning; extern SysData_T g_sysData; //系统数据 extern SysInfo_T g_sysInfo; //系统信息 - #define OS_RUNING() g_ucRuning #define ERROR_HANDLER() Error_Handle(__FILE__, __LINE__) diff --git a/Src/system/upgrade.c b/Src/system/upgrade.c new file mode 100644 index 0000000..73554ad --- /dev/null +++ b/Src/system/upgrade.c @@ -0,0 +1,282 @@ +锘#include "upgrade.h" +#include +#include +#include +#include +#include "debug.h" + +const char author[24] = "www.hdsmart.net.cn"; +UpgradeInfo_T g_upgradeInfo; +FileInfo_T g_fileInfo[UPGRADE_MAX_FILE]; +void UpgradePackInit(UpgradeInfo_T *_info) +{ + errno_t err = 0; + time_t now_time = time(NULL); + struct tm t_tm; + err = localtime_s(&t_tm ,&now_time); + + memset((void*)_info, 0, sizeof(UpgradeInfo_T)); + _info->signature = 0x4D756E5A; /*绛惧悕0x4D756E5A*/ + _info->fVersion = 0x00010001; /*鍥轰欢鍖呮牸寮忕増鏈*/ + asctime_s(_info->date, 32, &t_tm); + + memcpy(_info->author, author, 24); + DEBUG_MSG("淇℃伅澶村ぇ灏忥細 %d\r\n", sizeof(UpgradeInfo_T)); + DEBUG_MSG("浣滆咃細%s\r\n", _info->author); + DEBUG_MSG("鏃ユ湡锛%s\r\n", _info->date); +} +void UpgradePackInfoGenerate(UpgradeInfo_T* _info,UINT8* _buf) +{ + printf("\r\n寮濮嬬敓鎴愬浐浠跺寘...\r\n"); + for (int i = 0; i < 4; i++) + _buf[i] = ((_info->signature >> (i * 8)) & 0xff); /*绛惧悕0x4D756E5A*/ + printf("绛惧悕锛 0x%X\r\n", _info->signature); + for (int i = 0; i < 4; i++) + _buf[4 + i] = ((_info->fVersion >> (i * 8)) & 0xff); /*鍥轰欢鍖呮牸寮忕増鏈*/ + printf("鍥轰欢鍖呮牸寮忕増鏈細 V%d.%d.%d\r\n", _buf[6], _buf[5], _buf[4]); + for (int i = 0; i < 4; i++) + _buf[8 + i] = ((_info->totalSize >> (i * 8)) & 0xff); /*鍥轰欢鍖呮诲ぇ灏*/ + printf("鍥轰欢鍖呮诲ぇ灏忥細 %d\r\n", _info->totalSize); + for (int i = 0; i < 4; i++) + _buf[12 + i] = ((_info->version >> (i * 8)) & 0xff); /*鍥轰欢搴旂敤鐗堟湰*/ + printf("APP鐗堟湰锛 V%d.%d.%d\r\n", _buf[14], _buf[13], _buf[12]); + for (int i = 0; i < 24; i++) + _buf[16 + i] = _info->author[i]; /*鍥轰欢鍖呭垱寤鸿厀ww.hdsmart.net.cn*/ + printf("鍥轰欢鍖呭垱寤鸿咃細 %s\r\n", _info->author); + for (int i = 0; i < 24; i++) + _buf[40 + i] = _info->name[i]; /*鍥轰欢App鍚嶇О*/ + printf("鍥轰欢App鍚嶇О锛 %s\r\n", _info->name); + for (int i = 0; i < 32; i++) + _buf[64 + i] = _info->date[i]; /*鍥轰欢鍖呭垱寤烘椂闂*/ + printf("鍥轰欢鍖呭垱寤烘椂闂达細 %s\r\n", _info->date); + for (int i = 0; i < 16; i++) + _buf[96 + i] = _info->model[i]; /*鍥轰欢鍖呭垱寤烘椂闂*/ + printf("鍨嬪彿锛 %s\r\n", _info->model); + _buf[112] = _info->fBlock; /*闇瑕佹洿鏂扮殑鍥轰欢鍧椾釜鏁帮紝鏈澶10涓潡*/ + printf("鍥轰欢鍧椾釜鏁帮細 %d\r\n", _info->fBlock); + _buf[113] = _info->logo; /*鏄惁闇瑕佹洿鏂癓OGO锛屽闇鏇存柊鍒欑1涓暟鎹潡涓篖OGO鏁版嵁*/ + printf("LOGO绫诲瀷锛 %d\r\n", _info->logo); + _buf[114] = _info->compress; /*鍘嬬缉绫诲瀷*/ + printf("鍘嬬缉绫诲瀷锛 %d\r\n", _info->compress); + _buf[115] = _info->encryption; /*鍔犲瘑绫诲瀷*/ + printf("鍔犲瘑绫诲瀷锛 %d\r\n", _info->compress); + + for (int i = 0; i < 4; i++) + _buf[116 + i] = 0xff; + + for (int i = 0; i < _buf[112]; i++) + { + for (int j = 0; j < 4; j++) + { + _buf[119 + i * 16 + j] = ((_info->info[i].size >> (j * 8)) & 0xff); /*鍥轰欢澶у皬*/ + _buf[123 + i * 16 + j] = ((_info->info[i].crc32 >> (j * 8)) & 0xff); /*鍥轰欢澶у皬*/ + _buf[127 + i * 16 + j] = ((_info->info[i].offset >> (j * 8)) & 0xff); /*鍥轰欢澶у皬*/ + _buf[131 + i * 16 + j] = ((_info->info[i].addr >> (j * 8)) & 0xff); /*鍥轰欢澶у皬*/ + } + } + for (int i = 0; i < 4; i++) + _buf[248 + i] = 0xff; + _info->crc = HDlib_CalCRC32(_buf, 252); + for (int i = 0; i < 4; i++) + _buf[252 + i] = ((_info->crc >> (i * 8)) & 0xff); /*淇℃伅澶碈RC32鏍¢獙*/ + printf("淇℃伅澶碈RC32锛 0x%X\r\n", _info->crc); + printf("\r\n"); +#if 0 + for (int i = 0; i < 256; i++) + { + printf("%02X ", _buf[i]); + if((i % 16) == 15) + printf("\r\n"); + } +#endif +} +UINT8 UpgradePackInfoDecode(UpgradeInfo_T* _info, UINT8* _buf) +{ + UINT32 crcValue; + + crcValue = 0; + crcValue = HDlib_CalCRC32(_buf, 252); + _info->crc = (_buf[252] | (UINT32)(_buf[253] << 8) | (UINT32)(_buf[254] << 16) | (UINT32)(_buf[255] << 24)); /*淇℃伅澶碈RC32鏍¢獙*/ + printf("淇℃伅澶碈RC32锛 0x%X\r\n", _info->crc); + + if (crcValue == _info->crc) + { + _info->signature = (_buf[0] | (UINT32)(_buf[1] << 8) | (UINT32)(_buf[2] << 16) | (UINT32)(_buf[3] << 24)); /*绛惧悕0x4D756E5A*/ + printf("\r\n绛惧悕锛 0x%X\r\n", _info->signature); + + _info->fVersion = (_buf[4] | (UINT32)(_buf[5] << 8) | (UINT32)(_buf[6] << 16) | (UINT32)(_buf[7] << 24)); /*鍥轰欢鍖呮牸寮忕増鏈*/ + printf("鍥轰欢鍖呮牸寮忕増鏈細 V%d.%d.%d\r\n", _buf[6], _buf[5], _buf[4]); + + _info->totalSize = (_buf[8] | (UINT32)(_buf[9] << 8) | (UINT32)(_buf[10] << 16) | (UINT32)(_buf[11] << 24)); /*鍥轰欢鍖呮诲ぇ灏*/ + printf("鍥轰欢鍖呮诲ぇ灏忥細 %d\r\n", _info->totalSize); + + _info->version = (_buf[12] | (UINT32)(_buf[13] << 8) | (UINT32)(_buf[14] << 16) | (UINT32)(_buf[15] << 24)); /*鍥轰欢搴旂敤鐗堟湰*/ + printf("搴旂敤鐗堟湰锛 V%d.%d.%d\r\n", _buf[14], _buf[13], _buf[12]); + + memcpy(_info->author, &_buf[16], 24); /*鍥轰欢鍖呭垱寤鸿厀ww.hdsmart.net.cn*/ + _info->author[23] = 0; + printf("鍥轰欢鍖呭垱寤鸿咃細 %s\r\n", _info->author); + + memcpy(_info->name, &_buf[40], 24); /*鍥轰欢App鍚嶇О*/ + _info->name[23] = 0; + printf("App鍚嶇О锛 %s\r\n", _info->name); + + memcpy(_info->date, &_buf[64], 32); /*鍥轰欢鍖呭垱寤烘椂闂*/ + _info->date[31] = 0; + printf("鍥轰欢鍒涘缓鏃堕棿锛 %s\r\n", _info->date); + + memcpy(_info->model, &_buf[96], 16); /*鍥轰欢鍖呭垱寤烘椂闂*/ + _info->date[15] = 0; + printf("鍨嬪彿锛 %s\r\n", _info->model); + + _info->fBlock = _buf[112]; /*闇瑕佹洿鏂扮殑鍥轰欢鍧椾釜鏁帮紝鏈澶10涓潡*/ + printf("鍥轰欢鍧椾釜鏁帮細 %d\r\n", _info->fBlock); + _info->logo = _buf[113]; /*鏄惁闇瑕佹洿鏂癓OGO锛屽闇鏇存柊鍒欑1涓暟鎹潡涓篖OGO鏁版嵁*/ + printf("LOGO绫诲瀷锛 %d\r\n", _info->logo); + _info->compress = _buf[114]; /*鍘嬬缉绫诲瀷*/ + printf("鍘嬬缉绫诲瀷锛 %d\r\n", _info->compress); + _info->encryption = _buf[115]; /*鍔犲瘑绫诲瀷*/ + printf("鍔犲瘑绫诲瀷锛 %d\r\n", _info->compress); + for (int i = 0; i < _info->fBlock; i++) + { + _info->info[i].size = (_buf[119 + i * 16] | (UINT32)(_buf[119 + i * 16 + 1] << 8) | \ + (UINT32)(_buf[119 + i * 16 + 2] << 16) | (UINT32)(_buf[119 + i * 16 + 3] << 24)); /*鍥轰欢澶у皬*/ + _info->info[i].crc32 = (_buf[123 + i * 16] | (UINT32)(_buf[123 + i * 16 + 1] << 8) | \ + (UINT32)(_buf[123 + i * 16 + 2] << 16) | (UINT32)(_buf[123 + i * 16 + 3] << 24)); /*鍥轰欢澶у皬*/ + _info->info[i].offset = (_buf[127 + i * 16] | (UINT32)(_buf[127 + i * 16 + 1] << 8) | \ + (UINT32)(_buf[127 + i * 16 + 2] << 16) | (UINT32)(_buf[127 + i * 16 + 3] << 24)); /*鍥轰欢澶у皬*/ + _info->info[i].addr = (_buf[131 + i * 16] | (UINT32)(_buf[131 + i * 16 + 1] << 8) | \ + (UINT32)(_buf[131 + i * 16 + 2] << 16) | (UINT32)(_buf[131 + i * 16 + 3] << 24)); /*鍥轰欢澶у皬*/ + printf("鍥轰欢鍧楋細%d size = %d crc32 = 0x%X offset = %d addr = 0x%X\r\n", i, _info->info[i].size, _info->info[i].crc32, \ + _info->info[i].offset, _info->info[i].addr); + } + printf("\r\n"); + return 0; + } + printf("鍥轰欢淇℃伅澶磋В鏋愬け璐r\n"); + printf("淇℃伅澶碿rcValue锛0x%X\r\n", crcValue); + for (int i = 0; i < 256; i++) + { + printf("%02X ", _buf[i]); + if ((i % 16) == 15) + printf("\r\n"); + } + return 1; +} +UINT8 App_GetFileInfo(FileInfo_T* _info) +{ + FILE* fp; + errno_t err; + + err = fopen_s(&fp, _info->name, "rb"); + if (err != 0) + { + printf("function:%s line = %d:%s鏂囦欢鎵撳紑澶辫触锛侊紒锛乗r\n", __FUNCTION__, __LINE__, _info->name); + return 1; + } + + fseek(fp, 0, SEEK_END); + _info->size = ftell(fp); + _info->cache = malloc(_info->size); + if (_info->cache != NULL) + { + fseek(fp, 0, SEEK_SET); + fread(_info->cache, 1, _info->size, fp); + } + + fclose(fp); + return 0; +} +UINT8 App_StrToHex(char* str, UINT32 _len, UINT32* _hex) +{ + char ch; + UINT32 value = 0,cnt = 0; + //printf("App_StrToHex:%s len = %d\r\n", str, _len); + if(_len < 3) + return 1; + if ((str[0] == '0') && ((str[1] == 'x') || (str[1] == 'X'))) + { + _len -= 2; + for (cnt = 0; cnt < _len; cnt++) + { + ch = str[2 + cnt]; + value <<= 4; + if ((ch >= '0') && (ch <= '9')) + { + value |= (UINT32)(ch - '0'); + } + else if ((ch >= 'a') && (ch <= 'z')) + { + value |= (UINT32)(ch - 'a'); + } + else if ((ch >= 'A') && (ch <= 'Z')) + { + value |= (UINT32)(ch - 'A'); + } + else + { + printf("function:%s line = %d:鍙傛暟閿欒锛侊紒锛乗r\n", __FUNCTION__, __LINE__); + return 1; + } + } + *_hex = value; + return 0; + } + return 1; +} +const UINT32 upgradeCRC32Table[] = +{ + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, + 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, + 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, + 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, + 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, + 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, + 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, + 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, + 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, + 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, + 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, + 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, + 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, + 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, + 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, + 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, + 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, + 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, + 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, + 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, + 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, + 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d +}; +UINT32 HDlib_CalCRC32(UINT8* _buf, UINT32 _len) +{ + UINT32 crc32 = 0xffffffffL, i; + + for (i = 0; i < _len; ++i) + { + crc32 = upgradeCRC32Table[(crc32 ^ _buf[i]) & 0xff] ^ (crc32 >> 8); + } + return (crc32 ^ 0xffffffffL); +} diff --git a/Src/system/upgrade.h b/Src/system/upgrade.h new file mode 100644 index 0000000..00d0a4d --- /dev/null +++ b/Src/system/upgrade.h @@ -0,0 +1,85 @@ +#ifndef __UPGRADE_H +#define __UPGRADE_H + +#ifdef __cplusplus + extern "C" { +#endif +#include +#include "system.h" + +#define UPGRADE_MAX_FILE 5 + +#define UPGRADE_PACKAGE_NAME "IMAGE.FPK" + +typedef enum { + UPGRADE_OK = 0, + UPGRADE_SUCCEED, + UPGRADE_FAIL, + UPGRADE_CRC_ERR, + OTA_READY, + OTA_DOWNLOAD, + OTA_UPDATE, + +}UpgradeSta_E; +typedef enum { + OTA_NULL = 0, + OTA_CODE, + OTA_RESOURCE, + OTA_PROGRESS, + OTA_MAX, +}UpgradeType_E; +typedef enum { /*LOGO文件类型*/ + LOGO_NULL = 0, /*不更新LOGO*/ + LOGO_BIN_RGB565, + LOGO_BIN_RGB888, + LOGO_JPEG, + LOGO_MAX, +}LogoType_E; +typedef struct { + UINT32 addr; /*烧录地址*/ + UINT32 size; /*文件总大小*/ + UINT32 crc32; + UINT8* cache; + UINT8 name[100]; /*文件名称*/ +}FileInfo_T; +/*VS2022默认8字节对齐*/ +typedef struct { + UINT32 signature; /*签名0x4D756E5A*/ + UINT32 fVersion; /*固件包格式版本*/ + UINT32 totalSize; /*固件包总大小*/ + UINT32 version; /*固件应用版本*/ + UINT8 author[24]; /*固件包创建者www.hdsmart.net.cn*/ + UINT8 name[24]; /*固件App名称*/ + UINT8 date[32]; /*固件包创建时间*/ + UINT8 model[16]; /*产品型号*/ + UINT8 fBlock; /*需要更新的固件块个数,最大10个块*/ + UINT8 logo; /*是否需要更新LOGO,如需更新则第1个数据块为LOGO数据*/ + UINT8 compress; /*文件压缩类型,0:不压缩*/ + UINT8 encryption; /*加密类型,0:不加密*/ + UINT8 reserve[4]; /*保留字节,默认为0xff*/ + struct { + UINT32 size; /*固件大小*/ + UINT32 crc32; /*固件CRC32校验*/ + UINT32 offset; /*固件偏移地址*/ + UINT32 addr; /*固件运行地址*/ + }info[8]; + UINT8 reserve1[4]; /*保留字节,默认为0xff*/ + UINT32 crc; /*信息头CRC32校验*/ +}UpgradeInfo_T; + + extern UpgradeInfo_T g_upgradeInfo; + extern FileInfo_T g_fileInfo[UPGRADE_MAX_FILE]; + +void UpgradePackInit(UpgradeInfo_T* _info); +void UpgradePackInfoGenerate(UpgradeInfo_T* _info, UINT8* _buf); +UINT8 UpgradePackInfoDecode(UpgradeInfo_T* _info, UINT8* _buf); + +UINT32 HDlib_CalCRC32(UINT8* _buf, UINT32 _len); +UINT8 App_StrToHex(char* str, UINT32 _len, UINT32 *_hex); +UINT8 App_GetFileInfo(FileInfo_T* _info); + + +#ifdef __cplusplus +} +#endif +#endif diff --git a/Src/upackage/upackage.cpp b/Src/upackage/upackage.cpp index d5fc72d..95a8fb2 100644 --- a/Src/upackage/upackage.cpp +++ b/Src/upackage/upackage.cpp @@ -1,7 +1,15 @@ #include "upackage.h" +#include + +#include "../system/system.h" +#include "../system/debug.h" +#include "../system/upgrade.h" + +#define MODEL_MAX_NUM 3 +static char gs_model[MODEL_MAX_NUM][20] = {"MD49","MD46","HD399"}; +#define LOGO_TYPE_MAX_NUM 4 +static char gs_logoType[LOGO_TYPE_MAX_NUM][20] = {"JPG","PNG","BIN5","BIN8"}; -#define MODEL_MAX_NUM 1 -static char gs_model[MODEL_MAX_NUM][20] = {"HD49"}; Upackage::Upackage(QWidget *parent) : QWidget(parent) { @@ -10,12 +18,29 @@ Upackage::Upackage(QWidget *parent) : QWidget(parent) connect(col1CBox[0], SIGNAL(stateChanged(int)), this, SLOT(Upackage_AutoVersion(int))); connect(col1CBox[1], SIGNAL(stateChanged(int)), this, SLOT(Upackage_LogoControl(int))); - connect(makePButton, SIGNAL(clicked()), this, SLOT(Upackage_GeneratePackage())); + connect(generatePButton, SIGNAL(clicked()), this, SLOT(Upackage_Generate())); + connect(fileGButton, SIGNAL(buttonClicked(QAbstractButton *)), this, SLOT(Upackage_GroupAddFile(QAbstractButton *))); } void Upackage::Upackage_Init(void) { Upackage_UiInit(); + modeComBox->clear(); //清除组件内容 + QStringList strList; + for(int i=0;iaddItems(strList); //将列表加入组件 + logoComBox->clear(); //清除组件内容 + strList.clear(); + for(int i=0;iaddItems(strList); //将列表加入组件 modelLabel->setMinimumWidth(65); logLabel->setMinimumWidth(65); @@ -23,103 +48,83 @@ void Upackage::Upackage_Init(void) logoLEdit->setEnabled(false); logoPButton->setEnabled(false); - QStringList modelStrList; - for(int i=0;i < MODEL_MAX_NUM;i++) + appLEdit->setValidator(new QRegExpValidator(QRegExp("[a-zA-Z0-9_-]+$")));//只能输入数字和字母 + appLEdit->setMaxLength(23); + appLEdit->setText("image"); + + verLEdit->setValidator(new QRegExpValidator(QRegExp("[0-9]+$")));//只能输入数字 + verLEdit->setMaxLength(12); + verLEdit->setInputMask("0.00.00;_ "); + verLEdit->setText("1.00.00"); + verLEdit->setEnabled(false); + col1CBox[0]->setCheckState( Qt::Checked); + + for(int i = 0;i < 5;i++) { - modelStrList<addItems(modelStrList); + addrLEdit[i]->setMaximumWidth(100); + addrLEdit[i]->setValidator(new QRegExpValidator(QRegExp("[a-fA-F0-9_-]+$")));//只能输入数字和字母 + } + addrLEdit[0]->setText("8000000"); } void Upackage::Upackage_UiInit(void) { Upackage_UiCreate(); -#if 0 - confLayout[0]->addWidget(modelLabel); - confLayout[0]->addWidget(modeComBox); - confLayout[0]->addStretch(); - - confLayout[1]->addWidget(verLabel); - confLayout[1]->addWidget(col1CBox[0]); - confLayout[1]->addWidget(autoLabel); - confLayout[1]->addWidget(verLEdit); - confLayout[1]->addStretch(); - - confLayout[2]->addWidget(logLabel); - confLayout[2]->addWidget(col1CBox[1]); - confLayout[2]->addWidget(logoComBox); - confLayout[2]->addWidget(logoLEdit); - confLayout[2]->addWidget(filePButton[0]); - - confLayout[3]->addWidget(fileLabel[0]); - confLayout[3]->addWidget(col1CBox[2]); - confLayout[3]->addWidget(fileLEdit[0]); - confLayout[3]->addWidget(filePButton[1]); - - confLayout[4]->addWidget(fileLabel[1]); - confLayout[4]->addWidget(col1CBox[3]); - confLayout[4]->addWidget(fileLEdit[1]); - confLayout[4]->addWidget(filePButton[2]); - - confLayout[5]->addWidget(fileLabel[2]); - confLayout[5]->addWidget(col1CBox[4]); - confLayout[5]->addWidget(fileLEdit[2]); - confLayout[5]->addWidget(filePButton[3]); - - confLayout[6]->addWidget(fileLabel[3]); - confLayout[6]->addWidget(col1CBox[5]); - confLayout[6]->addWidget(fileLEdit[3]); - confLayout[6]->addWidget(filePButton[4]); - - confLayout[7]->addWidget(fileLabel[4]); - confLayout[7]->addWidget(col1CBox[6]); - confLayout[7]->addWidget(fileLEdit[4]); - confLayout[7]->addWidget(filePButton[5]); -#endif configLayout->addWidget(modelLabel,0,0,1,1); configLayout->addWidget(modeComBox,0,1,1,2); - configLayout->addWidget(makePButton,0,4,1,1); + configLayout->addWidget(appLabel,0,3,1,1); + configLayout->addWidget(appLEdit,0,4,1,1); + configLayout->addWidget(generatePButton,0,5,2,1); + configLayout->addWidget(verLabel,1,0,1,1); configLayout->addWidget(col1CBox[0],1,1,1,1); configLayout->addWidget(autoLabel,1,2,1,1); - configLayout->addWidget(verLEdit,1,3,1,1); + configLayout->addWidget(verLEdit,1,3,1,2); configLayout->addWidget(logLabel,2,0,1,1); configLayout->addWidget(col1CBox[1],2,1,1,1); configLayout->addWidget(logoComBox,2,2,1,1); - configLayout->addWidget(logoLEdit,2,3,1,1); - configLayout->addWidget(logoPButton,2,4,1,1); + configLayout->addWidget(logoLEdit,2,3,1,2); + configLayout->addWidget(logoPButton,2,5,1,1); configLayout->addWidget(fileLabel[0],3,0,1,1); configLayout->addWidget(col1CBox[2],3,1,1,1); - configLayout->addWidget(fileLEdit[0],3,2,1,2); - configLayout->addWidget(filePButton[0],3,4,1,1); + configLayout->addWidget(addrLEdit[0],3,2,1,1); + configLayout->addWidget(fileLEdit[0],3,3,1,2); + configLayout->addWidget(filePButton[0],3,5,1,1); configLayout->addWidget(fileLabel[1],4,0,1,1); configLayout->addWidget(col1CBox[3],4,1,1,1); - configLayout->addWidget(fileLEdit[1],4,2,1,2); - configLayout->addWidget(filePButton[1],4,4,1,1); + configLayout->addWidget(addrLEdit[1],4,2,1,1); + configLayout->addWidget(fileLEdit[1],4,3,1,2); + configLayout->addWidget(filePButton[1],4,5,1,1); configLayout->addWidget(fileLabel[2],5,0,1,1); configLayout->addWidget(col1CBox[4],5,1,1,1); - configLayout->addWidget(fileLEdit[2],5,2,1,2); - configLayout->addWidget(filePButton[2],5,4,1,1); + configLayout->addWidget(addrLEdit[2],5,2,1,1); + configLayout->addWidget(fileLEdit[2],5,3,1,2); + configLayout->addWidget(filePButton[2],5,5,1,1); configLayout->addWidget(fileLabel[3],6,0,1,1); configLayout->addWidget(col1CBox[5],6,1,1,1); - configLayout->addWidget(fileLEdit[3],6,2,1,2); - configLayout->addWidget(filePButton[3],6,4,1,1); + configLayout->addWidget(addrLEdit[3],6,2,1,1); + configLayout->addWidget(fileLEdit[3],6,3,1,2); + configLayout->addWidget(filePButton[3],6,5,1,1); configLayout->addWidget(fileLabel[4],7,0,1,1); configLayout->addWidget(col1CBox[6],7,1,1,1); - configLayout->addWidget(fileLEdit[4],7,2,1,2); - configLayout->addWidget(filePButton[4],7,4,1,1); - //for(int i = 0;i < 8;i++) - //configLayout->addLayout(confLayout[i]); + configLayout->addWidget(addrLEdit[4],7,2,1,1); + configLayout->addWidget(fileLEdit[4],7,3,1,2); + configLayout->addWidget(filePButton[4],7,5,1,1); + fileGButton->addButton(logoPButton); + for(int i = 0;i < 5;i++) + { + fileGButton->addButton(filePButton[i]); + } mainLayout->addLayout(configLayout); mainLayout->addWidget(logText); @@ -136,6 +141,7 @@ void Upackage::Upackage_UiCreate(void) logText = new QTextBrowser; modelLabel = new QLabel(QString::fromLocal8Bit("型号")); + appLabel = new QLabel(QString::fromLocal8Bit("APP名称")); verLabel = new QLabel(QString::fromLocal8Bit("版本")); autoLabel = new QLabel(QString::fromLocal8Bit("自动版本")); logLabel = new QLabel(QString::fromLocal8Bit("LOGO")); @@ -151,20 +157,159 @@ void Upackage::Upackage_UiCreate(void) for(int i = 0;i < 7;i++) col1CBox[i] = new QCheckBox; + generatePButton = new QPushButton(QString::fromLocal8Bit("生成")); + appLEdit = new QLineEdit; verLEdit = new QLineEdit; logoLEdit = new QLineEdit; for(int i = 0;i < 5;i++) fileLEdit[i] = new QLineEdit; for(int i = 0;i < 5;i++) - filePButton[i] = new QPushButton(QString::fromLocal8Bit("打开")); + addrLEdit[i] = new QLineEdit; - makePButton = new QPushButton(QString::fromLocal8Bit("生成包")); + for(int i = 0;i < 5;i++) + filePButton[i] = new QPushButton(QString::fromLocal8Bit("打开")); logoPButton = new QPushButton(QString::fromLocal8Bit("打开")); + fileGButton = new QButtonGroup; } /************************************************槽函数开始区*******************************************************/ /* ********************************************************************************************* +* 功 能:生成固件包 +* 输 入:无 +* 输 出:无 +* 返回值:无 +********************************************************************************************* +*/ +void Upackage::Upackage_Generate() +{ + QFile *file; + QByteArray tempChar; + UpgradePackInit(&g_upgradeInfo); + logText->clear(); + + QString str = QString::fromLocal8Bit("型号: "); + QString disString; + disString = str + modeComBox->currentText(); + logText->append(disString); + str = modeComBox->currentText(); + tempChar = str.toLatin1(); + for(int i = 0;i < str.size();i++) + g_upgradeInfo.model[i] = tempChar[i]; + str = QString::fromLocal8Bit("App名称: "); + disString = str + appLEdit->text(); + logText->append(disString); + str = appLEdit->text(); + tempChar = str.toLatin1(); + for(int i = 0;i < str.size();i++) + g_upgradeInfo.name[i] = tempChar[i]; + + str = QString::fromLocal8Bit("版本号: "); + if(col1CBox[0]->isChecked()) + { + disString = str + "1.0.1"; + } + else + { + disString = str + verLEdit->text(); + } + logText->append(disString); + str = QString::fromLocal8Bit("LOGO类型: "); + if(col1CBox[1]->isChecked()) + { + disString = str + logoComBox->currentText(); + logText->append(disString); + str = QString::fromLocal8Bit("LOGO文件: "); + disString = str+ logoLEdit->text(); + g_upgradeInfo.logo = 1; + g_upgradeInfo.fBlock = 1; + } + else + { + str = QString::fromLocal8Bit("LOGO: 无"); + disString = str; + g_upgradeInfo.fBlock = 0; + g_upgradeInfo.logo = 0; + } + logText->append(disString); + int block = 0; + UINT32 version = 0; + UINT32 offset = 256; + for(int i = 0;i < 5;i++) + { + if(col1CBox[2 + i]->isChecked()) + { + fileName[block] = fileLEdit[i]->text(); + str.clear(); + str = addrLEdit[i]->text(); + fileAddr[block] = str.toUInt(0,16); + str = QString::fromLocal8Bit("烧录文件"); + disString.sprintf("%s%d: 0x%X---%s",str.toUtf8().data(),block,fileAddr[block],fileName[block].toUtf8().data()); + logText->append(disString); + g_fileInfo[block].addr = fileAddr[block]; + + file = new QFile(fileName[block]); + file->open(QIODevice::ReadOnly); + QFileInfo info(fileName[block]);//获取文件信息 + g_fileInfo[block].size = info.size(); + g_fileInfo[block].cache = (UINT8* )malloc(g_fileInfo[block].size); + file->read((char *)g_fileInfo[block].cache,g_fileInfo[block].size); + + g_fileInfo[block].crc32 = HDlib_CalCRC32(g_fileInfo[block].cache, g_fileInfo[block].size); + DEBUG_MSG("File Size :%d\r\n",g_fileInfo[block].size); + DEBUG_MSG("File CRC32 :0x%X\r\n",g_fileInfo[block].crc32); + file->close(); + g_upgradeInfo.info[block].size = g_fileInfo[block].size; + g_upgradeInfo.info[block].addr = g_fileInfo[block].addr; + g_upgradeInfo.info[block].crc32 = g_fileInfo[block].crc32; + g_upgradeInfo.info[block].offset = offset; + offset += g_fileInfo[block].size; + if (version == 0) + { + DEBUG_MSG("File addr :%X\r\n",g_fileInfo[block].addr); + if (g_upgradeInfo.info[block].addr != 0) + { + UINT32 size = g_fileInfo[block].size; + + DEBUG_MSG("软件版本: V%d.%d.%d\r\n", g_fileInfo[block].cache[size - 2], g_fileInfo[block].cache[size - 3], g_fileInfo[block].cache[size - 4]); + DEBUG_MSG("硬件版本: V%d\r\n", g_fileInfo[block].cache[size - 7]); + DEBUG_MSG("协议版本: V%d\r\n", g_fileInfo[block].cache[size - 8]); + DEBUG_MSG("固件版本: V%d.%d.%d\r\n", g_fileInfo[block].cache[size - 10], g_fileInfo[block].cache[size - 11], g_fileInfo[block].cache[size - 12]); + version = (UINT32)(g_fileInfo[block].cache[size - 2] << 16) | (UINT32)(g_fileInfo[block].cache[size - 3] << 8) | g_fileInfo[block].cache[size - 4]; + g_upgradeInfo.version = version; + } + } + block++; + } + } + g_upgradeInfo.fBlock += block; + g_upgradeInfo.totalSize = offset; + + UINT8 infoHeader[256]; + memset((void*)infoHeader, 0xff, 256); + UpgradePackInfoGenerate(&g_upgradeInfo,infoHeader); + str = QString::fromLocal8Bit("烧录块个数:"); + disString.sprintf("%s%d",str.toUtf8().data(),g_upgradeInfo.fBlock); + logText->append(disString); + QFile outFile("./out/IMAGE.FPK"); + outFile.open(QIODevice::WriteOnly); + + outFile.write((char *)infoHeader,256); + + + for(int i = 0;i < g_upgradeInfo.fBlock;i++) + { + str = QString::fromLocal8Bit("烧录文件"); + disString.sprintf("%s%d: %s",str.toUtf8().data(),i,fileName[i].toUtf8().data()); + logText->append(disString); + outFile.write((char *)g_fileInfo[i].cache, g_upgradeInfo.info[i].size); + if(g_fileInfo[i].cache != NULL) + free(g_fileInfo[i].cache); + } + outFile.close(); +} +/* +********************************************************************************************* * 功 能:自动版本设置 * 输 入:_status:状态 * 输 出:无 @@ -215,17 +360,31 @@ void Upackage::Upackage_AutoVersion(int _status) } /* ********************************************************************************************* -* 功 能:生成固件包 -* 输 入:无 +* 功 能:Logo设置 +* 输 入:_status:状态 * 输 出:无 * 返回值:无 ********************************************************************************************* */ -void Upackage::Upackage_GeneratePackage(void) +void Upackage::Upackage_GroupAddFile(QAbstractButton *button) { - logText->clear(); - logText->append(QString::fromLocal8Bit("型号:") + modeComBox->currentText()); - - - repaint(); + QString fileName; + QString file=QFileDialog::getOpenFileName(this,QString::fromLocal8Bit("文件"),fileName,QString::fromLocal8Bit("*.bin"));//用个文件登陆框来选择文件,包括多个文件 + if(!file.isEmpty()) + { + if(button == logoPButton) + { + logoLEdit->setText(file); + } + else + { + for(int i = 0;i < 5;i++) + { + if(button == filePButton[i]) + { + fileLEdit[i]->setText(file); + } + } + } + } } diff --git a/Src/upackage/upackage.h b/Src/upackage/upackage.h index e121626..6c092e6 100644 --- a/Src/upackage/upackage.h +++ b/Src/upackage/upackage.h @@ -38,29 +38,32 @@ public: signals: private slots: - void Upackage_AutoVersion(int _status); void Upackage_LogoControl(int _status); - void Upackage_GeneratePackage(void); - + void Upackage_Generate(); + void Upackage_GroupAddFile(QAbstractButton *button); private: + QString fileName[5]; + unsigned int fileAddr[5]; QVBoxLayout *mainLayout; QGridLayout *configLayout; QHBoxLayout *confLayout[8]; QTextBrowser *logText; - QLabel *modelLabel,*verLabel,*autoLabel,*logLabel; - QLabel *fileLabel[5]; + QLabel *modelLabel,*appLabel,*verLabel,*autoLabel,*logLabel; + QLabel *fileLabel[5]; QComboBox *modeComBox,*logoComBox; - QPushButton *makePButton; QCheckBox *col1CBox[7]; - + QPushButton *generatePButton; + QLineEdit *appLEdit; QLineEdit *verLEdit; QLineEdit *logoLEdit; QPushButton *logoPButton; + QLineEdit *addrLEdit[5]; QLineEdit *fileLEdit[5]; QPushButton *filePButton[5]; + QButtonGroup *fileGButton; }; #endif // UPACKAGE_H diff --git a/mainwindow.cpp b/mainwindow.cpp index 493ff8e..2ce7752 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -17,7 +17,9 @@ MainWindow::MainWindow(QWidget *parent) ui->setupUi(this); setMenuBar(nullptr); - setStatusBar(nullptr); /*去除状态栏*/ + //setStatusBar(nullptr); /*去除状态栏*/ + //statusBar()->setSizeGripEnabled(false); + //statusBar()->setStyleSheet("QStatusBar::item{border: 0px}"); QString str = QString::fromLocal8Bit("调试工具 V"); str += APP_VERSION; @@ -29,19 +31,82 @@ MainWindow::MainWindow(QWidget *parent) mainTabWindget.addTab(new GIFTool,QString::fromLocal8Bit("GIF")); mainTabWindget.addTab(new mcuDownload,QString::fromLocal8Bit("下载")); mainTabWindget.addTab(new Upackage,QString::fromLocal8Bit("升级")); +#if 1 + /************************状态区**************************************/ + statusPart.curTimeLabel = new QLabel; + statusPart.cntLabel = new QLabel(QString::fromLocal8Bit("TX:0 RX:0")); + statusPart.linkLabel = new QLabel(QString::fromLocal8Bit("仓库:multitools")); + // statusPart.linkLabel = new QLabel("gitee.com/multitools"); + + statusPart.linkLabel->setOpenExternalLinks(true); + statusBar()->addWidget(statusPart.cntLabel); + statusBar()->addWidget(statusPart.linkLabel); + statusBar()->addPermanentWidget(statusPart.curTimeLabel); +#endif this->setCentralWidget(&mainTabWindget); - // statusBar()->showMessage("QSimulate has started"); + //statusBar()->showMessage("QSimulate has started"); QDir *folder = new QDir; if(!folder->exists("./out")) { folder->mkpath("./out"); } +#if 1 + realTimer = new QTimer; + + connect(realTimer, SIGNAL(timeout()), this, SLOT(Main_UpdateTime())); /*更新实时时钟*/ + connect(&mainTabWindget, SIGNAL(currentChanged(int)), this, SLOT(Main_WindowChanged(int))); + + realTimer->start(100); +#endif } MainWindow::~MainWindow() { delete ui; } +/*******************************************槽函数开始区**********************************************/ +/* +**************************************************************** +* 功能:更新实时时间 +* 输入:无 +* 输出:无 +* 返回值:无 +**************************************************************** +*/ +void MainWindow::Main_UpdateTime(void) +{ + QTime timeCur = QTime::currentTime(); + + //curTimeLabel->setText(tr("%1").arg(timeCur.toString())); + statusPart.curTimeLabel->setText(timeCur.toString("hh:mm:ss")); + + QString crcStr; + if(mainTabWindget.currentIndex() == 0) + crcStr.sprintf("TX:%ld RX:%ld",g_sysData.serialTxCnt,g_sysData.serialRxCnt); + else if(mainTabWindget.currentIndex() == 1) + crcStr.sprintf("TX:%ld RX:%ld",g_sysData.wifiTxCnt,g_sysData.wifiRxCnt); + statusPart. cntLabel->setText(crcStr); + +} +/* +**************************************************************** +* 功能:更新实时时间 +* 输入:无 +* 输出:无 +* 返回值:无 +**************************************************************** +*/ +void MainWindow::Main_WindowChanged(int index) +{ + if(index > 1) + { + statusPart.cntLabel->setVisible(false); + } + else + { + statusPart.cntLabel->setVisible(true); + } +} diff --git a/mainwindow.h b/mainwindow.h index 22c52b5..5061eb3 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -3,6 +3,12 @@ #include +#include +#include + +#include +#include +#include QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } QT_END_NAMESPACE @@ -15,9 +21,21 @@ public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); +private slots: + void Main_UpdateTime(void); + void Main_WindowChanged(int index); private: Ui::MainWindow *ui; QTabWidget mainTabWindget; + + QTimer *realTimer; + /************************状态区**************************************/ + struct StaBar{ + QLabel *curTimeLabel; + QLabel *cntLabel; + QLabel *linkLabel; + }statusPart; + }; #endif // MAINWINDOW_H diff --git a/multiTools.pro b/multiTools.pro index ff05ddb..932f019 100644 --- a/multiTools.pro +++ b/multiTools.pro @@ -2,6 +2,7 @@ QT += core gui QT += serialport QT += network QT += sql +QT += charts RC_ICONS += tool.ico @@ -20,7 +21,6 @@ CONFIG += c++11 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ - Src/upackage/upackage.cpp \ main.cpp \ mainwindow.cpp \ src/gif/giftool.cpp \ @@ -34,10 +34,11 @@ SOURCES += \ src/serial/serial.cpp \ src/system/debug.cpp \ src/system/sysFifo.c \ - src/system/system.c + src/system/system.c \ + src/system/upgrade.c \ + src/upackage/upackage.cpp HEADERS += \ - Src/upackage/upackage.h \ mainwindow.h \ src/gif/giftool.h \ src/mcuDownload/mcudownload.h \ @@ -53,7 +54,9 @@ HEADERS += \ src/system/sysFifo.h \ src/system/sysList.h \ src/system/system.h \ - src/system/uConfig.h + src/system/uConfig.h \ + src/system/upgrade.h \ + src/upackage/upackage.h FORMS += \ mainwindow.ui diff --git a/multiTools.pro.user b/multiTools.pro.user index 07a9b7f..8a0295b 100644 --- a/multiTools.pro.user +++ b/multiTools.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -40,7 +40,7 @@ false true false - 0 + 1 true true 0 @@ -94,13 +94,13 @@ Desktop Qt 5.12.12 MinGW 64-bit Desktop Qt 5.12.12 MinGW 64-bit qt.qt5.51212.win64_mingw73_kit - 1 + 0 0 0 0 - D:/Workspace/Qt/Build - D:/Workspace/Qt/Build + E:/Qt/Build + E:/Qt/Build true @@ -137,8 +137,8 @@ 2 - E:/Qt/Build - E:/Qt/Build + E:\Qt\build-multiTools-Desktop_Qt_5_12_12_MinGW_64_bit-Release + E:/Qt/build-multiTools-Desktop_Qt_5_12_12_MinGW_64_bit-Release true @@ -177,8 +177,8 @@ 0 - D:\Code\build-multiTools-Desktop_Qt_5_12_12_MinGW_64_bit-Profile - D:/Code/build-multiTools-Desktop_Qt_5_12_12_MinGW_64_bit-Profile + E:\Qt\build-multiTools-Desktop_Qt_5_12_12_MinGW_64_bit-Profile + E:/Qt/build-multiTools-Desktop_Qt_5_12_12_MinGW_64_bit-Profile true -- Gitee