Haobin Luo hace 1 año
commit
2c4cc89189
Se han modificado 6 ficheros con 925 adiciones y 0 borrados
  1. 5 0
      .gitignore
  2. 20 0
      .qmake.stash
  3. 9 0
      main.cpp
  4. 107 0
      mock-jamming.pro
  5. 724 0
      wsserver.cpp
  6. 60 0
      wsserver.h

+ 5 - 0
.gitignore

@@ -0,0 +1,5 @@
+debug
+release
+*.pro.user
+Makefile
+Makefile.*

+ 20 - 0
.qmake.stash

@@ -0,0 +1,20 @@
+QMAKE_CXX.QT_COMPILER_STDCXX = 199711L
+QMAKE_CXX.QMAKE_MSC_VER = 1916
+QMAKE_CXX.QMAKE_MSC_FULL_VER = 191627050
+QMAKE_CXX.COMPILER_MACROS = \
+    QT_COMPILER_STDCXX \
+    QMAKE_MSC_VER \
+    QMAKE_MSC_FULL_VER
+QMAKE_CXX.INCDIRS = \
+    "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\ATLMFC\\include" \
+    "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\include" \
+    "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17763.0\\ucrt" \
+    "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17763.0\\shared" \
+    "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17763.0\\um" \
+    "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17763.0\\winrt" \
+    "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.17763.0\\cppwinrt"
+QMAKE_CXX.LIBDIRS = \
+    "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\ATLMFC\\lib\\x64" \
+    "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\lib\\x64" \
+    "C:\\Program Files (x86)\\Windows Kits\\10\\lib\\10.0.17763.0\\ucrt\\x64" \
+    "C:\\Program Files (x86)\\Windows Kits\\10\\lib\\10.0.17763.0\\um\\x64"

+ 9 - 0
main.cpp

@@ -0,0 +1,9 @@
+#include <QCoreApplication>
+#include "wsserver.h"
+
+int main(int argc, char *argv[])
+{
+    QCoreApplication a(argc, argv);
+    WSServer *server = new WSServer(nullptr,1235);
+    return a.exec();
+}

+ 107 - 0
mock-jamming.pro

