This commit is contained in:
nguyentrungthat 2025-11-05 09:10:25 +07:00
parent d031c1e93e
commit ef7ea5c9af
6 changed files with 41 additions and 22 deletions

View File

@ -21,10 +21,10 @@ class APCController {
private apc_port: number
private apc_username: string
private apc_password: string
private status: 'CONNECTED' | 'DISCONNECTED' | 'TIMEOUT'
public status: 'CONNECTED' | 'DISCONNECTED' | 'TIMEOUT'
private socket: Socket
private buffer: string
private output: string
public output: string
private promptCallbacks: PromptCallback[]
private onData: (data: string, status: string) => void
private retryConnect: number

View File

@ -0,0 +1,17 @@
import { BaseSchema } from '@adonisjs/lucid/schema'
export default class extends BaseSchema {
protected tableName = 'users'
async up() {
this.schema.alterTable(this.tableName, (table) => {
table.string('email').nullable().alter()
})
}
async down() {
this.schema.alterTable(this.tableName, (table) => {
table.string('email').notNullable().alter()
})
}
}

View File

@ -249,10 +249,12 @@ export class WebSocketIo {
socket.on('connect_apc', async (data) => {
const { apcIp, station, apcName } = data
if (this.apcsControl.has(apcIp)) {
const apc = this.apcsControl.get(apcIp)
if (apc && apc.status === 'CONNECTED') {
return
}
await this.connectApc(io, apcName, station)
} else if (apc && apc.status !== 'CONNECTED') {
await apc.reconnect()
} else await this.connectApc(io, apcName, station)
})
})
@ -377,6 +379,7 @@ export class WebSocketIo {
port,
username,
password,
number: apcName === 'apc_1' ? 1 : 2,
onData: (data: string, status: string) => {
socket.emit('apc_output', {
stationId: station.id,

View File

@ -23,10 +23,10 @@ function Register() {
const handleRegister = async () => {
try {
if (!formRegister.email) {
if (!formRegister.user_name) {
notifications.show({
title: "Error",
message: "Email is required",
message: "Username is required",
color: "red",
});
return;

View File

@ -263,7 +263,7 @@ export default function DraggableTabs({
/>
}
/>
<Flex gap={"xs"} ms={"md"}>
{/* <Flex gap={"xs"} ms={"md"}>
<Button
miw={"80px"}
size="xs"
@ -305,7 +305,7 @@ export default function DraggableTabs({
>
Switch
</Button>
</Flex>
</Flex> */}
</Flex>
<Tabs.List className={classes.list}>
<SortableContext

View File

@ -171,7 +171,7 @@ export const DrawerAPCControl: React.FC<DrawerProps> = ({
useEffect(() => {
socket?.on("apc_output", (data) => {
if (data.stationId !== stationAPI.id) return;
let apcs: APCProps[] = [];
const outlets: TSelectedOutlet[] = [];
setDataStation((prev) => {
const apc1 =
data.apcNumber === 1
@ -181,19 +181,18 @@ export const DrawerAPCControl: React.FC<DrawerProps> = ({
data.apcNumber === 2
? { ...prev.apc2, output: data.data, status: data.status }
: prev.apc2;
apcs = [apc1, apc2];
return prev.id === data.stationId
? { ...prev, apc1: apc1, apc2: apc2 }
: prev;
});
const outlets: TSelectedOutlet[] = [];
console.log("apcs", apcs);
apcs.forEach(async (apc, i) => {
const result: TSelectedOutlet[] = [];
const lines = apc?.output?.split("\n") || [];
await detectOutlet(apc, lines, result, i);
outlets.push(...result);
[apc1, apc2].forEach(async (apc, i) => {
if (!apc) return;
const result: TSelectedOutlet[] = [];
const lines = apc?.output?.split("\n") || [];
await detectOutlet(apc, lines, result, i);
console.log("result", result);
outlets.push(...result);
});
return { ...prev, apc1: apc1, apc2: apc2 };
});
// console.log("outlets", outlets);
setListOutlet(outlets);
});
}, [socket]);