Browse Source

change driver_cloud_grpc_civetweb. for add remotectrl.

yuchuli 3 years ago
parent
commit
4cf7ac8c70

+ 12 - 2
src/driver/driver_cloud_grpc_civetweb/driver_cloud_grpc_civetweb.pro

@@ -24,7 +24,12 @@ SOURCES += main.cpp \
     ../../include/msgtype/rawpic.pb.cc \
     grpccivet.cpp \
     ../../../thirdpartylib/civetweb/CivetServer.cpp \
-    ../../../thirdpartylib/civetweb/civetweb.c
+    ../../../thirdpartylib/civetweb/civetweb.c \
+    pichandler.cpp \
+    starthandler.cpp \
+    remotehandler.cpp \
+    ../../include/msgtype/gpsimu.pb.cc \
+    ../../include/msgtype/remotectrl.pb.cc
 
 
 !include(../../../include/common.pri ) {
@@ -51,7 +56,12 @@ HEADERS += \
     ../../include/msgtype/rawpic.pb.h \
     grpccivet.h \
     ../../../thirdpartylib/civetweb/CivetServer.h \
-    ../../../thirdpartylib/civetweb/civetweb.h
+    ../../../thirdpartylib/civetweb/civetweb.h \
+    pichandler.h \
+    starthandler.h \
+    remotehandler.h \
+    ../../include/msgtype/gpsimu.pb.h \
+    ../../include/msgtype/remotectrl.pb.h
 
 INCLUDEPATH += $$PWD/../../../thirdpartylib/civetweb
 DEFINES += NO_SSL

+ 29 - 0
src/driver/driver_cloud_grpc_civetweb/grpccivet.cpp

@@ -1,7 +1,36 @@
 #include "grpccivet.h"
 
+#include <QFile>
+
 grpccivet::grpccivet()
 {
 //    mpgrpcpc = new grpcpc;
 //    mpgrpcpc->start();
+    mgrpc = new grpcpc("test");
+    mgrpc->start();
+
+    QFile xFile;
+    xFile.setFileName("./frontend/tvsnow.jpg");
+    if(xFile.open(QIODevice::ReadOnly))
+    {
+        mbasnow = xFile.readAll();
+
+    }
+    xFile.close();
+}
+
+grpccivet & grpccivet::GetInst()
+{
+    static grpccivet xgrpccivet;
+    return xgrpccivet;
+}
+
+grpcpc * grpccivet::Getgrpcpc()
+{
+    return mgrpc;
+}
+
+QByteArray grpccivet::GetSNOW()
+{
+    return mbasnow;
 }

+ 14 - 1
src/driver/driver_cloud_grpc_civetweb/grpccivet.h

@@ -10,7 +10,20 @@ public:
     grpccivet();
 
 private:
-    grpcpc * mpgrpcpc;
+//    grpcpc * mpgrpcpc;
+    grpcpc * mgrpc;
+
+
+    QByteArray mbasnow;
+
+public:
+    static grpccivet & GetInst();
+
+public:
+    grpcpc * Getgrpcpc();
+    QByteArray GetSNOW();
 };
 
+#define ServiceGRPCCIVET grpccivet::GetInst()
+
 #endif // GRPCCIVET_H

+ 13 - 451
src/driver/driver_cloud_grpc_civetweb/main.cpp

@@ -1,445 +1,20 @@
 #include <QCoreApplication>
 
+#include "starthandler.h"
+#include "pichandler.h"
+#include "remotehandler.h"
 
-#include <QMutex>
-#include <iostream>
-#include <QFile>
-#include <QJsonObject>
-#include <QJsonDocument>
-#include <QJsonArray>
 
 #include "xmlparam.h"
 
 #include "rawpic.pb.h"
 
-#include "CivetServer.h"
-#include <cstring>
-
-#ifdef _WIN32
-#include <windows.h>
-#else
-#include <unistd.h>
-#endif
 
 #include "grpccivet.h"
 
 #define DOCUMENT_ROOT "./frontend/dist"
 
