Browse Source

add fwupdate. not complete.

yuchuli 1 year ago
parent
commit
d6cf842ce2

+ 11 - 0
src/tool/server_fwupdate/main.cpp

@@ -0,0 +1,11 @@
+#include "mainwindow.h"
+#include <QApplication>
+
+int main(int argc, char *argv[])
+{
+    QApplication a(argc, argv);
+    MainWindow w;
+    w.show();
+
+    return a.exec();
+}

+ 114 - 0
src/tool/server_fwupdate/mainwindow.cpp

@@ -0,0 +1,114 @@
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+
+MainWindow::MainWindow(QWidget *parent) :
+    QMainWindow(parent),
+    ui(new Ui::MainWindow)
+{
+    ui->setupUi(this);
+
+    m_tcpserverFW = new QTcpServer(this);
+    m_tcpserverFW->listen(QHostAddress::Any,19100);//监听的端口号
+    m_tcpserverFW->setMaxPendingConnections(2000);
+    connect(m_tcpserverFW,SIGNAL(newConnection()), this,SLOT(newfwupdateConnect()));
+}
+
+MainWindow::~MainWindow()
+{
+    delete ui;
+}
+
+
+void MainWindow::newfwupdateConnect()
+{
+    qDebug("new connect");
+    QTcpSocket * pSocket = m_tcpserverFW->nextPendingConnection();
+    if(pSocket != NULL)
+    {
+        pSocket->setSocketOption(QAbstractSocket::LowDelayOption,1);
+        connect(pSocket,SIGNAL(readyRead()),this,SLOT(readfwupdateMessage()));
+        connect(pSocket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(errorfwupdate()));
+        connect(pSocket,SIGNAL(disconnected()),this,SLOT(disconnetfwupdate()));
+        std::shared_ptr<fwupdateClient> p = std::shared_ptr<fwupdateClient>( new fwupdateClient);
+        p->mnState = 0;
+        p->mpSocket = pSocket;
+
+//        p->mLat = 0;
+//        p->mLon = 0;
+        mMutex.lock();
+        mvectorFC.push_back(p);
+        mMutex.unlock();
+//        mnNCCount++;
+    }
+    else
+    {
+    }
+}
+
+void MainWindow::readfwupdateMessage()
+{
+    QTcpSocket * pSocket = static_cast<QTcpSocket *>(this->sender());
+    QByteArray ba = pSocket->readAll();
+    int i;
+    bool bNeedClose = false;
+    mMutex.lock();
+    for(i=0;i<mvectorFC.size();i++)
+    {
+        if(pSocket == mvectorFC.at(i)->mpSocket)
+        {
+            //Send Auth.
+
+            char * strSend = new char[1000];
+            int nauth = 1;
+            memcpy(strSend,&nauth,sizeof(int));
+            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;
+            strSend[nsend] = 0;
+
+            pSocket->write(strSend,nsend);
+            pSocket->flush();
+
+
+
+        }
+    }
+    mMutex.unlock();
+    if(bNeedClose )
+    {
+        pSocket->close();
+    }
+}
+
+void MainWindow::errorfwupdate()
+{
+    QTcpSocket * pSocket = static_cast<QTcpSocket *>(this->sender());
+    mMutex.lock();
+    int i;
+    for(i=0;i<mvectorFC.size();i++)
+    {
+        if(pSocket == mvectorFC.at(i)->mpSocket)
+        {
+            mvectorFC.erase(mvectorFC.begin()+i);
+  //            mnNCCount--;
+        }
+    }
+    mMutex.unlock();
+}
+
+void MainWindow::disconnetfwupdate()
+{
+    qDebug("disconnect");
+    QTcpSocket * pSocket = static_cast<QTcpSocket *>(this->sender());
+    mMutex.lock();
+    int i;
+    for(i=0;i<mvectorFC.size();i++)
+    {
+        if(pSocket == mvectorFC.at(i)->mpSocket)
+        {
+             mvectorFC.erase(mvectorFC.begin()+i);
+        }
+    }
+    mMutex.unlock();
+}

+ 50 - 0
src/tool/server_fwupdate/mainwindow.h

