simulationcontrol.cpp 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076
  1. #include "simulationcontrol.h"
  2. SimulationControl::SimulationControl(QObject *parent) : QObject(parent)
  3. {
  4. // 想定文件路径
  5. QFile file(QString::fromLocal8Bit("C:\\Users\\luo_h\\Downloads\\突防想定002.json"));
  6. if (!file.open(QFile::ReadOnly | QFile::Text)) {
  7. qDebug() << "can't open error!";
  8. return;
  9. }
  10. // 读取文件的全部内容
  11. QTextStream stream(&file);
  12. stream.setCodec("UTF-8"); // 设置读取编码是UTF8
  13. QString str = stream.readAll();
  14. file.close();
  15. // QJsonParseError类用于在JSON解析期间报告错误。
  16. QJsonParseError jsonError;
  17. // 将json解析为UTF-8编码的json文档,并从中创建一个QJsonDocument。
  18. // 如果解析成功,返回QJsonDocument对象,否则返回null
  19. QJsonDocument doc = QJsonDocument::fromJson(str.toUtf8(), &jsonError);
  20. // 判断是否解析失败
  21. if (jsonError.error != QJsonParseError::NoError && !doc.isNull()) {
  22. qDebug() << "Json格式错误!" << jsonError.error;
  23. return;
  24. }
  25. qDebug() << QString::fromLocal8Bit("想定文件读取成功");
  26. if (doc.isObject()) {
  27. QJsonObject docobj = doc.object();
  28. qDebug() << QString::fromLocal8Bit("想定编号:") << docobj.value("id").toString();
  29. qDebug() << QString::fromLocal8Bit("想定名称:") << docobj.value("xdname").toString();
  30. qDebug() << QString::fromLocal8Bit("想定类型:") << docobj.value("type").toString();
  31. qDebug() << QString::fromLocal8Bit("开始时间:") << docobj.value("starttime").toString();
  32. qDebug() << QString::fromLocal8Bit("结束时间:") << docobj.value("endtime").toString();
  33. qDebug() << QString::fromLocal8Bit("仿真步长:") << docobj.value("steptime").toDouble();
  34. int redcnt = docobj.value("redcnt").toInt();
  35. int bluecnt = docobj.value("bluecnt").toInt();
  36. qDebug() << QString::fromLocal8Bit("红方作战单元数:") << redcnt;
  37. QJsonArray redunits = docobj.value("redunit").toArray();
  38. for (int i = 0; i < redcnt; i++) {
  39. QJsonObject unit = redunits.at(i).toObject();
  40. int unitid = unit.value("unitID").toInt();
  41. QString unitType = unit.value("type").toString();
  42. QString unitName = unit.value("name").toString();
  43. QString unitTask = unit.value("task").toString();
  44. int unitMovementID = unit.value("component_movementid").toInt();
  45. if (i == 0) {
  46. allymissile.push_back(new Platform(this, unitid, unitName, 120,27, 8000, -600, 600, -900));
  47. }
  48. else {
  49. allymissile.push_back(new Platform(this, unitid, unitName, 120.5,27.5, 8000, -600, 600, -900));
  50. }
  51. qDebug() << "\t" << QString::fromLocal8Bit("初始化作战单元:") << unitid << unitName;
  52. qDebug() << "\t" << QString::fromLocal8Bit("作战单元类型:") << unitType;
  53. qDebug() << "\t" << QString::fromLocal8Bit("作战单元意图:") << unitTask;
  54. qDebug() << "\t" << QString::fromLocal8Bit("作战单元运动模型ID:") << unitMovementID;
  55. int componentCnt = unit.value("components_ids").toInt();
  56. QJsonObject componentsJson = unit.value("components_json").toObject();
  57. for (auto i : componentsJson.keys())
  58. {
  59. QJsonObject componentNow = componentsJson.value(i).toObject();
  60. int componentID = componentNow.value("id").toInt();
  61. QString componentName = componentNow.value("number").toString();
  62. QString componentType = componentNow.value("type").toString();
  63. QString componentUrl = componentNow.value("url").toString();
  64. Jamming *jammingtmp = new Jamming(this, unitid, componentID, true, componentName,
  65. componentUrl, 1);
  66. allyJammingSim.insert(std::pair<int, Jamming*>(componentID, jammingtmp));
  67. qDebug() << "\t\t" << QString::fromLocal8Bit("初始化单元组件:") << i << componentID << (componentName);
  68. qDebug() << "\t\t" << QString::fromLocal8Bit("单元组件类型:") << (componentType) << (componentUrl);
  69. }
  70. }
  71. qDebug() << QString::fromLocal8Bit("蓝方作战单元数:") << ":" << bluecnt;
  72. QJsonArray blueunits = docobj.value("blueunit").toArray();
  73. for (int i = 0; i < bluecnt; i++) {
  74. QJsonObject unit = blueunits.at(i).toObject();
  75. int unitid = unit.value("unitID").toInt();
  76. QString unitType = unit.value("type").toString();
  77. QString unitName = unit.value("name").toString();
  78. QString unitTask = unit.value("task").toString();
  79. int unitMovementID = unit.value("component_movementid").toInt();
  80. qDebug() << "\t" << QString::fromLocal8Bit("初始化作战单元:") << unitid << unitName;
  81. qDebug() << "\t" << QString::fromLocal8Bit("作战单元类型:") << unitType;
  82. qDebug() << "\t" << QString::fromLocal8Bit("作战单元意图:") << unitTask;
  83. qDebug() << "\t" << QString::fromLocal8Bit("作战单元运动模型ID:") << unitMovementID;
  84. if (unitType.compare(QString::fromLocal8Bit("末端拦截系统"))==0) {
  85. if (i == 0) {
  86. enemyradar.push_back(new Platform(this,unitid,unitName,121,24.5,0));
  87. }
  88. else {
  89. enemyradar.push_back(new Platform(this,unitid,unitName,121,22.5,0));
  90. }
  91. }
  92. else if (unitType.compare(QString::fromLocal8Bit("预警卫星"))==0){
  93. // ...
  94. enemysat.push_back(new Platform(this,unitid,unitName));
  95. }
  96. int componentCnt = unit.value("components_ids").toInt();
  97. QJsonObject componentsJson = unit.value("components_json").toObject();
  98. for (auto i : componentsJson.keys())
  99. {
  100. QJsonObject componentNow = componentsJson.value(i).toObject();
  101. int componentID = componentNow.value("id").toInt();
  102. QString componentName = componentNow.value("name").toString();
  103. QString componentType = componentNow.value("type").toString();
  104. QString componentUrl = componentNow.value("url").toString();
  105. if (componentType.compare(QString::fromLocal8Bit("雷达"))==0)
  106. {
  107. Radar *radarNow = new Radar(this, unitid, componentID, true, componentName,
  108. componentUrl);
  109. enemyThaadRadarSim.insert(std::pair<int, Radar*>(componentID, radarNow));
  110. }
  111. else
  112. {
  113. // ...
  114. }
  115. qDebug() << "\t\t" << QString::fromLocal8Bit("初始化单元组件:") << i << componentID << (componentName);
  116. qDebug() << "\t\t" << QString::fromLocal8Bit("单元组件类型:") << (componentType) << (componentUrl);
  117. }
  118. }
  119. }
  120. qDebug() << QString::fromLocal8Bit("启动推演...");
  121. // 添加场景平台
  122. // allyplane.push_back(new Platform(this, 1001, QString::fromLocal8Bit("弹道导弹1"),120,27,8000,-600,600,-900));
  123. // allymissile.push_back(new Platform(this, 1004, QString::fromLocal8Bit("弹道导弹4"),120.3,27.3,8000,-600,600,-900));
  124. ally.push_back(allyplane);
  125. ally.push_back(allymissile);
  126. enemy.push_back(enemyradar);
  127. enemy.push_back(enemysat);
  128. // // 添加雷达模拟器
  129. // Radar *radar1 = new Radar(this, 6001, 12, true, QString::fromLocal8Bit("AN-TPY/2雷达-1"),
  130. // QStringLiteral("ws://localhost:1235"));
  131. // enemyThaadRadarSim.insert(std::pair<int, Radar*>(12, radar1));
  132. // // 添加干扰器
  133. // Jamming *jamming1 = new Jamming(this, 1001, 20, true, QString::fromLocal8Bit("干扰器1"),
  134. // QStringLiteral("ws://localhost:1240"),1);
  135. // allyJammingSim.insert(std::pair<int, Jamming*>(20, jamming1));
  136. }
  137. void SimulationControl::SlotGetInit(QWebSocket *pSender, QJsonObject obj)
  138. {
  139. qDebug() << "Build with Slot";
  140. QJsonObject *InitState = new QJsonObject();
  141. InitState->insert("InitState", 100);
  142. QJsonObject *ret = new QJsonObject();
  143. ret->insert("url", obj.value("url"));
  144. ret->insert("data", *InitState);
  145. delete InitState;
  146. emit SigReturnData(pSender, ret);
  147. }
  148. void SimulationControl::SlotGetLeadPost(QWebSocket *pSender, QJsonObject obj)
  149. {
  150. QJsonArray *LeadPost = new QJsonArray();
  151. QJsonObject *CurrentLeadPost;
  152. CurrentLeadPost = new QJsonObject();
  153. CurrentLeadPost->insert("time", "20:20:01");
  154. CurrentLeadPost->insert("GroupID", QString::fromLocal8Bit("编队1"));
  155. CurrentLeadPost->insert("LeaderID", "1001");
  156. CurrentLeadPost->insert("Abstract", QString::fromLocal8Bit("发现雷达"));
  157. LeadPost->append(*CurrentLeadPost);
  158. delete CurrentLeadPost;
  159. CurrentLeadPost = new QJsonObject();
  160. CurrentLeadPost->insert("time", "20:20:30");
  161. CurrentLeadPost->insert("GroupID", QString::fromLocal8Bit("编队1"));
  162. CurrentLeadPost->insert("LeaderID", "1002");
  163. CurrentLeadPost->insert("Abstract", QString::fromLocal8Bit("请求施加干扰"));
  164. LeadPost->append(*CurrentLeadPost);
  165. delete CurrentLeadPost;
  166. CurrentLeadPost = new QJsonObject();
  167. CurrentLeadPost->insert("time", "20:20:40");
  168. CurrentLeadPost->insert("GroupID", QString::fromLocal8Bit("编队1"));
  169. CurrentLeadPost->insert("LeaderID", "1002");
  170. CurrentLeadPost->insert("Abstract", QString::fromLocal8Bit("干扰样式生成"));
  171. LeadPost->append(*CurrentLeadPost);
  172. delete CurrentLeadPost;
  173. CurrentLeadPost = new QJsonObject();
  174. CurrentLeadPost->insert("time", "20:21:00");
  175. CurrentLeadPost->insert("GroupID", QString::fromLocal8Bit("编队1"));
  176. CurrentLeadPost->insert("LeaderID", "1003");
  177. CurrentLeadPost->insert("Abstract", QString::fromLocal8Bit("干扰信号发射"));
  178. LeadPost->append(*CurrentLeadPost);
  179. delete CurrentLeadPost;
  180. QJsonObject *ret = new QJsonObject();
  181. ret->insert("url", obj.value("url"));
  182. ret->insert("PlatformID", obj.value("PlatformID"));
  183. ret->insert("data", *LeadPost);
  184. delete LeadPost;
  185. emit SigReturnData(pSender, ret);
  186. }
  187. void SimulationControl::SlotGetTaskPlan(QWebSocket *pSender, QJsonObject obj)
  188. {
  189. QJsonObject *TaskPlan = new QJsonObject();
  190. QJsonObject *CurrentAirLine;
  191. QJsonObject *CurrentTaskPlan;
  192. CurrentAirLine = new QJsonObject;
  193. CurrentAirLine->insert("TargetArea", 3);
  194. CurrentAirLine->insert("Longitude", 123);
  195. CurrentAirLine->insert("Longitude", 27);
  196. CurrentAirLine->insert("Radius", 300000);
  197. CurrentTaskPlan = new QJsonObject;
  198. CurrentTaskPlan->insert("TargetArea", 2);
  199. CurrentTaskPlan->insert("ThrowGas", 2);
  200. CurrentTaskPlan->insert("ThrowBT", 2);
  201. TaskPlan->insert("Airline", *CurrentAirLine);
  202. TaskPlan->insert("TaskPlan", *CurrentTaskPlan);
  203. QJsonObject *ret = new QJsonObject();
  204. ret->insert("url", obj.value("url"));
  205. ret->insert("PlatformID", obj.value("PlatformID"));
  206. ret->insert("data", *TaskPlan);
  207. delete TaskPlan;
  208. delete CurrentAirLine;
  209. delete CurrentTaskPlan;
  210. emit SigReturnData(pSender, ret);
  211. }
  212. void SimulationControl::SlotGetGlobalMap(QWebSocket *pSender, QJsonObject obj)
  213. {
  214. QJsonObject GlobalMap;
  215. // QJsonObject *alies = new QJsonObject();
  216. // QJsonObject *enemys = new QJsonObject();
  217. QJsonObject allies;
  218. QJsonObject enemys;
  219. for (int i=0; i < ally.size(); i++)
  220. {
  221. QJsonArray allyNow;
  222. for (auto j: ally.at(i))
  223. {
  224. QJsonArray temparray = {j->lon, j->lat, j->h};
  225. QJsonObject tempObject
  226. {
  227. {"name", j->Name},
  228. {"value", temparray}
  229. };
  230. allyNow.append(tempObject);
  231. }
  232. if (i == 0)
  233. {
  234. allies.insert("Planes", allyNow);
  235. }
  236. else if (i == 1)
  237. {
  238. allies.insert("Missiles",allyNow);
  239. }
  240. }
  241. for (int i=0; i < enemy.size(); i++)
  242. {
  243. QJsonArray enemyNow;
  244. for (auto j: enemy.at(i))
  245. {
  246. QJsonArray temparray = {j->lon, j->lat, j->h};
  247. QJsonObject tempObject
  248. {
  249. {"name", j->Name},
  250. {"value", temparray}
  251. };
  252. enemyNow.append(tempObject);
  253. }
  254. if (i == 0)
  255. {
  256. enemys.insert("Radars", enemyNow);
  257. }
  258. }
  259. GlobalMap.insert("friend", QJsonValue(allies));
  260. GlobalMap.insert("enemy", QJsonValue(enemys));
  261. QJsonObject *ret = new QJsonObject();
  262. ret->insert("url", obj.value("url"));
  263. ret->insert("PlatformID", obj.value("PlatformID"));
  264. ret->insert("data",QJsonValue(GlobalMap));
  265. emit SigReturnData(pSender, ret);
  266. }
  267. void SimulationControl::SlotGetPlatformTable(QWebSocket *pSender, QJsonObject obj)
  268. {
  269. QJsonArray Platforms;
  270. for (int i = 0; i < ally.size(); i++)
  271. {
  272. std::vector<Platform *> allyplatforms = ally.at(i);
  273. if (true || i == 0) // for simplicity
  274. {
  275. for (auto j : allyplatforms)
  276. {
  277. QJsonObject SinglePlatform
  278. {
  279. {"platformID", QString::number(j->ID)},
  280. {"platformName", j->Name}
  281. };
  282. Platforms.append(SinglePlatform);
  283. }
  284. }
  285. }
  286. QJsonObject *ret = new QJsonObject();
  287. ret->insert("url", obj.value("url"));
  288. ret->insert("data",QJsonValue(Platforms));
  289. emit SigReturnData(pSender, ret);
  290. }
  291. void SimulationControl::SlotGetInstanceTable(QWebSocket *pSender, QJsonObject obj)
  292. {
  293. QJsonArray *Instances = new QJsonArray();
  294. QJsonObject *SingleInstance;
  295. if (true)
  296. {
  297. SingleInstance = new QJsonObject();
  298. SingleInstance->insert("instanceID", 22);
  299. SingleInstance->insert("instanceName", QString::fromLocal8Bit("侦察机_1"));
  300. Instances->append(*SingleInstance);
  301. delete SingleInstance;
  302. SingleInstance = new QJsonObject();
  303. SingleInstance->insert("instanceID", 62);
  304. SingleInstance->insert("instanceName", QString::fromLocal8Bit("信号侦察_1"));
  305. Instances->append(*SingleInstance);
  306. delete SingleInstance;
  307. SingleInstance = new QJsonObject();
  308. SingleInstance->insert("instanceID", 96);
  309. SingleInstance->insert("instanceName", QString::fromLocal8Bit("体系增量_1"));
  310. Instances->append(*SingleInstance);
  311. delete SingleInstance;
  312. SingleInstance = new QJsonObject();
  313. SingleInstance->insert("instanceID", 111);
  314. SingleInstance->insert("instanceName", QString::fromLocal8Bit("侦察平台任务系统_1"));
  315. Instances->append(*SingleInstance);
  316. delete SingleInstance;
  317. SingleInstance = new QJsonObject();
  318. SingleInstance->insert("instanceID", 171);
  319. SingleInstance->insert("instanceName", QString::fromLocal8Bit("导航_1"));
  320. Instances->append(*SingleInstance);
  321. delete SingleInstance;
  322. }
  323. QJsonObject *ret = new QJsonObject();
  324. ret->insert("url", obj.value("url"));
  325. ret->insert("PlatformID", obj.value("PlatformID"));
  326. ret->insert("data",QJsonValue(*Instances));
  327. delete Instances;
  328. emit SigReturnData(pSender, ret);
  329. }
  330. void SimulationControl::SlotGetRadarInstances(QWebSocket *pSender, QJsonObject obj)
  331. {
  332. int nowPlatform = obj.value("PlatformID").toInt();
  333. QJsonArray RadarInstances;
  334. for (auto i : enemyThaadRadarSim)
  335. {
  336. QJsonObject tempThaad;
  337. if (1 || nowPlatform == i.second->PlatformID)
  338. {
  339. tempThaad.insert("instanceID", QString::number(i.first));
  340. tempThaad.insert("instanceName",i.second->Name);
  341. if (i.second->SwitchMode)
  342. {
  343. tempThaad.insert("instanceState", QString::fromLocal8Bit("开机"));
  344. }
  345. else
  346. {
  347. tempThaad.insert("instanceState", QString::fromLocal8Bit("关机"));
  348. }
  349. }
  350. RadarInstances.append(tempThaad);
  351. }
  352. QJsonObject *ret = new QJsonObject();
  353. ret->insert("url", obj.value("url"));
  354. ret->insert("PlatformID", obj.value("PlatformID"));
  355. ret->insert("data",QJsonValue(RadarInstances));
  356. emit SigReturnData(pSender, ret);
  357. }
  358. void SimulationControl::SlotGetRadarParams(QWebSocket *pSender, QJsonObject obj)
  359. {
  360. int nowInstance = obj.value("InstanceID").toString().toInt();
  361. Radar *nowRadar = enemyThaadRadarSim.at(nowInstance);
  362. if (nowRadar == nullptr)
  363. {
  364. QJsonObject *ret = new QJsonObject();
  365. ret->insert("url", obj.value("url"));
  366. ret->insert("PlatformID", obj.value("PlatformID"));
  367. ret->insert("InstanceID", obj.value("InstanceID"));
  368. ret->insert("data",QJsonValue());
  369. emit SigReturnData(pSender, ret);
  370. }
  371. else if (true || nowRadar->PlatformID == obj.value("PlatformID").toInt())
  372. {
  373. int styleIdx = nowRadar->style;
  374. qDebug() << styleIdx;
  375. Style nowStyle = nowRadar->RadarStyleList.at(styleIdx);
  376. QJsonObject nowfs {
  377. {"key", QString::fromLocal8Bit("采样频率")},
  378. {"value", nowStyle.fs}
  379. };
  380. QJsonObject nowfc {
  381. {"key", QString::fromLocal8Bit("载波频率")},
  382. {"value", nowStyle.fc}
  383. };
  384. QJsonObject nowModuType {
  385. {"key", QString::fromLocal8Bit("调制类型")},
  386. {"value", nowStyle.moduType}
  387. };
  388. QJsonObject nowPRFMode {
  389. {"key", QString::fromLocal8Bit("PRF模式")},
  390. {"value", nowStyle.PRFMode}
  391. };
  392. QJsonArray PRFarray;
  393. for (auto i : nowStyle.PRFs)
  394. {
  395. PRFarray.push_back(i);
  396. }
  397. QJsonObject nowPRF
  398. {
  399. {"key", QString::fromLocal8Bit("PRF")},
  400. {"value", PRFarray}
  401. };
  402. QJsonObject nowPW
  403. {
  404. {"key", QString::fromLocal8Bit("脉冲宽度")},
  405. {"value", nowStyle.PulseWidth}
  406. };
  407. QJsonObject nowBW
  408. {
  409. {"key", QString::fromLocal8Bit("带宽")},
  410. {"value", nowStyle.BandWidth}
  411. };
  412. QJsonArray nowParams = {nowfs, nowfc, nowModuType, nowPRFMode, nowPRF, nowPW, nowBW};
  413. QJsonObject initMaxDis {
  414. {"key", QString::fromLocal8Bit("最大量程")},
  415. {"value", 800000}
  416. };
  417. QJsonObject initMinDis {
  418. {"key", QString::fromLocal8Bit("最小量程")},
  419. {"value", 1000}
  420. };
  421. QJsonObject initMaxFre {
  422. {"key", QString::fromLocal8Bit("最大频率")},
  423. {"value", 12e9}
  424. };
  425. QJsonObject initMinFre {
  426. {"key", QString::fromLocal8Bit("最大频率")},
  427. {"value", 8e9}
  428. };
  429. QJsonObject initNumArrayElement {
  430. {"key", QString::fromLocal8Bit("阵元数")},
  431. {"value", 25344}
  432. };
  433. QJsonObject initGain {
  434. {"key", QString::fromLocal8Bit("天线增益")},
  435. {"value", 48.77}
  436. };
  437. QJsonObject initPt {
  438. {"key", QString::fromLocal8Bit("发射机功率")},
  439. {"value", 405e3}
  440. };
  441. QJsonArray initParams = {initMaxDis, initMinDis, initMaxFre, initMinFre, initNumArrayElement, initGain, initPt};
  442. QJsonObject retParams {
  443. {"InitParams", initParams},
  444. {"CtrlParams", nowParams}
  445. };
  446. QJsonObject *ret = new QJsonObject({
  447. {"url", obj.value("url")},
  448. {"PlatformID", obj.value("PlatformID")},
  449. {"InstanceID", obj.value("InstanceID")},
  450. {"data",QJsonValue(retParams)}
  451. });
  452. emit SigReturnData(pSender, ret);
  453. }
  454. }
  455. void SimulationControl::SlotGetThaadInstances(QWebSocket *pSender, QJsonObject obj)
  456. {
  457. QJsonArray RadarInstances;
  458. for (auto i : enemyThaadRadarSim)
  459. {
  460. QJsonObject tempThaad;
  461. if (1)
  462. {
  463. tempThaad.insert("instanceID", QString::number(i.first));
  464. tempThaad.insert("instanceName",i.second->Name);
  465. if (i.second->SwitchMode)
  466. {
  467. tempThaad.insert("instanceState", QString::fromLocal8Bit("开机"));
  468. }
  469. else
  470. {
  471. tempThaad.insert("instanceState", QString::fromLocal8Bit("关机"));
  472. }
  473. }
  474. RadarInstances.append(tempThaad);
  475. }
  476. QJsonObject *ret = new QJsonObject();
  477. ret->insert("url", obj.value("url"));
  478. ret->insert("PlatformID", obj.value("PlatformID"));
  479. ret->insert("data",QJsonValue(RadarInstances));
  480. emit SigReturnData(pSender, ret);
  481. }
  482. void SimulationControl::SlotGetThaadParams(QWebSocket *pSender, QJsonObject obj)
  483. {
  484. int nowInstance = obj.value("InstanceID").toString().toInt();
  485. Radar *nowRadar = enemyThaadRadarSim.at(nowInstance);
  486. if (nowRadar == nullptr)
  487. {
  488. QJsonObject *ret = new QJsonObject();
  489. ret->insert("url", obj.value("url"));
  490. ret->insert("PlatformID", obj.value("PlatformID"));
  491. ret->insert("InstanceID", obj.value("InstanceID"));
  492. ret->insert("data",QJsonValue());
  493. emit SigReturnData(pSender, ret);
  494. }
  495. else if (true || nowRadar->PlatformID == obj.value("PlatformID").toInt())
  496. {
  497. int styleIdx = nowRadar->style;
  498. qDebug() << styleIdx;
  499. Style nowStyle = nowRadar->RadarStyleList.at(styleIdx);
  500. QJsonObject nowfs {
  501. {"key", QString::fromLocal8Bit("采样频率")},
  502. {"value", nowStyle.fs}
  503. };
  504. QJsonObject nowfc {
  505. {"key", QString::fromLocal8Bit("载波频率")},
  506. {"value", nowStyle.fc}
  507. };
  508. QJsonObject nowModuType {
  509. {"key", QString::fromLocal8Bit("调制类型")},
  510. {"value", nowStyle.moduType}
  511. };
  512. QJsonObject nowPRFMode {
  513. {"key", QString::fromLocal8Bit("PRF模式")},
  514. {"value", nowStyle.PRFMode}
  515. };
  516. QJsonArray PRFarray;
  517. for (auto i : nowStyle.PRFs)
  518. {
  519. PRFarray.push_back(i);
  520. }
  521. QJsonObject nowPRF
  522. {
  523. {"key", QString::fromLocal8Bit("PRF")},
  524. {"value", PRFarray}
  525. };
  526. QJsonObject nowPW
  527. {
  528. {"key", QString::fromLocal8Bit("脉冲宽度")},
  529. {"value", nowStyle.PulseWidth}
  530. };
  531. QJsonObject nowBW
  532. {
  533. {"key", QString::fromLocal8Bit("带宽")},
  534. {"value", nowStyle.BandWidth}
  535. };
  536. QJsonArray nowParams = {nowfs, nowfc, nowModuType, nowPRFMode, nowPRF, nowPW, nowBW};
  537. QJsonObject initMaxDis {
  538. {"key", QString::fromLocal8Bit("最大量程")},
  539. {"value", 800000}
  540. };
  541. QJsonObject initMinDis {
  542. {"key", QString::fromLocal8Bit("最小量程")},
  543. {"value", 1000}
  544. };
  545. QJsonObject initMaxFre {
  546. {"key", QString::fromLocal8Bit("最大频率")},
  547. {"value", 12e9}
  548. };
  549. QJsonObject initMinFre {
  550. {"key", QString::fromLocal8Bit("最大频率")},
  551. {"value", 8e9}
  552. };
  553. QJsonObject initNumArrayElement {
  554. {"key", QString::fromLocal8Bit("阵元数")},
  555. {"value", 25344}
  556. };
  557. QJsonObject initGain {
  558. {"key", QString::fromLocal8Bit("天线增益")},
  559. {"value", 48.77}
  560. };
  561. QJsonObject initPt {
  562. {"key", QString::fromLocal8Bit("发射机功率")},
  563. {"value", 405e3}
  564. };
  565. QJsonArray initParams = {initMaxDis, initMinDis, initMaxFre, initMinFre, initNumArrayElement, initGain, initPt};
  566. QJsonObject retParams {
  567. {"InitParams", initParams},
  568. {"CtrlParams", nowParams}
  569. };
  570. QJsonObject *ret = new QJsonObject({
  571. {"url", obj.value("url")},
  572. {"PlatformID", obj.value("PlatformID")},
  573. {"InstanceID", obj.value("InstanceID")},
  574. {"data",QJsonValue(retParams)}
  575. });
  576. emit SigReturnData(pSender, ret);
  577. }
  578. }
  579. void SimulationControl::SlotSetThaadStyle(QWebSocket *pSender, QJsonObject obj)
  580. {
  581. // PlatformID和InstanceID是字符串
  582. int nowPlatform = obj.value("PlatformID").toString().toInt();
  583. int nowInstance = obj.value("InstanceID").toString().toInt();
  584. QJsonObject nowdata = obj.value("data").toObject();
  585. if (nowdata.contains("Style"))
  586. {
  587. // Style索引是整型
  588. int nowStyle = nowdata.value("Style").toInt();
  589. // qDebug() << nowPlatform <<" "<< nowInstance << " " << nowStyle;
  590. Radar *nowRadar = enemyThaadRadarSim.at(nowInstance);
  591. if (nowRadar == nullptr)
  592. {
  593. QJsonObject *ret = new QJsonObject();
  594. ret->insert("url", obj.value("url"));
  595. ret->insert("PlatformID", obj.value("PlatformID"));
  596. ret->insert("InstanceID", obj.value("InstanceID"));
  597. ret->insert("data", QJsonValue(""));
  598. emit SigReturnData(pSender, ret);
  599. }
  600. else
  601. {
  602. nowRadar->StyleUpdate(nowStyle);
  603. int styleIdx = nowRadar->style;
  604. qDebug() << styleIdx;
  605. Style nowStyle = nowRadar->RadarStyleList.at(styleIdx);
  606. QJsonObject nowfs {
  607. {"key", QString::fromLocal8Bit("采样频率")},
  608. {"value", nowStyle.fs}
  609. };
  610. QJsonObject nowfc {
  611. {"key", QString::fromLocal8Bit("载波频率")},
  612. {"value", nowStyle.fc}
  613. };
  614. QJsonObject nowModuType {
  615. {"key", QString::fromLocal8Bit("调制类型")},
  616. {"value", nowStyle.moduType}
  617. };
  618. QJsonObject nowPRFMode {
  619. {"key", QString::fromLocal8Bit("PRF模式")},
  620. {"value", nowStyle.PRFMode}
  621. };
  622. QJsonArray PRFarray;
  623. for (auto i : nowStyle.PRFs)
  624. {
  625. PRFarray.push_back(i);
  626. }
  627. QJsonObject nowPRF
  628. {
  629. {"key", QString::fromLocal8Bit("PRF")},
  630. {"value", PRFarray}
  631. };
  632. QJsonObject nowPW
  633. {
  634. {"key", QString::fromLocal8Bit("脉冲宽度")},
  635. {"value", nowStyle.PulseWidth}
  636. };
  637. QJsonObject nowBW
  638. {
  639. {"key", QString::fromLocal8Bit("带宽")},
  640. {"value", nowStyle.BandWidth}
  641. };
  642. QJsonArray nowParams = {nowfs, nowfc, nowModuType, nowPRFMode, nowPRF, nowPW, nowBW};
  643. QJsonObject initMaxDis {
  644. {"key", QString::fromLocal8Bit("最大量程")},
  645. {"value", 800000}
  646. };
  647. QJsonObject initMinDis {
  648. {"key", QString::fromLocal8Bit("最小量程")},
  649. {"value", 1000}
  650. };
  651. QJsonObject initMaxFre {
  652. {"key", QString::fromLocal8Bit("最大频率")},
  653. {"value", 12e9}
  654. };
  655. QJsonObject initMinFre {
  656. {"key", QString::fromLocal8Bit("最大频率")},
  657. {"value", 8e9}
  658. };
  659. QJsonObject initNumArrayElement {
  660. {"key", QString::fromLocal8Bit("阵元数")},
  661. {"value", 25344}
  662. };
  663. QJsonObject initGain {
  664. {"key", QString::fromLocal8Bit("天线增益")},
  665. {"value", 48.77}
  666. };
  667. QJsonObject initPt {
  668. {"key", QString::fromLocal8Bit("发射机功率")},
  669. {"value", 405e3}
  670. };
  671. QJsonArray initParams = {initMaxDis, initMinDis, initMaxFre, initMinFre, initNumArrayElement, initGain, initPt};
  672. QJsonObject retParams {
  673. {"InitParams", initParams},
  674. {"CtrlParams", nowParams}
  675. };
  676. QJsonObject *ret = new QJsonObject({
  677. {"url", obj.value("url")},
  678. {"PlatformID", obj.value("PlatformID")},
  679. {"InstanceID", obj.value("InstanceID")},
  680. {"data",QJsonValue(retParams)}
  681. });
  682. emit SigReturnData(pSender, ret);
  683. }
  684. }
  685. }
  686. void SimulationControl::SlotGetJammingInstances(QWebSocket *pSender, QJsonObject obj)
  687. {
  688. int nowPlatform = obj.value("PlatformID").toString().toInt();
  689. QJsonArray JammingInstances;
  690. for (auto i : allyJammingSim)
  691. {
  692. QJsonObject tempJamming;
  693. if (true || nowPlatform == i.second->PlatformID)
  694. {
  695. tempJamming.insert("instanceID", QString::number(i.first));
  696. tempJamming.insert("instanceName",i.second->Name);
  697. if (i.second->SwitchMode)
  698. {
  699. tempJamming.insert("instanceState", QString::fromLocal8Bit("开机"));
  700. }
  701. else
  702. {
  703. tempJamming.insert("instanceState", QString::fromLocal8Bit("关机"));
  704. }
  705. JammingInstances.append(tempJamming);
  706. }
  707. }
  708. QJsonObject *ret = new QJsonObject();
  709. ret->insert("url", obj.value("url"));
  710. ret->insert("PlatformID", obj.value("PlatformID"));
  711. ret->insert("data",QJsonValue(JammingInstances));
  712. emit SigReturnData(pSender, ret);
  713. }
  714. void SimulationControl::SlotGetJammingParams(QWebSocket *pSender, QJsonObject obj)
  715. {
  716. int nowInstance = obj.value("InstanceID").toString().toInt();
  717. Jamming *nowJamming = allyJammingSim.at(nowInstance);
  718. if (true || nowJamming->PlatformID == obj.value("PlatformID").toString().toInt())
  719. {
  720. int styleIdx = nowJamming->style;
  721. qDebug() << styleIdx;
  722. JammingStyle nowStyle = nowJamming->JammingStyleList.at(styleIdx);
  723. QJsonObject nowfs
  724. {
  725. {"key", QString::fromLocal8Bit("采样频率")},
  726. {"value", nowStyle.fs}
  727. };
  728. QJsonObject nowfc
  729. {
  730. {"key", QString::fromLocal8Bit("载波频率")},
  731. {"value", nowStyle.fc}
  732. };
  733. QJsonObject nowOpMode
  734. {
  735. {"key", QString::fromLocal8Bit("调制类型")},
  736. {"value", nowStyle.OpMode}
  737. };
  738. QJsonArray nowParams = {nowfs, nowfc, nowOpMode};
  739. QJsonObject *ret = new QJsonObject();
  740. ret->insert("url", obj.value("url"));
  741. ret->insert("PlatformID", obj.value("PlatformID"));
  742. ret->insert("InstanceID", obj.value("InstanceID"));
  743. ret->insert("data",QJsonValue(nowParams));
  744. emit SigReturnData(pSender, ret);
  745. }
  746. }
  747. void SimulationControl::SlotSetJammingStyle(QWebSocket *pSender, QJsonObject obj)
  748. {
  749. // PlatformID和InstanceID是字符串
  750. int nowPlatform = obj.value("PlatformID").toString().toInt();
  751. int nowInstance = obj.value("InstanceID").toString().toInt();
  752. QJsonObject nowdata = obj.value("data").toObject();
  753. if (nowdata.contains("Style"))
  754. {
  755. // Style索引是整型
  756. int nowStyle = nowdata.value("Style").toInt();
  757. // qDebug() << nowPlatform <<" "<< nowInstance << " " << nowStyle;
  758. Jamming *nowJamming = allyJammingSim.at(nowInstance);
  759. if (nowJamming == nullptr)
  760. {
  761. QJsonObject *ret = new QJsonObject();
  762. ret->insert("url", obj.value("url"));
  763. ret->insert("PlatformID", obj.value("PlatformID"));
  764. ret->insert("InstanceID", obj.value("InstanceID"));
  765. ret->insert("data", QJsonValue(""));
  766. emit SigReturnData(pSender, ret);
  767. }
  768. else
  769. {
  770. nowJamming->StyleUpdate(nowStyle);
  771. int styleIdx = nowJamming->style;
  772. qDebug() << styleIdx;
  773. JammingStyle nowStyle = nowJamming->JammingStyleList.at(styleIdx);
  774. QJsonObject nowfs {
  775. {"key", QString::fromLocal8Bit("采样频率")},
  776. {"value", nowStyle.fs}
  777. };
  778. QJsonObject nowfc {
  779. {"key", QString::fromLocal8Bit("载波频率")},
  780. {"value", nowStyle.fc}
  781. };
  782. QJsonObject nowOpMode {
  783. {"key", QString::fromLocal8Bit("开关机状态")},
  784. {"value", nowStyle.OpMode}
  785. };
  786. QJsonArray nowParams = {nowfs, nowfc, nowOpMode};
  787. QJsonObject *ret = new QJsonObject({
  788. {"url", obj.value("url")},
  789. {"PlatformID", obj.value("PlatformID")},
  790. {"InstanceID", obj.value("InstanceID")},
  791. {"data",QJsonValue(nowParams)}
  792. });
  793. emit SigReturnData(pSender, ret);
  794. }
  795. }
  796. }
  797. void SimulationControl::SlotGetESMParams(QWebSocket *pSender, QJsonObject obj)
  798. {
  799. int InstanceID = obj.value("InstanceID").toInt();
  800. QJsonArray *ESMInitParams;
  801. QJsonArray *ESMCtrlParams;
  802. QJsonObject *ESMPropTemp;
  803. if (true)
  804. {
  805. ESMInitParams = new QJsonArray();
  806. ESMCtrlParams = new QJsonArray();
  807. ESMPropTemp = new QJsonObject();
  808. ESMPropTemp->insert("key","fBeamAzWidth");
  809. ESMPropTemp->insert("value",2);
  810. ESMInitParams->append(*ESMPropTemp);
  811. delete ESMPropTemp;
  812. ESMPropTemp = new QJsonObject();
  813. ESMPropTemp->insert("key","fBeamElWidth");
  814. ESMPropTemp->insert("value",2);
  815. ESMInitParams->append(*ESMPropTemp);
  816. delete ESMPropTemp;
  817. ESMPropTemp = new QJsonObject();
  818. ESMPropTemp->insert("key","fTecMinFreqMhz");
  819. ESMPropTemp->insert("value",2e3);
  820. ESMInitParams->append(*ESMPropTemp);
  821. delete ESMPropTemp;
  822. ESMPropTemp = new QJsonObject();
  823. ESMPropTemp->insert("key","fTecMaxFreqMhz");
  824. ESMPropTemp->insert("value",18e3);
  825. ESMInitParams->append(*ESMPropTemp);
  826. delete ESMPropTemp;
  827. ESMPropTemp = new QJsonObject();
  828. ESMPropTemp->insert("key","fInstantPageWidMhz");
  829. ESMPropTemp->insert("value",500);
  830. ESMInitParams->append(*ESMPropTemp);
  831. delete ESMPropTemp;
  832. ESMPropTemp = new QJsonObject();
  833. ESMPropTemp->insert("key","ulChanNum");
  834. ESMPropTemp->insert("value",64);
  835. ESMInitParams->append(*ESMPropTemp);
  836. delete ESMPropTemp;
  837. ESMPropTemp = new QJsonObject();
  838. ESMPropTemp->insert("key","fTecMinPW");
  839. ESMPropTemp->insert("value",0.5);
  840. ESMInitParams->append(*ESMPropTemp);
  841. delete ESMPropTemp;
  842. ESMPropTemp = new QJsonObject();
  843. ESMPropTemp->insert("key","fTecMaxPW");
  844. ESMPropTemp->insert("value",10);
  845. ESMInitParams->append(*ESMPropTemp);
  846. delete ESMPropTemp;
  847. ESMPropTemp = new QJsonObject();
  848. ESMPropTemp->insert("key","fTecPriMean");
  849. ESMPropTemp->insert("value",40);
  850. ESMInitParams->append(*ESMPropTemp);
  851. delete ESMPropTemp;
  852. ESMPropTemp = new QJsonObject();
  853. ESMPropTemp->insert("key","ulTecTrNumMean");
  854. ESMPropTemp->insert("value",5);
  855. ESMInitParams->append(*ESMPropTemp);
  856. delete ESMPropTemp;
  857. ESMPropTemp = new QJsonObject();
  858. ESMPropTemp->insert("key","fMinSnrdB");
  859. ESMPropTemp->insert("value",0.5);
  860. ESMInitParams->append(*ESMPropTemp);
  861. delete ESMPropTemp;
  862. ESMPropTemp = new QJsonObject();
  863. ESMPropTemp->insert("key","fSysRcvLoss");
  864. ESMPropTemp->insert("value",5);
  865. ESMInitParams->append(*ESMPropTemp);
  866. delete ESMPropTemp;
  867. ESMPropTemp = new QJsonObject();
  868. ESMPropTemp->insert("key","fFreqAccuracyReq");
  869. ESMPropTemp->insert("value",100);
  870. ESMInitParams->append(*ESMPropTemp);
  871. delete ESMPropTemp;
  872. ESMPropTemp = new QJsonObject();
  873. ESMPropTemp->insert("key","uRrPowerOn");
  874. ESMPropTemp->insert("value",0);
  875. ESMCtrlParams->append(*ESMPropTemp);
  876. delete ESMPropTemp;
  877. ESMPropTemp = new QJsonObject();
  878. ESMPropTemp->insert("key","uRrWorkMode");
  879. ESMPropTemp->insert("value",0);
  880. ESMCtrlParams->append(*ESMPropTemp);
  881. delete ESMPropTemp;
  882. ESMPropTemp = new QJsonObject();
  883. ESMPropTemp->insert("key","dScanAzCentDeg");
  884. ESMPropTemp->insert("value",0);
  885. ESMCtrlParams->append(*ESMPropTemp);
  886. delete ESMPropTemp;
  887. ESMPropTemp = new QJsonObject();
  888. ESMPropTemp->insert("key","dScanAzWidthDeg");
  889. ESMPropTemp->insert("value",5);
  890. ESMCtrlParams->append(*ESMPropTemp);
  891. delete ESMPropTemp;
  892. ESMPropTemp = new QJsonObject();
  893. ESMPropTemp->insert("key","dScanElCentDeg");
  894. ESMPropTemp->insert("value",0);
  895. ESMCtrlParams->append(*ESMPropTemp);
  896. delete ESMPropTemp;
  897. ESMPropTemp = new QJsonObject();
  898. ESMPropTemp->insert("key","uLineNumPerFrame");
  899. ESMPropTemp->insert("value",20);
  900. ESMCtrlParams->append(*ESMPropTemp);
  901. delete ESMPropTemp;
  902. ESMPropTemp = new QJsonObject();
  903. ESMPropTemp->insert("key","fAntScanVel");
  904. ESMPropTemp->insert("value",1);
  905. ESMCtrlParams->append(*ESMPropTemp);
  906. delete ESMPropTemp;
  907. ESMPropTemp = new QJsonObject();
  908. ESMPropTemp->insert("key","fFreqScanVel");
  909. ESMPropTemp->insert("value",100);
  910. ESMCtrlParams->append(*ESMPropTemp);
  911. delete ESMPropTemp;
  912. ESMPropTemp = new QJsonObject();
  913. ESMPropTemp->insert("key","fTecBeginFreqMhz");
  914. ESMPropTemp->insert("value",500);
  915. ESMCtrlParams->append(*ESMPropTemp);
  916. delete ESMPropTemp;
  917. ESMPropTemp = new QJsonObject();
  918. ESMPropTemp->insert("key","fTecEndFreqMhz");
  919. ESMPropTemp->insert("value",10000);
  920. ESMCtrlParams->append(*ESMPropTemp);
  921. delete ESMPropTemp;
  922. }
  923. QJsonObject *ESMParams = new QJsonObject();
  924. ESMParams->insert("InitParams", *ESMInitParams);
  925. ESMParams->insert("CtrlParams", *ESMCtrlParams);
  926. QJsonObject *ret = new QJsonObject();
  927. ret->insert("url", obj.value("url"));
  928. ret->insert("PlatformID", obj.value("PlatformID"));
  929. ret->insert("InstanceID", InstanceID);
  930. ret->insert("data", *ESMParams);
  931. emit SigReturnData(pSender, ret);
  932. delete ESMInitParams;
  933. delete ESMCtrlParams;
  934. delete ESMParams;
  935. }