EmbHMI/mctype/mainwidgetfunction.cpp

6849 lines
223 KiB
C++
Raw Normal View History

2024-02-06 06:27:07 +00:00
#include "mainwidgetfunction.h"
MainWidgetFunction::MainWidgetFunction(QObject *parent) :
QObject(parent),
m_pPromptDlg(NULL),
m_pSystemManageDlg(NULL),
m_pBrokenLineDialog(NULL),
m_pDebugInfoDlg(NULL)
{
initialize();
initializeLotData();//初始化物联网数据
m_pPromptDlg = new PromptDialog();
m_pPromptDlg->hide();
connect(m_pPromptDlg, SIGNAL(siEmbSpindleAction(int)),this, SLOT(slotEmbSpindleAction(int)));
connect(m_pPromptDlg, SIGNAL(siEmbSpindleRotate(int)),this, SLOT(slotEmbSpindleRotate(int)));
connect(m_pPromptDlg, SIGNAL(siElasticCtrlPos(int)),this, SLOT(slotElasticCtrlPos(int)));
connect(m_pPromptDlg, SIGNAL(siLiftMotorCtrl(int)),this, SLOT(slotLiftMotorCtrl(int)));
//测试电位器的标志
//connect(this, SIGNAL(siTestADC(int)),m_pPromptDlg, SLOT(slotTestADC(int)));
connect(m_pPromptDlg, SIGNAL(siUpdataCancel()),g_pMachine, SLOT(breakFileTrans()));
connect(g_pMachine, SIGNAL(siTransProgress(u8,int,int)),this, SLOT(slotTransProgress(u8,int,int)));//升级主控进度条
// connect(g_pLotMachine,SIGNAL(siConnectToMqtt()),this,SLOT(slotSendJsonToMqtt()));
connect(g_pLotMachine,SIGNAL(siRunLotDataAction(QString)),this,SLOT(slotRunLotDataAction(QString)));
//机器信息改变
connect(g_pMachine, SIGNAL(siMcInfoChange()), this, SLOT(slotMCInfoChange()));
//接收文件信息
connect(g_pMachine, SIGNAL(siFileInfoChange()), this, SLOT(slotFileInfoChange()));
m_pSystemManageDlg = new SystemManageDialog();
connect(m_pSystemManageDlg,SIGNAL(siClearProductStatis()),this,SLOT(slotClearProductStatis()));
connect(m_pSystemManageDlg,SIGNAL(siCsvExport(int)),this,SLOT(slotCsvExport(int)));
connect(m_pSystemManageDlg,SIGNAL(siCsvChangeErro( )),this,SLOT(slotJournalError()));
connect(m_pSystemManageDlg,SIGNAL(siCsvChangeBrea( )),this,SLOT(slotJournalBreakage()));
connect(m_pSystemManageDlg,SIGNAL(siCsvChangeDebug( )),this,SLOT(slotCsvChangeDebug()));
connect(m_pSystemManageDlg,SIGNAL(siClearJournal()),this,SLOT(slotClearJournal()));
connect(m_pSystemManageDlg,SIGNAL(siRefreshWifiList()),this,SLOT(slotRefreshWifiList()));
connect(m_pSystemManageDlg,SIGNAL(siSetDynamicIP(QString)),this,SLOT(slotSetDynamicIP(QString)));
connect(m_pSystemManageDlg,SIGNAL(siSetStaticIP(QString,QString,QString)),this,SLOT(slotSetStaticIP(QString,QString,QString)));
m_pSystemManageDlg->hide();
m_pBrokenLineDialog = new BrokenLineDialog();
connect(m_pBrokenLineDialog,SIGNAL(siSetHeadData(u8*)),this,SLOT(slotSetQuiHeadBuf(u8*)));
m_pBrokenLineDialog->hide();
m_pDebugInfoDlg = new DebugInfoDialog();
m_pDebugInfoDlg->hide();
m_pTipsTimer = new QTimer(this);
m_pTipsTimer->setInterval(14400000);//设置定时器时间间隔 4小时
connect(m_pTipsTimer, SIGNAL(timeout()), this, SLOT(onTipsTimer()));
#if(IFOPENGATEWAY)
//物联网
m_pLotTimer = new QTimer(this);
connect(m_pLotTimer, SIGNAL(timeout()), this, SLOT(slotSendLotData()));
m_pLotTimer->setInterval(5000);
m_pLotTimer->start();
#endif
}
MainWidgetFunction::~MainWidgetFunction()
{
if(m_pPromptDlg != NULL)
{
delete m_pPromptDlg;
}
if(m_pSystemManageDlg != NULL)
{
delete m_pSystemManageDlg;
}
if(m_pBrokenLineDialog != NULL)
{
delete m_pBrokenLineDialog;
}
if(m_pDebugInfoDlg != NULL)
{
delete m_pDebugInfoDlg;
}
}
void MainWidgetFunction::initialize()
{
//初始化机头断线次数
memset(&m_embHeadBreakLine,0,sizeof(EmbHeadBreakLine));
memset(&m_coilHeadBreakLine,0,sizeof(CoilHeadBreakLine));
memset(&m_chenHeadBreakLine,0,sizeof(ChenHeadBreakLine));
memset((char*)&m_mcStatus,0,sizeof(MCStatus));
QDir apppath(qApp->applicationDirPath());
QString breakFilePath = apppath.path() + apppath.separator() + BREAKINFOFILE;
QFile breakFile(breakFilePath);
if(!breakFile.open(QIODevice::ReadOnly))
{
qDebug() << "open breakFile fail when read";
}
else
{
QByteArray array = breakFile.readAll();
if((u32)array.length() >= sizeof(EmbHeadBreakLine))
{
for(s32 i = 0; i < HEADNUM; i++)
{
for(s32 j = 0; j < NEEDLENUM; j++)
{
memcpy(&m_embHeadBreakLine.headNeedleBreakNum[i][j], array.data()+(i*NEEDLENUM+j)*sizeof(s32),sizeof(s32));
}
}
}
if((u32)array.length() >= (sizeof(EmbHeadBreakLine)+sizeof(CoilHeadBreakLine)))
{
for(s32 i = 0; i < HEADNUM; i++)
{
for(s32 j = 0; j < NEEDLENUM; j++)
{
if((i*NEEDLENUM+j)*sizeof(s32) < (u32)array.size())
{
memcpy(&m_coilHeadBreakLine.headNeedleBreakNum[i][j], array.data()+sizeof(EmbHeadBreakLine)+(i*NEEDLENUM+j)*sizeof(s32),sizeof(s32));
}
}
}
}
if((u32)array.length() >= (sizeof(EmbHeadBreakLine)+sizeof(CoilHeadBreakLine)+sizeof(ChenHeadBreakLine)))
{
for(s32 i = 0; i < HEADNUM; i++)
{
for(s32 j = 0; j < NEEDLENUM; j++)
{
if((i*NEEDLENUM+j)*sizeof(s32) < (u32)array.size())
{
memcpy(&m_chenHeadBreakLine.headNeedleBreakNum[i][j], array.data()+sizeof(EmbHeadBreakLine)+sizeof(CoilHeadBreakLine)+(i*NEEDLENUM+j)*sizeof(s32),sizeof(s32));
}
}
}
}
breakFile.close();
}
memset(&m_mcStatus,0,sizeof(MCStatus));
m_curFileID = 1;// 当前文件ID
m_beginX = 0;
m_beginY = 0;
m_noseHead = FLATEMB;//三个机头的选择,默认是平绣
m_potValue = 0;//电位器值
m_gearValue = 0;//档位值
m_workNoseHead = 0; //当前工作机头(从主控中读到的/界面下方显示的当前机头)
m_adcFlag = -1;
m_filePath.clear();
m_fileName.clear();
m_getScore = 0;
m_totalScore = 0;
m_camColorChange = 0;//凸轮换色
m_camColorChange = g_pSettings->readFromInHMIiFile("HMI/camColorChange").toInt();
initializeLotInfo();
}
void MainWidgetFunction::initializeLotInfo()
{
QDir apppath(qApp->applicationDirPath());
QString iniPath = apppath.path() + apppath.separator() + "config.ini";
QSettings setting(iniPath, QSettings::IniFormat); //QSettings能记录一些程序中的信息下次再打开时可以读取出来
m_getScore = setting.value("Progress/getScore").toInt();
s16 towel = g_pSettings->readFromInHMIiFile("HMI/towel").toInt();//是否有毛巾功能
s16 coil = g_pSettings->readFromInHMIiFile("HMI/coil").toInt();//是否有缠绕功能
QString path = apppath.path() + apppath.separator() + CSV_PROGRESS;
QFile file(path);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
qDebug() << "Open CSV file failed!";
return;
}
QStringList strlist;
strlist.clear();
QTextStream out(&file);
out.setCodec("GB2312"); //支持读取中文信息
//遍历行
for(int i = 0; !out.atEnd(); i++)
{
QString strLine = out.readLine();
if(strLine.size() <= 0)
{
continue;
}
m_csvFileStrList.append(strLine);
strlist = strLine.split(",", QString::SkipEmptyParts); //根据","分隔开每行的列
if(i > 0) //第一行不执行操作
{
if (strlist.size() > COLUMN_SCORE)
{
QString code = strlist.at(COLUMN_CODE);
QStringList strlist1 = code.split("_", QString::SkipEmptyParts); //根据"_"分隔开每行的列
int type = 0;
if(strlist1.size() > 0)
{
char *buf = strdup(strlist1[1].toLatin1().data());
sscanf (buf, "%x", &type);
}
s16 score = 0;
if(type == CSV_MC_TYPE_02 && towel != 0)//带毛巾
{
score = strlist.at(COLUMN_SCORE).toInt();
}
else if(type == CSV_MC_TYPE_03 && coil != 0)//带缠绕
{
score = strlist.at(COLUMN_SCORE).toInt();
}
else if(type == 0)
{
score = strlist.at(COLUMN_SCORE).toInt();
}
m_totalScore += score;
}
}
}
file.close();//关闭文件
}
//初始化物联网数据
void MainWidgetFunction::initializeLotData()
{
memset(&m_mcLotData,0,sizeof(McLotData));
memset(&m_HMILotData,0,sizeof(HMILotData));
QString verStr = getVersionStr();
memcpy(m_HMILotData.HMIVerStr, verStr.data(), verStr.length()); // 版本号
u32 rackNum = g_pSettings->readFromIniFile("IOT/rackNumber").toInt();//机架号
m_HMILotData.machineNumber = rackNum; // 机架号
u16 dProgress = g_pSettings->readFromIniFile("IOT/debugProgress").toInt();//调试进度
m_HMILotData.debugProgress = dProgress; //调试进度
QString deliveryTime = g_pSettings->readFromIniFile("IOT/deliveryTime").toString();//工厂预计交货时间
QByteArray arr = deliveryTime.toLocal8Bit();
memcpy(m_HMILotData.deliveryTime, arr.data(), arr.size()); //交货日期
//电机总数-先固定写为4个如果后续变动较大可把电机个数写为全局变量或从其他cpp中传参
m_HMILotData.motorNum = 4;
m_HMILotData.workState = S0505;
QString fileName = m_fileName;
memcpy(m_HMILotData.fileName, fileName.data(), fileName.length()); // 文件名称
}
//优盘检测
QString MainWidgetFunction::detectUsb()
{
QString usbPath = "";
#ifdef Q_OS_LINUX
QDir dir(LINUXUSBPATH);
if(!dir.exists())
{
usbPath = "";
}
else
{
usbPath = LINUXUSBPATH;
}
#endif
#ifdef Q_OS_WIN
QFileInfoList list = QDir::drives();
for(int i = 0; i<list.count(); i++)
{
UINT ret = GetDriveType((WCHAR *) list.at(i).filePath().utf16());
if(ret == DRIVE_REMOVABLE)
{
usbPath = list.at(i).filePath();
break;
}
}
#endif
return usbPath;
}
s16 MainWidgetFunction::detectWifiConnect()
{
s16 value = -1;
#ifdef Q_OS_LINUX
QProcess cmd;
QString cmdStr;
cmdStr.clear();
QString strCmdOut;
strCmdOut.clear();
QStringList lineStrList;
lineStrList.clear();
cmdStr = "wpa_cli -i wlan0 status";//查询wifi连接状态
cmd.start(cmdStr);
cmd.waitForStarted();
cmd.waitForFinished();
strCmdOut=QString::fromLocal8Bit(cmd.readAllStandardOutput());
//qDebug()<<"strCmdOut"<<strCmdOut;
lineStrList = strCmdOut.split("\n", QString::SkipEmptyParts); //换行符
//qDebug()<<"lineStrList.size()"<<lineStrList.size();
for(int i = 0; i < lineStrList.size(); i++)
{
QStringList lineStr = lineStrList[i].split("=", QString::SkipEmptyParts);
if(lineStr.size() >= 2)
{
QString str1 = lineStr[0];
//qDebug()<<lineStrList[i];
if(str1.indexOf("wpa_state") != -1)
{
QString str2 = lineStr[1];
//qDebug()<<str2;
if(str2.indexOf("COMPLETED") == -1)
{
cmd.close();
value = -1;
}
}
if(str1.indexOf("ip_address") != -1)
{
cmd.close();
value = 1;
break;
}
}
}
cmd.close();
#endif
return value;
}
void MainWidgetFunction::systemUpgrade(int type, int paraType, u8 protocol, u8 nodeid, u8 nodeType)
{
QString usbPath = detectUsb();
if(usbPath.length() <= 0)
{
//优盘不存在
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("USB flash drive is not detected!");//未检测到优盘!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
QDir apppath(qApp->applicationDirPath());
QString targetDir = apppath.absolutePath() + apppath.separator();
QDir dir (usbPath);
dir.setFilter(QDir::Files | QDir::NoSymLinks); // 设置类型过滤器,只为文件格式
QFileInfoList fileList = dir.entryInfoList();
if(type == HMI_UPDATA)//界面升级
{
qDebug()<<"update 1";
//界面文件、语言文件、RCC资源文件、打包的AUT文件
for (int var = 0; var < fileList.size(); var++)
{
#ifdef Q_OS_WIN
if((fileList.at(var).fileName().toUpper().indexOf(APPNAME) != -1 &&
fileList.at(var).suffix().toUpper() == "EXE") ||
fileList.at(var).fileName().toUpper().indexOf(".QM") != -1 ||
fileList.at(var).fileName().toUpper().indexOf(".RCC") != -1 ||
fileList.at(var).fileName().toUpper().indexOf(".AUT") != -1)
{
m_pSystemManageDlg->addItem(fileList.at(var).fileName());
}
#endif
#ifdef Q_OS_LINUX
if((fileList.at(var).fileName().toUpper().indexOf(APPNAME) != -1 &&
fileList.at(var).suffix().toUpper().length() == 0) ||
fileList.at(var).fileName().toUpper().indexOf(".QM") != -1 ||
fileList.at(var).fileName().toUpper().indexOf(".RCC") != -1 ||
fileList.at(var).fileName().toUpper().indexOf(".AUT") != -1)
{
m_pSystemManageDlg->addItem(fileList.at(var).fileName());
}
#endif
}
qDebug()<<"update 2";
}
else if(type == MC_UPDATA)//主控升级
{
for (int var = 0; var < fileList.size(); var++)
{
if( fileList.at(var).suffix().toUpper() == "RNPU")
{
m_pSystemManageDlg->addItem(fileList.at(var).fileName());
}
}
qDebug()<<"update 3";
}
else if(type == EXBOARD_UPDATA)//外围板升级
{
for (int var = 0; var < fileList.size(); var++)
{
if( fileList.at(var).suffix().toUpper() == "RNPU")
{
m_pSystemManageDlg->addItem(fileList.at(var).fileName());
}
}
qDebug()<<"update 5";
}
else if(type == PARA_IMPORT ||
type == WKPARA_IMPORT)//参数导入或工作参数导入
{
QString fileSuffix;
fileSuffix.clear();
if(paraType == 0)
{
fileSuffix = "PARADAT";
}
else
{
if (paraType == PARA_TYPE_HEADPARAMETER)
{
fileSuffix = "FHDPARADAT";
}
else if (paraType == PARA_TYPE_TOWELHEADPARAMETER)
{
fileSuffix = "THDPARADAT";
}
else if (paraType == PARA_TYPE_COILHEADPARAMETER)
{
fileSuffix = "CHDPARADAT";
}
else if (paraType == PARA_TYPE_HCPSPARAMETER)//平绣换色板
{
fileSuffix = "FHSPARADAT";
}
else if ( paraType == PARA_TYPE_TOWELHCPSPARAMETER)//毛巾换色板
{
fileSuffix = "CHSPARADAT";
}
}
for (int var = 0; var < fileList.size(); var++)
{
if( fileList.at(var).suffix().toUpper() == fileSuffix)
{
m_pSystemManageDlg->addItem(fileList.at(var).fileName());
}
}
qDebug()<<"update 4";
}
else if(type == FRAMEPARA_IMPORT)//动框参数导入
{
for (int var = 0; var < fileList.size(); var++)
{
if( fileList.at(var).suffix().toUpper() == "FRAMEPARADAT")
{
m_pSystemManageDlg->addItem(fileList.at(var).fileName());
}
}
}
//点击了确认按钮
if(m_pSystemManageDlg->exec(type) == 1)
{
QString fileName = m_pSystemManageDlg->getCurFile();
if(type == HMI_UPDATA)//界面升级
{
QString sPath,tPath;
#ifdef Q_OS_WIN
if(fileName.toUpper().indexOf(APPNAME) != -1 &&
fileName.toUpper().indexOf(".EXE") != -1)
{
sPath = usbPath + fileName;
tPath = targetDir + WIN_APPNAME;
qDebug()<<"HMI Update";
qDebug()<<"sPath"<<sPath;
qDebug()<<"tPath"<<tPath;
QFile::remove(tPath);
QFile::copy( sPath , tPath);
qApp->exit();
}
#endif
#ifdef Q_OS_LINUX
if(fileName.toUpper().indexOf(APPNAME) != -1 &&
fileName.toUpper().indexOf(".EXE") == -1 &&
fileName.toUpper().indexOf(".AUT") == -1)//非aut打包文件
{
sPath = usbPath + fileName;
tPath = targetDir + LINUX_APPNAME;
qDebug()<<"HMI Update";
qDebug()<<"sPath"<<sPath;
qDebug()<<"tPath"<<tPath;
QFile::remove(tPath);
system("sync");
QFile::copy( sPath , tPath);
system("sync");
system("reboot");
qDebug()<<"reboot";
}
#endif
else if(fileName.toUpper().indexOf(".QM") != -1 )
{
//增加语言包选择日期
QString tPath;// 目标文件
if(fileName.toUpper().indexOf("LAG-ZH") != -1 ) //中文语言包 //XPlatForm-SEW-RP-LAG-ZH-V220511.qm
{
tPath = targetDir + "chinese.qm"; // 目标文件
}
else if(fileName.toUpper().indexOf("LAG-EN") != -1 ) // 英语
{
tPath = targetDir + "english.qm";
}
else if(fileName.toUpper().indexOf("LAG-ES") != -1 ) // 西班牙语
{
tPath = targetDir + "spanish.qm";
}
else if(fileName.toUpper().indexOf("LAG-TK") != -1 ) // 土耳其语
{
tPath = targetDir + "turkey.qm";
}
else if(fileName.toUpper().indexOf("LAG-RQ") != -1 ) // 葡萄牙语
{
tPath = targetDir + "portugal.qm";
}
else if(fileName.toUpper().indexOf("LAG-FR") != -1 ) // 法语
{
tPath = targetDir + "french.qm";
}
else
{
tPath = targetDir + fileName ;
}
QString sPath = usbPath + fileName ;//源文件
QString tPath1 = targetDir + "language.qm";
QString tPath2 = targetDir + fileName;
qDebug()<<"Language Update";
qDebug()<<"sPath"<<sPath; //sPath "F:/chinese.qm"
qDebug()<<"tPath"<<tPath; //tPath "D:/work/workQT/XPlatform/Windows/debug\\chinese.qm"
qDebug()<<"tPath1"<<tPath1; //tPath1 "D:/work/workQT/XPlatform/Windows/debug\\language.qm"
QFile::remove(tPath);
QFile::remove(tPath1);
QFile::remove(tPath2);
#ifdef Q_OS_LINUX
system("sync");
#endif
QFile::copy(sPath , tPath);//sPath复制到tPath
QFile::copy(sPath , tPath1);
QFile::copy(sPath , tPath2);
#ifdef Q_OS_WIN
qApp->exit();
#endif
#ifdef Q_OS_LINUX
system("sync");
system("reboot");
#endif
}
else if(fileName.toUpper().indexOf(".RCC") != -1 )
{
QString sPath = usbPath + fileName ;
QString tPath = targetDir + "nxcui.rcc";
qDebug()<<"RCC Update";
qDebug()<<"sPath"<<sPath;
qDebug()<<"tPath"<<tPath;
QFile::remove(tPath );
#ifdef Q_OS_LINUX
system("sync");
#endif
QFile::copy(sPath , tPath);
#ifdef Q_OS_WIN
qApp->exit();
#endif
#ifdef Q_OS_LINUX
system("sync");
system("reboot");
#endif
}
else if(fileName.toUpper().indexOf(".AUT") != -1)//界面打包文件(包括升级文件、语言包、RCC等)
{
QString strFile = usbPath + fileName;
QFile file(strFile);
file.open(QIODevice::ReadOnly);
QByteArray AllData = file.readAll();
HMIFileHead *fhead = (HMIFileHead*)(AllData.data());
int filenum = fhead->fileNum;
int bSize = 0;
for(int j = 0; j < filenum; j++)
{
int cSize = j*sizeof(HMIItemFileHead) + sizeof(HMIFileHead) + bSize;
HMIItemFileHead *ahead;
ahead = (HMIItemFileHead*)(AllData.data() + cSize);
QString fName = ahead->fileName;
int fileSize = ahead->fileSize;
if(fileSize <= 0)
{
return;
}
int sDataCheck = ahead->dataCheck;
cSize = cSize + sizeof(HMIItemFileHead);
QByteArray buf = AllData.mid(cSize,fileSize);
int tDataCheck = calcCheckSum32((u8*)buf.data(),fileSize);
bSize = bSize + fileSize;
//校验相同,查找相同的文件替换
if(sDataCheck == tDataCheck)
{
QString uFileName = targetDir + fName;
QFile uFile(uFileName);
QString cName = fName;
if(uFile.exists())//执行目录中存在U盘中的文件fileName
{
QString targetPath;
targetPath.clear();
#ifdef Q_OS_WIN
if(fName.toUpper().indexOf(APPNAME) != -1 &&
fName.toUpper().indexOf(".EXE") != -1)
{
targetPath = targetDir + WIN_APPNAME;
}
#endif
#ifdef Q_OS_LINUX
if(fName.toUpper().indexOf(APPNAME) != -1 &&
fName.toUpper().indexOf(".EXE") == -1)
{
targetPath = targetDir + LINUX_APPNAME;
cName = LINUX_APPNAME;
}
#endif
#if(0)
if(fName.toUpper().indexOf(APPNAME) != -1)
{
#ifdef Q_OS_WIN
targetPath = targetDir + WIN_APPNAME;
#endif
#ifdef Q_OS_LINUX
targetPath = targetDir + LINUX_APPNAME;
cName = LINUX_APPNAME;
#endif
}
#endif
else//其他文件
{
targetPath = uFileName;
}
QFile::remove(targetPath);
QFile tFile(targetPath);
if(tFile.open(QIODevice::WriteOnly) == false)
{
return;
}
tFile.write(buf);
qDebug()<<"AUT Update";
qDebug()<<"targetPath"<<targetPath;
#ifdef Q_OS_LINUX
QString str = "chmod 777 " + cName;
system(str.toLatin1());
#endif
}
else//不存在
{
QString targetPath;
targetPath.clear();
#ifdef Q_OS_WIN
if(fName.toUpper().indexOf(APPNAME) != -1 &&
fName.toUpper().indexOf(".EXE") != -1)
{
targetPath = targetDir + WIN_APPNAME;
}
#endif
#ifdef Q_OS_LINUX
if(fName.toUpper().indexOf(APPNAME) != -1 &&
fName.toUpper().indexOf(".EXE") == -1)
{
targetPath = targetDir + LINUX_APPNAME;
cName = LINUX_APPNAME;
}
#endif
#if(0)
if(fName.toUpper().indexOf(APPNAME) != -1)
{
#ifdef Q_OS_WIN
targetPath = targetDir + WIN_APPNAME;
#endif
#ifdef Q_OS_LINUX
targetPath = targetDir + LINUX_APPNAME;
cName = LINUX_APPNAME;
#endif
}
#endif
else//其他文件
{
#ifdef Q_OS_WIN
if(fName.toUpper().indexOf(APPNAME) != -1 &&
fName.toUpper().indexOf(".EXE") == -1)
{
continue;
}
#endif
#ifdef Q_OS_LINUX
if(fName.toUpper().indexOf(APPNAME) != -1 &&
fName.toUpper().indexOf(".EXE") != -1)
{
continue;
}
#endif
targetPath = uFileName;
}
QFile tFile(targetPath);
if(tFile.open(QIODevice::WriteOnly) == false)
{
return;
}
tFile.write(buf);
qDebug()<<"not exist"<<cName;
qDebug()<<"targetPath"<<targetPath;
#ifdef Q_OS_LINUX
QString str = "chmod 777 " + cName;
system(str.toLatin1());
#endif
}
}
else
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentStr(tr("The program is corrupted, please re-upgrade after replacing the program!")); //程序已损坏,请更换程序后重新升级!
m_pPromptDlg->exec();
return;
}
}
file.close();
#ifdef Q_OS_LINUX
qDebug()<<"reboot before";
system("sync");
system("reboot");
qDebug()<<"reboot end";
#endif
//需放在linux重启命令后面
#ifdef Q_OS_WIN
qDebug()<<"qApp->exit()";
qApp->exit();
#endif
}
else
{
//所选文件非升级文件
//文件格式错误,请重新选择!
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("The file format is wrong, please select again!");//文件格式错误,请重新选择!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
}
}
else if(type == MC_UPDATA)//主控升级
{
if(fileName.toUpper().indexOf(".RNPU") != -1)
{
QString uPath = usbPath + fileName;
qDebug()<<"RNPU update";
qDebug()<<"uPath"<<uPath;
AppFileHead appHead ;
memset(&appHead , 0 , sizeof(appHead));
QFile file(uPath);
u8 * pBuff = (u8 *) malloc(file.size());
qDebug() << "file.size()" << file.size();
if(file.size() <= 0)
{
//文件格式错误,请重新选择!
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("File bytes are 0, please check the file!");//文件字节为0请检查文件!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
file.open(QIODevice::ReadOnly);
file.read( (char *)pBuff , file.size()) ;
file.close();
int nameSize = uPath.toUtf8().size() ;
if( nameSize > 32 )
{
nameSize = 32;
}
memcpy(appHead.fileName , uPath.toUtf8().data() , nameSize);
appHead.dataSize = file.size();
appHead.dataChecksum = calcCheckSum32(pBuff , file.size());
static int nID = 0;
if( g_pMachine->isConnected() == 3)
{
g_pMachine->sendAPPFileProc(FILE_TYPE_PGM,
0,
nID++,
appHead ,
pBuff
);
}
free(pBuff);
}
}
else if(type == EXBOARD_UPDATA)//外围板升级
{
if(fileName.toUpper().indexOf(".RNPU") != -1)
{
QString uPath = usbPath + fileName;
qDebug()<<"RNPU update";
qDebug()<<"uPath"<<uPath;
BoardFileHead boardHead ;
memset(&boardHead , 0 , sizeof(boardHead));
QFile file(uPath);
u8 * pBuff = (u8 *) malloc( file.size());
qDebug() << "file.size()" << file.size();
file.open(QIODevice::ReadOnly);
file.read( (char *)pBuff , file.size()) ;
file.close();
int nameSize = uPath.toUtf8().size() ;
if( nameSize > 32 )
{
nameSize = 32;
}
memcpy(boardHead.fileName , uPath.toUtf8().data() , nameSize);
boardHead.dataSize = file.size();
boardHead.dataChecksum = calcCheckSum32(pBuff , file.size());
boardHead.protocol = protocol;
boardHead.nodeid = nodeid;
boardHead.nodeType = nodeType;
boardHead.fileType = FILE_TYPE_PGM;
static int nID = 0;
if( g_pMachine->isConnected() == 3)
{
g_pMachine->sendBoardFileProc(FILE_TYPE_BOARD,
0,
nID++,
boardHead ,
pBuff
);
}
free(pBuff);
}
}
else if(type == PARA_IMPORT)//参数导入
{
QString uPath = usbPath + fileName;
qDebug()<<"Para Import";
qDebug()<<"uPath"<<uPath;
QFile paraFile(uPath);
if(!paraFile.exists())
{
return;
}
paraFile.open(QIODevice::ReadOnly);
if(paraFile.size() != 0)
{
int readSize = 0;
// 将文件 读取成结构体
ParaFile paraFileStruct;
memset(&paraFileStruct,0,sizeof(ParaFile));
HeadInfo headParaValues;
memset(&headParaValues,0,sizeof(HeadInfo));
HcpsInfo hcpsParaValues;
memset(&hcpsParaValues,0,sizeof(HcpsInfo));
int paraSize = 0;
if(paraType != 0)
{
//换色板
if(paraType == PARA_TYPE_TOWELHCPSPARAMETER ||
paraType == PARA_TYPE_HCPSPARAMETER)
{
readSize = paraFile.read((char*)&hcpsParaValues,sizeof(HcpsInfo));
paraSize = sizeof(HcpsInfo);
}
else
{
readSize = paraFile.read((char*)&headParaValues,sizeof(HeadInfo));
paraSize = sizeof(HeadInfo);
}
paraFile.close();
}
else
{
readSize = paraFile.read((char*)&paraFileStruct,sizeof(ParaFile));
paraSize = sizeof(ParaFile);
paraFile.close();
}
if(readSize != paraFile.size())
{
//文件大小不匹配,无效的参数文件
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = (tr("File size not match, invalid file!"));//文件大小不匹配,无效的参数文件!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
if( readSize != paraSize)
{
//文件大小不匹配,无效的参数文件
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = (tr("File size not match, invalid file!"));//文件大小不匹配,无效的参数文件!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
// 参数被正确的读取
if(paraType == 0)
{
if(
( paraFileStruct.s_head[0] == 'P' )
&& ( paraFileStruct.s_head[1] == 'A' )
&& ( paraFileStruct.s_head[2] == 'R' )
&& ( paraFileStruct.s_head[3] == 'A' )
&& ( paraFileStruct.s_type == 0 )
&& ( paraFileStruct.s_len == 4096 )
)
{
unsigned short i_crc = calcCrc16( (unsigned char *) paraFileStruct.s_para_buff , paraFileStruct.s_len);
if( paraFileStruct.s_crc != i_crc )
{
//数据校验错误,无效的参数文件
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = (tr("Data check error, invalid file!"));//数据校验错误,无效的参数文件!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
//将 一个文件 拆分成两个 缓冲区
unsigned char mac_config [1024] ;
unsigned char work_config [1024] ;
unsigned char pre_mac_config [1024] ;
unsigned char pre_work_config [1024] ;
// 清空
memset( mac_config , 0 , 1024 ) ;
memset( work_config , 0 , 1024 ) ;
memset( pre_mac_config , 0 , 1024 ) ;
memset( pre_work_config , 0 , 1024 ) ;
memcpy( work_config , paraFileStruct.s_para_buff , 1024 ) ;
memcpy( mac_config , ((char*)paraFileStruct.s_para_buff) + 1024 , 1024 ) ;
memcpy( pre_mac_config , ((char*)paraFileStruct.s_para_buff) + 2048 , 1024 ) ;
memcpy( pre_work_config , ((char*)paraFileStruct.s_para_buff) + 3072 , 1024 ) ;
g_pMachine->setMcPara((ParaStruct *) mac_config);
g_pMachine->setWkPara((ParaStruct *) work_config);
g_pMachine->setMcPrePara((ParaStruct *) pre_mac_config);
g_pMachine->setWkPrePara((ParaStruct *) pre_work_config);
QString str;
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
str = (tr("Parameters imported successfully!"));//参数导入成功!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
else
{
//文件头不匹配,无效的参数文件!
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = (tr("File head not match, invalid file!"));//文件头不匹配,无效的参数文件!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
}
else if(paraType != 0)
{
if(paraType == PARA_TYPE_HEADPARAMETER)
{
g_pMachine->setHeadBoardPara(&headParaValues, FLATEMB);
}
else if(paraType == PARA_TYPE_TOWELHEADPARAMETER)
{
g_pMachine->setHeadBoardPara(&headParaValues, TOWEL);
}
else if(paraType == PARA_TYPE_COILHEADPARAMETER)
{
g_pMachine->setHeadBoardPara(&headParaValues, COIL);
}
else if(paraType == PARA_TYPE_TOWELHCPSPARAMETER ||
paraType == PARA_TYPE_HCPSPARAMETER)
{
g_pMachine->setHcpsBoardPara(&hcpsParaValues,1);
}
emit siHeadParaImportFinish(paraType);
QString str;
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
str = (tr("Parameters imported successfully!"));//参数导入成功!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
}
}
else if (type == WKPARA_IMPORT) //工作参数导入
{
QString uPath = usbPath + fileName;
QFile paraFile(uPath);
if(!paraFile.exists())
{
return;
}
paraFile.open(QIODevice::ReadOnly);
if(paraFile.size() != 0)
{
// 将文件 读取成结构体
ParaFile paraFileStruct;
memset(&paraFileStruct,0,sizeof(ParaFile));
int readSize = paraFile.read((char*)&paraFileStruct,sizeof(ParaFile));
paraFile.close();
if(readSize != paraFile.size())
{
//文件大小不匹配,无效的参数文件
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = (tr("File size not match, invalid file!"));//文件大小不匹配,无效的参数文件!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
if( readSize != sizeof(ParaFile) )
{
//文件大小不匹配,无效的参数文件
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = (tr("File size not match, invalid file!"));//文件大小不匹配,无效的参数文件!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
// 参数被正确的读取
if(
( paraFileStruct.s_head[0] == 'P' )
&& ( paraFileStruct.s_head[1] == 'A' )
&& ( paraFileStruct.s_head[2] == 'R' )
&& ( paraFileStruct.s_head[3] == 'A' )
&& ( paraFileStruct.s_type == 0 )
&& ( paraFileStruct.s_len == 4096 )
)
{
unsigned short i_crc = calcCrc16( (unsigned char *) paraFileStruct.s_para_buff , paraFileStruct.s_len);
if( paraFileStruct.s_crc != i_crc )
{
//数据校验错误,无效的参数文件
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = (tr("Data check error, invalid file!"));//数据校验错误,无效的参数文件!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
//将 一个文件 拆分成两个 缓冲区
unsigned char mac_config [1024] ;
unsigned char work_config [1024] ;
unsigned char pre_mac_config [1024] ;
unsigned char pre_work_config [1024] ;
// 清空
memset( mac_config , 0 , 1024 ) ;
memset( work_config , 0 , 1024 ) ;
memset( pre_mac_config , 0 , 1024 ) ;
memset( pre_work_config , 0 , 1024 ) ;
memcpy( work_config , paraFileStruct.s_para_buff , 1024 ) ;
memcpy( mac_config , ((char*)paraFileStruct.s_para_buff) + 1024 , 1024 ) ;
memcpy( pre_mac_config , ((char*)paraFileStruct.s_para_buff) + 2048 , 1024 ) ;
memcpy( pre_work_config , ((char*)paraFileStruct.s_para_buff) + 3072 , 1024 ) ;
QString str;
g_pMachine->setWkPara((ParaStruct *) work_config);
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
str = (tr("Work parameters imported successfully!"));//工作参数导入成功!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
else
{
//文件头不匹配,无效的参数文件!
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = (tr("File head not match, invalid file!"));//文件头不匹配,无效的参数文件!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
}
}
else if(type == FRAMEPARA_IMPORT)//动框参数导入
{
QString uPath = usbPath + fileName;
QFile paraFile(uPath);
if(!paraFile.exists())
{
return;
}
paraFile.open(QIODevice::ReadOnly);
if(paraFile.size() != 0)
{
// 将文件 读取成结构体
ParaFile paraFileStruct;
memset(&paraFileStruct,0,sizeof(ParaFile));
int readSize = paraFile.read((char*)&paraFileStruct,sizeof(ParaFile));
paraFile.close();
if(readSize != paraFile.size())
{
//文件大小不匹配,无效的参数文件
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = (tr("File size not match, invalid file!"));//文件大小不匹配,无效的参数文件!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
if( readSize != sizeof(ParaFile) )
{
//文件大小不匹配,无效的参数文件
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = (tr("File size not match, invalid file!"));//文件大小不匹配,无效的参数文件!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
// 参数被正确的读取
if(
( paraFileStruct.s_head[0] == 'P' )
&& ( paraFileStruct.s_head[1] == 'A' )
&& ( paraFileStruct.s_head[2] == 'R' )
&& ( paraFileStruct.s_head[3] == 'A' )
&& ( paraFileStruct.s_type == 0 )
&& ( paraFileStruct.s_len == 4096 )
)
{
unsigned short i_crc = calcCrc16( (unsigned char *) paraFileStruct.s_para_buff , paraFileStruct.s_len);
if( paraFileStruct.s_crc != i_crc )
{
//数据校验错误,无效的参数文件
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = (tr("Data check error, invalid file!"));//数据校验错误,无效的参数文件!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
//将 一个文件 拆分成两个 缓冲区
unsigned char frame1_config [1024] ;
//unsigned char frame2_config [1024] ;
unsigned char pre_frame1_config [1024] ;
// unsigned char pre_frame2_config [1024] ;
// 清空
memset( frame1_config , 0 , 1024 ) ;
//memset( frame2_config , 0 , 1024 ) ;
memset( pre_frame1_config , 0 , 1024 ) ;
//memset( pre_frame2_config , 0 , 1024 ) ;
memcpy( frame1_config , paraFileStruct.s_para_buff , 1024 ) ;
// memcpy( frame2_config , ((char*)paraFileStruct.s_para_buff) + 1024 , 1024 ) ;
memcpy( pre_frame1_config , ((char*)paraFileStruct.s_para_buff) + 1024 , 1024 ) ;
//memcpy( pre_frame2_config , ((char*)paraFileStruct.s_para_buff) + 3072 , 1024 ) ;
QString str;
g_pMachine->setFrameAnglePara((EmbMvAng *) frame1_config);
// g_pMachine->setWkPara((ParaStruct *) frame2_config);
g_pMachine->setFrameAnglePara((EmbMvAng *) pre_frame1_config);
// g_pMachine->setWkPrePara((ParaStruct *) pre_frame2_config);
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
str = (tr("Frame parameters imported successfully!"));//动框参数导入成功!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
else
{
//文件头不匹配,无效的参数文件!
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = (tr("File head not match, invalid file!"));//文件头不匹配,无效的参数文件!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
}
}
}
}
s16 MainWidgetFunction::refreshWifiList(QStringList &wifiStrList,s16 scan)
{
if(scan == 0){}//为了去掉编译警告
wifiStrList.clear();
QProcess cmd;
QString cmdStr;
cmdStr.clear();
QString strCmdOut;
strCmdOut.clear();
QStringList lineStrList;
lineStrList.clear();
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
#ifdef Q_OS_LINUX
cmdStr = "ifconfig";//查看wlan0初始化是否成功
cmd.start(cmdStr);
cmd.waitForStarted();
cmd.waitForFinished();
strCmdOut=QString::fromLocal8Bit(cmd.readAllStandardOutput());
lineStrList = strCmdOut.split("\n", QString::SkipEmptyParts); //换行符
int initFlag = 0;
for(int i = 0; i < lineStrList.size(); i++)
{
QString lineStr = lineStrList[i];
if(lineStr.indexOf("wlan0") != -1)
{
initFlag = 1;
break;
}
}
if(initFlag == 0)
{
m_pPromptDlg->setContentStr(tr("Failed to initialize wlan0!"));//初始化wlan0失败
m_pPromptDlg->exec();
return -1;
}
if(scan != 0)
{
cmdStr = "wpa_cli -i wlan0 scan";//搜索可见wifi
cmd.start(cmdStr);
cmd.waitForStarted();
cmd.waitForFinished();
strCmdOut=QString::fromLocal8Bit(cmd.readAllStandardOutput());
int flag = 0;
while(strCmdOut.toUpper().indexOf("OK") == -1)
{
cmdStr = "wpa_cli -i wlan0 scan";//搜索可见wifi
cmd.start(cmdStr);
cmd.waitForStarted();
cmd.waitForFinished();
strCmdOut=QString::fromLocal8Bit(cmd.readAllStandardOutput());
flag++;
if(flag >= 100)
{
break;
}
}
}
cmdStr = "wpa_cli -i wlan0 scan_result";//获取搜索结果
cmd.start(cmdStr);
cmd.waitForStarted();
cmd.waitForFinished();
strCmdOut=QString::fromLocal8Bit(cmd.readAllStandardOutput());
lineStrList = strCmdOut.split("\n", QString::SkipEmptyParts);//换行符
for(int i = 0; i < lineStrList.size(); i++)
{
//qDebug()<<i<<lineStrList[i];
QStringList lineStr = lineStrList[i].split("\t", QString::SkipEmptyParts);//tap
if(lineStr.size() >= 2 && lineStr[lineStr.size()-1].indexOf("]") == -1)
{
QString str = lineStr[lineStr.size()-1].remove(QRegExp("^ +\\s*"));//正则表达式去掉空格
s16 ifExist = 0;
for(s16 m = 0; m < wifiStrList.size(); m++)
{
if(wifiStrList[m] == str)
{
ifExist = 1;
break;
}
}
if(ifExist == 0)
{
wifiStrList.append(str);
}
}
}
if(wifiStrList.size() <= 0)
{
m_pPromptDlg->setContentStr(tr("Failed to search for WiFi list. Please try again later!"));//搜索wifi列表失败请稍后重试
m_pPromptDlg->exec();
return -1;
}
#endif
return 1;
}
QString MainWidgetFunction::getIpSegment(bool bl)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString ipStr;
ipStr.clear();
if(bl == true){}//为了去掉编译警告
//linux下查询wifi连接状态
#ifdef Q_OS_LINUX
s16 value = -1;
QProcess cmd;
QString cmdStr;
cmdStr.clear();
QString strCmdOut;
strCmdOut.clear();
QStringList lineStrList;
lineStrList.clear();
cmdStr = "wpa_cli -i wlan0 status";//查询wifi连接状态
cmd.start(cmdStr);
cmd.waitForStarted();
cmd.waitForFinished();
strCmdOut=QString::fromLocal8Bit(cmd.readAllStandardOutput());
//qDebug()<<"strCmdOut"<<strCmdOut;
lineStrList = strCmdOut.split("\n", QString::SkipEmptyParts); //换行符
//qDebug()<<"lineStrList.size()"<<lineStrList.size();
for(int i = 0; i < lineStrList.size(); i++)
{
QStringList lineStr = lineStrList[i].split("=", QString::SkipEmptyParts);
if(lineStr.size() >= 2)
{
QString str1 = lineStr[0];
//qDebug()<<lineStrList[i];
if(str1.indexOf("wpa_state") != -1)
{
QString str2 = lineStr[1];
//qDebug()<<str2;
if(str2.indexOf("COMPLETED") == -1)
{
cmd.close();
}
}
if(str1.indexOf("ip_address") != -1)
{
ipStr = lineStr[1].remove(QRegExp("^ +\\s*"));//正则表达式去掉空格-IP
cmd.close();
value = 1;
break;
}
}
}
cmd.close();
if(value >= 0)
{
QString modeStr;
modeStr.clear();
if(bl == false)
{
modeStr = tr("dynamic");//动态
}
else if(bl == true)
{
modeStr = tr("static");//静态
}
ipStr = ipStr + "(" + modeStr + ")";
}
else
{
if(bl == true)
{
m_pPromptDlg->setContentStr(tr("Failed to obtain IP. Please check the settings!"));//获取IP失败请检查设置
m_pPromptDlg->exec();
}
}
#endif
return ipStr;
}
//工作参数导入
void MainWidgetFunction::funImportWkParameter(QString tStyle)
{
m_pSystemManageDlg->setTypeLogo(tStyle);
m_pSystemManageDlg->setMainTitle(tr("WkParameter Import"));
m_pSystemManageDlg->setSubTitle(tr("Auxiliary Function > WkParameter Import"));
m_pSystemManageDlg->initDialog();
systemUpgrade(WKPARA_IMPORT);
}
//参数导入
void MainWidgetFunction::funImportParameter(QString tStyle)
{
m_pSystemManageDlg->setTypeLogo(tStyle);
m_pSystemManageDlg->setMainTitle(tr("Parameter Import"));
m_pSystemManageDlg->setSubTitle(tr("Auxiliary Function > Parameter Import"));
m_pSystemManageDlg->initDialog();
systemUpgrade(PARA_IMPORT);
}
//主控升级
void MainWidgetFunction::funMCUpgrade(QString tStyle)
{
m_pSystemManageDlg->setTypeLogo(tStyle);
m_pSystemManageDlg->setMainTitle(tr("MC Upgrade"));
m_pSystemManageDlg->setSubTitle(tr("Auxiliary Function > MC Upgrade"));
m_pSystemManageDlg->initDialog();
systemUpgrade(MC_UPDATA);
}
//界面升级
void MainWidgetFunction::funHMIUpgrade(QString tStyle)
{
m_pSystemManageDlg->setTypeLogo(tStyle);
m_pSystemManageDlg->setMainTitle(tr("HMI Upgrade"));
m_pSystemManageDlg->setSubTitle(tr("Auxiliary Function > HMI Upgrade"));
m_pSystemManageDlg->initDialog();
systemUpgrade(HMI_UPDATA);
}
void MainWidgetFunction::funEXBUpgrade(QString tStyle, u8 protocol, u8 nodeid , u8 nodeType)
{
m_pSystemManageDlg->setTypeLogo(tStyle);
m_pSystemManageDlg->setMainTitle(tr("EXB Upgrade"));
m_pSystemManageDlg->setSubTitle(tr("Auxiliary Function > EXB Upgrade"));
m_pSystemManageDlg->initDialog();
systemUpgrade(EXBOARD_UPDATA, 0, protocol, nodeid, nodeType);
}
void MainWidgetFunction::funWIFI(QString tStyle)
{
QStringList wifiStrList;
wifiStrList.clear();
s16 rel = refreshWifiList(wifiStrList);//加载wifi列表
if(rel > 0)
{
m_pSystemManageDlg->setTypeLogo(tStyle);
m_pSystemManageDlg->setMainTitle(tr("WIFI"));
m_pSystemManageDlg->setSubTitle(tr("Auxiliary Function > WIFI"));
bool mode = false;//动态获取IP方式
QString iniPath = WIFIINIPATH;
QSettings setting(iniPath,QSettings::IniFormat);
QString wifiName = QByteArray::fromBase64(setting.value("WIFI/default_ssid").toByteArray());
QString wifiPass = QByteArray::fromBase64(setting.value("WIFI/default_passwd").toByteArray());
mode = setting.value("WIFI/static_mode").toBool();
QString ip = getIpSegment(mode);
if(ip.length() > 0)//已连接
{
m_pSystemManageDlg->setWifiInfo(ip,wifiName,wifiPass,mode);
m_pSystemManageDlg->initDialog(1);
for(s16 i = 0; i < wifiStrList.size(); i++)
{
m_pSystemManageDlg->addItem(wifiStrList.at(i));
}
emit siWifiState(true);
}
else//未连接
{
m_pSystemManageDlg->initDialog(1);
for(s16 i = 0; i < wifiStrList.size(); i++)
{
m_pSystemManageDlg->addItem(wifiStrList.at(i));
}
emit siWifiState(false);
}
m_pSystemManageDlg->exec();
}
}
//参数导出
void MainWidgetFunction::funExportParameter(int type)
{
QString usbPath = detectUsb();
if(usbPath.length() <= 0)
{
//优盘不存在
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("USB flash drive is not detected!");//未检测到优盘!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
if (g_pMachine != NULL)
{
if(g_pMachine->isConnected() != 3)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentStr(tr("No connection"));
m_pPromptDlg->exec();
return;
}
}
// MCInfo info1 = g_pMachine->getMcInfo();
//QString software_ver;
//software_ver.sprintf("%s",info1.softwareVerStr);
//QStringList i_sof = software_ver.split("-");//读取空格之前的版本信息
//QString i_info = i_sof[1]+"-"+ i_sof[2]; //Epara_231019_092812//之前的主控版本 列表会溢出
QString i_para = "Epara";
QString paradat;
paradat.clear();
if(type == 0)
{
paradat = ".paradat";
}
else
{
if (type == PARA_TYPE_HEADPARAMETER)
{
paradat = ".fhdparadat";
}
else if (type == PARA_TYPE_TOWELHEADPARAMETER)
{
paradat = ".thdparadat";
}
else if (type == PARA_TYPE_COILHEADPARAMETER)
{
paradat = ".chdparadat";
}
else if (type == PARA_TYPE_HCPSPARAMETER)//平绣换色板
{
paradat = ".fhsparadat";
}
else if ( type == PARA_TYPE_TOWELHCPSPARAMETER)//毛巾换色板
{
paradat = ".chsparadat";
}
}
QString i_time = QDateTime::currentDateTime().toString("_yyMMdd_hhmmss");//时间日期
//QString strName = i_para + i_info + i_time + paradat;
QString strName = i_para + i_time + paradat;
QString paraFileName = usbPath + strName;
QFile::remove (paraFileName);
#ifdef Q_OS_LINUX
system("sync");
#endif
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
if(type == 0)
{
char para_mc [ 1024 ];
char para_wk [ 1024 ];
char pre_para_mc [ 1024 ];
char pre_para_wk [ 1024 ];
memcpy(para_mc , (u8*) (&(g_pMachine->getMcPara())) , 1024 );
memcpy(para_wk , (u8*) (&(g_pMachine->getWkPara())) , 1024 );
memcpy(pre_para_mc , (u8*) (&(g_pMachine->getPreMcPara())) , 1024 );
memcpy(pre_para_wk , (u8*) (&(g_pMachine->getPreWkPara())) , 1024 );
//两个缓冲区,输出成一个参数文件
// 转换结构体 开始
ParaFile paraFileStruct ;
memset(&paraFileStruct,0,sizeof(ParaFile)) ;
paraFileStruct.s_head[0] = 'P';
paraFileStruct.s_head[1] = 'A';
paraFileStruct.s_head[2] = 'R';
paraFileStruct.s_head[3] = 'A';
paraFileStruct.s_type = 0 ;
paraFileStruct.s_len = 4096 ;
memcpy( paraFileStruct.s_para_buff , para_wk , 1024 );
memcpy( (char *) (paraFileStruct.s_para_buff) + 1024 , para_mc , 1024 );
memcpy( (char *) (paraFileStruct.s_para_buff) + 2048 , pre_para_mc , 1024 );
memcpy( (char *) (paraFileStruct.s_para_buff) + 3072 , pre_para_wk , 1024 );
paraFileStruct.s_crc = calcCrc16( (u8 * ) paraFileStruct.s_para_buff , 4096 ) ;
// 转换结构体 结束
// 保存文件 开始
QFile file(paraFileName);
bool bl = file.open(QIODevice::ReadWrite | QIODevice::Truncate);
if(bl == false)
{
//参数导出失败!
str = tr("Parameters exported failed!");//参数导出失败!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
file.close();
return;
}
bl = file.write((char*)&paraFileStruct,sizeof(ParaFile));
if(bl == false)
{
//参数导出失败!
str = tr("Parameters exported failed!");//参数导出失败!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
file.close();
return;
}
file.flush();
file.close();
}
else
{
HeadInfo headParaValues;
HcpsInfo hcpsParaValues;
QFile file(paraFileName);
bool bl = file.open(QIODevice::ReadWrite | QIODevice::Truncate);
if(bl == false)
{
//参数导出失败!
str = tr("Parameters exported failed!");//参数导出失败!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
file.close();
return;
}
if (type == PARA_TYPE_HEADPARAMETER)
{
if(g_pMachine->getHeadPara(0,FLATEMB) != NULL)
{
memcpy(&headParaValues, g_pMachine->getHeadPara(0,FLATEMB), sizeof(HeadInfo));
bl = file.write((char*)&headParaValues,sizeof(HeadInfo));
}
}
else if (type == PARA_TYPE_TOWELHEADPARAMETER)
{
if(g_pMachine->getHeadPara(0,TOWEL) != NULL)//找到的数据包不是空
{
memcpy(&headParaValues, g_pMachine->getHeadPara(0,TOWEL), sizeof(HeadInfo));
bl = file.write((char*)&headParaValues,sizeof(HeadInfo));
}
}
else if (type == PARA_TYPE_COILHEADPARAMETER)
{
if(g_pMachine->getHeadPara(0,COIL) != NULL)//找到的数据包不是空
{
memcpy(&headParaValues, g_pMachine->getHeadPara(0,COIL), sizeof(HeadInfo));
bl = file.write((char*)&headParaValues,sizeof(HeadInfo));
}
}
else if (type == PARA_TYPE_HCPSPARAMETER)//平绣换色板
{
memcpy(&hcpsParaValues, &g_pMachine->getHcpsPara(0), sizeof(HcpsInfo));
bl = file.write((char*)&hcpsParaValues,sizeof(HcpsInfo));
}
else if ( type == PARA_TYPE_TOWELHCPSPARAMETER)//毛巾换色板
{
memcpy(&hcpsParaValues, &g_pMachine->getHcpsPara(1), sizeof(HcpsInfo));
bl = file.write((char*)&hcpsParaValues,sizeof(HcpsInfo));
}
if(bl == false)
{
//参数导出失败!
str = tr("Parameters exported failed!");//参数导出失败!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
file.close();
return;
}
// 保存文件 开始
file.flush();
file.close();
}
// 保存文件 结束
#ifdef Q_OS_LINUX
system("sync");
#endif
//参数导出成功
str = tr("Parameters exported successfully!");//参数导出成功!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
//动框参数导出
void MainWidgetFunction::funExportFrameParameter()
{
QString usbPath = detectUsb();
if(usbPath.length() <= 0)
{
//优盘不存在
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("USB flash drive is not detected!");//未检测到优盘!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
MCInfo info1 = g_pMachine->getMcInfo();
QString software_ver;
software_ver.sprintf("%s",info1.softwareVerStr);
// QStringList i_sof = software_ver.split("-");
// QString i_info = i_sof[1]+"-" + i_sof[2];
QString i_para = "FrameEpara";
QString paradat = ".frameparadat";
QString i_time = QDateTime::currentDateTime().toString("_yyMMdd_hhmmss");//时间日期
// QString strName = i_para + i_info + i_time + paradat;
QString strName = i_para + i_time + paradat;
QString paraFileName = usbPath + strName;
QFile::remove (paraFileName) ;
#ifdef Q_OS_LINUX
system("sync");
#endif
char para_frame1 [ 1024 ];
//char para_frame2 [ 1024 ];
char pre_para_frame1 [ 1024 ];
// char pre_para_frame2 [ 1024 ];
memcpy(para_frame1 , (u8*) (&(g_pMachine->getFrameAnglePara())) , 1024 );
//memcpy(para_frame2 , (u8*) (&(g_pMachine->getWkPara())) , 1024 );
memcpy(pre_para_frame1 , (u8*) (&(g_pMachine->getFrameAnglePara())) , 1024 );
//memcpy(pre_para_wk , (u8*) (&(g_pMachine->getPreWkPara())) , 1024 );
//两个缓冲区,输出成一个参数文件
// 转换结构体 开始
ParaFile paraFileStruct ;
memset(&paraFileStruct,0,sizeof(ParaFile)) ;
paraFileStruct.s_head[0] = 'P';
paraFileStruct.s_head[1] = 'A';
paraFileStruct.s_head[2] = 'R';
paraFileStruct.s_head[3] = 'A';
paraFileStruct.s_type = 0 ;
paraFileStruct.s_len = 4096 ;
memcpy( paraFileStruct.s_para_buff , para_frame1 , 1024 );
//memcpy( (char *) (paraFileStruct.s_para_buff) + 1024 , para_mc , 1024 );
memcpy( (char *) (paraFileStruct.s_para_buff) + 1024 , pre_para_frame1 , 1024 );
//memcpy( (char *) (paraFileStruct.s_para_buff) + 3072 , pre_para_wk , 1024 );
paraFileStruct.s_crc = calcCrc16( (u8 * ) paraFileStruct.s_para_buff , 4096 ) ;
// 转换结构体 结束
// 保存文件 开始
QFile file(paraFileName);
file.open(QIODevice::ReadWrite | QIODevice::Truncate);
file.write((char*)&paraFileStruct,sizeof(ParaFile));
file.flush();
file.close();
// 保存文件 结束
#ifdef Q_OS_LINUX
system("sync");
#endif
//参数导出成功
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("Frame parameters exported successfully!");//动框参数导出成功!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
//全部归零
void MainWidgetFunction::funAllToZero()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("All to zero"));//全部归零
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->allToZero();
}
}
}
//产量清零(产线左下角)
void MainWidgetFunction::funResetOutput()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("All to reset"));//产量清零
QString str;
str = tr("Whether to reset the output?");//是否重置产量?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->resetOutput();
}
}
}
//流程复位
void MainWidgetFunction::funAllToReset()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("All to reset"));//流程复位
QString str;
str = tr("If all process to reset?");//是否全部流程复位?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->allToReset();
}
}
}
//平绣勾线
void MainWidgetFunction::funFlatEmbHook()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Flat embroidery hook"));//平绣勾线
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->manualAction(EMB_HOOK_THREAD);
}
}
}
//主轴点动
void MainWidgetFunction::funSpindleJog()
{
int towel = g_pSettings->readFromInHMIiFile("HMI/towel").toInt();//是否有毛巾功能
int coil = g_pSettings->readFromInHMIiFile("HMI/coil").toInt();//是否有缠绕功能
if(g_emMacType == MACHINE_EMB && (towel == 1 || coil == 1)) //-rq
{
m_pPromptDlg->initDialog(PromptDialog::BTN_NOSEHESD);
m_pPromptDlg->setTitleStr(tr("Spindle jog"));//主轴点动
m_pPromptDlg->setNoseHeadStrVisible(false);//当前针杆label是否可见
if(m_pPromptDlg->exec() == 1)
{
int noseHesdJog = m_pPromptDlg->getNoseHead();
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
QString str;
if(noseHesdJog == TOWEL)//毛巾
{
m_pPromptDlg->setTitleStr(tr("Chenille Spindle jog"));//毛巾主轴点动
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->chenilleJog();
}
}
}
else if(noseHesdJog == COIL)//缠绕
{
m_pPromptDlg->setTitleStr(tr("Winding spindle jog"));//缠绕主轴点动
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->manualAction(COIL_MS_JOG);
}
}
}
else if(noseHesdJog == FLATEMB)
{
m_pPromptDlg->setTitleStr(tr("Emb Spindle jog"));//平绣主轴点动
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->embJog();
}
}
}
slotCalMachineProgress(CSV_00_CODE_1);
}
}
else if(g_emMacType == MACHINE_EMB && g_emProductType == PRODUCT_CHEN)//纯毛巾
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Spindle jog"));//毛巾主轴点动
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->chenilleJog();
}
}
}
else
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Spindle jog"));//主轴点动
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->embJog();
}
}
}
}
//主轴旋转
void MainWidgetFunction::funSpindleRotate()
{
int towel = g_pSettings->readFromInHMIiFile("HMI/towel").toInt();//是否有毛巾功能
int coil = g_pSettings->readFromInHMIiFile("HMI/coil").toInt();//是否有缠绕功能
if(g_emMacType == MACHINE_EMB && (towel == 1 || coil == 1)) //-rq
{
m_pPromptDlg->initDialog(PromptDialog::BTN_NOSEHESDTHREE);
m_pPromptDlg->setTitleStr(tr("Spindle rotate angle"));//主轴旋转角度
if(m_pPromptDlg->exec() == 1)
{
m_noseHead = m_pPromptDlg->getNoseHead();
m_pPromptDlg->initDialog(PromptDialog::BTN_SPINDLE_ROTATE);
if(m_noseHead == TOWEL)
{
m_pPromptDlg->setTitleStr(tr("Chenille Spindle rotate angle"));//毛巾主轴旋转角度
}
else if(m_noseHead == COIL)
{
m_pPromptDlg->setTitleStr(tr("Winding Spindle rotate angle"));//缠绕主轴旋转角度
}
else if(m_noseHead == FLATEMB)
{
m_pPromptDlg->setTitleStr(tr("Emb Spindle rotate angle"));//平绣主轴旋转角度
}
m_pPromptDlg->exec();
}
}
else if(g_emMacType == MACHINE_EMB && g_emProductType == PRODUCT_CHEN)//纯毛巾
{
m_noseHead = TOWEL;
m_pPromptDlg->initDialog(PromptDialog::BTN_SPINDLE_ROTATE);
m_pPromptDlg->setTitleStr(tr("Spindle rotate angle"));//主轴旋转角度
m_pPromptDlg->exec();
}
else
{
m_noseHead = FLATEMB;
m_pPromptDlg->initDialog(PromptDialog::BTN_SPINDLE_ROTATE);
m_pPromptDlg->setTitleStr(tr("Spindle rotate angle"));//主轴旋转角度
m_pPromptDlg->exec();
}
#if(0)
if (m_pPromptDlg->exec() == 1)
{
s32 val = m_pPromptDlg->getSpindleRotateAngle();
if(g_pMachine != NULL)
{
g_pMachine->manualAction(EMB_SPINDLE_TO_ANGLE,val);
}
}
#endif
}
//回工作点
void MainWidgetFunction::funBackWorkPoint()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Back work point"));//回工作点
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->gotoWorkPos();
}
}
}
//回原点
void MainWidgetFunction::funBackToOrigin()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Back to origin"));//回原点
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->gotoZeroPos();
}
}
}
//边框检查超限后重新自动设置起绣点
void MainWidgetFunction::funResetStartPoint(QString filePath,DataFilePos pos)
{
int st = 1;
if(filePath.length() <= 0)
{
return;
}
u32 workNoseHead = 1;
s32 beginX,beginY;
beginX = beginY = 0;
beginX = pos.beginX;
beginY = pos.beginY;
if(g_pMachine != NULL)
{
workNoseHead = g_pMachine->getMcStatus().workNoseHead;
}
if(g_pCurEmbData != NULL)
{
g_pCurEmbData->setStartPosition(beginX,beginY,st,workNoseHead);
}
//边框检查后自动定起绣点总是不成功(数据发送失败),所以加了延时已临时解决
QDateTime oldTime = QDateTime::currentDateTime();
while(1)
{
QDateTime curTime = QDateTime::currentDateTime();
if(oldTime.msecsTo(curTime) > 100)
{
break;
}
}
sendPatternHead(filePath);
//将新的起始点写回到文件中
writePonitToFile(filePath,START_POINT,beginX,beginY,st,workNoseHead);
m_beginX = beginX;
m_beginY = beginY;
//流程复位
g_pMachine->allToReset();
}
//定偏移点
void MainWidgetFunction::funSetOffsetPoint()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Set offset point"));//定偏移点
QString str;
str = tr("Whether to set the current point as the offset point?");//是否将当前点设置为偏移点?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->setOffsetPos();
}
}
}
//回偏移点
void MainWidgetFunction::funBackOffsetPoint()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Back offset point"));//回偏移点
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->gotoOffsetPos();
}
}
}
//设置起始点
void MainWidgetFunction::funSetStartPoint(QString filePath)
{
int st = 1;
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Set start point"));//定起始点
QString str;
str = tr("Whether to set the current point as the start point?");//是否将当前点设置为起始点?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
s32 x,y;
u32 workNoseHead;
x = y = 0;
workNoseHead =0;
if(g_pMachine != NULL)
{
m_mcStatus = g_pMachine->getMcStatus();
x = m_mcStatus.xPos;
y = m_mcStatus.yPos;
workNoseHead = m_mcStatus.workNoseHead;
}
if(g_pCurEmbData != NULL)
{
g_pCurEmbData->setStartPosition(x,y,st,workNoseHead);
}
sendPatternHead(filePath);
//将新的起始点写回到文件中
writePonitToFile(filePath,START_POINT,x,y,st,workNoseHead);
m_beginX = x;
m_beginY = y;
//流程复位
g_pMachine->allToReset();
}
}
//回起始点
void MainWidgetFunction::funBackStartPoint()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Back embroidery poin"));//回起始点
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->gotoStartPos();
}
}
}
//边框检查
void MainWidgetFunction::funBorderCheck()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Border check"));//边框检查
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if((m_mcStatus.workStatus & WORK_STA_BUSY) != 0) // 下位机在执行动作
{
return;
}
g_pMachine->checkFrame(); // 发给下位机,边框检查
slotCalMachineProgress(CSV_00_CODE_4);
}
}
//切换工作状态
void MainWidgetFunction::funWorkState()
{
if(g_emMacType == MACHINE_EMB)
{
if(g_pMachine != NULL)
{
if ((m_mcStatus.workStatus & WORK_STA_SIMULATE) == WORK_STA_SIMULATE) //模拟工作
{
//正常工作
g_pMachine->setNormalWork();
}
else //正常工作
{
//模拟工作
g_pMachine->setSimulateWork();
}
}
}
else if(g_emMacType == QUIMACHINE_EMB)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Switching working status"));//切换工作状态
QString str;
str = tr("Do you want to switch the simulation working state?");//是否切换模拟工作状态?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
if ((m_mcStatus.workStatus & WORK_STA_SIMULATE) == WORK_STA_SIMULATE) //模拟工作
{
//正常工作
g_pMachine->setNormalWork();
}
else //正常工作
{
//模拟工作
g_pMachine->setSimulateWork();
}
}
}
}
}
//手动剪线(平绣,毛巾剪线)
void MainWidgetFunction::funManualTrim()
{
int towel = g_pSettings->readFromInHMIiFile("HMI/towel").toInt();//是否有毛巾功能
int coil = g_pSettings->readFromInHMIiFile("HMI/coil").toInt();//是否有缠绕功能
if(g_emMacType == MACHINE_EMB && (towel == 1 || coil == 1)) //-rq
{
m_pPromptDlg->initDialog(PromptDialog::BTN_NOSEHESD);
m_pPromptDlg->setTitleStr(tr("Trim"));//剪线
m_pPromptDlg->setNoseHeadStrVisible(false);//当前针杆label是否可见
if(m_pPromptDlg->exec() == 1)
{
int noseHesdTrim = m_pPromptDlg->getNoseHead();
if(noseHesdTrim == TOWEL)//毛巾
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Chenille trim"));//毛巾剪线
QString str;
str = tr("The machine is about to cut the thread, please pay attention to safety!");//机器即将剪线,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->chenilleCutThread();
}
}
}
else if(noseHesdTrim == COIL)//缠绕
{
funCoilManualTrim();
}
else if(noseHesdTrim == FLATEMB)//平绣
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Emboriey trim"));//平绣剪线
QString str;
str = tr("The machine is about to cut the thread, please pay attention to safety!");//机器即将剪线,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->embCutThread();
}
}
}
}
}
else if(g_emMacType == MACHINE_EMB && g_emProductType == PRODUCT_CHEN)//纯毛巾
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Trim"));//毛巾剪线
QString str;
str = tr("The machine is about to cut the thread, please pay attention to safety!");//机器即将剪线,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->chenilleCutThread();
}
}
}
else
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Emboriey trim"));//平绣剪线
QString str;
str = tr("The machine is about to cut the thread, please pay attention to safety!");//机器即将剪线,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->embCutThread();
}
}
}
}
//毛巾剪线 (单独的一个快捷功能,黄色的按钮)//目前没用到
void MainWidgetFunction::funTowelTrim()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Chenille trim"));//毛巾剪线
QString str;
str = tr("The machine is about to cut the thread, please pay attention to safety!");//机器即将剪线,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->chenilleCutThread();
}
}
}
//切换机头(毛巾,平绣)
void MainWidgetFunction::funSwitchHead()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_NOSEHESD);
m_pPromptDlg->setTitleStr(tr("Switch Head"));//切换机头
m_pPromptDlg->setNoseHeadStrVisible(false);//当前针杆label是否可见
if(m_pPromptDlg->exec() == 1)
{
int noseHesdSwitch = m_pPromptDlg->getNoseHead();
if(noseHesdSwitch == TOWEL)//毛巾
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Switch Head"));//切换机头
QString str;
str = tr("Whether to switch to chenille head!");//是否切换为毛巾机头!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->headSwitch(5);
}
}
}
else if(noseHesdSwitch == FLATEMB)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Switch Head"));//切换机头
QString str;
str = tr("Whether to switch to emb head!");//是否切换为平绣机头!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->headSwitch(1);
}
}
}
//缠绕
else if(noseHesdSwitch == COIL)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Switch Head"));//切换机头
QString str;
str = tr("Whether to switch to coil head!");//是否切换为缠绕机头!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->headSwitch(4);
}
}
}
}
}
void MainWidgetFunction::funMSpindleRotate()
{
int towel = g_pSettings->readFromInHMIiFile("HMI/towel").toInt();//是否有毛巾功能
int coil = g_pSettings->readFromInHMIiFile("HMI/coil").toInt();//是否有缠绕功能
if(g_emMacType == MACHINE_EMB && towel == 1 && coil == 1) //-rq
{
m_pPromptDlg->initDialog(PromptDialog::BTN_MSPINDLE_ROTATE);
m_pPromptDlg->setTitleStr(tr("M axis rotation angle"));//M轴旋转角度
if(m_pPromptDlg->exec() == 1)
{
m_noseHead = m_pPromptDlg->getNoseHead();
m_pPromptDlg->initDialog(PromptDialog::BTN_SPINDLE_ROTATE);
if(m_noseHead == TOWELM)
{
m_pPromptDlg->setTitleStr(tr("Chenille M axis rotate angle"));//毛巾M轴旋转角度
}
else if(m_noseHead == COILM)
{
m_pPromptDlg->setTitleStr(tr("Winding M axis rotate angle"));//缠绕M轴旋转角度
}
m_pPromptDlg->exec();
}
}
else if(g_emMacType == MACHINE_EMB && towel == 1)
{
m_noseHead = TOWELM;
m_pPromptDlg->initDialog(PromptDialog::BTN_SPINDLE_ROTATE);
m_pPromptDlg->setTitleStr(tr("Chenille M axis rotate angle"));//毛巾M轴旋转角度
m_pPromptDlg->exec();
}
else if(g_emMacType == MACHINE_EMB && coil == 1)
{
m_noseHead = COILM;
m_pPromptDlg->initDialog(PromptDialog::BTN_SPINDLE_ROTATE);
m_pPromptDlg->setTitleStr(tr("Winding M axis rotate angle"));//缠绕M轴旋转角度
m_pPromptDlg->exec();
}
}
//毛巾设置可工作区域
void MainWidgetFunction::funChenWorkArea()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_WORK_AREA);
m_pPromptDlg->setTitleStr(tr("Chenille setting workable area"));//毛巾设置可工作区域
int areaValue = m_pPromptDlg->getArea();
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->manualAction(EMB_CUT_ONOFF,TOWEL,areaValue);
}
}
}
//平绣设置可工作区域
void MainWidgetFunction::funEmbWorkArea()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_WORK_AREA);
m_pPromptDlg->setTitleStr(tr("Flat embroidery setting workable area"));//平绣设置可工作区域
int areaValue = m_pPromptDlg->getArea();
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->manualAction(EMB_CUT_ONOFF,FLATEMB,areaValue);
}
}
}
//剪刀开合
void MainWidgetFunction::funCutterOpenAndClose()
{
int coil = g_pSettings->readFromInHMIiFile("HMI/coil").toInt();//是否有缠绕功能
if(g_emMacType == MACHINE_EMB && coil == 1)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_TRIMDOWN);
m_pPromptDlg->setTitleStr(tr("Lower cutter"));//下剪线
m_pPromptDlg->setNoseHeadStrVisible(false);//当前针杆label是否可见
if(m_pPromptDlg->exec() == 1)
{
int noseHesdColor = m_pPromptDlg->getNoseHead();
if(noseHesdColor == COIL)//缠绕
{
funCoilCutterOpenAndClose();
}
else if (noseHesdColor == FLATEMB)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Emb Lower cutter"));//平绣下剪线
QString str;
str = tr("Emb scissors are about to move, please pay attention to safety!");//平绣剪刀即将动作,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->manualAction(EMB_CUT_ONOFF);
}
}
}
}
}
else
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Lower cutter"));//下剪线
QString str;
str = tr("The scissors are about to move, please pay attention to safety!");//剪刀即将动作,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->manualAction(EMB_CUT_ONOFF);
}
}
}
}
//手动换色
void MainWidgetFunction::funManualChangeColor()
{
if(m_camColorChange == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->testADC(1);
m_adcFlag = 1;
//测试电位器的标志
}
}
int towel = g_pSettings->readFromInHMIiFile("HMI/towel").toInt();//是否有毛巾功能
if(g_emMacType == MACHINE_EMB && towel == 1)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_NOSEHESD);
m_pPromptDlg->setTitleStr(tr("Manual color change"));//手动换色
m_pPromptDlg->setNoseHeadStrVisible(false);//当前工作机头label是否可见
if(m_pPromptDlg->exec() == 1)
{
int noseHesdColor = m_pPromptDlg->getNoseHead();
if(noseHesdColor == TOWEL)//毛巾
{
m_pPromptDlg->initDialog(PromptDialog::BTN_M_C_C);
m_pPromptDlg->setTitleStr(tr("Chenille color change"));
m_pPromptDlg->setCurNeedleStrVisible(true);//当前针杆label是否可见
// m_pPromptDlg->setCurNeedleStr(value);//显示当前针杆
m_pPromptDlg->initNeedleBar(PRODUCT_TOWEL);
if (m_pPromptDlg->exec() == 1)
{
s32 val = m_pPromptDlg->getNeedleSelectIdx();//获取所选针杆的索引值
if(g_pMachine != NULL)
{
g_pMachine->chenilleSwitchNeedle(val);// 毛巾换色
}
}
}
else
{
m_pPromptDlg->initDialog(PromptDialog::BTN_M_C_C);
m_pPromptDlg->setTitleStr(tr("Emb color change"));
m_pPromptDlg->setCurNeedleStrVisible(true);//当前针杆label是否可见
//m_pPromptDlg->setCurNeedleStr(value);//显示当前针杆
m_pPromptDlg->initNeedleBar(PRODUCT_EMB);
if (m_pPromptDlg->exec() == 1)
{
s32 val = m_pPromptDlg->getNeedleSelectIdx();//获取所选针杆的索引值
if(g_pMachine != NULL)
{
g_pMachine->embSwitchNeedle(val);// 平绣换色
}
}
}
}
}
else if(g_emMacType == MACHINE_EMB && g_emProductType == PRODUCT_CHEN)//纯毛巾
{
m_pPromptDlg->initDialog(PromptDialog::BTN_M_C_C);
m_pPromptDlg->setTitleStr(tr("Color change"));
m_pPromptDlg->setCurNeedleStrVisible(true);//当前针杆label是否可见
// m_pPromptDlg->setCurNeedleStr(value);//显示当前针杆
m_pPromptDlg->initNeedleBar(PRODUCT_TOWEL);
if (m_pPromptDlg->exec() == 1)
{
s32 val = m_pPromptDlg->getNeedleSelectIdx();//获取所选针杆的索引值
if(g_pMachine != NULL)
{
g_pMachine->chenilleSwitchNeedle(val);// 毛巾换色
}
}
}
else
{
m_pPromptDlg->initDialog(PromptDialog::BTN_M_C_C);
m_pPromptDlg->setTitleStr(tr("Manual change color"));
m_pPromptDlg->setCurNeedleStrVisible(true);//当前针杆label是否可见
//m_pPromptDlg->setCurNeedleStr(value);//显示当前针杆
m_pPromptDlg->initNeedleBar(PRODUCT_EMB);
if (m_pPromptDlg->exec() == 1)
{
s32 val = m_pPromptDlg->getNeedleSelectIdx();//获取所选针杆的索引值
if(g_pMachine != NULL)
{
g_pMachine->embSwitchNeedle(val);// 平绣换色
}
}
}
slotCalMachineProgress(CSV_00_CODE_5);
if (m_adcFlag == 1)//弹窗界面显示,点击了取消按钮,弹窗关闭
{
if(g_pMachine != NULL)
{
g_pMachine->testADC(0);//点击关闭按钮发退出测试电位器命令para2=0
m_adcFlag = -1;
}
}
}
//毛巾换色 -rq (单独的一个快捷功能,黄色的按钮)//目前没用到
void MainWidgetFunction::funTowelChangeColor()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_M_C_C);
m_pPromptDlg->setTitleStr(tr("Towel color change"));
m_pPromptDlg->setCurNeedleStrVisible(false);//当前针杆label是否可见
m_pPromptDlg->initNeedleBar(PRODUCT_TOWEL);
if (m_pPromptDlg->exec() == 1)
{
s32 val = m_pPromptDlg->getNeedleSelectIdx();//获取所选针杆的索引值
if(g_pMachine != NULL)
{
g_pMachine->chenilleSwitchNeedle(val);// 毛巾换色
}
}
}
//线迹偏移
void MainWidgetFunction::funTraceOffset()
{
if(g_pMachine == NULL)
{
return;
}
m_pPromptDlg->initDialog(PromptDialog::BTN_LINE_OFFSET);
m_pPromptDlg->setTitleStr(tr("Trace offset"));//线迹偏移
if(m_pPromptDlg->exec() == 1)
{
s16 val = m_pPromptDlg->getTraceOffsetType();
if (val == 1)//线迹偏移
{
g_pMachine->traceOffset();
}
else if (val == 2)//线迹偏移数据复位
{
g_pMachine->resetTraceOffset();
}
else if (val == 3)//清除当前索引的线迹偏移数据
{
g_pMachine->clearCurTraceOffset();
}
}
}
//绗绣机 工作暂停功能
void MainWidgetFunction::funWorkPause()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Work Pause"));//工作暂停
QString str;
str = tr("Work Pause, please pay attention to safety!");//工作暂停,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->pauseWork();
}
}
}
//缠绕剪刀开合
void MainWidgetFunction::funCoilCutterOpenAndClose()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Winding and cut the thread"));//缠绕下剪线
QString str;
str = tr("Winding scissors are about to move, please pay attention to safety!");//缠绕剪刀即将动作,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->manualAction(COIL_CUT_ONOFF);
}
}
}
void MainWidgetFunction::funCoilManualTrim()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Coil Trim"));//缠绕剪线
QString str;
str = tr("The scissors are about to move, please pay attention to safety!");//剪刀即将动作,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->manualAction(COIL_CUT_THREAD);
}
}
}
void MainWidgetFunction::funCoilSpindleJog()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Coil Spindle jog"));//缠绕主轴点动
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->manualAction(COIL_MS_JOG);
}
}
}
//缠绕主轴旋转
void MainWidgetFunction::funCoilSpindleRotate()
{
m_noseHead = COIL;
m_pPromptDlg->initDialog(PromptDialog::BTN_SPINDLE_ROTATE);
m_pPromptDlg->setTitleStr(tr("Coil Spindle rotate angle"));//旋转角度
m_pPromptDlg->exec();
}
//缠绕M轴旋转
void MainWidgetFunction::funCoilMSpindleRotate()
{
m_noseHead = COILM;
m_pPromptDlg->initDialog(PromptDialog::BTN_SPINDLE_ROTATE);
m_pPromptDlg->setTitleStr(tr("Coil M Spindle rotate angle"));//旋转角度
m_pPromptDlg->exec();
}
//亮片换色sq 0代表左亮片1代表右亮片
void MainWidgetFunction::funSequinChangeColor(s16 sq)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_M_C_C);
QString str = tr("Left sequin change color");//左亮片换色
if(sq == 1)
{
str = tr("Right sequin change color");//右亮片换色
}
m_pPromptDlg->setTitleStr(str);
m_pPromptDlg->setCurNeedleStrVisible(false);
#if(0)
int sequinNum = 0;
if(g_pMachine != NULL)
{
ParaStruct mcParaValues;
mcParaValues = g_pMachine->getMcPara();
if(sq == 0)
{
sequinNum = 8;
//sequinNum = mcParaValues.buf[48];//左亮片规格
}
else if(sq == 1)
{
sequinNum = 8;
//sequinNum = mcParaValues.buf[49];//右亮片规格
}
//sequinNum = 10;//亮片规格
}
#endif
//亮片换色界面现在是固定的8个针杆改成和针杆设置中设置的亮片针杆 -rq
m_pPromptDlg->initNeedleBar(RODUCT_SEQUIN);
// m_pPromptDlg->initSequinNeedleBar(sequinNum);//亮片默认就是8个针杆
if (m_pPromptDlg->exec() == 1)
{
s32 val = m_pPromptDlg->getNeedleSelectIdx();//获取所选针杆的索引值
if(g_pMachine != NULL)
{
g_pMachine->sequinSwitchNeedle(val,sq);
}
}
}
//定量移框
void MainWidgetFunction::funQuantityMoveFrame()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_MOVE_FRAME);
m_pPromptDlg->setTitleStr(tr("Quantity move frame"));//定量移框
if (m_pPromptDlg->exec() == 1)
{
s32 x = m_pPromptDlg->getMoveX();
s32 y = m_pPromptDlg->getMoveY();
if(g_pMachine != NULL)
{
g_pMachine->quantityMoveFrame(x,y);
}
}
}
//针杆定位
void MainWidgetFunction::funNeedleRodPosition()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Needle rod position"));//针杆定位
QString str;
str = tr("The needle pole is about to drop, please pay attention to safety!");//针杆即将下降,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->manualAction(EMB_NEEDLE_POS);
}
}
}
//空走边框
void MainWidgetFunction::funSimulateFrame()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Simulate frame"));//空走边框
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if((m_mcStatus.workStatus & WORK_STA_BUSY) != 0) // 下位机在执行动作
{
return;
}
g_pMachine->simulateFrame(); // 发给下位机,空走边框
}
}
//流程复位
void MainWidgetFunction::funProcessReset()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Process reset"));//流程复位
QString str;
str = tr("The machine is about to reset, please pay attention to safety!");//机器即将流程复位,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->allToReset();
}
}
}
//定上料点 -rq
void MainWidgetFunction::funSetFeedPoint()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("set feeding point"));//定上料点
QString str;
str = tr("Whether to set the current point as the feeding point?");//是否将当前点设置为上料点?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->setFeedPos();
}
}
}
//回上料点
void MainWidgetFunction::funBackFeedPoint()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Back feed point"));//回上料点
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->gotoFeedPos();
}
}
}
//手动加油
void MainWidgetFunction::funManualOil()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Manual oil"));//手动加油
QString str;
str = tr("The machine is about to oil!");//机器即将加油!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->manualOil(1);
}
slotCalMachineProgress(CSV_00_CODE_6);
}
}
//重置反复次数
void MainWidgetFunction::funResetRepeatNum()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Reset Repeat Num"));//重置反复次数
QString str;
str = tr("Reset Repeat Num!");//重置反复次数!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->resetRepeatNum();
}
}
}
//梭盘计数复位
void MainWidgetFunction::funShuttleChange()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Shuttle count reset"));//梭盘计数复位
QString str;
str = tr("The machine is about to change the shuttle automatically!");//机器即将自动换梭!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->shuttleCounter();
}
}
}
//框架归零
void MainWidgetFunction::funGotoZeroPos()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Goto zero pos"));//框架归零
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->gotoZeroPos();
}
}
}
//定工作范围
void MainWidgetFunction::funSetWorkRange()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Set work range"));//定工作范围
QString str;
str = tr("If automatically set work range?");//是否自动定工作范围?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->setWorkRange();
}
}
}
void MainWidgetFunction::sendPatternHead(QString filePath)
{
int fileMode = g_pSettings->readFromInHMIiFile("HMI/fileMode").toInt();
if(fileMode == DATA_DS16)//ds16
{
//获取文件头并重新发送文件头
DataDs16FileHead *pDs16Head = g_pCurEmbData->getDsDatHead();
g_pMachine->setFilePara(0, m_curFileID, (DataFilePara&)*pDs16Head);
}
else if(fileMode == DATA_DS8)//ds8
{
QString ds8FilePath = filePath + ".ds8";
QFile file(ds8FilePath);
if(file.exists())//存在ds8文件
{
if(!file.open(QIODevice::ReadOnly))
{
qDebug() << "open file fail when read";
return;
}
QByteArray ary = file.readAll();
DataDs16FileHead *pDs8Head = (DataDs16FileHead *)(ary.data());
DataDs16FileHead *pDs16Head = g_pCurEmbData->getDsDatHead();
pDs8Head->anchorX = pDs16Head->anchorX;
pDs8Head->anchorY = pDs16Head->anchorY;
pDs8Head->beginX = pDs16Head->beginX;
pDs8Head->beginY = pDs16Head->beginY;
pDs8Head->beginR = pDs16Head->beginR;
//pDs8Head->combineMode = pDs16Head->combineMode;
pDs8Head->maxX = pDs16Head->maxX;
pDs8Head->maxY = pDs16Head->maxY;
pDs8Head->minX = pDs16Head->minX;
pDs8Head->minY = pDs16Head->minY;
memcpy(pDs8Head->switchTable,pDs16Head->switchTable,sizeof(pDs8Head->switchTable));
g_pMachine->setFilePara(0, m_curFileID, (DataFilePara&)*pDs8Head);
file.close();
}
else
{
QByteArray ds16dat = g_pCurEmbData->getDsDat();//获得ds16数据
QByteArray ds8dat;
ds8dat.clear();
// ds16数据
int size = ds16dat.size();
if (size <= (int)sizeof(DataDs16FileHead))
{
qDebug("data less then head size");
return;
}
DataDs16FileHead * pDs16Head = (DataDs16FileHead *)(ds16dat.data());
ds8dat.append((char*)pDs16Head,sizeof(DataDs16FileHead));
int datasize = size - sizeof(DataDs16FileHead);
if (datasize <= 0)
{
qDebug("ds16 dataBegin err");
return;
}
int stepsize = datasize/sizeof(Ds16Item);
if (stepsize <= 0)
{
qDebug("ds16 data size err");
return;
}
Ds16Item *pData = (Ds16Item *)(ds16dat.data() + sizeof(DataDs16FileHead));
Ds16Item * dataPtr = pData;
u8 ctrl,attr;
s16 dx,dy,dr;
Ds8Item ds8Item;
for (int i = 0; i < stepsize; i++)
{
ctrl = dataPtr->ctrl;
attr = dataPtr->attr;
dx = dataPtr->dx;
dy = dataPtr->dy;
dr = dataPtr->dr;
ds8Item.ctrl = ctrl;
ds8Item.attr = attr;
ds8Item.dx = dx;
ds8Item.dy = dy;
ds8Item.dr = dr;
ds8dat.append((char*)&ds8Item,sizeof(Ds8Item));
dataPtr++;
}
//发送ds8数据
DataDs16FileHead * pDs8Head = (DataDs16FileHead *)(ds8dat.data());
Ds8Item *tData = (Ds8Item *)(ds8dat.data() + sizeof(DataDs16FileHead));
//重新生成文件头
pDs8Head->dataSize = pDs8Head->itemNums*sizeof(Ds8Item); // 数据字节数
pDs8Head->bytesPerItem = sizeof(Ds8Item); // 每项占的字节数
pDs8Head->dataChecksum = calcCheckSum32((u8 *)(tData) , pDs8Head->dataSize);; // 数据累加校验和
pDs8Head->checkCrc = calcCrc16((u8 *)(pDs8Head), HEAD_FIX_INFO_LEN); // 前面6个字段的CRC校验6个字段分别为文件名称字节数项个数每项字节数每块字节数数据累加和的CRC校验值
g_pMachine->setFilePara(0, m_curFileID, (DataFilePara&)*pDs8Head);
}
}
}
void MainWidgetFunction::sendPatternPatchHeadData(QString filePath,int type)
{
//发送隔头机头设置
u8 headBuf[HEADBUF];
memset(headBuf,0,sizeof(headBuf));
QFile file(filePath + ".fcg");
if(file.exists())//存在fcg文件
{
if(file.open(QIODevice::ReadOnly))
{
QByteArray ary = file.readAll();
int totalSize = sizeof(DataFileHead)+HEADBUF;
if(ary.size() >= totalSize)
{
memcpy(headBuf,ary.data()+sizeof(DataFileHead),sizeof(headBuf));
}
}
file.close();
}
if(type == FILE_TYPE_FRAME)//边框刺绣时隔头绣数据清空
{
memset(headBuf,0,sizeof(headBuf));
}
//发送buf给下位机包总共8192因为每次只能发1024所以分8次发下去
if(g_pMachine != NULL)
{
for(u16 i = 0; i < sizeof(headBuf)/MAX_EXDP_LEN; i++)
{
g_pMachine->setHeadPara((ParaStruct*)(headBuf+i*MAX_EXDP_LEN),i);
}
}
//发送贴布绣参数设置
u16 patchColorBuf[PATCHCOLORBUF];
memset(patchColorBuf,0,sizeof(patchColorBuf));
NeedlePatch patchNeedleBuf[PATCHNEEDLEBUF];
memset(patchNeedleBuf,0,sizeof(patchNeedleBuf));
if(file.exists())//存在fcg文件
{
if(file.open(QIODevice::ReadOnly))
{
QByteArray ary = file.readAll();
int totalSize = sizeof(DataFileHead)+HEADBUF+PATCHCOLORBUF*sizeof(u16);
if(ary.size() >= totalSize)
{
memcpy(patchColorBuf,ary.data()+sizeof(DataFileHead)+HEADBUF,sizeof(patchColorBuf));
}
totalSize = sizeof(DataFileHead)+HEADBUF+PATCHCOLORBUF*sizeof(u16)+PATCHNEEDLEBUF*sizeof(NeedlePatch);
if(ary.size() >= totalSize)
{
memcpy(patchNeedleBuf,ary.data()+sizeof(DataFileHead)+HEADBUF+PATCHCOLORBUF*sizeof(u16),sizeof(patchNeedleBuf));
}
}
file.close();
}
if(type == FILE_TYPE_FRAME)//边框刺绣时隔头绣数据清空
{
memset(patchColorBuf,0,sizeof(patchColorBuf));
memset(patchNeedleBuf,0,sizeof(patchNeedleBuf));
}
//发送buf给下位机
if(g_pMachine != NULL)
{
g_pMachine->setPatchColorPara((ParaStruct*)(patchColorBuf));
g_pMachine->setPatchNeedlePara((ParaStruct*)(patchNeedleBuf));
}
}
void MainWidgetFunction::sendPatternTowelHeightData(QString filePath)
{
u8 dataBuf[TOWELHIGHBUF];
memset(dataBuf,0,sizeof(dataBuf));
QFile file(filePath + ".fcg");
if(file.exists())//存在fcg文件
{
if(file.open(QIODevice::ReadOnly))
{
QByteArray ary = file.readAll();
int totalSize = sizeof(DataFileHead)+HEADBUF+PATCHCOLORBUF*sizeof(u16)+PATCHNEEDLEBUF*sizeof(NeedlePatch)+TOWELHIGHBUF;
if(ary.size() >= totalSize)
{
int size = sizeof(DataFileHead)+HEADBUF+PATCHCOLORBUF*sizeof(u16)+PATCHNEEDLEBUF*sizeof(NeedlePatch);
memcpy(dataBuf,ary.data()+size,sizeof(dataBuf));
}
}
file.close();
}
//发送buf给下位机总共1024个字节
if(g_pMachine != NULL)
{
g_pMachine->setTowelHeightPara((ParaStruct*)(dataBuf));
}
}
//选择花样后发送数据并显示大图
void MainWidgetFunction::sendPatternData(QString filePath,int type)
{
m_filePath = filePath;
sendPatternPatchHeadData(filePath,type);
int towel = g_pSettings->readFromInHMIiFile("HMI/towel").toInt();//是否有毛巾功能
if(towel == 1)//有毛巾功能
{
sendPatternTowelHeightData(filePath);
}
//保存最后一次绣作的花样路径到配置文件中
if(g_pSettings != NULL)
{
g_pSettings->writeToInHMIiFile("Pattern/name",filePath);
}
int fileMode = g_pSettings->readFromInHMIiFile("HMI/fileMode").toInt();
if(fileMode == DATA_DS16)
{
sendDs16PatternData(type);//发送ds16数据
}
else if(fileMode == DATA_DS8)
{
convertDs16ToDs8AndSend(filePath,type);//将ds16数据转换为ds8数据并发送
}
}
void MainWidgetFunction::funBottomDetect(int headType)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_BOTTOM);
m_pPromptDlg->setHeadType(headType);
m_pPromptDlg->setTitleStr(tr("Bottom line detection"));
//m_pPromptDlg->setCurNeedleStr(value);//显示当前针杆
//m_pPromptDlg->setCurNeedleStrVisible(true);//当前针杆label是否可见
if(headType == FLATEMB)
{
m_pPromptDlg->initNeedleBar(PRODUCT_EMB);
m_pPromptDlg->setCurNeedleStrVisible(true);//当前针杆label是否可见
}
else if(headType == COIL)
{
m_pPromptDlg->initNeedleBar(PRODUCT_COIL);
m_pPromptDlg->setCurNeedleStrVisible(false);//当前针杆label是否可见
}
m_pPromptDlg->exec();
}
void MainWidgetFunction::funFaceDetect(int headType)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_FACE);
m_pPromptDlg->setHeadType(headType);
m_pPromptDlg->setTitleStr(tr("Face line detection"));
//m_pPromptDlg->setCurNeedleStr(value);
if(headType == FLATEMB)
{
m_pPromptDlg->initNeedleBar(PRODUCT_EMB);
m_pPromptDlg->setCurNeedleStrVisible(true);//当前针杆label是否可见
}
else if(headType == COIL)
{
m_pPromptDlg->initNeedleBar(PRODUCT_COIL);
m_pPromptDlg->setCurNeedleStrVisible(false);//当前针杆label是否可见
}
m_pPromptDlg->exec();
}
void MainWidgetFunction::funExitRoot()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
g_emUser = operate;
m_pPromptDlg->setContentStr(tr("Exit successfully!"));//成功退出!
m_pPromptDlg->exec();
}
void MainWidgetFunction::funGetMCVersionInfo()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("System info"));
m_pPromptDlg->setContentInfoShow();
m_pPromptDlg->exec();
}
//内缝被 老化测试 功能
void MainWidgetFunction::funAgingTest()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);//有确定和取消按钮
m_pPromptDlg->setTitleStr(tr("Aging test"));//老化测试
QString str;
if(g_pMachine != NULL)
{
//老化测试 m_mcStatus 读的是第一个主板
if ((m_mcStatus.workStatus & WORK_STA_SIMULATE) == WORK_STA_SIMULATE) //模拟工作
{
str = tr("Whether to turn off the aging test?");//是否关闭老化测试?
}
else
{
str = tr("Whether to carry out aging test?");//是否进行老化测试?
}
}
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)//第一个主板的g_pMachine指针 //指针必须不为空才能去调用
{ //每次只判断第一个主板的机器状态
if ((m_mcStatus.workStatus & WORK_STA_SIMULATE) == WORK_STA_SIMULATE) //模拟工作
{
//正常工作
if(g_pMachine != NULL)
{
g_pMachine->setNormalWork();
}
}
else //正常工作
{
//模拟工作
if(g_pMachine != NULL)
{
g_pMachine->setSimulateWork();
}
}
}
}
}
void MainWidgetFunction::funGetEXBVersionInfo(QString tStyle)
{
m_pSystemManageDlg->setTypeLogo(tStyle);
m_pSystemManageDlg->setMainTitle(tr("EXB system info"));
m_pSystemManageDlg->setSubTitle(tr("Auxiliary Function > EXB system info"));
m_pSystemManageDlg->initDialog();
m_pSystemManageDlg->exec(-1);
}
void MainWidgetFunction::funProductStatistics(QString tStyle,QString filePath,int patternBreakLineNum)
{
m_pSystemManageDlg->setTypeLogo(tStyle);
m_pSystemManageDlg->setMainTitle(tr("Production statistics"));//生产统计
m_pSystemManageDlg->setSubTitle(tr("Auxiliary Function > Production statistics"));//辅助功能 > 生产统计
m_pSystemManageDlg->initDialog();
m_filePath = filePath;
QFileInfo file(m_filePath);
QString fileName = file.fileName();
m_fileName = fileName;
addProductStatisInfo(patternBreakLineNum);
m_pSystemManageDlg->exec(PRODUCTSTATIS);
}
//错误日志
void MainWidgetFunction::slotJournalError()
{
//m_pSystemManageDlg->setTypeLogo(tStyle);
m_pSystemManageDlg->setMainTitle(tr("Error Log"));//错误日志
m_pSystemManageDlg->setSubTitle(tr("Auxiliary Function > Error Log"));//辅助功能 > 错误日志
m_pSystemManageDlg->initDialog();
addJournalInfoError();
//m_pSystemManageDlg->exec(JOURNALERROR);//显示窗体
}
//断线日志
void MainWidgetFunction::slotJournalBreakage()
{
//m_pSystemManageDlg->setTypeLogo(tStyle);
m_pSystemManageDlg->setMainTitle(tr("Breakage Log"));//断线日志
m_pSystemManageDlg->setSubTitle(tr("Auxiliary Function > Breakage Log"));//辅助功能 > 断线日志
m_pSystemManageDlg->initDialog();
addJournalInfoBreakage();
//m_pSystemManageDlg->exec(JOURNALBREAKAGE);//显示窗体
}
//调试信息
void MainWidgetFunction::slotCsvChangeDebug()
{
//m_pSystemManageDlg->setTypeLogo(tStyle);
m_pSystemManageDlg->setMainTitle(tr("Debug Info"));//调试信息
m_pSystemManageDlg->setSubTitle(tr("Auxiliary Function >Debug Info"));//辅助功能 > 调试信息
m_pSystemManageDlg->initDialog();
addJournalInfoDebug();
//m_pSystemManageDlg->exec(JOURNALBREAKAGE);//显示窗体
}
void MainWidgetFunction::slotCounterPrompt(s16 flag)
{
QString str;
if(flag == 0)
{
str = tr("Generating pattern profile file...");//正在生成花样轮廓文件...
m_pPromptDlg->initDialog(PromptDialog::BTN_NONE);
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->show();
QCoreApplication::processEvents(QEventLoop::AllEvents);
}
else
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
str = tr("The pattern contour file has been generated!");//花样轮廓文件已生成!
m_pPromptDlg->setContentStr(str);
}
}
//错误日志
void MainWidgetFunction::funJournalError(QString tStyle)
{
m_pSystemManageDlg->setTypeLogo(tStyle);
m_pSystemManageDlg->setMainTitle(tr("ErrorLog"));//错误日志
m_pSystemManageDlg->setSubTitle(tr("Auxiliary Function > ErrorLog"));//辅助功能 > 错误日志
m_pSystemManageDlg->initDialog();
addJournalInfoError();
m_pSystemManageDlg->exec(JOURNAL);//显示窗体
}
//调试信息
void MainWidgetFunction::funDebugInfo()
{
m_pDebugInfoDlg->initDialog();
m_pDebugInfoDlg->addListInfo();
m_pDebugInfoDlg->exec();//显示窗体
}
void MainWidgetFunction::funSoftwareAuthor()
{
if (g_pMachine != NULL)
{
if(g_pMachine->isConnected() == 3)
{
g_pMachine->getInfoFromMachine();
}
else
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentStr(tr("No connection"));
m_pPromptDlg->exec();
return;
}
}
// 设置板卡ID值的显示
m_pPromptDlg->initDialog(PromptDialog::BTN_WARRANT);
m_pPromptDlg->setTitleStr(tr("Warrant"));
m_pPromptDlg->setContentWarrantShow();
m_pPromptDlg->exec();
}
void MainWidgetFunction::funHeadEmb(QString filePath)
{
int headNum = 0;
if(g_pMachine != NULL)
{
ParaStruct mcParaValues;
mcParaValues = g_pMachine->getMcPara();
headNum = mcParaValues.buf[2];//机头个数
//qDebug()<<"headNum"<<headNum;
//headNum =30;//机头个数
}
int colorOrderNum = g_pCurEmbData->getColorNums();//总颜色数
m_pPromptDlg->initDialog(PromptDialog::BTN_HEAD_EMB);
m_pPromptDlg->setTitleStr(tr("Head embroidery"));
m_pPromptDlg->initEmbHead(headNum,colorOrderNum,filePath);
if (m_pPromptDlg->exec() == 1)
{
u8 headBuf[HEADBUF];
memset(headBuf,0,sizeof(headBuf));
memcpy(headBuf,m_pPromptDlg->getHeadBuf(),sizeof(headBuf));
//保存buf到配置文件中
QFile file(filePath+".fcg");
QByteArray fileAry;
fileAry.resize(sizeof(DataFileHead)+HEADBUF+PATCHCOLORBUF*sizeof(u16)+PATCHNEEDLEBUF*sizeof(NeedlePatch)+TOWELHIGHBUF);
memset(fileAry.data(),0,fileAry.length());
if(file.exists())//存在fcg文件
{
if(file.open(QIODevice::ReadOnly))
{
QByteArray ary = file.readAll();
memcpy(fileAry.data(),ary.data(),ary.length());
}
file.close();
}
if(!file.open(QIODevice::WriteOnly | QIODevice::Truncate))
{
qDebug() << "open file fail when wirte";
return;
}
else
{
if((u32)fileAry.length() >= (sizeof(DataFileHead)+sizeof(headBuf)))
{
memcpy(fileAry.data()+sizeof(DataFileHead),(char*)headBuf,sizeof(headBuf));
file.write(fileAry.data(),fileAry.length());
}
file.close();
}
emit siHeadBuf(headBuf);//发送隔头绣数据,为了改变色序设定中的隔头绣数据
//发送buf给下位机包总共8192因为每次只能发1024所以分8次发下去
if(g_pMachine != NULL)
{
for(u16 i = 0; i < sizeof(headBuf)/MAX_EXDP_LEN; i++)
{
g_pMachine->setHeadPara((ParaStruct*)(headBuf+i*MAX_EXDP_LEN),i);
}
}
}
}
void MainWidgetFunction::funQuiHeadEmb(QString filePath)
{
m_filePath = filePath;
int headNum = 0;
int showHead = 0;
if(g_pMachine != NULL)
{
ParaStruct mcParaValues;
mcParaValues = g_pMachine->getMcPara();
headNum = mcParaValues.buf[2];//机头个数
//qDebug()<<"headNum"<<headNum;
//headNum = 120;//机头个数
}
if(g_emProductType == PRODUCT_QUI_SINGLE)//单排
{
showHead = headNum;
}
else if(g_emProductType == PRODUCT_QUI_DOUBLE)//双排
{
showHead = headNum / 2;
}
int colorOrderNum = g_pCurEmbData->getColorNums();//总颜色数
m_pBrokenLineDialog->initDialog(BrokenLineDialog::BTN_HEADEMB);
m_pBrokenLineDialog->setTitleStr(tr("Head embroidery"));
m_pBrokenLineDialog->initEmbHead(showHead,colorOrderNum,filePath);
m_pBrokenLineDialog->show();
}
void MainWidgetFunction::funSendPatchEmb(QString filePath,u16* patchColorBuf,NeedlePatch* patchNeedleBuf)
{
//保存buf到配置文件中
QFile file(filePath+".fcg");
QByteArray fileAry;
fileAry.resize(sizeof(DataFileHead)+HEADBUF+PATCHCOLORBUF*sizeof(u16)+PATCHNEEDLEBUF*sizeof(NeedlePatch)+TOWELHIGHBUF);
memset(fileAry.data(),0,fileAry.length());
if(file.exists())//存在fcg文件
{
if(file.open(QIODevice::ReadOnly))
{
QByteArray ary = file.readAll();
memcpy(fileAry.data(),ary.data(),ary.length());
}
file.close();
}
if(!file.open(QIODevice::WriteOnly | QIODevice::Truncate))
{
qDebug() << "open file fail when wirte";
return;
}
else
{
u32 size = fileAry.length();
if(size >= sizeof(DataFileHead)+HEADBUF+PATCHCOLORBUF*sizeof(u16))
{
memcpy(fileAry.data()+sizeof(DataFileHead)+HEADBUF,(char*)patchColorBuf,PATCHCOLORBUF*sizeof(u16));
}
if(size >= sizeof(DataFileHead)+HEADBUF+PATCHCOLORBUF*sizeof(u16)+PATCHNEEDLEBUF*sizeof(NeedlePatch))
{
memcpy(fileAry.data()+sizeof(DataFileHead)+HEADBUF+PATCHCOLORBUF*sizeof(u16),(char*)patchNeedleBuf,PATCHNEEDLEBUF*sizeof(NeedlePatch));
}
file.write(fileAry.data(),size);
file.close();
}
//发送buf给下位机
if(g_pMachine != NULL)
{
g_pMachine->setPatchColorPara((ParaStruct*)(patchColorBuf));
g_pMachine->setPatchNeedlePara((ParaStruct*)(patchNeedleBuf));
}
}
void MainWidgetFunction::funColorOrderChange(QString filePath,u8* buf,s16 combineMode)
{
sendPatternHead(filePath);//发送头文件
//组合模式发送机头工作缓存
if(combineMode != 0)
{
u8 headBuf[HEADBUF];
memset(headBuf,0,sizeof(headBuf));
memcpy(headBuf,buf,sizeof(headBuf));
//保存buf到配置文件中
QFile file(filePath+".fcg");
QByteArray fileAry;
fileAry.resize(sizeof(DataFileHead)+HEADBUF+PATCHCOLORBUF*sizeof(u16)+PATCHNEEDLEBUF*sizeof(NeedlePatch)+TOWELHIGHBUF);
memset(fileAry.data(),0,fileAry.length());
if(file.exists())//存在fcg文件
{
if(file.open(QIODevice::ReadOnly))
{
QByteArray ary = file.readAll();
memcpy(fileAry.data(),ary.data(),ary.length());
}
file.close();
}
if(!file.open(QIODevice::WriteOnly | QIODevice::Truncate))
{
qDebug() << "open file fail when wirte";
return;
}
else
{
if((u32)fileAry.length() >= sizeof(DataFileHead)+sizeof(headBuf))
{
memcpy(fileAry.data()+sizeof(DataFileHead),(char*)headBuf,sizeof(headBuf));
file.write(fileAry.data(),fileAry.length());
}
file.close();
}
//发送buf给下位机包总共8192因为每次只能发1024所以分8次发下去
if(g_pMachine != NULL)
{
for(u16 i = 0; i < sizeof(headBuf)/MAX_EXDP_LEN; i++)
{
g_pMachine->setHeadPara((ParaStruct*)(headBuf+i*MAX_EXDP_LEN),i);
}
}
}
}
//报错信息
int MainWidgetFunction::funErrorPrompt(u32 errcode,QString info)
{
int ret = 0;
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
//QString errInfo= errcode+info;
m_pPromptDlg->setContentStr(info);
if(m_pPromptDlg->exec() == 1)
{
if(m_adcFlag == 1)//错误信息弹窗,点击确认按钮后,退出电位器测试
{
if(g_pMachine != NULL)
{
g_pMachine->testADC(0);//点击关闭按钮发退出测试电位器命令para2=0
m_adcFlag= -1;
}
}
if(g_emMacType == MACHINE_EMB||
g_emMacType == QUIMACHINE_EMB)
{
if(errcode == ERR_CHANGE_BOBBIN)
{
g_pMachine->resetBobbinCounter();// 底线计数复位
}
}
g_pMachine->cleanError();
}
return ret;
}
//信号异常报错弹窗
int MainWidgetFunction::funDetectSignalStatus(int type)
{
m_pBrokenLineDialog->initDialog(BrokenLineDialog::BTN_BROKEN);
int headState = m_mcStatus.potval;
QString headNumStr;//机头号
headNumStr.clear();
QString headTypeStr;//机头类型
headTypeStr.clear();
int ret = 0;
u32 headNum = 0;
u32 headType = 0;
if(headState >0)
{
ret = 1;
headType = (headState & 0xffff0000)>> 16;//高16位
headNum = headState&0xFFFF;//低16位
if(headType == FLATEMB)
{
headTypeStr = tr("Emb Head");//平绣机头
}
else if(headType == COIL)
{
headTypeStr = tr("Coil Head");//缠绕机头
}
else if(headType == TOWEL)
{
headTypeStr = tr("Chenille upper Head");//毛巾上机头
}
else if(headType == TOWEL_DOWN_HEAD)
{
headTypeStr = tr("Chenille lower Head");//毛巾下机头
}
if(type == 1)//ZP信号异常
{
m_pBrokenLineDialog->setTitleStr(tr("ZP signal abnormality:")+headTypeStr);
}
else//0 MP信号异常
{
m_pBrokenLineDialog->setTitleStr(tr("MP signal abnormality:")+headTypeStr);
}
m_pBrokenLineDialog->setContentStr(QString::number(headNum));//设置数字显示内容
m_pBrokenLineDialog->show(1);
}
return ret;
}
int MainWidgetFunction::funDetectBreakHeadStatus(int type)
{
m_pBrokenLineDialog->initDialog(BrokenLineDialog::BTN_BROKEN);
int headState = m_mcStatus.potval;
QString allStr;
allStr.clear();
QString headStr;
headStr.clear();
int ret = 0;
if(headState >0)
{
ret = 1;
if(type == 1)
{
m_pBrokenLineDialog->setTitleStr(tr("Lifting motor movement timeout"));
}
else
{
m_pBrokenLineDialog->setTitleStr(tr("Towel lifting motor position error"));
}
m_pBrokenLineDialog->setContentStr(QString::number(headState));//设置数字显示内容
m_pBrokenLineDialog->show(1);
}
return ret;
}
int MainWidgetFunction::funDetectBreakHeadStatusBit(int type)
{
m_pBrokenLineDialog->initDialog(BrokenLineDialog::BTN_BROKEN);
int headState = m_mcStatus.potval;
QString allStr;
allStr.clear();
QString headStr;
headStr.clear();
int ret = 0;
for(int i = 0; i < 32; i++)
{
if(((headState >> (i%32)) & 1) == 1)
{
ret = 1;
headStr += QString::number(i + 1)+"-";
}
}
if (ret == 1)
{
if(type == 1)
{
m_pBrokenLineDialog->setTitleStr(tr("Towel scissors movement timeout"));
}
else if(type == 2)
{
m_pBrokenLineDialog->setTitleStr(tr("Flat embroidery cutter is not returning"));
}
else
{
m_pBrokenLineDialog->setTitleStr(tr("Towel scissors not returned"));
}
if(headStr.length() > 0)
{
allStr += headStr;
allStr = allStr.left(allStr.length() - 1);
}
m_pBrokenLineDialog->setContentStr(allStr);//设置数字显示内容
m_pBrokenLineDialog->show(1);
}
return ret;
}
int MainWidgetFunction::funDetectBreakLineStatus()
{
m_pBrokenLineDialog->initDialog(BrokenLineDialog::BTN_BROKEN);
int allState = 0;
//用于绗缝机断线提醒
int allfState = 0;
int allbState = 0;
int fState1 = m_mcStatus.UThreadBkSta;//面线检测状态
int bState1 = m_mcStatus.DThreadBkSta;//底线检测状态
int allState1 = fState1 | bState1;//把底线的变量和面线变量或一下,然后再判断每位(机头)
// int allState = 45056; //1 -6 -11
//断线状态 33-64
int fState2 = m_mcStatus.tempdat1[0];//面线检测状态
int bState2 = m_mcStatus.tempdat1[1];//底线检测状态
int allState2 = fState2 | bState2;//把底线的变量和面线变量或一下,然后再判断每位(机头)
//断线状态 65-96
int fState3 = m_mcStatus.UThreadBkSta1[0];//面线检测状态
int bState3 = m_mcStatus.tempdat4[0];//底线检测状态
int allState3 = fState3 | bState3;//把底线的变量和面线变量或一下,然后再判断每位(机头)
//断线状态 97-128
int fState4 = m_mcStatus.UThreadBkSta1[1];//面线检测状态
int bState4 = m_mcStatus.tempdat4[1];//底线检测状态
int allState4 = fState4 | bState4;//把底线的变量和面线变量或一下,然后再判断每位(机头)
//断线状态 128-160
int fState5 = m_mcStatus.UThreadBkSta1[2];//面线检测状态
int bState5 = m_mcStatus.tempdat4[2];//底线检测状态
int allState5 = fState5 | bState5;//把底线的变量和面线变量或一下,然后再判断每位(机头)
allfState = fState1 | fState2 | fState3 | fState4 | fState5;
allbState = bState1 | bState2 | bState3 | bState4 | bState5;
QString allStr;
allStr.clear();
QString headStr;
headStr.clear();
QString quiHeadStr;//用于绗绣机断线提示
quiHeadStr.clear();
QString infoStr;//记录到csv的内容
infoStr.clear();
int ret = 0;
int chenHeadNum = 0;
int embHeadNum = 0;
int coilHeadNum = 0;
s16 type = 0;
if(g_pMachine != NULL)
{
ParaStruct mcParaValues;
mcParaValues = g_pMachine->getMcPara();
embHeadNum = mcParaValues.buf[2];//平绣机头个数
chenHeadNum = mcParaValues.buf[8];//毛巾机头个数
coilHeadNum = mcParaValues.buf[7];//缠绕机头个数
//如果为绗绣机读一下单双排
if(g_emMacType == QUIMACHINE_EMB)
{
type = (((mcParaValues.buf[15]>>(14-1))) & 0x01); //单排还是双排
}
}
int needDispNum = 0; // 需要显示的数字个数
int canDispNum = 3; // 能够显示的数字个数
int num = 0;
//当前工作机头
if(m_workNoseHead==1)//平绣
{
if (embHeadNum <= 1)
{
canDispNum = 0;
}
infoStr = tr("EmbBrokenLine Head:");
}
else if (m_workNoseHead==2)//毛巾
{
if (chenHeadNum <= 1)
{
canDispNum = 0;
}
infoStr = tr("ChenBrokenLine Head:");
}
else if (m_workNoseHead==3)//缠绕
{
if (coilHeadNum <= 1)
{
canDispNum = 0;
}
infoStr = tr("CoilBrokenLine Head:");
}
for(int i = 0; i < 160; i++)//支持160个机头
{
if(i >= 0 && i <32)
{
allState = allState1;
}
else if(i >= 32 && i <64)
{
allState = allState2;
}
else if(i >= 64 && i <96)
{
allState = allState3;
}
else if(i >= 96 && i <128)
{
allState = allState4;
}
else if(i >= 128 && i <160)
{
allState = allState5;
}
if(((allState >> (i%32)) & 1) == 1)//把底线的变量和面线变量或一下,然后再判断机头
{
ret = 1;
if(type == 0)//绗绣机单排或绣花机
{
headStr += QString::number(i+1)+"-";
}
else//绗绣机双排
{
if(i >= embHeadNum/2)
{
s16 cidx = i - embHeadNum/2;
headStr += "S"+QString::number(cidx+1)+"-";
}
else
{
headStr += QString::number(i+1)+"-";
}
}
if(m_workNoseHead==1)
{
num = m_embHeadBreakLine.headNeedleBreakNum[i][m_mcStatus.needleIdx-1];
m_embHeadBreakLine.headNeedleBreakNum[i][m_mcStatus.needleIdx-1]++;
}
else if(m_workNoseHead==2)
{
num = m_chenHeadBreakLine.headNeedleBreakNum[i][m_mcStatus.needleIdx-1];
m_chenHeadBreakLine.headNeedleBreakNum[i][m_mcStatus.needleIdx-1]++;
}
else if(m_workNoseHead==3)
{
num = m_coilHeadBreakLine.headNeedleBreakNum[i][m_mcStatus.needleIdx-1];
m_coilHeadBreakLine.headNeedleBreakNum[i][m_mcStatus.needleIdx-1]++;
}
//记录每个针位的断线
infoStr += QString::number(i+1)+" "+tr("NeedleIdx:")+QString::number(m_mcStatus.needleIdx)+" "+tr("break line num:") + QString::number(num);
if (i < 9)
{
needDispNum++;
}
else
{
needDispNum += 2;
}
}
}
if (ret == 1)
{
if(g_emMacType == QUIMACHINE_EMB)
{
if(allfState >0)
{
quiHeadStr = tr("face break line")+"\n";
}
if(allbState >0)
{
quiHeadStr += tr("bottom break line");
}
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Alarm"));
m_pPromptDlg->setStrColor(quiHeadStr);
m_pPromptDlg->exec();
}
else
{
if (needDispNum > canDispNum)
{
if(m_workNoseHead==1)
{
m_pBrokenLineDialog->setContentInfoStr(tr("EmbHead BrokenLine"));//平绣断线
}
else if(m_workNoseHead==2)
{
m_pBrokenLineDialog->setContentInfoStr(tr("Chenille BrokenLine"));//毛巾断线
}
else if(m_workNoseHead==3)
{
m_pBrokenLineDialog->setContentInfoStr(tr("Coil BrokenLine"));//缠绕断线
}
m_pBrokenLineDialog->show(0);
}
else
{
if(headStr.length() > 0)
{
allStr += headStr;
allStr = allStr.left(allStr.length() - 1);
}
m_pBrokenLineDialog->setContentStr(allStr);
m_pBrokenLineDialog->show(0);
}
}
}
writeBreakageInfoToFile();
g_pSettings->writeToCsv(infoStr,TYPE_BREAK);//保存到csv
return ret;
}
void MainWidgetFunction::funSetPromptDlgVisibleFalse()
{
if(m_pPromptDlg->isVisible())
{
m_pPromptDlg->done(1);
}
if(m_pBrokenLineDialog->isVisible())//断线检测弹窗消失
{
m_pBrokenLineDialog->hide();
}
}
//底线计数复位
void MainWidgetFunction::funBottomLineCountReset()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentStr(tr("Is the bottom line count reset?")); //是否底线计数复位?
if(m_pPromptDlg->exec() == 1)
{
g_pMachine->resetBobbinCounter(); // 底线计数复位
}
}
//手自动工作状态切换 0:手动 1:自动
void MainWidgetFunction::funManualOrAutoSwitch(s16 val)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Prompt"));
if(val == 0)
{
m_pPromptDlg->setContentStr(tr("Are you sure to ManualSwitch?")); //是否手动工作状态切换?
if(m_pPromptDlg->exec() == 1)
{
g_pMachine->setToManualWork();
}
}
else if( val ==1)
{
m_pPromptDlg->setContentStr(tr("Are you sure to AutoSwitch?")); //是否自动工作状态切换?
if(m_pPromptDlg->exec() == 1)
{
g_pMachine->setToAutoWork();
}
}
}
void MainWidgetFunction::getPatternHeadConfig(QString path,DataFileHead & head)
{
memset(&head,0,sizeof(DataFileHead));
QString filePath = path + ".fcg";
QFile file(filePath);
if(file.exists())//存在fcg文件
{
if(file.open(QIODevice::ReadOnly))
{
QByteArray ary = file.readAll();
if((u32)ary.size() > sizeof(DataFileHead))
{
memcpy(&head,ary.data(),sizeof(DataFileHead));
}
}
file.close();
}
}
void MainWidgetFunction::slotCalMachineProgress(s16 csvCode,s16 type)
{
int per = 0;
int ifPress = 0;
for(int i = 1; i < m_csvFileStrList.size(); i++)
{
QStringList strlist = m_csvFileStrList[i].split(",", QString::SkipEmptyParts); //根据","分隔开每行的列
if(strlist.size() > 0)
{
QString code = strlist.at(COLUMN_CODE);
QStringList strlist1 = code.split("_", QString::SkipEmptyParts); //根据"_"分隔开每行的列
int infoCode = 0;
int csvType = 0;
if(strlist1.size() >= 2)
{
char *bufCode = strdup(strlist1[2].toLatin1().data());
sscanf (bufCode, "%x", &infoCode);
char *bufType = strdup(strlist1[1].toLatin1().data());
sscanf (bufType, "%x", &csvType);
}
if(infoCode == csvCode && type == csvType)
{
QStringList strlist2 = m_csvFileStrList[i].split(",", QString::SkipEmptyParts); //根据","分隔开每行的列
if(COLUMN_PRESSNUM < strlist2.size())
{
ifPress = strlist2.at(COLUMN_PRESSNUM).toInt()+1;
strlist2[COLUMN_PRESSNUM] = QString::number(ifPress);
QString str;
for(int m = 0; m < strlist2.size(); m++)
{
str.append(strlist2[m]);
if(m != strlist2.size() - 1)
{
str.append(",");
}
}
m_csvFileStrList[i] = str;
//如果按钮没被点击过就加入百分比的计算
if(ifPress == 1)
{
per += strlist2.at(COLUMN_SCORE).toInt();
}
}
m_getScore += per;
if(per != 0)
{
if(m_totalScore == 0)
{
m_totalScore = 1;
}
sendDataToGateway(csvCode,type);
}
break;
}
}
}
if(ifPress == 1)
{
QTextCodec::setCodecForLocale(QTextCodec::codecForName("GBK"));
QByteArray array;
array.clear();
for(int j = 0; j < m_csvFileStrList.size(); j++)
{
QString str = m_csvFileStrList[j];
array.append(str.toLocal8Bit());
if(j != m_csvFileStrList.size() - 1)
{
array.append('\n');
}
}
QDir apppath(qApp->applicationDirPath());
QString path = apppath.path() + apppath.separator() + CSV_PROGRESS;
QFile file(path);
if (file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text))
{
file.write(array);
#ifdef Q_OS_LINUX
system("sync");
#endif
}
file.close();
QString iniPath = apppath.path() + apppath.separator() + "config.ini";
QSettings setting(iniPath, QSettings::IniFormat); //QSettings能记录一些程序中的信息下次再打开时可以读取出来
setting.setValue("Progress/getScore",m_getScore); //记录路径到QSetting中保存
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
}
}
void MainWidgetFunction::slotHeadParaImport(QString tStyle, int type)
{
m_pSystemManageDlg->setTypeLogo(tStyle);
m_pSystemManageDlg->setMainTitle(tr("Head Parameter Import"));//机头板参数导入
m_pSystemManageDlg->setSubTitle(tr("Root > Head Parameter Import"));//超级用户 > 机头板参数导入
m_pSystemManageDlg->initDialog();
systemUpgrade(PARA_IMPORT,type);
}
void MainWidgetFunction::slotHeadParaExport(int type)
{
funExportParameter(type);
}
void MainWidgetFunction::setPatternHeadConfig(QString path, DataFileHead head)
{
QByteArray fileAry;
fileAry.resize(sizeof(DataFileHead)+HEADBUF+PATCHCOLORBUF*sizeof(u16)+PATCHNEEDLEBUF*sizeof(NeedlePatch)+TOWELHIGHBUF);//数组大小
memset(fileAry.data(),0,fileAry.length());//清空数组
QFile file(path+".fcg");//path当前选择的花样路径//创建 QFile 对象,同时指定要操作的文件
//QFile file("D:/demo.txt");
if(file.exists())//存在fcg文件
{
if(file.open(QIODevice::ReadOnly))//只能对文件进行读操作
{
QByteArray ary = file.readAll();
memcpy(fileAry.data(),ary.data(),ary.length());
}
file.close();
}
DataFileHead wHead;
memcpy(&wHead,&head,sizeof(wHead));
//WriteOnly:只能对文件进行写操作,如果目标文件不存在,会自行创建一个新文件。
//Truncate:以重写模式打开,写入的数据会将原有数据全部清除。注意,此打开方式不能单独使用,通常会和 ReadOnly 或 WriteOnly 搭配。
if(!file.open(QIODevice::WriteOnly | QIODevice::Truncate))
{
qDebug() << "open file fail when wirte, path =" << path;//文件打开失败
return;
}
else
{
memcpy(fileAry.data(),(char*)&wHead,sizeof(DataFileHead));
file.write(fileAry.data(),fileAry.length());
#ifdef Q_OS_LINUX
system("sync");
#endif
file.close();
}
}
void MainWidgetFunction::getPatternTowelHeightFcg(QString path,QByteArray & datBuf)
{
QString filePath = path + ".fcg";
QFile file(filePath);
if(file.exists())//存在fcg文件
{
if(file.open(QIODevice::ReadOnly))
{
QByteArray ary = file.readAll();
s16 size = sizeof(DataFileHead)+HEADBUF+PATCHCOLORBUF*sizeof(u16)+PATCHNEEDLEBUF*sizeof(NeedlePatch)+TOWELHIGHBUF;
if(ary.size() >= size)
{
s16 oft = sizeof(DataFileHead)+HEADBUF+PATCHCOLORBUF*sizeof(u16)+PATCHNEEDLEBUF*sizeof(NeedlePatch);
memcpy(datBuf.data(),ary.data()+oft,datBuf.length());
}
}
file.close();
}
}
void MainWidgetFunction::setPatternTowelHeightFcg(QString path,QByteArray datBuf)
{
QByteArray fileAry;
fileAry.resize(sizeof(DataFileHead)+HEADBUF+PATCHCOLORBUF*sizeof(u16)+PATCHNEEDLEBUF*sizeof(NeedlePatch)+TOWELHIGHBUF);//数组大小
memset(fileAry.data(),0,fileAry.length());//清空数组
QFile file(path+".fcg");//path当前选择的花样路径//创建 QFile 对象,同时指定要操作的文件
//QFile file("D:/demo.txt");
if(file.exists())//存在fcg文件
{
if(file.open(QIODevice::ReadOnly))//只能对文件进行读操作
{
QByteArray ary = file.readAll();
memcpy(fileAry.data(),ary.data(),ary.length());
}
file.close();
}
//WriteOnly:只能对文件进行写操作,如果目标文件不存在,会自行创建一个新文件。
//Truncate:以重写模式打开,写入的数据会将原有数据全部清除。注意,此打开方式不能单独使用,通常会和 ReadOnly 或 WriteOnly 搭配。
if(!file.open(QIODevice::WriteOnly | QIODevice::Truncate))
{
qDebug() << "open file fail when wirte, path =" << path;//文件打开失败
return;
}
else
{
s32 size = fileAry.length();
s16 totalSize = sizeof(DataFileHead) + HEADBUF + PATCHCOLORBUF*sizeof(u16) +PATCHNEEDLEBUF*sizeof(NeedlePatch) +TOWELHIGHBUF;
if(size >= totalSize)
{
s16 oft = sizeof(DataFileHead) + HEADBUF + PATCHCOLORBUF*sizeof(u16) +PATCHNEEDLEBUF*sizeof(NeedlePatch);
memcpy(fileAry.data()+oft,datBuf.data(),datBuf.length());
}
file.write(fileAry.data(),size);
file.close();
}
}
//发送ds16花样数据
void MainWidgetFunction::sendDs16PatternData(int type)
{
QByteArray & ds16dat = g_pCurEmbData->getDsDat();
// ds16数据转换的
int size = ds16dat.size();
if (size <= (int)sizeof(DataDs16FileHead))
{
qDebug("data less then head size");
return;
}
DataDs16FileHead * pDs16Head = (DataDs16FileHead *)(ds16dat.data());
qDebug()<<"fileid 2"<<pDs16Head->fileid;
int datasize = size - sizeof(DataDs16FileHead);
if (datasize <= 0)
{
qDebug("ds16 dataBegin err");
return;
}
int stepsize = datasize/sizeof(Ds16Item);
if (stepsize <= 0)
{
qDebug("ds16 data size err");
return;
}
Ds16Item *pData = (Ds16Item *)(ds16dat.data() + sizeof(DataDs16FileHead));
#if(0)
Ds16Item item;
item.dx = pData->dx;
item.dy = pData->dy;
item.dr = pData->dr;
if(item.dx == 0 && item.dy == 0)
{
ds16dat.remove(0,sizeof(Ds16Item));
pData = (Ds16Item *)(ds16dat.data() + sizeof(DataDs16FileHead));
}
#endif
//发送ds16数据
m_curFileID++;
if ((m_curFileID & 0xffff) == 0)
{
m_curFileID = 1;
}
if(g_pMachine != NULL)
{
#if(IFDYSENDMODE)
{
//只有花样文件是动态传输,其他(边框刺绣、轮廓刺绣、开位线绣)还是非动态传输模式
if(type == FILE_TYPE_DAT)
{
g_pMachine->dySendFileProc(type, 0, m_curFileID, pDs16Head, (u8*)pData);//动态传输文件
}
else
{
g_pMachine->sendFileProc(type, 0, m_curFileID, pDs16Head, (u8*)pData);
}
}
#else
{
g_pMachine->sendFileProc(type, 0, m_curFileID, pDs16Head, (u8*)pData);
}
#endif
}
m_beginX = pDs16Head->beginX;
m_beginY = pDs16Head->beginY;
}
//将ds16数据转换为ds8数据并发送
void MainWidgetFunction::convertDs16ToDs8AndSend(QString filePath,int type)
{
QByteArray ds16dat = g_pCurEmbData->getDsDat();//获得ds16数据
QByteArray ds8dat;
ds8dat.clear();
// ds16数据
int size = ds16dat.size();
if (size <= (int)sizeof(DataDs16FileHead))
{
qDebug("data less then head size");
return;
}
DataDs16FileHead * pDs16Head = (DataDs16FileHead *)(ds16dat.data());
ds8dat.append((char*)pDs16Head,sizeof(DataDs16FileHead));
int datasize = size - sizeof(DataDs16FileHead);
if (datasize <= 0)
{
qDebug("ds16 dataBegin err");
return;
}
int stepsize = datasize/sizeof(Ds16Item);
if (stepsize <= 0)
{
qDebug("ds16 data size err");
return;
}
Ds16Item *pData = (Ds16Item *)(ds16dat.data() + sizeof(DataDs16FileHead));
Ds16Item * dataPtr = pData;
u8 ctrl,attr;
s16 dx,dy,dr;
Ds8Item ds8Item;
for (int i = 0; i < stepsize; i++)
{
ctrl = dataPtr->ctrl;
attr = dataPtr->attr;
dx = dataPtr->dx;
dy = dataPtr->dy;
dr = dataPtr->dr;
ds8Item.ctrl = ctrl;
ds8Item.attr = attr;
ds8Item.dx = dx;
ds8Item.dy = dy;
ds8Item.dr = dr;
ds8dat.append((char*)&ds8Item,sizeof(Ds8Item));
dataPtr++;
}
#if(1)
//保存成ds8文件
QString ds8FilePath = filePath + ".ds8";
QFile file(ds8FilePath);
//边框刺绣不保存ds8数据避免边框刺绣完成后自动加载花样获得ds8文件头不对(还是边框刺绣的文件头)
if(type != FILE_TYPE_FRAME)
{
if(file.exists())//存在ds8文件
{
QFile::remove(ds8FilePath);
}
}
#endif
//发送ds8数据
DataDs16FileHead * pDs8Head = (DataDs16FileHead *)(ds8dat.data());
Ds8Item *tData = (Ds8Item *)(ds8dat.data() + sizeof(DataDs16FileHead));
//重新生成文件头
pDs8Head->dataSize = pDs8Head->itemNums*sizeof(Ds8Item); // 数据字节数
pDs8Head->bytesPerItem = sizeof(Ds8Item); // 每项占的字节数
pDs8Head->dataChecksum = calcCheckSum32((u8 *)(tData) , pDs8Head->dataSize);; // 数据累加校验和
pDs8Head->checkCrc = calcCrc16((u8 *)(pDs8Head), HEAD_FIX_INFO_LEN); // 前面6个字段的CRC校验6个字段分别为文件名称字节数项个数每项字节数每块字节数数据累加和的CRC校验值
m_curFileID++;
if ((m_curFileID & 0xffff) == 0)
{
m_curFileID = 1;
}
g_pMachine->sendFileProc(type, 0, m_curFileID, pDs8Head, (u8*)tData);
m_beginX = pDs8Head->beginX;
m_beginY = pDs8Head->beginY;
#if(1)
//边框刺绣不保存ds8数据避免边框刺绣完成后自动加载花样获得ds8文件头不对(还是边框刺绣的文件头)
if(type != FILE_TYPE_FRAME)
{
if(!file.open(QIODevice::WriteOnly | QIODevice::Truncate))
{
qDebug() << "open file fail when wirte, path =" << filePath;
return;
}
else
{
file.write(ds8dat);
file.close();
}
}
#endif
}
void MainWidgetFunction::addProductStatisInfo(int patternBreakLineNum)
{
//刷新生产统计信息
m_pSystemManageDlg->initDialog();
QString itemStr;
itemStr.clear();
if(g_emMacType == QUIMACHINE_EMB)//绗绣机
{
double num = (m_mcStatus.outCounter)/10.0;
itemStr = tr("Production Count: ") + QString::number(num,'f',1)+tr("cm");//产量计数:
}
else
{
itemStr = tr("Total number of patterns processed: ") + QString::number(m_mcStatus.outCounter);//总共加工花样数量:
}
m_pSystemManageDlg->addItem(itemStr);
itemStr = tr("Total number of embroidery: ") + QString::number(m_mcStatus.embNeedleNum);//总刺绣针数:
m_pSystemManageDlg->addItem(itemStr);
itemStr = tr("Pattern name: ") + m_fileName;//花样名称:
m_pSystemManageDlg->addItem(itemStr);
itemStr = tr("Pattern break line num: ") + QString::number(patternBreakLineNum);//花样断线次数:
m_pSystemManageDlg->addItem(itemStr);
ParaStruct mcParaValues;
mcParaValues = g_pMachine->getMcPara();
int embHeadNum = mcParaValues.buf[2];//平绣机头个数
int chenHeadNum = mcParaValues.buf[8];//毛巾机头个数
int coilHeadNum = mcParaValues.buf[7];//缠绕机头个数
for(int i= 0; i < embHeadNum; i++)
{
int needleBreakNum = 0;
for(int j = 0; j < NEEDLENUM; j++)
{
needleBreakNum += m_embHeadBreakLine.headNeedleBreakNum[i][j];
}
//机头断线次数:
itemStr = tr("Head ") + QString::number(i+1) + tr(" break line num: ") + QString::number(needleBreakNum);// 机头断线次数:
m_pSystemManageDlg->addItem(itemStr);
}
for(int i= 0; i < chenHeadNum; i++)
{
int needleBreakNum = 0;
for(int j = 0; j < NEEDLENUM; j++)
{
needleBreakNum += m_chenHeadBreakLine.headNeedleBreakNum[i][j];
}
//机头断线次数:
itemStr = tr("Head ") + QString::number(i+1) + tr(" break line num: ") + QString::number(needleBreakNum);// 机头断线次数:
m_pSystemManageDlg->addItem(itemStr);
}
for(int i= 0; i < coilHeadNum; i++)
{
int needleBreakNum = 0;
for(int j = 0; j < NEEDLENUM; j++)
{
needleBreakNum += m_coilHeadBreakLine.headNeedleBreakNum[i][j];
}
//机头断线次数:
itemStr = tr("Head ") + QString::number(i+1) + tr(" break line num: ") + QString::number(needleBreakNum);// 机头断线次数:
m_pSystemManageDlg->addItem(itemStr);
}
}
void MainWidgetFunction::addJournalInfoError()
{
//刷新信息
m_pSystemManageDlg->initDialog();
m_pSystemManageDlg->addListError();//读取csv列表
}
void MainWidgetFunction::addJournalInfoBreakage()
{
//刷新信息
m_pSystemManageDlg->initDialog();
m_pSystemManageDlg->addListBreakage();//读取csv列表
}
void MainWidgetFunction::addJournalInfoDebug()
{
//刷新信息
m_pSystemManageDlg->initDialog();
m_pSystemManageDlg->addListDebug();//读取csv列表
}
QString MainWidgetFunction::getCompileDateTime()
{
const char *pMonth[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
const char date[12] = __DATE__; // 取编译日期
int i;
int month, year, day;
month = year = day = 0;
for(i = 0; i < 12; i++)
{
if(memcmp(date, pMonth[i], 3) == 0)
{
month = i + 1;
break;
}
}
year = (unsigned char)atoi(date + 9); // date[9]为2位年份, date[7]为完整年份
day = (unsigned char)atoi(date + 4); // 日期
QString str;
str.sprintf("%02d%02d%02d", year, month, day);
return str;
}
//组成json键值对
QString MainWidgetFunction::compositionJson(QString key, QString value)
{
QString mStr="\"";//引号的字符串
QString str = mStr + key + mStr + ":" + mStr + value + mStr + ",";
return str;
}
HMILotData MainWidgetFunction::getHMILotData()
{
HMILotData lotFata;
memset(&lotFata, 0, sizeof(HMILotData));
memcpy(lotFata.HMIVerStr, getVersionStr().data(), getVersionStr().length()); // 版本信息
memcpy(lotFata.fileName, m_fileName.data(), m_fileName.length()); // 文件名称
u32 rackNum = g_pSettings->readFromIniFile("IOT/rackNumber").toInt();//机架号
lotFata.machineNumber = rackNum; // 机架号
QString deliveryTime = g_pSettings->readFromIniFile("IOT/deliveryTime").toString();//工厂预计交货时间
QByteArray arr = deliveryTime.toLocal8Bit();
memcpy(lotFata.deliveryTime, arr.data(), arr.size()); //交货日期
u16 debugProgress = g_pSettings->readFromIniFile("IOT/debugProgress").toInt();//调试进度
lotFata.debugProgress = debugProgress; //调试进度
//电机总数-先固定写为4个如果后续变动较大可把电机个数写为全局变量或从其他cpp中传参
lotFata.motorNum = 4;
return lotFata;
}
//将断线信息重新写回文件
void MainWidgetFunction::writeBreakageInfoToFile()
{
//将断线信息重新写回文件
//各机头针杆断线信息
QDir apppath(qApp->applicationDirPath());
QString breakFilePath = apppath.path() + apppath.separator() + BREAKINFOFILE;
QFile breakFile(breakFilePath);
if(!breakFile.open(QIODevice::WriteOnly | QIODevice::Truncate))
{
qDebug() << "open breakFile fail when wirte";
return;
}
else
{
QByteArray array;
array.clear();
for(s32 i = 0; i < HEADNUM; i++)
{
for(s32 j = 0; j < NEEDLENUM; j++)
{
QByteArray arr;
arr.resize(sizeof(s32));
memcpy(arr.data(), &m_embHeadBreakLine.headNeedleBreakNum[i][j], sizeof(s32));
array.append(arr);
}
}
for(s32 i = 0; i < HEADNUM; i++)
{
for(s32 j = 0; j < NEEDLENUM; j++)
{
QByteArray arr;
arr.resize(sizeof(s32));
memcpy(arr.data(), &m_coilHeadBreakLine.headNeedleBreakNum[i][j], sizeof(s32));
array.append(arr);
}
}
for(s32 i = 0; i < HEADNUM; i++)
{
for(s32 j = 0; j < NEEDLENUM; j++)
{
QByteArray arr;
arr.resize(sizeof(s32));
memcpy(arr.data(), &m_chenHeadBreakLine.headNeedleBreakNum[i][j], sizeof(s32));
array.append(arr);
}
}
breakFile.write(array);
breakFile.close();
}
return;
}
//发送数据到物联网
void MainWidgetFunction::sendDataToGateway(s16 code,s16 type)
{
QString mStr="\"";//引号的字符串
QString mcType = mStr+U00016+mStr+":"+mStr+"Emb"+mStr+",";
QString mcStr1;
mcStr1.clear();
QString mcStr2;
mcStr2.clear();
mcStr1 = mStr+"Towel"+mStr+":0,";
mcStr2 = mStr+"Coil"+mStr+":0,";
s16 towel = g_pSettings->readFromInHMIiFile("HMI/towel").toInt();//是否有毛巾功能
s16 coil = g_pSettings->readFromInHMIiFile("HMI/coil").toInt();//是否有缠绕功能
if(towel == 1)
{
mcStr1 = mStr+"Towel"+mStr+":1,";
}
if(coil == 1)
{
mcStr2 = mStr+"Coil"+mStr+":1,";
}
QString sensorMotorStr;
sensorMotorStr.clear();
sensorMotorStr = mStr+S00000+mStr+":1,"+mStr+S00010+mStr+":1,"+mStr+S00070+mStr+":1,"+mStr+S01000+mStr+":1,";
if(type == 0)
{
switch (code)
{
case CSV_00_CODE_1:
sensorMotorStr += mStr+S00020+mStr+":1,";
sensorMotorStr += mStr+M0003+mStr+":1,";
break;
case CSV_00_CODE_4://边框检查
case CSV_00_CODE_8://自动定软限位
sensorMotorStr += mStr+S00200+mStr+":1,";
sensorMotorStr += mStr+S00201+mStr+":1,";
sensorMotorStr += mStr+S00220+mStr+":1,";
sensorMotorStr += mStr+S00221+mStr+":1,";
sensorMotorStr += mStr+S00230+mStr+":1,";
sensorMotorStr += mStr+S00231+mStr+":1,";
sensorMotorStr += mStr+M0001+mStr+":1,";
sensorMotorStr += mStr+M0002+mStr+":1,";
break;
case CSV_00_CODE_5:
sensorMotorStr += mStr+M0004+mStr+":1,";
break;
default:
break;
}
}
else if(type == CSV_MC_TYPE_02)
{
switch (code)
{
case CSV_02_CODE_1://毛巾M轴零位
sensorMotorStr += mStr+S01020+mStr+":1,";
sensorMotorStr += mStr+M0005+mStr+":1,";
sensorMotorStr += mStr+M0006+mStr+":1,";
break;
case CSV_02_CODE_2://毛巾打环轴归零
sensorMotorStr += mStr+S01021+mStr+":1,";
sensorMotorStr += mStr+M0007+mStr+":1,";
break;
default:
break;
}
}
else if(type == CSV_MC_TYPE_03)
{
switch (code)
{
case CSV_03_CODE_1://缠绕压脚电机归零
sensorMotorStr += mStr+M0008+mStr+":1,";
sensorMotorStr += mStr+M0009+mStr+":1,";
sensorMotorStr += mStr+M0010+mStr+":1,";
break;
case CSV_03_CODE_2://缠绕锯齿电机归零
sensorMotorStr += mStr+M0011+mStr+":1,";
break;
default:
break;
}
}
int val = ((double)m_getScore / (double)m_totalScore) * 100;
//emit siShowPercentage(val);//测试物联网用
QString timeStr;
timeStr.clear();
#ifdef Q_OS_LINUX
//timeStr = QString::number(QDateTime::currentDateTime().toMSecsSinceEpoch() - 28800000);//mcgs下时间差8个小时
timeStr = QString::number(QDateTime::currentDateTime().toMSecsSinceEpoch());
#endif
#ifdef Q_OS_WIN
timeStr = QString::number(QDateTime::currentDateTime().toMSecsSinceEpoch());
#endif
QString lotStr;
lotStr.clear();
lotStr = "{" + mStr + QString::number(m_HMILotData.machineNumber) + "#" + mStr + ":[{" +
mStr + "ts" + mStr + ":" + timeStr + "," +
mStr + "values" + mStr + ":{\"timestamp" + mStr + ":" + timeStr + ",\"RackNumber\":\"" + QString::number(m_HMILotData.machineNumber) + "#\"" + ","
+ mcType + mcStr1 + mcStr2 + sensorMotorStr;
QString keyStr = compositionJson(U00001, QString::number(val));
lotStr += keyStr;
lotStr.chop(1);
lotStr += "}}]}";
//qDebug()<<lotStr;
g_pLotMachine->sendLotDataToGateway(lotStr);
}
void MainWidgetFunction::setErrorCodeAndStateList(QList<ErrorCodeStateItem> list)
{
m_errorCodeAndStateItemList.clear();
m_errorCodeAndStateItemList.append(list);
}
//上电计算 关机时间 并发送给主控
void MainWidgetFunction::setShutDownTime()
{
int oldSecond = g_pSettings->readFromIniFile("DateTime/second").toInt();//上次上电的系统时间
QDateTime dateTime = QDateTime::currentDateTime(); //当前时间
int curSecond = dateTime.toTime_t();//单位为秒 //新的时间
int diff = curSecond - oldSecond;//关机秒数
if (diff >= 0)
{
}
else//小于0
{
diff = 5000*3600;
}
qDebug()<<"shutdown second"<<diff;
if(g_pMachine != NULL && oldSecond != 0)
{
g_pMachine->setShutDownTime(0, diff);//可能这个diff太大了
}
}
//设置机器状态
void MainWidgetFunction::setMcStates(MCStatus mcStatus)
{
memcpy((char*)&m_mcStatus,(char*)&mcStatus,sizeof(MCStatus));
m_gearValue = m_mcStatus.tempdat3;//档位值和松紧线位置
m_pPromptDlg->setGearValueStr(m_gearValue);//提升电机控制界面显示档位值
m_potValue = m_mcStatus.potval;
float potValue = m_potValue*0.01;
QString potValueStr;
potValueStr.sprintf("%.2f",potValue);
m_pPromptDlg->setPosValueStr(potValueStr);//电位器值
m_workNoseHead = m_mcStatus.workNoseHead;
m_pPromptDlg->setNoseHeadValueStr(m_workNoseHead);//机头切换,当前工作机头
m_pPromptDlg->setCurNeedleStr(m_workNoseHead,QString("%1").arg(m_mcStatus.needleIdx),potValueStr);//当前针杆
}
QString MainWidgetFunction::getVersionStr()
{
// int towel = g_pSettings->readFromInHMIiFile("HMI/towel").toInt();//是否有毛巾功能
// int coil = g_pSettings->readFromInHMIiFile("HMI/coil").toInt();//是否有缠绕功能
QString str;
#if(0)
if(g_emMacType == QUIMACHINE_EMB)//绗绣机
{
if(g_emProductType == PRODUCT_QUI_SINGLE)//单排绗绣
{
str.sprintf("RPQE-SFE-XPlatformF-LAUTO-V");
}
else if(g_emProductType == PRODUCT_QUI_DOUBLE)//双排
{
str.sprintf("RPQE-DFE-XPlatformF-LAUTO-V");
}
}
else if(g_emMacType == MACHINE_EMB && g_emProductType !=PRODUCT_CHEN)//绣花机
{
str.sprintf("RPCE-FE-XPlatformF-LAUTO-V");
if(towel==1&& coil !=1)
{
str.sprintf("RPCE-FECC-XPlatformF-LAUTO-V");//平绣+毛巾
}
else if(towel!=1&&coil ==1)
{
str.sprintf("RPCE-FECT-XPlatformF-LAUTO-V");//平绣+缠绕
}
else if(towel==1&&coil ==1)
{
str.sprintf("RPCE-FECTCC-XPlatformF-LAUTO-V");//平绣+缠绕+毛巾
}
}
else if(g_emMacType == MACHINE_EMB && g_emProductType ==PRODUCT_CHEN)//纯毛巾
{
str.sprintf("RPCE-CC-XPlatformF-LAUTO-V");//毛巾
}
#endif
if(g_emMacType == QUIMACHINE_EMB)//绗绣机
{
str.sprintf("RPQE-ALL-XPlatformF-LAUTO-V");
}
else if(g_emMacType == MACHINE_EMB)
{
str.sprintf("RPCE-ALL-XPlatformF-LAUTO-V");
}
str += getCompileDateTime();
return str;
}
//将起绣点写回到文件中
void MainWidgetFunction::writePonitToFile(QString filePath,u8 type, int x, int y, int st ,u8 workHead)
{
QFileInfo fileInfo(filePath);
QString suffix = fileInfo.suffix().toUpper();//后缀大写
if(suffix == "DST")
{
DataFileDst dst;
dst.initFile(filePath);
dst.loadFile();
dst.writePointToFile(type,x,y,st,workHead);
}
else if(suffix == "DSR")
{
DataFileDsr dsr;
dsr.initFile(filePath);
dsr.loadFile();
dsr.writePointToFile(type,x,y,st,workHead);
}
}
//机器信息改变
void MainWidgetFunction::slotMCInfoChange()
{
static int fID = 0;
m_mcStatus = g_pMachine->getMcStatus();
//可使用时长
int workTime = m_mcStatus.workableTimer;
if( workTime > 0 && workTime < INT_MAX )
{
QString strTime;
QString strDay;
QString strHour;
QString strSec;
int day = workTime/(60 *24);
//使用时长不足5天就主动提示用户
if(day < 5 && fID == 0)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
strDay = QString::number(workTime/(60 *24) , 10);
strHour = QString::number((workTime%(60 *24))/60 , 10) ;
strSec = QString::number(workTime%60 , 10);
strTime = strDay + " " + tr("Day") + " " + strHour + " " + tr("Hour") + " " + strSec + " " + tr("Minutes") ; // 天 小时 分钟
//机器剩余可用时间为
str = tr("The remaining available time of the machine is ") + strTime;
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
//开启一个定时器隔4个小时就发一次查询机器状态
m_pTipsTimer->start();
fID++;
}
}
}
void MainWidgetFunction::slotFileInfoChange()
{
DataDs16FileHead ds16HeadSend;
memcpy(&ds16HeadSend,(char*)g_pCurEmbData->getDsDatHead(),sizeof(DataDs16FileHead));
DataDs16FileHead ds16HeadMC;
memset((char*)&ds16HeadMC,0,sizeof(DataDs16FileHead));
ds16HeadMC = g_pMachine->getFileInfo();
u32 fileIdMc = ds16HeadMC.fileid;
u32 fileIdSend = ds16HeadSend.fileid;
//发送的文件头fileid和机器接收的文件头fileid不一致文件发送失败提示重新发送
if(fileIdMc != fileIdSend)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentStr(tr("File sending failed, please reselect and send!"));//文件发送失败,请重新选择并发送!
m_pPromptDlg->exec();
return;
}
}
//给主控发查询机器信息
void MainWidgetFunction::onTipsTimer()
{
if (g_pMachine != NULL)
{
g_pMachine->getInfoFromMachine();
}
m_pTipsTimer->stop(); //关定时器
}
void MainWidgetFunction::slotSetDynamicIP(QString ssid)
{
if(ssid.length() <= 0)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentStr(tr("ssid is empty!"));//ssid为空
m_pPromptDlg->exec();
return;
}
WordsInputDialog wordInputDlg;
wordInputDlg.wifiClean();
wordInputDlg.setTitleStr(tr("Password input"));//密码输入
wordInputDlg.setOldWordsStr("");
if(wordInputDlg.exec() == 1)
{
#ifdef Q_OS_LINUX
QString psd = wordInputDlg.getInputStr();
//密码不能小于8位(一般密码不允许少于8位)如果写入小于8位的密码系统文件会写入失败造成文件内容丢失会造成wifi列表获取失败
//wifi不需要密码登录的时候也可以点击确认按钮连接wifi
if(psd.length() < 8 && psd.length() > 0)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("The password cannot be less than 8 digits, please check!");//密码不能小于8位请检查
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
//base64解密
//向配置文件写入加密结果设置动态IP
QString iniPath = WIFIINIPATH;
QSettings setting(iniPath,QSettings::IniFormat);
setting.beginGroup("WIFI");
setting.setValue("default_passwd",psd.toLatin1().toBase64());
setting.setValue("default_ssid",ssid.toLatin1().toBase64());
setting.setValue("static_ip","");
setting.setValue("static_mask","");
setting.setValue("static_mode","false");
setting.endGroup();
system("sync");
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("Settings require screen restart to take effect!");//设置需要重启屏幕才生效!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
system("reboot");
}
#endif
}
}
void MainWidgetFunction::slotSetStaticIP(QString ssid, QString psd,QString dnip)
{
if(ssid.length() <= 0)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentStr(tr("ssid is empty!"));//ssid为空
m_pPromptDlg->exec();
return;
}
if(psd.length() <= 0){}//为了去掉编译警告
PassWordDialog passWordDlg;
QString ip;
ip.clear();
passWordDlg.setTitleStr(tr("IP input"),-1);//IP输入
passWordDlg.setShowIfVisible(true);
passWordDlg.setIpStr(dnip);
int rslt = passWordDlg.exec();
if(rslt == 1)
{
ip = passWordDlg.getInputStr();
}
#ifdef Q_OS_LINUX
if(ip.length() <= 0)
{
return;
}
//base64解密
//向配置文件写入加密结果设置静态IP
QString iniPath = WIFIINIPATH;
QSettings setting(iniPath,QSettings::IniFormat);
setting.beginGroup("WIFI");
setting.setValue("default_passwd",psd.toLatin1().toBase64());
setting.setValue("default_ssid",ssid.toLatin1().toBase64());
setting.setValue("static_ip",ip);
setting.setValue("static_mask","255.255.255.0");
setting.setValue("static_mode","true");
setting.endGroup();
system("sync");
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("Settings require screen restart to take effect!");//设置需要重启屏幕才生效!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
system("reboot");
}
return;
#endif
}
void MainWidgetFunction::slotSetQuiHeadBuf(u8 *buf)
{
//保存buf到配置文件中
QFile file(m_filePath+".fcg");
QByteArray fileAry;
fileAry.resize(sizeof(DataFileHead)+HEADBUF+PATCHCOLORBUF*sizeof(u16)+PATCHNEEDLEBUF*sizeof(NeedlePatch)+TOWELHIGHBUF);
memset(fileAry.data(),0,fileAry.length());
if(file.exists())//存在fcg文件
{
if(file.open(QIODevice::ReadOnly))
{
QByteArray ary = file.readAll();
memcpy(fileAry.data(),ary.data(),ary.length());
}
file.close();
}
if(!file.open(QIODevice::WriteOnly | QIODevice::Truncate))
{
qDebug() << "open file fail when wirte";
return;
}
else
{
if((u32)fileAry.length() >= (sizeof(DataFileHead)+HEADBUF))
{
memcpy(fileAry.data()+sizeof(DataFileHead),(char*)buf,HEADBUF);
file.write(fileAry.data(),fileAry.length());
}
file.close();
}
emit siHeadBuf(buf);//发送隔头绣数据,为了改变色序设定中的隔头绣数据
//发送buf给下位机包总共8192因为每次只能发1024所以分8次发下去
if(g_pMachine != NULL)
{
for(u16 i = 0; i < HEADBUF/MAX_EXDP_LEN; i++)
{
g_pMachine->setHeadPara((ParaStruct*)(buf+i*MAX_EXDP_LEN),i);
}
}
}
//接收到主板的物联网数据
void MainWidgetFunction::slotSendLotData()
{
QString mStr="\"";//引号的字符串
QString lotStr;
lotStr.clear();
QString timeStr;
timeStr.clear();
#ifdef Q_OS_LINUX
//imeStr = QString::number(QDateTime::currentDateTime().toMSecsSinceEpoch() - 28800000);//mcgs下时间差8个小时
timeStr = QString::number(QDateTime::currentDateTime().toMSecsSinceEpoch());
#endif
#ifdef Q_OS_WIN
timeStr = QString::number(QDateTime::currentDateTime().toMSecsSinceEpoch());
#endif
lotStr.clear();
lotStr = "{" + mStr + QString::number(m_HMILotData.machineNumber) + mStr + ":[{" +
mStr + "ts" + mStr + ":" + timeStr + "," +
mStr + "values" + mStr + ":{\"RackNumber\":\"" + QString::number(m_HMILotData.machineNumber) + "\"" + ",";
QString keyStr;
keyStr.clear();
if(g_pLotMachine != NULL)
{
if(g_pMachine == NULL)
{
return;
}
if(m_HMILotData.workState == S0505)
{
m_HMILotData.workState = S0507;
qint64 time = 0;
#ifdef Q_OS_LINUX
time = QDateTime::currentDateTime().toMSecsSinceEpoch() - 28800000;//mcgs下时间差8个小时
#endif
#ifdef Q_OS_WIN
time = QDateTime::currentDateTime().toMSecsSinceEpoch();
#endif
m_HMILotData.endTime = time;
m_HMILotData.startTime = time;
}
if((m_mcStatus.workStatus & WORK_STA_WORKING) == WORK_STA_WORKING)
{
if(m_HMILotData.workState != S0506)
{
qint64 time = 0;
#ifdef Q_OS_LINUX
time = QDateTime::currentDateTime().toMSecsSinceEpoch() - 28800000;//mcgs下时间差8个小时
#endif
#ifdef Q_OS_WIN
time = QDateTime::currentDateTime().toMSecsSinceEpoch();
#endif
m_HMILotData.workState = S0506;
m_HMILotData.startTime = time;
}
keyStr = compositionJson(U00048, QString::number(S0506)); //设备状态
lotStr += keyStr;
}
else
{
if(m_HMILotData.workState != S0507)
{
qint64 time = 0;
#ifdef Q_OS_LINUX
time = QDateTime::currentDateTime().toMSecsSinceEpoch() - 28800000;//mcgs下时间差8个小时
#endif
#ifdef Q_OS_WIN
time = QDateTime::currentDateTime().toMSecsSinceEpoch();
#endif
m_HMILotData.endTime = time;
m_HMILotData.workState = S0507;
}
keyStr = compositionJson(U00049, QString::number(m_HMILotData.startTime)); //开始时间
lotStr += keyStr;
keyStr = compositionJson(U00050, QString::number(m_HMILotData.endTime)); //结束时间
lotStr += keyStr;
int pins = m_HMILotData.endPins - m_HMILotData.startPins;
keyStr = compositionJson(U00051, QString::number(pins)); //区间针数
lotStr += keyStr;
keyStr = compositionJson(U00048, QString::number(S0507)); //设备状态
lotStr += keyStr;
keyStr = compositionJson(U00052, QString::number(m_mcStatus.outCounter)); //产量统计
lotStr += keyStr;
}
keyStr = compositionJson("ts", timeStr); //时间戳
lotStr += keyStr;
if(lotStr.at(lotStr.length()-1) == ',')//去除最后一个逗号
{
lotStr.chop(1); //删除字符串右边n个字符
}
lotStr += "}}]}";
//qDebug()<<lotStr;
//发送物联数据到网关
g_pLotMachine->sendLotDataToGateway(lotStr);
}
}
//执行网关数据动作
void MainWidgetFunction::slotRunLotDataAction(QString str)
{
int cmd = str.toInt();
if(cmd == 1)//点动
{
funSpindleJog();
}
else if(cmd == 2)//剪线
{
funManualTrim();
}
}
#if(0)
//当界面与网关建立连接时需要向网关发送固定的键值对
void MainWidgetFunction::slotSendJsonToMqtt()
{
QString mStr="\"";//引号的字符串
QString lotStr;
lotStr.clear();
lotStr += "{" + mStr + "device" + mStr + ":" + mStr + QString::number(m_HMILotData.machineNumber) + "#" + mStr + "}";
if(g_pLotMachine != NULL)
{
g_pLotMachine->sendLotDataToGateway(lotStr);
}
}
#endif
void MainWidgetFunction::slotTransProgress(u8 fileType, int send, int total)
{
int csend = 0;
int ctotal = 0;
if(fileType == FILE_TYPE_PGM)//主控升级文件
{
csend += g_pMachine->getTotalSendNum();
ctotal += g_pMachine->getTotalPacketNum();
if (csend < 0 && ctotal < 0)
{
// 失败
m_pPromptDlg->initDialog(PromptDialog::BTN_UCANCEL);
m_pPromptDlg->setTitleStr(tr("MC Upgrade"));//主控升级
//m_pPromptDlg->setButtonUCancelStr(tr("Close"));//关闭
m_pPromptDlg->setContentProcessStr(tr("Failed to upgrade the main control system!")); //主控系统升级失败!
}
else if (csend == 0 && ctotal == 0)
{
// 成功
m_pPromptDlg->initDialog(PromptDialog::BTN_RESTART);
m_pPromptDlg->setTitleStr(tr("MC Upgrade"));//主控升级
m_pPromptDlg->setContentProcessStr(tr("The main control system has been successed, waiting until machine restart"));
int seconds = 10;//界面重启时间改成10秒
for(int i = 0; i < seconds; i++)
{
QString str = QString(tr("System will restart %1 s later")).arg(seconds-i);//系统将在 %1 秒后重启
m_pPromptDlg->setContentProcessStr(str);
g_pMachine->sleep(1);
}
#ifdef Q_OS_WIN
qApp->exit();
#endif
#ifdef Q_OS_LINUX
system("reboot");
#endif
m_pPromptDlg->hide();
}
else if(csend >= 0 && csend <= ctotal)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_UCANCEL);
m_pPromptDlg->setTitleStr(tr("MC Upgrade"));//主控升级
m_pPromptDlg->setContentProcessStr(tr("Main control system is being upgraded...")); //主控系统升级中...
//m_pPromptDlg->setButtonUCancelStr(tr("Cancel"));//取消
m_pPromptDlg->setRange(0, total);
m_pPromptDlg->setValue(send);
m_pPromptDlg->show();
QCoreApplication::processEvents(QEventLoop::AllEvents);
}
else
{
m_pPromptDlg->hide();
}
}
else
{
if (send < 0 && total < 0)
{
// 失败
m_pPromptDlg->initDialog(PromptDialog::BTN_UCANCEL);
if(fileType == FILE_TYPE_BOARD)//外围板升级文件
{
m_pPromptDlg->setTitleStr(tr("EXB Upgrade"));//外围板升级
//m_pPromptDlg->setButtonUCancelStr(tr("Close"));//关闭
m_pPromptDlg->setContentProcessStr(tr("Perparalboard system upgrade failed!")); //外围板系统升级失败!
}
else if(fileType == FILE_TYPE_DAT || fileType == FILE_TYPE_FRAME)//花样数据文件(边框刺绣文件)
{
m_pPromptDlg->setTitleStr(tr("Prompt"));
//m_pPromptDlg->setButtonUCancelStr(tr("Close"));//关闭
m_pPromptDlg->setContentStr(tr("Failed to send data file!")); //发送数据文件失败!
}
}
else if (send == 0 && total == 0)
{
if(fileType == FILE_TYPE_BOARD)//外围板升级文件
{
// 成功
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("EXB Upgrade"));//外围板升级
//外围板系统升级成功!
m_pPromptDlg->setContentProcessStr(tr("The external board system is upgraded!"));
}
else if(fileType == FILE_TYPE_DAT || fileType == FILE_TYPE_FRAME)//花样数据文件(边框刺绣文件)
{
// 成功
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentProcessStr(tr("The data file is send successfully!")); //数据文件发送成功!
}
m_pPromptDlg->hide();
//发送完成,获取文件信息,判断文件发送是否成功
if(fileType == FILE_TYPE_DAT || fileType == FILE_TYPE_FRAME)//花样数据文件或边框刺绣文件
{
if(g_pMachine != NULL)
{
g_pMachine->getFileInfoFromMachine();
}
}
}
else if(send >= 0 && send <= total)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_UCANCEL);
if(fileType == FILE_TYPE_BOARD)//外围板升级文件
{
m_pPromptDlg->setTitleStr(tr("EXB Upgrade"));//外围板升级
m_pPromptDlg->setContentProcessStr(tr("The external board system upgrade...")); //外围板系统升级中...
}
else if(fileType == FILE_TYPE_DAT || fileType == FILE_TYPE_FRAME)//花样数据文件(边框刺绣文件)
{
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentProcessStr(tr("Data file sending...")); //数据文件发送中...
}
//m_pPromptDlg->setButtonUCancelStr(tr("Cancel"));//取消
m_pPromptDlg->setRange(0, total);
m_pPromptDlg->setValue(send);
m_pPromptDlg->show();
QCoreApplication::processEvents(QEventLoop::AllEvents);
}
else
{
m_pPromptDlg->hide();
}
}
}
//导出csv文件到U盘
void MainWidgetFunction::slotCsvExport(int logType)
{
QString usbPath = detectUsb();//U盘路径
if(usbPath.length() <= 0)
{
//优盘不存在
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("USB flash drive is not detected!");//未检测到优盘!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
QDir apppath(qApp->applicationDirPath());//D:/work/workQT/XPlatform/Windows/debug
QString newName = usbPath + apppath.separator();//G
QString timeStr = QDateTime::currentDateTime().toString("_yyMMdd_hhmmss");//时间日期 _230215_144121
QString astr;
if(logType == TYPE_ERROR)
{
astr = "error";
}
else if(logType == TYPE_BREAK)
{
astr = "break";
}
else if(logType == TYPE_DEBUGINFO)
{
astr = "debuginfo";
}
QString newFileName = newName+astr+timeStr+".csv";
//csv文件路径
QString csvfile;
if(logType == TYPE_ERROR)
{
csvfile = apppath.path() + apppath.separator() + CSV_ERROR;
}
else if(logType == TYPE_BREAK)
{
csvfile = apppath.path() + apppath.separator() + CSV_BREAK;
}
else if(logType == TYPE_DEBUGINFO)
{
csvfile = apppath.path() + apppath.separator() + CSV_DEBUGINFO;
}
QString csvfilePath = QDir(csvfile).absolutePath();//为了将"\"变为"/"
bool bl = QFile::copy(csvfilePath,newFileName);
//强制写入
//linux下写入文件或者拷贝、删除文件的情况
#ifdef Q_OS_LINUX
system("sync");
#endif
QString str;
if(bl == true)
{
str = tr("Journal exported successfully!");//文件日志导出成功!
}
else
{
str = tr("Journal exported failed!");//文件日志导出失败!
}
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
void MainWidgetFunction::slotClearJournal()
{
QDir apppath(qApp->applicationDirPath());
QString csvfile = apppath.path() + apppath.separator();
g_pSettings->fileClear(csvfile+CSV_ERROR);//清空文件日志内容,但文件还在
g_pSettings->fileClear(csvfile+CSV_BREAK);//清空文件日志内容,但文件还在
memset(&m_embHeadBreakLine,0,sizeof(EmbHeadBreakLine));
memset(&m_coilHeadBreakLine,0,sizeof(CoilHeadBreakLine));
memset(&m_chenHeadBreakLine,0,sizeof(ChenHeadBreakLine));
writeBreakageInfoToFile();
// 刷新文件日志界面信息
m_pSystemManageDlg->initDialog();
m_pSystemManageDlg->exec(JOURNAL);//显示窗体
}
void MainWidgetFunction::slotRefreshWifiList()
{
QStringList wifiStrList;
wifiStrList.clear();
s16 rel = refreshWifiList(wifiStrList,1);
if(rel > 0)
{
m_pSystemManageDlg->setItemList(wifiStrList);
}
}
//清空产量统计
void MainWidgetFunction::slotClearProductStatis()
{
if(g_pMachine != NULL)
{
g_pMachine->resetOutput();//清除产量统计(主控计数)
}
//清空花版断线计数和机头断线计数
memset(&m_embHeadBreakLine,0,sizeof(EmbHeadBreakLine));
memset(&m_chenHeadBreakLine,0,sizeof(ChenHeadBreakLine));
memset(&m_coilHeadBreakLine,0,sizeof(CoilHeadBreakLine));
writeBreakageInfoToFile();
emit siClearPatternBreakLineNum();
addProductStatisInfo(0);//花版断线次数清零
m_pSystemManageDlg->refreshUi();
}
//平绣主轴动作
void MainWidgetFunction::slotEmbSpindleAction(int action)
{
if(g_pMachine != NULL)
{
if(m_noseHead == TOWEL)
{
g_pMachine->motoMove(MT_LTM, action, 0);
}
else if(m_noseHead == TOWELM)
{
g_pMachine->motoMove(MT_LTMM, action, 0);
}
else if(m_noseHead == FLATEMB)
{
g_pMachine->motoMove(MT_LEM, action, 0);
}
else if(m_noseHead == COIL)
{
g_pMachine->motoMove(MT_LCM2, action, 0);
}
else if(m_noseHead == COILM)
{
g_pMachine->motoMove(MT_LCMM, action, 0);
}
}
}
//平绣,毛巾主轴旋转
void MainWidgetFunction::slotEmbSpindleRotate(int angle)
{
if(g_pMachine != NULL)
{
// int towel = g_pSettings->readFromInHMIiFile("HMI/towel").toInt();//是否有毛巾功能.
// int coil = g_pSettings->readFromIniFile("HMI/coil").toInt();//是否有缠绕功能
if(m_noseHead == TOWEL)
{
g_pMachine->manualAction(CHENILLE_SPINDLE_TO_ANGLE,angle);
}
else if(m_noseHead == TOWELM)
{
g_pMachine->manualAction(CHENILLE_M_TO_ANGLE,angle);
}
else if(m_noseHead == FLATEMB)
{
g_pMachine->manualAction(EMB_SPINDLE_TO_ANGLE,angle);
}
else if(m_noseHead == COIL)
{
g_pMachine->manualAction(COIL_SPINDLE_TO_ANGLE,angle);
}
else if(m_noseHead == COILM)
{
g_pMachine->manualAction(COIL_M_TO_ANGLE,angle);
}
}
}
void MainWidgetFunction::slotElasticCtrlPos(int elasticPos)
{
if(g_pMachine != NULL)
{
g_pMachine->elasticCtrl(elasticPos);//点击确认按钮发松紧线控制的命令para2=松紧线位置
}
}
void MainWidgetFunction::slotLiftMotorCtrl(int gearValue)
{
if(g_pMachine != NULL)
{
g_pMachine->hoistCtrl(gearValue);;//点击确认按钮发提升电机制的命令para2=档位值
}
}
//用户登录
void MainWidgetFunction::slotUserLogin(s16 user)
{
// QTextCodec *cod = QTextCodec::codecForLocale();
PassWordDialog passWordDlg;
QString str("");
if(user == repair)
{
passWordDlg.setTitleStr(tr("Password input *"));//密码输入
}
else if(user == factory)
{
passWordDlg.setTitleStr(tr("Password input **"));//密码输入
}
else if(user == resetpara)
{
passWordDlg.setTitleStr(tr("Password input ****"));//密码输入
}
int rslt = passWordDlg.exec();
if(rslt == 1)
{
str = passWordDlg.getInputStr();
if(user == repair)
{
if (str == g_passwordOne)
{
g_emUser = repair;
emit siSetButtonUserLogo(1);
if(g_emMacType == MACHINE_EMB)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentStr(tr("Primary password successfully logged in!"));//一级密码成功登入!
m_pPromptDlg->exec();
}
}
else
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentStr(tr("The password is wrong,please re-enter!"));//密码错误,请重新输入密码!
m_pPromptDlg->exec();
return;
}
}
else if(user == factory)
{
if (str == PASSWORD_TWO)
{
g_emUser = factory;
emit siSetButtonUserLogo(2);
if(g_emMacType == MACHINE_EMB)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentStr(tr("Root successfully logged in!"));//超级用户成功登入!
m_pPromptDlg->exec();
}
}
else if (str == PASSWORD_THREE)
{
g_emUser = root;
emit siSetButtonUserLogo(2);//设置超级用户图标
if(g_emMacType == MACHINE_EMB)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentStr(tr("Three-level password successfully logged in!"));//三级密码成功登入!
m_pPromptDlg->exec();
}
}
else
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentStr(tr("The password is wrong,please re-enter!"));//密码错误,请重新输入密码!
m_pPromptDlg->exec();
return;
}
}
else if(user == resetpara)
{
if (str == PASSWORD_RESETPARA)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
g_emUser = resetpara;
m_pPromptDlg->setContentStr(tr("reset parameters password successfully logged in!"));//重置参数密码成功登入!
m_pPromptDlg->exec();
emit siSetButtonUserLogo(2);
}
else
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentStr(tr("The password is wrong,please re-enter!"));//密码错误,请重新输入密码!
m_pPromptDlg->exec();
return;
}
}
}
}
//界面解密
void MainWidgetFunction::slotHMIDecrypt(QString id)
{
// 获取网卡号并输入序列号
m_pPromptDlg->initDialog(PromptDialog::BTN_HMI_DECRYPT);
m_pPromptDlg->setTitleStr(tr("HMI decrypt"));
m_pPromptDlg->setContentHMIDecryptShow(id);
if(m_pPromptDlg->exec() == 1)
{
QString inputStr = m_pPromptDlg->getInputPassword();
QByteArray inputAry = inputStr.toLatin1();
QString idStr = m_pPromptDlg->getNetworkCardID();
QByteArray idAry = idStr.toLatin1();
char inputBuf[20]; //输入的注册码
u8 idBuf[12]; //id号16进制字符串
memset(inputBuf,0,sizeof(inputBuf));
memset(idBuf,0,sizeof(idBuf));
memcpy(inputBuf,inputAry.data(),inputStr.toLatin1().length());
memcpy(idBuf,idAry.data(),idStr.toLatin1().length());
char outputBuf[20]; //生成的注册码
int num,i;
u8 anBuf[16],chanBuf[16];
memset(anBuf,0,sizeof(anBuf));
memset(chanBuf,0,sizeof(chanBuf));
memset(outputBuf,0,sizeof(outputBuf));
for(i = 0; i < 4; i++)
{
if((inputBuf[i] >= '0') && (inputBuf[i] <= '9'))
anBuf[i]=inputBuf[i] - '0';
else if((inputBuf[i] >= 'a') && (inputBuf[i] <= 'f'))
anBuf[i]=inputBuf[i] - 'a' + 10;
else if((inputBuf[i] >= 'A') && (inputBuf[i] <= 'F'))
anBuf[i]=inputBuf[i] - 'A' + 10;
else
break;
}
for(u16 i = 0; i < sizeof(idBuf);)
{
if((idBuf[i] >= '0') && (idBuf[i] <= '9'))
idBuf[i]=idBuf[i] - '0';
else if((idBuf[i] >= 'a') && (idBuf[i] <= 'f'))
idBuf[i]=idBuf[i] - 'a' + 10;
else if((idBuf[i] >= 'A') && (idBuf[i] <= 'F'))
idBuf[i]=idBuf[i] - 'A' + 10;
if((idBuf[i+1] >= '0') && (idBuf[i+1] <= '9'))
idBuf[i+1]=idBuf[i+1] - '0';
else if((idBuf[i+1] >= 'a') && (idBuf[i+1] <= 'f'))
idBuf[i+1]=idBuf[i+1] - 'a' + 10;
else if((idBuf[i+1] >= 'A') && (idBuf[i+1] <= 'F'))
idBuf[i+1]=idBuf[i+1] - 'A' + 10;
i += 2;
}
num=((u8)(anBuf[0]*16 + anBuf[1]))*256 + (u8)(anBuf[2]*16 + anBuf[3]);
anBuf[4]=(u8)(((idBuf[0] << 4) | idBuf[1]) + num) >> 4;
anBuf[5]=(u8)(((idBuf[0] << 4) | idBuf[1]) + num) & 0x0f;
anBuf[6]=(u8)(((idBuf[2] << 4) | idBuf[3]) + num) >> 4;
anBuf[7]=(u8)(((idBuf[2] << 4) | idBuf[3]) + num) & 0x0f;
anBuf[8]=(u8)(((idBuf[4] << 4) | idBuf[5]) + num) >> 4;
anBuf[9]=(u8)(((idBuf[4] << 4) | idBuf[5]) + num) & 0x0f;
anBuf[10]=(u8)(((idBuf[6] << 4) | idBuf[7]) + num) >> 4;
anBuf[11]=(u8)(((idBuf[6] << 4) | idBuf[7]) + num) & 0x0f;
anBuf[12]=(u8)(((idBuf[8] << 4) | idBuf[9]) + num) >> 4;
anBuf[13]=(u8)(((idBuf[8] << 4) | idBuf[9]) + num) & 0x0f;
anBuf[14]=(u8)(((idBuf[10] << 4) | idBuf[11]) + num) >> 4;
anBuf[15]=(u8)(((idBuf[10] << 4) | idBuf[11]) + num) & 0x0f;
chanBuf[0]=(u8)(anBuf[0]*16 + anBuf[1]);
chanBuf[1]=(u8)(anBuf[2]*16 + anBuf[3]);
chanBuf[2]=(u8)(anBuf[7]*16 + anBuf[9]);
chanBuf[3]=(u8)(anBuf[6]*16 + anBuf[8]);
chanBuf[4]=(u8)(anBuf[10]*16 + anBuf[15]);
chanBuf[5]=(u8)(anBuf[5]*16 + anBuf[11]);
chanBuf[6]=(u8)(anBuf[13]*16 + anBuf[4]);
chanBuf[7]=(u8)(anBuf[14]*16 + anBuf[12]);
//id号长度大于12以此类推
//chanbuf[8]=(u8)(anbuf[17]*16 + anbuf[16]);
//chanbuf[9]=(u8)(anbuf[19]*16 + anbuf[18]);
//chanbuf[10]=(u8)(anbuf[21]*16 + anbuf[20]);
sprintf(outputBuf,"%02x%02x%02x%02x%02x%02x%02x%02x",chanBuf[0],
chanBuf[1],chanBuf[2],chanBuf[3],chanBuf[4],chanBuf[5],chanBuf[6],chanBuf[7]);
QDir apppath(qApp->applicationDirPath());
QString HMIDecryptConfigfile;
HMIDecryptConfigfile = apppath.path() + apppath.separator() + "HMIDecryptConfig.ini";
QSettings iniSetting(HMIDecryptConfigfile, QSettings::IniFormat);
if( 0 == memcmp(inputBuf, outputBuf, sizeof(inputBuf)) ) // 比较两个缓存区内容是否相同(等于0相等)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("The interface program is licensed, and then take effect after restarting, please restart manually!");//界面程序授权成功,重启后生效,请手动重启!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
iniSetting.setValue("HMIDecrypt/ifdecrypt",1);
return;
}
else
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("Password error, interface program authorization failed!");//密码错误,界面程序授权失败!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
//iniSetting.setValue("HMIDecrypt/ifdecrypt",0);
return;
}
}
}
//平绣勾刀测试
void MainWidgetFunction::slotHookTest()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_HOOK_TEST);
m_pPromptDlg->setTitleStr(tr("Hook test"));//平绣勾刀
QString str;
str = tr("Hook the knife is about to move, please pay attention to safety!");//勾刀即将动作,请注意安全!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
}
void MainWidgetFunction::slotFootTest()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_FOOT_TEST);
m_pPromptDlg->setTitleStr(tr("Foot test"));//独立压脚测试
QString str;
str = tr("Foot is about to move, please pay attention to safety!");//压脚即将动作,请注意安全!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
}
//自动定软限位
void MainWidgetFunction::slotAutoSetSoftLimit()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Auto set softlimit"));//自动定软限位
QString str;
str = tr("The machine is about to move, please pay attention to safety!");//机器即将运动,请注意安全!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->autoSetSoftLimit();
slotCalMachineProgress(CSV_00_CODE_8);
}
}
}
//平绣主轴齿轮比测试
void MainWidgetFunction::slotEMBSpindleTest()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Emb Spindle Gear Ratio Test"));//平绣主轴齿轮比测试
QString str;
str = tr("Whether to test the gear ratio of the flat embroidery spindle?");//是否测试平绣主轴齿轮比?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->embSpindleTest();
}
}
}
//毛巾主轴齿轮比测试
void MainWidgetFunction::slotChenSpindleTest()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Chenille Spindle Gear Ratio Test"));//毛巾主轴齿轮比测试
QString str;
str = tr("Whether to test the gear ratio of the flat chenille spindle?");//是否测试平绣主轴齿轮比?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->chenSpindleTest();
}
}
}
//测试平绣主轴编码器宽度
void MainWidgetFunction::slotEcdWidthTest()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Flat Ecd Width Test"));//测试平绣主轴编码器宽度
QString str;
str = tr("Is the width of the flat spindle encoder tested?");//是否测试平绣主轴编码器宽度?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->ecdWidthTest();
}
}
}
//动框参数导入
void MainWidgetFunction::slotFrameParaImport()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Moving frame parameter import"));//动框参数导入
QString str;
str = tr("Whether to import movable frame parameters?");//是否动框参数导入?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
m_pSystemManageDlg->setTypeLogo("");
m_pSystemManageDlg->setMainTitle(tr("Frame parameter Import"));
m_pSystemManageDlg->setSubTitle(tr("Root > Frame Parameter Import"));
m_pSystemManageDlg->initDialog();
systemUpgrade(FRAMEPARA_IMPORT);
}
}
//动框参数导出
void MainWidgetFunction::slotFrameParaExport()
{
if (g_pMachine != NULL)
{
if(g_pMachine->isConnected() == 3)
{
g_pMachine->getInfoFromMachine();
}
else
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentStr(tr("No connection"));
m_pPromptDlg->exec();
return;
}
}
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Moving frame parameter export"));//动框参数导出
QString str;
str = tr("Whether to export moving frame parameters?");//是否动框参数导出?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
funExportFrameParameter();
}
}
//机头板总线检测
void MainWidgetFunction::slotHeadBoardBusDetect()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Head board bus detect"));//机头板总线检测
QString str;
str = tr("Do you perform head board bus detection?");//是否进行机头板总线检测?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->headBoardBusDetect();
}
}
}
//超级用户退出程序
void MainWidgetFunction::slotExitApp()
{
//是否退出程序
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Prompt"));//提示
QString str;
str = tr("Whether to exit the program?");//是否退出程序?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
QApplication* app;
app->exit(0);
}
}
//超级用户版本恢复
void MainWidgetFunction::slotVerRecovery()
{
//是否版本恢复
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Prompt"));//提示
QString str;
str = tr("Is the version restored?");//是否版本恢复?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
}
}
//超级用户修改一级密码
void MainWidgetFunction::slotChangePassword()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_CHANGE_PASSWORD);//修改一级密码界面
m_pPromptDlg->setTitleStr(tr("Modify the first level password"));
m_pPromptDlg->setContentChangePasswordShow();
if(m_pPromptDlg->exec() == 1)//点击确认按钮,确认修改密码
{
/*点击确定,首先检查编辑框中是否为空,然后检查两次输入的密码是否一致,
*/
QString n_pwd = m_pPromptDlg->getInputNewPassword();//新密码
QString rn_pwd = m_pPromptDlg->getInputConfirmPassword();//确认新密码
if(n_pwd != rn_pwd)
{
//新密码和确认密码不一致
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("The two passwords are inconsistent!");//新密码和确认密码不一致!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
}
else
{
g_passwordOne = n_pwd;//新的密码变成一级密码
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("Password reset complete!");//密码修改成功!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
g_pSettings->writeToIniFile("HMI/passwordOne",g_passwordOne);
}
}
}
//删除执行目录下的config.ini
void MainWidgetFunction::slotDeleteIni()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Prompt"));//提示
QString str;
str = tr("Do you delete the configuration file?");//是否删除配置文件?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
QDir apppath(qApp->applicationDirPath());
//配置文件路径
QString configfile;
configfile = apppath.path() + apppath.separator() + "config.ini";
QFile::remove(configfile);
QString HMIConfigfile;
HMIConfigfile = apppath.path() + apppath.separator() + "HMIConfig.ini";
QFile::remove(HMIConfigfile);
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("The settings take effect after restarting the interface!");//重启界面后设置生效!
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
#ifdef Q_OS_WIN
qApp->exit();
#endif
#ifdef Q_OS_LINUX
system("reboot");
#endif
}
}
}
//导入csv文件
void MainWidgetFunction::slotImportCSV()
{
QString usbPath = detectUsb();
if(usbPath.length() <= 0)
{
//优盘不存在
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("USB flash drive is not detected!");//未检测到优盘!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
return;
}
QString sPath = usbPath + CSV_PROGRESS;
QDir apppath(qApp->applicationDirPath());
QString tPath= apppath.absolutePath() + apppath.separator() + CSV_PROGRESS;
QFile::remove(tPath);
QFile::copy(sPath,tPath);
#ifdef Q_OS_LINUX
system("sync");
#endif
//成功导入csv文件
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("Import csv file successful!");//成功导入csv文件
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
}
//删除csv文件
void MainWidgetFunction::slotDeleteCSV()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Prompt"));//提示
QString str;
str = tr("Do you delete the csv file?");//是否删除csv文件
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
QDir apppath(qApp->applicationDirPath());
//配置文件路径
QString csvfile;
csvfile = apppath.path() + apppath.separator() + CSV_PROGRESS;
QFile::remove(csvfile);
#ifdef Q_OS_LINUX
system("sync");
#endif
}
}
//重置csv文件
void MainWidgetFunction::slotResetCSV()
{
m_csvFileStrList.clear();
QDir apppath(qApp->applicationDirPath());
QString path = apppath.path() + apppath.separator() + CSV_PROGRESS;
QFile file(path);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
qDebug() << "Open file failed!";
return;
}
QTextStream out(&file);
out.setCodec("GB2312"); //支持读取中文信息
//遍历行
for(int i = 0; !out.atEnd(); i++)
{
QString strLine = out.readLine();
if(strLine.size() <= 0)
{
continue;
}
QStringList strlist = strLine.split(",", QString::SkipEmptyParts); //根据","分隔开每行的列
if(COLUMN_PRESSNUM < strlist.size())
{
if(i != 0)
{
strlist[COLUMN_PRESSNUM] = "0";
}
QString str;
for(int m = 0; m < strlist.size(); m++)
{
str.append(strlist[m]);
if(m != strlist.size() - 1)
{
str.append(",");
}
}
m_csvFileStrList.append(str);
}
}
file.close();
QTextCodec::setCodecForLocale(QTextCodec::codecForName("GBK"));
QByteArray array;
array.clear();
for(int j = 0; j < m_csvFileStrList.size(); j++)
{
QString str = m_csvFileStrList[j];
array.append(str.toLocal8Bit());
if(j != m_csvFileStrList.size() - 1)
{
array.append('\n');
}
}
QFile wfile(path);
if (wfile.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text))
{
wfile.write(array);
#ifdef Q_OS_LINUX
system("sync");
#endif
}
wfile.close();
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
QString iniPath = apppath.path() + apppath.separator() + "config.ini";
QSettings setting(iniPath, QSettings::IniFormat);
setting.setValue("Progress/getScore",0);
m_getScore = 0;
//成功导入csv文件
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
QString str;
str = tr("Reset succeeded!");//重置成功!
m_pPromptDlg->setContentStr(str);
m_pPromptDlg->exec();
}
//毛巾提升电机控制
void MainWidgetFunction::slotLiftMotor()
{
int chenilleHeadNum = 0;
if(g_pMachine != NULL)
{
ParaStruct mcParaValues;
mcParaValues = g_pMachine->getMcPara();
chenilleHeadNum = mcParaValues.buf[8];//毛巾机头个数
}
m_pPromptDlg->initDialog(PromptDialog::BTN_LIFTMOTORCONTROL);
m_pPromptDlg->setTitleStr(tr("Lift Motor Control"));
m_pPromptDlg->initChenilleHead(chenilleHeadNum);
if (m_pPromptDlg->exec() == 0)//弹窗界面显示,点击了取消按钮,弹窗关闭
{
if(g_pMachine != NULL)
{
g_pMachine->testADC(0);//点击关闭按钮发退出测试电位器命令para2=0
}
}
}
//毛巾松紧线控制
void MainWidgetFunction::slotLElasticCtrl()
{
if(g_pMachine != NULL)
{
g_pMachine->testADC(2);
m_adcFlag = 1;
// emit siTestADC(m_adcFlag);
//测试电位器的标志
}
m_pPromptDlg->initDialog(PromptDialog::BTN_ELASTICCONTROL);
m_pPromptDlg->setTitleStr(tr("Slack Wire Control"));
if (m_pPromptDlg->exec() == 0)//弹窗界面显示,点击了取消按钮,弹窗关闭
{
if(g_pMachine != NULL)
{
g_pMachine->testADC(0);//点击关闭按钮发退出测试电位器命令para2=0
}
}
}
//毛巾换色调试
void MainWidgetFunction::slotChenilleColorDebug()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_M_C_C);
m_pPromptDlg->setTitleStr(tr("Chenille Color Change Debug"));
m_pPromptDlg->setCurNeedleStrVisible(true);//当前针杆label是否可见
m_pPromptDlg->initNeedleBar(PRODUCT_TOWEL);
if (m_pPromptDlg->exec() == 1)
{
s32 val = m_pPromptDlg->getNeedleSelectIdx();//获取所选针杆的索引值
if(g_pMachine != NULL)
{
g_pMachine->chenilleColorDebug(val);// 毛巾换色
}
}
}
//界面调试模式,调试模式时不需要密码 -rq
void MainWidgetFunction::slotDebugMode()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Prompt"));//提示
QString str;
if (g_emDebugMode == nodebugMode)
{
str = tr("Whether to enter debug mode?");//是否进入调试模式?
}
else
{
str = tr("whether to exit debug mode?");//是否退出调试模式?
}
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if (g_emDebugMode == nodebugMode)
{
g_emDebugMode = debugMode;
}
else //退出了调试模式
{
g_emDebugMode = nodebugMode;//全局的
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));//提示
QString str2;
str2 = tr("Please log in to super user again!");//请重新登录超级用户!
m_pPromptDlg->setContentStr(str2);
if(m_pPromptDlg->exec() == 1) //退出超级用户界面
{
emit siCloseRootPara();//关闭超级用户参数界面
}
}
g_pSettings->writeToInHMIiFile("HMI/debugMode",g_emDebugMode);//写入配置文件
emit siDebugState();//主界面接收信号,调试模式时,界面不需要密码,界面标题变红
}
}
//超级用户花样总清
void MainWidgetFunction::slotPatternClear()
{
//是否花样总清
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Prompt"));//提示
QString str;
str = tr("Is the pattern clear?");//是否花样总清?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{ //删除文件
QDir apppath(qApp->applicationDirPath());
QString targetDir = apppath.absolutePath() + apppath.separator();
QString tPath = targetDir + PATTERNPATH;
deleteDir(tPath);
}
}
void MainWidgetFunction:: deleteDir(QString tPath)
{
QDir dir(tPath);//项目中所保存的路径
dir.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot);//设置过滤
QFileInfoList fileList = dir.entryInfoList();// 获取所有的文件信息
foreach (QFileInfo file,fileList)//遍历文件信息
{
if (file.isFile()) //是文件,删除,文件夹也要删除
{
file.dir().remove(file.fileName());
}
else //递归删除
{
deleteDir(file.absoluteFilePath());
}
}
dir.rmpath(dir.absolutePath());
//检测是否删除
QDir dir1(tPath);
dir1.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot);//设置过滤
QFileInfoList fileList_1 = dir1.entryInfoList();//获取所有的文件信息
if(fileList_1.size() == 0)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentStr(tr("Delete complete!"));//删除完成!
m_pPromptDlg->exec();
emit siClearPattern();//清空当前选择的花样
return;
}
else
{
deleteDir(tPath);
// m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
// m_pPromptDlg->setTitleStr(tr("Prompt"));
// m_pPromptDlg->setContentStr(tr("Not cleaned up!"));//未清理完成!
// m_pPromptDlg->exec();
// return;
}
}
void MainWidgetFunction::slotPatternFcgClear()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Prompt"));//提示
QString str;
str = tr("Is the pattern Fcg clear?");//是否删除花样fcg文件
m_pPromptDlg->setContentStr(str);
//清除所有的fcg花样参数点了确认按钮才会生成新的fcg文件没有fcg文件时花样参数是默认值
if(m_pPromptDlg->exec() == 1)
{
//删除文件
QDir apppath(qApp->applicationDirPath());
QString targetDir = apppath.absolutePath() + apppath.separator();
QString tPath = targetDir + PATTERNPATH;
QDir dir(tPath);//项目中所保存的路径
dir.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot);//设置过滤
QFileInfoList fileList = dir.entryInfoList(QStringList()<<"*.fcg");// 获取.fcg的文件列表
foreach (QFileInfo file,fileList)//遍历文件信息
{
if (file.isFile()) //是文件,删除
{
file.dir().remove(file.fileName());
}
else //递归删除
{
// deleteDir(file.absoluteFilePath());
}
}
//检测是否删除
QDir dir1(tPath);
dir1.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot);//设置过滤
QFileInfoList fileList_1 = dir1.entryInfoList(QStringList()<<"*.fcg");//获取.fcg的文件信息
if(fileList_1.size() == 0)
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentStr(tr("Delete complete,please reselect the file!"));//删除完成,请重新选择文件!
m_pPromptDlg->exec();
emit siClearPatternFcg();//清空当前选择的花样
return;
}
else
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentStr(tr("Not cleaned up!"));//未清理完成!
m_pPromptDlg->exec();
return;
}
}
}
void MainWidgetFunction::slotPatternFcgClearFileid()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Prompt"));//提示
QString str;
str = tr("If reset the pattern Fcg data?");//是否重置花样fcg文件数据
m_pPromptDlg->setContentStr(str);
//重置所有的fcg数据
if(m_pPromptDlg->exec() == 1)
{
QDir apppath(qApp->applicationDirPath());
QString targetDir = apppath.absolutePath() + apppath.separator();
QString tPath = targetDir + PATTERNPATH;
QDir dir(tPath);//项目中所保存的路径
dir.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot);//设置过滤
QFileInfoList fileList = dir.entryInfoList(QStringList()<<"*.fcg");// 获取.fcg的文件列表
foreach (QFileInfo file,fileList)//遍历文件信息
{
if (file.isFile()) //是文件,重置
{
//优化不删除将影响fileid的属性置为默认
qDebug() <<"fileList=" <<file.filePath();
QString getTemp_filePath = file.filePath().left(file.filePath().length() - 4);
QString setTemp_filePath = file.filePath().left(file.filePath().length() - 4);
{
//xcy 20230223
DataFileHead temp_fileHead;
getPatternHeadConfig(getTemp_filePath,temp_fileHead);
temp_fileHead.rotateStyle = 0;
temp_fileHead.horizontalStyle = 0;
temp_fileHead.verticalStyle = 0;
temp_fileHead.rotateAngle = 0;
temp_fileHead.xZoom = 100;
temp_fileHead.yZoom = 100;
temp_fileHead.repeatStyle = 0;
temp_fileHead.priority = 0;
temp_fileHead.xRepeatNum = 1;
temp_fileHead.yRepeatNum = 1;
temp_fileHead.xRepeatSpace = 0;
temp_fileHead.yRepeatSpace = 0;
temp_fileHead.stepCompensation = 0;
temp_fileHead.xCompensate = 20;
temp_fileHead.yCompensate = 20;
temp_fileHead.lockNeedlesNum = 2;
temp_fileHead.lockNeedlesStepNum = 1;
temp_fileHead.lockNeedlesStepLength = 100;
temp_fileHead.minStep = 0;
setPatternHeadConfig(setTemp_filePath,temp_fileHead);
}
}
else //递归删除
{
// deleteDir(file.absoluteFilePath());
}
}
m_pPromptDlg->initDialog(PromptDialog::BTN_OK);
m_pPromptDlg->setTitleStr(tr("Prompt"));
m_pPromptDlg->setContentStr(tr("Reset complete,please reselect the file!"));//重置完成,请重新选择文件!
m_pPromptDlg->exec();
emit siAfterDeleteFileid();//清空当前选择的花样
return;
}
}
//win下关机按钮
void MainWidgetFunction::funShutDown()
{
//是否关闭计算机
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Prompt"));//提示
QString str;
str = tr("Whether to shut down the computer?");//是否关闭计算机?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
system("shutdown -s -t 00");//电脑关机
}
}
//自动换一个梭
void MainWidgetFunction::funChangeOneShuttle()
{
m_pPromptDlg->initDialog(PromptDialog::BTN_OK_CANCEL);
m_pPromptDlg->setTitleStr(tr("Prompt"));//提示
QString str;
str = tr("Whether to set to change a shuttle automatically?");//是否设置自动换一个梭?
m_pPromptDlg->setContentStr(str);
if(m_pPromptDlg->exec() == 1)
{
if(g_pMachine != NULL)
{
g_pMachine->changeOneShuttle();
}
}
}
// 改变弹窗位置
void MainWidgetFunction::moveDlgPos(void)
{
switch (g_emResolut)
{
case resolution1910:
m_pPromptDlg->move((1920-m_pPromptDlg->width())/2+g_mainWidgetPos.x(),(1080-m_pPromptDlg->height())/2+g_mainWidgetPos.y());
m_pBrokenLineDialog->move(192+g_mainWidgetPos.x(),62+g_mainWidgetPos.y());
m_pSystemManageDlg->move(g_mainWidgetPos.x(),g_mainWidgetPos.y());
m_pDebugInfoDlg->move(192+g_mainWidgetPos.x(),65+g_mainWidgetPos.y());
break;
case resolution1006:
m_pPromptDlg->move((1024-m_pPromptDlg->width())/2+g_mainWidgetPos.x(),(600-m_pPromptDlg->height())/2+g_mainWidgetPos.y());
m_pBrokenLineDialog->move(100+g_mainWidgetPos.x(),30+g_mainWidgetPos.y());
m_pSystemManageDlg->move(g_mainWidgetPos.x(),g_mainWidgetPos.y());
m_pDebugInfoDlg->move(101+g_mainWidgetPos.x(),36+g_mainWidgetPos.y());
default:
break;
}
}
#if(0)
void MainWidgetFunction::testBreakLineNeedle()
{
QTime randtime;
randtime = QTime::currentTime();
qsrand(randtime.msec()+randtime.second()*1000); //以当前时间ms为随机种子
int i = qrand() % 32; //产生32以内的随机整数
//float fn = float(n)/10; //产生10以内的随机浮点数精度为小数点后1位
int m_needleIdx = qrand() % 16; //产生32以内的随机整数
QString infoStrtest ;
infoStrtest.clear();
//xcy 0314 机头针位断线
//for(int i = 0; i < 32; i++)
{
if(m_needleIdx >= 1 && m_needleIdx <= 15)
{
int j = m_needleIdx - 1;
g_pSettings->writeToIniFile(("Head" + QString::number(i+1) + "NeedleBreakLine/needle" + QString::number(j+1)),m_headBreakLine.headNeedleBreakLine[i][j]++);
infoStrtest = tr("EmbBrokenLine Head :")+QString::number(i+1)+tr(";")+tr("")+tr("NeedleIdx:")+QString::number(m_needleIdx)+tr(" break line num: ") + QString::number(m_headBreakLine.headNeedleBreakLine[i][j]);//平绣断线机头6 ; 针位 2
}
}
g_pSettings->writeToCsv(infoStrtest,TYPE_BREAK);//保存到csv
}
#endif