backgroundserver.cpp 25 KB

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