wsserver.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. //#pragma execution_character_set("utf-8")
  2. #include "wsserver.h"
  3. WSServer::WSServer(QObject *parent, quint16 port) : QObject(parent)
  4. {
  5. m_pWebSocketServer = new QWebSocketServer(QStringLiteral("Mock Server"),
  6. QWebSocketServer::NonSecureMode,
  7. this);
  8. if (m_pWebSocketServer->listen(QHostAddress::Any, port))
  9. {
  10. qDebug() << "Mock Server listening on port" << port;
  11. connect(m_pWebSocketServer, &QWebSocketServer::newConnection,
  12. this, &WSServer::onNewConnection);
  13. }
  14. }
  15. WSServer::~WSServer()
  16. {
  17. m_pWebSocketServer->close();
  18. qDeleteAll(m_clients.begin(), m_clients.end());
  19. }
  20. void WSServer::onNewConnection()
  21. {
  22. QWebSocket *pSocket = m_pWebSocketServer->nextPendingConnection();
  23. connect(pSocket, &QWebSocket::textMessageReceived, this, &WSServer::processMessage);
  24. connect(pSocket, &QWebSocket::disconnected, this, &WSServer::socketDisconnected);
  25. m_clients << pSocket;
  26. }
  27. QJsonObject WSServer::processJsonObj(QJsonObject objin)
  28. {
  29. QJsonObject ret;
  30. QStringList Keys = objin.keys();
  31. for (auto k : Keys)
  32. {
  33. QJsonValue v = objin.value(k);
  34. if (k == "url")
  35. {
  36. ret.insert(k, v);
  37. }
  38. else if (k == "InstanceID")
  39. {
  40. ret.insert(k, v);
  41. }
  42. else if (k == "data")
  43. {
  44. if (v.isObject())
  45. {
  46. QJsonObject Props = v.toObject();
  47. QStringList Propkeys = Props.keys();
  48. if (Propkeys.contains("InstanceID"))
  49. {
  50. ret.insert("InstanceID", Props.take("InstanceID"));
  51. }
  52. if (Propkeys.contains("PlatformID"))
  53. {
  54. ret.insert("PlatformID", Props.take("PlatformID"));
  55. }
  56. ret.insert("data",Props);
  57. }
  58. }
  59. // if (v.isArray())
  60. // {
  61. // for (auto i : v.toArray())
  62. // {
  63. // if (i.isString())
  64. // {
  65. // objout->insert(i.toString(),QJsonValue());
  66. // }
  67. // }
  68. // }
  69. // else if (v.isObject())
  70. // {
  71. // QJsonObject Props = v.toObject();
  72. // QStringList Propkeys = Props.keys();
  73. // for (auto propkey: Propkeys)
  74. // {
  75. // objout->insert(propkey,Props.value(k));
  76. // }
  77. // }
  78. // 不想打印
  79. // if (v.isObject())
  80. // {
  81. // processJsonObj(v.toObject(),objout);
  82. // }
  83. // 打印调试信息
  84. if (v.isDouble())
  85. {
  86. qDebug() << k << ": " << v.toDouble();
  87. }
  88. else if (v.isString())
  89. {
  90. qDebug() << k << ": " << v.toString();
  91. }
  92. else if (v.isObject())
  93. {
  94. qDebug() << k << "{";
  95. // processJsonObj(v.toObject(),objout);
  96. QJsonObject objout = processJsonObj(v.toObject());
  97. qDebug() << "}";
  98. }
  99. else if (v.isArray())
  100. {
  101. QJsonArray qarray = v.toArray();
  102. qDebug() << k << "[";
  103. for (auto i : qarray)
  104. {
  105. if (i.isString())
  106. {
  107. qDebug() << i.toString();
  108. }
  109. }
  110. qDebug() << "]";
  111. }
  112. }
  113. //qDebug() << QString(QJsonDocument(*objout).toJson());
  114. return ret;
  115. }
  116. void WSServer::processMessage(QString message)
  117. {
  118. // 获取客户端
  119. QWebSocket *pSender = qobject_cast<QWebSocket *>(sender());
  120. // 以Json格式解码message
  121. QByteArray *ByteMessage = new QByteArray();
  122. ByteMessage->append(message);
  123. QJsonParseError *error = new QJsonParseError();
  124. QJsonDocument IncomingJson = QJsonDocument::fromJson(*ByteMessage, error);
  125. if (error->error == QJsonParseError::NoError)
  126. {
  127. if (IncomingJson.isObject())
  128. {
  129. // 解析message
  130. QJsonObject IncomingObj = IncomingJson.object();
  131. QJsonObject msgobj = this->processJsonObj(IncomingObj);
  132. QStringList props = msgobj.keys();
  133. QString url = msgobj.value("url").toString();
  134. // qDebug() << QString(QJsonDocument(msgobj).toJson());
  135. qDebug() << "url:" << url;
  136. // 判断请求
  137. if (url == "getInit")
  138. {
  139. getInit(pSender, msgobj);
  140. }
  141. else if (url == "getPlatformTable")
  142. {
  143. getPlatformTable(pSender, msgobj);
  144. }
  145. else if (url == "getGlobalMap" || url == "getLocalMap" || url == "getRemoteMap" || url == "getCombineMap")
  146. {
  147. getGlobalMap(pSender, msgobj);
  148. }
  149. else if (url == "getJammingSig")
  150. {
  151. getJammingSig(pSender, msgobj);
  152. }
  153. else
  154. {
  155. // 其他接口都需要带平台ID
  156. if (msgobj.contains("PlatformID")==false)
  157. {
  158. QJsonObject *ret = new QJsonObject();
  159. ret->insert("data", QJsonValue());
  160. // 要是没有平台ID,返回空数据
  161. msgobj.insert("data", QJsonValue());
  162. if (msgobj.contains("url") == true)
  163. {
  164. ret->insert("url", msgobj.value("url"));
  165. }
  166. returnMessage(pSender, ret);
  167. }
  168. else if (url == "getRadarInstances")
  169. {
  170. getRadarInstances(pSender, msgobj);
  171. }
  172. else if (url == "getRadarParams" && msgobj.contains("InstanceID"))
  173. {
  174. getRadarParams(pSender, msgobj);
  175. }
  176. else if (url == "getThaadParams" && msgobj.contains("InstanceID"))
  177. {
  178. getRadarParams(pSender, msgobj);
  179. }
  180. else if (url == "getJammingInstances")
  181. {
  182. getJammingInstances(pSender, msgobj);
  183. }
  184. else if (url == "getJammingParams" && msgobj.contains("InstanceID"))
  185. {
  186. getJammingParams(pSender, msgobj);
  187. }
  188. else if (url == "setJammingStyle" && msgobj.contains("InstanceID"))
  189. {
  190. setJammingStyle(pSender, msgobj);
  191. }
  192. else if (url == "getNavParams")
  193. {
  194. // getNavParams(msgobj);
  195. }
  196. else if (url == "setFreePost")
  197. {
  198. // setFreePost(msgobj);
  199. }
  200. else if (url == "getLeadPost")
  201. {
  202. getLeadPost(pSender, msgobj);
  203. }
  204. else if (url == "getTaskPlan")
  205. {
  206. getTaskPlan(pSender, msgobj);
  207. }
  208. }
  209. // qDebug() << "return message:";
  210. // qDebug() << QString(QJsonDocument(*msgobj).toJson());
  211. // QWebSocket *pSender = qobject_cast<QWebSocket *>(sender());
  212. // pSender->sendTextMessage(QString(QJsonDocument(*msgobj).toJson()));
  213. // for (QWebSocket *pClient : qAsConst(m_clients)) {
  214. // QJsonDocument *msgdoc = new QJsonDocument(*msgobj);
  215. // if (pClient == pSender) //don't echo message back to sender
  216. // {
  217. // QJsonValue msg = new QJsonValue(message);
  218. // pClient->sendTextMessage(QString(msgdoc->toJson()));
  219. // }
  220. // qDebug() << QString(msgdoc->toJson());
  221. }
  222. }
  223. }
  224. void WSServer::socketDisconnected()
  225. {
  226. QWebSocket *pClient = qobject_cast<QWebSocket *>(sender());
  227. if (pClient)
  228. {
  229. m_clients.removeAll(pClient);
  230. pClient->deleteLater();
  231. }
  232. }
  233. void WSServer::getInit(QWebSocket *pSender, QJsonObject obj)
  234. {
  235. qDebug() << "Build with Slot";
  236. // 假接口,指针写法
  237. QJsonObject *InitState = new QJsonObject();
  238. InitState->insert("InitState", 100);
  239. QJsonObject *ret = new QJsonObject();
  240. ret->insert("url", obj.value("url"));
  241. ret->insert("data", *InitState);
  242. delete InitState;
  243. // 真实接口,局部变量
  244. // QJsonObject InitState
  245. // {
  246. // {"InitState",100*(int)this->grman->common_inter->InitState}
  247. // };
  248. // QJsonObject *ret = new QJsonObject(
  249. // {
  250. // {"url", obj.value("url")},
  251. // {"data", InitState}
  252. // });
  253. returnMessage(pSender, ret);
  254. }
  255. void WSServer::getLeadPost(QWebSocket *pSender, QJsonObject obj)
  256. {
  257. QJsonArray *LeadPost = new QJsonArray();
  258. QJsonObject *CurrentLeadPost;
  259. CurrentLeadPost = new QJsonObject();
  260. CurrentLeadPost->insert("time", "20:20:01");
  261. CurrentLeadPost->insert("GroupID", "编队1");
  262. CurrentLeadPost->insert("LeaderID", "1001");
  263. CurrentLeadPost->insert("Abstract", "发现雷达");
  264. LeadPost->append(*CurrentLeadPost);
  265. delete CurrentLeadPost;
  266. CurrentLeadPost = new QJsonObject();
  267. CurrentLeadPost->insert("time", "20:20:30");
  268. CurrentLeadPost->insert("GroupID", "编队1");
  269. CurrentLeadPost->insert("LeaderID", "1002");
  270. CurrentLeadPost->insert("Abstract", "请求施加干扰");
  271. LeadPost->append(*CurrentLeadPost);
  272. delete CurrentLeadPost;
  273. CurrentLeadPost = new QJsonObject();
  274. CurrentLeadPost->insert("time", "20:20:40");
  275. CurrentLeadPost->insert("GroupID", "编队1");
  276. CurrentLeadPost->insert("LeaderID", "1002");
  277. CurrentLeadPost->insert("Abstract", "干扰样式生成");
  278. LeadPost->append(*CurrentLeadPost);
  279. delete CurrentLeadPost;
  280. CurrentLeadPost = new QJsonObject();
  281. CurrentLeadPost->insert("time", "20:21:00");
  282. CurrentLeadPost->insert("GroupID", "编队1");
  283. CurrentLeadPost->insert("LeaderID", "1003");
  284. CurrentLeadPost->insert("Abstract", "干扰信号发射");
  285. LeadPost->append(*CurrentLeadPost);
  286. delete CurrentLeadPost;
  287. QJsonObject *ret = new QJsonObject();
  288. ret->insert("url", obj.value("url"));
  289. ret->insert("PlatformID", obj.value("PlatformID"));
  290. ret->insert("data", *LeadPost);
  291. delete LeadPost;
  292. returnMessage(pSender, ret);
  293. }
  294. void WSServer::getTaskPlan(QWebSocket *pSender, QJsonObject obj)
  295. {
  296. QJsonObject *TaskPlan = new QJsonObject();
  297. QJsonObject *CurrentAirLine;
  298. QJsonObject *CurrentTaskPlan;
  299. CurrentAirLine = new QJsonObject;
  300. CurrentAirLine->insert("TargetArea", 3);
  301. CurrentAirLine->insert("Longitude", 123);
  302. CurrentAirLine->insert("Longitude", 27);
  303. CurrentAirLine->insert("Radius", 300000);
  304. CurrentTaskPlan = new QJsonObject;
  305. CurrentTaskPlan->insert("TargetArea", 2);
  306. CurrentTaskPlan->insert("ThrowGas", 2);
  307. CurrentTaskPlan->insert("ThrowBT", 2);
  308. TaskPlan->insert("Airline", *CurrentAirLine);
  309. TaskPlan->insert("TaskPlan", *CurrentTaskPlan);
  310. QJsonObject *ret = new QJsonObject();
  311. ret->insert("url", obj.value("url"));
  312. ret->insert("PlatformID", obj.value("PlatformID"));
  313. ret->insert("data", *TaskPlan);
  314. delete TaskPlan;
  315. delete CurrentAirLine;
  316. delete CurrentTaskPlan;
  317. returnMessage(pSender, ret);
  318. }
  319. void WSServer::getGlobalMap(QWebSocket *pSender, QJsonObject obj)
  320. {
  321. QJsonArray *alies = new QJsonArray();
  322. QJsonArray *enemys = new QJsonArray();
  323. QJsonArray *temparray;
  324. QJsonObject *tempobj;
  325. {
  326. temparray = new QJsonArray();
  327. tempobj = new QJsonObject();
  328. tempobj->insert("name", "80xxA电子侦察船_1");
  329. temparray->append(120.446), temparray->append(24.8902), temparray->append(100);
  330. tempobj->insert("value", *temparray);
  331. // alies->insert("80xxA电子侦察船_1"), QJsonValue(*temparray));
  332. alies->append(*tempobj);
  333. delete temparray;
  334. delete tempobj;
  335. temparray = new QJsonArray();
  336. tempobj = new QJsonObject();
  337. tempobj->insert("name", "导弹发射架_1");
  338. temparray->append(117.525), temparray->append(25.826), temparray->append(100);
  339. tempobj->insert("value", *temparray);
  340. alies->append(*tempobj);
  341. delete temparray;
  342. delete tempobj;
  343. temparray = new QJsonArray();
  344. tempobj = new QJsonObject();
  345. tempobj->insert("name", "机场_1");
  346. temparray->append(119.271), temparray->append(26.26), temparray->append(100);
  347. tempobj->insert("value", *temparray);
  348. alies->append(*tempobj);
  349. delete temparray;
  350. delete tempobj;
  351. temparray = new QJsonArray();
  352. tempobj = new QJsonObject();
  353. tempobj->insert("name", "预警机_1");
  354. temparray->append(120.288), temparray->append(25.5734), temparray->append(100);
  355. tempobj->insert("value", *temparray);
  356. alies->append(*tempobj);
  357. delete temparray;
  358. delete tempobj;
  359. temparray = new QJsonArray();
  360. tempobj = new QJsonObject();
  361. tempobj->insert("name", "运侦8_1");
  362. temparray->append(117.525), temparray->append(25.826), temparray->append(100);
  363. tempobj->insert("value", *temparray);
  364. alies->append(*tempobj);
  365. delete temparray;
  366. delete tempobj;
  367. }
  368. {
  369. temparray = new QJsonArray();
  370. tempobj = new QJsonObject();
  371. tempobj->insert("name", "宙斯盾舰");
  372. temparray->append(123.528), temparray->append(25.2951), temparray->append(100);
  373. tempobj->insert("value",*temparray);
  374. enemys->append(*tempobj);
  375. delete temparray;
  376. delete tempobj;
  377. }
  378. QJsonObject GlobalMap
  379. {
  380. {"friend", QJsonValue(*alies)},
  381. {"enemy", QJsonValue(*enemys)}
  382. };
  383. QJsonObject *ret = new QJsonObject(
  384. {
  385. {"url", obj.value("url")},
  386. {"data", GlobalMap}
  387. });
  388. returnMessage(pSender, ret);
  389. delete alies;
  390. delete enemys;
  391. }
  392. void WSServer::getPlatformTable(QWebSocket *pSender, QJsonObject obj)
  393. {
  394. QJsonArray Platforms;
  395. // 假接口
  396. QJsonObject SinglePlatform[] {
  397. {
  398. {"platformID", 8013},
  399. {"platformName", "干扰机_1"}
  400. },
  401. {
  402. {"platformID", 8014},
  403. {"platformName", "干扰机_2"}
  404. },
  405. };
  406. for (auto i: SinglePlatform)
  407. {
  408. Platforms.append(i);
  409. }
  410. // 真实接口
  411. // for (auto i : this->grman->grtaskplats)
  412. // {
  413. // QJsonObject SinglePlatform
  414. // {
  415. // {"platformID", (int)i->PlatID},
  416. // {"platformName", QString::fromLocal8Bit(i->PlatName.c_str())}
  417. // };
  418. // Platforms.append(SinglePlatform);
  419. // }
  420. // 构造返回对象
  421. QJsonObject *ret = new QJsonObject(
  422. {
  423. {"url", obj.value("url")},
  424. {"data", Platforms}
  425. });
  426. returnMessage(pSender, ret);
  427. }
  428. void WSServer::getRadarInstances(QWebSocket *pSender, QJsonObject obj)
  429. {
  430. int nowPlatform = obj.value("PlatformID").toInt();
  431. QJsonArray RadarInstances;
  432. if (1)
  433. {
  434. QJsonObject tempRadar
  435. {
  436. {"instanceID",20},
  437. {"instanceName","雷达_1"},
  438. {"instanceState","开机"}
  439. };
  440. RadarInstances.append(tempRadar);
  441. }
  442. QJsonObject *ret = new QJsonObject();
  443. ret->insert("url", obj.value("url"));
  444. ret->insert("PlatformID", obj.value("PlatformID"));
  445. ret->insert("data",QJsonValue(RadarInstances));
  446. returnMessage(pSender, ret);
  447. }
  448. void WSServer::getRadarParams(QWebSocket *pSender, QJsonObject obj)
  449. {
  450. int nowInstance = obj.value("InstanceID").toString().toInt();
  451. QJsonObject *ret = new QJsonObject({
  452. {"url", obj.value("url")},
  453. {"PlatformID", obj.value("PlatformID")},
  454. {"InstanceID", obj.value("InstanceID")},
  455. {"data",QJsonValue()}
  456. });
  457. returnMessage(pSender, ret);
  458. }
  459. void WSServer::getJammingInstances(QWebSocket *pSender, QJsonObject obj)
  460. {
  461. QJsonArray ECMInstances;
  462. if (1)
  463. {
  464. QJsonObject tempECM
  465. {
  466. {"instanceID",20},
  467. {"instanceName","ECM_1"},
  468. {"instanceState","开机"}
  469. };
  470. ECMInstances.append(tempECM);
  471. }
  472. QJsonObject *ret = new QJsonObject();
  473. ret->insert("url", obj.value("url"));
  474. ret->insert("PlatformID", obj.value("PlatformID"));
  475. ret->insert("data",QJsonValue(ECMInstances));
  476. returnMessage(pSender, ret);
  477. }
  478. void WSServer::getJammingParams(QWebSocket *pSender, QJsonObject obj)
  479. {
  480. QJsonArray nowParams = {};
  481. QJsonObject *ret = new QJsonObject();
  482. ret->insert("url", obj.value("url"));
  483. ret->insert("PlatformID", obj.value("PlatformID"));
  484. ret->insert("InstanceID", obj.value("InstanceID"));
  485. ret->insert("data",QJsonValue(nowParams));
  486. returnMessage(pSender, ret);
  487. }
  488. void WSServer::setJammingStyle(QWebSocket *pSender, QJsonObject obj)
  489. {
  490. // PlatformID和InstanceID是字符串
  491. int nowPlatform = obj.value("PlatformID").toString().toInt();
  492. int nowInstance = obj.value("InstanceID").toString().toInt();
  493. QJsonObject *ret = new QJsonObject({
  494. {"url", obj.value("url")},
  495. {"PlatformID", obj.value("PlatformID")},
  496. {"InstanceID", obj.value("InstanceID")},
  497. {"data",QJsonValue()}
  498. });
  499. returnMessage(pSender, ret);
  500. }
  501. void WSServer::getJammingSig(QWebSocket *pSender, QJsonObject obj)
  502. {
  503. QJsonObject dat = obj.value("data").toObject();
  504. if (dat.contains("order")==false)
  505. {
  506. QJsonObject *ret = new QJsonObject({
  507. {"order", 0}
  508. });
  509. returnMessage(pSender, ret);
  510. }
  511. else {
  512. int order = dat.value("order").toInt();
  513. QJsonObject *ret = new QJsonObject({
  514. {"order", order}
  515. });
  516. if(order==1){
  517. int lines = 0;
  518. double N = 10000;
  519. double B_n = 2e6;
  520. double T_s = 100e-6;
  521. double m_fe = 1;
  522. double f_0 = 10e6;
  523. double A = 1;
  524. double f_s =100e6;
  525. coder::array<double, 2U> S;
  526. coder::array<double, 2U> S0;
  527. FMjamming_H(N,B_n,f_s,T_s,m_fe,A,f_0,S,S0);
  528. ret->insert("size",S.size(1));
  529. QJsonArray data;
  530. for (int i=0; i<S.size(1); i++)
  531. {
  532. data.append(S[i]);
  533. }
  534. ret->insert("data",data);
  535. }
  536. else if(order==2){
  537. int lines = 0;
  538. double N = 10000;
  539. double B_n = 2e6;
  540. double m_A = 1;
  541. double f_0 = 10e6;
  542. double f_s = 100e6;
  543. coder::array<double, 2U> S;
  544. AMJamming_H(N,f_s,B_n,f_0,m_A,S);
  545. ret->insert("size",S.size(1));
  546. QJsonArray data;
  547. for (int i=0; i<S.size(1); i++)
  548. {
  549. data.append(S[i]);
  550. }
  551. ret->insert("data",data);
  552. }
  553. else if(order==3){
  554. int lines = 0;
  555. double N = 1024;
  556. double B_n = 2e6;
  557. double A = 1;
  558. double f_0 = 10e6;
  559. double f_s = 100e6;
  560. coder::array<creal_T, 2U> S;
  561. jamming_H(N,f_s,A,B_n,f_0,S);
  562. double sig[1024];
  563. QJsonArray data;
  564. for(int i=0;i<S.size(1);i++)
  565. {
  566. sig[i] = S[i].re;
  567. data.append(sig[i]);
  568. }
  569. ret->insert("size",1024);
  570. ret->insert("data",data);
  571. }
  572. else if(order==4){
  573. int lines = 0;
  574. double fd = 200/3e2;
  575. double N = 1;
  576. double ts = 1/1e7;
  577. double Tr = 5e-4;
  578. double t_r = 2/1e4;
  579. double tau = 30e-6;
  580. double fo = 1e6;
  581. double k = 1e12/6;
  582. double A = 1;
  583. double dlt_t = 25e-6;
  584. double R = 30e3;
  585. double fs = 1e7;
  586. coder::array<double, 2U> S;
  587. coder::array<double, 2U> S1;
  588. coder::array<double, 2U> SS;
  589. coder::array<double, 2U> S_disturb;
  590. coder::array<double, 2U> S3;
  591. false_target_distance(fd,N,ts,Tr,t_r,tau,fo,k,A,dlt_t,R,fs,S,S1,SS,S_disturb,S3);
  592. ret->insert("size",S3.size(1));
  593. QJsonArray data;
  594. for(int i=0;i<S3.size(1);i++)
  595. {
  596. data.append(S3[i]);
  597. }
  598. ret->insert("data", data);
  599. }
  600. else if(order==5){
  601. int lines = 0;
  602. double fd = 4;
  603. double N = 1;
  604. double ts = 1e-7;
  605. double Tr = 5e-4;
  606. double t_r = 20e-5;
  607. double tau = 30e-6;
  608. double fo = 1e6;
  609. double k = 5e6/30e-6;
  610. double V = 600;
  611. coder::array<double, 2U> S;
  612. false_speed(fd,fo,ts,tau,Tr,k,t_r,V,N,S);
  613. ret->insert("size",S.size(1));
  614. QJsonArray data;
  615. for(int i=0;i<S.size(1);i++)
  616. {
  617. data.append(S[i]);
  618. }
  619. ret->insert("data", data);
  620. }
  621. else if(order==6){
  622. int lines = 0;
  623. double fd = 0.2;
  624. double N = 1;
  625. double dlt = 25e-6;
  626. double S[10500];
  627. S_jam(fd,dlt,N,S);
  628. ret->insert("size",10500);
  629. QJsonArray data;
  630. for(int i=0;i<10500;i++)
  631. {
  632. data.append(S[i]);
  633. }
  634. ret->insert("data", data);
  635. }
  636. returnMessage(pSender, ret);
  637. }
  638. }
  639. void WSServer::returnMessage(QWebSocket *pSender, QJsonObject *obj)
  640. {
  641. qDebug() << "return message:";
  642. qDebug() << QString(QJsonDocument(*obj).toJson());
  643. pSender->sendTextMessage(QString(QJsonDocument(*obj).toJson()));
  644. delete obj;
  645. }