wsserver.cpp 27 KB

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