diff --git a/mainwindow.cpp b/mainwindow.cpp index ed4d2f3..751bdab 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -3,6 +3,7 @@ #include "worker.h" #include "utils.h" #include "progress_event.h" +#include "update_dc_event.h" #include "plugins/interfaces.h" #include @@ -10,14 +11,102 @@ #include #include -MainWindow::MainWindow(hwinf *hw, Worker *worker, QWidget *parent) + + +#if EMERGENCY_LEAVE_BL==1 +static int step = 0; + +void MainWindow::emergencyLeaveBL() { + // + qCritical() << __func__ << step; + switch(step) { + case 0: + if (m_hw->dc_openSerial(5, "115200", "ttymxc2", 1)) { + qCritical() << __func__ << "open ok"; + step++; + QThread::msleep(2000); + m_hw->dc_autoRequest(false); + emit leaveBL(); + } + break; + case 1: + m_hw->bl_rebootDC(); + QThread::msleep(1000); + qCritical() << __func__ << "reboot ok" << QDateTime::currentDateTime().toString(Qt::ISODateWithMs); + step++; + emit leaveBL(); + break; + case 2: + case 3: + case 4: + case 5: + case 6: + m_hw->bl_startBL(); + QThread::msleep(1000); + qCritical() << __func__ << "start" << QDateTime::currentDateTime().toString(Qt::ISODateWithMs); + step++; + emit leaveBL(); + break; + case 7: + case 9: + case 11: + case 13: + case 15: + m_hw->bl_checkBL(); + qCritical() << __func__ << "check" << QDateTime::currentDateTime().toString(Qt::ISODateWithMs); + QThread::msleep(1500); + ++step; + emit leaveBL(); + break; + case 8: + case 10: + case 12: + case 14: + case 16: + qCritical() << __func__ << "is Up..." << QDateTime::currentDateTime().toString(Qt::ISODateWithMs); + if (m_hw->bl_isUp()) { + qCritical() << __func__ << "is Up...OK" << step << QDateTime::currentDateTime().toString(Qt::ISODateWithMs); + QThread::msleep(5000); + step = 16; + } else { + qCritical() << __func__ << "is Up...NO" << step << QDateTime::currentDateTime().toString(Qt::ISODateWithMs); + } + ++step; + emit leaveBL(); + break; + case 17: + case 18: + case 19: + qCritical() << __func__ << "stop" << QDateTime::currentDateTime().toString(Qt::ISODateWithMs); + m_hw->bl_stopBL(); + QThread::msleep(1000); + //m_hw->dc_closeSerial(); + ++step; + emit leaveBL(); + break; + } +} +#endif + +MainWindow::MainWindow(hwinf *hw, Worker *worker, Update *update, QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) , m_hw(hw) , m_worker(worker) , m_width(70) , m_progressRunning(false) - , m_progressValue(0) { + , m_progressValue(0) + , m_update(update) + , m_updateStep(UpdateDcEvent::UpdateStep::NONE) { + +#if EMERGENCY_LEAVE_BL==1 + QTimer *t = new QTimer(this); + connect(t, SIGNAL(timeout()), this, SLOT(emergencyLeaveBL())); + connect(this, SIGNAL(leaveBL()), this, SLOT(emergencyLeaveBL()), Qt::QueuedConnection); + t->setSingleShot(true); + t->start(1000); + return; +#endif this->setStatusBar(new QStatusBar(this)); QFont f;