-QByteArray gbasnow;
-
-
-grpcpc * ggrpc;
-
-class WsStartHandler : public CivetHandler
-{
-  public:
-    bool
-    handleGet(CivetServer *server, struct mg_connection *conn)
-    {
-
-    mg_printf(conn,
-              "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: "
-              "close\r\n\r\n");
-
-    mg_printf(conn, "<!DOCTYPE html>\n");
-    mg_printf(conn, "<html>\n<head>\n");
-    mg_printf(conn, "<meta charset=\"UTF-8\">\n");
-    mg_printf(conn, "<title>ADC IV RemoteCtrl UI</title>\n");
-
-    QFile xFile;
-    xFile.setFileName("./frontend/index.html");
-    if(xFile.open(QIODevice::ReadOnly))
-    {
-        QByteArray ba = xFile.readAll();
-        mg_printf(conn,ba.data());
-
-    }
-
-    return 1;
-
-
-
-    }
-};
-
-class PicFrontHandler : public CivetHandler
-{
-  public:
-    bool
-    handleGet(CivetServer *server, struct mg_connection *conn)
-    {
-
-        static int ncount;
-
-        mg_printf(conn,
-                  "HTTP/1.1 200 OK\r\n"
-                  "Connection: close\r\n"
-                  "Max-Age: 0\r\n"
-                  "Expires: 0\r\n"
-                  "Cache-Control: no-cache, no-store, must-revalidate, private\r\n"
-                  "Pragma: no-cache\r\n"
-                  "Content-Type: multipart/x-mixed-replace; "
-                  "boundary=--BoundaryString\r\n"
-                  "\r\n");
-
-        mg_printf(conn,"<meta http-equiv=\"refresh\" content=\"1\">");
-        mg_printf(conn,
-        "<script type=\"text/javascript\">\r\n"
-            "function myrefresh() {\r\n"
-                "window.location.reload();\r\n"
-            "}\r\n"
-            "setTimeout('myrefresh()', 1000);\r\n"
-        "</script>\r\n");
-
-        QByteArray ba;
-
-
-        iv::vision::rawpic xrawpic;
-        if(ggrpc->GetRawPic(0,xrawpic) == 1)
-        {
-            ba.append(xrawpic.picdata().data(),xrawpic.picdata().size());
-        }
-        else
-        {
-            ba = gbasnow;
-        }
-//        if(gLastUpdate > 0)
-//        {
-//        iv::vision::rawpic xrawpic;
-//        gMutex.lock();
-//        xrawpic.CopyFrom(mRawPic);
-//        gMutex.unlock();
-//        ba.append(xrawpic.picdata().data(),xrawpic.picdata().size());
-
-//        }
-        mg_printf(conn,
-                  "--BoundaryString\r\n"
-                  "Content-type: image/jpeg\r\n"
-                  "Content-Length: %zu\r\n"
-                  "\r\n",
-                  ba.size());
-
-
-        mg_write(conn, ba.data(), ba.size());
-
-
-        mg_printf(conn, "\r\n\r\n");
-
-
-        ncount++;
-        printf("send pic. %d\n",ncount);
-
-        return true;
-    }
-};
-
-
-class PicRearHandler : public CivetHandler
-{
-  public:
-    bool
-    handleGet(CivetServer *server, struct mg_connection *conn)
-    {
-
-        static int ncount;
-
-        mg_printf(conn,
-                  "HTTP/1.1 200 OK\r\n"
-                  "Connection: close\r\n"
-                  "Max-Age: 0\r\n"
-                  "Expires: 0\r\n"
-                  "Cache-Control: no-cache, no-store, must-revalidate, private\r\n"
-                  "Pragma: no-cache\r\n"
-                  "Content-Type: multipart/x-mixed-replace; "
-                  "boundary=--BoundaryString\r\n"
-                  "\r\n");
-
-        mg_printf(conn,"<meta http-equiv=\"refresh\" content=\"1\">");
-        mg_printf(conn,
-        "<script type=\"text/javascript\">\r\n"
-            "function myrefresh() {\r\n"
-                "window.location.reload();\r\n"
-            "}\r\n"
-            "setTimeout('myrefresh()', 1000);\r\n"
-        "</script>\r\n");
-
-        QByteArray ba;
-
-
-        iv::vision::rawpic xrawpic;
-        if(ggrpc->GetRawPic(1,xrawpic) == 1)
-        {
-            ba.append(xrawpic.picdata().data(),xrawpic.picdata().size());
-        }
-        else
-        {
-            ba = gbasnow;
-        }
-//        if(gLastUpdate > 0)
-//        {
-//        iv::vision::rawpic xrawpic;
-//        gMutex.lock();
-//        xrawpic.CopyFrom(mRawPic);
-//        gMutex.unlock();
-//        ba.append(xrawpic.picdata().data(),xrawpic.picdata().size());
-
-//        }
-        mg_printf(conn,
-                  "--BoundaryString\r\n"
-                  "Content-type: image/jpeg\r\n"
-                  "Content-Length: %zu\r\n"
-                  "\r\n",
-                  ba.size());
-
-
-        mg_write(conn, ba.data(), ba.size());
-
-
-        mg_printf(conn, "\r\n\r\n");
-
-
-        ncount++;
-        printf("send pic. %d\n",ncount);
-
-        return true;
-    }
-};
-
-
-
-class PicLeftHandler : public CivetHandler
-{
-  public:
-    bool
-    handleGet(CivetServer *server, struct mg_connection *conn)
-    {
-
-        static int ncount;
-
-        mg_printf(conn,
-                  "HTTP/1.1 200 OK\r\n"
-                  "Connection: close\r\n"
-                  "Max-Age: 0\r\n"
-                  "Expires: 0\r\n"
-                  "Cache-Control: no-cache, no-store, must-revalidate, private\r\n"
-                  "Pragma: no-cache\r\n"
-                  "Content-Type: multipart/x-mixed-replace; "
-                  "boundary=--BoundaryString\r\n"
-                  "\r\n");
-
-        mg_printf(conn,"<meta http-equiv=\"refresh\" content=\"1\">");
-        mg_printf(conn,
-        "<script type=\"text/javascript\">\r\n"
-            "function myrefresh() {\r\n"
-                "window.location.reload();\r\n"
-            "}\r\n"
-            "setTimeout('myrefresh()', 1000);\r\n"
-        "</script>\r\n");
-
-        QByteArray ba;
-
 
-        iv::vision::rawpic xrawpic;
-        if(ggrpc->GetRawPic(2,xrawpic) == 1)
-        {
-            ba.append(xrawpic.picdata().data(),xrawpic.picdata().size());
-        }
-        else
-        {
-            ba = gbasnow;
-        }
-//        if(gLastUpdate > 0)
-//        {
-//        iv::vision::rawpic xrawpic;
-//        gMutex.lock();
-//        xrawpic.CopyFrom(mRawPic);
-//        gMutex.unlock();
-//        ba.append(xrawpic.picdata().data(),xrawpic.picdata().size());
-
-//        }
-        mg_printf(conn,
-                  "--BoundaryString\r\n"
-                  "Content-type: image/jpeg\r\n"
-                  "Content-Length: %zu\r\n"
-                  "\r\n",
-                  ba.size());
-
-
-        mg_write(conn, ba.data(), ba.size());
-
-
-        mg_printf(conn, "\r\n\r\n");
-
-
-        ncount++;
-        printf("send pic. %d\n",ncount);
-
-        return true;
-    }
-};
-
-
-
-class PicRightHandler : public CivetHandler
-{
-  public:
-    bool
-    handleGet(CivetServer *server, struct mg_connection *conn)
-    {
-
-        static int ncount;
-
-        mg_printf(conn,
-                  "HTTP/1.1 200 OK\r\n"
-                  "Connection: close\r\n"
-                  "Max-Age: 0\r\n"
-                  "Expires: 0\r\n"
-                  "Cache-Control: no-cache, no-store, must-revalidate, private\r\n"
-                  "Pragma: no-cache\r\n"
-                  "Content-Type: multipart/x-mixed-replace; "
-                  "boundary=--BoundaryString\r\n"
-                  "\r\n");
-
-        mg_printf(conn,"<meta http-equiv=\"refresh\" content=\"1\">");
-        mg_printf(conn,
-        "<script type=\"text/javascript\">\r\n"
-            "function myrefresh() {\r\n"
-                "window.location.reload();\r\n"
-            "}\r\n"
-            "setTimeout('myrefresh()', 1000);\r\n"
-        "</script>\r\n");
-
-        QByteArray ba;
-
-
-        iv::vision::rawpic xrawpic;
-        if(ggrpc->GetRawPic(3,xrawpic) == 1)
-        {
-            ba.append(xrawpic.picdata().data(),xrawpic.picdata().size());
-        }
-        else
-        {
-            ba = gbasnow;
-        }
-//        if(gLastUpdate > 0)
-//        {
-//        iv::vision::rawpic xrawpic;
-//        gMutex.lock();
-//        xrawpic.CopyFrom(mRawPic);
-//        gMutex.unlock();
-//        ba.append(xrawpic.picdata().data(),xrawpic.picdata().size());
-
-//        }
-        mg_printf(conn,
-                  "--BoundaryString\r\n"
-                  "Content-type: image/jpeg\r\n"
-                  "Content-Length: %zu\r\n"
-                  "\r\n",
-                  ba.size());
-
-
-        mg_write(conn, ba.data(), ba.size());
-
-
-        mg_printf(conn, "\r\n\r\n");
-
-
-        ncount++;
-        printf("send pic. %d\n",ncount);
-
-        return true;
-    }
-};
-
-
-#ifdef USE_WEBSOCKET
-class WebSocketHandler : public CivetWebSocketHandler {
-
-    int a = 1;
-    virtual bool handleConnection(CivetServer *server,
-                                  const struct mg_connection *conn) {
-        printf("WS connected\n");
-        return true;
-    }
-
-    virtual void handleReadyState(CivetServer *server,
-                                  struct mg_connection *conn) {
-        printf("WS ready\n");
-
-        const char *text = "Hello from the websocket ready handler";
-        mg_websocket_write(conn, MG_WEBSOCKET_OPCODE_TEXT, text, strlen(text));
-    }
-
-    virtual bool handleData(CivetServer *server,
-                            struct mg_connection *conn,
-                            int bits,
-                            char *data,
-                            size_t data_len) {
-        printf("WS got %lu bytes: ", (long unsigned)data_len);
-        QJsonDocument xup;
-        QByteArray bajson;
-        bajson.push_back(data);
-        xup = QJsonDocument::fromJson(bajson);
-
-        QJsonObject xupo = xup.object();
-        QString strctrl = "AA";
-        if(xupo.contains("Ctrl"))
-        {
-            strctrl = xupo.value("Ctrl").toString();
-        }
-        QString strshift = "D";
-        if(xupo.contains("Shift"))
-        {
-            strshift = xupo.value("Shift").toString();
-        }
-        QString strvel = "0.13";
-        if(xupo.contains("Vel"))
-        {
-            strvel = xupo.value("Vel").toString();
-        }
-        QString strwheel = "0.03";
-        if(xupo.contains("Wheel"))
-        {
-            strwheel = xupo.value("Wheel").toString();
-        }
-        fwrite(data, 1, data_len, stdout);
-//        printf("\n");
-
-
-        QJsonObject obj1;
-
-     //   obj1.insert("Class", "sindata");
-
-        obj1.insert("test","test");
-
-        QString strsend = QString(QJsonDocument(obj1).toJson(QJsonDocument::Compact));
-
-
-
-                mg_websocket_write(conn, MG_WEBSOCKET_OPCODE_TEXT,strsend.toLatin1().data(),strsend.length());
-                return (data_len<5);
-
-        char strout[100];
-  //      snprintf(strout,100,"hello %s <img src =\"/Pic?%d\"> ",data,a);a++;
-
-        snprintf(strout,100,"<p><h3>hello %s </h3> acc:%f <br> brake:%f <br> wheel:%f</p> ",data,1.0,0.0,300.0);a++;
-
-
-
-
- //       mg_websocket_write(conn, MG_WEBSOCKET_OPCODE_TEXT, data, data_len);
-        mg_websocket_write(conn, MG_WEBSOCKET_OPCODE_TEXT,strout,strnlen(strout,255));
-  //      mg_websocket_write(conn, MG_WEBSOCKET_OPCODE_TEXT,"hello",5);
-        return true;
-//        return (data_len<5);
-    }
-
-    virtual void handleClose(CivetServer *server,
-                             const struct mg_connection *conn) {
-        printf("WS closed\n");
-    }
-};
-#endif
 
 
 int main(int argc, char *argv[])
