#include #include "mainwindow.h" #include "ui_mainwindow.h" #include "Common/filemanage.h" #include "Common/mymessagebox.h" #include "qprocess.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); this->setGeometry(QRect(0,0,800,480)); upLoadBattery(); work_thread = new Work_Thread(); work_thread->start(); connect(work_thread,SIGNAL(SentInterface(int)),this,SLOT(UpdateInterface(int))); work_thread->localData.Interface = FACE_HOME; one_sub_window_exist = false; main_page_flag = false; countindex = 0; timedelay = 0; counttime = new QTimer(this); connect(counttime,SIGNAL(timeout()),this,SLOT(showtime())); counttime->setInterval(1000); Autobox = new MessageBox( this, QMessageBox::Question, MB_Caption, tr("是否进行续测?60秒后自动续测"), QMessageBox::Yes|QMessageBox::No); QTimer::singleShot(5000,this,SLOT(welcomeToMain())); #ifdef SOFT_ARM this->setWindowFlags(Qt::FramelessWindowHint); #endif connect(ui->pushButton_test,SIGNAL(pressed()),this,SLOT(btn_beep())); connect(ui->pushButton_data,SIGNAL(pressed()),this,SLOT(btn_beep())); connect(ui->pushButton_system,SIGNAL(pressed()),this,SLOT(btn_beep())); //connect(ui->pushButton_welcome,SIGNAL(pressed()),this,SLOT(btn_beep())); connect(ui->pushButton_welcome,SIGNAL(released()),this,SLOT(MainBtnAction())); connect(ui->pushButton_test,SIGNAL(released()),this,SLOT(MainBtnAction())); connect(ui->pushButton_data,SIGNAL(released()),this,SLOT(MainBtnAction())); connect(ui->pushButton_system,SIGNAL(released()),this,SLOT(MainBtnAction())); workpage = new Working_Page(this,work_thread); workpage->toHide(); rs485_tcp = new SlaveCtrl(workpage); rs485_tcp->start(); rs485pc = new SlavePC(workpage); rs485pc->start(); QProcess::startDetached("insmod /usr/test/8723ds.ko"); logoStrSet(); SystemTime(); } MainWindow::~MainWindow() { delete counttime; delete Autobox; delete ui; } void MainWindow::logoStrSet(void) { if(!ClassXML::ReadLOGOXml(logo)) { logo.LOGOEN = true; logo.ModelLogo = "IDCE-2415NT"; logo.MachineName = "蓄电池单体活化仪"; logo.CompanyCName = "福 州 福 光 电 子 有 限 公 司"; logo.CompanyEName = "FUZHOU FUGUANG ELECTRONICS Co.,LTD."; ClassXML::CreateLOGOXml(logo); } if(logo.MachineName == "使用图片") { ui->label_BG->setStyleSheet("border-image:url(/app/welcome.png);"); ui->label_logo->setText(logo.ModelLogo); ui->label_LOGO->setVisible(false); ui->label_Type->setVisible(false); ui->label_Name->setVisible(false); ui->label_CName->setVisible(false); ui->label_EName->setVisible(false); } else { ui->label_logo->setText(logo.ModelLogo); if(logo.LOGOEN) { ui->label_LOGO->setVisible(true); } else { ui->label_LOGO->setVisible(false); } ui->label_Type->setText(logo.ModelLogo); ui->label_Name->setText(logo.MachineName); ui->label_CName->setText(logo.CompanyCName); ui->label_EName->setText(logo.CompanyEName); } } void MainWindow::MainBtnAction() { //========================================================================== //将sender()强制类型转换为 QToolButton 指针 //sender()返回发送信号的对象的指针,所以必须与信号槽有关 //在这里,这是个槽,相关连的信号由button发送,所以返回触发这个槽的信号,也就是button值; QPushButton *pb = dynamic_cast(sender()); //========================================================================== if(ui->pushButton_test == pb) { if(true == one_sub_window_exist) { return; } work_thread->enterpage_init(); ui->label_test->setStyleSheet("color:white;"); Choose_Page *choose = new Choose_Page(this,work_thread); one_sub_window_exist = true; choose->execCustom(); one_sub_window_exist = false; if(work_thread->openWorkPage) { work_thread->openWorkPage = false; workpage->toShow(FACE_DIS); } } else if(ui->pushButton_data == pb) { if(true == one_sub_window_exist) { return; } ui->label_data->setStyleSheet("color:white;"); Data_Page *data = new Data_Page(this,work_thread); one_sub_window_exist = true; data->execCustom(); one_sub_window_exist = false; } else if(ui->pushButton_system == pb) { if(true == one_sub_window_exist) { return; } ui->label_system->setStyleSheet("color:white;"); SysSet_Page *sysset = new SysSet_Page(this,work_thread,rs485_tcp); one_sub_window_exist = true; sysset->execCustom(); one_sub_window_exist = false; } else if(ui->pushButton_welcome == pb) { welcomeToMain(); } } //************更新时间*****************// void MainWindow::SystemTime(void) { checkIcon(); QDateTime time = QDateTime::currentDateTime();//获取系统现在的时间 QString str = time.toString("yyyy-MM-dd hh:mm:ss"); //设置显示格式 ui->label_Time->setText(str); if(IF_RESTART){ if((countindex++) > 57){//60 30s work_thread->set_app_checkcount(); countindex = 0; } } QTimer::singleShot(500, this, SLOT(SystemTime())); } void MainWindow::checkIcon() { if(work_thread->iconState.monomerState){ if(work_thread->get_mon_source()==MONO_TYPE_WIRED) { ui->label_MON->setStyleSheet("image: url(:/new/prefix1/1.png);"); } else { if(mon_use_type == 2) ui->label_MON->setStyleSheet("border-image: url(:/new/prefix1/lora_mon.png);"); else ui->label_MON->setStyleSheet("border-image: url(:/new/prefix1/mon.png);"); } } else ui->label_MON->setStyleSheet(""); if(work_thread->iconState.usbState) ui->label_USB->setPixmap(QPixmap(":new/prefix1/usb.png")); else ui->label_USB->setPixmap(QPixmap("")); if(work_thread->iconState.wifiState) ui->label_WIFI->setStyleSheet("border-image: url(:/new/prefix1/wificonnect.png);"); else ui->label_WIFI->setStyleSheet(""); } void MainWindow::btn_beep(void) { BuzzerDrv BD; BD.BuzzerBeep(50); QPushButton *pb = dynamic_cast(sender()); //========================================================================== if(ui->pushButton_test == pb) { ui->label_test->setStyleSheet("color:yellow;"); } else if(ui->pushButton_data == pb) { ui->label_data->setStyleSheet("color:yellow;"); } else if(ui->pushButton_system == pb) { ui->label_system->setStyleSheet("color:yellow;"); } } void MainWindow::welcomeToMain(void) { if(!main_page_flag) //未点击屏幕,自动进入主界面 { main_page_flag = true; BuzzerDrv BD; BD.BuzzerBeep(50); WidgetHorizontalScroll(ui->widget_3,1); QTimer::singleShot(100,this,SLOT(checkROM())); if(IF_RESTART) continuetestCheck(); else work_thread->set_ifinit(true); } } void MainWindow::checkROM(void) { int filecount = filemanage->FindLocalFileFromPath(dataDir,dataType); if(filecount>=MaxDataNum) popBox(tr("内存已满,请及时清理!")); } void MainWindow::upLoadBattery() { TEST_PARAM_XML test_param_xml; #if PageType == FBI48CT //FBI机型没有放电模式,但有充电功能,需把test_mode置为ONline_working test_param_xml.test_mode = ONline_working; #else test_param_xml.test_mode = OFFline_working; #endif test_param_xml.acstop_op = ACOFF_CONTINUE; test_param_xml.nominal_cap = 1000; test_param_xml.hourly_rate = 10; test_param_xml.preset_cur = 100; test_param_xml.preset_cap = 1000; test_param_xml.preset_time = 600; test_param_xml.mon_vol = 20; test_param_xml.mon_lower = 180; test_param_xml.group_lower = VolTooLow; test_param_xml.mon_number = 108; test_param_xml.group_number = 1; test_param_xml.lower_number = 1; test_param_xml.onlinevol_lowlimit = onlinevollow; test_param_xml.booster_ceiling = 552; test_param_xml.charge_limit = 300; test_param_xml.temp_High = 500; test_param_xml.discharge_mode = 0; test_param_xml.preset_power = MinPower; ClassXML::CreateTestParamXml(Default_Battery,test_param_xml); } void MainWindow::WidgetHorizontalScroll(QWidget *widget, int index) { QPropertyAnimation *animation = new QPropertyAnimation(widget, "geometry"); animation->setDuration(10); QRect rect = widget->geometry(); animation->setEndValue(QRect((0-index)*800, rect.y(), widget->width(), widget->height())); animation->start(QPropertyAnimation::DeleteWhenStopped); } //************告警窗口*****************// void MainWindow::popBox(QString msg) { MessageBox box( this, QMessageBox::Warning,MB_Caption, msg, QMessageBox::Ok, QMessageBox::Ok, work_thread); box.exec(); } void MainWindow::UpdateInterface(int interface) { if(work_thread->localData.Interface != interface) { switch(work_thread->localData.Interface) { case FACE_CHAR: case FACE_DIS: workpage->toHide(); one_sub_window_exist = false; break; default: one_sub_window_exist = false; break; } } if(interface == FACE_DIS) { if(work_thread->iconState.wifiState) work_thread->enterpage_init(); workpage->toShow(FACE_DIS); } else if(interface == FACE_CHAR) { if(work_thread->iconState.wifiState) work_thread->enterpage_init(); workpage->toShow(FACE_CHAR); } } void MainWindow::continuetestCheck(){ CHECK_DATA check_data; int page_index = FACE_HOME; if(Check_Obj::RTest_Data(check_data)){//读取成功 if(check_data.workstate!=WorkStopped){ if(check_data.workstate == Charging || check_data.workstate == Paused_charge){ page_index = FACE_CHAR; } else { page_index = FACE_DIS; } } else { work_thread->setPowerCtrl(POWER_CTRL_INIT); work_thread->set_ifinit(true); } } else {//读取失败 work_thread->setPowerCtrl(POWER_CTRL_INIT); work_thread->set_ifinit(true); } if(page_index != FACE_HOME){ // qDebug()<<"工作状态:"<localData.Work_State; if(work_thread->localData.Work_State == 0){//接触器已断开 // qDebug()<<"接触器已断开"; work_thread->setPowerCtrl(POWER_CTRL_INIT); if(check_data.workstate == Discharging || (check_data.workstate == Paused_charge && PageType!=IDCE48CT && check_data.alarmstate!=CPPauseNullCharging)|| check_data.workstate == Paused_Dischg || check_data.workstate == WaitForCharging || (check_data.workstate == Charging && check_data.alarmstate != CPNullCharging)){ work_thread->RecvSysCtrlCMD(work_thread->CMD_StartFanWork,NULL);//开风扇 if(check_data.workstate == Discharging) work_thread->ctrlJDQ(); } work_thread->set_ifinit(true); Autobox->setText(tr("是否进行续测?60秒后自动续测")); Autobox->set_yes_btn_text(false,(tr("是(")+QString::number(5-timedelay)+")")); counttime->start(); Autobox->exec(); if(Autobox == NULL)//不点击自动进入 { FBO_DATA fbo_data; if(Check_Obj::Read_Fbo_Data(check_data.testfilename,fbo_data)){ UpdateInterface(page_index); workpage->ContinueTest(check_data,fbo_data); } } else { counttime->stop();//2019-12-17 if(Autobox->result()!=QMessageBox::Yes) { check_data.workstate = WorkStopped; Check_Obj::MTest_Data(check_data,false); FBO_DATA fbo_data; if(Check_Obj::Read_Fbo_Data(check_data.testfilename,fbo_data)){ work_thread->WriteEndFile(check_data.testfilename,fbo_data); } } else { FBO_DATA fbo_data; if(Check_Obj::Read_Fbo_Data(check_data.testfilename,fbo_data)){ UpdateInterface(page_index); workpage->ContinueTest(check_data,fbo_data); } } } } else {//接触器未断开,直接开始 // qDebug()<<"接触器未断开,直接开始"; work_thread->setPowerCtrl(check_data.PowerCtrl); work_thread->set_ifinit(false); FBO_DATA fbo_data; if(Check_Obj::Read_Fbo_Data(check_data.testfilename,fbo_data)){ UpdateInterface(page_index); workpage->ContinueTest(check_data,fbo_data); } work_thread->set_ifinit(true); } } } void MainWindow::showtime() { if(timedelay == 59) { counttime->stop(); Autobox->accept(); Autobox = NULL; return; } Autobox->setText(tr("是否进行续测?")+QString::number(59-timedelay)+tr("秒后自动续测")); if(timedelay<=3){ Autobox->set_yes_btn_text(false,(tr("是(")+QString::number(4-timedelay)+")")); } else { Autobox->set_yes_btn_text(true,tr("是")); Autobox->setDefaultButton(QMessageBox::Yes); } timedelay++; }