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.
This commit is contained in:
nguyentrungthat 2025-11-27 10:00:45 +07:00
parent f2a78c76d2
commit 68411ef611
3 changed files with 51 additions and 15 deletions

View File

@ -237,6 +237,10 @@ export default class LineConnection {
return return
} }
console.log(
`Write command "${cmd}" to line ${this.config.lineNumber} of ${this.config.stationName}`
)
this.client.write(cmd) this.client.write(cmd)
if (userName) { if (userName) {
// appendLog( // appendLog(
@ -286,6 +290,10 @@ export default class LineConnection {
return return
} }
console.log(
`Run scenario "${script?.title}" to line ${this.config.lineNumber} of ${this.config.stationName}`
)
this.isRunningScript = true this.isRunningScript = true
const now = Date.now() const now = Date.now()
this.outputScenario += `\n\n---start-scenarios---${now}---${userName}---${script?.title}---\n---scenario---${script?.title}---${now}---\n` this.outputScenario += `\n\n---start-scenarios---${now}---${userName}---${script?.title}---\n---scenario---${script?.title}---${now}---\n`

View File

@ -537,8 +537,8 @@ export class WebSocketIo {
console.log(`Socket server is running on port ${SOCKET_IO_PORT}`) 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 // 🔹 Tự động lưu dữ liệu định kỳ mỗi 10 giây
setInterval(async () => await this.saveState(), 60000) setInterval(async () => await this.saveState(), 10000)
return io return io
} }

View File

@ -125,7 +125,7 @@ export const DrawerAPCControl: React.FC<DrawerProps> = ({
} }
}); });
if (result.length > 0) apc.outlets = result; if (result.length > 0 && apc?.status === "CONNECTED") apc.outlets = result;
else { else {
Array.from({ length: 8 }).forEach((_, index) => { Array.from({ length: 8 }).forEach((_, index) => {
result.push({ result.push({
@ -245,12 +245,18 @@ export const DrawerAPCControl: React.FC<DrawerProps> = ({
<Text fw={700} c={"#514d4d"} fz={"xs"}> <Text fw={700} c={"#514d4d"} fz={"xs"}>
APC 1 APC 1
</Text> </Text>
{RenderAPCStatus(dataStation?.apc1)} {dataStation?.apc_1_ip ? (
RenderAPCStatus(dataStation?.apc1)
) : (
<Text fw={800} c="red" fz={"12px"}>
APC not available
</Text>
)}
{dataStation?.apc1?.status !== "CONNECTED" ? ( {dataStation?.apc1?.status !== "CONNECTED" ? (
<Button <Button
style={{ height: "24px" }} style={{ height: "24px" }}
size="xs" size="xs"
disabled={isSubmit} disabled={isSubmit || !dataStation?.apc_1_ip}
variant="filled" variant="filled"
color="yellow" color="yellow"
onClick={() => { onClick={() => {
@ -273,7 +279,11 @@ export const DrawerAPCControl: React.FC<DrawerProps> = ({
<div style={{ height: "24px" }}></div> <div style={{ height: "24px" }}></div>
)} )}
<Button <Button
disabled={isSubmit} disabled={
isSubmit ||
!dataStation?.apc_1_ip ||
dataStation?.apc1?.status !== "CONNECTED"
}
title={ title={
listOutletSelected.filter((el) => el.apc === 1).length === listOutletSelected.filter((el) => el.apc === 1).length ===
listOutlet.length listOutlet.length
@ -419,7 +429,11 @@ export const DrawerAPCControl: React.FC<DrawerProps> = ({
padding="xs" padding="xs"
radius="md" radius="md"
withBorder withBorder
className={`${isSubmit ? classes.isDisabled : ""}`} className={`${
isSubmit || !dataStation?.apc_1_ip
? classes.isDisabled
: ""
}`}
style={{ style={{
paddingLeft: 0, paddingLeft: 0,
paddingRight: 0, paddingRight: 0,
@ -461,12 +475,18 @@ export const DrawerAPCControl: React.FC<DrawerProps> = ({
<Text fw={700} c={"#514d4d"} fz={"xs"}> <Text fw={700} c={"#514d4d"} fz={"xs"}>
APC 2 APC 2
</Text> </Text>
{RenderAPCStatus(dataStation?.apc2)} {dataStation?.apc_2_ip ? (
RenderAPCStatus(dataStation?.apc2)
) : (
<Text fw={800} c="red" fz={"12px"}>
APC not available
</Text>
)}
{dataStation?.apc2?.status !== "CONNECTED" ? ( {dataStation?.apc2?.status !== "CONNECTED" ? (
<Button <Button
style={{ height: "24px" }} style={{ height: "24px" }}
size="xs" size="xs"
disabled={isSubmit} disabled={isSubmit || !dataStation?.apc_2_ip}
variant="filled" variant="filled"
color="yellow" color="yellow"
onClick={() => { onClick={() => {
@ -489,7 +509,11 @@ export const DrawerAPCControl: React.FC<DrawerProps> = ({
<div style={{ height: "24px" }}></div> <div style={{ height: "24px" }}></div>
)} )}
<Button <Button
disabled={isSubmit} disabled={
isSubmit ||
!dataStation?.apc_2_ip ||
dataStation?.apc2?.status !== "CONNECTED"
}
title={ title={
listOutletSelected.filter((el) => el.apc === 2).length === listOutletSelected.filter((el) => el.apc === 2).length ===
listOutlet.length listOutlet.length
@ -636,7 +660,11 @@ export const DrawerAPCControl: React.FC<DrawerProps> = ({
padding="xs" padding="xs"
radius="md" radius="md"
withBorder withBorder
className={`${isSubmit ? classes.isDisabled : ""}`} className={`${
isSubmit || !dataStation?.apc_2_ip
? classes.isDisabled
: ""
}`}
style={{ style={{
paddingLeft: 0, paddingLeft: 0,
paddingRight: 0, paddingRight: 0,
@ -859,15 +887,15 @@ export const DrawerSwitchControl: React.FC<DrawerProps> = ({
{dataStation?.switch ? ( {dataStation?.switch ? (
RenderAPCStatus(dataStation?.switch) RenderAPCStatus(dataStation?.switch)
) : ( ) : (
<Text size="sm" fw={800} c="red"> <Text fw={800} c="red" fz={"12px"}>
DISCONNECTED Switch not available
</Text> </Text>
)} )}
</Box> </Box>
{dataStation?.switch?.status !== "CONNECTED" ? ( {dataStation?.switch?.status !== "CONNECTED" ? (
<Button <Button
size="xs" size="xs"
disabled={isSubmit} disabled={isSubmit || !dataStation?.switch_control_ip}
variant="filled" variant="filled"
color="yellow" color="yellow"
onClick={() => { onClick={() => {
@ -890,7 +918,7 @@ export const DrawerSwitchControl: React.FC<DrawerProps> = ({
)} )}
<Button <Button
className={classes.buttonMenuTool} className={classes.buttonMenuTool}
disabled={isSubmit} disabled={isSubmit || !dataStation?.switch_control_ip}
title={ title={
listPortsSelected.length === listPorts.flat().length && listPortsSelected.length === listPorts.flat().length &&
listPorts.flat().length > 0 listPorts.flat().length > 0