wsserver.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939
  1. //#pragma execution_character_set("utf-8")
  2. #include "wsserver.h"
  3. WSServer::WSServer(QObject *parent, quint16 port) : QObject(parent)
  4. {
  5. EsmworkPara.uRrPowerOn=1;
  6. EsmworkPara.uRrWorkMode=0;
  7. EsmworkPara.dScanAzCentDeg=0;
  8. EsmworkPara.dScanAzWidthDeg=5;
  9. EsmworkPara.dScanElCentDeg= 0;
  10. EsmworkPara.uLineNumPerFrame = 20;
  11. EsmworkPara.fAntScanVel = 1;
  12. EsmworkPara.fFreqScanVel = 100;
  13. EsmworkPara.fTecBeginFreqMhz = 500;
  14. EsmworkPara.fTecEndFreqMhz = 10000;
  15. m_pWebSocketServer = new QWebSocketServer(QStringLiteral("ZC Server"),
  16. QWebSocketServer::NonSecureMode,
  17. this);
  18. if (m_pWebSocketServer->listen(QHostAddress::Any, port))
  19. {
  20. qDebug() << "ZC Server listening on port" << port;
  21. connect(m_pWebSocketServer, &QWebSocketServer::newConnection,
  22. this, &WSServer::onNewConnection);
  23. }
  24. }
  25. WSServer::~WSServer()
  26. {
  27. m_pWebSocketServer->close();
  28. qDeleteAll(m_clients.begin(), m_clients.end());
  29. }
  30. void WSServer::onNewConnection()
  31. {
  32. QWebSocket *pSocket = m_pWebSocketServer->nextPendingConnection();
  33. connect(pSocket, &QWebSocket::textMessageReceived, this, &WSServer::processMessage);
  34. connect(pSocket, &QWebSocket::disconnected, this, &WSServer::socketDisconnected);
  35. m_clients << pSocket;
  36. }
  37. QJsonObject WSServer::processJsonObj(QJsonObject objin)
  38. {
  39. QJsonObject objout;
  40. QStringList Keys = objin.keys();
  41. for (auto k : Keys)
  42. {
  43. QJsonValue v = objin.value(k);
  44. if (k == "url")
  45. {
  46. objout.insert(k, v);
  47. }
  48. else if (k == "InstanceID")
  49. {
  50. objout.insert(k, v);
  51. }
  52. else if (k == "data")
  53. {
  54. if (v.isObject())
  55. {
  56. QJsonObject Props = v.toObject();
  57. QStringList Propkeys = Props.keys();
  58. QJsonObject Dataout;
  59. for (auto propkey : Propkeys)
  60. {
  61. if (propkey.compare("InstanceID")==0)
  62. {
  63. objout.insert("InstanceID", Props.value("InstanceID"));
  64. }
  65. else if (propkey.compare("PlatformID")==0)
  66. {
  67. objout.insert("PlatformID", Props.value("PlatformID"));
  68. }
  69. else
  70. {
  71. Dataout.insert(propkey, Props.value(propkey));
  72. }
  73. }
  74. if (!Dataout.isEmpty())
  75. objout.insert("data", Dataout);
  76. }
  77. }
  78. // if (v.isArray())
  79. // {
  80. // for (auto i : v.toArray())
  81. // {
  82. // if (i.isString())
  83. // {
  84. // objout->insert(i.toString(),QJsonValue());
  85. // }
  86. // }
  87. // }
  88. // else if (v.isObject())
  89. // {
  90. // QJsonObject Props = v.toObject();
  91. // QStringList Propkeys = Props.keys();
  92. // for (auto propkey: Propkeys)
  93. // {
  94. // objout->insert(propkey,Props.value(k));
  95. // }
  96. // }
  97. // 不想打印
  98. // if (v.isObject())
  99. // {
  100. // processJsonObj(v.toObject(),objout);
  101. // }
  102. // 打印调试信息
  103. if (v.isDouble())
  104. {
  105. qDebug() << k << ": " << v.toDouble();
  106. }
  107. else if (v.isString())
  108. {
  109. qDebug() << k << ": " << v.toString();
  110. }
  111. else if (v.isObject())
  112. {
  113. qDebug() << k << "{";
  114. QJsonObject objout = processJsonObj(v.toObject());
  115. qDebug() << "}";
  116. }
  117. else if (v.isArray())
  118. {
  119. QJsonArray qarray = v.toArray();
  120. qDebug() << k << "[";
  121. for (auto i : qarray)
  122. {
  123. if (i.isString())
  124. {
  125. qDebug() << i.toString();
  126. }
  127. }
  128. qDebug() << "]";
  129. }
  130. }
  131. return objout;
  132. //qDebug() << QString(QJsonDocument(*objout).toJson());
  133. }
  134. void WSServer::processMessage(QString message)
  135. {
  136. // 以Json格式解码message
  137. QByteArray *ByteMessage = new QByteArray();
  138. ByteMessage->append(message);
  139. QJsonParseError *error = new QJsonParseError();
  140. QJsonDocument IncomingJson = QJsonDocument::fromJson(*ByteMessage, error);
  141. if (error->error == QJsonParseError::NoError)
  142. {
  143. if (IncomingJson.isObject())
  144. {
  145. QWebSocket *pSender = qobject_cast<QWebSocket *>(sender());
  146. // 解析message
  147. QJsonObject IncomingObj = IncomingJson.object();
  148. QJsonObject msgobj = this->processJsonObj(IncomingObj);
  149. QStringList props = msgobj.keys();
  150. QString url = msgobj.value("url").toString();
  151. qDebug() << "url:" << url;
  152. // 判断请求
  153. if (url == "getInit")
  154. {
  155. getInit(pSender,msgobj);
  156. }
  157. else if (url == "getPlatformTable")
  158. {
  159. getPlatformTable(pSender,msgobj);
  160. }
  161. else if (url == "getGlobalMap")
  162. {
  163. getGlobalMap(pSender,msgobj);
  164. }
  165. else
  166. {
  167. // 其他接口都需要带平台ID
  168. if (msgobj.contains("PlatformID")==false || msgobj.value("PlatformID") == QJsonValue())
  169. {
  170. // 要是没有平台ID,返回空数据
  171. QJsonObject *ret = new QJsonObject(
  172. {
  173. {"url",url},
  174. {"data",""}
  175. });
  176. returnMessage(pSender, ret);
  177. }
  178. // 态势接口
  179. else if (url == "getLocalMap" || url == "getRemoteMap" || url == "getCombineMap")
  180. {
  181. }
  182. // ESM接口
  183. else if (url == "getESMInstances")
  184. {
  185. getESMInstances(pSender,msgobj);
  186. }
  187. else if (url == "setESMParams")
  188. {
  189. setESMParams(pSender,msgobj);
  190. }
  191. else if (url == "getESMParams")
  192. {
  193. getESMParams(pSender,msgobj);
  194. }
  195. else if (url == "getESMStatus")
  196. {
  197. getESMStatus(pSender,msgobj);
  198. }
  199. else if (url == "getESMData")
  200. {
  201. getESMData(pSender,msgobj);
  202. }
  203. else if (url == "getNavParams")
  204. {
  205. getNavParams(pSender,msgobj);
  206. }
  207. else if (url == "setFreePost")
  208. {
  209. setFreePost(pSender,msgobj);
  210. }
  211. else if (url == "getLeadPost")
  212. {
  213. getLeadPost(pSender,msgobj);
  214. }
  215. else if (url == "getTaskPlan")
  216. {
  217. getTaskPlan(pSender,msgobj);
  218. }
  219. }
  220. }
  221. }
  222. }
  223. void WSServer::socketDisconnected()
  224. {
  225. QWebSocket *pClient = qobject_cast<QWebSocket *>(sender());
  226. if (pClient)
  227. {
  228. m_clients.removeAll(pClient);
  229. pClient->deleteLater();
  230. }
  231. }
  232. void WSServer::returnMessage(QWebSocket *pSender, QJsonObject *jsonObj)
  233. {
  234. // qDebug() << "return message:";
  235. // qDebug() << QString(QJsonDocument(*jsonObj).toJson());
  236. pSender->sendTextMessage(QString(QJsonDocument(*jsonObj).toJson()));
  237. delete jsonObj;
  238. }
  239. // --------------------初始化状态接口---------------------------------
  240. void WSServer::getInit(QWebSocket *pSender, QJsonObject obj)
  241. {
  242. qDebug() << "网页请求初始化状态";
  243. // 假接口
  244. QJsonObject InitState
  245. {
  246. {"InitState",100}
  247. };
  248. // 真实接口
  249. // QJsonObject InitState
  250. // {
  251. // {"InitState",100*(int)this->zcman->common_inter->InitState}
  252. // };
  253. QJsonObject *ret = new QJsonObject(
  254. {
  255. {"url", obj.value("url")},
  256. {"data", InitState}
  257. });
  258. returnMessage(pSender, ret);
  259. }
  260. // --------------------平台表接口----------------------------------------------
  261. void WSServer::getPlatformTable(QWebSocket *pSender, QJsonObject obj)
  262. {
  263. qDebug() << "网页请求平台信息";
  264. QJsonArray Platforms;
  265. // 假接口
  266. QJsonObject SinglePlatform[] {
  267. {
  268. {"platformID", 8015},
  269. {"platformName", "侦察机_1"}
  270. },
  271. {
  272. {"platformID", 8016},
  273. {"platformName", "侦察机_2"}
  274. },
  275. };
  276. for (auto i: SinglePlatform)
  277. {
  278. Platforms.append(i);
  279. }
  280. // 真实接口
  281. // for (auto i : this->grman->grtaskplats)
  282. // {
  283. // QJsonObject SinglePlatform
  284. // {
  285. // {"platformID", (int)i->PlatID},
  286. // {"platformName", QString::fromLocal8Bit(i->PlatName.c_str())}
  287. // };
  288. // Platforms.append(SinglePlatform);
  289. // }
  290. // 构造返回对象
  291. QJsonObject *ret = new QJsonObject(
  292. {
  293. {"url", obj.value("url")},
  294. {"data", Platforms}
  295. });
  296. returnMessage(pSender, ret);
  297. }
  298. // --------------------------任务管理显控接口------------------------------
  299. void WSServer::getLeadPost(QWebSocket *pSender, QJsonObject obj)
  300. {
  301. qDebug() << "网页请求指挥电文";
  302. // 假接口
  303. QJsonObject CurrentLeadPost1
  304. {
  305. {"time", "20:20:01"},
  306. {"GroupID", "0001"},
  307. {"LeaderID", "8015"},
  308. {"Abstract", "开始侦察"}
  309. };
  310. QJsonObject CurrentLeadPost2
  311. {
  312. {"time", "20:20:30"},
  313. {"GroupID", "0001"},
  314. {"LeaderID", "8015"},
  315. {"Abstract", "发现辐射源"}
  316. };
  317. QJsonObject CurrentLeadPost3
  318. {
  319. {"time", "20:20:40"},
  320. {"GroupID", "0001"},
  321. {"LeaderID", "8015"},
  322. {"Abstract", "请求干扰"}
  323. };
  324. QJsonObject CurrentLeadPost4
  325. {
  326. {"time", "20:20:01"},
  327. {"GroupID", "0003"},
  328. {"LeaderID", "8014"},
  329. {"Abstract", "开始干扰"}
  330. };
  331. QJsonArray LeadPost = {
  332. CurrentLeadPost1,
  333. CurrentLeadPost2,
  334. CurrentLeadPost3,
  335. CurrentLeadPost4
  336. };
  337. // 真实接口
  338. // 待定
  339. // 构造返回对象
  340. QJsonObject *ret = new QJsonObject(
  341. {
  342. {"url", obj.value("url")},
  343. {"PlatformID", obj.value("PlatformID")},
  344. {"data", LeadPost}
  345. });
  346. returnMessage(pSender, ret);
  347. }
  348. void WSServer::getTaskPlan(QWebSocket *pSender, QJsonObject obj)
  349. {
  350. qDebug() << "网页请求任务计划";
  351. // 假接口
  352. QJsonObject CurrentAirLine
  353. {
  354. {"TargetArea", 3},
  355. {"Longitude", 123},
  356. {"Longitude", 27},
  357. {"Radius", 300000}
  358. };
  359. QJsonObject CurrentTaskPlan
  360. {
  361. {"TargetArea", 2},
  362. {"ThrowGas", 2},
  363. {"ThrowBT", 2}
  364. };
  365. QJsonObject TaskPlan
  366. {
  367. {"Airline", CurrentAirLine},
  368. {"TaskPlan", CurrentTaskPlan}
  369. };
  370. // 真实接口 待定
  371. // 构造返回对象
  372. QJsonObject *ret = new QJsonObject(
  373. {
  374. {"url", obj.value("url")},
  375. {"PlatformID", obj.value("PlatformID")},
  376. {"data", TaskPlan}
  377. });
  378. returnMessage(pSender, ret);
  379. }
  380. // --------------------------雷侦、通侦显控接口-------------------------------
  381. void WSServer::getESMInstances(QWebSocket *pSender, QJsonObject obj)
  382. {
  383. qDebug() << "网页请求ESM传感器实例";
  384. // 假接口
  385. QJsonArray *Instances = new QJsonArray();
  386. QJsonObject *SingleInstance;
  387. if (true)
  388. {
  389. SingleInstance = new QJsonObject();
  390. SingleInstance->insert("instanceID", 62);
  391. SingleInstance->insert("instanceName", "信号侦察_1");
  392. Instances->append(*SingleInstance);
  393. delete SingleInstance;
  394. }
  395. QJsonObject *ret = new QJsonObject({
  396. {"url", obj.value("url")},
  397. {"PlatformID", obj.value("PlatformID")},
  398. {"data", *Instances}
  399. });
  400. returnMessage(pSender, ret);
  401. delete Instances;
  402. }
  403. void WSServer::setESMParams(QWebSocket *pSender, QJsonObject obj)
  404. {
  405. qDebug() << "网页修改ESM参数";
  406. // 假接口
  407. int PlatformID = obj.value("PlatformID").toInt();
  408. int InstanceID = obj.value("InstanceID").toInt();
  409. QJsonObject data = obj.value("data").toObject();
  410. if (data.contains("uRrPoweron"))
  411. {
  412. EsmworkPara.uRrPowerOn = data.value("uRrPoweron").toBool()?1:0;
  413. }
  414. if (data.contains("uRrWorkMode"))
  415. {
  416. EsmworkPara.uRrWorkMode = data.value("uRrWorkMode").toInt();
  417. }
  418. if (data.contains("uLineNumPerFrame"))
  419. {
  420. EsmworkPara.uLineNumPerFrame = data.value("uLineNumPerFrame").toInt();
  421. }
  422. if (data.contains("dScanAzCentDeg"))
  423. {
  424. EsmworkPara.dScanAzCentDeg = data.value("dScanAzCentDeg").toDouble();
  425. }
  426. if (data.contains("dScanAzWidthDeg"))
  427. {
  428. EsmworkPara.dScanAzWidthDeg = data.value("dScanAzWidthDeg").toDouble();
  429. }
  430. if (data.contains("dScanElCentDeg"))
  431. {
  432. EsmworkPara.dScanElCentDeg = data.value("dScanElCentDeg").toDouble();
  433. }
  434. if (data.contains("fAntScanVel"))
  435. {
  436. EsmworkPara.fAntScanVel = data.value("fAntScanVel").toDouble();
  437. }
  438. if (data.contains("fFreqScanVel"))
  439. {
  440. EsmworkPara.fFreqScanVel = data.value("fFreqScanVel").toDouble();
  441. }
  442. if (data.contains("fFreqMode"))
  443. {
  444. int mode = data.value("fFreqMode").toInt();
  445. if (mode == 1)
  446. {
  447. EsmworkPara.fTecBeginFreqMhz = 500;
  448. EsmworkPara.fTecEndFreqMhz = 2000;
  449. }
  450. else if (mode == 2)
  451. {
  452. EsmworkPara.fTecBeginFreqMhz = 2000;
  453. EsmworkPara.fTecEndFreqMhz = 5000;
  454. }
  455. else if (mode == 3)
  456. {
  457. EsmworkPara.fTecBeginFreqMhz = 5000;
  458. EsmworkPara.fTecEndFreqMhz = 18000;
  459. }
  460. }
  461. QJsonObject *ret = new QJsonObject({
  462. {"url", obj.value("url")},
  463. {"PlatformID", obj.value("PlatformID")},
  464. {"data", 1}
  465. });
  466. returnMessage(pSender, ret);
  467. }
  468. void WSServer::getESMParams(QWebSocket *pSender, QJsonObject obj)
  469. {
  470. qDebug() << "网页请求ESM参数";
  471. // 假接口
  472. int InstanceID = obj.value("InstanceID").toInt();
  473. if (true)
  474. {
  475. QJsonObject ESMProps[]
  476. {
  477. //fBeamAzWidth
  478. {
  479. {"key","方位波束宽度"},
  480. {"value", 2}
  481. },
  482. //fBeamElWidth
  483. {
  484. {"key","俯仰波束宽度"},
  485. {"value", 2}
  486. },
  487. //fTecMinFreqMhz
  488. {
  489. {"key","侦收最小频率"},
  490. {"value", 2e3}
  491. },
  492. //fTecMaxFreqMhz
  493. {
  494. {"key","侦收最大频率"},
  495. {"value", 18e3}
  496. },
  497. //fInstantPageWidMhz
  498. {
  499. {"key","瞬时侦察工作频带带宽"},
  500. {"value", 500}
  501. },
  502. //ulChanNum
  503. {
  504. {"key","信道个数"},
  505. {"value", 64}
  506. },
  507. //fTecMinPW
  508. {
  509. {"key","侦收最小脉冲宽度"},
  510. {"value", 0.5}
  511. },
  512. //fTecMaxPW
  513. {
  514. {"key","侦收最大脉冲宽度"},
  515. {"value", 10}
  516. },
  517. //fTecPriMean
  518. {
  519. {"key","侦收平均重复周期"},
  520. {"value", 40}
  521. },
  522. //ulTecTrNumMean
  523. {
  524. {"key","侦收平均脉冲个数"},
  525. {"value", 5}
  526. },
  527. //fMinSnrdB
  528. {
  529. {"key","最小信噪比"},
  530. {"value", 0.5}
  531. },
  532. //fSysRcvLoss
  533. {
  534. {"key","接收内部系统损耗"},
  535. {"value", 5}
  536. },
  537. //fFreqAccuracyReq
  538. {
  539. {"key","频率测量精度要求"},
  540. {"value", 100}
  541. },
  542. //uRrPowerOn
  543. {
  544. {"key","工作状态"},
  545. {"value",(int)EsmworkPara.uRrPowerOn}
  546. },
  547. //uRrWorkMode
  548. {
  549. {"key","工作模式"},
  550. {"value",(int)EsmworkPara.uRrWorkMode}
  551. },
  552. //dScanAzCentDeg
  553. {
  554. {"key","侦察方位中心"},
  555. {"value",EsmworkPara.dScanAzCentDeg}
  556. },
  557. //dScanAzWidthDeg
  558. {
  559. {"key","侦察方位范围"},
  560. {"value",EsmworkPara.dScanAzWidthDeg}
  561. },
  562. //dScanElCentDeg
  563. {
  564. {"key","侦察俯仰中心"},
  565. {"value",EsmworkPara.dScanElCentDeg}
  566. },
  567. //uLineNumPerFrame
  568. {
  569. {"key","景幅行数"},
  570. {"value",(int)EsmworkPara.uLineNumPerFrame}
  571. },
  572. //fAntScanVel
  573. {
  574. {"key","天线扫描速度"},
  575. {"value",EsmworkPara.fAntScanVel}
  576. },
  577. //fFreqScanVel
  578. {
  579. {"key","频率扫描速度"},
  580. {"value",EsmworkPara.fFreqScanVel}
  581. },
  582. //fTecBeginFreqMhz
  583. {
  584. {"key","侦收起始频率"},
  585. {"value",EsmworkPara.fTecBeginFreqMhz}
  586. },
  587. //fTecEndFreqMhz
  588. {
  589. {"key","侦收终止频率"},
  590. {"value",EsmworkPara.fTecEndFreqMhz}
  591. }
  592. };
  593. QJsonArray ESMInitParams, ESMCtrlParams;
  594. for (int i =0;i<13;i++)
  595. {
  596. ESMInitParams.append(ESMProps[i]);
  597. }
  598. for (int i =13;i<23;i++)
  599. {
  600. ESMCtrlParams.append(ESMProps[i]);
  601. }
  602. QJsonObject ESMParams
  603. {
  604. {"InitParams", ESMInitParams},
  605. {"CtrlParams", ESMCtrlParams}
  606. };
  607. QJsonObject *ret = new QJsonObject({
  608. {"url", obj.value("url")},
  609. {"PlatformID", obj.value("PlatformID")},
  610. {"InstanceID", InstanceID},
  611. {"data", ESMParams}
  612. });
  613. returnMessage(pSender, ret);
  614. }
  615. }
  616. void WSServer::getESMStatus(QWebSocket *pSender, QJsonObject obj)
  617. {
  618. qDebug() << "网页请求初始化状态";
  619. // 假接口
  620. QJsonArray ESMStatus;
  621. QJsonObject ESMState[]{
  622. {
  623. {"key","扫描行号"},
  624. {"value",0}
  625. },
  626. {
  627. {"key","扫描行状态"},
  628. {"value",0}
  629. },
  630. {
  631. {"key","侦察频率中心"},
  632. {"value",0}
  633. },
  634. {
  635. {"key","侦察频率带宽"},
  636. {"value",0}
  637. },
  638. {
  639. {"key","天线系波束方位"},
  640. {"value",0}
  641. },
  642. {
  643. {"key","天线系波束俯仰"},
  644. {"value",0}
  645. },
  646. {
  647. {"key","天线系波束方位"},
  648. {"value",0}
  649. },
  650. {
  651. {"key","天线系波束方位"},
  652. {"value",0}
  653. }
  654. };
  655. for (int i = 0; i < 8; i++)
  656. {
  657. ESMStatus.append(ESMState[i]);
  658. }
  659. // 真实接口
  660. int PlatformID = obj.value("PlatformID").toInt();
  661. int InstanceID = obj.value("InstanceID").toInt();
  662. // 构造返回对象
  663. QJsonObject *ret = new QJsonObject(
  664. {
  665. {"url", obj.value("url")},
  666. {"PlatformID", obj.value("PlatformID")},
  667. {"data", ESMStatus}
  668. });
  669. returnMessage(pSender, ret);
  670. }
  671. void WSServer::getESMData(QWebSocket *pSender, QJsonObject obj)
  672. {
  673. }
  674. // --------------------------态势显控接口---------------------------------
  675. void WSServer::getLocalMap(QWebSocket *pSender, QJsonObject obj)
  676. {
  677. qDebug() << "网页请求本地态势";
  678. // 来源1:导航位置信息
  679. // 来源2:ESM数据
  680. }
  681. void WSServer::getRemoteMap(QWebSocket *pSender, QJsonObject obj)
  682. {
  683. qDebug() << "网页请求远端态势";
  684. // 来源:保存下来的平台参数情报和航迹情报
  685. }
  686. void WSServer::getCombineMap(QWebSocket *pSender, QJsonObject obj)
  687. {
  688. qDebug() << "网页请求融合态势";
  689. // 来源1:导航位置信息
  690. // 来源2:ESM数据
  691. // 来源3:保存下来的平台参数情报和航迹情报
  692. }
  693. void WSServer::getGlobalMap(QWebSocket *pSender, QJsonObject obj)
  694. {
  695. qDebug() << "网页请求全局态势";
  696. // 来源:支撑平台的平台位置信息
  697. // 假接口
  698. QJsonArray *alies = new QJsonArray();
  699. QJsonArray *enemys = new QJsonArray();
  700. QJsonArray *temparray;
  701. QJsonObject *tempobj;
  702. {
  703. temparray = new QJsonArray();
  704. tempobj = new QJsonObject();
  705. tempobj->insert("name", "80xxA电子侦察船_1");
  706. temparray->append(120.446), temparray->append(24.8902), temparray->append(100);
  707. tempobj->insert("value", *temparray);
  708. // alies->insert(("80xxA电子侦察船_1"), QJsonValue(*temparray));
  709. alies->append(*tempobj);
  710. delete temparray;
  711. delete tempobj;
  712. temparray = new QJsonArray();
  713. tempobj = new QJsonObject();
  714. tempobj->insert("name", "导弹发射架_1");
  715. temparray->append(117.525), temparray->append(25.826), temparray->append(100);
  716. tempobj->insert("value", *temparray);
  717. alies->append(*tempobj);
  718. delete temparray;
  719. delete tempobj;
  720. temparray = new QJsonArray();
  721. tempobj = new QJsonObject();
  722. tempobj->insert("name", "机场_1");
  723. temparray->append(119.271), temparray->append(26.26), temparray->append(100);
  724. tempobj->insert("value", *temparray);
  725. alies->append(*tempobj);
  726. delete temparray;
  727. delete tempobj;
  728. temparray = new QJsonArray();
  729. tempobj = new QJsonObject();
  730. tempobj->insert("name", "预警机_1");
  731. temparray->append(120.288), temparray->append(25.5734), temparray->append(100);
  732. tempobj->insert("value", *temparray);
  733. alies->append(*tempobj);
  734. delete temparray;
  735. delete tempobj;
  736. temparray = new QJsonArray();
  737. tempobj = new QJsonObject();
  738. tempobj->insert("name", "运侦8_1");
  739. temparray->append(117.525), temparray->append(25.826), temparray->append(100);
  740. tempobj->insert("value", *temparray);
  741. alies->append(*tempobj);
  742. delete temparray;
  743. delete tempobj;
  744. }
  745. {
  746. temparray = new QJsonArray();
  747. tempobj = new QJsonObject();
  748. tempobj->insert("name", "宙斯盾舰");
  749. temparray->append(123.528), temparray->append(25.2951), temparray->append(100);
  750. tempobj->insert("value",*temparray);
  751. enemys->append(*tempobj);
  752. delete temparray;
  753. delete tempobj;
  754. }
  755. QJsonObject GlobalMap
  756. {
  757. {"friend", QJsonValue(*alies)},
  758. {"enemy", QJsonValue(*enemys)}
  759. };
  760. delete alies;
  761. delete enemys;
  762. // 真实接口
  763. // QJsonArray ally;
  764. // QJsonArray enemy;
  765. // for (auto i : this->zcman->common_inter->PlatformMovement)
  766. // {
  767. // QJsonArray currentPos = {
  768. // i.second.PlatLon,
  769. // i.second.PlatLat,
  770. // 100
  771. // };
  772. // QJsonObject currentPlat
  773. // {
  774. // {"name", QString::fromLocal8Bit(i.second.PlatName.c_str())},
  775. // {"value", currentPos}
  776. // };
  777. // // 判断敌我
  778. // if (i.second.PlatIdentification == 2)
  779. // {
  780. // ally.append(currentPlat);
  781. // }
  782. // else if (i.second.PlatIdentification == 1)
  783. // {
  784. // enemy.append(currentPlat);
  785. // }
  786. // }
  787. // QJsonObject GlobalMap
  788. // {
  789. // {"friend", QJsonValue(ally)},
  790. // {"enemy", QJsonValue(enemy)}
  791. // };
  792. // 构造返回对象
  793. QJsonObject *ret = new QJsonObject({
  794. {"url", obj.value("url")},
  795. {"data", GlobalMap}
  796. });
  797. returnMessage(pSender, ret);
  798. }
  799. void WSServer::getNavParams(QWebSocket *pSender, QJsonObject obj)
  800. {
  801. int InstanceID = obj.value("InstanceID").toInt();
  802. QJsonArray *NavInitParams;
  803. QJsonArray *NavCtrlParams;
  804. QJsonObject *NavPropTemp;
  805. NavInitParams = new QJsonArray();
  806. NavCtrlParams = new QJsonArray();
  807. NavPropTemp = new QJsonObject();
  808. NavPropTemp->insert("key","precision");
  809. NavPropTemp->insert("value",QJsonValue(5));
  810. NavInitParams->append(*NavPropTemp);
  811. delete NavPropTemp;
  812. qDebug() << "aaa" << QString(QJsonDocument(*NavCtrlParams).toJson());
  813. NavPropTemp = new QJsonObject();
  814. NavPropTemp->insert("key","longitude");
  815. NavPropTemp->insert("value",QJsonValue(120));
  816. NavCtrlParams->append(*NavPropTemp);
  817. delete NavPropTemp;
  818. NavPropTemp = new QJsonObject();
  819. NavPropTemp->insert("key","latitude");
  820. NavPropTemp->insert("value",QJsonValue(30));
  821. NavCtrlParams->append(*NavPropTemp);
  822. delete NavPropTemp;
  823. NavPropTemp = new QJsonObject();
  824. NavPropTemp->insert("key","altitude");
  825. NavPropTemp->insert("value",QJsonValue(8014.8));
  826. NavCtrlParams->append(*NavPropTemp);
  827. delete NavPropTemp;
  828. NavPropTemp = new QJsonObject();
  829. NavPropTemp->insert("key","azimush");
  830. NavPropTemp->insert("value",QJsonValue(10));
  831. NavCtrlParams->append(*NavPropTemp);
  832. delete NavPropTemp;
  833. NavPropTemp = new QJsonObject();
  834. NavPropTemp->insert("key","elevation");
  835. NavPropTemp->insert("value",QJsonValue(-3));
  836. NavCtrlParams->append(*NavPropTemp);
  837. delete NavPropTemp;
  838. QJsonObject *NAVParams = new QJsonObject();
  839. NAVParams->insert("InitParams", *NavInitParams);
  840. NAVParams->insert("CtrlParams", *NavCtrlParams);
  841. QJsonObject *ret = new QJsonObject({
  842. {"url", obj.value("url")},
  843. {"PlatformID", obj.value("PlatformID")},
  844. {"data", *NAVParams}
  845. });
  846. returnMessage(pSender, ret);
  847. delete NavInitParams;
  848. delete NavCtrlParams;
  849. delete NAVParams;
  850. }
  851. void WSServer::setFreePost(QWebSocket *pSender, QJsonObject obj)
  852. {
  853. }