You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

360 lines
6.5 KiB

  1. import express from "express";
  2. import { delay } from "../utils/helper";
  3. const router = express.Router();
  4. import points from "../utils/measure.json";
  5. import { MeasureState } from "../types/wsTypes";
  6. import { WsProxy } from "../utils/wss";
  7. let ptIndex = 0;
  8. let intervalId1: ReturnType<typeof setInterval>;
  9. let intervalId2: ReturnType<typeof setInterval>;
  10. router.post("/cache-measurement", async (req, res) => {
  11. await delay(100);
  12. // setTimeout(() => {
  13. // wsSend(req.app.locals["wss"], {
  14. // type: "cmd",
  15. // data: {
  16. // commandId: req.body.commandId,
  17. // status: "D0000",
  18. // },
  19. // });
  20. // }, 2000);
  21. // const measure: MeasureState["data"] = req.app.locals["measure"];
  22. // measure.taskStatus = "IDLE";
  23. // wsSend(req.app.locals["wss"], {
  24. // messageType: "STATE",
  25. // data: req.app.locals["measure"],
  26. // path: "/measurement-task/get-task-state",
  27. // });
  28. res.json({ status: 0 });
  29. });
  30. router.post("/start-measurement", (req, res) => {
  31. setTimeout(() => {
  32. ptIndex = 0;
  33. WsProxy.send({
  34. messageType: "EVENT",
  35. data: "START_RECORD_LEFT",
  36. path: "/api/measurement-task/event",
  37. })
  38. });
  39. intervalId1 = setInterval(() => {
  40. if (ptIndex >= points.length / 2) {
  41. clearInterval(intervalId1);
  42. WsProxy.send({
  43. messageType: "EVENT",
  44. data: "FINISH_RECORD_LEFT",
  45. path: "/api/measurement-task/event",
  46. });
  47. setTimeout(() => {
  48. WsProxy.send({
  49. messageType: "EVENT",
  50. data: "START_RECORD_RIGHT",
  51. path: "/api/measurement-task/event",
  52. });
  53. intervalId2 = setInterval(() => {
  54. if (ptIndex >= points.length) {
  55. clearInterval(intervalId2);
  56. ptIndex = 0;
  57. WsProxy.send({
  58. messageType: "EVENT",
  59. data: "FINISH_RECORD_RIGHT",
  60. path: "/api/measurement-task/event",
  61. });
  62. return;
  63. }
  64. WsProxy.send({
  65. messageType: "STATE",
  66. data: {
  67. x: points[ptIndex].x,
  68. y: points[ptIndex].y + 1,
  69. },
  70. path: "/api/measurement-task/point-report",
  71. });
  72. ptIndex = ptIndex + 2;
  73. }, 10);
  74. }, 2000);
  75. return;
  76. }
  77. WsProxy.send({
  78. messageType: "STATE",
  79. data: {
  80. x: points[ptIndex].x,
  81. y: points[ptIndex].y + 1,
  82. },
  83. path: "/api/measurement-task/point-report",
  84. });
  85. ptIndex = ptIndex + 2;
  86. }, 10);
  87. res.json({ status: 0 });
  88. });
  89. router.post("/stop-measurement", async (req, res) => {
  90. ptIndex = 0;
  91. clearInterval(intervalId1);
  92. clearInterval(intervalId2);
  93. res.json({ status: 0 });
  94. });
  95. router.post("/save-analysis-report/6001", async (req, res) => {
  96. await delay(100);
  97. res.json({
  98. status: 0,
  99. data: {
  100. railHeadWidth: 0,
  101. w1: 0,
  102. angleAnalysisList: [
  103. {
  104. base: {
  105. x: "-31.20880",
  106. y: "5.46060",
  107. },
  108. measure: {
  109. x: "-18.33515",
  110. y: "18.33426",
  111. },
  112. pointA: {
  113. x: "-32.62301",
  114. y: "4.04639",
  115. },
  116. pointB: {
  117. x: "-29.79458",
  118. y: "6.87482",
  119. },
  120. distance: "18.206",
  121. describe: "-45.0°",
  122. },
  123. {
  124. base: {
  125. x: "-28.51641",
  126. y: "3.39466",
  127. },
  128. measure: {
  129. x: "-22.92048",
  130. y: "13.08709",
  131. },
  132. pointA: {
  133. x: "-29.51641",
  134. y: "1.66261",
  135. },
  136. pointB: {
  137. x: "-27.51641",
  138. y: "5.12671",
  139. },
  140. distance: "11.192",
  141. describe: "-30.0°",
  142. },
  143. {
  144. base: {
  145. x: "-25.38106",
  146. y: "2.09596",
  147. },
  148. measure: {
  149. x: "-24.26901",
  150. y: "6.24616",
  151. },
  152. pointA: {
  153. x: "-25.89870",
  154. y: "0.16410",
  155. },
  156. pointB: {
  157. x: "-24.86342",
  158. y: "4.02781",
  159. },
  160. distance: "4.297",
  161. describe: "-15.0°",
  162. },
  163. {
  164. base: {
  165. x: "-21.01959",
  166. y: "1.19347",
  167. },
  168. measure: {
  169. x: "-20.63937",
  170. y: "3.34981",
  171. },
  172. pointA: {
  173. x: "-21.36689",
  174. y: "-0.77615",
  175. },
  176. pointB: {
  177. x: "-20.67230",
  178. y: "3.16308",
  179. },
  180. distance: "2.190",
  181. describe: "-10.0°",
  182. },
  183. {
  184. base: {
  185. x: "-14.10020",
  186. y: "0.28251",
  187. },
  188. measure: {
  189. x: "-14.04551",
  190. y: "0.90758",
  191. },
  192. pointA: {
  193. x: "-14.27451",
  194. y: "-1.70988",
  195. },
  196. pointB: {
  197. x: "-13.92589",
  198. y: "2.27490",
  199. },
  200. distance: "0.627",
  201. describe: "-5.0°",
  202. },
  203. {
  204. base: {
  205. x: "0.00000",
  206. y: "0.00000",
  207. },
  208. measure: {
  209. x: "0.00000",
  210. y: "0.00000",
  211. },
  212. pointA: {
  213. x: "0.03000",
  214. y: "-1.99977",
  215. },
  216. pointB: {
  217. x: "-0.03000",
  218. y: "1.99977",
  219. },
  220. distance: "0.000",
  221. describe: "0.0°",
  222. },
  223. {
  224. base: {
  225. x: "9.91970",
  226. y: "0.02682",
  227. },
  228. measure: {
  229. x: "9.91964",
  230. y: "0.02864",
  231. },
  232. pointA: {
  233. x: "9.98950",
  234. y: "-1.97196",
  235. },
  236. pointB: {
  237. x: "9.84990",
  238. y: "2.02560",
  239. },
  240. distance: "0.002",
  241. describe: "2.0°",
  242. },
  243. {
  244. base: {
  245. x: "14.10020",
  246. y: "0.28251",
  247. },
  248. measure: {
  249. x: "14.05095",
  250. y: "0.84548",
  251. },
  252. pointA: {
  253. x: "14.27451",
  254. y: "-1.70988",
  255. },
  256. pointB: {
  257. x: "13.92589",
  258. y: "2.27490",
  259. },
  260. distance: "0.565",
  261. describe: "5.0°",
  262. },
  263. {
  264. base: {
  265. x: "21.01959",
  266. y: "1.19347",
  267. },
  268. measure: {
  269. x: "20.66094",
  270. y: "3.22749",
  271. },
  272. pointA: {
  273. x: "21.36689",
  274. y: "-0.77615",
  275. },
  276. pointB: {
  277. x: "20.67230",
  278. y: "3.16308",
  279. },
  280. distance: "2.065",
  281. describe: "10.0°",
  282. },
  283. {
  284. base: {
  285. x: "25.38106",
  286. y: "2.09596",
  287. },
  288. measure: {
  289. x: "24.31693",
  290. y: "6.06734",
  291. },
  292. pointA: {
  293. x: "25.89870",
  294. y: "0.16410",
  295. },
  296. pointB: {
  297. x: "24.86342",
  298. y: "4.02781",
  299. },
  300. distance: "4.111",
  301. describe: "15.0°",
  302. },
  303. {
  304. base: {
  305. x: "28.51641",
  306. y: "3.39466",
  307. },
  308. measure: {
  309. x: "23.09930",
  310. y: "12.77737",
  311. },
  312. pointA: {
  313. x: "29.51641",
  314. y: "1.66261",
  315. },
  316. pointB: {
  317. x: "27.51641",
  318. y: "5.12671",
  319. },
  320. distance: "10.834",
  321. describe: "30.0°",
  322. },
  323. {
  324. base: {
  325. x: "31.20880",
  326. y: "5.46060",
  327. },
  328. measure: {
  329. x: "18.68979",
  330. y: "17.97962",
  331. },
  332. pointA: {
  333. x: "32.62301",
  334. y: "4.04639",
  335. },
  336. pointB: {
  337. x: "29.79458",
  338. y: "6.87482",
  339. },
  340. distance: "17.705",
  341. describe: "45.0°",
  342. },
  343. ],
  344. },
  345. timestamp: 1741697350184,
  346. });
  347. });
  348. router.post("/save-report", async (req, res) => {
  349. await delay(100);
  350. res.json({ status: 0 });
  351. });
  352. export default router;