|
|
@ -4,6 +4,7 @@ import { wsSend } from "../utils/wss"; |
|
|
|
const router = express.Router(); |
|
|
|
|
|
|
|
import points from "../utils/measure.json"; |
|
|
|
import { MeasureState } from "../types/wsTypes"; |
|
|
|
let ptIndex = 0; |
|
|
|
let intervalId: ReturnType<typeof setInterval>; |
|
|
|
|
|
|
@ -18,6 +19,15 @@ router.post("/cache-measurement", async (req, res) => { |
|
|
|
// },
|
|
|
|
// });
|
|
|
|
// }, 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 }); |
|
|
|
}); |
|
|
|
|
|
|
@ -31,11 +41,27 @@ router.post("/start-measurement", (req, res) => { |
|
|
|
}, |
|
|
|
path: "/measurement-task/get-task-state", |
|
|
|
}); |
|
|
|
|
|
|
|
const measure: MeasureState["data"] = req.app.locals["measure"]; |
|
|
|
measure.taskStatus = "MEASURING"; |
|
|
|
wsSend(req.app.locals["wss"], { |
|
|
|
messageType: "STATE", |
|
|
|
data: req.app.locals["measure"], |
|
|
|
path: "/measurement-task/get-task-state", |
|
|
|
}); |
|
|
|
}); |
|
|
|
intervalId = setInterval(() => { |
|
|
|
if (ptIndex >= points.length) { |
|
|
|
clearInterval(intervalId); |
|
|
|
// ptIndex = 0;
|
|
|
|
const measure: MeasureState["data"] = req.app.locals["measure"]; |
|
|
|
measure.taskStatus = "FINISHED"; |
|
|
|
wsSend(req.app.locals["wss"], { |
|
|
|
messageType: "STATE", |
|
|
|
data: req.app.locals["measure"], |
|
|
|
path: "/measurement-task/get-task-state", |
|
|
|
}); |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
wsSend(req.app.locals["wss"], { |
|
|
@ -55,6 +81,22 @@ router.post("/stop-measurement", async (req, res) => { |
|
|
|
ptIndex = 0; |
|
|
|
clearInterval(intervalId); |
|
|
|
|
|
|
|
wsSend(req.app.locals["wss"], { |
|
|
|
messageType: "EVENT", |
|
|
|
data: { |
|
|
|
event: "END_RECORD_SIG", |
|
|
|
}, |
|
|
|
path: "/measurement-task/get-task-state", |
|
|
|
}); |
|
|
|
|
|
|
|
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("/analyze-measurement", async (req, res) => { |
|
|
@ -69,14 +111,17 @@ router.post("/analyze-measurement", async (req, res) => { |
|
|
|
// });
|
|
|
|
// }, 2000);
|
|
|
|
|
|
|
|
res.json({ status: 0, data: { |
|
|
|
angles: [ |
|
|
|
{ x: 9.949007022412, y: -0.1650166186941, degree: 80, describe: "80°"}, |
|
|
|
{ x: 25.35, y: -2.184814802617, degree: 60, describe: "60°" }, |
|
|
|
{ x: -9.949007022412, y: -0.1650166186941, degree: 100, describe: "100°" }, |
|
|
|
{ x: -25.35, y: -2.184814802617, degree: 120, describe: "120°" }, |
|
|
|
] |
|
|
|
}}); |
|
|
|
res.json({ |
|
|
|
status: 0, |
|
|
|
data: { |
|
|
|
angles: [ |
|
|
|
{ x: 9.949007022412, y: -0.1650166186941, degree: 80, describe: "80°" }, |
|
|
|
{ x: 25.35, y: -2.184814802617, degree: 60, describe: "60°" }, |
|
|
|
{ x: -9.949007022412, y: -0.1650166186941, degree: 100, describe: "100°" }, |
|
|
|
{ x: -25.35, y: -2.184814802617, degree: 120, describe: "120°" }, |
|
|
|
], |
|
|
|
}, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
router.post("/save-report", async (req, res) => { |
|
|
|