@@ -451,14 +26,6 @@ int main(int argc, char *argv[])
     std::string strport = xp.GetParam("Port","6101");
 //    gpa = iv::modulecomm::RegisterRecv(strmsgname.data(),Listenpic);
 
-    QFile xFile;
-    xFile.setFileName("./frontend/tvsnow.jpg");
-    if(xFile.open(QIODevice::ReadOnly))
-    {
-        gbasnow = xFile.readAll();
-
-    }
-    xFile.close();
 
     mg_init_library(0);
 
@@ -474,27 +41,22 @@ int main(int argc, char *argv[])
     // CivetServer server(options); // <-- C style start
     CivetServer server(cpp_options); // <-- C++ style start
 
-    WsStartHandler h_ws;
-    server.addHandler("/", h_ws);
+    starthandler h_ws;
+    server.addHandler("/",h_ws);
 
-    PicFrontHandler h_picfront;
-    server.addHandler("/picfront", h_picfront);
+    PicHandler h_pic;
 
-    PicRearHandler h_picrear;
-    server.addHandler("/picrear", h_picrear);
-    PicLeftHandler h_picleft;
-    server.addHandler("/picleft", h_picleft);
-    PicRightHandler h_picright;
-    server.addHandler("/picright", h_picright);
+    server.addHandler("/picfront", h_pic);
+    server.addHandler("/picrear", h_pic);
+    server.addHandler("/picleft", h_pic);
+    server.addHandler("/picright", h_pic);
 
 #ifdef USE_WEBSOCKET