@@ -0,0 +1,107 @@
+QT -= gui
+QT += core webchannel websockets
+
+CONFIG += c++11 console
+CONFIG -= app_bundle
+
+# You can make your code fail to compile if it uses deprecated APIs.
+# In order to do so, uncomment the following line.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
+
+SOURCES += \
+        ../share/algorithms/XYZ2ELL.cpp \
+        ../share/algorithms/blh2xyz.cpp \
+        ../share/algorithms/colon.cpp \
+        ../share/algorithms/eml_rand_mt19937ar.cpp \
+        ../share/algorithms/fun1_FFTImplementationCallback.cpp \
+        ../share/algorithms/fun1_false_target_distance.cpp \
+        ../share/algorithms/fun1_fft.cpp \
+        ../share/algorithms/fun1_fftshift.cpp \
+        ../share/algorithms/fun1_ifft.cpp \
+        ../share/algorithms/fun2.cpp \
+        ../share/algorithms/fun4_S_jam.cpp \
+        ../share/algorithms/fun4_S_orignal.cpp \
+        ../share/algorithms/fun5.cpp \
+        ../share/algorithms/fun6.cpp \
+        ../share/algorithms/fun7_DRFMRF.cpp \
+        ../share/algorithms/fun7_DRFMRF_data.cpp \
+        ../share/algorithms/fun7_DRFMRF_initialize.cpp \
+        ../share/algorithms/fun7_FFTImplementationCallback.cpp \
+        ../share/algorithms/fun7_eml_rand_mt19937ar_stateful.cpp \
+        ../share/algorithms/fun7_ifft.cpp \
+        ../share/algorithms/fun7_randn.cpp \
+        ../share/algorithms/fun8_2_FFTImplementationCallback.cpp \
+        ../share/algorithms/fun8_2_FMjamming_H.cpp \
+        ../share/algorithms/fun8_2_FMjamming_H_data.cpp \
+        ../share/algorithms/fun8_2_eml_rand_mt19937ar_stateful.cpp \
+        ../share/algorithms/fun8_2_ifft.cpp \
+        ../share/algorithms/fun8_2_randn.cpp \
+        ../share/algorithms/fun8_2_std.cpp \
+        ../share/algorithms/fun8_3_FFTImplementationCallback.cpp \
+        ../share/algorithms/fun8_3_eml_rand_mt19937ar_stateful.cpp \
+        ../share/algorithms/fun8_3_ifft.cpp \
+        ../share/algorithms/fun8_3_jamming_H.cpp \
+        ../share/algorithms/fun8_3_jamming_H_data.cpp \
+        ../share/algorithms/fun8_3_randn.cpp \
+        ../share/algorithms/fun8_AMJamming_H.cpp \
+        ../share/algorithms/fun8_AMJamming_H_data.cpp \
+        ../share/algorithms/fun8_FFTImplementationCallback.cpp \
+        ../share/algorithms/fun8_eml_rand_mt19937ar_stateful.cpp \
+        ../share/algorithms/fun8_randn.cpp \
+        ../share/algorithms/fun8_std.cpp \
+        ../share/algorithms/rt_nonfinite.cpp \
+        main.cpp \
+        wsserver.cpp
+
+# Default rules for deployment.
+qnx: target.path = /tmp/$${TARGET}/bin
+else: unix:!android: target.path = /opt/$${TARGET}/bin
+!isEmpty(target.path): INSTALLS += target
+
+HEADERS += \
+    ../share/algorithms/XYZ2ELL.h \
+    ../share/algorithms/blh2xyz.h \
+    ../share/algorithms/coder_array.h \
+    ../share/algorithms/colon.h \
+    ../share/algorithms/eml_rand_mt19937ar.h \
+    ../share/algorithms/fun1_FFTImplementationCallback.h \
+    ../share/algorithms/fun1_false_target_distance.h \
+    ../share/algorithms/fun1_fft.h \
+    ../share/algorithms/fun1_fftshift.h \
+    ../share/algorithms/fun1_ifft.h \
+    ../share/algorithms/fun2.h \
+    ../share/algorithms/fun4_S_jam.h \
+    ../share/algorithms/fun4_S_orignal.h \
+    ../share/algorithms/fun5.h \
+    ../share/algorithms/fun6.h \
+    ../share/algorithms/fun7_DRFMRF.h \
+    ../share/algorithms/fun7_DRFMRF_data.h \
+    ../share/algorithms/fun7_DRFMRF_initialize.h \
+    ../share/algorithms/fun7_FFTImplementationCallback.h \
+    ../share/algorithms/fun7_eml_rand_mt19937ar_stateful.h \
+    ../share/algorithms/fun7_ifft.h \
+    ../share/algorithms/fun7_randn.h \
+    ../share/algorithms/fun8_2_FFTImplementationCallback.h \
+    ../share/algorithms/fun8_2_FMjamming_H.h \
+    ../share/algorithms/fun8_2_FMjamming_H_data.h \
+    ../share/algorithms/fun8_2_eml_rand_mt19937ar_stateful.h \
+    ../share/algorithms/fun8_2_ifft.h \
+    ../share/algorithms/fun8_2_randn.h \
+    ../share/algorithms/fun8_2_std.h \
+    ../share/algorithms/fun8_3_FFTImplementationCallback.h \
+    ../share/algorithms/fun8_3_eml_rand_mt19937ar_stateful.h \
+    ../share/algorithms/fun8_3_ifft.h \
+    ../share/algorithms/fun8_3_jamming_H.h \
+    ../share/algorithms/fun8_3_jamming_H_data.h \
+    ../share/algorithms/fun8_3_randn.h \
+    ../share/algorithms/fun8_AMJamming_H.h \
+    ../share/algorithms/fun8_AMJamming_H_data.h \
+    ../share/algorithms/fun8_FFTImplementationCallback.h \
+    ../share/algorithms/fun8_eml_rand_mt19937ar_stateful.h \
+    ../share/algorithms/fun8_randn.h \
+    ../share/algorithms/fun8_std.h \
+    ../share/algorithms/rt_defines.h \
+    ../share/algorithms/rt_nonfinite.h \
+    ../share/algorithms/rtwtypes.h \
+    ../share/algorithms/tmwtypes.h \
+    wsserver.h

+ 724 - 0
wsserver.cpp

