第一次提交

master
yanju1219 1 year ago
commit 2b3f8d699a

@ -0,0 +1,29 @@
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++17
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
msvc {
QMAKE_CFLAGS += /utf-8
QMAKE_CXXFLAGS += /utf-8
}
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

@ -0,0 +1,267 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 12.0.1, 2024-01-10T18:39:15. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
<value type="QByteArray">{8cfa9d78-659c-4111-ba1f-cc573f4fb26a}</value>
</data>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
<value type="qlonglong">0</value>
</data>
<data>
<variable>ProjectExplorer.Project.EditorSettings</variable>
<valuemap type="QVariantMap">
<value type="bool" key="EditorConfiguration.AutoIndent">true</value>
<value type="bool" key="EditorConfiguration.AutoSpacesForTabs">false</value>
<value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
<value type="QString" key="language">Cpp</value>
<valuemap type="QVariantMap" key="value">
<value type="QByteArray" key="CurrentPreferences">CppGlobal</value>
</valuemap>
</valuemap>
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
<value type="QString" key="language">QmlJS</value>
<valuemap type="QVariantMap" key="value">
<value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value>
</valuemap>
</valuemap>
<value type="qlonglong" key="EditorConfiguration.CodeStyle.Count">2</value>
<value type="QByteArray" key="EditorConfiguration.Codec">UTF-8</value>
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
<value type="int" key="EditorConfiguration.IndentSize">4</value>
<value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
<value type="int" key="EditorConfiguration.MarginColumn">80</value>
<value type="bool" key="EditorConfiguration.MouseHiding">true</value>
<value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
<value type="int" key="EditorConfiguration.PaddingMode">1</value>
<value type="int" key="EditorConfiguration.PreferAfterWhitespaceComments">0</value>
<value type="bool" key="EditorConfiguration.PreferSingleLineComments">false</value>
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
<value type="bool" key="EditorConfiguration.ShowMargin">false</value>
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">0</value>
<value type="bool" key="EditorConfiguration.SmartSelectionChanging">true</value>
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
<value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
<value type="int" key="EditorConfiguration.TabSize">8</value>
<value type="bool" key="EditorConfiguration.UseGlobal">true</value>
<value type="bool" key="EditorConfiguration.UseIndenter">false</value>
<value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
<value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
<value type="bool" key="EditorConfiguration.cleanIndentation">true</value>
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
<value type="QString" key="EditorConfiguration.ignoreFileTypes">*.md, *.MD, Makefile</value>
<value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
<value type="bool" key="EditorConfiguration.skipTrailingWhitespace">true</value>
<value type="bool" key="EditorConfiguration.tintMarginArea">true</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.PluginSettings</variable>
<valuemap type="QVariantMap">
<valuemap type="QVariantMap" key="AutoTest.ActiveFrameworks">
<value type="bool" key="AutoTest.Framework.Boost">true</value>
<value type="bool" key="AutoTest.Framework.CTest">false</value>
<value type="bool" key="AutoTest.Framework.Catch">true</value>
<value type="bool" key="AutoTest.Framework.GTest">true</value>
<value type="bool" key="AutoTest.Framework.QtQuickTest">true</value>
<value type="bool" key="AutoTest.Framework.QtTest">true</value>
</valuemap>
<valuemap type="QVariantMap" key="AutoTest.CheckStates"/>
<value type="int" key="AutoTest.RunAfterBuild">0</value>
<value type="bool" key="AutoTest.UseGlobal">true</value>
<valuemap type="QVariantMap" key="ClangTools">
<value type="bool" key="ClangTools.AnalyzeOpenFiles">true</value>
<value type="bool" key="ClangTools.BuildBeforeAnalysis">true</value>
<value type="QString" key="ClangTools.DiagnosticConfig">Builtin.DefaultTidyAndClazy</value>
<value type="int" key="ClangTools.ParallelJobs">8</value>
<value type="bool" key="ClangTools.PreferConfigFile">true</value>
<valuelist type="QVariantList" key="ClangTools.SelectedDirs"/>
<valuelist type="QVariantList" key="ClangTools.SelectedFiles"/>
<valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
<value type="bool" key="ClangTools.UseGlobalSettings">true</value>
</valuemap>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.Target.0</variable>
<valuemap type="QVariantMap">
<value type="QString" key="DeviceType">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.15.2 MSVC2019 64bit</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.15.2 MSVC2019 64bit</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.qt5.5152.win64_msvc2019_64_kit</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">1</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="int" key="EnableQmlDebugging">0</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">E:\MyCode\Qt\build-ModifyDatTime-Desktop_Qt_5_15_2_MSVC2019_64bit-Debug</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">E:/MyCode/Qt/build-ModifyDatTime-Desktop_Qt_5_15_2_MSVC2019_64bit-Debug</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
<valuelist type="QVariantList" key="QtProjectManager.QMakeBuildStep.SelectedAbis"/>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Debug</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">2</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">E:\MyCode\Qt\build-ModifyDatTime-Desktop_Qt_5_15_2_MSVC2019_64bit-Release</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">E:/MyCode/Qt/build-ModifyDatTime-Desktop_Qt_5_15_2_MSVC2019_64bit-Release</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
<valuelist type="QVariantList" key="QtProjectManager.QMakeBuildStep.SelectedAbis"/>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Release</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">0</value>
<value type="int" key="QtQuickCompiler">0</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.2">
<value type="int" key="EnableQmlDebugging">0</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">E:\MyCode\Qt\build-ModifyDatTime-Desktop_Qt_5_15_2_MSVC2019_64bit-Profile</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">E:/MyCode/Qt/build-ModifyDatTime-Desktop_Qt_5_15_2_MSVC2019_64bit-Profile</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
<valuelist type="QVariantList" key="QtProjectManager.QMakeBuildStep.SelectedAbis"/>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Profile</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">0</value>
<value type="int" key="QtQuickCompiler">0</value>
<value type="int" key="SeparateDebugInfo">0</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.BuildConfigurationCount">3</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.DeployConfiguration.CustomData"/>
<value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
<value type="int" key="Analyzer.Valgrind.Callgrind.CostFormat">0</value>
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
<valuelist type="QVariantList" key="CustomOutputParsers"/>
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="bool" key="PE.EnvironmentAspect.PrintOnRun">false</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:E:/MyCode/Qt/ModifyDatTime/ModifyDatTime.pro</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">E:/MyCode/Qt/ModifyDatTime/ModifyDatTime.pro</value>
<value type="bool" key="ProjectExplorer.RunConfiguration.Customized">false</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default">E:/MyCode/Qt/build-ModifyDatTime-Desktop_Qt_5_15_2_MSVC2019_64bit-Release</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.TargetCount</variable>
<value type="qlonglong">1</value>
</data>
<data>
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>
<value type="int">22</value>
</data>
<data>
<variable>Version</variable>
<value type="int">22</value>
</data>
</qtcreator>