-    WebSocketHandler h_websocket;
-    server.addWebSocketHandler("/remoteservice", h_websocket);
+    RemoteHandler h_remotesocket;
+    server.addWebSocketHandler("/remoteservice", h_remotesocket);
 //    printf("Run websocket example at http://localhost:%s/\n", PORT);
 #endif
 
-    ggrpc = new grpcpc("test");
-    ggrpc->start();
-
     return a.exec();
+
 }

+ 105 - 0
src/driver/driver_cloud_grpc_civetweb/pichandler.cpp

@@ -0,0 +1,105 @@
+#include "pichandler.h"
+
+#include "grpccivet.h"
+
+#include "rawpic.pb.h"
+
+PicHandler::PicHandler()
+{
+
+}
+
+bool PicHandler::handleGet(CivetServer *server, mg_connection *conn)
+{
+    static int ncount;
+
+    mg_printf(conn,
+              "HTTP/1.1 200 OK\r\n"
+              "Connection: close\r\n"
+              "Max-Age: 0\r\n"
+              "Expires: 0\r\n"
+              "Cache-Control: no-cache, no-store, must-revalidate, private\r\n"
+              "Pragma: no-cache\r\n"
+              "Content-Type: multipart/x-mixed-replace; "
+              "boundary=--BoundaryString\r\n"
+              "\r\n");
+
+    mg_printf(conn,"<meta http-equiv=\"refresh\" content=\"1\">");
+    mg_printf(conn,
+    "<script type=\"text/javascript\">\r\n"
+        "function myrefresh() {\r\n"
+            "window.location.reload();\r\n"
+        "}\r\n"
+        "setTimeout('myrefresh()', 1000);\r\n"
+    "</script>\r\n");
+
+
+
+
+    grpcpc * pgrpc = ServiceGRPCCIVET.Getgrpcpc();
+    if(pgrpc == NULL)return false;
+
+    unsigned int ncam = 10000;
+    const struct mg_request_info * preq = mg_get_request_info(conn);
+    if(preq->local_uri != NULL)
+    {
+        if(strncmp(preq->local_uri,"/picfront",256) == 0)
+        {
+            ncam = 0;
+        }
+        if(strncmp(preq->local_uri,"/picrear",256) == 0)
+        {
+            ncam = 1;
+        }
+        if(strncmp(preq->local_uri,"/picleft",256) == 0)
+        {
+            ncam = 2;
+        }
+        if(strncmp(preq->local_uri,"/picright",256) == 0)
+        {
+            ncam = 3;
+        }
+    }
+
+    QByteArray ba;
+
+
+    iv::vision::rawpic xrawpic;
+
+    if(pgrpc->GetRawPic((unsigned int)ncam,xrawpic) == 1)
+    {
+        ba.append(xrawpic.picdata().data(),xrawpic.picdata().size());
+    }
+    else
+    {
+        ba = ServiceGRPCCIVET.GetSNOW();
+    }
+
+//        if(gLastUpdate > 0)
+//        {
+//        iv::vision::rawpic xrawpic;
+//        gMutex.lock();
+//        xrawpic.CopyFrom(mRawPic);
+//        gMutex.unlock();
+//        ba.append(xrawpic.picdata().data(),xrawpic.picdata().size());
+
+//        }
+    mg_printf(conn,
+              "--BoundaryString\r\n"
+              "Content-type: image/jpeg\r\n"
+              "Content-Length: %zu\r\n"
+              "\r\n",
+              ba.size());
+
+
+    mg_write(conn, ba.data(), ba.size());
+
+
+    mg_printf(conn, "\r\n\r\n");
+
+
+    ncount++;
+    printf("send pic. %d\n",ncount);
+
+    return true;
+}

