Browse Source

add driver_service_maintain for maintain service. use frp and nomachane for remote login agx in autonomous car for develop. not complete.

yuchuli 2 years ago
parent
commit
8ad0a1a147

+ 1 - 1
src/detection/detection_lidar_pointpillars_cuda/src/pointpillar.cpp

@@ -62,7 +62,7 @@ TRT::TRT(std::string modelFile, cudaStream_t stream):stream_(stream)
     // define config
     auto networkConfig = builder->createBuilderConfig();
 #if defined (__arm64__) || defined (__aarch64__) 
-//    networkConfig->setFlag(nvinfer1::BuilderFlag::kFP16);
+    networkConfig->setFlag(nvinfer1::BuilderFlag::kFP16);
     std::cout << "Enable fp16!" << std::endl;
 #endif
     // set max batch size

+ 73 - 0
src/driver/driver_service_maintain/.gitignore

@@ -0,0 +1,73 @@
+# This file is used to ignore files which are generated
+# ----------------------------------------------------------------------------
+
+*~
+*.autosave
+*.a
+*.core
+*.moc
+*.o
+*.obj
+*.orig
+*.rej
+*.so
+*.so.*
+*_pch.h.cpp
+*_resource.rc
+*.qm
+.#*
+*.*#
+core
+!core/
+tags
+.DS_Store
+.directory
+*.debug
+Makefile*
+*.prl
+*.app
+moc_*.cpp
+ui_*.h
+qrc_*.cpp
+Thumbs.db
+*.res
+*.rc
+/.qmake.cache
+/.qmake.stash
+
+# qtcreator generated files
+*.pro.user*
+
+# xemacs temporary files
+*.flc
+
+# Vim temporary files
+.*.swp
+
+# Visual Studio generated files
+*.ib_pdb_index
+*.idb
+*.ilk
+*.pdb
+*.sln
+*.suo
+*.vcproj
+*vcproj.*.*.user
+*.ncb
+*.sdf
+*.opensdf
+*.vcxproj
+*vcxproj.*
+
+# MinGW generated files
+*.Debug
+*.Release
+
+# Python byte code
+*.pyc
+
+# Binaries
+# --------
+*.dll
+*.exe
+

+ 34 - 0
src/driver/driver_service_maintain/driver_service_maintain.pro

@@ -0,0 +1,34 @@
+QT -= gui
+
+QT += network
+
+CONFIG += c++11 console
+CONFIG -= app_bundle
+
+# The following define makes your compiler emit warnings if you use
+# any Qt feature that has been marked 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 it uses 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 \
+        service_maintain.cpp
+
+# Default rules for deployment.
+qnx: target.path = /tmp/$${TARGET}/bin
+else: unix:!android: target.path = /opt/$${TARGET}/bin
+!isEmpty(target.path): INSTALLS += target
+
+!include(../../../include/common.pri ) {
+    error( "Couldn't find the common.pri file!" )
+}
+
+HEADERS += \
+    service_maintain.h
+

+ 44 - 0
src/driver/driver_service_maintain/main.cpp

@@ -0,0 +1,44 @@
+#include <QCoreApplication>
+
+#include "xmlparam.h"
+
+#include "service_maintain.h"
+
+#include <iostream>
+
+void LoadParam(std::string strxmlpath,iv::service_maintain_param & xparam)
+{
+    iv::xmlparam::Xmlparam xp(strxmlpath);
+    xparam.mstrserverip = xp.GetParam("server_addr","116.63.46.168");
+    xparam.mstrserverport = xp.GetParam("server_port","9000");
+    xparam.mstrtoken = xp.GetParam("token","12345678");
+    xparam.mstrnomachineport = xp.GetParam("local_port","4000");
+    xparam.mstrfrpcfolder = xp.GetParam("frpfolder","/home/nvidia/frp");
+    xparam.mstrlistenport = xp.GetParam("listenport","60009");
+}
+
+
+
+int main(int argc, char *argv[])
+{
+    QCoreApplication a(argc, argv);
+
+    std::string strparapath;
+    if(argc<2)
+    {
+        strparapath = "./driver_service_maintain.xml";
+    }
+    else
+    {
+        strparapath = argv[2];
+    }
+
+    iv::service_maintain_param xparam;
+
+    LoadParam(strparapath,xparam);
+
+    service_maintain servicem(xparam);
+
+
+    return a.exec();
+}