@@ -0,0 +1,724 @@
+//#pragma execution_character_set("utf-8")
+#include "wsserver.h"
+
+WSServer::WSServer(QObject *parent, quint16 port) : QObject(parent)
+{
+    m_pWebSocketServer = new QWebSocketServer(QStringLiteral("Mock Server"),
+                                                    QWebSocketServer::NonSecureMode,
+                                                    this);
+    if (m_pWebSocketServer->listen(QHostAddress::Any, port))
+    {
+      qDebug() << "Mock Server listening on port" << port;
+      connect(m_pWebSocketServer, &QWebSocketServer::newConnection,
+              this, &WSServer::onNewConnection);
+    }
+}
+
+WSServer::~WSServer()
+{
+    m_pWebSocketServer->close();
+    qDeleteAll(m_clients.begin(), m_clients.end());
+}
+
+void WSServer::onNewConnection()
+{
+    QWebSocket *pSocket = m_pWebSocketServer->nextPendingConnection();
+
+    connect(pSocket, &QWebSocket::textMessageReceived, this, &WSServer::processMessage);
+    connect(pSocket, &QWebSocket::disconnected, this, &WSServer::socketDisconnected);
+
+    m_clients << pSocket;
+}
+
+QJsonObject WSServer::processJsonObj(QJsonObject objin)
+{
+    QJsonObject ret;
+
+    QStringList Keys = objin.keys();
+
+    for (auto k : Keys)
+    {
+        QJsonValue v = objin.value(k);
+
+        if (k == "url")
+        {
+            ret.insert(k, v);
+        }
+        else if (k == "InstanceID")
+        {
+            ret.insert(k, v);
+        }
+        else if (k == "data")
+        {
+            if (v.isObject())
+            {
+                QJsonObject Props = v.toObject();
+                QStringList Propkeys = Props.keys();
+                if (Propkeys.contains("InstanceID"))
+                {
+                    ret.insert("InstanceID", Props.take("InstanceID"));
+                }
+                if (Propkeys.contains("PlatformID"))
+                {
+                    ret.insert("PlatformID", Props.take("PlatformID"));
+                }
+                ret.insert("data",Props);
+            }
+        }
+//            if (v.isArray())
+//            {
+//                for (auto i : v.toArray())
+//                {
+//                    if (i.isString())
+//                    {
+//                        objout->insert(i.toString(),QJsonValue());
+//                    }
+//                }
+//            }
+//            else if (v.isObject())
+//            {
+//                QJsonObject Props = v.toObject();
+//                QStringList Propkeys = Props.keys();
+//                for (auto propkey: Propkeys)
+//                {
+//                    objout->insert(propkey,Props.value(k));
+//                }
+//            }
+
+        // 不想打印
+//        if (v.isObject())
+//        {
+//            processJsonObj(v.toObject(),objout);
+//        }
+
+        // 打印调试信息
+        if (v.isDouble())
+        {
+            qDebug() << k << ": " << v.toDouble();
+        }
+        else if (v.isString())
+        {
+            qDebug() << k << ": " << v.toString();
+        }
+        else if (v.isObject())
+        {
+            qDebug() << k << "{";
+//            processJsonObj(v.toObject(),objout);
+            QJsonObject objout = processJsonObj(v.toObject());
+            qDebug() << "}";
+        }
+        else if (v.isArray())
+        {
+            QJsonArray qarray = v.toArray();
+            qDebug() << k << "[";
+
+            for (auto i : qarray)
+            {
+                if (i.isString())
+                {
+                    qDebug() << i.toString();
+                }
+            }
+            qDebug() << "]";
+        }
+    }
+    //qDebug() << QString(QJsonDocument(*objout).toJson());
+    return ret;
+}
+
+void WSServer::processMessage(QString message)
+{
+    // 获取客户端
+    QWebSocket *pSender = qobject_cast<QWebSocket *>(sender());
+
+    // 以Json格式解码message
+    QByteArray *ByteMessage = new QByteArray();
+    ByteMessage->append(message);
+    QJsonParseError *error = new QJsonParseError();
+    QJsonDocument IncomingJson = QJsonDocument::fromJson(*ByteMessage, error);
+
+
+    if (error->error == QJsonParseError::NoError)
+    {
+        if (IncomingJson.isObject())
+        {
+            // 解析message
+            QJsonObject IncomingObj = IncomingJson.object();
+            QJsonObject msgobj = this->processJsonObj(IncomingObj);
+
+            QStringList props = msgobj.keys();
+            QString url = msgobj.value("url").toString();
+//            qDebug() << QString(QJsonDocument(msgobj).toJson());
+            qDebug() << "url:" << url;
+            // 判断请求
+            if (url == "getInit")
+            {
+                getInit(pSender, msgobj);
+            }
+            else if (url == "getPlatformTable")
+            {
+                getPlatformTable(pSender, msgobj);
+            }
+            else if (url == "getGlobalMap" || url == "getLocalMap" || url == "getRemoteMap" || url == "getCombineMap")
+            {
+                getGlobalMap(pSender, msgobj);
+            }
+            else if (url == "getJammingSig")
+            {
+                getJammingSig(pSender, msgobj);
+            }
+            else
+            {
+                // 其他接口都需要带平台ID
+                if (msgobj.contains("PlatformID")==false)
+                {
+                    QJsonObject *ret = new QJsonObject();
+                    ret->insert("data", QJsonValue());
+                    // 要是没有平台ID,返回空数据
+                    msgobj.insert("data", QJsonValue());
+                    if (msgobj.contains("url") == true)
+                    {
+                        ret->insert("url", msgobj.value("url"));
+                    }
+
+                    returnMessage(pSender, ret);
+                }
+                else if (url == "getRadarInstances")
+                {
+                    getRadarInstances(pSender, msgobj);
+                }
+                else if (url == "getRadarParams" && msgobj.contains("InstanceID"))
+                {
+                    getRadarParams(pSender, msgobj);
+                }
+                else if (url == "getThaadParams" && msgobj.contains("InstanceID"))
+                {
+                    getRadarParams(pSender, msgobj);
+                }
+                else if (url == "getJammingInstances")
+                {
+                    getJammingInstances(pSender, msgobj);
+                }
+                else if (url == "getJammingParams" && msgobj.contains("InstanceID"))
+                {
+                    getJammingParams(pSender, msgobj);
+                }
+                else if (url == "setJammingStyle" && msgobj.contains("InstanceID"))
+                {
+                    setJammingStyle(pSender, msgobj);
+                }
+                else if (url == "getNavParams")
+                {
+//                    getNavParams(msgobj);
+                }
+                else if (url == "setFreePost")
+                {
+//                    setFreePost(msgobj);
+                }
+                else if (url == "getLeadPost")
+                {
+                    getLeadPost(pSender, msgobj);
+                }
+                else if (url == "getTaskPlan")
+                {
+                    getTaskPlan(pSender, msgobj);
+                }
+            }
+
+//        qDebug() << "return message:";
+//        qDebug() << QString(QJsonDocument(*msgobj).toJson());
+
+//        QWebSocket *pSender = qobject_cast<QWebSocket *>(sender());
+//        pSender->sendTextMessage(QString(QJsonDocument(*msgobj).toJson()));
+
+//        for (QWebSocket *pClient : qAsConst(m_clients)) {
+
+//            QJsonDocument *msgdoc = new QJsonDocument(*msgobj);
+
+//            if (pClient == pSender) //don't echo message back to sender
+//            {
+//                QJsonValue msg = new QJsonValue(message);
+//                pClient->sendTextMessage(QString(msgdoc->toJson()));
+//            }
+//            qDebug() << QString(msgdoc->toJson());
+        }
+    }
+}
+
+void WSServer::socketDisconnected()
+{
+    QWebSocket *pClient = qobject_cast<QWebSocket *>(sender());
+    if (pClient)
+    {
+        m_clients.removeAll(pClient);
+        pClient->deleteLater();
+    }
+}
+
+void WSServer::getInit(QWebSocket *pSender, QJsonObject obj)
+{
+    qDebug() << "Build with Slot";
+    // 假接口,指针写法
+    QJsonObject *InitState = new QJsonObject();
+    InitState->insert("InitState", 100);
+    QJsonObject *ret = new QJsonObject();
+    ret->insert("url", obj.value("url"));
+    ret->insert("data", *InitState);
+    delete InitState;
+
+    // 真实接口,局部变量
+//    QJsonObject InitState
+//    {
+//        {"InitState",100*(int)this->grman->common_inter->InitState}
+//    };
+
+//    QJsonObject *ret = new QJsonObject(
+//    {
+//       {"url", obj.value("url")},
+//       {"data", InitState}
+//    });
+
+    returnMessage(pSender, ret);
+}
+
+void WSServer::getLeadPost(QWebSocket *pSender, QJsonObject obj)
+{
+    QJsonArray *LeadPost = new QJsonArray();
+    QJsonObject *CurrentLeadPost;
+
+    CurrentLeadPost = new QJsonObject();
+    CurrentLeadPost->insert("time", "20:20:01");
+    CurrentLeadPost->insert("GroupID", "编队1");
+    CurrentLeadPost->insert("LeaderID", "1001");
+    CurrentLeadPost->insert("Abstract", "发现雷达");
+    LeadPost->append(*CurrentLeadPost);
+    delete CurrentLeadPost;
+    CurrentLeadPost = new QJsonObject();
+    CurrentLeadPost->insert("time", "20:20:30");
+    CurrentLeadPost->insert("GroupID", "编队1");
+    CurrentLeadPost->insert("LeaderID", "1002");
+    CurrentLeadPost->insert("Abstract", "请求施加干扰");
+    LeadPost->append(*CurrentLeadPost);
+    delete CurrentLeadPost;
+    CurrentLeadPost = new QJsonObject();
+    CurrentLeadPost->insert("time", "20:20:40");
+    CurrentLeadPost->insert("GroupID", "编队1");
+    CurrentLeadPost->insert("LeaderID", "1002");
+    CurrentLeadPost->insert("Abstract", "干扰样式生成");
+    LeadPost->append(*CurrentLeadPost);
+    delete CurrentLeadPost;
+    CurrentLeadPost = new QJsonObject();
+    CurrentLeadPost->insert("time", "20:21:00");
+    CurrentLeadPost->insert("GroupID", "编队1");
+    CurrentLeadPost->insert("LeaderID", "1003");
+    CurrentLeadPost->insert("Abstract", "干扰信号发射");
+    LeadPost->append(*CurrentLeadPost);
+    delete CurrentLeadPost;
+
+    QJsonObject *ret = new QJsonObject();
+    ret->insert("url", obj.value("url"));
+    ret->insert("PlatformID", obj.value("PlatformID"));
+    ret->insert("data", *LeadPost);
+
+    delete LeadPost;
+    returnMessage(pSender, ret);
+}
+
+void WSServer::getTaskPlan(QWebSocket *pSender, QJsonObject obj)
+{
+    QJsonObject *TaskPlan = new QJsonObject();
+
+    QJsonObject *CurrentAirLine;
+    QJsonObject *CurrentTaskPlan;
+
+    CurrentAirLine = new QJsonObject;
+    CurrentAirLine->insert("TargetArea", 3);
+    CurrentAirLine->insert("Longitude", 123);
+    CurrentAirLine->insert("Longitude", 27);
+    CurrentAirLine->insert("Radius", 300000);
+
+    CurrentTaskPlan = new QJsonObject;
+    CurrentTaskPlan->insert("TargetArea", 2);
+    CurrentTaskPlan->insert("ThrowGas", 2);
+    CurrentTaskPlan->insert("ThrowBT", 2);
+
+    TaskPlan->insert("Airline", *CurrentAirLine);
+    TaskPlan->insert("TaskPlan", *CurrentTaskPlan);
+
+    QJsonObject *ret = new QJsonObject();
+    ret->insert("url", obj.value("url"));
+    ret->insert("PlatformID", obj.value("PlatformID"));
+    ret->insert("data", *TaskPlan);
+
+    delete TaskPlan;
+    delete CurrentAirLine;
+    delete CurrentTaskPlan;
+    returnMessage(pSender, ret);
+}
+void WSServer::getGlobalMap(QWebSocket *pSender, QJsonObject obj)
+{
+    QJsonArray *alies = new QJsonArray();
+    QJsonArray *enemys = new QJsonArray();
+    QJsonArray *temparray;
+    QJsonObject *tempobj;
+
+    {
+        temparray = new QJsonArray();
+        tempobj = new QJsonObject();
+        tempobj->insert("name", "80xxA电子侦察船_1");
+        temparray->append(120.446), temparray->append(24.8902), temparray->append(100);
+        tempobj->insert("value", *temparray);
+//        alies->insert("80xxA电子侦察船_1"), QJsonValue(*temparray));
+        alies->append(*tempobj);
+        delete temparray;
+        delete tempobj;
+
+        temparray = new QJsonArray();
+        tempobj = new QJsonObject();
+        tempobj->insert("name", "导弹发射架_1");
+        temparray->append(117.525), temparray->append(25.826), temparray->append(100);
+        tempobj->insert("value", *temparray);
+        alies->append(*tempobj);
+        delete temparray;
+        delete tempobj;
+
+        temparray = new QJsonArray();
+        tempobj = new QJsonObject();
+        tempobj->insert("name", "机场_1");
+        temparray->append(119.271), temparray->append(26.26), temparray->append(100);
+        tempobj->insert("value", *temparray);
+        alies->append(*tempobj);
+        delete temparray;
+        delete tempobj;
+
+        temparray = new QJsonArray();
+        tempobj = new QJsonObject();
+        tempobj->insert("name", "预警机_1");
+        temparray->append(120.288), temparray->append(25.5734), temparray->append(100);
+        tempobj->insert("value", *temparray);
+        alies->append(*tempobj);
+        delete temparray;
+        delete tempobj;
+
+        temparray = new QJsonArray();
+        tempobj = new QJsonObject();
+        tempobj->insert("name", "运侦8_1");
+        temparray->append(117.525), temparray->append(25.826), temparray->append(100);
+        tempobj->insert("value", *temparray);
+        alies->append(*tempobj);
+        delete temparray;
+        delete tempobj;
+    }
+
+    {
+        temparray = new QJsonArray();
+        tempobj = new QJsonObject();
+        tempobj->insert("name", "宙斯盾舰");
+        temparray->append(123.528), temparray->append(25.2951), temparray->append(100);
+        tempobj->insert("value",*temparray);
+        enemys->append(*tempobj);
+        delete temparray;
+        delete tempobj;
+    }
+
+    QJsonObject GlobalMap
+    {
+        {"friend", QJsonValue(*alies)},
+        {"enemy", QJsonValue(*enemys)}
+    };
+
+    QJsonObject *ret = new QJsonObject(
+    {
+        {"url", obj.value("url")},
+        {"data", GlobalMap}
+    });
+
+    returnMessage(pSender, ret);
+
+    delete alies;
+    delete enemys;
+}
+
+void WSServer::getPlatformTable(QWebSocket *pSender, QJsonObject obj)
+{
+    QJsonArray Platforms;
+    // 假接口
+    QJsonObject SinglePlatform[] {
+        {
+            {"platformID", 8013},
+            {"platformName", "干扰机_1"}
+        },
+        {
+            {"platformID", 8014},
+            {"platformName", "干扰机_2"}
+        },
+    };
+    for (auto i: SinglePlatform)
+    {
+        Platforms.append(i);
+    }
+
+    // 真实接口
+//    for (auto i : this->grman->grtaskplats)
+//    {
+//        QJsonObject SinglePlatform
+//        {
+//            {"platformID", (int)i->PlatID},
+//            {"platformName", QString::fromLocal8Bit(i->PlatName.c_str())}
+//        };
+//        Platforms.append(SinglePlatform);
+//    }
+
+    // 构造返回对象
+    QJsonObject *ret = new QJsonObject(
+    {
+        {"url", obj.value("url")},
+        {"data", Platforms}
+    });
+    returnMessage(pSender, ret);
+}
+
+void WSServer::getRadarInstances(QWebSocket *pSender, QJsonObject obj)
+{
+    int nowPlatform = obj.value("PlatformID").toInt();
+
+    QJsonArray RadarInstances;
+
+    if (1)
+    {
+        QJsonObject tempRadar
+        {
+            {"instanceID",20},
+            {"instanceName","雷达_1"},
+            {"instanceState","开机"}
+        };
+        RadarInstances.append(tempRadar);
+    }
+    QJsonObject *ret = new QJsonObject();
+    ret->insert("url", obj.value("url"));
+    ret->insert("PlatformID", obj.value("PlatformID"));
+    ret->insert("data",QJsonValue(RadarInstances));
+
+    returnMessage(pSender, ret);
+}
+
+void WSServer::getRadarParams(QWebSocket *pSender, QJsonObject obj)
+{
+
+    int nowInstance = obj.value("InstanceID").toString().toInt();
+
+
+    QJsonObject *ret = new QJsonObject({
+                                           {"url", obj.value("url")},
+                                           {"PlatformID", obj.value("PlatformID")},
+                                           {"InstanceID", obj.value("InstanceID")},
+                                           {"data",QJsonValue()}
+                                       });
+
+    returnMessage(pSender, ret);
+}
+
+void WSServer::getJammingInstances(QWebSocket *pSender, QJsonObject obj)
+{
+    QJsonArray ECMInstances;
+
+    if (1)
+    {
+        QJsonObject tempECM
+        {
+            {"instanceID",20},
+            {"instanceName","ECM_1"},
+            {"instanceState","开机"}
+        };
+        ECMInstances.append(tempECM);
+    }
+
+    QJsonObject *ret = new QJsonObject();
+    ret->insert("url", obj.value("url"));
+    ret->insert("PlatformID", obj.value("PlatformID"));
+    ret->insert("data",QJsonValue(ECMInstances));
+
+    returnMessage(pSender, ret);
+}
+
+void WSServer::getJammingParams(QWebSocket *pSender, QJsonObject obj)
+{
+
+    QJsonArray nowParams = {};
+
+    QJsonObject *ret = new QJsonObject();
+    ret->insert("url", obj.value("url"));
+    ret->insert("PlatformID", obj.value("PlatformID"));
+    ret->insert("InstanceID", obj.value("InstanceID"));
+    ret->insert("data",QJsonValue(nowParams));
+
+    returnMessage(pSender, ret);
+
+}
+
+void WSServer::setJammingStyle(QWebSocket *pSender, QJsonObject obj)
+{
+    // PlatformID和InstanceID是字符串
+    int nowPlatform = obj.value("PlatformID").toString().toInt();
+    int nowInstance = obj.value("InstanceID").toString().toInt();
+
+    QJsonObject *ret = new QJsonObject({
+                                           {"url", obj.value("url")},
+                                           {"PlatformID", obj.value("PlatformID")},
+                                           {"InstanceID", obj.value("InstanceID")},
+                                           {"data",QJsonValue()}
+                                       });
+
+    returnMessage(pSender, ret);
+}
+
+void WSServer::getJammingSig(QWebSocket *pSender, QJsonObject obj)
+{
+    QJsonObject dat = obj.value("data").toObject();
+    if (dat.contains("order")==false)
+    {
+        QJsonObject *ret = new QJsonObject({
+            {"order", 0}
+        });
+        returnMessage(pSender, ret);
+    }
+    else {
+        int order = dat.value("order").toInt();
+        QJsonObject *ret = new QJsonObject({
+            {"order", order}
+        });
+
+        if(order==1){
+            int lines = 0;
+
+            double N = 10000;
+            double B_n = 2e6;
+            double T_s = 100e-6;
+            double m_fe = 1;
+            double f_0 = 10e6;
+            double A = 1;
+            double f_s =100e6;
+            coder::array<double, 2U> S;
+            coder::array<double, 2U> S0;
+            FMjamming_H(N,B_n,f_s,T_s,m_fe,A,f_0,S,S0);
+            ret->insert("size",S.size(1));
+            QJsonArray data;
+            for (int i=0; i<S.size(1); i++)
+            {
+                data.append(S[i]);
+            }
+            ret->insert("data",data);
+        }
+        else if(order==2){
+            int lines = 0;
+            double N = 10000;
+            double B_n = 2e6;
+            double m_A = 1;
+            double f_0 = 10e6;
+            double f_s = 100e6;
+            coder::array<double, 2U> S;
+            AMJamming_H(N,f_s,B_n,f_0,m_A,S);
+            ret->insert("size",S.size(1));
+            QJsonArray data;
+            for (int i=0; i<S.size(1); i++)
+            {
+                data.append(S[i]);
+            }
+            ret->insert("data",data);
+        }
+        else if(order==3){
+            int lines = 0;
+            double N = 1024;
+            double B_n = 2e6;
+            double A = 1;
+            double f_0 = 10e6;
+            double f_s = 100e6;
+            coder::array<creal_T, 2U> S;
+
+            jamming_H(N,f_s,A,B_n,f_0,S);
+            double sig[1024];
+            QJsonArray data;
+            for(int i=0;i<S.size(1);i++)
+            {
+                sig[i] = S[i].re;
+                data.append(sig[i]);
+            }
+            ret->insert("size",1024);
+            ret->insert("data",data);
+        }
+        else if(order==4){
+            int lines = 0;
+            double fd = 200/3e2;
+            double N = 1;
+            double ts = 1/1e7;
+            double Tr = 5e-4;
+            double t_r = 2/1e4;
+            double tau = 30e-6;
+            double fo = 1e6;
+            double k = 1e12/6;
+            double A = 1;
+            double dlt_t = 25e-6;
+            double R = 30e3;
+            double fs = 1e7;
+            coder::array<double, 2U> S;
+            coder::array<double, 2U> S1;
+            coder::array<double, 2U> SS;
+            coder::array<double, 2U> S_disturb;
+            coder::array<double, 2U> S3;
+            false_target_distance(fd,N,ts,Tr,t_r,tau,fo,k,A,dlt_t,R,fs,S,S1,SS,S_disturb,S3);
+            ret->insert("size",S3.size(1));
+            QJsonArray data;
+            for(int i=0;i<S3.size(1);i++)
+            {
+                data.append(S3[i]);
+            }
+            ret->insert("data", data);
+        }
+        else if(order==5){
+            int lines = 0;
+            double fd = 4;
+            double N = 1;
+            double ts = 1e-7;
+            double Tr = 5e-4;
+            double t_r = 20e-5;
+            double tau = 30e-6;
+            double fo = 1e6;
+            double k = 5e6/30e-6;
+            double V = 600;
+            coder::array<double, 2U> S;
+            false_speed(fd,fo,ts,tau,Tr,k,t_r,V,N,S);
+            ret->insert("size",S.size(1));
+            QJsonArray data;
+            for(int i=0;i<S.size(1);i++)
+            {
+                data.append(S[i]);
+            }
+            ret->insert("data", data);
+        }
+        else if(order==6){
+            int lines = 0;
+            double fd = 0.2;
+            double N = 1;
+            double dlt = 25e-6;
+            double S[10500];
+            S_jam(fd,dlt,N,S);
+            ret->insert("size",10500);
+            QJsonArray data;
+            for(int i=0;i<10500;i++)
+            {
+                data.append(S[i]);
+            }
+            ret->insert("data", data);
+        }
+        returnMessage(pSender, ret);
+    }
+}
+
+
+void WSServer::returnMessage(QWebSocket *pSender, QJsonObject *obj)
+{
+    qDebug() << "return message:";
+    qDebug() << QString(QJsonDocument(*obj).toJson());
+    pSender->sendTextMessage(QString(QJsonDocument(*obj).toJson()));
+    delete obj;
+}