@@ -0,0 +1,50 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+#include <QTcpServer>
+#include <vector>
+#include <memory>
+#include <mutex>
+#include <QTcpSocket>
+
+namespace Ui {
+class MainWindow;
+}
+
+class fwupdateClient
+{
+public:
+    int mnState;
+    QTcpSocket * mpSocket;
+};
+
+class MainWindow : public QMainWindow
+{
+    Q_OBJECT
+
+public:
+    explicit MainWindow(QWidget *parent = 0);
+    ~MainWindow();
+
+private slots:
+
+    void newfwupdateConnect();
+    void readfwupdateMessage();
+    void errorfwupdate();
+    void disconnetfwupdate();
+
+private:
+    Ui::MainWindow *ui;
+
+
+    std::vector<std::shared_ptr<fwupdateClient >> mvectorFC;
+
+    std::mutex mMutex;
+
+    QTcpServer * m_tcpserverFW;
+
+};
+
+#endif // MAINWINDOW_H

+ 24 - 0
src/tool/server_fwupdate/mainwindow.ui

@@ -0,0 +1,24 @@
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow" >
+  <property name="geometry" >
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle" >
+   <string>MainWindow</string>
+  </property>
+  <widget class="QMenuBar" name="menuBar" />
+  <widget class="QToolBar" name="mainToolBar" />
+  <widget class="QWidget" name="centralWidget" />
+  <widget class="QStatusBar" name="statusBar" />
+ </widget>
+ <layoutDefault spacing="6" margin="11" />
+ <pixmapfunction></pixmapfunction>
+ <resources/>
+ <connections/>
+</ui>

+ 36 - 0
src/tool/server_fwupdate/server_fwupdate.pro

@@ -0,0 +1,36 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2023-08-25T08:11:34
+#
+#-------------------------------------------------
+
+QT       += core gui  network
+
+
+
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+
+TARGET = server_fwupdate
+TEMPLATE = app
+
+# The following define makes your compiler emit warnings if you use
+# any feature of Qt which has been marked as deprecated (the exact warnings
+# depend on your compiler). Please consult the documentation of the
+# deprecated API in order to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+
+# You can also make your code fail to compile if you use deprecated APIs.
+# In order to do so, uncomment the following line.
+# You can also select to disable deprecated APIs only up to a certain version of Qt.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
+
+
+SOURCES += \
+        main.cpp \
+        mainwindow.cpp
+
+HEADERS += \
+        mainwindow.h
+
+FORMS += \
+        mainwindow.ui

+ 11 - 0
src/tool/tool_fwupdate/main.cpp

@@ -0,0 +1,11 @@
+#include "mainwindow.h"
+#include <QApplication>
+
+int main(int argc, char *argv[])
+{
+    QApplication a(argc, argv);
+    MainWindow w;
+    w.show();
+
+    return a.exec();
+}

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

@@ -0,0 +1,111 @@
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+
+MainWindow::MainWindow(QWidget *parent) :
+    QMainWindow(parent),
+    ui(new Ui::MainWindow)
+{
+    ui->setupUi(this);
+
+    socket_ = new QTcpSocket(this);
+//    socket_->connectToHost("rtk.ntrip.qxwz.com",8002);
+    connect(socket_, SIGNAL(connected()), this, SLOT(connectedSlot()));
+    connect(socket_, SIGNAL(disconnected()), this, SLOT(disconnectedSlot()));
+    connect(socket_, SIGNAL(readyRead()), this, SLOT(readyReadSlot()));
+    connect(socket_, SIGNAL(error(QAbstractSocket::SocketError)), this,
+            SLOT(errorSlot(QAbstractSocket::SocketError)));
+}
+
+MainWindow::~MainWindow()
+{
+    delete ui;
+}
+
+void MainWindow::on_pushButton_Update_clicked()
+{
+    ui->pushButton_Update->setEnabled(false);
+    ui->plainTextEdit->setPlainText("Connecting server...");
+
+    socket_->connectToHost("127.0.0.1",19100);
+
+}
+
+void MainWindow::connectedSlot()
+{
+    if(socket_->state() == QAbstractSocket::ConnectedState)
+    {
+        qDebug("main is connected.\n");
+
+        char strsen[100];
+        socket_->write(strsen,100);
+        socket_->flush();
+    }
+    else
+    {
+        qDebug("main is not connected.\n");
+    }
+    isConnected_ = true;
+}
+
+void MainWindow::disconnectedSlot()
+{
+//    qDebug("connect server fail.");
+    isConnected_ = false;
+    socket_->close();
+
+
+
+}
+
+void MainWindow::readyReadSlot()
+{
+    char * str;
+
+    QByteArray message = socket_->readAll();
+
+    char * strbuff = new char[1000];
+    if((message.size()<1000)&&(message.size()>5))
+    {
+        int nauth;
+        char strdownname[1000];
+        memcpy(&nauth,message.data(),sizeof(int));
+        memcpy(strdownname,message.data()+sizeof(int),(message.size()-sizeof(int)));
+        strdownname[message.size()-sizeof(int)] = 0;
+        if(nauth == 0)
+        {
+            ui->plainTextEdit->setPlainText(strdownname);
+            ui->pushButton_Update->setEnabled(true);
+        }
+        else
+        {
+            strncpy(mstrdownname,strdownname,1000);
+            ui->plainTextEdit->setPlainText("Down File....");
+
+        }
+
+
+
+    }
+    else
+    {
+        ui->plainTextEdit->setPlainText("Reply fail.");
+        ui->pushButton_Update->setEnabled(false);
+    }
+
+
+
+    socket_->close();
+//    qDebug(message.data());
+
+
+
+}
+
+void MainWindow::errorSlot(QAbstractSocket::SocketError)
+{
+//    QMessageBox::information(this, "show", socket_->errorString());
+    disconnectedSlot();
+    ui->plainTextEdit->setPlainText("Connect Server Fail.");
+    ui->pushButton_Update->setEnabled(true);
+}
+

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