+ 22 - 0
src/driver/driver_cloud_grpc_civetweb/pichandler.h

@@ -0,0 +1,22 @@
+#ifndef PICHANDLER_H
+#define PICHANDLER_H
+
+#include "grpcpc.h"
+
+#include "CivetServer.h"
+#include <cstring>
+
+#ifdef _WIN32
+#include <windows.h>
+#else
+#include <unistd.h>
+#endif
+
+class PicHandler : public CivetHandler
+{
+public:
+    PicHandler();
+    bool handleGet(CivetServer *server, struct mg_connection *conn);
+};
+
+#endif // PICHANDLER_H

+ 209 - 0
src/driver/driver_cloud_grpc_civetweb/remotehandler.cpp

@@ -0,0 +1,209 @@
+#include "remotehandler.h"
+
+#include <QMutex>
+#include <iostream>
+#include <QFile>
+#include <QJsonObject>
+#include <QJsonDocument>
+#include <QJsonArray>
+
+#include "grpccivet.h"
+
+#include "remotectrl.pb.h"
+
+#ifdef USE_WEBSOCKET
+
+RemoteHandler::RemoteHandler()
+{
+
+}
+
+bool RemoteHandler::handleConnection(CivetServer *server, const mg_connection *conn)
+{
+    printf("WS connected\n");
+    return true;
+}
+
+void RemoteHandler::handleReadyState(CivetServer *server, mg_connection *conn)
+{
+    printf("WS ready\n");
+
+    const char *text = "Hello from the websocket ready handler";
+    mg_websocket_write(conn, MG_WEBSOCKET_OPCODE_TEXT, text, strlen(text));
+}
+
+bool RemoteHandler::handleData(CivetServer *server, mg_connection *conn, int bits, char *data, size_t data_len)
+{
+    printf("WS got %lu bytes: ", (long unsigned)data_len);
+    QJsonDocument xup;
+    QByteArray bajson;
+    bajson.push_back(data);
+    xup = QJsonDocument::fromJson(bajson);
+
+    QJsonObject xupo = xup.object();
+    QString strctrl = "AA";
+    if(xupo.contains("Ctrl"))
+    {
+        strctrl = xupo.value("Ctrl").toString();
+    }
+    QString strshift = "D";
+    if(xupo.contains("Shift"))
+    {
+        strshift = xupo.value("Shift").toString();
+    }
+    QString strvel = "0.00";
+    if(xupo.contains("Vel"))
+    {
+        strvel = xupo.value("Vel").toString();
+    }
+    QString strwheel = "0.50";
+    if(xupo.contains("Wheel"))
+    {
+        strwheel = xupo.value("Wheel").toString();
+    }
+    fwrite(data, 1, data_len, stdout);
+//        printf("\n");
+
+    iv::cloud::cloudmsg xmsg;
+    CalcRemote(xmsg,strctrl,strshift,strvel,strwheel);
+    ServiceGRPCCIVET.Getgrpcpc()->SetSendMsg(xmsg);
+
+    QJsonObject obj1;
+
+ //   obj1.insert("Class", "sindata");
+
+    obj1.insert("test","test");
+
+    QString strsend = QString(QJsonDocument(obj1).toJson(QJsonDocument::Compact));
+
+
+
+    mg_websocket_write(conn, MG_WEBSOCKET_OPCODE_TEXT,strsend.toLatin1().data(),strsend.length());
+    return (data_len<5);
+
+    char strout[100];
+//      snprintf(strout,100,"hello %s <img src =\"/Pic?%d\"> ",data,a);a++;
+
+    snprintf(strout,100,"<p><h3>hello %s </h3> acc:%f <br> brake:%f <br> wheel:%f</p> ",data,1.0,0.0,300.0);
+
+
+
+
+//       mg_websocket_write(conn, MG_WEBSOCKET_OPCODE_TEXT, data, data_len);
+    mg_websocket_write(conn, MG_WEBSOCKET_OPCODE_TEXT,strout,strnlen(strout,255));
+//      mg_websocket_write(conn, MG_WEBSOCKET_OPCODE_TEXT,"hello",5);
+    return true;
+//        return (data_len<5);
+}
+
+int RemoteHandler::CalcRemote(iv::cloud::cloudmsg &xmsg,QString strctrl,QString strshift,QString strvel,QString strwheel)
+{
+    grpcpc * pgrpc = ServiceGRPCCIVET.Getgrpcpc();
+    iv::cloud::cloudmsg xrecv;
+    int nrecv = pgrpc->GetRecvMsg(xrecv);
+    iv::gps::gpsimu xgpsimu;
+    bool bhavegps = false;
+    if(nrecv == 1)
+    {
+        int nsize = xrecv.xclouddata_size();
+        int i;
+        for(i=0;i<nsize;i++)
+        {
+            if(xrecv.xclouddata(i).msgname() == "hcp2_gpsimu")
+            {
+                bhavegps = xgpsimu.ParseFromArray(xrecv.xclouddata(i).data().data(),xrecv.xclouddata(i).data().size());
+                break;
+            }
+        }
+    }
+    iv::remotectrl xremote;
+    if(bhavegps == false)
+    {
+
+        xremote.set_ntype(iv::remotectrl_CtrlType_AUTO);
+
+    }
+    else
+    {
+        if(strctrl == "Auto")
+        {
+            xremote.set_ntype(iv::remotectrl_CtrlType_AUTO);
+        }
+        else
+        {
+            xremote.set_ntype(iv::remotectrl_CtrlType_REMOTE);
+            if(strshift == "Drive")
+            {
+                xremote.set_shift(1);
+            }
+            else
+            {
+                if(strshift == "Rear")
+                {
+                    xremote.set_shift(-1);
+                }
+                else
+                {
+                    xremote.set_shift(0);
+                }
+            }
+            double fwheel = strwheel.toDouble();
+            fwheel = (0.5 - fwheel)*200.0;
+            xremote.set_wheel(fwheel);
+            double fVel = strvel.toDouble();
+            double fAcc,fBrake;
+            CalcMidCarWheelBrake(xgpsimu,fVel,fAcc,fBrake);
+            xremote.set_acc(fAcc);
+            xremote.set_brake(fBrake);
+
+        }
+    }
+
+    iv::cloud::cloudunit xunit;
+    int nunitsize = xremote.ByteSize();
+    std::shared_ptr<char> pstr_ptr = std::shared_ptr<char>(new char[nunitsize]);
+    if(xremote.SerializeToArray(pstr_ptr.get(),nunitsize))
+    {
+        xunit.set_msgname("remotectrl");
+        xunit.set_data(pstr_ptr.get(),nunitsize);
+        iv::cloud::cloudunit * punit = xmsg.add_xclouddata();
+        punit->CopyFrom(xunit);
+    }
+
+    return 0;
+}
+
+void  RemoteHandler::CalcMidCarWheelBrake(iv::gps::gpsimu &xgpsimu, double fVel, double &fAcc, double &fBrake)
+{
+    const double fMaxVel = 5.0;
+    double fV = sqrt(pow(xgpsimu.ve(),2)+pow(xgpsimu.vn(),2))*3.6;
+    double fNeedV = fVel * fMaxVel/10.0;
+    if(fNeedV > fV)
+    {
+        fBrake = 0.0;
+        fAcc = 50.0;
+    }
+    else
+    {
+        if(fNeedV>0.5)
+        {
+            if(fNeedV>(0.9*fV))
+            {
+                fAcc = 0.0;
+                fBrake = 0.0;
+            }
+            else
+            {
+                fAcc =0.0;
+                fBrake = 30.0;
+            }
+        }
+        else
+        {
+            fAcc = 0.0;
+            fBrake = 0.0;
+        }
+    }
+}
+
+#endif

