backgroundserver.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. #include "backgroundserver.h"
  2. BackgroundServer::BackgroundServer(QObject *parent, quint16 port) : QObject(parent)
  3. {
  4. sim = new SimulationControl();
  5. SimThread = new QThread();
  6. sim->moveToThread(SimThread);
  7. connect(this,&BackgroundServer::sigGetInit,
  8. sim,&SimulationControl::SlotGetInit);
  9. connect(this,&BackgroundServer::sigGetLeadPost,
  10. sim,&SimulationControl::SlotGetLeadPost);
  11. connect(this,&BackgroundServer::sigGetTaskPlan,
  12. sim,&SimulationControl::SlotGetTaskPlan);
  13. connect(this,&BackgroundServer::sigGetGlobalMap,
  14. sim,&SimulationControl::SlotGetGlobalMap);
  15. connect(this,&BackgroundServer::sigGetPlatformTable,
  16. sim,&SimulationControl::SlotGetPlatformTable);
  17. connect(this,&BackgroundServer::sigGetInstanceTable,
  18. sim,&SimulationControl::SlotGetInstanceTable);
  19. connect(this,&BackgroundServer::sigGetRadarInstances,
  20. sim,&SimulationControl::SlotGetRadarInstances);
  21. connect(this,&BackgroundServer::sigGetRadarParams,
  22. sim,&SimulationControl::SlotGetRadarParams);
  23. connect(this,&BackgroundServer::sigGetThaadInstances,
  24. sim,&SimulationControl::SlotGetThaadInstances);
  25. connect(this,&BackgroundServer::sigGetThaadParams,
  26. sim,&SimulationControl::SlotGetThaadParams);
  27. connect(this,&BackgroundServer::sigSetThaadStyle,
  28. sim,&SimulationControl::SlotSetThaadStyle);
  29. connect(this,&BackgroundServer::sigGetJammingInstances,
  30. sim,&SimulationControl::SlotGetJammingInstances);
  31. connect(this,&BackgroundServer::sigGetJammingParams,
  32. sim,&SimulationControl::SlotGetJammingParams);
  33. connect(this,&BackgroundServer::sigSetJammingStyle,
  34. sim,&SimulationControl::SlotSetJammingStyle);
  35. connect(this,&BackgroundServer::sigGetESMParams,
  36. sim,&SimulationControl::SlotGetESMParams);
  37. connect(sim,&SimulationControl::SigReturnData,
  38. this,&BackgroundServer::SlotReturnData);
  39. SimThread->start();
  40. m_pWebSocketServer = new QWebSocketServer(QStringLiteral("Mock Server"),
  41. QWebSocketServer::NonSecureMode,
  42. this);
  43. if (m_pWebSocketServer->listen(QHostAddress::Any, port))
  44. {
  45. qDebug() << "Mock Server listening on port" << port;
  46. connect(m_pWebSocketServer, &QWebSocketServer::newConnection,
  47. this, &BackgroundServer::onNewConnection);
  48. }
  49. }
  50. BackgroundServer::~BackgroundServer()
  51. {
  52. m_pWebSocketServer->close();
  53. qDeleteAll(m_clients.begin(), m_clients.end());
  54. }
  55. void BackgroundServer::onNewConnection()
  56. {
  57. QWebSocket *pSocket = m_pWebSocketServer->nextPendingConnection();
  58. connect(pSocket, &QWebSocket::textMessageReceived, this, &BackgroundServer::processMessage);
  59. connect(pSocket, &QWebSocket::disconnected, this, &BackgroundServer::socketDisconnected);
  60. m_clients << pSocket;
  61. }
  62. QJsonObject BackgroundServer::processJsonObj(QJsonObject objin)
  63. {
  64. QJsonObject ret;
  65. QStringList Keys = objin.keys();
  66. for (auto k : Keys)
  67. {
  68. QJsonValue v = objin.value(k);
  69. if (k == "url")
  70. {
  71. ret.insert(k, v);
  72. }
  73. else if (k == "InstanceID")
  74. {
  75. ret.insert(k, v);
  76. }
  77. else if (k == "data")
  78. {
  79. if (v.isObject())
  80. {
  81. QJsonObject Props = v.toObject();
  82. QStringList Propkeys = Props.keys();
  83. if (Propkeys.contains("InstanceID"))
  84. {
  85. ret.insert("InstanceID", Props.take("InstanceID"));
  86. }
  87. if (Propkeys.contains("PlatformID"))
  88. {
  89. ret.insert("PlatformID", Props.take("PlatformID"));
  90. }
  91. ret.insert("data",Props);
  92. }
  93. }
  94. // if (v.isArray())
  95. // {
  96. // for (auto i : v.toArray())
  97. // {
  98. // if (i.isString())
  99. // {
  100. // objout->insert(i.toString(),QJsonValue());
  101. // }
  102. // }
  103. // }
  104. // else if (v.isObject())
  105. // {
  106. // QJsonObject Props = v.toObject();
  107. // QStringList Propkeys = Props.keys();
  108. // for (auto propkey: Propkeys)
  109. // {
  110. // objout->insert(propkey,Props.value(k));
  111. // }
  112. // }
  113. // 不想打印
  114. // if (v.isObject())
  115. // {
  116. // processJsonObj(v.toObject(),objout);
  117. // }
  118. // 打印调试信息
  119. if (v.isDouble())
  120. {
  121. qDebug() << k << ": " << v.toDouble();
  122. }
  123. else if (v.isString())
  124. {
  125. qDebug() << k << ": " << v.toString();
  126. }
  127. else if (v.isObject())
  128. {
  129. qDebug() << k << "{";
  130. // processJsonObj(v.toObject(),objout);
  131. QJsonObject objout = processJsonObj(v.toObject());
  132. qDebug() << "}";
  133. }
  134. else if (v.isArray())
  135. {
  136. QJsonArray qarray = v.toArray();
  137. qDebug() << k << "[";
  138. for (auto i : qarray)
  139. {
  140. if (i.isString())
  141. {
  142. qDebug() << i.toString();
  143. }
  144. }
  145. qDebug() << "]";
  146. }
  147. }
  148. //qDebug() << QString(QJsonDocument(*objout).toJson());
  149. return ret;
  150. }
  151. void BackgroundServer::processMessage(QString message)
  152. {
  153. // 获取客户端
  154. QWebSocket *pSender = qobject_cast<QWebSocket *>(sender());
  155. // 以Json格式解码message
  156. QByteArray *ByteMessage = new QByteArray();
  157. ByteMessage->append(message);
  158. QJsonParseError *error = new QJsonParseError();
  159. QJsonDocument IncomingJson = QJsonDocument::fromJson(*ByteMessage, error);
  160. if (error->error == QJsonParseError::NoError)
  161. {
  162. if (IncomingJson.isObject())
  163. {
  164. // 解析message
  165. QJsonObject IncomingObj = IncomingJson.object();
  166. QJsonObject msgobj = this->processJsonObj(IncomingObj);
  167. QStringList props = msgobj.keys();
  168. QString url = msgobj.value("url").toString();
  169. // qDebug() << QString(QJsonDocument(msgobj).toJson());
  170. qDebug() << "url:" << url;
  171. // 判断请求
  172. if (url == "getInit")
  173. {
  174. emit sigGetInit(pSender, msgobj);
  175. }
  176. else if (url == "getPlatformTable")
  177. {
  178. emit sigGetPlatformTable(pSender, msgobj);
  179. }
  180. else if (url == "getGlobalMap" || url == "getLocalMap" || url == "getRemoteMap" || url == "getCombineMap")
  181. {
  182. emit sigGetGlobalMap(pSender, msgobj);
  183. }
  184. else if (url == "getThaadInstances")
  185. {
  186. emit sigGetThaadInstances(pSender, msgobj);
  187. }
  188. else
  189. {
  190. // 其他接口都需要带平台ID
  191. if (msgobj.contains("PlatformID")==false)
  192. {
  193. QJsonObject *ret = new QJsonObject();
  194. ret->insert("data", QJsonValue());
  195. // 要是没有平台ID,返回空数据
  196. msgobj.insert("data", QJsonValue());
  197. if (msgobj.contains("url") == true)
  198. {
  199. ret->insert("url", msgobj.value("url"));
  200. }
  201. SlotReturnData(pSender, ret);
  202. }
  203. else if (url == "getInstanceTable")
  204. {
  205. emit sigGetInstanceTable(pSender, msgobj);
  206. }
  207. else if (url == "getRadarInstances")
  208. {
  209. emit sigGetRadarInstances(pSender, msgobj);
  210. }
  211. else if (url == "getRadarParams" && msgobj.contains("InstanceID"))
  212. {
  213. emit sigGetRadarParams(pSender, msgobj);
  214. }
  215. else if (url == "getThaadParams" && msgobj.contains("InstanceID"))
  216. {
  217. emit sigGetRadarParams(pSender, msgobj);
  218. }
  219. else if (url == "setThaadStyle" && msgobj.contains("InstanceID"))
  220. {
  221. emit sigSetThaadStyle(pSender, msgobj);
  222. }
  223. else if (url == "getJammingInstances")
  224. {
  225. emit sigGetJammingInstances(pSender, msgobj);
  226. }
  227. else if (url == "getJammingParams" && msgobj.contains("InstanceID"))
  228. {
  229. emit sigGetJammingParams(pSender, msgobj);
  230. }
  231. else if (url == "setJammingStyle" && msgobj.contains("InstanceID"))
  232. {
  233. emit sigSetJammingStyle(pSender, msgobj);
  234. }
  235. else if (url == "getESMParams")
  236. {
  237. emit sigGetESMParams(pSender, msgobj);
  238. }
  239. else if (url == "getNavParams")
  240. {
  241. // getNavParams(msgobj);
  242. }
  243. else if (url == "setFreePost")
  244. {
  245. // setFreePost(msgobj);
  246. }
  247. else if (url == "getLeadPost")
  248. {
  249. emit sigGetLeadPost(pSender, msgobj);
  250. }
  251. else if (url == "getTaskPlan")
  252. {
  253. emit sigGetTaskPlan(pSender, msgobj);
  254. }
  255. }
  256. // qDebug() << "return message:";
  257. // qDebug() << QString(QJsonDocument(*msgobj).toJson());
  258. // QWebSocket *pSender = qobject_cast<QWebSocket *>(sender());
  259. // pSender->sendTextMessage(QString(QJsonDocument(*msgobj).toJson()));
  260. // for (QWebSocket *pClient : qAsConst(m_clients)) {
  261. // QJsonDocument *msgdoc = new QJsonDocument(*msgobj);
  262. // if (pClient == pSender) //don't echo message back to sender
  263. // {
  264. // QJsonValue msg = new QJsonValue(message);
  265. // pClient->sendTextMessage(QString(msgdoc->toJson()));
  266. // }
  267. // qDebug() << QString(msgdoc->toJson());
  268. }
  269. }
  270. }
  271. void BackgroundServer::socketDisconnected()
  272. {
  273. QWebSocket *pClient = qobject_cast<QWebSocket *>(sender());
  274. if (pClient)
  275. {
  276. m_clients.removeAll(pClient);
  277. pClient->deleteLater();
  278. }
  279. }
  280. void BackgroundServer::getInit(QJsonObject *obj)
  281. {
  282. //obj->insert("data",QJsonValue(1));
  283. QJsonObject *InitState = new QJsonObject();
  284. InitState->insert("InitState", 100);
  285. obj->insert("data", *InitState);
  286. delete InitState;
  287. }
  288. void BackgroundServer::getLeadPost(QJsonObject *obj)
  289. {
  290. QJsonArray *LeadPost = new QJsonArray();
  291. QJsonObject *CurrentLeadPost;
  292. CurrentLeadPost = new QJsonObject();
  293. CurrentLeadPost->insert("time", "20:20:01");
  294. CurrentLeadPost->insert("GroupID", "0001");
  295. CurrentLeadPost->insert("LeaderID", "8013");
  296. CurrentLeadPost->insert("Abstract", QString::fromLocal8Bit("冲冲冲"));
  297. LeadPost->append(*CurrentLeadPost);
  298. delete CurrentLeadPost;
  299. CurrentLeadPost = new QJsonObject();
  300. CurrentLeadPost->insert("time", "20:20:30");
  301. CurrentLeadPost->insert("GroupID", "0001");
  302. CurrentLeadPost->insert("LeaderID", "8013");
  303. CurrentLeadPost->insert("Abstract", QString::fromLocal8Bit("有点小寄"));
  304. LeadPost->append(*CurrentLeadPost);
  305. delete CurrentLeadPost;
  306. CurrentLeadPost = new QJsonObject();
  307. CurrentLeadPost->insert("time", "20:20:40");
  308. CurrentLeadPost->insert("GroupID", "0003");
  309. CurrentLeadPost->insert("LeaderID", "8014");
  310. CurrentLeadPost->insert("Abstract", QString::fromLocal8Bit("有内鬼"));
  311. LeadPost->append(*CurrentLeadPost);
  312. delete CurrentLeadPost;
  313. CurrentLeadPost = new QJsonObject();
  314. CurrentLeadPost->insert("time", "20:21:00");
  315. CurrentLeadPost->insert("GroupID", "0002");
  316. CurrentLeadPost->insert("LeaderID", "8015");
  317. CurrentLeadPost->insert("Abstract", QString::fromLocal8Bit("好起来了"));
  318. LeadPost->append(*CurrentLeadPost);
  319. delete CurrentLeadPost;
  320. obj->insert("data", *LeadPost);
  321. }
  322. void BackgroundServer::getTaskPlan(QJsonObject *obj)
  323. {
  324. QJsonObject *TaskPlan = new QJsonObject();
  325. QJsonObject *CurrentAirLine;
  326. QJsonObject *CurrentTaskPlan;
  327. CurrentAirLine = new QJsonObject;
  328. CurrentAirLine->insert("TargetArea", 3);
  329. CurrentAirLine->insert("Longitude", 123);
  330. CurrentAirLine->insert("Longitude", 27);
  331. CurrentAirLine->insert("Radius", 300000);
  332. CurrentTaskPlan = new QJsonObject;
  333. CurrentTaskPlan->insert("TargetArea", 2);
  334. CurrentTaskPlan->insert("ThrowGas", 2);
  335. CurrentTaskPlan->insert("ThrowBT", 2);
  336. TaskPlan->insert("Airline", *CurrentAirLine);
  337. TaskPlan->insert("TaskPlan", *CurrentTaskPlan);
  338. obj->insert("data", *TaskPlan);
  339. delete TaskPlan;
  340. delete CurrentAirLine;
  341. delete CurrentTaskPlan;
  342. }
  343. void BackgroundServer::getGlobalMap(QJsonObject *obj)
  344. {
  345. QJsonObject *GlobalMap = new QJsonObject();
  346. // QJsonObject *alies = new QJsonObject();
  347. // QJsonObject *enemys = new QJsonObject();
  348. QJsonArray *alies = new QJsonArray();
  349. QJsonArray *enemys = new QJsonArray();
  350. QJsonArray *temparray;
  351. QJsonObject *tempobj;
  352. {
  353. temparray = new QJsonArray();
  354. tempobj = new QJsonObject();
  355. tempobj->insert("name", QString::fromLocal8Bit("80xxA电子侦察船_1"));
  356. temparray->append(120.446), temparray->append(24.8902), temparray->append(100);
  357. tempobj->insert("value", *temparray);
  358. // alies->insert(QString::fromLocal8Bit("80xxA电子侦察船_1"), QJsonValue(*temparray));
  359. alies->append(*tempobj);
  360. delete temparray;
  361. delete tempobj;
  362. temparray = new QJsonArray();
  363. tempobj = new QJsonObject();
  364. tempobj->insert("name", QString::fromLocal8Bit("导弹发射架_1"));
  365. temparray->append(117.525), temparray->append(25.826), temparray->append(100);
  366. tempobj->insert("value", *temparray);
  367. alies->append(*tempobj);
  368. delete temparray;
  369. delete tempobj;
  370. temparray = new QJsonArray();
  371. tempobj = new QJsonObject();
  372. tempobj->insert("name", QString::fromLocal8Bit("机场_1"));
  373. temparray->append(119.271), temparray->append(26.26), temparray->append(100);
  374. tempobj->insert("value", *temparray);
  375. alies->append(*tempobj);
  376. delete temparray;
  377. delete tempobj;
  378. temparray = new QJsonArray();
  379. tempobj = new QJsonObject();
  380. tempobj->insert("name", QString::fromLocal8Bit("预警机_1"));
  381. temparray->append(120.288), temparray->append(25.5734), temparray->append(100);
  382. tempobj->insert("value", *temparray);
  383. alies->append(*tempobj);
  384. delete temparray;
  385. delete tempobj;
  386. temparray = new QJsonArray();
  387. tempobj = new QJsonObject();
  388. tempobj->insert("name", QString::fromLocal8Bit("运侦8_1"));
  389. temparray->append(117.525), temparray->append(25.826), temparray->append(100);
  390. tempobj->insert("value", *temparray);
  391. alies->append(*tempobj);
  392. delete temparray;
  393. delete tempobj;
  394. }
  395. GlobalMap->insert("friend", QJsonValue(*alies));
  396. {
  397. temparray = new QJsonArray();
  398. tempobj = new QJsonObject();
  399. tempobj->insert("name", QString::fromLocal8Bit("宙斯盾舰"));
  400. temparray->append(123.528), temparray->append(25.2951), temparray->append(100);
  401. tempobj->insert("value",*temparray);
  402. enemys->append(*tempobj);
  403. delete temparray;
  404. delete tempobj;
  405. }
  406. GlobalMap->insert("enemy", QJsonValue(*enemys));
  407. obj->insert("data",QJsonValue(*GlobalMap));
  408. delete GlobalMap;
  409. delete alies;
  410. delete enemys;
  411. }
  412. void BackgroundServer::getPlatformTable(QJsonObject *obj)
  413. {
  414. QJsonArray *Platforms = new QJsonArray();
  415. QJsonObject *SinglePlatform;
  416. {
  417. SinglePlatform = new QJsonObject();
  418. SinglePlatform->insert("platformID", 8015);
  419. SinglePlatform->insert("platformName", QString::fromLocal8Bit("侦察机_1"));
  420. Platforms->append(*SinglePlatform);
  421. delete SinglePlatform;
  422. SinglePlatform = new QJsonObject();
  423. SinglePlatform->insert("platformID", 8016);
  424. SinglePlatform->insert("platformName", QString::fromLocal8Bit("侦察机_2"));
  425. Platforms->append(*SinglePlatform);
  426. delete SinglePlatform;
  427. }
  428. obj->insert("data",QJsonValue(*Platforms));
  429. delete Platforms;
  430. }
  431. void BackgroundServer::getInstanceTable(QJsonObject *obj)
  432. {
  433. QJsonArray *Instances = new QJsonArray();
  434. QJsonObject *SingleInstance;
  435. if (true)
  436. {
  437. SingleInstance = new QJsonObject();
  438. SingleInstance->insert("instanceID", 22);
  439. SingleInstance->insert("instanceName", QString::fromLocal8Bit("侦察机_1"));
  440. Instances->append(*SingleInstance);
  441. delete SingleInstance;
  442. SingleInstance = new QJsonObject();
  443. SingleInstance->insert("instanceID", 62);
  444. SingleInstance->insert("instanceName", QString::fromLocal8Bit("信号侦察_1"));
  445. Instances->append(*SingleInstance);
  446. delete SingleInstance;
  447. SingleInstance = new QJsonObject();
  448. SingleInstance->insert("instanceID", 96);
  449. SingleInstance->insert("instanceName", QString::fromLocal8Bit("体系增量_1"));
  450. Instances->append(*SingleInstance);
  451. delete SingleInstance;
  452. SingleInstance = new QJsonObject();
  453. SingleInstance->insert("instanceID", 111);
  454. SingleInstance->insert("instanceName", QString::fromLocal8Bit("侦察平台任务系统_1"));
  455. Instances->append(*SingleInstance);
  456. delete SingleInstance;
  457. SingleInstance = new QJsonObject();
  458. SingleInstance->insert("instanceID", 171);
  459. SingleInstance->insert("instanceName", QString::fromLocal8Bit("导航_1"));
  460. Instances->append(*SingleInstance);
  461. delete SingleInstance;
  462. }
  463. obj->insert("data",QJsonValue(*Instances));
  464. delete Instances;
  465. }
  466. void BackgroundServer::getESMParams(QJsonObject *obj)
  467. {
  468. int InstanceID = obj->value("InstanceID").toInt();
  469. QJsonArray *ESMInitParams;
  470. QJsonArray *ESMCtrlParams;
  471. QJsonObject *ESMPropTemp;
  472. if (true)
  473. {
  474. ESMInitParams = new QJsonArray();
  475. ESMCtrlParams = new QJsonArray();
  476. ESMPropTemp = new QJsonObject();
  477. ESMPropTemp->insert("key","fBeamAzWidth");
  478. ESMPropTemp->insert("value",2);
  479. ESMInitParams->append(*ESMPropTemp);
  480. delete ESMPropTemp;
  481. ESMPropTemp = new QJsonObject();
  482. ESMPropTemp->insert("key","fBeamElWidth");
  483. ESMPropTemp->insert("value",2);
  484. ESMInitParams->append(*ESMPropTemp);
  485. delete ESMPropTemp;
  486. ESMPropTemp = new QJsonObject();
  487. ESMPropTemp->insert("key","fTecMinFreqMhz");
  488. ESMPropTemp->insert("value",2e3);
  489. ESMInitParams->append(*ESMPropTemp);
  490. delete ESMPropTemp;
  491. ESMPropTemp = new QJsonObject();
  492. ESMPropTemp->insert("key","fTecMaxFreqMhz");
  493. ESMPropTemp->insert("value",18e3);
  494. ESMInitParams->append(*ESMPropTemp);
  495. delete ESMPropTemp;
  496. ESMPropTemp = new QJsonObject();
  497. ESMPropTemp->insert("key","fInstantPageWidMhz");
  498. ESMPropTemp->insert("value",500);
  499. ESMInitParams->append(*ESMPropTemp);
  500. delete ESMPropTemp;
  501. ESMPropTemp = new QJsonObject();
  502. ESMPropTemp->insert("key","ulChanNum");
  503. ESMPropTemp->insert("value",64);
  504. ESMInitParams->append(*ESMPropTemp);
  505. delete ESMPropTemp;
  506. ESMPropTemp = new QJsonObject();
  507. ESMPropTemp->insert("key","fTecMinPW");
  508. ESMPropTemp->insert("value",0.5);
  509. ESMInitParams->append(*ESMPropTemp);
  510. delete ESMPropTemp;
  511. ESMPropTemp = new QJsonObject();
  512. ESMPropTemp->insert("key","fTecMaxPW");
  513. ESMPropTemp->insert("value",10);
  514. ESMInitParams->append(*ESMPropTemp);
  515. delete ESMPropTemp;
  516. ESMPropTemp = new QJsonObject();
  517. ESMPropTemp->insert("key","fTecPriMean");
  518. ESMPropTemp->insert("value",40);
  519. ESMInitParams->append(*ESMPropTemp);
  520. delete ESMPropTemp;
  521. ESMPropTemp = new QJsonObject();
  522. ESMPropTemp->insert("key","ulTecTrNumMean");
  523. ESMPropTemp->insert("value",5);
  524. ESMInitParams->append(*ESMPropTemp);
  525. delete ESMPropTemp;
  526. ESMPropTemp = new QJsonObject();
  527. ESMPropTemp->insert("key","fMinSnrdB");
  528. ESMPropTemp->insert("value",0.5);
  529. ESMInitParams->append(*ESMPropTemp);
  530. delete ESMPropTemp;
  531. ESMPropTemp = new QJsonObject();
  532. ESMPropTemp->insert("key","fSysRcvLoss");
  533. ESMPropTemp->insert("value",5);
  534. ESMInitParams->append(*ESMPropTemp);
  535. delete ESMPropTemp;
  536. ESMPropTemp = new QJsonObject();
  537. ESMPropTemp->insert("key","fFreqAccuracyReq");
  538. ESMPropTemp->insert("value",100);
  539. ESMInitParams->append(*ESMPropTemp);
  540. delete ESMPropTemp;
  541. ESMPropTemp = new QJsonObject();
  542. ESMPropTemp->insert("key","uRrPowerOn");
  543. ESMPropTemp->insert("value",0);
  544. ESMCtrlParams->append(*ESMPropTemp);
  545. delete ESMPropTemp;
  546. ESMPropTemp = new QJsonObject();
  547. ESMPropTemp->insert("key","uRrWorkMode");
  548. ESMPropTemp->insert("value",0);
  549. ESMCtrlParams->append(*ESMPropTemp);
  550. delete ESMPropTemp;
  551. ESMPropTemp = new QJsonObject();
  552. ESMPropTemp->insert("key","dScanAzCentDeg");
  553. ESMPropTemp->insert("value",0);
  554. ESMCtrlParams->append(*ESMPropTemp);
  555. delete ESMPropTemp;
  556. ESMPropTemp = new QJsonObject();
  557. ESMPropTemp->insert("key","dScanAzWidthDeg");
  558. ESMPropTemp->insert("value",5);
  559. ESMCtrlParams->append(*ESMPropTemp);
  560. delete ESMPropTemp;
  561. ESMPropTemp = new QJsonObject();
  562. ESMPropTemp->insert("key","dScanElCentDeg");
  563. ESMPropTemp->insert("value",0);
  564. ESMCtrlParams->append(*ESMPropTemp);
  565. delete ESMPropTemp;
  566. ESMPropTemp = new QJsonObject();
  567. ESMPropTemp->insert("key","uLineNumPerFrame");
  568. ESMPropTemp->insert("value",20);
  569. ESMCtrlParams->append(*ESMPropTemp);
  570. delete ESMPropTemp;
  571. ESMPropTemp = new QJsonObject();
  572. ESMPropTemp->insert("key","fAntScanVel");
  573. ESMPropTemp->insert("value",1);
  574. ESMCtrlParams->append(*ESMPropTemp);
  575. delete ESMPropTemp;
  576. ESMPropTemp = new QJsonObject();
  577. ESMPropTemp->insert("key","fFreqScanVel");
  578. ESMPropTemp->insert("value",100);
  579. ESMCtrlParams->append(*ESMPropTemp);
  580. delete ESMPropTemp;
  581. ESMPropTemp = new QJsonObject();
  582. ESMPropTemp->insert("key","fTecBeginFreqMhz");
  583. ESMPropTemp->insert("value",500);
  584. ESMCtrlParams->append(*ESMPropTemp);
  585. delete ESMPropTemp;
  586. ESMPropTemp = new QJsonObject();
  587. ESMPropTemp->insert("key","fTecEndFreqMhz");
  588. ESMPropTemp->insert("value",10000);
  589. ESMCtrlParams->append(*ESMPropTemp);
  590. delete ESMPropTemp;
  591. QJsonObject *ESMParams = new QJsonObject();
  592. ESMParams->insert("InitParams", *ESMInitParams);
  593. ESMParams->insert("CtrlParams", *ESMCtrlParams);
  594. obj->insert("data", *ESMParams);
  595. delete ESMInitParams;
  596. delete ESMCtrlParams;
  597. delete ESMParams;
  598. }
  599. }
  600. void BackgroundServer::getESMData(QJsonObject *obj)
  601. {
  602. }
  603. void BackgroundServer::getNavParams(QJsonObject *obj)
  604. {
  605. if (obj->contains("InstanceID")==false)
  606. {
  607. obj->insert("data", QJsonValue());
  608. return;
  609. }
  610. int InstanceID = obj->value("InstanceID").toInt();
  611. QJsonArray *NavInitParams;
  612. QJsonArray *NavCtrlParams;
  613. QJsonObject *NavPropTemp;
  614. NavInitParams = new QJsonArray();
  615. NavCtrlParams = new QJsonArray();
  616. NavPropTemp = new QJsonObject();
  617. NavPropTemp->insert("key","precision");
  618. NavPropTemp->insert("value",QJsonValue(5));
  619. NavInitParams->append(*NavPropTemp);
  620. delete NavPropTemp;
  621. qDebug() << "aaa" << QString(QJsonDocument(*NavCtrlParams).toJson());
  622. NavPropTemp = new QJsonObject();
  623. NavPropTemp->insert("key","longitude");
  624. NavPropTemp->insert("value",QJsonValue(120));
  625. NavCtrlParams->append(*NavPropTemp);
  626. delete NavPropTemp;
  627. NavPropTemp = new QJsonObject();
  628. NavPropTemp->insert("key","latitude");
  629. NavPropTemp->insert("value",QJsonValue(30));
  630. NavCtrlParams->append(*NavPropTemp);
  631. delete NavPropTemp;
  632. NavPropTemp = new QJsonObject();
  633. NavPropTemp->insert("key","altitude");
  634. NavPropTemp->insert("value",QJsonValue(8014.8));
  635. NavCtrlParams->append(*NavPropTemp);
  636. delete NavPropTemp;
  637. NavPropTemp = new QJsonObject();
  638. NavPropTemp->insert("key","azimush");
  639. NavPropTemp->insert("value",QJsonValue(10));
  640. NavCtrlParams->append(*NavPropTemp);
  641. delete NavPropTemp;
  642. NavPropTemp = new QJsonObject();
  643. NavPropTemp->insert("key","elevation");
  644. NavPropTemp->insert("value",QJsonValue(-3));
  645. NavCtrlParams->append(*NavPropTemp);
  646. delete NavPropTemp;
  647. QJsonObject *NAVParams = new QJsonObject();
  648. NAVParams->insert("InitParams", *NavInitParams);
  649. NAVParams->insert("CtrlParams", *NavCtrlParams);
  650. obj->insert("data", *NAVParams);
  651. QJsonDocument *NavDoc = new QJsonDocument(*NAVParams);
  652. qDebug() << QString(NavDoc->toJson());
  653. delete NavDoc;
  654. delete NavInitParams;
  655. delete NavCtrlParams;
  656. delete NAVParams;
  657. }
  658. void BackgroundServer::setFreePost(QJsonObject *obj)
  659. {
  660. if (obj->contains("PlatformID")==false)
  661. {
  662. obj->insert("data", QJsonValue());
  663. return;
  664. }
  665. }
  666. void BackgroundServer::SlotReturnData(QWebSocket *pSender, QJsonObject *obj)
  667. {
  668. qDebug() << "return message:";
  669. qDebug() << QString(QJsonDocument(*obj).toJson());
  670. pSender->sendTextMessage(QString(QJsonDocument(*obj).toJson()));
  671. delete obj;
  672. }