@ -0,0 +1,11 @@
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}

@ -0,0 +1,362 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFile>
#include <QDataStream>
#include <QByteArray>
#include <QDir>
#include <QFileDialog>
#include <QMessageBox>
#include <QDate>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
folderPath = "";
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::ReadDat(QString fileName)
{
int year = ui->yearSpinBox->value();
int month = ui->monthSpinBox->value();
int day = ui->daySpinBox->value();
//转化为16进制
uint8_t hexYear = IntToHex(year);
uint8_t hexMonth = IntToHex(month);
uint8_t hexDay = IntToHex(day);
//QString filename = outputDir+"/"+fileName;
// // 一个示例日期年月日分别为2023年、12月、3日
// QDate date(year+2000, month, day);
// // 将日期格式化为yymmdd
// QString formattedDate = date.toString("yyyyMMdd");
// //修改文件名的时间信息
// QString f1 = fileName;
// f1.remove(11,f1.length()-11);
// QString f2 = fileName;
// f2.remove(0,11+8);
// QString str = f1+formattedDate+f2;
QString outputFileName = GetOutputFileName(fileName,year,month,day);
//创建修改后的dat文件
QFile writeFile(outputDir+"/"+outputFileName);
QDataStream outStream;
if (writeFile.open(QIODevice::WriteOnly)) {
// 创建数据流,用于写入二进制数据
// outStream = QDataStream(&writeFile);
outStream.setDevice(&writeFile);
outStream.setByteOrder(QDataStream::LittleEndian);
}
int len = 265;
quint8 *data = new quint8[len];
QFile file1 = QFile(folderPath+"/"+fileName);
//QFile file1 = QFile("E:\\dat\\output\\下行遥测_0_1_0_20230619230109.dat");
file1.open(QIODevice::ReadOnly);
QDataStream readStream = QDataStream(&file1);
readStream.setVersion(QDataStream::Qt_5_15); //设置数据流的版本
readStream.setByteOrder(QDataStream::LittleEndian);
int i =0;
quint8* content = new quint8[28]; //创建一个28字节的数据缓冲区
// int sub1 = 0;
// int sub2 = 0;
while(!readStream.atEnd())
{
readStream.readRawData((char *)data, len); //读取一帧
// i++;
//四个子帧解析
// int id1 = 16;
// int id2 = id1+32;
// int id3 = id2+32;
// int id4 = id3+32;
int startID = 16;
for (int var = 0; var < 4; ++var) {
startID = 16 + 32*var;
// if(data[startID]!=0x23)
// qDebug()<<"************Zhen1:"<<data[startID];
// if(data[startID+1]!=0x23)
// qDebug()<<"************Zhen2:"<<data[startID];
quint8 zhenID = data[startID+4];
if(zhenID==0x87 || zhenID==0x89 || zhenID==0x8A)
{
// if(data[startID+17]==0x01)
// {
// //quint32 ss = quint32(data[startID+25] | (data[startID+26]<<8) | (data[startID+27]<<16) | (data[startID+28]<<24))*0.001;
// //qDebug()<<"************SS:"<<ss;
// quint8 vid = quint8(data[startID+29]);
// //qDebug()<<"************vid1:"<<vid;
// }
if(data[startID+17]==0x02) //子帧2
{
// quint8 d = quint8(data[startID+18]);
// quint8 m = quint8(data[startID+19]);
//quint8 y = quint8(data[startID+20]);
//qDebug()<<"************Year:"<<y;
// int a = 1;
//修改UTC年月日数据
if(hexDay>0)
data[startID+18] = hexDay;
if(hexMonth>0)
data[startID+19] = hexMonth;
if(hexYear>0)
data[startID+20] = hexYear;
//计算CRC16校验位
for(int i=0;i<28;i++)//提取数据帧内容
{
content[i] = data[startID+2+i];
}
quint16 crc = GetCrcSum(content,28);//计算校验码
// 提取高位和低位
quint8 highByte = static_cast<quint8>((crc >> 8) & 0xFF);
quint8 lowByte = static_cast<quint8>(crc & 0xFF);
//修改CRC校验位
data[startID+30] = lowByte;
data[startID+31] = highByte;
}
}
}
// bool b = data[16]==0x23;
// bool b1 = data[17]==0x23;
// bool b2 = data[18]==0x85;
//修改系统时间戳
if(hexYear>0)
data[2] = hexYear;
if(hexMonth>0)
data[3] = hexMonth;
if(hexDay>0)
data[4] = hexDay;
//修改最后校验位
data[len-1] = GetDataCheckCRC(data,len);
//写入文件
outStream.writeRawData((char *)data,len);
}
file1.close();
writeFile.close();
qDebug()<<"*********************i:"<<i;
}
uint8_t MainWindow::IntToHex(int data)
{
// 将十进制整数转换为十六进制表示
QByteArray hexData = QByteArray::number(data, 16);
// 将十六进制表示转换为 uint8_t 类型
bool ok;
return hexData.toUInt(&ok, 16);
}
/*******************************************************************************
GetCrcSum
CRC
CRC
*******************************************************************************/
quint16 MainWindow::GetCrcSum(quint8 *dataptr, quint16 len)
{
qint16 count = 0;
quint8 C0 = 0,C1 = 0,Y0 = 0,Y1 = 0,Z0 = 0,Z1 = 0;
C0=C1=Y0=Y1=Z0=Z1=0;
while(count < len)
{
Y0=(CRCLIST[2*(*dataptr)]^C1) & 0x00FF;
Y1=(CRCLIST[2*(*dataptr)+1]) & 0x00FF;
Z0=CRCLIST[2*C0] & 0x00FF;
Z1=CRCLIST[2*C0+1] & 0x00FF;
C0=(Y0^Z0) & 0x00FF;
C1=(Y1^Z1) & 0x00FF;
dataptr++;
count++;
}
return(C0+C1*256);/* return crc result */
}
quint8 MainWindow::GetDataCheckCRC(quint8 *dataptr, quint16 len)
{
quint8 sum = 0;
for(int i = 0;i<264;i++)
{
sum += quint8(dataptr[i]);
}
return quint8(~(sum & 0xFF)+1);
}
/**
*
*
* @param year
* @return truefalse
*/
bool MainWindow::isLeapYear(int year)
{
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
return true;
} else {
return false;
}
}
/**
*
*
* @param year
* @param month
* @param day
* @return truefalse
*/
bool MainWindow::isValidDay(int year, int month, int day)
{
if (month == 2) {
if (isLeapYear(year)) {
if (day >= 1 && day <= 29) {
return true;
}
} else {
if (day >= 1 && day <= 28) {
return true;
}
}
} else if (month == 4 || month == 6 || month == 9 || month == 11) {
if (day >= 1 && day <= 30) {
return true;
}
} else {
if (day >= 1 && day <= 31) {
return true;
}
}
return false;
}
QString MainWindow::GetOutputFileName(QString fileName,int year, int month, int day)
{
//QString str = "下行遥测_0_17_0_20221114024453.dat";
QStringList strList = fileName.split("_");
QString endstr = strList.constLast();
QString lastStr = endstr.mid(8,-1);
if(year==0)
year = endstr.mid(0,4).toInt()-2000;
//QString year0 = endstr.mid(0,4);
if(month==0)
month = endstr.mid(4,2).toInt();
if(day==0)
day = endstr.mid(6,2).toInt();
// QString month = endstr.mid(4,2);
// QString day = endstr.mid(6,2);
// 一个示例日期年月日分别为2023年、12月、3日
QDate date(year+2000, month, day);
// 将日期格式化为yymmdd
QString formattedDate = date.toString("yyyyMMdd");
QString outputFileName = "";
strList.removeLast();
strList.append(formattedDate);
outputFileName = strList.join("_") + lastStr;
// for (int var = 0; var < strList.length()-2; ++var) {
// outputFileName += strList.at(var);
// }
return outputFileName;
}
void MainWindow::on_openDirBtn_clicked()
{
// 创建一个QFileDialog对象
QFileDialog dialog;
// 设置对话框的标题
dialog.setWindowTitle("Select Folder");
// 设置对话框模式为选择文件夹
dialog.setFileMode(QFileDialog::Directory);
// 打开对话框
if (dialog.exec()) {
// 获取用户选择的文件夹路径
folderPath = dialog.selectedFiles().at(0);
qDebug() << "Selected Folder: " << folderPath;
} else {
qDebug() << "User canceled the operation.";
}
}
void MainWindow::CreateDir()
{
// 创建一个QDir对象
QDir dir;
outputDir = folderPath+"/output";
// 设置目录路径
dir.setPath(outputDir);
// 创建文件夹
if (dir.mkpath(outputDir)) {
qDebug() << "Folder created successfully.";
} else {
qDebug() << "Failed to create folder.";
}
//QDir directory(folderPath+"/output");
}
void MainWindow::on_startModifyBtn_clicked()
{
int year = ui->yearSpinBox->value();
int month = ui->monthSpinBox->value();
int day = ui->daySpinBox->value();
if(year<=0&&month<=0&&day<=0)
{
QMessageBox::information(NULL,"提示","请设置要修改的年月日!!!");
return;
}
if(folderPath=="")
{
QMessageBox::information(NULL,"提示","请先设置文件夹!!!");
return;
}
// 检查Day是否正确
if(day>0 && !isValidDay(year+2000,month,day))
{
QMessageBox::information(NULL,"提示","日期有误,请重新设置!!!");
return;
}
// 创建一个 QDir 对象
QDir directory(folderPath);
// 获取文件夹中的所有文件
QStringList files = directory.entryList(QDir::Files);
int numFiles = files.length();
if(numFiles==0)
{
QMessageBox::information(NULL,"提示","该文件夹没有dat文件!!!");
return;
}
//新建output文件夹
CreateDir();
//开始处理
for (int n = 0; n < numFiles; ++n)
{
ReadDat(files.at(n));
}
QMessageBox::information(NULL,"提示","处理结束!!!");
}