+ 164 - 0
src/driver/driver_service_maintain/service_maintain.cpp

@@ -0,0 +1,164 @@
+#include "service_maintain.h"
+
+#include <iostream>
+#include <QFile>
+
+service_maintain::service_maintain(iv::service_maintain_param & param)
+{
+    mparam = param;
+
+    mpServer = new QUdpSocket(this);
+
+    mpServer->bind(QHostAddress::Any,std::atoi(mparam.mstrlistenport.data()));
+
+    connect(mpServer,SIGNAL(readyRead()),this,SLOT(onRecvData()));
+
+    StartService();
+
+
+}
+
+void service_maintain::onRecvData()
+{
+    while(mpServer->hasPendingDatagrams())
+    {
+        QByteArray ba;
+        ba.resize(mpServer->bytesAvailable());
+        QHostAddress host;
+        quint16 port;
+        mpServer->readDatagram(ba.data(),ba.size(),&host,&port);
+        std::cout<<" recevive data from "<<host.toString().toLatin1().data()<<":"<<port<<" data size: "<<ba.size()<<std::endl;
+        ProcessData(ba);
+    }
+}
+
+
+int service_maintain::generateRandomNumber()
+{
+    qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
+    int nrtn = qrand()%1000;
+    std::cout<<" rand value: "<<nrtn<<std::endl;
+    return nrtn;
+}
+
+void service_maintain::ProcessData(QByteArray & ba)
+{
+
+}
+
+void service_maintain::StartService()
+{
+    if((mnServiceCode > 0)&&(mnServcieStatus == 1))
+    {
+        std::cout<<" Service is opened. "<<std::endl;
+        return;
+    }
+    int nport = generateRandomNumber();
+    nport = nport + 14000;
+    mnServiceCode =  nport;
+
+    std::string strfrpc = mparam.mstrfrpcfolder + "/frpc";
+    QFileInfo xFileInfo(strfrpc.data());
+    if(xFileInfo.exists() == false)
+    {
+        mnServiceCode = -1;
+        mstrError = "No frpc program.";
+        mnServcieStatus = 0;
+        std::cout<<"No frpc program."<<std::endl;
+        return;
+    }
+
+    if(xFileInfo.isExecutable() == false)
+    {
+        mnServiceCode = -1;
+        mstrError = "frpc program is not executable.";
+        mnServcieStatus = 0;
+        std::cout<<"frpc program is not executable."<<std::endl;
+        return;
+    }
+
+    CreateIniFile();
+
+    if(mnServiceCode  > 0)
+    {
+        mpfrpProcess = new QProcess(this);
+
+
+        connect(mpfrpProcess,SIGNAL(started()),this,SLOT(onProcessStarted()));
+        connect(mpfrpProcess,SIGNAL(finished(int)),this,SLOT(onProcessEnd()));
+        connect(mpfrpProcess,SIGNAL(readyReadStandardOutput()),this,SLOT(onReadStandardOutput()));
+        connect(mpfrpProcess,SIGNAL(readyReadStandardError()),this,SLOT(onReadStandardError()));
+
+
+ //       connect(mpfrpProcess,SIGNAL(error(QProcess::ProcessError)),this,SLOT(onProcessErrorStarted(QProcess::ProcessError)));
+
+
+        char strcmd[1000];
+        snprintf(strcmd,1000,"%s/frpc -c %s",mparam.mstrfrpcfolder.data(), mstrIniFile.data());
+
+        std::cout<<" cmd: "<<strcmd<<std::endl;
+
+        mpfrpProcess->start(strcmd);
+    }
+}
+
+std::string service_maintain::CreateIniFile()
+{
+    std::string strfilepath = mparam.mstrfrpcfolder + "/frpc" + QString::number(std::chrono::system_clock::now().time_since_epoch().count() ).toStdString() + ".ini";
+    mstrIniFile = strfilepath;
+    QFile xFile;
+    xFile.setFileName(strfilepath.data());
+    if(!xFile.open(QIODevice::ReadWrite))
+    {
+        mnServiceCode = -1;
+        mnServcieStatus = 0;
+        mstrError = "Can't Create ini file.";
+        std::cout<<"Can't Create ini file."<<std::endl;
+        return mstrIniFile;
+    }
+    char strline[1000];
+    snprintf(strline,1000,"[common]\n");xFile.write(strline,strnlen(strline,1000));
+    snprintf(strline,1000,"server_addr = %s\n",mparam.mstrserverip.data());xFile.write(strline,strnlen(strline,1000));
+    snprintf(strline,1000,"server_port = %s\n",mparam.mstrserverport.data());xFile.write(strline,strnlen(strline,1000));
+    snprintf(strline,1000,"token = %s\n",mparam.mstrtoken.data());xFile.write(strline,strnlen(strline,1000));
+    snprintf(strline,1000,"\n");xFile.write(strline,strnlen(strline,1000));
+    snprintf(strline,1000,"[nomachine_tcp]\n");xFile.write(strline,strnlen(strline,1000));
+    snprintf(strline,1000,"type = tcp\n");xFile.write(strline,strnlen(strline,1000));
+    snprintf(strline,1000,"local_ip = 127.0.0.1\n");xFile.write(strline,strnlen(strline,1000));
+    snprintf(strline,1000,"local_port = %s\n",mparam.mstrnomachineport.data());xFile.write(strline,strnlen(strline,1000));
+    snprintf(strline,1000,"remote_port = %d\n",mnServiceCode);xFile.write(strline,strnlen(strline,1000));
+    xFile.close();
+
+}
+
+void service_maintain::onProcessStarted()
+{
+    std::cout<<" Started. "<<std::endl;
+}
+
+void service_maintain::onProcessEnd()
+{
+    QProcess * proc = (QProcess *)sender();
+}
+
+void service_maintain::onChRead()
+{
+
+}
+
+void service_maintain::onReadStandardOutput()
+{
+    QProcess * proc = (QProcess *)sender();
+    QByteArray ba = proc->readAllStandardOutput();
+    std::cout<<"Std Out:"<<std::endl;
+    std::cout<<ba.data()<<std::endl;
+}
+
+void service_maintain::onReadStandardError()
+{
+    QProcess * proc = (QProcess *)sender();
+    QByteArray ba = proc->readAllStandardError();
+    std::cout<<"Error Out:"<<std::endl;
+    std::cout<<ba.data()<<std::endl;
+}
+