+ 44 - 0
src/driver/driver_cloud_grpc_civetweb/remotehandler.h

@@ -0,0 +1,44 @@
+#ifndef REMOTEHANDLER_H
+#define REMOTEHANDLER_H
+
+#include "CivetServer.h"
+#include <cstring>
+
+#ifdef _WIN32
+#include <windows.h>
+#else
+#include <unistd.h>
+#endif
+
+#include "gpsimu.pb.h"
+#include "cloud.pb.h"
+
+#ifdef USE_WEBSOCKET
+
+#include <QString>
+
+class RemoteHandler : public CivetWebSocketHandler
+{
+public:
+    RemoteHandler();
+
+public:
+    virtual bool handleConnection(CivetServer *server,
+                                  const struct mg_connection *conn);
+    virtual void handleReadyState(CivetServer *server,
+                                  struct mg_connection *conn);
+    virtual bool handleData(CivetServer *server,
+                            struct mg_connection *conn,
+                            int bits,
+                            char *data,
+                            size_t data_len);
+
+
+private:
+    int CalcRemote(iv::cloud::cloudmsg & xmsg,QString strctrl,QString strshift,QString strvel,QString strwheel);
+    void  CalcMidCarWheelBrake(iv::gps::gpsimu & xgpsimu,double fVel,double & fAcc,double & fBrake);
+};
+
+#endif
+
+#endif // REMOTEHANDLER_H