@ -0,0 +1,78 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QString>
QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
void on_openDirBtn_clicked();
void on_startModifyBtn_clicked();
private:
void CreateDir();
void ReadDat(QString fileName);
uint8_t IntToHex(int data);
quint16 GetCrcSum(quint8 *dataptr, quint16 len);
quint8 GetDataCheckCRC(quint8 *dataptr, quint16 len);
bool isLeapYear(int year);
bool isValidDay(int year, int month, int day);
QString GetOutputFileName(QString fileName,int year,int month,int day);
private:
Ui::MainWindow *ui;
QString folderPath;
QString outputDir;
const quint8 CRCLIST[512]=
{
0x0,0x0,0x89,0x11,0x12,0x23,0x9b,0x32,0x24,0x46,0xad,0x57,0x36,0x65,0xbf,0x74,
0x48,0x8c,0xc1,0x9d,0x5a,0xaf,0xd3,0xbe,0x6c,0xca,0xe5,0xdb,0x7e,0xe9,0xf7,0xf8,
0x81,0x10,0x8,0x1,0x93,0x33,0x1a,0x22,0xa5,0x56,0x2c,0x47,0xb7,0x75,0x3e,0x64,
0xc9,0x9c,0x40,0x8d,0xdb,0xbf,0x52,0xae,0xed,0xda,0x64,0xcb,0xff,0xf9,0x76,0xe8,
0x2,0x21,0x8b,0x30,0x10,0x2,0x99,0x13,0x26,0x67,0xaf,0x76,0x34,0x44,0xbd,0x55,
0x4a,0xad,0xc3,0xbc,0x58,0x8e,0xd1,0x9f,0x6e,0xeb,0xe7,0xfa,0x7c,0xc8,0xf5,0xd9,
0x83,0x31,0xa,0x20,0x91,0x12,0x18,0x3,0xa7,0x77,0x2e,0x66,0xb5,0x54,0x3c,0x45,
0xcb,0xbd,0x42,0xac,0xd9,0x9e,0x50,0x8f,0xef,0xfb,0x66,0xea,0xfd,0xd8,0x74,0xc9,
0x4,0x42,0x8d,0x53,0x16,0x61,0x9f,0x70,0x20,0x4,0xa9,0x15,0x32,0x27,0xbb,0x36,
0x4c,0xce,0xc5,0xdf,0x5e,0xed,0xd7,0xfc,0x68,0x88,0xe1,0x99,0x7a,0xab,0xf3,0xba,
0x85,0x52,0xc,0x43,0x97,0x71,0x1e,0x60,0xa1,0x14,0x28,0x5,0xb3,0x37,0x3a,0x26,
0xcd,0xde,0x44,0xcf,0xdf,0xfd,0x56,0xec,0xe9,0x98,0x60,0x89,0xfb,0xbb,0x72,0xaa,
0x6,0x63,0x8f,0x72,0x14,0x40,0x9d,0x51,0x22,0x25,0xab,0x34,0x30,0x6,0xb9,0x17,
0x4e,0xef,0xc7,0xfe,0x5c,0xcc,0xd5,0xdd,0x6a,0xa9,0xe3,0xb8,0x78,0x8a,0xf1,0x9b,
0x87,0x73,0xe,0x62,0x95,0x50,0x1c,0x41,0xa3,0x35,0x2a,0x24,0xb1,0x16,0x38,0x7,
0xcf,0xff,0x46,0xee,0xdd,0xdc,0x54,0xcd,0xeb,0xb9,0x62,0xa8,0xf9,0x9a,0x70,0x8b,
0x8,0x84,0x81,0x95,0x1a,0xa7,0x93,0xb6,0x2c,0xc2,0xa5,0xd3,0x3e,0xe1,0xb7,0xf0,
0x40,0x8,0xc9,0x19,0x52,0x2b,0xdb,0x3a,0x64,0x4e,0xed,0x5f,0x76,0x6d,0xff,0x7c,
0x89,0x94,0x0,0x85,0x9b,0xb7,0x12,0xa6,0xad,0xd2,0x24,0xc3,0xbf,0xf1,0x36,0xe0,
0xc1,0x18,0x48,0x9,0xd3,0x3b,0x5a,0x2a,0xe5,0x5e,0x6c,0x4f,0xf7,0x7d,0x7e,0x6c,
0xa,0xa5,0x83,0xb4,0x18,0x86,0x91,0x97,0x2e,0xe3,0xa7,0xf2,0x3c,0xc0,0xb5,0xd1,
0x42,0x29,0xcb,0x38,0x50,0xa,0xd9,0x1b,0x66,0x6f,0xef,0x7e,0x74,0x4c,0xfd,0x5d,
0x8b,0xb5,0x2,0xa4,0x99,0x96,0x10,0x87,0xaf,0xf3,0x26,0xe2,0xbd,0xd0,0x34,0xc1,
0xc3,0x39,0x4a,0x28,0xd1,0x1a,0x58,0xb,0xe7,0x7f,0x6e,0x6e,0xf5,0x5c,0x7c,0x4d,
0xc,0xc6,0x85,0xd7,0x1e,0xe5,0x97,0xf4,0x28,0x80,0xa1,0x91,0x3a,0xa3,0xb3,0xb2,
0x44,0x4a,0xcd,0x5b,0x56,0x69,0xdf,0x78,0x60,0xc,0xe9,0x1d,0x72,0x2f,0xfb,0x3e,
0x8d,0xd6,0x4,0xc7,0x9f,0xf5,0x16,0xe4,0xa9,0x90,0x20,0x81,0xbb,0xb3,0x32,0xa2,
0xc5,0x5a,0x4c,0x4b,0xd7,0x79,0x5e,0x68,0xe1,0x1c,0x68,0xd,0xf3,0x3f,0x7a,0x2e,
0xe,0xe7,0x87,0xf6,0x1c,0xc4,0x95,0xd5,0x2a,0xa1,0xa3,0xb0,0x38,0x82,0xb1,0x93,
0x46,0x6b,0xcf,0x7a,0x54,0x48,0xdd,0x59,0x62,0x2d,0xeb,0x3c,0x70,0xe,0xf9,0x1f,
0x8f,0xf7,0x6,0xe6,0x9d,0xd4,0x14,0xc5,0xab,0xb1,0x22,0xa0,0xb9,0x92,0x30,0x83,
0xc7,0x7b,0x4e,0x6a,0xd5,0x58,0x5c,0x49,0xe3,0x3d,0x6a,0x2c,0xf1,0x1e,0x78,0xf
};
};
#endif // MAINWINDOW_H

