Browse Source

change fwupdate.

yuchuli 1 year ago
parent
commit
0f6883bc01

+ 3 - 1
src/tool/server_fwupdate/mainwindow.cpp

@@ -11,6 +11,8 @@ MainWindow::MainWindow(QWidget *parent) :
     m_tcpserverFW->listen(QHostAddress::Any,19100);//监听的端口号
     m_tcpserverFW->setMaxPendingConnections(2000);
     connect(m_tcpserverFW,SIGNAL(newConnection()), this,SLOT(newfwupdateConnect()));
+
+    setWindowTitle("Shenlan Firmware update auth server.");
 }
 
 MainWindow::~MainWindow()
@@ -64,7 +66,7 @@ void MainWindow::readfwupdateMessage()
             char strdownname[256];
             snprintf(strdownname,256,"shenlan_v2_fw.zip");
             memcpy(strSend + sizeof(int),strdownname,strnlen(strdownname,256));
-            int nsend = sizeof(int) + strnlen(strdownname,256) + 1;
+            int nsend = sizeof(int) + strnlen(strdownname,256) ;
             strSend[nsend] = 0;
 
             pSocket->write(strSend,nsend);

+ 101 - 0
src/tool/tool_fwupdate/mainwindow.cpp

@@ -1,6 +1,8 @@
 #include "mainwindow.h"
 #include "ui_mainwindow.h"
 
+#include <QFile>
+
 MainWindow::MainWindow(QWidget *parent) :
     QMainWindow(parent),
     ui(new Ui::MainWindow)
@@ -14,6 +16,12 @@ MainWindow::MainWindow(QWidget *parent) :
     connect(socket_, SIGNAL(readyRead()), this, SLOT(readyReadSlot()));
     connect(socket_, SIGNAL(error(QAbstractSocket::SocketError)), this,
             SLOT(errorSlot(QAbstractSocket::SocketError)));
+
+    mpTimer = new QTimer(this);
+    connect(mpTimer,SIGNAL(timeout()),this,SLOT(onTimer()));
+    mpTimer->start(100);
+
+    setWindowTitle("Firmware Update");
 }
 
 MainWindow::~MainWindow()
@@ -81,6 +89,12 @@ void MainWindow::readyReadSlot()
             strncpy(mstrdownname,strdownname,1000);
             ui->plainTextEdit->setPlainText("Down File....");
 
+            int64_t nnow = std::chrono::system_clock::now().time_since_epoch().count();
+            snprintf(mstrfilename,256,"%lld.zip",nnow);
+            snprintf(mstrlogname,256,"%lld.log",nnow);
+
+            mnState = 1;
+
         }
 
 
@@ -109,3 +123,90 @@ void MainWindow::errorSlot(QAbstractSocket::SocketError)
     ui->pushButton_Update->setEnabled(true);
 }
 
+void MainWindow::threadunzip()
+{
+    char * strhome = getenv("HOME");
+    char strshell[1000];
+    snprintf(strshell,1000,"unzip -o %s -d %s; rm %s;rm %s,cd %s; unzip -o app.zip -d .;rm app.zip; rm frp.zip; ",
+             mstrfilename,strhome,mstrfilename,mstrlogname,strhome);
+    system(strshell);
+    std::cout<<strshell<<std::endl;
+    mbunzipcomplete = true;
+}
+
+void MainWindow::onTimer()
+{
+    if(mnState == 1)
+    {
+
+        char strshell[1000];
+        snprintf(strshell,256,"wget -b -O %s http://116.63.46.168:19000/%s -o %s",mstrfilename,mstrdownname,mstrlogname);
+        std::cout<<strshell<<std::endl;
+
+        system(strshell);
+
+        mnState = 2;
+        ui->progressBar->setValue(0);
+
+    }
+
+    if(mnState == 3)
+    {
+        mbunzipcomplete = false;
+        mpthread = new std::thread(&MainWindow::threadunzip,this);
+
+        mnState = 4;
+    }
+
+    if(mnState == 4)
+    {
+        if(mbunzipcomplete)
+        {
+            QMessageBox::information(this,"Update","Update Complete",QMessageBox::YesAll);
+            mnState = 0;
+//            ui->pushButton_Update->setEnabled(true);
+        }
+    }
+
+    if(mnState == 2)
+    {
+        QFile xFile;
+//        snprintf(mstrlogname,256,"1692931161205695836.log");
+//        snprintf(mstrfilename,256,"1692931161205695836.zip");
+        xFile.setFileName(mstrlogname);
+        bool bProcOK = false;
+        int nProc = 0;
+        if(xFile.open(QIODevice::ReadOnly))
+        {
+            QByteArray ba;
+            ba = xFile.readLine(3000);
+            while(ba.size()>0)
+            {
+
+                QString strline(ba);
+                int index = strline.indexOf("........");
+                if((index > 0) &&(strline.size()>60))
+                {
+                    QString strproc =strline.mid(index + 54,3);
+                    nProc = strproc.toInt();
+                    bProcOK = true;
+                }
+                ba = xFile.readLine(3000);
+            }
+            if(bProcOK)
+            {
+                ui->progressBar->setValue(nProc);
+
+                if(nProc == 100)
+                {
+                    mnState = 3;
+                    ui->plainTextEdit->setPlainText("Unzip File.");
+                }
+
+
+            }
+
+            xFile.close();
+        }
+    }
+}

+ 21 - 0
src/tool/tool_fwupdate/mainwindow.h

@@ -6,6 +6,13 @@
 #include <QNetworkDatagram>
 #include <QtNetwork/QTcpSocket>
 
+#include <QTimer>
+
+#include <thread>
+#include <iostream>
+
+#include <QMessageBox>
+
 namespace Ui {
 class MainWindow;
 }
@@ -26,6 +33,8 @@ private slots:
     void readyReadSlot();
     void errorSlot(QAbstractSocket::SocketError);
 
+    void onTimer();
+
 private:
     Ui::MainWindow *ui;
 
@@ -34,6 +43,18 @@ private:
 
     char mstrdownname[1000];
 
+    char mstrfilename[256];
+    char mstrlogname[256];
+
+    int mnState = 0;
+
+    QTimer * mpTimer;
+
+    void threadunzip();
+    bool mbunzipcomplete = false;
+
+    std::thread * mpthread;
+
 };
 
 #endif // MAINWINDOW_H