+ 32 - 0
src/driver/driver_cloud_grpc_civetweb/starthandler.cpp

@@ -0,0 +1,32 @@
+#include "starthandler.h"
+
+#include <QFile>
+
+starthandler::starthandler()
+{
+
+}
+
+bool starthandler::handleGet(CivetServer *server, mg_connection *conn)
+{
+    (void )server;
+    mg_printf(conn,
+              "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: "
+              "close\r\n\r\n");
+
+    mg_printf(conn, "<!DOCTYPE html>\n");
+    mg_printf(conn, "<html>\n<head>\n");
+    mg_printf(conn, "<meta charset=\"UTF-8\">\n");
+    mg_printf(conn, "<title>ADC IV RemoteCtrl UI</title>\n");
+
+    QFile xFile;
+    xFile.setFileName("./frontend/index.html");
+    if(xFile.open(QIODevice::ReadOnly))
+    {
+        QByteArray ba = xFile.readAll();
+        mg_printf(conn,"%s",ba.data());
+
+    }
+
+    return true;
+}

+ 23 - 0
src/driver/driver_cloud_grpc_civetweb/starthandler.h

@@ -0,0 +1,23 @@
+#ifndef STARTHANDLER_H
+#define STARTHANDLER_H
+
+#include "CivetServer.h"
+#include <cstring>
+
+#ifdef _WIN32
+#include <windows.h>
+#else
+#include <unistd.h>
+#endif
+
+
+class starthandler : public CivetHandler
+{
+public:
+    starthandler();
+
+public:
+  bool handleGet(CivetServer *server, struct mg_connection *conn);
+};
+
+#endif // STARTHANDLER_H