添加一些基本类
This commit is contained in:
73
.gitignore
vendored
Normal file
73
.gitignore
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
# This file is used to ignore files which are generated
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
*~
|
||||
*.autosave
|
||||
*.a
|
||||
*.core
|
||||
*.moc
|
||||
*.o
|
||||
*.obj
|
||||
*.orig
|
||||
*.rej
|
||||
*.so
|
||||
*.so.*
|
||||
*_pch.h.cpp
|
||||
*_resource.rc
|
||||
*.qm
|
||||
.#*
|
||||
*.*#
|
||||
core
|
||||
!core/
|
||||
tags
|
||||
.DS_Store
|
||||
.directory
|
||||
*.debug
|
||||
Makefile*
|
||||
*.prl
|
||||
*.app
|
||||
moc_*.cpp
|
||||
ui_*.h
|
||||
qrc_*.cpp
|
||||
Thumbs.db
|
||||
*.res
|
||||
*.rc
|
||||
/.qmake.cache
|
||||
/.qmake.stash
|
||||
|
||||
# qtcreator generated files
|
||||
*.pro.user*
|
||||
|
||||
# xemacs temporary files
|
||||
*.flc
|
||||
|
||||
# Vim temporary files
|
||||
.*.swp
|
||||
|
||||
# Visual Studio generated files
|
||||
*.ib_pdb_index
|
||||
*.idb
|
||||
*.ilk
|
||||
*.pdb
|
||||
*.sln
|
||||
*.suo
|
||||
*.vcproj
|
||||
*vcproj.*.*.user
|
||||
*.ncb
|
||||
*.sdf
|
||||
*.opensdf
|
||||
*.vcxproj
|
||||
*vcxproj.*
|
||||
|
||||
# MinGW generated files
|
||||
*.Debug
|
||||
*.Release
|
||||
|
||||
# Python byte code
|
||||
*.pyc
|
||||
|
||||
# Binaries
|
||||
# --------
|
||||
*.dll
|
||||
*.exe
|
||||
|
37
base/base.cpp
Normal file
37
base/base.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
|
||||
#include "base/base.h"
|
||||
#include "QList"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 字符串转化为数字列表
|
||||
template<typename T>
|
||||
QList<T> str_to_nums(mystring str,char c){
|
||||
QStringList snums = str.split(c);
|
||||
QList<T> nums;
|
||||
for(int i=0;i<snums.size();i++)
|
||||
nums.append(T(snums[i].toInt(nullptr, 10)));
|
||||
return nums;
|
||||
}
|
||||
|
||||
// 字符串转化为数组
|
||||
myarray str_to_data(mystring str,char c){
|
||||
QStringList snums = str.split(c);
|
||||
myarray d;
|
||||
for(int i=0;i<snums.size();i++){
|
||||
d.append(uint8_t(snums[i].toInt(nullptr, 10)));
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
79
base/base.h
Normal file
79
base/base.h
Normal file
@@ -0,0 +1,79 @@
|
||||
#ifndef BASE_H
|
||||
#define BASE_H
|
||||
|
||||
|
||||
#include "QByteArray"
|
||||
#include "QList"
|
||||
|
||||
|
||||
class myarray:public QByteArray
|
||||
{
|
||||
public:
|
||||
myarray(){}
|
||||
myarray(const char *data,int len):QByteArray(data,len){}
|
||||
myarray(const char *data):QByteArray(){
|
||||
int len=strlen(data)+1;
|
||||
QByteArray::append(data,len);
|
||||
}
|
||||
myarray(int size,char data):QByteArray(size,data){}
|
||||
myarray(const myarray &data):QByteArray(data){}
|
||||
virtual ~myarray(){}
|
||||
char operator [](int index){
|
||||
int size=this->size();
|
||||
if(index<0) index=size+index;
|
||||
if(index>=size) return char(0);
|
||||
return QByteArray::operator [](index);
|
||||
}
|
||||
myarray &operator =(const myarray &b){
|
||||
QByteArray::operator =(b);
|
||||
return *this;
|
||||
}
|
||||
// myarray &operator =(const myarray b){
|
||||
// QByteArray::operator =(b);
|
||||
// return *this;
|
||||
// }
|
||||
myarray &operator =(const QByteArray &b){
|
||||
QByteArray::operator =(b);
|
||||
return *this;
|
||||
}
|
||||
// myarray &operator =(const QByteArray b){
|
||||
// QByteArray::operator =(b);
|
||||
// return *this;
|
||||
// }
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
class mystring:public QString
|
||||
{
|
||||
public:
|
||||
mystring(){}
|
||||
mystring(const char *data):QString(data){}
|
||||
mystring(myarray &data):QString(data.data()){}
|
||||
mystring(QByteArray &data):QString(data.data()){}
|
||||
mystring(QByteArray data):QString(data.data()){}
|
||||
mystring(QString &data):QString(data){}
|
||||
mystring(QString data):QString(data){}
|
||||
virtual ~mystring(){}
|
||||
const char *data(){
|
||||
localdata=QString::toLocal8Bit();
|
||||
return localdata.data();
|
||||
}
|
||||
mystring &operator =(const QString &b){
|
||||
QString::operator =(b);
|
||||
return *this;
|
||||
}
|
||||
protected:
|
||||
myarray localdata;
|
||||
};
|
||||
|
||||
|
||||
template<typename T>
|
||||
QList<T> str_to_nums(mystring str,char c);
|
||||
|
||||
myarray str_to_data(mystring str,char c);
|
||||
|
||||
|
||||
|
||||
#endif // BASE_H
|
192
base/crc.cpp
Normal file
192
base/crc.cpp
Normal file
@@ -0,0 +1,192 @@
|
||||
#include "crc.h"
|
||||
#include <QDebug>
|
||||
#include "QString"
|
||||
|
||||
|
||||
crc::crc()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
uint8_t crc::crc8(uint8_t *Ptr,uint8_t num)
|
||||
{
|
||||
|
||||
uint8_t crc = 0;
|
||||
uint16_t j,i;
|
||||
|
||||
for (j = 0; j < num; j++)
|
||||
{
|
||||
crc ^= *(Ptr+j);
|
||||
for ( i = 0; i < 8; i++)
|
||||
{
|
||||
if ((crc & 0x01) != 0)
|
||||
{
|
||||
crc >>= 1;
|
||||
crc ^= 0x8c;
|
||||
}
|
||||
else
|
||||
{
|
||||
crc >>= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return crc;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void crc::crc16(uint8_t *data, int offset, int len,uint8_t *lb,uint8_t *hb)
|
||||
{
|
||||
if (len > 0)
|
||||
{
|
||||
uint16_t crc = 0xFFFF;
|
||||
int i = offset;
|
||||
for (; i < len; i++)
|
||||
{
|
||||
crc = (uint16_t)(crc ^ (data[i]));
|
||||
for (int j = 0; j < 8; j++)
|
||||
{
|
||||
crc = (crc & 1) != 0 ? (uint16_t)((crc >> 1) ^ 0xA001) : (uint16_t)(crc >> 1);
|
||||
}
|
||||
}
|
||||
uint8_t hi = (uint8_t)((crc & 0xFF00) >> 8); //高位置
|
||||
uint8_t lo = (uint8_t)(crc & 0x00FF); //低位置
|
||||
*lb=lo;*hb=hi;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int8_t crc::CheckSumCode(uint8_t CODEMODE, uint8_t *pBuffer, uint16_t Len, uint16_t offset, uint8_t *CHKA, uint8_t *CHKB)
|
||||
{
|
||||
uint16_t i = 0;
|
||||
uint8_t _CHKA = 0x00,_CHKB = 0x00;
|
||||
|
||||
|
||||
for(i=offset;i<Len;i++)
|
||||
{
|
||||
_CHKA += pBuffer[i];
|
||||
_CHKB +=_CHKA;
|
||||
}
|
||||
if(CODEMODE==DECODE){
|
||||
if(_CHKA!=*CHKA)
|
||||
return -1;
|
||||
if(_CHKB!=*CHKB)
|
||||
return -2;
|
||||
}
|
||||
else{
|
||||
*CHKA = _CHKA;
|
||||
|
||||
*CHKB = _CHKB;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int crc::CheckSumCode(uint8_t CODEMODE, QByteArray pBuffer, uint16_t Len, uint16_t offset, uint8_t *CHKA, uint8_t *CHKB)
|
||||
{
|
||||
uint16_t i = 0;
|
||||
uint8_t _CHKA = 0x00,_CHKB = 0x00;
|
||||
|
||||
|
||||
for(i=offset;i<Len;i++)
|
||||
{
|
||||
_CHKA += pBuffer[i];
|
||||
_CHKB +=_CHKA;
|
||||
}
|
||||
if(CODEMODE==DECODE){
|
||||
if(_CHKA!=*CHKA)
|
||||
return -1;
|
||||
if(_CHKB!=*CHKB)
|
||||
return -2;
|
||||
}
|
||||
else{
|
||||
*CHKA = _CHKA;
|
||||
|
||||
*CHKB = _CHKB;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
QString crc::byte_array_to_string(QByteArray data)
|
||||
{
|
||||
QString ret(data.toHex().toUpper());
|
||||
int len = ret.length()/2;
|
||||
for(int i=1;i<len;i++)
|
||||
{
|
||||
ret.insert(2*i+i-1," ");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
// u16转为整形
|
||||
QString crc::byte_array_to_int_string(QByteArray data)
|
||||
{
|
||||
QString str;
|
||||
int len = data.size()/2;
|
||||
for(int i=0;i<len;i++)
|
||||
{
|
||||
str.append(QString::number(data[i*2]|(data[i*2+1]<<8),10));
|
||||
str.append(',');
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
uint32_t crc::crc32(const QByteArray &data_buf)
|
||||
{
|
||||
uint32_t temp,crc = 0xFFFFFFFF;
|
||||
int i,j;
|
||||
i = 0;
|
||||
ConverBuf cov;
|
||||
if((data_buf.size() %4) != 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
while(i<data_buf.size())
|
||||
{
|
||||
cov.c_databuf[0] = data_buf[i++];
|
||||
cov.c_databuf[1] = data_buf[i++];
|
||||
cov.c_databuf[2] = data_buf[i++];
|
||||
cov.c_databuf[3] = data_buf[i++];
|
||||
temp = cov.ul_data;
|
||||
for(j=0; j<32; j++)
|
||||
{
|
||||
if( (crc ^ temp) & 0x80000000 )
|
||||
{
|
||||
crc = 0x04C11DB7 ^(crc<<1);
|
||||
}
|
||||
else
|
||||
{
|
||||
crc <<=1;
|
||||
}
|
||||
temp<<=1;
|
||||
}
|
||||
crc&=0xFFFFFFFF;
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
|
||||
QString crc::uint8_array_to_string(uint8_t * buf,int len)
|
||||
{
|
||||
QString temp,msg;
|
||||
int j = 0;
|
||||
|
||||
while (j<len)
|
||||
{
|
||||
temp = QString("%1 ").arg((int)buf[j], 2, 16, QLatin1Char('0'));
|
||||
msg.append(temp);
|
||||
j++;
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
37
base/crc.h
Normal file
37
base/crc.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef CRC_H
|
||||
#define CRC_H
|
||||
#include <QObject>
|
||||
#include "stdint-gcc.h"
|
||||
#include "QString"
|
||||
#include "QByteArray"
|
||||
|
||||
#define DECODE 0
|
||||
#define ENCODE 1
|
||||
|
||||
typedef union{
|
||||
int32_t l_data;
|
||||
uint32_t ul_data;
|
||||
uint8_t uc_databuf[4];
|
||||
char c_databuf[4];
|
||||
uint16_t us_databuf[2];
|
||||
int16_t s_databuf[2];
|
||||
} ConverBuf;
|
||||
|
||||
class crc
|
||||
{
|
||||
public:
|
||||
crc();
|
||||
static int8_t CheckSumCode(uint8_t CODEMODE, uint8_t *pBuffer, uint16_t Len, uint16_t offset, uint8_t *CHKA, uint8_t *CHKB);
|
||||
static int CheckSumCode(uint8_t CODEMODE, QByteArray pBuffer, uint16_t Len, uint16_t offset, uint8_t *CHKA, uint8_t *CHKB);
|
||||
|
||||
static QString byte_array_to_string(QByteArray data);
|
||||
static QString byte_array_to_int_string(QByteArray data);
|
||||
static QString uint8_array_to_string(uint8_t * buf,int len);
|
||||
|
||||
static uint8_t crc8(uint8_t *Ptr,uint8_t num);
|
||||
static void crc16(uint8_t *data, int offset, int len,uint8_t *lb,uint8_t *hb);
|
||||
static uint32_t crc32(const QByteArray &data_buf);
|
||||
|
||||
};
|
||||
|
||||
#endif // CRC_H
|
240
base/file.h
Normal file
240
base/file.h
Normal file
@@ -0,0 +1,240 @@
|
||||
|
||||
|
||||
|
||||
#ifndef file_h__
|
||||
#define file_h__
|
||||
|
||||
|
||||
|
||||
#include <QFile>
|
||||
#include "QByteArray"
|
||||
#include "stdint-gcc.h"
|
||||
#include "QList"
|
||||
#include "base.h"
|
||||
#include <QDebug>
|
||||
#include<QDir>
|
||||
#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="<<addr<<endl;
|
||||
}
|
||||
// 找到下一个文件
|
||||
QByteArray get_next_file(QString &name)
|
||||
{
|
||||
if(addr>=data.size())
|
||||
{
|
||||
//qDebug()<<"addr="<<addr<<"data.size()="<<data.size()<<endl;
|
||||
return QByteArray();
|
||||
}
|
||||
int size;
|
||||
size=data[addr]|(data[addr+1]<<8)|(data[addr+2]<<16)|(data[addr+3]<<24);
|
||||
name=data.mid(addr+4,256-4);
|
||||
//qDebug()<<"file name="<<name<<endl;
|
||||
QByteArray da=data.mid(addr+256,size-256);
|
||||
addr+=size;
|
||||
return da;
|
||||
}
|
||||
// 输出文件列表
|
||||
QList<mystring> get_file_list(){
|
||||
QList<mystring> l;
|
||||
set_file_point();
|
||||
for(int i=0;addr<data.size();i++){
|
||||
int size;
|
||||
size=data[addr]|(data[addr+1]<<8)|(data[addr+2]<<16)|(data[addr+3]<<24);
|
||||
myarray name_t(data.mid(addr+4,256-4));
|
||||
mystring a=name_t;
|
||||
l.append(a);
|
||||
addr+=size;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
// 根据文件名返回数据
|
||||
QByteArray get_file(QString name){
|
||||
set_file_point();
|
||||
for(int i=0;addr<data.size();i++){
|
||||
int size;
|
||||
size=data[addr]|(data[addr+1]<<8)|(data[addr+2]<<16)|(data[addr+3]<<24);
|
||||
QByteArray n=data.mid(addr+4,256-4);
|
||||
if(name==QString(n)){
|
||||
return data.mid(addr+256,size-256);
|
||||
}
|
||||
addr+=size;
|
||||
}
|
||||
return QByteArray();
|
||||
}
|
||||
private:
|
||||
QByteArray data;
|
||||
int addr;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#define COMM_FILE_PATH QString("/home/root/comm_log/")
|
||||
#define COMM_FILE_NAME "comm_log.csv"
|
||||
|
||||
|
||||
class comm_file:public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
comm_file(mycfg *cfg_){
|
||||
QDir tempDir;
|
||||
if(!tempDir.exists(COMM_FILE_PATH))
|
||||
{
|
||||
tempDir.mkpath(COMM_FILE_PATH);
|
||||
}
|
||||
file_=nullptr;
|
||||
this->cfg_=cfg_;
|
||||
|
||||
bool new_file=true;
|
||||
file_ = new QFile(COMM_FILE_PATH+find_file());
|
||||
qInfo()<<"save comm_log at "<<file_->fileName()<<endl;
|
||||
if(file_->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:"<<ret_infos<<"size="<<ret_infos.size()<<endl;
|
||||
tWrite<<QString("时间,序号,流程结果,");
|
||||
for(int i=0;i<ret_infos.size();i++){
|
||||
tWrite<<ret_infos[i];
|
||||
tWrite<<",";
|
||||
}
|
||||
tWrite<<"\n";
|
||||
}
|
||||
|
||||
}
|
||||
~comm_file(){
|
||||
if(file_!=nullptr) {
|
||||
file_->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="<<files<<endl;
|
||||
if(files.size()>0){
|
||||
// 删除超时的记录
|
||||
foreach (QString name, files) {
|
||||
if(dateout(name)==true){
|
||||
QFile fi;
|
||||
fi.setFileName(COMM_FILE_PATH+name);
|
||||
qDebug()<<"will remove "<<fi.fileName()<<endl;
|
||||
if(fi.remove()!=true)
|
||||
{
|
||||
qWarning()<<"remove file "<<fi.fileName()<<"err"<<endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
QDate t=QDate::currentDate();
|
||||
// return t.toString("yyyy_MM_dd")+"-"+QString::number(cfg_->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="<<name<<endl;
|
||||
QDate t=QDate::fromString(name[0].split("-")[0],"yyyy_MM_dd");
|
||||
QDate t2=QDate::currentDate();
|
||||
qDebug()<<"t="<<t.toString("yyyy_MM_dd")<<" t2="<<t2.toString("yyyy_MM_dd")<<endl;
|
||||
if((t.daysTo(t2)>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<<t.toString("yyyy.MM.dd hh:mm:ss.zzz ddd");
|
||||
tWrite<<",";
|
||||
tWrite<<str;
|
||||
}
|
||||
}
|
||||
private:
|
||||
QFile *file_;
|
||||
mycfg *cfg_;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
304
base/mycfg.cpp
Normal file
304
base/mycfg.cpp
Normal file
@@ -0,0 +1,304 @@
|
||||
#include "mycfg.h"
|
||||
|
||||
#include <QJsonObject>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonParseError>
|
||||
#include <QJsonValue>
|
||||
#include <QJsonArray>
|
||||
#include "QDebug"
|
||||
#include "base/file.h"
|
||||
#include <QApplication>
|
||||
#include <QCryptographicHash>
|
||||
|
||||
|
||||
|
||||
// 配置路径
|
||||
#define CFG_PATH QString("/home/root/config/")
|
||||
//#define CFG_PATH qApp->applicationDirPath()+"/config/"
|
||||
|
||||
// 配置文件
|
||||
#define CFG_FILE_NAME CFG_PATH+"cfg.json"
|
||||
#define CHECK_CFG_FILE_NAME cfg_->def_check_cfg
|
||||
|
||||
// 自启动路径
|
||||
#define AUTO_START_PATH "/usr/local/QDesktop-fb"
|
||||
|
||||
// 方案配置文件关键字段,用于生成默认方案文件名
|
||||
#define CHECK_CFG_FILE_KEY "checker_ye_cfg"
|
||||
// mcu程序关键字段,用于生成默认程序文件名
|
||||
#define MCU_APP_FILE_KEY "JQChecker"
|
||||
// shell脚本关键字段,用于运行shell脚本
|
||||
#define SHELL_FILE_KEY "checker_app_pre"
|
||||
// 程序信息
|
||||
#define APP_INFO_FILE "info.json"
|
||||
// 判断脚本
|
||||
#define APP_JUDGE_FILE "judge.lua"
|
||||
|
||||
// 软件版本
|
||||
#define SOFT_VERSION "unknown"
|
||||
#define HARD_VERSION "unknown"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
QList<int> jarray_to_intlist(QJsonValue j){
|
||||
QJsonArray arr;
|
||||
if(j.isArray()){
|
||||
arr= j.toArray();
|
||||
}
|
||||
QList<int> intl;
|
||||
for(int i=0;i<arr.size();i++){
|
||||
QJsonValue item = arr.at(i);
|
||||
intl.append(item.toInt(0));
|
||||
}
|
||||
return intl;
|
||||
}
|
||||
QList<mystring> jarray_to_strlist(QJsonValue j){
|
||||
QJsonArray arr;
|
||||
if(j.isArray()){
|
||||
arr= j.toArray();
|
||||
}
|
||||
QList<mystring> strl;
|
||||
for(int i=0;i<arr.size();i++){
|
||||
QJsonValue item = arr.at(i);
|
||||
strl.append(item.toString());
|
||||
}
|
||||
return strl;
|
||||
}
|
||||
|
||||
|
||||
QJsonArray intlist_to_jarray(QList<int> intl)
|
||||
{
|
||||
QJsonArray a;
|
||||
for(int i=0;i<intl.size();i++){
|
||||
a.append(intl[i]);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
|
||||
class app_info{
|
||||
public:
|
||||
app_info(QJsonObject json){
|
||||
build_date=json.value("build_date").toString("default");
|
||||
hard_version=json.value("hard_version").toString("default");
|
||||
soft_version=json.value("soft_version").toString("default");
|
||||
privates=jarray_to_strlist(json.value("private"));
|
||||
}
|
||||
mystring build_date;
|
||||
mystring hard_version;
|
||||
mystring soft_version;
|
||||
QList<mystring> privates;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
mycfg::mycfg()
|
||||
{
|
||||
}
|
||||
|
||||
void mycfg::to_class(mystring str)
|
||||
{
|
||||
QJsonParseError err;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(str.toUtf8(),&err);
|
||||
QJsonObject j;
|
||||
if(err.error != QJsonParseError::NoError)
|
||||
{
|
||||
qWarning()<<"parse json failed:"<<err.errorString();
|
||||
}else{
|
||||
QJsonObject j=doc.object();
|
||||
}
|
||||
tcp_enable=j.value("tcp_enable").toBool(true);
|
||||
server_ip=j.value("server_ip").toString("192.168.80.80");
|
||||
server_port=j.value("server_port").toInt(9527);
|
||||
local_ip=j.value("local_ip").toString("192.168.80.87");
|
||||
local_port=j.value("local_port").toInt(0);
|
||||
gateway_ip=j.value("gateway_ip").toString("192.168.80.1");
|
||||
netmask=j.value("netmask").toString("255.255.255.0");
|
||||
can_bitrate=j.value("can_bitrate").toInt(200000);
|
||||
local_id=j.value("local_id").toInt(7);
|
||||
slave_num=j.value("slave_num").toInt(10);
|
||||
mcu_timeout=j.value("mcu_timeout").toInt(500);
|
||||
debug_ip=j.value("debug_ip").toString("192.168.80.80");
|
||||
debug_port=j.value("debug_port").toInt(12345);
|
||||
cmd_port=j.value("cmd_port").toInt(7777);
|
||||
log_redirect=j.value("log_redirect").toString("console");
|
||||
def_check_cfg=j.value("def_check_cfg").toString("checker_ye_cfg.json");
|
||||
def_mcu_app=j.value("def_mcu_app").toString("slave_app.pkt");
|
||||
use_lua_judge=j.value("use_lua_judge").toBool(false);
|
||||
device_type=j.value("device_type").toString("checker");
|
||||
moter_count=j.value("moter_count").toInt(20000);
|
||||
uart_bsp=j.value("uart_bsp").toInt(57600);
|
||||
def_lua_judge=j.value("lua_judge").toString("judge.lua");
|
||||
coder_return_mode=j.value("coder_return_mode").toInt(1);
|
||||
slave_addr_start=j.value("slave_addr_start").toInt(0);
|
||||
slave_scheme_ext=j.value("slave_scheme_ext").toInt(0);
|
||||
production_info=jarray_to_intlist(j.value("production_info"));
|
||||
}
|
||||
|
||||
mystring mycfg::to_json()
|
||||
{
|
||||
QJsonObject qJsonObject
|
||||
{
|
||||
{"tcp_enable",tcp_enable},
|
||||
{"server_ip",server_ip},
|
||||
{"server_port",server_port},
|
||||
{"local_ip",local_ip},
|
||||
{"local_port",local_port},
|
||||
{"gateway_ip",gateway_ip},
|
||||
{"netmask",netmask},
|
||||
{"can_bitrate",can_bitrate},
|
||||
{"local_id",local_id},
|
||||
{"slave_num",slave_num},
|
||||
{"mcu_timeout",mcu_timeout},
|
||||
{"debug_ip",debug_ip},
|
||||
{"debug_port",debug_port},
|
||||
{"cmd_port",cmd_port},
|
||||
{"log_redirect",log_redirect},
|
||||
{"def_check_cfg",def_check_cfg},
|
||||
{"def_mcu_app",def_mcu_app},
|
||||
{"use_lua_judge",use_lua_judge},
|
||||
{"device_type",device_type},
|
||||
{"moter_count",moter_count},
|
||||
{"uart_bsp",uart_bsp},
|
||||
{"lua_judge",def_lua_judge},
|
||||
{"coder_return_mode",coder_return_mode},
|
||||
{"slave_addr_start",slave_addr_start},
|
||||
{"slave_scheme_ext",slave_scheme_ext}
|
||||
};
|
||||
qJsonObject.insert("production_info",intlist_to_jarray(production_info));
|
||||
QJsonDocument jsonDoc(qJsonObject);
|
||||
//qDebug() << jsonDoc.toJson()<<endl;
|
||||
return jsonDoc.toJson();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 初始化环境,建立工作目录,复制程序文件
|
||||
void mycfg::init_env()
|
||||
{
|
||||
// 建立工作用文件夹
|
||||
QDir path;
|
||||
if (!path.exists(CFG_PATH)) {
|
||||
path.mkpath(CFG_PATH);
|
||||
}
|
||||
|
||||
|
||||
// 把附加文件释放到工作文件夹
|
||||
app_file app(qApp->applicationFilePath());
|
||||
QByteArray d;
|
||||
d=app.get_file(APP_INFO_FILE);
|
||||
QJsonParseError err;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(d,&err);
|
||||
if(err.error != QJsonParseError::NoError)
|
||||
{
|
||||
qWarning()<<"parse json failed:"<<err.errorString();
|
||||
return;
|
||||
}
|
||||
QJsonObject j=doc.object();
|
||||
app_info info(j);
|
||||
soft_version=info.soft_version;
|
||||
hard_version=info.hard_version;
|
||||
|
||||
QList<mystring> list_files=app.get_file_list();
|
||||
for(int i=0;i<list_files.size();i++){
|
||||
QFile file;
|
||||
mystring name=list_files[i];
|
||||
d=app.get_file(name);
|
||||
file.setFileName(CFG_PATH+name);
|
||||
if((!file.exists())||(file.size()==0))
|
||||
{
|
||||
if(!info.privates.contains(name))
|
||||
{
|
||||
qInfo()<<"release file "<<file.fileName()<<endl;
|
||||
file.open(QIODevice::ReadWrite);
|
||||
file.write(d);
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
// 设置默认方案配置文件
|
||||
if(name.contains(CHECK_CFG_FILE_KEY,Qt::CaseSensitive))
|
||||
{
|
||||
def_check_cfg=CFG_PATH+name;
|
||||
}
|
||||
else if(name.contains(MCU_APP_FILE_KEY,Qt::CaseSensitive))
|
||||
{
|
||||
def_mcu_app=CFG_PATH+name;
|
||||
}
|
||||
else if(name.contains(SHELL_FILE_KEY,Qt::CaseSensitive))
|
||||
{
|
||||
def_shell=CFG_PATH+name;
|
||||
}
|
||||
else if(name.right(4)==".lua"){
|
||||
if(name!=APP_JUDGE_FILE){
|
||||
lua_libs.append(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 复制程序文件
|
||||
QFile file_dst;
|
||||
file_dst.setFileName(AUTO_START_PATH);
|
||||
QFile file_src;
|
||||
file_src.setFileName(qApp->applicationFilePath());
|
||||
if(file_dst.exists())
|
||||
{
|
||||
if(file_dst.open(QIODevice::ReadOnly)&&file_src.open(QIODevice::ReadOnly))
|
||||
{
|
||||
QByteArray c1=file_src.readAll();
|
||||
QByteArray c2=file_dst.readAll();
|
||||
QByteArray md5_1=QCryptographicHash::hash(c1, QCryptographicHash::Md5);
|
||||
QByteArray md5_2=QCryptographicHash::hash(c2, QCryptographicHash::Md5);
|
||||
if(md5_1!=md5_2)
|
||||
{
|
||||
if(file_dst.remove()!=true)
|
||||
qWarning()<<"remove file "<<file_dst.fileName()<<"err"<<endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!file_dst.exists())
|
||||
{
|
||||
if(!QFile::copy(file_src.fileName(), file_dst.fileName()))
|
||||
{
|
||||
qWarning()<<"copy app failed."<<endl;
|
||||
}
|
||||
}
|
||||
if(file_dst.fileName()!=file_src.fileName())
|
||||
{
|
||||
system("systemctl stop atk-qtapp-start.service");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
mycfg g_syscfg;
|
||||
|
||||
mycfg *syscfg(){
|
||||
return &g_syscfg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
59
base/mycfg.h
Normal file
59
base/mycfg.h
Normal file
@@ -0,0 +1,59 @@
|
||||
#ifndef MYCFG_H
|
||||
#define MYCFG_H
|
||||
|
||||
|
||||
#include "base/base.h"
|
||||
|
||||
|
||||
class mycfg
|
||||
{
|
||||
public:
|
||||
mycfg();
|
||||
|
||||
void to_class(mystring str);
|
||||
mystring to_json();
|
||||
void init_env();
|
||||
|
||||
bool tcp_enable;//tcp使能
|
||||
mystring server_ip;
|
||||
int server_port;
|
||||
mystring local_ip;
|
||||
int local_port;
|
||||
mystring gateway_ip;
|
||||
mystring netmask;
|
||||
int local_id;// 用于区分不同批检仪的id号
|
||||
int can_bitrate;//can bps
|
||||
int slave_num;// 从机个数
|
||||
int mcu_timeout;// 从机通信超时时间
|
||||
mystring debug_ip;// debug信息输出地址
|
||||
int debug_port;// debug输出端口
|
||||
mystring build_date;
|
||||
mystring soft_version;
|
||||
mystring hard_version;
|
||||
int cmd_port;// 命令端口
|
||||
mystring log_redirect;// 日志重定向
|
||||
mystring def_check_cfg;// 默认方案文件
|
||||
mystring def_mcu_app;// 默认mcu程序
|
||||
mystring def_shell; // 默认shell脚本
|
||||
QList<mystring> lua_libs;// lua库
|
||||
mystring def_lua_judge;// lua判断异常脚本
|
||||
bool use_lua_judge;// 是否使用lua脚本
|
||||
mystring config_path;// 配置文件夹
|
||||
mystring device_type;// 设备类型
|
||||
int moter_count;// 电机步数
|
||||
int uart_bsp;// 串口波特率
|
||||
int auto_test;// 自动测试
|
||||
int coder_return_mode;// 赋码仪返回模式0精简,1完整
|
||||
int slave_addr_start;// 赋码仪起始地址0,1
|
||||
QList<int> production_info;// 生产信息
|
||||
mystring def_jwt_app;// 默认jwt程序
|
||||
int slave_scheme_ext;// 小板使用方案扩展
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
mycfg *syscfg();
|
||||
|
||||
|
||||
#endif // MYCFG_H
|
48
checker_host.pro
Normal file
48
checker_host.pro
Normal file
@@ -0,0 +1,48 @@
|
||||
QT += core gui
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
CONFIG += c++11
|
||||
|
||||
# The following define makes your compiler emit warnings if you use
|
||||
# any Qt feature that has been marked deprecated (the exact warnings
|
||||
# depend on your compiler). Please consult the documentation of the
|
||||
# deprecated API in order to know how to port your code away from it.
|
||||
DEFINES += QT_DEPRECATED_WARNINGS
|
||||
|
||||
# You can also make your code fail to compile if it uses deprecated APIs.
|
||||
# In order to do so, uncomment the following line.
|
||||
# You can also select to disable deprecated APIs only up to a certain version of Qt.
|
||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||
|
||||
SOURCES += \
|
||||
base/base.cpp \
|
||||
base/crc.cpp \
|
||||
base/mycfg.cpp \
|
||||
interface/codec.cpp \
|
||||
interface/codec_ym.cpp \
|
||||
interface/if_tcp.cpp \
|
||||
interface/interface.cpp \
|
||||
main.cpp \
|
||||
mainwindow.cpp
|
||||
|
||||
HEADERS += \
|
||||
base/base.h \
|
||||
base/crc.h \
|
||||
base/file.h \
|
||||
base/mycfg.h \
|
||||
interface/codec.h \
|
||||
interface/if_tcp.h \
|
||||
interface/interface.h \
|
||||
mainwindow.h
|
||||
|
||||
FORMS += \
|
||||
mainwindow.ui
|
||||
|
||||
TRANSLATIONS += \
|
||||
checker_host_zh_CN.ts
|
||||
|
||||
# Default rules for deployment.
|
||||
qnx: target.path = /tmp/$${TARGET}/bin
|
||||
else: unix:!android: target.path = /opt/$${TARGET}/bin
|
||||
!isEmpty(target.path): INSTALLS += target
|
3
checker_host_zh_CN.ts
Normal file
3
checker_host_zh_CN.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.1" language="checker_host_zh_CN"></TS>
|
0
interface/codec.cpp
Normal file
0
interface/codec.cpp
Normal file
34
interface/codec.h
Normal file
34
interface/codec.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef CODEC_H
|
||||
#define CODEC_H
|
||||
|
||||
#include "QObject"
|
||||
#include "base/base.h"
|
||||
|
||||
class Codec : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Codec()
|
||||
{
|
||||
fullFrame = false;
|
||||
}
|
||||
virtual ~Codec() {}
|
||||
virtual myarray encode(int srcAddr, int dstAddr, int cmd, myarray data) = 0;
|
||||
virtual myarray decode(int &srcAddr, int &dstAddr, int &cmd, myarray data) = 0;
|
||||
virtual myarray decode(int &srcAddr, int &dstAddr, int &cmd)
|
||||
{
|
||||
if (fullFrame == true)
|
||||
{
|
||||
fullFrame = false;
|
||||
return decode(srcAddr, dstAddr, cmd, data);
|
||||
}
|
||||
return myarray();
|
||||
}
|
||||
virtual bool recvByte(int byte) = 0;
|
||||
|
||||
protected:
|
||||
bool fullFrame;
|
||||
myarray data;
|
||||
};
|
||||
|
||||
#endif // CODEC_H
|
136
interface/codec_ym.cpp
Normal file
136
interface/codec_ym.cpp
Normal file
@@ -0,0 +1,136 @@
|
||||
|
||||
#include "codec.h"
|
||||
|
||||
class CodecYm : public Codec
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CodecYm() : Codec()
|
||||
{
|
||||
is_big_data = false;
|
||||
num_to_read = 0;
|
||||
}
|
||||
~CodecYm() {}
|
||||
// 重载接收字节函数
|
||||
bool recvByte(int byte)
|
||||
{
|
||||
bool ack = false;
|
||||
if (fullFrame == true)
|
||||
{
|
||||
return fullFrame;
|
||||
}
|
||||
data.append(uint8_t(byte));
|
||||
switch (data.size())
|
||||
{
|
||||
case 2:
|
||||
if (uint8_t(data[0]) == 0x59u && uint8_t(data[1]) == 0x6du)
|
||||
{
|
||||
is_big_data = false;
|
||||
num_to_read = 4; // 帧头+2byte负载长度
|
||||
}
|
||||
else
|
||||
{
|
||||
data.remove(0, 1);
|
||||
num_to_read = 0;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
{
|
||||
int len = data[2] | (data[3] << 8);
|
||||
if (len < 65535)
|
||||
{
|
||||
is_big_data = false;
|
||||
num_to_read += len + 2; // 负载+2byte校验
|
||||
qDebug("normal data. len=%d", len);
|
||||
}
|
||||
else
|
||||
{
|
||||
is_big_data = true;
|
||||
num_to_read = 11; // 扩展数据长度
|
||||
qDebug("big data.");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 11:
|
||||
{
|
||||
if (is_big_data == true)
|
||||
{
|
||||
int len = data[7] | (data[8] << 8) | (data[9] << 16) | (data[10] << 24);
|
||||
num_to_read = 4 + len + 2; // 负载+2byte校验
|
||||
qDebug("big data. len=%d", len);
|
||||
}
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// 此时一帧数据已完成
|
||||
if (num_to_read > 0 && num_to_read == data.size())
|
||||
{
|
||||
ack = true;
|
||||
num_to_read = 0;
|
||||
}
|
||||
|
||||
fullFrame = ack;
|
||||
return fullFrame;
|
||||
}
|
||||
// 重载解码函数
|
||||
QByteArray decode(int &srcAddr, int &dstAddr, int &cmd, QByteArray data)
|
||||
{
|
||||
Q_UNUSED(srcAddr);
|
||||
Q_UNUSED(dstAddr);
|
||||
QByteArray r;
|
||||
if (data.size() < 9)
|
||||
{
|
||||
// 主机一帧数据至少9字节
|
||||
qWarning("recv data len too less");
|
||||
return r;
|
||||
}
|
||||
|
||||
if ((uint8_t(data[0]) != 0x59u) || (uint8_t(data[1]) != 0x6du))
|
||||
{
|
||||
// 帧头不对
|
||||
qWarning("frame head not 0x59 0x6d");
|
||||
return r;
|
||||
}
|
||||
|
||||
int len = (data[2] | (data[3] << 8));
|
||||
if (len == 65535)
|
||||
{
|
||||
// 重新设置数据长度
|
||||
len = data[7] | (data[8] << 8) | (data[9] << 16) | (data[10] << 24);
|
||||
is_big_data = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
is_big_data = false;
|
||||
}
|
||||
if (len + 6 != data.size())
|
||||
{
|
||||
// 如果长度不相等则产生了数据丢失
|
||||
qWarning("recv data have lossed");
|
||||
return r;
|
||||
}
|
||||
uint8_t chk_a = 0, chk_b = 0;
|
||||
// crc::crc16((uint8_t *)data.data(),2,len+4,&chk_a,&chk_b);
|
||||
if (chk_a != uint8_t(data[data.size() - 2]) || chk_b != uint8_t(data[data.size() - 1]))
|
||||
{
|
||||
// crc校验不对
|
||||
qWarning("recv data check error:%02x,%02x %02x,%02x", chk_a, chk_b, int(data[data.size() - 2]),
|
||||
int(data[data.size() - 1]));
|
||||
}
|
||||
// 保存此流水号
|
||||
cmd_no = data[5] | (data[6] << 8);
|
||||
cmd = data[4];
|
||||
// 数据负载
|
||||
if (is_big_data == false)
|
||||
r = data.mid(7, len - 3);
|
||||
else
|
||||
r = data.mid(11, len - 7);
|
||||
return r;
|
||||
}
|
||||
|
||||
private:
|
||||
bool is_big_data;
|
||||
int num_to_read;
|
||||
int cmd_no;
|
||||
};
|
11
interface/if_tcp.cpp
Normal file
11
interface/if_tcp.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "if_tcp.h"
|
||||
|
||||
if_tcp::if_tcp()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if_tcp::~if_tcp()
|
||||
{
|
||||
|
||||
}
|
17
interface/if_tcp.h
Normal file
17
interface/if_tcp.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef IF_TCP_H
|
||||
#define IF_TCP_H
|
||||
|
||||
#include <QObject>
|
||||
#include <interface/interface.h>
|
||||
|
||||
class if_tcp : public InterFace
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
if_tcp();
|
||||
virtual ~if_tcp();
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
#endif // IF_TCP_H
|
32
interface/interface.cpp
Normal file
32
interface/interface.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
|
||||
#include "interface.h"
|
||||
#include "string.h"
|
||||
#include "QDebug"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
InterFace *interface;
|
||||
const char *name;
|
||||
} self_table_def;
|
||||
|
||||
static self_table_def g_self_table[] =
|
||||
{
|
||||
{.interface = 0, .name = "default"},
|
||||
};
|
||||
|
||||
InterFace *interFaceFind(const char *name)
|
||||
{
|
||||
int num = sizeof(g_self_table) / sizeof(g_self_table[0]);
|
||||
self_table_def *item = 0;
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
item = &g_self_table[i];
|
||||
if (item != nullptr)
|
||||
{
|
||||
if (strcmp(name, item->name) == 0)
|
||||
return item->interface;
|
||||
}
|
||||
}
|
||||
qWarning("can not find interface named '%s'", name);
|
||||
return nullptr;
|
||||
}
|
25
interface/interface.h
Normal file
25
interface/interface.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef INTERFACE_H
|
||||
#define INTERFACE_H
|
||||
|
||||
#include <QObject>
|
||||
#include "base/base.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace std::placeholders;
|
||||
|
||||
typedef std::function<void(void)> irq_cb;
|
||||
|
||||
class InterFace : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
InterFace() {}
|
||||
virtual ~InterFace() {}
|
||||
virtual void init() = 0;
|
||||
virtual int write(myarray data) = 0;
|
||||
virtual void set_irq(irq_cb fun, myarray &data) = 0;
|
||||
};
|
||||
|
||||
InterFace *interFaceFind(const char *name);
|
||||
|
||||
#endif // INTERFACE_H
|
58
main.cpp
Normal file
58
main.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
#include "mainwindow.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QString>
|
||||
#include <QDebug>
|
||||
#include <QTextCodec>
|
||||
#include "base/base.h"
|
||||
#include "base/mycfg.h"
|
||||
|
||||
#define log(fmt, ...) \
|
||||
{ \
|
||||
QString str = QString::asprintf(fmt, ##__VA_ARGS__); \
|
||||
printf("%s", str.toLocal8Bit().data()); \
|
||||
}
|
||||
|
||||
using namespace std;
|
||||
using namespace std::placeholders;
|
||||
|
||||
typedef std::function<void(int, int)> Fun;
|
||||
|
||||
class B
|
||||
{
|
||||
public:
|
||||
void call(int a, Fun f)
|
||||
{
|
||||
f(a, 2);
|
||||
}
|
||||
};
|
||||
|
||||
class Test
|
||||
{
|
||||
public:
|
||||
void callback(int a, int b)
|
||||
{
|
||||
// qDebug()<<a<<"+"<<b<<"="<<a+b<<endl;
|
||||
qDebug("%d+%d=%d,%s", a, b, a + b, QString("ssssss").toLocal8Bit().data());
|
||||
}
|
||||
|
||||
void bind()
|
||||
{
|
||||
Fun fun = std::bind(&Test::callback, this, _1, _2);
|
||||
B b;
|
||||
b.call(1, fun);
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
MainWindow w;
|
||||
w.show();
|
||||
// Test test;
|
||||
// test.bind();
|
||||
|
||||
qDebug("local ip=%s",syscfg()->local_ip);
|
||||
|
||||
return app.exec();
|
||||
}
|
13
mainwindow.cpp
Normal file
13
mainwindow.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent), ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
24
mainwindow.h
Normal file
24
mainwindow.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui
|
||||
{
|
||||
class MainWindow;
|
||||
}
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
};
|
||||
#endif // MAINWINDOW_H
|
31
mainwindow.ui
Normal file
31
mainwindow.ui
Normal file
@@ -0,0 +1,31 @@
|
||||
<?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>800</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget"/>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Reference in New Issue
Block a user