@@ -0,0 +1,39 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+#include <QNetworkDatagram>
+#include <QtNetwork/QTcpSocket>
+
+namespace Ui {
+class MainWindow;
+}
+
+class MainWindow : public QMainWindow
+{
+    Q_OBJECT
+
+public:
+    explicit MainWindow(QWidget *parent = 0);
+    ~MainWindow();
+
+private slots:
+    void on_pushButton_Update_clicked();
+
+    void connectedSlot();
+    void disconnectedSlot();
+    void readyReadSlot();
+    void errorSlot(QAbstractSocket::SocketError);
+
+private:
+    Ui::MainWindow *ui;
+
+    QTcpSocket *socket_;
+    bool isConnected_;
+
+    char mstrdownname[1000];
+
+};
+
+#endif // MAINWINDOW_H

+ 77 - 0
src/tool/tool_fwupdate/mainwindow.ui

@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>582</width>
+    <height>383</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>MainWindow</string>
+  </property>
+  <widget class="QWidget" name="centralWidget">
+   <widget class="QPushButton" name="pushButton_Update">
+    <property name="geometry">
+     <rect>
+      <x>80</x>
+      <y>20</y>
+      <width>131</width>
+      <height>61</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string>Update</string>
+    </property>
+   </widget>
+   <widget class="QProgressBar" name="progressBar">
+    <property name="geometry">
+     <rect>
+      <x>80</x>
+      <y>220</y>
+      <width>421</width>
+      <height>61</height>
+     </rect>
+    </property>
+    <property name="value">
+     <number>24</number>
+    </property>
+   </widget>
+   <widget class="QPlainTextEdit" name="plainTextEdit">
+    <property name="geometry">
+     <rect>
+      <x>80</x>
+      <y>100</y>
+      <width>421</width>
+      <height>101</height>
+     </rect>
+    </property>
+   </widget>
+  </widget>
+  <widget class="QMenuBar" name="menuBar">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>582</width>
+     <height>28</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QToolBar" name="mainToolBar">
+   <attribute name="toolBarArea">
+    <enum>TopToolBarArea</enum>
+   </attribute>
+   <attribute name="toolBarBreak">
+    <bool>false</bool>
+   </attribute>
+  </widget>
+  <widget class="QStatusBar" name="statusBar"/>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <resources/>
+ <connections/>
+</ui>

+ 36 - 0
src/tool/tool_fwupdate/tool_fwupdate.pro

@@ -0,0 +1,36 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2023-08-25T08:33:29
+#
+#-------------------------------------------------
+
+QT       += core gui
+
+QT += network
+
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+
+TARGET = tool_fwupdate
+TEMPLATE = app
+
+# The following define makes your compiler emit warnings if you use
+# any feature of Qt which has been marked as deprecated (the exact warnings
+# depend on your compiler). Please consult the documentation of the
+# deprecated API in order to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+
+# You can also make your code fail to compile if you use deprecated APIs.
+# In order to do so, uncomment the following line.
+# You can also select to disable deprecated APIs only up to a certain version of Qt.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
+
+
+SOURCES += \
+        main.cpp \
+        mainwindow.cpp
+
+HEADERS += \
+        mainwindow.h
+
+FORMS += \
+        mainwindow.ui