813 lines
26 KiB
C++
813 lines
26 KiB
C++
#include "dlginputaddr.h"
|
|
#include "ui_dlginputaddr.h"
|
|
#include <QFile>
|
|
#include <QMessageBox>
|
|
#include <QDate>
|
|
#include <QDateEdit>
|
|
#include <time.h>
|
|
#include <QDebug>
|
|
#include <QTime>
|
|
#include "qnamespace.h"
|
|
#include <unistd.h>
|
|
#include <QProcess>
|
|
#include <iostream>
|
|
#include <string>
|
|
#include <QString>
|
|
#include <QChar>
|
|
#include <QByteArray>
|
|
// 修改超级密码,一周一变,增加校验码,且顺序改为 123C4DD
|
|
#define MAC_FILE_PATH "/home/plg/conf/mac.bin"
|
|
|
|
DlgInputAddr::DlgInputAddr(QWidget *parent) :
|
|
QDialog(parent),
|
|
ui(new Ui::DlgInputAddr)
|
|
{
|
|
ui->setupUi(this);
|
|
initTimer();
|
|
connect(this,SIGNAL(changePowerCnt(QString )),ui->labPowerMinuteCnt,SLOT(setText(QString)));
|
|
connect(this,SIGNAL(changePrintCnt(QString )),ui->labPrintDotCnt,SLOT(setText(QString)));
|
|
curDate =QDate::currentDate();
|
|
QDate curDate1;
|
|
curDate1.setDate(2017,11,13);
|
|
if(curDate<curDate1) {
|
|
curDate=curDate1;
|
|
setTime(2017,11,13,20,29,1 );
|
|
}
|
|
ui->lineEdit->setValidator(new QIntValidator(100000, 999999, this));
|
|
ui->superNodeIp3->setValidator(new QIntValidator(1, 255, this));
|
|
ui->superNodeIp2->setValidator(new QIntValidator(0, 255, this));
|
|
ui->superNodeIp1->setValidator(new QIntValidator(0, 255, this));
|
|
ui->superNodeIp0->setValidator(new QIntValidator(1, 255, this));
|
|
|
|
ui->edgeIp3->setValidator(new QIntValidator(1, 255, this));
|
|
ui->edgeIp2->setValidator(new QIntValidator(0, 255, this));
|
|
ui->edgeIp1->setValidator(new QIntValidator(0, 255, this));
|
|
ui->edgeIp0->setValidator(new QIntValidator(1, 255, this));
|
|
repairTimeLess = 0;
|
|
adjustSize();
|
|
}
|
|
|
|
|
|
DlgInputAddr::~DlgInputAddr()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void DlgInputAddr::SetAddr()
|
|
{
|
|
jd.addr = ui->lineEdit->text().toInt(0,10);
|
|
if(jd.addr < 100001 || jd.addr > 999999) jd.addr = 100001;
|
|
|
|
//QStringList superNodeIpList = ui->superNodeIpEdit->text().split(".");
|
|
quint8 ip3 = ui->superNodeIp3->text().toInt(0,10);
|
|
quint8 ip2 = ui->superNodeIp2->text().toInt(0,10);
|
|
quint8 ip1 = ui->superNodeIp1->text().toInt(0,10);
|
|
quint8 ip0 = ui->superNodeIp0->text().toInt(0,10);
|
|
jd.superNodeIp = (ip3<<24) + (ip2<<16) + (ip1<<8) + ip0;
|
|
|
|
ip3 = ui->edgeIp3->text().toInt(0,10);
|
|
ip2 = ui->edgeIp2->text().toInt(0,10);
|
|
ip1 = ui->edgeIp1->text().toInt(0,10);
|
|
ip0 = ui->edgeIp0->text().toInt(0,10);
|
|
jd.edgeIp = (ip3<<24) + (ip2<<16) + (ip1<<8) + ip0;
|
|
|
|
SaveJm();
|
|
SaveAddrBackup();
|
|
}
|
|
void DlgInputAddr::vpnConnect()
|
|
{
|
|
QStringList edgeArgList;
|
|
//QProcess edge
|
|
//edge -d n2n0 -c vernonbach -k encryptvb -a 10.0.0.11 -l xxx.xxx.xxx.xxx:1000 >/dev/null &
|
|
edgeArgList<<"-d"<<"n2n0";
|
|
edgeArgList<<"-c"<<"vernonbach";
|
|
edgeArgList<<"-k"<<"encryptvb";
|
|
edgeArgList<<"-a"<<QString("%1.%2.%3.%4").arg((jd.edgeIp>>24)&0xFF).arg((jd.edgeIp>>16)&0xFF).arg((jd.edgeIp>>8)&0xFF).arg((jd.edgeIp)&0xFF);
|
|
edgeArgList<<"-l"<<QString("%1.%2.%3.%4:1000").arg((jd.superNodeIp>>24)&0xFF).arg((jd.superNodeIp>>16)&0xFF).arg((jd.superNodeIp>>8)&0xFF).arg((jd.superNodeIp)&0xFF);
|
|
edgeArgList<<">/dev/null &";
|
|
QProcess::startDetached("edge",edgeArgList);
|
|
}
|
|
|
|
QString DlgInputAddr::GetAddr()
|
|
{
|
|
ReadJm();
|
|
return ui->lineEdit->text();
|
|
}
|
|
|
|
void DlgInputAddr::SaveJm()
|
|
{
|
|
QFile file("/lib/syst");
|
|
if (file.isOpen()) {
|
|
file.close();
|
|
}
|
|
jdDataRwLock.lockForWrite();
|
|
if(!file.open(QIODevice::WriteOnly)){//怀疑是QIODevice::Truncate 引起参数错误,去掉试试看
|
|
QMessageBox::warning(0,"警告",QString("无法打开文件 1") );
|
|
}
|
|
else {
|
|
file.seek(0);
|
|
file.write((char *)&jd,(qint64)sizeof(jd));
|
|
fsync(file.handle());
|
|
file.close();
|
|
}
|
|
jdDataRwLock.unlock();
|
|
}
|
|
|
|
void DlgInputAddr::ReadJm()
|
|
{
|
|
QFile file("/lib/syst");
|
|
QFile Macfile(MAC_FILE_PATH);
|
|
unsigned int addr;
|
|
|
|
if(!Macfile.exists())
|
|
{
|
|
if(!Macfile.open(QIODevice::WriteOnly)){//怀疑是QIODevice::Truncate 引起参数错误,去掉试试看
|
|
QMessageBox::warning(0,"警告",QString("无法打开文件:mac.bin") );
|
|
}
|
|
}
|
|
|
|
if(!file.exists())
|
|
{
|
|
if(!file.open(QIODevice::WriteOnly)){//怀疑是QIODevice::Truncate 引起参数错误,去掉试试看
|
|
QMessageBox::warning(0,"警告",QString("无法打开文件") );
|
|
}
|
|
else {
|
|
file.close();
|
|
ResetJm();
|
|
show();
|
|
}
|
|
}
|
|
else {
|
|
if (file.isOpen()) {
|
|
file.close();
|
|
}
|
|
jdDataRwLock.lockForRead();
|
|
if(!file.open(QIODevice::ReadOnly)){//怀疑是QIODevice::Truncate 引起参数错误,去掉试试看
|
|
QMessageBox::warning(0,"警告",QString("无法打开文件") );
|
|
}
|
|
else {
|
|
file.seek(0);
|
|
//file.read((char *)&jd.addr,(long long int)sizeof(jd));
|
|
file.read((char *)&jd,(qint64)sizeof(jd));
|
|
file.close();
|
|
}
|
|
////////////////////
|
|
if (Macfile.isOpen()) {
|
|
Macfile.close();
|
|
}
|
|
//jdDataRwLock.lockForRead();
|
|
if(!Macfile.open(QIODevice::ReadOnly)){//怀疑是QIODevice::Truncate 引起参数错误,去掉试试看
|
|
//QMessageBox::warning(0,"警告",QString("无法打开文件") );
|
|
}
|
|
else {
|
|
Macfile.seek(0);
|
|
//file.read((char *)&jd.addr,(long long int)sizeof(jd));
|
|
Macfile.read((char *)&addr,(qint64)sizeof(addr));
|
|
Macfile.close();
|
|
}
|
|
|
|
jdDataRwLock.unlock();
|
|
}
|
|
if((jd.addr != addr) && (addr >= 100001 && addr <= 999999)){
|
|
jd.addr = addr;
|
|
SaveJm();
|
|
}
|
|
ui->lineEdit->setText(QString().sprintf("%06d",jd.addr) );
|
|
ui->labPowerMax->setText(QString("%1").arg(jd.powerMinuteMax));
|
|
ui->labPrintMax->setText(QString("%1").arg(jd.printMax));
|
|
ui->labPowerMinuteCnt->setText(QString("%1").arg(jd.powerMinuteCnt));
|
|
ui->labPrintDotCnt->setText(QString("%1").arg(jd.printCnt));
|
|
ui->EditStartTime->setText(QString("%1").arg(jd.start));
|
|
ui->EditEndTime->setText(QString("%1").arg(jd.end));
|
|
|
|
//qDebug()<<"jd.superNodeIp"<<jd.superNodeIp;
|
|
ui->superNodeIp3->setText(QString::number((jd.superNodeIp>>24)&0xFF));
|
|
ui->superNodeIp2->setText(QString::number((jd.superNodeIp>>16)&0xFF));
|
|
ui->superNodeIp1->setText(QString::number((jd.superNodeIp>>8)&0xFF));
|
|
ui->superNodeIp0->setText(QString::number((jd.superNodeIp)&0xFF));
|
|
|
|
ui->edgeIp3->setText(QString::number((jd.edgeIp>>24)&0xFF));
|
|
ui->edgeIp2->setText(QString::number((jd.edgeIp>>16)&0xFF));
|
|
ui->edgeIp1->setText(QString::number((jd.edgeIp>>8)&0xFF));
|
|
ui->edgeIp0->setText(QString::number((jd.edgeIp)&0xFF));
|
|
//ui->lineEditLanIP->setInputMask("119.23.201.56");
|
|
|
|
}
|
|
|
|
void DlgInputAddr::setNodeIpAndPrivateIp(bool bNodeIpSetDone)
|
|
{
|
|
ui->label->setVisible(bNodeIpSetDone);
|
|
ui->lineEdit->setEnabled(bNodeIpSetDone);
|
|
ui->lineEdit->setVisible(bNodeIpSetDone);
|
|
ui->label_2->setVisible(bNodeIpSetDone);
|
|
ui->EditStartTime->setEnabled(bNodeIpSetDone);
|
|
ui->EditStartTime->setVisible(bNodeIpSetDone);
|
|
ui->label_3->setVisible(bNodeIpSetDone);
|
|
ui->EditEndTime->setEnabled(bNodeIpSetDone);
|
|
ui->EditEndTime->setVisible(bNodeIpSetDone);
|
|
|
|
ui->horizontalLayout->setEnabled(bNodeIpSetDone);
|
|
ui->labPowerMinuteCnt->setVisible(bNodeIpSetDone);
|
|
ui->labPowerMax->setVisible(bNodeIpSetDone);
|
|
ui->labPrintDotCnt->setVisible(bNodeIpSetDone);
|
|
ui->labPrintMax->setVisible(bNodeIpSetDone);
|
|
ui->line->setVisible(bNodeIpSetDone);
|
|
ui->line_2->setVisible(bNodeIpSetDone);
|
|
ui->line_3->setVisible(bNodeIpSetDone);
|
|
//adjustSize();
|
|
}
|
|
|
|
void DlgInputAddr::on_buttonBox_clicked(QAbstractButton *button)
|
|
{
|
|
//QMessageBox::warning(0,"警告",QString("无法打开文件 3") );
|
|
if(ui->buttonBox->button(QDialogButtonBox::Ok) == button) //判断按下的是否为"确定”按钮
|
|
{
|
|
if(!ui->lineEdit->text().isEmpty()) //判断lineEdit是否为空,不为空返回0
|
|
{
|
|
SetAddr();
|
|
vpnConnect();
|
|
emit changeMac(QString(" Mac:%1").arg(jd.addr));
|
|
}
|
|
}
|
|
setNodeIpAndPrivateIp(true);
|
|
//else if(button == ui->buttonBox->button((QDialogButtonBox::Cancel)))
|
|
// ui->lineEdit->setText("001002");
|
|
}
|
|
#define XXXX
|
|
|
|
char DlgInputAddr::isEnabled()// check where is enable?10秒钟1次
|
|
{
|
|
char res=0;
|
|
static int cnt=0;
|
|
static char changTimeCnt=0;
|
|
|
|
curDate =QDate::currentDate();
|
|
unsigned int ndate = curDate.toString("yyyyMMdd").toInt(0,10);
|
|
|
|
if(cnt<5)
|
|
{
|
|
cnt++;
|
|
if((jd.workout && jd.nDate<=jd.start) && ndate>=jd.start && ndate< jd.end )
|
|
{
|
|
jd.nDate = ndate;
|
|
jd.workout =0;
|
|
SaveJm();
|
|
// qDebug()<<ndate<<"CA4";
|
|
//printErrorStatus(curDate.toString(tr("喷码机恢复工作!")),3); //
|
|
printErrorStatus(tr("喷码机恢复工作!"),3);
|
|
}
|
|
}
|
|
else cnt=0;
|
|
if(cnt==1)//1分钟1次
|
|
{
|
|
QString jdEnd = QString::number(jd.end);
|
|
QDateTime currentTime = QDateTime::currentDateTime();
|
|
QDateTime endTime = QDateTime::fromString(jdEnd, "yyyyMMdd");
|
|
repairTimeLess = qMax(0, (int)((endTime.toTime_t() - currentTime.toTime_t()) / (60*60)));
|
|
//curDate =QDate::currentDate();
|
|
//unsigned int ndateWarn = curDate.addDays(2).toString("yyyyMMdd").toInt(0,10);
|
|
unsigned int ndateWarn = curDate.addDays(6).toString("yyyyMMdd").toInt(0,10);
|
|
//unsigned int ndate = curDate.toString("yyyyMMdd").toInt(0,10);
|
|
//unsigned int ndateStop = curDate.addDays(1).toString("yyyyMMdd").toInt(0,10);
|
|
|
|
if(jd.end < ndate || jd.start>ndate ) {
|
|
res |=(1<<2);
|
|
if( jd.workout==0)
|
|
{
|
|
jd.nDate = ndate;
|
|
jd.workout =1;
|
|
SaveJm();
|
|
// qDebug()<<ndate<<"CA3";
|
|
printErrorStatus(curDate.toString("喷码机工作!"),1); //
|
|
}
|
|
}
|
|
else if( ndateWarn>jd.end )
|
|
{
|
|
// QString jdEnd = QString::number(jd.end);
|
|
|
|
// QDateTime currentTime = QDateTime::currentDateTime();
|
|
// QDateTime endTime = QDateTime::fromString(jdEnd, "yyyyMMdd");
|
|
//// qDebug() << "currentTime.toTime_t()" << currentTime.toTime_t();
|
|
//// qDebug() << "endTime.toTime_t(" << endTime.toTime_t();
|
|
|
|
// repairTimeLess = (endTime.toTime_t() - currentTime.toTime_t()) / (60*60);
|
|
|
|
// emit printErrorStatus(QString(tr("Mac:%1维护时间剩余")+"%2").arg(jd.addr).arg(repairTimeLess)+tr("小时,喷码机将停止工作.请与供应商联系!"),2);
|
|
}
|
|
|
|
//qDebug()<<jd.nDate<<ndate<<jd.end<<jd.start<<jd.workout;
|
|
if( jd.nDate == ndate ) emit dateError("");
|
|
else if( jd.nDate < ndate ){
|
|
if(jd.nDate <jd.end)
|
|
{
|
|
jd.nDate = ndate;
|
|
SaveJm();
|
|
changTimeCnt=0;
|
|
// qDebug()<<ndate<<"CA444";
|
|
}
|
|
}
|
|
else { //
|
|
if(changTimeCnt++>3)
|
|
{
|
|
changTimeCnt=0;
|
|
QTime time1= QTime::currentTime();
|
|
//qDebug()<<time1.toString("hhmmss")<<"C10";
|
|
setTime((jd.nDate/10000)%10000,(jd.nDate%10000)/100,jd.nDate%100, time1.hour(),time1.minute(),time1.second());
|
|
// qDebug()<<time1.toString("hhmmss")<<ndate<<"C12";
|
|
}
|
|
//emit dateError("请确认日期:"+curDate.toString("yyyy-MM-dd")+ "正确?");
|
|
if(changTimeCnt==1)
|
|
{
|
|
// emit printErrorStatus(tr("当前日期:")+curDate.toString("yyyy-MM-dd")+ tr("正确?"),2);
|
|
}
|
|
}
|
|
#ifdef SPV210
|
|
QDate curDate1;
|
|
curDate1.setDate(2017,7,20);
|
|
if(curDate1<curDate){
|
|
jd.workout =2;
|
|
emit printErrorStatus(curDate.toString("V6维护时间已到,喷码机停止工作!"),1);
|
|
}
|
|
#endif
|
|
#ifdef MYTEST
|
|
QDate curDate1;
|
|
curDate1.setDate(2017,7,20);
|
|
if(curDate1<curDate){
|
|
jd.workout =2;
|
|
emit printErrorStatus(curDate.toString("本软件仅用于测试版,测试时间已到!"),1);
|
|
}
|
|
#endif
|
|
// if(jd.workout ==1)
|
|
// emit printErrorStatus(tr("Mac:%1维护时间已到,喷码机停止工作!请与供应商联系").arg(jd.addr),1);
|
|
|
|
//if(res & (1<<0)) emit printErrorStatus(tr(" 机器很长时间没有进行保养了!请联系厂家进行保养!"));
|
|
//else emit printErrorStatus(curDate.toString("yyyy-MM-dd"));
|
|
|
|
//if(res & (1<<1)) emit dateError(tr("请使用原厂家提供的墨水!"));
|
|
//emit dateError(QString("%1").arg(jd.start));
|
|
}
|
|
//qDebug()<<jd.nDate<<ndate<<jd.end<<jd.start<<jd.workout;
|
|
// emit changePowerCnt(QString(tr("累计工作时间(分钟):")+"%1").arg( jd.powerMinuteCnt));
|
|
// emit changePrintCnt(QString(tr("累计墨水用量:")+"%1").arg(jd.printCnt/4));
|
|
// enCodeWh("100");
|
|
|
|
return res;
|
|
}
|
|
|
|
void DlgInputAddr::CheckDate()
|
|
{
|
|
//char changTimeCnt=0;
|
|
curDate =QDate::currentDate();
|
|
//unsigned int ndateWarn = curDate.addDays(2).toString("yyyyMMdd").toInt(0,10);
|
|
unsigned int ndate = curDate.toString("yyyyMMdd").toInt(0,10);
|
|
//unsigned int ndateStop = curDate.addDays(1).toString("yyyyMMdd").toInt(0,10);
|
|
if( jd.nDate == ndate ) emit dateError("");
|
|
else if( jd.nDate < ndate ){
|
|
if(jd.nDate >=jd.end);
|
|
else {
|
|
// jd.nDate = ndate;
|
|
// SaveJm();
|
|
//qDebug()<<ndate<<"C2";
|
|
}
|
|
}
|
|
else { //
|
|
// QTime time1= QTime::currentTime();
|
|
// setTime((jd.nDate/10000)%10000,(jd.nDate%10000)/100,jd.nDate%100, time1.hour(),time1.minute(),time1.second());
|
|
// qDebug()<<time1.toString("yyyy-MM-dd")<<"C1";
|
|
// emit printErrorStatus(tr("当前日期:")+curDate.toString("yyyy-MM-dd")+ tr("正确?"),2);
|
|
}
|
|
|
|
}
|
|
void DlgInputAddr::ResetJm()
|
|
{
|
|
memset((char *)&jd.addr,0,sizeof(jd));
|
|
jd.addr = 100001;
|
|
jd.validity=6;
|
|
jd.powerEn=1;
|
|
jd.printEn =1;
|
|
jd.enable =1;
|
|
jd.powerMinuteCnt=0;
|
|
jd.printCnt=0;
|
|
jd.powerMinuteMax=jd.validity*31*18*60;// minute cnt
|
|
jd.printMax = 0xfffff000;
|
|
curDate =QDate::currentDate();
|
|
QDate curDate1;
|
|
curDate1.setDate(2014,9,4);
|
|
if(curDate<curDate1) { curDate=curDate1;
|
|
setTime(2014,9,4,17,1,1 );
|
|
}
|
|
jd.start =curDate.toString("yyyyMMdd").toInt(0);
|
|
jd.nDate = jd.start; //
|
|
|
|
//curDate1.toString("yyyyMMdd").toInt(0);
|
|
curDate1 = curDate.addMonths(jd.validity);
|
|
//curDate1.setYMD(curDate.year()+jd.validity/12, (curDate.month()+jd.validity)%12,curDate.day());
|
|
jd.end = curDate1.toString("yyyyMMdd").toInt(0);
|
|
jd.workout =0x00;
|
|
//qDebug()<<jd.start<<jd.end ;
|
|
|
|
jd.superNodeIp = (119<<24) + (23<<16) + (201<<8) + 56;//119.23.201.56
|
|
jd.edgeIp = (10<<24) + (0<<16) + (0<<8) + 11;//10.0.0.11
|
|
|
|
SaveJm();
|
|
//ReadJm();
|
|
}
|
|
|
|
// 通过密码设置有效期
|
|
void DlgInputAddr::SetNewJm(unsigned int validity)
|
|
{
|
|
// jd.addr = 100001;
|
|
jd.validity=validity;
|
|
jd.powerEn=1;
|
|
jd.printEn =1;
|
|
jd.enable =1;
|
|
jd.powerMinuteCnt=0;
|
|
jd.printCnt=0;
|
|
jd.powerMinuteMax=jd.validity*31*18*60;// minute cnt
|
|
jd.printMax = 0xfffff000;
|
|
curDate =QDate::currentDate();
|
|
QDate curDate1;
|
|
curDate1.setDate(2016,2,10);
|
|
if(curDate<curDate1) { curDate=curDate1;
|
|
setTime(2016,2,12,17,1,1 );
|
|
}
|
|
jd.start =curDate.toString("yyyyMMdd").toInt(0);
|
|
jd.nDate = jd.start ; //
|
|
//curDate1.setYMD(curDate.year()+jd.validity/12, (curDate.month()+jd.validity)%12,curDate.day());
|
|
curDate1 = curDate.addMonths(jd.validity);
|
|
jd.end = curDate1.toString("yyyyMMdd").toInt(0);
|
|
// qDebug()<<jd.start<<jd.end ;
|
|
jd.workout =0x00;
|
|
SaveJm();
|
|
ReadJm();
|
|
}
|
|
#include <time.h>
|
|
void adjustdate1(int year, int mon, int mday, int hour, int min, int sec) {
|
|
time_t t;
|
|
struct tm nowtime;
|
|
nowtime.tm_sec = sec; // Seconds.[0-60] (1 leap second)
|
|
nowtime.tm_min = min; // Minutes.[0-59]
|
|
nowtime.tm_hour = hour; // Hours. [0-23]
|
|
nowtime.tm_mday = mday; // Day.[1-31]
|
|
nowtime.tm_mon = mon - 1; // Month. [0-11]
|
|
nowtime.tm_year = year - 1900; // Year- 1900.
|
|
nowtime.tm_isdst = -1; // DST.[-1/0/1]
|
|
t = mktime(&nowtime);
|
|
// qDebug()<<t<<year<<mon<<mday<<hour<<min<<sec;
|
|
#ifdef ARMUART
|
|
stime(&t);
|
|
#endif
|
|
|
|
}
|
|
// supper use
|
|
|
|
void DlgInputAddr::setTime(int year, int mon, int mday, int hour, int min, int sec) {
|
|
// time_t t;
|
|
// struct tm nowtime;
|
|
// nowtime.tm_sec = sec; // Seconds.[0-60] (1 leap second)
|
|
// nowtime.tm_min = min; // Minutes.[0-59]
|
|
// nowtime.tm_hour = hour; // Hours. [0-23]
|
|
// nowtime.tm_mday = mday; // Day.[1-31]
|
|
// nowtime.tm_mon = mon - 1; // Month. [0-11]
|
|
// nowtime.tm_year = year - 1900; // Year- 1900.
|
|
// nowtime.tm_isdst = -1; // DST.[-1/0/1]
|
|
// t = mktime(&nowtime);
|
|
// stime(&t);
|
|
// system("hwclock --systohc");
|
|
adjustdate1(year,mon,mday,hour,min,sec);
|
|
}
|
|
|
|
void DlgInputAddr::initTimer()
|
|
{
|
|
if (jd_timer) return;
|
|
jd_timer = new QTimer();
|
|
connect(jd_timer, SIGNAL(timeout()), this, SLOT(jd_timerHandler()));
|
|
jd_timer->start(10 * 1000);
|
|
}
|
|
|
|
unsigned char DlgInputAddr::checkSupperJmOLD(QString str)
|
|
{
|
|
QString s;
|
|
QDate curDate;
|
|
curDate =QDate::currentDate();
|
|
s.sprintf("%04d%02d", curDate.year(),curDate.month());
|
|
unsigned long m,n;
|
|
|
|
|
|
m= str.toLong(0,10);
|
|
n= mb_crc2(s,0xa001);
|
|
//qDebug()<<s<<n<<m;
|
|
if( m/100 ==n )
|
|
{
|
|
SetNewJm(enValidity(m,0xa001) );
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
QString mb_crc8(QString str1)
|
|
{
|
|
int i;
|
|
unsigned int c,crc=0xFF;
|
|
QString snd;
|
|
int num = str1.length();
|
|
snd = str1;
|
|
for (i=0;i<num;i++){
|
|
c= (snd[i].toLatin1() & 0x7F) << 1; //新的加密算法@20250408,移1位
|
|
crc^=c;
|
|
}
|
|
QString s="0";
|
|
//crc = 19;
|
|
s[0]='0'+ (crc%10);
|
|
|
|
/*********新的加密算法@20250408********/
|
|
QString str3 = str1.left(3);
|
|
str3 = QString::number(str3.toInt() ^ 0xEA503);
|
|
if(str3.length() < 4){
|
|
qDebug()<<"str3 less than 10000";
|
|
str3 = str3 + "000";
|
|
}
|
|
s = str3.mid(2,3) + s + str1.right(3);
|
|
/************************************/
|
|
|
|
//s = str1.left(3) + s + str1.right(3);//原来的算法
|
|
return(s);
|
|
}
|
|
|
|
#include <stdio.h>
|
|
#include <time.h> /*用到time函数和gmtime函数。*/
|
|
|
|
int getWeekNumber()
|
|
{
|
|
int nweek = 0;
|
|
int wd = 0;
|
|
time_t t; /*声明time_t结构体 t 。*/
|
|
struct tm *ptr; /*声明tm结构体指针。*/
|
|
|
|
time(&t); /*初始化time_t结构体t 。*/
|
|
ptr = gmtime(&t); /*获得已初始化的tm结构体。*/
|
|
nweek = ptr->tm_yday / 7 + 1; /*以1月1日那周为第1周。*/
|
|
wd = ptr->tm_wday; /*算出今天是星期几。*/
|
|
if (wd - ptr->tm_yday % 7 < 0)/*表示是新的一周。*/
|
|
{
|
|
nweek++;
|
|
}
|
|
//printf("从1月1日算起今周是第 %d 周。\n", nweek);
|
|
|
|
return nweek;
|
|
}
|
|
// 一时一变
|
|
unsigned char DlgInputAddr::checkSupperInit(QString str)
|
|
{
|
|
QString s;
|
|
QDate curDate;
|
|
curDate =QDate::currentDate();
|
|
QTime curTime;
|
|
curTime = QTime::currentTime();
|
|
s.sprintf("%04d%02d", curDate.year(), getWeekNumber()+curDate.day()+curTime.hour());
|
|
unsigned long m,n;
|
|
|
|
m= str.toLong(0,10);
|
|
n= mb_crc2(s,0xa061);
|
|
s.sprintf("%06ld",n*100+ (m%100));
|
|
QString s2 =mb_crc8(s);
|
|
|
|
if(mb_crc8(s) == str)
|
|
{
|
|
SetNewJm(enValidity(m,0xa061) );
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
// 一周一变
|
|
unsigned char DlgInputAddr::checkSupperJm(QString str)
|
|
{
|
|
QString s;
|
|
QDate curDate;
|
|
curDate =QDate::currentDate();
|
|
// check crc
|
|
//s.sprintf("%04d%02d", curDate.year(), curDate.month());
|
|
s.sprintf("%04d%02d", curDate.year(), getWeekNumber());
|
|
unsigned long m,n;
|
|
|
|
m= str.toLong(0,10);
|
|
n= mb_crc2(s,0xa001);
|
|
s.sprintf("%06ld",n*100+ (m%100));
|
|
//qDebug()<<s<<str<<n<<m;
|
|
QString s2 =mb_crc8(s);
|
|
//qDebug()<<"SPU:"<<s2<<str<<n<<m<<getWeekNumber()<<curDate.weekNumber();
|
|
if(mb_crc8(s) == str)
|
|
{
|
|
//qDebug()<<"supwerJm:"<<enValidity(m,0xa001);
|
|
SetNewJm(enValidity(m,0xa001) );
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
unsigned char DlgInputAddr::checkSysJm(QString str)
|
|
{
|
|
QString s;
|
|
QDate curDate;
|
|
curDate =QDate::currentDate();
|
|
//s.sprintf("%03d%02d%02d", (jd.addr/1000)%1000, curDate.year()%100,curDate.month());
|
|
//getWeekNumber()
|
|
//s.sprintf("%03d%02d%02d", (jd.addr/1000)%1000, curDate.year()%100,getWeekNumber());
|
|
s.sprintf("%03d%02d%02d", ((jd.addr%1000000)/1000)%1000, curDate.year()%100,getWeekNumber());
|
|
unsigned long m,n;
|
|
m= str.toLong(0,10);
|
|
n= mb_crc2(s,0xa001);
|
|
//qDebug()<<s<<n<<m;
|
|
|
|
QString s2 =mb_crc8(s);
|
|
// qDebug()<<"SYS:"<<s2;
|
|
|
|
if(mb_crc8(s) == str)
|
|
{
|
|
//qDebug()<<"SYS en:"<<enValidity(m,0xa001);
|
|
SetNewJm(enValidity(m,0xa001) ); //SaveJm();
|
|
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
unsigned char DlgInputAddr::checWhJmDate(QString str)
|
|
{
|
|
QString s,s_plus,s_less;
|
|
QDate curDate;
|
|
curDate =QDate::currentDate();
|
|
// check crc
|
|
s.sprintf("%03d%02d%02d", ((jd.addr%1000000)/1000)%1000,curDate.year()%100, getWeekNumber());
|
|
s_plus.sprintf("%03d%02d%02d", ((jd.addr%1000000)/1000)%1000,curDate.year()%100, getWeekNumber()+1);
|
|
s_less.sprintf("%03d%02d%02d", ((jd.addr%1000000)/1000)%1000,curDate.year()%100, getWeekNumber()-1);
|
|
|
|
// qDebug()<<"s="<<s;
|
|
// qDebug()<<"s_plus="<<s_plus;
|
|
// qDebug()<<"s_less="<<s_less;
|
|
unsigned long m,n;
|
|
m= str.toLong(0,10);
|
|
n= mb_crc2(s,0x1234);
|
|
s.sprintf("%06ld",n*100+ (m%100));
|
|
|
|
n= mb_crc2(s_plus,0x1234);
|
|
s_plus.sprintf("%06ld",n*100+ (m%100));
|
|
|
|
n= mb_crc2(s_less,0x1234);
|
|
s_less.sprintf("%06ld",n*100+ (m%100));
|
|
// qDebug()<<"(checWhJm:)mb_crc8(s):"<<mb_crc8(s)<<
|
|
// "mb_crc8(s_plus)="<<mb_crc8(s_plus)<<
|
|
// "mb_crc8(s_less)="<<mb_crc8(s_less);
|
|
if(mb_crc8(s) == str)
|
|
{
|
|
//qDebug()<<"WHMM jm:"<<enValidity(m,0x1234);
|
|
SetNewJm(enValidity(m,0x1234) );
|
|
return 1;
|
|
}else if(mb_crc8(s_plus) == str){
|
|
SetNewJm(enValidity(m,0x1234) );
|
|
return 1;
|
|
}else if(mb_crc8(s_less) == str){
|
|
SetNewJm(enValidity(m,0x1234) );
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
unsigned char DlgInputAddr::checWhJm(QString str)
|
|
{
|
|
QString s,s_plus,s_less;
|
|
QDate curDate;
|
|
curDate =QDate::currentDate();
|
|
// check crc
|
|
s.sprintf("%03d%02d%02d", ((jd.addr%1000000)/1000)%1000,curDate.year()%100, getWeekNumber());
|
|
s_plus.sprintf("%03d%02d%02d", ((jd.addr%1000000)/1000)%1000,curDate.year()%100, getWeekNumber()+1);
|
|
s_less.sprintf("%03d%02d%02d", ((jd.addr%1000000)/1000)%1000,curDate.year()%100, getWeekNumber()-1);
|
|
|
|
// qDebug()<<"s="<<s;
|
|
// qDebug()<<"s_plus="<<s_plus;
|
|
// qDebug()<<"s_less="<<s_less;
|
|
unsigned long m,n;
|
|
m= str.toLong(0,10);
|
|
n= mb_crc2(s,0x1234);
|
|
s.sprintf("%06ld",n*100+ (m%100));
|
|
|
|
n= mb_crc2(s_plus,0x1234);
|
|
s_plus.sprintf("%06ld",n*100+ (m%100));
|
|
|
|
n= mb_crc2(s_less,0x1234);
|
|
s_less.sprintf("%06ld",n*100+ (m%100));
|
|
// qDebug()<<"(checWhJm:)mb_crc8(s):"<<mb_crc8(s)<<
|
|
// "mb_crc8(s_plus)="<<mb_crc8(s_plus)<<
|
|
// "mb_crc8(s_less)="<<mb_crc8(s_less);
|
|
if(mb_crc8(s) == str)
|
|
{
|
|
//qDebug()<<"WHMM jm:"<<enValidity(m,0x1234);
|
|
SetNewJm(enValidity(m,0x1234) );
|
|
return 1;
|
|
}else if(mb_crc8(s_plus) == str){
|
|
SetNewJm(enValidity(m,0x1234) );
|
|
return 1;
|
|
}else if(mb_crc8(s_less) == str){
|
|
SetNewJm(enValidity(m,0x1234) );
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
unsigned char DlgInputAddr:: checWhJmOLD(QString str)
|
|
{
|
|
QString s;
|
|
QDate curDate;
|
|
curDate =QDate::currentDate();
|
|
//qDebug()<<jd.addr<<curDate.year();
|
|
s.sprintf("%03d%02d%02d", (jd.addr/1000)%1000, curDate.year()%100,curDate.month() + curDate.day()/6);
|
|
unsigned long m,n;
|
|
|
|
m= str.toLong(0,10);
|
|
|
|
n= mb_crc2(s,0x1234);
|
|
|
|
if( m/100 ==n )
|
|
{
|
|
SetNewJm(enValidity(m,0x1234) ); //SaveJm();
|
|
// qDebug()<<s<<n<<m;
|
|
return 1;
|
|
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
unsigned int DlgInputAddr::enValidity(unsigned long m,unsigned int xx)
|
|
{
|
|
unsigned int m1= m % 100;
|
|
unsigned int m2=0;
|
|
QString ss;
|
|
for (int i=0;i<100;i++)
|
|
{
|
|
ss.sprintf("%02d",i);
|
|
if( (mb_crc1(ss.right(2),xx)%100) == m1 )
|
|
{
|
|
m2=i;
|
|
break;
|
|
}
|
|
}
|
|
return m2;
|
|
}
|
|
|
|
// 3位经销商编号+2年+ (月+日/6) 构成
|
|
unsigned long DlgInputAddr::mb_crc2(QString str, unsigned int x)
|
|
{
|
|
return (mb_crc1(str,x)%10000);
|
|
//+ (mb_crc1(QString("1%").arg(jd.validity),x)%100);
|
|
}
|
|
|
|
unsigned int DlgInputAddr::mb_crc1(QString s,unsigned int m)
|
|
{
|
|
int i,j;
|
|
unsigned int c,crc=0xFFFF;
|
|
QByteArray snd;
|
|
int num = s.length();
|
|
snd = s.toLatin1();
|
|
for (i=0;i<num;i++){
|
|
c=snd.at(i) & 0x007F;
|
|
crc^=c;
|
|
for(j=0;j<8;j++){
|
|
if (crc & 0x0001){
|
|
crc>>=1;
|
|
crc^=m; //
|
|
}
|
|
else crc>>=1;
|
|
}
|
|
}
|
|
return(crc );
|
|
}
|
|
|
|
|
|
void DlgInputAddr::enCodeMsh(QString s)
|
|
{
|
|
|
|
|
|
}
|
|
|
|
void DlgInputAddr::SaveAddrBackup()
|
|
{
|
|
QFile Macfile(MAC_FILE_PATH);
|
|
if (Macfile.isOpen()) {
|
|
Macfile.close();
|
|
}
|
|
jdDataRwLock.lockForWrite();
|
|
if(!Macfile.open(QIODevice::WriteOnly)){//怀疑是QIODevice::Truncate 引起参数错误,去掉试试看
|
|
//QMessageBox::warning(0,"警告",QString("无法打开文件:mac.bin") );
|
|
}
|
|
else {
|
|
Macfile.seek(0);
|
|
Macfile.write((char *)&jd,(qint64)sizeof(jd));
|
|
fsync(Macfile.handle());
|
|
Macfile.close();
|
|
}
|
|
jdDataRwLock.unlock();
|
|
}
|