diff --git a/public/index.html b/public/index.html
index 24578de..aab4565 100644
--- a/public/index.html
+++ b/public/index.html
@@ -9,13 +9,11 @@
diff --git a/public/main.js b/public/main.js
index 47758b2..8d1e66c 100644
--- a/public/main.js
+++ b/public/main.js
@@ -13,14 +13,39 @@ ws.onclose = () => {
console.log("Disconnected from server");
};
-$("#moveArm").on("click", () => {
- const x = $("#armX").val();
- const y = $("#armY").val();
- const z = $("#armZ").val();
+$("#startRecord").on("click", () => {
$.ajax({
type: "POST",
- url: "/api/debug/railArm",
- data: JSON.stringify({ x: +x, y: +y, z: +z }),
+ url: "/api/debug/record-sig/start",
+ data: JSON.stringify({}),
+ contentType: "application/json",
+ success: res => {
+ console.log("Success", res);
+ },
+ error: err => {
+ console.error("Error", err);
+ },
+ });
+});
+$("#endRecord").on("click", () => {
+ $.ajax({
+ type: "POST",
+ url: "/api/debug/record-sig/stop",
+ data: JSON.stringify({}),
+ contentType: "application/json",
+ success: res => {
+ console.log("Success", res);
+ },
+ error: err => {
+ console.error("Error", err);
+ },
+ });
+});
+$("#upload").on("click", () => {
+ $.ajax({
+ type: "POST",
+ url: "/api/debug/record-sig/upload",
+ data: JSON.stringify({}),
contentType: "application/json",
success: res => {
console.log("Success", res);
diff --git a/src/index.ts b/src/index.ts
index 17faed5..448abf6 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -5,9 +5,11 @@ import bodyParser from "body-parser";
import cmdRouter from "./routes/cmd";
import debugRouter from "./routes/debug";
+import authRouter from "./routes/auth";
-import { defaultStatus, StatusDatagram } from "./types/wsTypes";
+// import { defaultStatus, StatusDatagram } from "./types/wsTypes";
import { wsSend } from "./utils/wss";
+import { ContextMessage, defaultContext } from "./types/wsTypes";
const app = express();
app.use(express.static("public"));
@@ -30,23 +32,32 @@ wss.on("connection", ws => {
// }
// });
// });
- // 当连接关闭时触发
- ws.send(JSON.stringify(getCurrStatus()));
+
+ // DeviceContext
+ ws.send(
+ JSON.stringify({
+ messageType: "DeviceContext",
+ data: app.locals["context"],
+ path: "/deviceContext",
+ })
+ );
ws.on("close", () => {
console.log("Client disconnected");
});
});
-function getCurrStatus() {
- return app.locals["status"] as StatusDatagram["data"];
+function getCurrContext() {
+ return app.locals["context"] as ContextMessage["data"];
}
+
app.locals["wss"] = wss;
-app.locals["status"] = defaultStatus;
+app.locals["context"] = defaultContext;
// app.get("/", (req, res) => {
// res.send("Hello World!");
// });
app.use("/api/debug", debugRouter);
app.use("/api/cmd", cmdRouter);
+app.use("/auth", authRouter);
//@ts-ignore
app.use((err, req, res, next) => {
@@ -55,7 +66,7 @@ app.use((err, req, res, next) => {
});
// 监听端口
-const PORT = process.env.PORT || 3003;
+const PORT = process.env.PORT || 3005;
server.listen(PORT, () => {
console.log(`Server is listening on port ${PORT}`);
});
diff --git a/src/routes/auth.ts b/src/routes/auth.ts
new file mode 100644
index 0000000..33e9131
--- /dev/null
+++ b/src/routes/auth.ts
@@ -0,0 +1,60 @@
+import express from "express";
+const router = express.Router();
+import { wsSend } from "../utils/wss";
+import { delay } from "../utils/helper";
+
+router.post("/login", async (req, res) => {
+ console.log("/login:", req.body);
+ req.app.locals["context"] = {
+ loginFlag: true,
+ loginUser: {
+ id: 0,
+ account: "Demo",
+ nickname: "Demo",
+ password: "Demo",
+ userRole: "Admin",
+ isBuiltInUser: false,
+ },
+ };
+
+ wsSend(req.app.locals["wss"], {
+ messageType: "DeviceContext",
+ data: req.app.locals["context"],
+ path: "/deviceContext",
+ });
+
+ await delay(200);
+
+ res.json({
+ status: 0,
+ data: {
+ id: 3, //数据主键id
+ createTime: "2025-03-03 17:51:13", //数据创建时间
+ updateTime: "2025-03-03 19:22:35", //数据更新时间
+ account: "test001", //用户账户
+ nickname: "测试账户001", //用户昵称
+ password: null,
+ usrRole: "Admin", //用户角色,可用值:User,Admin,Dev
+ isBuiltInUser: false, //是否内置用户(内置用户不可删除)
+ },
+ timestamp: 1741001321389,
+ });
+});
+
+router.post("/logout", (req, res) => {
+ req.app.locals["context"] = {
+ loginFlag: false,
+ loginUser: {},
+ };
+ wsSend(req.app.locals["wss"], {
+ messageType: "DeviceContext",
+ data: req.app.locals["context"],
+ path: "/deviceContext",
+ });
+
+ res.json({
+ status: 0,
+ timestamp: 1741005358167,
+ });
+});
+export default router;
diff --git a/src/routes/cmd.ts b/src/routes/cmd.ts
index 6f6288f..2bbde14 100644
--- a/src/routes/cmd.ts
+++ b/src/routes/cmd.ts
@@ -5,15 +5,15 @@ const router = express.Router();
router.post("/", async (req, res) => {
await delay(200);
- setTimeout(() => {
- wsSend(req.app.locals["wss"], {
- type: "cmd",
- data: {
- commandId: req.body.commandId,
- status: "D0000",
- },
- });
- }, 2000);
+ // setTimeout(() => {
+ // wsSend(req.app.locals["wss"], {
+ // type: "cmd",
+ // data: {
+ // commandId: req.body.commandId,
+ // status: "D0000",
+ // },
+ // });
+ // }, 2000);
res.json({ code: "00000", msg: "执行成功" });
});
diff --git a/src/routes/debug.ts b/src/routes/debug.ts
index 9f6e4a1..85f1801 100644
--- a/src/routes/debug.ts
+++ b/src/routes/debug.ts
@@ -1,21 +1,56 @@
import express from "express";
import { delay } from "../utils/helper";
import { wsSend } from "../utils/wss";
-import { StatusDatagram } from "../types/wsTypes";
+import { TrackRecordSig } from "../types/wsTypes";
const router = express.Router();
+import points from "../utils/measure.json";
+let ptIndex = 0;
+let intervalId: ReturnType