@ -0,0 +1,131 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>404</width>
<height>181</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QPushButton" name="openDirBtn">
<property name="geometry">
<rect>
<x>80</x>
<y>20</y>
<width>92</width>
<height>28</height>
</rect>
</property>
<property name="text">
<string>打开文件夹</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>20</x>
<y>70</y>
<width>31</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>年:</string>
</property>
</widget>
<widget class="QSpinBox" name="yearSpinBox">
<property name="geometry">
<rect>
<x>50</x>
<y>70</y>
<width>50</width>
<height>28</height>
</rect>
</property>
<property name="buttonSymbols">
<enum>QAbstractSpinBox::NoButtons</enum>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>120</x>
<y>70</y>
<width>31</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>月:</string>
</property>
</widget>
<widget class="QSpinBox" name="monthSpinBox">
<property name="geometry">
<rect>
<x>150</x>
<y>70</y>
<width>50</width>
<height>28</height>
</rect>
</property>
<property name="buttonSymbols">
<enum>QAbstractSpinBox::NoButtons</enum>
</property>
<property name="maximum">
<number>12</number>
</property>
</widget>
<widget class="QSpinBox" name="daySpinBox">
<property name="geometry">
<rect>
<x>250</x>
<y>70</y>
<width>50</width>
<height>28</height>
</rect>
</property>
<property name="buttonSymbols">
<enum>QAbstractSpinBox::NoButtons</enum>
</property>
<property name="maximum">
<number>31</number>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>220</x>
<y>70</y>
<width>31</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>日:</string>
</property>
</widget>
<widget class="QPushButton" name="startModifyBtn">
<property name="geometry">
<rect>
<x>200</x>
<y>20</y>
<width>92</width>
<height>28</height>
</rect>
</property>
<property name="text">
<string>开始处理</string>
</property>
</widget>
</widget>
</widget>
<resources/>
<connections/>
</ui>
Loading…
Cancel
Save