|
@@ -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();
|
|
|
+
|
|
|
}
|