From 68411ef6112207e593f3b2bf02ff4e413d13c96b Mon Sep 17 00:00:00 2001 From: nguyentrungthat <80239428+nguentrungthat@users.noreply.github.com> Date: Thu, 27 Nov 2025 10:00:45 +0700 Subject: [PATCH] Improve APC and switch control validation and logging Added console logs for command and scenario execution in line_connection.ts for better traceability. Changed socket_io_provider.ts to save state every 10 seconds instead of 60. Updated DrawerControl.tsx to disable controls and show status messages when APC or switch IPs are unavailable or not connected, improving UI feedback and preventing invalid actions. --- BACKEND/app/services/line_connection.ts | 8 ++++ BACKEND/providers/socket_io_provider.ts | 4 +- FRONTEND/src/components/DrawerControl.tsx | 54 +++++++++++++++++------ 3 files changed, 51 insertions(+), 15 deletions(-) diff --git a/BACKEND/app/services/line_connection.ts b/BACKEND/app/services/line_connection.ts index 7347ab6..27dd03d 100644 --- a/BACKEND/app/services/line_connection.ts +++ b/BACKEND/app/services/line_connection.ts @@ -237,6 +237,10 @@ export default class LineConnection { return } + console.log( + `Write command "${cmd}" to line ${this.config.lineNumber} of ${this.config.stationName}` + ) + this.client.write(cmd) if (userName) { // appendLog( @@ -286,6 +290,10 @@ export default class LineConnection { return } + console.log( + `Run scenario "${script?.title}" to line ${this.config.lineNumber} of ${this.config.stationName}` + ) + this.isRunningScript = true const now = Date.now() this.outputScenario += `\n\n---start-scenarios---${now}---${userName}---${script?.title}---\n---scenario---${script?.title}---${now}---\n` diff --git a/BACKEND/providers/socket_io_provider.ts b/BACKEND/providers/socket_io_provider.ts index 77f09fe..0ef6530 100644 --- a/BACKEND/providers/socket_io_provider.ts +++ b/BACKEND/providers/socket_io_provider.ts @@ -537,8 +537,8 @@ export class WebSocketIo { console.log(`Socket server is running on port ${SOCKET_IO_PORT}`) }) - // 🔹 Tự động lưu dữ liệu định kỳ mỗi 60 giây - setInterval(async () => await this.saveState(), 60000) + // 🔹 Tự động lưu dữ liệu định kỳ mỗi 10 giây + setInterval(async () => await this.saveState(), 10000) return io } diff --git a/FRONTEND/src/components/DrawerControl.tsx b/FRONTEND/src/components/DrawerControl.tsx index d6c87a6..5392d98 100644 --- a/FRONTEND/src/components/DrawerControl.tsx +++ b/FRONTEND/src/components/DrawerControl.tsx @@ -125,7 +125,7 @@ export const DrawerAPCControl: React.FC = ({ } }); - if (result.length > 0) apc.outlets = result; + if (result.length > 0 && apc?.status === "CONNECTED") apc.outlets = result; else { Array.from({ length: 8 }).forEach((_, index) => { result.push({ @@ -245,12 +245,18 @@ export const DrawerAPCControl: React.FC = ({ APC 1 - {RenderAPCStatus(dataStation?.apc1)} + {dataStation?.apc_1_ip ? ( + RenderAPCStatus(dataStation?.apc1) + ) : ( + + APC not available + + )} {dataStation?.apc1?.status !== "CONNECTED" ? (