+ 60 - 0
wsserver.h

@@ -0,0 +1,60 @@
+#ifndef WSSERVER_H
+#define WSSERVER_H
+
+#include <QObject>
+#include <QList>
+#include <QByteArray>
+#include <QJsonArray>
+#include <QJsonDocument>
+#include <QJsonObject>
+#include <QJsonValue>
+#include <QJsonParseError>
+#include "QtWebSockets/QWebSocketServer"
+#include "QtWebSockets/QWebSocket"
+#include "../share/algorithms/coder_array.h"
+#include "../share/algorithms/fun1_false_target_distance.h"
+#include "../share/algorithms/fun2.h"
+#include "../share/algorithms/fun4_S_jam.h"
+#include "../share/algorithms/fun8_2_FMjamming_H.h"
+#include "../share/algorithms/fun8_AMJamming_H.h"
+#include "../share/algorithms/fun8_3_jamming_H.h"
+#include "../share/algorithms/fun5.h"
+#include "../share/algorithms/fun6.h"
+#include "../share/algorithms/fun7_DRFMRF.h"
+
+//QT_FORWARD_DECLARE_CLASS(QWebSocketServer)
+//QT_FORWARD_DECLARE_CLASS(QWebSocket)
+
+class WSServer : public QObject
+{
+    Q_OBJECT
+public:
+    QWebSocketServer *m_pWebSocketServer;
+    QList<QWebSocket *> m_clients;
+
+    explicit WSServer(QObject *parent = nullptr, quint16 port = 80);
+    virtual ~WSServer();
+signals:
+
+public slots:
+    void onNewConnection();
+    QJsonObject processJsonObj(QJsonObject objin);
+    void processMessage(QString message);
+    void socketDisconnected();
+
+    void getInit(QWebSocket *pSender, QJsonObject obj);
+    void getPlatformTable(QWebSocket *pSender, QJsonObject obj);
+    void getLeadPost(QWebSocket *pSender, QJsonObject obj);
+    void getTaskPlan(QWebSocket *pSender, QJsonObject obj);
+    void getGlobalMap(QWebSocket *pSender, QJsonObject obj);
+    void getRadarInstances(QWebSocket *pSender, QJsonObject obj);
+    void getRadarParams(QWebSocket *pSender, QJsonObject obj);
+    void getJammingInstances(QWebSocket *pSender, QJsonObject obj);
+    void getJammingParams(QWebSocket *pSender, QJsonObject obj);
+    void setJammingStyle(QWebSocket *pSender, QJsonObject obj);
+    void getJammingSig(QWebSocket *pSender, QJsonObject obj);
+
+    void returnMessage(QWebSocket *pSender, QJsonObject *obj);
+};
+
+#endif // WSSERVER_H