+ 68 - 0
src/driver/driver_service_maintain/service_maintain.h

@@ -0,0 +1,68 @@
+#ifndef SERVICE_MAINTAIN_H
+#define SERVICE_MAINTAIN_H
+
+#include <string>
+
+#include <thread>
+
+#include <QtCore>
+
+#include <QUdpSocket>
+#include <QDir>
+
+#include <QProcess>
+
+namespace iv {
+struct service_maintain_param
+{
+    std::string mstrserverip;
+    std::string mstrserverport;
+    std::string mstrtoken;
+    std::string mstrnomachineport;
+//    std::string mstrnomachineremoteport;
+    std::string mstrfrpcfolder;
+    std::string mstrlistenport;
+};
+
+}
+
+class service_maintain : public QObject
+{
+    Q_OBJECT
+public:
+    service_maintain(iv::service_maintain_param & param);
+
+private slots:
+    void onRecvData();
+
+    void onProcessStarted();
+    void onProcessEnd();
+    void onChRead();
+    void onReadStandardOutput();
+    void onReadStandardError();
+
+private:
+    iv::service_maintain_param mparam;
+
+    QUdpSocket * mpServer;
+
+    void ProcessData(QByteArray & ba);
+
+private:
+    void StartService();
+    void StopService();
+    int generateRandomNumber();
+
+    std::string CreateIniFile();
+    void DeleteIniFile();
+
+
+    int mnServcieStatus = 0;  //0 not open  1 open
+    int mnServiceCode = 0;    // >0 OK -1 Fail
+    std::string mstrError;
+    std::string mstrIniFile;
+
+    QProcess * mpfrpProcess;
+};
+
+#endif // SERVICE_MAINTAIN_H