123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774 |
- #include "backgroundserver.h"
- BackgroundServer::BackgroundServer(QObject *parent, quint16 port) : QObject(parent)
- {
- sim = new SimulationControl();
- SimThread = new QThread();
- sim->moveToThread(SimThread);
- connect(this,&BackgroundServer::sigGetInit,
- sim,&SimulationControl::SlotGetInit);
- connect(this,&BackgroundServer::sigGetLeadPost,
- sim,&SimulationControl::SlotGetLeadPost);
- connect(this,&BackgroundServer::sigGetTaskPlan,
- sim,&SimulationControl::SlotGetTaskPlan);
- connect(this,&BackgroundServer::sigGetGlobalMap,
- sim,&SimulationControl::SlotGetGlobalMap);
- connect(this,&BackgroundServer::sigGetPlatformTable,
- sim,&SimulationControl::SlotGetPlatformTable);
- connect(this,&BackgroundServer::sigGetInstanceTable,
- sim,&SimulationControl::SlotGetInstanceTable);
- connect(this,&BackgroundServer::sigGetRadarInstances,
- sim,&SimulationControl::SlotGetRadarInstances);
- connect(this,&BackgroundServer::sigGetRadarParams,
- sim,&SimulationControl::SlotGetRadarParams);
- connect(this,&BackgroundServer::sigGetThaadInstances,
- sim,&SimulationControl::SlotGetThaadInstances);
- connect(this,&BackgroundServer::sigGetThaadParams,
- sim,&SimulationControl::SlotGetThaadParams);
- connect(this,&BackgroundServer::sigSetThaadStyle,
- sim,&SimulationControl::SlotSetThaadStyle);
- connect(this,&BackgroundServer::sigGetJammingInstances,
- sim,&SimulationControl::SlotGetJammingInstances);
- connect(this,&BackgroundServer::sigGetJammingParams,
- sim,&SimulationControl::SlotGetJammingParams);
- connect(this,&BackgroundServer::sigSetJammingStyle,
- sim,&SimulationControl::SlotSetJammingStyle);
- connect(this,&BackgroundServer::sigGetESMParams,
- sim,&SimulationControl::SlotGetESMParams);
- connect(sim,&SimulationControl::SigReturnData,
- this,&BackgroundServer::SlotReturnData);
- SimThread->start();
- 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, &BackgroundServer::onNewConnection);
- }
- }
- BackgroundServer::~BackgroundServer()
- {
- m_pWebSocketServer->close();
- qDeleteAll(m_clients.begin(), m_clients.end());
- }
- void BackgroundServer::onNewConnection()
- {
- QWebSocket *pSocket = m_pWebSocketServer->nextPendingConnection();
- connect(pSocket, &QWebSocket::textMessageReceived, this, &BackgroundServer::processMessage);
- connect(pSocket, &QWebSocket::disconnected, this, &BackgroundServer::socketDisconnected);
- m_clients << pSocket;
- }
- QJsonObject BackgroundServer::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 BackgroundServer::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")
- {
- emit sigGetInit(pSender, msgobj);
- }
- else if (url == "getPlatformTable")
- {
- emit sigGetPlatformTable(pSender, msgobj);
- }
- else if (url == "getGlobalMap" || url == "getLocalMap" || url == "getRemoteMap" || url == "getCombineMap")
- {
- emit sigGetGlobalMap(pSender, msgobj);
- }
- else if (url == "getThaadInstances")
- {
- emit sigGetThaadInstances(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"));
- }
- SlotReturnData(pSender, ret);
- }
- else if (url == "getInstanceTable")
- {
- emit sigGetInstanceTable(pSender, msgobj);
- }
- else if (url == "getRadarInstances")
- {
- emit sigGetRadarInstances(pSender, msgobj);
- }
- else if (url == "getRadarParams" && msgobj.contains("InstanceID"))
- {
- emit sigGetRadarParams(pSender, msgobj);
- }
- else if (url == "getThaadParams" && msgobj.contains("InstanceID"))
- {
- emit sigGetRadarParams(pSender, msgobj);
- }
- else if (url == "setThaadStyle" && msgobj.contains("InstanceID"))
- {
- emit sigSetThaadStyle(pSender, msgobj);
- }
- else if (url == "getJammingInstances")
- {
- emit sigGetJammingInstances(pSender, msgobj);
- }
- else if (url == "getJammingParams" && msgobj.contains("InstanceID"))
- {
- emit sigGetJammingParams(pSender, msgobj);
- }
- else if (url == "setJammingStyle" && msgobj.contains("InstanceID"))
- {
- emit sigSetJammingStyle(pSender, msgobj);
- }
- else if (url == "getESMParams")
- {
- emit sigGetESMParams(pSender, msgobj);
- }
- else if (url == "getNavParams")
- {
- // getNavParams(msgobj);
- }
- else if (url == "setFreePost")
- {
- // setFreePost(msgobj);
- }
- else if (url == "getLeadPost")
- {
- emit sigGetLeadPost(pSender, msgobj);
- }
- else if (url == "getTaskPlan")
- {
- emit sigGetTaskPlan(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 BackgroundServer::socketDisconnected()
- {
- QWebSocket *pClient = qobject_cast<QWebSocket *>(sender());
- if (pClient)
- {
- m_clients.removeAll(pClient);
- pClient->deleteLater();
- }
- }
- void BackgroundServer::getInit(QJsonObject *obj)
- {
- //obj->insert("data",QJsonValue(1));
- QJsonObject *InitState = new QJsonObject();
- InitState->insert("InitState", 100);
- obj->insert("data", *InitState);
- delete InitState;
- }
- void BackgroundServer::getLeadPost(QJsonObject *obj)
- {
- QJsonArray *LeadPost = new QJsonArray();
- QJsonObject *CurrentLeadPost;
- CurrentLeadPost = new QJsonObject();
- CurrentLeadPost->insert("time", "20:20:01");
- CurrentLeadPost->insert("GroupID", "0001");
- CurrentLeadPost->insert("LeaderID", "8013");
- CurrentLeadPost->insert("Abstract", QString::fromLocal8Bit("冲冲冲"));
- LeadPost->append(*CurrentLeadPost);
- delete CurrentLeadPost;
- CurrentLeadPost = new QJsonObject();
- CurrentLeadPost->insert("time", "20:20:30");
- CurrentLeadPost->insert("GroupID", "0001");
- CurrentLeadPost->insert("LeaderID", "8013");
- CurrentLeadPost->insert("Abstract", QString::fromLocal8Bit("有点小寄"));
- LeadPost->append(*CurrentLeadPost);
- delete CurrentLeadPost;
- CurrentLeadPost = new QJsonObject();
- CurrentLeadPost->insert("time", "20:20:40");
- CurrentLeadPost->insert("GroupID", "0003");
- CurrentLeadPost->insert("LeaderID", "8014");
- CurrentLeadPost->insert("Abstract", QString::fromLocal8Bit("有内鬼"));
- LeadPost->append(*CurrentLeadPost);
- delete CurrentLeadPost;
- CurrentLeadPost = new QJsonObject();
- CurrentLeadPost->insert("time", "20:21:00");
- CurrentLeadPost->insert("GroupID", "0002");
- CurrentLeadPost->insert("LeaderID", "8015");
- CurrentLeadPost->insert("Abstract", QString::fromLocal8Bit("好起来了"));
- LeadPost->append(*CurrentLeadPost);
- delete CurrentLeadPost;
- obj->insert("data", *LeadPost);
- }
- void BackgroundServer::getTaskPlan(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);
- obj->insert("data", *TaskPlan);
- delete TaskPlan;
- delete CurrentAirLine;
- delete CurrentTaskPlan;
- }
- void BackgroundServer::getGlobalMap(QJsonObject *obj)
- {
- QJsonObject *GlobalMap = new QJsonObject();
- // QJsonObject *alies = new QJsonObject();
- // QJsonObject *enemys = new QJsonObject();
- QJsonArray *alies = new QJsonArray();
- QJsonArray *enemys = new QJsonArray();
- QJsonArray *temparray;
- QJsonObject *tempobj;
- {
- temparray = new QJsonArray();
- tempobj = new QJsonObject();
- tempobj->insert("name", QString::fromLocal8Bit("80xxA电子侦察船_1"));
- temparray->append(120.446), temparray->append(24.8902), temparray->append(100);
- tempobj->insert("value", *temparray);
- // alies->insert(QString::fromLocal8Bit("80xxA电子侦察船_1"), QJsonValue(*temparray));
- alies->append(*tempobj);
- delete temparray;
- delete tempobj;
- temparray = new QJsonArray();
- tempobj = new QJsonObject();
- tempobj->insert("name", QString::fromLocal8Bit("导弹发射架_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", QString::fromLocal8Bit("机场_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", QString::fromLocal8Bit("预警机_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", QString::fromLocal8Bit("运侦8_1"));
- temparray->append(117.525), temparray->append(25.826), temparray->append(100);
- tempobj->insert("value", *temparray);
- alies->append(*tempobj);
- delete temparray;
- delete tempobj;
- }
- GlobalMap->insert("friend", QJsonValue(*alies));
- {
- temparray = new QJsonArray();
- tempobj = new QJsonObject();
- tempobj->insert("name", QString::fromLocal8Bit("宙斯盾舰"));
- temparray->append(123.528), temparray->append(25.2951), temparray->append(100);
- tempobj->insert("value",*temparray);
- enemys->append(*tempobj);
- delete temparray;
- delete tempobj;
- }
- GlobalMap->insert("enemy", QJsonValue(*enemys));
- obj->insert("data",QJsonValue(*GlobalMap));
- delete GlobalMap;
- delete alies;
- delete enemys;
- }
- void BackgroundServer::getPlatformTable(QJsonObject *obj)
- {
- QJsonArray *Platforms = new QJsonArray();
- QJsonObject *SinglePlatform;
- {
- SinglePlatform = new QJsonObject();
- SinglePlatform->insert("platformID", 8015);
- SinglePlatform->insert("platformName", QString::fromLocal8Bit("侦察机_1"));
- Platforms->append(*SinglePlatform);
- delete SinglePlatform;
- SinglePlatform = new QJsonObject();
- SinglePlatform->insert("platformID", 8016);
- SinglePlatform->insert("platformName", QString::fromLocal8Bit("侦察机_2"));
- Platforms->append(*SinglePlatform);
- delete SinglePlatform;
- }
- obj->insert("data",QJsonValue(*Platforms));
- delete Platforms;
- }
- void BackgroundServer::getInstanceTable(QJsonObject *obj)
- {
- QJsonArray *Instances = new QJsonArray();
- QJsonObject *SingleInstance;
- if (true)
- {
- SingleInstance = new QJsonObject();
- SingleInstance->insert("instanceID", 22);
- SingleInstance->insert("instanceName", QString::fromLocal8Bit("侦察机_1"));
- Instances->append(*SingleInstance);
- delete SingleInstance;
- SingleInstance = new QJsonObject();
- SingleInstance->insert("instanceID", 62);
- SingleInstance->insert("instanceName", QString::fromLocal8Bit("信号侦察_1"));
- Instances->append(*SingleInstance);
- delete SingleInstance;
- SingleInstance = new QJsonObject();
- SingleInstance->insert("instanceID", 96);
- SingleInstance->insert("instanceName", QString::fromLocal8Bit("体系增量_1"));
- Instances->append(*SingleInstance);
- delete SingleInstance;
- SingleInstance = new QJsonObject();
- SingleInstance->insert("instanceID", 111);
- SingleInstance->insert("instanceName", QString::fromLocal8Bit("侦察平台任务系统_1"));
- Instances->append(*SingleInstance);
- delete SingleInstance;
- SingleInstance = new QJsonObject();
- SingleInstance->insert("instanceID", 171);
- SingleInstance->insert("instanceName", QString::fromLocal8Bit("导航_1"));
- Instances->append(*SingleInstance);
- delete SingleInstance;
- }
- obj->insert("data",QJsonValue(*Instances));
- delete Instances;
- }
- void BackgroundServer::getESMParams(QJsonObject *obj)
- {
- int InstanceID = obj->value("InstanceID").toInt();
- QJsonArray *ESMInitParams;
- QJsonArray *ESMCtrlParams;
- QJsonObject *ESMPropTemp;
- if (true)
- {
- ESMInitParams = new QJsonArray();
- ESMCtrlParams = new QJsonArray();
- ESMPropTemp = new QJsonObject();
- ESMPropTemp->insert("key","fBeamAzWidth");
- ESMPropTemp->insert("value",2);
- ESMInitParams->append(*ESMPropTemp);
- delete ESMPropTemp;
- ESMPropTemp = new QJsonObject();
- ESMPropTemp->insert("key","fBeamElWidth");
- ESMPropTemp->insert("value",2);
- ESMInitParams->append(*ESMPropTemp);
- delete ESMPropTemp;
- ESMPropTemp = new QJsonObject();
- ESMPropTemp->insert("key","fTecMinFreqMhz");
- ESMPropTemp->insert("value",2e3);
- ESMInitParams->append(*ESMPropTemp);
- delete ESMPropTemp;
- ESMPropTemp = new QJsonObject();
- ESMPropTemp->insert("key","fTecMaxFreqMhz");
- ESMPropTemp->insert("value",18e3);
- ESMInitParams->append(*ESMPropTemp);
- delete ESMPropTemp;
- ESMPropTemp = new QJsonObject();
- ESMPropTemp->insert("key","fInstantPageWidMhz");
- ESMPropTemp->insert("value",500);
- ESMInitParams->append(*ESMPropTemp);
- delete ESMPropTemp;
- ESMPropTemp = new QJsonObject();
- ESMPropTemp->insert("key","ulChanNum");
- ESMPropTemp->insert("value",64);
- ESMInitParams->append(*ESMPropTemp);
- delete ESMPropTemp;
- ESMPropTemp = new QJsonObject();
- ESMPropTemp->insert("key","fTecMinPW");
- ESMPropTemp->insert("value",0.5);
- ESMInitParams->append(*ESMPropTemp);
- delete ESMPropTemp;
- ESMPropTemp = new QJsonObject();
- ESMPropTemp->insert("key","fTecMaxPW");
- ESMPropTemp->insert("value",10);
- ESMInitParams->append(*ESMPropTemp);
- delete ESMPropTemp;
- ESMPropTemp = new QJsonObject();
- ESMPropTemp->insert("key","fTecPriMean");
- ESMPropTemp->insert("value",40);
- ESMInitParams->append(*ESMPropTemp);
- delete ESMPropTemp;
- ESMPropTemp = new QJsonObject();
- ESMPropTemp->insert("key","ulTecTrNumMean");
- ESMPropTemp->insert("value",5);
- ESMInitParams->append(*ESMPropTemp);
- delete ESMPropTemp;
- ESMPropTemp = new QJsonObject();
- ESMPropTemp->insert("key","fMinSnrdB");
- ESMPropTemp->insert("value",0.5);
- ESMInitParams->append(*ESMPropTemp);
- delete ESMPropTemp;
- ESMPropTemp = new QJsonObject();
- ESMPropTemp->insert("key","fSysRcvLoss");
- ESMPropTemp->insert("value",5);
- ESMInitParams->append(*ESMPropTemp);
- delete ESMPropTemp;
- ESMPropTemp = new QJsonObject();
- ESMPropTemp->insert("key","fFreqAccuracyReq");
- ESMPropTemp->insert("value",100);
- ESMInitParams->append(*ESMPropTemp);
- delete ESMPropTemp;
- ESMPropTemp = new QJsonObject();
- ESMPropTemp->insert("key","uRrPowerOn");
- ESMPropTemp->insert("value",0);
- ESMCtrlParams->append(*ESMPropTemp);
- delete ESMPropTemp;
- ESMPropTemp = new QJsonObject();
- ESMPropTemp->insert("key","uRrWorkMode");
- ESMPropTemp->insert("value",0);
- ESMCtrlParams->append(*ESMPropTemp);
- delete ESMPropTemp;
- ESMPropTemp = new QJsonObject();
- ESMPropTemp->insert("key","dScanAzCentDeg");
- ESMPropTemp->insert("value",0);
- ESMCtrlParams->append(*ESMPropTemp);
- delete ESMPropTemp;
- ESMPropTemp = new QJsonObject();
- ESMPropTemp->insert("key","dScanAzWidthDeg");
- ESMPropTemp->insert("value",5);
- ESMCtrlParams->append(*ESMPropTemp);
- delete ESMPropTemp;
- ESMPropTemp = new QJsonObject();
- ESMPropTemp->insert("key","dScanElCentDeg");
- ESMPropTemp->insert("value",0);
- ESMCtrlParams->append(*ESMPropTemp);
- delete ESMPropTemp;
- ESMPropTemp = new QJsonObject();
- ESMPropTemp->insert("key","uLineNumPerFrame");
- ESMPropTemp->insert("value",20);
- ESMCtrlParams->append(*ESMPropTemp);
- delete ESMPropTemp;
- ESMPropTemp = new QJsonObject();
- ESMPropTemp->insert("key","fAntScanVel");
- ESMPropTemp->insert("value",1);
- ESMCtrlParams->append(*ESMPropTemp);
- delete ESMPropTemp;
- ESMPropTemp = new QJsonObject();
- ESMPropTemp->insert("key","fFreqScanVel");
- ESMPropTemp->insert("value",100);
- ESMCtrlParams->append(*ESMPropTemp);
- delete ESMPropTemp;
- ESMPropTemp = new QJsonObject();
- ESMPropTemp->insert("key","fTecBeginFreqMhz");
- ESMPropTemp->insert("value",500);
- ESMCtrlParams->append(*ESMPropTemp);
- delete ESMPropTemp;
- ESMPropTemp = new QJsonObject();
- ESMPropTemp->insert("key","fTecEndFreqMhz");
- ESMPropTemp->insert("value",10000);
- ESMCtrlParams->append(*ESMPropTemp);
- delete ESMPropTemp;
- QJsonObject *ESMParams = new QJsonObject();
- ESMParams->insert("InitParams", *ESMInitParams);
- ESMParams->insert("CtrlParams", *ESMCtrlParams);
- obj->insert("data", *ESMParams);
- delete ESMInitParams;
- delete ESMCtrlParams;
- delete ESMParams;
- }
- }
- void BackgroundServer::getESMData(QJsonObject *obj)
- {
- }
- void BackgroundServer::getNavParams(QJsonObject *obj)
- {
- if (obj->contains("InstanceID")==false)
- {
- obj->insert("data", QJsonValue());
- return;
- }
- int InstanceID = obj->value("InstanceID").toInt();
- QJsonArray *NavInitParams;
- QJsonArray *NavCtrlParams;
- QJsonObject *NavPropTemp;
- NavInitParams = new QJsonArray();
- NavCtrlParams = new QJsonArray();
- NavPropTemp = new QJsonObject();
- NavPropTemp->insert("key","precision");
- NavPropTemp->insert("value",QJsonValue(5));
- NavInitParams->append(*NavPropTemp);
- delete NavPropTemp;
- qDebug() << "aaa" << QString(QJsonDocument(*NavCtrlParams).toJson());
- NavPropTemp = new QJsonObject();
- NavPropTemp->insert("key","longitude");
- NavPropTemp->insert("value",QJsonValue(120));
- NavCtrlParams->append(*NavPropTemp);
- delete NavPropTemp;
- NavPropTemp = new QJsonObject();
- NavPropTemp->insert("key","latitude");
- NavPropTemp->insert("value",QJsonValue(30));
- NavCtrlParams->append(*NavPropTemp);
- delete NavPropTemp;
- NavPropTemp = new QJsonObject();
- NavPropTemp->insert("key","altitude");
- NavPropTemp->insert("value",QJsonValue(8014.8));
- NavCtrlParams->append(*NavPropTemp);
- delete NavPropTemp;
- NavPropTemp = new QJsonObject();
- NavPropTemp->insert("key","azimush");
- NavPropTemp->insert("value",QJsonValue(10));
- NavCtrlParams->append(*NavPropTemp);
- delete NavPropTemp;
- NavPropTemp = new QJsonObject();
- NavPropTemp->insert("key","elevation");
- NavPropTemp->insert("value",QJsonValue(-3));
- NavCtrlParams->append(*NavPropTemp);
- delete NavPropTemp;
- QJsonObject *NAVParams = new QJsonObject();
- NAVParams->insert("InitParams", *NavInitParams);
- NAVParams->insert("CtrlParams", *NavCtrlParams);
- obj->insert("data", *NAVParams);
- QJsonDocument *NavDoc = new QJsonDocument(*NAVParams);
- qDebug() << QString(NavDoc->toJson());
- delete NavDoc;
- delete NavInitParams;
- delete NavCtrlParams;
- delete NAVParams;
- }
- void BackgroundServer::setFreePost(QJsonObject *obj)
- {
- if (obj->contains("PlatformID")==false)
- {
- obj->insert("data", QJsonValue());
- return;
- }
- }
- void BackgroundServer::SlotReturnData(QWebSocket *pSender, QJsonObject *obj)
- {
- qDebug() << "return message:";
- qDebug() << QString(QJsonDocument(*obj).toJson());
- pSender->sendTextMessage(QString(QJsonDocument(*obj).toJson()));
- delete obj;
- }
|