wsserver.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  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. {{"url", url},
  173. {"data", ""}});
  174. returnMessage(pSender, ret);
  175. }
  176. // 态势接口
  177. else if (url == "getLocalMap" || url == "getRemoteMap" || url == "getCombineMap")
  178. {
  179. }
  180. // ESM接口
  181. else if (url == "getESMInstances")
  182. {
  183. getESMInstances(pSender, msgobj);
  184. }
  185. else if (url == "setESMParams")
  186. {
  187. setESMParams(pSender, msgobj);
  188. }
  189. else if (url == "getESMParams")
  190. {
  191. getESMParams(pSender, msgobj);
  192. }
  193. else if (url == "getESMStatus")
  194. {
  195. getESMStatus(pSender, msgobj);
  196. }
  197. else if (url == "getESMData")
  198. {
  199. getESMData(pSender, msgobj);
  200. }
  201. else if (url == "getNavParams")
  202. {
  203. getNavParams(pSender, msgobj);
  204. }
  205. else if (url == "setFreePost")
  206. {
  207. setFreePost(pSender, msgobj);
  208. }
  209. else if (url == "getLeadPost")
  210. {
  211. getLeadPost(pSender, msgobj);
  212. }
  213. else if (url == "getTaskPlan")
  214. {
  215. getTaskPlan(pSender, msgobj);
  216. }
  217. }
  218. }
  219. }
  220. }
  221. void WSServer::socketDisconnected()
  222. {
  223. QWebSocket *pClient = qobject_cast<QWebSocket *>(sender());
  224. if (pClient)
  225. {
  226. m_clients.removeAll(pClient);
  227. pClient->deleteLater();
  228. }
  229. }
  230. void WSServer::returnMessage(QWebSocket *pSender, QJsonObject *jsonObj)
  231. {
  232. // qDebug() << "return message:";
  233. // qDebug() << QString(QJsonDocument(*jsonObj).toJson());
  234. pSender->sendTextMessage(QString(QJsonDocument(*jsonObj).toJson()));
  235. delete jsonObj;
  236. }
  237. // --------------------初始化状态接口---------------------------------
  238. void WSServer::getInit(QWebSocket *pSender, QJsonObject obj)
  239. {
  240. qDebug() << "网页请求初始化状态";
  241. // 假接口
  242. QJsonObject InitState{
  243. {"InitState", 100}};
  244. // 真实接口
  245. // QJsonObject InitState
  246. // {
  247. // {"InitState",100*(int)this->zcman->common_inter->InitState}
  248. // };
  249. QJsonObject *ret = new QJsonObject(
  250. {{"url", obj.value("url")},
  251. {"data", InitState}});
  252. returnMessage(pSender, ret);
  253. }
  254. // --------------------平台表接口----------------------------------------------
  255. void WSServer::getPlatformTable(QWebSocket *pSender, QJsonObject obj)
  256. {
  257. qDebug() << "网页请求平台信息";
  258. QJsonArray Platforms;
  259. // 假接口
  260. QJsonObject SinglePlatform[]{
  261. {{"platformID", 8015},
  262. {"platformName", "侦察机_1"}},
  263. {{"platformID", 8016},
  264. {"platformName", "侦察机_2"}},
  265. };
  266. for (auto i : SinglePlatform)
  267. {
  268. Platforms.append(i);
  269. }
  270. // 真实接口
  271. // for (auto i : this->grman->grtaskplats)
  272. // {
  273. // QJsonObject SinglePlatform
  274. // {
  275. // {"platformID", (int)i->PlatID},
  276. // {"platformName", QString::fromLocal8Bit(i->PlatName.c_str())}
  277. // };
  278. // Platforms.append(SinglePlatform);
  279. // }
  280. // 构造返回对象
  281. QJsonObject *ret = new QJsonObject(
  282. {{"url", obj.value("url")},
  283. {"data", Platforms}});
  284. returnMessage(pSender, ret);
  285. }
  286. // --------------------------任务管理显控接口------------------------------
  287. void WSServer::getLeadPost(QWebSocket *pSender, QJsonObject obj)
  288. {
  289. qDebug() << "网页请求指挥电文";
  290. // 假接口
  291. QJsonObject CurrentLeadPost1{
  292. {"time", "20:20:01"},
  293. {"GroupID", "0001"},
  294. {"LeaderID", "8015"},
  295. {"Abstract", "开始侦察"}};
  296. QJsonObject CurrentLeadPost2{
  297. {"time", "20:20:30"},
  298. {"GroupID", "0001"},
  299. {"LeaderID", "8015"},
  300. {"Abstract", "发现辐射源"}};
  301. QJsonObject CurrentLeadPost3{
  302. {"time", "20:20:40"},
  303. {"GroupID", "0001"},
  304. {"LeaderID", "8015"},
  305. {"Abstract", "请求干扰"}};
  306. QJsonObject CurrentLeadPost4{
  307. {"time", "20:20:01"},
  308. {"GroupID", "0003"},
  309. {"LeaderID", "8014"},
  310. {"Abstract", "开始干扰"}};
  311. QJsonArray LeadPost = {
  312. CurrentLeadPost1,
  313. CurrentLeadPost2,
  314. CurrentLeadPost3,
  315. CurrentLeadPost4};
  316. // 真实接口
  317. // 待定
  318. // 构造返回对象
  319. QJsonObject *ret = new QJsonObject(
  320. {{"url", obj.value("url")},
  321. {"PlatformID", obj.value("PlatformID")},
  322. {"data", LeadPost}});
  323. returnMessage(pSender, ret);
  324. }
  325. void WSServer::getTaskPlan(QWebSocket *pSender, QJsonObject obj)
  326. {
  327. qDebug() << "网页请求任务计划";
  328. // 假接口
  329. QJsonObject CurrentAirLine{
  330. {"TargetArea", 3},
  331. {"Longitude", 123},
  332. {"Longitude", 27},
  333. {"Radius", 300000}};
  334. QJsonObject CurrentTaskPlan{
  335. {"TargetArea", 2},
  336. {"ThrowGas", 2},
  337. {"ThrowBT", 2}};
  338. QJsonObject TaskPlan{
  339. {"Airline", CurrentAirLine},
  340. {"TaskPlan", CurrentTaskPlan}};
  341. // 真实接口 待定
  342. // 构造返回对象
  343. QJsonObject *ret = new QJsonObject(
  344. {{"url", obj.value("url")},
  345. {"PlatformID", obj.value("PlatformID")},
  346. {"data", TaskPlan}});
  347. returnMessage(pSender, ret);
  348. }
  349. // --------------------------态势显控接口---------------------------------
  350. void WSServer::getLocalMap(QWebSocket *pSender, QJsonObject obj)
  351. {
  352. qDebug() << "网页请求本地态势";
  353. // 来源1:导航位置信息
  354. // 来源2:ESM数据
  355. }
  356. void WSServer::getRemoteMap(QWebSocket *pSender, QJsonObject obj)
  357. {
  358. qDebug() << "网页请求远端态势";
  359. // 来源:保存下来的平台参数情报和航迹情报
  360. }
  361. void WSServer::getCombineMap(QWebSocket *pSender, QJsonObject obj)
  362. {
  363. qDebug() << "网页请求融合态势";
  364. // 来源1:导航位置信息
  365. // 来源2:ESM数据
  366. // 来源3:保存下来的平台参数情报和航迹情报
  367. }
  368. void WSServer::getGlobalMap(QWebSocket *pSender, QJsonObject obj)
  369. {
  370. qDebug() << "网页请求全局态势";
  371. // 来源:支撑平台的平台位置信息
  372. // 假接口
  373. QJsonArray allyNames = {
  374. "导弹发射架_1",
  375. "机场_1",
  376. "预警机_1",
  377. "运侦8_1"};
  378. QJsonArray allyPos[] = {
  379. {117.525, 25.826, 100},
  380. {119.271, 26.26, 100},
  381. {120.288, 25.5734, 100},
  382. {117.525, 25.826, 100}};
  383. QJsonArray enemyNames = {
  384. "80xxA电子侦察船_1",
  385. "宙斯盾舰"};
  386. QJsonArray enemyPos[] = {
  387. {120.446, 24.8902, 100},
  388. {123.528, 25.2951, 100}};
  389. QJsonArray ally;
  390. QJsonArray enemy;
  391. for (int i= 0;i<allyNames.count();i++)
  392. {
  393. QJsonObject temp {
  394. {"name",allyNames.at(i)},
  395. {"value",allyPos[i]}
  396. };
  397. ally.append(temp);
  398. }
  399. for (int i= 0;i<enemyNames.count();i++)
  400. {
  401. QJsonObject temp {
  402. {"name",enemyNames.at(i)},
  403. {"value",enemyPos[i]}
  404. };
  405. enemy.append(temp);
  406. }
  407. // 真实接口
  408. // QJsonArray ally;
  409. // QJsonArray enemy;
  410. // for (auto i : this->zcman->common_inter->PlatformMovement)
  411. // {
  412. // QJsonArray currentPos = {
  413. // i.second.PlatLon,
  414. // i.second.PlatLat,
  415. // 100
  416. // };
  417. // QJsonObject currentPlat
  418. // {
  419. // {"name", QString::fromLocal8Bit(i.second.PlatName.c_str())},
  420. // {"value", currentPos}
  421. // };
  422. // // 判断敌我
  423. // if (i.second.PlatIdentification == 2)
  424. // {
  425. // ally.append(currentPlat);
  426. // }
  427. // else if (i.second.PlatIdentification == 1)
  428. // {
  429. // enemy.append(currentPlat);
  430. // }
  431. // }
  432. // 构造返回对象
  433. QJsonObject GlobalMap
  434. {
  435. {"friend", QJsonValue(ally)},
  436. {"enemy", QJsonValue(enemy)}
  437. };
  438. QJsonObject *ret = new QJsonObject({{"url", obj.value("url")},
  439. {"data", GlobalMap}});
  440. returnMessage(pSender, ret);
  441. }
  442. // --------------------------雷侦、通侦显控接口-------------------------------
  443. void WSServer::getESMInstances(QWebSocket *pSender, QJsonObject obj)
  444. {
  445. qDebug() << "网页请求ESM传感器实例";
  446. // 假接口
  447. QJsonArray Instances;
  448. QJsonObject SingleInstance[] = {
  449. {{"instanceID", 62},
  450. {"instanceName", "信号侦察_1"}},
  451. {{"instanceID", 63},
  452. {"instanceName", "信号侦察_2"}}};
  453. // 真实接口 待开发
  454. // 构造返回对象
  455. for (auto i : SingleInstance)
  456. {
  457. Instances.append(i);
  458. }
  459. QJsonObject *ret = new QJsonObject({{"url", obj.value("url")},
  460. {"PlatformID", obj.value("PlatformID")},
  461. {"data", Instances}});
  462. returnMessage(pSender, ret);
  463. }
  464. void WSServer::setESMParams(QWebSocket *pSender, QJsonObject obj)
  465. {
  466. qDebug() << "网页修改ESM参数";
  467. // 假接口
  468. int PlatformID = obj.value("PlatformID").toInt();
  469. int InstanceID = obj.value("InstanceID").toInt();
  470. QJsonObject data = obj.value("data").toObject();
  471. if (data.contains("uRrPoweron"))
  472. {
  473. EsmworkPara.uRrPowerOn = data.value("uRrPoweron").toBool() ? 1 : 0;
  474. }
  475. if (data.contains("uRrWorkMode"))
  476. {
  477. EsmworkPara.uRrWorkMode = data.value("uRrWorkMode").toInt();
  478. }
  479. if (data.contains("uLineNumPerFrame"))
  480. {
  481. EsmworkPara.uLineNumPerFrame = data.value("uLineNumPerFrame").toInt();
  482. }
  483. if (data.contains("dScanAzCentDeg"))
  484. {
  485. EsmworkPara.dScanAzCentDeg = data.value("dScanAzCentDeg").toDouble();
  486. }
  487. if (data.contains("dScanAzWidthDeg"))
  488. {
  489. EsmworkPara.dScanAzWidthDeg = data.value("dScanAzWidthDeg").toDouble();
  490. }
  491. if (data.contains("dScanElCentDeg"))
  492. {
  493. EsmworkPara.dScanElCentDeg = data.value("dScanElCentDeg").toDouble();
  494. }
  495. if (data.contains("fAntScanVel"))
  496. {
  497. EsmworkPara.fAntScanVel = data.value("fAntScanVel").toDouble();
  498. }
  499. if (data.contains("fFreqScanVel"))
  500. {
  501. EsmworkPara.fFreqScanVel = data.value("fFreqScanVel").toDouble();
  502. }
  503. if (data.contains("fFreqMode"))
  504. {
  505. int mode = data.value("fFreqMode").toInt();
  506. if (mode == 1)
  507. {
  508. EsmworkPara.fTecBeginFreqMhz = 500;
  509. EsmworkPara.fTecEndFreqMhz = 2000;
  510. }
  511. else if (mode == 2)
  512. {
  513. EsmworkPara.fTecBeginFreqMhz = 2000;
  514. EsmworkPara.fTecEndFreqMhz = 5000;
  515. }
  516. else if (mode == 3)
  517. {
  518. EsmworkPara.fTecBeginFreqMhz = 5000;
  519. EsmworkPara.fTecEndFreqMhz = 18000;
  520. }
  521. }
  522. QJsonObject *ret = new QJsonObject({{"url", obj.value("url")},
  523. {"PlatformID", obj.value("PlatformID")},
  524. {"data", 1}});
  525. returnMessage(pSender, ret);
  526. }
  527. void WSServer::getESMParams(QWebSocket *pSender, QJsonObject obj)
  528. {
  529. qDebug() << "网页请求ESM参数";
  530. // 假接口
  531. int InstanceID = obj.value("InstanceID").toInt();
  532. if (true)
  533. {
  534. QJsonObject ESMProps[]{
  535. // fBeamAzWidth
  536. {
  537. {"key", "方位波束宽度"},
  538. {"value", 2}},
  539. // fBeamElWidth
  540. {
  541. {"key", "俯仰波束宽度"},
  542. {"value", 2}},
  543. // fTecMinFreqMhz
  544. {
  545. {"key", "侦收最小频率"},
  546. {"value", 2e3}},
  547. // fTecMaxFreqMhz
  548. {
  549. {"key", "侦收最大频率"},
  550. {"value", 18e3}},
  551. // fInstantPageWidMhz
  552. {
  553. {"key", "瞬时侦察工作频带带宽"},
  554. {"value", 500}},
  555. // ulChanNum
  556. {
  557. {"key", "信道个数"},
  558. {"value", 64}},
  559. // fTecMinPW
  560. {
  561. {"key", "侦收最小脉冲宽度"},
  562. {"value", 0.5}},
  563. // fTecMaxPW
  564. {
  565. {"key", "侦收最大脉冲宽度"},
  566. {"value", 10}},
  567. // fTecPriMean
  568. {
  569. {"key", "侦收平均重复周期"},
  570. {"value", 40}},
  571. // ulTecTrNumMean
  572. {
  573. {"key", "侦收平均脉冲个数"},
  574. {"value", 5}},
  575. // fMinSnrdB
  576. {
  577. {"key", "最小信噪比"},
  578. {"value", 0.5}},
  579. // fSysRcvLoss
  580. {
  581. {"key", "接收内部系统损耗"},
  582. {"value", 5}},
  583. // fFreqAccuracyReq
  584. {
  585. {"key", "频率测量精度要求"},
  586. {"value", 100}},
  587. // uRrPowerOn
  588. {
  589. {"key", "工作状态"},
  590. {"value", (int)EsmworkPara.uRrPowerOn}},
  591. // uRrWorkMode
  592. {
  593. {"key", "工作模式"},
  594. {"value", (int)EsmworkPara.uRrWorkMode}},
  595. // dScanAzCentDeg
  596. {
  597. {"key", "侦察方位中心"},
  598. {"value", EsmworkPara.dScanAzCentDeg}},
  599. // dScanAzWidthDeg
  600. {
  601. {"key", "侦察方位范围"},
  602. {"value", EsmworkPara.dScanAzWidthDeg}},
  603. // dScanElCentDeg
  604. {
  605. {"key", "侦察俯仰中心"},
  606. {"value", EsmworkPara.dScanElCentDeg}},
  607. // uLineNumPerFrame
  608. {
  609. {"key", "景幅行数"},
  610. {"value", (int)EsmworkPara.uLineNumPerFrame}},
  611. // fAntScanVel
  612. {
  613. {"key", "天线扫描速度"},
  614. {"value", EsmworkPara.fAntScanVel}},
  615. // fFreqScanVel
  616. {
  617. {"key", "频率扫描速度"},
  618. {"value", EsmworkPara.fFreqScanVel}},
  619. // fTecBeginFreqMhz
  620. {
  621. {"key", "侦收起始频率"},
  622. {"value", EsmworkPara.fTecBeginFreqMhz}},
  623. // fTecEndFreqMhz
  624. {
  625. {"key", "侦收终止频率"},
  626. {"value", EsmworkPara.fTecEndFreqMhz}}};
  627. QJsonArray ESMInitParams, ESMCtrlParams;
  628. for (int i = 0; i < 13; i++)
  629. {
  630. ESMInitParams.append(ESMProps[i]);
  631. }
  632. for (int i = 13; i < 23; i++)
  633. {
  634. ESMCtrlParams.append(ESMProps[i]);
  635. }
  636. QJsonObject ESMParams{
  637. {"InitParams", ESMInitParams},
  638. {"CtrlParams", ESMCtrlParams}};
  639. QJsonObject *ret = new QJsonObject({{"url", obj.value("url")},
  640. {"PlatformID", obj.value("PlatformID")},
  641. {"InstanceID", InstanceID},
  642. {"data", ESMParams}});
  643. returnMessage(pSender, ret);
  644. }
  645. }
  646. void WSServer::getESMStatus(QWebSocket *pSender, QJsonObject obj)
  647. {
  648. qDebug() << "网页请求初始化状态";
  649. // 假接口
  650. QJsonArray ESMStatus;
  651. QJsonObject ESMState[]{
  652. {{"key", "扫描行号"},
  653. {"value", 0}},
  654. {{"key", "扫描行状态"},
  655. {"value", 0}},
  656. {{"key", "侦察频率中心"},
  657. {"value", 0}},
  658. {{"key", "侦察频率带宽"},
  659. {"value", 0}},
  660. {{"key", "天线系波束方位"},
  661. {"value", 0}},
  662. {{"key", "天线系波束俯仰"},
  663. {"value", 0}},
  664. {{"key", "天线系波束方位"},
  665. {"value", 0}},
  666. {{"key", "天线系波束方位"},
  667. {"value", 0}}};
  668. for (int i = 0; i < 8; i++)
  669. {
  670. ESMStatus.append(ESMState[i]);
  671. }
  672. // 真实接口
  673. int PlatformID = obj.value("PlatformID").toInt();
  674. int InstanceID = obj.value("InstanceID").toInt();
  675. // 构造返回对象
  676. QJsonObject *ret = new QJsonObject(
  677. {{"url", obj.value("url")},
  678. {"PlatformID", obj.value("PlatformID")},
  679. {"data", ESMStatus}});
  680. returnMessage(pSender, ret);
  681. }
  682. void WSServer::getESMData(QWebSocket *pSender, QJsonObject obj)
  683. {
  684. }
  685. void WSServer::getNavParams(QWebSocket *pSender, QJsonObject obj)
  686. {
  687. // int InstanceID = obj.value("InstanceID").toInt();
  688. // QJsonArray *NavInitParams;
  689. // QJsonArray *NavCtrlParams;
  690. // QJsonObject *NavPropTemp;
  691. // NavInitParams = new QJsonArray();
  692. // NavCtrlParams = new QJsonArray();
  693. // NavPropTemp = new QJsonObject();
  694. // NavPropTemp->insert("key", "precision");
  695. // NavPropTemp->insert("value", QJsonValue(5));
  696. // NavInitParams->append(*NavPropTemp);
  697. // delete NavPropTemp;
  698. // qDebug() << "aaa" << QString(QJsonDocument(*NavCtrlParams).toJson());
  699. // NavPropTemp = new QJsonObject();
  700. // NavPropTemp->insert("key", "longitude");
  701. // NavPropTemp->insert("value", QJsonValue(120));
  702. // NavCtrlParams->append(*NavPropTemp);
  703. // delete NavPropTemp;
  704. // NavPropTemp = new QJsonObject();
  705. // NavPropTemp->insert("key", "latitude");
  706. // NavPropTemp->insert("value", QJsonValue(30));
  707. // NavCtrlParams->append(*NavPropTemp);
  708. // delete NavPropTemp;
  709. // NavPropTemp = new QJsonObject();
  710. // NavPropTemp->insert("key", "altitude");
  711. // NavPropTemp->insert("value", QJsonValue(8014.8));
  712. // NavCtrlParams->append(*NavPropTemp);
  713. // delete NavPropTemp;
  714. // NavPropTemp = new QJsonObject();
  715. // NavPropTemp->insert("key", "azimush");
  716. // NavPropTemp->insert("value", QJsonValue(10));
  717. // NavCtrlParams->append(*NavPropTemp);
  718. // delete NavPropTemp;
  719. // NavPropTemp = new QJsonObject();
  720. // NavPropTemp->insert("key", "elevation");
  721. // NavPropTemp->insert("value", QJsonValue(-3));
  722. // NavCtrlParams->append(*NavPropTemp);
  723. // delete NavPropTemp;
  724. // QJsonObject *NAVParams = new QJsonObject();
  725. // NAVParams->insert("InitParams", *NavInitParams);
  726. // NAVParams->insert("CtrlParams", *NavCtrlParams);
  727. // QJsonObject *ret = new QJsonObject({{"url", obj.value("url")},
  728. // {"PlatformID", obj.value("PlatformID")},
  729. // {"data", *NAVParams}});
  730. // returnMessage(pSender, ret);
  731. // delete NavInitParams;
  732. // delete NavCtrlParams;
  733. // delete NAVParams;
  734. }
  735. void WSServer::setFreePost(QWebSocket *pSender, QJsonObject obj)
  736. {
  737. }