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

import express from "express";
import { delay } from "../utils/helper";
const router = express.Router();
import points from "../utils/measure.json";
import { MeasureState } from "../types/wsTypes";
import { WsProxy } from "../utils/wss";
let ptIndex = 0;
let intervalId1: ReturnType<typeof setInterval>;
let intervalId2: ReturnType<typeof setInterval>;
router.post("/cache-measurement", async (req, res) => {
await delay(100);
// setTimeout(() => {
// wsSend(req.app.locals["wss"], {
// type: "cmd",
// data: {
// commandId: req.body.commandId,
// status: "D0000",
// },
// });
// }, 2000);
// const measure: MeasureState["data"] = req.app.locals["measure"];
// measure.taskStatus = "IDLE";
// wsSend(req.app.locals["wss"], {
// messageType: "STATE",
// data: req.app.locals["measure"],
// path: "/measurement-task/get-task-state",
// });
res.json({ status: 0 });
});
router.post("/start-measurement", (req, res) => {
setTimeout(() => {
ptIndex = 0;
WsProxy.send({
messageType: "EVENT",
data: "START_RECORD_LEFT",
path: "/api/measurement-task/event",
})
});
intervalId1 = setInterval(() => {
if (ptIndex >= points.length / 2) {
clearInterval(intervalId1);
WsProxy.send({
messageType: "EVENT",
data: "FINISH_RECORD_LEFT",
path: "/api/measurement-task/event",
});
setTimeout(() => {
WsProxy.send({
messageType: "EVENT",
data: "START_RECORD_RIGHT",
path: "/api/measurement-task/event",
});
intervalId2 = setInterval(() => {
if (ptIndex >= points.length) {
clearInterval(intervalId2);
ptIndex = 0;
WsProxy.send({
messageType: "EVENT",
data: "FINISH_RECORD_RIGHT",
path: "/api/measurement-task/event",
});
return;
}
WsProxy.send({
messageType: "STATE",
data: {
x: points[ptIndex].x,
y: points[ptIndex].y + 1,
},
path: "/api/measurement-task/point-report",
});
ptIndex = ptIndex + 2;
}, 10);
}, 2000);
return;
}
WsProxy.send({
messageType: "STATE",
data: {
x: points[ptIndex].x,
y: points[ptIndex].y + 1,
},
path: "/api/measurement-task/point-report",
});
ptIndex = ptIndex + 2;
}, 10);
res.json({ status: 0 });
});
router.post("/stop-measurement", async (req, res) => {
ptIndex = 0;
clearInterval(intervalId1);
clearInterval(intervalId2);
res.json({ status: 0 });
});
router.post("/save-analysis-report/6001", async (req, res) => {
await delay(100);
res.json({
status: 0,
data: {
railHeadWidth: 0,
w1: 0,
angleAnalysisList: [
{
base: {
x: "-31.20880",
y: "5.46060",
},
measure: {
x: "-18.33515",
y: "18.33426",
},
pointA: {
x: "-32.62301",
y: "4.04639",
},
pointB: {
x: "-29.79458",
y: "6.87482",
},
distance: "18.206",
describe: "-45.0°",
},
{
base: {
x: "-28.51641",
y: "3.39466",
},
measure: {
x: "-22.92048",
y: "13.08709",
},
pointA: {
x: "-29.51641",
y: "1.66261",
},
pointB: {
x: "-27.51641",
y: "5.12671",
},
distance: "11.192",
describe: "-30.0°",
},
{
base: {
x: "-25.38106",
y: "2.09596",
},
measure: {
x: "-24.26901",
y: "6.24616",
},
pointA: {
x: "-25.89870",
y: "0.16410",
},
pointB: {
x: "-24.86342",
y: "4.02781",
},
distance: "4.297",
describe: "-15.0°",
},
{
base: {
x: "-21.01959",
y: "1.19347",
},
measure: {
x: "-20.63937",
y: "3.34981",
},
pointA: {
x: "-21.36689",
y: "-0.77615",
},
pointB: {
x: "-20.67230",
y: "3.16308",
},
distance: "2.190",
describe: "-10.0°",
},
{
base: {
x: "-14.10020",
y: "0.28251",
},
measure: {
x: "-14.04551",
y: "0.90758",
},
pointA: {
x: "-14.27451",
y: "-1.70988",
},
pointB: {
x: "-13.92589",
y: "2.27490",
},
distance: "0.627",
describe: "-5.0°",
},
{
base: {
x: "0.00000",
y: "0.00000",
},
measure: {
x: "0.00000",
y: "0.00000",
},
pointA: {
x: "0.03000",
y: "-1.99977",
},
pointB: {
x: "-0.03000",
y: "1.99977",
},
distance: "0.000",
describe: "0.0°",
},
{
base: {
x: "9.91970",
y: "0.02682",
},
measure: {
x: "9.91964",
y: "0.02864",
},
pointA: {
x: "9.98950",
y: "-1.97196",
},
pointB: {
x: "9.84990",
y: "2.02560",
},
distance: "0.002",
describe: "2.0°",
},
{
base: {
x: "14.10020",
y: "0.28251",
},
measure: {
x: "14.05095",
y: "0.84548",
},
pointA: {
x: "14.27451",
y: "-1.70988",
},
pointB: {
x: "13.92589",
y: "2.27490",
},
distance: "0.565",
describe: "5.0°",
},
{
base: {
x: "21.01959",
y: "1.19347",
},
measure: {
x: "20.66094",
y: "3.22749",
},
pointA: {
x: "21.36689",
y: "-0.77615",
},
pointB: {
x: "20.67230",
y: "3.16308",
},
distance: "2.065",
describe: "10.0°",
},
{
base: {
x: "25.38106",
y: "2.09596",
},
measure: {
x: "24.31693",
y: "6.06734",
},
pointA: {
x: "25.89870",
y: "0.16410",
},
pointB: {
x: "24.86342",
y: "4.02781",
},
distance: "4.111",
describe: "15.0°",
},
{
base: {
x: "28.51641",
y: "3.39466",
},
measure: {
x: "23.09930",
y: "12.77737",
},
pointA: {
x: "29.51641",
y: "1.66261",
},
pointB: {
x: "27.51641",
y: "5.12671",
},
distance: "10.834",
describe: "30.0°",
},
{
base: {
x: "31.20880",
y: "5.46060",
},
measure: {
x: "18.68979",
y: "17.97962",
},
pointA: {
x: "32.62301",
y: "4.04639",
},
pointB: {
x: "29.79458",
y: "6.87482",
},
distance: "17.705",
describe: "45.0°",
},
],
},
timestamp: 1741697350184,
});
});
router.post("/save-report", async (req, res) => {
await delay(100);
res.json({ status: 0 });
});
export default router;