#ifndef file_h__ #define file_h__ #include #include "QByteArray" #include "stdint-gcc.h" #include "QList" #include "base.h" #include #include #include "base/crc.h" #include "QDateTime" #include "base/mycfg.h" /* Type for a 16-bit quantity. */ typedef uint16_t Elf32_Half; typedef uint32_t Elf32_Word; /* Type of addresses. */ typedef uint32_t Elf32_Addr; /* Type of file offsets. */ typedef uint32_t Elf32_Off; #define EI_NIDENT (16) typedef struct { unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */ Elf32_Half e_type; /* Object file type */ Elf32_Half e_machine; /* Architecture */ Elf32_Word e_version; /* Object file version */ Elf32_Addr e_entry; /* Entry point virtual address */ Elf32_Off e_phoff; /* Program header table file offset */ Elf32_Off e_shoff; /* Section header table file offset */ Elf32_Word e_flags; /* Processor-specific flags */ Elf32_Half e_ehsize; /* ELF header size in bytes */ Elf32_Half e_phentsize; /* Program header table entry size */ Elf32_Half e_phnum; /* Program header table entry count */ Elf32_Half e_shentsize; /* Section header table entry size */ Elf32_Half e_shnum; /* Section header table entry count */ Elf32_Half e_shstrndx; /* Section header string table index */ } Elf32_Ehdr; class app_file:public QObject { Q_OBJECT public: app_file(QString name){ QFile file; file.setFileName(name); if(file.exists()) { file.open(QIODevice::ReadOnly); data = file.readAll(); file.close(); } } ~app_file(){} void set_file_point() { Elf32_Ehdr h; memcpy((void *)&h,data.data(),sizeof(h)); addr= h.e_shoff+h.e_shnum*h.e_shentsize; //qDebug()<<"ext file addr="<=data.size()) { //qDebug()<<"addr="<cfg_=cfg_; bool new_file=true; file_ = new QFile(COMM_FILE_PATH+find_file()); qInfo()<<"save comm_log at "<fileName()<exists()) { new_file=false; } if (!file_->open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append)){ return; } if(new_file==true){ QTextStream tWrite(file_); // QStringList ret_infos=cfg_->get_return_info(); QStringList ret_infos; qDebug()<<"ret_info:"<flush(); file_->close(); delete file_; file_=nullptr; } } QString find_file(){ // 找到检测日志文件,超过7天则删除 QDir dir=QDir(COMM_FILE_PATH); QStringList list; list.append("*.csv"); QStringList files=dir.entryList(list,QDir::NoFilter,QDir::NoSort); qDebug()<<"files="<0){ // 删除超时的记录 foreach (QString name, files) { if(dateout(name)==true){ QFile fi; fi.setFileName(COMM_FILE_PATH+name); qDebug()<<"will remove "<get_plan_id())+".csv"; return t.toString("yyyy_MM_dd")+"-"+QString::number(0)+".csv"; } // 是否超时,true超时 bool dateout(QString file){ QStringList name=file.split("."); qDebug()<<"name="<30)||(!t.isValid())){ return true; } return false; } void save(uint8_t src,QByteArray data) { if(file_){ QTextStream tWrite(file_); QString str=QString("%1,").arg(src); str.append(QString("%1,").arg(crc::byte_array_to_string(data.mid(0,8)))); str.append(QString("%1\n").arg(crc::byte_array_to_int_string(data.mid(16,data.size()-16)))); QDateTime t=QDateTime::currentDateTime(); tWrite<